[gnome-maps/wip/jonasdn/geojson: 3/6] mapView: Add openGeoJSON method
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps/wip/jonasdn/geojson: 3/6] mapView: Add openGeoJSON method
- Date: Sat, 24 Oct 2015 14:26:20 +0000 (UTC)
commit 2eaae73193e4e66d2c0e053ed1c7d2ddf3053b6d
Author: Jonas Danielsson <jonas threetimestwo org>
Date: Fri Oct 23 12:07:47 2015 +0200
mapView: Add openGeoJSON method
src/mapView.js | 36 ++++++++++++++++++++++++++++++++++++
1 files changed, 36 insertions(+), 0 deletions(-)
---
diff --git a/src/mapView.js b/src/mapView.js
index 185db2f..c64627d 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,38 @@ const MapView = new Lang.Class({
}
},
+ _openGeoJSONInternal: function(file) {
+ 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('realize',
+ 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]