diff options
author | Marcus Lundblad <ml@dfupdate.se> | 2022-12-06 22:00:08 +0100 |
---|---|---|
committer | Marcus Lundblad <ml@dfupdate.se> | 2022-12-06 22:19:40 +0100 |
commit | b5d36a769d8d35981164820158f35166cef0c12a (patch) | |
tree | 80525dfb848c5174b1e1a42209af1c93191f268b | |
parent | c8efc8c9901b44e4dbfb0560ca06c320776284dc (diff) | |
download | gnome-maps-b5d36a769d8d35981164820158f35166cef0c12a.tar.gz |
shapeLayer: Move duplicated code from subclasseswip/mlundblad/remove-shapelayer-construct-duplication
The implementations of ShapeLayer each construct
the overlay map layer and GeoJSONSource in their
constructors.
Instead do this in the super class constructor
to avoid code duplication.
-rw-r--r-- | src/geoJSONShapeLayer.js | 12 | ||||
-rw-r--r-- | src/gpxShapeLayer.js | 12 | ||||
-rw-r--r-- | src/kmlShapeLayer.js | 12 | ||||
-rw-r--r-- | src/shapeLayer.js | 9 |
4 files changed, 7 insertions, 38 deletions
diff --git a/src/geoJSONShapeLayer.js b/src/geoJSONShapeLayer.js index b5309c2e..064552f8 100644 --- a/src/geoJSONShapeLayer.js +++ b/src/geoJSONShapeLayer.js @@ -18,9 +18,7 @@ */ import GObject from 'gi://GObject'; -import Shumate from 'gi://Shumate'; -import {GeoJSONSource} from './geoJSONSource.js'; import {ShapeLayer} from './shapeLayer.js'; import * as Utils from './utils.js'; @@ -35,16 +33,6 @@ export class GeoJSONShapeLayer extends ShapeLayer { return new GeoJSONShapeLayer(params); }; - constructor(params) { - super(params); - - this._mapSource = new GeoJSONSource({ mapView: this._mapView, - markerLayer: this._markerLayer }); - this._overlayLayer = - new Shumate.MapLayer({ map_source: this._mapSource, - viewport: this._mapView.map.viewport }); - } - getName() { /* Special Case since this file extension contains 2 periods */ let suffix = '.geo.json'; diff --git a/src/gpxShapeLayer.js b/src/gpxShapeLayer.js index afcd2781..a1223568 100644 --- a/src/gpxShapeLayer.js +++ b/src/gpxShapeLayer.js @@ -18,9 +18,7 @@ */ import GObject from 'gi://GObject'; -import Shumate from 'gi://Shumate'; -import {GeoJSONSource} from './geoJSONSource.js'; import {ShapeLayer} from './shapeLayer.js'; import * as Utils from './utils.js'; import * as Togeojson from './togeojson/togeojson.js'; @@ -35,16 +33,6 @@ export class GpxShapeLayer extends ShapeLayer { return new GpxShapeLayer(params); }; - constructor(params) { - super(params); - - this._mapSource = new GeoJSONSource({ mapView: this._mapView, - markerLayer: this._markerLayer }); - this._overlayLayer = - new Shumate.MapLayer({ map_source: this._mapSource, - viewport: this._mapView.map.viewport }); - } - _parseContent() { let s = Utils.getBufferText(this._fileContents); let parser = new Domparser.DOMParser(); diff --git a/src/kmlShapeLayer.js b/src/kmlShapeLayer.js index 985cfba3..c46b2c14 100644 --- a/src/kmlShapeLayer.js +++ b/src/kmlShapeLayer.js @@ -18,9 +18,7 @@ */ import GObject from 'gi://GObject'; -import Shumate from 'gi://Shumate'; -import {GeoJSONSource} from './geoJSONSource.js'; import {ShapeLayer} from './shapeLayer.js'; import * as Utils from './utils.js'; import * as Togeojson from './togeojson/togeojson.js'; @@ -35,16 +33,6 @@ export class KmlShapeLayer extends ShapeLayer { return new KmlShapeLayer(params); } - constructor(params) { - super(params); - - this._mapSource = new GeoJSONSource({ mapView: this._mapView, - markerLayer: this._markerLayer }); - this._overlayLayer = - new Shumate.MapLayer({ map_source: this._mapSource, - viewport: this._mapView.map.viewport }); - } - _parseContent() { let s = Utils.getBufferText(this._fileContents); let parser = new Domparser.DOMParser(); diff --git a/src/shapeLayer.js b/src/shapeLayer.js index 1cb798ce..d027b062 100644 --- a/src/shapeLayer.js +++ b/src/shapeLayer.js @@ -22,7 +22,7 @@ import GObject from 'gi://GObject'; import Gtk from 'gi://Gtk'; import Shumate from 'gi://Shumate'; -import {GeoJSONShapeLayer} from './geoJSONShapeLayer.js'; +import {GeoJSONSource} from './geoJSONSource.js'; import * as Utils from './utils.js'; export class ShapeLayer extends GObject.Object { @@ -58,7 +58,12 @@ export class ShapeLayer extends GObject.Object { selection_mode: Gtk.SelectionMode.SINGLE, viewport: this._mapView.map.viewport }); - this._mapSource = null; + + this._mapSource = new GeoJSONSource({ mapView: this._mapView, + markerLayer: this._markerLayer }); + this._overlayLayer = + new Shumate.MapLayer({ map_source: this._mapSource, + viewport: this._mapView.map.viewport }); } get bbox() { |