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