[gnome-maps] Use osm-type+osm-id as index for places.
- From: Jonas Danielsson <jonasdn src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-maps] Use osm-type+osm-id as index for places.
- Date: Wed, 3 Dec 2014 18:38:59 +0000 (UTC)
commit fed9e0604a346e3a571865fce98fc7a41e7e0c11
Author: Jonas Danielsson <jonas threetimestwo org>
Date: Mon Dec 1 05:27:51 2014 -0500
Use osm-type+osm-id as index for places.
The osm id is only unique within a type of place such as
node, way or relation. We need the osm-type to make the index
unique.
https://bugzilla.gnome.org/show_bug.cgi?id=740937
src/mapBubble.js | 2 +-
src/place.js | 6 ++++++
src/placeStore.js | 43 ++++++++++++++++++++++---------------------
src/searchResultBubble.js | 4 ++--
4 files changed, 31 insertions(+), 24 deletions(-)
---
diff --git a/src/mapBubble.js b/src/mapBubble.js
index e12e351..7c7f80c 100644
--- a/src/mapBubble.js
+++ b/src/mapBubble.js
@@ -99,7 +99,7 @@ const MapBubble = new Lang.Class({
_initFavoriteButton: function(button) {
let placeStore = Application.placeStore;
- let isFavorite = placeStore.exists(this._place.osm_id,
+ let isFavorite = placeStore.exists(this._place,
PlaceStore.PlaceType.FAVORITE);
button.visible = true;
button.active = isFavorite;
diff --git a/src/place.js b/src/place.js
index 8248140..76bf071 100644
--- a/src/place.js
+++ b/src/place.js
@@ -44,6 +44,7 @@ const Place = new Lang.Class({
if (params.place) {
params = { osm_id: params.place.osm_id,
+ osm_type: params.place.osm_type,
name: params.place.name,
location: params.place.location,
bounding_box: params.place.bounding_box,
@@ -68,6 +69,10 @@ const Place = new Lang.Class({
this.parent(params);
},
+ get uniqueID() {
+ return this.osm_type + '-' + this.osm_id;
+ },
+
set population(v) {
this._population = v;
},
@@ -151,6 +156,7 @@ const Place = new Lang.Class({
accuracy: this.location.accuracy };
return { id: this.osm_id,
+ osm_type: this.osm_type,
name: this.name,
bounding_box: bounding_box,
this_type: this.this_type,
diff --git a/src/placeStore.js b/src/placeStore.js
index 3723714..a117476 100644
--- a/src/placeStore.js
+++ b/src/placeStore.js
@@ -90,21 +90,21 @@ const PlaceStore = new Lang.Class({
},
_addFavorite: function(place) {
- if (this.exists(place.osm_id, PlaceType.FAVORITE)) {
+ if (this.exists(place, PlaceType.FAVORITE)) {
return;
}
- if (this.exists(place.osm_id, PlaceType.RECENT)) {
+ if (this.exists(place, PlaceType.RECENT)) {
this._removeIf((function(model, iter) {
let p = model.get_value(iter, Columns.PLACE);
- return p.osm_id === place.osm_id;
- }), true);
+ return p.uniqueID === place.uniqueID;
+ }).bind(this), true);
}
this._addPlace(place, PlaceType.FAVORITE);
},
_addRecent: function(place) {
- if (this.exists(place.osm_id, PlaceType.RECENT)) {
+ if (this.exists(place, PlaceType.RECENT)) {
this._updatePlace(place);
return;
}
@@ -117,7 +117,7 @@ const PlaceStore = new Lang.Class({
if (type === PlaceType.RECENT) {
let place = model.get_value(iter, Columns.PLACE);
- this._typeTable[place.osm_id] = null;
+ this._typeTable[place.uniqueID] = null;
this._numRecent--;
return true;
}
@@ -163,13 +163,13 @@ const PlaceStore = new Lang.Class({
},
removePlace: function(place, placeType) {
- if (!this.exists(place.osm_id, placeType))
+ if (!this.exists(place, placeType))
return;
this._removeIf((function(model, iter) {
let p = model.get_value(iter, Columns.PLACE);
- if (p.osm_id === place.osm_id) {
- this._typeTable[place.osm_id] = null;
+ if (p.uniqueID === place.uniqueID) {
+ this._typeTable[place.uniqueID] = null;
return true;
}
return false;
@@ -223,27 +223,28 @@ const PlaceStore = new Lang.Class({
this.set(iter, [Columns.ICON], [pixbuf]);
}).bind(this));
}
- this._typeTable[place.osm_id] = type;
+ this._typeTable[place.uniqueID] = type;
},
- get: function(osmId) {
- let place = null;
- this.foreach(function(model, path, iter) {
+ get: function(place) {
+ let storedPlace = null;
+
+ this.foreach((function(model, path, iter) {
let p = model.get_value(iter, Columns.PLACE);
- if (p.osm_id === osmId) {
- place = p;
+ if (p.uniqueID === place.uniqueID) {
+ storedPlace = p;
return true;
}
return false;
- });
- return place;
+ }).bind(this));
+ return storedPlace;
},
- exists: function(osmId, type) {
+ exists: function(place, type) {
if (type !== undefined && type !== null)
- return this._typeTable[osmId] === type;
+ return this._typeTable[place.uniqueID] === type;
else
- return this._typeTable[osmId] !== undefined;
+ return this._typeTable[place.uniqueID] !== undefined;
},
_removeIf: function(evalFunc, stop) {
@@ -261,7 +262,7 @@ const PlaceStore = new Lang.Class({
this.foreach((function(model, path, iter) {
let p = model.get_value(iter, Columns.PLACE);
- if (p.osm_id === place.osm_id) {
+ if (p.uniqueID === place.uniqueID) {
let type = model.get_value(iter, Columns.TYPE);
this._setPlace(iter, place, type, new Date().getTime());
this._store();
diff --git a/src/searchResultBubble.js b/src/searchResultBubble.js
index b70bc3c..092d8c6 100644
--- a/src/searchResultBubble.js
+++ b/src/searchResultBubble.js
@@ -55,8 +55,8 @@ const SearchResultBubble = new Lang.Class({
this._title = ui.labelTitle;
this._boxContent = ui.boxContent;
- if (Application.placeStore.exists(this.place.osm_id, null)) {
- let place = Application.placeStore.get(this.place.osm_id);
+ if (Application.placeStore.exists(this.place, null)) {
+ let place = Application.placeStore.get(this.place);
this._populate(place);
} else {
let overpass = new Overpass.Overpass();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]