【发布时间】:2015-01-11 18:31:04
【问题描述】:
我正在开发 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()
我希望我已经清楚地解释了我的问题,期待解决方案。非常感谢您的时间和支持。
【问题讨论】:
标签: javascript openstreetmap openlayers-3