diff --git a/public/js/map.js b/public/js/map.js index 01480ed..adaa750 100644 --- a/public/js/map.js +++ b/public/js/map.js @@ -13,6 +13,7 @@ var addPointInProcess = false; var layer; var layers = Array(); var defaultZoom = 13; +var rightCoords = []; categories.im = L.icon({ iconUrl: '/ico/man.png', @@ -109,6 +110,19 @@ function init(lat, lng) { filter() }); + // Добавление произвольной точки в маршрут по правому клику + myMap.on('contextmenu',function(e){ + if (status == statusReady) + { + rightCoords = [e.latlng.lat, e.latlng.lng]; + popupContent = ''; + popup = L.popup(); + popup.setContent(popupContent); + popup.setLatLng(e.latlng); + popup.openOn(myMap); + } + }); + return true; } diff --git a/public/js/route.js b/public/js/route.js index 0f5280d..5586d84 100644 --- a/public/js/route.js +++ b/public/js/route.js @@ -1,4 +1,4 @@ -/* +/* * Набор функций для работы с маршрутами. */ @@ -14,8 +14,18 @@ function buildRoute(fit) $('#wayPoints div').each(function(i, el) { - lat = points[$(el).attr('pointId')]._latlng.lat; - lng = points[$(el).attr('pointId')]._latlng.lng; + if ($(el).attr('pointId').length <= 10) { + lat = points[$(el).attr('pointId')]._latlng.lat; + lng = points[$(el).attr('pointId')]._latlng.lng; + + wayPoints.push({latLng: points[$(el).attr('pointId')]._latlng}); + } else { + coords = JSON.parse($(el).attr('pointId')); + lat = coords[0]; + lng = coords[1]; + + wayPoints.push({latLng: {lat: lat, lng: lng}}); + } if (i == 0) { @@ -26,8 +36,6 @@ function buildRoute(fit) if (lat > bounds[1][0]) bounds[1][0] = lat; if (lng > bounds[1][1]) bounds[1][1] = lng; } - - wayPoints.push({latLng: points[$(el).attr('pointId')]._latlng}); }); if (fit === true) @@ -103,6 +111,10 @@ function loadRouteJSON(data) response = JSON.parse(data); for (var k in response) { + if (response[k].length >= 10) { + response[k] = JSON.parse(response[k]); + } + addToRoute(response[k], false); } @@ -151,14 +163,30 @@ function deleteRoute(id) */ function addToRoute(id, build) { - $('#wayPoints').append('
× '+ points[id].options.title + '
'); - closePopup(); - openBox('Route', true); + if ($.isArray(id)) { + n = (id[0]>=0) ? 'N'+id[0] : 'S'+Math.abs(id[0]); + e = (id[1]>=0) ? 'E'+id[1] : 'W'+Math.abs(id[1]); - if (build !== false) - buildRoute(); + coordsName = n.substring(0,10)+'° '+e.substring(0,10)+'°'; + $('#wayPoints').append('
× '+coordsName+'
'); + closePopup(); + openBox('Route', true); - return true; + if (build !== false) { + buildRoute(); + } + + return true; + } else { + $('#wayPoints').append('
× '+ points[id].options.title + '
'); + closePopup(); + openBox('Route', true); + + if (build !== false) + buildRoute(); + + return true; + } } /**