【发布时间】:2011-10-12 06:48:24
【问题描述】:
我正在使用 Google Maps API (v3),但遇到了标记图标问题。我正在尝试根据标记的各个数据属性来改变标记的大小。
图标本身位于一个包含三个不同圆形标记的精灵中,每个标记为 16 像素 x 16 像素。我正在尝试缩放单个图标,但到目前为止还没有成功。
这是我的代码:
var offset = Math.floor(Math.random() * 3) * 16; // pick one of the three icons in the sprite
// Calculate desired pixel-size of the marker
var size = Math.floor(4*(count-1) + 8);
// Create custom marker
var marker = new google.maps.Marker({
position: new google.maps.LatLng(lat, lng),
icon: new google.maps.MarkerImage(
'img/dot.png', // my sprite with 3 circular icons
new google.maps.Size(16, 16), // 16x16 is the original size of each individual icon
new google.maps.Point(0, offset), // picking one of the three icons in the sprite
new google.maps.Point(Math.floor(size/2), Math.floor(size/2)), // setting correct anchor for the marker
new google.maps.Size(size, size) // trying to scale the marker
)
});
问题似乎出在最后一行,我试图将标记图标缩放到所需的大小。我没有正确缩放,而是得到了一个奇怪的、扭曲的椭圆形图标。
我做错了什么?
【问题讨论】:
-
这已被弃用。请参阅developers.google.com/maps/documentation/javascript/overlays上的“将 MarkerImage 对象转换为类型图标”
标签: javascript image google-maps google-maps-api-3 gis