[gnome-maps/wip/jonasdn/geojson: 5/7] mapView: Add openGeoJSON method



commit ca3533a0aed16389c0cfdf71a03ee3c6d21a52a7
Author: Jonas Danielsson <jonas threetimestwo org>
Date:   Fri Oct 23 12:07:47 2015 +0200

    mapView: Add openGeoJSON method

 src/mapView.js |   39 +++++++++++++++++++++++++++++++++++++++
 1 files changed, 39 insertions(+), 0 deletions(-)
---
diff --git a/src/mapView.js b/src/mapView.js
index 185db2f..6c88c1d 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 GeoJSONSource = imports.geoJSONSource;
 const Location = imports.location;
 const Maps = imports.gi.GnomeMaps;
 const MapWalker = imports.mapWalker;
@@ -134,6 +135,9 @@ const MapView = new Lang.Class({
 
         this._instructionMarkerLayer = new Champlain.MarkerLayer({ selection_mode: mode });
         this.view.add_layer(this._instructionMarkerLayer);
+
+        this._annotationMarkerLayer = new Champlain.MarkerLayer({ selection_mode: mode });
+        this.view.add_layer(this._annotationMarkerLayer);
     },
 
     _connectRouteSignals: function() {
@@ -180,6 +184,41 @@ const MapView = new Lang.Class({
         }
     },
 
+    _openGeoJSONInternal: function(file) {
+        if (!this.view.realized)
+            return;
+
+        try {
+            this._annotationMarkerLayer.remove_all();
+            let geoJSONSource = new GeoJSONSource.GeoJSONSource({
+                file: file,
+                mapView: this,
+                markerLayer: this._annotationMarkerLayer
+            });
+            geoJSONSource.parse();
+
+            if (this._annotationSource)
+                this.view.remove_overlay_source(this._annotationSource);
+
+            this._annotationSource = geoJSONSource;
+            this.view.add_overlay_source(this._annotationSource, 255);
+            if (geoJSONSource.bbox.is_valid())
+                this._gotoBBox(geoJSONSource.bbox);
+        } catch(e) {
+            let msg = _("Failed to parse GeoJSON:" + e.message);
+            Application.notificationManager.showMessage(msg);
+        }
+    },
+
+    openGeoJSON: function(file) {
+        if (this.view.realized) {
+            this._openGeoJSONInternal(file);
+        } else {
+            this.view.connect('notify::realized',
+                              this._openGeoJSONInternal.bind(this, file));
+        }
+    },
+
     gotoUserLocation: function(animate) {
         if (!this._userLocation)
             return;


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