openlayers3 -如何在openlayers3中使用Geojson的特性



我正在使用openlayers3,我想把我的功能从功能。json,似乎当我的地图加载时,我可以从网络获得功能文件作为xhr请求,但我无法在地图上看到我的多边形。下面是我的代码

function showMap() {
  var vector = new ol.layer.Vector({
    projection: 'EPSG:5650',
    source: new ol.source.Vector({
      format: new ol.format.GeoJSON(),
      projection: 'EPSG:5650',
      url: 'feature.json'
    })
  });
  var map = new ol.Map({
    target: 'tilemap',
    controls: ol.control.defaults({
      attributionOptions: /** @type {olx.control.AttributionOptions} */ ({
       collapsible: false
      })
    }),
    layers: [
      new ol.layer.Image({
        source: new ol.source.ImageWMS({
          url: 'http://www.geodaten-mv.de/dienste/adv_dop',
          crossOrigin: null,
          projection: 'EPSG:5650',
          params: {
            VERSION: '1.3.0',
            LAYERS: 'mv_dop',
            FORMAT: 'image/jpeg',
            CRS: 'EPSG:5650'
          }
        })
      }),vector
    ],
    view: new ol.View({
      projection: 'EPSG:5650',
      center: [33355494, 5983295],
      zoom: 10
    })
  });
  DisplayTilesServices.setMap(map);
}

我使用的是旧版本的openlayers,而不是在源代码中使用url,现在我使用的是功能,它可以工作!!参见下面的代码

 $http.get('feature.geojson').then(function(res){
    var format = new ol.format.GeoJSON();
    source=new ol.source.Vector({
      projection: 'EPSG:5650',
      features:format.readFeatures(res.data)
    });
    var vectorLayer = new ol.layer.Vector({
      source: source
    });
    map.addLayer(vectorLayer);
  },function(){})

最新更新