diff options
-rw-r--r-- | app/assets/javascripts/hierfehltwas.js | 32 | ||||
-rw-r--r-- | app/assets/stylesheets/hierfehltwas.css | 2 | ||||
-rw-r--r-- | app/views/layouts/application.html.erb | 1 | ||||
-rw-r--r-- | app/views/pois/_form.html.erb | 16 | ||||
-rw-r--r-- | 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 <http://www.openstreetmap.org/copyright> and contributors, ODbL <http://wiki.openstreetmap.org/wiki/Legal_FAQ#I_would_like_to_use_OpenStreetMap_maps._How_should_I_credit_you.#> .' - 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 %> + <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" /> </head> <body> 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 @@ +<div id="map"></div> + <%= form_for(@poi) do |f| %> <% if @poi.errors.any? %> <div id="error_explanation"> @@ -11,20 +13,14 @@ </div> <% end %> - <div id="map"></div> - <div class="field"> <%= f.label :message %><br> <%= f.text_area :message %> </div> - <div class="field"> - <%= f.label :lat %><br> - <%= f.text_field :lat %> - </div> - <div class="field"> - <%= f.label :lon %><br> - <%= f.text_field :lon %> - </div> + + <%= f.hidden_field :lat %> + <%= f.hidden_field :lon %> + <div class="actions"> <%= f.submit %> </div> 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 @@ -<h1>New poi</h1> - <%= render 'form' %> - -<%= link_to 'Back', pois_path %> |