Openlayers 3 如何在openlayers3中使用Geojson的功能?
我使用的是openlayers3,我想从feature.json中获取我的功能,似乎当我的地图被放置时,我可以根据xhr请求从网络中获取功能文件,但我无法在地图上看到我的多边形。下面是我的代码Openlayers 3 如何在openlayers3中使用Geojson的功能?,openlayers-3,geojson,Openlayers 3,Geojson,我使用的是openlayers3,我想从feature.json中获取我的功能,似乎当我的地图被放置时,我可以根据xhr请求从网络中获取功能文件,但我无法在地图上看到我的多边形。下面是我的代码 function showMap() { var vector = new ol.layer.Vector({ projection: 'EPSG:5650', source: new ol.source.Vector({ format: new ol.format.Geo
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的OldServerVersion,而不是在源代码中使用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(){})
JSON文件和GeoJSON文件之间有一点不同。你的
feature.json
是有效的GeoJSON文件吗?我找到了解决方案,我使用的是openlayers的olderversion,现在我使用的不是源代码中的url,而是功能,它可以工作!!