Skip invalid map markers
Why: Sometimes the latitude or longitude it passed to the map as ********* instead of the actual latitude or longitud. The asterisks are not a string, breaking the whole array https://github.com/consul/consul/issues/2380 What: This commits skips invalid markers and displays the rest How: - Substituting the mysterious asterisks for null (cleanInvestmentCoordinates) - Validating the coordinates are numbers before trying to pain them(validCoordinates) - Adding a numeric function to validate the latitude and longitude (isNumeric) https://stackoverflow.com/questions/9716468/is-there-any-function-like-i snumeric-in-javascript-to-validate-numbers#answer-9716488
This commit is contained in:
@@ -12,6 +12,7 @@ App.Map =
|
||||
App.Map.toogleMap()
|
||||
|
||||
initializeMap: (element) ->
|
||||
App.Map.cleanInvestmentCoordinates(element)
|
||||
|
||||
mapCenterLatitude = $(element).data('map-center-latitude')
|
||||
mapCenterLongitude = $(element).data('map-center-longitude')
|
||||
@@ -102,7 +103,21 @@ App.Map =
|
||||
marker.options['id'] = i.investment_id
|
||||
|
||||
marker.on 'click', openMarkerPopup
|
||||
add_marker=createMarker(i.lat , i.long)
|
||||
add_marker.bindPopup(contentPopup(i.investment_title, i.investment_id, i.budget_id))
|
||||
|
||||
toogleMap: ->
|
||||
$('.map').toggle()
|
||||
$('.js-location-map-remove-marker').toggle()
|
||||
|
||||
cleanInvestmentCoordinates: (element) ->
|
||||
markers = $(element).attr('data-marker-investments-coordinates')
|
||||
if markers?
|
||||
clean_markers = markers.replace(/-?(\*+)/g, null)
|
||||
$(element).attr('data-marker-investments-coordinates', clean_markers)
|
||||
|
||||
validCoordinates: (coordinates) ->
|
||||
App.Map.isNumeric(coordinates.lat) && App.Map.isNumeric(coordinates.long)
|
||||
|
||||
isNumeric: (n) ->
|
||||
!isNaN(parseFloat(n)) && isFinite(n)
|
||||
|
||||
Reference in New Issue
Block a user