0
我正在从服务器加载功能并将它们添加为矢量图层的源。功能未显示
var map = new ol.Map({
target: 'map',
interactions: ol.interaction.defaults().extend([
new ol.interaction.DragRotate()
]),
controls: ol.control.defaults().extend([
new ol.control.FullScreen(),
new ol.control.ScaleLine()
]),
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),
new ol.layer.Tile({
source: new ol.source.TileWMS({
url: 'https://server.com/wms?',
params: {
'LAYERS': 'operational_structures',
'TILED': true
}
}),
maxResolution: 500,
opacity: 0.3
}),
new ol.layer.Vector({
source: new ol.source.Vector({
url: function (extent, resolution, projection) {
return 'https://server/wms?Request=GetFeature&BBOX='
+ extent.join(',');
},
format: new ol.format.GeoJSON(),
strategy: ol.loadingstrategy.bbox
}),
style: new ol.style.Style({
image: new ol.style.Circle({
radius: 10,
fill: new ol.style.Fill({color: 'rgba(255, 0, 0, 0.1)'}),
stroke: new ol.style.Stroke({color: 'red', width: 1})
})
})
})
],
view: new ol.View({
center: ol.proj.fromLonLat([0, 0]),
zoom: 4
})
});
一切工作正常,取得所有功能。我可以使用layer.getSource().getFeatures()
访问它们。我的数据是这样的:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {
"id": 1,
"ref": "GIS_af05"
},
"geometry": {
"type": "Point",
"coordinates": [ -119383.2138463442, 7156374.7828825945 ]
}
},
{
"type": "Feature",
"properties": {
"id": 2,
"ref": "GIS_af06" },
"geometry": {
"type": "Point",
"coordinates": [ -117573.06816312684, 7163838.359699009 ]
}
},
{
"type": "Feature",
"properties": {
"id": 3,
"ref": "GIS_af21" },
"geometry": {
"type": "Point",
"coordinates": [ -128431.22137966838, 7169061.1280527115 ]
}
}]
}
但是因为不明原因他们不会出现。我错过了什么吗?
编辑:
所以我发现它搞乱与预测。它会尝试将要素坐标从ESPG:4326
转换为ESPG:3857
。问题是,他们已经是ESPG:3857
。我怎样才能防止呢?
你能提供的代码的其余部分?特别是地图初始化。 – ohvitorino
你不应该在你的矢量图层中调用http:// server/wfs而不是wms吗? –
@HichamZouarhi这只是一个API名称。其实我打电话给'server/wmf?Service = wfs&...',但是我把它丢掉了,因为它不值一提。正如我所说:数据被认为是geoJSON,我可以访问从它加载的'ol.Feature'对象。 – gerric