I have a function responsible for hiding/showing markers, so I decided to use removeMarkers() and addMarkers() with a variable which contains all markers displayed on map, preventing AJAX requests. However, removeMarkers() appears to not working when used after addMarkers() function:
#/assets/javascript/general.js.coffee
@buildMap = (markers)->
provider = Gmaps.build(
'Google',
{
builders: { Marker: RichMarkerBuilder},
markers:
clusterer:
gridSize: 50
styles: [
url: "/assets/cluster.png"
textSize: 15
width: 56
height: 56
]
}
)
Gmaps.handler = @clustereredHandler()
Gmaps.handler.buildMap {
provider: provider,
internal: {id: 'map'} }, ->
Gmaps.markers = _.map(markers, (marker_json) ->
marker = Gmaps.handler.addMarker(marker_json)
_.extend marker, marker_json
marker
)
Gmaps.map = Gmaps.handler.getMap()
Gmaps.handler.bounds.extendWith(Gmaps.markers)
Gmaps.handler.fitMapToBounds()
#app/views/stores/index.html.erb
buildMap(<%=raw @hash.to_json %>);
So, I have:
- Handler on
Gmaps.handlervariable; - All markers on
Gmaps.markersvariable; - Map on
Gmaps.mapvariable.
Steps to failure:
- Load map - OK (All markers loaded correctly);
- >
Gmaps.handler.removeMarkers(Gmaps.markers)- OK (All markers hidden correctly); - >
Gmaps.handler.addMarkers(Gmaps.markers)- OK (All markers shown correctly); - >
Gmaps.handler.removeMarkers(Gmaps.markers)- FAILURE! (Markers still being displayed);
I'm using 2.1.2version. Is there any fix for it?
Thanks
According to my plunkr here, there is no bug with gmaps4rails.
I feel like you have an issue with your own functions (maybe dont use extend?) and replace with:
I cant tell much more since they are not included.