UNPKG

thematic-earth

Version:

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

2 lines 5.38 kB
/* Copyright (c) 2023 Read Write Tools. Legal use subject to the Thematic Earth Software License Agreement. */ import BasePackage from'../packages/base-package.class.js';import*as PackageGrammar from'../packages/package-grammar.js';import aver from'../dev/aver.js';import terminal from'../dev/terminal.js';export default class ParamPackage extends BasePackage{constructor(a,e){super(a,e),this.params={}}parseLine(a){var e=a.indexOf(':');if(-1!=e){var t=a.substr(0,e),i=a.substr(e+1);null!=t&&null!=i&&(t=t.trim(),','==(i=i.trim()).charAt(i.length-1)&&(i=i.substr(0,i.length-1)),i.length>2&&i.charAt(0)==i.charAt(i.length-1)&&('\''!=i.charAt(0)&&'"'!=i.charAt(0)||(i=i.substr(1,i.length-2))),this.params[t]=i)}}async processEntry(){switch(this.entryName){case'Packages':await this.packageHandler.processDeclaredPackages(this.params);break;case'MenuOptions':await this.processMenuOptions();break;case'PanelOptions':await this.processPanelOptions();break;case'SpatialOptions':var a=await this.thematicEarthElement.addSpatialData(this.params);this.packageHandler.spatialDataId=a;break;case'Layer':var e=await this.thematicEarthElement.addLayer(this.packageHandler.spatialDataId,this.params);this.packageHandler.layerId=e;break;case'Legend':this.params.layerId=this.packageHandler.layerId,this.thematicEarthElement.addLegend(this.params);break;case'Citation':this.thematicEarthElement.addMapCitation(this.params);break;case'Metadata':this.thematicEarthElement.addMetadata(this.params);break;case'Startup':if(this.params.initialLongitude&&this.thematicEarthElement.setTangentLongitude(this.params.initialLongitude),this.params.initialLatitude&&this.thematicEarthElement.setTangentLatitude(this.params.initialLatitude),this.params.initialGeolocation&&this.thematicEarthElement.setInitialGeolocation(this.params.initialGeolocation),this.params.mapScale&&this.thematicEarthElement.setMapScale(this.params.mapScale),this.params.timezone&&this.thematicEarthElement.changeTimezoneOffset(this.params.timezone),this.params.rotationTimeLapse||this.params.rotationIncrement){var t=this.params.rotationTimeLapse??1,i=this.params.rotationIncrement??1;this.thematicEarthElement.animateLongitude(t,i)}break;default:terminal.logic(`Unhandled packageName ${this.packageName}`)}}summarizePackage(){return this.params}validateParams(){var a=PackageGrammar.validParams[this.entryName];for(let e of Object.keys(this.params))0==a.includes(e)&&terminal.warning(`The package parameter "${this.entryName}.${e}" (${this.packageHandler.url}) is not recognized.\n Valid parameters are: ${a.join(',')}`)}validateSpatialOptions(){this.params.spatialDataType?1!=PackageGrammar.spatialDataTypes.includes(this.params.spatialDataType)&&terminal.warning(`The value "${this.params.spatialDataType}" for package parameter "SpatialOptions.spatialDataType" (${this.packageHandler.url}) is not recognized.\nValid values are: ${PackageGrammar.spatialDataTypes.join(',')}`):terminal.warning(`The package parameter "SpatialOptions.spatialDataType" (${this.packageHandler.url}) is missing or misspelled.`)}async processMenuOptions(){aver('MenuOptions'==this.entryName);var a=this.params,e=this.thematicEarthElement.menu,t=this.thematicEarthElement.menu.rwtDockablePanels;await t.waitOnLoading().then((async()=>{if(a.panels){var i=a.panels.split(' ');for(let a=0;a<i.length;a++){var s=i[a].trim();0==PackageGrammar.validPanelIds.includes(s)&&terminal.warning(`The value "${s}" within "MenuOptions.panels" (${this.packageHandler.url}) is not valid.\nValid values are: ${PackageGrammar.validPanelIds.join(',')}`)}t.style.display='none',await e.configureDockablePanels(a.panels)}if(a.initialPlacement)switch(a.initialPlacement){case'bottom-left':case'bottom-right':case'top-left':case'top-right':t.setCorner(a.initialPlacement);break;default:terminal.warning(`The value "${a.initialPlacement}" for package parameter "MenuOptions.initialPlacement" (${this.packageHandler.url}) is not valid.\nValid values are: 'bottom-left','bottom-right','top-left','top-right'`)}a.titlebar&&t.setTitlebar(a.titlebar),a.initialState&&('open'==a.initialState?t.openToolbar():'closed'==a.initialState?t.closeToolbar():terminal.warning(`The value "${a.initialState}" for package parameter "MenuOptions.initialState" (${this.packageHandler.url}) is not valid.\nValid values are: open, closed`)),a.shortcutKey&&(a.shortcutKey.length>0&&'F'==a.shortcutKey.charAt(0)?t.shortcutKey=a.shortcutKey:terminal.warning(`The value "${a.shortcutKey}" for package parameter "MenuOptions.shortcutKey" (${this.packageHandler.url}) is not valid.\nValid values are: "F1" through "F12"`)),1==e.hasPanels&&(t.style.display='block')}))}processPanelOptions(){aver('PanelOptions'==this.entryName);var a=this.params,e=this.thematicEarthElement.menu.rwtDockablePanels,t=a.panelId;null!=t&&(0==PackageGrammar.validPanelIds.includes(t)&&terminal.warning(`The value "${t}" within "PanelsOptions.panelId" (${this.packageHandler.url}) is not valid.\nValid values are: ${PackageGrammar.validPanelIds.join(',')}`),a.detachedX&&e.presetDetachedX(t,a.detachedX),a.detachedY&&e.presetDetachedY(t,a.detachedY),a.detachedWidth&&e.presetDetachedWidth(t,a.detachedWidth),a.detachedHeight&&e.presetDetachedHeight(t,a.detachedHeight),a.initialState&&('open'==a.initialState?e.expandPanel(t):e.collapsePanel(t)),a.initialMode&&('detached'==a.initialMode?e.detachPanel(t):e.attachPanel(t)))}}