alvarocavalcanti/gigantealerta — pull request #8 by josuelima (2014-06-18 02:18:00+00:00)
Title: Issue #2: fixes markers blinking when dragging the map

Why it happens: Every time the map is dragged ```load_markers()``` is called, and then ```clear_markers()```. It removes the markers from the map and then reloads everything again.

Solution: Don't clear the map and reload everything again. Instead, keep the current markers on the map and only add new ones.

Code: First, I created an identifier on each marker (for this I used the marker id adding it to the json response in the controller, and then linking it on the javascript marker object). Now every marker has an identifier. Then, I removed the ```clear_markers()``` call and added a verification to only push to the map markers that are not yet there (checking by its ids).

Now every time the map is dragged the reload function is called in order to look for new markers added, but not cleaning it and adding all the markers again.

PS.: another workaround could be comment ```load_markers()``` on ```onMapDragEnd()```, but by doing this new markers added by concurrent users would only appear when refreshing the entire page (F5).