Don't overwrite marker when creating investment markers
The `marker` variable is like a global variable inside the `initializeMap` function, so assigning it inside the `createMarker` function was changing its value in other places. So we're using different variable names like `newMarker` in order to make the code easier to follow. Now we "only" change the `marker` variable in functions that modify the marker.
This commit is contained in:
@@ -29,19 +29,19 @@
|
|||||||
html: '<div class="map-icon"></div>'
|
html: '<div class="map-icon"></div>'
|
||||||
});
|
});
|
||||||
createMarker = function(latitude, longitude) {
|
createMarker = function(latitude, longitude) {
|
||||||
var markerLatLng;
|
var newMarker, markerLatLng;
|
||||||
markerLatLng = new L.LatLng(latitude, longitude);
|
markerLatLng = new L.LatLng(latitude, longitude);
|
||||||
marker = L.marker(markerLatLng, {
|
newMarker = L.marker(markerLatLng, {
|
||||||
icon: markerIcon,
|
icon: markerIcon,
|
||||||
draggable: editable
|
draggable: editable
|
||||||
});
|
});
|
||||||
if (editable) {
|
if (editable) {
|
||||||
marker.on("dragend", function() {
|
newMarker.on("dragend", function() {
|
||||||
App.Map.updateFormfields(map, marker);
|
App.Map.updateFormfields(map, newMarker);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
marker.addTo(map);
|
newMarker.addTo(map);
|
||||||
return marker;
|
return newMarker;
|
||||||
};
|
};
|
||||||
removeMarker = function(e) {
|
removeMarker = function(e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
@@ -79,10 +79,12 @@
|
|||||||
}
|
}
|
||||||
if (addMarkerInvestments) {
|
if (addMarkerInvestments) {
|
||||||
addMarkerInvestments.forEach(function(coordinates) {
|
addMarkerInvestments.forEach(function(coordinates) {
|
||||||
|
var investmentMarker;
|
||||||
|
|
||||||
if (App.Map.validCoordinates(coordinates)) {
|
if (App.Map.validCoordinates(coordinates)) {
|
||||||
marker = createMarker(coordinates.lat, coordinates.long);
|
investmentMarker = createMarker(coordinates.lat, coordinates.long);
|
||||||
marker.options.id = coordinates.investment_id;
|
investmentMarker.options.id = coordinates.investment_id;
|
||||||
marker.on("click", App.Map.openMarkerPopup);
|
investmentMarker.on("click", App.Map.openMarkerPopup);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user