openlayers 편집 영역

5390 단어




    
    
    <link rel="stylesheet" href="lib/OpenLayers/ol.css" type="text/css"/>

    <script src="http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"/>
    <script src="lib/OpenLayers/ol.js"/>
    <script src="olStyle/Light.js"/>
    <style>
        html,
        body {
            width: 100%;
            height: 100%;
            margin: 0;
        }

        .map {
            width: 100%;
            height: 100%;
            background: #f6f6f4;
        }
    </style>



    <div id="map" class="map" data-id="11"/>
    <script type="text/javascript">  

        $(function () {

            InitMap();

            AddPolygon();

            // 
            EditArea();

        })

        var map;

        var layer = new ol.layer.Vector({
            source: new ol.source.Vector(),
            style: new ol.style.Style({
                fill: new ol.style.Fill({
                    color: 'rgba(255, 0, 0, 0.5)'
                }),
                stroke: new ol.style.Stroke({
                    color: 'red',
                    width: 2
                }),
                image: new ol.style.Circle({
                        // 
                        radius: 7,
                        // 
                        fill: new ol.style.Fill({
                            // 
                            color: '#e81818'
                        })
                    })
            })
        });

        // 
        function InitMap() {
            map = new ol.Map({
                layers: [new ol.layer.Vector({
                    source: new ol.source.Vector()
                    }),
                    style: function (feature, resolution) {
                        switch (feature.get('layer')) {
                            case 'poi':
                                poiStyle.getText().setText(feature.get('name'));
                                return poiStyle;
                            case 'boundary': return boundaryStyle;
                            case 'lawn': return lawnStyle;
                            case 'road':
                                roadStyle.getText().setText(feature.get('name'));
                                return (resolution < 2) ? roadStyle : null;
                            case 'building':
                                return buildingStyle(feature, resolution);
                            case 'other':
                                otherStyle.getText().setText(feature.get('name'));
                                return otherStyle;
                            default: return null;
                        }
                    }
                }), layer],
                target: 'map',
                view: new ol.View({
                    center: ol.proj.fromLonLat([120.277, 36.330]),
                    minZoom: 1,
                    zoom: 16
                })
            });
        }
        
        /* **********************************************************************************/
        function AddPolygon() {
            layer.getSource().clear();

            // var points = [[
            //     ol.proj.fromLonLat([120.27681827545163, 36.33236136226455]),
            //     ol.proj.fromLonLat([120.28038024902342, 36.33141061727086]),
            //     ol.proj.fromLonLat([120.27681827545163, 36.33001040806349]),
            //     ol.proj.fromLonLat([120.27681827545163, 36.33236136226455])
            // ]]

            // var plygon = new ol.geom.Polygon(points)
            // // 
            // var feature = new ol.Feature({
            //     geometry: plygon
            // });

            //var points = ol.proj.fromLonLat([120.27611017227173,36.331306898933306]);
            var points = [13389075.33897296,4346304.97458048]

            var plygon = new ol.geom.Circle(points,294)
            var feature = new ol.Feature({
                geometry: plygon
            });

            layer.getSource().addFeature(feature);

        }

        function EditArea() {

            modify = new ol.interaction.Modify({
                source: layer.getSource(),
            });
            //modify.setActive(true);
            modify.on("modifyend", function () {
                //  
                // var features = layer.getSource().getFeatures();

                // var geometry = features[0].getGeometry();

                // var points;
                // var lnglat = [];

                // points = geometry.getCoordinates()[0];

                // for (var i = 0; i < points.length; i++) {
                //     lnglat.push(ol.proj.transform(points[i], 'EPSG:3857', 'EPSG:4326'));
                // }

                // console.log(lnglat);
            })
            map.addInteraction(modify);
        }


    </script>



</code></pre> 
   </div> 
   <p>  </p> 
  </div> 
  <p> :https://www.cnblogs.com/zhoushangwu/p/9449011.html</p> 
 </div> 
</div>
                            </div>
                        </div>

좋은 웹페이지 즐겨찾기