From 181cf43f378c686c990db6f092de321e52dd26bd Mon Sep 17 00:00:00 2001 From: Krivchikov Dmitry Date: Wed, 2 Jul 2014 14:14:52 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=BD=D0=B8=D1=86=D0=B8=D0=B0=D0=BB?= =?UTF-8?q?=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D1=87=D0=B5=D1=80=D0=B5?= =?UTF-8?q?=D0=B7=20=D1=8F=D0=BD=D0=B4=D0=B5=D0=BA=D1=81=20-=20=D1=83?= =?UTF-8?q?=D0=B7=D0=BD=D0=B0=D1=91=D0=BC=20=D0=BA=D0=BE=D0=BE=D1=80=D0=B4?= =?UTF-8?q?=D0=B8=D0=BD=D0=B0=D1=82=D1=8B=20=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7?= =?UTF-8?q?=D0=BE=D0=B2=D0=B0=D1=82=D0=B5=D0=BB=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/map.js | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) diff --git a/public/js/map.js b/public/js/map.js index 0bf97de..ac69601 100644 --- a/public/js/map.js +++ b/public/js/map.js @@ -2,7 +2,6 @@ * Let's GO! */ -$(document).ready(function(){init()}); var myMap; var categories = Array(); var points = Array(); @@ -13,14 +12,34 @@ var addPointInProcess = false; var layer; var layers = Array(); +categories.im = L.icon({ + iconUrl: '/ico/man.png', + iconSize: [32, 37], + iconAnchor: [16, 37], + popupAnchor: [0, 1] +}); + // ----------------------------------------------------------------------------- +/** + * Инициализируем яндекс-карты и узнаём расположение пользователя. + */ +ymaps.ready(function(){ + lat = ymaps.geolocation.latitude; + lng = ymaps.geolocation.longitude; + init(lat, lng); + + points.im = L.marker([lat, lng], {icon: categories.im, title: 'Вы здесь'}); + points.im.addTo(myMap); + points.im.bindPopup('Ваше местоположение
') +}); + /** * Инициализируем переменные и подгружаем данные. * @returns true */ -function init() { - myMap = L.map('map',{zoomControl: false}).setView([57, 30], 4); +function init(lat, lng) { + myMap = L.map('map',{zoomControl: false}).setView([lat, lng], 11); layers['quest'] = L.tileLayer('http://otile1.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png', {attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery © Mapbox',maxZoom: 18}); layers['osm'] = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: 'Map data © OpenStreetMap contributors, CC-BY-SA, Imagery ©',maxZoom: 18}); @@ -72,14 +91,6 @@ function init() { return true; } -ymaps.ready(function(){ - points.im = L.marker( - [ymaps.geolocation.latitude, ymaps.geolocation.longitude], {icon: categories.im, title: 'Вы здесь'} - ); - points.im.addTo(myMap); - points.im.bindPopup('Ваше местоположение
') -}); - /** * Создаёт точку для карту - Placemark. * @param {Array} data @@ -203,13 +214,6 @@ function initCategories() }); } - categories.im = L.icon({ - iconUrl: '/ico/man.png', - iconSize: [32, 37], - iconAnchor: [16, 37], - popupAnchor: [0, 1] - }); - initPoints(); } }); @@ -252,8 +256,10 @@ function searchAdderess() function showMeOnTheMap() { navigator.geolocation.getCurrentPosition(function(pos) { - //points.im.geometry.setCoordinates([pos.coords.latitude, pos.coords.longitude]); - myMap.setView([pos.coords.latitude, pos.coords.longitude], 15); + coords = [pos.coords.latitude, pos.coords.longitude]; + myMap.removeLayer(points.im); + points.im.setLatLng(coords).addTo(myMap); + myMap.setView(coords, 15); }); //myMap.setCenter(points.im.geometry.getCoordinates());