[Mapbender-commits] r9154 - in trunk/mapbender/http: php plugins
svn_mapbender at osgeo.org
svn_mapbender at osgeo.org
Mon Feb 23 06:16:59 PST 2015
Author: syed
Date: 2015-02-23 06:16:59 -0800 (Mon, 23 Feb 2015)
New Revision: 9154
Added:
trunk/mapbender/http/php/mod_GetPublishedData.php
Modified:
trunk/mapbender/http/plugins/kmlTree.js
Log:
fix publish data-collection
Added: trunk/mapbender/http/php/mod_GetPublishedData.php
===================================================================
--- trunk/mapbender/http/php/mod_GetPublishedData.php (rev 0)
+++ trunk/mapbender/http/php/mod_GetPublishedData.php 2015-02-23 14:16:59 UTC (rev 9154)
@@ -0,0 +1,293 @@
+<?php
+
+/**
+ * @version Changed: ### 2015-02-23 14:00:42 UTC ###
+ * @author Raphael.Syed <raphael.syed at WhereGroup.com> http://WhereGroup.com
+ */
+
+
+//import classes
+require_once(dirname(__FILE__) . "/../classes/class_wmc.php");
+require_once(dirname(__FILE__)."/../php/mb_validateSession.php");
+include_once(dirname(__FILE__)."../../lib/geoPHP/geoPHP.inc");
+
+/**
+ * publish the choosed data
+ */
+
+// get data from session and request
+$user_id = Mapbender::session()->get("mb_user_id");
+$wmc_id = $_GET["wmc_id"];
+$outputFormat = $_GET['outputFormat'];
+$wmc_serial_id;
+
+
+//get the wmc_serial_id from database
+
+$sql = 'SELECT wmc_serial_id FROM mb_user_wmc WHERE wmc_id = $1';
+$v = array($wmc_id);
+$t = array("c");
+$res = db_prep_query($sql, $v, $t);
+//fetch the array
+if($row = db_fetch_array($res)){
+
+ $wmc_serial_id = $row;
+
+}
+
+//create a WMC object from a WMC in the database
+$xml = wmc::getDocument($wmc_serial_id[0]);
+$myWmc = new wmc();
+$myWmc->createFromXml($xml);
+
+# Decode from JSON to array
+foreach ($myWmc->generalExtensionArray as $key => &$value) {
+ $value = json_decode($value,true);
+}
+// create and numerically indexed array
+$kmls = array_values($myWmc->generalExtensionArray["KMLS"]);
+//parse the geojson from the array
+$geoJson = $kmls[0]["data"];
+//create the fileName
+$file = "myDataCollection.".$outputFormat;
+// set headers to force the download
+header("Content-Disposition: attachment; filename=" . urlencode($file));
+header("Content-Type: application/force-download");
+header("Content-Type: application/octet-stream");
+header("Content-Type: application/download");
+
+
+// handle the different outputformat
+if ($outputFormat == 'geojson') {
+ // create the json-file
+ $geoJsonFile = '../tmp/myDataCollection.geojson';
+ // put the contents to the created file
+ file_put_contents($geoJsonFile, json_encode($geoJson));
+ // create a string from the created file
+ $fileString = file_get_contents('../tmp/myDataCollection.geojson');
+ // return the string
+ echo $fileString;
+ die;
+
+}elseif ($outputFormat == 'gpx') {
+ //convert geojson to kml
+
+ //create the geojson-file temporary
+ $temp_geojson = '../tmp/myDataCollection.geojson';
+ // write the file
+ file_put_contents($temp_geojson,json_encode($geoJson));
+ //transform the geojson to kml
+ $unique = '../tmp/myDataCollection';
+ $fGeojson = $unique.".geojson";
+ $fKml = $unique.".kml";
+ $pathOgr = '/usr/bin/ogr2ogr';
+ // execute ogr2ogr
+ $exec = $pathOgr.' -f KML '.$fKml.' '.$fGeojson;
+ exec(escapeshellcmd($exec));
+ //enter location of KML file here
+ $kml = "../tmp/myDataCollection.kml";
+ // create gpx from kml
+ kml_to_gpx($kml);
+ die;
+
+}elseif ($outputFormat == 'kml') {
+ //convert geojson to kml
+
+ //create the geojson-file temporary
+ $temp_geojson = '../tmp/myDataCollection.geojson';
+ // write the file
+ file_put_contents($temp_geojson,json_encode($geoJson));
+ //transform the file to kml
+ $unique = '../tmp/myDataCollection';
+ $fGeojson = $unique.".geojson";
+ $fKml = $unique.".kml";
+ $pathOgr = '/usr/bin/ogr2ogr';
+ //execute ogr2ogr to transfrom json to kml
+ $exec = $pathOgr.' -f KML '.$fKml.' '.$fGeojson;
+ exec(escapeshellcmd($exec));
+ // create string from kml-file
+ $fileString = file_get_contents('../tmp/myDataCollection.kml');
+ //return the string
+ echo $fileString;
+ die;
+}
+
+/**
+ * converts a kml-file into a gpx-file
+ * @param string $u the file location
+ * @return the gpx-file
+ */
+function kml_to_gpx($u){
+
+ $u_parts = pathinfo($u); //array of url parts
+ $u_ext = strtoupper($u_parts['extension']);
+ if ($u_ext== "KML") {
+
+ $dom_kml = new DOMDocument();
+ $dom_kml->load($u);
+
+ $dom_gpx = new DOMDocument('1.0', 'UTF-8');
+ $dom_gpx->formatOutput = true;
+
+ //root node
+ $gpx = $dom_gpx->createElement('gpx');
+ $gpx = $dom_gpx->appendChild($gpx);
+
+ $gpx_version = $dom_gpx->createAttribute('version');
+ $gpx->appendChild($gpx_version);
+ $gpx_version_text = $dom_gpx->createTextNode('1.0');
+ $gpx_version->appendChild($gpx_version_text);
+
+ $gpx_creator = $dom_gpx->createAttribute('creator');
+ $gpx->appendChild($gpx_creator);
+ $gpx_creator_text = $dom_gpx->createTextNode('http://thydzik.com');
+ $gpx_creator->appendChild($gpx_creator_text);
+
+ $gpx_xmlns_xsi = $dom_gpx->createAttribute('xmlns:xsi');
+ $gpx->appendChild($gpx_xmlns_xsi);
+ $gpx_xmlns_xsi_text = $dom_gpx->createTextNode('http://www.w3.org/2001/XMLSchema-instance');
+ $gpx_xmlns_xsi->appendChild($gpx_xmlns_xsi_text);
+
+ $gpx_xmlns = $dom_gpx->createAttribute('xmlns');
+ $gpx->appendChild($gpx_xmlns);
+ $gpx_xmlns_text = $dom_gpx->createTextNode('http://www.topografix.com/GPX/1/0');
+ $gpx_xmlns->appendChild($gpx_xmlns_text);
+
+ $gpx_xsi_schemaLocation = $dom_gpx->createAttribute('xsi:schemaLocation');
+ $gpx->appendChild($gpx_xsi_schemaLocation);
+ $gpx_xsi_schemaLocation_text = $dom_gpx->createTextNode('http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd');
+ $gpx_xsi_schemaLocation->appendChild($gpx_xsi_schemaLocation_text);
+
+ $gpx_url = $dom_gpx->createElement('url');
+ $gpx_url = $gpx->appendChild($gpx_url);
+ $gpx_url_text = $dom_gpx->createTextNode($u_parts['dirname']);
+ $gpx_url->appendChild($gpx_url_text);
+
+ $gpx_time = $dom_gpx->createElement('time');
+ $gpx_time = $gpx->appendChild($gpx_time);
+ $gpx_time_text = $dom_gpx->createTextNode(utcdate());
+ $gpx_time->appendChild($gpx_time_text);
+
+ // placemarks
+ $names = array();
+ foreach ($dom_kml->getElementsByTagName('Placemark') as $placemark) {
+ //name
+ foreach ($placemark->getElementsByTagName('name') as $name) {
+ $name = $name->nodeValue;
+ //check if the key exists
+ if (array_key_exists($name, $names)) {
+ //increment the value
+ ++$names[$name];
+ $name = $name." ({$names[$name]})";
+ } else {
+ $names[$name] = 0;
+ }
+ }
+ //description
+ foreach ($placemark->getElementsByTagName('description') as $description) {
+ $description = $description->nodeValue;
+ }
+ foreach ($placemark->getElementsByTagName('Point') as $point) {
+ foreach ($point->getElementsByTagName('coordinates') as $coordinates) {
+ //add the marker
+ $coordinate = $coordinates->nodeValue;
+ $coordinate = str_replace(" ", "", $coordinate);//trim white space
+ $latlng = explode(",", $coordinate);
+
+ if (($lat = $latlng[1]) && ($lng = $latlng[0])) {
+ $gpx_wpt = $dom_gpx->createElement('wpt');
+ $gpx_wpt = $gpx->appendChild($gpx_wpt);
+
+ $gpx_wpt_lat = $dom_gpx->createAttribute('lat');
+ $gpx_wpt->appendChild($gpx_wpt_lat);
+ $gpx_wpt_lat_text = $dom_gpx->createTextNode($lat);
+ $gpx_wpt_lat->appendChild($gpx_wpt_lat_text);
+
+ $gpx_wpt_lon = $dom_gpx->createAttribute('lon');
+ $gpx_wpt->appendChild($gpx_wpt_lon);
+ $gpx_wpt_lon_text = $dom_gpx->createTextNode($lng);
+ $gpx_wpt_lon->appendChild($gpx_wpt_lon_text);
+
+ $gpx_time = $dom_gpx->createElement('time');
+ $gpx_time = $gpx_wpt->appendChild($gpx_time);
+ $gpx_time_text = $dom_gpx->createTextNode(utcdate());
+ $gpx_time->appendChild($gpx_time_text);
+
+ $gpx_name = $dom_gpx->createElement('name');
+ $gpx_name = $gpx_wpt->appendChild($gpx_name);
+ $gpx_name_text = $dom_gpx->createTextNode($name);
+ $gpx_name->appendChild($gpx_name_text);
+
+ $gpx_desc = $dom_gpx->createElement('desc');
+ $gpx_desc = $gpx_wpt->appendChild($gpx_desc);
+ $gpx_desc_text = $dom_gpx->createTextNode($description);
+ $gpx_desc->appendChild($gpx_desc_text);
+
+ //$gpx_url = $dom_gpx->createElement('url');
+ //$gpx_url = $gpx_wpt->appendChild($gpx_url);
+ //$gpx_url_text = $dom_gpx->createTextNode($ref);
+ //$gpx_url->appendChild($gpx_url_text);
+
+ $gpx_sym = $dom_gpx->createElement('sym');
+ $gpx_sym = $gpx_wpt->appendChild($gpx_sym);
+ $gpx_sym_text = $dom_gpx->createTextNode('Waypoint');
+ $gpx_sym->appendChild($gpx_sym_text);
+ }
+ }
+ }
+ foreach ($placemark->getElementsByTagName('LineString') as $lineString) {
+ foreach ($lineString->getElementsByTagName('coordinates') as $coordinates) {
+ //add the new track
+ $gpx_trk = $dom_gpx->createElement('trk');
+ $gpx_trk = $gpx->appendChild($gpx_trk);
+
+ $gpx_name = $dom_gpx->createElement('name');
+ $gpx_name = $gpx_trk->appendChild($gpx_name);
+ $gpx_name_text = $dom_gpx->createTextNode($name);
+ $gpx_name->appendChild($gpx_name_text);
+
+ $gpx_trkseg = $dom_gpx->createElement('trkseg');
+ $gpx_trkseg = $gpx_trk->appendChild($gpx_trkseg);
+
+ $coordinates = $coordinates->nodeValue;
+ $coordinates = preg_split("/[\s\r\n]+/", $coordinates); //split the coords by new line
+ foreach ($coordinates as $coordinate) {
+ $latlng = explode(",", $coordinate);
+
+ if (($lat = $latlng[1]) && ($lng = $latlng[0])) {
+ $gpx_trkpt = $dom_gpx->createElement('trkpt');
+ $gpx_trkpt = $gpx_trkseg->appendChild($gpx_trkpt);
+
+ $gpx_trkpt_lat = $dom_gpx->createAttribute('lat');
+ $gpx_trkpt->appendChild($gpx_trkpt_lat);
+ $gpx_trkpt_lat_text = $dom_gpx->createTextNode($lat);
+ $gpx_trkpt_lat->appendChild($gpx_trkpt_lat_text);
+
+ $gpx_trkpt_lon = $dom_gpx->createAttribute('lon');
+ $gpx_trkpt->appendChild($gpx_trkpt_lon);
+ $gpx_trkpt_lon_text = $dom_gpx->createTextNode($lng);
+ $gpx_trkpt_lon->appendChild($gpx_trkpt_lon_text);
+
+ $gpx_time = $dom_gpx->createElement('time');
+ $gpx_time = $gpx_trkpt->appendChild($gpx_time);
+ $gpx_time_text = $dom_gpx->createTextNode(utcdate());
+ $gpx_time->appendChild($gpx_time_text);
+ }
+ }
+ }
+ }
+ }
+ header("Content-Type: text/xml");
+ echo $dom_gpx->saveXML();
+ }
+
+}
+
+
+/**
+ * create a utcdate
+ * @return utcdate objekt]
+ */
+function utcdate() {
+ return gmdate("Y-m-d\Th:i:s\Z");
+}
Modified: trunk/mapbender/http/plugins/kmlTree.js
===================================================================
--- trunk/mapbender/http/plugins/kmlTree.js 2015-02-18 15:16:49 UTC (rev 9153)
+++ trunk/mapbender/http/plugins/kmlTree.js 2015-02-23 14:16:59 UTC (rev 9154)
@@ -108,12 +108,14 @@
v[3] = '<img src="' + v[3] + '"></img>';
}
if (v[4]) {
- v[4] = '<img src="../img/osgeo_graphics/check.png"></img><img src="../img/osgeo_graphics/geosilk/link22.png"></img>';
+ v[4] = '<img src="../img/osgeo_graphics/check.png"></img><img class="exportImage" src="../img/osgeo_graphics/geosilk/link22.png"></img>';
} else {
v[4] = '<img src="../img/button_digitize/geomRemove.png"></img>';
}
v[5] = Math.round(v[5] / 1024) + 'kb';
});
+
+ // add dialog for ópen links
$('#kml-from-wmc').html('<table class="display"></table>').find('table').dataTable({
aaData: data,
aoColumns: [{
@@ -129,8 +131,107 @@
}, {
sTitle: 'size'
}]
+ }).find('.exportImage').bind('click', function(event) { // add click event to the link image
+ // stop event propagation beacause the following bind has to catch the click events on the 'tr'
+ event.stopPropagation();
+ if ($('#dataExportDialog').dialog('isOpen') === true) {
+
+ $('#dataExportDialog').dialog('close');
+ $('#dataExportDialog').remove();
+ $(this).trigger('click');
+
+ } else {
+ var title = $(this).parent().siblings().eq(1).html();
+ var wmc_id = $(this).parent().siblings().eq(0).html();
+ var outputFormat;
+
+ var dataExportDlg = $('<div id="dataExportDialog"></div>').dialog({
+ title: "Export my data " + title,
+ width: 250,
+ height: 212,
+ position: {
+ my: "center",
+ at: "top",
+ of: window
+ },
+ close: function() {
+
+ $('#dataExportDialog').dialog('destroy');
+ $('#dataExportDialog').remove();
+ }
+ });
+ var exportHtmlsdfdsf = '<div id="exportHtml">' + '<form>' + '<label class="export-format-kml">KML<input type="radio" name="export-format" value="kml" checked="checked"></input></label>' + '<label class="export-format-kml">KML<input type="radio" name="export-format" value="kml" checked="checked"></input></label>' + '<label class="export-format-kml">KML<input type="radio" name="export-format" value="kml" checked="checked"></input></label><br><br>' +
+ '<img src="../img/osgeo_graphics/geosilk/link22.png"/>' + '<label class="export-format-gpx">GPX</label>' + '<label class="export-format-geojson">geoJSON</label><br></br>' +
+ '<a download="myfeatures.kml" href="#" class="digitize-image digitize-export" style="float: left;"></a>' + '</form>' + '</div>';
+ var exportHtml = '<div id="exportHtml"><table><tbody>' +
+ '<tr><td>KML:</td><td><label class="export-format-kml exportDatasetIcon" style="padding-top:11px;"></label></td><td class="exportDataLink kml" wmcId="'+wmc_id+'"outputFormat="kml"><img src="../img/osgeo_graphics/geosilk/link22.png"/></td></tr>' +
+ '<tr><td>GPX:</td><td><label class="export-format-gpx exportDatasetIcon" style="padding-top:11px;"></label></td><td class="exportDataLink gpx" wmcId="'+wmc_id+'"outputFormat="gpx"><img src="../img/osgeo_graphics/geosilk/link22.png"/></td></tr>' +
+ '<tr><td>GeoJson:</td><td><label class="export-format-geojson exportDatasetIcon" style="padding-top:11px;"></label></td><td class="exportDataLink geojson" wmcId="'+wmc_id+'"outputFormat="geojson"><img src="../img/osgeo_graphics/geosilk/link22.png"/></td></tr>' +
+ '</tbody></table></div><iframe id="export-DataCollection" style="border:0;height:0; width:0;"></iframe>';
+ // append the context
+ $(dataExportDlg).append(exportHtml);
+ //export the data
+ $('.exportDatasetIcon').bind('click', function(event) {
+
+ var exportClass = $(this).attr('class').toString().split(' ')[0];
+ //getting the outputformat
+ switch (exportClass) {
+ case 'export-format-kml':
+
+ outputFormat = 'kml';
+ break;
+ case 'export-format-gpx':
+
+ outputFormat = 'gpx';
+ break;
+ case 'export-format-geojson':
+
+ outputFormat = 'geojson';
+ break;
+ }
+ $('#export-DataCollection').attr("src", "../php/mod_GetPublishedData.php?wmc_id=" + wmc_id + "&outputFormat=" + outputFormat);
+
+ // $.ajax({
+ // url: '../php/mod_GetPublishedData.php',
+ // type: 'GET',
+ // data: {
+ // wmc_id: wmc_id,
+ // outputFormat: outputFormat
+ // },
+
+ // success: function(data) {
+ // console.log(data);
+ // console.log('Export completed');
+ // }
+
+ // });
+
+
+ });
+
+ $('.exportDataLink').bind('click', function(event) {
+ var format = $(this).attr('outputFormat');
+ var exportDataLinkDlg = $('<div id="exportDataLinkDlg"></div>').dialog({
+ "title": "Link to your Dataset",
+ width: 350,
+ height: 80,
+ close: function() {
+ $('#exportDataLinkDlg').dialog('destroy');
+ $('#exportDataLinkDlg').remove();
+
+ }
+ });
+
+ // var exportDataLinkContent = '<div><input size="35" type="text" value="http://192.168.0.117/mapbender/php/mod_GetPublishedData.php?wmc_id='+wmc_id+'&outputFormat='+format+'/></div>';
+ var exportDataLinkContent = '<div><label for="exportLinkInput">Link: </label><input id="exportLinkInput" size="35" type="text" value="http://192.168.0.117/mapbender/php/mod_GetPublishedData.php?wmc_id='+wmc_id+'&outputFormat='+format+'"></div>';
+ // var exportDataLinkContent = '<div>test</div>';
+ $(exportDataLinkDlg).append(exportDataLinkContent);
+ });
+ }
})
+ .end()
.find('tr').bind('click', function() {
+ console.log('test');
var id = $($(this).find('td')[0]).text();
var d;
$.each(origData, function(_, val) {
@@ -163,9 +264,17 @@
id: id
},
success: function(data) {
- if (!data.success) {
- alert('Problem when deleting local data: ' + data.message);
+ if (arguments[1] == 'success') {
+
+ alert('Deleting local data was succesfull');
+ $('#mySpatialData').dialog('destroy');
+ $('#mySpatialData').remove();
+ $($addButton).trigger('click');
+ } else {
+ alert('Problem when deleting local data');
+
}
+
}
});
}
@@ -276,7 +385,7 @@
"</select></td>" +
"<td id='licenseImg'></td>" +
"<td id='licenseDescription'></td>" +
- "<td id='licenseOpen'></td></tr>" + // TODO: add content for this field
+ "<td id='licenseOpen' nowrap></td></tr>" + // TODO: add content for this field
"<tr id='submitLicense' ><td style='border:none;cursor:pointer; nowrap'><img src='../img/osgeo_graphics/check.png' style='margin-top:10px'/> <span>Publish data</span></td></tr>" +
"</table></div>";
@@ -326,14 +435,11 @@
if (data.isopen == 1) {
$('#licenseOpen').html('<img src="../img/od_80x15_blue.png" />');
- }else{
+ } else {
$('#licenseOpen').html('<span>No OpenData</span>');
}
- // console.log(data['description']);
-
-
}
});
@@ -360,15 +466,11 @@
$('#licenseOpen').html('<img src="../img/od_80x15_blue.png" />');
- }else{
+ } else {
$('#licenseOpen').html('<span>No OpenData</span>');
}
- // console.log(data['description']);
-
-
-
}
});
More information about the Mapbender_commits
mailing list