我需要创建一个标记,代表每个用户在谷歌地图上的本地化,我使用谷歌地图 api v3,我把标记放在地图上,这很容易,但是当用户进行缩放时我如何做到这一点,图标不会调整大小, 我如何在缩放更改或任何更改时不调整图标大小?
原因是我有一个圆形图像,代表每个用户 50 米的无线电,如果图像改变,圆形的无线电会改变。
这是我的代码:
//Creamos el marcador para saber donde esta el usuario
marker:function(map,latLng) {
//create a marker image with the path to your graphic and the size of your graphic
var markerImage = new google.maps.MarkerImage(
'/img/marker.png',
new google.maps.Size(130,130), //size
null, //origin
null, //anchor
new google.maps.Size(130,130) //scale
);
var marker = new google.maps.Marker({
position: latLng,
map: map,
icon: markerImage //set the markers icon to the MarkerImage
});
marker.setMap(map);
//when the map zoom changes, resize the icon based on the zoom level so the marker covers the same geographic area
google.maps.event.addListener(map, 'zoom_changed', function() {
var pixelSizeAtZoom0 = 130; //the size of the icon at zoom level 0
var maxPixelSize = 130; //restricts the maximum size of the icon, otherwise the browser will choke at higher zoom levels trying to scale an image to millions of pixels
var zoom = map.getZoom();
var relativePixelSize = Math.round(pixelSizeAtZoom0*Math.pow(2,zoom)); // use 2 to the power of current zoom to calculate relative pixel size. Base of exponent is 2 because relative size should double every time you zoom in
if(relativePixelSize > maxPixelSize) //restrict the maximum size of the icon
relativePixelSize = maxPixelSize;
//change the size of the icon
marker.setIcon(
new google.maps.MarkerImage(
marker.getIcon().url, //marker's same icon graphic
null,//size
null,//origin
null, //anchor
new google.maps.Size(relativePixelSize, relativePixelSize) //changes the scale
)
);
});
return marker;
},