mirror of
https://github.com/umap-project/umap.git
synced 2025-04-29 03:42:37 +02:00
Merge pull request #2094 from umap-project/overpass-boundary-persistent
feat: make boundary persistent in overpass importer
This commit is contained in:
commit
5e6ac993d9
3 changed files with 76 additions and 16 deletions
|
@ -306,15 +306,11 @@ export const SingleMixin = (Base) =>
|
||||||
textContent: '×',
|
textContent: '×',
|
||||||
})
|
})
|
||||||
this.input.style.display = 'none'
|
this.input.style.display = 'none'
|
||||||
DomEvent.on(
|
DomEvent.on(close, 'click', () => {
|
||||||
close,
|
|
||||||
'click',
|
|
||||||
function () {
|
|
||||||
this.selectedContainer.innerHTML = ''
|
this.selectedContainer.innerHTML = ''
|
||||||
this.input.style.display = 'block'
|
this.input.style.display = 'block'
|
||||||
},
|
this.options.on_unselect(result)
|
||||||
this
|
})
|
||||||
)
|
|
||||||
this.hide()
|
this.hide()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,11 +52,10 @@ export class Importer {
|
||||||
options?.searchUrl ||
|
options?.searchUrl ||
|
||||||
'https://photon.komoot.io/api?q={q}&layer=county&layer=city&layer=state'
|
'https://photon.komoot.io/api?q={q}&layer=county&layer=city&layer=state'
|
||||||
this.id = 'overpass'
|
this.id = 'overpass'
|
||||||
|
this.boundaryChoice = null
|
||||||
}
|
}
|
||||||
|
|
||||||
async open(importer) {
|
async open(importer) {
|
||||||
let boundary = null
|
|
||||||
let boundaryName = null
|
|
||||||
const container = DomUtil.create('div')
|
const container = DomUtil.create('div')
|
||||||
container.innerHTML = TEMPLATE
|
container.innerHTML = TEMPLATE
|
||||||
this.autocomplete = new Autocomplete(container.querySelector('#area'), {
|
this.autocomplete = new Autocomplete(container.querySelector('#area'), {
|
||||||
|
@ -65,10 +64,15 @@ export class Importer {
|
||||||
'Type area name, or let empty to load data in current map view'
|
'Type area name, or let empty to load data in current map view'
|
||||||
),
|
),
|
||||||
on_select: (choice) => {
|
on_select: (choice) => {
|
||||||
boundary = choice.item.value
|
this.boundaryChoice = choice
|
||||||
boundaryName = choice.item.label
|
},
|
||||||
|
on_unselect: (choice) => {
|
||||||
|
this.boundaryChoice = null
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
if (this.boundaryChoice) {
|
||||||
|
this.autocomplete.displaySelected(this.boundaryChoice)
|
||||||
|
}
|
||||||
this.map.help.parse(container)
|
this.map.help.parse(container)
|
||||||
|
|
||||||
const confirm = (form) => {
|
const confirm = (form) => {
|
||||||
|
@ -79,10 +83,10 @@ export class Importer {
|
||||||
let tags = form.tags
|
let tags = form.tags
|
||||||
if (!tags.startsWith('[')) tags = `[${tags}]`
|
if (!tags.startsWith('[')) tags = `[${tags}]`
|
||||||
let area = '{south},{west},{north},{east}'
|
let area = '{south},{west},{north},{east}'
|
||||||
if (boundary) area = `area:${boundary}`
|
if (this.boundaryChoice) area = `area:${this.boundaryChoice.item.value}`
|
||||||
const query = `[out:json];nwr${tags}(${area});out ${form.out};`
|
const query = `[out:json];nwr${tags}(${area});out ${form.out};`
|
||||||
importer.url = `${this.baseUrl}?data=${query}`
|
importer.url = `${this.baseUrl}?data=${query}`
|
||||||
if (boundary) importer.layerName = boundaryName
|
if (this.boundaryChoice) importer.layerName = this.boundaryChoice.item.label
|
||||||
importer.format = 'osm'
|
importer.format = 'osm'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,7 +95,7 @@ export class Importer {
|
||||||
template: container,
|
template: container,
|
||||||
className: `${this.id} importer dark`,
|
className: `${this.id} importer dark`,
|
||||||
accept: translate('Choose this data'),
|
accept: translate('Choose this data'),
|
||||||
cancel: false
|
cancel: false,
|
||||||
})
|
})
|
||||||
.then(confirm)
|
.then(confirm)
|
||||||
}
|
}
|
||||||
|
|
|
@ -579,6 +579,66 @@ def test_overpass_import_with_bbox(page, live_server, tilelayer, settings):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_overpass_import_retains_boundary(page, live_server, tilelayer, settings):
|
||||||
|
settings.UMAP_IMPORTERS = {
|
||||||
|
"overpass": {
|
||||||
|
"url": "https://my.overpass.io/interpreter",
|
||||||
|
"searchUrl": "https://foobar.io/api?q={q}",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def handle(route):
|
||||||
|
route.fulfill(
|
||||||
|
json={
|
||||||
|
"features": [
|
||||||
|
{
|
||||||
|
"geometry": {
|
||||||
|
"coordinates": [3.2394035, 48.4149956],
|
||||||
|
"type": "Point",
|
||||||
|
},
|
||||||
|
"type": "Feature",
|
||||||
|
"properties": {
|
||||||
|
"osm_type": "R",
|
||||||
|
"osm_id": 1393025,
|
||||||
|
"extent": [3.2290211, 48.4268302, 3.2623032, 48.4041636],
|
||||||
|
"country": "France",
|
||||||
|
"osm_key": "place",
|
||||||
|
"countrycode": "FR",
|
||||||
|
"osm_value": "village",
|
||||||
|
"postcode": "77480",
|
||||||
|
"name": "Bray-sur-Seine",
|
||||||
|
"county": "Seine-et-Marne",
|
||||||
|
"state": "Île-de-France",
|
||||||
|
"type": "city",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"type": "FeatureCollection",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Intercept the route
|
||||||
|
page.route(re.compile("https://foobar.io/api.*"), handle)
|
||||||
|
page.goto(f"{live_server.url}/map/new/")
|
||||||
|
page.get_by_role("link", name="Import data").click()
|
||||||
|
page.get_by_role("button", name="Overpass").click()
|
||||||
|
page.get_by_placeholder("amenity=drinking_water").fill("building")
|
||||||
|
page.get_by_placeholder("Type area name, or let empty").click()
|
||||||
|
page.get_by_placeholder("Type area name, or let empty").press_sequentially("bray")
|
||||||
|
page.get_by_text("Bray-sur-Seine, Seine-et-Marne, Île-de-France, France").click()
|
||||||
|
expect(page.locator("#area")).to_contain_text(
|
||||||
|
"Bray-sur-Seine, Seine-et-Marne, Île-de-France, France"
|
||||||
|
)
|
||||||
|
page.get_by_role("button", name="Choose this data").click()
|
||||||
|
expect(page.get_by_placeholder("Provide an URL here")).to_have_value(
|
||||||
|
"https://my.overpass.io/interpreter?data=[out:json];nwr[building](area:3601393025);out geom;"
|
||||||
|
)
|
||||||
|
page.get_by_role("button", name="Overpass").click()
|
||||||
|
expect(page.locator("#area")).to_contain_text(
|
||||||
|
"Bray-sur-Seine, Seine-et-Marne, Île-de-France, France"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def test_import_from_datasets(page, live_server, tilelayer, settings):
|
def test_import_from_datasets(page, live_server, tilelayer, settings):
|
||||||
settings.UMAP_IMPORTERS = {
|
settings.UMAP_IMPORTERS = {
|
||||||
"datasets": {
|
"datasets": {
|
||||||
|
|
Loading…
Reference in a new issue