Migrate to GeoJSON output, because it's just so much nicer than KML...

This commit is contained in:
Klaus-Uwe Mitterer 2017-10-06 13:34:52 +02:00
parent dbdb9df725
commit 2e6fdd2d4c
2 changed files with 80 additions and 42 deletions

View file

@ -20,32 +20,51 @@ $sql = "SELECT ts, lat, lon FROM tracker WHERE device='" . mysqli_real_escape_st
$result = $conn->query($sql);
if ($result->num_rows > 0) {
header('Content-Type: application/vnd.google-earth.kml+xml');
header('Content-Disposition: attachment; filename="export.kml"');
echo '<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
<ExtendedData>
<Data name="styleUrl"><value>#style</value></Data>
<Data name="styleHash"><value>1a1ac94e</value></Data>
<Data name="stroke"><value>#ffff00</value></Data>
<Data name="stroke-opacity"><value>0.4980392156862745</value></Data>
<Data name="stroke-width"><value>4</value></Data>
<Data name="fill"><value>#00ff00</value></Data>
<Data name="fill-opacity"><value>0.4980392156862745</value></Data>
</ExtendedData>
<LineString>
<coordinates>
header('Content-Type: application/vnd.geo+json');
header('Content-Disposition: attachment; filename="export.geojson"');
$output = '{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature",
"properties": {
"Name": null,
"description": null,
"timestamp": null,
"begin": null,
"end": null,
"altitudeMode": null,
"tessellate": -1,
"extrude": 0,
"visibility": -1,
"drawOrder": null,
"icon": null,
"styleUrl": "#style",
"styleHash": "1a1ac94e",
"stroke": "#ffff00",
"stroke_opacity": "0.4980392156862745",
"stroke_width": "4",
"fill": "#00ff00",
"fill_opacity": "0.4980392156862745"
},
"geometry": {
"type": "LineString",
"coordinates": [
';
while($row = $result->fetch_assoc()) {
echo $row["lon"] . "," . $row["lat"] . "\n";
$output .= " [ " . $row["lon"] . ", " . $row["lat"] . " ],\n";
}
echo '</coordinates>
</LineString></Placemark>
</Document></kml>';
$output = substr_replace($output, "", strrpos($output, ","), 1);
$output .= ' ]
}
}
]
}';
echo $output;
} else {
die("No records found.");

61
day.php
View file

@ -20,32 +20,51 @@ $sql = "SELECT ts, lat, lon FROM tracker WHERE device='" . mysqli_real_escape_st
$result = $conn->query($sql);
if ($result->num_rows > 0) {
header('Content-Type: application/vnd.google-earth.kml+xml');
header('Content-Disposition: attachment; filename="export.kml"');
echo '<?xml version="1.0" encoding="UTF-8"?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document>
<Placemark>
<ExtendedData>
<Data name="styleUrl"><value>#style</value></Data>
<Data name="styleHash"><value>1a1ac94e</value></Data>
<Data name="stroke"><value>#ffff00</value></Data>
<Data name="stroke-opacity"><value>0.4980392156862745</value></Data>
<Data name="stroke-width"><value>4</value></Data>
<Data name="fill"><value>#00ff00</value></Data>
<Data name="fill-opacity"><value>0.4980392156862745</value></Data>
</ExtendedData>
<LineString>
<coordinates>
header('Content-Type: application/vnd.geo+json');
header('Content-Disposition: attachment; filename="export.geojson"');
$output = '{
"type": "FeatureCollection",
"crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:OGC:1.3:CRS84" } },
"features": [
{ "type": "Feature",
"properties": {
"Name": null,
"description": null,
"timestamp": null,
"begin": null,
"end": null,
"altitudeMode": null,
"tessellate": -1,
"extrude": 0,
"visibility": -1,
"drawOrder": null,
"icon": null,
"styleUrl": "#style",
"styleHash": "1a1ac94e",
"stroke": "#ffff00",
"stroke_opacity": "0.4980392156862745",
"stroke_width": "4",
"fill": "#00ff00",
"fill_opacity": "0.4980392156862745"
},
"geometry": {
"type": "LineString",
"coordinates": [
';
while($row = $result->fetch_assoc()) {
echo $row["lon"] . "," . $row["lat"] . "\n";
$output .= " [ " . $row["lon"] . ", " . $row["lat"] . " ],\n";
}
echo '</coordinates>
</LineString></Placemark>
</Document></kml>';
$output = substr_replace($output, "", strrpos($output, ","), 1);
$output .= ' ]
}
}
]
}';
echo $output;
} else {
die("No records found.");