Add map locations helper. Allow to configure map marker edition on map instantiation at views.
This commit is contained in:
@@ -8,16 +8,17 @@ App.Map =
|
|||||||
App.Map.initializeMap map
|
App.Map.initializeMap map
|
||||||
|
|
||||||
initializeMap: (element) ->
|
initializeMap: (element) ->
|
||||||
latitude = $(element).data('latitude')
|
latitude = $(element).data('marker-latitude')
|
||||||
longitude = $(element).data('longitude')
|
longitude = $(element).data('marker-longitude')
|
||||||
zoom = $(element).data('zoom')
|
zoom = $(element).data('map-zoom')
|
||||||
mapTilesProvider = $(element).data('tiles-provider')
|
mapTilesProvider = $(element).data('map-tiles-provider')
|
||||||
mapAttributionSelector = $(element).data('tiles-attribution-selector')
|
mapAttributionSelector = $(element).data('map-tiles-attribution-selector')
|
||||||
latitudeInputSelector = $(element).data('latitude-input-selector')
|
latitudeInputSelector = $(element).data('latitude-input-selector')
|
||||||
longitudeInputSelector = $(element).data('longitude-input-selector')
|
longitudeInputSelector = $(element).data('longitude-input-selector')
|
||||||
zoomInputSelector = $(element).data('zoom-input-selector')
|
zoomInputSelector = $(element).data('zoom-input-selector')
|
||||||
removeMarkerSelector = $(element).data('remove-marker-selector')
|
removeMarkerSelector = $(element).data('marker-remove-selector')
|
||||||
attribution = $(mapAttributionSelector)
|
attribution = $(mapAttributionSelector)
|
||||||
|
editable = $(element).data('marker-editable')
|
||||||
marker_icon = L.divIcon(
|
marker_icon = L.divIcon(
|
||||||
iconSize: null
|
iconSize: null
|
||||||
html: '<div class="map-marker"></div>')
|
html: '<div class="map-marker"></div>')
|
||||||
@@ -48,10 +49,11 @@ App.Map =
|
|||||||
|
|
||||||
latLng = new (L.LatLng)(latitude, longitude)
|
latLng = new (L.LatLng)(latitude, longitude)
|
||||||
map = L.map(element.id).setView(latLng, zoom)
|
map = L.map(element.id).setView(latLng, zoom)
|
||||||
marker = L.marker(latLng, { icon: marker_icon, draggable: 'true' })
|
marker = L.marker(latLng, { icon: marker_icon, draggable: editable })
|
||||||
L.tileLayer(mapTilesProvider, attribution: attribution.html()).addTo map
|
L.tileLayer(mapTilesProvider, attribution: attribution.html()).addTo map
|
||||||
marker.addTo(map)
|
marker.addTo(map)
|
||||||
|
|
||||||
|
if editable
|
||||||
$(removeMarkerSelector).on 'click', removeMarker
|
$(removeMarkerSelector).on 'click', removeMarker
|
||||||
marker.on 'dragend', updateFormfields
|
marker.on 'dragend', updateFormfields
|
||||||
map.on 'zoomend', updateFormfields
|
map.on 'zoomend', updateFormfields
|
||||||
|
|||||||
19
app/helpers/map_locations_helper.rb
Normal file
19
app/helpers/map_locations_helper.rb
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
module MapLocationsHelper
|
||||||
|
|
||||||
|
def map_location_latitude(map_location)
|
||||||
|
map_location.present? && map_location.latitude.present? ? map_location.latitude : Setting["map.latitude"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def map_location_longitude(map_location)
|
||||||
|
map_location.present? && map_location.longitude.present? ? map_location.longitude : Setting["map.longitude"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def map_location_zoom(map_location)
|
||||||
|
map_location.present? && map_location.zoom.present? ? map_location.zoom : Setting["map.zoom"]
|
||||||
|
end
|
||||||
|
|
||||||
|
def map_location_input_id(prefix, attribute)
|
||||||
|
"#{prefix}_map_location_attributes_#{attribute}"
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -35,8 +35,9 @@
|
|||||||
<%= render 'map_locations/form_fields',
|
<%= render 'map_locations/form_fields',
|
||||||
form: f,
|
form: f,
|
||||||
map_location: @investment.map_location || MapLocation.new,
|
map_location: @investment.map_location || MapLocation.new,
|
||||||
label: t("proposals.form.map_location"),
|
label: t("budgets.investments.form.map_location"),
|
||||||
help: t("proposals.form.map_location_instructions"),
|
help: t("budgets.investments.form.map_location_instructions"),
|
||||||
|
remove_marker_label: t("budgets.investments.form.map_remove_marker"),
|
||||||
parent_class: "budget_investment" %>
|
parent_class: "budget_investment" %>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,25 +1,34 @@
|
|||||||
<%= form.label :map_location, label %>
|
<%= form.label :map_location, label %>
|
||||||
<p class="help-text" id="tag-list-help-text"><%= help %></p>
|
<p class="help-text" id="tag-list-help-text"><%= help %></p>
|
||||||
<div id="location-map" class="map" data-map
|
|
||||||
data-latitude="<%= map_location.present? && map_location.latitude.present? ? map_location.latitude : Setting["map.latitude"] %>"
|
<div class="map"
|
||||||
data-longitude="<%= map_location.present? && map_location.longitude.present? ? map_location.longitude : Setting["map.longitude"] %>"
|
data-map
|
||||||
data-zoom="<%= map_location.present? && map_location.zoom.present? ? map_location.zoom : Setting["map.zoom"] %>"
|
data-map-zoom="<%= map_location_zoom(map_location) %>"
|
||||||
data-tiles-attribution-selector="#map-location-attribution"
|
data-map-tiles-attribution-selector="#map-location-attribution"
|
||||||
data-tiles-provider="//{s}.tile.osm.org/{z}/{x}/{y}.png"
|
data-map-tiles-provider="//{s}.tile.osm.org/{z}/{x}/{y}.png"
|
||||||
data-latitude-input-selector="#<%= parent_class %>_map_location_attributes_latitude"
|
data-marker-editable="true"
|
||||||
data-longitude-input-selector="#<%= parent_class %>_map_location_attributes_longitude"
|
data-marker-latitude="<%= map_location_latitude(map_location) %>"
|
||||||
data-zoom-input-selector="#<%= parent_class %>_map_location_attributes_zoom"
|
data-marker-longitude="<%= map_location_longitude(map_location) %>"
|
||||||
data-remove-marker-selector=".location-map-remove-marker-button">
|
data-marker-remove-selector=".location-map-remove-marker-button"
|
||||||
|
data-latitude-input-selector="#<%= map_location_input_id(parent_class, 'latitude') %>"
|
||||||
|
data-longitude-input-selector="#<%= map_location_input_id(parent_class, 'longitude') %>"
|
||||||
|
data-zoom-input-selector="#<%= map_location_input_id(parent_class, 'zoom') %>">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="map-location-attribution" class="map-attributtion">
|
<div id="map-location-attribution" class="map-attributtion">
|
||||||
© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors
|
© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<a class="location-map-remove-marker-button" href="#">Remove marker</a>
|
<a class="location-map-remove-marker-button" href="#"><%= remove_marker_label %></a>
|
||||||
|
|
||||||
<%= form.fields_for :map_location, map_location do |map_location_fields| %>
|
<%= form.fields_for :map_location, map_location do |m_l_fields| %>
|
||||||
<%= map_location_fields.hidden_field :latitude, value: map_location.latitude, id: "#{parent_class}_map_location_attributes_latitude" %>
|
<%= m_l_fields.hidden_field :latitude,
|
||||||
<%= map_location_fields.hidden_field :longitude, value: map_location.longitude, id: "#{parent_class}_map_location_attributes_longitude" %>
|
value: map_location.latitude,
|
||||||
<%= map_location_fields.hidden_field :zoom, value: map_location.zoom, id: "#{parent_class}_map_location_attributes_zoom" %>
|
id: map_location_input_id(parent_class, 'latitude') %>
|
||||||
|
<%= m_l_fields.hidden_field :longitude,
|
||||||
|
value: map_location.longitude,
|
||||||
|
id: map_location_input_id(parent_class, 'latitude') %>
|
||||||
|
<%= m_l_fields.hidden_field :zoom,
|
||||||
|
value: map_location.zoom,
|
||||||
|
id: map_location_input_id(parent_class, 'latitude') %>
|
||||||
<% end %>
|
<% end %>
|
||||||
@@ -67,6 +67,7 @@
|
|||||||
map_location: @proposal.map_location || MapLocation.new,
|
map_location: @proposal.map_location || MapLocation.new,
|
||||||
label: t("proposals.form.map_location"),
|
label: t("proposals.form.map_location"),
|
||||||
help: t("proposals.form.map_location_instructions"),
|
help: t("proposals.form.map_location_instructions"),
|
||||||
|
remove_marker_label: t("proposals.form.map_remove_marker"),
|
||||||
parent_class: "proposal" %>
|
parent_class: "proposal" %>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -55,6 +55,9 @@ en:
|
|||||||
tags_instructions: "Tag this proposal. You can choose from proposed categories or add your own"
|
tags_instructions: "Tag this proposal. You can choose from proposed categories or add your own"
|
||||||
tags_label: Tags
|
tags_label: Tags
|
||||||
tags_placeholder: "Enter the tags you would like to use, separated by commas (',')"
|
tags_placeholder: "Enter the tags you would like to use, separated by commas (',')"
|
||||||
|
map_location: "Map location"
|
||||||
|
map_location_instructions: "Navigate the map to the location and place the marker."
|
||||||
|
map_remove_marker: "Remove map marker"
|
||||||
index:
|
index:
|
||||||
title: Participatory budgeting
|
title: Participatory budgeting
|
||||||
unfeasible: Unfeasible investment projects
|
unfeasible: Unfeasible investment projects
|
||||||
|
|||||||
@@ -335,6 +335,7 @@ en:
|
|||||||
tags_placeholder: "Enter the tags you would like to use, separated by commas (',')"
|
tags_placeholder: "Enter the tags you would like to use, separated by commas (',')"
|
||||||
map_location: "Map location"
|
map_location: "Map location"
|
||||||
map_location_instructions: "Navigate the map to the location and place the marker."
|
map_location_instructions: "Navigate the map to the location and place the marker."
|
||||||
|
map_remove_marker: "Remove map marker"
|
||||||
index:
|
index:
|
||||||
featured_proposals: Featured
|
featured_proposals: Featured
|
||||||
filter_topic:
|
filter_topic:
|
||||||
|
|||||||
@@ -55,6 +55,9 @@ es:
|
|||||||
tags_label: Temas
|
tags_label: Temas
|
||||||
tag_category_label: "Categorías"
|
tag_category_label: "Categorías"
|
||||||
tags_placeholder: "Escribe las etiquetas que desees separadas por una coma (',')"
|
tags_placeholder: "Escribe las etiquetas que desees separadas por una coma (',')"
|
||||||
|
map_location: "Ubicación en el mapa"
|
||||||
|
map_location_instructions: "Navega por el mapa hasta la ubicación y coloca el marcador."
|
||||||
|
map_remove_marker: "Eliminar el marcador"
|
||||||
index:
|
index:
|
||||||
title: Presupuestos participativos
|
title: Presupuestos participativos
|
||||||
unfeasible: Propuestas de inversión no viables
|
unfeasible: Propuestas de inversión no viables
|
||||||
|
|||||||
@@ -335,6 +335,7 @@ es:
|
|||||||
tags_placeholder: "Escribe las etiquetas que desees separadas por una coma (',')"
|
tags_placeholder: "Escribe las etiquetas que desees separadas por una coma (',')"
|
||||||
map_location: "Ubicación en el mapa"
|
map_location: "Ubicación en el mapa"
|
||||||
map_location_instructions: "Navega por el mapa hasta la ubicación y coloca el marcador."
|
map_location_instructions: "Navega por el mapa hasta la ubicación y coloca el marcador."
|
||||||
|
map_remove_marker: "Eliminar el marcador"
|
||||||
index:
|
index:
|
||||||
featured_proposals: Destacadas
|
featured_proposals: Destacadas
|
||||||
filter_topic:
|
filter_topic:
|
||||||
|
|||||||
Reference in New Issue
Block a user