Set marker coordinates as map center when map location fields has valid coordinates
When a user recovers a page from browser history where placed a marker in different map pane (visible map layer) marker was successfully added to the map but the map center is the one defined at Settings map properties so the marker was not visible to the user. Now when map_location form has valid coordinates we use them instead of default map center settings. This will avoid the user to have to rellocate the marker (or find the correct pane where the marker was added) if already placed.
This commit is contained in:
@@ -20,14 +20,12 @@
|
||||
App.Map.maps = [];
|
||||
},
|
||||
initializeMap: function(element) {
|
||||
var addMarkerInvestments, clearFormfields, createMarker, editable, formCoordinates, getPopupContent,
|
||||
latitudeInputSelector, longitudeInputSelector, map, mapAttribution, mapCenterLatLng,
|
||||
var addMarkerInvestments, clearFormfields, createMarker, dataCoordinates, editable, formCoordinates,
|
||||
getPopupContent, latitudeInputSelector, longitudeInputSelector, map, mapAttribution, mapCenterLatLng,
|
||||
mapCenterLatitude, mapCenterLongitude, mapTilesProvider, marker, markerIcon, markerLatitude,
|
||||
markerLongitude, moveOrPlaceMarker, openMarkerPopup, removeMarker, removeMarkerSelector,
|
||||
updateFormfields, zoom, zoomInputSelector;
|
||||
App.Map.cleanInvestmentCoordinates(element);
|
||||
mapCenterLatitude = $(element).data("map-center-latitude");
|
||||
mapCenterLongitude = $(element).data("map-center-longitude");
|
||||
mapTilesProvider = $(element).data("map-tiles-provider");
|
||||
mapAttribution = $(element).data("map-tiles-provider-attribution");
|
||||
latitudeInputSelector = $(element).data("latitude-input-selector");
|
||||
@@ -38,12 +36,23 @@
|
||||
long: $(longitudeInputSelector).val(),
|
||||
zoom: $(zoomInputSelector).val()
|
||||
};
|
||||
dataCoordinates = {
|
||||
lat: $(element).data("marker-latitude"),
|
||||
long: $(element).data("marker-longitude")
|
||||
};
|
||||
if (App.Map.validCoordinates(formCoordinates)) {
|
||||
markerLatitude = formCoordinates.lat;
|
||||
markerLongitude = formCoordinates.long;
|
||||
mapCenterLatitude = formCoordinates.lat;
|
||||
mapCenterLongitude = formCoordinates.long;
|
||||
} else if (App.Map.validCoordinates(dataCoordinates)) {
|
||||
markerLatitude = dataCoordinates.lat;
|
||||
markerLongitude = dataCoordinates.long;
|
||||
mapCenterLatitude = dataCoordinates.lat;
|
||||
mapCenterLongitude = dataCoordinates.lat;
|
||||
} else {
|
||||
markerLatitude = $(element).data("marker-latitude");
|
||||
markerLongitude = $(element).data("marker-longitude");
|
||||
mapCenterLatitude = $(element).data("map-center-latitude");
|
||||
mapCenterLongitude = $(element).data("map-center-longitude");
|
||||
}
|
||||
if (App.Map.validZoom(formCoordinates.zoom)) {
|
||||
zoom = formCoordinates.zoom;
|
||||
|
||||
@@ -134,6 +134,38 @@ shared_examples "mappable" do |mappable_factory_name, mappable_association_name,
|
||||
expect(page.execute_script("return App.Map.maps[0].getZoom();")).to eq(11)
|
||||
end
|
||||
end
|
||||
|
||||
scenario "shows marker at map center", :js do
|
||||
do_login_for user
|
||||
visit send(mappable_new_path, arguments)
|
||||
|
||||
within ".map_location" do
|
||||
expect(page).not_to have_css(".map-icon")
|
||||
end
|
||||
|
||||
place_map_at(-68.592487, -62.391357)
|
||||
find("#new_map_location").click
|
||||
|
||||
within ".map_location" do
|
||||
expect(page).to have_css(".map-icon")
|
||||
end
|
||||
|
||||
if management
|
||||
click_link "Select user"
|
||||
|
||||
expect(page).to have_content "User management"
|
||||
else
|
||||
click_link "Help"
|
||||
|
||||
expect(page).to have_content "CONSUL is a platform for citizen participation"
|
||||
end
|
||||
|
||||
go_back
|
||||
|
||||
within ".map_location" do
|
||||
expect(page).to have_css(".map-icon")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
scenario "Skip map", :js do
|
||||
@@ -335,3 +367,11 @@ def map_zoom_in
|
||||
sleep 0.01
|
||||
end
|
||||
end
|
||||
|
||||
def place_map_at(latitude, longitude)
|
||||
page.execute_script("App.Map.maps[0].setView(new L.LatLng(#{latitude}, #{longitude}))")
|
||||
|
||||
until page.execute_script("return App.Map.maps[0].getCenter().lat === #{latitude};") do
|
||||
sleep 0.01
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user