Remove default center to prevent multiple map initialisations

We want to init the map view once, in our initCenter method,
so we remove any center from the option, to prevent Leaflet
to init the map on this centers

fix #1277
This commit is contained in:
Yohan Boniface 2023-08-24 20:48:24 +02:00
parent 981f727281
commit 9c16bbfe51
4 changed files with 26 additions and 9 deletions

View file

@ -1,8 +1,6 @@
L.Map.mergeOptions({
overlay: null,
datalayers: [],
center: [50, 4],
zoom: 6,
hash: true,
default_color: 'DarkBlue',
default_smoothFactor: 1.0,
@ -86,11 +84,12 @@ L.U.Map.include({
geojson.properties.fullscreenControl = false
L.Util.setBooleanFromQueryString(geojson.properties, 'scrollWheelZoom')
// Before calling parent initialize
if (geojson.geometry) this.options.center = this.latLng(geojson.geometry)
L.Map.prototype.initialize.call(this, el, geojson.properties)
// After calling parent initialize, as we are doing initCenter our-selves
if (geojson.geometry) this.options.center = this.latLng(geojson.geometry)
this.ui = new L.U.UI(this._container)
this.xhr = new L.U.Xhr(this.ui)
this.xhr.on('dataloading', (e) => this.fire('dataloading', e))

View file

@ -0,0 +1,16 @@
describe('L.U.Map.initialize', function () {
afterEach(function () {
resetMap()
})
it("should not show a minimap by default", function () {
this.map = initMap()
assert.notOk(qs('.leaflet-control-minimap'))
})
it("should show a minimap", function () {
this.map = initMap({ miniMap: true })
assert.ok(qs('.leaflet-control-minimap'))
})
})

View file

@ -107,10 +107,6 @@ var defaultDatalayerData = function (custom) {
function initMap(options) {
default_options = {
geometry: {
type: 'Point',
coordinates: [5.0592041015625, 52.05924589011585],
},
type: 'Feature',
properties: {
umap_id: 42,
@ -197,7 +193,7 @@ function initMap(options) {
allowEdit: true,
moreControl: true,
scaleControl: true,
miniMap: true,
miniMap: false,
datalayersControl: true,
displayCaptionOnLoad: false,
displayPopupFooter: false,
@ -205,7 +201,12 @@ function initMap(options) {
},
}
default_options.properties.datalayers.push(defaultDatalayerData())
options = options || {}
options.properties = L.extend({}, default_options.properties, options)
options.geometry = {
type: 'Point',
coordinates: [5.0592041015625, 52.05924589011585],
}
return new L.U.Map('map', options)
}

View file

@ -67,6 +67,7 @@
</script>
<script src="./_pre.js"></script>
<script src="./Map.js"></script>
<script src="./Map.Init.js"></script>
<script src="./DataLayer.js"></script>
<script src="./TableEditor.js"></script>
<script src="./Feature.js"></script>