【发布时间】:2019-04-24 23:09:43
【问题描述】:
我正在尝试使用 json 对象设置多边形,但我的多边形放置在地图上的不同位置。我是第一次使用 openlayers。我提到了一些关于开放层文档的例子,但没有一个能解决我的问题。我附上了一些相同的屏幕截图。请帮我。如果我应该遵循任何文档,这将对我有很大帮助。
我尝试了以下链接:
- https://gis.stackexchange.com/questions/134688/add-geojson-layer-to-openlayers-3
- GeoJSON feature coordinates not displaying on OpenLayers map
- Trying to display a GeoJSON on Openlayers 3
var image = new CircleStyle({
radius: 5,
fill: null,
stroke: new Stroke({color: 'red', width: 1})
});
var styles = {
'Point': new Style({
image: image
}),
'LineString': new Style({
stroke: new Stroke({
color: 'green',
width: 1
})
}),
'MultiLineString': new Style({
stroke: new Stroke({
color: 'green',
width: 1
})
}),
'MultiPoint': new Style({
image: image
}),
'MultiPolygon': new Style({
stroke: new Stroke({
color: 'yellow',
width: 1
}),
fill: new Fill({
color: 'rgba(255, 255, 0, 0.1)'
})
}),
'Polygon': new Style({
stroke: new Stroke({
color: 'blue',
lineDash: [4],
width: 3
}),
fill: new Fill({
color: 'rgba(0, 0, 255, 0.1)'
})
}),
'GeometryCollection': new Style({
stroke: new Stroke({
color: 'magenta',
width: 2
}),
fill: new Fill({
color: 'magenta'
}),
image: new CircleStyle({
radius: 10,
fill: null,
stroke: new Stroke({
color: 'magenta'
})
})
}),
'Circle': new Style({
stroke: new Stroke({
color: 'red',
width: 2
}),
fill: new Fill({
color: 'rgba(255,0,0,0.2)'
})
})
};
var styleFunction = function(feature) {
return styles[feature.getGeometry().getType()];
};
var geojsonObject = {
"type": "FeatureCollection",
"features": [
...
],
"totalFeatures": 12,
"numberMatched": 12,
"numberReturned": 12,
"timeStamp": "2019-04-23T05:39:42.875Z",
"crs": {
"type": "name",
"properties": {
"name": "urn:ogc:def:crs:EPSG::3997"
}
}
}
var vectorSource = new VectorSource({
features: (new GeoJSON({
featureProjection: 'EPSG:3997',
dataProjection: 'EPSG:4326'
})).readFeatures(geojsonObject),
});
// var center = fromLonLat([0, 0], 'EPSG:4326', 'EPSG:3997');
vectorSource.addFeature(new Feature());
var vectorLayer = new VectorLayer({
source: vectorSource,
style: styleFunction,
});
var map = new Map({
layers: [
new TileLayer({
source: new OSM()
}),
vectorLayer
],
target: 'map',
view: new OlView({
center: [0, 0],
zoom: 2,
})
});
我正在获取位于非洲而非阿联酋地区的样式。
【问题讨论】:
-
您能否提供一个 minimal reproducible example 来证明您的问题,其中至少有一个位于错误位置的示例功能?
-
有没有办法上传图片?所以我会告诉你出了什么问题。
-
您可以发布图片链接,但图片不是minimal reproducible example(尽管它们可能有助于理解问题)。请提供一个 minimal reproducible example 来证明该问题。
标签: angular5 geojson openlayers-5