feat: allow to set zoomTo from query string

When using data/dataUrl querystring, uMap will import data at load,
and will set view using this data bounds. In some situation (Deveco),
the user wants to control the max zoom of the final view.

Also add labelKey and showLabel to be parsed from query string, still
for Deveco needs.
This commit is contained in:
Yohan Boniface 2024-02-12 09:51:13 +01:00
parent 246c0eef18
commit c378d5dc60
3 changed files with 15 additions and 4 deletions

View file

@ -27,6 +27,10 @@ L.Util.setBooleanFromQueryString = (options, name) => {
const value = L.Util.queryString(name) const value = L.Util.queryString(name)
if (typeof value !== 'undefined') options[name] = value == '1' || value == 'true' if (typeof value !== 'undefined') options[name] = value == '1' || value == 'true'
} }
L.Util.setNumberFromQueryString = (options, name) => {
const value = +L.Util.queryString(name)
if (!isNaN(value)) options[name] = value
}
L.Util.setNullableBooleanFromQueryString = (options, name) => { L.Util.setNullableBooleanFromQueryString = (options, name) => {
let value = L.Util.queryString(name) let value = L.Util.queryString(name)
if (typeof value !== 'undefined') { if (typeof value !== 'undefined') {

View file

@ -86,16 +86,16 @@ U.Map = L.Map.extend({
popupShape: String, popupShape: String,
popupTemplate: String, popupTemplate: String,
popupContentTemplate: String, popupContentTemplate: String,
zoomTo: undefined, zoomTo: Number,
captionBar: Boolean, captionBar: Boolean,
captionMenus: Boolean, captionMenus: Boolean,
slideshow: undefined, slideshow: undefined,
sortKey: undefined, sortKey: undefined,
labelKey: undefined, labelKey: String,
filterKey: undefined, filterKey: undefined,
facetKey: undefined, facetKey: undefined,
slugKey: undefined, slugKey: undefined,
showLabel: undefined, showLabel: 'NullableBoolean',
labelDirection: undefined, labelDirection: undefined,
labelInteractive: undefined, labelInteractive: undefined,
outlinkTarget: undefined, outlinkTarget: undefined,
@ -342,8 +342,12 @@ U.Map = L.Map.extend({
case 'NullableBoolean': case 'NullableBoolean':
L.Util.setNullableBooleanFromQueryString(options, key) L.Util.setNullableBooleanFromQueryString(options, key)
break break
case Number:
L.Util.setNumberFromQueryString(options, key)
break
case String: case String:
L.Util.setFromQueryString(options, key) L.Util.setFromQueryString(options, key)
break
} }
} }
// Specific case for datalayersControl // Specific case for datalayersControl

View file

@ -1458,7 +1458,10 @@ U.DataLayer = L.Evented.extend({
zoomTo: function () { zoomTo: function () {
if (!this.isVisible()) return if (!this.isVisible()) return
const bounds = this.layer.getBounds() const bounds = this.layer.getBounds()
if (bounds.isValid()) this.map.fitBounds(bounds) if (bounds.isValid()) {
const options = {maxZoom: this.getOption("zoomTo")}
this.map.fitBounds(bounds, options)
}
}, },
// Is this layer type browsable in theorie // Is this layer type browsable in theorie