[gnome-maps/wip/jonasdn/geojson: 5/8] mapView: Add openGeoJSON method
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/jonasdn/geojson: 5/8] mapView: Add openGeoJSON method
- Date: Sun, 25 Oct 2015 11:49:00 +0000 (UTC)
commit 5bc16c7d05a04dfd061e3450423e41840c65c251
Author: Jonas Danielsson <jonas threetimestwo org>
Date: Fri Oct 23 12:07:47 2015 +0200
mapView: Add openGeoJSON method
src/mapView.js | 40 ++++++++++++++++++++++++++++++++++++++++
1 files changed, 40 insertions(+), 0 deletions(-)
---
diff --git a/src/mapView.js b/src/mapView.js
index 185db2f..1c63527 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,42 @@ 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 file");
+ Application.notificationManager.showMessage(msg);
+ Utils.debug("failed to parse geojson file: %s".format(e.message));
+ }
+ },
+
+ 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]