[gnome-maps] Layers: Add backend for KML shape layer files
- From: Hashem Nasarat <hnasarat src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] Layers: Add backend for KML shape layer files
- Date: Mon, 15 Feb 2016 19:31:09 +0000 (UTC)
commit 7930e66a2590f6241013bbf3334c4f9fa6de86f8
Author: Hashem Nasarat <hashem riseup net>
Date: Fri Jan 22 15:29:55 2016 -0500
Layers: Add backend for KML shape layer files
This commit leverages the GeoJSONSource backend by using togeojson to
convert the KML files to GeoJSON for rendering.
https://bugzilla.gnome.org/show_bug.cgi?id=757171
data/org.gnome.Maps.desktop.in | 2 +-
src/kmlShapeLayer.js | 49 ++++++++++++++++++++++++++++++++++
src/mapView.js | 2 +
src/org.gnome.Maps.src.gresource.xml | 1 +
4 files changed, 53 insertions(+), 1 deletions(-)
---
diff --git a/data/org.gnome.Maps.desktop.in b/data/org.gnome.Maps.desktop.in
index fe62d2b..8c53fdf 100644
--- a/data/org.gnome.Maps.desktop.in
+++ b/data/org.gnome.Maps.desktop.in
@@ -10,4 +10,4 @@ StartupNotify=true
Categories=GNOME;GTK;Utility;
_Keywords=Maps;
DBusActivatable=true
-MimeType=application/vnd.geo+json;x-scheme-handler/geo;
+MimeType=application/vnd.geo+json;x-scheme-handler/geo;application/vnd.google-earth.kml+xml;
diff --git a/src/kmlShapeLayer.js b/src/kmlShapeLayer.js
new file mode 100644
index 0000000..7e4e06d
--- /dev/null
+++ b/src/kmlShapeLayer.js
@@ -0,0 +1,49 @@
+/* -*- Mode: JS2; indent-tabs-mode: nil; js2-basic-offset: 4 -*- */
+/* vim: set et ts=4 sw=4: */
+/*
+ * GNOME Maps is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * GNOME Maps is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with GNOME Maps; if not, see <http://www.gnu.org/licenses/>.
+ *
+ * Author: Hashem Nasarat <hashem riseup net>
+ */
+
+const Lang = imports.lang;
+
+const GeoJSONSource = imports.geoJSONSource;
+const ShapeLayer = imports.shapeLayer;
+const Togeojson = imports.togeojson.togeojson;
+const Domparser = imports.xmldom.domparser;
+
+const KmlShapeLayer = new Lang.Class({
+ Name: 'KmlShapeLayer',
+ Extends: ShapeLayer.ShapeLayer,
+
+ _init: function(params) {
+ this.parent(params);
+
+ this._mapSource = new GeoJSONSource.GeoJSONSource({
+ mapView: this._mapView,
+ markerLayer: this._markerLayer
+ });
+ },
+
+ _parseContent: function() {
+ let s = this._fileContents.toString();
+ let parser = new Domparser.DOMParser();
+ let json = Togeojson.toGeoJSON.kml(parser.parseFromString(s));
+ this._mapSource.parse(json);
+ }
+});
+
+KmlShapeLayer.mimeTypes = ['application/vnd.google-earth.kml+xml'];
+KmlShapeLayer.displayName = 'KML';
diff --git a/src/mapView.js b/src/mapView.js
index 10ef068..cb86264 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -32,6 +32,7 @@ const Application = imports.application;
const ContactPlace = imports.contactPlace;
const Geoclue = imports.geoclue;
const GeoJSONShapeLayer = imports.geoJSONShapeLayer;
+const KmlShapeLayer = imports.kmlShapeLayer;
const Location = imports.location;
const Maps = imports.gi.GnomeMaps;
const MapWalker = imports.mapWalker;
@@ -164,6 +165,7 @@ const MapView = new Lang.Class({
this.view.add_layer(this._annotationMarkerLayer);
ShapeLayer.SUPPORTED_TYPES.push(GeoJSONShapeLayer.GeoJSONShapeLayer);
+ ShapeLayer.SUPPORTED_TYPES.push(KmlShapeLayer.KmlShapeLayer);
},
_connectRouteSignals: function() {
diff --git a/src/org.gnome.Maps.src.gresource.xml b/src/org.gnome.Maps.src.gresource.xml
index 36fca64..75b36ea 100644
--- a/src/org.gnome.Maps.src.gresource.xml
+++ b/src/org.gnome.Maps.src.gresource.xml
@@ -21,6 +21,7 @@
<file>geoJSONStyle.js</file>
<file>http.js</file>
<file>instructionRow.js</file>
+ <file>kmlShapeLayer.js</file>
<file>layersPopover.js</file>
<file>location.js</file>
<file>locationServiceNotification.js</file>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]