[gnome-maps] Layers: Add backend for GPX shape layer files



commit 8c38c4902189b9077e225656bdd9c7bcb2e9da75
Author: Hashem Nasarat <hashem riseup net>
Date:   Sun Feb 14 19:51:19 2016 -0500

    Layers: Add backend for GPX shape layer files
    
    This commit leverages the GeoJSONSource backend by using togeojson to
    convert the GPX files to GeoJSON for rendering.
    
    To get the mime type support working I needed to add:
    
      <mime-type type="application/gpx+xml">
        <comment>GPS Exchange Format</comment>
        <sub-class-of type="application/xml"/>
        <glob pattern="*.gpx"/>
      </mime-type>
    
    to /usr/share/mime/packages/freedesktop.org.xml then run
    update-mime-database /usr/share/mime.
    There's an unmerged patch for gpx mimeinfo in
    https://bugs.freedesktop.org/show_bug.cgi?id=94154
    
    https://bugzilla.gnome.org/show_bug.cgi?id=757171

 data/org.gnome.Maps.desktop.in       |    2 +-
 src/gpxShapeLayer.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 8c53fdf..2d1b5de 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;application/vnd.google-earth.kml+xml;
+MimeType=application/vnd.geo+json;x-scheme-handler/geo;application/vnd.google-earth.kml+xml;application/gpx+xml;
diff --git a/src/gpxShapeLayer.js b/src/gpxShapeLayer.js
new file mode 100644
index 0000000..049e953
--- /dev/null
+++ b/src/gpxShapeLayer.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 GpxShapeLayer = new Lang.Class({
+    Name: 'GpxShapeLayer',
+    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.gpx(parser.parseFromString(s));
+        this._mapSource.parse(json);
+    }
+});
+
+GpxShapeLayer.mimeTypes = ['application/gpx+xml' ];
+GpxShapeLayer.displayName = 'GPX';
diff --git a/src/mapView.js b/src/mapView.js
index cb86264..2bf8f04 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -33,6 +33,7 @@ const ContactPlace = imports.contactPlace;
 const Geoclue = imports.geoclue;
 const GeoJSONShapeLayer = imports.geoJSONShapeLayer;
 const KmlShapeLayer = imports.kmlShapeLayer;
+const GpxShapeLayer = imports.gpxShapeLayer;
 const Location = imports.location;
 const Maps = imports.gi.GnomeMaps;
 const MapWalker = imports.mapWalker;
@@ -166,6 +167,7 @@ const MapView = new Lang.Class({
 
         ShapeLayer.SUPPORTED_TYPES.push(GeoJSONShapeLayer.GeoJSONShapeLayer);
         ShapeLayer.SUPPORTED_TYPES.push(KmlShapeLayer.KmlShapeLayer);
+        ShapeLayer.SUPPORTED_TYPES.push(GpxShapeLayer.GpxShapeLayer);
     },
 
     _connectRouteSignals: function() {
diff --git a/src/org.gnome.Maps.src.gresource.xml b/src/org.gnome.Maps.src.gresource.xml
index 75b36ea..769ec81 100644
--- a/src/org.gnome.Maps.src.gresource.xml
+++ b/src/org.gnome.Maps.src.gresource.xml
@@ -19,6 +19,7 @@
     <file>geoJSONShapeLayer.js</file>
     <file>geoJSONSource.js</file>
     <file>geoJSONStyle.js</file>
+    <file>gpxShapeLayer.js</file>
     <file>http.js</file>
     <file>instructionRow.js</file>
     <file>kmlShapeLayer.js</file>


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]