[gnome-maps] Layers: Load GeoJSON file outside of geoJSONSource
- From: Hashem Nasarat <hnasarat src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] Layers: Load GeoJSON file outside of geoJSONSource
- Date: Mon, 15 Feb 2016 19:30:44 +0000 (UTC)
commit 02eab20fb09cb9a0423bb8bf96dadd1f7e82098f
Author: Hashem Nasarat <hashem riseup net>
Date: Mon Feb 15 00:09:05 2016 -0500
Layers: Load GeoJSON file outside of geoJSONSource
This decouples the on-disk storage from the contents of a GeoJSON layer
in geoJSONSource. This is beneficial if we ever want to load GeoJSON
layers that aren't stored as on-disk geojson files.
https://bugzilla.gnome.org/show_bug.cgi?id=757171
src/geoJSONShapeLayer.js | 6 ++----
src/geoJSONSource.js | 9 +--------
src/shapeLayer.js | 10 ++++++++++
3 files changed, 13 insertions(+), 12 deletions(-)
---
diff --git a/src/geoJSONShapeLayer.js b/src/geoJSONShapeLayer.js
index d3049ef..2ab926a 100644
--- a/src/geoJSONShapeLayer.js
+++ b/src/geoJSONShapeLayer.js
@@ -30,7 +30,6 @@ const GeoJSONShapeLayer = new Lang.Class({
this.parent(params);
this._mapSource = new GeoJSONSource.GeoJSONSource({
- file: this.file,
mapView: this._mapView,
markerLayer: this._markerLayer
});
@@ -45,9 +44,8 @@ const GeoJSONShapeLayer = new Lang.Class({
return this.parent();
},
- load: function() {
- this._mapSource.parse();
- this.parent();
+ _parseContent: function() {
+ this._mapSource.parse(JSON.parse(this._fileContents));
}
});
diff --git a/src/geoJSONSource.js b/src/geoJSONSource.js
index 01fd917..dd4e514 100644
--- a/src/geoJSONSource.js
+++ b/src/geoJSONSource.js
@@ -45,7 +45,6 @@ const GeoJSONSource = new Lang.Class({
_init: function(params) {
this.parent();
- this._file = params.file;
this._mapView = params.mapView;
this._markerLayer = params.markerLayer;
this._bbox = new Champlain.BoundingBox();
@@ -54,7 +53,6 @@ const GeoJSONSource = new Lang.Class({
get bbox() {
return this._bbox;
},
-
vfunc_get_tile_size: function() {
return TILE_SIZE;
},
@@ -205,12 +203,7 @@ const GeoJSONSource = new Lang.Class({
}
},
- parse: function() {
- let [status, buffer] = this._file.load_contents(null);
- if (!status)
- throw new Error(_("failed to load file"));
-
- let json = JSON.parse(buffer);
+ parse: function(json) {
this._parseInternal(json);
this._tileIndex = Geojsonvt.geojsonvt(json, { extent: TILE_SIZE,
maxZoom: 20 });
diff --git a/src/shapeLayer.js b/src/shapeLayer.js
index de416ef..b6b3a8e 100644
--- a/src/shapeLayer.js
+++ b/src/shapeLayer.js
@@ -87,10 +87,20 @@ const ShapeLayer = new Lang.Class({
},
load: function() {
+ let [status, buffer] = this.file.load_contents(null);
+ this._fileContents = buffer;
+ if (!status)
+ throw new Error(_("failed to load file"));
+ this._parseContent();
this._mapView.view.add_layer(this._markerLayer);
this._mapView.view.add_overlay_source(this._mapSource, 255);
},
+
+ _parseContent: function() {
+ /* Unimplemented */
+ },
+
unload: function() {
this._mapView.view.remove_layer(this._markerLayer);
this._mapView.view.remove_overlay_source(this._mapSource);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]