sort layers to write them in gpx file

merge-requests/1/head
Julien Veyssier 2017-03-21 15:03:57 -03:00
parent 90e5304b9a
commit d60f29b5c1
2 changed files with 68 additions and 7 deletions

View File

@ -19,8 +19,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- integration in "Files" and "File sharing" context menu for .gpx files - integration in "Files" and "File sharing" context menu for .gpx files
[#11](https://gitlab.com/eneiluj/gpxedit-oc/issues/11) @rugk [#11](https://gitlab.com/eneiluj/gpxedit-oc/issues/11) @rugk
- notifications on tile layer add/remove - notifications on tile layer add/remove
- makefile signs the app code
### Changed ### Changed
- numeric/alphabetic sort of layers by name in gpx file
### Fixed ### Fixed
- app is now compliant to occ check-code - app is now compliant to occ check-code

View File

@ -193,8 +193,8 @@
} }
// get url from key and layer type // get url from key and layer type
function geopUrl (key, layer, format) function geopUrl(key, layer, format) {
{ return 'http://wxs.ign.fr/' + key + '/wmts?LAYER=' + layer + return 'http://wxs.ign.fr/' + key + '/wmts?LAYER=' + layer +
'&EXCEPTIONS=text/xml&FORMAT=' + (format?format:'image/jpeg') + '&EXCEPTIONS=text/xml&FORMAT=' + (format?format:'image/jpeg') +
'&SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&STYLE=normal' + '&SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&STYLE=normal' +
'&TILEMATRIXSET=PM&TILEMATRIX={z}&TILECOL={x}&TILEROW={y}' ; '&TILEMATRIXSET=PM&TILEMATRIX={z}&TILECOL={x}&TILEROW={y}' ;
@ -544,7 +544,7 @@
// generate gpx text from current map elements // generate gpx text from current map elements
function generateGpx() { function generateGpx() {
var lat, lng, alt, time, i; var lat, lng, alt, time, i, ia;
var gpxText = '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n'; var gpxText = '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n';
var now = new Date(); var now = new Date();
var now_utc_str = now.getUTCFullYear() + '-' + var now_utc_str = now.getUTCFullYear() + '-' +
@ -575,7 +575,66 @@
} }
gpxText = gpxText + '</metadata>\n'; gpxText = gpxText + '</metadata>\n';
var layerArray = [];
gpxedit.editableLayers.eachLayer(function(layer) { gpxedit.editableLayers.eachLayer(function(layer) {
layerArray.push(layer);
});
// sort
var sortedLayerArray = layerArray.sort(function (layer1, layer2) {
var res;
var id1 = layer1.gpxedit_id;
var id2 = layer2.gpxedit_id;
var name1 = gpxedit.layersData[id1].name;
var name2 = gpxedit.layersData[id2].name;
var numname1 = parseInt(name1);
var numname2 = parseInt(name2);
// special cases : at least one of them does not begin by a number
// number is always inferior than string
if (isNaN(numname1) && !isNaN(numname2)) {
res = 1;
}
else if (!isNaN(numname1) && isNaN(numname2)) {
res = -1;
}
// if both are not begining with a number : compare strings
else if (isNaN(numname1) && isNaN(numname2)) {
if (name1 < name2) {
res = -1;
}
else if (name1 === name2) {
res = 0;
}
else {
res = 1;
}
}
// normal case : both begin with a number
else{
if (numname1 < numname2) {
res = -1;
}
// if numbers are identical : compare strings
else if(numname1 === numname2) {
if (name1 < name2) {
res = -1;
}
else if (name1 === name2) {
res = 0;
}
else {
res = 1;
}
}
else{
res = 1;
}
}
return res;
});
for (ia = 0; ia < sortedLayerArray.length; ia++){
var layer = sortedLayerArray[ia];
var id = layer.gpxedit_id; var id = layer.gpxedit_id;
var name = gpxedit.layersData[id].name; var name = gpxedit.layersData[id].name;
var comment = gpxedit.layersData[id].comment; var comment = gpxedit.layersData[id].comment;
@ -671,7 +730,7 @@
} }
gpxText = gpxText + ' </rte>\n'; gpxText = gpxText + ' </rte>\n';
} }
}); }
gpxText = gpxText + ' <extensions/>\n</gpx>'; gpxText = gpxText + ' <extensions/>\n</gpx>';
return gpxText; return gpxText;
} }