jbdemonte / gmap3

jQuery plugin to create Google maps
http://gmap3.net
668 stars 198 forks source link

Can't remove a single marker #153

Open adam-jones-net opened 4 years ago

adam-jones-net commented 4 years ago

I have setup some maps with popup info windows and that works fine. However now that I need to interact with existing markers I am having trouble. I've seen very brief explanations of how to use setMap(null) but they haven't helped me.

Can someone clarify with a fuller example? My setup code is as follows...

var infoWindows = [];
var locations=[
    {id:'marker1', position:[51.528308,-0.3817765],content:'test content',icon:'assets/mappointer.png'}
]
var map=$('#mapDiv').gmap3({
    mapTypeId: "teststyle",
    scrollwheel: true
})
.marker(locations)
.infowindow(locations)
.then(function (infowindow) {
    // handle click events for each marker
    var map = this.get(0);
    var marker = this.get(1);
    marker.forEach(function(item,i){
        item.addListener('click', function() {
            infowindow[i].open(map, item);
            infoWindows.push(infowindow[i]);
        });
    })
})
.styledmaptype("teststyle",mapStyle)
.fit();