UNPKG

thematic-earth

Version:

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

2 lines 2.51 kB
/* Copyright (c) 2023 Read Write Tools. Legal use subject to the Thematic Earth Software License Agreement. */ import*as MapScale from'../projection/map-scale.js';export default class CartesianTransformation{constructor(t,a,s,e,r){this.thematicEarthElement=t,this.signal=this.thematicEarthElement.signal,this.earth=a,this.translate={},this.translate.a=parseInt(s),this.translate.b=parseInt(e),this.mapScale=r,this.multiplier=1/r,this.allPointsNeedTransformation=!0,Object.seal(this)}reflectValues(){this.signal.broadcast('carte/translationEastWest',this.translate.a),this.signal.broadcast('carte/translationNorthSouth',this.translate.b),this.signal.broadcast('carte/mapScale',this.mapScale)}setTranslation(t,a){this.translate.a=parseInt(t),this.translate.b=parseInt(a),this.allPointsNeedTransformation=!0,this.signal.broadcast('carte/translationEastWest',this.translate.a),this.signal.broadcast('carte/translationNorthSouth',this.translate.b)}setTranslationEastWest(t){this.translate.a=parseInt(t),this.allPointsNeedTransformation=!0,this.signal.broadcast('carte/translationEastWest',this.translate.a)}setTranslationNorthSouth(t){this.translate.b=parseInt(t),this.allPointsNeedTransformation=!0,this.signal.broadcast('carte/translationNorthSouth',this.translate.b)}getTranslation(){return this.translate}getTranslationEastWest(){return this.translate.a}getTranslationNorthSouth(){return this.translate.b}setMultiplier(t){(t=parseFloat(t))<0||isNaN(t)||(this.multiplier=t,this.mapScale=1/t,this.allPointsNeedTransformation=!0,this.signal.broadcast('carte/mapScale',this.mapScale))}getMultiplier(){return this.multiplier}setMapScale(t){return t=parseInt(t,10),isNaN(t)?MapScale.INITIAL_MAP_SCALE:t<MapScale.MIN_MAP_SCALE?MapScale.MIN_MAP_SCALE:t>MapScale.MAX_MAP_SCALE?MapScale.MAX_MAP_SCALE:(this.mapScale=t,this.multiplier=1/t,this.allPointsNeedTransformation=!0,void this.signal.broadcast('carte/mapScale',this.mapScale))}getMapScale(){return this.mapScale}toEarthXY(t,a,s,e){var r=t.easting,i=t.northing;t.projectedTheta=Math.atan2(i,r),t.projectedTheta<0&&(t.projectedTheta=2*Math.PI+t.projectedTheta),s&&(r+=this.translate.a,i+=this.translate.b),e&&(r*=this.multiplier,i*=this.multiplier),t.earthX=Math.round(r),t.earthY=Math.round(i)}metersPerPixel(){return Math.floor(1/this.multiplier)}kilometersPerPixel(){return(this.metersPerPixel()/1e3).toFixed(3)}inverseTransformation(t){var a=t.earthX,s=t.earthY;a/=this.multiplier,s/=this.multiplier,a-=this.translate.a,s-=this.translate.b,t.easting=a,t.northing=s}}