Инициализация через яндекс - узнаём координаты пользователя
This commit is contained in:
parent
90d8f3e235
commit
181cf43f37
|
|
@ -2,7 +2,6 @@
|
||||||
* Let's GO!
|
* Let's GO!
|
||||||
*/
|
*/
|
||||||
|
|
||||||
$(document).ready(function(){init()});
|
|
||||||
var myMap;
|
var myMap;
|
||||||
var categories = Array();
|
var categories = Array();
|
||||||
var points = Array();
|
var points = Array();
|
||||||
|
|
@ -13,14 +12,34 @@ var addPointInProcess = false;
|
||||||
var layer;
|
var layer;
|
||||||
var layers = Array();
|
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('<b>Ваше местоположение</b><br/><img src="/ico/man.png" /> <button type="button" class="btn btn-default btn-xs" onclick="addToRoute(\'im\')"><span class="glyphicon glyphicon-plus"></span> Добавить в маршрут</button>')
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Инициализируем переменные и подгружаем данные.
|
* Инициализируем переменные и подгружаем данные.
|
||||||
* @returns true
|
* @returns true
|
||||||
*/
|
*/
|
||||||
function init() {
|
function init(lat, lng) {
|
||||||
myMap = L.map('map',{zoomControl: false}).setView([57, 30], 4);
|
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 © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',maxZoom: 18});
|
layers['quest'] = L.tileLayer('http://otile1.mqcdn.com/tiles/1.0.0/osm/{z}/{x}/{y}.png', {attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery © <a href="http://mapbox.com">Mapbox</a>',maxZoom: 18});
|
||||||
layers['osm'] = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery ©</a>',maxZoom: 18});
|
layers['osm'] = L.tileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {attribution: 'Map data © <a href="http://openstreetmap.org">OpenStreetMap</a> contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>, Imagery ©</a>',maxZoom: 18});
|
||||||
|
|
@ -72,14 +91,6 @@ function init() {
|
||||||
return true;
|
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('<b>Ваше местоположение</b><br/><img src="/ico/man.png" /> <button type="button" class="btn btn-default btn-xs" onclick="addToRoute(\'im\')"><span class="glyphicon glyphicon-plus"></span> Добавить в маршрут</button>')
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Создаёт точку для карту - Placemark.
|
* Создаёт точку для карту - Placemark.
|
||||||
* @param {Array} data
|
* @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();
|
initPoints();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
@ -252,8 +256,10 @@ function searchAdderess()
|
||||||
function showMeOnTheMap()
|
function showMeOnTheMap()
|
||||||
{
|
{
|
||||||
navigator.geolocation.getCurrentPosition(function(pos) {
|
navigator.geolocation.getCurrentPosition(function(pos) {
|
||||||
//points.im.geometry.setCoordinates([pos.coords.latitude, pos.coords.longitude]);
|
coords = [pos.coords.latitude, pos.coords.longitude];
|
||||||
myMap.setView([pos.coords.latitude, pos.coords.longitude], 15);
|
myMap.removeLayer(points.im);
|
||||||
|
points.im.setLatLng(coords).addTo(myMap);
|
||||||
|
myMap.setView(coords, 15);
|
||||||
});
|
});
|
||||||
|
|
||||||
//myMap.setCenter(points.im.geometry.getCoordinates());
|
//myMap.setCenter(points.im.geometry.getCoordinates());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue