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 @@ -
')
+});
+
/**
* Создаёт точку для карту - 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('