Mapstraction:添加图标后更改其图像 URL?

发布于 2024-08-30 18:33:45 字数 1895 浏览 2 评论 0原文

我正在尝试使用 marker.setIcon() 来更改标记图像。然而,尽管这更改了 marker.iconUrl 属性,但图标本身正在使用 marker.proprietary_marker.$.icon.image 来显示标记图像 - 因此标记图标保持不变。有没有办法动态更改marker.proprietary_marker.$.icon.image

  1. 添加标记。
  2. 检查图标的图像网址和专有图标的图像 - 它们是相同的。
  3. 更改图标。
  4. 再次检查 URL。现在图标 URL 已更改,但标记仍然显示专有标记对象中的旧图像。

 <head>
<title>Map Test</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=Your-Google-API-Key" type="text/javascript"></script>
<script src="mapstraction.js"></script>

<script type="text/javascript">
var map;
var marker;

function getMap(){
        map = new mxn.Mapstraction('myMap','google');
    map.setCenterAndZoom(new mxn.LatLonPoint(45.559242,-122.636467), 15);
}


function addMarker(){
        marker = new mxn.Marker(new mxn.LatLonPoint(45.559242, -122.636467));
    marker.addData({infoBubble : "Text", label : "Label",  marker : 4, icon: "http://mapscripting.com/examples/mashups/richter-high.png"});
    map.addMarker(marker);
}

function changeIcon(){
    marker.setIcon("http://assets1.mapufacture.com/images/markers/usgs_marker.png");
}


function showIconURL(){
        alert(marker.iconUrl);
} 


function showProprietaryIconURL(){
    alert(marker.proprietary_marker.$.icon.image);
}

</script>
</head>
<body onload="getMap()">
<div id="myMap" style="width:627px; height:412px;"></div>
<div>
    <input type="button" value="add marker" OnClick="addMarker();">
    <input type="button" value="change icon" OnClick="changeIcon();">
    <input type="button" value="show icon URL" OnClick="showIconURL();">
    <input type="button" value="show proprierty icon URL " OnClick="showProprietaryIconURL();">
</div>
</body>
</html>

I am trying to use marker.setIcon() to change a markers image. However it appears that although this changes the marker.iconUrl attribute the icon itself is using marker.proprietary_marker.$.icon.image to display the markers image - so the markers icon remains unchanged. Is there a way to dynamically change the marker.proprietary_marker.$.icon.image?

  1. Add a marker.
  2. Check the icon's image url and the proprietary icon's image - they're the same.
  3. Change the icon.
  4. Again check the Urls. Now the Icon Url has changed but the marker still shows the old image which is in the proprietary marker object.
 <head>
<title>Map Test</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=Your-Google-API-Key" type="text/javascript"></script>
<script src="mapstraction.js"></script>

<script type="text/javascript">
var map;
var marker;

function getMap(){
        map = new mxn.Mapstraction('myMap','google');
    map.setCenterAndZoom(new mxn.LatLonPoint(45.559242,-122.636467), 15);
}


function addMarker(){
        marker = new mxn.Marker(new mxn.LatLonPoint(45.559242, -122.636467));
    marker.addData({infoBubble : "Text", label : "Label",  marker : 4, icon: "http://mapscripting.com/examples/mashups/richter-high.png"});
    map.addMarker(marker);
}

function changeIcon(){
    marker.setIcon("http://assets1.mapufacture.com/images/markers/usgs_marker.png");
}


function showIconURL(){
        alert(marker.iconUrl);
} 


function showProprietaryIconURL(){
    alert(marker.proprietary_marker.$.icon.image);
}

</script>
</head>
<body onload="getMap()">
<div id="myMap" style="width:627px; height:412px;"></div>
<div>
    <input type="button" value="add marker" OnClick="addMarker();">
    <input type="button" value="change icon" OnClick="changeIcon();">
    <input type="button" value="show icon URL" OnClick="showIconURL();">
    <input type="button" value="show proprierty icon URL " OnClick="showProprietaryIconURL();">
</div>
</body>
</html>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

江挽川 2024-09-06 18:33:45

据我所知,一旦您创建了标记,您就无法再更改标记的“图标”。您可以更改标记本身的图像属性,但从我所读到的内容来看,我不认为一旦生成标记就可以通过图标选项更改它。

我还相信我读到,如果您确实更改了图标的图像,它将保持您最初在标记选项的图标设置中设置的相同大小属性。 IE 如果第一个图像设置为 15x15,第二个图像设置为 5x5,则 5x5 将调整大小为 15x15。

It was to my understanding from what I have read that once you create a marker you can no longer change the "icon" of the marker. You can change the image property of the marker itself but from what I have read I don't believe that it is possible to change it through the icon options once the marker has been generated.

I also believe I read that if you do change the image of the icon it will maintain the same size properties that you originally set in your icon settings for the marker options. IE if the first image was set to a 15x15 and the second is a 5x5 the 5x5 will be resized to the 15x15.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文