UNPKG

thematic-earth

Version:

HTML-based, whole-Earth thematic maps using locally hosted data layers

2 lines 3.31 kB
/* Copyright (c) 2023 Read Write Tools. Legal use subject to the Thematic Earth Software License Agreement. */ import BaseFeature from'./base-feature.class.js';import ProjectedPoint from'../projection/projected-point.class.js';import BoundingBox from'../graphics/bounding-box.class.js';import*as PointGraphics from'../graphics/point-graphics.js';import FT from'../enum/feature-type.enum.js';import RS from'../enum/rendering-state.enum.js';import expect from'../dev/expect.js';const degreesToRadians=Math.PI/180;export default class PointFeature extends BaseFeature{constructor(){super(),this.discretePoint=new ProjectedPoint(0,0),this.mouseEpsilon=3}get featureType(){return FT.POINT}setPoint(e){expect(e,'ProjectedPoint'),this.discretePoint=e}computeFeatureStyle(e,t,i,s,r,n){if(expect(e,'RenderClock'),expect(t,'Visualizer'),expect(i,'String'),expect(s,'String'),expect(r,'Number'),expect(n,'Number'),0==this.featureIsOnNearSide(e.renderingState))return;if(0==this.featureIsOnCanvas(e.renderingState))return;let a=t.computeStyle('point',i,s,this.isSelected,this.featureName,this.kvPairs,r);expect(a,'CanvasParams'),this.setCanvasParamsPerLayerId(n,a);var o=a.getSymbolOverallDiameter('')*a.scaleSymbolsCoefficient()/2;this.mouseEpsilon=Math.max(3,o)}runCourtesyValidator(e,t,i,s,r){e.runCourtesyValidator(FT.POINT,t,i,this.featureName,this.kvPairs,s)}toGeoCoords(e,t){t.toPhiLambda(this.discretePoint)}toPlane(e,t){expect(e,'RenderClock'),expect(t,'OrthographicProjection'),this.pointsOnNearSide=0,this.pointsOnFarSide=0;let i=this.discretePoint;if(t.toEastingNorthing(i),i.isOnNearSide)this.pointsOnNearSide++;else if(this.pointsOnFarSide++,e.renderingState==RS.SKETCHING)return}toPixels(e,t){expect(e,'RenderClock'),expect(t,'CartesianTransformation'),0!=this.featureIsOnNearSide(e.renderingState)&&t.toEarthXY(this.discretePoint,!0,!0,!0)}toViewportCanvas(e,t){if(expect(e,'RenderClock'),expect(t,'Viewport'),0==this.featureIsOnNearSide(e.renderingState))return;this.pointsOnCanvas=0,this.pointsOffCanvas=0;let i=this.discretePoint;t.toCanvasXY(i),i.isOnNearSide&&(i.isOnCanvas?this.pointsOnCanvas++:this.pointsOffCanvas++)}drawFeature(e,t,i){if(expect(e,'RenderClock'),expect(t,'Earth'),expect(i,'Layer'),0==this.featureIsOnNearSide(e.renderingState))return;if(0==this.featureIsOnCanvas(e.renderingState))return;let s=this.getCanvasParamsPerLayerId(i.layerId);if(0==this.hasSomethingToDraw(s))return;if(0==s.displaySymbols())return;var r=t.canvas.getContext('2d');PointGraphics.draw(r,'',s,this.discretePoint),e.renderingState==RS.PAINTING&&i.isLabelable()&&s.displayLabels()&&s.wantsLabel()&&''!=s.getLabelText(this.kvPairs)&&t.addToLabelEngineQueue(i.layerId,i.spatialId,this.featureId,FT.POINT)}isPointerAtPoint(e,t){if(0==this.discretePoint.isOnNearSide)return!1;var i=this.discretePoint.canvasX,s=this.discretePoint.canvasY;return e-this.mouseEpsilon<i&&i<e+this.mouseEpsilon&&t-this.mouseEpsilon<s&&s<t+this.mouseEpsilon}roughAndReadyPoint(){return{latitude:this.discretePoint.latitude,longitude:this.discretePoint.longitude}}getFeatureBoundingBox(e){if(expect(e,'Number'),this.discretePoint.isOnCanvas){var t=this.discretePoint.canvasX-e,i=this.discretePoint.canvasX+e,s=this.discretePoint.canvasY-e,r=this.discretePoint.canvasY+e;return new BoundingBox(t,i,s,r)}return new BoundingBox(0,0,0,0)}}