gpt4 book ai didi

javascript - 在谷歌地图V3中打开图像?

转载 作者:行者123 更新时间:2023-11-28 10:24:57 25 4
gpt4 key购买 nike

我需要有关 google map v3 中 JavaScript 的帮助 我有一张图像,我需要能够转动它。这可行,但真正的问题是我无法影响标记,因为我不知道如何调用它并修改该标记。我向您展示了部分代码:

标记:

sURL    =  'http://www.sl2o.com/tc/picture/Fleche.PNG';
iWidth = 97;
iHeight = 100;

mImage = new google.maps.MarkerImage(sURL, new google.maps.Size(iWidth,iHeight), new google.maps.Point(0,0), new google.maps.Point(Math.round(iWidth/2),Math.round(iHeight/2)));

var oMarker = new google.maps.Marker({
'position': new google.maps.LatLng(iStartLat,iStartLon),
'map': map,
'title': 'mon point',
'icon': mImage
});

然后我有这个:

onload=function(){ 
rotate.call(document.getElementById('im'),50);
}
</script>
<img id="im" src="http://www.sl2o.com/tc/picture/Fleche.PNG" width="97" height="100" />

所以就是这样。正如您所看到的,我正在影响该图像,实际上我需要影响标记。我该怎么做 ?拜托,我需要这个,我已经工作了好几个小时了。谢谢!!

最佳答案

不幸的是,Google Maps API 没有提供任何访问 img 元素的方法(我已经查找了很多次)。 img 元素混合在 DOM 树中,因此是可搜索的。即:

var imgElements = document.getElementsByTagName('img'),
i = 0;
for (i = 0; i < imgElements.length; i+= 1) {
if (imgElements[i].src === 'http://www.sl2o.com/tc/picture/Fleche.PNG') {
rotate.call(imgElements[i], 50);
}
}

这会将所有 img-elments 转换为指定的 src,您可以向 if 语句添加更多条件以使其更加具体。

但这通常不是一个好的解决方案,因为通常有更多的标记具有相同的 img src。

我会制作多个图像并在 Photoshop(或任何其他图像处理工具)中旋转它们,然后为您要使用的每个变体创建一个新的 MarkerImage。并使用 .setIcon() 更改标记的图像。即:

oMarker.setIcon(mImage);

..弗雷德里克

关于javascript - 在谷歌地图V3中打开图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4644835/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com