Got continents working. Very slow though - should simplify them using e.g. Concaveman.

master
Sander Vocke 6 years ago
parent cd0bfe1cf8
commit 6ed986bfc3
  1. 52
      src/geo_store.js
  2. 12
      src/userquerywidget.js

@ -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));
})
}

@ -34,6 +34,7 @@ import {
TimeFilter, ImageTypeFilter, ImageTypeEnum, LocationFilter
} from './queries.js'
import { Typography } from '@material-ui/core';
import { query_geometry } from './geo_store.js';
const useStyles = makeStyles(theme => ({
root: {},
@ -90,11 +91,12 @@ export function EditLocationFilterExpression(props) {
return;
}
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) {
updateProposal(jsonres[0]);
// Do a geometry query.
query_geometry(query)
.then(result => {
console.log("Query result:", result);
if (result) {
updateProposal(result);
}
});
}

Loading…
Cancel
Save