openlayers根据坐标在地图上划区域-创新互联

openlayers根据坐标在地图上划区域

成都创新互联主要从事成都网站建设、网站设计、网页设计、企业做网站、公司建网站等业务。立足成都服务壶关,十年网站建设经验,价格优惠、服务专业,欢迎来电咨询建站服务:18980820575
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,
    });

详细源码
官方源码注释

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


分享文章:openlayers根据坐标在地图上划区域-创新互联
本文网址:http://myzitong.com/article/pdiho.html