mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-16 13:59:27 +02:00
Use locationManager to resolve/query community index
This commit is contained in:
+37
-40
@@ -1,11 +1,10 @@
|
||||
import { dispatch as d3_dispatch } from 'd3-dispatch';
|
||||
import { select as d3_select } from 'd3-selection';
|
||||
|
||||
import LocationConflation from '@ideditor/location-conflation';
|
||||
import whichPolygon from 'which-polygon';
|
||||
|
||||
import { fileFetcher } from '../core/file_fetcher';
|
||||
import { locationManager } from '../core/locations';
|
||||
import { t, localizer } from '../core/localizer';
|
||||
|
||||
import { svgIcon } from '../svg/icon';
|
||||
import { uiDisclosure } from '../ui/disclosure';
|
||||
import { utilRebind } from '../util/rebind';
|
||||
@@ -23,36 +22,34 @@ export function uiSuccess(context) {
|
||||
|
||||
function ensureOSMCommunityIndex() {
|
||||
const data = fileFetcher;
|
||||
return Promise.all([ data.get('oci_resources'), data.get('oci_features') ])
|
||||
return Promise.all([
|
||||
data.get('oci_features'),
|
||||
data.get('oci_resources')
|
||||
])
|
||||
.then(vals => {
|
||||
if (_oci) return _oci;
|
||||
|
||||
const ociResources = vals[0].resources;
|
||||
const loco = new LocationConflation(vals[1]);
|
||||
let ociFeatures = {};
|
||||
// Merge Custom Features
|
||||
if (vals[0] && Array.isArray(vals[0].features)) {
|
||||
locationManager.mergeCustomGeoJSON(vals[0]);
|
||||
}
|
||||
|
||||
Object.values(ociResources).forEach(resource => {
|
||||
let feature;
|
||||
try {
|
||||
feature = loco.resolveLocationSet(resource.locationSet).feature;
|
||||
let ociFeature = ociFeatures[feature.id];
|
||||
if (!ociFeature) {
|
||||
ociFeature = JSON.parse(JSON.stringify(feature)); // deep clone
|
||||
ociFeature.properties.resourceIDs = new Set();
|
||||
ociFeatures[feature.id] = ociFeature;
|
||||
}
|
||||
ociFeature.properties.resourceIDs.add(resource.id);
|
||||
} catch (err) {
|
||||
/* ignore communities with an unresolvable locationSet */
|
||||
console.warn(`warning: skipping community resource ${resource.id}: ${err.message}`); // eslint-disable-line no-console
|
||||
}
|
||||
});
|
||||
const ociResources = Object.values(vals[1].resources);
|
||||
const locationSets = ociResources.map(r => r.locationSet);
|
||||
|
||||
return _oci = {
|
||||
features: ociFeatures,
|
||||
resources: ociResources,
|
||||
query: whichPolygon({ type: 'FeatureCollection', features: Object.values(ociFeatures) })
|
||||
};
|
||||
// Resolve all locationSet features.
|
||||
// When done, assign the locationSetIDs (we use these to quickly test where each community is valid).
|
||||
if (locationSets.length) {
|
||||
return locationManager.mergeLocationSets(locationSets)
|
||||
.then(() => {
|
||||
ociResources.forEach(r => r.locationSetID = locationManager.locationSetID(r.locationSet));
|
||||
_oci = { resources: ociResources };
|
||||
return _oci;
|
||||
});
|
||||
} else {
|
||||
_oci = { resources: [] }; // no resources?
|
||||
return _oci;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -156,19 +153,19 @@ export function uiSuccess(context) {
|
||||
// Get OSM community index features intersecting the map..
|
||||
ensureOSMCommunityIndex()
|
||||
.then(oci => {
|
||||
let communities = [];
|
||||
const properties = oci.query(context.map().center(), true) || [];
|
||||
const loc = context.map().center();
|
||||
const validLocations = locationManager.locationsAt(loc);
|
||||
|
||||
// Gather the communities from the result
|
||||
properties.forEach(props => {
|
||||
const resourceIDs = Array.from(props.resourceIDs);
|
||||
resourceIDs.forEach(resourceID => {
|
||||
const resource = oci.resources[resourceID];
|
||||
communities.push({
|
||||
area: props.area || Infinity,
|
||||
order: resource.order || 0,
|
||||
resource: resource
|
||||
});
|
||||
// Gather the communities
|
||||
let communities = [];
|
||||
oci.resources.forEach(resource => {
|
||||
let area = validLocations[resource.locationSetID];
|
||||
if (!area) return;
|
||||
|
||||
communities.push({
|
||||
area: area,
|
||||
order: resource.order || 0,
|
||||
resource: resource
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user