|
|
|
@ -7,6 +7,7 @@ var g_GeoStore = { |
|
|
|
|
areas: {}, |
|
|
|
|
area_query_results: {}, |
|
|
|
|
image_index: {}, |
|
|
|
|
static_areas: {}, |
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
export function hash_geo_area(geo_area) { |
|
|
|
@ -147,10 +148,51 @@ export function image_in_area(image_id, area_hash) { |
|
|
|
|
export function load_static_geo_polygons() { |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
fetch('/continent_polygons.geojson') |
|
|
|
|
.then(res => res.json()) |
|
|
|
|
.then(json => { |
|
|
|
|
console.log("Continents:", json); |
|
|
|
|
resolve(json); |
|
|
|
|
}); |
|
|
|
|
.then(res => res.json()) |
|
|
|
|
.then(json => { |
|
|
|
|
// The continents are stored as an array of features. Change it to a
|
|
|
|
|
// dictionary of name to geometry.
|
|
|
|
|
json.features.forEach(feature => { |
|
|
|
|
g_GeoStore.static_areas[feature.properties.continent] = feature.geometry; |
|
|
|
|
}); |
|
|
|
|
resolve(); |
|
|
|
|
}); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
export function query_geometry(query) { |
|
|
|
|
return new Promise((resolve, reject) => { |
|
|
|
|
const query_words = query.toLowerCase().trim().split(/\s+/); |
|
|
|
|
for(var key in g_GeoStore.static_areas) { |
|
|
|
|
const static_words = key.toLowerCase().trim().split(/\s+/); |
|
|
|
|
if(query_words.length == static_words.length) { |
|
|
|
|
var match = true; |
|
|
|
|
for(let i=0; i<static_words.length; i++) { |
|
|
|
|
if(static_words[i] != query_words[i]) { |
|
|
|
|
match = false; |
|
|
|
|
break; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
if(match) { |
|
|
|
|
// Matched a static geometry in our store.
|
|
|
|
|
resolve({ |
|
|
|
|
display_name: key, |
|
|
|
|
geojson: g_GeoStore.static_areas[key], |
|
|
|
|
}); |
|
|
|
|
return; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
// No match in our store, query Nominatim instead
|
|
|
|
|
fetch("https://nominatim.openstreetmap.org/search?polygon_geojson=1&polygon_threshold=0.001&format=json&limit=5&q=" + query) |
|
|
|
|
.then(res => res.json()) |
|
|
|
|
.then(jsonres => { |
|
|
|
|
if (Array.isArray(jsonres) && jsonres.length > 0) { |
|
|
|
|
resolve(jsonres[0]); |
|
|
|
|
} |
|
|
|
|
resolve(false); |
|
|
|
|
return; |
|
|
|
|
}) |
|
|
|
|
.catch(e => reject(e)); |
|
|
|
|
}) |
|
|
|
|
} |