[gnome-maps] shapeLayer: Load file contents asynchronously
- From: Marcus Lundblad <mlundblad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] shapeLayer: Load file contents asynchronously
- Date: Sat, 19 Dec 2020 09:32:41 +0000 (UTC)
commit ba125a91a0bb83c598009b777e111e94c0754109
Author: tyagi619 <tyagianubhav619 gmail com>
Date: Mon Dec 14 19:02:07 2020 +0530
shapeLayer: Load file contents asynchronously
The loading of the file contents which is done from
shapelayer.js uses load_contents() which is a synchronous
call. Replaced load_contents() with load_contents_async()
which is an async version of loading the file contents.
Fixes #59
src/mapView.js | 19 ++++++++++++++++---
src/shapeLayer.js | 27 ++++++++++++++++++---------
2 files changed, 34 insertions(+), 12 deletions(-)
---
diff --git a/src/mapView.js b/src/mapView.js
index f6166599..f4e5e3d5 100644
--- a/src/mapView.js
+++ b/src/mapView.js
@@ -453,9 +453,24 @@ var MapView = GObject.registerClass({
this._scale.visible = !this._scale.visible;
}
+ _onShapeLoad(error, bbox, layer) {
+ if (error) {
+ let msg = _("Failed to open layer");
+ Utils.showDialog(msg, Gtk.MessageType.ERROR, this._mainWindow);
+ } else {
+ bbox.compose(layer.bbox);
+ }
+
+ this._remainingFilesToLoad--;
+ if (this._remainingFilesToLoad === 0) {
+ this.gotoBBox(bbox);
+ }
+ }
+
openShapeLayers(files) {
let bbox = new Champlain.BoundingBox();
let ret = true;
+ this._remainingFilesToLoad = files.length;
files.forEach((file) => {
try {
let i = this._findShapeLayerIndex(file);
@@ -464,10 +479,9 @@ var MapView = GObject.registerClass({
layer = ShapeLayer.newFromFile(file, this);
if (!layer)
throw new Error(_("File type is not supported"));
- layer.load();
+ layer.load(this._onShapeLoad.bind(this), bbox);
this.shapeLayerStore.append(layer);
}
- bbox.compose(layer.bbox);
} catch (e) {
Utils.debug(e);
let msg = _("Failed to open layer");
@@ -476,7 +490,6 @@ var MapView = GObject.registerClass({
}
});
- this.gotoBBox(bbox);
return ret;
}
diff --git a/src/shapeLayer.js b/src/shapeLayer.js
index 1b9b00ae..7d42c9b4 100644
--- a/src/shapeLayer.js
+++ b/src/shapeLayer.js
@@ -22,6 +22,7 @@ const Gio = imports.gi.Gio;
const GObject = imports.gi.GObject;
const GeoJSONShapeLayer = imports.geoJSONShapeLayer;
+const Utils = imports.utils;
var SUPPORTED_TYPES = [];
@@ -84,17 +85,25 @@ var ShapeLayer = GObject.registerClass({
return this.filename.replace(/\.[^\.]+$/, '');
}
- load() {
- 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);
+ load(callback, bbox) {
+ this.file.load_contents_async(null, (sourceObject, result) => {
+ let error = false;
+ try {
+ let [status, buffer] = this.file.load_contents_finish(result);
+ 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);
+ } catch (e) {
+ Utils.debug(e);
+ error = true;
+ }
+ callback(error, bbox, this);
+ });
}
-
_parseContent() {
/* Unimplemented */
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]