Implemented a mapChangeLock variable to prevent mapChanges.

This commit is contained in:
Severin Opel 2019-12-02 16:51:20 +01:00
parent 096e374997
commit 8745554cee
1 changed files with 52 additions and 82 deletions

View File

@ -223,7 +223,15 @@ export class MapLayer extends GeoLayer {
mapList,
scatterContainer,
displayObject,
{ onTransform = null, onChange = null, focus = null, zoom = null, viewport = null, name = null } = {}
{
onTransform = null,
onChange = null,
focus = null,
zoom = null,
viewport = null,
name = null,
mapChangeLocked = false
} = {}
) {
super(displayObject, {
name
@ -251,6 +259,7 @@ export class MapLayer extends GeoLayer {
// this.maps = maps
// if (opts.map) this.placeMap(opts.map)
this.dynamicElements = new Map()
this._mapChangeLocked = mapChangeLocked
// Binds the transformed callback beforehand.
this.transformed = this.transformed.bind(this)
@ -258,13 +267,24 @@ export class MapLayer extends GeoLayer {
this.changeMap(mapList.active)
}
get mapChangeLocked() {
return this._mapChangeLocked
}
lockMapChange() {
this._mapChangeLocked = true
}
unlockMapChange() {
this._mapChangeLocked = false
}
adapt() {
this.layers.forEach(layer => {
if (layer.adapt) layer.adapt(this.map)
})
}
focus(coordinates, zoom) {
this.mapview.updateFocusPoint(this.map)
}
@ -314,89 +334,39 @@ export class MapLayer extends GeoLayer {
/* map ,
useScatterAsContainer = true // If set to false, the normal container is used. This is necessary when using submaps and the container need to be a RigidContainer.*/
) {
console.log('🗺️ Change map to: ', name)
let oldMap = this.map
if (!this.mapChangeLocked) {
console.log('🗺️ Change map to: ', name)
let oldMap = this.map
this.mapList.select(name)
this.mapList.select(name)
if (oldMap) {
oldMap.unload()
oldMap.onTransform.remove(this.transformed)
}
let map = this.map
if (map) {
map.load()
this.scatterContainer.addChild(map.image)
this.mapview.apply(map)
map.image.addChild(this.displayObject)
// A geolayer's displayObject is on the parent layer.
// A maplayer's displayobject is always the child of the map.
this.adapt()
this.changeHandler.call(this, map, oldMap)
//Call transform one time manually.
this.transformed()
map.onTransform.add(this.transformed)
} else {
console.error(`Could not change map to ${name}.`)
}
/*Logging.log(`Map change: ${key}`)
if (this.active !== key) {
if (this.maps.hasOwnProperty(key)) {
let old = this.map ? this.map : null
this._map = this.maps[key]
this._map.name = key
this.active = key
let container = useScatterAsContainer ? this.scatterContainer : this.container
this.map.load(container)
// Copies all layers.
this.layers.forEach(layer => {
if (old) this.map.image.addChild(layer.container)
})
this.placeMap(this.map)
/**
* TODO: Improve
*
* I'm quite sure if I made a design mistake here.
* In an earlier version I did not need to migrate the
* layers manually from the map to the next map.
*
* I believe the old version was a container next to the
* map, which got updated on transform.
*
* -SO
*/
/*
if (old) old.unload()
} else {
let keys = Object.keys(this.maps)
if (keys.length == 0) console.error('There is no map set for the map layer!')
else {
let fallbackMap = keys[0]
console.error(
`A map with the key (${key}) does not exists within the mapapp. Fallback to map: ${fallbackMap}.`
)
this.changeMap(fallbackMap, {
useScatterAsContainer
})
}
if (oldMap) {
oldMap.unload()
oldMap.onTransform.remove(this.transformed)
}
}*/
let map = this.map
if (map) {
map.load()
this.scatterContainer.addChild(map.image)
this.mapview.apply(map)
map.image.addChild(this.displayObject)
// A geolayer's displayObject is on the parent layer.
// A maplayer's displayobject is always the child of the map.
this.adapt()
this.changeHandler.call(this, map, oldMap)
//Call transform one time manually.
this.transformed()
map.onTransform.add(this.transformed)
} else {
console.error(`Could not change map to ${name}.`)
}
}
}
refocus() {