[gnome-maps/wip/jonasdn/geojson] wip showing shapes from geojson files



commit 09457fc29668f09bb8050f5aef8c8701277cb8e1
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Sun Sep 6 14:50:50 2015 +0200

    wip showing shapes from geojson files

 src/lineString.js                    |   32 +++++++++++++++++++
 src/mapView.js                       |    7 ++++
 src/org.gnome.Maps.src.gresource.xml |    4 ++
 src/polygon.js                       |   32 +++++++++++++++++++
 src/shapeLayer.js                    |   57 ++++++++++++++++++++++++++++++++++
 5 files changed, 132 insertions(+), 0 deletions(-)
---
diff --git a/src/lineString.js b/src/lineString.js
new file mode 100644
index 0000000..0a0dce1
--- /dev/null
+++ b/src/lineString.js
@@ -0,0 +1,32 @@
+/* -*- 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: Jonas Danielsson <jonas threetimestwo org>
+ */
+
+const Lang = imports.lang;
+
+const LineString = new Lang.Class({
+    Name: 'LineString',
+
+    _init: function(params) {
+        this._coordinates = params.coordinates || [];
+    },
+
+    get coordinates() {
+        return this._coordinates;
+    }
+});
diff --git a/src/mapView.js b/src/mapView.js
index c4f4675..bd98114 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -29,6 +29,7 @@ const Lang = imports.lang;
 const Application = imports.application;
 const ContactPlace = imports.contactPlace;
 const Geoclue = imports.geoclue;
+const GeoJSON = imports.geoJSON;
 const Location = imports.location;
 const MapWalker = imports.mapWalker;
 const Place = imports.place;
@@ -87,6 +88,9 @@ const MapView = new Lang.Class({
                                     this._updateUserLocation.bind(this));
 
         this._connectRouteSignals();
+        this._geoJSON = new GeoJSON.GeoJSON({ filename: '/home/jonas/test.geojson',
+                                              mapView: this });
+        this._geoJSON.parse();
     },
 
     _initView: function() {
@@ -277,6 +281,9 @@ const MapView = new Lang.Class({
 
         this._placeLayer.add_marker(placeMarker);
         placeMarker.goToAndSelect(animation);
+
+        this._geoJSON.render();
+        this._gotoBBox(this._geoJSON.bbox);
     },
 
     showRoute: function(route) {
diff --git a/src/org.gnome.Maps.src.gresource.xml b/src/org.gnome.Maps.src.gresource.xml
index a15ac7e..d986c44 100644
--- a/src/org.gnome.Maps.src.gresource.xml
+++ b/src/org.gnome.Maps.src.gresource.xml
@@ -15,8 +15,10 @@
     <file>foursquareGoaAuthorizer.js</file>
     <file>geoclue.js</file>
     <file>geocodeService.js</file>
+    <file>geoJSON.js</file>
     <file>http.js</file>
     <file>layersPopover.js</file>
+    <file>lineString.js</file>
     <file>location.js</file>
     <file>locationServiceNotification.js</file>
     <file>main.js</file>
@@ -35,6 +37,7 @@
     <file>placeListRow.js</file>
     <file>placeMarker.js</file>
     <file>placeStore.js</file>
+    <file>polygon.js</file>
     <file>route.js</file>
     <file>routeEntry.js</file>
     <file>routeQuery.js</file>
@@ -43,6 +46,7 @@
     <file>serviceBackend.js</file>
     <file>settings.js</file>
     <file>sendToDialog.js</file>
+    <file>shapeLayer.js</file>
     <file>sidebar.js</file>
     <file>socialPlace.js</file>
     <file>socialPlaceListBox.js</file>
diff --git a/src/polygon.js b/src/polygon.js
new file mode 100644
index 0000000..3d518a8
--- /dev/null
+++ b/src/polygon.js
@@ -0,0 +1,32 @@
+/* -*- 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: Jonas Danielsson <jonas threetimestwo org>
+ */
+
+const Lang = imports.lang;
+
+const Polygon = new Lang.Class({
+    Name: 'Polygon',
+
+    _init: function(params) {
+        this._coordinates = params.coordinates || [];
+    },
+
+    get coordinates() {
+        return this._coordinates;
+    }
+});
diff --git a/src/shapeLayer.js b/src/shapeLayer.js
new file mode 100644
index 0000000..2314561
--- /dev/null
+++ b/src/shapeLayer.js
@@ -0,0 +1,57 @@
+/* -*- 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: Jonas Danielsson <jonas threetimestwo org>
+ */
+
+const Champlain = imports.gi.Champlain;
+const Lang = imports.lang;
+
+const Location = imports.location;
+const Utils = imports.utils;
+
+const ShapeLayer = new Lang.Class({
+    Name: 'ShapeLayer',
+    Extends: Champlain.PathLayer,
+
+    _init: function() {
+        this.parent();
+
+        this._bbox = new Champlain.BoundingBox();
+    },
+
+    get bbox() {
+        return this._bbox;
+    },
+
+    _addNode: function(coordinate) {
+        let [latitude, longitude] = [coordinate[1], coordinate[0]];
+
+        this.add_node(new Champlain.Coordinate({
+            latitude: latitude,
+            longitude: longitude
+        }));
+        this._bbox.extend(latitude, longitude);
+    },
+
+    addPolygon: function(polygon) {
+        polygon.coordinates.forEach(this._addNode.bind(this));
+    },
+
+    addLineString: function(lineString) {
+        lineString.coordinates.forEach(this._addNode.bind(this));
+    }
+});


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