2016-06-24 31 views
1

私はopenlayers3を使用しています。私はfeature.jsonから自分のフィーチャーを持っていきたいと思っています。マップが埋め込まれているようです。xhrリクエストとしてフィーチャーファイルをネットワークから取得できます。ここでは以下の私のコードは、私がOpenLayersをのolderversionを使用していたし、今の代わりにソース内のURLを使用しての、今私は機能を使用していますし、それが動作openlayers3でGeojsonの機能を使用するには?

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); 
} 
+1

JSONファイルとGeoJSONファイルの間には少し違いがあります。あなたの 'feature.json'は有効なGeoJSONファイルですか? –

+0

私は解決策を見つけました。私は古いバージョンのopenlayersを使用していましたが、ソースでURLを使用する代わりに、機能を使用しています。 –

答えて

1

です!以下のコードを参照してください

$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(){}) 
関連する問題