ADD Добавление в маршрут произвольных точек

This commit is contained in:
Krivchikov Dmitry 2015-05-21 14:01:53 +03:00
parent a72b69a3f1
commit 01ee3ee34c
2 changed files with 53 additions and 11 deletions

View File

@ -13,6 +13,7 @@ var addPointInProcess = false;
var layer; var layer;
var layers = Array(); var layers = Array();
var defaultZoom = 13; var defaultZoom = 13;
var rightCoords = [];
categories.im = L.icon({ categories.im = L.icon({
iconUrl: '/ico/man.png', iconUrl: '/ico/man.png',
@ -109,6 +110,19 @@ function init(lat, lng) {
filter() filter()
}); });
// Добавление произвольной точки в маршрут по правому клику
myMap.on('contextmenu',function(e){
if (status == statusReady)
{
rightCoords = [e.latlng.lat, e.latlng.lng];
popupContent = '<button type="button" class="btn btn-default" onclick="addToRoute(rightCoords)"><span class="glyphicon glyphicon-map-marker"></span> Добавить в маршрут</button>';
popup = L.popup();
popup.setContent(popupContent);
popup.setLatLng(e.latlng);
popup.openOn(myMap);
}
});
return true; return true;
} }

View File

@ -14,9 +14,19 @@ function buildRoute(fit)
$('#wayPoints div').each(function(i, el) $('#wayPoints div').each(function(i, el)
{ {
if ($(el).attr('pointId').length <= 10) {
lat = points[$(el).attr('pointId')]._latlng.lat; lat = points[$(el).attr('pointId')]._latlng.lat;
lng = points[$(el).attr('pointId')]._latlng.lng; 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) if (i == 0)
{ {
bounds = [[lat, lng],[lat, lng]]; bounds = [[lat, lng],[lat, lng]];
@ -26,8 +36,6 @@ function buildRoute(fit)
if (lat > bounds[1][0]) bounds[1][0] = lat; if (lat > bounds[1][0]) bounds[1][0] = lat;
if (lng > bounds[1][1]) bounds[1][1] = lng; if (lng > bounds[1][1]) bounds[1][1] = lng;
} }
wayPoints.push({latLng: points[$(el).attr('pointId')]._latlng});
}); });
if (fit === true) if (fit === true)
@ -103,6 +111,10 @@ function loadRouteJSON(data)
response = JSON.parse(data); response = JSON.parse(data);
for (var k in response) for (var k in response)
{ {
if (response[k].length >= 10) {
response[k] = JSON.parse(response[k]);
}
addToRoute(response[k], false); addToRoute(response[k], false);
} }
@ -151,6 +163,21 @@ function deleteRoute(id)
*/ */
function addToRoute(id, build) function addToRoute(id, build)
{ {
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]);
coordsName = n.substring(0,10)+'° '+e.substring(0,10)+'°';
$('#wayPoints').append('<div pointid="'+JSON.stringify(id)+'" class="wayPoint"><span class="del" onclick="$(this).parent().remove();buildRoute();">&times;</span> '+coordsName+'</div>');
closePopup();
openBox('Route', true);
if (build !== false) {
buildRoute();
}
return true;
} else {
$('#wayPoints').append('<div pointid="' + id + '" class="wayPoint" onclick="showInfo('+ id +');"><span class="del" onclick="$(this).parent().remove();buildRoute();">&times;</span> '+ points[id].options.title + '</div>'); $('#wayPoints').append('<div pointid="' + id + '" class="wayPoint" onclick="showInfo('+ id +');"><span class="del" onclick="$(this).parent().remove();buildRoute();">&times;</span> '+ points[id].options.title + '</div>');
closePopup(); closePopup();
openBox('Route', true); openBox('Route', true);
@ -159,6 +186,7 @@ function addToRoute(id, build)
buildRoute(); buildRoute();
return true; return true;
}
} }
/** /**