Gmaps4Rails V2 setVisible
-
20-12-2019 - |
Вопрос
I think this should be easy but every thing I try does not work. What I want to do is add code that hides markers if a review parameter is set. Unfortunately with Gmaps4Rails V2 I'm having trouble with hiding all markers.
<script src="//maps.google.com/maps/api/js?v=3.13&sensor=false&libraries=geometry" type="text/javascript"></script>
<script src='//google-maps-utility-library-v3.googlecode.com/svn/tags/markerclustererplus/2.0.14/src/markerclusterer_packed.js' type='text/javascript'></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/gmaps4rails/2.1.2/gmaps4rails.js"></script>
</div>
<div style='width: 100%;'>
<div id="map" style='width: 100%; height: 400px;'></div>
</div>
<script type="text/javascript">
handler = Gmaps.build('Google');
handler.buildMap({ provider: {}, internal: {id: 'map'}}, function(){
if(navigator.geolocation)
navigator.geolocation.getCurrentPosition(displayOnMap);
markers = handler.addMarkers (<%=raw @hash.to_json %>);
handler.bounds.extendWith(markers);
handler.fitMapToBounds();
_.each(markers, function(index){
markers[index].hide();
});
function displayOnMap(position){
homepostion = handler.addMarker({
lat: position.coords.latitude,
lng: position.coords.longitude
});
handler.map.centerOn(homepostion);
};
});
</script>
As always thank you in advance
Решение
All markers you get from addMarker
have show
and hide
functions see code
If you use the clusterer, it's another story, take inspiration from the removeMarker function
Не связан с StackOverflow