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());