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 +- 2 files changed, 29 insertions(+), 5 deletions(-) (limited to 'app/assets') 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%; } -- cgit v1.2.1