问题描述
我正在从geojson文件在地图上显示标记。在当前代码中,当我将鼠标悬停在标记上时,可以在弹出窗口中看到属性。我想在点击标记时添加飞行器或放大标记的确切位置。我该如何实现。
cityMarker = new L.geoJson(city,{
onEachFeature: function(feature,layer) {
//if (feature.properties && feature.properties.name) {
if ( feature.properties.name) {
layer.bindPopup(feature.properties.name,{closeButton: false,offset: L.point(0,-2)});
layer.on('mouSEOver',function() { layer.openPopup(); });
layer.on('mouSEOut',function() { layer.closePopup(); });
}
},pointToLayer: function (feature,latlng) {
var cityIcon = new L.Icon({
iconSize: [20,20],iconAnchor: [13,27],popupAnchor: [1,-20],iconUrl: './css/img/marker-icon-red.png'
});
//return L.circleMarker(latlng);
return L.marker(latlng,{icon: cityIcon});
}
});
map.addLayer(cityMarker);
解决方法
我已经找到了解决方案,所以,我在这里添加它。
cityMarker.on('click',function(e) {
map.setView(e.latlng,16);
});
,
要获得良好的平滑动画平移/缩放效果而不是跳跃,请使用flyTo
cityMarker.on('click',function(e) {
map.flyTo(e.latlng,16);
});