我正在使用 Web 功能服务 (WFS),并且我想在 OpenLayers 地图上显示一个标记。WFS 的回应摘录:
<?xml version="1.0" encoding="ISO-8859-1"?>
<wfs:FeatureCollection>
<gml:boundedBy>
<gml:Envelope srsName="EPSG:900913">
<gml:lowerCorner>-89132.899298 5581504.864113</gml:lowerCorner>
<gml:upperCorner>-51735.101149 5625545.655457</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
<gml:featureMember>
<bm:TB_ARRET_P gml:id="TB_ARRET_P.3473">
<gml:boundedBy>
<gml:Envelope srsName="EPSG:900913">
<gml:lowerCorner>-75379.857910 5601410.987374</gml:lowerCorner>
<gml:upperCorner>-75379.857910 5601410.987374</gml:upperCorner>
</gml:Envelope>
</gml:boundedBy>
<bm:geometry>
<gml:Point srsName="EPSG:900913">
<gml:pos>-75379.857910 5601410.987374</gml:pos>
</gml:Point>
</bm:geometry>
<bm:LIGNEDES>Citéis 72/Lianes 3</bm:LIGNEDES>
<bm:MOBILIE1>Poteau</bm:MOBILIE1>
<bm:NOMARRET>Mairie du Haillan</bm:NOMARRET>
<bm:VILLE>LE HAILLAN</bm:VILLE>
</bm:TB_ARRET_P>
<bm:TB_ARRET_P>
...
</bm:TB_ARRET_P>
</gml:featureMember>
</wfs:FeatureCollection>
我使用 OpenLayers 显示带有以下代码的标记:
const f = new Feature({geometry: new Point([-75379.857910, 5601410.987374])});
const orangePoint = new Style({
image: new CircleStyle({
radius: 5,
fill: new Fill({color: 'red'}),
stroke: new Stroke({color: 'red', width: 3})
})
});
f.setStyle(orangePoint);
const map = new Map({
layers: [
new TileLayer({ source: new XYZ({ url: this.mapboxTile }) }),
new VectorLayer({
source: new VectorSource({
features: [f]
})
})
],
target: this.idMaps$,
view: new View({
projection: 'EPSG:3857', // OpenLayers' default project and alias of 900913
center: [-64436.414844, 5595687.311159],
zoom: 12
})
});
因此,标记已显示,但位置不理想。我错过了什么?如何将标记置于“Mairie”公交车站的中心?
谢谢您的回答 !