[英]Location of iconFeature openlayers3
我有以下代码用于显示带有标记的地图。 我正在使用OpenLayers3。 问题是标记无法正常显示在正确的位置。 它必须在加拿大显示,但必须显示在地图中间
var iconFeature = new ol.Feature({
geometry: new ol.geom.Point([-72.66, 45.04]),
name: 'Null Island'
});
var iconStyle = new ol.style.Style({
image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
src: 'https://openlayers.org/en/v3.20.0/examples/data/icon.png'
}))
});
iconFeature.setStyle(iconStyle);
var vectorSource = new ol.source.Vector({
features: [iconFeature]
});
var vectorLayer = new ol.layer.Vector({
source: vectorSource
});
//map
var map = new ol.Map({
target: 'map',
layers: [
new ol.layer.Tile({
source: new ol.source.OSM()
}),vectorLayer
],
view: new ol.View({
center: ol.proj.fromLonLat([-72, 45]),
zoom: 6
})
});
我如何在正确的位置制作标记。 谢谢。
OSG层投影在EPSG:3857投影系统中。 但是传递给iconFeature的坐标在WGS84投影系统中。 设置中心时,将转换坐标。 同样需要为iconFeature Object应用相同的对象。
像对中心一样,变换iconFeature特征对象的坐标。
var iconFeature = new ol.Feature({
geometry: new ol.geom.Point(ol.proj.fromLonLat([-72.66, 45.04])),
name: 'Null Island'
});
在此插件链接中查看更新的代码
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.