diff --git a/js/gpxedit.js b/js/gpxedit.js index 4041c1d..23b492d 100644 --- a/js/gpxedit.js +++ b/js/gpxedit.js @@ -180,8 +180,8 @@ function load_map() { //gpxedit.map.on('zoomend',updateTrackListFromBounds); //gpxedit.map.on('baselayerchange',updateTrackListFromBounds); - var editableLayers = new L.FeatureGroup(); - gpxedit.map.addLayer(editableLayers); + gpxedit.editableLayers = new L.FeatureGroup(); + gpxedit.map.addLayer(gpxedit.editableLayers); var MyCustomMarker = L.Icon.extend({ options: { @@ -217,7 +217,7 @@ function load_map() { } }, edit: { - featureGroup: editableLayers, //REQUIRED!! + featureGroup: gpxedit.editableLayers, //REQUIRED!! } }; @@ -240,7 +240,7 @@ function load_map() { layer.gpxedit_id = gpxedit.id; layer.type = type; gpxedit.layersData[gpxedit.id] = {name:'', description:'', comment:'', layer: layer}; - editableLayers.addLayer(layer); + gpxedit.editableLayers.addLayer(layer); gpxedit.id++; }); gpxedit.map.on('draw:edited', function (e) { @@ -249,17 +249,17 @@ function load_map() { //do whatever you want; most likely save back to db //alert('edited : '+Object.keys(layer)); }); - editableLayers.eachLayer(function (layer) { - //alert('edited : '+Object.keys(layer)); - alert('edited : '+Object.keys(layer._leaflet_id)); - }); + //editableLayers.eachLayer(function (layer) { + // //alert('edited : '+Object.keys(layer)); + // alert('edited : '+Object.keys(layer._leaflet_id)); + //}); }); gpxedit.map.on('draw:deleted', function (e) { var layers = e.layers; layers.eachLayer(function (layer) { delete gpxedit.layersData[layer.gpxedit_id]; }); - editableLayers.eachLayer(function (layer) { + gpxedit.editableLayers.eachLayer(function (layer) { alert(layer.gpxedit_id); }); }); @@ -288,6 +288,69 @@ function getUrlParameter(sParam) } } +function generateGpx(){ + var gpxText = '\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 + '\n'; + gpxText = gpxText + '\n\n\n'; + + 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; + if (layer.type === 'marker'){ + var lat = layer._latlng.lat; + var lng = layer._latlng.lng; + gpxText = gpxText + ' \n'; + if (name){ + gpxText = gpxText + ' '+name+'\n'; + } + else{ + gpxText = gpxText + ' unnamed\n'; + } + if (comment){ + gpxText = gpxText + ' '+comment+'\n'; + } + if (description){ + gpxText = gpxText + ' '+description+'\n'; + } + gpxText = gpxText + ' \n'; + } + else{ + gpxText = gpxText + ' \n'; + if (name){ + gpxText = gpxText + ' '+name+'\n'; + } + else{ + gpxText = gpxText + ' unnamed\n'; + } + if (comment){ + gpxText = gpxText + ' '+comment+'\n'; + } + if (description){ + gpxText = gpxText + ' '+description+'\n'; + } + gpxText = gpxText + ' \n'; + for (var i=0; i\n'+ + ' \n'; + } + gpxText = gpxText + '\n\n'; + } + }); + gpxText = gpxText + ' \n'; + return gpxText; +} + $(document).ready(function(){ gpxedit.username = $('p#username').html(); load_map(); @@ -305,6 +368,14 @@ $(document).ready(function(){ gpxedit.map.closePopup(); }); + + $('button#saveButton').click(function(e){ + var gpxText = generateGpx(); + alert(gpxText); + //var m = L.marker([0,0]); + //m.addTo(gpxedit.map); + //m.addTo(gpxedit.editableLayers); + }); }); })(jQuery, OC);