Create new places
And find them in search
This commit is contained in:
30
app/routes/place/new.js
Normal file
30
app/routes/place/new.js
Normal file
@@ -0,0 +1,30 @@
|
||||
import Route from '@ember/routing/route';
|
||||
import { service } from '@ember/service';
|
||||
|
||||
export default class PlaceNewRoute extends Route {
|
||||
@service mapUi;
|
||||
|
||||
queryParams = {
|
||||
lat: { refreshModel: true },
|
||||
lon: { refreshModel: true },
|
||||
};
|
||||
|
||||
model(params) {
|
||||
return {
|
||||
lat: parseFloat(params.lat),
|
||||
lon: parseFloat(params.lon),
|
||||
};
|
||||
}
|
||||
|
||||
setupController(controller, model) {
|
||||
super.setupController(controller, model);
|
||||
if (model.lat && model.lon) {
|
||||
this.mapUi.updateCreationCoordinates(model.lat, model.lon);
|
||||
}
|
||||
this.mapUi.startCreating();
|
||||
}
|
||||
|
||||
deactivate() {
|
||||
this.mapUi.stopCreating();
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,26 @@ export default class SearchRoute extends Route {
|
||||
// Fetch POIs
|
||||
let pois = await this.osm.getNearbyPois(lat, lon, searchRadius);
|
||||
|
||||
// Get cached/saved places in search radius
|
||||
const localMatches = this.storage.savedPlaces.filter((p) => {
|
||||
const dist = getDistance(lat, lon, p.lat, p.lon);
|
||||
return dist <= searchRadius;
|
||||
});
|
||||
|
||||
// Add local matches to the list if they aren't already there
|
||||
// We use osmId to deduplicate if possible
|
||||
localMatches.forEach((local) => {
|
||||
const exists = pois.find(
|
||||
(poi) =>
|
||||
(local.osmId && poi.osmId === local.osmId) ||
|
||||
(poi.id && poi.id === local.id)
|
||||
);
|
||||
|
||||
if (!exists) {
|
||||
pois.push(local);
|
||||
}
|
||||
});
|
||||
|
||||
// Sort by distance from click
|
||||
pois = pois
|
||||
.map((p) => {
|
||||
|
||||
Reference in New Issue
Block a user