我如何使谷歌地图不更改标记的自定义图标大小
How I make that google maps not change the custom icons size of marker?
我需要创建一个标记来表示每个用户在谷歌地图上的本地化,我使用谷歌地图 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;
},
这不是标记的适当用法。相反,您将使用圆形叠加层。圆的半径以米为单位设置。
为了解决这个问题,我需要根据地图的缩放比例缩放图像,这是一个单一的解决方案,但你可以在这里改进:
var icon = {
url: 'icon.png',
size: new google.maps.Size(10, 10),
scaledSize: new google.maps.Size(10, 10),
anchor: new google.maps.Point(5, 5)
};
var iconMarker = new google.maps.Marker({
position: latLng,
map: map,
icon: icon
});
var size = RADIUS_SIZE / metersPerPixel(_gmap.getZoom() + 1);
icon.size = new google.maps.Size(size, size);
icon.scaledSize = new google.maps.Size(size, size);
icon.anchor = new google.maps.Point(size / 2, size / 2);
iconMarker.setMap(null);
iconMarker = new google.maps.Marker({
position: iconMarker.getPosition(),
map: map,
icon: icon
});
相关文章:
- 在标记mapbox.js上添加自定义图标
- 如何将自定义图标添加到 JqGrid 顶级工具栏按钮
- 如何在 Electron for OSX 中打包自定义图标
- 如何使用传单为传单实时插件设置自定义图标
- 传单错误:对象函数没有方法'createIcon'在LayerGroup中创建自定义图标标记时
- 带有Markercluster自定义图标样式的角形传单
- 如何在 ng 映射标记(角度)中使用自定义图标
- 我如何使谷歌地图不更改标记的自定义图标大小
- 自定义图标行为是否在JQueryMobile 1.4(Alpha / Beta / RC-1)中发生了变化
- 谷歌地图V3 - 如何将每个位置的标记更改为自定义图标
- 如何使用地图地点创建自定义图标.js
- 在视网膜显示中使用谷歌地图的自定义图标
- 使用缩放更改谷歌地图自定义图标
- 路线末端的自定义图标
- 带有自定义图标的谷歌地图标记定位
- 基于Openlayers 3中提取的数据应用自定义图标
- 如何在iPad上创建一个自定义图标'它基本上只是一个URL
- 单个集群图标的自定义图标
- 无法在手册中使用自定义图标
- 谷歌地图标记-为每个标记添加一个具有唯一标签的自定义图标