简体   繁体   English

单击按钮时更改标记图像

[英]Change marker image when a button clicked

I'm using gMap2, and I'd like to change the marker image from "marker1.png" to "marker2.png" when a button is clicked . 我正在使用gMap2,并且想在单击按钮时将标记图像从“ marker1.png”更改为“ marker2.png”。 I have the following code: 我有以下代码:

// Declare the marker
var customMarker = "img/marker1.png";

// Initialize the map
$('#map').gMap({

    address: "Paris, France, cité Nollez 3.",
    zoom: 12,
    markers:[
        {
            address: "Paris, France, cité Nollez 3.",
            html: "_address"
        }
    ],
    icon: {
        image: customMarker, 
        iconsize: [61, 63],
        iconanchor: [12, 46]
    }

});

// Change marker image on button click
$("button").click(function(){
    customMarker === "img/marker2.png";
});

Here's the jsFiddle: http://jsfiddle.net/hrLga/ 这是jsFiddle: http : //jsfiddle.net/hrLga/

Thanks a lot! 非常感谢!

我相信您需要在customMarker更改后再次调用gMap。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM