From 020507047aae0adc9f4f865ec37167fb890923de Mon Sep 17 00:00:00 2001 From: Marcus Lundblad Date: Thu, 29 Oct 2020 10:37:55 +0100 Subject: [PATCH 1/2] photonParser: Initialize Place instances directly Create Place instances directly using properties instead of passing in a temporary Geocode.Place object. --- src/photonParser.js | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/photonParser.js b/src/photonParser.js index 4ae3e42c..17aff883 100644 --- a/src/photonParser.js +++ b/src/photonParser.js @@ -55,40 +55,38 @@ function parsePlace(latitude, longitude, properties) { name = streetAddress; } - let place = new Geocode.Place({ name: name, - place_type: type, - location: location }); + let params = { name: name, place_type: type, location: location }; if (streetAddress) - place.street_address = streetAddress; + params.street_address = streetAddress; if (properties.osm_id && properties.osm_type) { - place.osm_id = properties.osm_id + ''; // Geocode-glib needs this as a string - place.osm_type = _parseOsmType(properties.osm_type); + params.osm_id = properties.osm_id + ''; // Geocode-glib needs this as a string + params.osm_type = _parseOsmType(properties.osm_type); } if (properties.street) - place.street = properties.street; + params.street = properties.street; if (properties.city) - place.town = properties.city; + params.town = properties.city; if (properties.postcode) - place.postal_code = properties.postcode; + params.postal_code = properties.postcode; if (properties.state) - place.state = properties.state; + params.state = properties.state; if (countryCode) - place.country_code = countryCode; + params.country_code = countryCode; if (!countryCode && properties.country) - place.country = properties.country; + params.country = properties.country; if (properties.extent) - place.bounding_box = _parseBoundingBox(properties.extent); + params.bounding_box = _parseBoundingBox(properties.extent); - return new Place.Place({ place: place }); + return new Place.Place(params); } function _parseName(properties) { -- GitLab From 32db4f1dae05020544b54ba223f061e7711395f8 Mon Sep 17 00:00:00 2001 From: Marcus Lundblad Date: Thu, 29 Oct 2020 10:38:46 +0100 Subject: [PATCH 2/2] storedRoute: Use place array directly Store the passed-in array of sub-places directly instead of initializing a new Place instance from each object, as they are already the appropriate type. --- src/storedRoute.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/storedRoute.js b/src/storedRoute.js index b9e0bc85..784c6693 100644 --- a/src/storedRoute.js +++ b/src/storedRoute.js @@ -52,29 +52,26 @@ class StoredRoute extends Place.Place { this._rtl = Gtk.get_locale_direction() === Gtk.TextDirection.RTL; - let places = params.places; + this.places = params.places; delete params.places; let directionMarker = this._rtl ? _RLM : _LRM; let arrow = this._rtl ? '←' : '→'; - params.name = directionMarker + places[0].name + directionMarker + - arrow + directionMarker + places[places.length -1].name; + params.name = directionMarker + this.places[0].name + directionMarker + + arrow + directionMarker + this.places.last().name; let geoclue = params.geoclue; delete params.geoclue; - this.places = []; this._containsCurrentLocation = false; let currentLocation = null; if (geoclue) currentLocation = geoclue.place; - places.forEach((place) => { + this.places.forEach((place) => { if (currentLocation && place === currentLocation) this._containsCurrentLocation = true; - - this.places.push(new Place.Place({ place: place })); }); super._init(params); -- GitLab