[gnome-maps/wip/jonasdn/geojson] wip showing shapes from geojson files
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/jonasdn/geojson] wip showing shapes from geojson files
- Date: Sun, 6 Sep 2015 13:05:12 +0000 (UTC)
commit 42110ac5fb7ad47cc03444c7403de648cad875a4
Author: Jonas Danielsson <jonas threetimestwo org>
Date: Sun Sep 6 14:50:50 2015 +0200
wip showing shapes from geojson files
src/application.js | 14 ++++++++
src/lineString.js | 32 +++++++++++++++++++
src/mapView.js | 13 ++++++++
src/org.gnome.Maps.src.gresource.xml | 4 ++
src/polygon.js | 32 +++++++++++++++++++
src/shapeLayer.js | 57 ++++++++++++++++++++++++++++++++++
6 files changed, 152 insertions(+), 0 deletions(-)
---
diff --git a/src/application.js b/src/application.js
index 1903336..5fa8a5e 100644
--- a/src/application.js
+++ b/src/application.js
@@ -78,6 +78,20 @@ const Application = new Lang.Class({
this.parent({ application_id: 'org.gnome.Maps' });
this._connected = false;
+
+ this.add_main_option('geojson',
+ 0,
+ GLib.OptionFlags.NONE,
+ GLib.OptionArg.FILENAME,
+ 'A path to a local tiles directory structure',
+ null);
+
+ this.connect('handle-local-options', (function(app, options) {
+ if (options.contains('geojson')) {
+ let variant = options.lookup_value('geojson', null);
+ this.geojson_file = variant.deep_unpack().toString();
+ }
+ }).bind(this));
},
_checkNetwork: function() {
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..40566e8 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -25,10 +25,12 @@ const GObject = imports.gi.GObject;
const Geocode = imports.gi.GeocodeGlib;
const GtkChamplain = imports.gi.GtkChamplain;
const Lang = imports.lang;
+const Mainloop = imports.mainloop;
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 +89,17 @@ const MapView = new Lang.Class({
this._updateUserLocation.bind(this));
this._connectRouteSignals();
+
+ Mainloop.timeout_add(1000, (function() {
+ this._geoJSON = new GeoJSON.GeoJSON({
+ filename: Application.application.geojson_file,
+ mapView: this });
+
+ if (this._geoJSON.parse()) {
+ this._geoJSON.render();
+ this._gotoBBox(this._geoJSON.bbox);
+ }
+ }).bind(this));
},
_initView: function() {
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]