Merge pull request #1592 from umap-project/zoomto-from-qs
feat: allow to set zoomTo from query string
This commit is contained in:
commit
34608f55c1
3 changed files with 15 additions and 4 deletions
|
@ -27,6 +27,10 @@ L.Util.setBooleanFromQueryString = (options, name) => {
|
|||
const value = L.Util.queryString(name)
|
||||
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) => {
|
||||
let value = L.Util.queryString(name)
|
||||
if (typeof value !== 'undefined') {
|
||||
|
|
|
@ -86,16 +86,16 @@ U.Map = L.Map.extend({
|
|||
popupShape: String,
|
||||
popupTemplate: String,
|
||||
popupContentTemplate: String,
|
||||
zoomTo: undefined,
|
||||
zoomTo: Number,
|
||||
captionBar: Boolean,
|
||||
captionMenus: Boolean,
|
||||
slideshow: undefined,
|
||||
sortKey: undefined,
|
||||
labelKey: undefined,
|
||||
labelKey: String,
|
||||
filterKey: undefined,
|
||||
facetKey: undefined,
|
||||
slugKey: undefined,
|
||||
showLabel: undefined,
|
||||
showLabel: 'NullableBoolean',
|
||||
labelDirection: undefined,
|
||||
labelInteractive: undefined,
|
||||
outlinkTarget: undefined,
|
||||
|
@ -342,8 +342,12 @@ U.Map = L.Map.extend({
|
|||
case 'NullableBoolean':
|
||||
L.Util.setNullableBooleanFromQueryString(options, key)
|
||||
break
|
||||
case Number:
|
||||
L.Util.setNumberFromQueryString(options, key)
|
||||
break
|
||||
case String:
|
||||
L.Util.setFromQueryString(options, key)
|
||||
break
|
||||
}
|
||||
}
|
||||
// Specific case for datalayersControl
|
||||
|
|
|
@ -1458,7 +1458,10 @@ U.DataLayer = L.Evented.extend({
|
|||
zoomTo: function () {
|
||||
if (!this.isVisible()) return
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue