首页 > 其他 > 详细

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

时间:2018-06-14 14:09:47      阅读:353      评论:0      收藏:0      [点我收藏+]
技术分享图片

    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,
    });

详细源码
官方源码注释

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

原文:http://blog.51cto.com/13562606/2129290

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!