开发者

How to clear specific marker with gmap3

开发者 https://www.devze.com 2023-04-08 05:52 出处:网络
I got a simple code that generate 10 different marker, actually i use : $(\"#test\").gmap3( {action:\'addMarker\', name:\'marker\', latLng: (my lat & lng value)},

I got a simple code that generate 10 different marker, actually i use :

$("#test").gmap3( {action:'addMarker', name:'marker', latLng: (my lat & lng value)}, ... (10 times) });

In order to clear my marker i user 开发者_如何转开发{action:'clear', name:'marker'} but it remove my all 10 markers!

How can i tell Gmap3 to remove a specific marker?

I have see i can add a tag to my marker like :

{action:'addMarker', name:'marker', latLng: (my lat & lng value), tag : "mytag"}

but then when i put :

{action:'clear', name:'marker', tag : "mytag"}

it doen't remove my specific tagged marker

any idea?

thank's a lot


Finally, i don't know why but Tag works perfectly well like this for exemple :

    `<script type="text/javascript">                

        $(function(){
            $("#putain").gmap3();
                $("#putain").gmap3({action:'addMarker', name:'marker', address: "paris", tag : "mytag-paris"});
                $("#putain").gmap3({action:'addMarker', name:'marker', address: "new york", tag : "mytag-newyork"});
                $("#putain").gmap3({action:'clear', name:'marker', tag:'mytag-paris'});         
        });

    </script>

`

in that case it remove specificaly the tagged "mytag-paris" marker and don't remove the tagged "tag-newyork" marker


I would expect if you gave each marker a unique name, then when you call the 'clear' action, using that unique name would remove just the one you want to.


I had a similar problem and utilizing your clue I found out what the issue was for me.

In my case the problem was in addMarker logic. In my case query:

{action:'addMarker', name:'marker', latLng: (my lat & lng value), tag : "mytag"}

worked perfectly.

However, when there was a map property in action, the gmap3 would fail to write tag to the marker. e.g:

{action:'addMarker', name:'marker',map:{center:true}, latLng: (my lat & lng value), tag : "mytag"}

In this case, gmap3 fails to copy the tag. I am not sure whether this is a bug or a feature.

This error happens within getObject() function.


It is an old post but in case someone is looking... I would simply use just the tag and leave out the name reference for removing one marker. Like this.

{action:'clear',tag:'my-tag-name'}
0

精彩评论

暂无评论...
验证码 换一张
取 消