mirror of
https://github.com/umap-project/umap.git
synced 2025-04-28 19:42:36 +02:00
chore: refactore LeafletMap.setup/update
This commit is contained in:
parent
e1a24b6180
commit
6d56bbb5de
3 changed files with 30 additions and 25 deletions
|
@ -306,8 +306,12 @@ const ControlsMixin = {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
initCaptionBar: function () {
|
renderCaptionBar: function () {
|
||||||
const container = DomUtil.create('div', 'umap-caption-bar', this._controlContainer)
|
if (this.options.noControl) return
|
||||||
|
const container =
|
||||||
|
this._controlContainer.querySelector('.umap-caption-bar') ||
|
||||||
|
DomUtil.create('div', 'umap-caption-bar', this._controlContainer)
|
||||||
|
container.innerHTML = ''
|
||||||
const name = DomUtil.create('h3', 'map-name', container)
|
const name = DomUtil.create('h3', 'map-name', container)
|
||||||
DomEvent.disableClickPropagation(container)
|
DomEvent.disableClickPropagation(container)
|
||||||
this.umap.addAuthorLink(container)
|
this.umap.addAuthorLink(container)
|
||||||
|
@ -316,8 +320,7 @@ const ControlsMixin = {
|
||||||
'umap-about-link flat',
|
'umap-about-link flat',
|
||||||
container,
|
container,
|
||||||
translate('Open caption'),
|
translate('Open caption'),
|
||||||
this.umap.openCaption,
|
() => this.umap.openCaption()
|
||||||
this
|
|
||||||
)
|
)
|
||||||
DomUtil.createButton(
|
DomUtil.createButton(
|
||||||
'umap-open-browser-link flat',
|
'umap-open-browser-link flat',
|
||||||
|
@ -334,8 +337,8 @@ const ControlsMixin = {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.umap.onceDatalayersLoaded(function () {
|
this.umap.onceDatalayersLoaded(() => {
|
||||||
this.slideshow.renderToolbox(container)
|
this.umap.slideshow.renderToolbox(container)
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -481,11 +484,18 @@ export const LeafletMap = BaseMap.extend({
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
attachToDom: function () {
|
setup: function () {
|
||||||
this.initControls()
|
this.initControls()
|
||||||
// Needs locate control and hash to exist
|
// Needs locate control and hash to exist
|
||||||
this.initCenter()
|
this.initCenter()
|
||||||
|
this.update()
|
||||||
|
},
|
||||||
|
|
||||||
|
update: function () {
|
||||||
|
this.setOptions(this.umap.properties)
|
||||||
this.initTileLayers()
|
this.initTileLayers()
|
||||||
|
this.renderCaptionBar()
|
||||||
|
this.renderEditToolbar()
|
||||||
// Needs tilelayer to exist for minimap
|
// Needs tilelayer to exist for minimap
|
||||||
this.renderControls()
|
this.renderControls()
|
||||||
this.handleLimitBounds()
|
this.handleLimitBounds()
|
||||||
|
|
|
@ -85,11 +85,16 @@ export default class Umap extends ServerStored {
|
||||||
if (center) {
|
if (center) {
|
||||||
this._leafletMap.options.center = this._leafletMap.latLng(center)
|
this._leafletMap.options.center = this._leafletMap.latLng(center)
|
||||||
}
|
}
|
||||||
this._leafletMap.attachToDom()
|
|
||||||
|
// Needed to render controls
|
||||||
|
this.permissions = new MapPermissions(this)
|
||||||
|
this.urls = new URLs(this.properties.urls)
|
||||||
|
this.slideshow = new Slideshow(this, this.properties.slideshow)
|
||||||
|
|
||||||
|
this._leafletMap.setup()
|
||||||
|
|
||||||
if (geojson.properties.schema) this.overrideSchema(geojson.properties.schema)
|
if (geojson.properties.schema) this.overrideSchema(geojson.properties.schema)
|
||||||
|
|
||||||
this.urls = new URLs(this.properties.urls)
|
|
||||||
|
|
||||||
this.panel = new Panel(this)
|
this.panel = new Panel(this)
|
||||||
this.dialog = new Dialog({ className: 'dark' })
|
this.dialog = new Dialog({ className: 'dark' })
|
||||||
|
@ -171,15 +176,12 @@ export default class Umap extends ServerStored {
|
||||||
await this.loadDataFromQueryString()
|
await this.loadDataFromQueryString()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.slideshow = new Slideshow(this, this.properties.slideshow)
|
|
||||||
this.permissions = new MapPermissions(this)
|
|
||||||
if (this.hasEditMode()) {
|
if (this.hasEditMode()) {
|
||||||
this._leafletMap.initEditTools()
|
this._leafletMap.initEditTools()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.properties.noControl) {
|
if (!this.properties.noControl) {
|
||||||
this.initShortcuts()
|
this.initShortcuts()
|
||||||
this._leafletMap.initCaptionBar()
|
|
||||||
this._leafletMap.on('contextmenu', this.onContextMenu)
|
this._leafletMap.on('contextmenu', this.onContextMenu)
|
||||||
this.onceDataLoaded(this.setViewFromQueryString)
|
this.onceDataLoaded(this.setViewFromQueryString)
|
||||||
this.propagate()
|
this.propagate()
|
||||||
|
@ -1253,10 +1255,7 @@ export default class Umap extends ServerStored {
|
||||||
for (const impact of impacts) {
|
for (const impact of impacts) {
|
||||||
switch (impact) {
|
switch (impact) {
|
||||||
case 'ui':
|
case 'ui':
|
||||||
this._leafletMap.setOptions(this.properties)
|
this._leafletMap.update()
|
||||||
this._leafletMap.initCaptionBar()
|
|
||||||
this._leafletMap.renderEditToolbar()
|
|
||||||
this._leafletMap.renderControls()
|
|
||||||
this.browser.redraw()
|
this.browser.redraw()
|
||||||
this.propagate()
|
this.propagate()
|
||||||
break
|
break
|
||||||
|
@ -1499,11 +1498,7 @@ export default class Umap extends ServerStored {
|
||||||
dataLayer.fromUmapGeoJSON(geojson)
|
dataLayer.fromUmapGeoJSON(geojson)
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: refactor with leafletMap init / render
|
this._leafletMap.update()
|
||||||
this._leafletMap.setOptions(this.properties)
|
|
||||||
this._leafletMap.initTileLayers()
|
|
||||||
this._leafletMap.renderControls()
|
|
||||||
this._leafletMap.handleLimitBounds()
|
|
||||||
this.eachDataLayer((datalayer) => {
|
this.eachDataLayer((datalayer) => {
|
||||||
if (mustReindex) datalayer.reindex()
|
if (mustReindex) datalayer.reindex()
|
||||||
datalayer.redraw()
|
datalayer.redraw()
|
||||||
|
|
|
@ -193,7 +193,7 @@ def test_websocket_connection_can_sync_map_properties(
|
||||||
|
|
||||||
@pytest.mark.xdist_group(name="websockets")
|
@pytest.mark.xdist_group(name="websockets")
|
||||||
def test_websocket_connection_can_sync_datalayer_properties(
|
def test_websocket_connection_can_sync_datalayer_properties(
|
||||||
context, live_server, websocket_server, tilelayer
|
new_page, live_server, websocket_server, tilelayer
|
||||||
):
|
):
|
||||||
map = MapFactory(name="sync", edit_status=Map.ANONYMOUS)
|
map = MapFactory(name="sync", edit_status=Map.ANONYMOUS)
|
||||||
map.settings["properties"]["syncEnabled"] = True
|
map.settings["properties"]["syncEnabled"] = True
|
||||||
|
@ -201,9 +201,9 @@ def test_websocket_connection_can_sync_datalayer_properties(
|
||||||
DataLayerFactory(map=map, data={})
|
DataLayerFactory(map=map, data={})
|
||||||
|
|
||||||
# Create two tabs
|
# Create two tabs
|
||||||
peerA = context.new_page()
|
peerA = new_page()
|
||||||
peerA.goto(f"{live_server.url}{map.get_absolute_url()}?edit")
|
peerA.goto(f"{live_server.url}{map.get_absolute_url()}?edit")
|
||||||
peerB = context.new_page()
|
peerB = new_page()
|
||||||
peerB.goto(f"{live_server.url}{map.get_absolute_url()}?edit")
|
peerB.goto(f"{live_server.url}{map.get_absolute_url()}?edit")
|
||||||
|
|
||||||
# Layer addition, name and type are synced
|
# Layer addition, name and type are synced
|
||||||
|
@ -215,7 +215,7 @@ def test_websocket_connection_can_sync_datalayer_properties(
|
||||||
peerA.locator("body").press("Escape")
|
peerA.locator("body").press("Escape")
|
||||||
|
|
||||||
peerB.get_by_role("link", name="Manage layers").click()
|
peerB.get_by_role("link", name="Manage layers").click()
|
||||||
peerB.get_by_role("button", name="Edit").first.click()
|
peerB.locator(".panel.right").get_by_role("button", name="Edit").first.click()
|
||||||
expect(peerB.locator('input[name="name"]')).to_have_value("synced layer!")
|
expect(peerB.locator('input[name="name"]')).to_have_value("synced layer!")
|
||||||
expect(peerB.get_by_role("combobox")).to_have_value("Choropleth")
|
expect(peerB.get_by_role("combobox")).to_have_value("Choropleth")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue