gmaps4rails显示隐藏功能

编程入门 行业动态 更新时间:2024-10-27 20:29:39
本文介绍了gmaps4rails显示隐藏功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我希望对gmaps4rails中的显示/隐藏功能有一点了解。

I'm hoping to get a little bit of insight on show / hide functionality in gmaps4rails.

示例功能

// == shows all markers of a particular category, and ensures the checkbox is checked == function show(category) { for (var i=0; i<gmarkers.length; i++) { if (gmarkers[i].mycategory == category) { gmarkers[i].setVisible(true); } } // == check the checkbox == document.getElementById(category+"box").checked = true; } // == hides all markers of a particular category, and ensures the checkbox is cleared == function hide(category) { for (var i=0; i<gmarkers.length; i++) { if (gmarkers[i].mycategory == category) { gmarkers[i].setVisible(false); } } // == clear the checkbox == document.getElementById(category+"box").checked = false; // == close the info window, in case its open on a marker that we just hid infowindow.close(); } // == a checkbox has been clicked == function boxclick(box,category) { if (box.checked) { show(category); } else { hide(category); } // == rebuild the side bar makeSidebar(); } function myclick(i) { google.maps.event.trigger(gmarkers[i],"click"); } // == rebuilds the sidebar to match the markers currently displayed == function makeSidebar() { var html = ""; for (var i=0; i<gmarkers.length; i++) { if (gmarkers[i].getVisible()) { html += '<a href="javascript:myclick(' + i + ')">' + gmarkers[i].myname + '<\/a><br>'; } } document.getElementById("side_bar").innerHTML = html; }

所以,在我的控制器中,我构建了一个标记列表,包括其类别为json。

So, in my controller, I'm building a list of markers, and including their categories as json.

@markersLoc = @locSearch.to_gmaps4rails do |loc, marker| letter.next! marker_image = "chart.apis.google/chart?chst=d_map_pin_letter&chld=#{letter}|82ABDD|000000" marker.infowindow render_to_string(partial: '/events/info', locals: {object: loc}) marker.picture({picture: marker_image, width: 32, height: 32, marker_anchor: [11,30], shadow_picture: "chart.apis.google/chart?chst=d_map_pin_shadow", shadow_width: 110, shadow_height: 110, shadow_anchor: [12,34]}) marker.title loc.what marker.sidebar render_to_string(partial: '/events/sidebar', locals: {object: loc, letter: marker_image}) marker.json({cat: loc.category}) end

我有点卡住了,在这里。我知道:cat 字符串可用(例如:1,3,4),但我不确定如何使用它来实现我之后的操作。 / p>

I'm kind of stuck, here. I know the :cat string is available (ex: 1,3,4), but I'm not sure how to use it to achieve what I'm after.

推荐答案

几乎可以使用那里的内容,并做了一些修改。这给了我9个类别的功能(可以更多或更少),并只查看我想要的。真棒。

Was able to pretty much use what was there, with some modification. This gave me functionality to have 9 categories (could be more or less), and only view what I want. Awesome.

// == shows all markers of a particular category, and ensures the checkbox is checked == function show(category) { var regEx = new RegExp("[" + category + "]") for (var i=0; i<Gmaps.map.markers.length; i++) { if (Gmaps.map.markers[i].cat) { if (Gmaps.map.markers[i].cat.match(regEx)) { Gmaps.map.showMarker(Gmaps.map.markers[i]); } } } // == check the checkbox == document.getElementById(category+"box").checked = true; } // == hides all markers of a particular category, and ensures the checkbox is cleared == function hide(category) { var regEx = new RegExp("[" + category + "]") for (var i=0; i<Gmaps.map.markers.length; i++) { if (Gmaps.map.markers[i].cat) { if (Gmaps.map.markers[i].cat.match(regEx)) { Gmaps.map.hideMarker(Gmaps.map.markers[i]); } } } // == clear the checkbox == document.getElementById(category+"box").checked = false; // == close the info window, in case its open on a marker that we just hid // Gmaps.map.infowindow.close(); } // == a checkbox has been clicked == function boxclick(box,category) { if (box.checked) { show(category); } else { hide(category); } }

更多推荐

gmaps4rails显示隐藏功能

本文发布于:2023-08-02 00:09:23,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1272927.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:功能   gmaps4rails

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!