Ongoing cleanup and refactoring of maps.

This commit is contained in:
2019-11-25 18:04:11 +01:00
parent 88048f14ec
commit 5305561619
16 changed files with 462 additions and 158 deletions
+26 -31
View File
@@ -53,7 +53,7 @@ export class GeoMap {
this.onLoad = new EventHandler('loaded', { listeners: onLoad })
this.onTransform = new EventHandler('transform', { listeners: onTransform })
this.alpha = alpha
this._alpha = alpha
this.cover = cover
this.debug = debug
@@ -134,10 +134,24 @@ export class GeoMap {
if (this.image.parent) {
this.image.parent.removeChild(this.image)
}
this.image.scatter = null
if (this.scatter) {
this.scatter.killAnimation()
this.image.scatter = null
}
}
}
remove() {
if (this.image) this.image.mask = null
this.removeFrame()
this.onTransform.empty()
this.onLoad.empty()
this.unload()
}
/**
* Is called when the scatter object is transformed.
*
@@ -161,12 +175,7 @@ export class GeoMap {
this.image = image
if (frame) this.setFrame(frame)
let min = this.mapdata.toPixel(this.viewport.min)
let max = this.mapdata.toPixel(this.viewport.max)
let boundaries = {
min: { x: min.x, y: max.y },
max: { x: max.x, y: min.y }
}
let boundaries = this.mapdata.getBoundaries()
let scatterOpts = Object.assign({
cover: this.cover,
@@ -185,17 +194,6 @@ export class GeoMap {
this.image.scatter = scatter == null ? this.scatter : scatter
this.onLoad.call(this)
// Object.assign(this.image, {
// set scatter (value) {
// console.trace("Scatter set.")
// this._scatter = value
// },
// get scatter (){
// console.trace("Get Scatter.")
// return this._scatter
// }
// })
}
/**
@@ -291,8 +289,8 @@ export class GeoMap {
console.error('Overload get distance in subclass.')
}
set alpha(value) {
console.error('Overload get alpha in subclass.')
get alpha() {
return this._alpha
}
/**
@@ -322,6 +320,10 @@ export class GeoMap {
return coords
}
removeFrame() {
this.frame = null
}
setFrame(frame) {
if (this.debug) console.log('Set Frame: ', frame)
this.frame = frame
@@ -383,7 +385,6 @@ export class GeoMap {
let maps = {}
if (GeoMap._validateJson(json, error)) {
for (let [mapname, data] of Object.entries(json)) {
console.log(data.tiles, data.tiles.path, root + data.tiles.path)
data.tiles.path = root + data.tiles.path
maps[mapname] = GeoMap._createMap(data)
maps[mapname].name = mapname
@@ -412,10 +413,6 @@ export class GeoMap {
return null
}
/**
*
*/
/**
* Validates if the map data contains valid data
* for creating the maps.
@@ -525,7 +522,6 @@ export class DeepZoomMap extends GeoMap {
* @param {object} opts - Additional options to specify the behaviour of the deep zoom image.
*/
constructor(mapdata, tilesConfig, opts = {}) {
if (!tilesConfig.app) console.error('App was not set in the tilesConfig.')
opts = Object.assign(
{
maxScale: Math.min(tilesConfig.width, tilesConfig.height) / tilesConfig.tileSize,
@@ -545,9 +541,7 @@ export class DeepZoomMap extends GeoMap {
if (!(this.mapdata instanceof MapData)) {
console.error('Use the MapData object for creating maps!')
} else {
if (this.mapdata instanceof DeepZoomMapData) {
if (!this.mapdata.app) console.error('No app was set on the mapdata!')
} else {
if (!(this.mapdata instanceof DeepZoomMapData)) {
console.error('Use the DeepZoomMapData object.')
}
}
@@ -559,6 +553,7 @@ export class DeepZoomMap extends GeoMap {
* @private
*/
load(container = null, scatter = null) {
if (!this.mapdata.app) console.error('App was not set in the mapdata.')
this.info = new DeepZoomInfo(this.tilesConfig)
let image = new DeepZoomImage(this.info, {
app: this.mapdata.app,
@@ -569,7 +564,6 @@ export class DeepZoomMap extends GeoMap {
super.load(image, container, scatter)
console.log('LOADED: ', this.image)
if (this.debug) console.log('Loaded image: ', image, 'With options: ', this.info)
}
@@ -748,6 +742,7 @@ DeepZoomMap.tintcolor = 0
export class ImageMap extends GeoMap {
constructor(sprite, mapdata, opts = {}) {
super(mapdata, opts)
if (this.debug) console.log('Construct Image Map', sprite, mapdata, opts)
this.sprite = sprite