From 0a2e76526b4fdb0edfcaa3697f4eea9e9c7c8eea Mon Sep 17 00:00:00 2001 From: Lars Henrik Mai Date: Sat, 29 Mar 2014 19:34:42 +0100 Subject: =?UTF-8?q?kinda=20works=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/assets/javascripts/hierfehltwas.js | 32 ++++++++++++++++++++++++++++---- app/assets/stylesheets/hierfehltwas.css | 2 +- app/views/layouts/application.html.erb | 1 + app/views/pois/_form.html.erb | 16 ++++++---------- app/views/pois/new.html.erb | 4 ---- 5 files changed, 36 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/hierfehltwas.js b/app/assets/javascripts/hierfehltwas.js index 96dcfe7..b1a0542 100644 --- a/app/assets/javascripts/hierfehltwas.js +++ b/app/assets/javascripts/hierfehltwas.js @@ -5,7 +5,7 @@ var plotlayers=[]; window.onDomReady = initReady; -window.onDomReady(initmap); +window.onDomReady(getLocation); function initReady(fn) { if(document.addEventListener) { @@ -13,24 +13,48 @@ function initReady(fn) { } } +var hfw_lat=51.335, + hfw_lon=12.37, + default_zoom=18; + +function getLocation() { + if (navigator.geolocation) { + navigator.geolocation.getCurrentPosition(setCoords); + } else { + setCoords({latitude: hfw_lat, longitude: hfw_lon}); + } + } + +function setCoords(position) { + hfw_lat=position.coords.latitude; + hfw_lon=position.coords.longitude; + initmap(); +} function initmap() { // set up the map - map = new L.Map('map'); + map = new L.Map('map'); // create the tile layer with correct attribution //var osmUrl='http://{s}.tile.cloudmade.com/API-key/997/256/{z}/{x}/{y}.png'; var osmUrl='http://otile1.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png'; //var osmUrl='http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'; var osmAttrib='Data, imagery and map information provided by MapQuest, OpenStreetMap and contributors, ODbL .' - var osm = new L.TileLayer(osmUrl, {minZoom: 12, maxZoom: 18, attribution: osmAttrib}); + var osm = new L.TileLayer(osmUrl, {minZoom: 12, maxZoom: 18, attribution: osmAttrib}); - map.setView(new L.LatLng(51.335, 12.37),14); + map.setView(new L.LatLng(hfw_lat, hfw_lon), default_zoom); map.addLayer(osm); //L.marker([51.33, 12.35], {icon: hfw1Icon}).addTo(map); //L.marker([51.37, 12.33], {icon: hfw2Icon}).addTo(map); //L.marker([51.31, 12.31], {icon: hfw3Icon}).addTo(map); + initForm(); + +} + +function initForm() { + $("#poi_lat").val(hfw_lat); + $("#poi_lon").val(hfw_lon); } var hfw1Icon = L.icon({ diff --git a/app/assets/stylesheets/hierfehltwas.css b/app/assets/stylesheets/hierfehltwas.css index c2042af..aae40b8 100644 --- a/app/assets/stylesheets/hierfehltwas.css +++ b/app/assets/stylesheets/hierfehltwas.css @@ -8,6 +8,6 @@ html, body { } #map { - height: 200px; + height: 50%; } diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index c941b11..c418005 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -5,6 +5,7 @@ <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> <%= javascript_include_tag "application", "data-turbolinks-track" => true %> <%= csrf_meta_tags %> + diff --git a/app/views/pois/_form.html.erb b/app/views/pois/_form.html.erb index 26db79d..e9006c9 100644 --- a/app/views/pois/_form.html.erb +++ b/app/views/pois/_form.html.erb @@ -1,3 +1,5 @@ +
+ <%= form_for(@poi) do |f| %> <% if @poi.errors.any? %>
@@ -11,20 +13,14 @@
<% end %> -
-
<%= f.label :message %>
<%= f.text_area :message %>
-
- <%= f.label :lat %>
- <%= f.text_field :lat %> -
-
- <%= f.label :lon %>
- <%= f.text_field :lon %> -
+ + <%= f.hidden_field :lat %> + <%= f.hidden_field :lon %> +
<%= f.submit %>
diff --git a/app/views/pois/new.html.erb b/app/views/pois/new.html.erb index ea4ebe0..2d34363 100644 --- a/app/views/pois/new.html.erb +++ b/app/views/pois/new.html.erb @@ -1,5 +1 @@ -

New poi

- <%= render 'form' %> - -<%= link_to 'Back', pois_path %> -- cgit v1.2.1