thematic-earth
Version:
HTML-based, whole-Earth thematic maps using locally hosted data layers
2 lines • 1.45 kB
JavaScript
/* Copyright (c) 2023 Read Write Tools. Legal use subject to the Thematic Earth Software License Agreement. */
import LabelPosition from'../enum/label-position.enum.js';import expect from'../dev/expect.js';import terminal from'../dev/terminal.js';export default class LabelLocation{constructor(e,i,a,t){expect(i,'LabelPoint'),expect(a,'Number'),expect(t,'BoundingBox'),this.labelPosition=e,this.x=0,this.y=0,this.width=0,this.height=0,this.initialize(e,i,a,t),Object.seal(this)}initialize(e,i,a,t){switch(expect(e,'String'),expect(i,'LabelPoint'),expect(a,'Number'),expect(t,'BoundingBox'),e){case LabelPosition.NW:case LabelPosition.SW:case LabelPosition.NE:case LabelPosition.SE:a*=.7071}var s=0,o=0;switch(e){case LabelPosition.NW:case LabelPosition.W:case LabelPosition.SW:s=i.canvasX-t.width-a;break;case LabelPosition.N:case LabelPosition.C:case LabelPosition.S:s=i.canvasX-.5*t.width;break;case LabelPosition.NE:case LabelPosition.E:case LabelPosition.SE:s=i.canvasX+a;break;default:terminal.abnormal(`Unrecognized LabelPosition ${e}`)}o=0;switch(e){case LabelPosition.NW:case LabelPosition.N:case LabelPosition.NE:o=i.canvasY-t.height-a;break;case LabelPosition.W:case LabelPosition.C:case LabelPosition.E:o=i.canvasY-.5*t.height;break;case LabelPosition.SW:case LabelPosition.S:case LabelPosition.SE:o=i.canvasY+a;break;default:terminal.abnormal(`Unrecognized LabelPosition ${e}`)}this.x=s,this.y=o,this.width=t.width,this.height=t.height}}