更新 Google 地图标记中的 MarkerImage sprite 原点 (v3)
我想动态更新由 Google Maps API v3 中的 MarkerImage 构造函数生成的精灵的“原点”点,并且想知道是否可以在不完全生成新的 MarkerImage 的情况下实现这一点。
这是一些代码:
// Marker options
var markerOptions = {
icon: new google.maps.MarkerImage('../images/content/marker.png',
new google.maps.Size(88,88),
new google.maps.Point(0,0),
new google.maps.Point(44,88)
),
position: position,
map: map
}
var marker = new google.maps.Marker(markerOptions);
我可以按照marker.setPoint(0,10)的方式做一些事情,还是需要创建一个新的MarkerImage只是为了再次设置精灵原点?
I want to dynamically update the "origin" point of a sprite generated by the MarkerImage constructor in Google Maps API v3, and am wondering if that's possible without generating a new MarkerImage entirely.
Here's some code:
// Marker options
var markerOptions = {
icon: new google.maps.MarkerImage('../images/content/marker.png',
new google.maps.Size(88,88),
new google.maps.Point(0,0),
new google.maps.Point(44,88)
),
position: position,
map: map
}
var marker = new google.maps.Marker(markerOptions);
Can I do something along the lines of marker.setPoint(0,10) or do I need to create a new MarkerImage just to set the sprite origin again?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当在地图上绘制 MarkerImage 时,最快的方法是:
When the MarkerImage is draw on the map the quickest way to do that is :
您可以设置标记图标的原点属性。在您的示例中:
以下内容也适用:
You can set the origin property of the marker's icon. In your example:
The following also works:
创建 MarkerImage 后,无法更改其属性(至少根据 API 参考)。您可以创建一个新的 MarkerImage 并调用
marker.setIcon()
。There is no way (at least according to the API reference) to alter the properties of a MarkerImage after it has been created. You can create a new MarkerImage and call
marker.setIcon()
.