[英]Cannot place marker at the right coordinates using openlayers 3
我正在研究openlayers 3並希望實現一個搜索功能,它獲取地點的名稱並在地圖上定位標記。 我能夠獲得坐標但是當我想在地圖上添加它的標記時,我總是得到不同的位置。 輸入位置的標記未放置在地圖的實際坐標上。
這是我一直在工作的代碼:
function addmarker(lat, long, pointerimgsrc){
var iconFeature = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.transform([lat, long], 'EPSG:4326', 'EPSG:3857')),
name: 'NULL'
});
var iconStyle = new ol.style.Style({
image: new ol.style.Icon(({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
opacity: 0.75,
//src: 'data/icon.png'
src: pointerimgsrc
}))
});
iconFeature.setStyle(iconStyle);
vectorSource = new ol.source.Vector({
features: [iconFeature]
});
vectorLayer = new ol.layer.Vector({
source: vectorSource
});
map.addLayer(vectorLayer);
}// END addmarkerr()
我希望我已經清楚地解釋了我的問題,期待找到解決方案。 非常感謝您的時間和支持。
EPSG:4326坐標順序lon,lat not lat,lon。 因此,您應該更改執行EPSG的行:4326到EPSG:3857轉換。
ol.proj.transform([lon, lat], 'EPSG:4326', 'EPSG:3857')
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.