Geographics placements working again.
This commit is contained in:
+33
-88
@@ -21,20 +21,20 @@ export class GeoLayer {
|
||||
)
|
||||
return null
|
||||
} else {
|
||||
this.geographics = []
|
||||
displayObject.map = this
|
||||
this.displayObject = displayObject
|
||||
|
||||
this.layers = []
|
||||
this.geographics = []
|
||||
|
||||
let pixiAddChild = displayObject.addChild.bind(displayObject)
|
||||
this.pixiAddChild = displayObject.addChild.bind(displayObject)
|
||||
displayObject.addChild = (...elements) => {
|
||||
elements.forEach(element => {
|
||||
if (element instanceof GeoGraphics) {
|
||||
this.geographics.push(element)
|
||||
pixiAddChild(element.graphics)
|
||||
this.pixiAddChild(element.graphics)
|
||||
} else {
|
||||
pixiAddChild(element)
|
||||
this.pixiAddChild(element)
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -112,59 +112,6 @@ export class GeoLayer {
|
||||
// }
|
||||
}
|
||||
|
||||
export class MapList {
|
||||
constructor(active, maps) {
|
||||
this.maps = maps
|
||||
this.active = active
|
||||
|
||||
if (Object.keys(maps).length > 0) this.select(active)
|
||||
}
|
||||
|
||||
/**
|
||||
* Selects a map from the map list.
|
||||
*
|
||||
* @param {string} active - Name of the map to select.
|
||||
* @returns
|
||||
* @memberof MapList
|
||||
*/
|
||||
select(active) {
|
||||
let map = null
|
||||
|
||||
if (active !== this.active) {
|
||||
let keys = Object.keys(this.maps)
|
||||
if (keys.length > 0) {
|
||||
if (this.maps[active] == null) {
|
||||
let altActive = keys[0]
|
||||
console.warn(
|
||||
`The MapList does not contain the provided active key '${active}'. Used '${altActive}' as fallback.`
|
||||
)
|
||||
|
||||
active = altActive
|
||||
}
|
||||
|
||||
if (this.active !== active) {
|
||||
this.active = active
|
||||
map = this.maps[active]
|
||||
}
|
||||
} else {
|
||||
console.error(`Could not provide a fallback map! The map object is empty.`)
|
||||
}
|
||||
}
|
||||
|
||||
return map
|
||||
}
|
||||
|
||||
add(key, map) {
|
||||
if (this.maps[key] != null) consol.warn('Key already in mapList. The existing key was overwritten.')
|
||||
this.maps[key] = map
|
||||
}
|
||||
|
||||
get map() {
|
||||
console.log(this.maps, this.active)
|
||||
return this.maps[this.active]
|
||||
}
|
||||
}
|
||||
|
||||
export class MapLayer extends GeoLayer {
|
||||
constructor(
|
||||
scatterContainer,
|
||||
@@ -249,27 +196,6 @@ export class MapLayer extends GeoLayer {
|
||||
// }
|
||||
// }
|
||||
|
||||
placeMap(map) {
|
||||
if (map instanceof GeoMap) {
|
||||
this.scatterContainer.addChild(map.image)
|
||||
this.map.onTransform.add(this.transformed.bind(this))
|
||||
this.mapview.update(this.map)
|
||||
|
||||
this.adapt()
|
||||
} else {
|
||||
console.error("Could not set map, it's not of type GeoMap.", map)
|
||||
}
|
||||
}
|
||||
|
||||
placeElement(elem) {
|
||||
if (elem instanceof PIXI.DisplayObject) {
|
||||
this.map.image.addChild(elem)
|
||||
this.elements.push(elem)
|
||||
} else {
|
||||
console.error('Element need to be of type PIXI.DisplayObject.', elem)
|
||||
}
|
||||
}
|
||||
|
||||
transformed(e) {
|
||||
this.mapview.transformed(this.map)
|
||||
this.transformHandler.call(this)
|
||||
@@ -294,18 +220,39 @@ export class MapLayer extends GeoLayer {
|
||||
return mapLayerClone
|
||||
}
|
||||
|
||||
/**
|
||||
* Changes the map to the specified one, keeping the position and the zoom of the old map.
|
||||
*
|
||||
* @public
|
||||
* @param {GeoMap} map
|
||||
* @memberof MapLayer
|
||||
*/
|
||||
changeMap(
|
||||
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.
|
||||
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.*/
|
||||
) {
|
||||
let oldMap = map
|
||||
this._map = map
|
||||
if (map instanceof GeoMap) {
|
||||
let oldMap = this.map
|
||||
if (oldMap) oldMap.unload()
|
||||
|
||||
if (oldMap) oldMap.unload()
|
||||
map.load()
|
||||
this._map = map
|
||||
|
||||
this.changeHandler.call(this, map, oldMap)
|
||||
this.placeMap(map)
|
||||
this.map.load()
|
||||
this.scatterContainer.addChild(this.map.image)
|
||||
|
||||
map.image.addChild(this.displayObject)
|
||||
this.mapview.update(this.map)
|
||||
|
||||
// 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)
|
||||
this.map.onTransform.add(this.transformed.bind(this))
|
||||
|
||||
} else {
|
||||
console.error("Could not set map, it's not of type GeoMap.", map)
|
||||
}
|
||||
|
||||
/*Logging.log(`Map change: ${key}`)
|
||||
|
||||
@@ -372,8 +319,6 @@ export class MapLayer extends GeoLayer {
|
||||
get mapLayer() {
|
||||
return this
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
MapLayer.idx = 0
|
||||
|
||||
Reference in New Issue
Block a user