Skip to content

Commit

Permalink
Improved filtering of places shown on the map. Fixes #58
Browse files Browse the repository at this point in the history
  • Loading branch information
ralexrdz committed Feb 13, 2018
1 parent 8d12c5d commit 2b33978
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/vientos-shell/vientos-shell.html
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@
<vientos-map
view="[[mapView]]"
locations="[[visiblePlaces]]"
projects="[[projects]]"
projects="[[visibleProjects]]"
intents="[[availableIntents]]"
current-place="[[currentPlace._id]]"
on-bbox="_updateBoundingBox"
Expand Down
7 changes: 3 additions & 4 deletions app/vientos-shell/vientos-shell.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ class VientosShell extends Polymer.mixinBehaviors(
visiblePlaces: {
type: Array,
value: [],
computed: '_setVisiblePlaces(places, boundingBox)'
computed: '_setVisiblePlaces(places, boundingBox, visibleProjects, availableIntents)'
},
reviews: {
type: Array,
Expand Down Expand Up @@ -284,7 +284,6 @@ class VientosShell extends Polymer.mixinBehaviors(

_filterProjects (...args) { return util.filterProjects(...args) }
_filterIntents (...args) { return util.filterIntents(...args) }
_filterPlaces (...args) { return util.filterPlaces(...args) }
_availableIntents (...args) { return util.availableIntents(...args) }
_getThumbnailUrl (...args) { return util.getThumbnailUrl(...args) }
_filterIntentConversations (...args) { return util.filterIntentConversations(...args) }
Expand Down Expand Up @@ -477,9 +476,9 @@ class VientosShell extends Polymer.mixinBehaviors(
}
}

_setVisiblePlaces (places, boundingBox) {
_setVisiblePlaces (places, boundingBox, visibleProjects, availableIntents) {
if (Array.from(arguments).includes(undefined)) return []
return places.filter(place => util.inBoundingBox(place, boundingBox))
return util.filterPlaces(places, boundingBox, visibleProjects, availableIntents)
}

_updateBoundingBox (e, detail) {
Expand Down
2 changes: 1 addition & 1 deletion app/widgets/vientos-map/vientos-map.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class VientosMap extends Polymer.Element {
_initializeMap ({ createMap, tileLayer, layerGroup, marker, icon, divIcon, toPoint }) {
this.map = createMap(this.$.map)
this.meIcon = divIcon({
html: '<div id="my-location"></div>',
html: '<div id="my-location"></div>'
})
this.map.setView([this.latitude, this.longitude], this.zoom)

Expand Down
10 changes: 6 additions & 4 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ export function hasLocationsInBoundingBox (entity, places, boundingBox) {
})
}

export function filterPlaces (entities, places, boundingBox) {
export function filterPlaces (places, boundingBox, projects, intents) {
if (Array.from(arguments).includes(undefined)) return []
return entities.reduce((acc, entity) => {
return acc.concat(hasLocationsInBoundingBox(entity, places, boundingBox))
}, [])
let boundedPlaces = places.filter(place => inBoundingBox(place, boundingBox))
return boundedPlaces.filter(place => {
return projects.some(project => project.locations.includes(place._id)) ||
intents.some(intent => intent.locations.includes(place._id))
})
}

function appearsInSearchResults (entity, searchTerm, searchIndex) {
Expand Down

0 comments on commit 2b33978

Please sign in to comment.