mirror of
https://github.com/FoggedLens/iD.git
synced 2026-03-31 01:09:22 +02:00
Don't bundle the community index anymore, fetch from CDN instead
Start fetching and preparing it just before the changeset gets sent
This commit is contained in:
@@ -1,43 +1,13 @@
|
||||
export { dataLocales } from './locales.json';
|
||||
export { en as dataEn } from '../dist/locales/en.json';
|
||||
|
||||
import {
|
||||
features as ociCustomFeatures,
|
||||
resources as ociResources
|
||||
} from 'osm-community-index';
|
||||
|
||||
import { dataImagery } from './imagery.json';
|
||||
import { presets } from './presets/presets.json';
|
||||
import { defaults } from './presets/defaults.json';
|
||||
import { categories } from './presets/categories.json';
|
||||
import { fields } from './presets/fields.json';
|
||||
|
||||
import LocationConflation from '@ideditor/location-conflation';
|
||||
import whichPolygon from 'which-polygon';
|
||||
|
||||
|
||||
// index the osm-community-index
|
||||
let ociFeatures = {};
|
||||
const loco = new LocationConflation({ type: 'FeatureCollection', features: ociCustomFeatures });
|
||||
|
||||
Object.values(ociResources).forEach(resource => {
|
||||
const feature = loco.resolveLocationSet(resource.locationSet);
|
||||
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);
|
||||
});
|
||||
|
||||
|
||||
export let data = {
|
||||
community: {
|
||||
features: ociFeatures,
|
||||
resources: ociResources,
|
||||
query: whichPolygon({ type: 'FeatureCollection', features: Object.values(ociFeatures) })
|
||||
},
|
||||
imagery: dataImagery, //legacy
|
||||
presets: {
|
||||
presets: presets,
|
||||
|
||||
@@ -16,6 +16,8 @@ export function coreData(context) {
|
||||
'intro_graph': 'data/intro_graph.min.json',
|
||||
'languages': 'data/languages.min.json',
|
||||
'locales': 'data/locales.min.json',
|
||||
'oci_features': 'https://cdn.jsdelivr.net/npm/osm-community-index@2/dist/features.min.json',
|
||||
'oci_resources': 'https://cdn.jsdelivr.net/npm/osm-community-index@2/dist/resources.min.json',
|
||||
'phone_formats': 'data/phone_formats.min.json',
|
||||
'shortcuts': 'data/shortcuts.min.json',
|
||||
'territory_languages': 'data/territory_languages.min.json',
|
||||
|
||||
@@ -1,20 +1,55 @@
|
||||
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 { t, languageName } from '../util/locale';
|
||||
import { data } from '../../data';
|
||||
import { svgIcon } from '../svg/icon';
|
||||
import { uiDisclosure } from '../ui/disclosure';
|
||||
import { utilDetect } from '../util/detect';
|
||||
import { utilRebind } from '../util/rebind';
|
||||
|
||||
|
||||
let _oci = null;
|
||||
|
||||
export function uiSuccess(context) {
|
||||
const MAXEVENTS = 2;
|
||||
const detected = utilDetect();
|
||||
const dispatch = d3_dispatch('cancel');
|
||||
let _changeset;
|
||||
let _location;
|
||||
ensureOSMCommunityIndex(); // start fetching the data
|
||||
|
||||
|
||||
function ensureOSMCommunityIndex() {
|
||||
const data = context.data();
|
||||
return Promise.all([ data.get('oci_resources'), data.get('oci_features') ])
|
||||
.then(vals => {
|
||||
if (_oci) return _oci;
|
||||
|
||||
const ociResources = vals[0];
|
||||
const loco = new LocationConflation(vals[1]);
|
||||
let ociFeatures = {};
|
||||
|
||||
Object.values(ociResources).forEach(resource => {
|
||||
const feature = loco.resolveLocationSet(resource.locationSet);
|
||||
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);
|
||||
});
|
||||
|
||||
return _oci = {
|
||||
features: ociFeatures,
|
||||
resources: ociResources,
|
||||
query: whichPolygon({ type: 'FeatureCollection', features: Object.values(ociFeatures) })
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// string-to-date parsing in JavaScript is weird
|
||||
@@ -114,28 +149,31 @@ export function uiSuccess(context) {
|
||||
}));
|
||||
|
||||
|
||||
// Get community index features intersecting the map..
|
||||
let communities = [];
|
||||
const properties = data.community.query(context.map().center(), true) || [];
|
||||
// Get OSM community index features intersecting the map..
|
||||
ensureOSMCommunityIndex()
|
||||
.then(oci => {
|
||||
let communities = [];
|
||||
const properties = oci.query(context.map().center(), true) || [];
|
||||
|
||||
// Gather the communities from the result
|
||||
properties.forEach(props => {
|
||||
const resourceIDs = Array.from(props.resourceIDs);
|
||||
resourceIDs.forEach(resourceID => {
|
||||
const resource = data.community.resources[resourceID];
|
||||
communities.push({
|
||||
area: props.area || Infinity,
|
||||
order: resource.order || 0,
|
||||
resource: resource
|
||||
// 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
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// sort communities by feature area ascending, community order descending
|
||||
communities.sort((a, b) => a.area - b.area || b.order - a.order);
|
||||
|
||||
body
|
||||
.call(showCommunityLinks, communities.map(c => c.resource));
|
||||
});
|
||||
});
|
||||
|
||||
// sort communities by feature area ascending, community order descending
|
||||
communities.sort((a, b) => a.area - b.area || b.order - a.order);
|
||||
|
||||
body
|
||||
.call(showCommunityLinks, communities.map(c => c.resource));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -95,7 +95,6 @@
|
||||
"name-suggestion-index": "3.7.0",
|
||||
"npm-run-all": "^4.0.0",
|
||||
"object-inspect": "0.4.0",
|
||||
"osm-community-index": "2.0.0",
|
||||
"phantomjs-prebuilt": "~2.1.11",
|
||||
"request": "^2.88.0",
|
||||
"rollup": "~1.29.1",
|
||||
|
||||
Reference in New Issue
Block a user