diff --git a/app/assets/stylesheets/layout.scss b/app/assets/stylesheets/layout.scss
index 59b851e79..7f4e1bb82 100644
--- a/app/assets/stylesheets/layout.scss
+++ b/app/assets/stylesheets/layout.scss
@@ -879,6 +879,13 @@ footer {
}
}
+.sidebar-map {
+
+ .map {
+ z-index: -1;
+ }
+}
+
.sidebar-title {
border-top: 2px solid $brand;
display: inline-block;
diff --git a/app/controllers/budgets/investments_controller.rb b/app/controllers/budgets/investments_controller.rb
index a456ff54e..c0e91b080 100644
--- a/app/controllers/budgets/investments_controller.rb
+++ b/app/controllers/budgets/investments_controller.rb
@@ -1,6 +1,5 @@
module Budgets
class InvestmentsController < ApplicationController
- OSM_DISTRICT_LEVEL_ZOOM = 12
include FeatureFlags
include CommentableActions
@@ -180,10 +179,7 @@ module Budgets
end
def load_map
- @map_location = MapLocation.new
- @map_location.zoom = OSM_DISTRICT_LEVEL_ZOOM
- @map_location.latitude = @heading.latitude.to_f
- @map_location.longitude = @heading.longitude.to_f
+ @map_location = MapLocation.load_from_heading(@heading)
end
end
diff --git a/app/models/budget/heading.rb b/app/models/budget/heading.rb
index 20f9aa921..50c5d3992 100644
--- a/app/models/budget/heading.rb
+++ b/app/models/budget/heading.rb
@@ -1,5 +1,7 @@
class Budget
class Heading < ActiveRecord::Base
+ OSM_DISTRICT_LEVEL_ZOOM = 12.freeze
+
include Sluggable
belongs_to :group
@@ -12,9 +14,9 @@ class Budget
validates :price, presence: true
validates :slug, presence: true, format: /\A[a-z0-9\-_]+\z/
validates :population, numericality: { greater_than: 0 }, allow_nil: true
- validates :latitude, length: { maximum: 22, minimum: 1 }, presence: true, \
+ validates :latitude, length: { maximum: 22 }, allow_blank: true, \
format: /\A(-|\+)?([1-8]?\d(?:\.\d{1,})?|90(?:\.0{1,6})?)\z/
- validates :longitude, length: { maximum: 22, minimum: 1}, presence: true, \
+ validates :longitude, length: { maximum: 22 }, allow_blank: true, \
format: /\A(-|\+)?((?:1[0-7]|[1-9])?\d(?:\.\d{1,})?|180(?:\.0{1,})?)\z/
delegate :budget, :budget_id, to: :group, allow_nil: true
diff --git a/app/models/map_location.rb b/app/models/map_location.rb
index f66d71e34..d141c167d 100644
--- a/app/models/map_location.rb
+++ b/app/models/map_location.rb
@@ -18,4 +18,12 @@ class MapLocation < ActiveRecord::Base
}
end
+ def self.load_from_heading(heading)
+ map = new
+ map.zoom = Budget::Heading::OSM_DISTRICT_LEVEL_ZOOM
+ map.latitude = heading.latitude.to_f if heading.latitude.present?
+ map.longitude = heading.longitude.to_f if heading.latitude.present?
+ map
+ end
+
end
diff --git a/app/views/budgets/ballot/lines/create.js.erb b/app/views/budgets/ballot/lines/create.js.erb
index b1c9f76be..6edf8a0f2 100644
--- a/app/views/budgets/ballot/lines/create.js.erb
+++ b/app/views/budgets/ballot/lines/create.js.erb
@@ -9,3 +9,5 @@ $("#<%= dom_id(@investment) %>_ballot").html('<%= j render("/budgets/investments
investment: @investment,
investment_ids: @investment_ids,
ballot: @ballot %>
+
+App.Map.initialize();
diff --git a/app/views/budgets/ballot/lines/destroy.js.erb b/app/views/budgets/ballot/lines/destroy.js.erb
index 82c303047..94120d3a9 100644
--- a/app/views/budgets/ballot/lines/destroy.js.erb
+++ b/app/views/budgets/ballot/lines/destroy.js.erb
@@ -10,3 +10,5 @@ $("#<%= dom_id(@investment) %>_ballot").html('<%= j render("/budgets/investments
investment: @investment,
investment_ids: @investment_ids,
ballot: @ballot %>
+
+App.Map.initialize();
diff --git a/app/views/budgets/investments/_map.html.erb b/app/views/budgets/investments/_map.html.erb
index af04ef639..37aa50f67 100644
--- a/app/views/budgets/investments/_map.html.erb
+++ b/app/views/budgets/investments/_map.html.erb
@@ -2,7 +2,7 @@