UNPKG

thematic-earth

Version:

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

2 lines 2.69 kB
/* Copyright (c) 2023 Read Write Tools. Legal use subject to the Thematic Earth Software License Agreement. */ import expect from'../dev/expect.js';import vartype from'../dev/vartype.js';const Static={nextSpatialFileId:0};Object.seal(Static);export default class BaseSpatialFile{constructor(e){this.thematicEarthElement=e,this.spatialId=Static.nextSpatialFileId++,this.featureLookupMap=new Map,this.localPointsNeedGeoCoords=!1,this.localPointsNeedProjection=!1,this.localPointsNeedTransformation=!1,this.localPointsNeedPlacement=!1}addFeatureToLookupMap(e){expect(e,['PointFeature','LineFeature','PolygonFeature','LabelFeature','GeneralFeature','GreatCircleFeature','HemisphereFeature']),this.featureLookupMap.set(e.featureId,e)}removeFeatureFromLookupMap(e){expect(e,'Number'),this.featureLookupMap.delete(e)}changeVisibility(e){1==e&&(this.localPointsNeedGeoCoords=!0,this.localPointsNeedProjection=!0,this.localPointsNeedTransformation=!0,this.localPointsNeedPlacement=!0),this.thematicEarthElement.earth.invalidateCanvas()}recomputeStyles(e,t,o,a){expect(e,'RenderClock'),expect(t,'Visualizer'),expect(o,'Layer'),expect(a,'Function'),0==t.allFeaturesNeedRestyling&&0==o.layerNeedsRestyling||(a(),e.isRenderTimeAvailable()&&(o.layerNeedsRestyling=!1))}runCourtesyValidator(e){expect(e,'Function'),e()}rotation(e,t,o){expect(e,'RenderClock'),expect(t,'GeocentricCoordinates'),expect(o,'Function'),0==t.allPointsNeedGeoCoords&&0==this.localPointsNeedGeoCoords||(o(),this.localPointsNeedGeoCoords=!1,this.localPointsNeedProjection=!0)}projection(e,t,o){expect(e,'RenderClock'),expect(t,'OrthographicProjection'),expect(o,'Function'),0==t.allPointsNeedProjection&&0==this.localPointsNeedProjection||(o(),this.localPointsNeedProjection=!1,this.localPointsNeedTransformation=!0)}transformation(e,t,o){expect(e,'RenderClock'),expect(t,'CartesianTransformation'),expect(o,'Function'),0==t.allPointsNeedTransformation&&0==this.localPointsNeedTransformation||(o(),this.localPointsNeedTransformation=!1,this.localPointsNeedPlacement=!0)}placement(e,t,o){expect(e,'RenderClock'),expect(t,'Viewport'),expect(o,'Function'),0==t.allPointsNeedPlacement&&0==this.localPointsNeedPlacement||(o(),this.localPointsNeedPlacement=!1)}drawLayer(e,t){expect(e,'RenderClock'),expect(t,'Function'),t()}discoverFeatures(e,t,o){return null}extendSpatialData(e,t,o){if(expect(e,'String'),expect(t,'String'),expect(o,'Array'),'Array'!=vartype(o))return 0;var a=0;for(let n=0;n<o.length;n++){var i=o[n];if('Object'!=vartype(i))return 0;if(0!=i.hasOwnProperty(t)){var r=i[t];for(let[t,o]of this.featureLookupMap.entries()){if(0!=o.kvPairs.hasOwnProperty(e))r==o.kvPairs[e]&&(a++,o.extendSpatialData(i))}}}return a}}