2016-11-30 19:00:03 +00:00
|
|
|
(function ($, OC) {
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
var gpxedit = {
|
|
|
|
map: {},
|
|
|
|
baseLayers: null,
|
2017-02-01 19:18:56 +00:00
|
|
|
restoredTileLayer: null,
|
2016-12-06 15:23:14 +00:00
|
|
|
drawControl: null,
|
2016-11-30 19:00:03 +00:00
|
|
|
id: 0,
|
|
|
|
// indexed by gpxedit_id
|
2016-12-27 17:04:47 +00:00
|
|
|
layersData: {},
|
|
|
|
currentAjax : null
|
2016-11-30 19:00:03 +00:00
|
|
|
};
|
|
|
|
|
2016-12-07 17:53:14 +00:00
|
|
|
var symbolSelectClasses = {
|
2016-12-19 22:45:13 +00:00
|
|
|
'unknown': 'unknown-select',
|
2016-12-07 17:53:14 +00:00
|
|
|
'marker': 'marker-select',
|
|
|
|
'Dot, White': 'dot-select',
|
|
|
|
'Pin, Blue': 'pin-blue-select',
|
|
|
|
'Pin, Green': 'pin-green-select',
|
|
|
|
'Pin, Red': 'pin-red-select',
|
|
|
|
'Flag, Green': 'flag-green-select',
|
|
|
|
'Flag, Red': 'flag-red-select',
|
|
|
|
'Flag, Blue': 'flag-blue-select',
|
|
|
|
'Block, Blue': 'block-blue-select',
|
|
|
|
'Block, Green': 'block-green-select',
|
|
|
|
'Block, Red': 'block-red-select',
|
|
|
|
'Blue Diamond': 'diamond-blue-select',
|
|
|
|
'Green Diamond': 'diamond-green-select',
|
|
|
|
'Red Diamond': 'diamond-red-select',
|
2016-12-08 09:23:36 +00:00
|
|
|
'Residence': 'residence-select',
|
|
|
|
'Drinking Water': 'drinking-water-select',
|
2016-12-07 17:53:14 +00:00
|
|
|
'Trail Head': 'hike-select',
|
|
|
|
'Bike Trail': 'bike-trail-select',
|
|
|
|
'Campground': 'campground-select',
|
|
|
|
'Bar': 'bar-select',
|
|
|
|
'Skull and Crossbones': 'skullcross-select',
|
|
|
|
'Geocache': 'geocache-select',
|
|
|
|
'Geocache Found': 'geocache-open-select',
|
|
|
|
'Medical Facility': 'medical-select',
|
2016-12-10 14:12:27 +00:00
|
|
|
'Contact, Alien': 'contact-alien-select',
|
|
|
|
'Contact, Big Ears': 'contact-bigears-select',
|
|
|
|
'Contact, Female3': 'contact-female3-select',
|
|
|
|
'Contact, Cat': 'contact-cat-select',
|
|
|
|
'Contact, Dog': 'contact-dog-select',
|
2016-12-07 17:53:14 +00:00
|
|
|
}
|
|
|
|
|
2016-12-06 18:22:26 +00:00
|
|
|
var symbolIcons = {
|
2016-12-07 14:12:29 +00:00
|
|
|
'marker': L.divIcon({
|
|
|
|
className: 'leaflet-marker-blue',
|
|
|
|
iconAnchor: [12, 41]
|
|
|
|
}),
|
2016-12-07 13:50:06 +00:00
|
|
|
'Dot, White': L.divIcon({
|
|
|
|
iconSize:L.point(7,7),
|
|
|
|
}),
|
|
|
|
'Pin, Blue': L.divIcon({
|
|
|
|
className: 'pin-blue',
|
|
|
|
iconAnchor: [5, 30]
|
|
|
|
}),
|
|
|
|
'Pin, Green': L.divIcon({
|
|
|
|
className: 'pin-green',
|
|
|
|
iconAnchor: [5, 30]
|
|
|
|
}),
|
|
|
|
'Pin, Red': L.divIcon({
|
|
|
|
className: 'pin-red',
|
|
|
|
iconAnchor: [5, 30]
|
|
|
|
}),
|
2016-12-06 18:22:26 +00:00
|
|
|
'Flag, Green': L.divIcon({
|
|
|
|
className: 'flag-green',
|
|
|
|
iconAnchor: [1, 25]
|
|
|
|
}),
|
|
|
|
'Flag, Red': L.divIcon({
|
|
|
|
className: 'flag-red',
|
|
|
|
iconAnchor: [1, 25]
|
|
|
|
}),
|
|
|
|
'Flag, Blue': L.divIcon({
|
|
|
|
className: 'flag-blue',
|
|
|
|
iconAnchor: [1, 25]
|
|
|
|
}),
|
2016-12-07 13:50:06 +00:00
|
|
|
'Block, Blue': L.divIcon({
|
|
|
|
className: 'block-blue',
|
|
|
|
iconAnchor: [8, 8]
|
|
|
|
}),
|
|
|
|
'Block, Green': L.divIcon({
|
|
|
|
className: 'block-green',
|
|
|
|
iconAnchor: [8, 8]
|
|
|
|
}),
|
|
|
|
'Block, Red': L.divIcon({
|
|
|
|
className: 'block-red',
|
|
|
|
iconAnchor: [8, 8]
|
|
|
|
}),
|
|
|
|
'Blue Diamond': L.divIcon({
|
|
|
|
className: 'diamond-blue',
|
|
|
|
iconAnchor: [9, 9]
|
|
|
|
}),
|
|
|
|
'Green Diamond': L.divIcon({
|
|
|
|
className: 'diamond-green',
|
|
|
|
iconAnchor: [9, 9]
|
|
|
|
}),
|
|
|
|
'Red Diamond': L.divIcon({
|
|
|
|
className: 'diamond-red',
|
|
|
|
iconAnchor: [9, 9]
|
|
|
|
}),
|
2016-12-08 09:23:36 +00:00
|
|
|
'Residence': L.divIcon({
|
|
|
|
className: 'residence',
|
|
|
|
iconAnchor: [12, 12]
|
|
|
|
}),
|
|
|
|
'Drinking Water': L.divIcon({
|
|
|
|
className: 'drinking-water',
|
|
|
|
iconAnchor: [12, 12]
|
|
|
|
}),
|
2016-12-07 16:28:14 +00:00
|
|
|
'Trail Head': L.divIcon({
|
|
|
|
className: 'hike',
|
|
|
|
iconAnchor: [12, 12]
|
|
|
|
}),
|
2016-12-07 13:50:06 +00:00
|
|
|
'Bike Trail': L.divIcon({
|
|
|
|
className: 'bike-trail',
|
|
|
|
iconAnchor: [12, 12]
|
|
|
|
}),
|
2016-12-07 16:28:14 +00:00
|
|
|
'Campground': L.divIcon({
|
|
|
|
className: 'campground',
|
|
|
|
iconAnchor: [12, 12]
|
|
|
|
}),
|
2016-12-07 13:50:06 +00:00
|
|
|
'Bar': L.divIcon({
|
|
|
|
className: 'bar',
|
|
|
|
iconAnchor: [10, 12]
|
|
|
|
}),
|
|
|
|
'Skull and Crossbones': L.divIcon({
|
|
|
|
className: 'skullcross',
|
|
|
|
iconAnchor: [12, 12]
|
|
|
|
}),
|
2016-12-07 16:28:14 +00:00
|
|
|
'Geocache': L.divIcon({
|
|
|
|
className: 'geocache',
|
|
|
|
iconAnchor: [11, 10]
|
|
|
|
}),
|
|
|
|
'Geocache Found': L.divIcon({
|
|
|
|
className: 'geocache-open',
|
|
|
|
iconAnchor: [11, 10]
|
|
|
|
}),
|
|
|
|
'Medical Facility': L.divIcon({
|
|
|
|
className: 'medical',
|
|
|
|
iconAnchor: [13, 11]
|
|
|
|
}),
|
2016-12-10 14:12:27 +00:00
|
|
|
'Contact, Alien': L.divIcon({
|
|
|
|
className: 'contact-alien',
|
|
|
|
iconAnchor: [12, 12]
|
|
|
|
}),
|
|
|
|
'Contact, Big Ears': L.divIcon({
|
|
|
|
className: 'contact-bigears',
|
|
|
|
iconAnchor: [12, 12]
|
|
|
|
}),
|
|
|
|
'Contact, Female3': L.divIcon({
|
|
|
|
className: 'contact-female3',
|
|
|
|
iconAnchor: [12, 12]
|
|
|
|
}),
|
|
|
|
'Contact, Cat': L.divIcon({
|
|
|
|
className: 'contact-cat',
|
|
|
|
iconAnchor: [12, 12]
|
|
|
|
}),
|
|
|
|
'Contact, Dog': L.divIcon({
|
|
|
|
className: 'contact-dog',
|
|
|
|
iconAnchor: [12, 12]
|
|
|
|
}),
|
2016-12-06 18:22:26 +00:00
|
|
|
}
|
|
|
|
|
2016-12-08 11:26:37 +00:00
|
|
|
var hoverStyle = {
|
|
|
|
weight: 12,
|
|
|
|
opacity: 0.7,
|
|
|
|
color: 'black'
|
|
|
|
};
|
|
|
|
var defaultStyle = {
|
|
|
|
opacity: 0.9,
|
|
|
|
color: '#f357a1',
|
|
|
|
weight: 7
|
|
|
|
};
|
|
|
|
|
2016-12-15 03:07:29 +00:00
|
|
|
function endsWith(str, suffix) {
|
|
|
|
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
|
|
|
}
|
|
|
|
|
2016-11-30 19:00:03 +00:00
|
|
|
function load_map() {
|
2016-12-16 01:23:20 +00:00
|
|
|
// change meta to send referrer
|
|
|
|
// usefull for IGN tiles authentication !
|
|
|
|
$('meta[name=referrer]').attr('content', 'origin');
|
|
|
|
|
2016-11-30 19:00:03 +00:00
|
|
|
var layer = getUrlParameter('layer');
|
|
|
|
var default_layer = 'OpenStreetMap';
|
2017-02-01 19:18:56 +00:00
|
|
|
if (gpxedit.restoredTileLayer !== null){
|
|
|
|
default_layer = gpxedit.restoredTileLayer;
|
|
|
|
}
|
|
|
|
else if (typeof layer !== 'undefined'){
|
2016-11-30 19:00:03 +00:00
|
|
|
default_layer = decodeURI(layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// get url from key and layer type
|
|
|
|
function geopUrl (key, layer, format)
|
|
|
|
{ return 'http://wxs.ign.fr/'+ key + '/wmts?LAYER=' + layer
|
|
|
|
+'&EXCEPTIONS=text/xml&FORMAT='+(format?format:'image/jpeg')
|
|
|
|
+'&SERVICE=WMTS&VERSION=1.0.0&REQUEST=GetTile&STYLE=normal'
|
|
|
|
+'&TILEMATRIXSET=PM&TILEMATRIX={z}&TILECOL={x}&TILEROW={y}' ;
|
|
|
|
}
|
2016-12-01 16:04:32 +00:00
|
|
|
// change it if you deploy GPXEDIT
|
2016-11-30 19:00:03 +00:00
|
|
|
var API_KEY = 'ljthe66m795pr2v2g8p7faxt';
|
|
|
|
var ign = new L.tileLayer ( geopUrl(API_KEY,'GEOGRAPHICALGRIDSYSTEMS.MAPS'),
|
|
|
|
{ attribution:'© <a href="http://www.ign.fr/">IGN-France</a>',
|
|
|
|
maxZoom:18
|
|
|
|
});
|
|
|
|
|
|
|
|
var osmUrl = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png';
|
|
|
|
var osmAttribution = 'Map data © 2013 <a href="http://openstreetmap'+
|
|
|
|
'.org">OpenStreetMap</a> contributors';
|
|
|
|
var osm = new L.TileLayer(osmUrl, {maxZoom: 18, attribution: osmAttribution});
|
|
|
|
|
|
|
|
var osmfrUrl = 'http://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png';
|
|
|
|
var osmfr = new L.TileLayer(osmfrUrl,
|
|
|
|
{maxZoom: 20, attribution: osmAttribution});
|
|
|
|
var osmfr2 = new L.TileLayer(osmfrUrl,
|
|
|
|
{minZoom: 0, maxZoom: 13, attribution: osmAttribution});
|
|
|
|
|
|
|
|
var openmapsurferUrl = 'http://openmapsurfer.uni-hd.de/tiles/roads/'+
|
|
|
|
'x={x}&y={y}&z={z}';
|
|
|
|
var openmapsurferAttribution = 'Imagery from <a href="http://giscience.uni'+
|
|
|
|
'-hd.de/">GIScience Research Group @ University of Heidelberg</a> — '+
|
|
|
|
'Map data © <a href="http://www.openstreetmap.org/copyright">'+
|
|
|
|
'OpenStreetMap</a>';
|
|
|
|
var openmapsurfer = new L.TileLayer(openmapsurferUrl,
|
|
|
|
{maxZoom: 18, attribution: openmapsurferAttribution});
|
|
|
|
|
|
|
|
var transportUrl = 'http://a.tile2.opencyclemap.org/transport/{z}/{x}/{y}.'+
|
|
|
|
'png';
|
|
|
|
var transport = new L.TileLayer(transportUrl,
|
|
|
|
{maxZoom: 18, attribution: osmAttribution});
|
|
|
|
|
|
|
|
var pisteUrl = 'http://tiles.openpistemap.org/nocontours/{z}/{x}/{y}.png';
|
|
|
|
var piste = new L.TileLayer(pisteUrl,
|
|
|
|
{maxZoom: 18, attribution: osmAttribution});
|
|
|
|
|
|
|
|
var hikebikeUrl = 'http://toolserver.org/tiles/hikebike/{z}/{x}/{y}.png';
|
|
|
|
var hikebike = new L.TileLayer(hikebikeUrl,
|
|
|
|
{maxZoom: 18, attribution: osmAttribution});
|
|
|
|
|
|
|
|
var osmCycleUrl = 'http://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png';
|
|
|
|
var osmCycleAttrib = '© <a href="http://www.opencyclemap.org">'+
|
|
|
|
'OpenCycleMap</a>, © <a href="http://www.openstreetmap.org/copyright">'+
|
|
|
|
'OpenStreetMap</a>';
|
|
|
|
var osmCycle = new L.TileLayer(osmCycleUrl,
|
|
|
|
{maxZoom: 18, attribution: osmCycleAttrib});
|
|
|
|
|
|
|
|
var darkUrl = 'http://a.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}.png';
|
|
|
|
var darkAttrib = '© Map tiles by CartoDB, under CC BY 3.0. Data by'+
|
|
|
|
' OpenStreetMap, under ODbL.';
|
|
|
|
var dark = new L.TileLayer(darkUrl, {maxZoom: 18, attribution: darkAttrib});
|
|
|
|
|
|
|
|
var esriTopoUrl = 'https://server.arcgisonline.com/ArcGIS/rest/services/World'+
|
|
|
|
'_Topo_Map/MapServer/tile/{z}/{y}/{x}';
|
|
|
|
var esriTopoAttrib = 'Tiles © Esri — Esri, DeLorme, NAVTEQ, '+
|
|
|
|
'TomTom, Intermap, iPC, USGS, FAO, NPS, NRCAN, GeoBase, Kadaster NL, Ord'+
|
|
|
|
'nance Survey, Esri Japan, METI, Esri China (Hong Kong), and the GIS User'+
|
|
|
|
' Community';
|
|
|
|
var esriTopo = new L.TileLayer(esriTopoUrl,
|
|
|
|
{maxZoom: 18, attribution: esriTopoAttrib});
|
|
|
|
|
|
|
|
var esriAerialUrl = 'https://server.arcgisonline.com/ArcGIS/rest/services'+
|
|
|
|
'/World_Imagery/MapServer/tile/{z}/{y}/{x}';
|
|
|
|
var esriAerialAttrib = 'Tiles © Esri — Source: Esri, i-cubed, '+
|
|
|
|
'USDA, USGS, AEX, GeoEye, Getmapping, Aerogrid, IGN, IGP, UPR-EGP, and the'+
|
|
|
|
' GIS User Community';
|
|
|
|
var esriAerial = new L.TileLayer(esriAerialUrl,
|
|
|
|
{maxZoom: 18, attribution: esriAerialAttrib});
|
|
|
|
|
|
|
|
var tonerUrl = 'http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.jpg';
|
|
|
|
var stamenAttribution = '<a href="http://leafletjs.com" title="A JS library'+
|
|
|
|
' for interactive maps">Leaflet</a> | © Map tiles by <a href="http://stamen'+
|
|
|
|
'.com">Stamen Design</a>, under <a href="http://creativecommons.org/license'+
|
|
|
|
's/by/3.0">CC BY 3.0</a>, Data by <a href="http://openstreetmap.org">OpenSt'+
|
|
|
|
'reetMap</a>, under <a href="http://creativecommons.org/licenses/by-sa/3.0"'+
|
|
|
|
'>CC BY SA</a>.';
|
|
|
|
var toner = new L.TileLayer(tonerUrl,
|
|
|
|
{maxZoom: 18, attribution: stamenAttribution});
|
|
|
|
|
|
|
|
var watercolorUrl = 'http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg';
|
|
|
|
var watercolor = new L.TileLayer(watercolorUrl,
|
|
|
|
{maxZoom: 18, attribution: stamenAttribution});
|
|
|
|
|
|
|
|
var routeUrl = 'http://{s}.tile.openstreetmap.fr/route500/{z}/{x}/{y}.png';
|
|
|
|
var routeAttrib = '©, Tiles © <a href="http://www.openstreetmap.fr">O'+
|
|
|
|
'penStreetMap France</a>';
|
|
|
|
var route = new L.TileLayer(routeUrl,
|
|
|
|
{minZoom: 1, maxZoom: 20, attribution: routeAttrib});
|
|
|
|
|
|
|
|
var baseLayers = {
|
|
|
|
'OpenStreetMap': osm,
|
|
|
|
'OpenCycleMap': osmCycle,
|
|
|
|
'IGN France': ign,
|
|
|
|
'OpenMapSurfer Roads': openmapsurfer,
|
|
|
|
'Hike & bike': hikebike,
|
|
|
|
'OSM Transport': transport,
|
|
|
|
'ESRI Aerial': esriAerial,
|
|
|
|
'ESRI Topo with relief': esriTopo,
|
|
|
|
'Dark' : dark,
|
|
|
|
'Toner' : toner,
|
|
|
|
'Watercolor' : watercolor,
|
|
|
|
'OpenStreetMap France': osmfr
|
|
|
|
};
|
2016-12-06 14:12:40 +00:00
|
|
|
// add custom layers
|
|
|
|
$('#tileserverlist li').each(function(){
|
|
|
|
var sname = $(this).attr('name');
|
|
|
|
var surl = $(this).attr('title');
|
|
|
|
baseLayers[sname] = new L.TileLayer(surl,
|
|
|
|
{maxZoom: 18, attribution: 'custom tile server'});
|
|
|
|
});
|
2016-11-30 19:00:03 +00:00
|
|
|
gpxedit.baseLayers = baseLayers;
|
|
|
|
var baseOverlays = {
|
|
|
|
'OsmFr Route500': route,
|
|
|
|
'OpenPisteMap Relief':
|
|
|
|
L.tileLayer('http://tiles2.openpistemap.org/landshaded/{z}/{x}/{y}.png',
|
|
|
|
{
|
|
|
|
attribution: '©, Tiles © <a href="http://www.o'+
|
|
|
|
'penstreetmap.fr">OpenStreetMap France</a>',
|
|
|
|
minZoom: 1,
|
|
|
|
maxZoom: 15
|
|
|
|
}
|
|
|
|
),
|
|
|
|
'OpenPisteMap pistes' : piste
|
|
|
|
};
|
|
|
|
|
|
|
|
var layerlist = [];
|
|
|
|
|
|
|
|
gpxedit.map = new L.Map('map', {
|
|
|
|
zoomControl: true,
|
|
|
|
layers: layerlist,
|
|
|
|
});
|
|
|
|
|
|
|
|
L.control.scale({metric: true, imperial: true, position:'topleft'})
|
|
|
|
.addTo(gpxedit.map);
|
|
|
|
|
|
|
|
L.control.mousePosition().addTo(gpxedit.map);
|
|
|
|
gpxedit.searchControl = L.Control.geocoder({position:'topleft'});
|
|
|
|
gpxedit.searchControl.addTo(gpxedit.map);
|
|
|
|
gpxedit.locateControl = L.control.locate({follow:true});
|
|
|
|
gpxedit.locateControl.addTo(gpxedit.map);
|
|
|
|
L.Control.measureControl().addTo(gpxedit.map);
|
|
|
|
L.control.sidebar('sidebar').addTo(gpxedit.map);
|
|
|
|
|
|
|
|
gpxedit.map.setView(new L.LatLng(27, 5), 3);
|
|
|
|
|
|
|
|
if (! baseLayers.hasOwnProperty(default_layer)){
|
|
|
|
default_layer = 'OpenStreetMap';
|
|
|
|
}
|
|
|
|
gpxedit.map.addLayer(baseLayers[default_layer]);
|
|
|
|
|
|
|
|
gpxedit.activeLayers = L.control.activeLayers(baseLayers, baseOverlays);
|
|
|
|
gpxedit.activeLayers.addTo(gpxedit.map);
|
|
|
|
|
|
|
|
gpxedit.minimapControl = new L.Control.MiniMap(
|
|
|
|
osmfr2,
|
2016-12-01 16:04:32 +00:00
|
|
|
{ toggleDisplay: true, position:'bottomright' }
|
2016-11-30 19:00:03 +00:00
|
|
|
).addTo(gpxedit.map);
|
|
|
|
gpxedit.minimapControl._toggleDisplayButtonClicked();
|
|
|
|
|
2016-12-01 00:30:19 +00:00
|
|
|
gpxedit.editableLayers = new L.FeatureGroup();
|
|
|
|
gpxedit.map.addLayer(gpxedit.editableLayers);
|
2016-11-30 19:00:03 +00:00
|
|
|
|
|
|
|
var options = {
|
2016-12-01 16:04:32 +00:00
|
|
|
position: 'bottomleft',
|
2016-11-30 19:00:03 +00:00
|
|
|
draw: {
|
|
|
|
polyline: {
|
|
|
|
shapeOptions: {
|
|
|
|
color: '#f357a1',
|
|
|
|
weight: 7
|
|
|
|
}
|
|
|
|
},
|
|
|
|
polygon:false,
|
|
|
|
circle: false,
|
|
|
|
rectangle:false,
|
|
|
|
marker: {
|
2016-12-08 11:07:30 +00:00
|
|
|
icon: symbolIcons['marker']
|
2016-11-30 19:00:03 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
edit: {
|
2016-12-01 00:30:19 +00:00
|
|
|
featureGroup: gpxedit.editableLayers, //REQUIRED!!
|
2016-11-30 19:00:03 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-12-14 18:15:40 +00:00
|
|
|
L.drawLocal.draw.toolbar.buttons.polyline = t('gpxedit','Draw a track');
|
|
|
|
L.drawLocal.draw.toolbar.buttons.marker = t('gpxedit','Add a waypoint');
|
|
|
|
L.drawLocal.edit.toolbar.buttons.edit = t('gpxedit','Edit');
|
|
|
|
L.drawLocal.edit.toolbar.buttons.editDisabled = t('gpxedit','Nothing to edit');
|
|
|
|
L.drawLocal.edit.toolbar.buttons.remove = t('gpxedit','Delete');
|
|
|
|
L.drawLocal.edit.toolbar.buttons.removeDisabled = t('gpxedit','Nothing to delete');
|
|
|
|
L.drawLocal.edit.toolbar.actions.save.title = t('gpxedit','Validate changes');
|
|
|
|
L.drawLocal.edit.toolbar.actions.save.text = t('gpxedit','Ok');
|
|
|
|
L.drawLocal.edit.toolbar.actions.cancel.title = t('gpxedit','Discard all changes');
|
|
|
|
L.drawLocal.edit.toolbar.actions.cancel.text = t('gpxedit','Cancel');
|
|
|
|
L.drawLocal.edit.handlers.edit.tooltip.text = t('gpxedit','Drag to move elements,<br/>click to remove a point');
|
|
|
|
L.drawLocal.edit.handlers.edit.tooltip.subtext = t('gpxedit','Click cancel to undo changes');
|
|
|
|
L.drawLocal.edit.handlers.remove.tooltip.text = t('gpxedit','Click on an element to delete it');
|
|
|
|
L.drawLocal.draw.handlers.marker.tooltip.start = t('gpxedit','Click map to add waypoint');
|
|
|
|
L.drawLocal.draw.handlers.polyline.tooltip.start = t('gpxedit','Click to start drawing track');
|
|
|
|
L.drawLocal.draw.handlers.polyline.tooltip.cont = t('gpxedit','Click to continue drawing track');
|
|
|
|
L.drawLocal.draw.handlers.polyline.tooltip.end = t('gpxedit','Click last point to finish track');
|
|
|
|
L.drawLocal.draw.toolbar.actions.text = t('gpxedit','Cancel');
|
|
|
|
L.drawLocal.draw.toolbar.actions.title = t('gpxedit','Cancel drawing');
|
|
|
|
L.drawLocal.draw.toolbar.finish.text = t('gpxedit','Finish');
|
|
|
|
L.drawLocal.draw.toolbar.finish.title = t('gpxedit','Finish drawing');
|
|
|
|
L.drawLocal.draw.toolbar.undo.text = t('gpxedit','Delete last point');
|
|
|
|
L.drawLocal.draw.toolbar.undo.title = t('gpxedit','Delete last point drawn');
|
2016-11-30 19:00:03 +00:00
|
|
|
var drawControl = new L.Control.Draw(options);
|
2016-12-06 15:23:14 +00:00
|
|
|
gpxedit.drawControl = drawControl;
|
2016-11-30 19:00:03 +00:00
|
|
|
gpxedit.map.addControl(drawControl);
|
|
|
|
|
2016-12-01 14:56:40 +00:00
|
|
|
// when something is created, we generate popup content
|
|
|
|
// and initialize layer data
|
2016-11-30 19:00:03 +00:00
|
|
|
gpxedit.map.on(L.Draw.Event.CREATED, function (e) {
|
2016-12-01 01:09:26 +00:00
|
|
|
onCreated(e.layerType, e.layer);
|
2016-11-30 19:00:03 +00:00
|
|
|
});
|
2016-12-01 14:56:40 +00:00
|
|
|
// not used for the moment
|
2016-11-30 19:00:03 +00:00
|
|
|
gpxedit.map.on('draw:edited', function (e) {
|
|
|
|
var layers = e.layers;
|
|
|
|
layers.eachLayer(function (layer) {
|
|
|
|
});
|
|
|
|
});
|
2016-12-01 14:56:40 +00:00
|
|
|
// remove data associated with the deleted layer
|
2016-11-30 19:00:03 +00:00
|
|
|
gpxedit.map.on('draw:deleted', function (e) {
|
|
|
|
var layers = e.layers;
|
|
|
|
layers.eachLayer(function (layer) {
|
|
|
|
delete gpxedit.layersData[layer.gpxedit_id];
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2016-12-01 14:56:40 +00:00
|
|
|
// load data into popup when it opens
|
|
|
|
// this is needed because popup content is created each time we open one
|
|
|
|
// so, the content is lost when it's closed
|
2016-11-30 19:00:03 +00:00
|
|
|
gpxedit.map.on('popupopen', function(e){
|
2016-12-08 10:01:45 +00:00
|
|
|
var id = e.popup._source.gpxedit_id;
|
|
|
|
//var id = parseInt(e.popup.getContent().match(/layerid="(\d+)"/)[1]);
|
2016-11-30 19:00:03 +00:00
|
|
|
var buttonParent = $('button.popupOkButton[layerid='+id+']').parent();
|
|
|
|
buttonParent.find('input.layerName').val(gpxedit.layersData[id].name);
|
|
|
|
buttonParent.find('textarea.layerDesc').val(gpxedit.layersData[id].description);
|
|
|
|
buttonParent.find('textarea.layerCmt').val(gpxedit.layersData[id].comment);
|
2016-12-08 10:01:45 +00:00
|
|
|
if (gpxedit.layersData[id].layer.type === 'marker'){
|
2016-12-19 22:45:13 +00:00
|
|
|
if (symbolIcons.hasOwnProperty(gpxedit.layersData[id].symbol)){
|
|
|
|
buttonParent.find('select[role=symbol]').val(gpxedit.layersData[id].symbol);
|
|
|
|
}
|
|
|
|
else if(gpxedit.layersData[id].symbol === ''){
|
|
|
|
buttonParent.find('select[role=symbol]').val('');
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
buttonParent.find('select[role=symbol]').val('unknown');
|
|
|
|
}
|
2016-12-08 10:01:45 +00:00
|
|
|
buttonParent.find('select[role=symbol]').change();
|
2017-01-20 14:03:24 +00:00
|
|
|
var latlng = gpxedit.layersData[id].layer.getLatLng();
|
2017-01-20 14:12:29 +00:00
|
|
|
buttonParent.find('input.layerLat').val(latlng.lat.toFixed(6));
|
|
|
|
buttonParent.find('input.layerLon').val(latlng.lng.toFixed(6));
|
2016-12-08 10:01:45 +00:00
|
|
|
}
|
2016-11-30 19:00:03 +00:00
|
|
|
});
|
|
|
|
|
2017-02-01 19:18:56 +00:00
|
|
|
gpxedit.map.on('baselayerchange',saveOptions);
|
|
|
|
|
2016-11-30 19:00:03 +00:00
|
|
|
}
|
|
|
|
|
2016-12-01 14:56:40 +00:00
|
|
|
// called when something is drawn by hand or when a gpx is loaded
|
|
|
|
// 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)
|
2016-12-01 01:09:26 +00:00
|
|
|
function onCreated(type, layer){
|
2016-12-08 11:07:30 +00:00
|
|
|
var popupTitle;
|
|
|
|
var layerType;
|
|
|
|
if (type === 'polyline' || type === 'track'){
|
2016-12-15 18:22:45 +00:00
|
|
|
popupTitle = t('gpxedit', 'Track');
|
2016-12-08 11:07:30 +00:00
|
|
|
layerType = 'track';
|
|
|
|
}
|
|
|
|
else if (type === 'route') {
|
2016-12-15 18:22:45 +00:00
|
|
|
popupTitle = t('gpxedit', 'Route');
|
2016-12-08 11:07:30 +00:00
|
|
|
layerType = 'route';
|
|
|
|
}
|
|
|
|
else if (type === 'marker') {
|
2016-12-15 18:22:45 +00:00
|
|
|
popupTitle = t('gpxedit', 'Waypoint');
|
2016-12-08 11:07:30 +00:00
|
|
|
layerType = 'marker';
|
|
|
|
}
|
2016-12-01 01:09:26 +00:00
|
|
|
|
2016-12-08 11:07:30 +00:00
|
|
|
var popupTxt = '<h2 class="popupTitle">'+popupTitle+'</h2><table class="popupdatatable">'+
|
2016-12-15 18:22:45 +00:00
|
|
|
'<tr><td>'+t('gpxedit', 'Name')+'</td><td><input class="layerName"></input></td></tr>'+
|
|
|
|
'<tr><td>'+t('gpxedit', 'Description')+'</td><td><textarea class="layerDesc"></textarea></td></tr>'+
|
|
|
|
'<tr><td>'+t('gpxedit', 'Comment')+'</td><td><textarea class="layerCmt"></textarea></td></tr>';
|
2016-12-08 11:07:30 +00:00
|
|
|
if (type === 'marker') {
|
2017-01-20 14:03:24 +00:00
|
|
|
popupTxt = popupTxt + '<tr><td>'+t('gpxedit', 'Lat')+'</td><td><input class="layerLat"></input></td></tr>';
|
|
|
|
popupTxt = popupTxt + '<tr><td>'+t('gpxedit', 'Lon')+'</td><td><input class="layerLon"></input></td></tr>';
|
2016-12-15 18:22:45 +00:00
|
|
|
popupTxt = popupTxt + '<tr><td>'+t('gpxedit', 'Symbol')+'</td><td><select role="symbol">';
|
|
|
|
popupTxt = popupTxt + '<option value="">'+t('gpxedit', 'No symbol')+'</option>';
|
2016-12-19 22:45:13 +00:00
|
|
|
popupTxt = popupTxt + '<option value="unknown">'+t('gpxedit', 'Unknown symbol')+'</option>';
|
2016-12-08 11:07:30 +00:00
|
|
|
for (var cl in symbolIcons){
|
|
|
|
if (cl !== 'marker'){
|
|
|
|
popupTxt = popupTxt + '<option value="'+cl+'">'+cl+'</option>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
popupTxt = popupTxt + '</select></td></tr>';
|
|
|
|
}
|
|
|
|
popupTxt = popupTxt + '</table>';
|
|
|
|
popupTxt = popupTxt + '<button class="popupOkButton" layerid="'+gpxedit.id+'">OK</button>';
|
2016-12-06 19:28:29 +00:00
|
|
|
|
2016-12-08 11:07:30 +00:00
|
|
|
layer.bindPopup(popupTxt);
|
2016-12-08 11:26:37 +00:00
|
|
|
if (type !== 'marker') {
|
|
|
|
layer.on('mouseover', function(){
|
|
|
|
layer.setStyle(hoverStyle);
|
|
|
|
});
|
|
|
|
layer.on('mouseout', function(){
|
|
|
|
layer.setStyle(defaultStyle);
|
|
|
|
});
|
|
|
|
}
|
2016-12-01 01:09:26 +00:00
|
|
|
|
2016-12-08 11:07:30 +00:00
|
|
|
layer.gpxedit_id = gpxedit.id;
|
|
|
|
layer.type = layerType;
|
2016-12-12 13:36:49 +00:00
|
|
|
gpxedit.layersData[gpxedit.id] = {
|
|
|
|
name:'',
|
|
|
|
description:'',
|
|
|
|
comment:'',
|
|
|
|
symbol:'',
|
|
|
|
time: '',
|
|
|
|
layer: layer
|
|
|
|
};
|
2016-12-08 11:07:30 +00:00
|
|
|
gpxedit.editableLayers.addLayer(layer);
|
|
|
|
gpxedit.id++;
|
|
|
|
return layer;
|
2016-12-01 01:09:26 +00:00
|
|
|
}
|
|
|
|
|
2016-11-30 19:00:03 +00:00
|
|
|
function getUrlParameter(sParam)
|
|
|
|
{
|
|
|
|
var sPageURL = window.location.search.substring(1);
|
|
|
|
var sURLVariables = sPageURL.split('&');
|
|
|
|
for (var i = 0; i < sURLVariables.length; i++)
|
|
|
|
{
|
|
|
|
var sParameterName = sURLVariables[i].split('=');
|
|
|
|
if (sParameterName[0] === sParam)
|
|
|
|
{
|
|
|
|
return sParameterName[1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-01 14:56:40 +00:00
|
|
|
// generate gpx text from current map elements
|
2016-12-01 00:30:19 +00:00
|
|
|
function generateGpx(){
|
|
|
|
var gpxText = '<?xml version="1.0" encoding="UTF-8" standalone="no" ?>\n';
|
|
|
|
var now = new Date();
|
|
|
|
var now_utc_str = now.getUTCFullYear()+'-'+
|
|
|
|
("0" + now.getUTCMonth()).slice(-2)+'-'+
|
|
|
|
("0" + now.getUTCDate()).slice(-2)+'T'+
|
|
|
|
("0" + now.getUTCHours()).slice(-2)+':'+
|
|
|
|
("0" + now.getUTCMinutes()).slice(-2)+':'+
|
|
|
|
("0" + now.getUTCSeconds()).slice(-2)+'Z';
|
2016-12-05 12:00:46 +00:00
|
|
|
gpxText = gpxText + '<gpx xmlns="http://www.topografix.com/GPX/1/1"'+
|
|
|
|
' xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3"'+
|
|
|
|
' xmlns:wptx1="http://www.garmin.com/xmlschemas/WaypointExtension/v1"'+
|
|
|
|
' xmlns:gpxtpx="http://www.garmin.com/xmlschemas/TrackPointExtension/v1"'+
|
2016-12-05 12:19:46 +00:00
|
|
|
' creator="GpxEdit Owncloud/Nextcloud app '+
|
|
|
|
$('#versionnumber').text().replace(/\s+/g,'')+'" version="1.1"'+
|
2016-12-05 12:00:46 +00:00
|
|
|
' xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"'+
|
|
|
|
' xsi:schemaLocation="http://www.topografix.com/GPX/1/1'+
|
|
|
|
' http://www.topografix.com/GPX/1/1/gpx.xsd'+
|
|
|
|
' http://www.garmin.com/xmlschemas/GpxExtensions/v3'+
|
|
|
|
' http://www8.garmin.com/xmlschemas/GpxExtensionsv3.xsd'+
|
|
|
|
' http://www.garmin.com/xmlschemas/WaypointExtension/v1'+
|
|
|
|
' http://www8.garmin.com/xmlschemas/WaypointExtensionv1.xsd'+
|
|
|
|
' http://www.garmin.com/xmlschemas/TrackPointExtension/v1'+
|
|
|
|
' http://www.garmin.com/xmlschemas/TrackPointExtensionv1.xsd">\n';
|
2016-12-12 14:28:15 +00:00
|
|
|
gpxText = gpxText + '<metadata>\n <time>'+now_utc_str+'</time>\n';
|
|
|
|
var fileDesc = $('#desctext').val();
|
|
|
|
if (fileDesc){
|
|
|
|
gpxText = gpxText + ' <desc>'+fileDesc+'</desc>\n';
|
|
|
|
}
|
|
|
|
gpxText = gpxText + '</metadata>\n';
|
2016-12-01 00:30:19 +00:00
|
|
|
|
|
|
|
gpxedit.editableLayers.eachLayer(function(layer){
|
|
|
|
var id = layer.gpxedit_id;
|
|
|
|
var name = gpxedit.layersData[id].name;
|
|
|
|
var comment = gpxedit.layersData[id].comment;
|
|
|
|
var description = gpxedit.layersData[id].description;
|
2016-12-12 13:36:49 +00:00
|
|
|
var time = gpxedit.layersData[id].time;
|
2016-12-01 00:30:19 +00:00
|
|
|
if (layer.type === 'marker'){
|
2016-12-06 23:40:41 +00:00
|
|
|
var symbol = gpxedit.layersData[id].symbol;
|
2016-12-01 00:30:19 +00:00
|
|
|
var lat = layer._latlng.lat;
|
|
|
|
var lng = layer._latlng.lng;
|
2016-12-05 12:09:28 +00:00
|
|
|
var alt = layer._latlng.alt;
|
2016-12-01 00:30:19 +00:00
|
|
|
gpxText = gpxText + ' <wpt lat="'+lat+'" lon="'+lng+'">\n';
|
|
|
|
if (name){
|
|
|
|
gpxText = gpxText + ' <name>'+name+'</name>\n';
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
gpxText = gpxText + ' <name>unnamed</name>\n';
|
|
|
|
}
|
2016-12-05 12:09:28 +00:00
|
|
|
if (alt !== undefined){
|
|
|
|
gpxText = gpxText + ' <ele>'+alt+'</ele>\n';
|
|
|
|
}
|
2016-12-01 00:30:19 +00:00
|
|
|
if (comment){
|
|
|
|
gpxText = gpxText + ' <cmt>'+comment+'</cmt>\n';
|
|
|
|
}
|
2016-12-06 23:40:41 +00:00
|
|
|
if (symbol){
|
|
|
|
gpxText = gpxText + ' <sym>'+symbol+'</sym>\n';
|
|
|
|
}
|
2016-12-01 00:30:19 +00:00
|
|
|
if (description){
|
|
|
|
gpxText = gpxText + ' <desc>'+description+'</desc>\n';
|
|
|
|
}
|
2016-12-12 13:36:49 +00:00
|
|
|
if (time){
|
|
|
|
gpxText = gpxText + ' <time>'+time+'</time>\n';
|
|
|
|
}
|
2016-12-01 00:30:19 +00:00
|
|
|
gpxText = gpxText + ' </wpt>\n';
|
|
|
|
}
|
2016-12-08 11:07:30 +00:00
|
|
|
else if(layer.type === 'track'){
|
2016-12-01 00:30:19 +00:00
|
|
|
gpxText = gpxText + ' <trk>\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';
|
|
|
|
}
|
|
|
|
gpxText = gpxText + ' <trkseg>\n';
|
|
|
|
for (var i=0; i<layer._latlngs.length; i++){
|
|
|
|
var lat = layer._latlngs[i].lat;
|
|
|
|
var lng = layer._latlngs[i].lng;
|
2016-12-05 12:00:46 +00:00
|
|
|
var alt = layer._latlngs[i].alt;
|
2016-12-12 13:36:49 +00:00
|
|
|
var time = layer._latlngs[i].time;
|
2016-12-05 12:00:46 +00:00
|
|
|
gpxText = gpxText + ' <trkpt lat="'+lat+'" lon="'+lng+'">\n';
|
2016-12-16 01:49:51 +00:00
|
|
|
if (time){
|
2016-12-12 13:36:49 +00:00
|
|
|
gpxText = gpxText + ' <time>'+time+'</time>\n';
|
|
|
|
}
|
2016-12-05 12:00:46 +00:00
|
|
|
if (alt !== undefined){
|
|
|
|
gpxText = gpxText + ' <ele>'+alt+'</ele>\n';
|
|
|
|
}
|
|
|
|
gpxText = gpxText + ' </trkpt>\n';
|
2016-12-01 00:30:19 +00:00
|
|
|
}
|
2016-12-01 01:09:26 +00:00
|
|
|
gpxText = gpxText + ' </trkseg>\n </trk>\n';
|
2016-12-01 00:30:19 +00:00
|
|
|
}
|
2016-12-08 11:07:30 +00:00
|
|
|
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;
|
2016-12-12 13:36:49 +00:00
|
|
|
var time = layer._latlngs[i].time;
|
2016-12-08 11:07:30 +00:00
|
|
|
gpxText = gpxText + ' <rtept lat="'+lat+'" lon="'+lng+'">\n';
|
2016-12-12 13:36:49 +00:00
|
|
|
if (time !== undefined){
|
|
|
|
gpxText = gpxText + ' <time>'+time+'</time>\n';
|
|
|
|
}
|
2016-12-08 11:07:30 +00:00
|
|
|
if (alt !== undefined){
|
|
|
|
gpxText = gpxText + ' <ele>'+alt+'</ele>\n';
|
|
|
|
}
|
|
|
|
gpxText = gpxText + ' </rtept>\n';
|
|
|
|
}
|
|
|
|
gpxText = gpxText + ' </rte>\n';
|
|
|
|
}
|
2016-12-01 00:30:19 +00:00
|
|
|
});
|
|
|
|
gpxText = gpxText + ' <extensions/>\n</gpx>';
|
|
|
|
return gpxText;
|
|
|
|
}
|
|
|
|
|
2016-12-01 14:56:40 +00:00
|
|
|
// adds a marker and initialize its data
|
2016-12-12 13:36:49 +00:00
|
|
|
function drawMarker(latlng, name, desc, cmt, sym, time){
|
2016-12-06 15:23:14 +00:00
|
|
|
var wst = $('#markerstyleselect').val();
|
2016-12-06 18:33:13 +00:00
|
|
|
var tst = $('#tooltipstyleselect').val();
|
2016-12-06 18:22:26 +00:00
|
|
|
var symboo = $('#symboloverwrite').is(':checked');
|
|
|
|
var m = L.marker(latlng);
|
|
|
|
if (symboo && sym !== '' && symbolIcons.hasOwnProperty(sym)){
|
|
|
|
m.setIcon(symbolIcons[sym]);
|
|
|
|
}
|
2016-12-19 22:45:13 +00:00
|
|
|
else if(symboo && sym !== ''){
|
|
|
|
m.setIcon(L.divIcon({
|
|
|
|
className: 'unknown',
|
|
|
|
iconAnchor: [12, 12]
|
|
|
|
}));
|
|
|
|
}
|
2016-12-07 14:12:29 +00:00
|
|
|
else{
|
|
|
|
m.setIcon(symbolIcons[wst]);
|
2016-12-06 15:23:14 +00:00
|
|
|
}
|
2016-12-01 14:56:40 +00:00
|
|
|
var layer = onCreated('marker', m);
|
2016-12-06 15:23:14 +00:00
|
|
|
if (name !== ''){
|
2016-12-06 18:33:13 +00:00
|
|
|
if (tst === 'p'){
|
2016-12-06 15:23:14 +00:00
|
|
|
m.bindTooltip(name, {permanent:true});
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
m.bindTooltip(name, {sticky:true});
|
|
|
|
}
|
|
|
|
}
|
2016-12-01 14:56:40 +00:00
|
|
|
gpxedit.layersData[layer.gpxedit_id].name = name;
|
|
|
|
gpxedit.layersData[layer.gpxedit_id].comment = cmt;
|
|
|
|
gpxedit.layersData[layer.gpxedit_id].description = desc;
|
2016-12-06 18:22:26 +00:00
|
|
|
gpxedit.layersData[layer.gpxedit_id].symbol = sym;
|
2016-12-12 13:36:49 +00:00
|
|
|
gpxedit.layersData[layer.gpxedit_id].time = time;
|
2016-12-01 14:56:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// adds a polyline and initialize its data
|
2016-12-12 13:36:49 +00:00
|
|
|
function drawLine(latlngs, name, desc, cmt, gpxtype, times){
|
2016-12-06 15:23:14 +00:00
|
|
|
var wst = $('#markerstyleselect').val();
|
2016-12-06 18:33:13 +00:00
|
|
|
var tst = $('#tooltipstyleselect').val();
|
2016-12-01 14:56:40 +00:00
|
|
|
var p = L.polyline(latlngs, {
|
|
|
|
color: '#f357a1',
|
|
|
|
weight: 7
|
|
|
|
});
|
2016-12-12 13:36:49 +00:00
|
|
|
if (times.length === p._latlngs.length){
|
|
|
|
for (var i=0; i<times.length; i++){
|
2016-12-16 01:49:51 +00:00
|
|
|
if (times[i]){
|
|
|
|
p._latlngs[i].time = times[i];
|
|
|
|
}
|
2016-12-12 13:36:49 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-08 11:07:30 +00:00
|
|
|
var layer = onCreated(gpxtype, p);
|
2016-12-06 15:23:14 +00:00
|
|
|
if (name !== ''){
|
2016-12-06 18:33:13 +00:00
|
|
|
if (tst === 'p'){
|
2016-12-06 15:23:14 +00:00
|
|
|
p.bindTooltip(name, {permanent:true});
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
p.bindTooltip(name, {sticky:true});
|
|
|
|
}
|
|
|
|
}
|
2016-12-01 14:56:40 +00:00
|
|
|
gpxedit.layersData[layer.gpxedit_id].name = name;
|
|
|
|
gpxedit.layersData[layer.gpxedit_id].comment = cmt;
|
|
|
|
gpxedit.layersData[layer.gpxedit_id].description = desc;
|
|
|
|
}
|
|
|
|
|
|
|
|
// parse gpx xml text to draw it on the map
|
|
|
|
function parseGpx(xml){
|
2016-12-06 12:35:03 +00:00
|
|
|
//var dom = $.parseXML(xml);
|
|
|
|
var dom = $(xml);
|
2016-12-12 14:28:15 +00:00
|
|
|
var fileDesc = dom.find('>metadata>desc').text();
|
|
|
|
$('#desctext').val(fileDesc);
|
2016-12-06 12:35:03 +00:00
|
|
|
dom.find('wpt').each(function(){
|
2016-12-01 14:56:40 +00:00
|
|
|
var lat = $(this).attr('lat');
|
|
|
|
var lon = $(this).attr('lon');
|
|
|
|
var name = $(this).find('name').text();
|
|
|
|
var cmt = $(this).find('cmt').text();
|
|
|
|
var desc = $(this).find('desc').text();
|
2016-12-06 18:22:26 +00:00
|
|
|
var sym = $(this).find('sym').text();
|
2016-12-05 12:09:28 +00:00
|
|
|
var ele = $(this).find('ele').text();
|
2016-12-12 13:36:49 +00:00
|
|
|
var time = $(this).find('time').text();
|
2016-12-05 12:09:28 +00:00
|
|
|
if (ele !== ''){
|
2016-12-12 13:36:49 +00:00
|
|
|
drawMarker([lat, lon, ele], name, desc, cmt, sym, time);
|
2016-12-05 12:09:28 +00:00
|
|
|
}
|
|
|
|
else{
|
2016-12-12 13:36:49 +00:00
|
|
|
drawMarker([lat, lon], name, desc, cmt, sym, time);
|
2016-12-05 12:09:28 +00:00
|
|
|
}
|
2016-12-01 14:56:40 +00:00
|
|
|
});
|
2016-12-06 12:35:03 +00:00
|
|
|
dom.find('trk').each(function(){
|
2016-12-01 14:56:40 +00:00
|
|
|
var latlngs = [];
|
2016-12-08 09:46:36 +00:00
|
|
|
var name = $(this).find('>name').text();
|
|
|
|
var cmt = $(this).find('>cmt').text();
|
|
|
|
var desc = $(this).find('>desc').text();
|
2016-12-12 13:36:49 +00:00
|
|
|
var times = [];
|
2016-12-01 14:56:40 +00:00
|
|
|
$(this).find('trkseg').each(function(){
|
|
|
|
$(this).find('trkpt').each(function(){
|
|
|
|
var lat = $(this).attr('lat');
|
|
|
|
var lon = $(this).attr('lon');
|
2016-12-05 12:00:46 +00:00
|
|
|
var ele = $(this).find('ele').text();
|
2016-12-12 13:36:49 +00:00
|
|
|
var time = $(this).find('time').text();
|
|
|
|
times.push(time);
|
2016-12-05 12:00:46 +00:00
|
|
|
if (ele !== ''){
|
|
|
|
latlngs.push([lat,lon,ele]);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
latlngs.push([lat,lon]);
|
|
|
|
}
|
2016-12-01 14:56:40 +00:00
|
|
|
});
|
|
|
|
});
|
2016-12-12 13:36:49 +00:00
|
|
|
drawLine(latlngs, name, desc, cmt, 'track', times);
|
2016-12-01 14:56:40 +00:00
|
|
|
});
|
2016-12-08 09:46:36 +00:00
|
|
|
dom.find('rte').each(function(){
|
|
|
|
var latlngs = [];
|
|
|
|
var name = $(this).find('>name').text();
|
|
|
|
var cmt = $(this).find('>cmt').text();
|
|
|
|
var desc = $(this).find('>desc').text();
|
2016-12-12 13:36:49 +00:00
|
|
|
var times = [];
|
2016-12-08 09:46:36 +00:00
|
|
|
$(this).find('rtept').each(function(){
|
|
|
|
var lat = $(this).attr('lat');
|
|
|
|
var lon = $(this).attr('lon');
|
|
|
|
var ele = $(this).find('ele').text();
|
2016-12-12 13:36:49 +00:00
|
|
|
var time = $(this).find('time').text();
|
|
|
|
times.push(time);
|
2016-12-08 09:46:36 +00:00
|
|
|
if (ele !== ''){
|
|
|
|
latlngs.push([lat,lon,ele]);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
latlngs.push([lat,lon]);
|
|
|
|
}
|
|
|
|
});
|
2016-12-12 13:36:49 +00:00
|
|
|
drawLine(latlngs, name, desc, cmt, 'route', times);
|
2016-12-08 09:46:36 +00:00
|
|
|
});
|
2016-12-01 14:56:40 +00:00
|
|
|
}
|
|
|
|
|
2016-12-01 18:38:50 +00:00
|
|
|
// remove layers from map and delete all layers data
|
|
|
|
function clear(){
|
|
|
|
var layersToRemove = [];
|
|
|
|
gpxedit.editableLayers.eachLayer(function (layer) {
|
2016-12-06 15:23:14 +00:00
|
|
|
layer.unbindTooltip();
|
2016-12-01 18:38:50 +00:00
|
|
|
delete gpxedit.layersData[layer.gpxedit_id];
|
|
|
|
layersToRemove.push(layer);
|
|
|
|
});
|
|
|
|
|
|
|
|
for(var i=0; i<layersToRemove.length; i++){
|
|
|
|
gpxedit.editableLayers.removeLayer(layersToRemove[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-01 16:04:32 +00:00
|
|
|
/*
|
|
|
|
* get key events
|
|
|
|
*/
|
|
|
|
function checkKey(e){
|
|
|
|
e = e || window.event;
|
|
|
|
var kc = e.keyCode;
|
|
|
|
console.log(kc);
|
|
|
|
|
|
|
|
if (kc === 161 || kc === 223){
|
|
|
|
e.preventDefault();
|
|
|
|
gpxedit.minimapControl._toggleDisplayButtonClicked();
|
|
|
|
}
|
|
|
|
if (kc === 60 || kc === 220){
|
|
|
|
e.preventDefault();
|
|
|
|
$('#sidebar').toggleClass('collapsed');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-15 18:22:45 +00:00
|
|
|
function showSaveFailAnimation(path, message){
|
|
|
|
$('#failed').find('b#content').html(t('gpxedit', 'Failed to save file')+' '+path+'<br/>'+message);
|
2016-12-02 14:31:45 +00:00
|
|
|
$('#failed').fadeIn();
|
2016-12-15 18:22:45 +00:00
|
|
|
setTimeout(hideFailedAnimation, 4000);
|
2016-12-02 14:31:45 +00:00
|
|
|
}
|
|
|
|
|
2016-12-15 18:22:45 +00:00
|
|
|
function showFailAnimation(message){
|
|
|
|
$('#failed').find('b#content').html(message);
|
|
|
|
$('#failed').fadeIn();
|
|
|
|
setTimeout(hideFailedAnimation, 4000);
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideFailedAnimation(){
|
2016-12-02 14:31:45 +00:00
|
|
|
$('#failed').fadeOut();
|
|
|
|
}
|
|
|
|
|
2016-12-01 23:00:01 +00:00
|
|
|
function showSaveSuccessAnimation(path){
|
2016-12-15 18:22:45 +00:00
|
|
|
$('#saved').find('b#content').html(t('gpxedit', 'File successfully saved as')+'<br/>'+path);
|
2016-12-02 09:51:27 +00:00
|
|
|
$('#saved').fadeIn();
|
2016-12-01 18:38:50 +00:00
|
|
|
setTimeout(hideSaveSuccessAnimation, 4000);
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideSaveSuccessAnimation(){
|
2016-12-02 09:51:27 +00:00
|
|
|
$('#saved').fadeOut();
|
2016-12-01 18:38:50 +00:00
|
|
|
}
|
|
|
|
|
2016-12-27 17:04:47 +00:00
|
|
|
function showLoadingAnimation(){
|
|
|
|
$('#loading').show();
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideLoadingAnimation(){
|
|
|
|
$('#loading').hide();
|
|
|
|
}
|
|
|
|
|
2017-01-28 02:57:26 +00:00
|
|
|
function showExportingAnimation(){
|
|
|
|
$('#exporting').show();
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideExportingAnimation(){
|
|
|
|
$('#exporting').hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
function showSavingAnimation(){
|
|
|
|
$('#saving').show();
|
|
|
|
}
|
|
|
|
|
|
|
|
function hideSavingAnimation(){
|
|
|
|
$('#saving').hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-27 17:04:47 +00:00
|
|
|
|
2016-12-08 17:27:50 +00:00
|
|
|
function loadAction(file){
|
2016-12-15 11:56:21 +00:00
|
|
|
if (!endsWith(file, '.gpx') &&
|
|
|
|
!endsWith(file, '.kml') &&
|
|
|
|
!endsWith(file, '.jpg') &&
|
2016-12-15 03:07:29 +00:00
|
|
|
!endsWith(file, '.csv')){
|
2016-12-15 03:15:36 +00:00
|
|
|
OC.dialogs.alert(t('gpxedit', 'Impossible to load this file. ')+
|
|
|
|
t('gpxedit', 'Supported formats are gpx, kml, csv (unicsv) and jpg.'),t('gpxedit', 'Load error'));
|
2016-12-15 03:07:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-12-08 17:27:50 +00:00
|
|
|
loadFile(file);
|
|
|
|
// set save name
|
|
|
|
var spl = file.split('/');
|
|
|
|
var basename = spl[spl.length-1];
|
|
|
|
$('input#saveName').val(
|
2016-12-12 16:54:23 +00:00
|
|
|
basename.replace(/\.jpg$/, '.gpx').replace(/\.kml$/, '.gpx').replace(/\.csv$/, '.gpx')
|
|
|
|
);
|
2016-12-08 17:27:50 +00:00
|
|
|
}
|
|
|
|
|
2016-12-01 23:00:01 +00:00
|
|
|
function loadFile(file){
|
|
|
|
var req = {
|
|
|
|
path : file
|
|
|
|
}
|
|
|
|
var url = OC.generateUrl('/apps/gpxedit/getgpx');
|
2017-01-29 19:44:38 +00:00
|
|
|
$('#loadingpc').text('0');
|
2016-12-27 17:04:47 +00:00
|
|
|
showLoadingAnimation();
|
2017-01-28 03:48:04 +00:00
|
|
|
gpxedit.currentAjax = $.ajax({
|
|
|
|
type: "POST",
|
|
|
|
async: true,
|
|
|
|
url: url,
|
|
|
|
data: req,
|
|
|
|
xhr: function(){
|
|
|
|
var xhr = new window.XMLHttpRequest();
|
|
|
|
xhr.addEventListener("progress", function(evt) {
|
|
|
|
if (evt.lengthComputable) {
|
|
|
|
var percentComplete = evt.loaded / evt.total * 100;
|
2017-01-29 19:44:38 +00:00
|
|
|
$('#loadingpc').text(parseInt(percentComplete));
|
2017-01-28 03:48:04 +00:00
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
return xhr;
|
|
|
|
}
|
2017-02-01 19:18:56 +00:00
|
|
|
}).done(function (response) {
|
2016-12-05 11:29:55 +00:00
|
|
|
if ($('#clearbeforeload').is(':checked')){
|
|
|
|
clear();
|
|
|
|
}
|
2016-12-01 23:00:01 +00:00
|
|
|
if (response.gpx === ''){
|
2017-03-10 18:24:58 +00:00
|
|
|
OC.dialogs.alert('The file does not exist or it is not supported', 'Load error');
|
2016-12-01 23:00:01 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
parseGpx(response.gpx);
|
|
|
|
var bounds = gpxedit.editableLayers.getBounds();
|
|
|
|
gpxedit.map.fitBounds(bounds,
|
|
|
|
{animate:true, paddingTopLeft: [parseInt($('#sidebar').css('width')), 0]}
|
|
|
|
);
|
2016-12-27 17:04:47 +00:00
|
|
|
hideLoadingAnimation();
|
2016-12-01 23:00:01 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-12-06 14:12:40 +00:00
|
|
|
function deleteTileServer(li){
|
|
|
|
var sname = li.attr('name');
|
|
|
|
var req = {
|
|
|
|
servername : sname
|
|
|
|
}
|
|
|
|
var url = OC.generateUrl('/apps/gpxedit/deleteTileServer');
|
|
|
|
$.ajax({
|
|
|
|
type:'POST',
|
|
|
|
url:url,
|
|
|
|
data:req,
|
|
|
|
async:true
|
|
|
|
}).done(function (response) {
|
|
|
|
//alert(response.done);
|
|
|
|
if (response.done){
|
2017-03-10 18:24:58 +00:00
|
|
|
li.fadeOut('slow', function() { li.remove(); });
|
2016-12-06 14:12:40 +00:00
|
|
|
var activeLayerName = gpxedit.activeLayers.getActiveBaseLayer().name;
|
|
|
|
// if we delete the active layer, first select another
|
|
|
|
if (activeLayerName === sname){
|
|
|
|
$('input.leaflet-control-layers-selector').first().click();
|
|
|
|
}
|
|
|
|
gpxedit.activeLayers.removeLayer(gpxedit.baseLayers[sname]);
|
|
|
|
delete gpxedit.baseLayers[sname];
|
|
|
|
}
|
|
|
|
}).always(function(){
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function addTileServer(){
|
|
|
|
var sname = $('#tileservername').val();
|
|
|
|
var surl = $('#tileserverurl').val();
|
|
|
|
if (sname === '' || surl === ''){
|
2017-03-10 18:24:58 +00:00
|
|
|
OC.dialogs.alert(t('gpxedit','Server name or server url should not be empty'), t('gpxedit','Impossible to add tile server'));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if ($('#tileserverlist ul li[name="'+sname+'"]').length > 0){
|
|
|
|
OC.dialogs.alert(t('gpxedit','A server with this name already exists'), t('gpxedit','Impossible to add tile server'));
|
2016-12-06 14:12:40 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
$('#tileservername').val('');
|
|
|
|
$('#tileserverurl').val('');
|
|
|
|
|
|
|
|
var req = {
|
|
|
|
servername : sname,
|
|
|
|
serverurl : surl
|
|
|
|
}
|
|
|
|
var url = OC.generateUrl('/apps/gpxedit/addTileServer');
|
|
|
|
$.ajax({
|
|
|
|
type:'POST',
|
|
|
|
url:url,
|
|
|
|
data:req,
|
|
|
|
async:true
|
|
|
|
}).done(function (response) {
|
|
|
|
//alert(response.done);
|
|
|
|
if (response.done){
|
|
|
|
$('#tileserverlist ul').prepend(
|
2017-03-10 18:24:58 +00:00
|
|
|
'<li style="display:none;" name="'+sname+'" title="'+surl+'">'+sname+' <button>'+
|
2016-12-06 14:12:40 +00:00
|
|
|
'<i class="fa fa-trash" aria-hidden="true" style="color:red;"></i> '+
|
|
|
|
t('gpxedit','Delete')+'</button></li>'
|
|
|
|
);
|
2017-03-10 18:24:58 +00:00
|
|
|
$('#tileserverlist ul li[name="'+sname+'"]').fadeIn('slow');
|
|
|
|
|
2016-12-06 14:12:40 +00:00
|
|
|
// add tile server in leaflet control
|
|
|
|
var newlayer = new L.TileLayer(surl,
|
|
|
|
{maxZoom: 18, attribution: 'custom tile server'});
|
|
|
|
gpxedit.activeLayers.addBaseLayer(newlayer, sname);
|
|
|
|
gpxedit.baseLayers[sname] = newlayer;
|
|
|
|
}
|
|
|
|
}).always(function(){
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-12-06 15:40:54 +00:00
|
|
|
// affects future markers and also existing ones
|
2016-12-06 15:23:14 +00:00
|
|
|
function updateLeafletDrawMarkerStyle(){
|
|
|
|
var wst = $('#markerstyleselect').val();
|
2016-12-07 17:53:14 +00:00
|
|
|
var theclass = symbolSelectClasses[wst];
|
|
|
|
$('#markerstyleselect').removeClass($('#markerstyleselect').attr('class'));
|
2016-12-13 02:28:57 +00:00
|
|
|
$('#markerstyleselect').attr('style','');
|
|
|
|
if (theclass){
|
|
|
|
$('#markerstyleselect').addClass(theclass);
|
|
|
|
}
|
|
|
|
else if (wst !== ''){
|
|
|
|
var url = OC.generateUrl('/apps/gpxedit/getExtraSymbol?');
|
|
|
|
var fullurl = url+'name='+encodeURI(wst+'.png');
|
|
|
|
$('#markerstyleselect').attr('style',
|
|
|
|
'background: url(\''+fullurl+'\') no-repeat '+
|
|
|
|
'right 8px center rgba(240, 240, 240, 0.90);'+
|
2016-12-13 17:03:25 +00:00
|
|
|
'background-size: contain;');
|
2016-12-13 02:28:57 +00:00
|
|
|
}
|
2016-12-06 18:33:13 +00:00
|
|
|
var tst = $('#tooltipstyleselect').val();
|
2016-12-07 14:12:29 +00:00
|
|
|
var theicon = symbolIcons[wst];
|
2016-12-06 15:40:54 +00:00
|
|
|
|
|
|
|
gpxedit.drawControl.setDrawingOptions({
|
|
|
|
marker: {
|
|
|
|
icon: theicon
|
|
|
|
}
|
|
|
|
});
|
2016-12-06 18:22:26 +00:00
|
|
|
|
|
|
|
var symboo = $('#symboloverwrite').is(':checked');
|
2016-12-06 15:40:54 +00:00
|
|
|
gpxedit.editableLayers.eachLayer(function(layer){
|
|
|
|
var id = layer.gpxedit_id;
|
|
|
|
var name = gpxedit.layersData[id].name;
|
2016-12-06 18:22:26 +00:00
|
|
|
var symbol = gpxedit.layersData[id].symbol;
|
2016-12-06 15:40:54 +00:00
|
|
|
if (layer.type === 'marker'){
|
2016-12-06 18:22:26 +00:00
|
|
|
if (symboo && symbol !== '' && symbolIcons.hasOwnProperty(symbol)){
|
|
|
|
layer.setIcon(symbolIcons[symbol]);
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
layer.setIcon(theicon);
|
|
|
|
}
|
2016-12-06 15:40:54 +00:00
|
|
|
}
|
|
|
|
if (name !== ''){
|
|
|
|
layer.unbindTooltip();
|
2016-12-06 18:33:13 +00:00
|
|
|
if (tst === 'p'){
|
2016-12-06 15:40:54 +00:00
|
|
|
layer.bindTooltip(name, {permanent:true});
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
layer.bindTooltip(name, {sticky:true});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2016-12-06 15:23:14 +00:00
|
|
|
}
|
|
|
|
|
2016-12-06 16:29:49 +00:00
|
|
|
function restoreOptions(){
|
|
|
|
var url = OC.generateUrl('/apps/gpxedit/getOptionsValues');
|
|
|
|
var req = {
|
|
|
|
}
|
|
|
|
var optionsValues = '{}';
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: url,
|
|
|
|
data: req,
|
|
|
|
async: false
|
|
|
|
}).done(function (response) {
|
|
|
|
optionsValues = response.values;
|
|
|
|
//alert('option values : '+optionsValues);
|
|
|
|
}).fail(function(){
|
2017-03-10 18:24:58 +00:00
|
|
|
OC.dialogs.alert(t('gpxedit','failed to restore options values'), t('gpxedit','Error'));
|
2016-12-06 16:29:49 +00:00
|
|
|
});
|
|
|
|
optionsValues = $.parseJSON(optionsValues);
|
2016-12-13 02:28:57 +00:00
|
|
|
if (optionsValues.markerstyle !== undefined &&
|
|
|
|
symbolIcons.hasOwnProperty(optionsValues.markerstyle)){
|
2016-12-06 16:29:49 +00:00
|
|
|
$('#markerstyleselect').val(optionsValues.markerstyle);
|
2016-12-06 18:33:13 +00:00
|
|
|
}
|
|
|
|
if (optionsValues.tooltipstyle !== undefined){
|
|
|
|
$('#tooltipstyleselect').val(optionsValues.tooltipstyle);
|
2016-12-06 16:29:49 +00:00
|
|
|
}
|
|
|
|
if (optionsValues.clearbeforeload !== undefined){
|
|
|
|
$('#clearbeforeload').prop('checked', optionsValues.clearbeforeload);
|
|
|
|
}
|
2016-12-06 18:22:26 +00:00
|
|
|
if (optionsValues.symboloverwrite !== undefined){
|
|
|
|
$('#symboloverwrite').prop('checked', optionsValues.symboloverwrite);
|
|
|
|
}
|
2017-02-01 19:18:56 +00:00
|
|
|
if (optionsValues.tilelayer !== undefined){
|
|
|
|
gpxedit.restoredTileLayer = optionsValues.tilelayer;
|
|
|
|
}
|
2016-12-06 16:29:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function saveOptions(){
|
|
|
|
var optionsValues = {};
|
|
|
|
optionsValues.markerstyle = $('#markerstyleselect').val();
|
2016-12-06 18:33:13 +00:00
|
|
|
optionsValues.tooltipstyle = $('#tooltipstyleselect').val();
|
2016-12-06 16:29:49 +00:00
|
|
|
optionsValues.clearbeforeload = $('#clearbeforeload').is(':checked');
|
2016-12-06 18:22:26 +00:00
|
|
|
optionsValues.symboloverwrite = $('#symboloverwrite').is(':checked');
|
2017-02-01 19:18:56 +00:00
|
|
|
optionsValues.tilelayer = gpxedit.activeLayers.getActiveBaseLayer().name;
|
2016-12-06 16:29:49 +00:00
|
|
|
//alert('to save : '+JSON.stringify(optionsValues));
|
|
|
|
|
|
|
|
var req = {
|
|
|
|
optionsValues : JSON.stringify(optionsValues),
|
|
|
|
}
|
|
|
|
var url = OC.generateUrl('/apps/gpxedit/saveOptionsValues');
|
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
url: url,
|
|
|
|
data: req,
|
|
|
|
async: true
|
|
|
|
}).done(function (response) {
|
|
|
|
//alert(response);
|
|
|
|
}).fail(function(){
|
2017-03-10 18:24:58 +00:00
|
|
|
OC.dialogs.alert(t('gpxedit','failed to save options values'), t('gpxedit','Error'));
|
2016-12-06 16:29:49 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-12-07 14:12:29 +00:00
|
|
|
function fillWaypointStyles(){
|
|
|
|
for (var st in symbolIcons){
|
|
|
|
$('select#markerstyleselect').append('<option value="'+st+'">'+st+'</option>');
|
|
|
|
}
|
|
|
|
$('select#markerstyleselect').val('marker');
|
|
|
|
}
|
|
|
|
|
2016-12-13 02:28:57 +00:00
|
|
|
function addExtraSymbols(){
|
|
|
|
var url = OC.generateUrl('/apps/gpxedit/getExtraSymbol?');
|
|
|
|
$('ul#extrasymbols li').each(function(){
|
|
|
|
var name = $(this).attr('name');
|
|
|
|
var smallname = $(this).html();
|
|
|
|
var fullurl = url+'name='+encodeURI(name);
|
|
|
|
var d = L.icon({
|
|
|
|
iconUrl: fullurl,
|
|
|
|
iconSize: L.point(24, 24),
|
|
|
|
iconAnchor: [12, 12]
|
|
|
|
});
|
|
|
|
symbolIcons[smallname] = d;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-12-15 02:54:28 +00:00
|
|
|
function saveAction(targetPath){
|
2017-01-28 02:57:26 +00:00
|
|
|
showExportingAnimation();
|
2016-12-15 02:54:28 +00:00
|
|
|
var saveFilePath = targetPath+'/'+$('input#saveName').val();
|
|
|
|
var gpxText = generateGpx();
|
2017-01-28 02:57:26 +00:00
|
|
|
hideExportingAnimation();
|
2017-01-29 19:44:38 +00:00
|
|
|
$('#savingpc').text('0');
|
2017-01-28 02:57:26 +00:00
|
|
|
showSavingAnimation();
|
2016-12-15 02:54:28 +00:00
|
|
|
var req = {
|
|
|
|
path: saveFilePath,
|
|
|
|
content: gpxText
|
|
|
|
}
|
|
|
|
var url = OC.generateUrl('/apps/gpxedit/savegpx');
|
2017-01-28 03:48:04 +00:00
|
|
|
$.ajax({
|
|
|
|
type: 'POST',
|
|
|
|
async: true,
|
|
|
|
url: url,
|
|
|
|
data: req,
|
|
|
|
xhr: function(){
|
|
|
|
var xhr = new window.XMLHttpRequest();
|
|
|
|
xhr.upload.addEventListener("progress", function(evt) {
|
|
|
|
if (evt.lengthComputable) {
|
|
|
|
var percentComplete = evt.loaded / evt.total * 100;
|
|
|
|
//Do something with upload progress here
|
2017-01-29 19:44:38 +00:00
|
|
|
$('#savingpc').text(parseInt(percentComplete));
|
2017-01-28 03:48:04 +00:00
|
|
|
}
|
|
|
|
}, false);
|
|
|
|
|
|
|
|
return xhr;
|
|
|
|
}
|
|
|
|
}).done(function (response) {
|
2017-01-28 02:57:26 +00:00
|
|
|
hideSavingAnimation();
|
2016-12-15 02:54:28 +00:00
|
|
|
if (response.status === 'fiw'){
|
2016-12-15 18:22:45 +00:00
|
|
|
showSaveFailAnimation(saveFilePath, t('gpxedit', 'Impossible to write file')+' : '+t('gpxedit', 'write access denied'));
|
2016-12-15 02:54:28 +00:00
|
|
|
}
|
|
|
|
else if (response.status === 'fu'){
|
2016-12-15 18:22:45 +00:00
|
|
|
showSaveFailAnimation(saveFilePath, t('gpxedit', 'Impossible to write file')+' : '+t('gpxedit', 'folder does not exist'));
|
2016-12-15 02:54:28 +00:00
|
|
|
}
|
|
|
|
else if (response.status === 'fw'){
|
2016-12-15 18:22:45 +00:00
|
|
|
showSaveFailAnimation(saveFilePath, t('gpxedit', 'Impossible to write file')+' : '+t('gpxedit', 'folder write access denied'));
|
2016-12-15 02:54:28 +00:00
|
|
|
}
|
|
|
|
else if (response.status === 'bfn'){
|
2016-12-15 18:22:45 +00:00
|
|
|
showSaveFailAnimation(saveFilePath, t('gpxedit', 'Bad file name, must end with ".gpx"'));
|
2016-12-15 02:54:28 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
showSaveSuccessAnimation(saveFilePath);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-11-30 19:00:03 +00:00
|
|
|
$(document).ready(function(){
|
|
|
|
gpxedit.username = $('p#username').html();
|
2017-02-01 19:18:56 +00:00
|
|
|
document.onkeydown = checkKey;
|
2016-12-13 02:28:57 +00:00
|
|
|
addExtraSymbols();
|
2016-12-07 14:12:29 +00:00
|
|
|
fillWaypointStyles();
|
2016-12-06 16:29:49 +00:00
|
|
|
restoreOptions();
|
2017-02-01 19:18:56 +00:00
|
|
|
load_map();
|
2016-11-30 19:00:03 +00:00
|
|
|
|
2016-12-06 15:23:14 +00:00
|
|
|
$('select#markerstyleselect').change(function(e){
|
|
|
|
updateLeafletDrawMarkerStyle();
|
2016-12-06 16:29:49 +00:00
|
|
|
saveOptions();
|
2016-12-06 15:23:14 +00:00
|
|
|
});
|
2016-12-06 18:33:13 +00:00
|
|
|
$('select#tooltipstyleselect').change(function(e){
|
|
|
|
updateLeafletDrawMarkerStyle();
|
|
|
|
saveOptions();
|
|
|
|
});
|
2016-12-06 18:22:26 +00:00
|
|
|
$('body').on('change','#symboloverwrite', function() {
|
|
|
|
updateLeafletDrawMarkerStyle();
|
|
|
|
saveOptions();
|
|
|
|
});
|
2016-12-06 16:29:49 +00:00
|
|
|
// to set the draw style
|
2016-12-06 15:23:14 +00:00
|
|
|
updateLeafletDrawMarkerStyle();
|
2016-12-06 16:29:49 +00:00
|
|
|
$('body').on('change','#clearbeforeload', function() {
|
|
|
|
saveOptions();
|
|
|
|
});
|
2016-11-30 19:00:03 +00:00
|
|
|
$('body').on('click','button.popupOkButton', function(e) {
|
|
|
|
var id = parseInt($(this).attr('layerid'));
|
|
|
|
var name = $(this).parent().find('.layerName').val();
|
|
|
|
var description = $(this).parent().find('.layerDesc').val();
|
|
|
|
var comment = $(this).parent().find('.layerCmt').val();
|
2016-12-07 17:53:14 +00:00
|
|
|
var symbol = $(this).parent().find('select[role=symbol]').val();
|
2016-12-06 15:23:14 +00:00
|
|
|
var wst = $('#markerstyleselect').val();
|
2016-12-06 18:33:13 +00:00
|
|
|
var tst = $('#tooltipstyleselect').val();
|
2016-12-06 19:28:29 +00:00
|
|
|
var symboo = $('#symboloverwrite').is(':checked');
|
2016-12-08 10:01:45 +00:00
|
|
|
var type = gpxedit.layersData[id].layer.type;
|
2016-11-30 19:00:03 +00:00
|
|
|
|
|
|
|
gpxedit.layersData[id].name = name;
|
|
|
|
gpxedit.layersData[id].description = description;
|
|
|
|
gpxedit.layersData[id].comment = comment;
|
2016-12-19 22:45:13 +00:00
|
|
|
if (symbol !== 'unknown'){
|
|
|
|
gpxedit.layersData[id].symbol = symbol;
|
|
|
|
}
|
2016-12-06 15:23:14 +00:00
|
|
|
gpxedit.layersData[id].layer.unbindTooltip();
|
2016-12-08 10:01:45 +00:00
|
|
|
if (type === 'marker'){
|
2016-12-19 22:45:13 +00:00
|
|
|
if (symbol === 'unknown'){
|
|
|
|
// pass
|
|
|
|
}
|
|
|
|
else if (symboo && symbol !== '' && symbolIcons.hasOwnProperty(symbol)){
|
2016-12-06 19:28:29 +00:00
|
|
|
gpxedit.layersData[id].layer.setIcon(symbolIcons[symbol])
|
|
|
|
}
|
|
|
|
else{
|
2016-12-07 14:12:29 +00:00
|
|
|
var theicon = symbolIcons[wst];
|
2016-12-06 19:28:29 +00:00
|
|
|
gpxedit.layersData[id].layer.setIcon(theicon);
|
|
|
|
}
|
2017-01-20 14:03:24 +00:00
|
|
|
var lat = $(this).parent().find('.layerLat').val();
|
|
|
|
var lon = $(this).parent().find('.layerLon').val();
|
|
|
|
var latlng = L.latLng(lat, lon);
|
|
|
|
gpxedit.layersData[id].layer.setLatLng(latlng);
|
2016-12-06 19:28:29 +00:00
|
|
|
}
|
2016-12-06 15:23:14 +00:00
|
|
|
if (name !== ''){
|
2016-12-06 18:33:13 +00:00
|
|
|
if (tst === 'p'){
|
2016-12-06 15:23:14 +00:00
|
|
|
gpxedit.layersData[id].layer.bindTooltip(name, {permanent:true});
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
gpxedit.layersData[id].layer.bindTooltip(name, {sticky:true});
|
|
|
|
}
|
|
|
|
}
|
2016-11-30 19:00:03 +00:00
|
|
|
|
|
|
|
gpxedit.map.closePopup();
|
|
|
|
});
|
2016-12-01 00:30:19 +00:00
|
|
|
|
2016-12-01 18:38:50 +00:00
|
|
|
$('button#clearButton').click(function(e){
|
|
|
|
clear();
|
|
|
|
});
|
2016-12-15 02:54:28 +00:00
|
|
|
$('button#loadButton').click(function(e){
|
2016-12-27 17:04:47 +00:00
|
|
|
if (gpxedit.currentAjax !== null){
|
|
|
|
gpxedit.currentAjax.abort();
|
|
|
|
hideLoadingAnimation();
|
|
|
|
}
|
2016-12-15 02:54:28 +00:00
|
|
|
OC.dialogs.filepicker(t('gpxedit', 'Load file (gpx, kml, csv, png)'), function(targetPath) {
|
|
|
|
loadAction(targetPath);
|
|
|
|
}, false, null, true);
|
2016-12-02 09:51:27 +00:00
|
|
|
});
|
|
|
|
|
2016-12-15 02:54:28 +00:00
|
|
|
$('button#saveButton').click(function(e){
|
2016-12-15 18:22:45 +00:00
|
|
|
if (gpxedit.editableLayers.getLayers().length === 0){
|
|
|
|
showFailAnimation(t('gpxedit', 'There is nothing to save'));
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
var filename = $('#saveName').val();
|
|
|
|
OC.dialogs.filepicker(t('gpxedit', 'Where to save')+' <b>'+filename+'</b>', function(targetPath) {
|
|
|
|
saveAction(targetPath);
|
|
|
|
}, false, "httpd/unix-directory", true);
|
|
|
|
}
|
2016-12-02 09:51:27 +00:00
|
|
|
});
|
|
|
|
|
2016-12-06 14:12:40 +00:00
|
|
|
// Custom tile server management
|
|
|
|
$('body').on('click','#tileserverlist button', function(e) {
|
|
|
|
deleteTileServer($(this).parent());
|
|
|
|
});
|
|
|
|
$('#addtileserver').click(function(){
|
|
|
|
addTileServer();
|
|
|
|
});
|
|
|
|
|
2016-12-07 17:53:14 +00:00
|
|
|
$('body').on('change', 'select[role=symbol]', function() {
|
|
|
|
$(this).removeClass($(this).attr('class'));
|
2016-12-13 02:28:57 +00:00
|
|
|
$(this).attr('style','');
|
|
|
|
if (symbolSelectClasses.hasOwnProperty($(this).val())){
|
|
|
|
$(this).addClass(symbolSelectClasses[$(this).val()]);
|
|
|
|
}
|
|
|
|
else if ($(this).val() !== ''){
|
|
|
|
var url = OC.generateUrl('/apps/gpxedit/getExtraSymbol?');
|
|
|
|
var fullurl = url+'name='+encodeURI($(this).val()+'.png');
|
|
|
|
$(this).attr('style',
|
|
|
|
'background: url(\''+fullurl+'\') no-repeat '+
|
|
|
|
'right 8px center rgba(240, 240, 240, 0.90);'+
|
2016-12-13 17:03:25 +00:00
|
|
|
'background-size: contain;');
|
2016-12-13 02:28:57 +00:00
|
|
|
}
|
2016-12-07 17:53:14 +00:00
|
|
|
});
|
|
|
|
|
2016-12-08 17:27:50 +00:00
|
|
|
// load a file if 'file' GET url parameter was given
|
2016-12-10 17:04:24 +00:00
|
|
|
var urlfileparam = getUrlParameter('file');
|
|
|
|
var fileparam = decodeURI(urlfileparam);
|
|
|
|
if (urlfileparam && urlfileparam !== undefined){
|
2016-12-08 17:27:50 +00:00
|
|
|
loadAction(fileparam);
|
|
|
|
}
|
|
|
|
|
2016-11-30 19:00:03 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
})(jQuery, OC);
|