From 908c8dd460d57e3f5035b1b3fa85f38e200b21b1 Mon Sep 17 00:00:00 2001 From: Krivchikov Dmitry Date: Wed, 2 Jul 2014 13:34:31 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A0=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=20=D1=81?= =?UTF-8?q?=20=D0=BC=D0=B0=D1=80=D1=88=D1=80=D1=83=D1=82=D0=B0=D0=BC=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ground/controllers/IndexController.php | 2 ++ ground/views/indexTemplate.php | 9 +++--- public/js/map.js | 44 ++++++++++++++------------ public/js/route.js | 39 ++++++++++++----------- 4 files changed, 51 insertions(+), 43 deletions(-) diff --git a/ground/controllers/IndexController.php b/ground/controllers/IndexController.php index 5b96c9a..19d9538 100644 --- a/ground/controllers/IndexController.php +++ b/ground/controllers/IndexController.php @@ -21,12 +21,14 @@ class IndexController extends Controller self::addScript('/js/app.js?ver='.App::getConfig('version')); self::addScript('/js/map.js?ver='.App::getConfig('version')); + self::addScript('/js/leaflet-routing-machine.js'); self::addScript('/js/route.js?ver='.App::getConfig('version')); self::addStyle('/css/style.css?ver='.App::getConfig('version')); self::addStyle('http://cdn.leafletjs.com/leaflet-0.7.3/leaflet.css'); self::addStyle('/css/bootstrap.min.css'); self::addStyle('/css/bootstrap-theme.min.css'); + self::addStyle('/css/leaflet-routing-machine.css'); if (!App::$user ) self::addScript('//ulogin.ru/js/ulogin.js'); diff --git a/ground/views/indexTemplate.php b/ground/views/indexTemplate.php index ca65481..e6d7fcd 100644 --- a/ground/views/indexTemplate.php +++ b/ground/views/indexTemplate.php @@ -47,13 +47,14 @@ -
+

Маршрут

- - - +
+ + +
Выйти diff --git a/public/js/map.js b/public/js/map.js index 5895385..0bf97de 100644 --- a/public/js/map.js +++ b/public/js/map.js @@ -55,28 +55,10 @@ function init() { } } else { - myMap._popup._close(); + closePopup(); } }); -// points.im = new ymaps.Placemark( -// [ymaps.geolocation.latitude, ymaps.geolocation.longitude], -// { -// balloonContentHeader: 'Вы здесь', -// hintContent: 'Ваше местоположение', -// balloonContent: -// '' -// }, -// { -// iconImageHref: '/ico/man.png', -// iconImageSize: [32, 37], -// iconImageOffset: [-16, -33], -// } -// ); -// myMap.geoObjects.add(points.im); - $("#wayPoints").sortable(); $("#wayPoints").disableSelection(); @@ -90,6 +72,14 @@ 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 @@ -212,6 +202,14 @@ function initCategories() popupAnchor: [0, 1] }); } + + categories.im = L.icon({ + iconUrl: '/ico/man.png', + iconSize: [32, 37], + iconAnchor: [16, 37], + popupAnchor: [0, 1] + }); + initPoints(); } }); @@ -397,7 +395,7 @@ function editPoint(id) $('#addPointLat').val(pointsSources[id].lat); $('#addPointLng').val(pointsSources[id].lng); - myMap._popup._close(); + closePopup(); $('#addPointModal').modal('show'); setStatus(statusEdit); } @@ -419,3 +417,9 @@ function setLayer(name) $('.layers').removeClass('selected'); $('.'+layer+'Layer').addClass('selected'); } + +function closePopup() +{ + if (myMap._popup) + myMap._popup._close(); +} diff --git a/public/js/route.js b/public/js/route.js index 358ec63..c086bb1 100644 --- a/public/js/route.js +++ b/public/js/route.js @@ -1,5 +1,5 @@ /* - * Набор функций для работы с маршрктами. + * Набор функций для работы с маршрутами. */ /** @@ -10,29 +10,29 @@ function buildRoute() { wayPoints = Array(); if (route) - myMap.geoObjects.remove(route); + myMap.removeLayer(route); $('#wayPoints div').each(function(i, el) { - wayPoints.push(points[$(el).attr('pointId')].geometry.getCoordinates()); + wayPoints.push({latLng: points[$(el).attr('pointId')]._latlng}); }); - ymaps.route(wayPoints, { - mapStateAutoApply: true - }).then(function(newRoute) { - route = newRoute; - route.options.set({ - // в балуне выводим только информацию о времени движения с учетом пробок - balloonContenBodyLayout: ymaps.templateLayoutFactory.createClass('$[properties.humanJamsTime]'), - strokeColor: '9000ffff', - opacity: 0.9 + if (wayPoints.length > 1) + { + L.Routing.osrm().route(wayPoints, function(err, routes) { + if (err) { + console.error(err); + alert('Произошла ошибка. Вероятно построить маршрут по выбранным точкам невозможно.'); + } else { + route = L.Routing.line(routes[0]); + distance = Math.round(routes[0].summary.totalDistance / 1000); + $('#routeDistance').html('Протяженность ' + distance + ' км.'); + route.addTo(myMap); + } }); - myMap.geoObjects.add(route); - distance = Math.round(route.getLength() / 1000); - $('#routeDistance').text(distance + ' км.'); routeToURL(); - }); + } } /** @@ -126,10 +126,11 @@ function deleteRoute(id) */ function addToRoute(id) { - console.log(points[id]); - $('#wayPoints').append('
× ' + points[id].options.title + '
'); - myMap._popup._close(); + $('#wayPoints').append('
× ' + points[id].options.title + '
'); + closePopup(); openBox('Route', true); + + buildRoute(); return true; }