openlayers根據座標在地圖上劃區域

R-B發表於2021-09-09


    var styles = {      'Polygon': [new ol.style.Style({        stroke: new ol.style.Stroke({          color: '#ff3100',          lineDash: [0],          width: 1        }),        fill: new ol.style.Fill({          color: 'rgba(0, 0, 255, 0.1)'        })      })],    };    var styleFunction = function(feature) {      console.log(feature)      return styles[feature.getGeometry().getType()];    };    var geojsonObject = {      'type': 'FeatureCollection',      'crs': {        'type': 'name',        'properties': {          'name': 'EPSG:3857'        }      },      'features': [        {        //區域          'type': 'Feature',          'geometry': {            'type': 'Polygon',            'coordinates': [              [                .........              ]            ]          }        },      ]    };    var vectorSource = new ol.source.Vector({      features: (new ol.format.GeoJSON()).readFeatures(geojsonObject)    });    var vectorLayer = new ol.layer.Vector({      source: vectorSource,      style: styleFunction,    });

詳細原始碼
官方原始碼註釋

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/4560/viewspace-2818265/,如需轉載,請註明出處,否則將追究法律責任。

相關文章