使用 gomap-plugin 隐藏/查看一组标记

发布于 2025-01-03 02:57:04 字数 2278 浏览 1 评论 0原文

我喜欢使用插件 gomap() 隐藏/查看地图中的一组标记,如下所示: http://www.pittss.lv/jquery/gomap/solutions/group.html

现在我只通过隐藏/查看一个标记来实现这一点:

$(function() { 
    $("#map_canvas").goMap({
        latitude: 46.839, 
        longitude: 9.285, 
        zoom: 15 ,
        scaleControl: true,
        maptype: 'ROADMAP',
        markers: [{  
            latitude: 46.839, 
            longitude: 9.285,  
            id: 'biketour1', 
            group: 'bike',
            icon: 'pic/Kategorien/icon_bike.png', 
            html: { 
                content: 'Das ist die Biketour1', 
                popup:false
            }
        },{ 
            ...
            } 
        }], 
    }); 
    });

$("#bike-check").click(function() {  
        $.goMap.showHideMarker('bike');  
    });

你能解释一下我如何实现隐藏/查看吗对于一个团体?我已经在课堂上尝试过了,但这不起作用......


更新:

$(".parentcheck").click(function() { 
var group = $(this).attr("id");

switch (group) {
    case "bike-check":
        showhidemarker("bike");
    break;
    case "event-check":
        //and so on
    break;
}
});



/*! show / hiding markergroup
    *
    * @ groupid Group id string
    * @ true  Optional boolean to set the visibility to a specific value. If omitted, markers will toggle.
*/
function showhidemarker(groupid){
    for (var i in $.goMap.markers) {
        $.goMap.showHideMarker($.goMap.markers[i], false); 
        console.log("it works");
    }
    $.goMap.showHideMarkerByGroup(groupid, true);
}

这里的html(通过单击复选框,标记应该可见或不可见)

...
    <ul>
      <li class="checkbox">
          <input id="bike-check" class="parentcheck" name="parentcheck" type="checkbox" checked="checked" value="Bike" />
          <p>Bike</p>
      </li>
      <li class="checkbox">
           <input id="event-check" class="parentcheck" type="checkbox" checked="checked" value="Events" />
           <p>Events</p>
       </li>
   </ul>
...

问题是,这个方法: $.goMap.showHideMarkerByGroup(groupid, true); 没有正常工作。

单击自行车的复选框后,事件中的标记就会消失 - 但单击自行车复选框后,自行车上的标记就会消失!

怎么了?

I like to hide/view a group of markers in a map with the plugin gomap() like here: http://www.pittss.lv/jquery/gomap/solutions/group.html

for now I realized it with hiding/viewing only one marker:

$(function() { 
    $("#map_canvas").goMap({
        latitude: 46.839, 
        longitude: 9.285, 
        zoom: 15 ,
        scaleControl: true,
        maptype: 'ROADMAP',
        markers: [{  
            latitude: 46.839, 
            longitude: 9.285,  
            id: 'biketour1', 
            group: 'bike',
            icon: 'pic/Kategorien/icon_bike.png', 
            html: { 
                content: 'Das ist die Biketour1', 
                popup:false
            }
        },{ 
            ...
            } 
        }], 
    }); 
    });

$("#bike-check").click(function() {  
        $.goMap.showHideMarker('bike');  
    });

Can you explain how I can realize the hiding/viewing for a group? I already tried it with class but this isn't working...

update:

$(".parentcheck").click(function() { 
var group = $(this).attr("id");

switch (group) {
    case "bike-check":
        showhidemarker("bike");
    break;
    case "event-check":
        //and so on
    break;
}
});



/*! show / hiding markergroup
    *
    * @ groupid Group id string
    * @ true  Optional boolean to set the visibility to a specific value. If omitted, markers will toggle.
*/
function showhidemarker(groupid){
    for (var i in $.goMap.markers) {
        $.goMap.showHideMarker($.goMap.markers[i], false); 
        console.log("it works");
    }
    $.goMap.showHideMarkerByGroup(groupid, true);
}

here the html (by clicking on the checkbox, the markers should be visible or not)

...
    <ul>
      <li class="checkbox">
          <input id="bike-check" class="parentcheck" name="parentcheck" type="checkbox" checked="checked" value="Bike" />
          <p>Bike</p>
      </li>
      <li class="checkbox">
           <input id="event-check" class="parentcheck" type="checkbox" checked="checked" value="Events" />
           <p>Events</p>
       </li>
   </ul>
...

the problem is, that this method: $.goMap.showHideMarkerByGroup(groupid, true);
is not working as it should.

The marker from event dissapears by clicking on the checkbox for the bike - but by clicking on checkbox bike the marker from bike should dissappear!

What is wrong?

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

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

发布评论

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

评论(3

弱骨蛰伏 2025-01-10 02:57:04

知道了 :)

var categories = {
        "bike-check": { 
            "groupID": "bike", 
            "isVisible": true
        },
        "event-check": {
            "groupID": "event", 
            "isVisible": true
        }
    };

$(".parentcheck").click(function() { 

    var id = $(this).attr("id");

    categories[ id ].isVisible = !categories[ id ].isVisible;
    showhidemarker( categories[ id ].groupID,categories[ id ].isVisible  );

});
function showhidemarker(groupid,show){
    $.goMap.showHideMarkerByGroup(groupid, show)
}

got it :)

var categories = {
        "bike-check": { 
            "groupID": "bike", 
            "isVisible": true
        },
        "event-check": {
            "groupID": "event", 
            "isVisible": true
        }
    };

$(".parentcheck").click(function() { 

    var id = $(this).attr("id");

    categories[ id ].isVisible = !categories[ id ].isVisible;
    showhidemarker( categories[ id ].groupID,categories[ id ].isVisible  );

});
function showhidemarker(groupid,show){
    $.goMap.showHideMarkerByGroup(groupid, show)
}
灼疼热情 2025-01-10 02:57:04

更简单的方法是隐藏所有内容并仅显示您需要的内容...GoMap 示例中的示例

for (var i in $.goMap.markers) {
    $.goMap.showHideMarker($.goMap.markers[i], false);
}
$.goMap.showHideMarkerByGroup(group, true);

Much easier is to hide all and only show the ones you need ... sample from the GoMap examples

for (var i in $.goMap.markers) {
    $.goMap.showHideMarker($.goMap.markers[i], false);
}
$.goMap.showHideMarkerByGroup(group, true);
浅听莫相离 2025-01-10 02:57:04

如果您使用复选框来显示/隐藏组,则可以这样做(假设复选框的 ID 为“NFLCheckbox”,组的名称为“NFLGroup”):

$("#NFLCheckbox").click(function () {
    if ($('#NFLCheckbox').is(':checked')) {
        $.goMap.showHideMarkerByGroup('NFLGroup', true)
    } else {
        $.goMap.showHideMarkerByGroup('NFLGroup', false)
    }
});

有关更多详细信息,我在这里写了一篇相关文章:http://www.codeproject.com/Articles/690045/How-to-Display-and-Hide-Marker-Groups-in-Google-Ma

If you use checkboxes to show/hide groups, you can do it this way (assuming the checkbox has the ID "NFLCheckbox" and the name of the group is "NFLGroup" here):

$("#NFLCheckbox").click(function () {
    if ($('#NFLCheckbox').is(':checked')) {
        $.goMap.showHideMarkerByGroup('NFLGroup', true)
    } else {
        $.goMap.showHideMarkerByGroup('NFLGroup', false)
    }
});

For more detail, I wrote an article about that here: http://www.codeproject.com/Articles/690045/How-to-Display-and-Hide-Marker-Groups-in-Google-Ma

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