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
+110 -62
View File
@@ -17203,22 +17203,21 @@
this.debugGraphics.endFill();
}
// if (this.cover) {
// // The reference to the element handler needs to be stored,
// // that we can remove it later on.
// this._applyInitialCover = this._applyInitialCover.bind(this)
// }
if (this.cover) {
// The reference to the element handler needs to be stored,
// that we can remove it later on.
this._applyInitialCover = this._applyInitialCover.bind(this);
this.displayObject.on('added', this._applyInitialCover);
this._applyInitialCover();
}
}
// _applyInitialCover() {
// if (this.debug) console.log('ApplyInitialCover: ', parent)
_applyInitialCover() {
if (this.debug) console.log('ApplyInitialCover: ', parent);
// if (this.displayObject.parent)
// this.forceCover(this.displayObject.parent.width, this.displayObject.parent.height)
// else {
// this.displayObject.on('added', eventHandler)
// }
// }
if (this.displayObject.parent)
this.forceCover(this.displayObject.parent.width, this.displayObject.parent.height);
}
get boundaries() {
if (this._boundaries) return this._boundaries
@@ -17341,8 +17340,6 @@
if (this.cover) {
let minCoverScale = this.calculateMinCoverScale(this.parent.width, this.parent.height);
if (scale < minCoverScale) {
console.error('USE MIN COVER SCALE', minCoverScale, scale);
scale = minCoverScale;
}
}
@@ -17458,7 +17455,7 @@
this.projection = projection;
if (this.clip) {
if (this.opts.clip) {
let _cmin = this.projection.forward(this.opts.clip.min);
let _cmax = this.projection.forward(this.opts.clip.max);
@@ -17481,7 +17478,7 @@
}
toCoordinates(point) {
if (this.clip) {
if (this.opts.clip) {
let min = this.clipExt.point.min;
let max = this.clipExt.point.max;
@@ -17534,24 +17531,28 @@
}
get clip() {
return this.opts.clip
let unclipped = {
min: { x: 0, y: 0 },
max: { x: 1, y: 1 }
};
return this.opts.clip ? this.opts.clip : unclipped
}
/**
* Bounds to pixel transforms some bounds in form of {min:{x:minLat, y:minLng},max:{x:maxLat, y:maxLng}}
* to pixel coordinates.
*
* @param {*} bounds
*/
boundsToPixel(bounds) {
let min = this.toPixel(bounds.min);
let max = this.toPixel(bounds.max);
getBoundaries() {
// let min = this.toPixel(bounds.min)
// let max = this.toPixel(bounds.max)
// Y values needs to be swapped, as PIXI has it's origin
// in the top-left corner and a regular map in the bottom-left corner.
let boundaries = {
min: { x: min.x, y: max.y },
max: { x: max.x, y: min.y }
min: { x: 0, y: 0 },
max: { x: 1, y: 1 }
};
return boundaries
@@ -17613,7 +17614,7 @@
* @memberof Projection
*/
backward(point) {
console.error('You must override the backward fuction in ' + this.name + '.');
console.error('You must override the backward function in ' + this.name + '.');
}
toString() {
@@ -17625,7 +17626,7 @@
}
get maxViewport() {
return { min: new PIXI.Point(-90, -180), max: new PIXI.Point(90, 180) }
return { min: new PIXI.Point(0, 0), max: new PIXI.Point(1, 1) }
}
}
@@ -17719,10 +17720,12 @@
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;
//TODO discuss if this is required here.
// Those are just scatter options and the information
// is redundant in the map class and the scatter.
@@ -17800,10 +17803,24 @@
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.
*
@@ -17827,12 +17844,7 @@
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,
@@ -17851,17 +17863,6 @@
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
// }
// })
}
/**
@@ -17957,8 +17958,8 @@
console.error('Overload get distance in subclass.');
}
set alpha(value) {
console.error('Overload get alpha in subclass.');
get alpha() {
return this._alpha
}
/**
@@ -17988,6 +17989,10 @@
return coords
}
removeFrame() {
this.frame = null;
}
setFrame(frame) {
if (this.debug) console.log('Set Frame: ', frame);
this.frame = frame;
@@ -18078,10 +18083,6 @@
return null
}
/**
*
*/
/**
* Validates if the map data contains valid data
* for creating the maps.
@@ -18414,6 +18415,7 @@
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;
@@ -18759,8 +18761,8 @@
_adjustLng(lng, inv = false) {
let moved = inv ? lng + this.lng0 : lng - this.lng0;
if (moved < -180) moved += 360;
if (moved > 180) moved -= 360;
// if (moved < -180) moved += 360
// if (moved > 180) moved -= 360
return moved
}
@@ -18781,12 +18783,20 @@
return { low: minIndex, high: maxIndex, ratio, sign }
}
toString() {
return
}
get name() {
return 'Robinson Projection'
}
get maxViewport() {
let min = new PIXI.Point(-90, -180);
let max = new PIXI.Point(90, 180);
max.x += this.lng0;
min.x += this.lng0;
console.log({ min, max });
return { min, max }
}
}
/**
@@ -19664,6 +19674,7 @@
add(key, map) {
if (this.maps[key] != null) consol.warn('Key already in mapList. The existing key was overwritten.');
if (this.active == null) this.active = key;
map.name = key;
this.maps[key] = map;
}
@@ -19680,6 +19691,13 @@
console.log(keys, idx, next);
return next
}
cleanup() {
for (let key in this.maps) {
let map = this.maps[key];
map.remove();
}
}
}
//import { GeoGraphics } from "../pixi/geographics.js"
@@ -19903,9 +19921,11 @@
mapList,
scatterContainer,
displayObject,
{ onTransform = null, onChange = null, focus = null, zoom = null, viewport = null } = {}
{ onTransform = null, onChange = null, focus = null, zoom = null, viewport = null, name = null } = {}
) {
super(displayObject);
super(displayObject, {
name
});
this.transformHandler = new EventHandler('onTransform', {
listeners: onTransform
@@ -19971,6 +19991,17 @@
return mapLayerClone
}
/**
* Helper function to quickly display the next map.
* Order is defined by the key ordering of the maplist.
*
* @memberof MapLayer
*/
next() {
let nextMap = this.mapList.next();
this.changeMap(nextMap);
}
/**
* Changes the map to the specified one, keeping the position and the zoom of the old map.
*
@@ -20082,6 +20113,10 @@
get mapLayer() {
return this
}
cleanup() {
this.mapList.cleanup();
}
}
MapLayer.idx = 0;
@@ -20167,11 +20202,22 @@
this._setupKeyboardUtils();
}
logMapBoundaries() {
let map = this.mapLayer.map;
let boundaries = {
min: this.mapLayer.mapview.coordinatesFromWindowPoint(map, { x: 0, y: 0 }),
max: this.mapLayer.mapview.coordinatesFromWindowPoint(map, { x: 0, y: 0 })
};
console.log(JSON.stringify(boundaries));
}
_setupMapLayer() {
this.mapContainer = new PIXI.Container();
console.log(this.mapList);
this.mapLayer = new MapLayer(this.mapList, this.scene, this.mapContainer, {
name: 'Map Layer',
name: 'Root Map Layer',
focus: this.focus,
zoom: this.zoom
});
@@ -21123,12 +21169,11 @@
return false
},
informationCallback = null,
adjustItems = null
adjustItems = null,
cleanupItems = null
} = {}) {
const name = this.name[0].toUpperCase() + this.name.slice(1).toLowerCase() + ' Overlay';
let geoLayer = new GeoLayer(new PIXI.Container(), { name });
console.log(this);
geoLayer.visibility = this.zoomVisibility;
if (this.rescale) geoLayer.rescale = this.rescale;
@@ -21141,6 +21186,9 @@
item.overlay = this;
let graphics = this.createItem(item, informationCallback);
geoLayer.addChild(graphics);
if (cleanupItems) {
cleanupItems(item);
}
}
});
return geoLayer