Removed PIXIUtils from geographics.
This commit is contained in:
@@ -2,6 +2,7 @@ import { Points } from '../../utils.js'
|
||||
import { EventHandler } from './utils.js'
|
||||
import { FlagPolygon } from '../graphics/label.js'
|
||||
import { DeepZoomMap } from './map.js'
|
||||
import { PIXIUtils } from '../../../../js/pixi/utils.js'
|
||||
|
||||
/**
|
||||
* GeoGraphics are graphical objects, that does not store the graphics information
|
||||
@@ -441,15 +442,12 @@ export class GeoShape extends GeoGraphics {
|
||||
*/
|
||||
_drawShape(polygon, hole = []) {
|
||||
// We save the fill specified in the onDraw event handler.
|
||||
//
|
||||
// Consider: Maybe it would be a good idea to add a 'onHoleDraw'
|
||||
// callback to make the hole customizable. Maybe you want
|
||||
// to fill it with a different color or an mediocre alpha value.
|
||||
// then feel free to implement it.
|
||||
let { fill, alpha } = PIXIUtils.saveFill(this.graphics)
|
||||
|
||||
/**
|
||||
* This may seem redundant, but it's required
|
||||
* a) Draw the hole with a polygon.
|
||||
*
|
||||
* This may seem redundant to (c), but it's required (in this order(!))
|
||||
* to make the hole clickable.
|
||||
*
|
||||
* It was a bit confusing, so I made a CodePen
|
||||
@@ -460,9 +458,15 @@ export class GeoShape extends GeoGraphics {
|
||||
this.graphics.drawPolygon(hole)
|
||||
}
|
||||
|
||||
/**
|
||||
* b) Draw the shape.
|
||||
*/
|
||||
this.graphics.beginFill(fill, alpha)
|
||||
this.graphics.drawPolygon(polygon)
|
||||
|
||||
/**
|
||||
* c) Add the hole.
|
||||
*/
|
||||
if (hole.length > 0) {
|
||||
this.graphics.beginHole()
|
||||
this.graphics.drawPolygon(hole)
|
||||
@@ -524,6 +528,14 @@ class GeoMultiGraphics extends GeoGraphics {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @export
|
||||
* @class GeoText
|
||||
* @extends {GeoPoint}
|
||||
*/
|
||||
export class GeoText extends GeoPoint {
|
||||
constructor(coordinates, text, opts) {
|
||||
super(coordinates, opts)
|
||||
@@ -531,14 +543,6 @@ export class GeoText extends GeoPoint {
|
||||
this.textStyle = Object.assign(new PIXI.TextStyle(), opts.textStyle)
|
||||
this._text = new PIXI.Text(text, this.textStyle)
|
||||
|
||||
//TODO: Make this more generic:
|
||||
// We have 8 layers (12-20) for each map so this temporarily works fine.
|
||||
// Outsource it to the map class.
|
||||
//let textScale = Math.pow(2, 7)
|
||||
|
||||
// let textScale = 5
|
||||
// this.text.scale.set(1 / textScale, 1 / textScale)
|
||||
|
||||
switch (this.align) {
|
||||
case 'left':
|
||||
break
|
||||
@@ -715,27 +719,3 @@ export class GeoMultiShape extends GeoShape {
|
||||
}
|
||||
}
|
||||
|
||||
class PIXIUtils {
|
||||
/*
|
||||
* Transform a pixi text to it's actual screensize,
|
||||
* ignoring it's local transforms
|
||||
*/
|
||||
static toScreenFontSize(pixiText, fontSize = null) {
|
||||
pixiText._recursivePostUpdateTransform()
|
||||
|
||||
let normalizedScale = {
|
||||
x: pixiText.scale.x / pixiText.transform.worldTransform.a,
|
||||
y: pixiText.scale.x / pixiText.transform.worldTransform.d
|
||||
}
|
||||
|
||||
pixiText.scale = { x: normalizedScale.x, y: normalizedScale.y }
|
||||
if (fontSize) pixiText.style.fontSize = fontSize
|
||||
}
|
||||
|
||||
static saveFill(graphics) {
|
||||
return {
|
||||
fill: graphics.fill.color,
|
||||
alpha: graphics.fill.alpha
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user