使用jquery-ui-map ,我尝试使用个性化图标。 我这样工作得很好:
$("#gmap_" + parent).gmap('addMarker', {
"id": "marker-"+m.id,
'position': new google.maps.LatLng(m.lat, m.lon),
'bounds':true,
'icon': '/images/'+m.icon
})
因为我的图标只是一个网址。但我想将所有图标放入 Sprite 中,因此我必须设置其他选项:
$("#gmap_" + parent).gmap('addMarker', {
"id": "marker-"+m.id,
'position': new google.maps.LatLng(m.lat, m.lon),
'bounds':true,
'icon': new google.maps.MarkerImage( {
'url' : "http://crm.brunet.pro/images/markers.png",
'origin': new google.maps.Point(m.pos, 0),
'size' : new google.maps.Size(20, 34)
})
})
我收到此错误:
GET http://mysite.com/[object%20Object] 400 (Bad Request)
所以看起来图标选项只接受一个字符串。但你可以在api中看到它应该接受 MarkerImage 对象。
我做错了什么?
谢谢
最佳答案
MarkerImage 最多使用五个参数创建,例如 MarkerImage(myUrl, size1, point1, point2)
,但您已将其编写为一个对象参数。
我确实认为 API 文档在这种情况下可能会令人困惑。查看这些示例:
https://developers.google.com/maps/documentation/javascript/overlays#ComplexIcons
var image = new google.maps.MarkerImage('images/beachflag.png',
// This marker is 20 pixels wide by 32 pixels tall.
new google.maps.Size(20, 32),
// The origin for this image is 0,0.
new google.maps.Point(0,0),
// The anchor for this image is the base of the flagpole at 0,32.
new google.maps.Point(0, 32));
http://blog.mridey.com/2010/03/using-markerimage-in-maps-javascript.html (解释从 Sprite 表加载)
大小、原点、 anchor
未提及,但您确实需要遵守 API 文档中给出的顺序。
关于jquery - 如何通过 jquery-ui-map 使用个性化图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10884030/