获取当前位置但未显示标记图像(locationStyle)
目前在页面加载或地图更改时获取当前位置。如何从外部按钮或链接点击获取当前位置
var locationCircle = new ol.Feature();
currentLocation = new ol.layer.Vector({
source: new ol.source.Vector({
features: [locationCircle]
})
});
var locationStyle = new ol.style.Style({
image: new ol.style.Icon(/** @type {olx.style.IconOptions} */ ({
anchor: [0.5, 46],
anchorXUnits: 'fraction',
anchorYUnits: 'pixels',
opacity: 0.75,
src: 'resources/icon.png'
}))
});
map = new ol.Map({
target: target,
layers: [bingMapsRoad, circleLayer,vector,vehicleVector,currentLocation],
// renderer: 'canvas',
view: new ol.View({
// center: ol.proj.transform([-0.12755, 51.507222], 'EPSG:27700', 'EPSG:3857'),
//center: [-10807016, 5029327],
// projection: 'EPSG:27700',
// resolutions: ResolutionsInfo,
center: ol.proj.transform([-0.12755, 51.507222], 'EPSG:4326', 'EPSG:3857'),
loadTilesWhileAnimating: true,
loadTilesWhileInteracting: true,
zoom: 6
}),
controls: ol.control.defaults({ attribution: false }),
loadTilesWhileInteracting: true
});
new ol.Geolocation({
projection: map.getView().getProjection(),
tracking: true,
trackingOptions: {
enableHighAccuracy: true
}
})
.on('change', function() {
var position = this.getPosition();
var speed = this.getSpeed();
var altitude = this.getAltitude();
var heading = this.getHeading();
map.getView().setCenter(position);
locationCircle.setGeometry(
new ol.geom.Circle(position, 20)
);
});
答案 0 :(得分:0)
你可以用它代替它:
geolocation.setProjection(map.getView().getProjection);
函数bindTo没有出现在最新的API文档中