load route and save it as route

merge-requests/1/head
Julien Veyssier 2016-12-08 12:07:30 +01:00
parent a7f8d16242
commit 82ae3a24cc
1 changed files with 69 additions and 36 deletions

View File

@ -325,10 +325,7 @@ function load_map() {
circle: false,
rectangle:false,
marker: {
icon: L.divIcon({
className: 'leaflet-div-icon2',
iconAnchor: [5, 30]
})
icon: symbolIcons['marker']
}
},
edit: {
@ -381,9 +378,19 @@ function load_map() {
// it generates the popup content and initializes the layer's data
// it returns the layer in case we want to set the layer's data manually (when loading a gpx)
function onCreated(type, layer){
var popupTitle = 'Track';
if (type === 'marker') {
var popupTitle;
var layerType;
if (type === 'polyline' || type === 'track'){
popupTitle = 'Track';
layerType = 'track';
}
else if (type === 'route') {
popupTitle = 'Route';
layerType = 'route';
}
else if (type === 'marker') {
popupTitle = 'Waypoint';
layerType = 'marker';
}
var popupTxt = '<h2 class="popupTitle">'+popupTitle+'</h2><table class="popupdatatable">'+
@ -406,7 +413,7 @@ function onCreated(type, layer){
layer.bindPopup(popupTxt);
layer.gpxedit_id = gpxedit.id;
layer.type = type;
layer.type = layerType;
gpxedit.layersData[gpxedit.id] = {name:'', description:'', comment:'', symbol:'', layer: layer};
gpxedit.editableLayers.addLayer(layer);
gpxedit.id++;
@ -485,7 +492,7 @@ function generateGpx(){
}
gpxText = gpxText + ' </wpt>\n';
}
else{
else if(layer.type === 'track'){
gpxText = gpxText + ' <trk>\n';
if (name){
gpxText = gpxText + ' <name>'+name+'</name>\n';
@ -512,6 +519,32 @@ function generateGpx(){
}
gpxText = gpxText + ' </trkseg>\n </trk>\n';
}
else if(layer.type === 'route'){
gpxText = gpxText + ' <rte>\n';
if (name){
gpxText = gpxText + ' <name>'+name+'</name>\n';
}
else{
gpxText = gpxText + ' <name>unnamed</name>\n';
}
if (comment){
gpxText = gpxText + ' <cmt>'+comment+'</cmt>\n';
}
if (description){
gpxText = gpxText + ' <desc>'+description+'</desc>\n';
}
for (var i=0; i<layer._latlngs.length; i++){
var lat = layer._latlngs[i].lat;
var lng = layer._latlngs[i].lng;
var alt = layer._latlngs[i].alt;
gpxText = gpxText + ' <rtept lat="'+lat+'" lon="'+lng+'">\n';
if (alt !== undefined){
gpxText = gpxText + ' <ele>'+alt+'</ele>\n';
}
gpxText = gpxText + ' </rtept>\n';
}
gpxText = gpxText + ' </rte>\n';
}
});
gpxText = gpxText + ' <extensions/>\n</gpx>';
return gpxText;
@ -545,14 +578,14 @@ function drawMarker(latlng, name, desc, cmt, sym){
}
// adds a polyline and initialize its data
function drawLine(latlngs, name, desc, cmt){
function drawLine(latlngs, name, desc, cmt, gpxtype){
var wst = $('#markerstyleselect').val();
var tst = $('#tooltipstyleselect').val();
var p = L.polyline(latlngs, {
color: '#f357a1',
weight: 7
});
var layer = onCreated('polyline', p);
var layer = onCreated(gpxtype, p);
if (name !== ''){
if (tst === 'p'){
p.bindTooltip(name, {permanent:true});
@ -603,7 +636,7 @@ function parseGpx(xml){
}
});
});
drawLine(latlngs, name, desc, cmt);
drawLine(latlngs, name, desc, cmt, 'track');
});
dom.find('rte').each(function(){
var latlngs = [];
@ -621,7 +654,7 @@ function parseGpx(xml){
latlngs.push([lat,lon]);
}
});
drawLine(latlngs, name, desc, cmt);
drawLine(latlngs, name, desc, cmt, 'route');
});
}