Skip to content

Commit

Permalink
KML layer on leaflet maps when source is KML
Browse files Browse the repository at this point in the history
  • Loading branch information
coreation committed Feb 15, 2016
1 parent 9c6c494 commit 31fdb6a
Show file tree
Hide file tree
Showing 9 changed files with 9,216 additions and 31 deletions.
12 changes: 10 additions & 2 deletions app/Tdt/Core/Formatters/MAPFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,21 @@ public static function createResponse($dataObj)
public static function getBody($dataObj)
{
$url = Request::url();
$url = preg_replace('/\.([^\.]*)$/m', '.geojson', $url);
$type = 'geojson';

if ($dataObj->definition['source_type'] == 'XmlDefinition' && $dataObj->source_definition['geo_formatted'] == 1) {
$url = preg_replace('/\.([^\.]*)$/m', '.kml', $url);
$type = 'kml';
} else {
$url = preg_replace('/\.([^\.]*)$/m', '.geojson', $url);
}

$resource = $dataObj->definition['collection_uri'] . "/" . $dataObj->definition['resource_name'];

// Render the view
return \View::make('layouts.map')->with('title', 'Dataset: ' . $resource . ' map | The Datatank')
->with('url', $url);
->with('url', $url)
->with('type', $type);
}

public static function getDocumentation()
Expand Down
44 changes: 31 additions & 13 deletions app/views/layouts/map.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,19 @@
minZoom: 3
}).addTo(map);
$.getJSON('{{ $url }}', function(data){
var geoData = L.geoJson(data, {
onEachFeature: function (feature, layer) {
var popup = '<strong>{[name]}</strong><br/>{[description]}<br/>';
@if ($type == 'geojson')
$.getJSON('{{ $url }}', function(data){
var geoData = L.geoJson(data, {
onEachFeature: function (feature, layer) {
var popup = '<strong>{[name]}</strong><br/>{[description]}<br/>';
$.each(layer.feature.properties, function (key, val) {
if (key != 'name' && key != 'description') {
popup += "<br/><strong>" + key + "</strong>: " + val;
} else {
popup = popup.replace('{[' + key + ']}', val);
}
});
$.each(layer.feature.properties, function (key, val) {
if (key != 'name' && key != 'description') {
popup += "<br/><strong>" + key + "</strong>: " + val;
} else {
popup = popup.replace('{[' + key + ']}', val);
}
});
// Replace when no data was provided
popup = popup.replace('<strong>{[name]}</strong><br/>', '');
Expand All @@ -46,8 +47,25 @@
}
}).addTo(map);
map.fitBounds(geoData.getBounds(), {padding: [20, 20]});
});
map.fitBounds(geoData.getBounds(), {padding: [20, 20]});
});
@elseif ($type == 'kml')
var bounds = {};
var data = omnivore.kml('{{ $url }}')
.on('ready', function() {
data.eachLayer(function(layer) {
var popup = '';
$.each(layer.feature.properties, function (key, val) {
if (key != 'name' && key != 'description') {
popup += "<strong>" + key + ": " + val + "</strong>\n";
}
});
layer.bindPopup(popup);
});
map.fitBounds(data.getBounds(), {padding: [20, 20]});
})
.addTo(map);
@endif
</script>
</body>
</html>
9,173 changes: 9,166 additions & 7 deletions dev/js/leaflet.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/css/error.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/css/leaflet.css

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/css/main.css

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions public/js/leaflet.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion public/js/rdf2html.min.js

Large diffs are not rendered by default.

Empty file removed public/packages/.gitkeep
Empty file.

0 comments on commit 31fdb6a

Please sign in to comment.