2016-11-30 19:00:03 +00:00
( function ( $ , OC ) {
2017-03-19 17:09:01 +00:00
'use strict' ;
var gpxedit = {
map : { } ,
baseLayers : null ,
restoredTileLayer : null ,
drawControl : null ,
id : 0 ,
// indexed by gpxedit_id
layersData : { } ,
currentAjax : null
} ;
var symbolSelectClasses = {
'unknown' : 'unknown-select' ,
'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' ,
'Residence' : 'residence-select' ,
'Drinking Water' : 'drinking-water-select' ,
'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' ,
'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' ,
} ;
var symbolIcons = {
'marker' : L . divIcon ( {
className : 'leaflet-marker-blue' ,
iconAnchor : [ 12 , 41 ]
} ) ,
'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 ]
} ) ,
'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 ]
} ) ,
'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 ]
} ) ,
'Residence' : L . divIcon ( {
className : 'residence' ,
iconAnchor : [ 12 , 12 ]
} ) ,
'Drinking Water' : L . divIcon ( {
className : 'drinking-water' ,
iconAnchor : [ 12 , 12 ]
} ) ,
'Trail Head' : L . divIcon ( {
className : 'hike' ,
iconAnchor : [ 12 , 12 ]
} ) ,
'Bike Trail' : L . divIcon ( {
className : 'bike-trail' ,
iconAnchor : [ 12 , 12 ]
} ) ,
'Campground' : L . divIcon ( {
className : 'campground' ,
iconAnchor : [ 12 , 12 ]
} ) ,
'Bar' : L . divIcon ( {
className : 'bar' ,
iconAnchor : [ 10 , 12 ]
} ) ,
'Skull and Crossbones' : L . divIcon ( {
className : 'skullcross' ,
iconAnchor : [ 12 , 12 ]
} ) ,
'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 ]
} ) ,
'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 ]
} ) ,
} ;
var hoverStyle = {
2017-05-09 00:14:25 +00:00
weight : 10 ,
2017-03-19 17:09:01 +00:00
opacity : 0.7 ,
color : 'black'
} ;
var defaultStyle = {
opacity : 0.9 ,
2017-05-09 00:14:25 +00:00
color : '#1196DA' ,
2017-03-19 17:09:01 +00:00
weight : 7
} ;
function endsWith ( str , suffix ) {
return str . indexOf ( suffix , str . length - suffix . length ) !== - 1 ;
2016-12-08 11:07:30 +00:00
}
2016-12-01 01:09:26 +00:00
2017-03-19 17:09:01 +00:00
function load _map ( ) {
// change meta to send referrer
// usefull for IGN tiles authentication !
$ ( 'meta[name=referrer]' ) . attr ( 'content' , 'origin' ) ;
var layer = getUrlParameter ( 'layer' ) ;
var default _layer = 'OpenStreetMap' ;
if ( gpxedit . restoredTileLayer !== null ) {
default _layer = gpxedit . restoredTileLayer ;
}
else if ( typeof layer !== 'undefined' ) {
2017-03-24 20:54:42 +00:00
default _layer = decodeURIComponent ( layer ) ;
2016-12-08 11:07:30 +00:00
}
2016-12-06 19:28:29 +00:00
2017-05-14 15:57:53 +00:00
var osmfr2 = new L . TileLayer ( 'https://{s}.tile.openstreetmap.fr/osmfr/{z}/{x}/{y}.png' , {
minZoom : 0 ,
maxZoom : 13 ,
attribution : 'Map data © 2013 <a href="http://openstreetmap.org">OpenStreetMap</a> contributors'
} ) ;
2017-03-19 17:09:01 +00:00
2017-05-14 15:57:53 +00:00
var baseLayers = { } ;
// add base layers
$ ( '#basetileservers li[type=tile]' ) . each ( function ( ) {
var sname = $ ( this ) . attr ( 'name' ) ;
var surl = $ ( this ) . attr ( 'url' ) ;
var minz = parseInt ( $ ( this ) . attr ( 'minzoom' ) ) ;
var maxz = parseInt ( $ ( this ) . attr ( 'maxzoom' ) ) ;
var sattrib = $ ( this ) . attr ( 'attribution' ) ;
2017-06-12 16:46:16 +00:00
var stransparent = ( $ ( this ) . attr ( 'transparent' ) === 'true' ) ;
var sopacity = $ ( this ) . attr ( 'opacity' ) ;
if ( sopacity !== '' ) {
sopacity = parseFloat ( sopacity ) ;
}
else {
sopacity = 1 ;
}
baseLayers [ sname ] = new L . TileLayer ( surl , { minZoom : minz , maxZoom : maxz , attribution : sattrib , opacity : sopacity , transparent : stransparent } ) ;
2017-05-14 15:57:53 +00:00
} ) ;
2017-06-12 16:28:34 +00:00
$ ( '#basetileservers li[type=tilewms]' ) . each ( function ( ) {
var sname = $ ( this ) . attr ( 'name' ) ;
var surl = $ ( this ) . attr ( 'url' ) ;
var slayers = $ ( this ) . attr ( 'layers' ) || '' ;
var sversion = $ ( this ) . attr ( 'version' ) || '1.1.1' ;
var stransparent = ( $ ( this ) . attr ( 'transparent' ) === 'true' ) ;
var sformat = $ ( this ) . attr ( 'format' ) || 'image/png' ;
2017-06-12 16:46:16 +00:00
var sopacity = $ ( this ) . attr ( 'opacity' ) ;
if ( sopacity !== '' ) {
sopacity = parseFloat ( sopacity ) ;
}
else {
sopacity = 1 ;
}
2017-06-12 16:28:34 +00:00
var sattrib = $ ( this ) . attr ( 'attribution' ) || '' ;
baseLayers [ sname ] = new L . tileLayer . wms ( surl , { layers : slayers , version : sversion , transparent : stransparent , opacity : sopacity , format : sformat , attribution : sattrib } ) ;
} ) ;
2017-03-19 17:09:01 +00:00
// add custom layers
$ ( '#tileserverlist li' ) . each ( function ( ) {
2017-06-12 22:45:54 +00:00
var sname = $ ( this ) . attr ( 'servername' ) ;
2017-03-19 17:09:01 +00:00
var surl = $ ( this ) . attr ( 'title' ) ;
2017-06-12 22:45:54 +00:00
var sminzoom = $ ( this ) . attr ( 'minzoom' ) || '1' ;
var smaxzoom = $ ( this ) . attr ( 'maxzoom' ) || '20' ;
var sattrib = $ ( this ) . attr ( 'attribution' ) || '' ;
2017-03-19 17:09:01 +00:00
baseLayers [ sname ] = new L . TileLayer ( surl ,
2017-06-12 22:45:54 +00:00
{ minZoom : sminzoom , maxZoom : smaxzoom , attribution : sattrib } ) ;
} ) ;
$ ( '#tileserverwmslist li' ) . each ( function ( ) {
var sname = $ ( this ) . attr ( 'servername' ) ;
var surl = $ ( this ) . attr ( 'title' ) ;
var sminzoom = $ ( this ) . attr ( 'minzoom' ) || '1' ;
var smaxzoom = $ ( this ) . attr ( 'maxzoom' ) || '20' ;
var slayers = $ ( this ) . attr ( 'layers' ) || '' ;
var sversion = $ ( this ) . attr ( 'version' ) || '1.1.1' ;
var sformat = $ ( this ) . attr ( 'format' ) || 'image/png' ;
var sattrib = $ ( this ) . attr ( 'attribution' ) || '' ;
baseLayers [ sname ] = new L . tilelayer . wms ( surl ,
{ format : sformat , version : sversion , layers : slayers , minZoom : sminzoom , maxZoom : smaxzoom , attribution : sattrib } ) ;
2016-12-08 11:26:37 +00:00
} ) ;
2017-03-19 17:09:01 +00:00
gpxedit . baseLayers = baseLayers ;
2017-05-14 15:57:53 +00:00
var baseOverlays = { } ;
// add base overlays
$ ( '#basetileservers li[type=overlay]' ) . each ( function ( ) {
var sname = $ ( this ) . attr ( 'name' ) ;
var surl = $ ( this ) . attr ( 'url' ) ;
var minz = parseInt ( $ ( this ) . attr ( 'minzoom' ) ) ;
var maxz = parseInt ( $ ( this ) . attr ( 'maxzoom' ) ) ;
var sattrib = $ ( this ) . attr ( 'attribution' ) ;
2017-06-12 22:45:54 +00:00
var stransparent ;
if ( $ ( this ) . attr ( 'transparent' ) !== '' ) {
stransparent = ( $ ( this ) . attr ( 'transparent' ) === 'true' ) ;
}
else {
stransparent = true ;
}
2017-06-12 16:46:16 +00:00
var sopacity = $ ( this ) . attr ( 'opacity' ) ;
if ( sopacity !== '' ) {
sopacity = parseFloat ( sopacity ) ;
}
else {
2017-06-12 16:50:19 +00:00
sopacity = 0.4 ;
2017-06-12 16:46:16 +00:00
}
baseOverlays [ sname ] = new L . TileLayer ( surl , { minZoom : minz , maxZoom : maxz , attribution : sattrib , opacity : sopacity , transparent : stransparent } ) ;
2017-05-14 15:57:53 +00:00
} ) ;
2017-06-12 16:28:34 +00:00
$ ( '#basetileservers li[type=overlaywms]' ) . each ( function ( ) {
var sname = $ ( this ) . attr ( 'name' ) ;
var surl = $ ( this ) . attr ( 'url' ) ;
var slayers = $ ( this ) . attr ( 'layers' ) || '' ;
var sversion = $ ( this ) . attr ( 'version' ) || '1.1.1' ;
2017-06-12 22:45:54 +00:00
var stransparent ;
if ( $ ( this ) . attr ( 'transparent' ) !== '' ) {
stransparent = ( $ ( this ) . attr ( 'transparent' ) === 'true' ) ;
}
else {
stransparent = true ;
}
2017-06-12 16:28:34 +00:00
var sformat = $ ( this ) . attr ( 'format' ) || 'image/png' ;
2017-06-12 16:46:16 +00:00
var sopacity = $ ( this ) . attr ( 'opacity' ) ;
if ( sopacity !== '' ) {
sopacity = parseFloat ( sopacity ) ;
}
else {
2017-06-12 16:50:19 +00:00
sopacity = 0.4 ;
2017-06-12 16:46:16 +00:00
}
2017-06-12 16:28:34 +00:00
var sattrib = $ ( this ) . attr ( 'attribution' ) || '' ;
baseOverlays [ sname ] = new L . tileLayer . wms ( surl , { layers : slayers , version : sversion , transparent : stransparent , opacity : sopacity , format : sformat , attribution : sattrib } ) ;
} ) ;
2017-05-14 15:57:53 +00:00
// add custom overlays
$ ( '#overlayserverlist li' ) . each ( function ( ) {
2017-06-12 22:45:54 +00:00
var sname = $ ( this ) . attr ( 'servername' ) ;
2017-05-14 15:57:53 +00:00
var surl = $ ( this ) . attr ( 'title' ) ;
2017-06-12 22:45:54 +00:00
var sminzoom = $ ( this ) . attr ( 'minzoom' ) || '1' ;
var smaxzoom = $ ( this ) . attr ( 'maxzoom' ) || '20' ;
var stransparent ;
if ( $ ( this ) . attr ( 'transparent' ) !== '' ) {
stransparent = ( $ ( this ) . attr ( 'transparent' ) === 'true' ) ;
}
else {
stransparent = true ;
}
var sopacity = $ ( this ) . attr ( 'opacity' ) ;
if ( sopacity !== '' ) {
sopacity = parseFloat ( sopacity ) ;
}
else {
sopacity = 0.4 ;
}
var sattrib = $ ( this ) . attr ( 'attribution' ) || '' ;
2017-05-14 15:57:53 +00:00
baseOverlays [ sname ] = new L . TileLayer ( surl ,
2017-06-12 22:45:54 +00:00
{ minZoom : sminzoom , maxZoom : smaxzoom , transparent : stransparent , opcacity : sopacity , attribution : sattrib } ) ;
} ) ;
$ ( '#overlayserverwmslist li' ) . each ( function ( ) {
var sname = $ ( this ) . attr ( 'servername' ) ;
var surl = $ ( this ) . attr ( 'title' ) ;
var sminzoom = $ ( this ) . attr ( 'minzoom' ) || '1' ;
var smaxzoom = $ ( this ) . attr ( 'maxzoom' ) || '20' ;
var slayers = $ ( this ) . attr ( 'layers' ) || '' ;
var sversion = $ ( this ) . attr ( 'version' ) || '1.1.1' ;
var stransparent ;
if ( $ ( this ) . attr ( 'transparent' ) !== '' ) {
stransparent = ( $ ( this ) . attr ( 'transparent' ) === 'true' ) ;
}
else {
stransparent = true ;
}
var sformat = $ ( this ) . attr ( 'format' ) || 'image/png' ;
var sopacity = $ ( this ) . attr ( 'opacity' ) ;
if ( sopacity !== '' ) {
sopacity = parseFloat ( sopacity ) ;
}
else {
sopacity = 0.4 ;
}
var sattrib = $ ( this ) . attr ( 'attribution' ) || '' ;
baseOverlays [ sname ] = new L . tileLayer . wms ( surl , { layers : slayers , version : sversion , transparent : stransparent , opacity : sopacity , format : sformat , attribution : sattrib , minZoom : sminzoom , maxZoom : smaxzoom } ) ;
2017-05-14 15:57:53 +00:00
} ) ;
gpxedit . overlayLayers = baseOverlays ;
2017-03-19 17:09:01 +00:00
gpxedit . map = new L . Map ( 'map' , {
zoomControl : true ,
2016-12-08 11:26:37 +00:00
} ) ;
2016-12-01 01:09:26 +00:00
2017-03-19 17:09:01 +00:00
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' ;
2016-12-01 00:30:19 +00:00
}
2017-03-19 17:09:01 +00:00
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 ,
{ toggleDisplay : true , position : 'bottomright' }
) . addTo ( gpxedit . map ) ;
gpxedit . minimapControl . _toggleDisplayButtonClicked ( ) ;
2017-05-08 01:31:49 +00:00
//gpxedit.editableLayers = new L.FeatureGroup();
//gpxedit.map.addLayer(gpxedit.editableLayers);
2017-03-19 17:09:01 +00:00
var options = {
position : 'bottomleft' ,
draw : {
2017-05-08 01:31:49 +00:00
polyline : true ,
2017-03-19 17:09:01 +00:00
polygon : false ,
circle : false ,
rectangle : false ,
marker : {
icon : symbolIcons . marker
}
} ,
edit : {
2017-05-08 01:31:49 +00:00
edit : true ,
remove : true ,
//featureGroup: gpxedit.editableLayers,
} ,
entry : 'edit-json'
2017-03-19 17:09:01 +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' ) ;
2017-05-30 14:51:14 +00:00
L . drawLocal . edit . handlers . edit . tooltip . text = t ( 'gpxedit' , 'Drag to move elements,<br/>click to remove a point<br/>hover a middle marker and press "Del" to cut the line' ) ;
2017-03-19 17:09:01 +00:00
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' ) ;
2017-05-08 01:31:49 +00:00
var drawControl = new L . Control . Draw . Plus ( options ) ;
2017-03-19 17:09:01 +00:00
gpxedit . drawControl = drawControl ;
gpxedit . map . addControl ( drawControl ) ;
// when something is created, we generate popup content
// and initialize layer data
gpxedit . map . on ( L . Draw . Event . CREATED , function ( e ) {
onCreated ( e . layerType , e . layer ) ;
} ) ;
// not used for the moment
gpxedit . map . on ( 'draw:edited' , function ( e ) {
var layers = e . layers ;
layers . eachLayer ( function ( layer ) {
} ) ;
} ) ;
// remove data associated with the deleted layer
gpxedit . map . on ( 'draw:deleted' , function ( e ) {
var layers = e . layers ;
layers . eachLayer ( function ( layer ) {
delete gpxedit . layersData [ layer . gpxedit _id ] ;
} ) ;
} ) ;
// 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
gpxedit . map . on ( 'popupopen' , function ( e ) {
var id = e . popup . _source . gpxedit _id ;
//var id = parseInt(e.popup.getContent().match(/layerid="(\d+)"/)[1]);
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 ) ;
if ( gpxedit . layersData [ id ] . layer . type === 'marker' ) {
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 ( '' ) ;
2016-12-12 13:36:49 +00:00
}
2017-03-19 17:09:01 +00:00
else {
buttonParent . find ( 'select[role=symbol]' ) . val ( 'unknown' ) ;
2016-12-05 12:00:46 +00:00
}
2017-03-19 17:09:01 +00:00
buttonParent . find ( 'select[role=symbol]' ) . change ( ) ;
var latlng = gpxedit . layersData [ id ] . layer . getLatLng ( ) ;
buttonParent . find ( 'input.layerLat' ) . val ( latlng . lat . toFixed ( 6 ) ) ;
buttonParent . find ( 'input.layerLon' ) . val ( latlng . lng . toFixed ( 6 ) ) ;
2016-12-01 00:30:19 +00:00
}
2017-03-19 17:09:01 +00:00
} ) ;
gpxedit . map . on ( 'baselayerchange' , saveOptions ) ;
}
// 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)
function onCreated ( type , layer ) {
2017-05-09 01:00:09 +00:00
var tst = $ ( '#tooltipstyleselect' ) . val ( ) ;
2017-03-19 17:09:01 +00:00
var popupTitle ;
var layerType ;
if ( type === 'polyline' || type === 'track' ) {
popupTitle = t ( 'gpxedit' , 'Track' ) ;
layerType = 'track' ;
2017-05-09 01:00:09 +00:00
layer . setStyle ( defaultStyle ) ;
2017-03-19 17:09:01 +00:00
}
else if ( type === 'route' ) {
popupTitle = t ( 'gpxedit' , 'Route' ) ;
layerType = 'route' ;
2017-05-09 01:00:09 +00:00
layer . setStyle ( defaultStyle ) ;
2016-12-01 00:30:19 +00:00
}
2017-03-19 17:09:01 +00:00
else if ( type === 'marker' ) {
popupTitle = t ( 'gpxedit' , 'Waypoint' ) ;
layerType = 'marker' ;
}
var popupTxt = '<h2 class="popupTitle">' + popupTitle + '</h2><table class="popupdatatable">' +
'<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>' ;
if ( type === 'marker' ) {
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>' ;
popupTxt = popupTxt + '<tr><td>' + t ( 'gpxedit' , 'Symbol' ) +
'</td><td><select role="symbol">' ;
popupTxt = popupTxt + '<option value="">' +
t ( 'gpxedit' , 'No symbol' ) + '</option>' ;
popupTxt = popupTxt + '<option value="unknown">' +
t ( 'gpxedit' , 'Unknown symbol' ) + '</option>' ;
for ( var cl in symbolIcons ) {
if ( cl !== 'marker' ) {
popupTxt = popupTxt + '<option value="' + cl + '">' +
cl + '</option>' ;
}
2016-12-08 11:07:30 +00:00
}
2017-03-19 17:09:01 +00:00
popupTxt = popupTxt + '</select></td></tr>' ;
}
popupTxt = popupTxt + '</table>' ;
popupTxt = popupTxt + '<button class="popupOkButton" layerid="' +
gpxedit . id + '">OK</button>' ;
layer . bindPopup ( popupTxt ) ;
if ( type !== 'marker' ) {
layer . on ( 'mouseover' , function ( ) {
2017-05-04 20:25:42 +00:00
layer . bringToFront ( ) ;
2017-03-19 17:09:01 +00:00
layer . setStyle ( hoverStyle ) ;
} ) ;
layer . on ( 'mouseout' , function ( ) {
layer . setStyle ( defaultStyle ) ;
} ) ;
}
2017-05-09 01:00:09 +00:00
// get properties of the splited line
if ( layer . hasOwnProperty ( 'gpxedit_id' ) ) {
gpxedit . layersData [ gpxedit . id ] = {
name : gpxedit . layersData [ layer . gpxedit _id ] . name ,
description : gpxedit . layersData [ layer . gpxedit _id ] . description ,
comment : gpxedit . layersData [ layer . gpxedit _id ] . comment ,
symbol : gpxedit . layersData [ layer . gpxedit _id ] . symbol ,
time : gpxedit . layersData [ layer . gpxedit _id ] . time ,
layer : layer
} ;
if ( gpxedit . layersData [ layer . gpxedit _id ] . name !== '' ) {
if ( tst === 'p' ) {
layer . bindTooltip (
gpxedit . layersData [ layer . gpxedit _id ] . name ,
{ permanent : true }
) ;
}
else {
layer . bindTooltip (
gpxedit . layersData [ layer . gpxedit _id ] . name ,
{ sticky : true }
) ;
}
}
}
else {
gpxedit . layersData [ gpxedit . id ] = {
name : '' ,
description : '' ,
comment : '' ,
symbol : '' ,
time : '' ,
layer : layer
} ;
}
2017-03-19 17:09:01 +00:00
layer . gpxedit _id = gpxedit . id ;
layer . type = layerType ;
2017-05-08 01:31:49 +00:00
gpxedit . drawControl . editLayers . addLayer ( layer ) ;
2017-03-19 17:09:01 +00:00
gpxedit . id ++ ;
return layer ;
}
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 ) {
2017-03-24 20:54:42 +00:00
return decodeURIComponent ( sParameterName [ 1 ] ) ;
2016-12-08 11:07:30 +00:00
}
2017-03-19 17:09:01 +00:00
}
}
// generate gpx text from current map elements
function generateGpx ( ) {
2017-03-21 18:03:57 +00:00
var lat , lng , alt , time , i , ia ;
2017-03-19 17:09:01 +00:00
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' ;
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"' +
' creator="GpxEdit Owncloud/Nextcloud app ' +
$ ( '#versionnumber' ) . text ( ) . replace ( /\s+/g , '' ) + '" version="1.1"' +
' 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' ;
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' ;
2017-03-21 18:03:57 +00:00
var layerArray = [ ] ;
2017-05-08 01:31:49 +00:00
gpxedit . drawControl . editLayers . eachLayer ( function ( layer ) {
2017-03-21 18:03:57 +00:00
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 ] ;
2017-03-19 17:09:01 +00:00
var id = layer . gpxedit _id ;
var name = gpxedit . layersData [ id ] . name ;
var comment = gpxedit . layersData [ id ] . comment ;
var description = gpxedit . layersData [ id ] . description ;
var time = gpxedit . layersData [ id ] . time ;
if ( layer . type === 'marker' ) {
var symbol = gpxedit . layersData [ id ] . symbol ;
lat = layer . _latlng . lat ;
lng = layer . _latlng . lng ;
alt = layer . _latlng . alt ;
gpxText = gpxText + ' <wpt lat="' + lat + '" lon="' + lng + '">\n' ;
if ( name ) {
gpxText = gpxText + ' <name>' + name + '</name>\n' ;
}
else {
2017-03-21 18:09:16 +00:00
gpxText = gpxText + ' <name></name>\n' ;
2017-03-19 17:09:01 +00:00
}
if ( alt !== undefined ) {
gpxText = gpxText + ' <ele>' + alt + '</ele>\n' ;
}
if ( comment ) {
gpxText = gpxText + ' <cmt>' + comment + '</cmt>\n' ;
}
if ( symbol ) {
gpxText = gpxText + ' <sym>' + symbol + '</sym>\n' ;
}
if ( description ) {
gpxText = gpxText + ' <desc>' + description + '</desc>\n' ;
}
if ( time ) {
gpxText = gpxText + ' <time>' + time + '</time>\n' ;
}
gpxText = gpxText + ' </wpt>\n' ;
2016-12-08 11:07:30 +00:00
}
2017-05-08 01:31:49 +00:00
else if ( ! layer . type || layer . type === 'track' ) {
2017-03-19 17:09:01 +00:00
gpxText = gpxText + ' <trk>\n' ;
if ( name ) {
gpxText = gpxText + ' <name>' + name + '</name>\n' ;
}
else {
2017-03-21 18:09:16 +00:00
gpxText = gpxText + ' <name></name>\n' ;
2017-03-19 17:09:01 +00:00
}
if ( comment ) {
gpxText = gpxText + ' <cmt>' + comment + '</cmt>\n' ;
}
if ( description ) {
gpxText = gpxText + ' <desc>' + description + '</desc>\n' ;
}
gpxText = gpxText + ' <trkseg>\n' ;
for ( i = 0 ; i < layer . _latlngs . length ; i ++ ) {
lat = layer . _latlngs [ i ] . lat ;
lng = layer . _latlngs [ i ] . lng ;
alt = layer . _latlngs [ i ] . alt ;
time = layer . _latlngs [ i ] . time ;
gpxText = gpxText + ' <trkpt lat="' + lat + '" lon="' + lng + '">\n' ;
if ( time ) {
gpxText = gpxText + ' <time>' + time + '</time>\n' ;
}
if ( alt !== undefined ) {
gpxText = gpxText + ' <ele>' + alt + '</ele>\n' ;
}
gpxText = gpxText + ' </trkpt>\n' ;
}
gpxText = gpxText + ' </trkseg>\n </trk>\n' ;
2016-12-08 11:07:30 +00:00
}
2017-03-19 17:09:01 +00:00
else if ( layer . type === 'route' ) {
gpxText = gpxText + ' <rte>\n' ;
if ( name ) {
gpxText = gpxText + ' <name>' + name + '</name>\n' ;
}
else {
2017-03-21 18:09:16 +00:00
gpxText = gpxText + ' <name></name>\n' ;
2016-12-12 13:36:49 +00:00
}
2017-03-19 17:09:01 +00:00
if ( comment ) {
gpxText = gpxText + ' <cmt>' + comment + '</cmt>\n' ;
2016-12-08 11:07:30 +00:00
}
2017-03-19 17:09:01 +00:00
if ( description ) {
gpxText = gpxText + ' <desc>' + description + '</desc>\n' ;
}
for ( i = 0 ; i < layer . _latlngs . length ; i ++ ) {
lat = layer . _latlngs [ i ] . lat ;
lng = layer . _latlngs [ i ] . lng ;
alt = layer . _latlngs [ i ] . alt ;
time = layer . _latlngs [ i ] . time ;
gpxText = gpxText + ' <rtept lat="' + lat + '" lon="' + lng + '">\n' ;
if ( time !== undefined ) {
gpxText = gpxText + ' <time>' + time + '</time>\n' ;
}
if ( alt !== undefined ) {
gpxText = gpxText + ' <ele>' + alt + '</ele>\n' ;
}
gpxText = gpxText + ' </rtept>\n' ;
}
gpxText = gpxText + ' </rte>\n' ;
2016-12-08 11:07:30 +00:00
}
2017-03-21 18:03:57 +00:00
}
2017-03-19 17:09:01 +00:00
gpxText = gpxText + ' <extensions/>\n</gpx>' ;
return gpxText ;
2016-12-06 15:23:14 +00:00
}
2017-03-19 17:09:01 +00:00
// adds a marker and initialize its data
function drawMarker ( latlng , name , desc , cmt , sym , time ) {
var wst = $ ( '#markerstyleselect' ) . val ( ) ;
var tst = $ ( '#tooltipstyleselect' ) . val ( ) ;
var symboo = $ ( '#symboloverwrite' ) . is ( ':checked' ) ;
var m = L . marker ( latlng ) ;
if ( symboo && sym !== '' && symbolIcons . hasOwnProperty ( sym ) ) {
m . setIcon ( symbolIcons [ sym ] ) ;
}
else if ( symboo && sym !== '' ) {
m . setIcon ( L . divIcon ( {
className : 'unknown' ,
iconAnchor : [ 12 , 12 ]
} ) ) ;
2016-12-06 15:23:14 +00:00
}
else {
2017-03-19 17:09:01 +00:00
m . setIcon ( symbolIcons [ wst ] ) ;
2016-12-06 15:23:14 +00:00
}
2017-03-19 17:09:01 +00:00
var layer = onCreated ( 'marker' , m ) ;
if ( name !== '' ) {
if ( tst === 'p' ) {
m . bindTooltip ( name , { permanent : true } ) ;
}
else {
m . bindTooltip ( name , { sticky : true } ) ;
2016-12-16 01:49:51 +00:00
}
2016-12-12 13:36:49 +00:00
}
2017-03-19 17:09:01 +00:00
gpxedit . layersData [ layer . gpxedit _id ] . name = name ;
gpxedit . layersData [ layer . gpxedit _id ] . comment = cmt ;
gpxedit . layersData [ layer . gpxedit _id ] . description = desc ;
gpxedit . layersData [ layer . gpxedit _id ] . symbol = sym ;
gpxedit . layersData [ layer . gpxedit _id ] . time = time ;
2016-12-12 13:36:49 +00:00
}
2017-03-19 17:09:01 +00:00
// adds a polyline and initialize its data
function drawLine ( latlngs , name , desc , cmt , gpxtype , times ) {
var wst = $ ( '#markerstyleselect' ) . val ( ) ;
var tst = $ ( '#tooltipstyleselect' ) . val ( ) ;
2017-05-09 00:14:25 +00:00
var p = L . polyline ( latlngs ) ;
2017-03-19 17:09:01 +00:00
if ( times . length === p . _latlngs . length ) {
for ( var i = 0 ; i < times . length ; i ++ ) {
if ( times [ i ] ) {
p . _latlngs [ i ] . time = times [ i ] ;
}
}
2016-12-06 15:23:14 +00:00
}
2017-03-19 17:09:01 +00:00
var layer = onCreated ( gpxtype , p ) ;
if ( name !== '' ) {
if ( tst === 'p' ) {
p . bindTooltip ( name , { permanent : true } ) ;
}
else {
p . bindTooltip ( name , { sticky : true } ) ;
}
2016-12-06 15:23:14 +00:00
}
2017-03-19 17:09:01 +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 15:23:14 +00:00
}
2017-03-19 17:09:01 +00:00
// parse gpx xml text to draw it on the map
function parseGpx ( xml ) {
//var dom = $.parseXML(xml);
var dom = $ ( xml ) ;
var fileDesc = dom . find ( '>metadata>desc' ) . text ( ) ;
$ ( '#desctext' ) . val ( fileDesc ) ;
dom . find ( 'wpt' ) . each ( function ( ) {
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 ( ) ;
var sym = $ ( this ) . find ( 'sym' ) . text ( ) ;
var ele = $ ( this ) . find ( 'ele' ) . text ( ) ;
var time = $ ( this ) . find ( 'time' ) . text ( ) ;
if ( ele !== '' ) {
drawMarker ( [ lat , lon , ele ] , name , desc , cmt , sym , time ) ;
}
else {
drawMarker ( [ lat , lon ] , name , desc , cmt , sym , time ) ;
}
} ) ;
dom . find ( 'trk' ) . each ( function ( ) {
var latlngs = [ ] ;
var name = $ ( this ) . find ( '>name' ) . text ( ) ;
var cmt = $ ( this ) . find ( '>cmt' ) . text ( ) ;
var desc = $ ( this ) . find ( '>desc' ) . text ( ) ;
var times = [ ] ;
$ ( this ) . find ( 'trkseg' ) . each ( function ( ) {
$ ( this ) . find ( 'trkpt' ) . each ( function ( ) {
var lat = $ ( this ) . attr ( 'lat' ) ;
var lon = $ ( this ) . attr ( 'lon' ) ;
var ele = $ ( this ) . find ( 'ele' ) . text ( ) ;
var time = $ ( this ) . find ( 'time' ) . text ( ) ;
times . push ( time ) ;
if ( ele !== '' ) {
latlngs . push ( [ lat , lon , ele ] ) ;
}
else {
latlngs . push ( [ lat , lon ] ) ;
}
} ) ;
} ) ;
drawLine ( latlngs , name , desc , cmt , 'track' , times ) ;
} ) ;
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 ( ) ;
var times = [ ] ;
$ ( this ) . find ( 'rtept' ) . each ( function ( ) {
2016-12-01 14:56:40 +00:00
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 ) ;
2017-03-19 17:09:01 +00:00
if ( ele !== '' ) {
latlngs . push ( [ lat , lon , ele ] ) ;
2016-12-05 12:00:46 +00:00
}
else {
2017-03-19 17:09:01 +00:00
latlngs . push ( [ lat , lon ] ) ;
2016-12-05 12:00:46 +00:00
}
2016-12-01 14:56:40 +00:00
} ) ;
2017-03-19 17:09:01 +00:00
drawLine ( latlngs , name , desc , cmt , 'route' , times ) ;
2016-12-01 14:56:40 +00:00
} ) ;
2017-03-19 17:09:01 +00:00
}
// remove layers from map and delete all layers data
function clear ( ) {
var i ;
var layersToRemove = [ ] ;
2017-05-08 01:31:49 +00:00
gpxedit . drawControl . editLayers . eachLayer ( function ( layer ) {
2017-03-19 17:09:01 +00:00
layer . unbindTooltip ( ) ;
delete gpxedit . layersData [ layer . gpxedit _id ] ;
layersToRemove . push ( layer ) ;
2016-12-08 09:46:36 +00:00
} ) ;
2016-12-01 18:38:50 +00:00
2017-03-19 17:09:01 +00:00
for ( i = 0 ; i < layersToRemove . length ; i ++ ) {
2017-05-08 01:31:49 +00:00
gpxedit . drawControl . editLayers . removeLayer ( layersToRemove [ i ] ) ;
2017-03-19 17:09:01 +00:00
}
2016-12-01 18:38:50 +00:00
}
2017-03-19 17:09:01 +00:00
/ *
* get key events
* /
function checkKey ( e ) {
e = e || window . event ;
var kc = e . keyCode ;
2017-05-16 15:25:58 +00:00
//console.log(kc);
2017-03-19 17:09:01 +00:00
if ( kc === 161 || kc === 223 ) {
e . preventDefault ( ) ;
gpxedit . minimapControl . _toggleDisplayButtonClicked ( ) ;
}
if ( kc === 60 || kc === 220 ) {
e . preventDefault ( ) ;
$ ( '#sidebar' ) . toggleClass ( 'collapsed' ) ;
}
2017-05-30 14:51:14 +00:00
if ( kc === 46 ) {
if ( gpxedit . hovermiddlemarker ) {
gpxedit . hovermiddlemarker . fire ( 'cut' , gpxedit . hovermiddlemarker ) ;
}
}
2016-12-01 16:04:32 +00:00
}
2017-03-19 17:09:01 +00:00
function showSaveFailAnimation ( path , message ) {
$ ( '#failed' ) . find ( 'b#content' ) . html (
t ( 'gpxedit' , 'Failed to save file' ) + ' ' + path + '<br/>' + message
) ;
$ ( '#failed' ) . fadeIn ( ) ;
setTimeout ( hideFailedAnimation , 4000 ) ;
2016-12-01 16:04:32 +00:00
}
2017-03-19 17:09:01 +00:00
function showFailAnimation ( message ) {
$ ( '#failed' ) . find ( 'b#content' ) . html ( message ) ;
$ ( '#failed' ) . fadeIn ( ) ;
setTimeout ( hideFailedAnimation , 4000 ) ;
2016-12-15 03:07:29 +00:00
}
2017-03-19 17:09:01 +00:00
function hideFailedAnimation ( ) {
$ ( '#failed' ) . fadeOut ( ) ;
2016-12-01 23:00:01 +00:00
}
2017-01-28 03:48:04 +00:00
2017-03-19 17:09:01 +00:00
function showSaveSuccessAnimation ( path ) {
$ ( '#saved' ) . find ( 'b#content' ) . html (
t ( 'gpxedit' , 'File successfully saved as' ) + '<br/>' + path
) ;
$ ( '#saved' ) . fadeIn ( ) ;
setTimeout ( hideSaveSuccessAnimation , 4000 ) ;
}
2016-12-01 23:00:01 +00:00
2017-03-19 17:09:01 +00:00
function hideSaveSuccessAnimation ( ) {
$ ( '#saved' ) . fadeOut ( ) ;
2016-12-06 14:12:40 +00:00
}
2017-03-19 17:09:01 +00:00
function showLoadingAnimation ( ) {
$ ( '#loading' ) . show ( ) ;
2017-03-10 18:24:58 +00:00
}
2017-03-19 17:09:01 +00:00
function hideLoadingAnimation ( ) {
$ ( '#loading' ) . hide ( ) ;
2016-12-06 14:12:40 +00:00
}
2017-03-19 17:09:01 +00:00
function showExportingAnimation ( ) {
$ ( '#exporting' ) . show ( ) ;
2016-12-06 14:12:40 +00:00
}
2017-03-10 18:24:58 +00:00
2017-03-19 17:09:01 +00:00
function hideExportingAnimation ( ) {
$ ( '#exporting' ) . hide ( ) ;
2016-12-13 02:28:57 +00:00
}
2017-03-19 17:09:01 +00:00
function showSavingAnimation ( ) {
$ ( '#saving' ) . show ( ) ;
2016-12-13 02:28:57 +00:00
}
2016-12-06 15:40:54 +00:00
2017-03-19 17:09:01 +00:00
function hideSavingAnimation ( ) {
$ ( '#saving' ) . hide ( ) ;
}
2017-03-27 17:46:04 +00:00
function loadFolderAction ( folder ) {
loadFolder ( folder ) ;
// set save name
var spl = folder . split ( '/' ) ;
var basename = spl [ spl . length - 1 ] ;
$ ( 'input#saveName' ) . val ( basename ) ;
}
function loadFolder ( folder ) {
2017-03-27 18:36:25 +00:00
var type = $ ( 'select#loadtypeselect' ) . val ( ) ;
2017-03-27 17:46:04 +00:00
var req = {
2017-03-27 18:36:25 +00:00
path : folder ,
type : type
2017-03-27 17:46:04 +00:00
} ;
var url = OC . generateUrl ( '/apps/gpxedit/getfoldergpxs' ) ;
$ ( '#loadingpc' ) . text ( '0' ) ;
showLoadingAnimation ( ) ;
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 ;
$ ( '#loadingpc' ) . text ( parseInt ( percentComplete ) ) ;
}
} , false ) ;
return xhr ;
}
} ) . done ( function ( response ) {
var i ;
if ( $ ( '#clearbeforeload' ) . is ( ':checked' ) ) {
clear ( ) ;
}
if ( response . gpxs . length === 0 ) {
OC . dialogs . alert ( 'The folder does not exist or does not contain any compatible file' ,
'Load folder error' ) ;
}
else {
for ( i = 0 ; i < response . gpxs . length ; i ++ ) {
parseGpx ( response . gpxs [ i ] ) ;
}
try {
2017-05-08 01:31:49 +00:00
var bounds = gpxedit . drawControl . editLayers . getBounds ( ) ;
2017-03-27 17:46:04 +00:00
gpxedit . map . fitBounds (
bounds ,
{
animate : true ,
paddingTopLeft : [ parseInt ( $ ( '#sidebar' ) . css ( 'width' ) ) , 0 ]
}
) ;
}
catch ( err ) {
console . log ( 'Impossible to fit to bounds \n' + err ) ;
}
}
hideLoadingAnimation ( ) ;
} ) . fail ( function ( ) {
OC . dialogs . alert ( 'Failed to communicate with the server' ,
'Load folder error' ) ;
hideLoadingAnimation ( ) ;
} ) ;
}
2017-03-19 17:09:01 +00:00
function loadAction ( file ) {
if ( ! endsWith ( file , '.gpx' )
&& ! endsWith ( file , '.kml' )
&& ! endsWith ( file , '.jpg' )
&& ! endsWith ( file , '.csv' )
) {
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' )
) ;
return ;
2016-12-06 15:40:54 +00:00
}
2016-12-06 18:22:26 +00:00
2017-03-19 17:09:01 +00:00
loadFile ( file ) ;
// set save name
var spl = file . split ( '/' ) ;
var basename = spl [ spl . length - 1 ] ;
$ ( 'input#saveName' ) . val (
basename . replace ( /\.jpg$/ , '.gpx' )
. replace ( /\.kml$/ , '.gpx' )
. replace ( /\.csv$/ , '.gpx' )
) ;
}
function loadFile ( file ) {
var req = {
path : file
} ;
var url = OC . generateUrl ( '/apps/gpxedit/getgpx' ) ;
$ ( '#loadingpc' ) . text ( '0' ) ;
showLoadingAnimation ( ) ;
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 ;
$ ( '#loadingpc' ) . text ( parseInt ( percentComplete ) ) ;
}
} , false ) ;
return xhr ;
}
} ) . done ( function ( response ) {
if ( $ ( '#clearbeforeload' ) . is ( ':checked' ) ) {
clear ( ) ;
}
if ( response . gpx === '' ) {
OC . dialogs . alert ( 'The file does not exist or it is not supported' ,
'Load error' ) ;
2016-12-06 18:22:26 +00:00
}
2017-03-26 22:37:51 +00:00
else {
2017-03-19 17:09:01 +00:00
parseGpx ( response . gpx ) ;
2017-03-26 22:37:51 +00:00
try {
2017-05-08 01:31:49 +00:00
var bounds = gpxedit . drawControl . editLayers . getBounds ( ) ;
2017-03-26 22:37:51 +00:00
gpxedit . map . fitBounds (
bounds ,
{
animate : true ,
paddingTopLeft : [ parseInt ( $ ( '#sidebar' ) . css ( 'width' ) ) , 0 ]
}
) ;
}
catch ( err ) {
console . log ( 'Impossible to fit to bounds \n' + err ) ;
}
2016-12-06 18:22:26 +00:00
}
2017-03-26 22:37:51 +00:00
hideLoadingAnimation ( ) ;
} ) . fail ( function ( ) {
OC . dialogs . alert ( 'Failed to communicate with the server' ,
'Load error' ) ;
hideLoadingAnimation ( ) ;
2017-03-19 17:09:01 +00:00
} ) ;
}
2017-05-14 15:57:53 +00:00
function deleteTileServer ( li , type ) {
2017-06-12 22:45:54 +00:00
var sname = li . attr ( 'servername' ) ;
2017-03-19 17:09:01 +00:00
var req = {
2017-05-14 15:57:53 +00:00
servername : sname ,
type : type
2017-03-19 17:09:01 +00:00
} ;
var url = OC . generateUrl ( '/apps/gpxedit/deleteTileServer' ) ;
$ . ajax ( {
type : 'POST' ,
url : url ,
data : req ,
async : true
} ) . done ( function ( response ) {
if ( response . done ) {
li . fadeOut ( 'slow' , function ( ) {
li . remove ( ) ;
} ) ;
2017-05-14 15:57:53 +00:00
if ( type === 'tile' ) {
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 ] ;
2017-03-19 17:09:01 +00:00
}
2017-05-14 15:57:53 +00:00
else {
gpxedit . activeLayers . removeLayer ( gpxedit . overlayLayers [ sname ] ) ;
delete gpxedit . overlayLayers [ sname ] ;
}
OC . Notification . showTemporary ( t ( 'gpxedit' , 'Tile server "{ts}" has been deleted' , { ts : sname } ) ) ;
2017-03-19 17:09:01 +00:00
}
else {
2017-05-14 15:57:53 +00:00
OC . Notification . showTemporary ( t ( 'gpxedit' , 'Failed to delete tile server "{ts}"' , { ts : sname } ) ) ;
2017-03-19 17:09:01 +00:00
}
} ) . always ( function ( ) {
} ) . fail ( function ( ) {
2017-05-14 15:57:53 +00:00
OC . Notification . showTemporary ( t ( 'gpxedit' , 'Failed to delete tile server "{ts}"' , { ts : sname } ) ) ;
2017-03-19 17:09:01 +00:00
} ) ;
}
2017-05-14 15:57:53 +00:00
function addTileServer ( type ) {
var sname = $ ( '#' + type + 'servername' ) . val ( ) ;
var surl = $ ( '#' + type + 'serverurl' ) . val ( ) ;
2017-06-12 22:45:54 +00:00
var sminzoom = $ ( '#' + type + 'minzoom' ) . val ( ) ;
var smaxzoom = $ ( '#' + type + 'maxzoom' ) . val ( ) ;
var stransparent = $ ( '#' + type + 'transparent' ) . val ( ) || '' ;
var sopacity = $ ( '#' + type + 'opacity' ) . val ( ) || '' ;
var sformat = $ ( '#' + type + 'format' ) . val ( ) || '' ;
var sversion = $ ( '#' + type + 'version' ) . val ( ) || '' ;
var slayers = $ ( '#' + type + 'layers' ) . val ( ) || '' ;
2017-03-19 17:09:01 +00:00
if ( sname === '' || surl === '' ) {
OC . dialogs . alert ( t ( 'gpxedit' , 'Server name or server url should not be empty' ) ,
t ( 'gpxedit' , 'Impossible to add tile server' ) ) ;
return ;
}
2017-06-12 22:45:54 +00:00
if ( $ ( '#' + type + 'serverlist ul li[servername="' + sname + '"]' ) . length > 0 ) {
2017-03-19 17:09:01 +00:00
OC . dialogs . alert ( t ( 'gpxedit' , 'A server with this name already exists' ) ,
t ( 'gpxedit' , 'Impossible to add tile server' ) ) ;
return ;
2016-12-06 15:40:54 +00:00
}
2017-05-14 15:57:53 +00:00
$ ( '#' + type + 'servername' ) . val ( '' ) ;
$ ( '#' + type + 'serverurl' ) . val ( '' ) ;
2017-03-19 17:09:01 +00:00
var req = {
servername : sname ,
2017-05-14 15:57:53 +00:00
serverurl : surl ,
2017-06-12 22:45:54 +00:00
type : type ,
layers : slayers ,
version : sversion ,
tformat : sformat ,
opacity : sopacity ,
transparent : stransparent ,
minzoom : sminzoom ,
maxzoom : smaxzoom ,
attribution : ''
2017-03-19 17:09:01 +00:00
} ;
var url = OC . generateUrl ( '/apps/gpxedit/addTileServer' ) ;
$ . ajax ( {
type : 'POST' ,
url : url ,
data : req ,
async : true
} ) . done ( function ( response ) {
if ( response . done ) {
2017-05-14 15:57:53 +00:00
$ ( '#' + type + 'serverlist ul' ) . prepend (
2017-06-12 22:45:54 +00:00
'<li style="display:none;" servername="' + escapeHTML ( sname ) +
2017-05-14 15:57:53 +00:00
'" title="' + escapeHTML ( surl ) + '">' +
escapeHTML ( sname ) + ' <button>' +
2017-03-19 17:09:01 +00:00
'<i class="fa fa-trash" aria-hidden="true" style="color:red;"></i> ' +
2017-05-05 00:19:38 +00:00
t ( 'gpxedit' , 'Delete' ) +
'</button></li>'
2017-03-19 17:09:01 +00:00
) ;
2017-06-12 22:45:54 +00:00
$ ( '#' + type + 'serverlist ul li[servername="' + sname + '"]' ) . fadeIn ( 'slow' ) ;
2017-05-14 15:57:53 +00:00
if ( type === 'tile' ) {
// add tile server in leaflet control
var newlayer = new L . TileLayer ( surl ,
{ maxZoom : 18 , attribution : 'custom ' + type + ' server' } ) ;
gpxedit . activeLayers . addBaseLayer ( newlayer , sname ) ;
gpxedit . baseLayers [ sname ] = newlayer ;
}
else {
// add tile server in leaflet control
var newlayer = new L . TileLayer ( surl ,
{ maxZoom : 18 , attribution : 'custom ' + type + ' server' } ) ;
gpxedit . activeLayers . addOverlay ( newlayer , sname ) ;
gpxedit . overlayLayers [ sname ] = newlayer ;
}
OC . Notification . showTemporary ( t ( 'gpxedit' , 'Tile server "{ts}" has been added' , { ts : sname } ) ) ;
2016-12-06 15:40:54 +00:00
}
else {
2017-05-14 15:57:53 +00:00
OC . Notification . showTemporary ( t ( 'gpxedit' , 'Failed to add tile server "{ts}"' , { ts : sname } ) ) ;
2016-12-06 15:40:54 +00:00
}
2017-03-19 17:09:01 +00:00
} ) . always ( function ( ) {
} ) . fail ( function ( ) {
2017-05-14 15:57:53 +00:00
OC . Notification . showTemporary ( t ( 'gpxedit' , 'Failed to add tile server "{ts}"' , { ts : sname } ) ) ;
2017-03-19 17:09:01 +00:00
} ) ;
}
// affects future markers and also existing ones
function updateLeafletDrawMarkerStyle ( ) {
var wst = $ ( '#markerstyleselect' ) . val ( ) ;
var theclass = symbolSelectClasses [ wst ] ;
$ ( '#markerstyleselect' ) . removeClass ( $ ( '#markerstyleselect' ) . attr ( 'class' ) ) ;
$ ( '#markerstyleselect' ) . attr ( 'style' , '' ) ;
if ( theclass ) {
$ ( '#markerstyleselect' ) . addClass ( theclass ) ;
2016-12-06 15:40:54 +00:00
}
2017-03-19 17:09:01 +00:00
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);' +
'background-size: contain;'
) ;
}
var tst = $ ( '#tooltipstyleselect' ) . val ( ) ;
var theicon = symbolIcons [ wst ] ;
2016-12-06 15:23:14 +00:00
2017-03-19 17:09:01 +00:00
gpxedit . drawControl . setDrawingOptions ( {
marker : {
icon : theicon
}
} ) ;
2016-12-06 16:29:49 +00:00
2017-03-19 17:09:01 +00:00
var symboo = $ ( '#symboloverwrite' ) . is ( ':checked' ) ;
2017-05-08 01:31:49 +00:00
gpxedit . drawControl . editLayers . eachLayer ( function ( layer ) {
2017-03-19 17:09:01 +00:00
var id = layer . gpxedit _id ;
var name = gpxedit . layersData [ id ] . name ;
var symbol = gpxedit . layersData [ id ] . symbol ;
if ( layer . type === 'marker' ) {
if ( symboo && symbol !== ''
&& symbolIcons . hasOwnProperty ( symbol )
) {
layer . setIcon ( symbolIcons [ symbol ] ) ;
}
else {
layer . setIcon ( theicon ) ;
}
}
if ( name !== '' ) {
layer . unbindTooltip ( ) ;
if ( tst === 'p' ) {
layer . bindTooltip ( name , { permanent : true } ) ;
}
else {
layer . bindTooltip ( name , { sticky : true } ) ;
}
}
2016-12-13 02:28:57 +00:00
} ) ;
2016-12-15 02:54:28 +00:00
}
2017-01-28 03:48:04 +00:00
2017-03-19 17:09:01 +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-05-05 00:19:38 +00:00
OC . dialogs . alert ( t ( 'gpxedit' , 'Failed to restore options values' ) ,
2017-03-19 17:09:01 +00:00
t ( 'gpxedit' , 'Error' ) ) ;
} ) ;
optionsValues = $ . parseJSON ( optionsValues ) ;
2017-05-07 01:06:28 +00:00
if ( optionsValues ) {
if ( optionsValues . markerstyle !== undefined
&& symbolIcons . hasOwnProperty ( optionsValues . markerstyle )
) {
$ ( '#markerstyleselect' ) . val ( optionsValues . markerstyle ) ;
}
if ( optionsValues . tooltipstyle !== undefined ) {
$ ( '#tooltipstyleselect' ) . val ( optionsValues . tooltipstyle ) ;
}
if ( optionsValues . clearbeforeload !== undefined ) {
$ ( '#clearbeforeload' ) . prop ( 'checked' , optionsValues . clearbeforeload ) ;
}
if ( optionsValues . symboloverwrite !== undefined ) {
$ ( '#symboloverwrite' ) . prop ( 'checked' , optionsValues . symboloverwrite ) ;
}
2017-06-01 17:19:05 +00:00
if ( optionsValues . approximateele !== undefined ) {
$ ( '#approximateele' ) . prop ( 'checked' , optionsValues . approximateele ) ;
L . drawLocal . edit . approximateElevations = $ ( '#approximateele' ) . is ( ':checked' ) ;
}
2017-05-07 01:06:28 +00:00
if ( optionsValues . tilelayer !== undefined ) {
gpxedit . restoredTileLayer = optionsValues . tilelayer ;
}
2016-12-15 02:54:28 +00:00
}
2017-03-19 17:09:01 +00:00
}
function saveOptions ( ) {
var optionsValues = { } ;
optionsValues . markerstyle = $ ( '#markerstyleselect' ) . val ( ) ;
optionsValues . tooltipstyle = $ ( '#tooltipstyleselect' ) . val ( ) ;
optionsValues . clearbeforeload = $ ( '#clearbeforeload' ) . is ( ':checked' ) ;
optionsValues . symboloverwrite = $ ( '#symboloverwrite' ) . is ( ':checked' ) ;
2017-06-01 17:19:05 +00:00
optionsValues . approximateele = $ ( '#approximateele' ) . is ( ':checked' ) ;
2017-03-19 17:09:01 +00:00
optionsValues . tilelayer = gpxedit . activeLayers . getActiveBaseLayer ( ) . name ;
//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-05-05 00:19:38 +00:00
OC . dialogs . alert ( t ( 'gpxedit' , 'Failed to save options values' ) ,
2017-03-19 17:09:01 +00:00
t ( 'gpxedit' , 'Error' ) ) ;
} ) ;
}
function fillWaypointStyles ( ) {
for ( var st in symbolIcons ) {
$ ( 'select#markerstyleselect' ) . append (
'<option value="' + st + '">' + st + '</option>'
) ;
2016-12-15 02:54:28 +00:00
}
2017-03-19 17:09:01 +00:00
$ ( 'select#markerstyleselect' ) . val ( 'marker' ) ;
}
2016-12-15 02:54:28 +00:00
2017-03-19 17:09:01 +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-11-30 19:00:03 +00:00
2017-03-19 17:09:01 +00:00
function saveAction ( targetPath ) {
showExportingAnimation ( ) ;
var saveFilePath = targetPath + '/' + $ ( 'input#saveName' ) . val ( ) ;
var gpxText = generateGpx ( ) ;
hideExportingAnimation ( ) ;
$ ( '#savingpc' ) . text ( '0' ) ;
showSavingAnimation ( ) ;
var req = {
path : saveFilePath ,
content : gpxText
} ;
var url = OC . generateUrl ( '/apps/gpxedit/savegpx' ) ;
$ . 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
$ ( '#savingpc' ) . text ( parseInt ( percentComplete ) ) ;
}
} , false ) ;
2016-11-30 19:00:03 +00:00
2017-03-19 17:09:01 +00:00
return xhr ;
2016-12-19 22:45:13 +00:00
}
2017-03-19 17:09:01 +00:00
} ) . done ( function ( response ) {
hideSavingAnimation ( ) ;
if ( response . status === 'fiw' ) {
showSaveFailAnimation (
saveFilePath ,
t ( 'gpxedit' , 'Impossible to write file' ) + ' : ' +
t ( 'gpxedit' , 'write access denied' )
) ;
2016-12-06 19:28:29 +00:00
}
2017-03-19 17:09:01 +00:00
else if ( response . status === 'fu' ) {
showSaveFailAnimation (
saveFilePath ,
t ( 'gpxedit' , 'Impossible to write file' ) + ' : ' +
t ( 'gpxedit' , 'folder does not exist' )
) ;
2016-12-06 19:28:29 +00:00
}
2017-03-19 17:09:01 +00:00
else if ( response . status === 'fw' ) {
showSaveFailAnimation (
saveFilePath ,
t ( 'gpxedit' , 'Impossible to write file' ) + ' : ' +
t ( 'gpxedit' , 'folder write access denied' )
) ;
}
else if ( response . status === 'bfn' ) {
showSaveFailAnimation (
saveFilePath ,
t ( 'gpxedit' , 'Bad file name, must end with ".gpx"' )
) ;
2016-12-06 15:23:14 +00:00
}
else {
2017-03-19 17:09:01 +00:00
showSaveSuccessAnimation ( saveFilePath ) ;
2016-12-06 15:23:14 +00:00
}
2017-03-19 17:09:01 +00:00
} ) ;
}
2016-11-30 19:00:03 +00:00
2017-03-19 17:09:01 +00:00
$ ( document ) . ready ( function ( ) {
gpxedit . username = $ ( 'p#username' ) . html ( ) ;
document . onkeydown = checkKey ;
addExtraSymbols ( ) ;
fillWaypointStyles ( ) ;
restoreOptions ( ) ;
load _map ( ) ;
$ ( 'select#markerstyleselect' ) . change ( function ( e ) {
updateLeafletDrawMarkerStyle ( ) ;
saveOptions ( ) ;
} ) ;
$ ( 'select#tooltipstyleselect' ) . change ( function ( e ) {
updateLeafletDrawMarkerStyle ( ) ;
saveOptions ( ) ;
} ) ;
$ ( 'body' ) . on ( 'change' , '#symboloverwrite' , function ( ) {
updateLeafletDrawMarkerStyle ( ) ;
saveOptions ( ) ;
} ) ;
// to set the draw style
updateLeafletDrawMarkerStyle ( ) ;
$ ( 'body' ) . on ( 'change' , '#clearbeforeload' , function ( ) {
saveOptions ( ) ;
} ) ;
2017-06-01 17:19:05 +00:00
$ ( 'body' ) . on ( 'change' , '#approximateele' , function ( ) {
L . drawLocal . edit . approximateElevations = $ ( this ) . is ( ':checked' ) ;
saveOptions ( ) ;
} ) ;
2017-03-19 17:09:01 +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 ( ) ;
var symbol = $ ( this ) . parent ( ) . find ( 'select[role=symbol]' ) . val ( ) ;
var wst = $ ( '#markerstyleselect' ) . val ( ) ;
var tst = $ ( '#tooltipstyleselect' ) . val ( ) ;
var symboo = $ ( '#symboloverwrite' ) . is ( ':checked' ) ;
var type = gpxedit . layersData [ id ] . layer . type ;
gpxedit . layersData [ id ] . name = name ;
gpxedit . layersData [ id ] . description = description ;
gpxedit . layersData [ id ] . comment = comment ;
if ( symbol !== 'unknown' ) {
gpxedit . layersData [ id ] . symbol = symbol ;
}
gpxedit . layersData [ id ] . layer . unbindTooltip ( ) ;
if ( type === 'marker' ) {
if ( symbol === 'unknown' ) {
// pass
}
else if ( symboo && symbol !== ''
&& symbolIcons . hasOwnProperty ( symbol )
) {
gpxedit . layersData [ id ] . layer . setIcon ( symbolIcons [ symbol ] ) ;
}
else {
var theicon = symbolIcons [ wst ] ;
gpxedit . layersData [ id ] . layer . setIcon ( theicon ) ;
}
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 ) ;
}
if ( name !== '' ) {
if ( tst === 'p' ) {
gpxedit . layersData [ id ] . layer . bindTooltip (
name ,
{ permanent : true }
) ;
}
else {
gpxedit . layersData [ id ] . layer . bindTooltip (
name ,
{ sticky : true }
) ;
}
}
2016-12-01 00:30:19 +00:00
2017-03-19 17:09:01 +00:00
gpxedit . map . closePopup ( ) ;
} ) ;
2016-12-02 09:51:27 +00:00
2017-03-19 17:09:01 +00:00
$ ( 'button#clearButton' ) . click ( function ( e ) {
2017-05-24 12:37:34 +00:00
var cancelButton = $ ( '.leaflet-draw .leaflet-draw-section:nth-child(2) li:nth-child(2) a' ) ;
if ( cancelButton . is ( ':visible' ) ) {
cancelButton [ 0 ] . click ( ) ;
}
2017-03-19 17:09:01 +00:00
clear ( ) ;
} ) ;
$ ( 'button#loadButton' ) . click ( function ( e ) {
2017-05-24 12:37:34 +00:00
var cancelButton = $ ( '.leaflet-draw .leaflet-draw-section:nth-child(2) li:nth-child(2) a' ) ;
if ( cancelButton . is ( ':visible' ) ) {
cancelButton [ 0 ] . click ( ) ;
}
2017-03-19 17:09:01 +00:00
if ( gpxedit . currentAjax !== null ) {
gpxedit . currentAjax . abort ( ) ;
hideLoadingAnimation ( ) ;
}
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
2017-03-27 17:46:04 +00:00
$ ( 'button#loadFolderButton' ) . click ( function ( e ) {
if ( gpxedit . currentAjax !== null ) {
gpxedit . currentAjax . abort ( ) ;
hideLoadingAnimation ( ) ;
}
2017-03-27 18:36:25 +00:00
var type = $ ( 'select#loadtypeselect' ) . val ( ) ;
2017-03-27 17:46:04 +00:00
OC . dialogs . filepicker (
2017-05-05 00:19:38 +00:00
t ( 'gpxedit' , 'Load folder' ) + ' (' +
t ( 'gpxedit' , type ) +
')' ,
2017-03-27 17:46:04 +00:00
function ( targetPath ) {
loadFolderAction ( targetPath ) ;
} ,
false , "httpd/unix-directory" , true
) ;
} ) ;
2017-03-19 17:09:01 +00:00
$ ( 'button#saveButton' ) . click ( function ( e ) {
2017-05-08 01:31:49 +00:00
if ( gpxedit . drawControl . editLayers . getLayers ( ) . length === 0 ) {
2017-03-19 17:09:01 +00:00
showFailAnimation ( t ( 'gpxedit' , 'There is nothing to save' ) ) ;
}
else {
var filename = $ ( '#saveName' ) . val ( ) ;
OC . dialogs . filepicker (
2017-05-05 00:19:38 +00:00
t ( 'gpxedit' , 'Where to save' ) +
' <b>' + filename + '</b>' ,
2017-03-19 17:09:01 +00:00
function ( targetPath ) {
saveAction ( targetPath ) ;
} ,
false , "httpd/unix-directory" , true
) ;
}
} ) ;
2016-12-06 14:12:40 +00:00
2017-03-19 17:09:01 +00:00
// Custom tile server management
$ ( 'body' ) . on ( 'click' , '#tileserverlist button' , function ( e ) {
2017-05-14 15:57:53 +00:00
deleteTileServer ( $ ( this ) . parent ( ) , 'tile' ) ;
2017-03-19 17:09:01 +00:00
} ) ;
$ ( '#addtileserver' ) . click ( function ( ) {
2017-05-14 15:57:53 +00:00
addTileServer ( 'tile' ) ;
} ) ;
$ ( 'body' ) . on ( 'click' , '#overlayserverlist button' , function ( e ) {
deleteTileServer ( $ ( this ) . parent ( ) , 'overlay' ) ;
} ) ;
$ ( '#addoverlayserver' ) . click ( function ( ) {
addTileServer ( 'overlay' ) ;
2017-03-19 17:09:01 +00:00
} ) ;
2016-12-07 17:53:14 +00:00
2017-06-12 22:45:54 +00:00
$ ( 'body' ) . on ( 'click' , '#tileserverwmslist button' , function ( e ) {
deleteTileServer ( $ ( this ) . parent ( ) , 'tilewms' ) ;
} ) ;
$ ( '#addtileserverwms' ) . click ( function ( ) {
addTileServer ( 'tilewms' ) ;
} ) ;
$ ( 'body' ) . on ( 'click' , '#overlayserverwmslist button' , function ( e ) {
deleteTileServer ( $ ( this ) . parent ( ) , 'overlaywms' ) ;
} ) ;
$ ( '#addoverlayserverwms' ) . click ( function ( ) {
addTileServer ( 'overlaywms' ) ;
} ) ;
2017-03-19 17:09:01 +00:00
$ ( 'body' ) . on ( 'change' , 'select[role=symbol]' , function ( ) {
$ ( this ) . removeClass ( $ ( this ) . attr ( 'class' ) ) ;
$ ( 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);' +
'background-size: contain;'
) ;
}
} ) ;
2016-12-08 17:27:50 +00:00
2017-03-19 17:09:01 +00:00
// load a file if 'file' GET url parameter was given
2017-03-24 20:54:42 +00:00
var fileparam = getUrlParameter ( 'file' ) ;
if ( fileparam && fileparam !== undefined ) {
loadAction ( fileparam ) ;
2017-03-19 17:09:01 +00:00
}
2017-04-04 23:59:28 +00:00
// load a directory if 'dir' GET url parameter was given
var dirparam = getUrlParameter ( 'dir' ) ;
if ( dirparam && dirparam !== undefined ) {
loadFolderAction ( dirparam ) ;
}
2017-03-19 17:09:01 +00:00
2017-05-24 15:45:22 +00:00
L . LatLngUtil . cloneLatLng = function ( latlng ) {
var ll = L . latLng ( latlng . lat , latlng . lng ) ;
if ( latlng . alt ) {
ll . alt = latlng . alt ;
}
if ( latlng . time ) {
ll . time = latlng . time ;
}
return ll ;
} ;
2017-05-30 14:51:14 +00:00
gpxedit . map . on ( 'middlehover' , function ( m ) {
gpxedit . hovermiddlemarker = m ;
} ) ;
gpxedit . map . on ( 'middlehoverout' , function ( ) {
gpxedit . hovermiddlemarker = null ;
} ) ;
2017-03-19 17:09:01 +00:00
} ) ;
2016-11-30 19:00:03 +00:00
} ) ( jQuery , OC ) ;