@openglobus/og 0.24.0 → 0.24.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/@openglobus/js/Clock.d.ts +2 -2
- package/lib/@openglobus/js/Globe.d.ts +10 -5
- package/lib/@openglobus/js/LonLat.d.ts +2 -2
- package/lib/@openglobus/js/Object3d.d.ts +3 -2
- package/lib/@openglobus/js/Popup.d.ts +7 -4
- package/lib/@openglobus/js/astro/astro.d.ts +1 -1
- package/lib/@openglobus/js/astro/earth.d.ts +1 -1
- package/lib/@openglobus/js/bv/Box.d.ts +1 -1
- package/lib/@openglobus/js/camera/Camera.d.ts +7 -4
- package/lib/@openglobus/js/camera/Frustum.d.ts +2 -2
- package/lib/@openglobus/js/camera/PlanetCamera.d.ts +1 -1
- package/lib/@openglobus/js/control/Atmosphere.d.ts +3 -3
- package/lib/@openglobus/js/control/AtmosphereConfig.d.ts +2 -2
- package/lib/@openglobus/js/control/CameraLock.d.ts +3 -3
- package/lib/@openglobus/js/control/CompassButton.d.ts +1 -1
- package/lib/@openglobus/js/control/DebugInfo.d.ts +1 -1
- package/lib/@openglobus/js/control/EarthCoordinates.d.ts +2 -2
- package/lib/@openglobus/js/control/GeoImageDragControl.d.ts +2 -2
- package/lib/@openglobus/js/control/KeyboardNavigation.d.ts +1 -1
- package/lib/@openglobus/js/control/LayerAnimation.d.ts +2 -2
- package/lib/@openglobus/js/control/LayerSwitcher.d.ts +4 -2
- package/lib/@openglobus/js/control/Lighting.d.ts +2 -1
- package/lib/@openglobus/js/control/MouseNavigation.d.ts +3 -2
- package/lib/@openglobus/js/control/OldMouseNavigation.d.ts +3 -2
- package/lib/@openglobus/js/control/RulerSwitcher.d.ts +2 -1
- package/lib/@openglobus/js/control/ScaleControl.d.ts +2 -1
- package/lib/@openglobus/js/control/SegmentBoundVisualization.d.ts +2 -1
- package/lib/@openglobus/js/control/ShowFps.d.ts +2 -1
- package/lib/@openglobus/js/control/SimpleNavigation.d.ts +3 -2
- package/lib/@openglobus/js/control/SimpleSkyBackground.d.ts +2 -1
- package/lib/@openglobus/js/control/Sun.d.ts +2 -1
- package/lib/@openglobus/js/control/ToggleWireframe.d.ts +2 -1
- package/lib/@openglobus/js/control/TouchNavigation.d.ts +3 -2
- package/lib/@openglobus/js/control/ZoomControl.d.ts +2 -1
- package/lib/@openglobus/js/control/drawing/DrawingControl.d.ts +1 -1
- package/lib/@openglobus/js/control/drawing/LineStringDrawingScene.d.ts +1 -1
- package/lib/@openglobus/js/control/drawing/PolygonDrawingScene.d.ts +3 -3
- package/lib/@openglobus/js/control/elevationProfile/ElevationProfile.d.ts +1 -1
- package/lib/@openglobus/js/control/elevationProfile/ElevationProfileButtonsView.d.ts +3 -2
- package/lib/@openglobus/js/control/elevationProfile/ElevationProfileControl.d.ts +2 -2
- package/lib/@openglobus/js/control/elevationProfile/ElevationProfileLegend.d.ts +1 -1
- package/lib/@openglobus/js/control/elevationProfile/ElevationProfileScene.d.ts +2 -2
- package/lib/@openglobus/js/control/elevationProfile/ElevationProfileView.d.ts +6 -4
- package/lib/@openglobus/js/control/elevationProfile/PointListDialog.d.ts +1 -1
- package/lib/@openglobus/js/control/geoObjectEditor/ArrowEntity.d.ts +1 -1
- package/lib/@openglobus/js/control/geoObjectEditor/AxisTrackEntity.d.ts +1 -1
- package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditor.d.ts +1 -1
- package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditorDialog.d.ts +1 -1
- package/lib/@openglobus/js/control/geoObjectEditor/GeoObjectEditorScene.d.ts +2 -2
- package/lib/@openglobus/js/control/geoObjectEditor/MoveAxisEntity.d.ts +1 -1
- package/lib/@openglobus/js/control/geoObjectEditor/MovePlaneEntity.d.ts +1 -1
- package/lib/@openglobus/js/control/geoObjectEditor/RotateEntity.d.ts +1 -1
- package/lib/@openglobus/js/control/heightRuler/HeightRuler.d.ts +1 -1
- package/lib/@openglobus/js/control/heightRuler/HeightRulerScene.d.ts +1 -1
- package/lib/@openglobus/js/control/ruler/Ruler.d.ts +2 -1
- package/lib/@openglobus/js/control/ruler/RulerScene.d.ts +2 -2
- package/lib/@openglobus/js/control/selection/Selection.d.ts +2 -1
- package/lib/@openglobus/js/control/timeline/TimelineControl.d.ts +1 -1
- package/lib/@openglobus/js/control/timeline/TimelineModel.d.ts +1 -1
- package/lib/@openglobus/js/control/timeline/TimelineView.d.ts +4 -3
- package/lib/@openglobus/js/ellipsoid/Ellipsoid.d.ts +1 -1
- package/lib/@openglobus/js/entity/BaseBillboard.d.ts +6 -3
- package/lib/@openglobus/js/entity/BaseBillboardHandler.d.ts +2 -2
- package/lib/@openglobus/js/entity/Billboard.d.ts +3 -2
- package/lib/@openglobus/js/entity/Entity.d.ts +23 -12
- package/lib/@openglobus/js/entity/EntityCollection.d.ts +4 -3
- package/lib/@openglobus/js/entity/GeoObject.d.ts +2 -2
- package/lib/@openglobus/js/entity/Geometry.d.ts +4 -3
- package/lib/@openglobus/js/entity/GeometryHandler.d.ts +3 -2
- package/lib/@openglobus/js/entity/InstanceData.d.ts +2 -2
- package/lib/@openglobus/js/entity/Label.d.ts +4 -2
- package/lib/@openglobus/js/entity/LabelHandler.d.ts +1 -1
- package/lib/@openglobus/js/entity/PointCloud.d.ts +1 -1
- package/lib/@openglobus/js/entity/Polyline.d.ts +9 -7
- package/lib/@openglobus/js/entity/Ray.d.ts +4 -2
- package/lib/@openglobus/js/entity/RayHandler.d.ts +2 -2
- package/lib/@openglobus/js/entity/Strip.d.ts +5 -3
- package/lib/@openglobus/js/input/KeyboardHandler.d.ts +1 -1
- package/lib/@openglobus/js/layer/BaseGeoImage.d.ts +6 -5
- package/lib/@openglobus/js/layer/Bing.d.ts +2 -1
- package/lib/@openglobus/js/layer/CanvasTiles.d.ts +4 -3
- package/lib/@openglobus/js/layer/GeoImage.d.ts +2 -1
- package/lib/@openglobus/js/layer/GeoTexture2d.d.ts +3 -2
- package/lib/@openglobus/js/layer/GeoVideo.d.ts +2 -1
- package/lib/@openglobus/js/layer/KML.d.ts +5 -3
- package/lib/@openglobus/js/layer/Layer.d.ts +5 -4
- package/lib/@openglobus/js/layer/Material.d.ts +2 -2
- package/lib/@openglobus/js/layer/OpenStreetMap.d.ts +2 -1
- package/lib/@openglobus/js/layer/Vector.d.ts +9 -7
- package/lib/@openglobus/js/layer/WMS.d.ts +2 -1
- package/lib/@openglobus/js/layer/XYZ.d.ts +4 -3
- package/lib/@openglobus/js/math/Quat.d.ts +6 -1
- package/lib/@openglobus/js/math/Vec3.d.ts +3 -2
- package/lib/@openglobus/js/math/coder.d.ts +5 -3
- package/lib/@openglobus/js/math/index.d.ts +6 -3
- package/lib/@openglobus/js/math.d.ts +2 -2
- package/lib/@openglobus/js/quadTree/earth/EarthEntityCollectionNodeLonLat.d.ts +2 -1
- package/lib/@openglobus/js/quadTree/earth/EarthQuadTreeStrategy.d.ts +0 -2
- package/lib/@openglobus/js/quadTree/equi/EquiEntityCollectionNodeLonLat.d.ts +2 -1
- package/lib/@openglobus/js/renderer/Renderer.d.ts +5 -3
- package/lib/@openglobus/js/renderer/RendererEvents.d.ts +6 -3
- package/lib/@openglobus/js/scene/Axes.d.ts +1 -1
- package/lib/@openglobus/js/scene/Planet.d.ts +8 -6
- package/lib/@openglobus/js/scene/SkyBox.d.ts +1 -1
- package/lib/@openglobus/js/segment/Segment.d.ts +7 -5
- package/lib/@openglobus/js/segment/SegmentLonLat.d.ts +1 -1
- package/lib/@openglobus/js/segment/SegmentLonLatEqui.d.ts +1 -1
- package/lib/@openglobus/js/shaders/atmos.d.ts +1 -1
- package/lib/@openglobus/js/shaders/drawnode.d.ts +1 -1
- package/lib/@openglobus/js/terrain/BilTerrain.d.ts +3 -2
- package/lib/@openglobus/js/terrain/EmptyTerrain.d.ts +1 -1
- package/lib/@openglobus/js/terrain/GlobusRgbTerrain.d.ts +2 -1
- package/lib/@openglobus/js/terrain/GlobusTerrain.d.ts +5 -4
- package/lib/@openglobus/js/terrain/RgbTerrain.d.ts +3 -2
- package/lib/@openglobus/js/ui/Button.d.ts +3 -2
- package/lib/@openglobus/js/ui/ButtonGroup.d.ts +1 -1
- package/lib/@openglobus/js/ui/Checkbox.d.ts +3 -2
- package/lib/@openglobus/js/ui/Color.d.ts +3 -2
- package/lib/@openglobus/js/ui/Dialog.d.ts +3 -2
- package/lib/@openglobus/js/ui/Input.d.ts +3 -2
- package/lib/@openglobus/js/ui/Slider.d.ts +3 -2
- package/lib/@openglobus/js/ui/ToggleButton.d.ts +4 -3
- package/lib/@openglobus/js/ui/View.d.ts +1 -1
- package/lib/@openglobus/js/utils/FontAtlas.d.ts +1 -1
- package/lib/@openglobus/js/utils/GeoImageCreator.d.ts +1 -1
- package/lib/@openglobus/js/utils/Loader.d.ts +1 -1
- package/lib/@openglobus/js/utils/NormalMapCreator.d.ts +2 -1
- package/lib/@openglobus/js/utils/TerrainWorker.d.ts +1 -1
- package/lib/@openglobus/js/utils/TextureAtlas.d.ts +4 -2
- package/lib/@openglobus/js/utils/objParser.d.ts +1 -1
- package/lib/@openglobus/js/utils/shared.d.ts +5 -3
- package/lib/@openglobus/js/webgl/Framebuffer.d.ts +3 -2
- package/lib/@openglobus/js/webgl/Handler.d.ts +11 -7
- package/lib/@openglobus/js/webgl/Multisample.d.ts +2 -1
- package/lib/@openglobus/js/webgl/Program.d.ts +2 -2
- package/lib/@openglobus/js/webgl/ProgramController.d.ts +2 -1
- package/lib/@openglobus/js/webgl/variableHandlers.d.ts +1 -1
- package/lib/@openglobus/og.esm.js +1 -1
- package/lib/@openglobus/og.esm.js.map +1 -1
- package/lib/@openglobus/og.umd.js +1 -1
- package/lib/@openglobus/og.umd.js.map +1 -1
- package/lib/js/Clock.d.ts +2 -2
- package/lib/js/Globe.d.ts +10 -5
- package/lib/js/Globe.js +6 -2
- package/lib/js/LonLat.d.ts +2 -2
- package/lib/js/Object3d.d.ts +3 -2
- package/lib/js/Popup.d.ts +7 -4
- package/lib/js/astro/astro.d.ts +1 -1
- package/lib/js/astro/earth.d.ts +1 -1
- package/lib/js/bv/Box.d.ts +1 -1
- package/lib/js/camera/Camera.d.ts +7 -4
- package/lib/js/camera/Frustum.d.ts +2 -2
- package/lib/js/camera/PlanetCamera.d.ts +1 -1
- package/lib/js/control/Atmosphere.d.ts +3 -3
- package/lib/js/control/AtmosphereConfig.d.ts +2 -2
- package/lib/js/control/CameraLock.d.ts +3 -3
- package/lib/js/control/CompassButton.d.ts +1 -1
- package/lib/js/control/DebugInfo.d.ts +1 -1
- package/lib/js/control/EarthCoordinates.d.ts +2 -2
- package/lib/js/control/GeoImageDragControl.d.ts +2 -2
- package/lib/js/control/KeyboardNavigation.d.ts +1 -1
- package/lib/js/control/LayerAnimation.d.ts +2 -2
- package/lib/js/control/LayerSwitcher.d.ts +4 -2
- package/lib/js/control/Lighting.d.ts +2 -1
- package/lib/js/control/MouseNavigation.d.ts +3 -2
- package/lib/js/control/OldMouseNavigation.d.ts +3 -2
- package/lib/js/control/RulerSwitcher.d.ts +2 -1
- package/lib/js/control/ScaleControl.d.ts +2 -1
- package/lib/js/control/SegmentBoundVisualization.d.ts +2 -1
- package/lib/js/control/ShowFps.d.ts +2 -1
- package/lib/js/control/SimpleNavigation.d.ts +3 -2
- package/lib/js/control/SimpleSkyBackground.d.ts +2 -1
- package/lib/js/control/Sun.d.ts +2 -1
- package/lib/js/control/ToggleWireframe.d.ts +2 -1
- package/lib/js/control/TouchNavigation.d.ts +3 -2
- package/lib/js/control/ZoomControl.d.ts +2 -1
- package/lib/js/control/drawing/DrawingControl.d.ts +1 -1
- package/lib/js/control/drawing/LineStringDrawingScene.d.ts +1 -1
- package/lib/js/control/drawing/PolygonDrawingScene.d.ts +3 -3
- package/lib/js/control/drawing/PolygonDrawingScene.js +0 -1
- package/lib/js/control/elevationProfile/ElevationProfile.d.ts +1 -1
- package/lib/js/control/elevationProfile/ElevationProfileButtonsView.d.ts +3 -2
- package/lib/js/control/elevationProfile/ElevationProfileControl.d.ts +2 -2
- package/lib/js/control/elevationProfile/ElevationProfileControl.js +0 -2
- package/lib/js/control/elevationProfile/ElevationProfileLegend.d.ts +1 -1
- package/lib/js/control/elevationProfile/ElevationProfileScene.d.ts +2 -2
- package/lib/js/control/elevationProfile/ElevationProfileView.d.ts +6 -4
- package/lib/js/control/elevationProfile/ElevationProfileView.js +1 -1
- package/lib/js/control/elevationProfile/PointListDialog.d.ts +1 -1
- package/lib/js/control/geoObjectEditor/ArrowEntity.d.ts +1 -1
- package/lib/js/control/geoObjectEditor/AxisTrackEntity.d.ts +1 -1
- package/lib/js/control/geoObjectEditor/GeoObjectEditor.d.ts +1 -1
- package/lib/js/control/geoObjectEditor/GeoObjectEditorDialog.d.ts +1 -1
- package/lib/js/control/geoObjectEditor/GeoObjectEditorScene.d.ts +2 -2
- package/lib/js/control/geoObjectEditor/MoveAxisEntity.d.ts +1 -1
- package/lib/js/control/geoObjectEditor/MovePlaneEntity.d.ts +1 -1
- package/lib/js/control/geoObjectEditor/RotateEntity.d.ts +1 -1
- package/lib/js/control/heightRuler/HeightRuler.d.ts +1 -1
- package/lib/js/control/heightRuler/HeightRulerScene.d.ts +1 -1
- package/lib/js/control/ruler/Ruler.d.ts +2 -1
- package/lib/js/control/ruler/RulerScene.d.ts +2 -2
- package/lib/js/control/selection/Selection.d.ts +2 -1
- package/lib/js/control/timeline/TimelineControl.d.ts +1 -1
- package/lib/js/control/timeline/TimelineModel.d.ts +1 -1
- package/lib/js/control/timeline/TimelineView.d.ts +4 -3
- package/lib/js/ellipsoid/Ellipsoid.d.ts +1 -1
- package/lib/js/ellipsoid/Ellipsoid.js +1 -1
- package/lib/js/entity/BaseBillboard.d.ts +6 -3
- package/lib/js/entity/BaseBillboardHandler.d.ts +2 -2
- package/lib/js/entity/Billboard.d.ts +3 -2
- package/lib/js/entity/Entity.d.ts +23 -12
- package/lib/js/entity/EntityCollection.d.ts +4 -3
- package/lib/js/entity/GeoObject.d.ts +2 -2
- package/lib/js/entity/Geometry.d.ts +4 -3
- package/lib/js/entity/GeometryHandler.d.ts +3 -2
- package/lib/js/entity/InstanceData.d.ts +2 -2
- package/lib/js/entity/Label.d.ts +4 -2
- package/lib/js/entity/LabelHandler.d.ts +1 -1
- package/lib/js/entity/PointCloud.d.ts +1 -1
- package/lib/js/entity/Polyline.d.ts +9 -7
- package/lib/js/entity/Polyline.js +2 -1
- package/lib/js/entity/Ray.d.ts +4 -2
- package/lib/js/entity/RayHandler.d.ts +2 -2
- package/lib/js/entity/Strip.d.ts +5 -3
- package/lib/js/input/KeyboardHandler.d.ts +1 -1
- package/lib/js/layer/BaseGeoImage.d.ts +6 -5
- package/lib/js/layer/Bing.d.ts +2 -1
- package/lib/js/layer/CanvasTiles.d.ts +4 -3
- package/lib/js/layer/GeoImage.d.ts +2 -1
- package/lib/js/layer/GeoTexture2d.d.ts +3 -2
- package/lib/js/layer/GeoVideo.d.ts +2 -1
- package/lib/js/layer/KML.d.ts +5 -3
- package/lib/js/layer/KML.js +1 -1
- package/lib/js/layer/Layer.d.ts +5 -4
- package/lib/js/layer/Material.d.ts +2 -2
- package/lib/js/layer/OpenStreetMap.d.ts +2 -1
- package/lib/js/layer/Vector.d.ts +9 -7
- package/lib/js/layer/Vector.js +1 -1
- package/lib/js/layer/WMS.d.ts +2 -1
- package/lib/js/layer/XYZ.d.ts +4 -3
- package/lib/js/math/Quat.d.ts +6 -1
- package/lib/js/math/Quat.js +6 -1
- package/lib/js/math/Vec3.d.ts +3 -2
- package/lib/js/math/coder.d.ts +5 -3
- package/lib/js/math/index.d.ts +6 -3
- package/lib/js/math.d.ts +2 -2
- package/lib/js/math.js +2 -2
- package/lib/js/quadTree/earth/EarthEntityCollectionNodeLonLat.d.ts +2 -1
- package/lib/js/quadTree/earth/EarthQuadTreeStrategy.d.ts +0 -2
- package/lib/js/quadTree/equi/EquiEntityCollectionNodeLonLat.d.ts +2 -1
- package/lib/js/renderer/Renderer.d.ts +5 -3
- package/lib/js/renderer/RendererEvents.d.ts +6 -3
- package/lib/js/renderer/RendererEvents.js +2 -2
- package/lib/js/scene/Axes.d.ts +1 -1
- package/lib/js/scene/Planet.d.ts +8 -6
- package/lib/js/scene/SkyBox.d.ts +1 -1
- package/lib/js/segment/Segment.d.ts +7 -5
- package/lib/js/segment/SegmentLonLat.d.ts +1 -1
- package/lib/js/segment/SegmentLonLatEqui.d.ts +1 -1
- package/lib/js/shaders/atmos.d.ts +1 -1
- package/lib/js/shaders/drawnode.d.ts +1 -1
- package/lib/js/terrain/BilTerrain.d.ts +3 -2
- package/lib/js/terrain/EmptyTerrain.d.ts +1 -1
- package/lib/js/terrain/GlobusRgbTerrain.d.ts +2 -1
- package/lib/js/terrain/GlobusTerrain.d.ts +5 -4
- package/lib/js/terrain/RgbTerrain.d.ts +3 -2
- package/lib/js/ui/Button.d.ts +3 -2
- package/lib/js/ui/ButtonGroup.d.ts +1 -1
- package/lib/js/ui/Checkbox.d.ts +3 -2
- package/lib/js/ui/Color.d.ts +3 -2
- package/lib/js/ui/Dialog.d.ts +3 -2
- package/lib/js/ui/Input.d.ts +3 -2
- package/lib/js/ui/Slider.d.ts +3 -2
- package/lib/js/ui/ToggleButton.d.ts +4 -3
- package/lib/js/ui/View.d.ts +1 -1
- package/lib/js/utils/FontAtlas.d.ts +1 -1
- package/lib/js/utils/GeoImageCreator.d.ts +1 -1
- package/lib/js/utils/Loader.d.ts +1 -1
- package/lib/js/utils/NormalMapCreator.d.ts +2 -1
- package/lib/js/utils/TerrainWorker.d.ts +1 -1
- package/lib/js/utils/TextureAtlas.d.ts +4 -2
- package/lib/js/utils/objParser.d.ts +1 -1
- package/lib/js/utils/shared.d.ts +5 -3
- package/lib/js/webgl/Framebuffer.d.ts +3 -2
- package/lib/js/webgl/Handler.d.ts +11 -7
- package/lib/js/webgl/Handler.js +6 -3
- package/lib/js/webgl/Multisample.d.ts +2 -1
- package/lib/js/webgl/Program.d.ts +2 -2
- package/lib/js/webgl/ProgramController.d.ts +2 -1
- package/lib/js/webgl/variableHandlers.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).og={})}(this,(function(e){"use strict";const t=2*Math.PI,i=Math.PI/2,s=Number.MAX_VALUE||17976931348623157e292,n=Math.log(2),r=2147483647,o=549755748352,a=-o,l=Math.PI/180,h=180/Math.PI,c=2*h,d=.5*l,_=Math.sqrt(.5),u=1e-5,g=1e-10,f=1e-12,p=1e-14;function m(e,t,i){return Math.max(t,Math.min(e,i))}function v(e){return!(e&e-1)}function y(e,t=4096){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1>t?t:e+1}function x(e=0,t=1){return Math.floor(Math.random()*(t-e))+e}function b(e,t){return(e%t+t)%t}function w(e){const i=b(e,t);return Math.abs(i)<p&&Math.abs(e)>p?t:i}function C(e){const t=Math.abs(e);return t-Math.floor(t)}function T(e,t,i){return i+e*(t-i)}function E(e){return e*e*e}function L(e){return e*e}function A(e){return e-360*Math.floor(e/360)}var P=Object.freeze({__proto__:null,ARCSECONDS_TO_RADIANS:484813681109536e-20,DEG2RAD:function(e){return e*l},DEGREES:h,DEGREES_DOUBLE:c,DEGREES_TO_HOURS:1/15,EPS1:.1,EPS10:g,EPS11:1e-11,EPS12:f,EPS13:1e-13,EPS14:p,EPS15:1e-15,EPS16:1e-16,EPS17:1e-17,EPS18:1e-18,EPS19:1e-19,EPS2:.01,EPS20:1e-20,EPS3:.001,EPS4:1e-4,EPS5:u,EPS6:1e-6,EPS7:1e-7,EPS8:1e-8,EPS9:1e-9,HOURS_TO_DEGREES:15,HOURS_TO_RADIANS:.26179938779914946,LOG2:n,MAX:o,MAX32:r,MAX_FLOAT:s,MIN:a,PI_TWO:i,RAD2DEG:function(e){return e*h},RADIANS:l,RADIANS_HALF:d,RADIANS_TO_HOURS:3.819718634205488,SQRT_HALF:_,TWO_PI:t,W:3,X:0,Y:1,Z:2,bezier1v:function(e,t,i,s,n){return E(1-e)*t+3*L(1-e)*e*i+3*(1-e)*L(e)*s+E(e)*n},bezier3v:function(e,t,i,s,n){let r=1-e,o=e*e,a=r*r,l=a*r,h=o*e;return t.scaleTo(l).addA(i.scaleTo(3*a*e)).addA(s.scaleTo(3*r*o)).addA(n.scaleTo(h))},clamp:m,cube:E,degToDec:function(e,t,i,s){return s?e+t/60+i/3600:-e-t/60-i/3600},exp2:function(e){return Math.pow(2,e)},frac:C,getAngleBetweenAzimuths:function(e,t){return(((e=w(e))-(t=w(t)))%360+360+180)%360-180},isPowerOfTwo:v,lerp:T,log:function(e,t){return Math.log(e)/Math.log(t)},log2:function(e){return Math.log(e)/n},mod:b,negativePItoPI:function(e){return w(e+Math.PI)-Math.PI},nextHighestPowerOfTwo:y,norm_lon:function(e){return e>180?(e+180)%360-180:e<-180?(e-180)%360+180:e},pow2i:function(e){return 2<<e-1},random:function(e=0,t=1){return Math.random()*(t-e)+e},randomi:x,rev:A,slice:function(e,t,i){return e*(t-i)},solve_iteration:function(e,t,i,s=50){let n=0,r=t;for(let t=0;t<s;t++)if(n=r,r=e(n),Math.abs(r-n)<i)return r;return r},solve_iteration_fixed:function(e,t,i){let s=0,n=t;for(let t=0;t<i;t++)s=n,n=e(s);return n},square:L,step:function(e,t){return t<e?0:1},zeroTwoPI:w});const S=.5*Math.PI,M=180/Math.PI,R=2*M,B=Math.PI/360,k=M*S;class I{constructor(e=0,t=0,i=0){this.lon=0,this.lat=0,this.height=0,this.lon=e,this.lat=t,this.height=i}isZero(){return 0===this.lon&&0===this.lat&&0===this.height}static join(e){let t=[];for(let i=0;i<e.length;i++){let s=e[i];t[i]=new I(s[0],s[1],s[2])}return t}static createFromArray(e){return new I(e[0],e[1],e[2])}static toArray(e){return[e.lon,e.lat,e.height]}toArray(){return I.toArray(this)}static forwardMercator(e,t,i){return new I(e*O,Math.log(Math.tan((90+t)*B))*N,i)}static forwardMercatorRes(e,t){return t.lon=e.lon*O,t.lat=Math.log(Math.tan((90+e.lat)*B))*N,t.height=e.height,t}static inverseMercator(e,t,i=0){return new I(e*V,R*Math.atan(Math.exp(t*F))-k,i)}set(e=0,t=0,i=0){return this.lon=e,this.lat=t,this.height=i,this}copy(e){return this.lon=e.lon,this.lat=e.lat,this.height=e.height,this}clone(){return new I(this.lon,this.lat,this.height)}forwardMercator(){return I.forwardMercator(this.lon,this.lat,this.height)}forwardMercatorEPS01(){let e=this.lat;return e>89.9?e=89.9:e<-89.9&&(e=-89.9),new I(this.lon*O,Math.log(Math.tan((90+e)*B))*N)}inverseMercator(){return I.inverseMercator(this.lon,this.lat,this.height)}equal(e){return e.height?this.lon===e.lon&&this.lat===e.lat&&this.height===e.height:this.lon===e.lon&&this.lat===e.lat}}const z=20037508.34,D=2*z,F=Math.PI/z,N=z/Math.PI,H=.5*Math.PI,O=z/180,V=180/z,U=Math.PI/360,G=Math.PI/180,Y=180/Math.PI,j=2*z,W=1/j;function q(e){return new I(e.lon*z/180,Math.log(Math.tan((90+e.lat)*U))*N,e.height)}function $(e){return e*z/180}function X(e){return Math.log(Math.tan((90+e)*U))*N}function Z(e){return Y*(2*Math.atan(Math.exp(e*F))-H)}function K(e,t,i){let s=D/(1<<i),n=new I(e*s-z,z-t*s-s);return new te(n,new I(n.lon+s,n.lat+s))}const Q=Z(z),J=-Q;var ee=Object.freeze({__proto__:null,INV_POLE_BY_180:V,MAX_LAT:Q,MIN_LAT:J,ONE_BY_POLE_DOUBLE:W,PI_BY_POLE:F,POLE:z,POLE2:D,POLE_BY_180:O,POLE_BY_PI:N,POLE_DOUBLE:j,forward:q,forwardArray:function(e){let t=[];for(let i=0;i<e.length;i++)t.push(e[i].forwardMercator());return t},forward_lat:X,forward_lon:$,getTileExtent:K,getTileX:function(e,t){return Math.floor((e+180)/360*Math.pow(2,t))},getTileY:function(e,t){return Math.floor(.5*(1-Math.log(Math.tan(e*G)+1/Math.cos(e*G))/Math.PI)*Math.pow(2,t))},inverse_lat:Z,inverse_lon:function(e){return 180*e/z}});class te{constructor(e=new I,t=new I){this.southWest=e,this.northEast=t}static createFromArray(e){return new te(new I(e[0],e[1]),new I(e[2],e[3]))}static createByCoordinates(e){let t=o,i=a,s=o,n=a;for(let r=0;r<e.length;r++){const o=e[r];o.lon<t&&(t=o.lon),o.lon>i&&(i=o.lon),o.lat<s&&(s=o.lat),o.lat>n&&(n=o.lat)}return new te(new I(t,s),new I(i,n))}static createByCoordinatesArr(e){let t=o,i=a,s=o,n=a;for(let r=0;r<e.length;r++){const o=e[r];o[0]<t&&(t=o[0]),o[0]>i&&(i=o[0]),o[1]<s&&(s=o[1]),o[1]>n&&(n=o[1])}return new te(new I(t,s),new I(i,n))}static fromTile(e,t,i,s=j,n=j){const r=1<<i,o=s/r,a=n/r,l=.5*-s+e*o,h=.5*n-t*a,c=l+o;return new te(new I(l,h-a),new I(c,h))}setByCoordinates(e){let t=o,i=a,s=o,n=a;for(let r=0;r<e.length;r++){const o=e[r];o.lon<t&&(t=o.lon),o.lon>i&&(i=o.lon),o.lat<s&&(s=o.lat),o.lat>n&&(n=o.lat)}return this.southWest.lon=t,this.southWest.lat=s,this.northEast.lon=i,this.northEast.lat=n,this}isInside(e){const t=this.southWest,i=this.northEast;return e.lon>=t.lon&&e.lon<=i.lon&&e.lat>=t.lat&&e.lat<=i.lat}overlaps(e){const t=this.southWest,i=this.northEast;return t.lon<=e.northEast.lon&&i.lon>=e.southWest.lon&&t.lat<=e.northEast.lat&&i.lat>=e.southWest.lat}getWidth(){return this.northEast.lon-this.southWest.lon}getHeight(){return this.northEast.lat-this.southWest.lat}clone(){return new te(this.southWest.clone(),this.northEast.clone())}getCenter(){const e=this.southWest,t=this.northEast;return new I(e.lon+.5*(t.lon-e.lon),e.lat+.5*(t.lat-e.lat))}getNorthWest(){return new I(this.southWest.lon,this.northEast.lat)}getNorthEast(){return new I(this.northEast.lon,this.northEast.lat)}getSouthWest(){return new I(this.southWest.lon,this.southWest.lat)}getSouthEast(){return new I(this.northEast.lon,this.southWest.lat)}getNorth(){return this.northEast.lat}getEast(){return this.northEast.lon}getWest(){return this.southWest.lon}getSouth(){return this.southWest.lat}equals(e){return this.southWest.lon===e.southWest.lon&&this.southWest.lat===e.southWest.lat&&this.northEast.lon===e.northEast.lon&&this.northEast.lat===e.northEast.lat}forwardMercator(){return new te(this.southWest.forwardMercator(),this.northEast.forwardMercator())}inverseMercator(){return new te(this.southWest.inverseMercator(),this.northEast.inverseMercator())}getCartesianBounds(e){let t=o,i=a,s=o,n=a,r=o,l=a;const h=[new I(this.southWest.lon,this.southWest.lat),new I(this.southWest.lon,this.northEast.lat),new I(this.northEast.lon,this.northEast.lat),new I(this.northEast.lon,this.southWest.lat)];for(let o=0;o<h.length;o++){const a=e.lonLatToCartesian(h[o]),c=a.x,d=a.y,_=a.z;c<t&&(t=c),c>i&&(i=c),d<s&&(s=d),d>n&&(n=d),_<r&&(r=_),_>l&&(l=_)}return[t,s,r,i,n,l]}toString(){return`[${this.southWest.lon.toFixed(5)}, ${this.southWest.lat.toFixed(5)}, ${this.northEast.lon.toFixed(5)}, ${this.northEast.lat.toFixed(5)}]`}}class ie{constructor(){this._m=[0,0,0,0,0,0,0,0,0]}set(e){return this._m[0]=e[0],this._m[1]=e[1],this._m[2]=e[2],this._m[3]=e[3],this._m[4]=e[4],this._m[5]=e[5],this._m[6]=e[6],this._m[7]=e[7],this._m[8]=e[8],this}clone(){let e=new ie;return e.set(this._m),e}copy(e){return this.set(e._m)}transposeTo(){let e=new ie,t=this._m;return e._m[0]=t[0],e._m[1]=t[3],e._m[2]=t[6],e._m[3]=t[1],e._m[4]=t[4],e._m[5]=t[7],e._m[6]=t[2],e._m[7]=t[5],e._m[8]=t[8],e}setIdentity(){return this._m[0]=1,this._m[1]=0,this._m[2]=0,this._m[3]=0,this._m[4]=1,this._m[5]=0,this._m[6]=0,this._m[7]=0,this._m[8]=1,this}mulVec(e){let t=e.x,i=e.y,s=e.z,n=this._m;return new oe(n[0]*t+n[3]*i+n[6]*s,n[1]*t+n[4]*i+n[7]*s,n[2]*t+n[5]*i+n[8]*s)}getMat4(){let e=new ne,t=e._m,i=this._m;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=0,t[4]=i[3],t[5]=i[4],t[6]=i[5],t[7]=0,t[8]=i[6],t[9]=i[7],t[10]=i[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,e}}class se{constructor(e=0,t=0,i=0,s=0){this.x=e,this.y=t,this.z=i,this.w=s}static get identity(){return new se(0,0,0,1)}static fromVec(e){return new se(e[0],e[1],e[2],e[3])}toVec3(){return new oe(this.x,this.y,this.z)}clone(){return new se(this.x,this.y,this.z,this.w)}equal(e){return this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this}toArray(){return[this.x,this.y,this.z,this.w]}toArray3(){return[this.x,this.y,this.z]}set(e,t,i,s){return this.x=e,this.y=t,this.z=i,this.w=s,this}addA(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}subA(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}scale(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}affinity(){let e=1/this.w;return this.x*=e,this.y*=e,this.z*=e,this.w=1,this}scaleTo(e){return new se(this.x*e,this.y*e,this.z*e,this.w*e)}getStep(e){return new se(this.x<e?0:1,this.y<e?0:1,this.z<e?0:1,this.w<e?0:1)}getFrac(e){return new se(C(e.x),C(e.y),C(e.z),C(e.w))}dot(e){return e.x*this.x+e.y*this.y+e.z*this.z+e.w*this.w}isZero(){return!(this.x||this.y||this.z||this.w)}}class ne{constructor(){this._m=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}static identity(){let e=new ne;return e._m[0]=1,e._m[1]=0,e._m[2]=0,e._m[3]=0,e._m[4]=0,e._m[5]=1,e._m[6]=0,e._m[7]=0,e._m[8]=0,e._m[9]=0,e._m[10]=1,e._m[11]=0,e._m[12]=0,e._m[13]=0,e._m[14]=0,e._m[15]=1,e}static getRotationAroundPoint(e,t=oe.ZERO,i=oe.UP){let s=ne.getRotation(e,i),n=(new ne).setIdentity().translate(t),r=(new ne).setIdentity().translate(t.negateTo());return n.mul(s).mul(r)}static getRotation(e,t=oe.UP){return(new ne).setRotation(t,e)}set(e){return this._m[0]=e[0],this._m[1]=e[1],this._m[2]=e[2],this._m[3]=e[3],this._m[4]=e[4],this._m[5]=e[5],this._m[6]=e[6],this._m[7]=e[7],this._m[8]=e[8],this._m[9]=e[9],this._m[10]=e[10],this._m[11]=e[11],this._m[12]=e[12],this._m[13]=e[13],this._m[14]=e[14],this._m[15]=e[15],this}clone(){let e=new ne;return e.set(this._m),e}copy(e){return this.set(e._m)}getMat3(){let e=new ie,t=this._m,i=e._m;return i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[4],i[4]=t[5],i[5]=t[6],i[6]=t[8],i[7]=t[9],i[8]=t[10],e}mulVec3(e){let t=e.x,i=e.y,s=e.z;return new oe(this._m[0]*t+this._m[4]*i+this._m[8]*s+this._m[12],this._m[1]*t+this._m[5]*i+this._m[9]*s+this._m[13],this._m[2]*t+this._m[6]*i+this._m[10]*s+this._m[14])}mulVec4(e){let t=e.x,i=e.y,s=e.z,n=e.w;return new se(this._m[0]*t+this._m[4]*i+this._m[8]*s+this._m[12]*n,this._m[1]*t+this._m[5]*i+this._m[9]*s+this._m[13]*n,this._m[2]*t+this._m[6]*i+this._m[10]*s+this._m[14]*n,this._m[3]*t+this._m[7]*i+this._m[11]*s+this._m[15]*n)}toInverseMatrix3(){let e=this._m,t=e[0],i=e[1],s=e[2],n=e[4],r=e[5],o=e[6],a=e[8],l=e[9],h=e[10],c=h*r-o*l,d=-h*n+o*a,_=l*n-r*a,u=t*c+i*d+s*_;if(!u)return;u=1/u;let g=new ie;return g._m[0]=c*u,g._m[1]=(-h*i+s*l)*u,g._m[2]=(o*i-s*r)*u,g._m[3]=d*u,g._m[4]=(h*t-s*a)*u,g._m[5]=(-o*t+s*n)*u,g._m[6]=_*u,g._m[7]=(-l*t+i*a)*u,g._m[8]=(r*t-i*n)*u,g}inverseTo(e=new ne){let t=this._m[0],i=this._m[1],s=this._m[2],n=this._m[3],r=this._m[4],o=this._m[5],a=this._m[6],l=this._m[7],h=this._m[8],c=this._m[9],d=this._m[10],_=this._m[11],u=this._m[12],g=this._m[13],f=this._m[14],p=this._m[15],m=t*o-i*r,v=t*a-s*r,y=t*l-n*r,x=i*a-s*o,b=i*l-n*o,w=s*l-n*a,C=h*g-c*u,T=h*f-d*u,E=h*p-_*u,L=c*f-d*g,A=c*p-_*g,P=d*p-_*f,S=1/(m*P-v*A+y*L+x*E-b*T+w*C);return e._m[0]=(o*P-a*A+l*L)*S,e._m[1]=(-i*P+s*A-n*L)*S,e._m[2]=(g*w-f*b+p*x)*S,e._m[3]=(-c*w+d*b-_*x)*S,e._m[4]=(-r*P+a*E-l*T)*S,e._m[5]=(t*P-s*E+n*T)*S,e._m[6]=(-u*w+f*y-p*v)*S,e._m[7]=(h*w-d*y+_*v)*S,e._m[8]=(r*A-o*E+l*C)*S,e._m[9]=(-t*A+i*E-n*C)*S,e._m[10]=(u*b-g*y+p*m)*S,e._m[11]=(-h*b+c*y-_*m)*S,e._m[12]=(-r*L+o*T-a*C)*S,e._m[13]=(t*L-i*T+s*C)*S,e._m[14]=(-u*x+g*v-f*m)*S,e._m[15]=(h*x-c*v+d*m)*S,e}transposeTo(){let e=new ne;return e._m[0]=this._m[0],e._m[1]=this._m[4],e._m[2]=this._m[8],e._m[3]=this._m[12],e._m[4]=this._m[1],e._m[5]=this._m[5],e._m[6]=this._m[9],e._m[7]=this._m[13],e._m[8]=this._m[2],e._m[9]=this._m[6],e._m[10]=this._m[10],e._m[11]=this._m[14],e._m[12]=this._m[3],e._m[13]=this._m[7],e._m[14]=this._m[11],e._m[15]=this._m[15],e}setIdentity(){return this._m[0]=1,this._m[1]=0,this._m[2]=0,this._m[3]=0,this._m[4]=0,this._m[5]=1,this._m[6]=0,this._m[7]=0,this._m[8]=0,this._m[9]=0,this._m[10]=1,this._m[11]=0,this._m[12]=0,this._m[13]=0,this._m[14]=0,this._m[15]=1,this}mul(e){let t=this._m[0],i=this._m[1],s=this._m[2],n=this._m[3],r=this._m[4],o=this._m[5],a=this._m[6],l=this._m[7],h=this._m[8],c=this._m[9],d=this._m[10],_=this._m[11],u=this._m[12],g=this._m[13],f=this._m[14],p=this._m[15],m=e._m[0],v=e._m[1],y=e._m[2],x=e._m[3],b=e._m[4],w=e._m[5],C=e._m[6],T=e._m[7],E=e._m[8],L=e._m[9],A=e._m[10],P=e._m[11],S=e._m[12],M=e._m[13],R=e._m[14],B=e._m[15],k=new ne;return k._m[0]=m*t+v*r+y*h+x*u,k._m[1]=m*i+v*o+y*c+x*g,k._m[2]=m*s+v*a+y*d+x*f,k._m[3]=m*n+v*l+y*_+x*p,k._m[4]=b*t+w*r+C*h+T*u,k._m[5]=b*i+w*o+C*c+T*g,k._m[6]=b*s+w*a+C*d+T*f,k._m[7]=b*n+w*l+C*_+T*p,k._m[8]=E*t+L*r+A*h+P*u,k._m[9]=E*i+L*o+A*c+P*g,k._m[10]=E*s+L*a+A*d+P*f,k._m[11]=E*n+L*l+A*_+P*p,k._m[12]=S*t+M*r+R*h+B*u,k._m[13]=S*i+M*o+R*c+B*g,k._m[14]=S*s+M*a+R*d+B*f,k._m[15]=S*n+M*l+R*_+B*p,k}translate(e){let t=e.x,i=e.y,s=e.z,n=this._m;return n[12]=n[0]*t+n[4]*i+n[8]*s+n[12],n[13]=n[1]*t+n[5]*i+n[9]*s+n[13],n[14]=n[2]*t+n[6]*i+n[10]*s+n[14],n[15]=n[3]*t+n[7]*i+n[11]*s+n[15],this}translateToPosition(e){let t=this._m;return t[12]=e.x,t[13]=e.y,t[14]=e.z,this}rotate(e,t){let i=Math.cos(t),s=Math.sin(t),n=new ne,r=n._m;return r[0]=i+(1-i)*e.x*e.x,r[1]=(1-i)*e.y*e.x-s*e.z,r[2]=(1-i)*e.z*e.x+s*e.y,r[3]=0,r[4]=(1-i)*e.x*e.y+s*e.z,r[5]=i+(1-i)*e.y*e.y,r[6]=(1-i)*e.z*e.y-s*e.x,r[7]=0,r[8]=(1-i)*e.x*e.z-s*e.y,r[9]=(1-i)*e.y*e.z+s*e.x,r[10]=i+(1-i)*e.z*e.z,r[11]=0,r[12]=0,r[13]=0,r[14]=0,r[15]=1,this.mul(n)}setRotation(e,t){let i=Math.cos(t),s=Math.sin(t),n=this._m;return n[0]=i+(1-i)*e.x*e.x,n[1]=(1-i)*e.y*e.x-s*e.z,n[2]=(1-i)*e.z*e.x+s*e.y,n[3]=0,n[4]=(1-i)*e.x*e.y+s*e.z,n[5]=i+(1-i)*e.y*e.y,n[6]=(1-i)*e.z*e.y-s*e.x,n[7]=0,n[8]=(1-i)*e.x*e.z-s*e.y,n[9]=(1-i)*e.y*e.z+s*e.x,n[10]=i+(1-i)*e.z*e.z,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,this}rotateBetweenVectors(e,t){return re.getRotationBetweenVectors(e,t).getMat4()}scale(e){let t=this._m;return t[0]=t[0]*e.x,t[1]=t[1]*e.x,t[2]=t[2]*e.x,t[3]=t[3]*e.x,t[4]=t[4]*e.y,t[5]=t[5]*e.y,t[6]=t[6]*e.y,t[7]=t[7]*e.y,t[8]=t[8]*e.z,t[9]=t[9]*e.z,t[10]=t[10]*e.z,t[11]=t[11]*e.z,this}setPerspective(e,t,i,s,n,r){let o=t-e,a=s-i,l=n-r,h=2*n,c=this._m;return c[0]=h/o,c[1]=0,c[2]=0,c[3]=0,c[4]=0,c[5]=h/a,c[6]=0,c[7]=0,c[8]=(t+e)/o,c[9]=(s+i)/a,c[10]=(r+n)/l,c[11]=-1,c[12]=0,c[13]=0,c[14]=h*r/l,c[15]=0,this}setOrtho(e,t,i,s,n,r){let o=1/(e-t),a=1/(i-s),l=1/(n-r),h=this._m;return h[0]=-2*o,h[1]=0,h[2]=0,h[3]=0,h[4]=0,h[5]=-2*a,h[6]=0,h[7]=0,h[8]=0,h[9]=0,h[10]=2*l,h[11]=0,h[12]=(e+t)*o,h[13]=(s+i)*a,h[14]=(r+n)*l,h[15]=1,this}eulerToMatrix(e,t,i){let s=Math.cos(e),n=Math.sin(e),r=Math.cos(t),o=Math.sin(t),a=Math.cos(i),l=Math.sin(i),h=s*o,c=n*o,d=this._m;return d[0]=r*a,d[1]=-r*l,d[2]=-o,d[4]=-c*a+s*l,d[5]=c*l+s*a,d[6]=-n*r,d[8]=h*a+n*l,d[9]=-h*l+n*a,d[10]=s*r,d[3]=d[7]=d[11]=d[12]=d[13]=d[14]=0,d[15]=1,this}}class re{constructor(e=0,t=0,i=0,s=0){this.x=e,this.y=t,this.z=i,this.w=s}static get IDENTITY(){return new re(0,0,0,1)}static xRotation(e){return e*=.5,new re(Math.sin(e),0,0,Math.cos(e))}static yRotation(e){return e*=.5,new re(0,Math.sin(e),0,Math.cos(e))}static zRotation(e){return e*=.5,new re(0,0,Math.sin(e),Math.cos(e))}static axisAngleToQuat(e,t=0){let i=e.getNormal(),s=.5*t,n=Math.sin(s);return new re(i.x*n,i.y*n,i.z*n,Math.cos(s))}static getLookRotation(e,t){let i=e.getNormal().negate(),s=t.cross(i).normalize(),n=i.cross(s),r=1+s.x+n.y+i.z;if(r>1e-6){let e=1/(2*Math.sqrt(r));return new re((i.y-n.z)*e,(s.z-i.x)*e,(n.x-s.y)*e,.25/e)}if(s.x>n.y&&s.x>i.z){let e=1/(2*Math.sqrt(1+s.x-n.y-i.z));return new re(.25/e,(n.x+s.y)*e,(s.z+i.x)*e,(i.y-n.z)*e)}if(n.y>i.z){let e=1/(2*Math.sqrt(1+n.y-s.x-i.z));return new re((n.x+s.y)*e,.25/e,(i.y+n.z)*e,(s.z-i.x)*e)}let o=1/(2*Math.sqrt(1+i.z-s.x-n.y));return new re((s.z+i.x)*o,(i.y+n.z)*o,.25/o,(n.x-s.y)*o)}static getLookAtSourceDest(e,t){let i=t.subA(e).normalize(),s=oe.FORWARD.dot(i);if(Math.abs(s- -1)<1e-6)return re.axisAngleToQuat(oe.UP,Math.PI);if(Math.abs(s-1)<1e-6)return new re(0,0,0,1);let n=Math.acos(s),r=oe.FORWARD.cross(i).normalize();return re.axisAngleToQuat(r,n)}static getRotationBetweenVectors(e,t){let i=e.cross(t);return new re(i.x,i.y,i.z,1+e.dot(t)).normalize()}static getRotationBetweenVectorsRes(e,t,i){let s=e.cross(t);return i.set(s.x,s.y,s.z,1+e.dot(t)),i.normalize()}static getRotationBetweenVectorsUp(e,t,i){let s=e.dot(t);if(Math.abs(s+1)<1e-6)return re.axisAngleToQuat(i,Math.PI);if(Math.abs(s-1)<1e-6)return new re(0,0,0,1);let n=Math.acos(s),r=e.cross(t).normalize();return re.axisAngleToQuat(r,n)}isZero(){return 0===this.x&&0===this.y&&0===this.z&&0===this.w}isNaN(){return isNaN(this.x)||isNaN(this.y)||isNaN(this.z)||isNaN(this.w)}clear(){return this.x=this.y=this.z=this.w=0,this}set(e,t,i,s){return this.x=e,this.y=t,this.z=i,this.w=s,this}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this}setIdentity(){return this.x=0,this.y=0,this.z=0,this.w=1,this}clone(){return new re(this.x,this.y,this.z,this.w)}add(e){return new re(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)}addRes(e,t){return t.set(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)}sub(e){return new re(this.x-e.x,this.y-e.y,this.z-e.z,this.w-e.w)}scaleTo(e){return new re(this.x*e,this.y*e,this.z*e,this.w*e)}scale(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}toVec(){return[this.x,this.y,this.z,this.w]}get xyz(){return new oe(this.x,this.y,this.z)}setLookRotation(e,t){let i=e.getNormal().negate(),s=t.cross(i).normalize(),n=i.cross(s),r=1+s.x+n.y+i.z;if(r>1e-6){let e=1/(2*Math.sqrt(r));this.x=(i.y-n.z)*e,this.y=(s.z-i.x)*e,this.z=(n.x-s.y)*e,this.w=.25/e}else if(s.x>n.y&&s.x>i.z){let e=1/(2*Math.sqrt(1+s.x-n.y-i.z));this.x=.25/e,this.y=(n.x+s.y)*e,this.z=(s.z+i.x)*e,this.w=(i.y-n.z)*e}else if(n.y>i.z){let e=1/(2*Math.sqrt(1+n.y-s.x-i.z));this.x=(n.x+s.y)*e,this.y=.25/e,this.z=(i.y+n.z)*e,this.w=(s.z-i.x)*e}else{let e=1/(2*Math.sqrt(1+i.z-s.x-n.y));this.x=(s.z+i.x)*e,this.y=(i.y+n.z)*e,this.z=.25/e,this.w=(n.x-s.y)*e}return this}setFromSphericalCoords(e,t,i){let s=Math.sin(i/2),n=Math.cos(i/2),r=Math.sin(e),o=Math.cos(e),a=Math.sin(t),l=Math.cos(t);return this.x=s*o*a,this.y=s*r,this.z=s*r*l,this.w=n,this}getSphericalCoords(){let e=this.w,t=Math.sqrt(1-e*e);Math.abs(t)<5e-4&&(t=1);let i,s=this.x/t,n=this.y/t,r=this.z/t,o=-Math.asin(n);return i=s*s+r*r<5e-4?0:Math.atan2(s,r),i<0&&(i+=360),{lat:o,lon:i,alpha:Math.acos(e)}}setFromAxisAngle(e,t){let i=e.getNormal(),s=.5*t,n=Math.sin(s);return this.set(i.x*n,i.y*n,i.z*n,Math.cos(s)),this}getAxisAngle(){let e,t,i=this.x,s=this.y,n=this.z,r=this.w,o=Math.sqrt(i*i+s*s+n*n);if(o>1e-7){let a=1/o;e=new oe(i*a,s*a,n*a),t=r<0?2*Math.atan2(-o,-r):2*Math.atan2(o,r)}else e=new oe(0,0,0),t=0;return{axis:e,angle:t}}getPitch(){let e=-2*(this.y*this.z-this.w*this.x);return Math.abs(e)>=1?Math.sign(e)*i:Math.asin(e)}getYaw(){return-Math.atan2(2*(this.x*this.z+this.w*this.y),1-2*(this.y*this.y+this.x*this.x))}getRoll(){return Math.atan2(2*(this.x*this.y+this.w*this.z),1-2*(this.z*this.z+this.x*this.x))}setPitchYawRoll(e,t,i,s=re.IDENTITY){let n=re.xRotation(-e),r=re.yRotation(t),o=re.zRotation(-i);return this.copy(o.mul(n).mul(r).mul(s).conjugate())}setFromEulerAngles(e,t,i){let s=e*d,n=t*d,r=i*d,o=Math.cos(s),a=Math.cos(n),l=Math.cos(r),h=Math.sin(s),c=Math.sin(n),_=Math.sin(r),u=a*l,g=c*_;return this.w=o*u+h*g,this.x=h*u-o*g,this.y=o*c*l+h*a*_,this.z=o*a*_-h*c*l,this.normalize()}getEulerAngles(){let e=this.x,t=this.y,i=this.z,s=this.w,n=t*t,r=s*t-i*e;return r<-1?r=-1:r>1&&(r=1),{roll:Math.atan2(2*(s*e+t*i),1-2*(e*e+n)),pitch:Math.asin(2*r),yaw:Math.atan2(2*(s*i+e*t),1-2*(n+i*i))}}setFromMatrix4(e){let t,i,s,n,r,o=[],a=e._m,l=[1,2,0];return t=a[0]+a[5]+a[10],t>0?(i=Math.sqrt(t+1),this.w=i/2,i=.5/i,this.x=(a[6]-a[9])*i,this.y=(a[8]-a[2])*i,this.z=(a[1]-a[4])*i):(s=0,a[5]>a[0]&&(s=1),a[10]>a[5*s]&&(s=2),n=l[s],r=l[n],i=Math.sqrt(a[5*s]-(a[5*n]+a[5*r])+1),o[s]=.5*i,0!==i&&(i=.5/i),o[3]=(a[4*n+r]-a[4*r+n])*i,o[n]=(a[4*s+n]+a[4*n+s])*i,o[r]=(a[4*s+r]+a[4*r+s])*i,this.x=o[0],this.y=o[1],this.z=o[2],this.w=o[3]),this}getMat4(e=new ne){let t=this.x+this.x,i=this.y+this.y,s=this.z+this.z,n=this.w*t,r=this.w*i,o=this.w*s,a=this.x*t,l=this.x*i,h=this.x*s,c=this.y*i,d=this.y*s,_=this.z*s;return e.set([1-(c+_),l-o,h+r,0,l+o,1-(a+_),d-n,0,h-r,d+n,1-(a+c),0,0,0,0,1])}getMat3(){let e=new ie,t=e._m,i=this.x,s=this.y,n=this.z,r=this.w,o=i+i,a=s+s,l=n+n,h=i*o,c=i*a;i*=l;let d=s*a;return s*=l,n*=l,o*=r,a*=r,r*=l,t[0]=1-(d+n),t[1]=c-r,t[2]=i+a,t[3]=c+r,t[4]=1-(h+n),t[5]=s-o,t[6]=i-a,t[7]=s+o,t[8]=1-(h+d),e}mulVec3(e){let t=e.x,i=e.y,s=e.z,n=this.x,r=this.y,o=this.z,a=this.w,l=a*t+r*s-o*i,h=a*i+o*t-n*s,c=a*s+n*i-r*t;return t=-n*t-r*i-o*s,new oe(l*a+t*-n+h*-o-c*-r,h*a+t*-r+c*-n-l*-o,c*a+t*-o+l*-r-h*-n)}mulVec3Res(e,t){let i=e.x,s=e.y,n=e.z,r=this.x,o=this.y,a=this.z,l=this.w,h=l*i+o*n-a*s,c=l*s+a*i-r*n,d=l*n+r*s-o*i;return i=-r*i-o*s-a*n,t.set(h*l+i*-r+c*-a-d*-o,c*l+i*-o+d*-r-h*-a,d*l+i*-a+h*-o-c*-r)}mul(e){let t=this.x,i=this.y,s=this.z,n=this.w,r=e.x,o=e.y,a=e.z,l=e.w;return new re(t*l+n*r+i*a-s*o,i*l+n*o+s*r-t*a,s*l+n*a+t*o-i*r,n*l-t*r-i*o-s*a)}mulRes(e,t){let i=this.x,s=this.y,n=this.z,r=this.w,o=e.x,a=e.y,l=e.z,h=e.w;return t.set(i*h+r*o+s*l-n*a,s*h+r*a+n*o-i*l,n*h+r*l+i*a-s*o,r*h-i*o-s*a-n*l)}mulA(e){let t=this.x,i=this.y,s=this.z,n=this.w,r=e.x,o=e.y,a=e.z,l=e.w;return this.x=t*l+n*r+i*a-s*o,this.y=i*l+n*o+s*r-t*a,this.z=s*l+n*a+t*o-i*r,this.w=n*l-t*r-i*o-s*a,this}conjugate(){return new re(-this.x,-this.y,-this.z,this.w)}inverse(){let e=1/this.magnitude2();return new re(-this.x*e,-this.y*e,-this.z*e,this.w*e)}magnitude(){let e=this.x,t=this.y,i=this.z,s=this.w;return Math.sqrt(e*e+t*t+i*i+s*s)}magnitude2(){let e=this.x,t=this.y,i=this.z,s=this.w;return e*e+t*t+i*i+s*s}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}normalize(){let e=this.x,t=this.y,i=this.z,s=this.w,n=Math.sqrt(e*e+t*t+i*i+s*s);return 0===n?(this.x=0,this.y=0,this.z=0,this.w=0,this):(n=1/n,this.x=e*n,this.y=t*n,this.z=i*n,this.w=s*n,this)}isEqual(e){let t=this.dot(e);return Math.abs(t-1)<.001}slerp(e,t){let i,s,n,r,o,a=this.x,l=this.y,h=this.z,c=this.w,d=e.x,_=e.y,u=e.z,g=e.w;return s=a*d+l*_+h*u+c*g,s<0&&(s=-s,d=-d,_=-_,u=-u,g=-g),1-s>1e-6?(i=Math.acos(s),n=Math.sin(i),r=Math.sin((1-t)*i)/n,o=Math.sin(t*i)/n):(r=1-t,o=t),new re(r*a+o*d,r*l+o*_,r*h+o*u,r*c+o*g)}}class oe{constructor(e=0,t=0,i=0){this.x=e,this.y=t,this.z=i}static get UP(){return new oe(0,1,0)}static get DOWN(){return new oe(0,-1,0)}static get RIGHT(){return new oe(1,0,0)}static get LEFT(){return new oe(-1,0,0)}static get FORWARD(){return new oe(0,0,-1)}static get BACKWARD(){return new oe(0,0,1)}static get ZERO(){return new oe}static get UNIT_X(){return new oe(1,0,0)}static get UNIT_Y(){return new oe(0,1,0)}static get UNIT_Z(){return new oe(0,0,1)}static get NORTH(){return oe.UNIT_Z}static doubleToTwoFloats(e,t,i){let s=e.x,n=e.y,r=e.z;if(s>=0){let e=65536*Math.floor(s/65536);t.x=Math.fround(e),i.x=Math.fround(s-e)}else{let e=65536*Math.floor(-s/65536);t.x=Math.fround(-e),i.x=Math.fround(s+e)}if(n>=0){let e=65536*Math.floor(n/65536);t.y=Math.fround(e),i.y=Math.fround(n-e)}else{let e=65536*Math.floor(-n/65536);t.y=Math.fround(-e),i.y=Math.fround(n+e)}if(r>=0){let e=65536*Math.floor(r/65536);t.z=Math.fround(e),i.z=Math.fround(r-e)}else{let e=65536*Math.floor(-r/65536);t.z=Math.fround(-e),i.z=Math.fround(r+e)}}static doubleToTwoFloat32Array(e,t,i){let s=e.x,n=e.y,r=e.z;if(s>=0){let e=65536*Math.floor(s/65536);t[0]=Math.fround(e),i[0]=Math.fround(s-e)}else{let e=65536*Math.floor(-s/65536);t[0]=Math.fround(-e),i[0]=Math.fround(s+e)}if(n>=0){let e=65536*Math.floor(n/65536);t[1]=Math.fround(e),i[1]=Math.fround(n-e)}else{let e=65536*Math.floor(-n/65536);t[1]=Math.fround(-e),i[1]=Math.fround(n+e)}if(r>=0){let e=65536*Math.floor(r/65536);t[2]=Math.fround(e),i[2]=Math.fround(r-e)}else{let e=65536*Math.floor(-r/65536);t[2]=Math.fround(-e),i[2]=Math.fround(r+e)}}static fromVec(e){return new oe(e[0],e[1],e[2])}static angle(e,t){let i=e.dot(t),s=e.cross(t).length();return Math.atan2(s,i)}static lerp(e,t,i){return new oe(e.x+(t.x-e.x)*i,e.y+(t.y-e.y)*i,e.z+(t.z-e.z)*i)}static add(e,t){let i=new oe(e.x,e.y,e.z);return i.addA(t),i}static sub(e,t){let i=new oe(e.x,e.y,e.z);return i.subA(t),i}static scale(e,t){return e.scaleTo(t)}static mul(e,t){let i=new oe(e.x,e.y,e.z);return i.mulA(t),i}static noncollinear(e,t){return Boolean(e.y*t.z-e.z*t.y||e.z*t.x-e.x*t.z||e.x*t.y-e.y*t.z)}static proj_b_to_plane(e,t,i){let s=e.sub(t.scaleTo(t.dot(e)/t.dot(t)));return i&&s.isZero()?new oe(i.x,i.y,i.z):s}static proj_b_to_a(e,t){return t.scaleTo(t.dot(e)/t.dot(t))}static orthoNormalize(e,t){return(e=e.getNormal()).scale(t.dot(e)),t.subA(e).normalize()}static div(e,t){let i=new oe(e.x,e.y,e.z);return i.divA(t),i}static length2(e){return e.length2()}static dot(e,t){return e.dot(t)}toVec4(){return new se(this.x,this.y,this.z,1)}clone(){return new oe(this.x,this.y,this.z)}toString(){return`(${this.x},${this.y},${this.z})`}isZero(){return!(this.x||this.y||this.z)}projToVec(e){return e.scaleTo(e.dot(this)/e.dot(e))}equal(e){return this.x===e.x&&this.y===e.y&&this.z===e.z}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}length2(){return this.x*this.x+this.y*this.y+this.z*this.z}getQuat(){return new re(this.x,this.y,this.z)}addA(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}add(e){return new oe(this.x+e.x,this.y+e.y,this.z+e.z)}addRes(e,t){return t.set(this.x+e.x,this.y+e.y,this.z+e.z)}subA(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}sub(e){return new oe(this.x-e.x,this.y-e.y,this.z-e.z)}scale(e){return this.x*=e,this.y*=e,this.z*=e,this}scaleTo(e){return new oe(this.x*e,this.y*e,this.z*e)}mulA(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}mul(e){return new oe(this.x*e.x,this.y*e.y,this.z*e.z)}mulRes(e,t){return t.set(this.x*e.x,this.y*e.y,this.z*e.z)}divA(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}div(e){return new oe(this.x/e.x,this.y/e.y,this.z/e.z)}dot(e){return e.x*this.x+e.y*this.y+e.z*this.z}dotArr(e){return e[0]*this.x+e[1]*this.y+e[2]*this.z}cross(e){return new oe(this.y*e.z-this.z*e.y,this.z*e.x-this.x*e.z,this.x*e.y-this.y*e.x)}clear(){return this.x=this.y=this.z=0,this}getNormal(){let e=new oe;e.copy(this);let t=1/e.length();return e.x*=t,e.y*=t,e.z*=t,e}normal(){let e=new oe;e.copy(this);let t=1/e.length();return e.x*=t,e.y*=t,e.z*=t,e}normalNegate(){let e=new oe;e.copy(this);let t=-1/e.length();return e.x*=t,e.y*=t,e.z*=t,e}normalNegateScale(e){let t=new oe;t.copy(this);let i=-e/t.length();return t.x*=i,t.y*=i,t.z*=i,t}normalScale(e){let t=new oe;t.copy(this);let i=e/t.length();return t.x*=i,t.y*=i,t.z*=i,t}normalize(){let e=1/this.length();return this.x*=e,this.y*=e,this.z*=e,this}toVec(){return[this.x,this.y,this.z]}toArray(){return[this.x,this.y,this.z]}distance(e){let t=this.x-e.x,i=this.y-e.y,s=this.z-e.z;return Math.sqrt(t*t+i*i+s*s)}distance2(e){let t=this.x-e.x,i=this.y-e.y,s=this.z-e.z;return t*t+i*i+s*s}set(e,t,i){return this.x=e,this.y=t,this.z=i,this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}negateTo(){return new oe(-this.x,-this.y,-this.z)}projToRay(e,t){let i=oe.proj_b_to_a(oe.sub(this,e),t);return i.addA(e),i}angle(e){return oe.angle(this,e)}lerp(e,t){return new oe(this.x+(e.x-this.x)*t,this.y+(e.y-this.y)*t,this.z+(e.z-this.z)*t)}smerp(e,t){let i=1-t;return new oe(this.x*t+e.x*i,this.y*t+e.y*i,this.z*t+e.z*i)}static get LERP_DELTA(){return 1e-6}slerp(e,t){let i,s,n,r,o=new oe;if(t<=0)return o.copy(this),o;if(t>=1)return o.copy(e),o;let a=this.dot(e);return 1-a>oe.LERP_DELTA?(i=Math.acos(a),s=Math.sin(i),n=Math.sin((1-t)*i)/s,r=Math.sin(t*i)/s):(n=1-t,r=t),oe.add(this.scaleTo(n),e.scale(r))}mulVecA(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}getRotationTo(e,t){let i=this.clone(),s=e.clone();i.normalize(),s.normalize();let n=i.dot(s);if(n>=1)return re.IDENTITY.clone();if(n<-.999999){if(t.equal(oe.ZERO)){let e=oe.UNIT_X.cross(i);return e.isZero()&&(e=oe.UNIT_Y.cross(i)),e.normalize(),re.axisAngleToQuat(e,Math.PI)}return re.axisAngleToQuat(t,Math.PI)}{let e=Math.sqrt(2*(1+n)),t=1/e,r=i.cross(s),o=new re(r.x*t,r.y*t,r.z*t,.5*e);return o.normalize(),o}}}class ae{constructor(e=0,t=0){this.x=e,this.y=t}static get UP(){return new ae(0,1)}static get DOWN(){return new ae(0,-1)}static get RIGHT(){return new ae(1,0)}static get LEFT(){return new ae(-1,0)}static get ZERO(){return new ae}static add(e,t){const i=new ae(e.x,e.y);return i.addA(t),i}static sub(e,t){var i=new ae(e.x,e.y);return i.subA(t),i}static scale(e,t){let i=new ae(e.x,e.y);return i.scale(t),i}static mul(e,t){let i=new ae(e.x,e.y);return i.mulA(t),i}static div(e,t){let i=new ae(e.x,e.y);return i.divA(t),i}static proj_b_to_a(e,t){return t.scaleTo(t.dot(e)/t.dot(t))}static angle(e,t){return Math.acos(e.dot(t)/Math.sqrt(e.length2()*t.length2()))}static orthoNormalize(e,t){return(e=e.normal()).scale(t.dot(e)),t.sub(e).normalize()}static proj_b_to_plane(e,t,i){let s=e.sub(t.scaleTo(t.dot(e)/t.dot(t)));return i&&s.isZero()?new ae(i.x,i.y):s}toVector3(){return new oe(this.x,this.y,0)}clone(){return new ae(this.x,this.y)}equal(e){return this.x===e.x&&this.y===e.y}copy(e){return this.x=e.x,this.y=e.y,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}length2(){return this.x*this.x+this.y*this.y}addA(e){return this.x+=e.x,this.y+=e.y,this}add(e){return new ae(this.x+e.x,this.y+e.y)}subA(e){return this.x-=e.x,this.y-=e.y,this}sub(e){return new ae(this.x-e.x,this.y-e.y)}scale(e){return this.x*=e,this.y*=e,this}scaleTo(e){return new ae(this.x*e,this.y*e)}mulA(e){return this.x*=e.x,this.y*=e.y,this}mul(e){return new ae(this.x*e.x,this.y*e.y)}divA(e){return this.x/=e.x,this.y/=e.y,this}dot(e){return e.x*this.x+e.y*this.y}dotArr(e){return e[0]*this.x+e[1]*this.y}cross(e){return this.x*e.y-this.y*e.x}clear(){return this.x=this.y=0,this}normal(){return this.getNormal()}getNormal(){let e=new ae;e.copy(this);let t=1/e.length();return e.x*=t,e.y*=t,e}normalize(){let e=1/this.length();return this.x*=e,this.y*=e,this}toVec(){return[this.x,this.y]}distance(e){return ae.sub(this,e).length()}set(e,t){return this.x=e,this.y=t,this}negate(){return this.x=-this.x,this.y=-this.y,this}negateTo(){return new ae(-this.x,-this.y)}projToRay(e,t){let i=ae.proj_b_to_a(ae.sub(this,e),t);return i.add(e),i}angle(e){return ae.angle(this,e)}lerp(e,t,i){let s=this.clone();return i<=0?s.copy(e):i>=1?s.copy(t):s=ae.add(e,ae.sub(t,e).scale(i)),s}static get LERP_DELTA(){return 1e-6}slerp(e,t){let i,s,n,r,o=new ae;if(t<=0)return o.copy(this),o;if(t>=1)return o.copy(e),o;let a=this.dot(e);return 1-a>ae.LERP_DELTA?(i=Math.acos(a),s=Math.sin(i),n=Math.sin((1-t)*i)/s,r=Math.sin(t*i)/s):(n=1-t,r=t),ae.add(this.scale(n),e.scale(r))}isZero(){return!(this.x||this.y)}}const le={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4","indianred ":"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgrey:"#d3d3d3",lightgreen:"#90ee90",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370d8",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#d87093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};class he{constructor(e=1,t=1){this._a=e,this._b=t,this._flattening=(e-t)/e,this._f=1/this._flattening,this._a2=e*e,this._b2=t*t;const i=Math.sqrt(this._a2-this._b2);this._e=i/e,this._e2=this._e*this._e,this._e22=this._e2*this._e2,this._k=i/t,this._k2=this._k*this._k,this._radii=new oe(e,e,t),this._radii2=new oe(this._a2,this._a2,this._b2),this._invRadii=new oe(1/e,1/e,1/t),this._invRadii2=new oe(1/this._a2,1/this._a2,1/this._b2)}rhumbDistanceTo(e,t){const i=e.lat*l,s=t.lat*l,n=s-i;let r=Math.abs(t.lon-e.lon)*l;Math.abs(r)>Math.PI&&(r=r>0?-(2*Math.PI-r):2*Math.PI+r);const o=Math.log(Math.tan(s/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),a=Math.abs(o)>1e-11?n/o:Math.cos(i);return Math.sqrt(n*n+a*a*r*r)*this._a}getIntermediatePointOnGreatCircle(e,t,i){if(0==i)return e.clone();if(1==i)return t.clone();const s=this.inverse(e,t),n=s.distance,r=s.initialAzimuth;return isNaN(r)?e:this.getGreatCircleDestination(e,r,n*i)}static getBearing(e,t){let i=e.lat*l,s=e.lon*l,n=t.lat*l,r=t.lon*l,o=Math.sin(r-s)*Math.cos(n),a=Math.cos(i)*Math.sin(n)-Math.sin(i)*Math.cos(n)*Math.cos(r-s);return Math.atan2(o,a)*h}getFlattening(){return this._flattening}getEquatorialSize(){return this._a}get equatorialSize(){return this._a}get equatorialSizeSqr(){return this._a2}getPolarSize(){return this._b}get polarSize(){return this._b}get polarSizeSqr(){return this._b2}lonLatToCartesian(e){return this.geodeticToCartesian(e.lon,e.lat,e.height)}lonLatToCartesianRes(e,t){return this.geodeticToCartesian(e.lon,e.lat,e.height,t)}geodeticToCartesian(e,t,i=0,s=new oe){let n=l*t,r=l*e,o=Math.sin(n),a=this._a/Math.sqrt(1-this._e2*o*o),h=(a+i)*Math.cos(n);return s.x=h*Math.cos(r),s.y=h*Math.sin(r),s.z=(a*(1-this._e2)+i)*o,s}projToSurface(e){let t=e.x||0,i=e.y||0,s=e.z||0,n=Math.sqrt(t*t+i*i+s*s);if(0===n)return this.lonLatToCartesian(new I);let r=this._invRadii2.x,o=this._invRadii2.y,a=this._invRadii2.z,l=t*t*r,h=i*i*o,c=s*s*a,d=l+h+c,_=Math.sqrt(1/d),u=e.scaleTo(_);if(d<.1)return Number.isFinite(_)?u:new oe;let g=(1-_)*n/u.mulA(this._invRadii2).length(),p=0,m=0,v=0;for(;;){p=1/(1+g*r),m=1/(1+g*o),v=1/(1+g*a);let e=p*p,t=m*m,i=v*v,s=l*e+h*t+c*i-1;if(Math.abs(s)<f)break;g+=.5*s/(l*(e*p)*r+h*(t*m)*o+c*(i*v)*a)}return new oe(t*p,i*m,s*v)}cartesianToLonLat(e){return this.cartesianToLonLatRes(e)}cartesianToLonLatRes(e,t=new I){let i=this.projToSurface(e),s=this.getSurfaceNormal3v(i),n=e.sub(i);return t.lon=Math.atan2(s.y,s.x)*h,t.lat=Math.asin(s.z)*h,t.height=Math.sign(n.dot(e))*n.length(),t}getSurfaceNormal3v(e){let t=this._invRadii2,i=e.x*t.x,s=e.y*t.y,n=e.z*t.z,r=1/Math.sqrt(i*i+s*s+n*n);return new oe(i*r,s*r,n*r)}getGreatCircleDistance(e,t){return this.inverse(e,t).distance}getGreatCircleDestination(e,t,i){return this.direct(e,t,i).destination}inverse(e,t){let i=this._a,s=this._b,n=this._flattening;const r=e.lat*l,o=e.lon*l,a=t.lat*l,c=t.lon*l-o,d=(1-n)*Math.tan(r),_=1/Math.sqrt(1+d*d),u=d*_,g=(1-n)*Math.tan(a),p=1/Math.sqrt(1+g*g),m=g*p,v=Math.abs(c)>Math.PI/2||Math.abs(a-r)>Math.PI/2;let y=c,x=null,b=null,C=v?Math.PI:0,T=0,E=v?-1:1,L=null,A=1,P=1,S=null,M=0;do{if(x=Math.sin(y),b=Math.cos(y),L=(p*x)**2+(_*m-u*p*b)**2,Math.abs(L)<1e-24)break;T=Math.sqrt(L),E=u*m+_*p*b,C=Math.atan2(T,E);const e=_*p*x/T;P=1-e*e,A=0!=P?E-2*u*m/P:0;const t=n/16*P*(4+n*(4-3*P));S=y,y=c+(1-t)*n*e*(C+t*T*(A+t*E*(2*A*A-1)))}while(Math.abs(y-S)>f&&++M<1e3);const R=P*(i*i-s*s)/(s*s),B=R/1024*(256+R*(R*(74-47*R)-128)),k=s*(1+R/16384*(4096+R*(R*(320-175*R)-768)))*(C-B*T*(A+B/4*(E*(2*A*A-1)-B/6*A*(4*T*T-3)*(4*A*A-3)))),I=Math.abs(L)<Number.EPSILON?0:Math.atan2(p*x,_*m-u*p*b),z=Math.abs(L)<Number.EPSILON?Math.PI:Math.atan2(_*x,-u*p+_*m*b);return{distance:k,initialAzimuth:Math.abs(k)<Number.EPSILON?NaN:w(I)*h,finalAzimuth:Math.abs(k)<Number.EPSILON?NaN:w(z)*h}}direct(e,t,i){let s=e.lon,n=e.lat,r=this._a,o=this._b,a=this._flattening,c=i,d=t*l,_=Math.sin(d),u=Math.cos(d),g=(1-a)*Math.tan(n*l),f=1/Math.sqrt(1+g*g),p=g*f,m=Math.atan2(g,u),v=f*_,y=1-v*v,x=y*(r*r-o*o)/(o*o),b=1+x/16384*(4096+x*(x*(320-175*x)-768)),w=x/1024*(256+x*(x*(74-47*x)-128)),C=c/(o*b),T=2*Math.PI,E=0,L=0,A=0,P=0;for(;Math.abs(C-T)>1e-12;)E=Math.cos(2*m+C),L=Math.sin(C),A=Math.cos(C),P=w*L*(E+w/4*(A*(2*E*E-1)-w/6*E*(4*L*L-3)*(4*E*E-3))),T=C,C=c/(o*b)+P;let S=p*L-f*A*u,M=Math.atan2(p*A+f*L*u,(1-a)*Math.sqrt(v*v+S*S)),R=a/16*y*(4+a*(4-3*y)),B=Math.atan2(L*_,f*A-p*L*u)-(1-R)*a*v*(C+R*L*(E+R*A*(2*E*E-1))),k=Math.atan2(v,-S);return{destination:new I(s+B*h,M*h),finalAzimuth:k*h}}hitRay(e,t){let i,s,n,r,o,a=this._invRadii.mul(e),l=this._invRadii.mul(t),h=a.dot(a),c=a.dot(l);if(h>1){if(c>=0)return;var d=c*c;if(i=h-1,s=l.dot(l),n=s*i,Math.abs(d-n)>1e-15&&d<n)return;if(d>n){r=c*c-n,o=-c+Math.sqrt(r);var _=o/s,u=i/o;return _<u?e.add(t.scaleTo(_)):e.add(t.scaleTo(u))}var g=Math.sqrt(i/s);return e.add(t.scaleTo(g))}return h<1?(i=h-1,s=l.dot(l),n=s*i,r=c*c-n,o=-c+Math.sqrt(r),e.add(t.scaleTo(o/s))):c<0?(s=l.dot(l),e.add(t.scaleTo(-c/s))):void 0}getNorthFrameRotation(e){let t=this.getSurfaceNormal3v(e),i=oe.proj_b_to_plane(oe.NORTH,t);return re.getLookRotation(i,t)}getBearingDestination(e,t=0,i=0){t*=l;var s=(e.lon+540)%360-180,n=e.lat*l,r=s*l,o=i/this._a,a=Math.asin(Math.sin(n)*Math.cos(o)+Math.cos(n)*Math.sin(o)*Math.cos(t));return new I((r+Math.atan2(Math.sin(t)*Math.sin(o)*Math.cos(n),Math.cos(o)-Math.sin(n)*Math.sin(a)))*h,a*h)}static getIntermediatePointOnGreatCircle(e,t,i){var s=e.lat*l,n=e.lon*l,r=t.lat*l,o=t.lon*l,a=Math.sin(s),c=Math.cos(s),d=Math.sin(n),_=Math.cos(n),u=Math.sin(r),g=Math.cos(r),f=Math.sin(o),p=Math.cos(o),m=r-s,v=o-n,y=Math.sin(m/2)*Math.sin(m/2)+Math.cos(s)*Math.cos(r)*Math.sin(v/2)*Math.sin(v/2),x=2*Math.atan2(Math.sqrt(y),Math.sqrt(1-y)),b=Math.sin((1-i)*x)/Math.sin(x),w=Math.sin(i*x)/Math.sin(x),C=b*c*_+w*g*p,T=b*c*d+w*g*f,E=b*a+w*u,L=Math.atan2(E,Math.sqrt(C*C+T*T)),A=Math.atan2(T,C);return new I((A*h+540)%360-180,L*h)}static getRhumbBearing(e,t){var i=(t.lon-e.lon)*l,s=Math.log(Math.tan(t.lat*l/2+Math.PI/4)/Math.tan(e.lat*l/2+Math.PI/4));return Math.abs(i)>Math.PI&&(i=i>0?-1*(2*Math.PI-i):2*Math.PI+i),(Math.atan2(i,s)*h+360)%360}getLonLatVisibilitySimple(e,t,i){const s=this.lonLatToCartesian(t),n=t.height,r=this.polarSize+n,o=Math.max(e.length()-this.polarSize,0),a=s.sub(e);let l;return l=o>0?Math.sqrt((r+o)**2-r**2):r,l>a.length()&&(!i||i.dot(a.normalize())>0)}}const ce=new he(6378137,6356752.314245179);function de(e,t){return null!=e?e:t}function _e(e){return null==e}function ue(e){return void 0===e}let ge=0;function fe(e){let t=e._openglobus_id;return t||(t=e._openglobus_id=++ge),t}function pe(e){return"string"==typeof e||e instanceof String}function me(e){return e.toString(16).padStart(2,"0")}function ve(e){let t,i,s;return e instanceof Array?(t=me(e[0]),i=me(e[1]),s=me(e[2])):(t=me(e.x),i=me(e.y),s=me(e.z)),`#${t}${i}${s}`}function ye(e,t){let i=le[e];if(i&&(e=i),"#"===e[0]){let i=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,s=e.replace(i,(function(e,t,i,s){return t+t+i+i+s+s})),n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(s);return n?new se(parseInt(n[1],16)/255,parseInt(n[2],16)/255,parseInt(n[3],16)/255,_e(t)?1:t):new se}{_e(t)&&(t=1);let i=e.split(",");return new se(parseInt(i[0].split("(")[1])/255,parseInt(i[1])/255,parseInt(i[2])/255,_e(i[3])?t:parseFloat(i[3]))}}function xe(e,t){let i=ye(e,t);return new Float32Array([i.x,i.y,i.z,i.w])}function be(e){let t=le[e];if(t&&(e=t),"#"===e[0]){let t=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,i=e.replace(t,(function(e,t,i,s){return t+t+i+i+s+s})),s=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(i);return s?new oe(parseInt(s[1],16)/255,parseInt(s[2],16)/255,parseInt(s[3],16)/255):new oe}{let t=e.split(",");return new oe(parseInt(t[0].split("(")[1])/255,parseInt(t[1])/255,parseInt(t[2])/255)}}function we(e,t){return e.replace(/{[^{}]+}/g,(function(e){return t[e.replace(/[{}]+/g,"")]||""}))}function Ce(e){let t=document.createElement("div");t.innerHTML=e;let i=[];for(let e=0;e<t.childNodes.length;e++)i.push(t.childNodes[e]),t.removeChild(t.childNodes[e]);return i}function Te(e,t,i,s){let n=document.getElementById(e);n||(n=document.createElement("div"),n.id=e,n.classList.add("defaultText"),document.body.appendChild(n)),n.innerHTML=t,n.style.left=`${i}px`,n.style.top=`${s}px`}function Ee(e){return"number"==typeof e}function Le(e,t=""){return e?e.trim():t}function Ae(e,t){if(e){if(Ee(e))return new oe(e,e,e);if(e instanceof oe)return e.clone();if(e instanceof Array)return oe.fromVec(e);if(e instanceof ae)return new oe(e.x,e.y,0)}else if(t)return t;return new oe}function Pe(e,t){if(e){if(pe(e))return ye(e);if(e instanceof Array)return se.fromVec(e);if(e instanceof se)return e.clone()}else if(t)return t;return new se(1,1,1,1)}function Se(e,t){if(e){if(pe(e))return be(e);if(e instanceof Array)return oe.fromVec(e);if(e instanceof oe)return e.clone()}else if(t)return t;return new oe(1,1,1)}function Me(e,t){if(e){if(e instanceof Array)return new te(Re(e[0]),Re(e[1]));if(e instanceof te)return e.clone()}else if(t)return t;return new te}function Re(e,t){if(e){if(e instanceof Array)return new I(e[0],e[1],e[2]);if(e instanceof I)return e.clone()}else if(t)return t;return new I}function Be(e,t){let i=0,s=e.length-1;for(;i<=s;){let n=Math.floor(.5*(i+s));if(Math.abs(e[n]-t)<.001)return n;e[n]<t?i=n+1:s=n-1}return-1}function ke(e,t,i){let s=0,n=e.length-1;for(;s<=n;){let r=n+s>>1,o=i(t,e[r],r);if(o>0)s=r+1;else{if(!(o<0))return r;n=r-1}}return-s-1}function Ie(e,t,i){let s=ke(e,t,i);return s<0&&(s=~s),e.splice(s,0,t),s}function ze(e,t,i,s,n=!1){let r=new I(t.lon-e.lon,t.lat-e.lat),o=new I(s.lon-i.lon,s.lat-i.lat),a=-r.lat,l=+r.lon,h=-(a*e.lon+l*e.lat),c=-o.lat,d=+o.lon,_=-(c*i.lon+d*i.lat),u=c*e.lon+d*e.lat+_,g=c*t.lon+d*t.lat+_,f=a*i.lon+l*i.lat+h,p=a*s.lon+l*s.lat+h;if(n&&(u*g>0||f*p>0))return;let m=u/(u-g);return new I(e.lon+m*r.lon,e.lat+m*r.lat)}const De={string:function(e){return _e(e)?e:e.toString()},date:function(e){return _e(e)?e:new Date(1e3*e)},datetime:function(e){return _e(e)?e:new Date(1e3*e)},time:function(e){return _e(e)?e:parseInt(e)},integer:function(e){return _e(e)?e:parseInt(e)},float:function(e){return _e(e)?e:parseFloat(e)},boolean:function(e){if(null===e)return e;if("boolean"==typeof e)return!0===e;if("string"==typeof e){if(""===e)return!1;if("true"===(e=e.replace(/^\s+|\s+$/g,"")).toLowerCase()||"yes"===e.toLowerCase())return!0;e=(e=e.replace(/,/g,".")).replace(/^\s*\-\s*/g,"-")}return!isNaN(e)&&0!==parseFloat(e)}};function Fe(e,t=""){let i=1024,s=atob(e),n=s.length,r=Math.ceil(n/i),o=new Array(r);for(let e=0;e<r;++e){let t=e*i,r=Math.min(t+i,n),a=new Array(r-t);for(let e=t,i=0;e<r;++i,++e)a[i]=s[e].charCodeAt(0);o[e]=new Uint8Array(a)}return new Blob(o,{type:t})}function Ne(e,t,i=!1){let s,n=0;return function(){const r=arguments;n?(i&&clearTimeout(s),s=setTimeout((()=>{Date.now()-n>=t&&(e.apply(null,r),n=Date.now())}),t-(Date.now()-n))):(e.apply(null,r),n=Date.now())}}function He(e,t){let i=new e.constructor(e.length+t.length);return i.set(e,0),i.set(t,e.length),i}function Oe(e=[],t=[]){if(ArrayBuffer.isView(e))return He(e,t);for(let i=0;i<t.length;i++)e.push(t[i]);return e}function Ve(e,t=Float32Array){if(ArrayBuffer.isView(e))return e;{const i=new t(e.length);return i.set(e,0),i}}function Ue(e){return ArrayBuffer.isView(e)?Array.from(e):e}function Ge(e,t,i,s){if(ArrayBuffer.isView(e))return t<0&&(i=Math.abs(t),t+=e.length),Ye(e,t,i,s);{let n;return n=t<0?e.splice(t):e.splice(t,i),s&&(s.result=n),e}}function Ye(e,t,i,s){if(0===e.length)return e;const n=e.length-i,r=new e.constructor(n);return r.set(e.subarray(0,t)),r.set(e.subarray(t+i),t),s&&(s.result=e.subarray(t,t+i)),r}function je(e,t,i,s,n){const r=n+1,o=i+r,a=s+r;let l=new Float64Array(r*r*3),h=0;for(let n=i;n<o;n++)for(let i=s;i<a;i++){let s=3*(n*(t+1)+i);l[h++]=e[s],l[h++]=e[s+1],l[h++]=e[s+2]}return l}function We(e,t,i,s,n){const r=n+1,o=i+r,a=s+r;let l=new Float32Array(r*r*3),h=0;for(let n=i;n<o;n++)for(let i=s;i<a;i++){let s=3*(n*(t+1)+i);l[h++]=e[s],l[h++]=e[s+1],l[h++]=e[s+2]}return l}function qe(e,t,i,s,n,r,o,a,l,h,c,d,_){const u=r+a+1,g=o+a+1;n+=1;let f=0,p=0;for(let a=r;a<u;a++)for(let r=o;r<g;r++){let o=a*n+r,u=3*o,g=e[u],m=e[u+1],v=e[u+2];s&&0!==s[o]?_[p]=1:(g<d.xmin&&(d.xmin=g),g>d.xmax&&(d.xmax=g),m<d.ymin&&(d.ymin=m),m>d.ymax&&(d.ymax=m),v<d.zmin&&(d.zmin=v),v>d.zmax&&(d.zmax=v)),p++,l[f]=g,c[f]=i[u],h[f++]=t[u],l[f]=m,c[f]=i[u+1],h[f++]=t[u+1],l[f]=v,c[f]=i[u+2],h[f++]=t[u+2]}}function $e(e){return e.map((e=>Array.isArray(e)?$e(e):e))}async function Xe(e){return new Promise((t=>{const i=new Image;return i.addEventListener("load",(()=>{t(i)})),i.src=e,i.crossOrigin="",i}))}function Ze(e){return e.complete&&0!==e.naturalHeight}function Ke(e){if(e>1e3){return 0!==e-Math.floor(e)?[(e/1e3).toFixed(2),"km"]:[(e/1e3).toFixed(0),"km"]}return e>9?[Math.round(e).toString(),"m"]:e<=.01?["0","m"]:[e.toFixed(1),"m"]}function Qe(e){let t=new URLSearchParams(location.search).get(e);if(t)return Number(t)}function Je(e,t=-1){if(t<0)return e.toString();const i=Math.pow(10,t);return(Math.round(e*i)/i).toString()}var et=Object.freeze({__proto__:null,base64StringToBlog:function(e){let t=e.split(";"),i=t[0].split(":")[1];return Fe(t[1].split(",")[1],i)},base64toBlob:Fe,binaryInsert:Ie,binarySearch:ke,binarySearchFast:Be,blerp:function(e,t,i,s,n,r,o=0,a=1,l=0,h=1){return(i*(a-e)*(h-t)+s*(e-o)*(h-t)+n*(a-e)*(t-l)+r*(e-o)*(t-l))/((a-o)*(h-l))},blerp2:function(e,t,i,s,n,r){return i*(1-e)*(1-t)+s*e*(1-t)+n*(1-e)*t+r*e*t},castType:De,cloneArray:$e,concatArrays:Oe,concatTypedArrays:He,createColorRGB:Se,createColorRGBA:Pe,createExtent:Me,createLonLat:Re,createVector3:Ae,createVector4:function(e,t){if(e){if(e instanceof se)return e.clone();if(e instanceof Array)return se.fromVec(e)}else if(t)return t;return new se},defaultString:Le,distanceFormat:function(e){return e>1e3?`${(e/1e3).toFixed(2)} km`:e>9?`${Math.round(e)} m`:`${e.toFixed(1)} m`},distanceFormatExt:Ke,extractElevationTiles:function(e,t,i){let s=Math.sqrt(t.length)-1,n=s+1,r=Math.sqrt(e.length/4),o=r/s,a=0,l=0;for(let h=0,c=0,d=e.length/4;h<d;h++){let d=e[4*h],_=Math.floor(h/r),u=h%r,g=Math.floor(u/s),f=Math.floor(_/s),p=i[f][g],m=_%s,v=u%s,y=(m+f)*n+v+g;if(p[y]=d,(_+f)%o==0&&(u+g)%o==0&&(t[c++]=d),(u+1)%s==0&&u!==r-1){a=e[4*(h+1)];let r=.5*(d+a);y=(m+f)*n+v+1,p[y]=r,(_+f)%o==0&&(t[c++]=r);let l=(m+f)*n+(v+1)%s;i[f][g+1][l]=r}if((_+1)%s==0&&_!==r-1){l=e[4*(h+r)];let a=.5*(d+l);y=(m+1)*n+v+g,p[y]=a,(u+g)%o==0&&(t[c++]=a);let _=(m+1)%s*n+v+g;i[f+1][g][_]=a}if((u+1)%s==0&&u!==r-1&&(_+1)%s==0&&_!==r-1){let o=.25*(d+a+l+e[4*(h+r+1)]);y=(m+1)*n+(v+1),p[y]=o,t[c++]=o;let _=(m+1)*n;i[f][g+1][_]=o;let u=s;i[f+1][g][u]=o;let x=0;i[f+1][g+1][x]=o}}},getDefault:de,getHTML:function(e,t){return we(e,t)},getLinesIntersection2v:function(e,t,i,s,n){let r=t.sub(e),o=s.sub(i),a=-r.y,l=+r.x,h=-(a*e.x+l*e.y),c=-o.y,d=+o.x,_=-(c*i.x+d*i.y),u=c*e.x+d*e.y+_,g=c*t.x+d*t.y+_,f=a*i.x+l*i.y+h,p=a*s.x+l*s.y+h;if(n&&(u*g>0||f*p>0))return;let m=u/(u-g);return new ae(e.x+m*r.x,e.y+m*r.y)},getLinesIntersectionLonLat:ze,getMatrixSubArray32:We,getMatrixSubArray64:je,getMatrixSubArrayBoundsExt:qe,getTileImageResolution:function(e,t,i,s=256,n=ce){let r=K(e,t,i),o=r.getSouthWest().inverseMercator(),a=r.getNorthEast().inverseMercator();return[n.getGreatCircleDistance(o,new I(a.lon,o.lat))/s,n.getGreatCircleDistance(o,new I(o.lon,a.lat))/s]},getUrlParam:Qe,htmlColorToFloat32Array:xe,htmlColorToRgb:be,htmlColorToRgba:ye,isEmpty:_e,isImageLoaded:Ze,isNumber:Ee,isString:pe,isUndef:ue,isUndefExt:function(e,t){return ue(e)?t:e},loadImage:Xe,makeArray:Ue,makeArrayTyped:Ve,parseHTML:Ce,print2d:Te,rgbToStringHTML:ve,spliceArray:Ge,spliceTypedArray:Ye,stamp:fe,stringTemplate:we,throttle:Ne,toFixedMax:Je,xmlToJson:function e(t){let i={};if(1===t.nodeType){if(t.attributes.length>0){i["@attributes"]={};for(let e=0;e<t.attributes.length;e++){let s=t.attributes.item(e);i["@attributes"][s.nodeName]=s.nodeValue}}}else 3===t.nodeType&&(i=t.nodeValue);if(t.hasChildNodes())for(let s=0;s<t.childNodes.length;s++){let n=t.childNodes.item(s),r=n.nodeName;if(void 0===i[r])i[r]=e(n);else{if(void 0===i[r].push){let e=i[r];i[r]=[],i[r].push(e)}i[r].push(e(n))}}return i}});const tt=.001,it=1e3,st=60,nt=1/st,rt=1/24,ot=3600,at=1/ot,lt=12*ot,ht=1440,ct=1/ht,dt=86400,_t=864e5,ut=1.1574074074074074e-8,gt=1/dt,ft=2451545;function pt(e,t,i){let s=(t-14)/12|0,n=e+4800+s;return(1461*n/4|0)+(367*(t-2-12*s)/12|0)-(3*((n+100)/100|0)/4|0)+i-32075}function mt(e){let t=pt(e.getUTCFullYear(),e.getUTCMonth()+1,e.getUTCDate()),i=e.getUTCHours()-12;i<0&&(i+=24);let s=e.getUTCSeconds()+i*ot+e.getUTCMinutes()*st+e.getUTCMilliseconds()*tt;s>=lt&&t--;let n=s*gt|0;return t+=n,s-=dt*n,s<0&&(t--,s+=dt),t+s*gt}function vt(e){let t=Tt,i=ke(t,e,(function(e,t){return e-t.jd}));i<0&&(i=~i),i>=t.length&&(i=t.length-1);let s=t[i].leapSeconds;return 0!==i&&(t[i].jd-e)*dt>s&&(s=t[i-1].leapSeconds),e+s*gt}function yt(e){let t=Tt,i=ke(t,e,(function(e,t){return e-t.jd}));if(i<0&&(i=~i),i>=t.length)return e-t[i-1].leapSeconds*gt;if(0===i)return e-t[0].leapSeconds*gt;let s=(t[i].jd-e)*dt;return 0===s?e-t[i].leapSeconds*gt:s<=1?void 0:e-t[i-1].leapSeconds*gt}function xt(e){let t=0|e,i=(e-t)*dt;i>=lt&&t++;let s=t+68569|0,n=4*s/146097|0;s=s-((146097*n+3)/4|0)|0;let r=4e3*(s+1)/1461001|0;s=s-(1461*r/4|0)+31|0;let o=80*s/2447|0,a=s-(2447*o/80|0)|0;s=o/11|0;let l=o+2-12*s|0,h=100*(n-49)+r+s|0,c=i*at|0,d=i-c*ot,_=d*nt|0;d-=_*st;let u=0|d,g=(d-u)*it|0;return c+=12,c>23&&(c-=24),new Date(Date.UTC(h,l-1,a,c,_,u,g))}function bt(e,t){return e+t*ut}function wt(e,t){return e+t*gt}function Ct(e,t){return{jd:e,leapSeconds:t}}const Tt=[Ct(2441317.5,10),Ct(2441499.5,11),Ct(2441683.5,12),Ct(2442048.5,13),Ct(2442413.5,14),Ct(2442778.5,15),Ct(2443144.5,16),Ct(2443509.5,17),Ct(2443874.5,18),Ct(2444239.5,19),Ct(2444786.5,20),Ct(2445151.5,21),Ct(2445516.5,22),Ct(2446247.5,23),Ct(2447161.5,24),Ct(2447892.5,25),Ct(2448257.5,26),Ct(2448804.5,27),Ct(2449169.5,28),Ct(2449534.5,29),Ct(2450083.5,30),Ct(2450630.5,31),Ct(2451179.5,32),Ct(2453736.5,33),Ct(2454832.5,34),Ct(2456109.5,35),Ct(2457204.5,36)],Et=vt(ft);var Lt=Object.freeze({__proto__:null,DAYS_PER_JULIAN_CENTURY:36525,DAYS_PER_JULIAN_YEAR:365.25,DateToTAI:function(e){return vt(mt(e))},DateToUTC:mt,HOURS_PER_DAY:24,J2000:ft,J2000TAI:Et,MILLISECONDS_PER_DAY:_t,MILLISECONDS_PER_SECOND:it,MINUTES_PER_DAY:ht,MINUTES_PER_HOUR:60,MODIFIED_JULIAN_DATE_DIFFERENCE:2400000.5,ONE_BY_HOURS_PER_DAY:rt,ONE_BY_MILLISECONDS_PER_DAY:ut,ONE_BY_MINUTES_PER_DAY:ct,ONE_BY_SECONDS_PER_DAY:gt,ONE_BY_SECONDS_PER_HOUR:at,ONE_BY_SECONDS_PER_MINUTE:nt,PICOSECOND:1e-9,SECONDS_PER_12_HOURS:lt,SECONDS_PER_DAY:dt,SECONDS_PER_HOUR:ot,SECONDS_PER_MILLISECOND:tt,SECONDS_PER_MINUTE:st,T:function(e){return(e-ft)/36525},TAItoDate:function(e){let t=yt(e);return t||(t=yt(wt(e,-1)),console.trace(`TAItoDate - can't convert ${e.toString()} to utc.`)),xt(t)},TAItoUTC:yt,UTCtoDate:xt,UTCtoTAI:vt,addDays:function(e,t){return e+t},addHours:function(e,t){return e+t*rt},addMilliseconds:bt,addMinutes:function(e,t){return e+t*ht},addSeconds:wt,daysToSeconds:function(e){return e*dt},getDayNumber:pt,getDays:function(e){return 0|e},getHours:function(e){let t=(e-(0|e))*dt,i=t*at|0,s=t-i*ot,n=s*nt|0;s-=n*st;let r=0|s;return i+=12+n/60+r/3600+((s-r)*it|0)/1e3,i>23&&(i-=24),i},getMilliseconds:function(e){let t=e-(0|e);return t*=dt,(t-(0|t))*it|0},getMinutes:function(e){return(e-(0|e))*ht|0},getSeconds:function(e){return(e-(0|e))*dt},secondsToDays:function(e){return e*gt}});class At{constructor(e){this.vertices=[new oe,new oe,new oe,new oe,new oe,new oe,new oe,new oe],e&&this.setFromBoundsArr(e)}copy(e){for(let t=0,i=this.vertices.length;t<i;t++)this.vertices[t].copy(e.vertices[t])}setFromBoundsArr(e){let t=e[0],i=e[3],s=e[1],n=e[4],r=e[2],o=e[5],a=this.vertices;a[0].set(t,s,r),a[1].set(i,s,r),a[2].set(i,s,o),a[3].set(t,s,o),a[4].set(t,n,r),a[5].set(i,n,r),a[6].set(i,n,o),a[7].set(t,n,o)}setFromExtent(e,t){this.setFromBoundsArr(t.getCartesianBounds(e))}}class Pt{constructor(e=0,t){this.radius=e,this.center=t?t.clone():new oe}setFromBounds(e){let t=new oe(e[0],e[1],e[2]);this.center.set(t.x+.5*(e[3]-t.x),t.y+.5*(e[3]-t.y),t.z+.5*(e[5]-t.z)),this.radius=this.center.distance(t)}setFromExtent(e,t){this.setFromBounds(t.getCartesianBounds(e))}}var St=Object.freeze({__proto__:null,Box:At,Sphere:Pt});function Mt(e,t){return new Rt(e,t)}class Rt{constructor(e,t){this.__id=Rt.__counter__++,this._eventNames=[],e&&this.registerNames(e),this._sender=t||this,this._stopPropagation=!1,this._stampCache={}}bindSender(e){this._sender=e||this}registerNames(e){for(let t=0;t<e.length;t++)this[e[t]]={active:!0,handlers:[]},this._eventNames.push(e[t]);return this}_getStamp(e,t,i){return`${e}_${t}_${i}`}_stamp(e,t){let i=fe(t),s=this._getStamp(e,this.__id,i);return!this._stampCache[s]&&(this._stampCache[s]=i,!0)}on(e,t,i,s=0){if(this._stamp(e,t)&&this[e]){let n=t.bind(i||this._sender);n._openglobus_id=t._openglobus_id,n._openglobus_priority=s,Ie(this[e].handlers,n,((e,t)=>(t._openglobus_priority||0)-(e._openglobus_priority||0)))}}off(e,t){if(t){let i=this._getStamp(e,this.__id,t._openglobus_id);if(t._openglobus_id&&this._stampCache[i]){let s=this[e].handlers,n=s.length,r=-1;for(;n--;){if(s[n]._openglobus_id===t._openglobus_id){r=n;break}}-1!==r&&(s.splice(r,1),this._stampCache[i]=void 0,delete this._stampCache[i])}}}dispatch(e,...t){let i=!0;if(e&&e.active&&!this._stopPropagation){let s=e.handlers.slice(0),n=s.length;for(;n--;)!1===s[n](...t)&&(i=!1)}return this._stopPropagation=!1,i}stopPropagation(){this._stopPropagation=!0}clear(){for(let e=0;e<this._eventNames.length;e++){let t=this[this._eventNames[e]];t.handlers.length=0,t.handlers=[]}this._eventNames.length=0,this._eventNames=[]}}Rt.__counter__=0;const Bt=["render"];class kt{constructor(e={}){this.__id=kt.__counter__++,this.events=Mt(Bt),this.model=e.model||null,this.template=e.template||"",this.parent=e.parent||null,this._classList=e.classList||[],this.el=null}on(e,t,i,s){this.events.on(e,t,i,s)}off(e,t){this.events.off(e,t)}static getHTML(e,t){return we(e,t)}static parseHTML(e){return Ce(e)}static insertAfter(e,t){Array.isArray(e)||(e=[e]);for(let i=0;i<e.length;i++)t.parentNode&&t.parentNode.insertBefore(e[i],t.nextSibling);return e}static insertBefore(e,t){Array.isArray(e)||(e=[e]);for(let i=0;i<e.length;i++)t.parentNode&&t.parentNode.insertBefore(e[i],t);return e}insertBefore(e){this.el||this.render(),this.el&&(e instanceof HTMLElement&&e.parentNode&&kt.insertBefore(this.el,e),e instanceof kt&&e.el&&e.el.parentNode&&kt.insertBefore(this.el,e.el))}insertAfter(e){this.el||this.render(),this.el&&(e instanceof HTMLElement&&e.parentNode&&kt.insertAfter(this.el,e),e instanceof kt&&e.el&&e.el.parentNode&&kt.insertAfter(this.el,e.el))}isEqual(e){return e.__id===this.__id}appendTo(e,t=!1,i=!1){return e&&(this.el||(this.beforeRender(e),this.render()),this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el),t&&(e.innerHTML=""),this.el&&(i&&e.childNodes[0]?kt.insertBefore(this.el,e.childNodes[0]):e.appendChild(this.el)),this.afterRender(e)),this}afterRender(e){}beforeRender(e){}stopPropagation(){this.events.stopPropagation()}renderTemplate(e){return kt.parseHTML(kt.getHTML(this.template,e||{}))[0]}render(e){this.el=this.renderTemplate(e);for(let e=0,t=this._classList.length;e<t;e++)this.el.classList.add(this._classList[e]);return this.events.dispatch(this.events.render,this),this}select(e){return this.el?this.el.querySelector(e):null}selectRemove(e){if(this.el){let t=this.select(e);if(t&&t.parentNode)return t.parentNode.removeChild(t),t}}selectAll(e,t){if(this.el){const i=this.el.querySelectorAll(e);if(t)for(let e=0,s=i.length;e<s;e++)t(i[e],e);return i}}remove(){this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el)}}kt.__counter__=0;const It=["click","mousedown","mouseup","touchstart","touchend","touchcancel"];class zt extends kt{constructor(e={}){super({template:we('<div class="og-button" title="{title}">\n <div class="og-button-icon">{icon}</div>\n <div class="og-button-text">{text}</div>\n </div>',{icon:e.icon||"",text:e.text||"",title:e.title||""}),...e}),this._onMouseDown=e=>{e.preventDefault(),this.events.dispatch(this.events.mousedown,this,e)},this._onMouseUp=e=>{e.preventDefault(),this.events.dispatch(this.events.mouseup,this,e)},this._onTouchStart=e=>{e.preventDefault(),this.events.dispatch(this.events.touchstart,this,e)},this._onTouchEnd=e=>{e.preventDefault(),this.events.dispatch(this.events.touchend,this,e)},this._onTouchCancel=e=>{e.preventDefault(),this.events.dispatch(this.events.touchcancel,this,e)},this._onMouseClick=e=>{this._mouseClickHandler(e)},this.events=this.events.registerNames(It),this.el=null,this.name=e.name||"",this.$icon=null,this.$text=null}render(e){return super.render(e),this.$icon=this.select(".og-button-icon"),this.$text=this.select(".og-button-text"),this.el.__og_button__=this,this._initEvents(),this}_initEvents(){this.el&&(this.el.addEventListener("click",this._onMouseClick),this.el.addEventListener("mousedown",this._onMouseDown),this.el.addEventListener("mouseup",this._onMouseUp),this.el.addEventListener("touchstart",this._onTouchStart),this.el.addEventListener("touchend",this._onTouchEnd),this.el.addEventListener("touchcancel",this._onTouchCancel))}_mouseClickHandler(e){e.preventDefault(),this.events.dispatch(this.events.click,this,e)}remove(){this._clearEvents(),super.remove()}_clearEvents(){this.el&&this.el.removeEventListener("click",this._onMouseClick)}}class Dt{constructor(e={}){this.__id=Dt.__counter__++,this._name=e.name||`_control_${this.__id.toString()}`,this.planet=null,this._initialized=!1,this.renderer=null,this.autoActivate=e.autoActivate||!1,this._active=!1,this._deferredActive=!0}get name(){return this._name}oninit(){}onadd(){}onremove(){}onactivate(){}ondeactivate(){}addTo(e){e&&(this.renderer=e,e.controls[this.name]=this,this.onadd&&this.onadd(),e.isInitialized()&&!this._initialized&&(this._initialized=!0,this.oninit&&this.oninit(),this.autoActivate&&this.activate()))}remove(){this.deactivate(),this.onremove&&this.onremove();let e=this.renderer,t=this.name;if(!e)return;let i=e.controls[t];i&&this.isEqual(i)&&delete e.controls[t],this.renderer=null,this._active=!1,this._initialized=!1}activate(){this._active||(this._initialized||(this._initialized=!0,this.oninit&&this.oninit()),this._deferredActive?(this._active=!0,this.onactivate&&this.onactivate()):this._deferredActive=!0)}deactivate(){this._active?(this._active=!1,this.ondeactivate&&this.ondeactivate()):this._initialized||(this._deferredActive=!1)}isActive(){return this._active}isEqual(e){return e.__id===this.__id}}Dt.__counter__=0;class Ft extends Dt{constructor(e={}){super(e),this._heading=0,this._svg=null}oninit(){let e=new zt({classList:["og-map-button","og-compass-button"],icon:'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg\n xmlns:dc="http://purl.org/dc/elements/1.1/"\n xmlns:cc="http://creativecommons.org/ns#"\n xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\n xmlns:svg="http://www.w3.org/2000/svg"\n xmlns="http://www.w3.org/2000/svg"\n xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"\n xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"\n viewBox="0 0 110.6 110.3"\n version="1.1"\n id="svg21"\n sodipodi:docname="aaa.svg"\n inkscape:version="0.92.3 (2405546, 2018-03-11)">\n <metadata\n id="metadata11">\n <rdf:RDF>\n <cc:Work\n rdf:about="">\n <dc:format>image/svg+xml</dc:format>\n <dc:type\n rdf:resource="http://purl.org/dc/dcmitype/StillImage" />\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs\n id="defs25" />\n <sodipodi:namedview\n pagecolor="#ffffff"\n bordercolor="#666666"\n borderopacity="1"\n objecttolerance="10"\n gridtolerance="10"\n guidetolerance="10"\n inkscape:pageopacity="0"\n inkscape:pageshadow="2"\n inkscape:window-width="1920"\n inkscape:window-height="1001"\n id="namedview23"\n showgrid="false"\n inkscape:zoom="9.4900968"\n inkscape:cx="28.376998"\n inkscape:cy="60.17054"\n inkscape:window-x="-9"\n inkscape:window-y="-9"\n inkscape:window-maximized="1"\n inkscape:current-layer="svg21" />\n <g\n id="Layer_2"\n data-name="Layer 2"\n transform="matrix(1,0,0,-1,0,110.3)">\n <g\n id="Слой_1"\n data-name="Слой 1">\n <g\n id="_Group_"\n data-name="<Group>">\n <g\n id="_Group_7"\n data-name="<Group>">\n <polygon\n id="_Path_7"\n data-name="<Path>"\n points="55.2,97.6 55.3,97.4 55.3,97.6 55.3,97.2 65.3,55.1 55.3,55.1 55.2,55.1 45.3,55.1 55.2,97.2 "\n style="fill:#ff2b45" />\n <polygon\n id="_Path_8"\n data-name="<Path>"\n points="55.3,12.7 55.3,12.9 55.2,12.7 55.2,13.1 45.3,55.1 55.2,55.1 55.3,55.1 65.3,55.1 55.3,13.1 "\n style="fill:#cecece;" />\n </g>\n </g>\n </g>\n </g>\n</svg>'});e.appendTo(this.renderer.div),e.events.on("click",this._onClick,this),this._svg=e.select("svg"),this.renderer.events.on("draw",this._draw,this)}_onClick(){const e=this.planet;let t=e.getCartesianFromPixelTerrain(this.renderer.handler.getCenter());t?e.flyCartesian(t.normal().scaleTo(t.length()+t.distance(e.camera.eye)),null,null,0,null,null,(()=>{e.camera.look(t)})):e.flyCartesian(e.camera.eye)}_draw(){this.setHeading(this.planet.camera.getHeading())}setHeading(e){this._heading!==e&&(this._heading=e,this._svg.style.transform=`rotateZ(${-e}deg)`)}}const Nt='<svg className="svg-icon" style="width: 1em; height: 1em;vertical-align: middle;fill: currentColor; overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">\n <path d="M777.856 280.192l-33.92-33.952-231.872 231.872-231.84-231.872-33.984 33.888 231.872 231.904-231.84 231.84 33.888 33.984 231.904-231.904 231.84 231.872 33.952-33.888-231.872-231.904z"/>\n</svg>',Ht=["resize","focus","visibility","dragstart","dragend"];class Ot extends kt{constructor(e={}){super({template:we('<div class="og-ddialog" \n style="display:{display}; resize:{resize}; width: {width}px; {height}; top: {top}px; left: {left}px; min-height: {minHeight}; max-height: {maxHeight}; min-width: {minWidth}; max-width: {maxWidth};">\n <div class="og-ddialog-header">\n <div class="og-ddialog-header__title">{title}</div> \n <div class="og-ddialog-header__buttons"></div> \n </div>\n <div class="og-ddialog-container"></div>\n </div>>',{title:e.title||"",display:de(e.visible,!0)?"flex":"none",resize:de(e.resizable,!0)?"both":"none",width:e.width||300,height:e.height?`height: ${e.height||200}px`:"",left:e.left||0,top:e.top||0,minHeight:e.minHeight?`${e.minHeight}px`:"unset",maxHeight:e.maxHeight?`${e.maxHeight}px`:"unset",minWidth:e.minWidth?`${e.minWidth}px`:"unset",maxWidth:e.maxWidth?`${e.maxWidth}px`:"unset"}),...e}),this._onCloseBtnClick=()=>{this.close()},this._onMouseDownAll=()=>{this.bringToFront()},this._onMouseDown=e=>{e.preventDefault(),this._startDragging(),this._startPosX=e.clientX,this._startPosY=e.clientY,document.addEventListener("mousemove",this._onMouseMove),document.addEventListener("mouseup",this._onMouseUp)},this._onMouseMove=e=>{e.preventDefault();let t=this._startPosX-e.clientX,i=this._startPosY-e.clientY;this._startPosX=e.clientX,this._startPosY=e.clientY,this.setPosition(this.el.offsetLeft-t,this.el.offsetTop-i)},this._onMouseUp=()=>{this._clearDragging(),document.removeEventListener("mouseup",this._onMouseUp),document.removeEventListener("mousemove",this._onMouseMove)},this.events=this.events.registerNames(Ht),this._startPosX=0,this._startPosY=0,this.$header=null,this.$title=null,this.$container=null,this.$buttons=null,this._closeBtn=new zt({icon:Nt,classList:["og-button-size__20"]}),this.useHide=e.useHide||!1,this._visibility=de(e.visible,!0),this._right=null!=e.right?e.right:null}setContainer(e){this.$container.innerHTML=e}get container(){return this.$container}get width(){return this.el?parseFloat(this.el.style.width):0}get height(){return this.el?parseFloat(this.el.style.height):0}bringToFront(){this.el.style.zIndex=String(Ot.__zIndex__++)}render(e){if(super.render(e),this.bringToFront(),this.$header=this.select(".og-ddialog-header"),this.$title=this.select(".og-ddialog-header__title"),this.$container=this.select(".og-ddialog-container"),this.$buttons=this.select(".og-ddialog-header__buttons"),this._initEvents(),this._initButtons(),null!=this._right){this.el.style.visibility="hidden";new IntersectionObserver(((e,t)=>{e.forEach((e=>{e.isIntersecting&&(this.el.style.visibility="visible",this.el.parentNode&&(this.setPosition(this.el.parentNode.clientWidth-this.el.clientWidth-this._right),t.disconnect()))}))})).observe(this.el)}return this}show(){this._visibility||(this._visibility=!0,this.el.style.display="flex",this.bringToFront(),this.events.dispatch(this.events.visibility,!0,this))}hide(){this._visibility&&(this._visibility=!1,this.el.style.display="none",this.events.dispatch(this.events.visibility,!1,this))}close(){this.useHide?this.hide():this.remove()}setVisibility(e){e?this.show():this.hide()}getVisibility(){return this._visibility}_initButtons(){this._closeBtn.events.on("click",this._onCloseBtnClick),this._closeBtn.appendTo(this.$buttons)}_initEvents(){this.$header.addEventListener("mousedown",this._onMouseDown),this.el.addEventListener("mousedown",this._onMouseDownAll)}setPosition(e,t){null!=e&&(this.el.style.left=`${e}px`),null!=t&&(this.el.style.top=`${t}px`)}_startDragging(){this.el.classList.contains("dragging")||(this.el.classList.add("dragging"),this.events.dispatch(this.events.dragstart,this))}_clearDragging(){this.el.classList.contains("dragging")&&(this.events.dispatch(this.events.dragend,this),this.el.classList.remove("dragging"))}remove(){this._clearDragging(),this._clearEvents(),super.remove()}_clearEvents(){this._closeBtn.events.off("click",this._onCloseBtnClick),document.removeEventListener("mouseup",this._onMouseUp),document.removeEventListener("mousemove",this._onMouseMove),this.$header.removeEventListener("mousedown",this._onMouseDown),this.el.removeEventListener("mousedown",this._onMouseDownAll)}}Ot.__zIndex__=0;const Vt=["change"];class Ut extends zt{constructor(e){super({...e}),this._onMouseClick=e=>{this.preventClick||(this._mouseClickHandler(e),this.setActive(!this.isActive))},this.events=this.events.registerNames(Vt),this._isActive=e.isActive||!1,this.preventClick=e.preventClick||!1}setActive(e,t=!1){e!==this._isActive&&(this._isActive=e,this._toggle(),t||this.events.dispatch(this.events.change,e,this))}_toggle(){this.el&&this.el.classList.toggle("og-button__active")}get isActive(){return this._isActive}render(e){return super.render(e),this._isActive&&this._toggle(),this}}const Gt=[2,3,0,1],Yt=[[-1,-1,0,1],[1,-1,3,-1],[2,3,-1,-1],[-1,0,-1,2]],jt=[[2,3,0,1],[1,0,3,2],[2,3,0,1],[1,0,3,2]],Wt=[[0,1,0,0],[1,0,0,0],[0,1,0,1],[1,1,1,1]];class qt{constructor(e,t){this.segment=e,this.layer=t,this.isReady=!1,this.isLoading=!1,this.texture=null,this.pickingMask=null,this.textureExists=!1,this.appliedNodeId=0,this.appliedNode=null,this.texOffset=[0,0,1,1],this.loadingAttempts=0,this._updateTexture=null,this._updatePickingMask=null,this.pickingReady=!1}abortLoading(){this.layer.abortMaterialLoading(this)}_createTexture(e){return this.layer._planet&&this.layer.createTexture(e,this.layer._internalFormat,this.isReady?this.texture:null)}applyImage(e){this.segment.initialized&&(this._updateTexture=null,this.texture=this._createTexture(e),this.isReady=!0,this.pickingReady=!0,this.textureExists=!0,this.isLoading=!1,this.appliedNodeId=this.segment.node.nodeId,this.texOffset=[0,0,1,1])}applyTexture(e,t){this.segment.initialized&&(this.texture=e,this._updateTexture=null,this.pickingMask=t||null,this._updatePickingMask=null,this.isReady=!0,this.pickingReady=!0,this.textureExists=!0,this.isLoading=!1,this.appliedNodeId=this.segment.node.nodeId,this.texOffset=[0,0,1,1])}textureNotExists(){this.segment.initialized&&(this.pickingReady=!0,this.isLoading=!1,this.isReady=!0,this.textureExists=!1)}clear(){this.loadingAttempts=0,this.layer.clearMaterial(this)}}class $t{constructor(e,t={}){if(this.isVector=!1,this.__id=$t.__counter__++,this._iconSrc=t.iconSrc||null,this.events=Mt(Xt,this),this.name=e||"noname",this.properties=t.properties||{},this.hideInLayerSwitcher=t.hideInLayerSwitcher||!1,this._hasImageryTiles=!0,this._opacity=null!=t.opacity?t.opacity:1,this.minZoom=t.minZoom||0,this.maxZoom=null!=t.maxZoom?t.maxZoom:50,this._planet=null,this.isVector=!1,this._attribution=t.attribution||"",this._zIndex=t.zIndex||0,this._isBaseLayer=t.isBaseLayer||!1,this._defaultTextures=t.defaultTextures||[null,null],this._visibility=void 0===t.visibility||t.visibility,this._fading=t.fading||!1,this._fadingFactor=this._opacity/30,this._fading?this._fadingOpacity=0:this._fadingOpacity=this._opacity,this._height=t.height||0,this._extent=new te,this.createTexture=null,this._textureFilter=t.textureFilter?t.textureFilter.trim().toUpperCase():"MIPMAP",this._isSRGB=null!=t.isSRGB&&t.isSRGB,this._internalFormat=null,this._extentMerc=new te,this.setExtent(Me(t.extent,new te(new I(-180,-90),new I(180,90)))),this._pickingColor=new oe,this._pickingEnabled=void 0===t.pickingEnabled||t.pickingEnabled,this._isPreloadDone=!1,this._preLoadZoomLevels=t.preLoadZoomLevels||[0,1],this._ambient=null,this._diffuse=null,this._specular=null,t.ambient){let e=Se(t.ambient,new oe(.2,.2,.2));this._ambient=new Float32Array([e.x,e.y,e.z])}if(t.diffuse){let e=Se(t.diffuse,new oe(.8,.8,.8));this._diffuse=new Float32Array([e.x,e.y,e.z])}if(t.specular){let e=Se(t.specular,new oe(3e-4,3e-4,3e-4)),i=t.shininess||20;this._specular=new Float32Array([e.x,e.y,e.z,i])}this.nightTextureCoefficient=t.nightTextureCoefficient||1}get iconSrc(){return this._iconSrc}set iconSrc(e){this._iconSrc=e}set diffuse(e){if(e){let t=Se(e);this._diffuse=new Float32Array(t.toArray())}else this._diffuse=null}set ambient(e){if(e){let t=Se(e);this._ambient=new Float32Array(t.toArray())}else this._ambient=null}set specular(e){if(e){let t=Se(e);this._specular=new Float32Array([t.x,t.y,t.y,this._specular?this._specular[3]:0])}else this._specular=null}set shininess(e){this._specular&&(this._specular[3]=e)}static getTMS(e,t,i){return{x:e,y:(1<<i)-t-1,z:i}}static getTileIndex(e,t,i,s){return`${s}::${e}_${t}_${i}`}get instanceName(){return"Layer"}get rendererEvents(){return this.events}set opacity(e){e!==this._opacity&&(this._fading?e>this._opacity?this._fadingFactor=(e-this._opacity)/30:e<this._opacity&&(this._fadingFactor=(this._opacity-e)/30):this._fadingOpacity=e,this._opacity=e)}set pickingEnabled(e){this._pickingEnabled=e}get pickingEnabled(){return this._pickingEnabled}hasImageryTiles(){return this._hasImageryTiles}getID(){return this.__id}get id(){return this.__id}get _id(){return this.__id}isEqual(e){return e.__id===this.__id}_assignPlanet(e){this._planet=e,e._layers.push(this),e.renderer&&e.renderer.isInitialized()&&(this._isSRGB?this._internalFormat=e.renderer.handler.gl.SRGB8_ALPHA8:this._internalFormat=e.renderer.handler.gl.RGBA8,this.createTexture=e.renderer.handler.createTexture[this._textureFilter],this.events.on("visibilitychange",e._onLayerVisibilityChanged,e),this._isBaseLayer&&this._visibility&&e.setBaseLayer(this),e.events.dispatch(e.events.layeradd,this),this.events.dispatch(this.events.add,e),e.updateVisibleLayers(),this._bindPicking(),this._visibility&&this.hasImageryTiles()&&this._preLoad())}get isIdle(){return this._planet&&this._planet._terrainCompletedActivated||!1}_bindPicking(){this._planet&&this._planet.renderer&&this._planet.renderer.assignPickingColor(this)}addTo(e){this._planet||this._assignPlanet(e)}remove(){let e=this._planet;if(e)for(let t=0;t<e._layers.length;t++)if(this.isEqual(e._layers[t]))return e.renderer&&e.renderer.clearPickingColor(this),e._layers.splice(t,1),e.updateVisibleLayers(),this.clear(),e.events.dispatch(e.events.layerremove,this),this.events.dispatch(this.events.remove,e),this._planet=null,this._internalFormat=null,this.createTexture=null,this;return this}clear(){this._planet&&this._planet._clearLayerMaterial(this)}get planet(){return this._planet}setAttribution(e){this._attribution!==e&&(this._attribution=e,this._planet&&this._planet.updateAttributionsList())}getAttribution(){return this._attribution}setHeight(e){this._height=e,this._planet&&this._planet.updateVisibleLayers()}getHeight(){return this._height}setZIndex(e){this._zIndex=e,this._planet&&this._planet.updateVisibleLayers()}getZIndex(){return this._zIndex}bringToFront(){if(this._planet){let e=this._planet.visibleTileLayers,t=e[e.length-1];t.isEqual(this)||this.setZIndex(t.getZIndex()+1)}}isBaseLayer(){return this._isBaseLayer}setBaseLayer(e){this._isBaseLayer=e,this._planet&&(!e&&this._planet.baseLayer&&this.isEqual(this._planet.baseLayer)&&(this._planet.baseLayer=null),this._planet.updateVisibleLayers())}setVisibility(e){e!==this._visibility&&(this._visibility=e,this._planet&&(this._isBaseLayer&&e&&this._planet.setBaseLayer(this),this._planet.updateVisibleLayers(),!e||this._isPreloadDone||this.isVector||(this._isPreloadDone=!0,this._preLoad())),this.events.dispatch(this.events.visibilitychange,this))}_forceMaterialApply(e){let t=e.materials,i=t[this.__id];i||(i=t[this.__id]=this.createMaterial(e)),i.isReady||(this._planet._renderCompleted=!1),this.applyMaterial(i,!0)}clearMaterial(e){}loadMaterial(e,t=!1){}applyMaterial(e,t=!1){return[0,0,1,1]}_preLoadRecursive(e,t){if(!(e.segment.tileZoom>t)){this._preLoadZoomLevels.includes(e.segment.tileZoom)&&this._forceMaterialApply(e.segment);for(let i=0,s=e.nodes.length;i<s;i++)e.nodes[i]&&this._preLoadRecursive(e.nodes[i],t)}}_preLoad(){if(this._planet&&this._preLoadZoomLevels.length){let e=this._planet,t=Math.max(...this._preLoadZoomLevels);for(let i=0,s=e.quadTreeStrategy.quadTreeList.length;i<s;i++)this._preLoadRecursive(e.quadTreeStrategy.quadTreeList[i],t)}}getVisibility(){return this._visibility}setExtent(e){let t=e.southWest.clone(),i=e.northEast.clone();t.lat<J&&(t.lat=J),i.lat>Q&&(i.lat=Q),this._extent=e.clone(),this._extentMerc=new te(t.forwardMercator(),i.forwardMercator()),this._correctFullExtent()}getExtent(){return this._extent}getExtentMerc(){return this._extentMerc}flyExtent(){this._planet?.flyExtent(this.getExtent())}viewExtent(){this._planet?.viewExtent(this.getExtent())}_correctFullExtent(){}get opacity(){return this._opacity}get screenOpacity(){return this._fading?this._fadingOpacity:this._opacity}_refreshFadingOpacity(){let e=this._planet;return this._visibility&&e.getViewExtent().overlaps(this._extent)&&e.maxCurrZoom>=this.minZoom&&e.minCurrZoom<=this.maxZoom?(this._fadingOpacity+=this._fadingFactor,(this._fadingFactor>0&&this._fadingOpacity>this._opacity||this._fadingFactor<0&&this._fadingOpacity<this._opacity)&&(this._fadingOpacity=this._opacity),!1):(this._fadingOpacity-=this._fadingFactor,this._fadingOpacity<=0&&(this._fadingOpacity=0),!1)}createMaterial(e){return new qt(e,this)}redraw(){this._planet?.quadTreeStrategy.clearLayerMaterial(this)}abortMaterialLoading(e){}abortLoading(){}}$t.__counter__=0;const Xt=["visibilitychange","add","remove","mousemove","mouseenter","mouseleave","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchmove","touchstart","touchend","doubletouch","touchleave","touchenter"],Zt=["load","loadend"];class Kt extends $t{constructor(e,t){super(e,t),this.events=this.events.registerNames(Zt),this.animated=t.animated||!1,this.minNativeZoom=t.minNativeZoom||0,this.maxNativeZoom=t.maxNativeZoom||100,this._counter=0,this._pendingsQueue=[],this.drawTile=t.drawTile,this._onLoadend_=null}addTo(e){return this._onLoadend_=this._onLoadend.bind(this),this.events.on("loadend",this._onLoadend_,this),super.addTo(e)}remove(){return this.events.off("loadend",this._onLoadend_),this._onLoadend_=null,super.remove()}_onLoadend(){this._planet&&this._planet._terrainCompletedActivated&&this._planet.events.dispatch(this._planet.events.layerloadend,this)}get instanceName(){return"CanvasTiles"}get isIdle(){return super.isIdle&&0===this._counter}abortLoading(){this._pendingsQueue.forEach((e=>{this.abortMaterialLoading(e)})),this._pendingsQueue=[]}setVisibility(e){e!==this._visibility&&(super.setVisibility(e),e||this.abortLoading())}loadMaterial(e){let t=e.segment;this._isBaseLayer?e.texture=t.getDefaultTexture():e.texture=t.planet.transparentTexture,(this._planet.layerLock.isFree()||e.segment.tileZoom<2)&&(e.isReady=!1,e.isLoading=!0,Kt.__requestsCounter>=Kt.MAX_REQUESTS&&this._counter?this._pendingsQueue.push(e):this._exec(e))}_exec(e){Kt.__requestsCounter++,this._counter++;const t=this.events.load;t.handlers.length&&this.events.dispatch(t,e),requestAnimationFrame((()=>{this.drawTile(e,(t=>{this._counter--,Kt.__requestsCounter--,this._correctCounter(),e.isLoading&&e.applyImage(t),this._dequeueRequest()}))}))}_correctCounter(){this._counter<0&&(this._counter=0),Kt.__requestsCounter<0&&(Kt.__requestsCounter=0)}abortMaterialLoading(e){e.isLoading&&(this._counter--,Kt.__requestsCounter--,this._correctCounter(),this._dequeueRequest()),e.isLoading=!1,e.isReady=!1}_dequeueRequest(){if(this._pendingsQueue.length){if(Kt.__requestsCounter<Kt.MAX_REQUESTS){const e=this._whilePendings();e&&this._exec(e)}}else 0===this._counter&&this._planet&&this._planet._terrainCompletedActivated&&this.events.dispatch(this.events.loadend)}_whilePendings(){for(;this._pendingsQueue.length;){const e=this._pendingsQueue.pop();if(e&&e.segment&&e.segment.node){if(e.segment.initialized&&1===e.segment.node.getState())return e;e.isLoading=!1}}return null}applyMaterial(e){if(e.isReady)return e.layer.animated&&requestAnimationFrame((()=>{this.drawTile(e,(function(t){e.applyImage(t)}))})),e.texOffset;if(e.segment.tileZoom<this.minNativeZoom)e.textureNotExists();else{let t=e.segment,i=t.node,s=!1,n=e.layer.maxNativeZoom;t.passReady&&!e.isLoading&&t.tileZoom<=n&&this.loadMaterial(e);let r=this._id,o=e;for(;i.parentNode;)if(i=i.parentNode,o=i.segment.materials[r],o&&o.textureExists){s=!0;break}if(t.passReady)if(i.segment.tileZoom===n)t.tileZoom>n&&e.textureNotExists();else if(i.segment.tileZoom<n){let i=t.node;for(;i.segment.tileZoom>n;)i=i.parentNode;let s=i.segment.materials[r];s?!s.isLoading&&!s.isReady&&this.loadMaterial(s):(s=i.segment.materials[e.layer._id]=e.layer.createMaterial(i.segment),this.loadMaterial(s))}if(s){e.layer.animated&&requestAnimationFrame((()=>{this.drawTile(e,(function(t){e.applyImage(t)}))})),e.appliedNodeId=i.nodeId,e.texture=o.texture;let s=1/(2<<t.tileZoom-i.segment.tileZoom-1);e.texOffset[0]=t.tileX*s-i.segment.tileX,e.texOffset[1]=t.tileY*s-i.segment.tileY,e.texOffset[2]=s,e.texOffset[3]=s}else e.texture=t.planet.transparentTexture,e.texOffset[0]=0,e.texOffset[1]=0,e.texOffset[2]=1,e.texOffset[3]=1}return e.texOffset}clearMaterial(e){e.isReady&&(e.isReady=!1,e.textureExists&&e.texture&&!e.texture.default&&(e.segment.handler.gl.deleteTexture(e.texture),e.texture=null)),this.abortMaterialLoading(e),e.isLoading=!1,e.textureExists=!1,e.layer=null,e.segment=null}}Kt.MAX_REQUESTS=20,Kt.__requestsCounter=0;const Qt=["change"];class Jt{constructor(e={}){this._onChange=(e,t)=>{if(e){t.preventClick=!0;for(let e=0;e<this._buttons.length;e++){let i=this._buttons[e];i.isEqual(t)||(i.setActive(!1),i.preventClick=!1)}this.events.dispatch(this.events.change,t)}},this.events=Mt(Qt),this._buttons=e.buttons||[];for(let e=0;e<this._buttons.length;e++)this._bindButton(this._buttons[e])}_bindButton(e){e.events.on("change",this._onChange)}add(e){this._buttons.push(e),this._bindButton(e)}remove(e){for(let t=0;t<this._buttons.length;t++)if(this._buttons[t].isEqual(e))return this._buttons.splice(t),void e.events.off("change",this._onChange)}}class ei{constructor(e=2,t){this._sourceId=0,this._source=new Map,this._pendingQueue=[],this._numWorkers=e,this._workerQueue=[],t&&this.setProgram(t)}check(){this._pendingQueue.length&&this.make(this._pendingQueue.pop())}setProgram(e){let t=new Blob([e],{type:"application/javascript"});for(let e=0;e<this._numWorkers;e++){let e=new Worker(URL.createObjectURL(t));e.onmessage=e=>{this._onMessage(e),this._workerQueue&&this._workerQueue.unshift(e.target),this.check()},this._workerQueue.push(e)}}make(e){}_onMessage(e){}destroy(){for(let e=0;e<this._workerQueue.length;e++){const t=this._workerQueue[e];t.onmessage=null,t.terminate()}this._pendingQueue=null,this._workerQueue=null}get pendingQueue(){return this._pendingQueue}}const ti=-2,ii=-1;class si extends ei{constructor(e=4){super(e,ni)}_onMessage(e){let t=this._source.get(e.data.id);t.label._lockId===ti?requestAnimationFrame((()=>{this.make({handler:t.handler,label:t.label})})):t.handler.workerCallback(e.data,t.label),this._source.delete(e.data.id)}make(e){let t=e.label;if(e.handler._entityCollection){let i=t.serializeWorkerData(this._sourceId);if(i)if(this._workerQueue.length){let s=this._workerQueue.pop();this._source.set(this._sourceId,e),t._lockId=this._sourceId,this._sourceId++,s.postMessage({labelData:i},[i.buffer])}else this._pendingQueue.push(e)}}}const ni="'use strict';\n\n function concatTypedArrays(dest, index, source) {\n let len = source.length,\n offset = index * len;\n for(let i = 0; i < len; i++) {\n dest[offset + i] = source[i];\n }\n }\n\n self.onmessage = function (e) {\n var labelData = e.data.labelData,\n id = labelData[0],\n maxLetters = labelData[1],\n isVisible = labelData[2],\n /*3, 4, 5*/_positionHigh_x = labelData[3], _positionHigh_y = labelData[4], _positionHigh_z = labelData[5],\n /*6, 7, 8*/_positionLow_x = labelData[6], _positionLow_y = labelData[7], _positionLow_z = labelData[8],\n /*9*/_size = labelData[9],\n /*10, 11, 12*/_offset_x = labelData[10], _offset_y = labelData[11], _offset_z = labelData[12],\n /*13, 14, 15, 16*/_color_x = labelData[13], _color_y = labelData[14], _color_z = labelData[15], _color_w = labelData[16],\n /*17*/_rotation = labelData[17],\n /*18, 19, 20*/_alignedAxis_x = labelData[18], _alignedAxis_y = labelData[19], _alignedAxis_z = labelData[20],\n /*21*/_fontIndex = labelData[21],\n /*22*/_outline = labelData[22],\n /*23, 24, 25, 26*/_outlineColor_x = labelData[23], _outlineColor_y = labelData[24], _outlineColor_z = labelData[25], _outlineColor_w = labelData[26],\n /*27, 28, 29*/_pickingColor_x = labelData[27], _pickingColor_y = labelData[28], _pickingColor_z = labelData[29]\n \n\n let _vertexArr = new Float32Array(maxLetters * 12),\n _texCoordArr = new Float32Array(maxLetters * 24),\n _gliphParamArr = new Float32Array(maxLetters * 24),\n _positionHighArr = new Float32Array(maxLetters * 18),\n _positionLowArr = new Float32Array(maxLetters * 18),\n _sizeArr = new Float32Array(maxLetters * 6),\n _offsetArr = new Float32Array(maxLetters * 18),\n _rgbaArr = new Float32Array(maxLetters * 24),\n _rotationArr = new Float32Array(maxLetters * 6),\n _alignedAxisArr = new Float32Array(maxLetters * 18),\n _fontIndexArr = new Float32Array(maxLetters * 6),\n _outlineArr = new Float32Array(maxLetters * 6),\n _outlineColorArr = new Float32Array(maxLetters * 24),\n _pickingColorArr = new Float32Array(maxLetters * 18);\n \n for (let i = 0; i < maxLetters; i++) {\n if (isVisible !== 0) {\n concatTypedArrays(_vertexArr, i, [0, 0, 0, -1, 1, -1, 1, -1, 1, 0, 0, 0]);\n } else {\n concatTypedArrays(_vertexArr, i, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);\n }\n\n concatTypedArrays(_texCoordArr, i, [0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0]);\n concatTypedArrays(_gliphParamArr, i, [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]);\n\n var x = _positionHigh_x, y = _positionHigh_y, z = _positionHigh_z, w;\n concatTypedArrays(_positionHighArr, i, [x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y, z]);\n\n x = _positionLow_x; y = _positionLow_y; z = _positionLow_z;\n concatTypedArrays(_positionLowArr, i, [x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y, z]);\n\n x = _size;\n concatTypedArrays(_sizeArr, i, [x, x, x, x, x, x]);\n\n x = _offset_x; y = _offset_y; z = _offset_z;\n concatTypedArrays(_offsetArr, i, [x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y, z]);\n\n x = _color_x; y = _color_y; z = _color_z; w = _color_w;\n concatTypedArrays(_rgbaArr, i, [x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w]);\n\n x = _rotation;\n concatTypedArrays(_rotationArr, i, [x, x, x, x, x, x]);\n\n x = _alignedAxis_x; y = _alignedAxis_y; z = _alignedAxis_z;\n concatTypedArrays(_alignedAxisArr, i, [x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y, z]);\n\n x = _fontIndex;\n concatTypedArrays(_fontIndexArr, i, [x, x, x, x, x, x]);\n\n x = _outline;\n concatTypedArrays(_outlineArr, i, [x, x, x, x, x, x]);\n\n x = _outlineColor_x; y = _outlineColor_y; z = _outlineColor_z; w = _outlineColor_w;\n concatTypedArrays(_outlineColorArr, i, [x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w]);\n\n x = _pickingColor_x / 255; y = _pickingColor_y / 255; z = _pickingColor_z / 255;\n concatTypedArrays(_pickingColorArr, i, [x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y, z]);\n }\n\n self.postMessage({\n id: id,\n vertexArr: _vertexArr,\n texCoordArr: _texCoordArr,\n gliphParamArr: _gliphParamArr,\n positionHighArr: _positionHighArr,\n positionLowArr: _positionLowArr,\n sizeArr: _sizeArr,\n offsetArr: _offsetArr,\n rgbaArr: _rgbaArr,\n rotationArr: _rotationArr,\n alignedAxisArr: _alignedAxisArr,\n fontIndexArr: _fontIndexArr,\n outlineArr: _outlineArr,\n outlineColorArr: _outlineColorArr,\n pickingColorArr: _pickingColorArr\n }, [\n _vertexArr.buffer,\n _texCoordArr.buffer,\n _gliphParamArr.buffer,\n _positionHighArr.buffer,\n _positionLowArr.buffer,\n _sizeArr.buffer,\n _offsetArr.buffer,\n _rgbaArr.buffer,\n _rotationArr.buffer,\n _alignedAxisArr.buffer,\n _fontIndexArr.buffer,\n _outlineArr.buffer,\n _outlineColorArr.buffer,\n _pickingColorArr.buffer\n ]);\n }";class ri{constructor(e={}){this.__id=ri.__counter__++,this._position=Ae(e.position),this._positionHigh=new oe,this._positionLow=new oe,oe.doubleToTwoFloats(this._position,this._positionHigh,this._positionLow),this._rotation=e.rotation||0,this._color=Pe(e.color),this._alignedAxis=Ae(e.alignedAxis),this._offset=Ae(e.offset),this._visibility=null==e.visibility||e.visibility,this._entity=null,this._handler=null,this._handlerIndex=-1,this._isReady=!1,this._lockId=ii}setPosition(e,t,i){this._position.x=e,this._position.y=t,this._position.z=i,oe.doubleToTwoFloats(this._position,this._positionHigh,this._positionLow),this._isReady&&this._handler?this._handler.setPositionArr(this._handlerIndex,this._positionHigh,this._positionLow):this._lockId!==ii&&(this._lockId=ti)}setPosition3v(e){this._position.x=e.x,this._position.y=e.y,this._position.z=e.z,oe.doubleToTwoFloats(e,this._positionHigh,this._positionLow),this._isReady&&this._handler?this._handler.setPositionArr(this._handlerIndex,this._positionHigh,this._positionLow):this._lockId!==ii&&(this._lockId=ti)}getPosition(){return this._position}setOffset(e,t,i){this._offset.x=e,this._offset.y=t,null!=i&&(this._offset.z=i),this._isReady&&this._handler?this._handler.setOffsetArr(this._handlerIndex,this._offset):this._lockId!==ii&&(this._lockId=ti)}setOffset3v(e){this.setOffset(e.x,e.y,e.z)}getOffset(){return this._offset}setRotation(e){e!==this._rotation&&(this._rotation=e,this._isReady&&this._handler?this._handler.setRotationArr(this._handlerIndex,e):this._lockId!==ii&&(this._lockId=ti))}getRotation(){return this._rotation}setOpacity(e){e!==this._color.w&&(null!=e&&(this._color.w=e),this._isReady&&this._handler?this._handler.setRgbaArr(this._handlerIndex,this._color):this._lockId!==ii&&(this._lockId=ti))}setColor(e,t,i,s){s===this._color.w&&e===this._color.x&&t===this._color.y&&this._color.z===i||(this._color.x=e,this._color.y=t,this._color.z=i,null!=s&&(this._color.w=s),this._isReady&&this._handler?this._handler.setRgbaArr(this._handlerIndex,this._color):this._lockId!==ii&&(this._lockId=ti))}setColor4v(e){this.setColor(e.x,e.y,e.z,e.w)}setColorHTML(e){this.setColor4v(ye(e))}getColor(){return this._color}setVisibility(e){e!==this._visibility&&(this._visibility=e,this._isReady&&this._handler?this._handler.setVisibility(this._handlerIndex,e):this._lockId!==ii&&(this._lockId=ti))}getVisibility(){return this._visibility}setAlignedAxis(e,t,i){this._alignedAxis.x=e,this._alignedAxis.y=t,this._alignedAxis.z=i,this._isReady&&this._handler?this._handler.setAlignedAxisArr(this._handlerIndex,this._alignedAxis):this._lockId!==ii&&(this._lockId=ti)}setAlignedAxis3v(e){this.setAlignedAxis(e.x,e.y,e.z)}getAlignedAxis(){return this._alignedAxis}remove(){this._entity=null,this._handler&&this._handler.remove(this)}setPickingColor3v(e){this._isReady&&this._handler?this._handler.setPickingColorArr(this._handlerIndex,e):this._lockId!==ii&&(this._lockId=ti)}serializeWorkerData(e){return this._handler?new Float32Array([]):null}}ri.__counter__=0;class oi extends ri{constructor(e={}){super(e),this._handler=null,this._src=e.src||null,this._image=e.image||null,this._scale=1,this._width=e.width||(e.size?e.size[0]:30),this._height=e.height||(e.size?e.size[1]:30)}setSrc(e){this._src=e;let t=this._handler;if(t&&e&&e.length){let i=t._entityCollection.renderNode;if(i&&i.renderer){let s=i.renderer.billboardsTextureAtlas,n=this;s.loadImage(e,(function(e){null!=e.__nodeIndex&&s.get(e.__nodeIndex)?(n._image=e,t.setTexCoordArr(n._handlerIndex,s.get(n._image.__nodeIndex).texCoords)):(s.addImage(e),s.createTexture(),n._image=e,i.updateBillboardsTexCoords())}))}}}getSrc(){return this._src}setImage(e){this.setSrc(e.src)}getImage(){return this._image}setSize(e,t){this._width=e,this._height=t,this._handler&&this._handler.setSizeArr(this._handlerIndex,e*this._scale,t*this._scale)}getSize(){return{width:this._width,height:this._height}}setWidth(e){this.setSize(e,this._height)}getWidth(){return this._width}setHeight(e){this.setSize(this._width,e)}getHeight(){return this._height}}var ai;e.GeometryTypeEnum=void 0,(ai=e.GeometryTypeEnum||(e.GeometryTypeEnum={}))[ai.POINT=1]="POINT",ai[ai.LINESTRING=2]="LINESTRING",ai[ai.POLYGON=3]="POLYGON",ai[ai.MULTIPOLYGON=4]="MULTIPOLYGON",ai[ai.MULTILINESTRING=5]="MULTILINESTRING";const li={POINT:1,LINESTRING:2,POLYGON:3,MULTIPOLYGON:4,MULTILINESTRING:5};class hi{constructor(t={}){this.__id=hi.__counter__++,this._entity=null,this._handler=null,this._handlerIndex=-1,this._polyVerticesHighMerc=[],this._polyVerticesLowMerc=[],this._polyVerticesLength=-1,this._polyIndexesLength=-1,this._polyVerticesHandlerIndex=-1,this._polyIndexesHandlerIndex=-1,this._lineVerticesHighMerc=[],this._lineVerticesLowMerc=[],this._lineVerticesLength=-1,this._lineOrdersLength=-1,this._lineIndexesLength=-1,this._lineColorsLength=-1,this._lineThicknessLength=-1,this._lineVerticesHandlerIndex=-1,this._lineOrdersHandlerIndex=-1,this._lineIndexesHandlerIndex=-1,this._lineThicknessHandlerIndex=-1,this._lineColorsHandlerIndex=-1,this._type=t.type&&hi.getType(t.type)||e.GeometryTypeEnum.POINT,this._coordinates=t.coordinates||[],this._extent=hi.getExtent({type:t.type||"POINT",coordinates:t.coordinates||[]},this._coordinates),t.style=t.style||{},this._style={fillColor:Pe(t.style.fillColor,new se(.19,.62,.85,.4)),lineColor:Pe(t.style.lineColor,new se(.19,.62,.85,1)),strokeColor:Pe(t.style.strokeColor,new se(1,1,1,.95)),lineWidth:t.style.lineWidth||3,strokeWidth:t.style.strokeWidth||0},this._visibility=t.visibility||!0,this._pickingReady=!1}get id(){return this.__id}get type(){return this._type}static getType(e){return li[e.toUpperCase()]}static getExtent(t,i){let s=new te(new I(180,90),new I(-180,-90)),n=hi.getType(t.type);if(n===e.GeometryTypeEnum.POINT){let e=t.coordinates[0],n=t.coordinates[1];s.southWest.lon=e,s.southWest.lat=n,s.northEast.lon=e,s.northEast.lat=n,i&&(i[0]=e)&&(i[1]=n)}else if(n===e.GeometryTypeEnum.LINESTRING){let e=t.coordinates;for(let t=0;t<e.length;t++){let n=e[t][0],r=e[t][1];n<s.southWest.lon&&(s.southWest.lon=n),r<s.southWest.lat&&(s.southWest.lat=r),n>s.northEast.lon&&(s.northEast.lon=n),r>s.northEast.lat&&(s.northEast.lat=r),i&&(i[t]=[n,r])}}else if(n===e.GeometryTypeEnum.POLYGON){let e=t.coordinates;for(let t=0;t<e.length;t++){let n=e[t];i&&(i[t]=[]);for(let e=0;e<n.length;e++){let r=n[e],o=r[0],a=r[1];o<s.southWest.lon&&(s.southWest.lon=o),a<s.southWest.lat&&(s.southWest.lat=a),o>s.northEast.lon&&(s.northEast.lon=o),a>s.northEast.lat&&(s.northEast.lat=a),i&&(i[t][e]=[o,a])}}}else if(n===e.GeometryTypeEnum.MULTIPOLYGON){let e=t.coordinates;for(let t=0;t<e.length;t++){let n=e[t];i&&(i[t]=[]);for(let e=0;e<n.length;e++){let r=n[e];i&&(i[t][e]=[]);for(let n=0;n<r.length;n++){let o=r[n],a=o[0],l=o[1];a<s.southWest.lon&&(s.southWest.lon=a),l<s.southWest.lat&&(s.southWest.lat=l),a>s.northEast.lon&&(s.northEast.lon=a),l>s.northEast.lat&&(s.northEast.lat=l),i&&(i[t][e][n]=[a,l])}}}}else if(n===e.GeometryTypeEnum.MULTILINESTRING){let e=t.coordinates;for(let t=0;t<e.length;t++){let n=e[t];i&&(i[t]=[]);for(let e=0;e<n.length;e++){let r=n[e],o=r[0],a=r[1];o<s.southWest.lon&&(s.southWest.lon=o),a<s.southWest.lat&&(s.southWest.lat=a),o>s.northEast.lon&&(s.northEast.lon=o),a>s.northEast.lat&&(s.northEast.lat=a),i&&(i[t][e]=[o,a])}}}else s.southWest.lon=s.southWest.lat=s.northEast.lon=s.northEast.lat=0,i&&(i[0]=0)&&(i[1]=0);return s}setGeometry(e){let t=this._handler;return t&&(this.remove(),this._type=hi.getType(e.type||"Point"),this._extent=hi.getExtent(e,this._coordinates),t.add(this)),this}setFillColor(e,t,i,s=1){let n=this._style.fillColor;return(0===n.w&&0!==s||0!==n.w&&0===s)&&(this._pickingReady=!1),n.x=e,n.y=t,n.z=i,n.w=s,this._handler&&this._handler.setPolyColorArr(this,n),this}overlaps(e){return this._extent.overlaps(e)}setFillColor4v(e){return this.setFillColor(e.x,e.y,e.z,e.w)}setStrokeColor(e,t,i,s=1){let n=this._style.strokeColor;return(0===n.w&&0!==s||0!==n.w&&0===s)&&(this._pickingReady=!1),n.x=e,n.y=t,n.z=i,n.w=s,this._handler&&this._handler.setLineStrokeColorArr(this,n),this}setLineColor(e,t,i,s=1){let n=this._style.lineColor;return(0===n.w&&0!==s||0!==n.w&&0===s)&&(this._pickingReady=!1),n.x=e,n.y=t,n.z=i,n.w=s,this._handler&&this._handler.setLineColorArr(this,n),this}setStrokeColor4v(e){return this.setStrokeColor(e.x,e.y,e.z,e.w)}setLineColor4v(e){return this.setLineColor(e.x,e.y,e.z,e.w)}setStrokeOpacity(e){let t=this._style.strokeColor;return t.w=e,this.setStrokeColor(t.x,t.y,t.z,e)}setLineOpacity(e){let t=this._style.lineColor;return t.w=e,this.setLineColor(t.x,t.y,t.z,e)}setStrokeWidth(e){return this._style.strokeWidth=e,this._pickingReady=!1,this._handler&&this._handler.setLineStrokeArr(this,e),this}bringToFront(){return this._handler&&this._handler.bringToFront(this),this}setLineWidth(e){return this._style.lineWidth=e,this._pickingReady=!1,this._handler&&this._handler.setLineThicknessArr(this,e),this}setFillOpacity(e){let t=this._style.fillColor;return(0===t.w&&0!==e||0!==t.w&&0===e)&&(this._pickingReady=!1),t.w=e,this._handler&&this._handler.setPolyColorArr(this,t),this}setVisibility(e){return this._visibility=e,this._handler&&this._handler.setGeometryVisibility(this),this}getVisibility(){return this._visibility}remove(){this._handler&&this._handler.remove(this)}getExtent(){return this._extent.clone()}getType(){return this._type}}hi.__counter__=0;class ci{constructor(e=0,t=0,i=0){this.a=e,this.b=t,this.c=i}static get(e,t){return new ci(t.y-e.y,e.x-t.x,t.x*e.y-e.x*t.y)}static getParallel(e,t){return new ci(e.a,e.b,-e.a*t.x-e.b*t.y)}static getIntersection(e,t){let i=(t.b*e.c-e.b*t.c)/(e.b*t.a-t.b*e.a);return new ae(i,-(e.c+e.a*i)/e.b)}intersects(e){return ci.getIntersection(this,e)}}class di{constructor(e,t){this.p0=e||new oe,this.p1=t||new oe}getMagnitude(){return this.p0.distance(this.p1)}getSphereIntersection(e){let t=this.p0,i=this.p1,s=e.center.x,n=e.center.y,r=e.center.z,o=t.x,a=t.y,l=t.z,h=i.x-o,c=i.y-a,d=i.z-l,_=h*h+c*c+d*d,u=2*(o*h+a*c+l*d-h*s-c*n-d*r),g=u*u-4*_*(o*o-2*o*s+s*s+a*a-2*a*n+n*n+l*l-2*l*r+r*r-e.radius*e.radius);if(g<0)return[];let f=(-u-Math.sqrt(g))/(2*_),p=new oe(t.x*(1-f)+f*i.x,t.y*(1-f)+f*i.y,t.z*(1-f)+f*i.z);if(0==g)return[p];let m=(-u+Math.sqrt(g))/(2*_),v=new oe(t.x*(1-m)+m*i.x,t.y*(1-m)+m*i.y,t.z*(1-m)+m*i.z);return Math.abs(f-.5)<Math.abs(m-.5)?[p,v]:[v,p]}intersects(e,t,i){let s=this.p0.sub(e.p0),n=e.p1.sub(e.p0);if(Math.abs(n.x)<g&&Math.abs(n.y)<g&&Math.abs(n.z)<g)return!1;let r=this.p1.sub(this.p0);if(Math.abs(r.x)<g&&Math.abs(r.y)<g&&Math.abs(r.z)<g)return!1;let o=s.x*n.x+s.y*n.y+s.z*n.z,a=n.x*r.x+n.y*r.y+n.z*r.z,l=s.x*r.x+s.y*r.y+s.z*r.z,h=n.x*n.x+n.y*n.y+n.z*n.z,c=(r.x*r.x+r.y*r.y+r.z*r.z)*h-a*a;if(Math.abs(c)<g)return!1;let d=(o*a-l*h)/c;if(t.x=this.p0.x+d*r.x,t.y=this.p0.y+d*r.y,t.z=this.p0.z+d*r.z,i){let t=(o+a*d)/h;i.x=e.p0.x+t*n.x,i.y=e.p0.y+t*n.y,i.z=e.p0.z+t*n.z}return!0}getNearestDistancePoint(e,t){let i=this.p0,s=this.p1,n=this.getMagnitude(),r=((e.x-i.x)*(s.x-i.x)+(e.y-i.y)*(s.y-i.y)+(e.z-i.z)*(s.z-i.z))/(n*n);return t.x=i.x+r*(s.x-i.x),t.y=i.y+r*(s.y-i.y),t.z=i.z+r*(s.z-i.z),!(r<0||r>1)}}class _i{constructor(e,t){this.p=e?e.clone():new oe,this.n=t?t.clone():this.p.isZero()?oe.UP:this.p.getNormal()}setByPoints(e,t,i){let s=oe.sub(t,e),n=oe.sub(i,e);return this.n=s.cross(n),this.p.copy(e),this}static fromPoints(e,t,i){return(new _i).setByPoints(e,t,i)}set(e,t){this.p.copy(e),this.n.copy(t)}getNormal(){return this.n.clone()}distance(e){let t=this.getProjection(e);return e.distance(t)}getProjection(e,t){return oe.proj_b_to_plane(e,this.n,t)}getProjectionPoint(e,t){let i=e.sub(this.p),s=this.n,n=i.dot(s);return t?t.copy(s.scale(n)):t=s.scale(n),e.sub(t)}getIntersection(e,t,i){let s,n=e.n.cross(t.n),r=n.x>=0?n.x:-n.x,o=n.y>=0?n.y:-n.y,a=n.z>=0?n.z:-n.z;if(r+o+a<u){let i=t.p.sub(e.p);return 0==e.n.dot(i)?1:0}s=r>o?r>a?1:3:o>a?2:3;let l,h,c=new oe;return l=-e.n.dot(e.p),h=-t.n.dot(t.p),1===s?(c.x=0,c.y=(h*e.n.z-l*t.n.z)/n.x,c.z=(l*t.n.y-h*e.n.y)/n.x):2===s?(c.x=(l*t.n.z-h*e.n.z)/n.y,c.y=0,c.z=(h*e.n.x-l*t.n.x)/n.y):3===s&&(c.x=(h*e.n.y-l*t.n.y)/n.z,c.y=(l*t.n.x-h*e.n.x)/n.z,c.z=0),i.p0.copy(c),i.p1.copy(c.add(n)),2}}let ui=class e{constructor(e=oe.ZERO,t=oe.ZERO){this.origin=e,this.direction=t}static get OUTSIDE(){return 0}static get INSIDE(){return 1}static get INPLANE(){return 2}static get AWAY(){return 3}set(e,t){return this.origin=e,this.direction=t,this}getPoint(e){return oe.add(this.origin,this.direction.scaleTo(e))}hitTriangleRes(t,i,s,n){let r=i.sub(t),o=s.sub(t),a=r.cross(o),l=this.origin.sub(t),h=-a.dot(l),c=a.dot(this.direction);if(Math.abs(c)<g)return 0===h?(n.copy(this.origin),e.INPLANE):e.OUTSIDE;let d=h/c;if(n.copy(this.origin.add(this.direction.scaleTo(d))),d<0)return e.AWAY;let _=r.dot(r),u=r.dot(o),f=o.dot(o),p=n.sub(t),m=p.dot(r),v=p.dot(o),y=u*u-_*f,x=(u*v-f*m)/y;if(x<0||x>1)return e.OUTSIDE;let b=(u*m-_*v)/y;return b<0||x+b>1?e.OUTSIDE:e.INSIDE}hitPlaneRes(t,i){const s=this.direction.dot(t.n);if(Math.abs(s)<g)return e.OUTSIDE;const n=t.p.sub(this.origin).dot(t.n)/s;return n<0?e.AWAY:(i.copy(this.getPoint(n)),e.INSIDE)}hitSphere(e){let t=e.radius,i=e.center,s=this.origin,n=this.direction,r=oe.sub(i,s);if(r.dot(n)<0){var o=r.length();if(o>t)return null;if(o===t)return s.clone();let e=i.projToRay(s,r);var a=oe.sub(e,i).length();let l=Math.sqrt(t*t-a*a)-oe.sub(e,s).length();return oe.add(s,n.scaleTo(l))}{let o=i.projToRay(s,n);var l=oe.sub(i,o).length();if(l>e.radius)return null;{let e,i=Math.sqrt(t*t-l*l);return o.subA(s),e=r.length()>t?o.length()-i:o.length()+i,oe.add(s,n.scaleTo(e))}}}hitBox(e){}};function gi(e){let t=e.split("/"),i=t[t.length-1],s=t[t.length-2];return`${s?s+"/":""}${i}`}class fi{constructor(){this.objPositions=[],this.objTexcoords=[],this.objNormals=[],this.objVertexData=[this.objPositions,this.objTexcoords,this.objNormals],this.vertexData=[[],[],[]],this._materialLibs=[],this.geometries=[],this.geometry=null,this.materials={},this.material={},this.object="default",this.groups=["default"],this._path="",this.keywords={v:e=>{this.objPositions.push(e.map(parseFloat))},vn:e=>{this.objNormals.push(e.map(parseFloat))},vt:e=>{this.objTexcoords.push([parseFloat(e[0]),1-parseFloat(e[1])])},f:e=>{this.setGeometry();const t=e.length-2;for(let i=0;i<t;++i)this.addVertex(e[0]),this.addVertex(e[i+1]),this.addVertex(e[i+2])},s:()=>{},mtllib:(e,t)=>{this._materialLibs.push(t)},usemtl:(e,t)=>{this.newGeometry(),this.setGeometry(),this.geometry&&(this.geometry.material=t)},g:e=>{this.groups=e,this.newGeometry()},o:(e,t)=>{this.object=t,this.newGeometry()},newmtl:(e,t)=>{const i={};this.material=i,this.materials[t]=i},Ns:(e,t)=>{this.material.shininess=parseFloat(t)},Ni:(e,t)=>{},Ka:(e,t)=>{this.material.ambient=e.map((e=>parseFloat(e)))},Kd:(e,t)=>{this.material.diffuse=e.map((e=>parseFloat(e)))},Ks:(e,t)=>{this.material.specular=e.map((e=>parseFloat(e)))},Ke:(e,t)=>{this.material.color=e.map((e=>parseFloat(e)))},illum:(e,t)=>{this.material.illum=parseFloat(t)},d:(e,t)=>{this.material.opacity=parseFloat(t)},Tr:(e,t)=>{this.material.opacity=parseFloat(t)},Tf:(e,t)=>{},map_Ka:(e,t)=>{},map_Kd:(e,t)=>{this.material.colorTexture=`${this._path}/${gi(t)}`},map_Bump:(e,t)=>{this.material.normalTexture=`${this._path}/${gi(t)}`},map_Ns:(e,t)=>{this.material.metallicRoughnessTexture=`${this._path}/${gi(t)}`}}}newGeometry(){this.geometry&&this.geometry.data.vertices.length&&(this.geometry=null)}setGeometry(){if(!this.geometry){const e=[],t=[],i=[];this.vertexData=[e,t,i],this.geometry={object:this.object,groups:this.groups,material:"",data:{vertices:e,texCoords:t,normals:i}},this.geometries.push(this.geometry)}}addVertex(e){let t=e.split("/");for(let e=0;e<t.length;e++){let i=t[e];if(!i)continue;let s=parseInt(i)-1,n=this.vertexData[e],r=n.length,o=this.objVertexData[e][s],a=o.length;this.vertexData[e].length=r+a;for(let e=0;e<a;e++)n[r+e]=o[e]}}_innerParser(e,t){const i=/(\w*)(?: )*(.*)/,s=e.split("\n");for(let e=0;e<s.length;++e){const n=s[e].trim();if(""===n||n.startsWith("#"))continue;const r=i.exec(n);if(!r)continue;const[,o,a]=r,l=n.split(/\s+/).slice(1),h=this.keywords[o];h?h(l,a):console.warn(`Unknown keyword '${o}' in '${t}:${e}'`)}}get data(){return{geometries:this.geometries,materials:this.materials}}async load(e){this._path=e.substring(0,e.lastIndexOf("/"));const t=await fetch(e);if(!t.ok)throw new Error(`Unable to load '${e}'`);const i=t.body.getReader(),s=new TextDecoder;let{value:n,done:r}=await i.read(),o="";for(;!r;){const t=(o+s.decode(n,{stream:!0})).split("\n");o=t.pop();for(const i of t)this._innerParser(i,e);({value:n,done:r}=await i.read())}o&&this._innerParser(o,e),this._cleanupGeometryArrays();let a=this._materialLibs.map((e=>(e=`${this._path}/${e}`,fetch(e).then((e=>e.text())).then((t=>({text:t,filename:e}))))));return await Promise.all(a).then((e=>{e.forEach((e=>this._innerParser(e.text,e.filename)))})),this.data}async _readAndParse(e){const t=e.stream().getReader(),i=new TextDecoder;let{value:s,done:n}=await t.read(),r="";for(;!n;){const o=(r+i.decode(s,{stream:!0})).split("\n");r=o.pop();for(const t of o)this._innerParser(t,e.name);({value:s,done:n}=await t.read())}r&&this._innerParser(r,e.name)}async readFile(e,t){return this._path="",await this._readAndParse(e),this._cleanupGeometryArrays(),t&&await this._readAndParse(t),this.data}_cleanupGeometryArrays(){for(const e of this.geometries)e.data=Object.fromEntries(Object.entries(e.data).filter((([e,t])=>t.length>0)))}}function pi(e){let t=new Float32Array([1,1,1]);if(e instanceof Array)t[0]=e[0],t[1]=e[1],t[2]=e[2];else if("string"==typeof e){let i=xe(e);t[0]=i[0],t[1]=i[1],t[2]=i[2]}return t}class mi{constructor(e={}){var t;if(this._name=e.name||"noname",this._vertices=e.vertices||[],this._numVertices=this._vertices.length/3,this._texCoords=e.texCoords||new Array(2*this._numVertices),this.color=(t=e.color)instanceof Array?new Float32Array(t):"string"==typeof t?xe(t):new Float32Array([1,1,1,1]),this.ambient=pi(e.ambient),this.diffuse=pi(e.diffuse),this.specular=pi(e.specular),this.shininess=e.shininess||100,this.colorTexture=e.colorTexture||"",this.normalTexture=e.normalTexture||"",this.metallicRoughnessTexture=e.metallicRoughnessTexture||"",e.scale){let t,i=e.scale;t="number"==typeof i?new oe(i,i,i):i,mi.scale(this._vertices,t)}if(e.center&&mi.centering(this._vertices),this.center=mi.getCenter(this._vertices),e.indices)this._indices=e.indices,this._normals=e.normals||[];else{this._normals=e.normals||mi.getNormals(this._vertices),this._indices=new Array(this._vertices.length/3);for(let e=0,t=this._indices.length;e<t;e++)this._indices[e]=e}}static getCenter(e){let t=o,i=o,s=o,n=a,r=a,l=a;for(let o=0,a=e.length;o<a;o+=3){let a=e[o],h=e[o+1],c=e[o+2];a<t&&(t=a),h<i&&(i=h),c<s&&(s=c),a>n&&(n=a),h>r&&(r=h),c>l&&(l=c)}return new oe(t+.5*(n-t),i+.5*(r-i),s+.5*(l-s))}static centering(e){let t=mi.getCenter(e);for(let i=0,s=e.length;i<s;i+=3)e[i]-=t.x,e[i+1]-=t.y,e[i+2]-=t.z}centering(){return mi.centering(this._vertices),this}applyMat4(e){for(let t=0,i=this._vertices.length;t<i;t+=3){let i=new oe(this._vertices[t],this._vertices[t+1],this._vertices[t+2]),s=new oe(this._normals[t],this._normals[t+1],this._normals[t+2]);i=e.mulVec3(i),s=e.mulVec3(s),this._vertices[t]=i.x,this._vertices[t+1]=i.y,this._vertices[t+2]=i.z,this._normals[t]=s.x,this._normals[t+1]=s.y,this._normals[t+2]=s.z}return this}scale(e){return mi.scale(this._vertices,e),this}translate(e){for(let t=0,i=this._vertices.length;t<i;t+=3)this._vertices[t]+=e.x,this._vertices[t+1]+=e.y,this._vertices[t+2]+=e.z;return this}get name(){return this._name}get vertices(){return this._vertices}get normals(){return this._normals}get indices(){return this._indices}get texCoords(){return this._texCoords}get numVertices(){return this._numVertices}static scale(e,t){for(let i=0;i<e.length;i+=3)e[i]*=t.x,e[i+1]*=t.y,e[i+2]*=t.z}static centroid(e){let t=1e3,i=1e3,s=1e3,n=-1e3,r=-1e3,o=-1e3;for(let a=0;a<e.length;a+=3){let l=e[a],h=e[a+1],c=e[a+2];l<t&&(t=l),h<i&&(i=h),c<s&&(s=c),l>n&&(n=l),h>r&&(r=h),c>o&&(o=c)}return[t+.5*(n-t),i+.5*(r-i),s+.5*(o-s)]}static translate(e,t){for(let i=0;i<e.length;i+=3)e[i]+=t[0],e[i+1]+=t[1],e[i+2]+=t[2]}static getNormals(e){let t=new Array(e.length);for(let i=0;i<e.length;i+=9){let s=i,n=i+3,r=i+6,o=e[s],a=e[s+1],l=e[s+2],h=e[n]-o,c=e[n+1]-a,d=e[n+2]-l,_=e[r]-o,u=e[r+1]-a,g=e[r+2]-l,f=c*g-d*u,p=d*_-h*g,m=h*u-c*_,v=Math.sqrt(f*f+p*p+m*m);f/=v,p/=v,m/=v,t[s]=f,t[s+1]=p,t[s+2]=m,t[n]=f,t[n+1]=p,t[n+2]=m,t[r]=f,t[r+1]=p,t[r+2]=m}return t}static createSphere(e=16,t=16,i=1,s=0,n=0,r=0){let o=[],a=[],l=[];for(let a=0;a<=t;a++){let h=a*Math.PI/t,c=Math.sin(h),d=Math.cos(h);for(let t=0;t<=e;t++){let a=2*t*Math.PI/e,h=Math.sin(a),_=Math.cos(a)*c+s,u=d+n,g=h*c+r;l.push(_),l.push(u),l.push(g),o.push(i*_),o.push(i*u),o.push(i*g)}}for(let i=0;i<t;i++)for(let t=0;t<e;t++){let s=i*(e+1)+t,n=s+e+1;a.push(s),a.push(s+1),a.push(n),a.push(n),a.push(s+1),a.push(n+1)}return new mi({vertices:o,normals:l,indices:a})}static createDisc(e=1,t=0,i=8,s=!0,n=0,r=0,o=0,a=0){let l=[],h=[],c=[],d=2*Math.PI,_=s?1:-1,u=n;for(let e=1;e<=i;e++)l.push(r,t*_+o,a),c.push(0,_,0),n++;let g=n;for(let s=0;s<=i;s++){let h=s/i*d+0,u=Math.cos(h),g=Math.sin(h);l.push(e*g+r,t*_+o,e*u+a),c.push(0,_,0),n++}for(let e=0;e<i;e++){let t=u+e,i=g+e;s?h.push(i,i+1,t):h.push(i+1,i,t)}return new mi({vertices:l,normals:c,indices:h})}static getFrustumScaleByCameraAngles(e,t,i){return new oe(2*e*Math.tan(d*t),2*e*Math.tan(d*i),e)}static getFrustumScaleByCameraAspectRatio(e,t,i){let s=c*Math.atan(Math.tan(d*t)/i);return mi.getFrustumScaleByCameraAngles(e,t,s)}static createFrustum(e=1,t=1,i=1,s=0,n=0,r=0){return new mi({vertices:[0+s,0+n,0+r,-1*(t*=.5)+s,1*(i*=.5)+n,-1*e+r,1*t+s,1*i+n,-1*e+r,0+s,0+n,0+r,1*t+s,-1*i+n,-1*e+r,-1*t+s,-1*i+n,-1*e+r,0+s,0+n,0+r,1*t+s,1*i+n,-1*e+r,1*t+s,-1*i+n,-1*e+r,0+s,0+n,0+r,-1*t+s,-1*i+n,-1*e+r,-1*t+s,1*i+n,-1*e+r,0+s,0+n,0+r,1*t+s,1*i+n,-1*e+r,-1*t+s,1*i+n,-1*e+r,0+s,0+n,0+r,-1*t+s,-1*i+n,-1*e+r,1*t+s,-1*i+n,-1*e+r,0+s,0+n,0+r,1*t+s,-1*i+n,-1*e+r,1*t+s,1*i+n,-1*e+r,0+s,0+n,0+r,-1*t+s,1*i+n,-1*e+r,-1*t+s,-1*i+n,-1*e+r]})}static createCylinder(e=1,t=1,i=1,s=32,n=1,r=!0,o=!0,a=0,l=0,h=0){let c=[],d=[],_=[],u=2*Math.PI,g=0,f=[],p=new oe,m=(t-e)/i;for(let r=0;r<=n;r++){let o=[],d=r/n,v=d*(t-e)+e;for(let e=0;e<=s;e++){let t=e/s*u+0,n=Math.sin(t),r=Math.cos(t);c.push(v*n+a,-d*i+i+l,v*r+h),p.set(n,m,r).normalize(),_.push(p.x,p.y,p.z),o.push(g++)}f.push(o)}for(let e=0;e<s;e++)for(let t=0;t<n;t++){let i=f[t][e],s=f[t+1][e],n=f[t+1][e+1],r=f[t][e+1];d.push(i,s,r),d.push(s,n,r)}if(0!==e&&r){let t=mi.createDisc(e,i,s,!0,g,a,l,h);c.push(...t.vertices),_.push(...t.normals),d.push(...t.indices)}if(0!==t&&o){let e=mi.createDisc(t,0,s,!1,g+(r?1+2*s:0),a,l,h);c.push(...e.vertices),_.push(...e.normals),d.push(...e.indices)}return new mi({vertices:c,normals:_,indices:d})}static createCube(e=1,t=1,i=1,s=0,n=0,r=0){let o=.5*e+s,a=.5*t+n,l=.5*i+r;return new mi({vertices:[-o,-a,l,o,-a,-l,o,-a,l,-o,-a,l,-o,-a,-l,o,-a,-l,-o,a,l,o,a,l,o,a,-l,-o,a,l,o,a,-l,-o,a,-l,-o,-a,l,o,-a,l,-o,a,l,-o,a,l,o,-a,l,o,a,l,-o,-a,-l,-o,a,-l,o,-a,-l,-o,a,-l,o,a,-l,o,-a,-l,o,-a,l,o,-a,-l,o,a,l,o,a,l,o,-a,-l,o,a,-l,-o,-a,l,-o,a,l,-o,-a,-l,-o,a,l,-o,a,-l,-o,-a,-l]})}static createPlane(e=1,t=1,i=0,s=0,n=0){let r=.5*e,o=.5*t;return new mi({vertices:[-r+i,s,o+n,r+i,s,-o+n,r+i,s,o+n,-r+i,s,o+n,-r+i,s,-o+n,r+i,s,-o+n,-r+i,s,o+n,r+i,s,o+n,r+i,s,-o+n,-r+i,s,o+n,r+i,s,-o+n,-r+i,s,-o+n]})}static createArrow(e=0,t=2.1,i=-15){return new mi({vertices:[0,t,0,7,0,6,0,0,i,0,0,e,7,0,6,0,t,0,-7,0,6,0,0,e,0,t,0,-7,0,6,0,t,0,0,0,i,-7,0,6,0,0,i,0,0,e,0,0,e,0,0,i,7,0,6]})}static async readFileObj(e,t){let i=new fi;const s=await i.readFile(e,t);let n=s.materials;return s.geometries.map((e=>{let t=n[e.material]||{};return new mi({name:e.object,vertices:e.data.vertices,normals:e.data.normals,texCoords:e.data.texCoords,ambient:t.ambient,diffuse:t.diffuse,specular:t.specular,shininess:t.shininess,color:t.color,colorTexture:t.colorTexture,normalTexture:t.normalTexture,metallicRoughnessTexture:t.metallicRoughnessTexture})}))}static async loadObj(e){let t=new fi;const i=await t.load(e);let s=i.materials;return i.geometries.map((e=>{let t=s[e.material]||{};return new mi({name:e.object,vertices:e.data.vertices,normals:e.data.normals,texCoords:e.data.texCoords,ambient:t.ambient,diffuse:t.diffuse,specular:t.specular,shininess:t.shininess,color:t.color,colorTexture:t.colorTexture,normalTexture:t.normalTexture,metallicRoughnessTexture:t.metallicRoughnessTexture})}))}merge(e){const t=this._vertices.length/3;let i=this._vertices.length;this._vertices.length=i+e._vertices.length;for(let t=0;t<e._vertices.length;t++)this._vertices[i+t]=e._vertices[t];i=this._normals.length,this._normals.length=i+e._normals.length;for(let t=0;t<e._normals.length;t++)this._normals[i+t]=e._normals[t];i=this._texCoords.length,this._texCoords.length=i+e._texCoords.length;for(let t=0;t<e._texCoords.length;t++)this._texCoords[i+t]=e._texCoords[t];i=this._indices.length,this._indices.length=i+e._indices.length;for(let s=0;s<e._indices.length;s++)this._indices[i+s]=e._indices[s]+t;return this._numVertices=this._vertices.length/3,this}static merge(e,t){let i=new mi,s=t||e.length;for(let t=0;t<s;t++)i.merge(e[t]);return i}}const vi=new oe(0,0,-1);class yi{constructor(e){this._handlerIndex=-1,this._tag=e.tag||"tag_"+yi.__counter__++,this._entity=null,this._position=Ae(e.position),this._rtcPositionHigh=new oe,this._rtcPositionLow=new oe,this._scale=Ae(e.scale,new oe(1,1,1)),this._translate=Ae(e.translate,new oe),this._localPosition=new oe,this._color=Pe(e.color,new se(.15,.15,.15,1)),this._handler=null,this._handlerIndex=-1,this._tagData=null,this._tagDataIndex=-1;let t=e.object3d;e.object3d&&0!==e.object3d?.vertices.length||(t=new mi),e.objSrc&&(this.setObjectSrc(e.objSrc),this._objectSrc=e.objSrc),this._object3d=t,this._visibility=null==e.visibility||e.visibility,this._children=[],this._direction=new oe,this._qFrame=new re,this._qRot=re.IDENTITY}get tag(){return this._tag}getPosition(){return this._position}get object3d(){return this._object3d}get vertices(){return this._object3d.vertices}get normals(){return this._object3d.normals}get texCoords(){return this._object3d.texCoords}get indices(){return this._object3d.indices}setOpacity(e){this._color.w=e,this.setColor(this._color.x,this._color.y,this._color.z,e)}getOpacity(){return this._color.w}setColor(e,t,i,s){this._color.x=e,this._color.y=t,this._color.z=i,null!=s&&(this._color.w=s),this._handler&&this._handler.setRgbaArr(this._tagData,this._tagDataIndex,this._color)}setColor4v(e){this._color.x=e.x,this._color.y=e.y,this._color.z=e.z,null!=e.w&&(this._color.w=e.w),this._handler&&this._handler.setRgbaArr(this._tagData,this._tagDataIndex,this._color)}setVisibility(e){this._visibility=e,this._handler&&this._handler.setVisibility(this._tagData,this._tagDataIndex,e)}getVisibility(){return this._visibility}setPosition(e,t,i){this._position.x=e,this._position.y=t,this._position.z=i,this.updateRTCPosition(),this.updateRotation()}updateRTCPosition(){this._handler&&(this._handler.getRTCPosition(this._position,this._rtcPositionHigh,this._rtcPositionLow),this._handler.setRTCPositionArr(this._tagData,this._tagDataIndex,this._rtcPositionHigh,this._rtcPositionLow))}setPosition3v(e){this.setPosition(e.x,e.y,e.z)}setObject(e){this._object3d=e}setObjectSrc(e){this._objectSrc=e,this._handler&&this._handler.setObjectSrc(e,this.tag)}setColorHTML(e){this.setColor4v(ye(e))}setScale(e){this._scale.x=this._scale.y=this._scale.z=e,this._handler&&this._handler.setScaleArr(this._tagData,this._tagDataIndex,this._scale)}setScale3v(e){this._scale.copy(e),this._handler&&this._handler.setScaleArr(this._tagData,this._tagDataIndex,e)}getScale(){return this._scale}setTranslate3v(e){this._translate.copy(e),this._handler&&this._handler.setTranslateArr(this._tagData,this._tagDataIndex,e)}getTranslate(){return this._translate.clone()}setLocalPosition3v(e){this._localPosition.copy(e),this._handler&&this._handler.setLocalPositionArr(this._tagData,this._tagDataIndex,e)}getLocalPosition(){return this._localPosition.clone()}remove(){this._entity=null,this._handler&&this._handler.remove(this)}setPickingColor3v(e){this._handler&&this._handler.setPickingColorArr(this._tagData,this._tagDataIndex,e)}setRotation(e){this._qRot.copy(e),this._qRot.mulVec3Res(vi,this._direction).normalize(),this.updateRotation()}getRotation(){return this._qRot}updateRotation(){this._handler&&this._handler.setQRotArr(this._tagData,this._tagDataIndex,this._qRot)}getDirection(){return this._direction.clone()}}yi.__counter__=0;const xi={RIGHT:0,LEFT:1,CENTER:2},bi={left:xi.LEFT,right:xi.RIGHT,center:xi.CENTER};class wi extends ri{constructor(e={}){super(e),this._handler=null,this._text=e.text||"",this._face=Le(e.face,"arial"),this._size=e.size||24,this._outline=null!=e.outline?e.outline:0,this._outlineColor=Pe(e.outlineColor,new se(0,0,0,1)),this._align=e.align&&bi[e.align.trim().toLowerCase()]||xi.RIGHT,this._fontIndex=0,this._fontAtlas=null,this._isRTL=e.isRTL||!1,this._letterSpacing=e.letterSpacing||0}setText(e){this._text=e.toString(),this._isReady&&this._handler&&this._handler.setText(this._handlerIndex,e,this._fontIndex,this._align,this._letterSpacing,this._isRTL)}setLetterSpacing(e){this._letterSpacing=e,this._isReady&&this._handler&&this._handler.setText(this._handlerIndex,this._text,this._fontIndex,this._align,e,this._isRTL)}getLetterSpacing(){return this._letterSpacing}setRtl(e){this._isRTL=e,this._isReady&&this._handler&&this._handler.setText(this._handlerIndex,this._text,this._fontIndex,this._align,this._letterSpacing,this._isRTL)}getText(){return this._text}setAlign(e){this._align=bi[e.trim().toLowerCase()],this._isReady&&this._handler?this._handler.setText(this._handlerIndex,this._text,this._fontIndex,this._align,this._letterSpacing,this._isRTL):this._lockId!==ii&&(this._lockId=ti)}getAlign(){return this._align}setFace(e){this._face=e.trim(),this.update()}getFace(){return this._face}setSize(e){e!==this._size&&(this._size=e,this._isReady&&this._handler?this._handler.setSizeArr(this._handlerIndex,e):this._lockId!==ii&&(this._lockId=ti))}getSize(){return this._size}setOutline(e){this._outline=e,this._isReady&&this._handler?this._handler.setOutlineArr(this._handlerIndex,e):this._lockId!==ii&&(this._lockId=ti)}getOutline(){return this._outline}setOpacity(e){super.setOpacity(e),this.setOutlineOpacity(e)}setOutlineColor(e,t,i,s){s===this._outlineColor.w&&e===this._outlineColor.x&&t===this._outlineColor.y&&i===this._outlineColor.z||(this._outlineColor.x=e,this._outlineColor.y=t,this._outlineColor.z=i,this._outlineColor.w=s,this._isReady&&this._handler?this._handler.setOutlineColorArr(this._handlerIndex,this._outlineColor):this._lockId!==ii&&(this._lockId=ti))}setOutlineColor4v(e){this.setOutlineColor(e.x,e.y,e.z,e.w)}setOutlineColorHTML(e){this.setOutlineColor4v(ye(e))}getOutlineColor(){return this._outlineColor}setOutlineOpacity(e){e!==this._outlineColor.w&&(this._outlineColor.w=e,this._isReady&&this._handler?this._handler.setOutlineColorArr(this._handlerIndex,this._outlineColor):this._lockId!==ii&&(this._lockId=ti))}getOutlineOpacity(){return this._outlineColor.w}async update(){if(this._fontAtlas){const e=await this._fontAtlas.getFontIndex(this._face);this._applyFontIndex(e)}}_applyFontIndex(e){this._fontIndex=e,this._isReady&&this._handler?(this._handler.setFontIndexArr(this._handlerIndex,this._fontIndex),this._handler.setText(this._handlerIndex,this._text,this._fontIndex,this._align,this._letterSpacing,this._isRTL)):this._lockId!==ii&&(this._lockId=ti)}assignFontAtlas(e){this._fontAtlas||(this._fontAtlas=e),this.update()}serializeWorkerData(e){return this._handler?new Float32Array([e,this._handler._maxLetters,this.getVisibility()?1:0,this._positionHigh.x,this._positionHigh.y,this._positionHigh.z,this._positionLow.x,this._positionLow.y,this._positionLow.z,this._size,this._offset.x,this._offset.y,this._offset.z,this._color.x,this._color.y,this._color.z,this._color.w,this._rotation,this._alignedAxis.x,this._alignedAxis.y,this._alignedAxis.z,this._fontIndex,this._outline,this._outlineColor.x,this._outlineColor.y,this._outlineColor.z,this._outlineColor.w,this._entity._pickingColor.x,this._entity._pickingColor.y,this._entity._pickingColor.z]):null}}class Ci{constructor(e={}){this.__id=Ci.__counter__++,this.visibility=null==e.visibility||e.visibility,this.pointSize=e.pointSize||3,this.pickingScale=e.pickingScale||0,this._renderNode=null,this._entity=null,this._points=[],this._coordinatesData=[],this._colorData=[],this._pickingColorData=[],this._coordinatesBuffer=null,this._colorBuffer=null,this._pickingColorBuffer=null,this._handler=null,this._handlerIndex=-1,this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[0]=this._createCoordinatesBuffer,this._buffersUpdateCallbacks[1]=this._createColorBuffer,this._buffersUpdateCallbacks[2]=this._createPickingColorBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length),e.points&&this.setPoints(e.points)}clear(){this._points.length=0,this._points=[],this._coordinatesData.length=0,this._coordinatesData=[],this._colorData.length=0,this._colorData=[],this._pickingColorData.length=0,this._pickingColorData=[],this._deleteBuffers()}setVisibility(e){this.visibility=e}getVisibility(){return this.visibility}setRenderNode(e){this._renderNode=e,this._setPickingColors()}remove(){this._entity=null,this._handler&&this._handler.remove(this)}setPoints(e){this.clear();for(let t=0;t<e.length;t++){let i=e[t],s=new oe(i[0],i[1],i[2]),n=new se(i[3],i[4],i[5],null==i[6]?255:i[6]);this._coordinatesData.push(s.x,s.y,s.z),this._colorData.push(n.x/255,n.y/255,n.z/255,n.w/255);let r={_entity:this._entity,_pickingColor:new oe,_entityCollection:this._entity?this._entity._entityCollection:null,index:t,position:s,color:n,pointCloud:this,properties:i[7]||{}};this._points.push(r),this._renderNode&&this._renderNode.renderer&&(this._renderNode.renderer.assignPickingColor(r),this._pickingColorData.push(r._pickingColor.x/255,r._pickingColor.y/255,r._pickingColor.z/255,1))}this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}setPointPosition(e,t,i,s){this._changedBuffers[0]=!0}setPointColor(e,t,i,s,n){this._changedBuffers[1]=!0}addPoints(e){this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}addPoint(e,t){this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}getPoint(e){return this._points[e]}removePoint(e){this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}insertPoint(e,t){this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}draw(){if(this.visibility&&this._coordinatesData.length){this._update();let e=this._renderNode.renderer,t=e.handler.programs.pointCloud,i=t._program,s=e.handler.gl,n=i.attributes,r=i.uniforms;t.activate(),s.uniformMatrix4fv(r.projectionViewMatrix,!1,e.activeCamera.getProjectionViewMatrix()),s.uniform1f(r.opacity,this._handler._entityCollection._fadingOpacity),s.uniform1f(r.pointSize,this.pointSize),s.bindBuffer(s.ARRAY_BUFFER,this._coordinatesBuffer),s.vertexAttribPointer(n.coordinates,this._coordinatesBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._colorBuffer),s.vertexAttribPointer(n.colors,this._colorBuffer.itemSize,s.FLOAT,!1,0,0),s.drawArrays(s.POINTS,0,this._coordinatesBuffer.numItems)}}drawPicking(){if(this.visibility&&this._coordinatesData.length){let e=this._renderNode.renderer,t=e.handler.programs.pointCloud,i=t._program,s=e.handler.gl,n=i.attributes,r=i.uniforms;t.activate(),s.uniformMatrix4fv(r.projectionViewMatrix,!1,e.activeCamera.getProjectionViewMatrix()),s.uniform1f(r.opacity,this._handler._entityCollection._fadingOpacity),s.uniform1f(r.pointSize,this.pointSize+this.pickingScale),s.bindBuffer(s.ARRAY_BUFFER,this._coordinatesBuffer),s.vertexAttribPointer(n.coordinates,this._coordinatesBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._pickingColorBuffer),s.vertexAttribPointer(n.colors,this._pickingColorBuffer.itemSize,s.FLOAT,!1,0,0),s.drawArrays(s.POINTS,0,this._coordinatesBuffer.numItems)}}_update(){if(this._renderNode){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1)}}_deleteBuffers(){if(this._renderNode){let e=this._renderNode.renderer.handler.gl;e.deleteBuffer(this._coordinatesBuffer),e.deleteBuffer(this._colorBuffer),e.deleteBuffer(this._pickingColorBuffer)}this._coordinatesBuffer=null,this._colorBuffer=null,this._pickingColorBuffer=null}_createCoordinatesBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._coordinatesBuffer),this._coordinatesBuffer=e.createArrayBuffer(new Float32Array(this._coordinatesData),3,this._coordinatesData.length/3)}_createColorBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._colorBuffer),this._colorBuffer=e.createArrayBuffer(new Float32Array(this._colorData),4,this._colorData.length/4)}_createPickingColorBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._pickingColorBuffer),this._pickingColorBuffer=e.createArrayBuffer(new Float32Array(this._pickingColorData),4,this._pickingColorData.length/4)}_setPickingColors(){if(this._renderNode&&this._renderNode.renderer){for(let e=0;e<this._points.length;e++){let t=this._points[e];t._entity=this._entity,t._entityCollection=this._entity._entityCollection,this._renderNode.renderer.assignPickingColor(t),this._pickingColorData.push(t._pickingColor.x/255,t._pickingColor.y/255,t._pickingColor.z/255,1)}this._changedBuffers[2]=!0}}}Ci.__counter__=0;class Ti{constructor(e={}){this.__id=Ti.__counter__++,this.__doubleToTwoFloats=oe.doubleToTwoFloats,this.altitude=e.altitude||0,this.thickness=e.thickness||1.5,this._opacity=null!=e.opacity?e.opacity:1,this._defaultColor=xe(e.color||"#0000FF",e.opacity),this.visibility=null==e.visibility||e.visibility,this._closedLine=e.isClosed||!1,this._path3v=[],this._pathLengths=[],this._pathLonLat=[],this._pathLonLatMerc=[],this._pathColors=e.pathColors?$e(e.pathColors):[],this._extent=new te,this._verticesHigh=[],this._verticesLow=[],this._orders=[],this._indexes=[],this._colors=[],this._verticesHighBuffer=null,this._verticesLowBuffer=null,this._ordersBuffer=null,this._indexesBuffer=null,this._colorsBuffer=null,this._pickingColor=[0,0,0],this._renderNode=null,this._entity=null,this._handler=null,this._handlerIndex=-1,this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[0]=this._createVerticesBuffer,this._buffersUpdateCallbacks[1]=this._createIndexBuffer,this._buffersUpdateCallbacks[2]=this._createColorsBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length);let t=Ae(e.visibleSpherePosition).toArray(),i=e.visibleSphereRadius||0;this._visibleSphere=new Float32Array([...t,i]),e.pathLonLat?this.setPathLonLat(e.pathLonLat):e.path3v&&this.setPath3v(e.path3v),this._refresh()}__appendLineData3v(e,t,i,s,n,r,o,a,l,h,c,d,_,u){var g=0,f=new oe,p=new oe;_&&(_.southWest.set(180,90),_.northEast.set(-180,-90)),a.length>0?(g=a[a.length-5]+9,a.push(g,g)):a.push(0,0);for(let L=0,A=e.length;L<A;L++){var m=e[L],v=t[L];if(h[L]=[],d[L]=[],c[L]=[],0===m.length)continue;var y,x=g;if(s)(y=m[m.length-1])instanceof Array&&(y=new oe(y[0],y[1],y[2]));else{var b=m[0],w=m[1]||b;b instanceof Array&&(b=new oe(b[0],b[1],b[2])),w instanceof Array&&(w=new oe(w[0],w[1],w[2])),y=new oe(b.x+b.x-w.x,b.y+b.y-w.y,b.z+b.z-w.z)}let A=i;v&&v[0]&&(A=v[0]),this.__doubleToTwoFloats(y,f,p),n.push(f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z),r.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z);let P=A[0],S=A[1],M=A[2],R=null!=A[3]?A[3]:1;L>0&&u.push(P,S,M,R,P,S,M,R,P,S,M,R,P,S,M,R),o.push(1,-1,2,-2);for(let e=0,t=m.length;e<t;e++){var C=m[e];if(C instanceof Array&&(C=new oe(C[0],C[1],C[2])),c[L].push(C),l){var T=l.cartesianToLonLat(C);h[L].push(T),d[L].push(T.forwardMercator()),T.lon<_.southWest.lon&&(_.southWest.lon=T.lon),T.lat<_.southWest.lat&&(_.southWest.lat=T.lat),T.lon>_.northEast.lon&&(_.northEast.lon=T.lon),T.lat>_.northEast.lat&&(_.northEast.lat=T.lat)}v&&v[e]&&(A=v[e]),P=A[0],S=A[1],M=A[2],R=null!=A[3]?A[3]:1,this.__doubleToTwoFloats(C,f,p),n.push(f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z),r.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z),u.push(P,S,M,R,P,S,M,R,P,S,M,R,P,S,M,R),o.push(1,-1,2,-2),a.push(g++,g++,g++,g++)}var E;if(s)(E=m[0])instanceof Array&&(E=new oe(E[0],E[1],E[2])),a.push(x,x+1,x+1,x+1);else{let e=m[m.length-1],t=m[m.length-2]||e;e instanceof Array&&(e=new oe(e[0],e[1],e[2])),t instanceof Array&&(t=new oe(t[0],t[1],t[2])),E=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z),a.push(g-1,g-1,g-1,g-1)}v&&v[m.length-1]&&(A=v[m.length-1]),P=A[0],S=A[1],M=A[2],R=null!=A[3]?A[3]:1,this.__doubleToTwoFloats(E,f,p),n.push(f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z),r.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z),u.push(P,S,M,R,P,S,M,R,P,S,M,R,P,S,M,R),o.push(1,-1,2,-2),L<e.length-1&&0!==e[L+1].length&&(g+=8,a.push(g,g))}}__appendPoint3v(e,t,i,s,n,r,o,a,l,h,c,d,_,u){var g=new oe,f=new oe,p=h.length-4,m=h[p-1]+1;0===e.length?(e.push([]),i[0]||(i[0]=[])):i[e.length-1]||(i[e.length-1]=[]);var v=e[e.length-1],y=v.length;v.push(t);let x=s[0],b=s[1],w=s[2],C=null!=s[3]?s[3]:1,T=i[e.length-1];if(T[y]?(T[y][0]=x,T[y][1]=b,T[y][2]=w,T[y][3]=C):T.push(s),1===y){var E;if(n)(E=v[y-1])instanceof Array&&(E=new oe(E[0],E[1],E[2]));else{let e=v[0],t=v[1]||e;e instanceof Array&&(e=new oe(e[0],e[1],e[2])),t instanceof Array&&(t=new oe(t[0],t[1],t[2])),E=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}this.__doubleToTwoFloats(E,g,f);let e=r.length-36;r[e]=g.x,r[e+1]=g.y,r[e+2]=g.z,r[e+3]=g.x,r[e+4]=g.y,r[e+5]=g.z,r[e+6]=g.x,r[e+7]=g.y,r[e+8]=g.z,r[e+9]=g.x,r[e+10]=g.y,r[e+11]=g.z,o[e]=f.x,o[e+1]=f.y,o[e+2]=f.z,o[e+3]=f.x,o[e+4]=f.y,o[e+5]=f.z,o[e+6]=f.x,o[e+7]=f.y,o[e+8]=f.z,o[e+9]=f.x,o[e+10]=f.y,o[e+11]=f.z}var L=m;if(c){0===d.length&&d.push([]),0===_.length&&_.push([]);var A=d[d.length-1],P=_[_.length-1];let e=c.cartesianToLonLat(t);A.push(e),P.push(e.forwardMercator()),e.lon<u.southWest.lon&&(u.southWest.lon=e.lon),e.lat<u.southWest.lat&&(u.southWest.lat=e.lat),e.lon>u.northEast.lon&&(u.northEast.lon=e.lon),e.lat>u.northEast.lat&&(u.northEast.lat=e.lat)}this.__doubleToTwoFloats(t,g,f);let S=r.length-12;r[S]=g.x,r[S+1]=g.y,r[S+2]=g.z,r[S+3]=g.x,r[S+4]=g.y,r[S+5]=g.z,r[S+6]=g.x,r[S+7]=g.y,r[S+8]=g.z,r[S+9]=g.x,r[S+10]=g.y,r[S+11]=g.z,o[S]=f.x,o[S+1]=f.y,o[S+2]=f.z,o[S+3]=f.x,o[S+4]=f.y,o[S+5]=f.z,o[S+6]=f.x,o[S+7]=f.y,o[S+8]=f.z,o[S+9]=f.x,o[S+10]=f.y,o[S+11]=f.z;let M=a.length-16;var R;if(a[M]=x,a[M+1]=b,a[M+2]=w,a[M+3]=C,a[M+4]=x,a[M+5]=b,a[M+6]=w,a[M+7]=C,a[M+8]=x,a[M+9]=b,a[M+10]=w,a[M+11]=C,a[M+12]=x,a[M+13]=b,a[M+14]=w,a[M+15]=C,h[p]=m++,h[p+1]=m++,h[p+2]=m++,h[p+3]=m++,n)R=v[0],h.push(L,L+1,L+1,L+1);else{let e=v[v.length-1],t=v[v.length-2]||e;R=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z),h.push(m-1,m-1,m-1,m-1)}this.__doubleToTwoFloats(R,g,f),r.push(g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z),o.push(f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z),a.push(x,b,w,C,x,b,w,C,x,b,w,C,x,b,w,C),l.push(1,-1,2,-2)}static setPathColors(e,t,i,s){for(let a=0,l=e.length;a<l;a++){var n=e[a],r=t[a];if(0===n.length)continue;let l=i;r&&r[0]&&(l=r[0]);let h=l[0],c=l[1],d=l[2],_=null!=l[3]?l[3]:1;a>0&&s.push(h,c,d,_,h,c,d,_,h,c,d,_,h,c,d,_);for(let e=0,t=n.length;e<t;e++){var o=n[e];o instanceof Array&&(o=new I(o[0],o[1],o[2])),r&&r[e]&&(l=r[e]),h=l[0],c=l[1],d=l[2],_=null!=l[3]?l[3]:1,s.push(h,c,d,_,h,c,d,_,h,c,d,_,h,c,d,_)}r&&r[n.length-1]&&(l=r[n.length-1]),h=l[0],c=l[1],d=l[2],_=null!=l[3]?l[3]:1,s.push(h,c,d,_,h,c,d,_,h,c,d,_,h,c,d,_)}}__appendLineDataLonLat(e,t,i,s,n,r,o,a,l,h,c,d,_,u){var g=0,f=new oe,p=new oe;_&&(_.southWest.set(180,90),_.northEast.set(-180,-90)),a.length>0?(g=a[a.length-5]+9,a.push(g)):a.push(0);for(let T=0,E=e.length;T<E;T++){var m=e[T],v=t[T];if(h[T]=[],d[T]=[],c[T]=[],0===m.length)continue;var y,x=g;if(s){let e=m[m.length-1];y=e instanceof Array?l.lonLatToCartesian(new I(e[0],e[1],e[2])):l.lonLatToCartesian(e)}else{let e,t,i=m[0];e=i instanceof Array?l.lonLatToCartesian(new I(i[0],i[1],i[2])):l.lonLatToCartesian(i),i=m[1],i||(i=m[0]),t=i instanceof Array?l.lonLatToCartesian(new I(i[0],i[1],i[2])):l.lonLatToCartesian(i),y=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}let E=i;v&&v[0]&&(E=v[0]),this.__doubleToTwoFloats(y,f,p),n.push(f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z),r.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z);let L=E[0],A=E[1],P=E[2],S=null!=E[3]?E[3]:1;T>0&&u.push(L,A,P,S,L,A,P,S,L,A,P,S,L,A,P,S),o.push(1,-1,2,-2);for(let e=0,t=m.length;e<t;e++){var b=m[e];b instanceof Array&&(b=new I(b[0],b[1],b[2])),v&&v[e]&&(E=v[e]),L=E[0],A=E[1],P=E[2],S=null!=E[3]?E[3]:1;var w=l.lonLatToCartesian(b);h[T].push(w),c[T].push(b),d[T].push(b.forwardMercator()),this.__doubleToTwoFloats(w,f,p),n.push(f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z),r.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z),u.push(L,A,P,S,L,A,P,S,L,A,P,S,L,A,P,S),o.push(1,-1,2,-2),a.push(g++,g++,g++,g++),b.lon<_.southWest.lon&&(_.southWest.lon=b.lon),b.lat<_.southWest.lat&&(_.southWest.lat=b.lat),b.lon>_.northEast.lon&&(_.northEast.lon=b.lon),b.lat>_.northEast.lat&&(_.northEast.lat=b.lat)}var C;if(s){let e=m[0];C=e instanceof Array?l.lonLatToCartesian(new I(e[0],e[1],e[2])):l.lonLatToCartesian(e),a.push(x,x+1,x+1,x+1)}else{let e,t,i=m[m.length-1];e=i instanceof Array?l.lonLatToCartesian(new I(i[0],i[1],i[2])):l.lonLatToCartesian(i),i=m[m.length-2],i||(i=m[0]),t=i instanceof Array?l.lonLatToCartesian(new I(i[0],i[1],i[2])):l.lonLatToCartesian(i),C=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z),a.push(g-1,g-1,g-1,g-1)}v&&v[m.length-1]&&(E=v[m.length-1]),L=E[0],A=E[1],P=E[2],S=null!=E[3]?E[3]:1,this.__doubleToTwoFloats(C,f,p),n.push(f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z),r.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z),u.push(L,A,P,S,L,A,P,S,L,A,P,S,L,A,P,S),o.push(1,-1,2,-2),T<e.length-1&&0!==e[T+1].length&&(g+=8,a.push(g,g))}}_setEqualPath3v(e){var t=this._extent;t.southWest.set(180,90),t.northEast.set(-180,-90);var i=new oe,s=new oe,n=this._verticesHigh,r=this._verticesLow,o=this._pathLonLat,a=this._pathLonLatMerc,l=0,h=this._renderNode.ellipsoid;for(let m=0;m<e.length;m++){var c,d,_=e[m];c=this._closedLine?_[_.length-1]:new oe(_[0].x+_[0].x-_[1].x,_[0].y+_[0].y-_[1].y,_[0].z+_[0].z-_[1].z),this.__doubleToTwoFloats(c,i,s),n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z,n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z,n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z,n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z;for(let e=0;e<_.length;e++){var u=_[e],g=this._path3v[m][e];if(g.x=u.x,g.y=u.y,g.z=u.z,h){var f=h.cartesianToLonLat(u);this._pathLonLat[m][e]=f,o[m][e]=f,a[m][e]=f.forwardMercator(),f.lon<t.southWest.lon&&(t.southWest.lon=f.lon),f.lat<t.southWest.lat&&(t.southWest.lat=f.lat),f.lon>t.northEast.lon&&(t.northEast.lon=f.lon),f.lat>t.northEast.lat&&(t.northEast.lat=f.lat)}this.__doubleToTwoFloats(u,i,s),n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z,n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z,n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z,n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z}if(this._closedLine)d=_[0];else{var p=_.length-1;d=new oe(_[p].x+_[p].x-_[p-1].x,_[p].y+_[p].y-_[p-1].y,_[p].z+_[p].z-_[p-1].z)}this.__doubleToTwoFloats(d,i,s),n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z,n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z,n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z,n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z}}_setEqualPathLonLat(e){var t=this._extent;t.southWest.set(180,90),t.northEast.set(-180,-90);var i=new oe,s=new oe,n=this._verticesHigh,r=this._verticesLow,o=this._pathLonLat,a=this._pathLonLatMerc,l=this._path3v,h=0,c=this._renderNode.ellipsoid;for(let p=0;p<e.length;p++){var d,_,u=e[p];if(this._closedLine)d=c.lonLatToCartesian(u[u.length-1]);else{let e=c.lonLatToCartesian(u[0]),t=c.lonLatToCartesian(u[1]);d=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}this.__doubleToTwoFloats(d,i,s),n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z,n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z,n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z,n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z;for(let e=0;e<u.length;e++){var g=u[e],f=c.lonLatToCartesian(g);l[p][e]=f,a[p][e]=g.forwardMercator(),o[p][e]=g,this.__doubleToTwoFloats(f,i,s),n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z,n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z,n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z,n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z,g.lon<t.southWest.lon&&(t.southWest.lon=g.lon),g.lat<t.southWest.lat&&(t.southWest.lat=g.lat),g.lon>t.northEast.lon&&(t.northEast.lon=g.lon),g.lat>t.northEast.lat&&(t.northEast.lat=g.lat)}if(this._closedLine)_=c.lonLatToCartesian(u[0]);else{let e=c.lonLatToCartesian(u[u.length-1]),t=c.lonLatToCartesian(u[u.length-2]);_=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}this.__doubleToTwoFloats(_,i,s),n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z,n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z,n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z,n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z}}setPointLonLat(e,t,i){if(this._renderNode&&this._renderNode.ellipsoid){let a=this._pathLonLat,l=this._pathLonLatMerc;a[i][t]=e,l[i][t]=e.forwardMercator();var s=this._extent;s.southWest.set(180,90),s.northEast.set(-180,-90);for(let e=0;e<a.length;e++){var n=a[e];for(let e=0;e<n.length;e++){var r=n[e].lon,o=n[e].lat;r>s.northEast.lon&&(s.northEast.lon=r),o>s.northEast.lat&&(s.northEast.lat=o),r<s.southWest.lon&&(s.southWest.lon=r),o<s.southWest.lat&&(s.southWest.lat=o)}}this.setPoint3v(this._renderNode.ellipsoid.lonLatToCartesian(e),t,i,!0)}else{let s=this._pathLonLat[i];s[t].lon=e.lon,s[t].lat=e.lat,s[t].height=e.height}}setPoint3v(e,t=0,i=0,s=!1){if(this._renderNode){var n,r=new oe,o=new oe,a=this._verticesHigh,l=this._verticesLow,h=this._pathLonLat,c=this._pathLonLatMerc,d=0;n=12*this._pathLengths[i]+24*i;let x=this._path3v[i];x[t].x=e.x,x[t].y=e.y,x[t].z=e.z;let b=this._closedLine||1===x.length;var _;if(0===t||1===t)_=b?x[x.length-1]:new oe(x[0].x+x[0].x-x[1].x,x[0].y+x[0].y-x[1].y,x[0].z+x[0].z-x[1].z),d=n,this.__doubleToTwoFloats(_,r,o),a[d]=r.x,a[d+1]=r.y,a[d+2]=r.z,a[d+3]=r.x,a[d+4]=r.y,a[d+5]=r.z,a[d+6]=r.x,a[d+7]=r.y,a[d+8]=r.z,a[d+9]=r.x,a[d+10]=r.y,a[d+11]=r.z,l[d]=o.x,l[d+1]=o.y,l[d+2]=o.z,l[d+3]=o.x,l[d+4]=o.y,l[d+5]=o.z,l[d+6]=o.x,l[d+7]=o.y,l[d+8]=o.z,l[d+9]=o.x,l[d+10]=o.y,l[d+11]=o.z;if(!s&&this._renderNode.ellipsoid){var u=this._renderNode.ellipsoid.cartesianToLonLat(e);h[i][t]=u,c[i][t]=u.forwardMercator();var g=this._extent;g.southWest.set(180,90),g.northEast.set(-180,-90);for(let e=0;e<h.length;e++){var f=h[e];for(let e=0;e<f.length;e++){var p=f[e].lon,m=f[e].lat;p>g.northEast.lon&&(g.northEast.lon=p),m>g.northEast.lat&&(g.northEast.lat=m),p<g.southWest.lon&&(g.southWest.lon=p),m<g.southWest.lat&&(g.southWest.lat=m)}}}if(d=n+12*t+12,this.__doubleToTwoFloats(e,r,o),a[d]=r.x,a[d+1]=r.y,a[d+2]=r.z,a[d+3]=r.x,a[d+4]=r.y,a[d+5]=r.z,a[d+6]=r.x,a[d+7]=r.y,a[d+8]=r.z,a[d+9]=r.x,a[d+10]=r.y,a[d+11]=r.z,l[d]=o.x,l[d+1]=o.y,l[d+2]=o.z,l[d+3]=o.x,l[d+4]=o.y,l[d+5]=o.z,l[d+6]=o.x,l[d+7]=o.y,l[d+8]=o.z,l[d+9]=o.x,l[d+10]=o.y,l[d+11]=o.z,t===x.length-1||t===x.length-2){var v;if(b)v=x[0];else{var y=x.length-1;v=new oe(x[y].x+x[y].x-x[y-1].x,x[y].y+x[y].y-x[y-1].y,x[y].z+x[y].z-x[y-1].z)}d=n+12*x.length+12,this.__doubleToTwoFloats(v,r,o),a[d]=r.x,a[d+1]=r.y,a[d+2]=r.z,a[d+3]=r.x,a[d+4]=r.y,a[d+5]=r.z,a[d+6]=r.x,a[d+7]=r.y,a[d+8]=r.z,a[d+9]=r.x,a[d+10]=r.y,a[d+11]=r.z,l[d]=o.x,l[d+1]=o.y,l[d+2]=o.z,l[d+3]=o.x,l[d+4]=o.y,l[d+5]=o.z,l[d+6]=o.x,l[d+7]=o.y,l[d+8]=o.z,l[d+9]=o.x,l[d+10]=o.y,l[d+11]=o.z}this._changedBuffers[0]=!0}else{let s=this._path3v[i];s[t].x=e.x,s[t].y=e.y,s[t].z=e.z}}_resizePathLengths(e=0){this._pathLengths[0]=0;for(let t=e+1,i=this._path3v.length;t<=i;t++)this._pathLengths[t]=this._pathLengths[t-1]+this._path3v[t-1].length}removeSegment(e){this._path3v.splice(e,1),this.setPath3v([].concat(this._path3v))}removePoint(e,t=0){this._path3v[t].splice(e,1),0===this._path3v[t].length&&this._path3v.splice(t,1),this.setPath3v([].concat(this._path3v))}insertPoint3v(e,t=0,i,s=0){let n=[].concat(this._path3v),r=n[s];if(r){let o=[].concat(this._pathColors);if(r.splice(t,0,e),i){let e=o[s];e||(e=new Array(r.length)),e.splice(t,0,i)}this.setPath3v(n,o)}else this.addPoint3v(e,s)}appendPoint3v(e,t,i){0!==this._path3v.length&&this._renderNode?(this._verticesHigh=Ue(this._verticesHigh),this._verticesLow=Ue(this._verticesLow),this._colors=Ue(this._colors),this._orders=Ue(this._orders),this._indexes=Ue(this._indexes),this.__appendPoint3v(this._path3v,e,this._pathColors,t||this._defaultColor,this._closedLine,this._verticesHigh,this._verticesLow,this._colors,this._orders,this._indexes,i?null:this._renderNode.ellipsoid,this._pathLonLat,this._pathLonLatMerc,this._extent),this._pathLengths[this._path3v.length]+=1,this._changedBuffers[0]=!0,this._changedBuffers[2]=!0,this._changedBuffers[1]=!0):(this._pathColors.push([t||this._defaultColor]),this.addPoint3v(e))}addPoint3v(e,t=0){t>=this._path3v.length&&this._path3v.push([]),this._path3v[t].push(e),this.setPath3v([].concat(this._path3v))}addPointLonLat(e,t=0){t>=this._pathLonLat.length&&this._pathLonLat.push([]),this._pathLonLat[t].push(e),this.setPathLonLat([].concat(this._pathLonLat))}clear(){this._clearData()}setPointColor(e,t=0,i=0){if(this._renderNode&&t<this._path3v[i].length){let s=this._pathColors[i];if(!s){if(!(this._path3v[i]&&t<this._path3v[i].length))return;this._pathColors[i]=new Array(this._path3v[i].length)}s[t]?(s[t][0]=e[0],s[t][1]=e[1],s[t][2]=e[2],s[t][3]=e[3]||1):s[t]=[e[0],e[1],e[2],e[3]||1];let n=this._colors,r=16*t+16*this._pathLengths[i]+32*i;n[r]=n[r+4]=n[r+8]=n[r+12]=e[0],n[r+1]=n[r+5]=n[r+9]=n[r+13]=e[1],n[r+2]=n[r+6]=n[r+10]=n[r+14]=e[2],n[r+3]=n[r+7]=n[r+11]=n[r+15]=e[3]||1,this._changedBuffers[2]=!0}else{this._pathColors[i][t]=e}}setOpacity(e){this._opacity=e}getOpacity(){return this._opacity}setAltitude(e){this.altitude=e}setThickness(e){this.thickness=e}getThickness(){return this.thickness}setVisibility(e){this.visibility=e}getVisibility(){return this.visibility}setRenderNode(e){e&&(this._renderNode=e,this._pathLonLat.length?this._createDataLonLat([].concat(this._pathLonLat)):this._createData3v([].concat(this._path3v)),this._refresh(),e.renderer&&e.renderer.isInitialized()&&this._update())}_clearData(){this._verticesHigh=null,this._verticesLow=null,this._orders=null,this._indexes=null,this._colors=null,this._verticesHigh=[],this._verticesLow=[],this._orders=[],this._indexes=[],this._colors=[],this._path3v.length=0,this._pathLonLat.length=0,this._pathLonLatMerc.length=0,this._path3v=[],this._pathLonLat=[],this._pathLonLatMerc=[]}_createData3v(e){this._clearData(),this.__appendLineData3v(e,this._pathColors,this._defaultColor,this._closedLine,this._verticesHigh,this._verticesLow,this._orders,this._indexes,this._renderNode.ellipsoid,this._pathLonLat,this._path3v,this._pathLonLatMerc,this._extent,this._colors),this._resizePathLengths(0)}_createDataLonLat(e){this._clearData(),this.__appendLineDataLonLat(e,this._pathColors,this._defaultColor,this._closedLine,this._verticesHigh,this._verticesLow,this._orders,this._indexes,this._renderNode.ellipsoid,this._path3v,this._pathLonLat,this._pathLonLatMerc,this._extent,this._colors),this._resizePathLengths(0)}remove(){this._entity=null,this._pathColors.length=0,this._pathColors=[],this._verticesHigh=null,this._verticesLow=null,this._orders=null,this._indexes=null,this._colors=null,this._verticesHigh=[],this._verticesLow=[],this._orders=[],this._indexes=[],this._colors=[],this._deleteBuffers(),this._handler&&this._handler.remove(this)}setPickingColor3v(e){this._pickingColor[0]=e.x/255,this._pickingColor[1]=e.y/255,this._pickingColor[2]=e.z/255}getExtent(){return this._extent.clone()}getPath3v(){return this._path3v}getPathLonLat(){return this._pathLonLat}getPathColors(){return this._pathColors}setPathColors(e){e&&(this._colors=[],this._pathColors=[].concat(e),Ti.setPathColors(this._pathLonLat,e,this._defaultColor,this._colors),this._changedBuffers[2]=!0)}setColorHTML(e){this._defaultColor=xe(e);let t=ye(e),i=this._pathColors;for(let e=0,s=i.length;e<s;e++){let s=i[e];for(let e=0,i=s.length;e<i;e++)s[e][0]=t.x,s[e][1]=t.y,s[e][2]=t.z,s[e][3]=t.w}let s=this._colors;for(let e=0,i=s.length;e<i;e+=4)s[e]=t.x,s[e+1]=t.y,s[e+2]=t.z,s[e+3]=t.w;this._changedBuffers[2]=!0}setPathLonLatFast(e,t){this.setPathLonLat(e,t,!0)}setPath3vFast(e,t){this.setPath3v(e,t,!0)}setPathLonLat(e,t,i=!1){t&&(this._pathColors=[].concat(t)),this._renderNode&&this._renderNode.ellipsoid?i?(this._setEqualPathLonLat(e),this._changedBuffers[0]=!0,this._changedBuffers[2]=!0):(this._createDataLonLat(e),this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0):this._pathLonLat=[].concat(e)}getSize(e=0){return this._path3v[e].length}setPath3v(e,t,i=!1){t&&(this._pathColors=[].concat(t)),this._renderNode?i?(this._setEqualPath3v(e),this._changedBuffers[0]=!0,this._changedBuffers[2]=!0):(this._createData3v(e),this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0):this._path3v=[].concat(e)}draw(){if(this.visibility&&this._path3v.length){this._update();let e=this._renderNode.renderer,t=e.handler.programs.polyline_screen,i=t._program,s=e.handler.gl,n=i.attributes,r=i.uniforms,o=this._handler._entityCollection;t.activate(),s.disable(s.CULL_FACE),s.uniform1f(r.depthOffset,o.polygonOffsetUnits),s.uniformMatrix4fv(r.proj,!1,e.activeCamera.getProjectionMatrix()),s.uniformMatrix4fv(r.view,!1,e.activeCamera.getViewMatrix()),s.uniform3fv(r.rtcEyePositionHigh,this._handler._rtcEyePositionHigh),s.uniform3fv(r.rtcEyePositionLow,this._handler._rtcEyePositionLow),s.uniform4fv(r.visibleSphere,this._visibleSphere),s.uniform2fv(r.viewport,[e.handler.canvas.width,e.handler.canvas.height]),s.uniform1f(r.thickness,.5*this.thickness),s.uniform1f(r.opacity,this._opacity*o._fadingOpacity),s.bindBuffer(s.ARRAY_BUFFER,this._colorsBuffer),s.vertexAttribPointer(n.color,this._colorsBuffer.itemSize,s.FLOAT,!1,0,0);let a=this._verticesHighBuffer;s.bindBuffer(s.ARRAY_BUFFER,a),s.vertexAttribPointer(n.prevHigh,a.itemSize,s.FLOAT,!1,12,0),s.vertexAttribPointer(n.currentHigh,a.itemSize,s.FLOAT,!1,12,48),s.vertexAttribPointer(n.nextHigh,a.itemSize,s.FLOAT,!1,12,96),a=this._verticesLowBuffer,s.bindBuffer(s.ARRAY_BUFFER,a),s.vertexAttribPointer(n.prevLow,a.itemSize,s.FLOAT,!1,12,0),s.vertexAttribPointer(n.currentLow,a.itemSize,s.FLOAT,!1,12,48),s.vertexAttribPointer(n.nextLow,a.itemSize,s.FLOAT,!1,12,96),s.bindBuffer(s.ARRAY_BUFFER,this._ordersBuffer),s.vertexAttribPointer(n.order,this._ordersBuffer.itemSize,s.FLOAT,!1,4,0),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,this._indexesBuffer),s.drawElements(s.TRIANGLE_STRIP,this._indexesBuffer.numItems,s.UNSIGNED_INT,0),s.enable(s.CULL_FACE)}}drawPicking(){if(this.visibility&&this._path3v.length){let e=this._renderNode.renderer,t=e.handler.programs.polyline_picking,i=t._program,s=e.handler.gl,n=i.attributes,r=i.uniforms,o=this._handler._entityCollection;t.activate(),s.disable(s.CULL_FACE),s.uniform1f(r.depthOffset,o.polygonOffsetUnits),s.uniformMatrix4fv(r.proj,!1,e.activeCamera.getProjectionMatrix()),s.uniformMatrix4fv(r.view,!1,e.activeCamera.getViewMatrix()),s.uniform4fv(r.color,[this._pickingColor[0],this._pickingColor[1],this._pickingColor[2],1]),s.uniform3fv(r.rtcEyePositionHigh,this._handler._rtcEyePositionHigh),s.uniform3fv(r.rtcEyePositionLow,this._handler._rtcEyePositionLow),s.uniform4fv(r.visibleSphere,this._visibleSphere),s.uniform2fv(r.viewport,[e.handler.canvas.width,e.handler.canvas.height]),s.uniform1f(r.thickness,.5*this.thickness*o.pickingScale[0]);let a=this._verticesHighBuffer;s.bindBuffer(s.ARRAY_BUFFER,a),s.vertexAttribPointer(n.prevHigh,a.itemSize,s.FLOAT,!1,12,0),s.vertexAttribPointer(n.currentHigh,a.itemSize,s.FLOAT,!1,12,48),s.vertexAttribPointer(n.nextHigh,a.itemSize,s.FLOAT,!1,12,96),a=this._verticesLowBuffer,s.bindBuffer(s.ARRAY_BUFFER,a),s.vertexAttribPointer(n.prevLow,a.itemSize,s.FLOAT,!1,12,0),s.vertexAttribPointer(n.currentLow,a.itemSize,s.FLOAT,!1,12,48),s.vertexAttribPointer(n.nextLow,a.itemSize,s.FLOAT,!1,12,96),s.bindBuffer(s.ARRAY_BUFFER,this._ordersBuffer),s.vertexAttribPointer(n.order,this._ordersBuffer.itemSize,s.FLOAT,!1,4,0),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,this._indexesBuffer),s.drawElements(s.TRIANGLE_STRIP,this._indexesBuffer.numItems,s.UNSIGNED_INT,0),s.enable(s.CULL_FACE)}}_refresh(){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]=!0}_update(){if(this._renderNode){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1)}}_deleteBuffers(){if(this._renderNode){let e=this._renderNode.renderer.handler.gl;e.deleteBuffer(this._verticesHighBuffer),e.deleteBuffer(this._verticesLowBuffer),e.deleteBuffer(this._ordersBuffer),e.deleteBuffer(this._indexesBuffer),e.deleteBuffer(this._colorsBuffer),this._verticesHighBuffer=null,this._verticesLowBuffer=null,this._ordersBuffer=null,this._indexesBuffer=null,this._colorsBuffer=null}}_createVerticesBuffer(){let e=this._renderNode.renderer.handler,t=this._verticesHigh.length/3;this._verticesHighBuffer&&this._verticesHighBuffer.numItems===t||(e.gl.deleteBuffer(this._verticesHighBuffer),e.gl.deleteBuffer(this._verticesLowBuffer),this._verticesHighBuffer=e.createStreamArrayBuffer(3,t),this._verticesLowBuffer=e.createStreamArrayBuffer(3,t)),this._verticesHigh=Ve(this._verticesHigh),this._verticesLow=Ve(this._verticesLow),e.setStreamArrayBuffer(this._verticesHighBuffer,this._verticesHigh),e.setStreamArrayBuffer(this._verticesLowBuffer,this._verticesLow)}_createIndexBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._ordersBuffer),e.gl.deleteBuffer(this._indexesBuffer),this._orders=Ve(this._orders),this._ordersBuffer=e.createArrayBuffer(this._orders,1,this._orders.length/2),this._indexes=Ve(this._indexes,Uint32Array),this._indexesBuffer=e.createElementArrayBuffer(this._indexes,1,this._indexes.length)}_createColorsBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._colorsBuffer),this._colors=Ve(this._colors),this._colorsBuffer=e.createArrayBuffer(new Float32Array(this._colors),4,this._colors.length/4)}setVisibleSphere(e,t){this._handler&&(this._visibleSphere[0]=e.x-this._handler._relativeCenter.x,this._visibleSphere[1]=e.y-this._handler._relativeCenter.y,this._visibleSphere[2]=e.z-this._handler._relativeCenter.z),this._visibleSphere[3]=t}updateRTCPosition(){this._handler&&this._renderNode&&(this._visibleSphere[0]=this._visibleSphere[0]-this._handler._relativeCenter.x,this._visibleSphere[1]=this._visibleSphere[1]-this._handler._relativeCenter.y,this._visibleSphere[2]=this._visibleSphere[2]-this._handler._relativeCenter.z,this._setEqualPath3v(this._path3v)),this._changedBuffers[0]=!0}}Ti.__counter__=0;class Ei{constructor(e={}){this.__id=Ei.__counter__++,this._thickness=e.thickness||2,this._startPosition=Ae(e.startPosition),this._startPositionHigh=new oe,this._startPositionLow=new oe,oe.doubleToTwoFloats(this._startPosition,this._startPositionHigh,this._startPositionLow),this._endPosition=Ae(e.endPosition),this._endPositionHigh=new oe,this._endPositionLow=new oe,oe.doubleToTwoFloats(this._endPosition,this._endPositionHigh,this._endPositionLow),this._startColor=Pe(e.startColor),this._endColor=Pe(e.endColor),this._visibility=null==e.visibility||e.visibility,this._entity=null,this._handler=null,this._handlerIndex=-1}setStartPosition(e,t,i){this._startPosition.x=e,this._startPosition.y=t,this._startPosition.z=i,oe.doubleToTwoFloats(this._startPosition,this._startPositionHigh,this._startPositionLow),this._handler&&this._handler.setStartPositionArr(this._handlerIndex,this._startPositionHigh,this._startPositionLow)}getLength(){return this._startPosition.distance(this._endPosition)}setStartPosition3v(e){this._startPosition.x=e.x,this._startPosition.y=e.y,this._startPosition.z=e.z,oe.doubleToTwoFloats(this._startPosition,this._startPositionHigh,this._startPositionLow),this._handler&&this._handler.setStartPositionArr(this._handlerIndex,this._startPositionHigh,this._startPositionLow)}setEndPosition(e,t,i){this._endPosition.x=e,this._endPosition.y=t,this._endPosition.z=i,oe.doubleToTwoFloats(this._endPosition,this._endPositionHigh,this._endPositionLow),this._handler&&this._handler.setEndPositionArr(this._handlerIndex,this._endPositionHigh,this._endPositionLow)}setEndPosition3v(e){this._endPosition.x=e.x,this._endPosition.y=e.y,this._endPosition.z=e.z,oe.doubleToTwoFloats(this._endPosition,this._endPositionHigh,this._endPositionLow),this._handler&&this._handler.setEndPositionArr(this._handlerIndex,this._endPositionHigh,this._endPositionLow)}setThickness(e){this._thickness=e,this._handler&&this._handler.setThicknessArr(this._handlerIndex,e)}setColors4v(e,t){e&&(this._startColor.x=e.x,this._startColor.y=e.y,this._startColor.z=e.z,this._startColor.w=e.w),t&&(this._endColor.x=t.x,this._endColor.y=t.y,this._endColor.z=t.z,this._endColor.w=t.w),this._handler&&this._handler.setRgbaArr(this._handlerIndex,this._startColor,this._endColor)}setColorsHTML(e,t){e&&(this._startColor=ye(e)),t&&(this._endColor=ye(t)),this._handler&&this._handler.setRgbaArr(this._handlerIndex,this._startColor,this._endColor)}getStartPosition(){return this._startPosition}getEndPosition(){return this._endPosition}setVisibility(e){this._visibility=e,this._handler&&this._handler.setVisibility(this._handlerIndex,e)}getVisibility(){return this._visibility}remove(){this._entity=null,this._handler&&this._handler.remove(this)}setPickingColor3v(e){this._handler&&this._handler.setPickingColorArr(this._handlerIndex,e)}}Ei.__counter__=0;let Li=new oe,Ai=new oe;class Pi{constructor(e={}){if(this.__id=Pi.__counter__++,this.visibility=null==e.visibility||e.visibility,this.color=new Float32Array([1,1,1,.5]),e.color){let t=Pe(e.color);this.setColor(t.x,t.y,t.z,t.w)}e.opacity&&this.setOpacity(e.opacity),this._renderNode=null,this._entity=null,this._verticesHighBuffer=null,this._verticesLowBuffer=null,this._indexBuffer=null,this._verticesHigh=[],this._verticesLow=[],this._indexes=[],this._path=[],this._pickingColor=new Float32Array(4),this._gridSize=1,this._handler=null,this._handlerIndex=-1,e.path&&this.setPath(e.path)}setPickingColor3v(e){this._pickingColor[0]=e.x/255,this._pickingColor[1]=e.y/255,this._pickingColor[2]=e.z/255,this._pickingColor[3]=1}clear(){this._path.length=0,this._path=[],this._verticesHigh.length=0,this._verticesHigh=[],this._verticesLow.length=0,this._verticesLow=[],this._indexes.length=0,this._indexes=[],this._deleteBuffers()}setColor4v(e){this.setColor(e.x,e.y,e.z,e.w)}setColorHTML(e){this.setColor4v(ye(e))}setColor(e,t,i,s){s=s||this.color[3],this.color[0]=e,this.color[1]=t,this.color[2]=i,this.color[3]=s}setOpacity(e){this.color[3]=e||0}setVisibility(e){this.visibility=e}getVisibility(){return this.visibility}setRenderNode(e){this._renderNode=e,this._createBuffers()}remove(){this._entity=null,this._handler&&this._handler.remove(this)}draw(){if(this.visibility&&this._verticesHigh.length){let e=this._renderNode.renderer,t=e.handler.gl,i=e.handler.programs.strip,s=i._program,n=s.attributes,r=s.uniforms;i.activate(),t.disable(t.CULL_FACE),t.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),t.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),t.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),t.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),t.uniform4fv(r.uColor,this.color),t.uniform1f(r.uOpacity,this._entity._entityCollection._fadingOpacity),t.bindBuffer(t.ARRAY_BUFFER,this._verticesHighBuffer),t.vertexAttribPointer(n.aVertexPositionHigh,this._verticesHighBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._verticesLowBuffer),t.vertexAttribPointer(n.aVertexPositionLow,this._verticesLowBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this._indexBuffer),t.drawElements(e.handler.gl.TRIANGLE_STRIP,this._indexBuffer.numItems,t.UNSIGNED_INT,0),t.enable(t.CULL_FACE)}}drawPicking(){if(this.visibility&&this._verticesHigh.length){let e=this._renderNode.renderer,t=e.handler.gl,i=e.handler.programs.strip,s=i._program,n=s.attributes,r=s.uniforms;i.activate(),t.disable(t.CULL_FACE),t.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),t.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),t.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),t.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),t.uniform1f(r.uOpacity,0!=this._entity._entityCollection._fadingOpacity?1:0),t.uniform4fv(r.uColor,this._pickingColor),t.bindBuffer(t.ARRAY_BUFFER,this._verticesHighBuffer),t.vertexAttribPointer(n.aVertexPositionHigh,this._verticesHighBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._verticesLowBuffer),t.vertexAttribPointer(n.aVertexPositionLow,this._verticesLowBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this._indexBuffer),t.drawElements(e.handler.gl.TRIANGLE_STRIP,this._indexBuffer.numItems,t.UNSIGNED_INT,0),t.enable(t.CULL_FACE)}}_deleteBuffers(){if(this._renderNode&&this._renderNode.renderer){let e=this._renderNode.renderer.handler.gl;e.deleteBuffer(this._indexBuffer),e.deleteBuffer(this._verticesHighBuffer),e.deleteBuffer(this._verticesLowBuffer)}this._verticesHighBuffer=null,this._verticesLowBuffer=null,this._indexBuffer=null}_createBuffers(){if(this._renderNode&&this._renderNode.renderer&&this._renderNode.renderer.isInitialized()){let e=this._renderNode.renderer.handler.gl;e.deleteBuffer(this._indexBuffer),e.deleteBuffer(this._verticesHighBuffer),e.deleteBuffer(this._verticesLowBuffer),this._verticesHighBuffer=this._renderNode.renderer.handler.createArrayBuffer(new Float32Array(this._verticesHigh),3,this._verticesHigh.length/3),this._verticesLowBuffer=this._renderNode.renderer.handler.createArrayBuffer(new Float32Array(this._verticesLow),3,this._verticesLow.length/3),this._indexBuffer=this._renderNode.renderer.handler.createElementArrayBuffer(new Uint32Array(this._indexes),1,this._indexes.length)}}addEdge3v(e,t){let i=this._path.length;if(0===i)this._path.push([e.clone(),t.clone()]);else{let s=this._path[i-1][0],n=this._path[i-1][1];this._path.push([e.clone(),t.clone()]);let r=this._verticesHigh,o=this._verticesLow,a=this._gridSize,l=a+1,h=new oe,c=this._verticesHigh.length/3,d=c,_=Math.abs(s.sub(n).normal().dot(e.sub(s).normal()));for(let i=0;i<l;i++){let u=i/a,g=s.lerp(e,u),f=n.lerp(t,u);for(let u=0;u<l;u++){let p=u/a,m=s.lerp(n,p),v=e.lerp(t,p);1!==_?new di(g,f).intersects(new di(m,v),h):h=v,d=c+i*l+u,oe.doubleToTwoFloats(h,Li,Ai);let y=3*d;r[y]=Li.x,r[y+1]=Li.y,r[y+2]=Li.z,o[y]=Ai.x,o[y+1]=Ai.y,o[y+2]=Ai.z,i<a&&this._indexes.push(d,d+l)}i<a&&this._indexes.push(d+l,d+1)}this._createBuffers()}}setEdge3v(e,t,i){if(i!==this._path.length)if(this._path[i]){if(this._path[i][0]=e,this._path[i][1]=t,this._path.length>1){let s=this._gridSize,n=s+1,r=n*n,o=new oe,a=this._verticesHigh,l=this._verticesLow;if(i===this._path.length-1){let h=this._path[i-1][0],c=this._path[i-1][1],d=this._verticesHigh.length/3-r,_=d,u=Math.abs(h.sub(c).normal().dot(e.sub(h).normal()));for(let i=0;i<n;i++){let r=i/s,g=h.lerp(e,r),f=c.lerp(t,r);for(let r=0;r<n;r++){let p=r/s,m=h.lerp(c,p),v=e.lerp(t,p);1!==u?new di(g,f).intersects(new di(m,v),o):o=v,_=d+i*n+r,oe.doubleToTwoFloats(o,Li,Ai);let y=3*_;a[y]=Li.x,a[y+1]=Li.y,a[y+2]=Li.z,l[y]=Ai.x,l[y+1]=Ai.y,l[y+2]=Ai.z}}}else if(0===i){let i=0,r=e,h=t;e=this._path[1][0],t=this._path[1][1];for(let c=0;c<n;c++){let d=c/s,_=r.lerp(e,d),u=h.lerp(t,d);for(let d=0;d<n;d++){let g=d/s,f=r.lerp(h,g),p=e.lerp(t,g);new di(_,u).intersects(new di(f,p),o),i=c*n+d,oe.doubleToTwoFloats(o,Li,Ai);let m=3*i;a[m]=Li.x,a[m+1]=Li.y,a[m+2]=Li.z,l[m]=Ai.x,l[m+1]=Ai.y,l[m+2]=Ai.z}}}else if(i>0&&i<this._path.length){let h=this._path[i-1][0],c=this._path[i-1][1],d=this._path[i+1][0],_=this._path[i+1][1],u=i*r,g=(i-1)*r,f=g;for(let i=0;i<n;i++){let r=i/s,p=h.lerp(e,r),m=t.lerp(_,r),v=e.lerp(d,r),y=c.lerp(t,r);for(let r=0;r<n;r++){let x=r/s,b=h.lerp(c,x),w=e.lerp(t,x);new di(p,y).intersects(new di(b,w),o);let C=i*n+r;f=g+C,oe.doubleToTwoFloats(o,Li,Ai);let T=3*f;a[T]=Li.x,a[T+1]=Li.y,a[T+2]=Li.z,l[T]=Ai.x,l[T+1]=Ai.y,l[T+2]=Ai.z;let E=d.lerp(_,x);w=e.lerp(t,x),new di(v,m).intersects(new di(w,E),o),f=u+C,oe.doubleToTwoFloats(o,Li,Ai),T=3*f,a[T]=Li.x,a[T+1]=Li.y,a[T+2]=Li.z,l[T]=Ai.x,l[T+1]=Ai.y,l[T+2]=Ai.z}}}this._createBuffers()}}else console.warn(`strip index ${i} is out of range`);else this.addEdge3v(e,t)}removeEdge(e){this._path.splice(e,1),this.setPath([].concat(this._path))}setGridSize(e){this._gridSize=e,this.setPath([].concat(this._path))}getPath(){return this._path}setPath(e){this._verticesHigh=[],this._verticesLow=[],this._indexes=[],this._path=[];for(let t=0;t<e.length;t++){let i=e[t][0],s=e[t][1];i instanceof Array&&(i=new oe(i[0],i[1],i[2])),s instanceof Array&&(s=new oe(s[0],s[1],s[2])),this.addEdge3v(i,s)}}insertEdge3v(e,t,i){if(i<this._path.length){let s=[].concat(this._path);s.splice(i,0,[e,t]),this.setPath(s)}else i===this._path.length&&this.addEdge3v(e,t)}}Pi.__counter__=0;class Si{constructor(e={}){e.properties=e.properties||{},this.__id=Si.__counter__++,this.properties=e.properties||{},this.properties.name=null!=this.properties.name?this.properties.name:"",this.childEntities=[],this.parent=null,this.forceGlobalPosition=e.forceGlobalPosition||!1,this.forceGlobalRotation=e.forceGlobalRotation||!1,this.forceGlobalScale=e.forceGlobalScale||!1,this._cartesian=Ae(e.cartesian),this._rootCartesian=new oe,this._localPosition=Ae(e.localPosition),this._absoluteLocalPosition=new oe,this._lonLat=Re(e.lonlat),this._lonLatMerc=new I,this._altitude=e.altitude||0,this._visibility=null==e.visibility||e.visibility,this._entityCollection=null,this._entityCollectionIndex=-1,this._layer=null,this._layerIndex=-1,this._pickingColor=new oe(0,0,0),this._independentPicking=e.independentPicking||!1,this._relativePosition=e.relativePosition||!1,this._pitchRad=e.pitch||0,this._yawRad=e.yaw||0,this._rollRad=e.roll||0,this._scale=Ae(e.scale,new oe(1,1,1)),this._qFrame=re.IDENTITY,this._qRot=re.IDENTITY,this._absoluteQRot=re.IDENTITY,this._featureConstructorArray={billboard:[oi,this.setBillboard],label:[wi,this.setLabel],polyline:[Ti,this.setPolyline],pointCloud:[Ci,this.setPointCloud],geometry:[hi,this.setGeometry],geoObject:[yi,this.setGeoObject],strip:[Pi,this.setStrip],ray:[Ei,this.setRay]},this.billboard=this._createOptionFeature("billboard",e.billboard),this.label=this._createOptionFeature("label",e.label),this.polyline=this._createOptionFeature("polyline",e.polyline),this.ray=this._createOptionFeature("ray",e.ray),this.pointCloud=this._createOptionFeature("pointCloud",e.pointCloud),this.geometry=this._createOptionFeature("geometry",e.geometry),this.geoObject=this._createOptionFeature("geoObject",e.geoObject),this.strip=this._createOptionFeature("strip",e.strip)}get rootEntity(){let e=this;for(;e;){if(!e.parent)return e;e=e.parent}return this}set relativePosition(e){if(e!==this._relativePosition){let t=this.getAbsoluteCartesian(),i=this.getAbsolutePitch(),s=this.getAbsoluteYaw(),n=this.getAbsoluteRoll();this._relativePosition=e,this.parent&&this._rootCartesian.copy(this.parent._rootCartesian),e?this.parent&&(this.setAbsoluteCartesian3v(t),this.setAbsolutePitch(i),this.setAbsoluteYaw(s),this.setAbsoluteRoll(n)):(this.setCartesian3v(t),this.setPitch(i),this.setYaw(s),this.setRoll(n))}}get relativePosition(){return this._relativePosition}get entityCollection(){return this._entityCollection}get id(){return this.__id}isEqual(e){return this.__id===e.__id}get layerIndex(){return this._layerIndex}get instanceName(){return"Entity"}_createOptionFeature(e,t){if(t){let i=this._featureConstructorArray[e];return i[1].call(this,new i[0](t))}return null}getCollectionIndex(){return this._entityCollectionIndex}addTo(e,t=!1){return e.add(this,t),this}remove(){this._layer&&this._layer.removeEntity(this),this._entityCollection&&this._entityCollection.removeEntity(this)}setVisibility(e){this._visibility=e,this.billboard&&this.billboard.setVisibility(e),this.geoObject&&this.geoObject.setVisibility(e),this.label&&this.label.setVisibility(e),this.polyline&&this.polyline.setVisibility(e),this.ray&&this.ray.setVisibility(e),this.geometry&&this.geometry.setVisibility(e);for(let t=0;t<this.childEntities.length;t++)this.childEntities[t].setVisibility(e)}getVisibility(){return this._visibility}setCartesian3v(e){this.setCartesian(e.x,e.y,e.z)}getScale(){return this._scale}setScale3v(e){this._scale.copy(e),this.geoObject&&this.geoObject.setScale3v(this._scale);for(let e=0;e<this.childEntities.length;e++){let t=this.childEntities[e];t.forceGlobalScale?t.setScale3v(this._scale):t.setScale3v(this.childEntities[e].getScale())}}setScale(e){this._scale.set(e,e,e),this.geoObject&&this.geoObject.setScale(e);for(let t=0;t<this.childEntities.length;t++){let i=this.childEntities[t];i.forceGlobalScale?i.setScale(e):i.setScale3v(this.childEntities[t].getScale())}}getAbsoluteRotation(){return this._absoluteQRot.clone()}getRotation(){return this._qRot}setLook3v(e){let t,i=new re,s=this.getAbsoluteCartesian();if(this._entityCollection){let n=this._entityCollection.renderNode.ellipsoid.getSurfaceNormal3v(s);t=i.setLookRotation(e.sub(s),n).conjugate()}else t=i.setLookRotation(e.sub(s),oe.UP).conjugate();this.setAbsoluteRotation(t)}setLookLonLat(e){if(this._entityCollection){let t=this._entityCollection.renderNode.ellipsoid.lonLatToCartesian(e);this.setLook3v(t)}}setAbsoluteRotation(e){this._absoluteQRot.copy(e),this._updatePitchYawRoll()}setRotation(e){}setPitch(e){this._pitchRad=e,this._updateAbsolutePosition()}setYaw(e){this._yawRad=e,this._updateAbsolutePosition()}setRoll(e){this._rollRad=e,this._updateAbsolutePosition()}getPitch(){return this._pitchRad}getYaw(){return this._yawRad}getRoll(){return this._rollRad}setAbsolutePitch(e){this._relativePosition?(this._absoluteQRot.setPitchYawRoll(e,this.getAbsoluteYaw(),this.getAbsoluteRoll(),this._qFrame),this._updatePitchYawRoll()):this.setPitch(e)}setAbsoluteYaw(e){this._relativePosition?(this._absoluteQRot.setPitchYawRoll(this.getAbsolutePitch(),e,this.getAbsoluteRoll(),this._qFrame),this._updatePitchYawRoll()):this.setYaw(e)}setAbsoluteRoll(e){this._relativePosition?(this._absoluteQRot.setPitchYawRoll(this.getAbsolutePitch(),this.getAbsoluteYaw(),e,this._qFrame),this._updatePitchYawRoll()):this.setRoll(e)}getAbsolutePitch(){return this.parent&&this._relativePosition?this._qFrame.conjugate().inverse().mul(this._absoluteQRot).getPitch():this._pitchRad}getAbsoluteYaw(){return this.parent&&this._relativePosition?this._qFrame.conjugate().inverse().mul(this._absoluteQRot).getYaw():this._yawRad}getAbsoluteRoll(){return this.parent&&this._relativePosition?this._qFrame.conjugate().inverse().mul(this._absoluteQRot).getRoll():this._rollRad}_getScaleByDistance(){let e=1;if(this._entityCollection){let t=this._entityCollection.scaleByDistance,i=1;this._entityCollection.renderNode&&this._entityCollection.renderNode.renderer&&(i=this._entityCollection.renderNode.renderer.activeCamera.eye.distance(this._rootCartesian)),e=t[2]*m(i,t[0],t[1])/t[0]}return e}setAbsoluteCartesian(e,t,i){this.setAbsoluteCartesian3v(new oe(e,t,i))}setAbsoluteCartesian3v(e){let t=e;if(this.parent&&this._relativePosition){let i=this._getScaleByDistance();t=e.sub(this.parent.getAbsoluteCartesian()).scale(1/i),t=this.parent._absoluteQRot.conjugate().mulVec3(t)}this.setCartesian3v(t)}getAbsoluteCartesian(){if(this.parent&&this._relativePosition){let e=this._getScaleByDistance();return this._rootCartesian.add(this._absoluteLocalPosition.scaleTo(e))}return this._cartesian.clone()}setCartesian(e,t,i){this._cartesian.set(e,t,i),this._updateAbsolutePosition();for(let s=0;s<this.childEntities.length;s++){let n=this.childEntities[s];n._relativePosition?n.setCartesian3v(n.getCartesian()):n.forceGlobalPosition&&n.setCartesian(e,t,i)}this._updateLonLat()}_updatePitchYawRoll(){if(this.parent){this._qRot=this.parent._absoluteQRot.conjugate().mul(this._absoluteQRot),this._pitchRad=this._qRot.getPitch(),this._yawRad=this._qRot.getYaw(),this._rollRad=this._qRot.getRoll(),this.geoObject&&this.geoObject.setRotation(this._absoluteQRot);for(let e=0;e<this.childEntities.length;e++)this.childEntities[e]._updateAbsolutePosition()}}_updateAbsolutePosition(){let e=this.parent;if(e&&this._relativePosition){this._qFrame.copy(e._qFrame),this._rootCartesian.copy(e._rootCartesian),this._qRot.setPitchYawRoll(this._pitchRad,this._yawRad,this._rollRad),e._absoluteQRot.mulRes(this._qRot,this._absoluteQRot);let t=e._absoluteQRot.mulVec3(this._cartesian.add(this._localPosition));e._absoluteLocalPosition.addRes(t,this._absoluteLocalPosition)}else this._qFrame=re.IDENTITY,this._entityCollection&&this._entityCollection.renderNode&&(this._qFrame=this._entityCollection.renderNode.getFrameRotation(this._cartesian)),e&&this.forceGlobalRotation?this._qRot.setPitchYawRoll(e._pitchRad,e._yawRad,e._rollRad,this._qFrame):this._qRot.setPitchYawRoll(this._pitchRad,this._yawRad,this._rollRad,this._qFrame),this._absoluteQRot.copy(this._qRot),this._rootCartesian.copy(this._cartesian),this._absoluteLocalPosition.copy(this._localPosition);this.geoObject&&(this.geoObject.setRotation(this._absoluteQRot),this.geoObject.setPosition3v(this._rootCartesian),this.geoObject.setLocalPosition3v(this._absoluteLocalPosition)),this.billboard&&this.billboard.setPosition3v(this._rootCartesian),this.label&&this.label.setPosition3v(this._rootCartesian);for(let e=0,t=this.childEntities.length;e<t;e++)this.childEntities[e]._updateAbsolutePosition();this._updateLonLat()}_setCartesian3vSilent(e,t=!1){this._cartesian.copy(e),this._updateAbsolutePosition();for(let e=0;e<this.childEntities.length;e++)this.childEntities[e].setCartesian(this._cartesian.x,this._cartesian.y,this._cartesian.z);t||this._updateLonLat()}_updateLonLat(){let e=this._entityCollection;e&&e.renderNode&&e.renderNode.ellipsoid&&(this._lonLat=e.renderNode.ellipsoid.cartesianToLonLat(this.getAbsoluteCartesian()),Math.abs(this._lonLat.lat)<Q?this._lonLatMerc=this._lonLat.forwardMercator():this._lonLatMerc.lon=this._lonLatMerc.lat=0)}getLonLat(){return this._lonLat.clone()}setLonLat(e){let t=this._lonLat;t.lon=e.lon,t.lat=e.lat,t.height=e.height;let i=this._entityCollection;if(i&&i.renderNode&&i.renderNode.ellipsoid){Math.abs(t.lat)<Q&&(this._lonLatMerc=t.forwardMercator());let e=new oe;i.renderNode.ellipsoid.lonLatToCartesianRes(t,e),this.setAbsoluteCartesian3v(e)}}setLonLat2(e,t,i){let s=this._lonLat;s.lon=e,s.lat=t,s.height=null!=i?i:s.height;let n=this._entityCollection;if(n&&n.renderNode&&n.renderNode.ellipsoid){Math.abs(s.lat)<Q?this._lonLatMerc=s.forwardMercator():this._lonLatMerc.lon=this._lonLatMerc.lat=this._lonLatMerc.height=0;let e=new oe;n.renderNode.ellipsoid.lonLatToCartesianRes(s,e),this.setAbsoluteCartesian3v(e)}}setAltitude(e){this._altitude=e}getAltitude(){return this._altitude}getCartesian(){return this._cartesian.clone()}setBillboard(e){return this.billboard&&this.billboard.remove(),this.billboard=e,this.billboard._entity=this,this.billboard.setPosition3v(this._cartesian),this.billboard.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.billboardHandler.add(e),e}setLabel(e){return this.label&&this.label.remove(),this.label=e,this.label._entity=this,this.label.setPosition3v(this._cartesian),this.label.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.labelHandler.add(e),e}setRay(e){return this.ray&&this.ray.remove(),this.ray=e,this.ray._entity=this,this.ray.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.rayHandler.add(e),e}setPolyline(e){return this.polyline&&this.polyline.remove(),this.polyline=e,this.polyline._entity=this,this.polyline.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.polylineHandler.add(e),e}setPointCloud(e){return this.pointCloud&&this.pointCloud.remove(),this.pointCloud=e,this.pointCloud._entity=this,this.pointCloud.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.pointCloudHandler.add(e),e}setGeometry(e){this.geometry&&this.geometry.remove(),this.geometry=e,this.geometry._entity=this,this.geometry.setVisibility(this._visibility);let t=this._layer;return this._layer&&this._layer.removeEntity(this),t&&t.add(this),e}setGeoObject(e){return this.geoObject&&this.geoObject.remove(),this.geoObject=e,this.geoObject._entity=this,this.geoObject.setPosition3v(this._cartesian),this.geoObject.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.geoObjectHandler.add(e),e}setStrip(e){return this.strip&&this.strip.remove(),this.strip=e,this.strip._entity=this,this.strip.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.stripHandler.add(e),e}get layer(){return this._layer}get rendererEvents(){return this._layer?this._layer.events:this._entityCollection?this._entityCollection.events:null}appendChild(e){e._entityCollection=this._entityCollection,e._independentPicking||(e._pickingColor=this._pickingColor),e.parent=this,this.childEntities.push(e),this._entityCollection&&this._entityCollection.appendChildEntity(e)}setPickingColor(){let e=this._pickingColor;this.billboard&&this.billboard.setPickingColor3v(e),this.label&&this.label.setPickingColor3v(e),this.polyline&&this.polyline.setPickingColor3v(e),this.ray&&this.ray.setPickingColor3v(e),this.strip&&this.strip.setPickingColor3v(e),this.geoObject&&this.geoObject.setPickingColor3v(e);for(let e=0;e<this.childEntities.length;e++)this.childEntities[e].setPickingColor()}getExtent(){let e,t=this._lonLat;e=this.billboard||this.label?new te(new I(t.lon,t.lat),new I(t.lon,t.lat)):new te(new I(180,90),new I(-180,-90));let i=e.southWest,s=e.northEast;if(this.polyline){let e=this.polyline.getExtent();e.southWest.lon<i.lon&&(i.lon=e.southWest.lon),e.southWest.lat<i.lat&&(i.lat=e.southWest.lat),e.northEast.lon>s.lon&&(s.lon=e.northEast.lon),e.northEast.lat>s.lat&&(s.lat=e.northEast.lat)}if(this.geometry){let e=this.geometry.getExtent();e.southWest.lon<i.lon&&(i.lon=e.southWest.lon),e.southWest.lat<i.lat&&(i.lat=e.southWest.lat),e.northEast.lon>s.lon&&(s.lon=e.northEast.lon),e.northEast.lat>s.lat&&(s.lat=e.northEast.lat)}for(let e=0;e<this.childEntities.length;e++){let t=this.childEntities[e].getExtent();t.southWest.lon<i.lon&&(i.lon=t.southWest.lon),t.southWest.lat<i.lat&&(i.lat=t.southWest.lat),t.northEast.lon>s.lon&&(s.lon=t.northEast.lon),t.northEast.lat>s.lat&&(s.lat=t.northEast.lat)}return e}}Si.__counter__=0;class Mi{constructor(e){this.__id=Mi.__counter__++,this._name=e||`nonameNode:${this.__id}`,this.topNode=this,this._dictionary={},this._dictionary[this._name]=this,this.childNodes=[],this.parentNode=null}get name(){return this._name}addNode(e){null==this.parentNode?e.topNode=this:e.topNode=this.topNode,e.parentNode=this,e._dictionary=this.topNode._dictionary,this.childNodes.push(e),this.topNode._dictionary[e.name]=e}destroy(){for(let e=0;e<this.childNodes.length;e++)this.childNodes[e].destroy();this._clear()}getNodeByName(e){return this._dictionary[e]}_clear(){this.parentNode=null,this.topNode=this,this.childNodes.length=0}isEqual(e){return e.__id===this.__id}}Mi.__counter__=0;class Ri extends Mi{constructor(e){super(e),this.childNodes=[],this.renderer=null,this.drawMode=0,this.show=!0,this._isActive=!0,this.lightEnabled=!1,this._lightPosition=new Float32Array([100,100,100]),this._lightParams=new Float32Array(9),this._lightShininess=100,this.entityCollections=[],this._entityCollectionsByDepthOrder=[],this._pickingId=-1}getFrameRotation(e){return re.IDENTITY}addNode(e){super.addNode(e),this.renderer&&e.assign(this.renderer)}assign(e){this.renderer=e,this._pickingId=e.addPickingCallback(this,this._entityCollectionPickingCallback),this.initialize()}initialize(){if(this.renderer&&this.renderer.isInitialized()){for(let e=0;e<this.entityCollections.length;e++)this.entityCollections[e].bindRenderNode(this);this.init()}}init(){}onremove(){}remove(){let e=this.renderer,t=this.name;if(e){e.renderNodes[t]&&e.renderNodes[t].isEqual(this)&&(e.renderNodes[t]=null,delete e.renderNodes[t]);for(let t=0;t<e._renderNodesArr.length;t++)if(e._renderNodesArr[t].isEqual(this)){e._renderNodesArr.splice(t,1);break}e.removePickingCallback(this._pickingId),this._pickingId=-1,this.onremove&&this.onremove()}}addEntityCollection(e,t){e.renderNode||(e.renderNode=this,t||(this.entityCollections.push(e),this.updateEntityCollectionsDepthOrder()),this.ellipsoid&&e._updateGeodeticCoordinates(this.ellipsoid),e.bindRenderNode(this),e.events.dispatch(e.events.add,this))}removeEntityCollection(e){for(let t=0;t<this.entityCollections.length;t++)if(this.entityCollections[t].isEqual(e))return this.entityCollections.splice(t,1),void this.updateEntityCollectionsDepthOrder()}updateEntityCollectionsDepthOrder(){let e={0:[]};for(const t of this.entityCollections)t.getVisibility()&&(e[t.depthOrder]||(e[t.depthOrder]=[]),e[t.depthOrder].push(t));this._entityCollectionsByDepthOrder.length=0,this._entityCollectionsByDepthOrder=[],this._entityCollectionsByDepthOrder=Object.keys(e).sort(((e,t)=>Number(e)-Number(t))).map((t=>e[Number(t)]))}addLight(e){return e.addTo(this),this}preDrawNode(){this._isActive&&this._preDrawNodes()}drawNode(){this._isActive&&this._drawNodes()}isActive(){return this._isActive}setActive(e){this._isActive=e,this.renderer&&(this._isActive&&-1===this._pickingId?this._pickingId=this.renderer.addPickingCallback(this,this._entityCollectionPickingCallback):this._isActive||-1===this._pickingId||(this.renderer.removePickingCallback(this._pickingId),this._pickingId=-1));for(let t=0;t<this.childNodes.length;t++)this.childNodes[t].setActive(e)}setDrawMode(e){this.drawMode=e;for(let t=0;t<this.childNodes.length;t++)this.childNodes[t].setDrawMode(e)}updateBillboardsTexCoords(){for(let e=0;e<this.entityCollections.length;e++)this.entityCollections[e].billboardHandler.refreshTexCoordsArr()}frame(){}preFrame(){}_preDrawNodes(){for(let e=0;e<this.childNodes.length;e++)this.childNodes[e]._isActive&&this.childNodes[e]._preDrawNodes();if(this.show){this.preFrame();for(let e=0;e<this._entityCollectionsByDepthOrder.length;e++)this.drawEntityCollections(this._entityCollectionsByDepthOrder[e],e)}}_drawNodes(){for(let e=0;e<this.childNodes.length;e++)this.childNodes[e]._isActive&&this.childNodes[e]._drawNodes();this.show&&this.frame()}drawEntityCollections(e,t=0){this.renderer.enqueueEntityCollectionsToDraw(e,t)}drawPickingEntityCollections(e){if(e.length){let t=e.length;for(;t--;)e[t]._fadingOpacity&&e[t].billboardHandler.drawPicking();for(t=e.length;t--;)e[t]._fadingOpacity&&e[t].geoObjectHandler.drawPicking();for(t=e.length;t--;)e[t]._fadingOpacity&&e[t].labelHandler.drawPicking();for(t=e.length;t--;)e[t]._fadingOpacity&&e[t].rayHandler.drawPicking();for(t=e.length;t--;)e[t]._visibility&&e[t].polylineHandler.drawPicking();for(t=e.length;t--;)e[t]._visibility&&e[t].stripHandler.drawPicking()}}_entityCollectionPickingCallback(){}}const Bi=new class{constructor(){this._container=document.createElement("div"),this._container.classList.add("ogConsole"),this._container.style.display="none",document.body&&document.body.appendChild(this._container),this._visibility=!1}getVisibility(){return this._visibility}setVisibility(e){this._visibility!=e&&(this._visibility=e,this._visibility?this.show():this.hide())}show(){this._container.parentNode||document.body&&document.body.appendChild(this._container),this._container.style.display="block",this._visibility=!0}hide(){this._container.style.display="none",this._visibility=!1}logErr(e){let t=document.createElement("div");t.classList.add("ogConsole-text"),t.classList.add("ogConsole-error"),t.innerHTML="error: "+e,console.trace(t.innerHTML),this._container.appendChild(t),this.show()}logWrn(e){let t=document.createElement("div");t.classList.add("ogConsole-text"),t.classList.add("ogConsole-warning"),t.innerHTML="warning: "+e,console.trace(t.innerHTML),this._container.appendChild(t),this.show()}log(e){let t=document.createElement("div");t.classList.add("ogConsole-text"),t.innerHTML=e,console.trace(e),this._container.appendChild(t),this.show()}};let ki=["FLOAT","DOUBLE","BOOL","INT","UINT","VEC2","VEC3","VEC4","DVEC2","DVEC3","DVEC4","BVEC2","BVEC3","BVEC4","IVEC2","IVEC3","IVEC4","UVEC2","UVEC3","UVEC4","MAT2","DMAT2","MAT3","DMAT3","MAT4","DMAT4","MAT2X3","MAT2X4","MAT3X2","MAT3X4","MAT4X2","MAT4X3","DMAT2X3","DMAT2X4","DMAT3X2","DMAT3X4","DMAT4X2","DMAT4X3","SAMPLER1D","SAMPLER2D","SAMPLER3D","SAMPLERCUBE","SAMPLER2DSHADOW","SAMPLER2DARRAY","INTXX","FLOATXX"];const Ii={};for(let e=0;e<ki.length;e++)Ii[ki[e]]=e;const zi={};for(let e=0;e<ki.length;e++)zi[ki[e].toLowerCase()]=Ii[ki[e]];const Di={u:[],a:[]};Di.u[Ii.MAT4]=function(e,t){e.gl.uniformMatrix4fv(t._pName,!1,t.value)},Di.u[Ii.MAT3]=function(e,t){e.gl.uniformMatrix3fv(t._pName,!1,t.value)},Di.u[Ii.FLOAT]=function(e,t){e.gl.uniform1f(t._pName,t.value)},Di.u[Ii.INT]=function(e,t){e.gl.uniform1i(t._pName,t.value)},Di.u[Ii.VEC2]=function(e,t){e.gl.uniform2fv(t._pName,t.value)},Di.u[Ii.VEC3]=function(e,t){e.gl.uniform3fv(t._pName,t.value)},Di.u[Ii.VEC4]=function(e,t){e.gl.uniform4fv(t._pName,t.value)},Di.u[Ii.SAMPLER2D]=function(e,t){let i=e.gl;i.activeTexture(i.TEXTURE0+e._textureID),i.bindTexture(i.TEXTURE_2D,t.value),i.uniform1i(t._pName,e._textureID),e._textureID++},Di.u[Ii.SAMPLERCUBE]=function(e,t){let i=e.gl;i.activeTexture(i.TEXTURE0+e._textureID),i.bindTexture(i.TEXTURE_CUBE_MAP,t.value),i.uniform1i(t._pName,e._textureID),e._textureID++},Di.u[Ii.SAMPLER2DARRAY]=function(e,t){let i=t.value,s=e.gl,n=i.length,r=new Int32Array(n);for(let t=0;t<n;t++)s.activeTexture(s.TEXTURE0+e._textureID+t),s.bindTexture(s.TEXTURE_2D,i[t]),r[t]=t;s.uniform1iv(t._pName,r)},Di.u[Ii.INTXX]=function(e,t){e.gl.uniform1iv(t._pName,t.value)},Di.u[Ii.FLOATXX]=function(e,t){e.gl.uniform1fv(t._pName,t.value)},Di.a[Ii.FLOAT]=function(e,t){e.gl.vertexAttrib1f(t._pName,t.value)},Di.a[Ii.VEC2]=function(e,t){e.gl.vertexAttrib2fv(t._pName,t.value)},Di.a[Ii.VEC3]=function(e,t){e.gl.vertexAttrib3fv(t._pName,t.value)};const Fi=["BYTE","SHORT","UNSIGNED_BYTE","UNSIGNED_SHORT","FLOAT","HALF_FLOAT"];class Ni{constructor(e,t){this.name=e,this._attributes={};for(let e in t.attributes)"string"==typeof t.attributes[e]||"number"==typeof t.attributes[e]?this._attributes[e]={type:t.attributes[e]}:this._attributes[e]=t.attributes[e];this._uniforms={};for(let e in t.uniforms)"string"==typeof t.uniforms[e]||"number"==typeof t.uniforms[e]?this._uniforms[e]={type:t.uniforms[e]}:this._uniforms[e]=t.uniforms[e];this.vertexShader=t.vertexShader,this.fragmentShader=t.fragmentShader,this.gl=null,this._variables={},this._p=null,this._textureID=0,this._attribArrays=[],this._attribDivisor=[],this.attributes={},this.uniforms={},this.vertexAttribDivisor=null,this.drawElementsInstanced=null}static bindBuffer(e,t){let i=e.gl;i&&(i.bindBuffer(i.ARRAY_BUFFER,t.value),i.vertexAttribPointer(t._pName,t.value.itemSize,t.itemType,t.normalized,0,0))}use(){this.gl&&this.gl.useProgram(this._p)}set(e){this._textureID=0;for(let t in e)this._variables[t].value=e[t],this._variables[t].func(this,this._variables[t])}apply(){this._textureID=0;let e=this._variables;for(let t in e)e[t].func(this,e[t])}drawIndexBuffer(e,t){let i=this.gl;i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,t),i.drawElements(e,t.numItems,i.UNSIGNED_SHORT,0)}drawArrays(e,t){this.gl.drawArrays(e,0,t)}_getShaderCompileStatus(e,t){return!!this.gl&&(this.gl.shaderSource(e,t),this.gl.compileShader(e),!!this.gl.getShaderParameter(e,this.gl.COMPILE_STATUS)||(Bi.logErr(`Shader program "${this.name}":${this.gl.getShaderInfoLog(e)}.`),!1))}_createVertexShader(e){if(!this.gl)return;let t=this.gl.createShader(this.gl.VERTEX_SHADER);return t&&this._getShaderCompileStatus(t,e)?t:void 0}_createFragmentShader(e){if(!this.gl)return;let t=this.gl.createShader(this.gl.FRAGMENT_SHADER);return t&&this._getShaderCompileStatus(t,e)?t:void 0}disableAttribArrays(){let e=this.gl,t=this._attribArrays;for(let i=0,s=t.length;i<s;i++)e.disableVertexAttribArray(t[i]),this.vertexAttribDivisor(t[i],0)}enableAttribArrays(){let e=this.gl,t=this._attribArrays,i=this._attribDivisor;for(let s=0,n=t.length;s<n;s++)e.enableVertexAttribArray(t[s]),this.vertexAttribDivisor(t[s],i[s])}delete(){this.gl&&this.gl.deleteProgram(this._p)}createProgram(e){if(this.gl=e,this._p=this.gl.createProgram(),!this._p)return;let t=this._createFragmentShader(this.fragmentShader),i=this._createVertexShader(this.vertexShader);if(t&&i){if(e.attachShader(this._p,t),e.attachShader(this._p,i),e.linkProgram(this._p),!this.drawElementsInstanced)if(e.drawElementsInstanced)this.drawElementsInstanced=e.drawElementsInstanced.bind(e);else{let t=e.getExtension("ANGLE_instanced_arrays");t&&(this.drawElementsInstanced=t.drawElementsInstancedANGLE.bind(t))}if(!this.vertexAttribDivisor)if(e.vertexAttribDivisor)this.vertexAttribDivisor=e.vertexAttribDivisor.bind(e);else{let t=e.getExtension("ANGLE_instanced_arrays");t&&(this.vertexAttribDivisor=t.vertexAttribDivisorANGLE.bind(t))}if(!e.getProgramParameter(this._p,e.LINK_STATUS))return Bi.logErr(`Shader program "${this.name}": initialization failed. ${e.getProgramInfoLog(this._p)}.`),void e.deleteProgram(this._p);this.use();for(let t in this._attributes){this._variables[t]=this._attributes[t],this._attributes[t].func=Ni.bindBuffer;let i=this._attributes[t].itemType,s=i?i.trim().toUpperCase():"FLOAT";if(-1==Fi.indexOf(s)?(Bi.logErr(`Shader program "${this.name}": attribute '${t}', item type '${this._attributes[t].itemType}' not exists.`),this._attributes[t].itemType=e.FLOAT):this._attributes[t].itemType=e[s],this._attributes[t].normalized=this._attributes[t].normalized||!1,this._attributes[t].divisor=this._attributes[t].divisor||0,this._p[t]=e.getAttribLocation(this._p,t),null==this._p[t])return Bi.logErr(`Shader program "${this.name}": attribute '${t}' not exists.`),void e.deleteProgram(this._p);let n=this._attributes[t].type;"string"==typeof n&&(n=zi[n.trim().toLowerCase()]);let r=this._attributes[t].divisor;if(n===Ii.MAT4){let e=this._p[t];this._attribArrays.push(e,e+1,e+2,e+3),this._attribDivisor.push(r,r,r,r)}else this._attribArrays.push(this._p[t]),this._attribDivisor.push(r);e.enableVertexAttribArray(this._p[t]),this._attributes[t]._pName=this._p[t],this.attributes[t]=this._p[t]}for(let t in this._uniforms){if("string"==typeof this._uniforms[t].type){let e=this._uniforms[t].type;this._uniforms[t].func=Di.u[zi[e.trim().toLowerCase()]]}else this._uniforms[t].func=Di.u[this._uniforms[t].type];if(this._variables[t]=this._uniforms[t],this._p[t]=e.getUniformLocation(this._p,t),null==this._p[t])return Bi.logErr(`Shader program "${this.name}": uniform '${t}' not exists.`),void e.deleteProgram(this._p);this._uniforms[t]._pName=this._p[t],this.uniforms[t]=this._p[t]}e.detachShader(this._p,t),e.detachShader(this._p,i),e.deleteShader(t),e.deleteShader(i)}}}const Hi="vec2 project(vec4 p) {\n return (0.5 * p.xyz / p.w + 0.5).xy * viewport;\n }",Oi="mat2 rotate2d(float angle) {\n return mat2(cos(angle), -sin(angle),\n sin(angle), cos(angle));\n }";class Vi{constructor(e){this.__id=Vi.__counter__++,this.pickingEnabled=!0,this._entityCollection=e,this._renderer=null,this._billboards=[],this._positionHighBuffer=null,this._positionLowBuffer=null,this._sizeBuffer=null,this._offsetBuffer=null,this._rgbaBuffer=null,this._rotationBuffer=null,this._texCoordBuffer=null,this._vertexBuffer=null,this._pickingColorBuffer=null,this._texCoordArr=new Float32Array([]),this._vertexArr=new Float32Array([]),this._positionHighArr=new Float32Array([]),this._positionLowArr=new Float32Array([]),this._sizeArr=new Float32Array([]),this._offsetArr=new Float32Array([]),this._rgbaArr=new Float32Array([]),this._rotationArr=new Float32Array([]),this._pickingColorArr=new Float32Array([]),this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[0]=this.createPickingColorBuffer,this._buffersUpdateCallbacks[1]=this.createPositionBuffer,this._buffersUpdateCallbacks[2]=this.createSizeBuffer,this._buffersUpdateCallbacks[3]=this.createOffsetBuffer,this._buffersUpdateCallbacks[4]=this.createRgbaBuffer,this._buffersUpdateCallbacks[5]=this.createRotationBuffer,this._buffersUpdateCallbacks[6]=this.createTexCoordBuffer,this._buffersUpdateCallbacks[7]=this.createVertexBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length)}isEqual(e){return e&&e.__id===this.__id}static concArr(e,t){for(let i=0;i<t.length;i++)e.push(t[i])}initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.billboard||this._renderer.handler.addProgram(new Ni("billboard",{uniforms:{viewport:"vec2",u_texture:"sampler2d",projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",planetRadius:"float",uScaleByDistance:"vec3",opacity:"float",depthOffset:"float"},attributes:{a_vertices:"vec2",a_texCoord:"vec2",a_positionsHigh:"vec3",a_positionsLow:"vec3",a_offset:"vec3",a_size:"vec2",a_rotation:"float",a_rgba:"vec4"},vertexShader:`precision highp float;\n attribute vec2 a_vertices;\n attribute vec2 a_texCoord;\n attribute vec3 a_positionsHigh;\n attribute vec3 a_positionsLow;\n attribute vec3 a_offset;\n attribute vec2 a_size;\n attribute float a_rotation;\n attribute vec4 a_rgba;\n\n varying vec2 v_texCoords;\n varying vec4 v_rgba;\n\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform vec3 uScaleByDistance;\n uniform float opacity;\n uniform float planetRadius;\n uniform vec2 viewport;\n uniform float depthOffset;\n\n const vec3 ZERO3 = vec3(0.0);\n\n ${Hi}\n\n ${Oi}\n\n void main() {\n \n vec3 a_positions = a_positionsHigh + a_positionsLow;\n vec3 cameraPos = eyePositionHigh + eyePositionLow;\n\n v_texCoords = a_texCoord;\n vec3 look = a_positions - cameraPos;\n float lookDist = length(look);\n v_rgba = a_rgba;\n\n if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){\n return;\n }\n\n //vec3 up = vec3( viewMatrix[0][1], viewMatrix[1][1], viewMatrix[2][1] );\n //vec3 right = vec3( viewMatrix[0][0], viewMatrix[1][0], viewMatrix[2][0] );\n\n float scd = (1.0 - smoothstep(uScaleByDistance[0], uScaleByDistance[1], lookDist)) * (1.0 - step(uScaleByDistance[2], lookDist));\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = a_positionsHigh - eyePositionHigh;\n vec3 lowDiff = a_positionsLow - eyePositionLow;\n vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n vec4 projPos = projectionMatrix * posRTE;\n \n float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos)); \n if(camSlope > 0.5) {\n float dist = dot(look, normalize(cameraPos));\n projPos.z += dist * 0.02;\n }else{\n projPos.z += -(abs(projPos.z)) * 0.002; \n }\n \n projPos.z += depthOffset + a_offset.z;\n \n vec2 screenPos = project(projPos);\n\n vec2 v = screenPos + rotate2d(a_rotation) * (a_vertices * a_size * scd + a_offset.xy);\n\n gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);\n }`,fragmentShader:"precision highp float;\n uniform sampler2D u_texture;\n varying vec2 v_texCoords;\n varying vec4 v_rgba;\n void main () {\n vec4 color = texture2D(u_texture, v_texCoords);\n if(color.a < 0.1)\n discard;\n gl_FragColor = color * v_rgba;\n }"})),this._renderer.handler.programs.billboardPicking||this._renderer.handler.addProgram(new Ni("billboardPicking",{uniforms:{viewport:"vec2",projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",planetRadius:"float",uScaleByDistance:"vec3",opacity:"float",depthOffset:"float"},attributes:{a_vertices:"vec2",a_positionsHigh:"vec3",a_positionsLow:"vec3",a_offset:"vec3",a_size:"vec2",a_rotation:"float",a_rgba:"vec4"},vertexShader:`precision highp float;\n attribute vec2 a_vertices;\n attribute vec3 a_positionsHigh;\n attribute vec3 a_positionsLow;\n attribute vec3 a_offset;\n attribute vec2 a_size;\n attribute float a_rotation;\n attribute vec4 a_rgba;\n\n varying vec3 v_rgb;\n\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform vec3 uScaleByDistance;\n uniform float opacity;\n uniform float planetRadius;\n uniform vec2 viewport;\n uniform float depthOffset;\n\n const vec3 ZERO3 = vec3(0.0);\n\n ${Hi}\n\n ${Oi}\n\n void main() {\n\n vec3 a_positions = a_positionsHigh + a_positionsLow;\n vec3 cameraPos = eyePositionHigh + eyePositionLow;\n\n vec3 look = a_positions - cameraPos;\n float lookDist = length(look);\n v_rgb = a_rgba.rgb;\n\n if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){\n return;\n }\n\n //vec3 up = vec3( viewMatrix[0][1], viewMatrix[1][1], viewMatrix[2][1] );\n //vec3 right = vec3( viewMatrix[0][0], viewMatrix[1][0], viewMatrix[2][0] );\n\n float scd = (1.0 - smoothstep(uScaleByDistance[0], uScaleByDistance[1], lookDist)) * (1.0 - step(uScaleByDistance[2], lookDist));\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = a_positionsHigh - eyePositionHigh;\n vec3 lowDiff = a_positionsLow - eyePositionLow;\n vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n vec4 projPos = projectionMatrix * posRTE;\n \n float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos)); \n if(camSlope > 0.5) {\n float dist = dot(look, normalize(cameraPos));\n projPos.z += dist * 0.02;\n }else{\n projPos.z += -(abs(projPos.z)) * 0.002; \n }\n \n projPos.z += depthOffset + a_offset.z;\n \n vec2 screenPos = project(projPos);\n\n vec2 v = screenPos + rotate2d(a_rotation) * (a_vertices * a_size * scd + a_offset.xy);\n\n gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);\n }`,fragmentShader:"precision highp float;\n varying vec3 v_rgb;\n void main () {\n gl_FragColor = vec4(v_rgb, 1.0);\n }"})))}setRenderer(e){this._renderer=e,this.initProgram()}refresh(){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]=!0}_removeBillboards(){let e=this._billboards.length;for(;e--;){let t=this._billboards[e];t._handlerIndex=-1,t._handler=null,t._isReady=!1,t._lockId=ii}this._billboards.length=0,this._billboards=[]}clear(){this._texCoordArr=null,this._vertexArr=null,this._positionHighArr=null,this._positionLowArr=null,this._sizeArr=null,this._offsetArr=null,this._rgbaArr=null,this._rotationArr=null,this._pickingColorArr=null,this._texCoordArr=new Float32Array([]),this._vertexArr=new Float32Array([]),this._positionHighArr=new Float32Array([]),this._positionLowArr=new Float32Array([]),this._sizeArr=new Float32Array([]),this._offsetArr=new Float32Array([]),this._rgbaArr=new Float32Array([]),this._rotationArr=new Float32Array([]),this._pickingColorArr=new Float32Array([]),this._removeBillboards(),this._deleteBuffers(),this.refresh()}_deleteBuffers(){if(this._renderer){let e=this._renderer.handler.gl;e.deleteBuffer(this._positionHighBuffer),e.deleteBuffer(this._positionLowBuffer),e.deleteBuffer(this._sizeBuffer),e.deleteBuffer(this._offsetBuffer),e.deleteBuffer(this._rgbaBuffer),e.deleteBuffer(this._rotationBuffer),e.deleteBuffer(this._vertexBuffer),e.deleteBuffer(this._texCoordBuffer),e.deleteBuffer(this._pickingColorBuffer)}this._positionHighBuffer=null,this._positionLowBuffer=null,this._sizeBuffer=null,this._offsetBuffer=null,this._rgbaBuffer=null,this._rotationBuffer=null,this._vertexBuffer=null,this._texCoordBuffer=null,this._pickingColorBuffer=null}update(){if(this._renderer){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1)}}add(e){-1==e._handlerIndex&&(e._isReady=!0,e._handler=this,e._handlerIndex=this._billboards.length,this._billboards.push(e))}_displayPASS(){let e=this._renderer,t=e.handler;t.programs.billboard.activate();let i=t.programs.billboard._program,s=i.attributes,n=i.uniforms,r=t.gl,o=this._entityCollection;r.disable(r.CULL_FACE),r.uniform1f(n.depthOffset,o.polygonOffsetUnits),r.uniform1i(n.u_texture,0),r.uniformMatrix4fv(n.viewMatrix,!1,e.activeCamera.getViewMatrix()),r.uniformMatrix4fv(n.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),r.uniform3fv(n.eyePositionHigh,e.activeCamera.eyeHigh),r.uniform3fv(n.eyePositionLow,e.activeCamera.eyeLow),r.uniform3fv(n.uScaleByDistance,o.scaleByDistance),r.uniform1f(n.opacity,o._fadingOpacity),r.bindBuffer(r.ARRAY_BUFFER,this._texCoordBuffer),r.vertexAttribPointer(s.a_texCoord,this._texCoordBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._vertexBuffer),r.vertexAttribPointer(s.a_vertices,this._vertexBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._positionHighBuffer),r.vertexAttribPointer(s.a_positionsHigh,this._positionHighBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._positionLowBuffer),r.vertexAttribPointer(s.a_positionsLow,this._positionLowBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._rgbaBuffer),r.vertexAttribPointer(s.a_rgba,this._rgbaBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._sizeBuffer),r.vertexAttribPointer(s.a_size,this._sizeBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._offsetBuffer),r.vertexAttribPointer(s.a_offset,this._offsetBuffer.itemSize,r.FLOAT,!1,0,0),r.uniform1f(n.planetRadius,o.renderNode._planetRadius2||0),r.uniform2fv(n.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),r.bindBuffer(r.ARRAY_BUFFER,this._rotationBuffer),r.vertexAttribPointer(s.a_rotation,this._rotationBuffer.itemSize,r.FLOAT,!1,0,0),r.drawArrays(r.TRIANGLES,0,this._vertexBuffer.numItems),r.enable(r.CULL_FACE)}_pickingPASS(){let e=this._renderer,t=e.handler;t.programs.billboardPicking.activate();let i=t.programs.billboardPicking._program,s=i.attributes,n=i.uniforms,r=t.gl,o=this._entityCollection;r.disable(r.CULL_FACE),r.uniform1f(n.depthOffset,o.polygonOffsetUnits),r.uniformMatrix4fv(n.viewMatrix,!1,e.activeCamera.getViewMatrix()),r.uniformMatrix4fv(n.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),r.uniform3fv(n.eyePositionHigh,e.activeCamera.eyeHigh),r.uniform3fv(n.eyePositionLow,e.activeCamera.eyeLow),r.uniform3fv(n.uScaleByDistance,o.scaleByDistance),r.uniform1f(n.opacity,o._fadingOpacity),r.bindBuffer(r.ARRAY_BUFFER,this._vertexBuffer),r.vertexAttribPointer(s.a_vertices,this._vertexBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._positionHighBuffer),r.vertexAttribPointer(s.a_positionsHigh,this._positionHighBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._positionLowBuffer),r.vertexAttribPointer(s.a_positionsLow,this._positionLowBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._pickingColorBuffer),r.vertexAttribPointer(s.a_rgba,this._pickingColorBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._sizeBuffer),r.vertexAttribPointer(s.a_size,this._sizeBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._offsetBuffer),r.vertexAttribPointer(s.a_offset,this._offsetBuffer.itemSize,r.FLOAT,!1,0,0),r.uniform1f(n.planetRadius,o.renderNode._planetRadius2||0),r.uniform2fv(n.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),r.bindBuffer(r.ARRAY_BUFFER,this._rotationBuffer),r.vertexAttribPointer(s.a_rotation,this._rotationBuffer.itemSize,r.FLOAT,!1,0,0),r.drawArrays(r.TRIANGLES,0,this._vertexBuffer.numItems),r.enable(r.CULL_FACE)}draw(){this._billboards.length&&(this.update(),this._displayPASS())}drawPicking(){this._billboards.length&&this.pickingEnabled&&this._pickingPASS()}reindexBillboardsArray(e){let t=this._billboards;for(let i=e;i<t.length;i++)t[i]._handlerIndex=i}_removeBillboard(e){let t=e._handlerIndex;this._billboards.splice(t,1);let i=24*t;this._rgbaArr=Ye(this._rgbaArr,i,24),i=18*t,this._positionHighArr=Ye(this._positionHighArr,i,18),this._positionLowArr=Ye(this._positionLowArr,i,18),this._offsetArr=Ye(this._offsetArr,i,18),this._pickingColorArr=Ye(this._pickingColorArr,i,18),i=12*t,this._vertexArr=Ye(this._vertexArr,i,12),this._sizeArr=Ye(this._sizeArr,i,12),this._texCoordArr=Ye(this._texCoordArr,i,12),i=6*t,this._rotationArr=Ye(this._rotationArr,i,6),this.reindexBillboardsArray(t),this.refresh(),e._handlerIndex=-1,e._handler=null,e._isReady=!1,e._lockId=ii}setAlignedAxisArr(e,t){}remove(e){e._handler&&(e._isReady&&this.__id===e._handler.__id?this._removeBillboard(e):e._handler=null)}setPositionArr(e,t,i){let s=18*e,n=this._positionHighArr,r=t.x,o=t.y,a=t.z;n[s]=r,n[s+1]=o,n[s+2]=a,n[s+3]=r,n[s+4]=o,n[s+5]=a,n[s+6]=r,n[s+7]=o,n[s+8]=a,n[s+9]=r,n[s+10]=o,n[s+11]=a,n[s+12]=r,n[s+13]=o,n[s+14]=a,n[s+15]=r,n[s+16]=o,n[s+17]=a,n=this._positionLowArr,r=i.x,o=i.y,a=i.z,n[s]=r,n[s+1]=o,n[s+2]=a,n[s+3]=r,n[s+4]=o,n[s+5]=a,n[s+6]=r,n[s+7]=o,n[s+8]=a,n[s+9]=r,n[s+10]=o,n[s+11]=a,n[s+12]=r,n[s+13]=o,n[s+14]=a,n[s+15]=r,n[s+16]=o,n[s+17]=a,this._changedBuffers[1]=!0}setPickingColorArr(e,t){let i=18*e,s=this._pickingColorArr,n=t.x/255,r=t.y/255,o=t.z/255;s[i]=n,s[i+1]=r,s[i+2]=o,s[i+3]=n,s[i+4]=r,s[i+5]=o,s[i+6]=n,s[i+7]=r,s[i+8]=o,s[i+9]=n,s[i+10]=r,s[i+11]=o,s[i+12]=n,s[i+13]=r,s[i+14]=o,s[i+15]=n,s[i+16]=r,s[i+17]=o,this._changedBuffers[0]=!0}setSizeArr(e,t,i){let s=12*e,n=this._sizeArr,r=t,o=i;n[s]=r,n[s+1]=o,n[s+2]=r,n[s+3]=o,n[s+4]=r,n[s+5]=o,n[s+6]=r,n[s+7]=o,n[s+8]=r,n[s+9]=o,n[s+10]=r,n[s+11]=o,this._changedBuffers[2]=!0}setOffsetArr(e,t){let i=18*e,s=this._offsetArr,n=t.x,r=t.y,o=t.z;s[i]=n,s[i+1]=r,s[i+2]=o,s[i+3]=n,s[i+4]=r,s[i+5]=o,s[i+6]=n,s[i+7]=r,s[i+8]=o,s[i+9]=n,s[i+10]=r,s[i+11]=o,s[i+12]=n,s[i+13]=r,s[i+14]=o,s[i+15]=n,s[i+16]=r,s[i+17]=o,this._changedBuffers[3]=!0}setRgbaArr(e,t){let i=24*e,s=this._rgbaArr,n=t.x,r=t.y,o=t.z,a=t.w;s[i]=n,s[i+1]=r,s[i+2]=o,s[i+3]=a,s[i+4]=n,s[i+5]=r,s[i+6]=o,s[i+7]=a,s[i+8]=n,s[i+9]=r,s[i+10]=o,s[i+11]=a,s[i+12]=n,s[i+13]=r,s[i+14]=o,s[i+15]=a,s[i+16]=n,s[i+17]=r,s[i+18]=o,s[i+19]=a,s[i+20]=n,s[i+21]=r,s[i+22]=o,s[i+23]=a,this._changedBuffers[4]=!0}setRotationArr(e,t){let i=6*e,s=this._rotationArr;s[i]=t,s[i+1]=t,s[i+2]=t,s[i+3]=t,s[i+4]=t,s[i+5]=t,this._changedBuffers[5]=!0}setTexCoordArr(e,t){let i=12*e,s=this._texCoordArr;s[i]=t[0],s[i+1]=t[1],s[i+2]=t[2],s[i+3]=t[3],s[i+4]=t[4],s[i+5]=t[5],s[i+6]=t[6],s[i+7]=t[7],s[i+8]=t[8],s[i+9]=t[9],s[i+10]=t[10],s[i+11]=t[11],this._changedBuffers[6]=!0}setVisibility(e,t){let i;i=t?[-.5,.5,-.5,-.5,.5,-.5,.5,-.5,.5,.5,-.5,.5]:[0,0,0,0,0,0,0,0,0,0,0,0],this.setVertexArr(e,i)}setVertexArr(e,t){let i=12*e,s=this._vertexArr;s[i]=t[0],s[i+1]=t[1],s[i+2]=t[2],s[i+3]=t[3],s[i+4]=t[4],s[i+5]=t[5],s[i+6]=t[6],s[i+7]=t[7],s[i+8]=t[8],s[i+9]=t[9],s[i+10]=t[10],s[i+11]=t[11],this._changedBuffers[7]=!0}createPositionBuffer(){let e=this._renderer.handler,t=this._positionHighArr.length/3;this._positionHighBuffer&&this._positionHighBuffer.numItems===t||(e.gl.deleteBuffer(this._positionHighBuffer),e.gl.deleteBuffer(this._positionLowBuffer),this._positionHighBuffer=e.createStreamArrayBuffer(3,t),this._positionLowBuffer=e.createStreamArrayBuffer(3,t)),e.setStreamArrayBuffer(this._positionHighBuffer,this._positionHighArr),e.setStreamArrayBuffer(this._positionLowBuffer,this._positionLowArr)}createSizeBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._sizeBuffer),this._sizeBuffer=e.createArrayBuffer(this._sizeArr,2,this._sizeArr.length/2)}createOffsetBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._offsetBuffer),this._offsetBuffer=e.createArrayBuffer(this._offsetArr,3,this._offsetArr.length/3)}createRgbaBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._rgbaBuffer),this._rgbaBuffer=e.createArrayBuffer(this._rgbaArr,4,this._rgbaArr.length/4)}createRotationBuffer(){let e=this._renderer.handler;this._rotationBuffer&&this._rotationBuffer.numItems===this._rotationArr.length||(e.gl.deleteBuffer(this._rotationBuffer),this._rotationBuffer=e.createStreamArrayBuffer(1,this._rotationArr.length)),e.setStreamArrayBuffer(this._rotationBuffer,this._rotationArr)}createVertexBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._vertexBuffer),this._vertexBuffer=e.createArrayBuffer(this._vertexArr,2,this._vertexArr.length/2)}createTexCoordBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._texCoordBuffer),this._texCoordBuffer=e.createArrayBuffer(this._texCoordArr,2,this._texCoordArr.length/2)}createPickingColorBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._pickingColorBuffer),this._pickingColorBuffer=e.createArrayBuffer(this._pickingColorArr,3,this._pickingColorArr.length/3)}refreshTexCoordsArr(){}}Vi.__counter__=0;class Ui extends Vi{constructor(e){super(e),this._billboards=[]}add(e){if(-1==e._handlerIndex){super.add(e),this._addBillboardToArrays(e),this.refresh();let t=e.getSrc()||e.getImage()&&e.getImage().src;t&&e.setSrc(t)}}_addBillboardToArrays(e){e.getVisibility()?this._vertexArr=He(this._vertexArr,[-.5,.5,-.5,-.5,.5,-.5,.5,-.5,.5,.5,-.5,.5]):this._vertexArr=He(this._vertexArr,[0,0,0,0,0,0,0,0,0,0,0,0]),this._texCoordArr=He(this._texCoordArr,[0,0,0,0,0,0,0,0,0,0,0,0]);let t,i=e._positionHigh.x,s=e._positionHigh.y,n=e._positionHigh.z;this._positionHighArr=He(this._positionHighArr,[i,s,n,i,s,n,i,s,n,i,s,n,i,s,n,i,s,n]),i=e._positionLow.x,s=e._positionLow.y,n=e._positionLow.z,this._positionLowArr=He(this._positionLowArr,[i,s,n,i,s,n,i,s,n,i,s,n,i,s,n,i,s,n]),i=e._width,s=e._height,this._sizeArr=He(this._sizeArr,[i,s,i,s,i,s,i,s,i,s,i,s]),i=e._offset.x,s=e._offset.y,n=e._offset.z,this._offsetArr=He(this._offsetArr,[i,s,n,i,s,n,i,s,n,i,s,n,i,s,n,i,s,n]),i=e._color.x,s=e._color.y,n=e._color.z,t=e._color.w,this._rgbaArr=He(this._rgbaArr,[i,s,n,t,i,s,n,t,i,s,n,t,i,s,n,t,i,s,n,t,i,s,n,t]),i=e._rotation,this._rotationArr=He(this._rotationArr,[i,i,i,i,i,i]),i=e._entity._pickingColor.x/255,s=e._entity._pickingColor.y/255,n=e._entity._pickingColor.z/255,this._pickingColorArr=He(this._pickingColorArr,[i,s,n,i,s,n,i,s,n,i,s,n,i,s,n,i,s,n])}get billboards(){return this._billboards}refreshTexCoordsArr(){if(this._entityCollection&&this._renderer){let e=this._renderer.billboardsTextureAtlas;for(let t=0;t<this._billboards.length;t++){let i=this._billboards[t],s=i.getImage();if(s){let t=e.get(s.__nodeIndex);t&&this.setTexCoordArr(i._handlerIndex,t.texCoords)}}}}}const Gi="vec3 qRotate(vec4 q, vec3 v){\n return v + 2.0 * cross(q.xyz, cross(q.xyz, v) + q.w * v);\n}";class Yi{constructor(e){this.isFree=!0,this._geoObjectHandler=e,this.geoObjects=[],this.numInstances=0,this._colorTexture=null,this._colorTextureSrc=null,this._normalTexture=null,this._normalTextureSrc=null,this._metallicRoughnessTexture=null,this._metallicRoughnessTextureSrc=null,this._sizeArr=[],this._translateArr=[],this._vertexArr=[],this._rtcPositionHighArr=[],this._rtcPositionLowArr=[],this._qRotArr=[],this._rgbaArr=[],this._normalsArr=[],this._indicesArr=[],this._pickingColorArr=[],this._visibleArr=[],this._texCoordArr=[],this._localPositionArr=[],this._sizeBuffer=null,this._translateBuffer=null,this._vertexBuffer=null,this._rtcPositionHighBuffer=null,this._rtcPositionLowBuffer=null,this._qRotBuffer=null,this._rgbaBuffer=null,this._normalsBuffer=null,this._indicesBuffer=null,this._pickingColorBuffer=null,this._visibleBuffer=null,this._texCoordBuffer=null,this._localPositionBuffer=null,this._materialParams=new Float32Array(9),this._materialShininess=0,this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[Qi]=this.createPickingColorBuffer,this._buffersUpdateCallbacks[$i]=this.createNormalsBuffer,this._buffersUpdateCallbacks[qi]=this.createRgbaBuffer,this._buffersUpdateCallbacks[Xi]=this.createIndicesBuffer,this._buffersUpdateCallbacks[ji]=this.createVertexBuffer,this._buffersUpdateCallbacks[Ki]=this.createSizeBuffer,this._buffersUpdateCallbacks[Ji]=this.createVisibleBuffer,this._buffersUpdateCallbacks[es]=this.createTexCoordBuffer,this._buffersUpdateCallbacks[Zi]=this.createQRotBuffer,this._buffersUpdateCallbacks[ts]=this.createTranslateBuffer,this._buffersUpdateCallbacks[Wi]=this.createRTCPositionBuffer,this._buffersUpdateCallbacks[is]=this.createLocalPositionBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length)}setMaterialAmbient(e,t,i){this._materialParams[0]=e,this._materialParams[1]=t,this._materialParams[2]=i}setMaterialDiffuse(e,t,i){this._materialParams[3]=e,this._materialParams[4]=t,this._materialParams[5]=i}setMaterialSpecular(e,t,i){this._materialParams[6]=e,this._materialParams[7]=t,this._materialParams[8]=i}setMaterialShininess(e){this._materialShininess=e}setMaterialParams(e,t,i,s){this.setMaterialAmbient(e[0],e[1],e[2]),this.setMaterialDiffuse(t[0],t[1],t[2]),this.setMaterialSpecular(i[0],i[1],i[2]),this.setMaterialShininess(s)}drawOpaque(e){let t=e.gl,i=e.uniforms,s=e.attributes;t.bindBuffer(t.ARRAY_BUFFER,this._qRotBuffer),t.vertexAttribPointer(s.qRot,this._qRotBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._sizeBuffer),t.vertexAttribPointer(s.aScale,this._sizeBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._translateBuffer),t.vertexAttribPointer(s.aTranslate,this._translateBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._localPositionBuffer),t.vertexAttribPointer(s.aLocalPosition,this._localPositionBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._visibleBuffer),t.vertexAttribPointer(s.aDispose,this._visibleBuffer.itemSize,t.FLOAT,!1,0,0),t.uniform1f(i.uUseTexture,this._colorTexture?1:0),t.bindBuffer(t.ARRAY_BUFFER,this._rgbaBuffer),t.vertexAttribPointer(s.aColor,this._rgbaBuffer.itemSize,t.FLOAT,!1,0,0),t.uniform3fv(i.materialParams,this._materialParams),t.uniform1f(i.materialShininess,this._materialShininess),this._drawElementsInstanced(e)}drawTransparent(e){let t=e.gl,i=e.uniforms,s=e.attributes;t.bindBuffer(t.ARRAY_BUFFER,this._qRotBuffer),t.vertexAttribPointer(s.qRot,this._qRotBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._sizeBuffer),t.vertexAttribPointer(s.aScale,this._sizeBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._translateBuffer),t.vertexAttribPointer(s.aTranslate,this._translateBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._localPositionBuffer),t.vertexAttribPointer(s.aLocalPosition,this._localPositionBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._visibleBuffer),t.vertexAttribPointer(s.aDispose,this._visibleBuffer.itemSize,t.FLOAT,!1,0,0),t.uniform1f(i.uUseTexture,this._colorTexture?1:0),t.uniform3fv(i.materialParams,this._materialParams),t.uniform1f(i.materialShininess,this._materialShininess),t.bindBuffer(t.ARRAY_BUFFER,this._rgbaBuffer),t.vertexAttribPointer(s.aColor,this._rgbaBuffer.itemSize,t.FLOAT,!1,0,0),this._drawElementsInstanced(e)}_drawElementsInstanced(e){let t=e.gl,i=e.uniforms,s=e.attributes,n=this._geoObjectHandler._renderer;t.bindBuffer(t.ARRAY_BUFFER,this._rtcPositionHighBuffer),t.vertexAttribPointer(s.aRTCPositionHigh,this._rtcPositionHighBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._rtcPositionLowBuffer),t.vertexAttribPointer(s.aRTCPositionLow,this._rtcPositionLowBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._normalsBuffer),t.vertexAttribPointer(s.aVertexNormal,this._normalsBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._vertexBuffer),t.vertexAttribPointer(s.aVertexPosition,this._vertexBuffer.itemSize,t.FLOAT,!1,0,0),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this._colorTexture||n.handler.defaultTexture),t.uniform1i(i.uTexture,0),t.bindBuffer(t.ARRAY_BUFFER,this._texCoordBuffer),t.vertexAttribPointer(s.aTexCoord,this._texCoordBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this._indicesBuffer),e.drawElementsInstanced(t.TRIANGLES,this._indicesBuffer.numItems,t.UNSIGNED_INT,0,this.numInstances)}createColorTexture(e){if(this._geoObjectHandler&&this._geoObjectHandler._renderer){let t=this._geoObjectHandler._renderer.handler;this._colorTexture=t.createTextureDefault(e,null,t.gl.REPEAT)}}createNormalTexture(e){if(this._geoObjectHandler&&this._geoObjectHandler._renderer){let t=this._geoObjectHandler._renderer.handler;this._normalTexture=t.createTextureDefault(e,null,t.gl.REPEAT)}}createMetallicRoughnessTexture(e){if(this._geoObjectHandler&&this._geoObjectHandler._renderer){let t=this._geoObjectHandler._renderer.handler;this._metallicRoughnessTexture=t.createTextureDefault(e,null,t.gl.REPEAT)}}clear(){this.numInstances=0,this.geoObjects=[],this._sizeArr=[],this._translateArr=[],this._vertexArr=[],this._rtcPositionHighArr=[],this._rtcPositionLowArr=[],this._qRotArr=[],this._rgbaArr=[],this._normalsArr=[],this._indicesArr=[],this._pickingColorArr=[],this._visibleArr=[],this._texCoordArr=[],this._localPositionArr=[],this._deleteBuffers(),this.isFree=!1}_deleteBuffers(){if(this._geoObjectHandler&&this._geoObjectHandler._renderer){let e=this._geoObjectHandler._renderer.handler,t=e.gl;e.deleteTexture(this._colorTexture),e.deleteTexture(this._normalTexture),e.deleteTexture(this._metallicRoughnessTexture),this._colorTexture=null,this._normalTexture=null,this._metallicRoughnessTexture=null,t.deleteBuffer(this._sizeBuffer),t.deleteBuffer(this._translateBuffer),t.deleteBuffer(this._vertexBuffer),t.deleteBuffer(this._rtcPositionHighBuffer),t.deleteBuffer(this._rtcPositionLowBuffer),t.deleteBuffer(this._qRotBuffer),t.deleteBuffer(this._rgbaBuffer),t.deleteBuffer(this._normalsBuffer),t.deleteBuffer(this._indicesBuffer),t.deleteBuffer(this._pickingColorBuffer),t.deleteBuffer(this._visibleBuffer),t.deleteBuffer(this._texCoordBuffer),t.deleteBuffer(this._localPositionBuffer)}this._sizeBuffer=null,this._translateBuffer=null,this._vertexBuffer=null,this._rtcPositionHighBuffer=null,this._rtcPositionLowBuffer=null,this._qRotBuffer=null,this._rgbaBuffer=null,this._normalsBuffer=null,this._indicesBuffer=null,this._pickingColorBuffer=null,this._visibleBuffer=null,this._texCoordBuffer=null,this._localPositionBuffer=null}createVertexBuffer(){const e=this._geoObjectHandler._renderer.handler;e.gl.deleteBuffer(this._vertexBuffer),this._vertexArr=Ve(this._vertexArr),this._vertexBuffer=e.createArrayBuffer(this._vertexArr,3,this._vertexArr.length/3)}createVisibleBuffer(){const e=this._geoObjectHandler._renderer.handler,t=this._visibleArr.length;this._visibleBuffer&&this._visibleBuffer.numItems===t||(e.gl.deleteBuffer(this._visibleBuffer),this._visibleBuffer=e.createStreamArrayBuffer(1,t)),this._visibleArr=Ve(this._visibleArr),e.setStreamArrayBuffer(this._visibleBuffer,this._visibleArr)}createSizeBuffer(){let e=this._geoObjectHandler._renderer.handler,t=this._sizeArr.length/3;this._sizeBuffer&&this._sizeBuffer.numItems===t||(e.gl.deleteBuffer(this._sizeBuffer),this._sizeBuffer=e.createStreamArrayBuffer(3,t)),this._sizeArr=Ve(this._sizeArr),e.setStreamArrayBuffer(this._sizeBuffer,this._sizeArr)}createTranslateBuffer(){let e=this._geoObjectHandler._renderer.handler,t=this._translateArr.length/3;this._translateBuffer&&this._translateBuffer.numItems===t||(e.gl.deleteBuffer(this._translateBuffer),this._translateBuffer=e.createStreamArrayBuffer(3,t)),this._translateArr=Ve(this._translateArr),e.setStreamArrayBuffer(this._translateBuffer,this._translateArr)}createLocalPositionBuffer(){let e=this._geoObjectHandler._renderer.handler,t=this._localPositionArr.length/3;this._localPositionBuffer&&this._localPositionBuffer.numItems===t||(e.gl.deleteBuffer(this._localPositionBuffer),this._localPositionBuffer=e.createStreamArrayBuffer(3,t)),this._localPositionArr=Ve(this._localPositionArr),e.setStreamArrayBuffer(this._localPositionBuffer,this._localPositionArr)}createTexCoordBuffer(){const e=this._geoObjectHandler._renderer.handler;e.gl.deleteBuffer(this._texCoordBuffer),this._texCoordArr=Ve(this._texCoordArr),this._texCoordBuffer=e.createArrayBuffer(this._texCoordArr,2,this._texCoordArr.length/2)}createRTCPositionBuffer(){let e=this._geoObjectHandler._renderer.handler,t=this._rtcPositionHighArr.length/3;this._rtcPositionHighBuffer&&this._rtcPositionHighBuffer.numItems===t||(e.gl.deleteBuffer(this._rtcPositionHighBuffer),e.gl.deleteBuffer(this._rtcPositionLowBuffer),this._rtcPositionHighBuffer=e.createStreamArrayBuffer(3,t),this._rtcPositionLowBuffer=e.createStreamArrayBuffer(3,t)),this._rtcPositionHighArr=Ve(this._rtcPositionHighArr),this._rtcPositionLowArr=Ve(this._rtcPositionLowArr),e.setStreamArrayBuffer(this._rtcPositionHighBuffer,this._rtcPositionHighArr),e.setStreamArrayBuffer(this._rtcPositionLowBuffer,this._rtcPositionLowArr)}createRgbaBuffer(){let e=this._geoObjectHandler._renderer.handler,t=this._rgbaArr.length/4;this._rgbaBuffer&&this._rgbaBuffer.numItems===t||(e.gl.deleteBuffer(this._rgbaBuffer),this._rgbaBuffer=e.createStreamArrayBuffer(4,t)),this._rgbaArr=Ve(this._rgbaArr),e.setStreamArrayBuffer(this._rgbaBuffer,this._rgbaArr)}createQRotBuffer(){let e=this._geoObjectHandler._renderer.handler,t=this._qRotArr.length/4;this._qRotBuffer&&this._qRotBuffer.numItems===t||(e.gl.deleteBuffer(this._qRotBuffer),this._qRotBuffer=e.createStreamArrayBuffer(4,t)),this._qRotArr=Ve(this._qRotArr),e.setStreamArrayBuffer(this._qRotBuffer,this._qRotArr)}createNormalsBuffer(){const e=this._geoObjectHandler._renderer.handler;e.gl.deleteBuffer(this._normalsBuffer),this._normalsArr=Ve(this._normalsArr),this._normalsBuffer=e.createArrayBuffer(this._normalsArr,3,this._normalsArr.length/3)}createIndicesBuffer(){const e=this._geoObjectHandler._renderer.handler;e.gl.deleteBuffer(this._indicesBuffer),this._indicesArr=Ve(this._indicesArr,Uint32Array),this._indicesBuffer=e.createElementArrayBuffer(this._indicesArr,1,this._indicesArr.length)}createPickingColorBuffer(){const e=this._geoObjectHandler._renderer.handler;e.gl.deleteBuffer(this._pickingColorBuffer),this._pickingColorArr=Ve(this._pickingColorArr),this._pickingColorBuffer=e.createArrayBuffer(this._pickingColorArr,3,this._pickingColorArr.length/3)}refresh(){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]=!0}update(){if(this._geoObjectHandler._renderer){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1);this.isFree=!0}}}const ji=0,Wi=1,qi=2,$i=3,Xi=4,Zi=5,Ki=6,Qi=7,Ji=8,es=9,ts=10,is=11;function ss(e,t=0,i=0,s=1,...n){const r=t*i;for(let t=r,o=r+i;t<o;t++)e[t]=n[t%s];return e}class ns{constructor(e){this.__id=ns.__counter__++,this.pickingEnabled=!0,this._entityCollection=e,this._renderNode=null,this._renderer=null,this._geoObjects=[],this._instanceDataMap=new Map,this._instanceDataMapValues=[],this._dataTagUpdateQueue=[],this._relativeCenter=new oe,this._rtcEyePositionHigh=new Float32Array([0,0,0]),this._rtcEyePositionLow=new Float32Array([0,0,0])}initProgram(){this._renderer&&(this._renderer.handler.programs.geo_object||this._renderer.handler.addProgram(new Ni("geo_object",{uniforms:{viewMatrix:"mat4",projectionMatrix:"mat4",uScaleByDistance:"vec3",eyePositionHigh:"vec3",eyePositionLow:"vec3",rtcEyePositionHigh:"vec3",rtcEyePositionLow:"vec3",sunPosition:"vec3",materialParams:"vec3",materialShininess:"float",uTexture:"sampler2d",uUseTexture:"float",useLighting:"float"},attributes:{aVertexPosition:"vec3",aVertexNormal:"vec3",aTexCoord:"vec2",aLocalPosition:{type:"vec3",divisor:1},aRTCPositionHigh:{type:"vec3",divisor:1},aRTCPositionLow:{type:"vec3",divisor:1},aColor:{type:"vec4",divisor:1},aScale:{type:"vec3",divisor:1},aTranslate:{type:"vec3",divisor:1},aDispose:{type:"float",divisor:1},qRot:{type:"vec4",divisor:1}},vertexShader:`precision highp float;\n \n attribute vec3 aVertexPosition;\n attribute vec3 aVertexNormal; \n \n attribute vec3 aRTCPositionHigh;\n attribute vec3 aRTCPositionLow; \n \n attribute vec4 aColor;\n attribute vec3 aScale;\n attribute vec3 aTranslate;\n attribute float aDispose;\n attribute float aUseTexture;\n attribute vec2 aTexCoord;\n attribute vec4 qRot;\n attribute vec3 aLocalPosition;\n \n uniform vec3 uScaleByDistance;\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n \n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n \n uniform vec3 rtcEyePositionHigh;\n uniform vec3 rtcEyePositionLow;\n\n varying vec3 cameraPosition;\n varying vec3 vNormal;\n varying vec3 v_vertex; \n varying vec4 vColor;\n varying float vDispose;\n varying vec2 vTexCoords;\n \n ${Gi}\n \n void main(void) {\n \n if (aDispose == 0.0) {\n return;\n }\n \n vColor = aColor;\n vTexCoords = aTexCoord; \n \n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n \n vec3 highDiff = aRTCPositionHigh - rtcEyePositionHigh;\n vec3 lowDiff = aRTCPositionLow - rtcEyePositionLow;\n \n cameraPosition = eyePositionHigh + eyePositionLow;\n \n highDiff = highDiff * step(1.0, length(highDiff));\n \n vec4 positionInViewSpace = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n float lookLength = length(positionInViewSpace.xyz);\n \n vNormal = normalize(qRotate(qRot, aVertexNormal));\n \n float scd = uScaleByDistance[2] * clamp(lookLength, uScaleByDistance[0], uScaleByDistance[1]) / uScaleByDistance[0];\n vec3 vert = qRotate(qRot, scd * (aVertexPosition * aScale + aTranslate)) + scd * aLocalPosition;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff + lowDiff + vert, 1.0);\n \n v_vertex = positionInViewSpace.xyz + vert;\n }`,fragmentShader:"precision highp float;\n \n uniform vec3 sunPosition;\n uniform vec3 materialParams[3];\n uniform float materialShininess;\n uniform sampler2D uTexture;\n uniform float uUseTexture;\n uniform float useLighting; \n \n varying vec3 cameraPosition;\n varying vec3 v_vertex; \n varying vec4 vColor;\n varying vec3 vNormal;\n varying vec2 vTexCoords;\n \n void main(void) { \n \n vec3 lightWeighting = vec3(1.0);\n \n if(useLighting != 0.0){\n vec3 normal = vNormal;\n vec3 lightDir = normalize(sunPosition);\n vec3 viewDir = normalize(cameraPosition - v_vertex); \n vec3 reflectionDirection = reflect(-lightDir, normal);\n float reflection = max( dot(reflectionDirection, viewDir), 0.0);\n float specularLightWeighting = pow( reflection, materialShininess); \n float diffuseLightWeighting = max(dot(normal, lightDir), 0.0);\n lightWeighting = vColor.rgb * materialParams[0] + materialParams[1] * diffuseLightWeighting + materialParams[2] * specularLightWeighting;\n } else {\n lightWeighting = vColor.rgb;\n }\n \n if(uUseTexture > 0.0) {\n vec4 texColor = texture2D(uTexture, vTexCoords);\n gl_FragColor = vec4(texColor.rgb * lightWeighting, texColor.a);\n } else {\n gl_FragColor = vec4(lightWeighting, vColor.a);\n }\n }"})),this._renderer.handler.programs.geo_object_picking||this._renderer.handler.addProgram(new Ni("geo_object_picking",{uniforms:{viewMatrix:"mat4",projectionMatrix:"mat4",uScaleByDistance:"vec3",pickingScale:"vec3",rtcEyePositionHigh:"vec3",rtcEyePositionLow:"vec3"},attributes:{aVertexPosition:"vec3",aRTCPositionHigh:{type:"vec3",divisor:1},aRTCPositionLow:{type:"vec3",divisor:1},aPickingColor:{type:"vec3",divisor:1},aScale:{type:"vec3",divisor:1},aTranslate:{type:"vec3",divisor:1},aLocalPosition:{type:"vec3",divisor:1},aDispose:{type:"float",divisor:1},qRot:{type:"vec4",divisor:1}},vertexShader:`precision highp float;\n\n attribute vec3 aVertexPosition;\n attribute vec3 aRTCPositionHigh;\n attribute vec3 aRTCPositionLow;\n attribute vec3 aPickingColor; \n attribute vec3 aScale;\n attribute vec3 aTranslate;\n attribute float aDispose;\n attribute vec4 qRot;\n \n attribute vec3 aLocalPosition;\n \n uniform vec3 rtcEyePositionHigh;\n uniform vec3 rtcEyePositionLow;\n \n uniform vec3 uScaleByDistance;\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 pickingScale;\n\n varying vec3 vColor;\n \n ${Gi}\n\n void main(void) {\n\n if (aDispose == 0.0) {\n return;\n } \n \n vColor = aPickingColor;\n \n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n \n vec3 highDiff = aRTCPositionHigh - rtcEyePositionHigh;\n vec3 lowDiff = aRTCPositionLow - rtcEyePositionLow; \n \n highDiff = highDiff * step(1.0, length(highDiff));\n \n vec4 positionInViewSpace = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n float lookLength = length(positionInViewSpace.xyz);\n \n float scd = uScaleByDistance[2] * clamp(lookLength, uScaleByDistance[0], uScaleByDistance[1]) / uScaleByDistance[0];\n\n vec3 vert = qRotate(qRot, scd * pickingScale * (aVertexPosition * aScale + aTranslate)) + scd * aLocalPosition;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff + lowDiff + vert, 1.0);\n }`,fragmentShader:"precision highp float;\n varying vec3 vColor;\n void main () {\n gl_FragColor = vec4(vColor, 1.0);\n }"})),this._renderer.handler.programs.geo_object_depth||this._renderer.handler.addProgram(new Ni("geo_object_depth",{uniforms:{viewMatrix:"mat4",projectionMatrix:"mat4",uScaleByDistance:"vec3",rtcEyePositionHigh:"vec3",rtcEyePositionLow:"vec3",frustumPickingColor:"float"},attributes:{aVertexPosition:"vec3",aRTCPositionHigh:{type:"vec3",divisor:1},aRTCPositionLow:{type:"vec3",divisor:1},aScale:{type:"vec3",divisor:1},aTranslate:{type:"vec3",divisor:1},aDispose:{type:"float",divisor:1},qRot:{type:"vec4",divisor:1},aLocalPosition:{type:"vec3",divisor:1}},vertexShader:`#version 300 es\n precision highp float;\n\n in vec3 aVertexPosition;\n in vec3 aRTCPositionHigh;\n in vec3 aRTCPositionLow;\n in vec3 aScale;\n in vec3 aTranslate;\n in float aDispose;\n in vec4 qRot;\n in vec3 aLocalPosition;\n \n uniform vec3 rtcEyePositionHigh;\n uniform vec3 rtcEyePositionLow;\n uniform vec3 uScaleByDistance;\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n \n ${Gi}\n\n void main(void) {\n\n if (aDispose == 0.0) {\n return;\n }\n \n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n \n vec3 highDiff = aRTCPositionHigh - rtcEyePositionHigh;\n vec3 lowDiff = aRTCPositionLow - rtcEyePositionLow; \n \n highDiff = highDiff * step(1.0, length(highDiff));\n \n vec4 positionInViewSpace = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n float lookLength = length(positionInViewSpace.xyz);\n \n float scd = uScaleByDistance[2] * clamp(lookLength, uScaleByDistance[0], uScaleByDistance[1]) / uScaleByDistance[0];\n\n vec3 vert = qRotate(qRot, scd * (aVertexPosition * aScale + aTranslate)) + scd * aLocalPosition;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff + lowDiff + vert, 1.0);\n }`,fragmentShader:"#version 300 es\n precision highp float;\n \n uniform float frustumPickingColor;\n \n layout(location = 0) out vec4 frustumColor;\n layout(location = 1) out vec4 depthColor;\n \n void main () {\n frustumColor = vec4(frustumPickingColor, frustumPickingColor, frustumPickingColor, 1.0);\n depthColor = vec4(gl_FragCoord.z, gl_FragCoord.z, gl_FragCoord.z, 1.0);\n }"})))}setRenderNode(e){this._renderNode=e,this._renderer=e.renderer,this.initProgram();for(let e=0;e<this._instanceDataMapValues.length;e++)this._loadColorTexture(this._instanceDataMapValues[e]),this._loadNormalTexture(this._instanceDataMapValues[e]),this._loadMetallicRoughnessTexture(this._instanceDataMapValues[e]);for(let e=0;e<this._geoObjects.length;e++)this._geoObjects[e].updateRotation();this.update()}setColorTextureTag(e,t){const i=this._instanceDataMap.get(t);i&&(i._colorTextureSrc=e,this._instanceDataMap.set(t,i),this._loadColorTexture(i))}setNormalTextureTag(e,t){const i=this._instanceDataMap.get(t);i&&(i._normalTextureSrc=e,this._instanceDataMap.set(t,i),this._loadNormalTexture(i))}setMetallicRoughnessTextureTag(e,t){const i=this._instanceDataMap.get(t);i&&(i._metallicRoughnessTextureSrc=e,this._instanceDataMap.set(t,i),this._loadMetallicRoughnessTexture(i))}setObjectSrc(e,t){const i=this._instanceDataMap.get(t);e&&i&&i._objectSrc!==e&&(i._objectSrc=e,mi.loadObj(e).then((e=>{this._updateInstanceData(e[0],t)})))}_updateInstanceData(e,t){const i=this._instanceDataMap.get(t);i&&(e.vertices.length!==i._vertexArr.length&&(i._vertexArr=e.vertices,i._changedBuffers[ji]=!0),e.normals.length!==i._normalsArr.length&&(i._normalsArr=e.normals,i._changedBuffers[$i]=!0),e.indices.length!==i._indicesArr.length&&(i._indicesArr=e.indices,i._changedBuffers[Xi]=!0),e.texCoords.length!==i._texCoordArr.length&&(i._texCoordArr=e.texCoords,i._changedBuffers[es]=!0),i._colorTextureSrc=e.colorTexture,i._normalTextureSrc=e.normalTexture,i._metallicRoughnessTexture=e.metallicRoughnessTexture,this._loadColorTexture(i),this._loadNormalTexture(i),this._loadMetallicRoughnessTexture(i),this._updateTag(i),this._instanceDataMapValues=Array.from(this._instanceDataMap.values()))}_addGeoObjectToArray(e){const t=e.tag;let i=this._instanceDataMap.get(t);i||(i=new Yi(this),this._instanceDataMap.set(t,i),this._instanceDataMapValues=Array.from(this._instanceDataMap.values()),i._vertexArr=e.vertices,i._normalsArr=e.normals,i._indicesArr=e.indices,i._texCoordArr=e.texCoords,i._colorTextureSrc=e.object3d.colorTexture,i._normalTextureSrc=e.object3d.normalTexture,i._metallicRoughnessTextureSrc=e.object3d.metallicRoughnessTexture,i.setMaterialParams(e.object3d.ambient,e.object3d.diffuse,e.object3d.specular,e.object3d.shininess),this._loadColorTexture(i),this._loadNormalTexture(i),this._loadMetallicRoughnessTexture(i)),e._tagDataIndex=i.numInstances++,e._tagData=i,i.geoObjects.push(e);let s=3;i._visibleArr=Oe(i._visibleArr,ss([],0,1,1,e.getVisibility()?1:0)),this.getRTCPosition(e.getPosition(),e._rtcPositionHigh,e._rtcPositionLow);let n,r=e._rtcPositionHigh.x,o=e._rtcPositionHigh.y,a=e._rtcPositionHigh.z;i._rtcPositionHighArr=Oe(i._rtcPositionHighArr,ss([],0,s,s,r,o,a)),r=e._rtcPositionLow.x,o=e._rtcPositionLow.y,a=e._rtcPositionLow.z,i._rtcPositionLowArr=Oe(i._rtcPositionLowArr,ss([],0,s,s,r,o,a)),r=e._entity._pickingColor.x/255,o=e._entity._pickingColor.y/255,a=e._entity._pickingColor.z/255,i._pickingColorArr=Oe(i._pickingColorArr,ss([],0,s,s,r,o,a)),s=4,r=e._qRot.x,o=e._qRot.y,a=e._qRot.z,n=e._qRot.w,i._qRotArr=Oe(i._qRotArr,ss([],0,s,s,r,o,a,n)),r=e._color.x,o=e._color.y,a=e._color.z,n=e._color.w,i._rgbaArr=Oe(i._rgbaArr,ss([],0,s,s,r,o,a,n)),s=3;let l=e.getScale();r=l.x,o=l.y,a=l.z,i._sizeArr=Oe(i._sizeArr,ss([],0,s,s,r,o,a));let h=e.getTranslate();r=h.x,o=h.y,a=h.z,i._translateArr=Oe(i._translateArr,ss([],0,s,s,r,o,a));let c=e.getLocalPosition();r=c.x,o=c.y,a=c.z,i._localPositionArr=Oe(i._localPositionArr,ss([],0,s,s,r,o,a))}_bindCommon(){let e=this._renderer,t=e.handler.programs.geo_object._program.uniforms,i=e.handler.gl,s=this._entityCollection;i.uniform3fv(t.uScaleByDistance,s.scaleByDistance),i.uniform1f(t.useLighting,s._useLighting),i.uniform3fv(t.eyePositionHigh,e.activeCamera.eyeHigh),i.uniform3fv(t.eyePositionLow,e.activeCamera.eyeLow),i.uniform3fv(t.rtcEyePositionHigh,this._rtcEyePositionHigh),i.uniform3fv(t.rtcEyePositionLow,this._rtcEyePositionLow),i.uniformMatrix4fv(t.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),i.uniformMatrix4fv(t.viewMatrix,!1,e.activeCamera.getViewMatrix()),i.uniform3fv(t.sunPosition,this._renderNode._lightPosition)}_displayOpaquePASS(){let e=this._renderer.handler.programs.geo_object,t=e._program;e.activate(),this._bindCommon();for(let e=0;e<this._instanceDataMapValues.length;e++){this._instanceDataMapValues[e].drawOpaque(t)}}_displayTransparentPASS(){let e=this._renderer.handler.programs.geo_object,t=e._program;e.activate(),this._bindCommon();for(let e=0;e<this._instanceDataMapValues.length;e++)this._instanceDataMapValues[e].drawTransparent(t)}_depthPASS(){let e=this._renderer,t=e.handler.programs.geo_object_depth,i=t._program,s=i.uniforms,n=i.attributes,r=e.handler.gl,o=this._entityCollection,a=e.activeCamera;t.activate(),r.uniform3fv(s.uScaleByDistance,o.scaleByDistance),r.uniform3fv(s.rtcEyePositionHigh,this._rtcEyePositionHigh),r.uniform3fv(s.rtcEyePositionLow,this._rtcEyePositionLow),r.uniformMatrix4fv(s.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),r.uniformMatrix4fv(s.viewMatrix,!1,e.activeCamera.getViewMatrix()),r.uniform1f(s.frustumPickingColor,a.frustumColorIndex);for(let e=0;e<this._instanceDataMapValues.length;e++){let t=this._instanceDataMapValues[e];r.bindBuffer(r.ARRAY_BUFFER,t._qRotBuffer),r.vertexAttribPointer(n.qRot,t._qRotBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._sizeBuffer),r.vertexAttribPointer(n.aScale,t._sizeBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._translateBuffer),r.vertexAttribPointer(n.aTranslate,t._translateBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._localPositionBuffer),r.vertexAttribPointer(n.aLocalPosition,t._localPositionBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._rtcPositionHighBuffer),r.vertexAttribPointer(n.aRTCPositionHigh,t._rtcPositionHighBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._rtcPositionLowBuffer),r.vertexAttribPointer(n.aRTCPositionLow,t._rtcPositionLowBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._visibleBuffer),r.vertexAttribPointer(n.aDispose,t._visibleBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._vertexBuffer),r.vertexAttribPointer(n.aVertexPosition,t._vertexBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,t._indicesBuffer),i.drawElementsInstanced(r.TRIANGLES,t._indicesBuffer.numItems,r.UNSIGNED_INT,0,t.numInstances)}}drawDepth(){this._geoObjects.length&&this._depthPASS()}drawPicking(){this._geoObjects.length&&this.pickingEnabled&&this._pickingPASS()}_pickingPASS(){let e=this._renderer,t=e.handler.programs.geo_object_picking,i=t._program,s=i.uniforms,n=i.attributes,r=e.handler.gl,o=this._entityCollection;t.activate(),r.uniform3fv(s.uScaleByDistance,o.scaleByDistance),r.uniform3fv(s.pickingScale,o.pickingScale),r.uniform3fv(s.rtcEyePositionHigh,this._rtcEyePositionHigh),r.uniform3fv(s.rtcEyePositionLow,this._rtcEyePositionLow),r.uniformMatrix4fv(s.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),r.uniformMatrix4fv(s.viewMatrix,!1,e.activeCamera.getViewMatrix());for(let e=0;e<this._instanceDataMapValues.length;e++){let t=this._instanceDataMapValues[e];r.bindBuffer(r.ARRAY_BUFFER,t._qRotBuffer),r.vertexAttribPointer(n.qRot,t._qRotBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._sizeBuffer),r.vertexAttribPointer(n.aScale,t._sizeBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._translateBuffer),r.vertexAttribPointer(n.aTranslate,t._translateBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._localPositionBuffer),r.vertexAttribPointer(n.aLocalPosition,t._localPositionBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._pickingColorBuffer),r.vertexAttribPointer(n.aPickingColor,t._pickingColorBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._rtcPositionHighBuffer),r.vertexAttribPointer(n.aRTCPositionHigh,t._rtcPositionHighBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._rtcPositionLowBuffer),r.vertexAttribPointer(n.aRTCPositionLow,t._rtcPositionLowBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._visibleBuffer),r.vertexAttribPointer(n.aDispose,t._visibleBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._vertexBuffer),r.vertexAttribPointer(n.aVertexPosition,t._vertexBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,t._indicesBuffer),i.drawElementsInstanced(r.TRIANGLES,t._indicesBuffer.numItems,r.UNSIGNED_INT,0,t.numInstances)}}async _loadColorTexture(e){if(this._renderer&&e._colorTextureSrc){const t=await Xe(e._colorTextureSrc);e.createColorTexture(t)}}async _loadNormalTexture(e){if(this._renderer&&e._normalTextureSrc){const t=await Xe(e._normalTextureSrc);e.createNormalTexture(t)}}async _loadMetallicRoughnessTexture(e){if(this._renderer&&e._metallicRoughnessTextureSrc){const t=await Xe(e._metallicRoughnessTextureSrc);e.createMetallicRoughnessTexture(t)}}setQRotArr(e,t,i){ss(e._qRotArr,t,4,4,i.x,i.y,i.z,i.w),e._changedBuffers[Zi]=!0,this._updateTag(e)}setVisibility(e,t,i){ss(e._visibleArr,t,1,1,i?1:0),e._changedBuffers[Ji]=!0,this._updateTag(e)}setRTCPositionArr(e,t,i,s){ss(e._rtcPositionHighArr,t,3,3,i.x,i.y,i.z),ss(e._rtcPositionLowArr,t,3,3,s.x,s.y,s.z),e._changedBuffers[Wi]=!0,this._updateTag(e)}setRgbaArr(e,t,i){ss(e._rgbaArr,t,4,4,i.x,i.y,i.z,i.w),e._changedBuffers[qi]=!0,this._updateTag(e)}setPickingColorArr(e,t,i){ss(e._pickingColorArr,t,3,3,i.x/255,i.y/255,i.z/255),e._changedBuffers[Qi]=!0,this._updateTag(e)}setScaleArr(e,t,i){ss(e._sizeArr,t,3,3,i.x,i.y,i.z),e._changedBuffers[Ki]=!0,this._updateTag(e)}setTranslateArr(e,t,i){ss(e._translateArr,t,3,3,i.x,i.y,i.z),e._changedBuffers[ts]=!0,this._updateTag(e)}setLocalPositionArr(e,t,i){ss(e._localPositionArr,t,3,3,i.x,i.y,i.z),e._changedBuffers[is]=!0,this._updateTag(e)}_updateTag(e){e.isFree&&(e.isFree=!1,this._dataTagUpdateQueue.push(e))}update(){for(let e=0,t=this._dataTagUpdateQueue.length;e<t;e++)this._dataTagUpdateQueue[e].update();this._dataTagUpdateQueue=[]}_removeAll(){let e=this._geoObjects.length;for(;e--;){const t=this._geoObjects[e];t._tagDataIndex=-1,t._tagData=null,t._handlerIndex=-1,t._handler=null}this._geoObjects.length=0,this._geoObjects=[];for(let e=0;e<this._instanceDataMapValues.length;e++)this._instanceDataMapValues[e].clear();this._instanceDataMap.clear(),this._instanceDataMapValues=[]}clear(){this._removeAll()}getRTCPosition(e,t,i){let s=e.sub(this._relativeCenter);oe.doubleToTwoFloats(s,t,i)}setRelativeCenter(e){this._relativeCenter.copy(e);for(let e=0;e<this._instanceDataMapValues.length;e++){let t=this._instanceDataMapValues[e].geoObjects;for(let e=0;e<t.length;e++)t[e].updateRTCPosition()}}_updateRTCEyePosition(){let e=this._renderer;if(e.activeCamera.isFirstPass){let t=e.activeCamera.eye.sub(this._relativeCenter);oe.doubleToTwoFloat32Array(t,this._rtcEyePositionHigh,this._rtcEyePositionLow)}}draw(){this._geoObjects.length&&(this._updateRTCEyePosition(),this.update(),this._displayOpaquePASS())}drawTransparent(){this._geoObjects.length&&this._displayTransparentPASS()}add(e){-1===e._handlerIndex&&(e._handler=this,e._handlerIndex=this._geoObjects.length,this._geoObjects.push(e),this._addGeoObjectToArray(e),e.updateRotation(),e._tagData.refresh(),this._updateTag(e._tagData),e.setObjectSrc(e._objectSrc))}remove(e){e._handler&&this.__id==e._handler.__id&&this._removeGeoObject(e)}_clearDataTagQueue(){this._dataTagUpdateQueue=[]}_removeGeoObject(e){let t=e._tagData,i=e.tag;t.numInstances--;let s=!1;0===t.numInstances&&(t.clear(),this._instanceDataMap.delete(i),this._instanceDataMapValues=[],this._clearDataTagQueue(),s=!0),this._geoObjects.splice(e._handlerIndex,1);for(let t=e._handlerIndex,i=this._geoObjects.length;t<i;t++){let e=this._geoObjects[t];e._handlerIndex=e._handlerIndex-1}let n=e._tagDataIndex;t.geoObjects.splice(n,1);for(let i=e._tagDataIndex,s=t.geoObjects.length;i<s;i++){let e=t.geoObjects[i];e._tagDataIndex=e._tagDataIndex-1}t._rgbaArr=Ge(t._rgbaArr,4*n,4),t._rtcPositionHighArr=Ge(t._rtcPositionHighArr,3*n,3),t._rtcPositionLowArr=Ge(t._rtcPositionLowArr,3*n,3),t._qRotArr=Ge(t._qRotArr,4*n,4),t._pickingColorArr=Ge(t._pickingColorArr,3*n,3),t._sizeArr=Ge(t._sizeArr,3*n,3),t._translateArr=Ge(t._translateArr,3*n,3),t._localPositionArr=Ge(t._localPositionArr,3*n,3),t._visibleArr=Ge(t._visibleArr,n,1),e._handlerIndex=-1,e._handler=null,e._tagDataIndex=-1,e._tagData=null,s||(t.refresh(),this._updateTag(t))}}ns.__counter__=0;const rs="\n#define EMPTY -1.0\n#define RTL 1.0",os="vec2 project(vec4 p) {\n return (0.5 * p.xyz / p.w + 0.5).xy * viewport;\n }",as="mat2 rotate2d(float angle) {\n return mat2(cos(angle), -sin(angle),\n sin(angle), cos(angle));\n }";const ls=-1;class hs extends Vi{constructor(e,t=21){super(e),this._billboards=[],this._gliphParamBuffer=null,this._fontIndexBuffer=null,this._outlineBuffer=null,this._outlineColorBuffer=null,this._gliphParamArr=new Float32Array([]),this._fontIndexArr=new Float32Array([]),this._outlineArr=new Float32Array([]),this._outlineColorArr=new Float32Array([]),this._buffersUpdateCallbacks[8]=this.createFontIndexBuffer,this._buffersUpdateCallbacks[9]=this.createOutlineBuffer,this._buffersUpdateCallbacks[10]=this.createOutlineColorBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length),this._maxLetters=t}initProgram(){this._renderer&&this._renderer.handler&&this._renderer.handler.gl&&(this._renderer.handler.programs.label||("webgl2"===this._renderer.handler.gl.type?this._renderer.handler.addProgram(new Ni("label",{uniforms:{viewport:"vec2",fontTextureArr:"sampler2darray",sdfParamsArr:"vec4",projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",planetRadius:"float",scaleByDistance:"vec3",opacity:"float",isOutlinePass:"int",depthOffset:"float"},attributes:{a_outline:"float",a_gliphParam:"vec4",a_vertices:"vec2",a_texCoord:"vec4",a_positionsHigh:"vec3",a_positionsLow:"vec3",a_size:"float",a_rotation:"float",a_rgba:"vec4",a_offset:"vec3",a_fontIndex:"float"},vertexShader:`#version 300 es\n \n ${rs}\n \n in float a_outline;\n in vec4 a_gliphParam;\n in vec2 a_vertices;\n in vec4 a_texCoord;\n in vec3 a_positionsHigh;\n in vec3 a_positionsLow;\n in vec3 a_offset;\n in float a_size;\n in float a_rotation;\n in vec4 a_rgba;\n in float a_fontIndex;\n\n out vec2 v_uv;\n out vec4 v_rgba;\n flat out int v_fontIndex; \n out vec4 v_outlineColor;\n flat out float v_outline;\n\n uniform vec2 viewport;\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float planetRadius;\n uniform vec3 scaleByDistance;\n uniform float opacity;\n uniform float depthOffset;\n\n const vec3 ZERO3 = vec3(0.0);\n \n ${os}\n\n ${as}\n\n void main() {\n\n if(a_texCoord.w == EMPTY) {\n gl_Position = vec4(0.0);\n v_fontIndex = -1;\n return;\n }\n \n vec3 a_positions = a_positionsHigh + a_positionsLow;\n vec3 cameraPos = eyePositionHigh + eyePositionLow;\n\n v_outline = a_outline;\n\n v_fontIndex = int(a_fontIndex);\n v_uv = a_texCoord.xy;\n vec3 look = a_positions - cameraPos;\n float lookDist = length(look);\n v_rgba = a_rgba;\n \n if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){\n return;\n }\n\n float scd = (1.0 - smoothstep(scaleByDistance[0], scaleByDistance[1], lookDist)) * (1.0 - step(scaleByDistance[2], lookDist));\n\n v_rgba.a *= opacity;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = a_positionsHigh - eyePositionHigh;\n vec3 lowDiff = a_positionsLow - eyePositionLow;\n vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n vec4 projPos = projectionMatrix * posRTE;\n \n float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos)); \n if(camSlope > 0.5) {\n float dist = dot(look, normalize(cameraPos));\n projPos.z += dist * 0.02; \n }else{\n projPos.z += -(abs(projPos.z)) * 0.002; \n }\n \n projPos.z += depthOffset + a_offset.z;\n \n vec2 screenPos = project(projPos);\n \n vec2 vert = a_vertices; \n vec4 gp = a_gliphParam; \n if(a_texCoord.w == RTL){\n vert.x = step(vert.x * 0.5 + 1.0, 1.0);\n gp.x = -a_gliphParam.x;\n gp.z = -(a_gliphParam.z + a_texCoord.z);\n }else{\n gp.z = a_gliphParam.z + a_texCoord.z;\n }\n \n vec2 v = screenPos + rotate2d(a_rotation) * ((vert * gp.xy + gp.zw) * a_size * scd + a_offset.xy);\n\n gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);\n }`,fragmentShader:"#version 300 es\n\n uniform int isOutlinePass;\n \n precision highp float;\n\n const int MAX_SIZE = 11;\n\n // x - ATLAS_WIDTH = 512.0;\n // y - ATLAS_HEIGHT = 512.0;\n // z - ATLAS_GLYPH_SIZE = 32.0;\n // w - ATLAS_FIELD_RANGE = 8.0;\n\n uniform sampler2D fontTextureArr[MAX_SIZE];\n uniform vec4 sdfParamsArr[MAX_SIZE];\n\n flat in int v_fontIndex;\n in vec2 v_uv;\n in vec4 v_rgba; \n\n flat in float v_outline;\n\n in vec3 v_pickingColor;\n\n layout(location = 0) out vec4 outScreen;\n\n float median(float r, float g, float b) {\n return max(min(r, g), min(max(r, g), b));\n }\n\n float getDistance() {\n vec3 msdf;\n if(v_fontIndex == 0) {\n msdf = texture(fontTextureArr[0], v_uv).rgb;\n } else if(v_fontIndex == 1){\n msdf = texture(fontTextureArr[1], v_uv).rgb;\n } else if(v_fontIndex == 2){\n msdf = texture(fontTextureArr[2], v_uv).rgb;\n } else if(v_fontIndex == 3){\n msdf = texture(fontTextureArr[3], v_uv).rgb;\n } else if(v_fontIndex == 4){\n msdf = texture(fontTextureArr[4], v_uv).rgb;\n } else if(v_fontIndex == 5){\n msdf = texture(fontTextureArr[5], v_uv).rgb;\n } else if(v_fontIndex == 6){\n msdf = texture(fontTextureArr[6], v_uv).rgb;\n } else if(v_fontIndex == 7){\n msdf = texture(fontTextureArr[7], v_uv).rgb;\n } else if(v_fontIndex == 8){\n msdf = texture(fontTextureArr[8], v_uv).rgb;\n } else if(v_fontIndex == 9){\n msdf = texture(fontTextureArr[9], v_uv).rgb;\n } else if(v_fontIndex == 10){\n msdf = texture(fontTextureArr[10], v_uv).rgb;\n }\n return median(msdf.r, msdf.g, msdf.b);\n }\n \n void main () {\n \n if(v_fontIndex == -1) {\n return;\n }\n \n vec4 sdfParams = sdfParamsArr[v_fontIndex];\n float sd = getDistance(); \n vec2 dxdy = fwidth(v_uv) * sdfParams.xy;\n\n if(isOutlinePass == 0){ \n float dist = sd + min(0.001, 0.5 - 1.0 / sdfParams.w) - 0.5;\n float opacity = clamp(dist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0);\n if(opacity <= 0.1){\n discard;\n }\n outScreen = vec4(v_rgba.rgb, opacity * v_rgba.a);\n } else { \n float dist = sd + min(v_outline, 0.5 - 1.0 / sdfParams.w) - 0.5;\n float opacity = clamp(dist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0); \n if(opacity <= 0.1){\n discard;\n }\n outScreen = vec4(v_rgba.rgb, opacity * v_rgba.a);\n //outScreen = v_rgba * strokeAlpha * (0.5 - opacity) * 2.0;\n } \n }"})):this._renderer.handler.addProgram(new Ni("label",{uniforms:{viewport:"vec2",fontTextureArr:"sampler2darray",sdfParamsArr:"vec4",projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",planetRadius:"float",scaleByDistance:"vec3",opacity:"float",isOutlinePass:"int",depthOffset:"float"},attributes:{a_outline:"float",a_gliphParam:"vec4",a_vertices:"vec2",a_texCoord:"vec4",a_positionsHigh:"vec3",a_positionsLow:"vec3",a_size:"float",a_rotation:"float",a_rgba:"vec4",a_offset:"vec3",a_fontIndex:"float"},vertexShader:` \n ${rs}\n \n attribute float a_outline;\n attribute vec4 a_gliphParam;\n attribute vec2 a_vertices;\n attribute vec4 a_texCoord;\n attribute vec3 a_positionsHigh;\n attribute vec3 a_positionsLow;\n attribute vec3 a_offset;\n attribute float a_size;\n attribute float a_rotation;\n attribute vec4 a_rgba;\n attribute float a_fontIndex;\n\n varying float v_outline;\n varying vec2 v_uv;\n varying vec4 v_rgba;\n varying float v_fontIndex; \n\n uniform vec2 viewport;\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float planetRadius;\n uniform vec3 scaleByDistance;\n uniform float opacity;\n uniform float depthOffset;\n\n const vec3 ZERO3 = vec3(0.0);\n\n ${os}\n\n ${as}\n\n void main() {\n\n if(a_texCoord.w == EMPTY) {\n gl_Position = vec4(0.0);\n v_fontIndex = -1.0;\n return;\n }\n \n vec3 a_positions = a_positionsHigh + a_positionsLow;\n vec3 cameraPos = eyePositionHigh + eyePositionLow;\n\n v_outline = a_outline;\n v_uv = vec2(a_texCoord.xy);\n v_rgba = a_rgba;\n v_fontIndex = a_fontIndex;\n \n vec3 look = a_positions - cameraPos;\n float lookDist = length(look);\n \n if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){\n return;\n }\n\n float scd = (1.0 - smoothstep(scaleByDistance[0], scaleByDistance[1], lookDist)) * (1.0 - step(scaleByDistance[2], lookDist));\n\n v_rgba.a *= opacity;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = a_positionsHigh - eyePositionHigh;\n vec3 lowDiff = a_positionsLow - eyePositionLow;\n vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n vec4 projPos = projectionMatrix * posRTE;\n \n float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos)); \n if(camSlope > 0.5) {\n float dist = dot(look, normalize(cameraPos));\n projPos.z += dist * 0.02; \n }else{\n projPos.z += -(abs(projPos.z)) * 0.002; \n }\n \n projPos.z += depthOffset + a_offset.z;\n \n vec2 screenPos = project(projPos);\n \n vec2 vert = a_vertices; \n vec4 gp = a_gliphParam; \n if(a_texCoord.w == RTL){\n vert.x = step(vert.x * 0.5 + 1.0, 1.0);\n gp.x = -a_gliphParam.x;\n gp.z = -(a_gliphParam.z + a_texCoord.z);\n }else{\n gp.z = a_gliphParam.z + a_texCoord.z;\n }\n \n vec2 v = screenPos + rotate2d(a_rotation) * ((vert * gp.xy + gp.zw) * a_size * scd + a_offset.xy);\n \n gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);\n }`,fragmentShader:"#extension GL_OES_standard_derivatives : enable\n\n precision highp float;\n precision highp int;\n\n const int MAX_SIZE = 11;\n\n // x - ATLAS_WIDTH = 512.0;\n // y - ATLAS_HEIGHT = 512.0;\n // z - ATLAS_GLYPH_SIZE = 32.0;\n // w - ATLAS_FIELD_RANGE = 8.0;\n\n uniform sampler2D fontTextureArr[MAX_SIZE];\n uniform vec4 sdfParamsArr[MAX_SIZE];\n uniform int isOutlinePass;\n \n varying float v_outline;\n varying vec2 v_uv;\n varying vec4 v_rgba; \n varying float v_fontIndex;\n \n float fontIndex;\n\n float median(float r, float g, float b) {\n return max(min(r, g), min(max(r, g), b));\n }\n\n float getDistance() {\n vec3 msdf;\n if(fontIndex >= 0.0 && fontIndex < 1.0) {\n msdf = texture2D(fontTextureArr[0], v_uv).rgb;\n } else if(fontIndex >= 1.0 && fontIndex < 2.0){\n msdf = texture2D(fontTextureArr[1], v_uv).rgb;\n } else if(fontIndex >= 2.0 && fontIndex < 3.0){\n msdf = texture2D(fontTextureArr[2], v_uv).rgb;\n } else if(fontIndex >= 3.0 && fontIndex < 4.0){\n msdf = texture2D(fontTextureArr[3], v_uv).rgb;\n } else if(fontIndex >= 4.0 && fontIndex < 5.0){\n msdf = texture2D(fontTextureArr[4], v_uv).rgb;\n } else if(fontIndex >= 5.0 && fontIndex < 6.0){\n msdf = texture2D(fontTextureArr[5], v_uv).rgb;\n } else if(fontIndex >= 6.0 && fontIndex < 7.0){\n msdf = texture2D(fontTextureArr[6], v_uv).rgb;\n } else if(fontIndex >= 7.0 && fontIndex < 8.0){\n msdf = texture2D(fontTextureArr[7], v_uv).rgb;\n } else if(fontIndex >= 8.0 && fontIndex < 9.0){\n msdf = texture2D(fontTextureArr[8], v_uv).rgb;\n } else if(fontIndex >= 9.0 && fontIndex < 10.0){\n msdf = texture2D(fontTextureArr[9], v_uv).rgb;\n } else if(fontIndex >= 10.0 && fontIndex < 11.0){\n msdf = texture2D(fontTextureArr[10], v_uv).rgb;\n }\n return median(msdf.r, msdf.g, msdf.b);\n }\n\n\n vec4 getSDFParams() {\n if(fontIndex >= 0.0 && fontIndex < 1.0) {\n return sdfParamsArr[0];\n } else if(fontIndex >= 1.0 && fontIndex < 2.0){\n return sdfParamsArr[1];\n } else if(fontIndex >= 2.0 && fontIndex < 3.0){\n return sdfParamsArr[2];\n } else if(fontIndex >= 3.0 && fontIndex < 4.0){\n return sdfParamsArr[3];\n } else if(fontIndex >= 4.0 && fontIndex < 5.0){\n return sdfParamsArr[4];\n } else if(fontIndex >= 5.0 && fontIndex < 6.0){\n return sdfParamsArr[5];\n } else if(fontIndex >= 6.0 && fontIndex < 7.0){\n return sdfParamsArr[6];\n } else if(fontIndex >= 7.0 && fontIndex < 8.0){\n return sdfParamsArr[7];\n } else if(fontIndex >= 8.0 && fontIndex < 9.0){\n return sdfParamsArr[8];\n } else if(fontIndex >= 9.0 && fontIndex < 10.0){\n return sdfParamsArr[9];\n } else if(fontIndex >= 10.0 && fontIndex < 11.0){\n return sdfParamsArr[10];\n }\n }\n \n void main () {\n\n fontIndex = v_fontIndex + 0.1;\n \n if(v_fontIndex < 0.0){\n return;\n }\n \n vec4 sdfParams = getSDFParams();\n float sd = getDistance(); \n vec2 dxdy = fwidth(v_uv) * sdfParams.xy;\n float dist = sd + min(0.001, 0.5 - 1.0 / sdfParams.w) - 0.5;\n float opacity = clamp(dist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0);\n\n if(isOutlinePass == 0){ \n //gl_FragColor = vec4(v_rgba.rgb, opacity * v_rgba.a);\n } else { \n float strokeDist = sd + min(v_outline, 0.5 - 1.0 / sdfParams.w) - 0.5;\n float strokeAlpha = v_rgba.a * clamp(strokeDist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0); \n if(strokeAlpha < 0.1){\n discard;\n }\n //gl_FragColor = v_rgba * strokeAlpha * (0.5 - opacity) * 2.0;\n }\n }"}))),this._renderer.handler.programs.labelPicking||this._renderer.handler.addProgram(new Ni("labelPicking",{uniforms:{viewport:"vec2",projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",planetRadius:"float",scaleByDistance:"vec3",opacity:"float",depthOffset:"float"},attributes:{a_gliphParam:"vec4",a_vertices:"vec2",a_texCoord:"vec4",a_positionsHigh:"vec3",a_positionsLow:"vec3",a_offset:"vec3",a_size:"float",a_rotation:"float",a_rgba:"vec4"},vertexShader:`\n \n ${rs}\n \n attribute vec4 a_gliphParam;\n attribute vec2 a_vertices;\n attribute vec4 a_texCoord;\n attribute vec3 a_positionsHigh;\n attribute vec3 a_positionsLow;\n attribute vec3 a_offset;\n attribute float a_size;\n attribute float a_rotation;\n attribute vec4 a_rgba;\n\n varying vec4 v_rgba;\n\n uniform vec2 viewport;\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float planetRadius;\n uniform vec3 scaleByDistance;\n uniform float opacity;\n uniform float depthOffset;\n\n const vec3 ZERO3 = vec3(0.0);\n\n ${os}\n\n ${as}\n\n void main() {\n vec3 a_positions = a_positionsHigh + a_positionsLow;\n vec3 cameraPos = eyePositionHigh + eyePositionLow;\n v_rgba = a_rgba;\n \n if(a_texCoord.w == EMPTY) {\n v_rgba.a = 0.0;\n gl_Position = vec4(0.0);\n return;\n }\n\n vec3 look = a_positions - cameraPos;\n float lookDist = length(look);\n if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){\n return;\n }\n\n float scd = (1.0 - smoothstep(scaleByDistance[0], scaleByDistance[1], lookDist)) * (1.0 - step(scaleByDistance[2], lookDist));\n\n v_rgba.a *= opacity;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = a_positionsHigh - eyePositionHigh;\n vec3 lowDiff = a_positionsLow - eyePositionLow;\n vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n vec4 projPos = projectionMatrix * posRTE;\n \n float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos)); \n if(camSlope > 0.5) {\n float dist = dot(look, normalize(cameraPos));\n projPos.z += dist * 0.02; \n }else{\n projPos.z += -(abs(projPos.z)) * 0.002; \n }\n \n projPos.z += depthOffset + a_offset.z;\n \n vec2 screenPos = project(projPos);\n \n vec2 vert = a_vertices; \n vec4 gp = a_gliphParam; \n if(a_texCoord.w == RTL){\n vert.x = step(vert.x * 0.5 + 1.0, 1.0);\n gp.x = -a_gliphParam.x;\n gp.z = -(a_gliphParam.z + a_texCoord.z);\n }else{\n gp.z = a_gliphParam.z + a_texCoord.z;\n }\n \n vec2 v = screenPos + rotate2d(a_rotation) * ((vert * gp.xy + gp.zw) * a_size * scd + a_offset.xy);\n \n gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);\n }`,fragmentShader:"precision highp float;\n\n varying vec4 v_rgba;\n\n varying vec3 v_pickingColor;\n\n void main () {\n\n vec4 color = v_rgba;\n if (color.a < 0.05) {\n return;\n }\n\n gl_FragColor = vec4(v_rgba.rgb, v_rgba.a);\n }"})))}get labels(){return this._billboards}add(e){e._handler||(e._handler=this,this.assignFontAtlas(e),this.refresh())}updateFonts(){let e=[...this._billboards];this._billboards=[];for(let t=0;t<e.length;t++)this.assignFontAtlas(e[t])}_addLabelToArrays(e){this._renderer&&this._renderer.labelWorker.make({handler:this,label:e})}assignFontAtlas(e){this._entityCollection&&this._renderer?(e.assignFontAtlas(this._renderer.fontAtlas),this._addLabelToArrays(e)):this._billboards.push(e)}workerCallback(e,t){t._lockId!==ii&&t._handler&&this.isEqual(t._handler)&&(t._isReady=!0,t._lockId=ii,t._handlerIndex=this._billboards.length,this._billboards.push(t),this._vertexArr=He(this._vertexArr,e.vertexArr),this._texCoordArr=He(this._texCoordArr,e.texCoordArr),this._gliphParamArr=He(this._gliphParamArr,e.gliphParamArr),this._positionHighArr=He(this._positionHighArr,e.positionHighArr),this._positionLowArr=He(this._positionLowArr,e.positionLowArr),this._sizeArr=He(this._sizeArr,e.sizeArr),this._offsetArr=He(this._offsetArr,e.offsetArr),this._rgbaArr=He(this._rgbaArr,e.rgbaArr),this._rotationArr=He(this._rotationArr,e.rotationArr),this._fontIndexArr=He(this._fontIndexArr,e.fontIndexArr),this._outlineArr=He(this._outlineArr,e.outlineArr),this._outlineColorArr=He(this._outlineColorArr,e.outlineColorArr),this._pickingColorArr=He(this._pickingColorArr,e.pickingColorArr),t.update(),this.refresh())}clear(){this._texCoordArr=null,this._gliphParamArr=null,this._vertexArr=null,this._positionHighArr=null,this._positionLowArr=null,this._sizeArr=null,this._offsetArr=null,this._rgbaArr=null,this._rotationArr=null,this._fontIndexArr=null,this._outlineArr=null,this._outlineColorArr=null,this._texCoordArr=new Float32Array([]),this._gliphParamArr=new Float32Array([]),this._vertexArr=new Float32Array([]),this._positionHighArr=new Float32Array([]),this._positionLowArr=new Float32Array([]),this._sizeArr=new Float32Array([]),this._offsetArr=new Float32Array([]),this._rgbaArr=new Float32Array([]),this._rotationArr=new Float32Array([]),this._fontIndexArr=new Float32Array([]),this._outlineArr=new Float32Array([]),this._outlineColorArr=new Float32Array([]),this._removeBillboards(),this._deleteBuffers(),this.refresh()}_deleteBuffers(){if(this._renderer){let e=this._renderer.handler.gl;e.deleteBuffer(this._gliphParamBuffer),e.deleteBuffer(this._sizeBuffer),e.deleteBuffer(this._fontIndexBuffer),e.deleteBuffer(this._texCoordBuffer),e.deleteBuffer(this._outlineBuffer),e.deleteBuffer(this._outlineColorBuffer),e.deleteBuffer(this._positionHighBuffer),e.deleteBuffer(this._positionLowBuffer),e.deleteBuffer(this._sizeBuffer),e.deleteBuffer(this._offsetBuffer),e.deleteBuffer(this._rgbaBuffer),e.deleteBuffer(this._rotationBuffer),e.deleteBuffer(this._vertexBuffer),e.deleteBuffer(this._texCoordBuffer),e.deleteBuffer(this._pickingColorBuffer),this._gliphParamBuffer=null,this._sizeBuffer=null,this._fontIndexBuffer=null,this._texCoordBuffer=null,this._outlineBuffer=null,this._outlineColorBuffer=null,this._positionHighBuffer=null,this._positionLowBuffer=null,this._sizeBuffer=null,this._offsetBuffer=null,this._rgbaBuffer=null,this._rotationBuffer=null,this._vertexBuffer=null,this._texCoordBuffer=null,this._pickingColorBuffer=null}}_displayPASS(){let e=this._renderer,t=e.handler;t.programs.label.activate();let i=t.programs.label._program,s=i.attributes,n=i.uniforms,r=t.gl,o=this._entityCollection;r.disable(r.CULL_FACE),r.uniform1iv(n.fontTextureArr,e.fontAtlas.samplerArr),r.uniform4fv(n.sdfParamsArr,e.fontAtlas.sdfParamsArr),r.uniformMatrix4fv(n.viewMatrix,!1,e.activeCamera.getViewMatrix()),r.uniformMatrix4fv(n.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),r.uniform3fv(n.eyePositionHigh,e.activeCamera.eyeHigh),r.uniform3fv(n.eyePositionLow,e.activeCamera.eyeLow),r.uniform3fv(n.scaleByDistance,o.scaleByDistance),r.uniform1f(n.opacity,o._fadingOpacity),r.uniform1f(n.planetRadius,o.renderNode._planetRadius2||0),r.uniform2fv(n.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),r.bindBuffer(r.ARRAY_BUFFER,this._texCoordBuffer),r.vertexAttribPointer(s.a_texCoord,this._texCoordBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._gliphParamBuffer),r.vertexAttribPointer(s.a_gliphParam,this._gliphParamBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._vertexBuffer),r.vertexAttribPointer(s.a_vertices,this._vertexBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._positionHighBuffer),r.vertexAttribPointer(s.a_positionsHigh,this._positionHighBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._positionLowBuffer),r.vertexAttribPointer(s.a_positionsLow,this._positionLowBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._sizeBuffer),r.vertexAttribPointer(s.a_size,this._sizeBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._rotationBuffer),r.vertexAttribPointer(s.a_rotation,this._rotationBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._offsetBuffer),r.vertexAttribPointer(s.a_offset,this._offsetBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._fontIndexBuffer),r.vertexAttribPointer(s.a_fontIndex,this._fontIndexBuffer.itemSize,r.FLOAT,!1,0,0),r.uniform1i(n.isOutlinePass,1),r.uniform1f(n.depthOffset,o.polygonOffsetUnits),r.bindBuffer(r.ARRAY_BUFFER,this._outlineColorBuffer),r.vertexAttribPointer(s.a_rgba,this._outlineColorBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._outlineBuffer),r.vertexAttribPointer(s.a_outline,this._outlineBuffer.itemSize,r.FLOAT,!1,0,0),r.drawArrays(r.TRIANGLES,0,this._vertexBuffer.numItems),r.depthFunc(r.EQUAL),r.uniform1i(n.isOutlinePass,0),r.uniform1f(n.depthOffset,o.polygonOffsetUnits),r.bindBuffer(r.ARRAY_BUFFER,this._rgbaBuffer),r.vertexAttribPointer(s.a_rgba,this._rgbaBuffer.itemSize,r.FLOAT,!1,0,0),r.drawArrays(r.TRIANGLES,0,this._vertexBuffer.numItems),r.depthFunc(r.LESS),r.enable(r.CULL_FACE)}_pickingPASS(){let e=this._renderer,t=e.handler;t.programs.labelPicking.activate();let i=t.programs.labelPicking._program,s=i.attributes,n=i.uniforms,r=t.gl,o=this._entityCollection,a=o.renderNode;r.disable(r.CULL_FACE),r.uniformMatrix4fv(n.viewMatrix,!1,e.activeCamera.getViewMatrix()),r.uniformMatrix4fv(n.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),r.uniform3fv(n.eyePositionHigh,e.activeCamera.eyeHigh),r.uniform3fv(n.eyePositionLow,e.activeCamera.eyeLow),r.uniform3fv(n.scaleByDistance,o.scaleByDistance),r.uniform1f(n.opacity,o._fadingOpacity),r.uniform1f(n.planetRadius,a._planetRadius2||0),r.uniform2fv(n.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),r.bindBuffer(r.ARRAY_BUFFER,this._texCoordBuffer),r.vertexAttribPointer(s.a_texCoord,this._texCoordBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._gliphParamBuffer),r.vertexAttribPointer(s.a_gliphParam,this._gliphParamBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._vertexBuffer),r.vertexAttribPointer(s.a_vertices,this._vertexBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._positionHighBuffer),r.vertexAttribPointer(s.a_positionsHigh,this._positionHighBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._positionLowBuffer),r.vertexAttribPointer(s.a_positionsLow,this._positionLowBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._sizeBuffer),r.vertexAttribPointer(s.a_size,this._sizeBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._rotationBuffer),r.vertexAttribPointer(s.a_rotation,this._rotationBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._offsetBuffer),r.vertexAttribPointer(s.a_offset,this._offsetBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._pickingColorBuffer),r.vertexAttribPointer(s.a_rgba,this._pickingColorBuffer.itemSize,r.FLOAT,!1,0,0),r.uniform1f(n.depthOffset,o.polygonOffsetUnits),r.drawArrays(r.TRIANGLES,0,this._vertexBuffer.numItems),r.enable(r.CULL_FACE)}_removeBillboard(e){let t=e._handlerIndex;this._billboards.splice(t,1);let i=24*this._maxLetters,s=t*i;this._rgbaArr=Ye(this._rgbaArr,s,i),this._outlineColorArr=Ye(this._outlineColorArr,s,i),this._texCoordArr=Ye(this._texCoordArr,s,i),this._gliphParamArr=Ye(this._gliphParamArr,s,i),i=18*this._maxLetters,s=t*i,this._positionHighArr=Ye(this._positionHighArr,s,i),this._positionLowArr=Ye(this._positionLowArr,s,i),this._offsetArr=Ye(this._offsetArr,s,i),this._pickingColorArr=Ye(this._pickingColorArr,s,i),i=12*this._maxLetters,s=t*i,this._vertexArr=Ye(this._vertexArr,s,i),i=6*this._maxLetters,s=t*i,this._sizeArr=Ye(this._sizeArr,s,i),this._rotationArr=Ye(this._rotationArr,s,i),this._fontIndexArr=Ye(this._fontIndexArr,s,i),this._outlineArr=Ye(this._outlineArr,s,i),this.reindexBillboardsArray(t),this.refresh(),e._handlerIndex=-1,e._handler=null,e._isReady=!1}setText(e,t,i,s,n=0,r=!1){t=t.normalize("NFKC");let o=this._renderer.fontAtlas.atlasesArr[i];if(!o)return;let a=24*e*this._maxLetters,l=this._texCoordArr,h=this._gliphParamArr,c=0,d=Math.min(this._maxLetters,t.length),_=0;r&&(_=1);let u=0,g=o.kernings;for(c=0;c<d;c++){let e=a+24*c,i=t[c],s=o.get(i.charCodeAt(0))||o.get(" ".charCodeAt(0));if(!s)continue;let r=s.texCoords,d=s.metrics;l[e]=r[0],l[e+1]=r[1],l[e+2]=u,l[e+3]=_,l[e+4]=r[2],l[e+5]=r[3],l[e+6]=u,l[e+7]=_,l[e+8]=r[4],l[e+9]=r[5],l[e+10]=u,l[e+11]=_,l[e+12]=r[6],l[e+13]=r[7],l[e+14]=u,l[e+15]=_,l[e+16]=r[8],l[e+17]=r[9],l[e+18]=u,l[e+19]=_,l[e+20]=r[10],l[e+21]=r[11],l[e+22]=u,l[e+23]=_,h[e]=d.nWidth,h[e+1]=d.nHeight,h[e+2]=d.nXOffset,h[e+3]=d.nYOffset,h[e+4]=d.nWidth,h[e+5]=d.nHeight,h[e+6]=d.nXOffset,h[e+7]=d.nYOffset,h[e+8]=d.nWidth,h[e+9]=d.nHeight,h[e+10]=d.nXOffset,h[e+11]=d.nYOffset,h[e+12]=d.nWidth,h[e+13]=d.nHeight,h[e+14]=d.nXOffset,h[e+15]=d.nYOffset,h[e+16]=d.nWidth,h[e+17]=d.nHeight,h[e+18]=d.nXOffset,h[e+19]=d.nYOffset,h[e+20]=d.nWidth,h[e+21]=d.nHeight,h[e+22]=d.nXOffset,h[e+23]=d.nYOffset;let f=g[i.charCodeAt(0)];if(f&&t[c+1]){let e=f[t[c+1].charCodeAt(0)];u+=e?d.nAdvance+e+n:d.nAdvance+n}else u+=d.nAdvance+n}if(s===xi.CENTER)for(u*=-.5,c=0;c<d;c++){let e=a+24*c;l[e+2]+=u,l[e+6]+=u,l[e+10]+=u,l[e+14]+=u,l[e+18]+=u,l[e+22]+=u}for(;c<this._maxLetters;c++){let e=a+24*c;l[e+3]=ls,l[e+7]=ls,l[e+11]=ls,l[e+15]=ls,l[e+19]=ls,l[e+23]=ls}this._changedBuffers[6]=!0}setPositionArr(e,t,i){let s=18*e*this._maxLetters,n=this._positionHighArr,r=t.x,o=t.y,a=t.z,l=this._positionLowArr,h=i.x,c=i.y,d=i.z;for(let e=0;e<this._maxLetters;e++){let t=s+18*e;n[t]=r,n[t+1]=o,n[t+2]=a,n[t+3]=r,n[t+4]=o,n[t+5]=a,n[t+6]=r,n[t+7]=o,n[t+8]=a,n[t+9]=r,n[t+10]=o,n[t+11]=a,n[t+12]=r,n[t+13]=o,n[t+14]=a,n[t+15]=r,n[t+16]=o,n[t+17]=a,l[t]=h,l[t+1]=c,l[t+2]=d,l[t+3]=h,l[t+4]=c,l[t+5]=d,l[t+6]=h,l[t+7]=c,l[t+8]=d,l[t+9]=h,l[t+10]=c,l[t+11]=d,l[t+12]=h,l[t+13]=c,l[t+14]=d,l[t+15]=h,l[t+16]=c,l[t+17]=d}this._changedBuffers[1]=!0}setPickingColorArr(e,t){let i=18*e*this._maxLetters,s=this._pickingColorArr,n=t.x/255,r=t.y/255,o=t.z/255;for(let e=0;e<this._maxLetters;e++){let t=i+18*e;s[t]=n,s[t+1]=r,s[t+2]=o,s[t+3]=n,s[t+4]=r,s[t+5]=o,s[t+6]=n,s[t+7]=r,s[t+8]=o,s[t+9]=n,s[t+10]=r,s[t+11]=o,s[t+12]=n,s[t+13]=r,s[t+14]=o,s[t+15]=n,s[t+16]=r,s[t+17]=o}this._changedBuffers[0]=!0}setSizeArr(e,t){let i=6*e*this._maxLetters,s=this._sizeArr;for(let e=0;e<this._maxLetters;e++){let n=i+6*e;s[n]=t,s[n+1]=t,s[n+2]=t,s[n+3]=t,s[n+4]=t,s[n+5]=t}this._changedBuffers[2]=!0}setOffsetArr(e,t){let i=18*e*this._maxLetters,s=this._offsetArr,n=t.x,r=t.y,o=t.z;for(let e=0;e<this._maxLetters;e++){let t=i+18*e;s[t]=n,s[t+1]=r,s[t+2]=o,s[t+3]=n,s[t+4]=r,s[t+5]=o,s[t+6]=n,s[t+7]=r,s[t+8]=o,s[t+9]=n,s[t+10]=r,s[t+11]=o,s[t+12]=n,s[t+13]=r,s[t+14]=o,s[t+15]=n,s[t+16]=r,s[t+17]=o}this._changedBuffers[3]=!0}setRgbaArr(e,t){let i=24*e*this._maxLetters,s=this._rgbaArr,n=t.x,r=t.y,o=t.z,a=t.w;for(let e=0;e<this._maxLetters;e++){let t=i+24*e;s[t]=n,s[t+1]=r,s[t+2]=o,s[t+3]=a,s[t+4]=n,s[t+5]=r,s[t+6]=o,s[t+7]=a,s[t+8]=n,s[t+9]=r,s[t+10]=o,s[t+11]=a,s[t+12]=n,s[t+13]=r,s[t+14]=o,s[t+15]=a,s[t+16]=n,s[t+17]=r,s[t+18]=o,s[t+19]=a,s[t+20]=n,s[t+21]=r,s[t+22]=o,s[t+23]=a}this._changedBuffers[4]=!0}setOutlineColorArr(e,t){let i=24*e*this._maxLetters,s=this._outlineColorArr,n=t.x,r=t.y,o=t.z,a=t.w;for(let e=0;e<this._maxLetters;e++){let t=i+24*e;s[t]=n,s[t+1]=r,s[t+2]=o,s[t+3]=a,s[t+4]=n,s[t+5]=r,s[t+6]=o,s[t+7]=a,s[t+8]=n,s[t+9]=r,s[t+10]=o,s[t+11]=a,s[t+12]=n,s[t+13]=r,s[t+14]=o,s[t+15]=a,s[t+16]=n,s[t+17]=r,s[t+18]=o,s[t+19]=a,s[t+20]=n,s[t+21]=r,s[t+22]=o,s[t+23]=a}this._changedBuffers[10]=!0}setOutlineArr(e,t){let i=6*e*this._maxLetters,s=this._outlineArr;for(let e=0;e<this._maxLetters;e++){let n=i+6*e;s[n]=t,s[n+1]=t,s[n+2]=t,s[n+3]=t,s[n+4]=t,s[n+5]=t}this._changedBuffers[9]=!0}setRotationArr(e,t){let i=6*e*this._maxLetters,s=this._rotationArr;for(let e=0;e<this._maxLetters;e++){let n=i+6*e;s[n]=t,s[n+1]=t,s[n+2]=t,s[n+3]=t,s[n+4]=t,s[n+5]=t}this._changedBuffers[5]=!0}setVisibility(e,t){let i;i=t?[0,0,0,-1,1,-1,1,-1,1,0,0,0]:[0,0,0,0,0,0,0,0,0,0,0,0],this.setVertexArr(e,i)}setVertexArr(e,t){let i=12*e*this._maxLetters,s=this._vertexArr;for(let e=0;e<this._maxLetters;e++){let n=i+12*e;s[n]=t[0],s[n+1]=t[1],s[n+2]=t[2],s[n+3]=t[3],s[n+4]=t[4],s[n+5]=t[5],s[n+6]=t[6],s[n+7]=t[7],s[n+8]=t[8],s[n+9]=t[9],s[n+10]=t[10],s[n+11]=t[11]}this._changedBuffers[7]=!0}setFontIndexArr(e,t){let i=6*e*this._maxLetters,s=this._fontIndexArr;for(let e=0;e<this._maxLetters;e++){let n=i+6*e;s[n]=t,s[n+1]=t,s[n+2]=t,s[n+3]=t,s[n+4]=t,s[n+5]=t}this._changedBuffers[8]=!0}createSizeBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._sizeBuffer),this._sizeBuffer=e.createArrayBuffer(this._sizeArr,1,this._sizeArr.length)}createFontIndexBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._fontIndexBuffer),this._fontIndexBuffer=e.createArrayBuffer(this._fontIndexArr,1,this._fontIndexArr.length)}createTexCoordBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._texCoordBuffer),this._texCoordBuffer=e.createArrayBuffer(this._texCoordArr,4,this._texCoordArr.length/4),e.gl.deleteBuffer(this._gliphParamBuffer),this._gliphParamBuffer=e.createArrayBuffer(this._gliphParamArr,4,this._gliphParamArr.length/4)}createOutlineBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._outlineBuffer),this._outlineBuffer=e.createArrayBuffer(this._outlineArr,1,this._outlineArr.length)}createOutlineColorBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._outlineColorBuffer),this._outlineColorBuffer=e.createArrayBuffer(this._outlineColorArr,4,this._outlineColorArr.length/4)}setMaxLetters(e){this._maxLetters=e}}class cs{constructor(e){this.pickingEnabled=!0,this.__id=cs.__counter__++,this.pickingEnabled=!0,this._entityCollection=e,this._renderer=null,this._pointClouds=[]}_initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.pointCloud||this._renderer.handler.addProgram(new Ni("pointCloud",{uniforms:{projectionViewMatrix:"mat4",opacity:"float",pointSize:"float"},attributes:{coordinates:"vec3",colors:"vec3"},vertexShader:"attribute vec3 coordinates;\n attribute vec4 colors;\n uniform mat4 projectionViewMatrix;\n uniform float opacity;\n uniform float pointSize;\n varying vec4 color;\n void main() {\n color = colors;\n color.a *= opacity;\n gl_Position = projectionViewMatrix * vec4(coordinates, 1.0);\n gl_PointSize = pointSize;\n }",fragmentShader:"precision highp float;\n varying vec4 color;\n void main(void) {\n gl_FragColor = color;\n }"})))}setRenderNode(e){this._renderer=e.renderer,this._initProgram();for(let t=0;t<this._pointClouds.length;t++)this._pointClouds[t].setRenderNode(e)}add(e){-1===e._handlerIndex&&(e._handler=this,e._handlerIndex=this._pointClouds.length,this._pointClouds.push(e),this._entityCollection&&this._entityCollection.renderNode&&e.setRenderNode(this._entityCollection.renderNode))}remove(e){let t=e._handlerIndex;-1!==t&&(e._deleteBuffers(),e._handlerIndex=-1,e._handler=null,this._pointClouds.splice(t,1),this._reindexPointCloudArray(t))}_reindexPointCloudArray(e){let t=this._pointClouds;for(let i=e;i<t.length;i++)t[i]._handlerIndex=i}draw(){let e=this._pointClouds.length;for(;e--;)this._pointClouds[e].draw()}drawPicking(){if(this.pickingEnabled){let e=this._pointClouds.length;for(;e--;)this._pointClouds[e].drawPicking()}}clear(){let e=this._pointClouds.length;for(;e--;)this._pointClouds[e]._deleteBuffers(),this._pointClouds[e]._handler=null,this._pointClouds[e]._handlerIndex=-1;this._pointClouds.length=0,this._pointClouds=[]}}cs.__counter__=0;const ds="\n float getLerpValue(in float min, in float max, in float between)\n {\n return (clamp(between, min, max) - min) / (max - min);\n }\n \n vec3 aces(vec3 color) \n {\n float a = 2.51;\n float b = 0.03;\n float c = 2.43;\n float d = 0.59;\n float e = 0.14;\n return clamp((color * (a * color + b)) / (color * (c * color + d ) + e), 0.0, 1.0);\n }\n \n bool intersectSphere(vec3 rayOrigin, vec3 rayDirection, float radius, inout float t1, inout float t2) \n {\n float b = dot(rayDirection, rayOrigin);\n float c = dot(rayOrigin, rayOrigin) - radius * radius;\n float d = b * b - c;\n if (d < 0.0) {\n return false;\n }\n t1 = -b - sqrt(d);\n t2 = -b + sqrt(d);\n return true;\n }\n \n bool intersectSphere(vec3 rayOrigin, vec3 rayDirection, float radius, inout float t) \n {\n float b = dot(rayDirection, rayOrigin);\n float c = dot(rayOrigin, rayOrigin) - radius * radius;\n float d = b * b - c;\n if (d < 0.0) {\n return false;\n }\n t = -b - sqrt(d);\n return true;\n }\n \n float intersectSphere( vec3 ro, vec3 rd, vec4 sph )\n {\n vec3 oc = ro - sph.xyz;\n float b = dot( oc, rd );\n float c = dot( oc, oc ) - sph.w*sph.w;\n float h = b*b - c;\n if( h<0.0 ) return -1.0;\n h = sqrt( h );\n return -b - h;\n }\n \n bool intersectEllipsoid( in vec3 ro, in vec3 rd, in vec3 ra, inout float t )\n {\n vec3 ocn = ro/ra;\n vec3 rdn = rd/ra;\n float a = dot( rdn, rdn );\n float b = dot( ocn, rdn );\n float c = dot( ocn, ocn );\n float h = b*b - a*(c-1.0);\n \n if (h < 0.0) \n { \n return false; \n }\n \n t = (-b-sqrt(h))/a;\n \n return true;\n }\n \n bool intersectEllipsoid( in vec3 ro, in vec3 rd, in vec3 ra, inout float t1, inout float t2)\n {\n vec3 ocn = ro/ra;\n vec3 rdn = rd/ra;\n float a = dot( rdn, rdn );\n float b = dot( ocn, rdn );\n float c = dot( ocn, ocn );\n float h = b*b - a*(c-1.0);\n \n if (h < 0.0) \n { \n return false; \n }\n \n h = sqrt(h);\n t1 = (-b-h)/a;\n t2 = (-b+h)/a;\n \n return true;\n }\n \n vec3 normalEllipsoid( in vec3 pos, in vec3 ra )\n {\n return normalize( pos/(ra*ra) );\n }\n";class _s{constructor(e){this.__id=_s.__counter__++,this._entityCollection=e,this._renderer=null,this._polylines=[],this.pickingEnabled=!0,this._relativeCenter=new oe,this._rtcEyePositionHigh=new Float32Array([0,0,0]),this._rtcEyePositionLow=new Float32Array([0,0,0])}_initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.polyline_screen||this._renderer.handler.addProgram(new Ni("polyline_screen",{uniforms:{viewport:"vec2",proj:"mat4",view:"mat4",rtcEyePositionHigh:"vec3",rtcEyePositionLow:"vec3",thickness:"float",opacity:"float",depthOffset:"float",visibleSphere:"vec4"},attributes:{prevHigh:"vec3",currentHigh:"vec3",nextHigh:"vec3",prevLow:"vec3",currentLow:"vec3",nextLow:"vec3",order:"float",color:"vec4"},vertexShader:"precision highp float;\n\n attribute vec3 prevHigh;\n attribute vec3 currentHigh;\n attribute vec3 nextHigh;\n\n attribute vec3 prevLow;\n attribute vec3 currentLow;\n attribute vec3 nextLow;\n\n attribute float order;\n\n attribute vec4 color;\n\n uniform float thickness;\n uniform mat4 proj;\n uniform mat4 view;\n uniform vec2 viewport;\n uniform vec3 rtcEyePositionHigh;\n uniform vec3 rtcEyePositionLow;\n uniform float opacity;\n uniform float depthOffset;\n \n\n varying vec4 vColor;\n varying vec3 vPos;\n varying vec3 uCamPos;\n\n const float NEAR = -1.0;\n\n vec2 getIntersection(vec2 start1, vec2 end1, vec2 start2, vec2 end2){\n vec2 dir = end2 - start2;\n vec2 perp = vec2(-dir.y, dir.x);\n float d2 = dot(perp, start2);\n float seg = dot(perp, start1) - d2;\n float prl = seg - dot(perp, end1) + d2;\n if(prl > -1.0 && prl < 1.0){\n return start1;\n }\n float u = seg / prl;\n return start1 + u * (end1 - start1);\n }\n\n vec2 project(vec4 p){\n return (0.5 * p.xyz / p.w + 0.5).xy * viewport;\n }\n\n void main(){\n\n uCamPos = rtcEyePositionHigh + rtcEyePositionLow;\n vPos = currentHigh + currentLow;\n \n vColor = vec4(color.rgb, color.a * opacity);\n\n mat4 viewMatrixRTE = view;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff, lowDiff;\n\n highDiff = currentHigh - rtcEyePositionHigh;\n highDiff = highDiff * step(1.0, length(highDiff));\n lowDiff = currentLow - rtcEyePositionLow; \n vec4 vCurrent = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n highDiff = prevHigh - rtcEyePositionHigh;\n highDiff = highDiff * step(1.0, length(highDiff));\n lowDiff = prevLow - rtcEyePositionLow;\n vec4 vPrev = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n highDiff = nextHigh - rtcEyePositionHigh;\n highDiff = highDiff * step(1.0, length(highDiff));\n lowDiff = nextLow - rtcEyePositionLow;\n vec4 vNext = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n /*Clip near plane, the point behind view plane*/\n if(vCurrent.z > NEAR) {\n if(vPrev.z < NEAR && abs(order) == 1.0){\n vCurrent = vPrev + (vCurrent - vPrev) * (NEAR - vPrev.z) / (vCurrent.z - vPrev.z);\n } else if(vNext.z < NEAR && abs(order) == 2.0){\n vCurrent = vNext + (vCurrent - vNext) * (NEAR - vNext.z) / (vCurrent.z - vNext.z);\n }\n }\n\n vec4 dCurrent = proj * vCurrent;\n vec2 _next = project(proj * vNext);\n vec2 _prev = project(proj * vPrev);\n vec2 _current = project(dCurrent);\n\n if(_prev == _current){\n if(_next == _current){\n _next = _current + vec2(1.0, 0.0);\n _prev = _current - _next;\n }else{\n _prev = _current + normalize(_current - _next);\n }\n }\n\n if(_next == _current){\n _next = _current + normalize(_current - _prev);\n }\n\n vec2 sNext = _next,\n sCurrent = _current,\n sPrev = _prev;\n\n vec2 dirNext = normalize(sNext - sCurrent);\n vec2 dirPrev = normalize(sPrev - sCurrent);\n float dotNP = dot(dirNext, dirPrev);\n\n vec2 normalNext = normalize(vec2(-dirNext.y, dirNext.x));\n vec2 normalPrev = normalize(vec2(dirPrev.y, -dirPrev.x));\n\n float d = thickness * sign(order);\n\n vec2 m;\n if(dotNP >= 0.99991){\n m = sCurrent - normalPrev * d;\n }else{\n m = getIntersection( sCurrent + normalPrev * d, sPrev + normalPrev * d,\n sCurrent + normalNext * d, sNext + normalNext * d );\n\n if( dotNP > 0.5 && dot(dirNext + dirPrev, m - sCurrent) < 0.0 ){\n float occw = order * sign(dirNext.x * dirPrev.y - dirNext.y * dirPrev.x);\n if(occw == -1.0){\n m = sCurrent + normalPrev * d;\n }else if(occw == 1.0){\n m = sCurrent + normalNext * d;\n }else if(occw == -2.0){\n m = sCurrent + normalNext * d;\n }else if(occw == 2.0){\n m = sCurrent + normalPrev * d;\n }\n }else if(distance(sCurrent, m) > min(distance(sCurrent, sNext), distance(sCurrent, sPrev))){\n m = sCurrent + normalNext * d;\n }\n }\n\n gl_Position = vec4((2.0 * m / viewport - 1.0) * dCurrent.w, dCurrent.z + depthOffset, dCurrent.w);\n }",fragmentShader:`precision highp float;\n \n uniform vec4 visibleSphere;\n \n varying vec3 uCamPos;\n varying vec4 vColor;\n varying vec3 vPos; \n \n ${ds}\n \n void main() {\n \n if(visibleSphere.w != 0.0) { \n vec3 cam_dir = normalize(vPos - uCamPos);\n vec3 sph_dir = normalize(vPos - visibleSphere.xyz);\n if( dot(cam_dir, sph_dir) > 0.11 ){\n discard;\n }\n }\n \n gl_FragColor = vec4(vColor.rgb, vColor.a);\n }`})),this._renderer.handler.programs.polyline_picking||this._renderer.handler.addProgram(new Ni("polyline_picking",{uniforms:{viewport:"vec2",proj:"mat4",view:"mat4",rtcEyePositionHigh:"vec3",rtcEyePositionLow:"vec3",color:"vec4",thickness:"float",depthOffset:"float",visibleSphere:"vec4"},attributes:{prevHigh:"vec3",currentHigh:"vec3",nextHigh:"vec3",prevLow:"vec3",currentLow:"vec3",nextLow:"vec3",order:"float"},vertexShader:"precision highp float;\n \n attribute vec3 prevHigh;\n attribute vec3 currentHigh;\n attribute vec3 nextHigh;\n \n attribute vec3 prevLow;\n attribute vec3 currentLow;\n attribute vec3 nextLow;\n\n attribute float order;\n\n uniform float thickness;\n uniform vec4 color;\n uniform mat4 proj;\n uniform mat4 view;\n uniform vec2 viewport;\n uniform vec3 rtcEyePositionHigh;\n uniform vec3 rtcEyePositionLow;\n uniform float depthOffset;\n\n varying vec4 vColor;\n varying vec3 vPos;\n varying vec3 uCamPos;\n \n \n const float NEAR = -1.0;\n \n vec2 getIntersection(vec2 start1, vec2 end1, vec2 start2, vec2 end2){\n vec2 dir = end2 - start2;\n vec2 perp = vec2(-dir.y, dir.x);\n float d2 = dot(perp, start2);\n float seg = dot(perp, start1) - d2;\n float prl = seg - dot(perp, end1) + d2;\n if(prl > -1.0 && prl < 1.0){\n return start1;\n }\n float u = seg / prl;\n return start1 + u * (end1 - start1);\n }\n \n vec2 project(vec4 p){\n return (0.5 * p.xyz / p.w + 0.5).xy * viewport;\n }\n \n void main(){\n\n uCamPos = rtcEyePositionHigh + rtcEyePositionLow;\n vPos = currentHigh + currentLow;\n vColor = color; \n\n vec3 highDiff, lowDiff;\n\n mat4 viewMatrixRTE = view;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n \n highDiff = currentHigh - rtcEyePositionHigh;\n highDiff = highDiff * step(1.0, length(highDiff));\n lowDiff = currentLow - rtcEyePositionLow;\n vec4 vCurrent = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n highDiff = prevHigh - rtcEyePositionHigh;\n highDiff = highDiff * step(1.0, length(highDiff));\n lowDiff = prevLow - rtcEyePositionLow; \n vec4 vPrev = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n highDiff = nextHigh - rtcEyePositionHigh;\n highDiff = highDiff * step(1.0, length(highDiff));\n lowDiff = nextLow - rtcEyePositionLow; \n vec4 vNext = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n /*Clip near plane*/\n if(vCurrent.z > NEAR) {\n if(vPrev.z < NEAR && abs(order) == 1.0){\n vCurrent = vPrev + (vCurrent - vPrev) * (NEAR - vPrev.z) / (vCurrent.z - vPrev.z);\n } else if(vNext.z < NEAR && abs(order) == 2.0){\n vCurrent = vNext + (vCurrent - vNext) * (NEAR - vNext.z) / (vCurrent.z - vNext.z);\n }\n }\n \n vec4 dCurrent = proj * vCurrent;\n vec2 _next = project(proj * vNext);\n vec2 _prev = project(proj * vPrev);\n vec2 _current = project(dCurrent);\n if(_prev == _current){\n if(_next == _current){\n _next = _current + vec2(1.0, 0.0);\n _prev = _current - _next;\n }else{\n _prev = _current + normalize(_current - _next);\n }\n }\n if(_next == _current){\n _next = _current + normalize(_current - _prev);\n }\n \n vec2 sNext = _next,\n sCurrent = _current,\n sPrev = _prev;\n\n vec2 dirNext = normalize(sNext - sCurrent);\n vec2 dirPrev = normalize(sPrev - sCurrent);\n float dotNP = dot(dirNext, dirPrev);\n \n vec2 normalNext = normalize(vec2(-dirNext.y, dirNext.x));\n vec2 normalPrev = normalize(vec2(dirPrev.y, -dirPrev.x));\n \n float d = thickness * sign(order);\n \n vec2 m;\n if(dotNP >= 0.99991){\n m = sCurrent - normalPrev * d;\n }else{\n m = getIntersection( sCurrent + normalPrev * d, sPrev + normalPrev * d,\n sCurrent + normalNext * d, sNext + normalNext * d );\n \n if( dotNP > 0.5 && dot(dirNext + dirPrev, m - sCurrent) < 0.0 ){\n float occw = order * sign(dirNext.x * dirPrev.y - dirNext.y * dirPrev.x);\n if(occw == -1.0){\n m = sCurrent + normalPrev * d;\n }else if(occw == 1.0){\n m = sCurrent + normalNext * d;\n }else if(occw == -2.0){\n m = sCurrent + normalNext * d;\n }else if(occw == 2.0){\n m = sCurrent + normalPrev * d;\n }\n }\n else if(distance(sCurrent, m) > min(distance(sCurrent, sNext), distance(sCurrent, sPrev))){\n m = sCurrent + normalNext * d;\n }\n }\n gl_Position = vec4((2.0 * m / viewport - 1.0) * dCurrent.w, dCurrent.z + depthOffset, dCurrent.w);\n }",fragmentShader:"precision highp float;\n \n uniform vec4 visibleSphere;\n \n varying vec3 uCamPos;\n varying vec4 vColor;\n varying vec3 vPos;\n \n void main() {\n if(visibleSphere.w != 0.0) { \n vec3 cam_dir = normalize(vPos - uCamPos);\n vec3 sph_dir = normalize(vPos - visibleSphere.xyz);\n if( dot(cam_dir, sph_dir) > 0.11 ){\n discard;\n }\n } \n gl_FragColor = vec4(vColor.rgb, vColor.a);\n }"})))}setRenderNode(e){this._renderer=e.renderer,this._initProgram();for(let t=0;t<this._polylines.length;t++)this._polylines[t].setRenderNode(e)}add(e){-1===e._handlerIndex&&(e._handler=this,e._handlerIndex=this._polylines.length,e.__doubleToTwoFloats=this.getRTCPosition.bind(this),this._polylines.push(e),this._entityCollection&&this._entityCollection.renderNode&&(e.setRenderNode(this._entityCollection.renderNode),e.updateRTCPosition()))}remove(e){let t=e._handlerIndex;-1!==t&&(e._deleteBuffers(),e._handlerIndex=-1,e._handler=null,this._polylines.splice(t,1),this.reindexPolylineArray(t))}reindexPolylineArray(e){let t=this._polylines;for(let i=e;i<t.length;i++)t[i]._handlerIndex=i}draw(){this._updateRTCEyePosition();let e=this._polylines.length;for(;e--;)this._polylines[e].draw()}drawPicking(){if(this.pickingEnabled){let e=this._polylines.length;for(;e--;)this._polylines[e].drawPicking()}}clear(){let e=this._polylines.length;for(;e--;)this._polylines[e]._deleteBuffers(),this._polylines[e]._handler=null,this._polylines[e]._handlerIndex=-1;this._polylines.length=0,this._polylines=[]}getRTCPosition(e,t,i){let s=e.sub(this._relativeCenter);oe.doubleToTwoFloats(s,t,i)}setRelativeCenter(e){this._relativeCenter.copy(e);for(let e=0;e<this._polylines.length;e++)this._polylines[e].updateRTCPosition()}_updateRTCEyePosition(){let e=this._renderer;if(e.activeCamera.isFirstPass){let t=e.activeCamera.eye.sub(this._relativeCenter);oe.doubleToTwoFloat32Array(t,this._rtcEyePositionHigh,this._rtcEyePositionLow)}}}_s.__counter__=0;class us{constructor(e){this.__id=us.__counter__++,this.pickingEnabled=!0,this._entityCollection=e,this._renderer=null,this._rays=[],this._vertexBuffer=null,this._startPositionHighBuffer=null,this._startPositionLowBuffer=null,this._endPositionHighBuffer=null,this._endPositionLowBuffer=null,this._thicknessBuffer=null,this._rgbaBuffer=null,this._pickingColorBuffer=null,this._vertexArr=[],this._startPositionHighArr=[],this._startPositionLowArr=[],this._endPositionHighArr=[],this._endPositionLowArr=[],this._thicknessArr=[],this._rgbaArr=[],this._pickingColorArr=[],this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[5]=this.createVertexBuffer,this._buffersUpdateCallbacks[1]=this.createStartPositionBuffer,this._buffersUpdateCallbacks[2]=this.createEndPositionBuffer,this._buffersUpdateCallbacks[4]=this.createThicknessBuffer,this._buffersUpdateCallbacks[3]=this.createRgbaBuffer,this._buffersUpdateCallbacks[0]=this.createPickingColorBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length)}static concArr(e,t){for(let i=0;i<t.length;i++)e.push(t[i])}initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.rayScreen||this._renderer.handler.addProgram(new Ni("rayScreen",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",resolution:"float",uOpacity:"float"},attributes:{a_vertices:"vec2",a_startPosHigh:"vec3",a_startPosLow:"vec3",a_endPosHigh:"vec3",a_endPosLow:"vec3",a_thickness:"float",a_rgba:"vec4"},vertexShader:"precision highp float;\n\n attribute vec4 a_rgba;\n attribute vec3 a_startPosHigh;\n attribute vec3 a_startPosLow;\n attribute vec3 a_endPosHigh;\n attribute vec3 a_endPosLow;\n attribute vec2 a_vertices;\n attribute float a_thickness;\n\n varying vec4 v_rgba;\n\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float resolution;\n uniform float uOpacity;\n\n void main() {\n\n v_rgba = vec4(a_rgba.rgb, a_rgba.a * uOpacity);\n\n vec3 v = (a_endPosHigh - a_startPosHigh) + (a_endPosLow - a_startPosLow);\n\n vec3 look = (a_startPosHigh - eyePositionHigh) + (a_startPosLow - eyePositionLow) + v * a_vertices.y;\n vec3 up = normalize(normalize(v));\n vec3 right = normalize(cross(look,up));\n \n float dist = dot(look, vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]));\n float focalSize = 2.0 * dist * resolution;\n vec3 vert = right * a_thickness * focalSize * a_vertices.x;\n\n vec3 highDiff;\n if(a_vertices.y == 0.0){\n highDiff = a_startPosHigh - eyePositionHigh;\n vert += a_startPosLow - eyePositionLow;\n }else{\n highDiff = a_endPosHigh - eyePositionHigh;\n vert += a_endPosLow - eyePositionLow;\n }\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n \n // Hack for iMac M1, looks like it doesnt \n // work correctly with zeroes in highDiff\n // if(length(highDiff) < 1.0){\n // highDiff = vec3(0.0);\n // }\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + vert, 1.0);\n }",fragmentShader:"precision highp float;\n varying vec4 v_rgba;\n void main () {\n gl_FragColor = v_rgba;\n }"})))}setRenderer(e){this._renderer=e,this.initProgram()}refresh(){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]=!0}_removeRays(){let e=this._rays.length;for(;e--;){let t=this._rays[e];t._handlerIndex=-1,t._handler=null}this._rays.length=0,this._rays=[]}clear(){this._vertexArr=null,this._startPositionHighArr=null,this._startPositionLowArr=null,this._endPositionHighArr=null,this._endPositionLowArr=null,this._thicknessArr=null,this._rgbaArr=null,this._vertexArr=new Float32Array([]),this._startPositionHighArr=new Float32Array([]),this._startPositionLowArr=new Float32Array([]),this._endPositionHighArr=new Float32Array([]),this._endPositionLowArr=new Float32Array([]),this._thicknessArr=new Float32Array([]),this._rgbaArr=new Float32Array([]),this._removeRays(),this._deleteBuffers(),this.refresh()}_deleteBuffers(){if(this._renderer){let e=this._renderer.handler.gl;e&&(e.deleteBuffer(this._startPositionHighBuffer),e.deleteBuffer(this._startPositionLowBuffer),e.deleteBuffer(this._endPositionHighBuffer),e.deleteBuffer(this._endPositionLowBuffer),e.deleteBuffer(this._thicknessBuffer),e.deleteBuffer(this._rgbaBuffer),e.deleteBuffer(this._vertexBuffer)),this._startPositionHighBuffer=null,this._startPositionLowBuffer=null,this._endPositionHighBuffer=null,this._endPositionLowBuffer=null,this._thicknessBuffer=null,this._rgbaBuffer=null,this._vertexBuffer=null}}update(){if(this._renderer){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1)}}add(e){-1==e._handlerIndex&&(e._handler=this,e._handlerIndex=this._rays.length,this._rays.push(e),this._addRayToArrays(e),this.refresh())}_addRayToArrays(e){e.getVisibility()?this._vertexArr=Oe(this._vertexArr,[-.5,1,-.5,0,.5,0,.5,0,.5,1,-.5,1]):this._vertexArr=Oe(this._vertexArr,[0,0,0,0,0,0,0,0,0,0,0,0]);let t=e._startPositionHigh.x,i=e._startPositionHigh.y,s=e._startPositionHigh.z;this._startPositionHighArr=Oe(this._startPositionHighArr,[t,i,s,t,i,s,t,i,s,t,i,s,t,i,s,t,i,s]),t=e._startPositionLow.x,i=e._startPositionLow.y,s=e._startPositionLow.z,this._startPositionLowArr=Oe(this._startPositionLowArr,[t,i,s,t,i,s,t,i,s,t,i,s,t,i,s,t,i,s]),t=e._endPositionHigh.x,i=e._endPositionHigh.y,s=e._endPositionHigh.z,this._endPositionHighArr=Oe(this._endPositionHighArr,[t,i,s,t,i,s,t,i,s,t,i,s,t,i,s,t,i,s]),t=e._endPositionLow.x,i=e._endPositionLow.y,s=e._endPositionLow.z,this._endPositionLowArr=Oe(this._endPositionLowArr,[t,i,s,t,i,s,t,i,s,t,i,s,t,i,s,t,i,s]),t=e._thickness,this._thicknessArr=Oe(this._thicknessArr,[t,t,t,t,t,t]);let n=e._startColor.x,r=e._startColor.y,o=e._startColor.z,a=e._startColor.w,l=e._endColor.x,h=e._endColor.y,c=e._endColor.z,d=e._endColor.w;this._rgbaArr=Oe(this._rgbaArr,[l,h,c,d,n,r,o,a,n,r,o,a,n,r,o,a,l,h,c,d,l,h,c,d]),t=e._entity._pickingColor.x/255,i=e._entity._pickingColor.y/255,s=e._entity._pickingColor.z/255,this._pickingColorArr=Oe(this._pickingColorArr,[t,i,s,t,i,s,t,i,s,t,i,s,t,i,s,t,i,s])}_displayPASS(){let e=this._renderer,t=e.handler;t.programs.rayScreen.activate();let i=t.programs.rayScreen._program,s=i.attributes,n=i.uniforms,r=t.gl,o=this._entityCollection;r.disable(r.CULL_FACE),r.uniform1f(n.uOpacity,o._fadingOpacity),r.uniformMatrix4fv(n.viewMatrix,!1,e.activeCamera.getViewMatrix()),r.uniformMatrix4fv(n.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),r.uniform3fv(n.eyePositionHigh,e.activeCamera.eyeHigh),r.uniform3fv(n.eyePositionLow,e.activeCamera.eyeLow),r.uniform1f(n.resolution,e.activeCamera._tanViewAngle_hradOneByHeight),r.bindBuffer(r.ARRAY_BUFFER,this._startPositionHighBuffer),r.vertexAttribPointer(s.a_startPosHigh,this._startPositionHighBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._startPositionLowBuffer),r.vertexAttribPointer(s.a_startPosLow,this._startPositionLowBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._endPositionHighBuffer),r.vertexAttribPointer(s.a_endPosHigh,this._endPositionHighBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._endPositionLowBuffer),r.vertexAttribPointer(s.a_endPosLow,this._endPositionLowBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._rgbaBuffer),r.vertexAttribPointer(s.a_rgba,this._rgbaBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._thicknessBuffer),r.vertexAttribPointer(s.a_thickness,this._thicknessBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._vertexBuffer),r.vertexAttribPointer(s.a_vertices,this._vertexBuffer.itemSize,r.FLOAT,!1,0,0),r.drawArrays(r.TRIANGLES,0,this._vertexBuffer.numItems),r.enable(r.CULL_FACE)}_pickingPASS(){}draw(){this._rays.length&&(this.update(),this._displayPASS())}drawPicking(){this._rays.length&&this.pickingEnabled&&this._pickingPASS()}reindexRaysArray(e){let t=this._rays;for(let i=e;i<t.length;i++)t[i]._handlerIndex=i}_removeRay(e){let t=e._handlerIndex;this._rays.splice(t,1);let i=24*t;this._rgbaArr=Ge(this._rgbaArr,i,24),i=18*t,this._startPositionHighArr=Ge(this._startPositionHighArr,i,18),this._startPositionLowArr=Ge(this._startPositionLowArr,i,18),this._endPositionHighArr=Ge(this._endPositionHighArr,i,18),this._endPositionLowArr=Ge(this._endPositionLowArr,i,18),this._pickingColorArr=Ge(this._pickingColorArr,i,18),i=12*t,this._vertexArr=Ge(this._vertexArr,i,12),i=6*t,this._thicknessArr=Ge(this._thicknessArr,i,6),this.reindexRaysArray(t),this.refresh(),e._handlerIndex=-1,e._handler=null}remove(e){e._handler&&this.__id===e._handler.__id&&this._removeRay(e)}setStartPositionArr(e,t,i){let s=18*e,n=this._startPositionHighArr,r=t.x,o=t.y,a=t.z;n[s]=r,n[s+1]=o,n[s+2]=a,n[s+3]=r,n[s+4]=o,n[s+5]=a,n[s+6]=r,n[s+7]=o,n[s+8]=a,n[s+9]=r,n[s+10]=o,n[s+11]=a,n[s+12]=r,n[s+13]=o,n[s+14]=a,n[s+15]=r,n[s+16]=o,n[s+17]=a,n=this._startPositionLowArr,r=i.x,o=i.y,a=i.z,n[s]=r,n[s+1]=o,n[s+2]=a,n[s+3]=r,n[s+4]=o,n[s+5]=a,n[s+6]=r,n[s+7]=o,n[s+8]=a,n[s+9]=r,n[s+10]=o,n[s+11]=a,n[s+12]=r,n[s+13]=o,n[s+14]=a,n[s+15]=r,n[s+16]=o,n[s+17]=a,this._changedBuffers[1]=!0}setEndPositionArr(e,t,i){let s=18*e,n=this._endPositionHighArr,r=t.x,o=t.y,a=t.z;n[s]=r,n[s+1]=o,n[s+2]=a,n[s+3]=r,n[s+4]=o,n[s+5]=a,n[s+6]=r,n[s+7]=o,n[s+8]=a,n[s+9]=r,n[s+10]=o,n[s+11]=a,n[s+12]=r,n[s+13]=o,n[s+14]=a,n[s+15]=r,n[s+16]=o,n[s+17]=a,n=this._endPositionLowArr,r=i.x,o=i.y,a=i.z,n[s]=r,n[s+1]=o,n[s+2]=a,n[s+3]=r,n[s+4]=o,n[s+5]=a,n[s+6]=r,n[s+7]=o,n[s+8]=a,n[s+9]=r,n[s+10]=o,n[s+11]=a,n[s+12]=r,n[s+13]=o,n[s+14]=a,n[s+15]=r,n[s+16]=o,n[s+17]=a,this._changedBuffers[2]=!0}setPickingColorArr(e,t){let i=18*e,s=this._pickingColorArr,n=t.x/255,r=t.y/255,o=t.z/255;s[i]=n,s[i+1]=r,s[i+2]=o,s[i+3]=n,s[i+4]=r,s[i+5]=o,s[i+6]=n,s[i+7]=r,s[i+8]=o,s[i+9]=n,s[i+10]=r,s[i+11]=o,s[i+12]=n,s[i+13]=r,s[i+14]=o,s[i+15]=n,s[i+16]=r,s[i+17]=o,this._changedBuffers[0]=!0}setRgbaArr(e,t,i){let s=24*e,n=this._rgbaArr,r=t.x,o=t.y,a=t.z,l=t.w,h=i.x,c=i.y,d=i.z,_=i.w;n[s]=h,n[s+1]=c,n[s+2]=d,n[s+3]=_,n[s+4]=r,n[s+5]=o,n[s+6]=a,n[s+7]=l,n[s+8]=r,n[s+9]=o,n[s+10]=a,n[s+11]=l,n[s+12]=r,n[s+13]=o,n[s+14]=a,n[s+15]=l,n[s+16]=h,n[s+17]=c,n[s+18]=d,n[s+19]=_,n[s+20]=h,n[s+21]=c,n[s+22]=d,n[s+23]=_,this._changedBuffers[3]=!0}setThicknessArr(e,t){let i=6*e,s=this._thicknessArr;s[i]=t,s[i+1]=t,s[i+2]=t,s[i+3]=t,s[i+4]=t,s[i+5]=t,this._changedBuffers[4]=!0}setVisibility(e,t){let i;i=t?[-.5,1,-.5,0,.5,0,.5,0,.5,1,-.5,1]:[0,0,0,0,0,0,0,0,0,0,0,0],this.setVertexArr(e,i)}setVertexArr(e,t){let i=12*e,s=this._vertexArr;s[i]=t[0],s[i+1]=t[1],s[i+2]=t[2],s[i+3]=t[3],s[i+4]=t[4],s[i+5]=t[5],s[i+6]=t[6],s[i+7]=t[7],s[i+8]=t[8],s[i+9]=t[9],s[i+10]=t[10],s[i+11]=t[11],this._changedBuffers[5]=!0}createStartPositionBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._startPositionHighBuffer),this._startPositionHighArr=Ve(this._startPositionHighArr),this._startPositionHighBuffer=e.createArrayBuffer(this._startPositionHighArr,3,this._startPositionHighArr.length/3,e.gl.DYNAMIC_DRAW),e.gl.deleteBuffer(this._startPositionLowBuffer),this._startPositionLowArr=Ve(this._startPositionLowArr),this._startPositionLowBuffer=e.createArrayBuffer(this._startPositionLowArr,3,this._startPositionLowArr.length/3,e.gl.DYNAMIC_DRAW)}createEndPositionBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._endPositionHighBuffer),this._endPositionHighArr=Ve(this._endPositionHighArr),this._endPositionHighBuffer=e.createArrayBuffer(this._endPositionHighArr,3,this._endPositionHighArr.length/3,e.gl.DYNAMIC_DRAW),e.gl.deleteBuffer(this._endPositionLowBuffer),this._endPositionLowArr=Ve(this._endPositionLowArr),this._endPositionLowBuffer=e.createArrayBuffer(this._endPositionLowArr,3,this._endPositionLowArr.length/3,e.gl.DYNAMIC_DRAW)}createRgbaBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._rgbaBuffer),this._rgbaArr=Ve(this._rgbaArr),this._rgbaBuffer=e.createArrayBuffer(this._rgbaArr,4,this._rgbaArr.length/4)}createThicknessBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._thicknessBuffer),this._thicknessArr=Ve(this._thicknessArr),this._thicknessBuffer=e.createArrayBuffer(this._thicknessArr,1,this._thicknessArr.length,e.gl.DYNAMIC_DRAW)}createVertexBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._vertexBuffer),this._vertexArr=Ve(this._vertexArr),this._vertexBuffer=e.createArrayBuffer(this._vertexArr,2,this._vertexArr.length/2,e.gl.DYNAMIC_DRAW)}createPickingColorBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._pickingColorBuffer),this._pickingColorArr=Ve(this._pickingColorArr),this._pickingColorBuffer=e.createArrayBuffer(this._pickingColorArr,3,this._pickingColorArr.length/3)}}us.__counter__=0;class gs{constructor(e){this.__id=gs.__counter__++,this.pickingEnabled=!0,this._entityCollection=e,this._renderer=null,this._strips=[]}_initProgram(){this._renderer&&this._renderer.handler&&!this._renderer.handler.programs.strip&&this._renderer.handler.addProgram(new Ni("strip",{uniforms:{projectionMatrix:{type:"mat4"},viewMatrix:{type:"mat4"},eyePositionHigh:"vec3",eyePositionLow:"vec3",uColor:{type:"vec4"},uOpacity:{type:"float"}},attributes:{aVertexPositionHigh:{type:"vec3"},aVertexPositionLow:{type:"vec3"}},vertexShader:"attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n void main(void) {\n\n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:"precision highp float;\n uniform vec4 uColor;\n uniform float uOpacity;\n void main(void) {\n gl_FragColor = vec4(uColor.rgb, uColor.a * uOpacity);\n }"}))}setRenderNode(e){this._renderer=e.renderer,this._initProgram();for(let t=0;t<this._strips.length;t++)this._strips[t].setRenderNode(e)}add(e){-1===e._handlerIndex&&(e._handler=this,e._handlerIndex=this._strips.length,this._strips.push(e),this._entityCollection&&this._entityCollection.renderNode&&e.setRenderNode(this._entityCollection.renderNode))}remove(e){let t=e._handlerIndex;-1!==t&&(e._deleteBuffers(),e._handlerIndex=-1,e._handler=null,this._strips.splice(t,1),this.reindexStripArray(t))}reindexStripArray(e){let t=this._strips;for(let i=e;i<t.length;i++)t[i]._handlerIndex=i}draw(){let e=this._strips.length;for(;e--;)this._strips[e].draw()}drawPicking(){if(this.pickingEnabled){let e=this._strips.length;for(;e--;)this._strips[e].drawPicking()}}clear(){let e=this._strips.length;for(;e--;)this._strips[e]._deleteBuffers(),this._strips[e]._handler=null,this._strips[e]._handlerIndex=-1;this._strips.length=0,this._strips=[]}}gs.__counter__=0;class fs{constructor(e={}){this._onChangeRelativeCenter=e=>{this.geoObjectHandler.setRelativeCenter(e),this.polylineHandler.setRelativeCenter(e)},this.__id=fs.__counter__++,this.renderNode=null,this._visibility=null==e.visibility||e.visibility,this.polygonOffsetUnits=null!=e.polygonOffsetUnits?e.polygonOffsetUnits:0,this.billboardHandler=new Ui(this),this.labelHandler=new hs(this,e.labelMaxLetters),this.polylineHandler=new _s(this),this.rayHandler=new us(this),this.pointCloudHandler=new cs(this),this.stripHandler=new gs(this),this.geoObjectHandler=new ns(this),null!=e.pickingEnabled&&this.setPickingEnabled(e.pickingEnabled),this._entities=[],this.scaleByDistance=e.scaleByDistance||[1,1,1];let t=new Float32Array([1,1,1]);void 0!==e.pickingScale&&(e.pickingScale instanceof Array?(t[0]=e.pickingScale[0]||t[0],t[1]=e.pickingScale[1]||t[1],t[2]=e.pickingScale[2]||t[2]):"number"==typeof e.pickingScale&&(t[0]=e.pickingScale,t[1]=e.pickingScale,t[2]=e.pickingScale)),this._depthOrder=e.depthOrder||0,this.pickingScale=t,this._opacity=null==e.opacity?1:e.opacity,this._fadingOpacity=this._opacity,this.events=this.rendererEvents=Mt(ps,this),this._useLighting=null!=e.useLighting?e.useLighting?1:0:1,e.entities&&this.addEntities(e.entities)}get depthOrder(){return this._depthOrder}set depthOrder(e){this._depthOrder=e,this.renderNode&&this.renderNode.updateEntityCollectionsDepthOrder()}isEmpty(){return 0==this._entities.length}get id(){return this.__id}get useLighting(){return Boolean(this._useLighting)}set useLighting(e){this._useLighting=Number(e)}isEqual(e){return null!==e&&this.__id===e.__id}setVisibility(e){this._visibility=e,this._fadingOpacity=this._opacity*(e?1:0),this.renderNode?.updateEntityCollectionsDepthOrder(),this.events.dispatch(this.events.visibilitychange,this)}getVisibility(){return this._visibility}setOpacity(e){this._opacity=e}setPickingEnabled(e){this.billboardHandler.pickingEnabled=e,this.labelHandler.pickingEnabled=e,this.polylineHandler.pickingEnabled=e,this.rayHandler.pickingEnabled=e,this.pointCloudHandler.pickingEnabled=e,this.stripHandler.pickingEnabled=e,this.geoObjectHandler.pickingEnabled=e}getOpacity(){return this._opacity}setScaleByDistance(e,t,i){this.scaleByDistance[0]=e,this.scaleByDistance[1]=t,this.scaleByDistance[2]=i||r}appendChildEntity(e){this._addRecursively(e)}_addRecursively(e){let t=this.renderNode;t&&(e._independentPicking||!e.parent?t&&t.renderer&&t.renderer.assignPickingColor(e):e._pickingColor=e.parent._pickingColor,t.renderer&&t.renderer.assignPickingColor(e),t.ellipsoid&&e._cartesian.isZero()&&e.setCartesian3v(t.ellipsoid.lonLatToCartesian(e._lonLat))),e.setPickingColor(),e._updateAbsolutePosition(),e.setScale3v(e.getScale()),e.billboard&&this.billboardHandler.add(e.billboard),e.label&&this.labelHandler.add(e.label),e.polyline&&this.polylineHandler.add(e.polyline),e.ray&&this.rayHandler.add(e.ray),e.pointCloud&&this.pointCloudHandler.add(e.pointCloud),e.strip&&this.stripHandler.add(e.strip),e.geoObject&&this.geoObjectHandler.add(e.geoObject),this.events.dispatch(this.events.entityadd,e);for(let t=0;t<e.childEntities.length;t++)e.childEntities[t]._entityCollection=this,e.childEntities[t]._entityCollectionIndex=e._entityCollectionIndex,this._addRecursively(e.childEntities[t])}add(e){return e._entityCollection||(e._entityCollection=this,e._entityCollectionIndex=this._entities.length,this._entities.push(e),this._addRecursively(e)),this}addEntities(e){for(let t=0,i=e.length;t<i;t++)this.add(e[t]);return this}belongs(e){return this.isEqual(e._entityCollection)}_removeRecursively(e){e._entityCollection=null,e._entityCollectionIndex=-1,e.billboard&&this.billboardHandler.remove(e.billboard),e.label&&this.labelHandler.remove(e.label),e.polyline&&this.polylineHandler.remove(e.polyline),e.ray&&this.rayHandler.remove(e.ray),e.pointCloud&&this.pointCloudHandler.remove(e.pointCloud),e.strip&&this.stripHandler.remove(e.strip),e.geoObject&&this.geoObjectHandler.remove(e.geoObject);for(let t=0;t<e.childEntities.length;t++)this._removeRecursively(e.childEntities[t])}removeEntity(e){this._entities.splice(e._entityCollectionIndex,1),this.reindexEntitiesArray(e._entityCollectionIndex),this.renderNode&&this.renderNode.renderer&&(this.renderNode.renderer.clearPickingColor(e),e._pickingColor.clear()),this.belongs(e)&&this._removeRecursively(e),this.events.dispatch(this.events.entityremove,e)}_removeEntitySilent(e){this._entities.splice(e._entityCollectionIndex,1),this.reindexEntitiesArray(e._entityCollectionIndex),this.renderNode&&this.renderNode.renderer&&(this.renderNode.renderer.clearPickingColor(e),e._pickingColor.clear()),this.belongs(e)&&this._removeRecursively(e)}createPickingColors(){if(!this.renderNode||!this.renderNode.renderer)return;let e=this._entities;for(let t=0;t<e.length;t++)e[t].parent||(this.renderNode.renderer.assignPickingColor(e[t]),e[t].setPickingColor())}reindexEntitiesArray(e){let t=this._entities;for(let i=e;i<t.length;i++)t[i]._entityCollectionIndex=i}addTo(e,t=!1){return this.renderNode||e.addEntityCollection(this,t),this}bindRenderNode(e){e.renderer&&e.renderer.isInitialized()&&(this.billboardHandler.setRenderer(e.renderer),this.labelHandler.setRenderer(e.renderer),this.rayHandler.setRenderer(e.renderer),this.geoObjectHandler.setRenderNode(e),this.polylineHandler.setRenderNode(e),this.pointCloudHandler.setRenderNode(e),this.stripHandler.setRenderNode(e),e.renderer.events.on("changerelativecenter",this._onChangeRelativeCenter),this.updateBillboardsTextureAtlas(),this.updateLabelsFontAtlas(),this.createPickingColors())}_updateGeodeticCoordinates(e){let t=this._entities,i=t.length;for(;i--;){let s=t[i];s._lonLat&&s.setCartesian3v(e.lonLatToCartesian(s._lonLat))}}updateBillboardsTextureAtlas(){let e=this.billboardHandler.billboards;for(let t=0;t<e.length;t++)e[t].setSrc(e[t].getSrc())}updateLabelsFontAtlas(){this.renderNode&&this.labelHandler.updateFonts()}remove(){this.renderNode&&(this.renderNode.removeEntityCollection(this),this.renderNode.renderer?.events.off("changerelativecenter",this._onChangeRelativeCenter),this.renderNode=null,this.events.dispatch(this.events.remove,this))}getEntities(){return[].concat(this._entities)}each(e){let t=this._entities.length;for(;t--;){let i=this._entities[t];i&&e(i)}}clear(){this.billboardHandler.clear(),this.labelHandler.clear(),this.polylineHandler.clear(),this.rayHandler.clear(),this.pointCloudHandler.clear(),this.stripHandler.clear(),this.geoObjectHandler.clear();let e=this._entities.length;for(;e--;){let t=this._entities[e];this.renderNode&&this.renderNode.renderer&&(this.renderNode.renderer.clearPickingColor(t),t._pickingColor.clear()),this._clearEntity(t)}this._entities.length=0,this._entities=[]}_clearEntity(e){e._entityCollection=null,e._entityCollectionIndex=-1;for(let t=0;t<e.childEntities.length;t++)this._clearEntity(e.childEntities[t])}}fs.__counter__=0;const ps=["draw","drawend","add","remove","entityadd","entityremove","visibilitychange","mousemove","mouseenter","mouseleave","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchmove","touchstart","touchend","doubletouch","touchleave","touchenter"];function ms(e,t){if(e>=0){let i=65536*Math.floor(e/65536);t[0]=Math.fround(i),t[1]=Math.fround(e-i)}else{let i=65536*Math.floor(-e/65536);t[0]=Math.fround(-i),t[1]=Math.fround(e+i)}return t}function vs(e,t){if(e>=0){let i=65536*Math.floor(e/65536);t.x=Math.fround(i),t.y=Math.fround(e-i)}else{let i=65536*Math.floor(-e/65536);t.x=Math.fround(-i),t.y=Math.fround(e+i)}return t}function ys(e,t,i){i=i||2;var s,n,r,o,a,l,h,c=t&&t.length,d=c?t[0]*i:e.length,_=xs(e,0,d,i,!0),u=[];if(!_)return u;if(c&&(_=function(e,t,i,s){var n,r,o,a=[];for(n=0,r=t.length;n<r;n++)(o=xs(e,t[n]*s,n<r-1?t[n+1]*s:e.length,s,!1))===o.next&&(o.steiner=!0),a.push(Ms(o));for(a.sort(As),n=0;n<a.length;n++)Ps(a[n],i),i=bs(i,i.next);return i}(e,t,_,i)),e.length>80*i){s=r=e[0],n=o=e[1];for(let t=i;t<d;t+=i)(a=e[t])<s&&(s=a),(l=e[t+1])<n&&(n=l),a>r&&(r=a),l>o&&(o=l);h=Math.max(r-s,o-n)}return ws(_,u,i,s,n,h),u}function xs(e,t,i,s,n){var r,o;if(n===function(e,t,i,s){var n=0;for(let r=t,o=i-s;r<i;r+=s)n+=(e[o]-e[r])*(e[r+1]+e[o+1]),o=r;return n}(e,t,i,s)>0)for(r=t;r<i;r+=s)o=Ns(r,e[r],e[r+1],o);else for(r=i-s;r>=t;r-=s)o=Ns(r,e[r],e[r+1],o);return o&&Is(o,o.next)&&(Hs(o),o=o.next),o}function bs(e,t){if(!e)return e;t||(t=e);var i,s=e;do{if(i=!1,s.steiner||!Is(s,s.next)&&0!==ks(s.prev,s,s.next))s=s.next;else{if(Hs(s),(s=t=s.prev)===s.next)return null;i=!0}}while(i||s!==t);return t}function ws(e,t,i,s,n,r,o){if(e){!o&&r&&function(e,t,i,s){var n=e;do{null===n.z&&(n.z=Ss(n.x,n.y,t,i,s)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next}while(n!==e);n.prevZ.nextZ=null,n.prevZ=null,function(e){var t,i,s,n,r,o,a,l,h=1;do{for(i=e,e=null,r=null,o=0;i;){for(o++,s=i,a=0,t=0;t<h&&(a++,s=s.nextZ);t++);for(l=h;a>0||l>0&&s;)0!==a&&(0===l||!s||i.z<=s.z)?(n=i,i=i.nextZ,a--):(n=s,s=s.nextZ,l--),r?r.nextZ=n:e=n,n.prevZ=r,r=n;i=s}r.nextZ=null,h*=2}while(o>1)}(n)}(e,s,n,r);for(var a,l,h=e;e.prev!==e.next;)if(a=e.prev,l=e.next,r?Ts(e,s,n,r):Cs(e))t.push(a.i/i),t.push(e.i/i),t.push(l.i/i),Hs(e),e=l.next,h=l.next;else if((e=l)===h){o?1===o?ws(e=Es(e,t,i),t,i,s,n,r,2):2===o&&Ls(e,t,i,s,n,r):ws(bs(e),t,i,s,n,r,1);break}}}function Cs(e){var t=e.prev,i=e,s=e.next;if(ks(t,i,s)>=0)return!1;for(var n=e.next.next;n!==e.prev;){if(Rs(t.x,t.y,i.x,i.y,s.x,s.y,n.x,n.y)&&ks(n.prev,n,n.next)>=0)return!1;n=n.next}return!0}function Ts(e,t,i,s){var n=e.prev,r=e,o=e.next;if(ks(n,r,o)>=0)return!1;for(var a=n.x<r.x?n.x<o.x?n.x:o.x:r.x<o.x?r.x:o.x,l=n.y<r.y?n.y<o.y?n.y:o.y:r.y<o.y?r.y:o.y,h=n.x>r.x?n.x>o.x?n.x:o.x:r.x>o.x?r.x:o.x,c=n.y>r.y?n.y>o.y?n.y:o.y:r.y>o.y?r.y:o.y,d=Ss(a,l,t,i,s),_=Ss(h,c,t,i,s),u=e.nextZ;u&&u.z<=_;){if(u!==e.prev&&u!==e.next&&Rs(n.x,n.y,r.x,r.y,o.x,o.y,u.x,u.y)&&ks(u.prev,u,u.next)>=0)return!1;u=u.nextZ}for(u=e.prevZ;u&&u.z>=d;){if(u!==e.prev&&u!==e.next&&Rs(n.x,n.y,r.x,r.y,o.x,o.y,u.x,u.y)&&ks(u.prev,u,u.next)>=0)return!1;u=u.prevZ}return!0}function Es(e,t,i){var s=e;do{var n=s.prev,r=s.next.next;!Is(n,r)&&zs(n,s,s.next,r)&&Ds(n,r)&&Ds(r,n)&&(t.push(n.i/i),t.push(s.i/i),t.push(r.i/i),Hs(s),Hs(s.next),s=e=r),s=s.next}while(s!==e);return s}function Ls(e,t,i,s,n,r){var o=e;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&Bs(o,a)){var l=Fs(o,a);return o=bs(o,o.next),l=bs(l,l.next),ws(o,t,i,s,n,r),void ws(l,t,i,s,n,r)}a=a.next}o=o.next}while(o!==e)}function As(e,t){return e.x-t.x}function Ps(e,t){if(t=function(e,t){var i,s=t,n=e.x,r=e.y,o=-1/0;do{if(r<=s.y&&r>=s.next.y&&s.next.y!==s.y){var a=s.x+(r-s.y)*(s.next.x-s.x)/(s.next.y-s.y);if(a<=n&&a>o){if(o=a,a===n){if(r===s.y)return s;if(r===s.next.y)return s.next}i=s.x<s.next.x?s:s.next}}s=s.next}while(s!==t);if(!i)return null;if(n===o)return i.prev;var l,h=i,c=i.x,d=i.y,_=1/0;s=i.next;for(;s!==h;)n>=s.x&&s.x>=c&&n!==s.x&&Rs(r<d?n:o,r,c,d,r<d?o:n,r,s.x,s.y)&&((l=Math.abs(r-s.y)/(n-s.x))<_||l===_&&s.x>i.x)&&Ds(s,e)&&(i=s,_=l),s=s.next;return i}(e,t),t){var i=Fs(t,e);bs(i,i.next)}}function Ss(e,t,i,s,n){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-i)/n)|e<<8))|e<<4))|e<<2))|e<<1))|(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-s)/n)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function Ms(e){var t=e,i=e;do{t.x<i.x&&(i=t),t=t.next}while(t!==e);return i}function Rs(e,t,i,s,n,r,o,a){return(n-o)*(t-a)-(e-o)*(r-a)>=0&&(e-o)*(s-a)-(i-o)*(t-a)>=0&&(i-o)*(r-a)-(n-o)*(s-a)>=0}function Bs(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!function(e,t){var i=e;do{if(i.i!==e.i&&i.next.i!==e.i&&i.i!==t.i&&i.next.i!==t.i&&zs(i,i.next,e,t))return!0;i=i.next}while(i!==e);return!1}(e,t)&&Ds(e,t)&&Ds(t,e)&&function(e,t){var i=e,s=!1,n=(e.x+t.x)/2,r=(e.y+t.y)/2;do{i.y>r!=i.next.y>r&&i.next.y!==i.y&&n<(i.next.x-i.x)*(r-i.y)/(i.next.y-i.y)+i.x&&(s=!s),i=i.next}while(i!==e);return s}(e,t)}function ks(e,t,i){return(t.y-e.y)*(i.x-t.x)-(t.x-e.x)*(i.y-t.y)}function Is(e,t){return e.x===t.x&&e.y===t.y}function zs(e,t,i,s){return!!(Is(e,t)&&Is(i,s)||Is(e,s)&&Is(i,t))||ks(e,t,i)>0!=ks(e,t,s)>0&&ks(i,s,e)>0!=ks(i,s,t)>0}function Ds(e,t){return ks(e.prev,e,e.next)<0?ks(e,t,e.next)>=0&&ks(e,e.prev,t)>=0:ks(e,t,e.prev)<0||ks(e,e.next,t)<0}function Fs(e,t){var i=new Os(e.i,e.x,e.y),s=new Os(t.i,t.x,t.y),n=e.next,r=t.prev;return e.next=t,t.prev=e,i.next=n,n.prev=i,s.next=i,i.prev=s,r.next=s,s.prev=r,s}function Ns(e,t,i,s){var n=new Os(e,t,i);return s?(n.next=s.next,n.prev=s,s.next.prev=n,s.next=n):(n.prev=n,n.next=n),n}function Hs(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function Os(e,t,i){this.i=e,this.x=t,this.y=i,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}function Vs(e){var t=e[0][0].length,i={vertices:[],holes:[],dimensions:t},s=0;for(let n=0;n<e.length;n++){for(let s=0;s<e[n].length;s++)for(let r=0;r<t;r++)i.vertices.push(e[n][s][r]);n>0&&(s+=e[n-1].length,i.holes.push(s))}return i}function Us(e,t,i){let s=e[0],n=e[1];if(s>=0){let e=65536*Math.floor(s/65536);t.x=Math.fround(e),i.x=Math.fround(s-e)}else{let e=65536*Math.floor(-s/65536);t.x=Math.fround(-e),i.x=Math.fround(s+e)}if(n>=0){let e=65536*Math.floor(n/65536);t.y=Math.fround(e),i.y=Math.fround(n-e)}else{let e=65536*Math.floor(-n/65536);t.y=Math.fround(-e),i.y=Math.fround(n+e)}}let Gs=new ae,Ys=new ae,js=new ae;class Ws{constructor(e){this.__id=Ws.__counter__++,this._layer=e,this._handler=null,this._geometries=[],this._updatedGeometryArr=[],this._updatedGeometry={},this._removeGeometryExtentArr=[],this._removeGeometryExtents={},this._polyVerticesHighMerc=[],this._polyVerticesLowMerc=[],this._polyColors=[],this._polyPickingColors=[],this._polyIndexes=[],this._lineVerticesHighMerc=[],this._lineVerticesLowMerc=[],this._lineOrders=[],this._lineIndexes=[],this._lineColors=[],this._linePickingColors=[],this._lineThickness=[],this._lineStrokes=[],this._lineStrokeColors=[],this._polyVerticesHighBufferMerc=null,this._polyVerticesLowBufferMerc=null,this._polyColorsBuffer=null,this._polyPickingColorsBuffer=null,this._polyIndexesBuffer=null,this._lineVerticesHighBufferMerc=null,this._lineVerticesLowBufferMerc=null,this._lineColorsBuffer=null,this._linePickingColorsBuffer=null,this._lineThicknessBuffer=null,this._lineStrokesBuffer=null,this._lineStrokeColorsBuffer=null,this._lineOrdersBuffer=null,this._lineIndexesBuffer=null,this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[0]=this.createPolyVerticesBuffer,this._buffersUpdateCallbacks[1]=this.createPolyIndexesBuffer,this._buffersUpdateCallbacks[2]=this.createPolyColorsBuffer,this._buffersUpdateCallbacks[3]=this.createLineVerticesBuffer,this._buffersUpdateCallbacks[4]=this.createLineIndexesBuffer,this._buffersUpdateCallbacks[5]=this.createLineOrdersBuffer,this._buffersUpdateCallbacks[6]=this.createLineColorsBuffer,this._buffersUpdateCallbacks[7]=this.createLineThicknessBuffer,this._buffersUpdateCallbacks[8]=this.createLineStrokesBuffer,this._buffersUpdateCallbacks[9]=this.createLineStrokeColorsBuffer,this._buffersUpdateCallbacks[10]=this.createPolyPickingColorsBuffer,this._buffersUpdateCallbacks[11]=this.createLinePickingColorsBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length)}static appendLineData(e,t,i,s,n,r,o,a,l,h,c,d,_,u,g,f,p,m){var v=0;c.length>0?(v=c[c.length-5]+9,c.push(v,v)):c.push(0,0);var y=n,x=[i.x,i.y,i.z,i.w],b=o,w=[r.x,r.y,r.z,r.w],C=[s.x,s.y,s.z,1];for(let i=0;i<e.length;i++){var T=e[i];if(0===T.length)continue;let s,n,r=v;if(t)s=T[T.length-1];else{let e=T[0],t=T[1];t||(t=e),s=[e[0]+e[0]-t[0],e[1]+e[1]-t[1]]}Us(s,Gs,Ys),a.push(Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y),l.push(Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y),p.push(Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y),m.push(Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y),h.push(1,-1,2,-2),u.push(y,y,y,y),f.push(b,b,b,b),d.push(x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3]),g.push(w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3]),_.push(C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3]);for(let e=0;e<T.length;e++){Us(T[e],Gs,Ys),a.push(Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y),l.push(Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y),p.push(Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y),m.push(Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y),h.push(1,-1,2,-2),u.push(y,y,y,y),f.push(b,b,b,b),d.push(x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3]),g.push(w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3]),_.push(C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3]),c.push(v++,v++,v++,v++)}if(t)n=T[0],c.push(r,r+1,r+1,r+1);else{let e=T[T.length-1],t=T[T.length-2];t||(t=e),n=[e[0]+e[0]-t[0],e[1]+e[1]-t[1]],c.push(v-1,v-1,v-1,v-1)}Us(n,Gs,Ys),a.push(Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y),l.push(Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y),p.push(Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y),m.push(Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y),h.push(1,-1,2,-2),u.push(y,y,y,y),f.push(b,b,b,b),d.push(x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3]),g.push(w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3]),_.push(C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3]),i<e.length-1&&(v+=8,c.push(v,v))}}assignHandler(e){this._handler=e,this.refresh(),e.isInitialized()&&this.update()}add(t){if(-1===t._handlerIndex){t._handler=this,t._handlerIndex=this._geometries.length,this._geometries.push(t);let i=t._entity._pickingColor.scaleTo(1/255);if(t._polyVerticesHighMerc=[],t._polyVerticesLowMerc=[],t._lineVerticesHighMerc=[],t._lineVerticesLowMerc=[],t._coordinates[0].length)if(t.type===e.GeometryTypeEnum.POLYGON){let e=t._coordinates,s=[];for(let t=0;t<e.length;t++){s[t]=[];for(let i=0;i<e[t].length;i++)s[t][i]=[$(e[t][i][0]),X(e[t][i][1])]}let n=Vs(s),r=ys(n.vertices,n.holes,2);t._polyVerticesHandlerIndex=this._polyVerticesHighMerc.length,t._polyIndexesHandlerIndex=this._polyIndexes.length;for(let e=0;e<r.length;e++)this._polyIndexes.push(r[e]+.5*t._polyVerticesHandlerIndex);let o=t._style.fillColor,a=[],l=[];for(let e=0;e<.5*n.vertices.length;e++)this._polyColors.push(o.x,o.y,o.z,o.w),this._polyPickingColors.push(i.x,i.y,i.z,1);for(let e=0;e<n.vertices.length;e++)vs(n.vertices[e],js),a[e]=js.x,l[e]=js.y;t._polyVerticesHighMerc=a,t._polyVerticesLowMerc=l,this._polyVerticesHighMerc.push.apply(this._polyVerticesHighMerc,a),this._polyVerticesLowMerc.push.apply(this._polyVerticesLowMerc,l),t._polyVerticesLength=n.vertices.length,t._polyIndexesLength=r.length,t._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,t._lineOrdersHandlerIndex=this._lineOrders.length,t._lineIndexesHandlerIndex=this._lineIndexes.length,t._lineColorsHandlerIndex=this._lineColors.length,t._lineThicknessHandlerIndex=this._lineThickness.length,Ws.appendLineData(s,!0,t._style.lineColor,i,t._style.lineWidth,t._style.strokeColor,t._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,t._lineVerticesHighMerc,t._lineVerticesLowMerc),t._lineVerticesLength=this._lineVerticesHighMerc.length-t._lineVerticesHandlerIndex,t._lineOrdersLength=this._lineOrders.length-t._lineOrdersHandlerIndex,t._lineIndexesLength=this._lineIndexes.length-t._lineIndexesHandlerIndex,t._lineColorsLength=this._lineColors.length-t._lineColorsHandlerIndex,t._lineThicknessLength=this._lineThickness.length-t._lineThicknessHandlerIndex}else if(t.type===e.GeometryTypeEnum.MULTIPOLYGON){let e=t._coordinates,s=[],n=[];t._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,t._lineOrdersHandlerIndex=this._lineOrders.length,t._lineIndexesHandlerIndex=this._lineIndexes.length,t._lineColorsHandlerIndex=this._lineColors.length,t._lineThicknessHandlerIndex=this._lineThickness.length;for(let r=0;r<e.length;r++){let o=e[r],a=[];for(let t=0;t<o.length;t++){a[t]=[];for(let i=0;i<e[r][t].length;i++)a[t][i]=[$(o[t][i][0]),X(o[t][i][1])]}let l=Vs(a),h=ys(l.vertices,l.holes,2);for(let e=0;e<h.length;e++)n.push(h[e]+.5*s.length);s.push.apply(s,l.vertices),Ws.appendLineData(a,!0,t._style.lineColor,i,t._style.lineWidth,t._style.strokeColor,t._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,t._lineVerticesHighMerc,t._lineVerticesLowMerc)}t._polyVerticesHandlerIndex=this._polyVerticesHighMerc.length,t._polyIndexesHandlerIndex=this._polyIndexes.length;for(let e=0;e<n.length;e++)this._polyIndexes.push(n[e]+.5*t._polyVerticesHandlerIndex);let r=t._style.fillColor,o=[],a=[];for(let e=0;e<.5*s.length;e++)this._polyColors.push(r.x,r.y,r.z,r.w),this._polyPickingColors.push(i.x,i.y,i.z,1);for(let e=0;e<s.length;e++)vs(s[e],js),o[e]=js.x,a[e]=js.y;t._polyVerticesHighMerc=o,t._polyVerticesLowMerc=a,this._polyVerticesHighMerc.push.apply(this._polyVerticesHighMerc,o),this._polyVerticesLowMerc.push.apply(this._polyVerticesLowMerc,a),t._polyVerticesLength=s.length,t._polyIndexesLength=n.length,t._lineVerticesLength=this._lineVerticesHighMerc.length-t._lineVerticesHandlerIndex,t._lineOrdersLength=this._lineOrders.length-t._lineOrdersHandlerIndex,t._lineIndexesLength=this._lineIndexes.length-t._lineIndexesHandlerIndex,t._lineColorsLength=this._lineColors.length-t._lineColorsHandlerIndex,t._lineThicknessLength=this._lineThickness.length-t._lineThicknessHandlerIndex}else if(t.type===e.GeometryTypeEnum.LINESTRING){let e=t._coordinates,s=new Array(e.length);for(let t=0;t<e.length;t++)s[t]=[$(e[t][0]),X(e[t][1])];t._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,t._lineOrdersHandlerIndex=this._lineOrders.length,t._lineIndexesHandlerIndex=this._lineIndexes.length,t._lineColorsHandlerIndex=this._lineColors.length,t._lineThicknessHandlerIndex=this._lineThickness.length,Ws.appendLineData([s],!1,t._style.lineColor,i,t._style.lineWidth,t._style.strokeColor,t._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,t._lineVerticesHighMerc,t._lineVerticesLowMerc),t._lineVerticesLength=this._lineVerticesHighMerc.length-t._lineVerticesHandlerIndex,t._lineOrdersLength=this._lineOrders.length-t._lineOrdersHandlerIndex,t._lineIndexesLength=this._lineIndexes.length-t._lineIndexesHandlerIndex,t._lineColorsLength=this._lineColors.length-t._lineColorsHandlerIndex,t._lineThicknessLength=this._lineThickness.length-t._lineThicknessHandlerIndex}else if(t.type===e.GeometryTypeEnum.MULTILINESTRING){let e=t._coordinates,s=[];for(let t=0;t<e.length;t++){s[t]=[];for(let i=0;i<e[t].length;i++)s[t][i]=[$(e[t][i][0]),X(e[t][i][1])]}t._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,t._lineOrdersHandlerIndex=this._lineOrders.length,t._lineIndexesHandlerIndex=this._lineIndexes.length,t._lineColorsHandlerIndex=this._lineColors.length,t._lineThicknessHandlerIndex=this._lineThickness.length,Ws.appendLineData(s,!1,t._style.lineColor,i,t._style.lineWidth,t._style.strokeColor,t._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,t._lineVerticesHighMerc,t._lineVerticesLowMerc),t._lineVerticesLength=this._lineVerticesHighMerc.length-t._lineVerticesHandlerIndex,t._lineOrdersLength=this._lineOrders.length-t._lineOrdersHandlerIndex,t._lineIndexesLength=this._lineIndexes.length-t._lineIndexesHandlerIndex,t._lineColorsLength=this._lineColors.length-t._lineColorsHandlerIndex,t._lineThicknessLength=this._lineThickness.length-t._lineThicknessHandlerIndex}this.setGeometryVisibility(t),!this._updatedGeometry[t.__id]&&this._updatedGeometryArr.push(t),this._updatedGeometry[t.__id]=!0,this.refresh()}}remove(e){const t=e._handlerIndex;if(-1!==t){this._geometries.splice(t,1),this._polyVerticesHighMerc.splice(e._polyVerticesHandlerIndex,e._polyVerticesLength),this._polyVerticesLowMerc.splice(e._polyVerticesHandlerIndex,e._polyVerticesLength),this._polyColors.splice(2*e._polyVerticesHandlerIndex,2*e._polyVerticesLength),this._polyPickingColors.splice(2*e._polyVerticesHandlerIndex,2*e._polyVerticesLength),this._polyIndexes.splice(e._polyIndexesHandlerIndex,e._polyIndexesLength);let i=.5*e._polyVerticesLength;for(let t=e._polyIndexesHandlerIndex;t<this._polyIndexes.length;t++)this._polyIndexes[t]-=i;this._lineVerticesHighMerc.splice(e._lineVerticesHandlerIndex,e._lineVerticesLength),this._lineVerticesLowMerc.splice(e._lineVerticesHandlerIndex,e._lineVerticesLength),this._lineOrders.splice(e._lineOrdersHandlerIndex,e._lineOrdersLength),this._lineColors.splice(e._lineColorsHandlerIndex,e._lineColorsLength),this._linePickingColors.splice(e._lineColorsHandlerIndex,e._lineColorsLength),this._lineStrokeColors.splice(e._lineColorsHandlerIndex,e._lineColorsLength),this._lineThickness.splice(e._lineThicknessHandlerIndex,e._lineThicknessLength),this._lineStrokes.splice(e._lineThicknessHandlerIndex,e._lineThicknessLength),this._lineIndexes.splice(e._lineIndexesHandlerIndex,e._lineIndexesLength),i=.5*e._lineVerticesLength;for(let t=e._lineIndexesHandlerIndex;t<this._lineIndexes.length;t++)this._lineIndexes[t]-=i;let s=this._geometries;for(let i=t;i<s.length;i++){let t=s[i];t._handlerIndex=i,t._polyVerticesHandlerIndex-=e._polyVerticesLength,t._polyIndexesHandlerIndex-=e._polyIndexesLength,t._lineVerticesHandlerIndex-=e._lineVerticesLength,t._lineOrdersHandlerIndex-=e._lineOrdersLength,t._lineColorsHandlerIndex-=e._lineColorsLength,t._lineThicknessHandlerIndex-=e._lineThicknessLength,t._lineIndexesHandlerIndex-=e._lineIndexesLength}e._pickingReady=!1,e._handler=null,e._handlerIndex=-1,e._polyVerticesHighMerc=[],e._polyVerticesLowMerc=[],e._polyVerticesLength=-1,e._polyIndexesLength=-1,e._polyVerticesHandlerIndex=-1,e._polyIndexesHandlerIndex=-1,e._lineVerticesHighMerc=[],e._lineVerticesLowMerc=[],e._lineVerticesLength=-1,e._lineOrdersLength=-1,e._lineIndexesLength=-1,e._lineColorsLength=-1,e._lineThicknessLength=-1,e._lineVerticesHandlerIndex=-1,e._lineOrdersHandlerIndex=-1,e._lineIndexesHandlerIndex=-1,e._lineThicknessHandlerIndex=-1,e._lineColorsHandlerIndex=-1,!this._removeGeometryExtents[e.__id]&&this._removeGeometryExtentArr.push(e.getExtent()),this._removeGeometryExtents[e.__id]=!0,this.refresh()}}_refreshRecursevely(e,t){if(t.ready){let i=this._layer._id;for(let s=0;s<t.nodes.length;s++){let n=t.nodes[s];if(e.overlaps(n.segment.getExtentLonLat())){this._refreshRecursevely(e,n);let t=n.segment.materials[i];t&&t.isReady&&(1!==t.segment.node.getState()?t.layer.clearMaterial(t):(t.pickingReady=t.pickingReady&&e._pickingReady,t.isReady=!1,t._updateTexture=t.texture,t._updatePickingMask=t.pickingMask),e._pickingReady=!0)}}}}_refreshRecursevelyExt(e,t){if(t.ready){let i=this._layer.__id;for(let s=0;s<t.nodes.length;s++){let n=t.nodes[s];if(e.overlaps(n.segment.getExtentLonLat())){this._refreshRecursevelyExt(e,n);let t=n.segment.materials[i];t&&t.isReady&&t.layer.clearMaterial(t)}}}}_refreshPlanetNode(e){let t,i=this._removeGeometryExtentArr;for(t=0;t<i.length;t++)this._refreshRecursevelyExt(i[t],e);let s=this._updatedGeometryArr;for(t=0;t<s.length;t++)this._refreshRecursevely(s[t],e)}_updatePlanet(){let e=this._layer._planet;if(e){let t=e.quadTreeStrategy.quadTreeList;for(let e=0;e<t.length;e++)this._refreshPlanetNode(t[e])}this._updatedGeometryArr.length=0,this._updatedGeometryArr=[],this._updatedGeometry={},this._removeGeometryExtentArr.length=0,this._removeGeometryExtentArr=[],this._removeGeometryExtents={}}refresh(){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]=!0}update(){if(this._handler){let e=!1,t=this._changedBuffers.length;for(;t--;)this._changedBuffers[t]&&(e=!0,this._buffersUpdateCallbacks[t].call(this),this._changedBuffers[t]=!1);e&&this._updatePlanet()}}setGeometryVisibility(e){let t=e.getVisibility()?1:0,i=this._polyVerticesHighMerc,s=this._polyVerticesLowMerc,n=e._polyVerticesLength,r=e._polyVerticesHandlerIndex;for(let o=0;o<n;o++)i[r+o]=e._polyVerticesHighMerc[o]*t,s[r+o]=e._polyVerticesLowMerc[o]*t;i=this._lineVerticesHighMerc,s=this._lineVerticesLowMerc,n=e._lineVerticesLength,r=e._lineVerticesHandlerIndex;for(let o=0;o<n;o++)i[r+o]=e._lineVerticesHighMerc[o]*t,s[r+o]=e._lineVerticesLowMerc[o]*t;this._changedBuffers[0]=!0,this._changedBuffers[3]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}setPolyColorArr(e,t){let i=2*e._polyVerticesHandlerIndex,s=i+2*e._polyVerticesLength,n=this._polyColors;for(let e=i;e<s;e+=4)n[e]=t.x,n[e+1]=t.y,n[e+2]=t.z,n[e+3]=t.w;this._changedBuffers[2]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}setLineStrokeColorArr(e,t){let i=e._lineColorsHandlerIndex,s=i+e._lineColorsLength,n=this._lineStrokeColors;for(let e=i;e<s;e+=4)n[e]=t.x,n[e+1]=t.y,n[e+2]=t.z,n[e+3]=t.w;this._changedBuffers[9]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}setLineColorArr(e,t){let i=e._lineColorsHandlerIndex,s=i+e._lineColorsLength,n=this._lineColors;for(let e=i;e<s;e+=4)n[e]=t.x,n[e+1]=t.y,n[e+2]=t.z,n[e+3]=t.w;this._changedBuffers[6]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}setLineStrokeArr(e,t){}setLineThicknessArr(e,t){let i=e._lineThicknessHandlerIndex,s=i+e._lineThicknessLength,n=this._lineThickness;for(let e=i;e<s;e++)n[e]=t;this._changedBuffers[7]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}bringToFront(e){let t=this._polyIndexes.splice(e._polyIndexesHandlerIndex,e._polyIndexesLength),i=this._lineIndexes.splice(e._lineIndexesHandlerIndex,e._lineIndexesLength);this._geometries.splice(e._handlerIndex,1);let s=this._geometries;for(let t=e._handlerIndex;t<s.length;t++){let i=s[t];i._handlerIndex=t,i._polyIndexesHandlerIndex-=e._polyIndexesLength,i._lineIndexesHandlerIndex-=e._lineIndexesLength}e._polyIndexesHandlerIndex=this._polyIndexes.length,e._lineIndexesHandlerIndex=this._lineIndexes.length,e._handlerIndex=this._geometries.length,this._geometries.push(e),this._polyIndexes.push.apply(this._polyIndexes,t),this._lineIndexes.push.apply(this._lineIndexes,i),this._changedBuffers[1]=!0,this._changedBuffers[4]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}createPolyVerticesBuffer(){let e=this._handler;e.gl.deleteBuffer(this._polyVerticesHighBufferMerc),this._polyVerticesHighBufferMerc=e.createArrayBuffer(new Float32Array(this._polyVerticesHighMerc),2,this._polyVerticesHighMerc.length/2),e.gl.deleteBuffer(this._polyVerticesLowBufferMerc),this._polyVerticesLowBufferMerc=e.createArrayBuffer(new Float32Array(this._polyVerticesLowMerc),2,this._polyVerticesLowMerc.length/2)}createPolyIndexesBuffer(){let e=this._handler;e.gl.deleteBuffer(this._polyIndexesBuffer),this._polyIndexesBuffer=e.createElementArrayBuffer(new Uint32Array(this._polyIndexes),1,this._polyIndexes.length)}createPolyColorsBuffer(){let e=this._handler;e.gl.deleteBuffer(this._polyColorsBuffer),this._polyColorsBuffer=e.createArrayBuffer(new Float32Array(this._polyColors),4,this._polyColors.length/4)}createPolyPickingColorsBuffer(){let e=this._handler;e.gl.deleteBuffer(this._polyPickingColorsBuffer),this._polyPickingColorsBuffer=e.createArrayBuffer(new Float32Array(this._polyPickingColors),4,this._polyPickingColors.length/4)}createLineVerticesBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineVerticesHighBufferMerc),this._lineVerticesHighBufferMerc=e.createArrayBuffer(new Float32Array(this._lineVerticesHighMerc),2,this._lineVerticesHighMerc.length/2),e.gl.deleteBuffer(this._lineVerticesLowBufferMerc),this._lineVerticesLowBufferMerc=e.createArrayBuffer(new Float32Array(this._lineVerticesLowMerc),2,this._lineVerticesLowMerc.length/2)}createLineIndexesBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineIndexesBuffer),this._lineIndexesBuffer=e.createElementArrayBuffer(new Uint32Array(this._lineIndexes),1,this._lineIndexes.length)}createLineOrdersBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineOrdersBuffer),this._lineOrdersBuffer=e.createArrayBuffer(new Float32Array(this._lineOrders),1,this._lineOrders.length/2)}createLineColorsBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineColorsBuffer),this._lineColorsBuffer=e.createArrayBuffer(new Float32Array(this._lineColors),4,this._lineColors.length/4)}createLinePickingColorsBuffer(){let e=this._handler;e.gl.deleteBuffer(this._linePickingColorsBuffer),this._linePickingColorsBuffer=e.createArrayBuffer(new Float32Array(this._linePickingColors),4,this._linePickingColors.length/4)}createLineThicknessBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineThicknessBuffer),this._lineThicknessBuffer=e.createArrayBuffer(new Float32Array(this._lineThickness),1,this._lineThickness.length)}createLineStrokesBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineStrokesBuffer),this._lineStrokesBuffer=e.createArrayBuffer(new Float32Array(this._lineStrokes),1,this._lineStrokes.length)}createLineStrokeColorsBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineStrokeColorsBuffer),this._lineStrokeColorsBuffer=e.createArrayBuffer(new Float32Array(this._lineStrokeColors),4,this._lineStrokeColors.length/4)}clear(){this._geometries=[],this._polyVerticesHighMerc=[],this._polyVerticesLowMerc=[],this._polyIndexes=[],this._polyColors=[],this._polyPickingColors=[],this._lineVerticesHighMerc=[],this._lineVerticesLowMerc=[],this._lineOrders=[],this._lineIndexes=[],this._lineColors=[],this._linePickingColors=[],this._lineThickness=[],this._lineStrokeColors=[],this._lineStrokes=[],this._deleteBuffers(),this._polyVerticesHighBufferMerc=null,this._polyVerticesLowBufferMerc=null,this._polyIndexesBuffer=null,this._polyColorsBuffer=null,this._polyPickingColorsBuffer=null,this._lineVerticesHighBufferMerc=null,this._lineVerticesLowBufferMerc=null,this._lineIndexesBuffer=null,this._lineOrdersBuffer=null,this._lineColorsBuffer=null,this._linePickingColorsBuffer=null,this._lineThicknessBuffer=null,this._lineStrokeColorsBuffer=null,this._lineStrokesBuffer=null,this._updatedGeometryArr=[],this._updatedGeometry={},this._removeGeometryExtentArr=[],this._removeGeometryExtents={},this.refresh()}_deleteBuffers(){if(this._layer._planet&&this._layer._planet.renderer){let e=this._layer._planet.renderer.handler.gl;e&&(e.deleteBuffer(this._polyVerticesHighBufferMerc),e.deleteBuffer(this._polyVerticesLowBufferMerc),e.deleteBuffer(this._polyIndexesBuffer),e.deleteBuffer(this._polyColorsBuffer),e.deleteBuffer(this._polyPickingColorsBuffer),e.deleteBuffer(this._lineVerticesHighBufferMerc),e.deleteBuffer(this._lineVerticesLowBufferMerc),e.deleteBuffer(this._lineIndexesBuffer),e.deleteBuffer(this._lineOrdersBuffer),e.deleteBuffer(this._lineColorsBuffer),e.deleteBuffer(this._linePickingColorsBuffer),e.deleteBuffer(this._lineThicknessBuffer),e.deleteBuffer(this._lineStrokeColorsBuffer),e.deleteBuffer(this._lineStrokesBuffer))}}}Ws.__counter__=0;class qs extends $t{constructor(e,t={}){super(e,t),this.events=this.events.registerNames($s),this.isVector=!0,this._hasImageryTiles=!1,this.scaleByDistance=t.scaleByDistance||[r,r,r],this._useLighting=void 0===t.useLighting||t.useLighting;let i=new Float32Array([1,1,1]);void 0!==t.pickingScale&&(t.pickingScale instanceof Array?(i[0]=t.pickingScale[0]||i[0],i[1]=t.pickingScale[1]||i[1],i[2]=t.pickingScale[2]||i[2]):"number"==typeof t.pickingScale&&(i[0]=t.pickingScale,i[1]=t.pickingScale,i[2]=t.pickingScale)),this.pickingScale=i,this.async=void 0===t.async||t.async,this.clampToGround=t.clampToGround||!1,this.relativeToGround=t.relativeToGround||!1,this._entities=function(e){let t=[];for(let i=0;i<e.length;i++){let s=e[i];"Entity"===s.instanceName?t.push(s):t.push(new Si(s))}return t}(t.entities||[]),this._labelMaxLetters=t.labelMaxLetters||24,this._stripEntityCollection=new fs({pickingEnabled:this.pickingEnabled}),this._bindEventsDefault(this._stripEntityCollection),this._polylineEntityCollection=new fs({pickingEnabled:this.pickingEnabled}),this._bindEventsDefault(this._polylineEntityCollection),this._geoObjectEntityCollection=new fs({pickingEnabled:this.pickingEnabled,useLighting:this._useLighting}),this._bindEventsDefault(this._geoObjectEntityCollection),this._geometryHandler=new Ws(this),this._nodeCapacity=t.nodeCapacity||60,this._entityCollectionsTreeStrategy=null,this.setEntities(this._entities),this.polygonOffsetUnits=null!=t.polygonOffsetUnits?t.polygonOffsetUnits:0,this.pickingEnabled=this._pickingEnabled,this._depthOrder=t.depthOrder||0}get depthOrder(){return this._depthOrder}set depthOrder(e){e!==this._depthOrder&&(this._depthOrder=e,this._planet&&this._planet.updateVisibleLayers())}get useLighting(){return this._useLighting}set useLighting(e){e!==this._useLighting&&(this._geoObjectEntityCollection.useLighting=e,this._useLighting=e)}get labelMaxLetters(){return this._labelMaxLetters}get instanceName(){return"Vector"}_bindPicking(){this._pickingColor.clear()}addTo(e){this._planet||(this._assignPlanet(e),this._geometryHandler.assignHandler(e.renderer.handler),this._polylineEntityCollection.addTo(e,!0),this._stripEntityCollection.addTo(e,!0),this._geoObjectEntityCollection.addTo(e,!0),this._polylineEntityCollection._layer=this,this._stripEntityCollection._layer=this,this._geoObjectEntityCollection._layer=this,this.setEntities(this._entities))}remove(){return super.remove(),this._polylineEntityCollection.remove(),this._stripEntityCollection.remove(),this._geoObjectEntityCollection.remove(),this._polylineEntityCollection._layer=void 0,this._stripEntityCollection._layer=void 0,this._geoObjectEntityCollection._layer=void 0,this}getEntities(){return[].concat(this._entities)}add(e,t=!1){return e._layer||e._entityCollection||(e._layer=this,e._layerIndex=this._entities.length,this._entities.push(e),this._proceedEntity(e,t)),this}insert(e,t,i=!1){if(!e._layer&&!e._entityCollection){e._layer=this,e._layerIndex=t,this._entities.splice(t,0,e);for(let e=t+1,i=this._entities.length;e<i;e++)this._entities[e]._layerIndex=e;this._proceedEntity(e,i)}return this}_proceedEntity(e,t=!1){let i=this._hasImageryTiles,s=!(e.strip||e.polyline||e.ray||e.geoObject||e.geometry);e.strip&&this._stripEntityCollection.add(e),(e.polyline||e.ray)&&this._polylineEntityCollection.add(e),(e.geoObject||s)&&this._geoObjectEntityCollection.add(e),e.geometry&&(this._hasImageryTiles=!0,this._planet&&(this._planet.renderer.assignPickingColor(e),this._geometryHandler.add(e.geometry))),this._planet&&((e.billboard||e.label||e.geoObject||s)&&(e._cartesian.isZero()&&!e._lonLat.isZero()?e._setCartesian3vSilent(this._planet.ellipsoid.lonLatToCartesian(e._lonLat)):(e._lonLat=this._planet.ellipsoid.cartesianToLonLat(e._cartesian),Math.abs(e._lonLat.lat)<Q?e._lonLatMerc=e._lonLat.forwardMercator():e._lonLatMerc.lon=e._lonLatMerc.lat=e._lonLatMerc.height=0)),(e.billboard||e.label)&&this._entityCollectionsTreeStrategy?.insertEntity(e)),this._planet&&this._hasImageryTiles!==i&&this._planet.updateVisibleLayers(),this.events.dispatch(this.events.entityadd,e)}addEntities(e,t=!1){let i=e.length;for(;i--;)this.add(e[i],t);return this}removeEntity(e){if(e._layer&&this.isEqual(e._layer)){if(this._entities.splice(e._layerIndex,1),this._reindexEntitiesArray(e._layerIndex),e._layer=null,e._layerIndex=-1,e._entityCollection){e._entityCollection._removeEntitySilent(e);let t=e._nodePtr;for(;t;)t.count--,t=t.parentNode;e._nodePtr&&0===e._nodePtr.count&&0===e._nodePtr.deferredEntities.length&&(e._nodePtr.entityCollection=null)}else if(e._nodePtr&&e._nodePtr.deferredEntities.length){let t=e._nodePtr.deferredEntities,i=t.length;for(;i--;)if(t[i].id===e.id){t.splice(i,1);let s=e._nodePtr;for(;s;)s.count--,s=s.parentNode;break}}this._planet&&e.geometry&&(this._geometryHandler.remove(e.geometry),this._planet.renderer.clearPickingColor(e)),e._nodePtr=void 0,this.events.dispatch(this.events.entityremove,e)}return this}set pickingEnabled(e){this._pickingEnabled=e,this._stripEntityCollection.setPickingEnabled(e),this._polylineEntityCollection.setPickingEnabled(e),this._geoObjectEntityCollection.setPickingEnabled(e),this._entityCollectionsTreeStrategy?.setPickingEnabled(e)}_reindexEntitiesArray(e){const t=this._entities;for(let i=e;i<t.length;i++)t[i]._layerIndex=i}removeEntities(e){let t=e.length;for(;t--;)this.removeEntity(e[t]);return this}clear(){super.clear();let e=new Array(this._entities.length);for(let t=0;t<e.length;t++)e[t]=this._entities[t];let t=this._entities.length;for(;t--;)this._entities[t].remove();this._entities.length=0,this._entities=[];for(let t=0;t<e.length;t++)this._entities[t]=e[t];this._entityCollectionsTreeStrategy?.dispose(),this._entityCollectionsTreeStrategy=null,this._geometryHandler.clear()}each(e){let t=this._entities,i=t.length;for(;i--;)e(t[i],i)}setEntities(e){let t=new Array(e.length);for(let i=0,s=e.length;i<s;i++)t[i]=e[i];this.clear(),this._entities=new Array(t.length);let i=[];for(let e=0;e<t.length;e++){let s=t[e];s._layer=this,s._layerIndex=e;let n=!(s.strip||s.polyline||s.ray||s.geoObject||s.billboard||s.label);s.strip?this._stripEntityCollection.add(s):s.polyline||s.ray?this._polylineEntityCollection.add(s):s.geoObject||n?this._geoObjectEntityCollection.add(s):(s.billboard||s.label)&&i.push(s),s.geometry&&(this._hasImageryTiles=!0,this._planet&&(this._planet.renderer.assignPickingColor(s),this._geometryHandler.add(s.geometry))),this._entities[e]=s}return this._createEntityCollectionsTree(i),this}_createEntityCollectionsTree(e){this._planet&&(this._entityCollectionsTreeStrategy=this._planet.quadTreeStrategy.createEntitiCollectionsTreeStrategy(this,this._nodeCapacity),this._entityCollectionsTreeStrategy.insertEntities(e))}_bindEventsDefault(e){let t=this.events;e.events.on("mousemove",(e=>{t.dispatch(t.mousemove,e)})),e.events.on("mouseenter",(e=>{t.dispatch(t.mouseenter,e)})),e.events.on("mouseleave",(e=>{t.dispatch(t.mouseleave,e)})),e.events.on("lclick",(e=>{t.dispatch(t.lclick,e)})),e.events.on("rclick",(e=>{t.dispatch(t.rclick,e)})),e.events.on("mclick",(e=>{t.dispatch(t.mclick,e)})),e.events.on("ldblclick",(e=>{t.dispatch(t.ldblclick,e)})),e.events.on("rdblclick",(e=>{t.dispatch(t.rdblclick,e)})),e.events.on("mdblclick",(e=>{t.dispatch(t.mdblclick,e)})),e.events.on("lup",(e=>{t.dispatch(t.lup,e)})),e.events.on("rup",(e=>{t.dispatch(t.rup,e)})),e.events.on("mup",(e=>{t.dispatch(t.mup,e)})),e.events.on("ldown",(e=>{t.dispatch(t.ldown,e)})),e.events.on("rdown",(e=>{t.dispatch(t.rdown,e)})),e.events.on("mdown",(e=>{t.dispatch(t.mdown,e)})),e.events.on("lhold",(e=>{t.dispatch(t.lhold,e)})),e.events.on("rhold",(e=>{t.dispatch(t.rhold,e)})),e.events.on("mhold",(e=>{t.dispatch(t.mhold,e)})),e.events.on("mousewheel",(e=>{t.dispatch(t.mousewheel,e)})),e.events.on("touchmove",(e=>{t.dispatch(t.touchmove,e)})),e.events.on("touchstart",(e=>{t.dispatch(t.touchstart,e)})),e.events.on("touchend",(e=>{t.dispatch(t.touchend,e)})),e.events.on("doubletouch",(e=>{t.dispatch(t.doubletouch,e)})),e.events.on("touchleave",(e=>{t.dispatch(t.touchleave,e)})),e.events.on("touchenter",(e=>{t.dispatch(t.touchenter,e)}))}_collectStripCollectionPASS(e){let t=this._stripEntityCollection;t._fadingOpacity=this._fadingOpacity,t.scaleByDistance=this.scaleByDistance,t.pickingScale=this.pickingScale,t.polygonOffsetUnits=this.polygonOffsetUnits,e.push(t)}_collectPolylineCollectionPASS(e){let t=this._polylineEntityCollection;if(t._fadingOpacity=this._fadingOpacity,t.scaleByDistance=this.scaleByDistance,t.pickingScale=this.pickingScale,t.polygonOffsetUnits=this.polygonOffsetUnits,e.push(t),this.clampToGround||this.relativeToGround){let e=Number(this.relativeToGround);const i=this._planet._renderedNodes,s=this._planet.getViewExtent();let n=t._entities,r=n.length,o=new oe;for(;r--;){let t=n[r].polyline;if(t&&s.overlaps(t._extent)){let s=t._pathLonLatMerc,n=s.length;for(;n--;){let r=s[n].length;for(;r--;){let a=s[n][r],l=i.length;for(;l--;){let s=i[l].segment;if(s._extent.isInside(a)){let i=t._path3v[n][r];s.getTerrainPoint(i,a,o);let l=e&&t.altitude||0;if(l){let e=this._planet.ellipsoid.getSurfaceNormal3v(o);t.setPoint3v(o.addA(e.scale(l)),r,n,!0)}else t.setPoint3v(o,r,n,!0);break}}}}}}}}_collectGeoObjectCollectionPASS(e){let t=this._geoObjectEntityCollection;t._fadingOpacity=this._fadingOpacity,t.scaleByDistance=this.scaleByDistance,t.pickingScale=this.pickingScale,t.polygonOffsetUnits=this.polygonOffsetUnits,e.push(t)}collectVisibleCollections(e){let t=this._planet;(this._fading&&this._fadingOpacity>0||this.minZoom<=t.maxCurrZoom&&this.maxZoom>=t.maxCurrZoom)&&(this._collectStripCollectionPASS(e),this._collectPolylineCollectionPASS(e),this._collectGeoObjectCollectionPASS(e),this._entityCollectionsTreeStrategy&&this._entityCollectionsTreeStrategy.collectVisibleEntityCollections(e))}loadMaterial(e){const t=e.segment;this._isBaseLayer?e.texture=t._isNorth?t.planet.solidTextureOne:t.planet.solidTextureTwo:e.texture=t.planet.transparentTexture,this._planet.layerLock.isFree()&&(e.isReady=!1,e.isLoading=!0,this._planet._vectorTileCreator.add(e))}abortMaterialLoading(e){e.isLoading=!1,e.isReady=!1}applyMaterial(e,t=!1){if(e.isReady)return[0,0,1,1];{!e.isLoading&&this.loadMaterial(e);const t=e.segment;let i=t.node,s=!1,n=this.__id,r=e;for(;i.parentNode;){if(r&&r.isReady){s=!0;break}i=i.parentNode,r=i.segment.materials[n]}if(s){e.appliedNodeId=i.nodeId,e.texture=r.texture,e.pickingMask=r.pickingMask;const s=1/(2<<t.tileZoom-i.segment.tileZoom-1);return[t.tileX*s-i.segment.tileX,t.tileY*s-i.segment.tileY,s,s]}return e.textureExists&&e._updateTexture?(e.texture=e._updateTexture,e.pickingMask=e._updatePickingMask):(e.texture=t.planet.transparentTexture,e.pickingMask=t.planet.transparentTexture),e.pickingReady=!0,[0,0,1,1]}}clearMaterial(e){if(e.isReady){const t=e.segment.handler.gl;e.isReady=!1,e.pickingReady=!1;let i=e.texture;e.texture=null,i&&!i.default&&t.deleteTexture(i),i=e.pickingMask,e.pickingMask=null,i&&!i.default&&t.deleteTexture(i),i=e._updateTexture,e._updateTexture=null,i&&!i.default&&t.deleteTexture(i),i=e._updatePickingMask,e._updatePickingMask=null,i&&!i.default&&t.deleteTexture(i)}this.abortMaterialLoading(e),e.isLoading=!1,e.textureExists=!1}update(){this._geometryHandler.update(),this.events.dispatch(this.events.draw,this)}}const $s=["draw","entityadd","entityremove"],Xs=["change","startpoint"],Zs=mi.createCylinder(1,1,2,20,1,!0,!1,0,-.5,0),Ks=200,Qs=.3,Js={scale:.5,instanced:!0,tag:"corners",color:"rgb(350, 350, 0)",object3d:Zs},en={scale:.4,instanced:!0,tag:"centers",color:"rgb(0, 350, 50)",object3d:Zs},tn={thickness:3.5,color:"rgb(0, 350, 50)"};class sn extends Ri{constructor(e){super(e.name),this._cornerDblClick=!1,this._onChange=e=>{if("POLYGON"===e.geometryType){let t=this.getCoordinates(),i=new Si({geometry:{type:e.geometryType,coordinates:[t],style:{fillColor:"rgba(0,146,247,0.2)"}}});this._geometryLayer.clear(),this._geometryLayer.add(i)}},this._onCornerMouseEnter=e=>{e.renderer.handler.canvas.style.cursor="pointer",this.hideGhostPointer()},this._onCornerMouseLeave=e=>{e.renderer.handler.canvas.style.cursor="default",this.showGhostPointer()},this._onCenterMouseEnter=e=>{e.renderer.handler.canvas.style.cursor="pointer",this.hideGhostPointer()},this._onCenterMouseLeave=e=>{e.renderer.handler.canvas.style.cursor="default",this._pickedCenter||this._pickedCorner||this.showGhostPointer()},this._onLup=e=>{this._planet.renderer.controls.mouseNavigation.activate(),(this._pickedCorner||this._pickedCenter)&&(this.events.dispatch(this.events.change,this),this.setGhostPointerPosition(this._planet.getCartesianFromPixelTerrain(e)),this.showGhostPointer(),this._pickedCorner=null,this._pickedCenter=null)},this._onCornerLdown=e=>{this._pickedCorner=this._getLdown(e)},this._onCenterLdown=e=>{this._pickedCenter=this._getLdown(e)},this._onMouseMove=e=>{this._pickedCenter?this._moveCenterPoint():this._pickedCorner?this._moveCornerPoint(e.pos):this.setGhostPointerPosition(this._planet.getCartesianFromPixelTerrain(e.pos))},this._onCornerLdblclick=e=>{this._cornerDblClick=!0;let t=this.getCoordinates();t.splice(e.pickingObject.layerIndex,1),this.setCoordinates(t)},this._onMouseDblClick=e=>{if(this._cornerDblClick)return void(this._cornerDblClick=!1);if(!this._showGhostPointer)return;let t=this._planet.getCartesianFromPixelTerrain(e);t&&(this._addNew(t),!this._isStartPoint&&this._cornerLayer.getEntities().length>2&&(this._isStartPoint=!0,this.events.dispatch(this.events.startpoint,this)),this.events.dispatch(this.events.change,this))},this.events=Mt(Xs),this._planet=null,this._initCoordinates=e.coordinates||[],this._pickedCorner=null,this._pickedCenter=null,this._startPos=null,this._startClick=new ae,this._geometryLayer=new qs,this._cornerLayer=new qs("corners",{pickingScale:3,pickingEnabled:!0,polygonOffsetUnits:-5,relativeToGround:!0,scaleByDistance:[100,4e6,1]}),this._centerLayer=new qs("centers",{pickingScale:3,pickingEnabled:!0,polygonOffsetUnits:-5,relativeToGround:!0,scaleByDistance:[100,4e6,1]}),this._outlineLayer=new qs("outline",{entities:[new Si({polyline:{path3v:[],isClosed:!1,...tn}})],pickingEnabled:!1,polygonOffsetUnits:-5,relativeToGround:!0}),this._outlineLayer.getEntities()[0].polyline.altitude=Qs,this._ghostCorner=new Si({geoObject:Js}),this._ghostOutlineLayer=new qs("ghost-pointer",{pickingEnabled:!1,polygonOffsetUnits:-5,relativeToGround:!0,scaleByDistance:[100,4e6,1],opacity:.5}),this._showGhostPointer=!1,this._isStartPoint=!1,this._insertCornerIndex=-1}get geometryType(){return"POLYGON"}getCoordinates(){let e=this._cornerLayer.getEntities();return e.length>0?e.map((e=>{let t=e.getLonLat();return[t.lon,t.lat,t.height]})):this._initCoordinates}bindPlanet(e){this._planet=e}init(){this._initEvents(),this._initGhostLayerPointer(),this._initCoordinates.length&&this.setCoordinates(this._initCoordinates),this._planet.addLayer(this._outlineLayer),this._planet.addLayer(this._cornerLayer),this._planet.addLayer(this._centerLayer),this.showGhostPointer(),this.startNewPoint(),this._planet.renderer.controls.mouseNavigation.deactivateDoubleClickZoom(),this._geometryLayer.addTo(this._planet),this.events.on("change",this._onChange,this)}onremove(){this._clearEvents(),this.hideGhostPointer(),this.stopNewPoint(),this.clear(),this._geometryLayer.remove()}clear(){this._geometryLayer.clear();let e=this._cornerLayer.getEntities(),t=e.length;for(;t--;)e[t].remove();let i=this._centerLayer.getEntities();for(t=i.length;t--;)i[t].remove();let s=this._outlineLayer.getEntities();for(t=s.length;t--;)s[t].polyline.clear(),t>0&&s[t].remove();this._clearGhostPointer()}setCoordinates(e){this.clear();for(let t=0;t<e.length;t++){let i=e[t],s=this._planet.ellipsoid.lonLatToCartesian(new I(i[0],i[1],i[2]));this._appendCart(s)}this.events.dispatch(this.events.change,this)}stopNewPoint(){this.renderer&&this.renderer.events.off("ldblclick",this._onMouseDblClick)}startNewPoint(){this.renderer.events.on("ldblclick",this._onMouseDblClick,this)}showGhostPointer(){this._showGhostPointer=!0,this._planet.addLayer(this._ghostOutlineLayer),this._insertCornerIndex=this._cornerLayer.getEntities().length}hideGhostPointer(){this._showGhostPointer=!1,this._ghostOutlineLayer.remove(),this._insertCornerIndex=-1}setGhostPointerPosition(e){e&&(this._ghostCorner.setCartesian3v(e),this._updateGhostOutlinePointer(e))}_getLdown(e){this._planet.renderer.controls.mouseNavigation.deactivate(),this._startClick.set(e.x,e.y);let t=e.pickingObject.getCartesian();return this._startPos=this._planet.getPixelFromCartesian(t),e.pickingObject}_initEvents(){this._cornerLayer.events.on("ldblclick",this._onCornerLdblclick,this),this._cornerLayer.events.on("ldown",this._onCornerLdown,this),this._centerLayer.events.on("ldown",this._onCenterLdown,this),this.renderer.events.on("lup",this._onLup,this),this.renderer.events.on("mousemove",this._onMouseMove,this),this._cornerLayer.events.on("mouseenter",this._onCornerMouseEnter,this),this._cornerLayer.events.on("mouseleave",this._onCornerMouseLeave,this),this._centerLayer.events.on("mouseenter",this._onCenterMouseEnter,this),this._centerLayer.events.on("mouseleave",this._onCenterMouseLeave,this)}_clearEvents(){this._cornerLayer.events.off("ldblclick",this._onCornerLdblclick),this._cornerLayer.events.off("ldown",this._onCornerLdown),this._centerLayer.events.off("ldown",this._onCenterLdown),this.renderer.events.off("lup",this._onLup),this.renderer.events.off("mousemove",this._onMouseMove),this._cornerLayer.events.off("mouseenter",this._onCornerMouseEnter),this._cornerLayer.events.off("mouseleave",this._onCornerMouseLeave),this._centerLayer.events.off("mouseenter",this._onCenterMouseEnter),this._centerLayer.events.off("mouseleave",this._onCenterMouseLeave)}_drawCorners(){let e=this._cornerLayer.getEntities();for(let t=0;t<e.length;t++){let i=e[t];this._checkTerrainCollision(i)}}_drawCenters(){let e=this._centerLayer.getEntities();for(let t=0;t<e.length;t++){let i=e[t];this._checkTerrainCollision(i)}}_drawGhostCorner(){this._showGhostPointer&&this._checkTerrainCollision(this._ghostCorner)}frame(){this._drawCorners(),this._drawCenters(),this._drawGhostCorner()}_checkTerrainCollision(e){let t=new oe,i=this._planet._renderedNodes;for(let s=0;s<i.length;s++){let n=i[s].segment;if(n&&n._extentLonLat.isInside(e.getLonLat())){n.getEntityTerrainPoint(e,t),e.setCartesian3v(t);break}}}_moveCenterPoint(){let e=this.getCoordinates(),t=this._pickedCenter.layerIndex+1,i=this._pickedCenter.getLonLat(),s=[i.lon,i.lat,i.height];e.splice(t,0,s),this.setCoordinates(e),this._pickedCenter=null,this._pickedCorner=this._cornerLayer.getEntities()[t]}_addNew(e){if(-1===this._insertCornerIndex||this._cornerLayer.getEntities().length<2)this._appendCart(e);else{let t=this.getCoordinates(),i=this._insertCornerIndex,s=this._planet.ellipsoid.cartesianToLonLat(e),n=[s.lon,s.lat,s.height];t.splice(i,0,n),this.clear(),this.setCoordinates(t)}}_appendCart(e){let t=this._cornerLayer.getEntities(),i=t[t.length-1],s=new Si({geoObject:Js});if(s.setCartesian3v(e),s.addTo(this._cornerLayer),this._checkTerrainCollision(s),i){let e=t[0].getCartesian(),n=i.getCartesian(),r=s.getCartesian().sub(n),o=s.getCartesian().sub(e),a=r.length(),l=o.length();r.normalize(),o.normalize();let h=[],c=[];for(let t=0;t<=Ks;t++){let i=r.scaleTo(t*a/Ks).addA(n);h.push(i);let s=o.scaleTo(t*l/Ks).addA(e);c.push(s)}this._outlineLayer.getEntities()[0].polyline.setPath3v([c]);let d=new Si({polyline:{path3v:[h],isClosed:!1,...tn}});d.polyline.altitude=Qs,this._outlineLayer.add(d);let _=this._centerLayer.getEntities(),u=_[_.length-1],g=r.scaleTo(.5*a).addA(n),f=o.scaleTo(.5*l).addA(e),p=new Si({geoObject:en});p.setCartesian3v(g),p.addTo(this._centerLayer),this._checkTerrainCollision(p),u.remove(),u.addTo(this._centerLayer),u.setCartesian3v(f)}else{new Si({geoObject:en}).addTo(this._centerLayer)}}_clearGhostPointer(){const e=this._ghostOutlineLayer;e.getEntities()[0].polyline.clear(),e.getEntities()[1].polyline.clear()}_moveCornerPoint(e){let t=new ae(e.x,e.y).sub(this._startClick),i=this._startPos.add(t),s=this._planet.getCartesianFromPixelTerrain(i);if(s){this._pickedCorner.setCartesian3v(s);let e=this._cornerLayer.getEntities();if(e.length){let t=this._pickedCorner.layerIndex,i=e.length,s=e[0===t?i-1:t-1].getCartesian(),n=e[(t+1)%i].getCartesian(),r=this._pickedCorner.getCartesian().sub(s),o=this._pickedCorner.getCartesian().sub(n),a=r.length(),l=o.length();r.normalize(),o.normalize();let h=[],c=[];for(let e=0;e<=Ks;e++){let t=r.scaleTo(e*a/Ks).addA(s);h.push(t);let i=o.scaleTo(e*l/Ks).addA(n);c.push(i)}let d=this._outlineLayer.getEntities(),_=d[t].polyline,u=d[(t+1)%i].polyline;_?.setPath3v([h]),u?.setPath3v([c]);let g=this._centerLayer.getEntities(),f=g[0===t?i-1:t-1],p=g[t],m=r.scaleTo(.5*a).addA(s),v=o.scaleTo(.5*l).addA(n);f.setCartesian3v(m),this._checkTerrainCollision(f),p.setCartesian3v(v),this._checkTerrainCollision(p)}}}_updateGhostOutlinePointer(e){let t=this._cornerLayer.getEntities(),i=t.length;if(i>0){let s=0,n=o;for(let r=0;r<i;r++){let i=t[r].getCartesian().distance(e);i<n&&(n=i,s=r)}let r=t[s].getCartesian(),a=t[(s+1)%i].getCartesian(),l=t[0===s?i-1:s-1].getCartesian().sub(r).normalize(),h=a.sub(r).normalize(),c=e.sub(r).normalize(),d=l.add(h).normalize(),_=c.cross(d),u=l.cross(h);_.dot(u)>0&&(s--,s<0&&(s=i-1));let g=new oe;for(let r=0;r<i;r++){if(new di(t[r].getCartesian(),t[(r+1)%i].getCartesian()).getNearestDistancePoint(e,g)){let t=g.distance(e);t<n&&(n=t,s=r)}}this._insertCornerIndex=(s+1)%i;let f=t[s%i].getCartesian(),p=t[(s+1)%i].getCartesian(),m=this._ghostCorner.getCartesian().sub(f),v=this._ghostCorner.getCartesian().sub(p),y=m.length(),x=v.length();m.normalize(),v.normalize();let b=[],w=[];for(let e=0;e<=Ks;e++){let t=m.scaleTo(e*y/Ks).addA(f);b.push(t);let i=v.scaleTo(e*x/Ks).addA(p);w.push(i)}let C=this._ghostOutlineLayer.getEntities(),T=C[0].polyline,E=C[1].polyline;T?.setPath3v([b]),E?.setPath3v([w])}}_initGhostLayerPointer(){this._ghostOutlineLayer.setEntities([new Si({polyline:{path3v:[],isClosed:!1,...tn}}),new Si({polyline:{path3v:[],isClosed:!1,...tn}}),this._ghostCorner]);const e=this._ghostOutlineLayer;e.getEntities()[0].polyline.altitude=e.getEntities()[1].polyline.altitude=Qs}}class nn extends sn{constructor(e){super(e)}get geometryType(){return"LineString"}_addNew(e){this._appendCart(e)}_appendCart(e){let t=this._cornerLayer.getEntities(),i=t[t.length-1],s=new Si({geoObject:Js});if(s.setCartesian3v(e),s.addTo(this._cornerLayer),this._checkTerrainCollision(s),i){let e=i.getCartesian(),t=s.getCartesian().sub(e),n=t.length();t.normalize();let r=[];for(let i=0;i<=Ks;i++){let s=t.scaleTo(i*n/Ks).addA(e);r.push(s)}let o=new Si({polyline:{path3v:[r],isClosed:!1,...tn}});o.polyline.altitude=Qs,this._outlineLayer.add(o);let a=t.scaleTo(.5*n).addA(e),l=new Si({geoObject:en});l.setCartesian3v(a),l.addTo(this._centerLayer),this._checkTerrainCollision(l)}}_clearGhostPointer(){this._ghostOutlineLayer.getEntities()[0].polyline.clear()}_moveCorner(e,t,i){let s=this._cornerLayer.getEntities();if(0==s.length)return;1==s.length&&(e=t=i=0);let n=s[e].getCartesian(),r=this._pickedCorner.getCartesian().sub(n),o=r.length();r.normalize();let a=[];for(let e=0;e<=Ks;e++){let t=r.scaleTo(e*o/Ks).addA(n);a.push(t)}let l=this._outlineLayer.getEntities()[t].polyline;l?.setPath3v([a]);let h=this._centerLayer.getEntities()[i];if(h){let e=r.scaleTo(.5*o).addA(n);h.setCartesian3v(e),this._checkTerrainCollision(h)}}_moveCornerPoint(e){let t=new ae(e.x,e.y).sub(this._startClick),i=this._startPos.add(t),s=this._planet.getCartesianFromPixelTerrain(i);if(s){this._pickedCorner.setCartesian3v(s);let e=this._cornerLayer.getEntities();if(e.length){let t=this._pickedCorner.layerIndex;0===t?this._moveCorner(t+1,t+1,t):(t===e.length-1||this._moveCorner(t+1,t+1,t),this._moveCorner(t-1,t,t-1))}}}_updateGhostOutlinePointer(e){let t=this._cornerLayer.getEntities(),i=t.length;if(i>0){let e=i-1;this._insertCornerIndex=e;let s=t[e].getCartesian(),n=this._ghostCorner.getCartesian().sub(s),r=n.length();n.normalize();let o=[];for(let e=0;e<=Ks;e++){let t=n.scaleTo(e*r/Ks).addA(s);o.push(t)}this._ghostOutlineLayer.getEntities()[0].polyline.setPath3v([o])}}_initGhostLayerPointer(){this._ghostOutlineLayer.setEntities([new Si({polyline:{path3v:[],isClosed:!1,...tn}}),this._ghostCorner]),this._ghostOutlineLayer.getEntities()[0].polyline.altitude=Qs}}class rn extends Dt{constructor(e={}){super(e),this._drawingScene=new nn({name:`drawingScene:${this.__id}`})}activatePolygonDrawing(){this.deactivate(),this._drawingScene=new sn({name:`polygonDrawingScene:${this.__id}`}),this.activate()}activateLineStringDrawing(){this.deactivate(),this._drawingScene=new nn({name:`linestringDrawingScene:${this.__id}`}),this.activate()}oninit(){}onactivate(){this.planet&&this._drawingScene.bindPlanet(this.planet),this.renderer&&this.renderer.addNode(this._drawingScene)}ondeactivate(){this.renderer&&this.renderer.removeNode(this._drawingScene)}}const on={ell:0,msl:1,gnd:2},an=.3048,ln=1/an,hn=1/3.6,cn=.001*an,dn=1/cn,_n=["m","km","ft","s","h","m/s","km/h","ft/s"],un=[0,2,0,0,0,0,0,0];let gn=[];function fn(e,t,i){return gn[e][t](i)}function pn(e,t,i,s,n){return e?fn(t,i,s).toFixed(n||un[i]):"--"}function mn(e){return _n[e]}gn[0]=[],gn[0][0]=e=>e,gn[0][1]=e=>.001*e,gn[0][2]=e=>e*ln,gn[2]=[],gn[2][0]=e=>e*an,gn[2][1]=e=>e*cn,gn[2][2]=e=>e,gn[1]=[],gn[1][0]=e=>1e3*e,gn[1][1]=e=>e,gn[1][2]=e=>e*dn,gn[5]=[],gn[5][5]=e=>e,gn[5][6]=e=>3.6*e,gn[5][7]=e=>3.28084*e,gn[6]=[],gn[6][5]=e=>e*hn,gn[6][6]=e=>e;var vn=Object.freeze({__proto__:null,ELL:0,GND:2,MSL:1,_tenth:un,convert:fn,convertExt:pn,ft:2,fts:7,h:4,heightMode:on,km:1,kmh:6,m:0,ms:5,s:3,toString:mn});const yn=['<div class="og-lat-side"></div><div class="og-lat-val"></div>\n <div class="og-lon-side"></div><div class="og-lon-val"></div>\n <div class="og-height"></div>\n <div class="og-units-height"></div>','<div class="og-lat-side"></div><div class="og-lat-val"></div>\n <div class="og-lon-side"></div><div class="og-lon-val"></div>\n <div class="og-height"></div>\n <div class="og-units-height"></div>'];class xn extends Dt{constructor(e={}){super(e),this._type=e.type||0,this._TYPE_FUNC=[this._SHOW_DECIMAL,this._SHOW_DEGREE],this._showFn=null,this._el=null,this._latSideEl=null,this._lonSideEl=null,this._latValEl=null,this._lonValEl=null,this._heightEl=null,this._altUnitVal=e.altitudeUnit||"m",this._heightModeVal=e.heightMode||"ell",this._altUnit=vn[this._altUnitVal],this._heightMode=on[this._heightModeVal],this._lonLat=null,this._centerMode=null==e.centerMode||e.centerMode}_SHOW_DECIMAL(e){if(e){let t=e.lat,i=e.lon;this._latSideEl.innerHTML=t>=0?"N":"S",this._lonSideEl.innerHTML=i>=0?"E":"W",this._latValEl.innerHTML=Math.abs(t).toFixed(7)+"°",this._lonValEl.innerHTML=Math.abs(i).toFixed(7)+"°"}}_SHOW_DEGREE(e){if(e){let t=e.lat,i=e.lon;this._latSideEl.innerHTML=t>=0?"N":"S",this._lonSideEl.innerHTML=i>=0?"E":"W";let s=0,n=t<0?Math.ceil(t):Math.floor(t),r=Math.floor(s=60*Math.abs(t-n)),o=Math.floor(6e3*(s-r))/100;this._latValEl.innerHTML=Math.abs(n)+"°"+r+"'"+o.toFixed(0)+'"',n=i<0?Math.ceil(i):Math.floor(i),r=Math.floor(s=60*Math.abs(i-n)),o=Math.floor(6e3*(s-r))/100,this._lonValEl.innerHTML=Math.abs(n)+"°"+r+"'"+o.toFixed(0)+'"'}}_createCenterEl(){let e=document.createElement("div");return e.className="og-center-icon",e.innerHTML='<svg width="12" height="12"><g><path stroke-width="1" stroke-opacity="1" d="M6 0L6 12M0 6L12 6" stroke="#337ab7"></path></g></svg>',e}_updateUnits(){this._heightMode=on[this._heightModeVal],this._altUnit=vn[this._altUnitVal],this._el.querySelector(".og-units-height").innerHTML=mn(this._altUnit),this._showHeight()}_refreshCoordinates(){this._type>=this._TYPE_FUNC.length&&(this._type=0);let e=this._el;e.innerHTML=yn[this._type],this._latSideEl=e.querySelector(".og-lat-side"),this._lonSideEl=e.querySelector(".og-lon-side"),this._latValEl=e.querySelector(".og-lat-val"),this._lonValEl=e.querySelector(".og-lon-val"),this._heightEl=e.querySelector(".og-height"),this._showFn=this._TYPE_FUNC[this._type],this._showFn(this._lonLat)}oninit(){this._el=document.createElement("div"),this._el.classList.add("og-coordinates"),this.renderer.div.appendChild(this._el),this._el.addEventListener("click",(()=>{this._type++,this._refreshCoordinates(),this._updateUnits(),this._showHeight()})),this._centerMode?(this.renderer.div.appendChild(this._createCenterEl()),this.planet.camera.events.on("moveend",this._grabCoordinates,this),this.planet.camera.events.on("moveend",Ne((()=>this._showHeight()),400,!0),this)):(this.renderer.events.on("mousemove",this._grabCoordinates,this),this.renderer.events.on("mousestop",Ne((()=>this._showHeight()),400,!0),this)),this._refreshCoordinates(),this._updateUnits()}_grabCoordinates(e){let t,i=e.pos,s=this.renderer;t=this._centerMode?s.handler.getCenter():i,this._lonLat=this.planet.getLonLatFromPixelTerrain(t)||null,this._showFn(this._lonLat)}async _showHeight(){if(this._lonLat&&this.planet){let e=0;this._heightEl.style.opacity="0.7",this._heightMode===on.ell?(e=await this.planet.getHeightAboveELL(this._lonLat),e=Number(pn(!0,0,this._altUnit,e))):this._heightMode===on.msl&&(e=await this.planet.getHeightDefault(this._lonLat),e=Number(pn(!0,0,this._altUnit,e))),this._heightEl.style.opacity="1.0",this._heightEl.innerHTML=e.toString()}}}const bn=["loadend"];class wn extends $t{constructor(e,t={}){super(e,t),this.events=this.events.registerNames(bn),this._projType=0,this._frameWidth=256,this._frameHeight=256,this._sourceReady=!1,this._sourceTexture=null,this._materialTexture=null,this._gridBufferLow=null,this._gridBufferHigh=null,this._extentWgs84ParamsHigh=new Float32Array(4),this._extentWgs84ParamsLow=new Float32Array(4),this._extentMercParamsHigh=new Float32Array(4),this._extentMercParamsLow=new Float32Array(4),this._refreshFrame=!0,this._frameCreated=!1,this._sourceCreated=!1,this._animate=!1,this._ready=!1,this._creationProceeding=!1,this._isRendering=!1,this._extentWgs84=new te,this._cornersWgs84=[],this._cornersMerc=[],this._isFullExtent=t.fullExtent?1:0,this.rendering=this._renderingProjType0.bind(this),this._onLoadend_=null,t.corners&&this.setCorners(t.corners)}get isIdle(){return super.isIdle&&this._ready}addTo(e){return this._onLoadend_=this._onLoadend.bind(this),this.events.on("loadend",this._onLoadend_,this),super.addTo(e)}_onLoadend(){this._planet&&this._planet.events.dispatch(this._planet.events.layerloadend,this)}remove(){return this.events.off("loadend",this._onLoadend_),this._onLoadend_=null,super.remove()}get instanceName(){return"BaseGeoImage"}getCornersLonLat(){let e=this._cornersWgs84;return[new I(e[0].lon,e[0].lat),new I(e[1].lon,e[1].lat),new I(e[2].lon,e[2].lat),new I(e[3].lon,e[3].lat)]}getCorners(){let e=this._cornersWgs84;return[[e[0].lon,e[0].lat],[e[1].lon,e[1].lat],[e[2].lon,e[2].lat],[e[3].lon,e[3].lat]]}setCorners(e){this.setCornersLonLat(I.join(e))}setCornersLonLat(e){this._refreshFrame=!0,this._cornersWgs84=[e[0].clone(),e[1].clone(),e[2].clone(),e[3].clone()];for(let e=0;e<this._cornersWgs84.length;e++)this._cornersWgs84[e].lat>=89.9&&(this._cornersWgs84[e].lat=89.9),this._cornersWgs84[e].lat<=-89.9&&(this._cornersWgs84[e].lat=-89.9);this._extent.setByCoordinates(this._cornersWgs84);let t=this._extent;t.southWest.lat>Q||t.northEast.lat<J?(this._projType=0,this.rendering=this._renderingProjType0):(this._projType=1,this.rendering=this._renderingProjType1),this._ready&&!this._creationProceeding&&this._planet._geoImageCreator.add(this)}_createFrame(){this._extentWgs84=this._extent.clone(),this._cornersMerc=[this._cornersWgs84[0].forwardMercatorEPS01(),this._cornersWgs84[1].forwardMercatorEPS01(),this._cornersWgs84[2].forwardMercatorEPS01(),this._cornersWgs84[3].forwardMercatorEPS01()],this._extentMerc=new te(this._extentWgs84.southWest.forwardMercatorEPS01(),this._extentWgs84.northEast.forwardMercatorEPS01());let e=new Float32Array(2);if(0===this._projType?(ms(this._extentWgs84.southWest.lon,e),this._extentWgs84ParamsHigh[0]=e[0],this._extentWgs84ParamsLow[0]=e[1],ms(this._extentWgs84.southWest.lat,e),this._extentWgs84ParamsHigh[1]=e[0],this._extentWgs84ParamsLow[1]=e[1],this._extentWgs84ParamsHigh[2]=2/this._extentWgs84.getWidth(),this._extentWgs84ParamsHigh[3]=2/this._extentWgs84.getHeight()):(ms(this._extentMerc.southWest.lon,e),this._extentMercParamsHigh[0]=e[0],this._extentMercParamsLow[0]=e[1],ms(this._extentMerc.southWest.lat,e),this._extentMercParamsHigh[1]=e[0],this._extentMercParamsLow[1]=e[1],this._extentMercParamsHigh[2]=2/this._extentMerc.getWidth(),this._extentMercParamsHigh[3]=2/this._extentMerc.getHeight()),this._planet){let e=this._planet.renderer.handler;e.gl.deleteTexture(this._materialTexture),this._materialTexture=e.createEmptyTexture_l(this._frameWidth,this._frameHeight);let t=this._planet._geoImageCreator.createGridBuffer(this._cornersWgs84,1===this._projType);this._gridBufferHigh=t[0],this._gridBufferLow=t[1],this._refreshFrame=!1}}abortMaterialLoading(e){this._creationProceeding=!1,e.isLoading=!1,e.isReady=!1}clear(){let e=this._planet;if(e){let t=e.renderer.handler.gl;this._creationProceeding&&e._geoImageCreator.remove(this),e._clearLayerMaterial(this),t&&(t.deleteBuffer(this._gridBufferHigh),t.deleteBuffer(this._gridBufferLow),t.deleteTexture(this._sourceTexture),this._materialTexture&&!this._materialTexture.default&&t.deleteTexture(this._materialTexture))}this._sourceTexture=null,this._materialTexture=null,this._gridBufferHigh=null,this._gridBufferLow=null,this._refreshFrame=!0,this._sourceCreated=!1,this._ready=!1,this._creationProceeding=!1}setVisibility(e){e!==this._visibility&&(super.setVisibility(e),this._planet&&this._sourceReady&&(e?this._planet._geoImageCreator.add(this):this._planet._geoImageCreator.remove(this)))}clearMaterial(e){e.texture=null,e.isLoading=!1,e.isReady=!1}applyMaterial(e){let t,i,s=e.segment;this._ready?e.applyTexture(this._materialTexture):(e.texture=this._planet.transparentTexture,!this._creationProceeding&&this.loadMaterial(e)),0===this._projType?(t=this._extentWgs84,i=s._extent):(t=this._extentMerc,i=s.getExtentMerc());let n=t.northEast.lon-t.southWest.lon,r=t.northEast.lat-t.southWest.lat;return[(i.southWest.lon-t.southWest.lon)/n,(t.northEast.lat-i.northEast.lat)/r,(i.northEast.lon-i.southWest.lon)/n,(i.northEast.lat-i.southWest.lat)/r]}get getFrameWidth(){return this._frameWidth}get getFrameHeight(){return this._frameHeight}_createSourceTexture(){}_renderingProjType1(){let e=this._planet,t=e.renderer.handler,i=t.gl,s=e._geoImageCreator;this._refreshFrame&&this._createFrame(),this._createSourceTexture();let n=s._framebuffer;n.setSize(this._frameWidth,this._frameHeight),n.activate(),t.programs.geoImageTransform.activate();let r=t.programs.geoImageTransform._program,o=r.attributes,a=r.uniforms;i.disable(i.CULL_FACE),n.bindOutputTexture(this._materialTexture),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT),i.uniform1i(a.isFullExtent,this._isFullExtent),i.bindBuffer(i.ARRAY_BUFFER,s._texCoordsBuffer),i.vertexAttribPointer(o.texCoords,2,i.UNSIGNED_SHORT,!0,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferHigh),i.vertexAttribPointer(o.cornersHigh,this._gridBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferLow),i.vertexAttribPointer(o.cornersLow,this._gridBufferLow.itemSize,i.FLOAT,!1,0,0),i.uniform4fv(a.extentParamsHigh,this._extentMercParamsHigh),i.uniform4fv(a.extentParamsLow,this._extentMercParamsLow),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this._sourceTexture),i.uniform1i(a.sourceTexture,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,s._indexBuffer),i.drawElements(i.TRIANGLE_STRIP,s._indexBuffer.numItems,i.UNSIGNED_INT,0),n.deactivate(),i.enable(i.CULL_FACE),this._ready=!0,this._creationProceeding=!1}_renderingProjType0(){let e=this._planet,t=e.renderer.handler,i=t.gl,s=e._geoImageCreator;this._refreshFrame&&this._createFrame(),this._createSourceTexture();let n=s._framebuffer;n.setSize(this._frameWidth,this._frameHeight),n.activate(),t.programs.geoImageTransform.activate();let r=t.programs.geoImageTransform._program,o=r.attributes,a=r.uniforms;i.disable(i.CULL_FACE),n.bindOutputTexture(this._materialTexture),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT),i.bindBuffer(i.ARRAY_BUFFER,s._texCoordsBuffer),i.vertexAttribPointer(o.texCoords,2,i.UNSIGNED_SHORT,!0,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferHigh),i.vertexAttribPointer(o.cornersHigh,this._gridBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferLow),i.vertexAttribPointer(o.cornersLow,this._gridBufferLow.itemSize,i.FLOAT,!1,0,0),i.uniform4fv(a.extentParamsHigh,this._extentWgs84ParamsHigh),i.uniform4fv(a.extentParamsLow,this._extentWgs84ParamsLow),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this._sourceTexture),i.uniform1i(a.sourceTexture,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,s._indexBuffer),i.drawElements(i.TRIANGLE_STRIP,s._indexBuffer.numItems,i.UNSIGNED_INT,0),n.deactivate(),i.enable(i.CULL_FACE),this._ready=!0,this._creationProceeding=!1}}const Cn={MB_LEFT:0,MB_RIGHT:2,MB_MIDDLE:1,KEY_CTRL:17,KEY_ALT:18,KEY_SHIFT:16,KEY_SPACE:32,KEY_PGUP:33,KEY_PGDN:34,KEY_LEFT:37,KEY_UP:38,KEY_RIGHT:39,KEY_DOWN:40,KEY_PRINTSCREEN:44,KEY_EQUALS:61,KEY_A:65,KEY_C:67,KEY_D:68,KEY_E:69,KEY_F:70,KEY_H:72,KEY_I:73,KEY_K:75,KEY_L:76,KEY_N:78,KEY_O:79,KEY_P:80,KEY_Q:81,KEY_R:82,KEY_S:83,KEY_V:86,KEY_W:87,KEY_X:88,KEY_Z:90,KEY_PLUS:107,KEY_F1:112,KEY_MINUS:173,KEY_APOSTROPHE:192,KEY_BACK_SLASH:220,KEY_MORE:190,KEY_SLASH:191,KEY_LESS:188,KEY_LEFT_SQUARE_BRACKET:219,KEY_RIGHT_SQUARE_BRACKET:221,KEY_SINGLE_QUOTE:222};const Tn=["change","idle","play","pause","stop"];class En extends kt{constructor(e){super({template:we('<button title={title} class="og-layerSwitcher__layerButton">{icon}<div class="og-layerSwitcher__name">{name}</div></button>',{title:e.model.name,name:e.model.name,icon:e.model.iconSrc?`<img src="${e.model.iconSrc}" />`:""}),...e}),this._onVisibilityChange=e=>{this.el&&(this.model.getVisibility()?this.el.classList.add("og-layerSwitcher__visible"):this.el.classList.remove("og-layerSwitcher__visible"))},this._onClick=()=>{this.model.isBaseLayer()?this.model.setVisibility(!0):this.model.setVisibility(!this.model.getVisibility())},this._onDblClick=()=>{this.model.flyExtent()}}render(e){return super.render(e),this.model.events.on("visibilitychange",this._onVisibilityChange),this._onVisibilityChange(this.model),this.el.addEventListener("click",this._onClick),this.el.addEventListener("dblclick",this._onDblClick),this}remove(){super.remove(),this.model.events.off("visibilitychange",this._onVisibilityChange)}}const Ln=["change"];class An extends kt{constructor(e={}){super({template:we('<div class="og-slider">\n <div class="og-slider-label">{label}</div>\n <div class="og-slider-panel">\n <div class="og-slider-progress"></div> \n <div class="og-slider-pointer"></div>\n </div>\n <input type="number"/>\n </div>',{label:e.label||""})}),this._onResize=()=>{this._setOffset((this._value-this._min)*this.$panel.clientWidth/(this._max-this._min))},this._onMouseWheel=e=>{(e=e||window.event).preventDefault(),e.stopPropagation(),this.value=this._value+Math.sign(e.wheelDelta)*(this._max-this._min)/100},this._onMouseWheelFF=e=>{this._onMouseWheel(e)},this._onInput=e=>{(e=e||window.event).preventDefault(),e.stopPropagation(),this.value=parseFloat(e.target.value)},this._onMouseDown=e=>{(e=e||window.event).preventDefault(),this._startPosX=e.clientX,this.value=this._min+(this._max-this._min)*(e.offsetX/this.$panel.clientWidth),document.addEventListener("mousemove",this._onMouseMove),document.addEventListener("mouseup",this._onMouseUp)},this._onMouseMove=e=>{(e=e||window.event).preventDefault(),e.stopPropagation();let t=this.$panel.getBoundingClientRect(),i=m(e.clientX,t.left,t.right),s=this._startPosX-i;this._startPosX=i,this.value=this._value-s*(this._max-this._min)/this.$panel.clientWidth},this._onMouseUp=()=>{document.removeEventListener("mouseup",this._onMouseUp),document.removeEventListener("mousemove",this._onMouseMove)},this.events=this.events.registerNames(Ln),this._value=e.value||0,this._min=e.min||0,this._max=e.max||1,this._resizeObserver=new ResizeObserver(this._onResize),this._startPosX=0,this.$label=null,this.$pointer=null,this.$progress=null,this.$input=null,this.$panel=null}render(e){return super.render(e),this.$label=this.select(".og-slider-label"),""===this.$label.innerHTML&&(this.$label.style.display="none"),this.$pointer=this.select(".og-slider-pointer"),this.$progress=this.select(".og-slider-progress"),this.$panel=this.select(".og-slider-panel"),this.$input=this.select("input"),this._resizeObserver.observe(this.el),this._initEvents(),this}set value(e){e!==this._value&&(this._value=m(e,this._min,this._max),this.$input.value=this._value.toString(),this._setOffset((this._value-this._min)*this.$panel.clientWidth/(this._max-this._min)),this.events.dispatch(this.events.change,this._value,this))}get value(){return this._value}_initEvents(){this.$panel.addEventListener("mousedown",this._onMouseDown),this.$panel.addEventListener("mousewheel",this._onMouseWheel),this.$panel.addEventListener("wheel",this._onMouseWheelFF),this.$input.addEventListener("input",this._onInput)}_clearEvents(){this.$panel.removeEventListener("mousedown",this._onMouseDown),this.$panel.removeEventListener("mousewheel",this._onMouseWheel),this.$panel.removeEventListener("wheel",this._onMouseWheelFF),this.$input.removeEventListener("input",this._onInput)}_setOffset(e){e>=0&&e<=this.$panel.clientWidth&&(this.$pointer.style.left=this.$progress.style.width=100*e/this.$panel.clientWidth+"%")}remove(){this._clearEvents(),super.remove()}}const Pn=["input"];let Sn=0;class Mn extends kt{constructor(e={}){super({template:we('<div class="og-color">\n <label for="{id}" class="og-color-label">{label}</label>\n <input type="color" name="{id}" value="{value}"/>\n </div>',{id:"color-"+Sn++,label:e.label||"",value:e.value||"#000000"})}),this._onInput=e=>{this.value=e.target.value},this.events=this.events.registerNames(Pn),this._value=e.value||"blue",this.$label=null,this.$input=null}render(e){return super.render(e),this.$label=this.select(".og-color-label"),""===this.$label.innerHTML&&(this.$label.style.display="none"),this.$input=this.select("input"),this._initEvents(),this}set value(e){e!==this._value&&(this._value=e,this.$input.value=this._value,this.events.dispatch(this.events.input,this._value,this))}get value(){return this._value}_initEvents(){this.$input.addEventListener("input",this._onInput)}_clearEvents(){this.$input.removeEventListener("input",this._onInput)}remove(){this._clearEvents(),super.remove()}}class Rn{constructor(){this._lock=0}lock(e){this._lock|=1<<e.id}free(e){this._lock&=~(1<<e.id)}isFree(){return 0===this._lock}isLocked(){return 0!==this._lock}}class Bn{constructor(){this.__id=Bn.__counter__++}get id(){return this.__id}}Bn.__counter__=0;class kn extends Dt{constructor(e={}){super(e),this._deactivate=!1,this._shiftBusy=!1,this._name="mouseNavigation",this.grabbedPoint=new oe,this._eye0=new oe,this.pointOnEarth=new oe,this.earthUp=new oe,this.inertia=.007,this.grabbedSpheroid=new Pt,this.qRot=new re,this.scaleRot=0,this.distDiff=.3,this.stepsCount=8,this.stepsForward=null,this.stepIndex=0,this._lmbDoubleClickActive=!0,this.minSlope=e.minSlope||.1,this._wheelDirection=1,this._keyLock=new Bn}static getMovePointsFromPixelTerrain(e,t,i,s,n,r,o){const a=[];let l=e.eye.clone(),h=e.getBackward(),c=e.getRight(),d=e.getUp(),_=t.getCartesianFromPixelTerrain(n);if(_||(_=t.getCartesianFromPixelTerrain(t.renderer.handler.getCenter())),_){o||(o=oe.sub(_,e.eye).normalize());let t=s*e.eye.distance(_)/i;t*=r?-1.25:2;const n=h.scaleTo(t);if(o.dot(e.eye.normal().negate())>=.1){const t=new Pt;t.radius=_.length();let s=[],r=[],u=!1;for(let e=0;e<i;e++){l.addA(n);const i=new ui(l,o).hitSphere(t);if(r[e]=l.clone(),!i){u=!0;break}s[e]=(new ne).rotateBetweenVectors(_.normal(),i.normal())}if(u){l=e.eye.clone();for(let e=0;e<i;e++)a[e]={eye:l.addA(n).clone(),v:d,u:c,n:h}}else for(let e=0;e<i;e++){let t=s[e];a[e]={eye:t.mulVec3(r[e]),v:t.mulVec3(d),u:t.mulVec3(c),n:t.mulVec3(h)}}}else for(let e=0;e<i;e++)a[e]={eye:l.addA(o.scaleTo(-t)).clone(),v:d,u:c,n:h};return a}}onactivate(){this.renderer&&(this.renderer.events.on("mousewheel",this.onMouseWheel,this),this.renderer.events.on("lhold",this.onMouseLeftButtonDown,this),this.renderer.events.on("rhold",this.onMouseRightButtonDown,this),this.renderer.events.on("ldown",this.onMouseLeftButtonClick,this),this.renderer.events.on("lup",this.onMouseLeftButtonUp,this),this.renderer.events.on("rdown",this.onMouseRightButtonClick,this),this.renderer.events.on("draw",this.onDraw,this,-1e3),this.renderer.events.on("mousemove",this.onMouseMove,this),this.renderer.events.on("mouseleave",this.onMouseLeave,this),this.renderer.events.on("mouseenter",this.onMouseEnter,this),this._lmbDoubleClickActive&&this.renderer.events.on("ldblclick",this.onMouseLeftButtonDoubleClick,this))}ondeactivate(){this.renderer&&(this.renderer.events.off("mousewheel",this.onMouseWheel),this.renderer.events.off("lhold",this.onMouseLeftButtonDown),this.renderer.events.off("rhold",this.onMouseRightButtonDown),this.renderer.events.off("ldown",this.onMouseLeftButtonClick),this.renderer.events.off("lup",this.onMouseLeftButtonUp),this.renderer.events.off("rdown",this.onMouseRightButtonClick),this.renderer.events.off("draw",this.onDraw),this.renderer.events.off("ldblclick",this.onMouseLeftButtonDoubleClick),this.renderer.events.off("mouseleave",this.onMouseLeave),this.renderer.events.off("mouseenter",this.onMouseEnter))}activateDoubleClickZoom(){this._lmbDoubleClickActive||(this._lmbDoubleClickActive=!0,this.renderer&&this.renderer.events.on("ldblclick",this.onMouseLeftButtonDoubleClick,this))}deactivateDoubleClickZoom(){this._lmbDoubleClickActive&&(this._lmbDoubleClickActive=!1,this.renderer&&this.renderer.events.off("ldblclick",this.onMouseLeftButtonDoubleClick))}onMouseEnter(e){const t=this.renderer.events;t.isKeyPressed(Cn.KEY_ALT)&&t.releaseKeys(),t.updateButtonsStates(e.sys.buttons),t.mouseState.leftButtonDown?this.renderer.handler.canvas.classList.add("ogGrabbingPoiner"):this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner")}onMouseLeave(){this.renderer.events.mouseState.leftButtonDown&&(this.scaleRot=0),this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner")}onMouseWheel(e){this.stepIndex||(this.planet.stopFlying(),this.stopRotation(),this._deactivate=!0,this.lockPlanet(!0),this.stepsForward=kn.getMovePointsFromPixelTerrain(this.planet.camera,this.planet,this.stepsCount,this.distDiff,e.pos,e.wheelDelta>0,e.direction)||null,this._wheelDirection=e.wheelDelta,this.stepsForward&&(this.stepIndex=this.stepsCount))}oninit(){this.activate(),this.renderer&&(this.renderer.events.on("keyfree",Cn.KEY_ALT,this.onShiftFree,this),this.renderer.events.on("keyfree",Cn.KEY_PRINTSCREEN,this.onShiftFree,this))}onMouseLeftButtonDoubleClick(e){this.planet.stopFlying(),this.stopRotation();const t=this.planet.getCartesianFromPixelTerrain(e.pos);if(t){const e=this.planet.camera;let i=e.maxAltitude+this.planet.ellipsoid.polarSize,s=e.minAltitude+this.planet.ellipsoid.polarSize;const n=e.eye.length(),r=this.planet.ellipsoid.cartesianToLonLat(t);if(n>i||n<s)return void this.planet.flyLonLat(new I(r.lon,r.lat));this.renderer.events.isKeyPressed(Cn.KEY_ALT)?this.planet.flyLonLat(new I(r.lon,r.lat,2*e.eye.distance(t))):this.planet.flyLonLat(new I(r.lon,r.lat,.57*e.eye.distance(t)))}}onMouseLeftButtonClick(){this._active&&(this.renderer.handler.canvas.classList.add("ogGrabbingPoiner"),this.grabbedPoint=this.planet.getCartesianFromMouseTerrain(),this.grabbedPoint&&(this._eye0.copy(this.planet.camera.eye),this.grabbedSpheroid.radius=this.grabbedPoint.length(),this.stopRotation()))}stopRotation(){this.qRot.clear(),this.freePlanet()}onMouseLeftButtonUp(e){this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner"),e.x===e.prev_x&&e.y===e.prev_y&&(this.scaleRot=0)}onMouseLeftButtonDown(e){if(this._active){if(!this.grabbedPoint)return;if(this.planet.stopFlying(),e.moving){let t=this.planet.camera;if(t.slope>.2){const i=new ui(t.eye,e.direction).hitSphere(this.grabbedSpheroid);if(i){this.scaleRot=1,this.qRot=re.getRotationBetweenVectors(i.normal(),this.grabbedPoint.normal());let e=this.qRot;t.eye=e.mulVec3(t.eye),t.rotate(e)}}else{let i=this.grabbedPoint,s=oe.add(i,t.getRight()),n=oe.add(i,i.normal()),r=new oe;new ui(t.eye,e.direction).hitPlaneRes(_i.fromPoints(i,s,n),r)===ui.INSIDE&&(t.eye=this._eye0.addA(r.subA(i).negate()))}}}}onMouseRightButtonClick(e){this.stopRotation(),this.planet.stopFlying(),this.pointOnEarth=this.planet.getCartesianFromPixelTerrain(e.pos),this.pointOnEarth&&(this.earthUp=this.pointOnEarth.normal())}onMouseRightButtonDown(e){const t=this.planet.camera;if(this.pointOnEarth&&e.moving){this.renderer.controlsBag.scaleRot=1;let i=.5/t.eye.distance(this.pointOnEarth)*t._lonLat.height*l;i>.007?i=.007:i<.003&&(i=.003),t.rotateHorizontal(i*(e.x-e.prev_x),!1,this.pointOnEarth,this.earthUp),t.rotateVertical(i*(e.y-e.prev_y),this.pointOnEarth,this.minSlope)}}onShiftFree(){this._shiftBusy=!1}onMouseMove(e){this._active&&this.renderer.events.isKeyPressed(Cn.KEY_ALT)&&(this._shiftBusy||(this._shiftBusy=!0,this.onMouseRightButtonClick(e)),this.onMouseRightButtonDown(e))}onDraw(){if(this._active){const e=this.renderer,t=this.planet.camera;let i=t.eye.clone();if(this.stepIndex){e.controlsBag.scaleRot=1;const i=this.stepsForward[this.stepsCount-this.stepIndex--];t.eye=i.eye,t._u=i.v,t._r=i.u,t._b=i.n,t._f.set(-t._b.x,-t._b.y,-t._b.z)}else this._deactivate&&(this._deactivate=!1,this.freePlanet());if(e.events.mouseState.leftButtonDown||!this.scaleRot)return;if(this.scaleRot-=this.inertia,this.scaleRot<=0)this.scaleRot=0;else{e.controlsBag.scaleRot=this.scaleRot;let i=this.qRot.slerp(re.IDENTITY,1-this.scaleRot*this.scaleRot*this.scaleRot).normalize();i.x||i.y||i.z||(this.scaleRot=0),t.eye=i.mulVec3(t.eye),t.rotate(i)}t.eye.distance(i)/t.getAltitude()>.01?this.lockPlanet():this.freePlanet()}}lockPlanet(e){this.planet.layerLock.lock(this._keyLock),!e&&this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock)}freePlanet(){this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock)}}const In=.96;class zn extends Dt{constructor(e={}){super({name:"mouseNavigation",autoActivate:!0,...e}),this._shiftBusy=!1,this._hold=!1,this._prevVel=new oe,this._screenPosIsChanged=!0,this._onShiftFree=()=>{this._shiftBusy=!1},this._onMouseMove=e=>{this._active&&this.renderer.events.isKeyPressed(Cn.KEY_ALT)&&(this._shiftBusy||(this._shiftBusy=!0,this._onRHold(e)),this._onRDown(e))},this._onMouseEnter=e=>{const t=this.renderer.events;t.isKeyPressed(Cn.KEY_ALT)&&t.releaseKeys(),t.updateButtonsStates(e.sys.buttons),t.mouseState.leftButtonDown?this.renderer.handler.canvas.classList.add("ogGrabbingPoiner"):this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner")},this._onMouseLeave=()=>{this.renderer.events.mouseState.leftButtonDown&&this.vel.scale(0),this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner")},this._onRHold=e=>{this._targetRotationPoint&&(this._velInertia=.8,this.force_h=.2*(e.x-e.prev_x),this.force_v=.2*(e.y-e.prev_y))},this._onRDown=e=>{this.planet&&(this.planet.stopFlying(),this._targetRotationPoint=this._getTargetPoint(e.pos),this._targetRotationPoint&&(this._targetZoomPoint=null,this._targetDragPoint=null,this.vel.set(0,0,0),this._tUp=this._targetRotationPoint.getNormal(),this._tRad=this.planet.camera.eye.distance(this._targetRotationPoint)))},this._onMouseWheel=e=>{if(this.planet){this._targetRotationPoint=null,this._targetDragPoint=null;let t=this._getTargetPoint(e.pos);if(!t)return;if(this._targetZoomPoint=t,this._grabbedSphere.radius=this._targetZoomPoint.length(),this._curPitch=this.planet.camera.getPitch(),this._curYaw=this.planet.camera.getYaw(),this._curRoll=this.planet.camera.getRoll(),Math.sign(e.wheelDelta)!==this._wheelDirection)return this.vel.scale(.3),this._currScreenPos.set(e.x,e.y),void(this._wheelDirection=Math.sign(e.wheelDelta));this._currScreenPos.set(e.x,e.y),this._wheelDirection=Math.sign(e.wheelDelta);let i=2;this._isTouchPad=e.isTouchPad,e.isTouchPad?(this._velInertia=.88,i=.5):this._velInertia=In;let s=this.planet.camera.eye.distance(this._targetZoomPoint)*i;this.force=e.direction.scale(Math.sign(this._wheelDirection)).normalize().scale(s),this.force_roll=this._curRoll}},this._onLDown=e=>{this.stop(),this._targetRotationPoint=null,this._targetZoomPoint=null,this.planet&&(this.planet.stopFlying(),this._grabbedPoint=this._getTargetPoint(e.pos),this._grabbedPoint&&(this.renderer.handler.canvas.classList.add("ogGrabbingPoiner"),this._grabbedSphere.radius=this._grabbedPoint.length(),this._eye0=this.planet.camera.eye.clone(),this._grabbedCameraHeight=this._eye0.length(),this._curPitch=this.planet.camera.getPitch(),this._curYaw=this.planet.camera.getYaw(),this._curRoll=this.planet.camera.getRoll(),this._currScreenPos.copy(e.pos),this.planet.camera.getUp().dot(new oe(0,0,1))>.3&&(this.fixedUp=!0)))},this._onLHold=e=>{if(this._grabbedPoint&&this.planet){let t=this.planet.camera;if(t.slope>.2){let i=new ui(t.eye,e.direction).hitSphere(this._grabbedSphere);if(!i)return;this._targetDragPoint=i;let s=new oe,n=re.getRotationBetweenVectors(this._targetDragPoint.getNormal(),this._grabbedPoint.getNormal());s.copy(n.mulVec3(t.eye)),this.force=s.sub(t.eye).scale(70)}else{let i=this._grabbedPoint,s=oe.add(i,t.getRight()),n=oe.add(i,i.getNormal()),r=new oe;new ui(t.eye,e.direction).hitPlaneRes(_i.fromPoints(i,s,n),r);let o=t.eye.add(r.subA(i).negate());this.force=o.sub(t.eye).scale(70),this._targetDragPoint=r}this.vel.set(0,0,0),this._currScreenPos.equal(e.pos)||(this._screenPosIsChanged=!0,this._currScreenPos.copy(e.pos)),this._hold=!0}},this._onLUp=e=>{this._hold=!1,this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner")},this.speed=e.speed||1,this.force=new oe,this.force_h=0,this.force_v=0,this.vel=new oe,this.vel_h=0,this.vel_v=0,this.vel_roll=0,this.force_roll=0,this.mass=1,this._velInertia=In,this._lookPos=void 0,this._grabbedPoint=null,this._targetZoomPoint=null,this._targetDragPoint=null,this._targetRotationPoint=null,this._tUp=new oe,this._tRad=0,this._rotHDir=0,this._rotVDir=0,this._wheelDirection=1,this._currScreenPos=new ae,this._grabbedSphere=new Pt,this.fixedUp=null==e.fixedUp||e.fixedUp,this._rot=new re,this._curPitch=0,this._curYaw=0,this._curRoll=0,this._eye0=new oe,this._newEye=new oe,this._grabbedCameraHeight=0,this._isTouchPad=!1}oninit(){this.renderer&&(this.renderer.events.on("keyfree",Cn.KEY_ALT,this._onShiftFree),this.renderer.events.on("keyfree",Cn.KEY_PRINTSCREEN,this._onShiftFree))}onactivate(){super.onactivate();let e=this.renderer;e.events.on("mousewheel",this._onMouseWheel),e.events.on("rhold",this._onRHold),e.events.on("rdown",this._onRDown),e.events.on("lhold",this._onLHold),e.events.on("ldown",this._onLDown),e.events.on("lup",this._onLUp),e.events.on("draw",this.onDraw,this,-1e3),e.events.on("mousemove",this._onMouseMove),e.events.on("mouseleave",this._onMouseLeave),e.events.on("mouseenter",this._onMouseEnter)}ondeactivate(){super.ondeactivate();let e=this.renderer;e.events.off("mousewheel",this._onMouseWheel),e.events.off("rhold",this._onRHold),e.events.off("rdown",this._onRDown),e.events.off("lhold",this._onLHold),e.events.off("ldown",this._onLDown),e.events.off("lup",this._onLUp),e.events.off("draw",this.onDraw),e.events.off("mousemove",this._onMouseMove),e.events.off("mouseleave",this._onMouseLeave),e.events.off("mouseenter",this._onMouseEnter)}onDraw(){this._updateVel(),this._handleZoom(),this._handleDrag(),this._handleRotation()}_handleRotation(){if(this.planet&&this._targetRotationPoint){let e=this.planet.camera,t=this.vel_h*this.dt,i=this.vel_v*this.dt;e.rotateHorizontal(t,!1,this._targetRotationPoint,this._tUp),e.rotateVertical(i,this._targetRotationPoint,.1),this._curPitch=e.getPitch(),this._curYaw=e.getYaw(),this._curRoll=e.getRoll(),this._velInertia=In}}_getTargetPoint(e){return this.planet?this.planet.camera.getAltitude()>1e4?this.planet.getCartesianFromPixelEllipsoid(e)||null:this.planet.getCartesianFromPixelTerrain(e)||null:null}_handleDrag(){if(this.planet&&this._targetDragPoint&&this._grabbedPoint&&this.vel.length()>0){this._velInertia=In;let e=this.planet.camera;if(Math.abs(e.eyeNorm.dot(oe.NORTH))>.9&&(this.fixedUp=!1),this._screenPosIsChanged||this.vel.length()>this._prevVel.length()&&(this.fixedUp=!1),this._screenPosIsChanged=!1,this._prevVel.copy(this.vel),e.slope>.2){let t=this.vel.scaleTo(this.dt),i=oe.proj_b_to_plane(t,e.eyeNorm),s=e.eye.add(i).normalize().scale(this._grabbedCameraHeight);if(this.fixedUp)e.eye.copy(s),this._corrRoll(),e.setPitchYawRoll(this._curPitch,this._curYaw,this._curRoll);else{let t=re.getRotationBetweenVectors(e.eye.getNormal(),s.getNormal());e.rotate(t),e.eye.copy(s)}}else{let t=this.vel.scaleTo(this.dt),i=e.eye.add(t);e.eye.copy(i),e.checkTerrainCollision()}}}_corrRoll(){this.planet.camera.slope<.5&&(this._curRoll-=this.vel_roll*this.dt,this._curRoll<.01*Math.PI/180&&(this._curRoll=.01*Math.PI/180))}_handleZoom(){if(this._targetZoomPoint&&this.vel.length()>0){let e=this.planet.camera,t=this._targetZoomPoint,i=t.sub(e.eye).normalize(),s=e.eye.clone(),n=Math.sign(this.vel.getNormal().dot(e.getForward())),r=this.vel.scaleTo(this.dt).projToVec(e.getForward().scale(n)),o=e.eye.distance(t);if(10*r.length()>o){let e=r.length();r.normalize().scale(.5*e),this.vel.scale(.5)}s.addA(r);let a=e.maxAltitude+this.planet.ellipsoid.getEquatorialSize();if(s.length()>a)return void s.copy(s.getNormal().scale(a));let l=new ui(s,i).hitSphere(this._grabbedSphere);if(!l)return void this.vel.set(0,0,0);let h=re.getRotationBetweenVectors(l.getNormal(),t.getNormal());if(e.eye=h.mulVec3(s),e.rotate(h),this.fixedUp){this._corrRoll(),e.setPitchYawRoll(this._curPitch,this._curYaw,this._curRoll),e.update();let i=e.unproject2v(this._currScreenPos),s=t.sub(e.eye).normalize(),n=new oe,r=new oe,o=_i.fromPoints(t,t.add(e.getUp()),t.add(e.getRight()));new ui(e.eye,i).hitPlaneRes(o,n),new ui(e.eye,s).hitPlaneRes(o,r);let a=r.sub(n);e.eye=e.eye.add(a)}e.checkTerrainCollision()}}_updateVel(){let e=this.force.scale(1/this.mass);this.vel.addA(e),this.vel.scale(this._velInertia),this.vel.length()<.001&&this.vel.set(0,0,0),this.force.set(0,0,0),this._updateVel_h(),this._updateVel_v(),this._updateVel_roll()}_updateVel_h(){let e=this.force_h/this.mass;this.vel_h+=e,this.vel_h*=this._velInertia,this.force_h=0}_updateVel_v(){let e=this.force_v/this.mass;this.vel_v+=e,this.vel_v*=this._velInertia,this.force_v=0}_updateVel_roll(){let e=this.force_roll/this.mass;this.vel_roll+=e,this.vel_roll*=this._velInertia,this.force_roll=0}get dt(){return.001*this.renderer.handler.deltaTime}stop(){this.vel.set(0,0,0),this.vel_h=0,this.vel_v=0,this._velInertia=In,this._targetZoomPoint=null,this._grabbedPoint=null,this._targetRotationPoint=null,this._targetDragPoint=null}}const Dn=e=>e>1e3?`${(e/1e3).toFixed(1)} km`:e>9?`${Math.round(e)} m`:`${e.toFixed(1)} m`;let Fn=mi.createCylinder(1.1,0,2.7,20,1,!0,!1,0,0,0);const Nn={text:"",size:11,color:"rgba(455,455,455,1.0)",outlineColor:"rgba(0,0,0,0.34)",outline:.23,align:"center",offset:[0,20,0]},Hn={scale:1,instanced:!0,tag:"ruler",color:"rgb(0,305,0)",object3d:Fn};class On extends Ri{constructor(e={}){super(e.name),this._onCornerLdown=e=>{if(!this._startLonLat){this.renderer?.controls.mouseNavigation?.deactivate(),this._startClick.set(e.x,e.y);let t=e.pickingObject.getCartesian();this._startPos=this._planet.getPixelFromCartesian(t),this._pickedCorner=e.pickingObject,"start"==e.pickingObject.properties.name?this._anchorLonLat=this._cornerEntity[1].getLonLat().clone():this._anchorLonLat=this._cornerEntity[0].getLonLat().clone()}},this._onLUp=()=>{this._pickedCorner&&(this.renderer.controls.mouseNavigation?.activate(),this._pickedCorner=null,this._anchorLonLat=null)},this._onCornerLup=()=>{this._onLUp()},this._onCornerEnter=e=>{e.renderer.handler.canvas.style.cursor="pointer"},this._onCornerLeave=e=>{e.renderer.handler.canvas.style.cursor="default"},this._onLdblclick=()=>{this._preventClick=!0},this._onLclick=e=>{let t=this._planet.getLonLatFromPixelTerrain(e.pos);t&&(this._timeout=setTimeout((()=>{this._preventClick||(this._startLonLat?this._startLonLat=null:(this.setVisibility(!0),this._stopDrawing=!1,this._startLonLat=t)),this._preventClick=!1,this._stopDrawing=!1,clearTimeout(this._timeout)}),200),this._startLonLat&&(this._stopDrawing=!0))},this._onMouseMove=e=>{if(this._startLonLat&&!this._stopDrawing){this._propsLabel.label.setVisibility(!0);let t=this._planet.getLonLatFromPixelTerrain(e.pos);if(!t)return;this._drawLine(this._startLonLat,t)}else if(this._pickedCorner){let t=this._planet.getLonLatFromPixelTerrain(e.pos);t&&("start"===this._pickedCorner.properties.name?this._drawLine(t,this._anchorLonLat):this._drawLine(this._anchorLonLat,t))}},this.events=Mt(Vn),this._ignoreTerrain=null==e.ignoreTerrain||e.ignoreTerrain,this._planet=e.planet||null,this._startLonLat=null,this._preventClick=!1,this._stopDrawing=!1,this._pickedCorner=null,this._startPos=null,this._startClick=new ae,this._anchorLonLat=null,this._heading=0,this._trackLayer=new qs("track",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-1,relativeToGround:!0,hideInLayerSwitcher:!0}),this._labelLayer=new qs("ruler-label",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-100,relativeToGround:!0,hideInLayerSwitcher:!0}),this._cornersLayer=new qs("corners",{entities:[],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[100,4e6,1],pickingScale:2}),this._propsLabel=new Si({name:"propsLabel",label:Nn}),this._trackEntity=new Si({polyline:{path3v:[],thickness:4.8,color:"rgb(255,131,0)",isClosed:!1}}),this._trackEntity.polyline.altitude=.01,this._cornerEntity=[new Si({geoObject:Hn,properties:{name:"start"}}),new Si({geoObject:Hn,properties:{name:"end"}})]}set ignoreTerrain(e){this._ignoreTerrain=e}bindPlanet(e){this._planet=e}_createCorners(){this._cornersLayer.addEntities(this._cornerEntity)}init(){this._createCorners(),this._trackLayer.addEntities([this._trackEntity]),this._labelLayer.addEntities([this._propsLabel]),this._planet.addLayer(this._labelLayer),this._planet.addLayer(this._trackLayer),this._planet.addLayer(this._cornersLayer),this._activate()}onremove(){this._deactivate()}_activate(){this._propsLabel.label.setVisibility(!1),this.setVisibility(!1),this.renderer.events.on("lclick",this._onLclick,this),this.renderer.events.on("mousemove",this._onMouseMove,this),this.renderer.events.on("ldblclick",this._onLdblclick,this),this.renderer.events.on("lup",this._onLUp,this),this._cornersLayer.events.on("mouseenter",this._onCornerEnter,this),this._cornersLayer.events.on("mouseleave",this._onCornerLeave,this),this._cornersLayer.events.on("ldown",this._onCornerLdown,this),this._cornersLayer.events.on("lup",this._onCornerLup,this)}_deactivate(){this._startLonLat=null,this._preventClick=!1,this._stopDrawing=!1,this._pickedCorner=null,this.renderer.events.off("lclick",this._onLclick),this.renderer.events.off("mousemove",this._onMouseMove),this.renderer.events.off("lup",this._onLUp),this._cornersLayer.events.off("mouseenter",this._onCornerEnter),this._cornersLayer.events.off("mouseleave",this._onCornerLeave),this._cornersLayer.events.off("ldown",this._onCornerLdown),this._cornersLayer.events.off("lup",this._onCornerLup),this.clear()}setVisibility(e){this._cornersLayer.setVisibility(e),this._trackLayer.setVisibility(e),this._labelLayer.setVisibility(e)}_drawLine(e,t,i){i||(i=this._planet.ellipsoid.lonLatToCartesian(e));let s=this._planet.ellipsoid.lonLatToCartesian(t),n=this._planet.ellipsoid.inverse(e,t),r=n.distance;this._heading=n.initialAzimuth;let o=[],a=s.sub(i),l=a.length();a.normalize();for(let e=0;e<120;e++){let t=a.scaleTo(e*l/120).addA(i);o.push(t)}o.push(s),this._trackEntity.polyline.setPath3v([o]),this._ignoreTerrain&&(this._propsLabel.setCartesian3v(o[Math.floor(o.length/2)]),this._propsLabel.label.setText(`${Dn(r)}, ${Math.round(this._heading)} deg`))}clear(){this._trackEntity.remove(),this._cornerEntity[0].remove(),this._cornerEntity[1].remove(),this._propsLabel.remove(),this._planet.removeLayer(this._trackLayer),this._planet.removeLayer(this._cornersLayer)}isCornersPositionChanged(){let e=this._trackEntity.polyline.getPath3v()[0];if(e){const t=e[0].clone(),i=e[e.length-1].clone();return this._cornerEntity[0].getCartesian().equal(t)&&this._cornerEntity[1].getCartesian().equal(i)}return!1}frame(){let e=this._trackEntity.polyline.getPath3v()[0];if(e){const t=e[0].clone(),i=e[e.length-1].clone();if(!this.isCornersPositionChanged()&&(this._cornerEntity[0].setCartesian3v(t),this._cornerEntity[1].setCartesian3v(i),!this._ignoreTerrain)){let t=0;for(let i=0,s=e.length-1;i<s;i++)t+=e[i+1].distance(e[i]);this._propsLabel.setCartesian3v(e[Math.floor(e.length/2)]),this._propsLabel.label.setText(`${Dn(t)}, ${Math.round(this._heading)} deg`)}}}get ellipsoid(){return this._planet?this._planet.ellipsoid:null}}const Vn=["add","remove","mousemove","mouseenter","mouseleave","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchmove","touchstart","touchend","doubletouch","touchleave","touchenter"];class Un extends Dt{constructor(e={}){super(e),this._rulerScene=new On({name:`rulerScene:${this.__id}`,ignoreTerrain:e.ignoreTerrain})}set ignoreTerrain(e){this._rulerScene.ignoreTerrain=e}oninit(){this._rulerScene.bindPlanet(this.planet)}onactivate(){this.renderer&&this.renderer.addNode(this._rulerScene)}ondeactivate(){this.renderer&&this.renderer.removeNode(this._rulerScene)}}let Gn=mi.createCylinder(1.1,0,2,6,1,!0,!0,0,0,0);const Yn={startColor:"rgb(255,131,0)",endColor:"rgb(255,131,0)",thickness:5},jn={text:"",size:11,color:"rgba(455,455,455,1.0)",outlineColor:"rgba(0,0,0,0.34)",outline:.23,align:"center",offset:[0,18,0]},Wn={scale:1,instanced:!0,tag:"height-ruler",color:"rgb(255,131,0)",object3d:Gn};class qn extends On{constructor(e={}){super(e),this._geoRulerLayer=new qs("rayHeightRuler",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-2,relativeToGround:!1,hideInLayerSwitcher:!0}),this._rayV=new Si({name:"verticalRay",ray:Yn}),this._rayH=new Si({name:"heightRay",ray:Yn}),this._heightLabels=[new Si({name:"startCornerLabel",label:{...jn}}),new Si({name:"endCornerLabel",label:{...jn}}),new Si({name:"deltaLabel",label:{...jn}})]}setVisibility(e){super.setVisibility(e),this._geoRulerLayer.setVisibility(e)}get deltaLabel(){return this._heightLabels[2]}get startLabel(){return this._heightLabels[0]}get endLabel(){return this._heightLabels[1]}get corners(){return this._cornerEntity}get startCorner(){return this.corners[0]}get endCorner(){return this.corners[1]}get startCornerLonLat(){return this.startCorner.getLonLat()}get startCornerHeight(){return this.startCornerLonLat.height}get endCornerLonLat(){return this.endCorner.getLonLat()}get endCornerHeight(){return this.endCornerLonLat.height}get maxHeightCornerLonLat(){return this.startCornerHeight<=this.endCornerHeight?this.endCornerLonLat:this.startCornerLonLat}get minHeightCornerLonLat(){return this.startCornerHeight>this.endCornerHeight?this.endCornerLonLat:this.startCornerLonLat}get deltaHeight(){return Math.abs(this.startCornerHeight-this.endCornerHeight)}_drawLine(e,t,i){super._drawLine(e,t,i),this._updateHeightRaysAndLabels()}async _updateHeightRaysAndLabels(){const e=this.minHeightCornerLonLat.clone();e.height=this.maxHeightCornerLonLat.height,this._rayH.ray.setStartPosition3v(this._planet.ellipsoid.lonLatToCartesian(this.maxHeightCornerLonLat)),this._rayH.ray.setEndPosition3v(this._planet.ellipsoid.lonLatToCartesian(e)),this._rayV.ray.setStartPosition3v(this._planet.ellipsoid.lonLatToCartesian(this.minHeightCornerLonLat)),this._rayV.ray.setEndPosition3v(this._planet.ellipsoid.lonLatToCartesian(e)),e.height=this.minHeightCornerLonLat.height+this.deltaHeight/2,this.deltaLabel.setLonLat(e),this.startLabel.setLonLat(this.startCornerLonLat),this.endLabel.setLonLat(this.endCornerLonLat);const t=await this._planet.getHeightDefault(this.startCornerLonLat),i=await this._planet.getHeightDefault(this.endCornerLonLat);this.deltaLabel.label.setText(`Δ ${Math.abs(t-i).toFixed(1)} m`),this.startLabel.label.setText(`P1 ${t.toFixed(1)} m`),this.endLabel.label.setText(`P2 ${i.toFixed(1)} m`)}clear(){this._rayH.remove(),this._rayV.remove(),this.startCorner.remove(),this.endCorner.remove(),this.startLabel.remove(),this.endLabel.remove(),this.deltaLabel.remove(),super.clear(),this._planet.removeLayer(this._geoRulerLayer)}_createCorners(){this._cornerEntity=[new Si({geoObject:Wn,properties:{name:"start"}}),new Si({geoObject:Wn,properties:{name:"end"}})],this._cornersLayer.setEntities(this._cornerEntity)}init(){super.init(),this._createCorners(),this._labelLayer.addEntities(this._heightLabels),this._geoRulerLayer.addEntities([this._rayH,this._rayV]),this._planet.addLayer(this._geoRulerLayer)}frame(){super.frame(),this._updateHeightRaysAndLabels()}}class $n extends Un{constructor(e={}){super(e),this._rulerScene=new qn({name:`heightRulerScene:${this.__id}`,ignoreTerrain:!1})}}const Xn=[.001,.005,.01,.05,.1,.2,.5,1,2,3,5,10,20,30,50,100,200,300,500,1e3,2e3,3e3,5e3,1e4,2e4,3e4,5e4,1e5,2e5,3e5,5e5,1e6,2e6,3e6,5e6,1e7];class Zn extends Dt{constructor(e={}){e.name&&""!==e.name||(e.name="scaleControl"),super(e),this._template='<div class="og-scale-container">\n <div class="og-scale-label"></div>\n <div class="og-scale-ruler"></div>\n </div>',this._minWidth=100,this._maxWidth=150,this._isCenter=null==e.isCenter||e.isCenter,this._mPx=0,this.currWidth=0,this._metersInMinSize=0,this.el=null,this._scaleLabelEl=null}_renderTemplate(){return Ce(this._template)[0]}oninit(){this.el=this._renderTemplate(),this._scaleLabelEl=this.el.querySelector(".og-scale-label"),this.renderer.div.appendChild(this.el),this._isCenter?(this.planet.camera.events.on("moveend",(()=>{this._drawScreen(this.planet.renderer.handler.getCenter())})),!this.planet.terrain.isEmpty&&this.planet.terrain.events.on("loadend",(()=>{this._drawScreen(this.planet.renderer.handler.getCenter())}))):(this.renderer.events.on("mousemove",(e=>{e.leftButtonHold||e.rightButtonHold||this._drawScreen(e.pos)})),this.planet.camera.events.on("moveend",(()=>{let e=this.renderer.events.mouseState;e.leftButtonHold||e.rightButtonHold||this._drawScreen(e.pos)})))}_drawScreen(e){let t=this.planet.camera,i=e,s=this.planet.getDistanceFromPixel(i)||0;0===s&&(i=t.project3v(oe.ZERO),s=this.planet.getDistanceFromPixel(i)||0);let n=t.getForward().scaleTo(s).addA(t.eye),r=s*Math.tan(t.viewAngle*l),o=n.add(t.getRight().scaleTo(r)),a=t.project3v(o);this._mPx=r/a.distance(i);let h=this._mPx*this._minWidth,c=ke(Xn,h,((e,t)=>e-t));c<0&&(c=~c);let d=Xn[c],_=(d-h)/(Xn[c+1]-d);this.currWidth=this._minWidth+_*(this._maxWidth-this._minWidth),this._scaleLabelEl.innerText=d>=1e3?d/1e3+" km":d>=1?`${d} m`:d>=.01?100*d+" cm":1e3*d+" mm",this._metersInMinSize=h,this.el.style.width=this.currWidth+"px"}}class Kn extends Dt{constructor(e={}){super({name:"SimpleSkyBackground",...e}),this._colorOne=new Float32Array([128/255,223/255,1]),this._colorTwo=new Float32Array([10/255,15/255,56/255])}get colorOne(){let e=this._colorOne;return ve([Math.round(255*e[0]),Math.round(255*e[1]),Math.round(255*e[2])])}get colorTwo(){let e=this._colorTwo;return ve([Math.round(255*e[0]),Math.round(255*e[1]),Math.round(255*e[2])])}set colorOne(e){let t=be(e);this._colorOne[0]=t.x,this._colorOne[1]=t.y,this._colorOne[2]=t.z}set colorTwo(e){let t=be(e);this._colorTwo[0]=t.x,this._colorTwo[1]=t.y,this._colorTwo[2]=t.z}oninit(){this.renderer.handler.addProgram(new Ni("simpleSkyBackground",{uniforms:{iResolution:"vec2",fov:"float",camPos:"vec3",earthRadius:"float",viewMatrix:"mat4",colorOne:"vec3",colorTwo:"vec3"},attributes:{corners:"vec3"},vertexShader:"attribute vec2 corners;\n \n varying vec2 tc;\n \n void main(void) {\n gl_Position = vec4(corners, 0.0, 1.0);\n tc = corners * 0.5 + 0.5;\n }",fragmentShader:"precision highp float;\n \n #define MAX 10e10\n #define PI 3.14159265359\n #define rad(x) x * PI / 180.\n #define ZERO vec3(0.0) \n \n #define RED vec4(1.0, 0.0, 0.0, 1.0)\n #define GREEN vec4(0.0, 1.0, 0.0, 1.0) \n \n uniform vec3 camPos; \n uniform vec2 iResolution;\n uniform float fov;\n uniform float earthRadius;\n uniform mat4 viewMatrix;\n \n uniform vec3 colorOne;\n uniform vec3 colorTwo;\n \n varying vec2 tc;\n \n // compute the view ray in the camera coordinate\n vec3 computeView(vec2 uv){\n float w_h_ratio = iResolution.x / iResolution.y; \n float h = tan(rad(fov/2.));\n return normalize(vec3(-w_h_ratio * h, -h, -1.) + vec3(uv.x * 2. * h * w_h_ratio, uv.y*2.*h, 0.));\n }\n\n // sphere of size ra centered at point ce\n vec2 sphIntersect( in vec3 ro, in vec3 rd, in vec3 ce, float ra )\n {\n vec3 oc = ro - ce;\n float b = dot( oc, rd );\n float c = dot( oc, oc ) - ra * ra;\n float h = b * b - c;\n if( h < 0.0 ) return vec2(MAX); // no intersection\n h = sqrt( h );\n return vec2( -b-h, -b+h );\n }\n \n mat3 transpose(mat3 matrix) {\n vec3 row0 = matrix[0];\n vec3 row1 = matrix[1];\n vec3 row2 = matrix[2];\n mat3 result = mat3(\n vec3(row0.x, row1.x, row2.x),\n vec3(row0.y, row1.y, row2.y),\n vec3(row0.z, row1.z, row2.z)\n );\n return result;\n }\n \n float det(mat2 matrix) {\n return matrix[0].x * matrix[1].y - matrix[0].y * matrix[1].x;\n }\n \n mat3 inverse(mat3 matrix) {\n vec3 row0 = matrix[0];\n vec3 row1 = matrix[1];\n vec3 row2 = matrix[2];\n \n vec3 minors0 = vec3(\n det(mat2(row1.y, row1.z, row2.y, row2.z)),\n det(mat2(row1.z, row1.x, row2.z, row2.x)),\n det(mat2(row1.x, row1.y, row2.x, row2.y))\n );\n vec3 minors1 = vec3(\n det(mat2(row2.y, row2.z, row0.y, row0.z)),\n det(mat2(row2.z, row2.x, row0.z, row0.x)),\n det(mat2(row2.x, row2.y, row0.x, row0.y))\n );\n vec3 minors2 = vec3(\n det(mat2(row0.y, row0.z, row1.y, row1.z)),\n det(mat2(row0.z, row0.x, row1.z, row1.x)),\n det(mat2(row0.x, row0.y, row1.x, row1.y))\n );\n \n mat3 adj = transpose(mat3(minors0, minors1, minors2));\n \n return (1.0 / dot(row0, minors0)) * adj;\n }\n \n void main(void) {\n \n vec3 dir = computeView(tc);\n dir = inverse(mat3(viewMatrix)) * dir;\n \n vec2 ER = sphIntersect(camPos, dir, vec3(0.0), earthRadius);\n \n float bigRadius = earthRadius * 2.5;\n vec3 bigCenter = normalize(camPos) * bigRadius * 1.3; \n \n vec2 BIG = sphIntersect(camPos, dir, bigCenter, bigRadius);\n \n float Ix = distance(camPos + dir * BIG.y, ZERO); \n \n float maxI = sqrt(bigRadius * bigRadius + bigRadius * bigRadius);\n \n gl_FragColor = vec4(mix(colorOne, colorTwo, Ix / maxI), 1.0);\n }"})),this.activate()}onactivate(){super.onactivate(),this.planet.events.on("draw",this._drawBackground,this)}ondeactivate(){super.ondeactivate(),this.planet.events.off("draw",this._drawBackground)}_drawBackground(){let e=this.renderer.handler,t=e.programs.simpleSkyBackground,i=t._program,s=i.uniforms,n=e.gl,r=this.planet.camera;n.disable(n.DEPTH_TEST),t.activate(),n.bindBuffer(n.ARRAY_BUFFER,this.renderer.screenFramePositionBuffer),n.vertexAttribPointer(i.attributes.corners,2,n.FLOAT,!1,0,0),n.uniform3fv(s.camPos,[r.eye.x,r.eye.y,r.eye.z]),n.uniform2fv(s.iResolution,[e.getWidth(),e.getHeight()]),n.uniform1f(s.fov,r.getViewAngle()),n.uniform1f(s.earthRadius,this.planet.ellipsoid.getPolarSize()+1),n.uniform3fv(s.colorOne,this._colorOne),n.uniform3fv(s.colorTwo,this._colorTwo),n.uniformMatrix4fv(s.viewMatrix,!1,r.getViewMatrix()),n.drawArrays(n.TRIANGLE_STRIP,0,4),n.enable(n.DEPTH_TEST)}}const Qn=14959787e4;function Jn(e){var i=e-ft,s=282.9404+470935e-10*i,n=.016709-1.151e-9*i,r=A(356.047+.9856002585*i),o=23.4392911-3.563e-7*i,a=r+h*n*Math.sin(r*l)*(1+n*Math.cos(r*l)),c=Math.cos(a*l)-n,d=Math.sin(a*l)*Math.sqrt(1-n*n),_=Math.sqrt(c*c+d*d),u=A(Math.atan2(d,c)*h+s),g=c=_*Math.cos(u*l),f=(d=_*Math.sin(u*l))*Math.cos(o*l),p=d*Math.sin(o*l),m=t*(24*i/23.9344694-259.853/360);return re.zRotation(-m).mulVec3(new oe(-g*Qn,-f*Qn,p*Qn))}class er{constructor(e){this._renderNode=null,this._position=e.position||new oe,this._ambient=e.ambient||new oe,this._diffuse=e.diffuse||new oe(.8,.8,.8),this._specular=e.specular||new oe(.18,.18,.18),this._shininess=null!=e.shininess?e.shininess:3.3,this._active=!0,this._tempAmbient=this._ambient.clone(),this._tempDiffuse=this._diffuse.clone(),this._tempSpecular=this._specular.clone(),this._tempShininess=this._shininess}isActive(){return this._active}setPosition3v(e){this.setPosition(e.x,e.y,e.z)}setPosition(e,t,i){this._position.x=e,this._position.y=t,this._position.z=i,this._renderNode&&(this._renderNode._lightPosition[0]=e,this._renderNode._lightPosition[1]=t,this._renderNode._lightPosition[2]=i)}getPosition(){return this._position.clone()}setAmbient3v(e){this.setAmbient(e.x,e.y,e.z)}setDiffuse3v(e){this.setDiffuse(e.x,e.y,e.z)}setSpecular3v(e){this.setSpecular(e.x,e.y,e.z)}setAmbient(e,t,i){this._ambient.set(e,t,i);const s=this._renderNode;s&&(s._lightParams[0]=e,s._lightParams[1]=t,s._lightParams[2]=i)}setDiffuse(e,t,i){this._diffuse.set(e,t,i);const s=this._renderNode;s&&(s._lightParams[3]=e,s._lightParams[4]=t,s._lightParams[5]=i)}setSpecular(e,t,i){this._specular.set(e,t,i);const s=this._renderNode;s&&(s._lightParams[6]=e,s._lightParams[7]=t,s._lightParams[8]=i)}setShininess(e){this._shininess=e;const t=this._renderNode;t&&(t._lightShininess=e)}addTo(e){this._renderNode=e,this.setShininess(this._shininess),this.setAmbient3v(this._ambient),this.setDiffuse3v(this._diffuse),this.setSpecular3v(this._specular)}}class tr extends Dt{constructor(e={}){super({autoActivate:!0,...e}),this._name="sun",this.activationHeight=e.activationHeight||12079e3,this.offsetVertical=e.offsetVertical||-5e6,this.offsetHorizontal=e.offsetHorizontal||5e6,this.sunlight=new er({ambient:new oe(.15,.15,.25),diffuse:new oe(.9,.9,.8),specular:new oe(.1,.1,.06),shininess:110}),this._currDate=0,this._prevDate=0,this._clockPtr=null,this._lightOn=!1,this._f=0,this._k=0,this._stopped=e.stopped||!1}oninit(){this.planet.lightEnabled=!0,this.sunlight.addTo(this.planet),this.renderer.events.on("draw",this._draw,this),this._clockPtr||(this._clockPtr=this.renderer.handler.defaultClock)}stop(){this._stopped=!0,this.deactivate()}start(){this._stopped=!1,this.activate()}onactivate(){super.onactivate(),this._stopped=!1}bindClock(e){this._clockPtr=e}_draw(){if(this._clockPtr)if(this._currDate=this._clockPtr.currentDate,this._stopped)this.sunlight.setPosition3v(Jn(this._currDate));else{let e=this.planet.camera;if(e.getHeight()<this.activationHeight||!this._active){this._lightOn=!0,this._f=1;let t=e.eye.normal(),i=e.getForward();i.scale(Math.sign(e.getUp().dot(t))),e.slope>.99&&(i=e.getUp());let s=oe.proj_b_to_plane(i,t,i).normalize().scale(this.offsetVertical),n=oe.proj_b_to_plane(e.getRight(),t,e.getRight()).normalize().scale(this.offsetHorizontal),r=s.add(n),o=e.eye.add(r);if(this._k>0){this._k-=.001;let e=re.getRotationBetweenVectors(this.sunlight._position.normal(),o.normal()).slerp(re.IDENTITY,this._k).normalize();this.sunlight.setPosition3v(e.mulVec3(this.sunlight._position))}else this.sunlight.setPosition3v(o)}else if(this._k=1,this._f>0){this._f-=.001;let e=re.getRotationBetweenVectors(this.sunlight._position.normal(),Jn(this._currDate).normal()).slerp(re.IDENTITY,this._f).normalize();this.sunlight.setPosition3v(e.mulVec3(this.sunlight._position))}else(Math.abs(this._currDate-this._prevDate)>34e-5&&this._active||this._lightOn)&&(this._lightOn=!1,this._prevDate=this._currDate,this.sunlight.setPosition3v(Jn(this._currDate)),this._f=0)}}}class ir{constructor(){this.x=0,this.y=0,this.prev_x=0,this.prev_y=0,this.grabbedPoint=null,this.grabbedSpheroid=new Pt,this._vec=new ae,this._vecPrev=new ae}get dY(){return this.y-this.prev_y}get dX(){return this.x-this.prev_x}get vec(){return this._vec.set(this.x,this.y)}get vecPrev(){return this._vecPrev.set(this.prev_x,this.prev_y)}}class sr extends Dt{constructor(e={}){super(e),this._name="touchNavigation",this.grabbedPoint=new oe,this.inertia=.007,this.grabbedSpheroid=new Pt,this.planet=null,this.qRot=new re,this.scaleRot=0,this.rot=1,this._eye0=new oe,this.pointOnEarth=null,this.earthUp=null,this.touches=[new ir,new ir],this._keyLock=new Bn,this._touching=!1}oninit(){this.renderer&&(this.renderer.events.on("touchstart",this.onTouchStart,this),this.renderer.events.on("touchend",this.onTouchEnd,this),this.renderer.events.on("doubletouch",this.onDoubleTouch,this),this.renderer.events.on("touchcancel",this.onTouchCancel,this),this.renderer.events.on("touchmove",this.onTouchMove,this),this.renderer.events.on("draw",this.onDraw,this))}onTouchStart(e){const t=this.renderer.handler;if(this._touching=!0,2===e.sys.touches.length){const i=this.touches[0],s=this.touches[1];i.x=(e.sys.touches.item(0).clientX-e.sys.offsetLeft)*t.pixelRatio,i.y=(e.sys.touches.item(0).clientY-e.sys.offsetTop)*t.pixelRatio,i.prev_x=i.x,i.prev_y=i.y,i.grabbedPoint=this.planet.getCartesianFromPixelTerrain(new ae(i.x,i.y))||null,s.x=(e.sys.touches.item(1).clientX-e.sys.offsetLeft)*t.pixelRatio,s.y=(e.sys.touches.item(1).clientY-e.sys.offsetTop)*t.pixelRatio,s.prev_x=s.x,s.prev_y=s.y,s.grabbedPoint=this.planet.getCartesianFromPixelTerrain(new ae(s.x,s.y))||null,this.pointOnEarth=this.planet.getCartesianFromPixelTerrain(this.renderer.handler.getCenter())||null,this.pointOnEarth&&(this.earthUp=this.pointOnEarth.normal()),i.grabbedPoint&&s.grabbedPoint&&(i.grabbedSpheroid.radius=i.grabbedPoint.length(),s.grabbedSpheroid.radius=s.grabbedPoint.length(),this.stopRotation())}else 1===e.sys.touches.length&&this._startTouchOne(e)}_startTouchOne(e){const t=this.touches[0],i=this.renderer.handler;t.x=(e.sys.touches.item(0).clientX-e.sys.offsetLeft)*i.pixelRatio,t.y=(e.sys.touches.item(0).clientY-e.sys.offsetTop)*i.pixelRatio,t.prev_x=t.x,t.prev_y=t.y,t.grabbedPoint=this.planet.getCartesianFromPixelTerrain(e)||null,this._eye0.copy(this.planet.camera.eye),t.grabbedPoint&&(t.grabbedSpheroid.radius=t.grabbedPoint.length(),this.stopRotation())}stopRotation(){this.qRot.clear(),this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock)}onDoubleTouch(e){this.planet.stopFlying(),this.stopRotation();const t=this.planet.getCartesianFromPixelTerrain(e);if(t){const e=this.planet.ellipsoid.cartesianToLonLat(t);this.planet.flyLonLat(new I(e.lon,e.lat,.57*this.planet.camera.eye.distance(t)))}}onTouchEnd(e){0===e.sys.touches.length&&(this._touching=!1),1===e.sys.touches.length&&this._startTouchOne(e),Math.abs(this.touches[0].x-this.touches[0].prev_x)<3&&Math.abs(this.touches[0].y-this.touches[0].prev_y)<3&&(this.scaleRot=0)}onTouchCancel(e){}onTouchMove(e){let t=this.planet.camera;const i=this.renderer.handler;if(2===e.sys.touches.length){this.renderer.controlsBag.scaleRot=1;let n=this.touches[0],r=this.touches[1];if(!n.grabbedPoint||!r.grabbedPoint)return;this.planet.stopFlying(),n.prev_x=n.x,n.prev_y=n.y,n.x=(e.sys.touches.item(0).clientX-e.sys.offsetLeft)*i.pixelRatio,n.y=(e.sys.touches.item(0).clientY-e.sys.offsetTop)*i.pixelRatio,r.prev_x=r.x,r.prev_y=r.y,r.x=(e.sys.touches.item(1).clientX-e.sys.offsetLeft)*i.pixelRatio,r.y=(e.sys.touches.item(1).clientY-e.sys.offsetTop)*i.pixelRatio;const o=n.vec.add(r.vec).scale(.5),a=this.planet.getCartesianFromPixelTerrain(o);if(a){this.pointOnEarth=a;const e=Math.atan2(n.prev_y-r.prev_y,n.prev_x-r.prev_x),i=Math.atan2(n.y-r.y,n.x-r.x)-e,o=t.eye.distance(this.pointOnEarth),h=n.vec.sub(r.vec),c=n.vecPrev.sub(r.vecPrev);let d=o*-(1-h.length()/c.length());t.eye.addA(t.getForward().scale(d)),t.rotateAround(-i,!1,this.pointOnEarth,this.earthUp);const _=n.vec.add(r.vec).scale(.5),u=n.vecPrev.add(r.vecPrev).scale(.5),g=_.sub(u).scale(-1);var s=.5/o*t._lonLat.height*l;s>.003&&(s=.003),t.rotateHorizontal(s*-g.x,!1,this.pointOnEarth,this.earthUp),t.rotateVertical(s*-g.y,this.pointOnEarth),t.checkTerrainCollision(),t.update()}this.scaleRot=0}else if(1===e.sys.touches.length){let s=this.touches[0];if(s.prev_x=s.x,s.prev_y=s.y,s.x=(e.sys.touches.item(0).clientX-e.sys.offsetLeft)*i.pixelRatio,s.y=(e.sys.touches.item(0).clientY-e.sys.offsetTop)*i.pixelRatio,!s.grabbedPoint)return;this.planet.stopFlying();let n=e.direction,r=new ui(t.eye,n).hitSphere(s.grabbedSpheroid);if(r)if(t.slope>.2){this.qRot=re.getRotationBetweenVectors(r.normal(),s.grabbedPoint.normal());let e=this.qRot;t.eye=e.mulVec3(t.eye),t.rotate(e),t.checkTerrainCollision(),t.update(),this.scaleRot=1}else{let e=s.grabbedPoint,i=oe.add(e,t.getUp()),n=oe.add(e,e.getNormal()),r=t.unproject(s.x,s.y),o=new oe;new ui(t.eye,r).hitPlaneRes(_i.fromPoints(e,i,n),o)===ui.INSIDE&&(t.eye=this._eye0.addA(o.subA(e).negate()),t.checkTerrainCollision(),t.update(),this.scaleRot=0)}}}onDraw(){const e=this.renderer;if(e.controlsBag.scaleRot=this.scaleRot,this._touching)return;let t=this.planet.camera,i=t.eye.clone();if(!e.events.mouseState.leftButtonDown&&this.scaleRot){if(this.scaleRot-=this.inertia,this.scaleRot<=0)this.scaleRot=0;else{e.controlsBag.scaleRot=this.scaleRot;let i=this.qRot.slerp(re.IDENTITY,1-this.scaleRot*this.scaleRot*this.scaleRot).normalize();i.x||i.y||i.z||(this.scaleRot=0),t.eye=i.mulVec3(t.eye),t.rotate(i),t.checkTerrainCollision(),t.update()}t.eye.distance(i)/t.getAltitude()>.01?(this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock)):(this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock))}}}class nr extends Dt{constructor(e={}){super(e),this._keyLock=new Bn,this._move=0,this._targetPoint=null}oninit(){let e=new zt({classList:["og-map-button","og-zoomin-button"],icon:'<?xml version="1.0"?><svg width=24 height=24 xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> <path d="M 11 5 L 11 11 L 5 11 L 5 13 L 11 13 L 11 19 L 13 19 L 13 13 L 19 13 L 19 11 L 13 11 L 13 5 L 11 5 z"/></svg>'});e.appendTo(this.renderer.div);let t=new zt({classList:["og-map-button","og-zoomout-button"],icon:'<?xml version="1.0"?><svg width=24 height=24 xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> <path d="M 5 11 L 5 13 L 19 13 L 19 11 L 5 11 z"/></svg>'});t.appendTo(this.renderer.div),e.events.on("mousedown",(()=>this.zoomIn())),e.events.on("mouseup",(()=>this.stopZoom())),t.events.on("mousedown",(()=>this.zoomOut())),t.events.on("mouseup",(()=>this.stopZoom())),e.events.on("touchstart",(()=>this.zoomIn())),e.events.on("touchend",(()=>this.stopZoom())),e.events.on("touchcancel",(()=>this.stopZoom())),t.events.on("touchstart",(()=>this.zoomOut())),t.events.on("touchend",(()=>this.stopZoom())),t.events.on("touchcancel",(()=>this.stopZoom())),this.renderer.events.on("draw",this._draw,this)}zoomIn(){this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock),this._targetPoint=this.renderer.getCenter(),this._move=1}zoomOut(){this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock),this._targetPoint=this.renderer.getCenter(),this._move=-1}stopZoom(){this._move=0,this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock)}_draw(e){const t=this.planet.camera;if(0!==this._move){const i=this.planet.getCartesianFromPixelTerrain(e.getCenter());if(i){let e=.035*t.eye.distance(i);t.eye.addA(t.getForward().scale(this._move*e)),t.checkTerrainCollision(),t.update()}}}}class rr extends Ri{constructor(e={}){super(e.name),this._ignoreTerrain=!1,this.events=new Rt(or),this._ignoreTerrain=null==e.ignoreTerrain||e.ignoreTerrain,this._onSelect=e.onSelect||null,this._autoSelectionHide=e.autoSelectionHide||!1,this._planet=e.planet||null,this._startLonLat=null,this._heading=0,this._propsLabel=new Si({name:"propsLabel",label:{text:"",size:11,color:"rgba(455,455,455,1.0)",outlineColor:"rgba(0,0,0,0.34)",outline:.23,align:"center",offset:[0,18]}}),this._propsLabel?.label?.setVisibility(!1),this._trackEntity=new Si({polyline:{path3v:[],thickness:3.8,color:"rgb(455,455,455)",isClosed:!1}}),this._trackEntity.polyline.altitude=.01;let t=mi.createCylinder(1.1,0,2.7,20,1,!0,!1,0,0,0);this._cornerEntity=[new Si({geoObject:{scale:1,instanced:!0,tag:"selection",color:"rgb(0,305,0)",object3d:t},properties:{name:"start"}}),new Si({geoObject:{scale:1,instanced:!0,tag:"selection",color:"rgb(455,0,0)",object3d:t},properties:{name:"end"}})],this._trackLayer=new qs("track",{entities:[this._trackEntity,this._propsLabel],pickingEnabled:!1,polygonOffsetUnits:-1,relativeToGround:!0,hideInLayerSwitcher:!1}),this._cornersLayer=new qs("corners",{entities:[this._cornerEntity[0],this._cornerEntity[1]],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[1,4e6,.01],pickingScale:2})}set ignoreTerrain(e){this._ignoreTerrain=e}bindPlanet(e){this._planet=e}init(){this._activate()}onremove(){this._deactivate()}_activate(){this._propsLabel?.label?.setVisibility(!1),this._onMouseMove_=this._onMouseMove.bind(this),this.renderer?.events.on("mousemove",this._onMouseMove_,this),this._onMouseLdown_=this._onMouseLdown.bind(this),this.renderer?.events.on("ldown",this._onMouseLdown_,this),this._onMouseLup_=this._onMouseLup.bind(this),this.renderer?.events.on("lup",this._onMouseLup_,this),this._planet.addLayer(this._trackLayer),this._planet.addLayer(this._cornersLayer)}_deactivate(){this._startLonLat=null,this._trackLayer.remove(),this._cornersLayer.remove(),this.renderer?.events.off("mousemove",this._onMouseMove_),this.renderer?.events.off("ldown",this._onMouseLdown_),this.renderer?.events.off("lup",this._onMouseLup_),this.clear(),this._onMouseMove_=null,this._onMouseLdown_=null,this._onMouseLup_=null}_onMouseLdown(e){if(e.renderer.handler.canvas.classList.remove("ogGrabbingPoiner"),e.renderer.handler.canvas.style.cursor="pointer",!this._startLonLat){this._propsLabel.label?.setVisibility(!1),this._trackEntity.polyline?.setPath3v([]),this._cornerEntity[0].geoObject?.setVisibility(!0),this._cornerEntity[1].geoObject?.setVisibility(!0),this.renderer?.controls.mouseNavigation?.deactivate(),this._startLonLat=this._planet.getLonLatFromPixelTerrain(e);let t=this._planet.ellipsoid.lonLatToCartesian(this._startLonLat);this._cornerEntity[0].setCartesian3v(t),this._cornerEntity[1].setCartesian3v(t)}}_onMouseLup(e){if(this._startLonLat){if(this._pickedCorner=null,this._anchorLonLat=null,this._propsLabel.label?.setVisibility(!0),this._onSelect&&"function"==typeof this._onSelect){let e=this._cornerEntity[0].getLonLat(),t=this._cornerEntity[1].getLonLat(),i=[Math.min(e.lon,t.lon),Math.min(e.lat,t.lat),Math.max(e.lon,t.lon),Math.max(e.lat,t.lat)];this._onSelect(i)}this._autoSelectionHide&&this.clear(),this._startLonLat=null}e.renderer.handler.canvas.style.cursor="default",this.renderer?.controls.mouseNavigation?.activate()}_drawLine(e,t,i){i||(i=this._planet.ellipsoid.lonLatToCartesian(e));let s=this._planet.ellipsoid.lonLatToCartesian(t),n=this._planet.ellipsoid.direct(e,t);this._heading=n.initialAzimuth;let r=[];this._cornerEntity[0].setCartesian3v(i),this._cornerEntity[1].setCartesian3v(s);let o=[i,this._planet.ellipsoid.lonLatToCartesian(new I(t.lon,e.lat,e.height)),s,this._planet.ellipsoid.lonLatToCartesian(new I(e.lon,t.lat,e.height)),i];r.push(i);let a=(e,t)=>{let i=t.sub(e),s=i.length();i.normalize();for(let t=0;t<120;t++){let n=i.scaleTo(t*s/120).addA(e);r.push(n)}};for(let e=0;e<o.length-1;e++)a(o[e],o[e+1]);this._trackEntity.polyline?.setPath3v([r]),this._ignoreTerrain}_onMouseMove(e){if(this._startLonLat){this._propsLabel.label?.setVisibility(!0);let t=this._planet.getLonLatFromPixelTerrain(e);if(!t)return;this._drawLine(this._startLonLat,t)}}clear(){this._trackEntity.polyline?.clear(),this._cornerEntity[0].geoObject?.setVisibility(!1),this._cornerEntity[1].geoObject?.setVisibility(!1)}frame(){let e=this._trackEntity.polyline?.getPath3v()[0];if(e&&!this._ignoreTerrain){let i=0;for(let t=0,s=e.length-1;t<s;t++)i+=e[t+1].distance(e[t]);this._propsLabel.setCartesian3v(e[Math.floor(e.length/2)]),this._propsLabel.label?.setText(`${t=i,t>1e3?`${(t/1e3).toFixed(1)} km`:t>9?`${Math.round(t)} m`:`${t.toFixed(1)} m`}, ${Math.round(this._heading)} deg`)}var t}get ellipsoid(){return this._planet?this._planet.ellipsoid:null}}const or=["add","remove","mousemove","mouseenter","mouseleave","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchmove","touchstart","touchend","doubletouch","touchleave","touchenter"];function ar(e,t){return new Date(+e+1e3*t)}function lr(e,t=!0,i=!1){let s=_r[e.getMonth()],n=e.getUTCDate(),r=e.getUTCFullYear();if(t){let t=e.getUTCHours().toString().padStart(2,"0"),o=e.getUTCMinutes().toString().padStart(2,"0"),a=e.getUTCSeconds().toString().padStart(2,"0");if(i){return`${s} ${n} ${r} ${t}:${o}:${a}.${e.getUTCMilliseconds().toString().padStart(3,"0")}`}return`${s} ${n} ${r} ${t}:${o}:${a}`}return`${s} ${n} ${r}`}function hr(e,t=0,i=10,s=2,n="white"){e.lineWidth=s,e.strokeStyle=n,e.beginPath(),e.moveTo(t,0),e.lineTo(t,i),e.stroke()}function cr(e,t,i,s,n="12px Arial",r="black",o="left",a="bottom",h=0){e.save(),e.translate(i,s),e.rotate(h*l),e.fillStyle=r,e.textBaseline=a,e.font=n,e.textAlign=o,e.fillText(t,0,0),e.restore()}const dr=[[.001,10],[.002,10],[.005,10],[.01,10],[.02,10],[.05,10],[.1,10],[.25,10],[.5,5],[1,10],[2,10],[5,5],[10,10],[15,15],[30,6],[60,12],[120,12],[300,5],[600,10],[900,15],[1800,6],[3600,12],[7200,10],[14400,4],[21600,6],[43200,12],[86400,24],[172800,2],[345600,4],[604800,7],[1296e3,15],[2592e3,5],[5184e3,6],[7776e3,9],[15552e3,18],[31536e3,12],[63072e3,2],[126144e3,4],[15768e4,5],[31536e4,10],[63072e4,2],[126144e4,4],[15768e5,5],[31536e5,10],[63072e5,2],[126144e5,4],[15768e6,5],[31536e6,10]];const _r=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],ur=["change","current"];class gr{constructor(e={}){this.events=Mt(ur),this._current=e.current||new Date,this._rangeStart=e.rangeStart||new Date,this._rangeEnd=e.rangeEnd||ar(this._rangeStart,3600),this._range=this._rangeEnd.getTime()-this._rangeStart.getTime(),this._minDate=e.minDate||null,this._maxDate=e.maxDate||null,this.multiplier=null!=e.multiplier?e.multiplier:1,this._requestAnimationFrameId=0,this._prevNow=0,this.dt=0}play(){this._requestAnimationFrameId||(this._prevNow=window.performance.now(),this._animationFrameCallback())}stop(){this._requestAnimationFrameId&&(window.cancelAnimationFrame(this._requestAnimationFrameId),this._requestAnimationFrameId=0)}stopped(){return 0==this._requestAnimationFrameId}_animationFrameCallback(){this._requestAnimationFrameId=window.requestAnimationFrame((()=>{this._frame(),this._animationFrameCallback()}))}_frame(){let e=window.performance.now();this.dt=e-this._prevNow,this._prevNow=e,this.current=new Date(this.currentTime+this.dt*this.multiplier)}get range(){return this._range}set(e,t){e===this._rangeStart&&t===this._rangeEnd||(this._rangeStart=e,this._rangeEnd=t,this._range=this._rangeEnd.getTime()-this._rangeStart.getTime(),this.events.dispatch(this.events.change,e,t))}get current(){return this._current}get rangeStart(){return this._rangeStart}get rangeEnd(){return this._rangeEnd}get rangeStartTime(){return this._rangeStart.getTime()}get rangeEndTime(){return this._rangeEnd.getTime()}get currentTime(){return this._current.getTime()}set current(e){e!==this._current&&(this._maxDate&&e>this._maxDate?this._current=this._maxDate:this._minDate&&e<this._minDate?this._current=this._minDate:this._current=e,this.events.dispatch(this.events.current,this._current))}set rangeStart(e){e!==this._rangeStart&&(this._rangeStart=e,this._range=this._rangeEnd.getTime()-this._rangeStart.getTime(),this.events.dispatch(this.events.change,e))}set rangeEnd(e){e!==this._rangeEnd&&(this._rangeEnd=e,this._range=this._rangeEnd.getTime()-this._rangeStart.getTime(),this.events.dispatch(this.events.change,e))}}const fr=.001,pr=["startdrag","stopdrag","startdragcurrent","stopdragcurrent","setcurrent","reset","play","playback","pause","visibility"],mr="#bfbfbf";class vr extends kt{constructor(e={}){super({template:'<div class="og-timeline">\n\n <div class="og-timeline-top">\n </div>\n\n <div class="og-timeline-frame">\n <div class="og-timeline-current">\n <div class="og-timeline-current-spin">\n <div class="og-timeline-current-arrow"></div>\n </div>\n </div>\n <div class="og-timeline-scale"></div>\n </div>\n\n <div class="og-timeline-bottom">\n <div class="og-timeline-controls">\n </div>\n </div>\n\n</div>',model:new gr({rangeStart:e.rangeStart,rangeEnd:e.rangeEnd,current:e.currentDate,minDate:e.minDate,maxDate:e.maxDate})}),this._onMouseWheel=e=>{if(this._isMouseOver){let t=this._canvasEl.getBoundingClientRect(),i=e.clientX-t.left,s=-(i-.5*this.clientWidth),n=this.model.rangeStartTime+this._millisecondsInPixel*i;this._zoom(n,s,Math.sign(e.wheelDelta))}else if(this._isCurrentMouseOver){let t=-((this.model.currentTime-this.model.rangeStartTime)/this._millisecondsInPixel-.5*this.clientWidth);this._zoom(this.model.currentTime,t,Math.sign(e.wheelDelta))}},this._onMouseWheelFF=e=>{this._onMouseWheel(e)},this._onMouseDown=e=>{this._isMouseOver?(this._isDragging=!0,document.body.classList.add("og-timeline-unselectable"),this._clickPosX=e.clientX,this._clickTime=Date.now(),this._clickRangeStart=this.model.rangeStart,this._clickRangeEnd=this.model.rangeEnd,this.events.dispatch(this.events.startdrag,e)):this._isCurrentMouseOver&&(this._isCurrentDragging=!0,document.body.classList.add("og-timeline-unselectable"),this._clickPosX=e.clientX,this._clickCurrentDate=this.model.current,this.events.dispatch(this.events.startdragcurrent,e))},this._onMouseUp=e=>{if(this._isDragging)if(this._isDragging=!1,document.body.classList.remove("og-timeline-unselectable"),this._clickPosX===e.clientX&&Date.now()-this._clickTime<this._clickDelay){let t=this._canvasEl.getBoundingClientRect(),i=new Date(this.model.rangeStartTime+(e.clientX-t.left)*this._millisecondsInPixel);this.model.current=i,this.events.dispatch(this.events.stopdrag,i),this.events.dispatch(this.events.setcurrent,i)}else this.events.dispatch(this.events.stopdrag,this.model.current);else this._isCurrentDragging&&(this._isCurrentDragging=!1,document.body.classList.remove("og-timeline-unselectable"),this.events.dispatch(this.events.stopdragcurrent,this.model.current))},this._onMouseEnter=()=>{this._isMouseOver=!0},this._onMouseOut=()=>{this._isMouseOver=!1},this._onCurrentMouseEnter=()=>{this._isCurrentMouseOver=!0},this._onCurrentMouseOut=()=>{this._isCurrentMouseOver=!1},this._onMouseMove=e=>{if(this._isDragging){let t=(this._clickPosX-e.clientX)*this._millisecondsInPixel*fr;this.model.set(ar(this._clickRangeStart,t),ar(this._clickRangeEnd,t))}else if(this._isCurrentDragging){let t=(this._clickPosX-e.clientX)*this._millisecondsInPixel*fr,i=ar(this._clickCurrentDate,-t);i>=this.model.rangeStart&&i<=this.model.rangeEnd&&(this.model.current=ar(this._clickCurrentDate,-t))}},this.events=this.events.registerNames(pr),this.fillStyle=e.fillStyle||"rgba(64, 59, 59, 1.0)",this.$controls=null,this._frameEl=null,this._currentEl=null,this._canvasEl=document.createElement("canvas"),this._ctx=this._canvasEl.getContext("2d"),this._isMouseOver=!1,this._isDragging=!1,this._isCurrentDragging=!1,this._isCurrentMouseOver=!1,this._minWidth=330,this._canvasScale=2,this._millisecondsInPixel=0,this._clickPosX=0,this._clickRangeStart=new Date,this._clickRangeEnd=new Date,this._clickCurrentDate=new Date,this._clickTime=0,this._clickDelay=450,this._onResizeObserver_=this._onResizeObserver.bind(this),this._resizeObserver=new ResizeObserver(this._onResizeObserver_),this._pauseBtn=new Ut({classList:["og-timeline-control_button"],icon:'<?xml version="1.0" ?><!DOCTYPE svg PUBLIC \'-//W3C//DTD SVG 1.1//EN\' \'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\'><svg enable-background="new 0 0 512 512" height="512px" version="1.1" viewBox="0 0 512 512" width="512px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="Layer_6"><rect fill="#252525" height="320" width="60" x="153" y="96"/><rect fill="#252525" height="320" width="60" x="299" y="96"/></g></svg>',name:"pause"}),this._playBtn=new Ut({classList:["og-timeline-control_button"],icon:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M8 5v14l11-7z" style="fill: black;"/></svg>',name:"play"}),this._buttons=new Jt({buttons:[this._pauseBtn,this._playBtn]}),this._visibility=!1}_onResizeObserver(){this.resize()}get canvasScale(){return this._canvasScale}set canvasScale(e){e!==this._canvasScale&&(this._canvasScale=e,this.resize())}resize(){this._resize(),this.draw()}afterRender(e){this.resize()}render(){return super.render(),this.$controls=this.select(".og-timeline-controls"),this._frameEl=this.select(".og-timeline-frame"),this._currentEl=this.select(".og-timeline-current"),this.select(".og-timeline-frame .og-timeline-scale").appendChild(this._canvasEl),this._resizeObserver.observe(this.el),this.model.events.on("change",(()=>{this.draw()})),this.model.events.on("current",(e=>{this._drawCurrent(),this.events.dispatch(this.events.setcurrent,e)})),this._canvasEl.addEventListener("mouseenter",this._onMouseEnter),this._canvasEl.addEventListener("mouseout",this._onMouseOut),this._currentEl.addEventListener("mouseenter",this._onCurrentMouseEnter),this._currentEl.addEventListener("mouseout",this._onCurrentMouseOut),document.body.addEventListener("mousemove",this._onMouseMove),document.body.addEventListener("mousedown",this._onMouseDown),document.body.addEventListener("mouseup",this._onMouseUp),document.body.addEventListener("wheel",this._onMouseWheelFF),this._playBtn.appendTo(this.$controls),this._pauseBtn.appendTo(this.$controls),this.model.stopped()?(this._pauseBtn.setActive(!0,!0),this._pauseBtn.preventClick=!0):(this._playBtn.setActive(!0,!0),this._playBtn.preventClick=!0),this._buttons.events.on("change",(e=>{switch(e.name){case"play":this.play();break;case"pause":this.pause()}})),this.setVisibility(!0),this}setVisibility(e){e!==this._visibility&&(this._visibility=e,this.el&&(this.el.style.display=e?"block":"none"),this.events.dispatch(this.events.visibility,e))}reset(){this.model.stop(),this.events.dispatch(this.events.reset,this.model)}play(){this.model.multiplier=Math.abs(this.model.multiplier),this.model.play(),this.events.dispatch(this.events.play,this.model)}pause(){this.model.stop(),this.events.dispatch(this.events.pause,this.model)}playBack(){this.model.multiplier=-1*Math.abs(this.model.multiplier),this.model.play(),this.events.dispatch(this.events.playback,this.model)}_zoom(e,t,i){let s=(e-(this.model.rangeStartTime+.5*this.model.range))*fr,n=ar(this.model.rangeStart,s),r=ar(this.model.rangeEnd,s),o=(r.getTime()-n.getTime())/20*fr,a=ar(n,o*i),l=ar(r,-o*i),h=(l.getTime()-a.getTime())/this.clientWidth;if(h<31536e6&&h>.1){let e=h*t*fr;this.model.set(ar(a,e),ar(l,e))}}get clientWidth(){return this._canvasEl?this._canvasEl.width/this._canvasScale:0}get clientHeight(){return this._canvasEl?this._canvasEl.height/this._canvasScale:0}_resize(){this._frameEl&&(this._canvasEl.width=this._frameEl.clientWidth*this._canvasScale,this._canvasEl.height=this._frameEl.clientHeight*this._canvasScale,this._canvasEl.style.width=`${this._frameEl.clientWidth}px`,this._canvasEl.style.height=`${this._frameEl.clientHeight}px`)}getOffsetByTime(e){return(e-this.model.rangeStartTime)/this._millisecondsInPixel}remove(){super.remove(),this.model.stop()}_clearCanvas(){this._ctx.fillStyle=this.fillStyle,this._ctx.fillRect(0,0,this.clientWidth*this._canvasScale,this.clientHeight*this._canvasScale)}_drawCurrent(){let e=(this.model.currentTime-this.model.rangeStartTime)/this._millisecondsInPixel;this.model.current<this.model.rangeStart||this.model.current>this.model.rangeEnd?this._currentEl.style.display="none":(this._currentEl.style.display="block",this._currentEl.style.transform=`translateX(${e}px)`)}draw(){this._millisecondsInPixel=this.model.range/this.clientWidth;let e=function(e){for(let t=0,i=dr.length;t<i;t++)if(dr[t][0]>e)return dr[t-1]}(this._minWidth*this._millisecondsInPixel*fr);if(e){this._clearCanvas();let i=1e3*e[0],s=i/this._millisecondsInPixel,n=e[1],r=(t=this.model.rangeStartTime)-t%i,o=e[0]<1,a=e[0]<86400;for(let e=r,t=this.model.rangeEndTime+i;e<t;e+=i){let t=this.getOffsetByTime(e);t>=0&&t<=this.clientWidth*this._canvasScale&&hr(this._ctx,t*this._canvasScale,10*this._canvasScale,2*this._canvasScale,mr);for(let e=1;e<n;e++){let i=t+e*(s/n);i>=0&&i<=this.clientWidth*this._canvasScale&&hr(this._ctx,i*this._canvasScale,5*this._canvasScale,1*this._canvasScale,mr)}cr(this._ctx,lr(new Date(e),a,o),t*this._canvasScale,26*this._canvasScale,"24px monospace","#bfbfbf","center")}this._drawCurrent()}var t}}function yr(e,t){const i=new Date(e);return i.setHours(i.getHours()+t),i}class xr{constructor(){this.resolve=()=>{},this.reject=()=>{},this.promise=new Promise(((e,t)=>{this.resolve=e,this.reject=t})),Object.freeze(this)}}const br=["startcollecting","profilecollected","clear"];class wr{constructor(e={}){this.events=Mt(br),this.planet=e.planet||null,this._warningHeightLevel=5,this._pointsReady=!1,this._isWarning=!1,this._minX=0,this._planeDistance=this._maxX=1e3,this._minY=0,this._maxY=200,this._drawData=[[],[]],this._promiseArr=[],this._promiseCounter=0,this._pMaxY=0,this._pMinY=0,this._pDist=0,this._pTrackCoords=[],this._pGroundCoords=[],this._pIndex=0}bindPlanet(e){this.planet=e}setWarningHeightLevel(e=0){this._warningHeightLevel=e}setRange(e,t,i,s){this._minX=e,this._maxX=t,i&&(this._minY=i),s&&(this._maxY=s)}_getHeightAsync(e,t,i){let s=new xr;if(this.planet){let n=this.planet.terrain.geoid.getHeightLonLat(e);this.planet.terrain.getHeightAsync(e,(r=>{this.planet&&i===this._promiseCounter?(r+=n,this._pGroundCoords[t][1]=r,this._pGroundCoords[t][2]=0,this._pGroundCoords[t][3]=e.height,r>this._pMaxY&&(this._pMaxY=r),r<this._pMinY&&(this._pMinY=r),this._updatePointType(t),s.resolve(r)):s.reject()}))}else s.reject();return s.promise}_collectCoordsBetweenTwoTrackPoints(e,t,i,s,n,r){if(this.planet)for(let o=1;o<=t;o++){this._pDist+=1,this._pIndex++;let t=o*i,a=s.add(n.scaleTo(t)),l=this.planet.ellipsoid.cartesianToLonLat(a);this._pGroundCoords[this._pIndex]=[this._pDist,0,0,0,e],((e,t)=>{this._promiseArr.push(this._getHeightAsync(e,t,r))})(l,this._pIndex)}}_collectAllPoints(e,t){if(!this.planet)return;if(t!==this._promiseCounter)return;let i=new oe,s=new oe;for(let n=1,r=e.length;n<r;n++){let r=e[n-1],o=e[n];this.planet.ellipsoid.lonLatToCartesianRes(r,i),this.planet.ellipsoid.lonLatToCartesianRes(o,s);let a=s.sub(i),l=a.length(),h=this.planet.ellipsoid.getSurfaceNormal3v(i),c=oe.proj_b_to_plane(a,h),d=c.length(),_=Math.floor(d/1),u=1*l/d;this._getGroundElevation(r,n-1,t),c.normalize(),a.normalize(),this._collectCoordsBetweenTwoTrackPoints(n-1,_,u,i,a,t),this._pDist+=d-1*_,this._pIndex++;let g=o.height;g>this._pMaxY&&(this._pMaxY=g),g<this._pMinY&&(this._pMinY=g),this._pTrackCoords[n]=[this._pDist,g,this._pIndex]}}_getGroundElevation(e,t,i){this._pGroundCoords[this._pIndex]=[this._pDist,0,0,0,t],this._promiseArr.push(this._getHeightAsync(e,this._pIndex,i))}_calcPointsAsync(e,t){return new Promise(((i,s)=>{this._pTrackCoords=[[0,e[0].height,0]],this._pMaxY=e[0].height,this._pMinY=this._pMaxY,this._pDist=0,this._pGroundCoords=[],this._pIndex=0,this._promiseArr=[],this._collectAllPoints(e,t),this._getGroundElevation(e[e.length-1],e.length-1,t),Promise.all(this._promiseArr).then((()=>{i({dist:this._pDist,minY:this._pMinY,maxY:this._pMaxY,trackCoords:this._pTrackCoords,groundCoords:this._pGroundCoords})}))}))}get minX(){return this._minX}get planeDistance(){return this._planeDistance}get maxX(){return this._maxX}get minY(){return this._minY}get maxY(){return this._maxY}get pointsReady(){return this._pointsReady}get isWarningOrCollision(){return this._isWarning}get drawData(){return this._drawData}collectProfile(e){let t=new xr;return this.planet||t.reject(),this._pointsReady=!1,this._isWarning=!1,e&&e.length?(this.events.dispatch(this.events.startcollecting,this),this._promiseCounter++,(i=>{this._calcPointsAsync(e,i).then((e=>{i===this._promiseCounter&&(this._planeDistance=e.dist,this.setRange(0,e.dist,e.minY-.1*Math.abs(e.minY),e.maxY+.2*Math.abs(e.maxY)),this._pointsReady=!0,this._drawData=[e.trackCoords,e.groundCoords],this.events.dispatch(this.events.profilecollected,this._drawData,this),t.resolve(this._drawData))}))})(this._promiseCounter),t.promise):(t.reject(),t.promise)}_updatePointType(e){this._pGroundCoords[e][3]>=this._pGroundCoords[e][1]&&this._pGroundCoords[e][3]<this._pGroundCoords[e][1]+this._warningHeightLevel-.1&&(this._pGroundCoords[e][2]=1),this._pGroundCoords[e][3]<=this._pGroundCoords[e][1]+1&&(this._pGroundCoords[e][2]=2),1!==this._pGroundCoords[e][2]&&2!==this._pGroundCoords[e][2]||(this._isWarning=!0)}_setPointsType(){this._isWarning=!1,this._pTrackCoords=this._drawData[0],this._pGroundCoords=this._drawData[1];for(let e=0;e<this._pGroundCoords.length;e++)this._updatePointType(e);this._drawData[1]=this._pGroundCoords,this.events.dispatch(this.events.profilecollected,this._drawData,this)}clear(){this._promiseCounter=0,this._pointsReady=!1,this._isWarning=!1,this._drawData=[[],[]],this._pMaxY=0,this._pMinY=0,this._pDist=0,this._pTrackCoords=[],this._pGroundCoords=[],this._pIndex=0,this.events.dispatch(this.events.clear,this._drawData,this)}}const Cr="rgb(198, 198, 198)",Tr=[Cr,"rgb(255, 255, 0)","rgb(255, 0, 0)"],Er=["startdrag","stopdrag","pointer","mouseenter","mouseleave","dblclick","tracklength","groundlength","warninglength","collisionlength"];class Lr extends kt{constructor(e={}){super({template:'<div class="og-elevationprofile">\n <div class="og-elevationprofile-loading" style="display: none;">\n <div class="loadingio-spinner-bars-r354qqyl5v">\n <div class="ldio-p0v5a1f6oz">\n <div></div>\n <div></div>\n <div></div>\n <div></div>\n </div>\n </div> \n </div> \n </div>',model:new wr}),this._onMouseDblClick=e=>{let t,i=this.$canvas.getBoundingClientRect(),s=e.clientX-i.left,n=this._leftDistance+(this._rightDistance-this._leftDistance)*s/this.clientWidth,r=this.model.drawData[1],o=this.model.drawData[0];n<0?(t=1,n=0,s=(0-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):n>this.model.planeDistance?(t=r.length-1,n=this.model.planeDistance,s=(n-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):t=-1-ke(r,n,((e,t)=>e-t[0]));let a=r[t-1],l=r[t],h=(n-a[0])/(l[0]-a[0]),c=a[1]+h*(l[1]-a[1]),d=a[4],_=o[d],u=o[d+1];h=(n-_[0])/(u[0]-_[0]);let g=_[1]+h*(u[1]-_[1]);this.events.dispatch(this.events.dblclick,n,_,u,a,l,d,t-1,g-c)},this._onMouseEnter=e=>{this._isMouseOver=!0,this.events.dispatch(this.events.mouseenter,e)},this._onMouseOut=e=>{this._isMouseOver=!1,this.events.dispatch(this.events.mouseleave,e)},this._onMouseDown=e=>{this._isMouseOver&&(this._isDragging=!0,document.body.classList.add("og-timeline-unselectable"),this._clickPosX=e.clientX,this._customFrame||(this._leftDistance=this.model.minX,this._rightDistance=this.model.maxX),this._clickLeftDistance=this._leftDistance,this._clickRightDistance=this._rightDistance,this.events.dispatch(this.events.startdrag,e))},this._onMouseUp=e=>{this._isDragging&&(this._isDragging=!1,document.body.classList.remove("og-timeline-unselectable"),this.events.dispatch(this.events.stopdrag,e))},this._onCanvasMouseMove=e=>{if(this.model.pointsReady)if(this._isDragging)this.clearPointerCanvas();else{this._customFrame||(this._leftDistance=this.model.minX,this._rightDistance=this.model.maxX);let t=this.$pointerCanvas.getBoundingClientRect(),i=e.clientX-t.left;this.redrawPointerCanvas(i)}},this._onMouseMove=e=>{if(this._isDragging&&this.model.pointsReady){let t=(this._clickPosX-e.clientX)*this._canvasScale/this._pixelsInMeter_x;this.setFrame(this._clickLeftDistance+t,this._clickRightDistance+t)}},this._onMouseWheelFF=e=>{this._onMouseWheel(e)},this._onMouseWheel=e=>{if(this._isMouseOver&&this.model.pointsReady){this._customFrame||(this._leftDistance=this.model.minX,this._rightDistance=this.model.maxX),this._customFrame=!0;let t=Math.sign(e.wheelDelta)*(this._rightDistance-this._leftDistance)/20,i=this.$canvas.getBoundingClientRect(),s=e.clientX-i.left,n=s-.5*this.$canvas.clientWidth,r=n*this._canvasScale/this._pixelsInMeter_x,o=r+this._leftDistance+t,a=r+this._rightDistance-t;r=-n*(a-o)/this.clientWidth,this.setFrame(o+r,a+r),this.redrawPointerCanvas(s)}},this.events=this.events.registerNames(Er),this.fillStyle=e.fillStyle||"rgb(63, 63, 63)",this._customFrame=!1,this._leftDistance=0,this._rightDistance=0,this._pixelsInMeter_x=0,this._pixelsInMeter_y=0,this._canvasScale=2,this.$canvas=document.createElement("canvas"),this.$canvas.style.position="absolute",this._ctx=this.$canvas.getContext("2d"),this.$pointerCanvas=document.createElement("canvas"),this.$pointerCanvas.style.pointerEvents="none",this.$pointerCanvas.style.position="absolute",this._pointerCtx=this.$pointerCanvas.getContext("2d"),this.$loading=null,this._isMouseOver=!1,this._isDragging=!1,this._clickPosX=0,this._clickLeftDistance=0,this._clickRightDistance=0,this._timeStartHandler=0,this._onResizeObserver_=this._onResizeObserver.bind(this),this._resizeObserver=new ResizeObserver(this._onResizeObserver_)}_onResizeObserver(){this.resize()}get canvasScale(){return this._canvasScale}set canvasScale(e){e!==this._canvasScale&&(this._canvasScale=e,this.resize())}resize(){this._resize(),this.draw()}render(){return super.render(),this._resizeObserver.observe(this.el),this.el.appendChild(this.$canvas),this.el.appendChild(this.$pointerCanvas),this.model.events.on("profilecollected",(e=>{this._hideLoading(),this.clearPointerCanvas(),this.draw()})),this.model.events.on("startcollecting",(()=>{clearTimeout(this._timeStartHandler),this._timeStartHandler=setTimeout((()=>{this._showLoading()}),450)})),this.model.events.on("clear",(()=>{this._customFrame=!1,this._leftDistance=0,this.clearCanvas(),this.clearPointerCanvas()})),this.$loading=this.select(".og-elevationprofile-loading"),this.$canvas.addEventListener("mouseenter",this._onMouseEnter),this.$canvas.addEventListener("mouseout",this._onMouseOut),this.$canvas.addEventListener("dblclick",this._onMouseDblClick),this.$canvas.addEventListener("mousemove",this._onCanvasMouseMove),document.body.addEventListener("mousemove",this._onMouseMove),document.body.addEventListener("mousedown",this._onMouseDown),document.body.addEventListener("mouseup",this._onMouseUp),document.body.addEventListener("wheel",this._onMouseWheelFF),this}_hideLoading(){clearTimeout(this._timeStartHandler),this.$loading.style.display="none"}_showLoading(){this.$loading.style.display="flex"}redrawPointerCanvas(e){this.clearPointerCanvas();let t,i=this._leftDistance+(this._rightDistance-this._leftDistance)*e/this.clientWidth,s=this.model.drawData[1],n=this.model.drawData[0];i<0?(t=1,i=0,e=(0-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):i>this.model.planeDistance?(t=s.length-1,i=this.model.planeDistance,e=(i-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):t=-1-ke(s,i,((e,t)=>e-t[0]));let r=s[t-1],o=s[t],a=(i-r[0])/(o[0]-r[0]),l=r[1]+a*(o[1]-r[1]),h=r[4],c=n[h],d=n[h+1];a=(i-c[0])/(d[0]-c[0]);let _=c[1]+a*(d[1]-c[1]),u=(this.model.maxY-_)*this._pixelsInMeter_y,g=(this.model.maxY-l)*this._pixelsInMeter_y;this.events.dispatch(this.events.pointer,i,c,d,r,o,h,t-1,_-l);let f=this._pointerCtx;f.lineWidth=3,f.strokeStyle="rgba(64,64,64,0.6)",f.beginPath(),f.moveTo(e*this._canvasScale,0),f.lineTo(e*this._canvasScale,this.clientHeight*this._canvasScale),f.stroke(),f.beginPath(),f.arc(e*this._canvasScale,g,4,0,2*Math.PI,!1),f.fillStyle="#FFB277",f.fill(),f.lineWidth=4,f.strokeStyle="#FFB277",f.stroke(),f.beginPath(),f.arc(e*this._canvasScale,u,4,0,2*Math.PI,!1),f.fillStyle="#FFB277",f.fill(),f.lineWidth=4,f.strokeStyle="#FFB277",f.stroke(),f.lineWidth=3,f.strokeStyle="#FFB277",f.beginPath(),f.moveTo(e*this._canvasScale,g),f.lineTo(e*this._canvasScale,u),f.stroke(),f.fillStyle="white",f.font=28/devicePixelRatio+"px Arial",f.textBaseline="middle",f.textAlign="left",f.fillText(`${Math.round(_-l).toString()} m`,(e+5)*this._canvasScale,g+.5*(u-g)),f.fillStyle="white",f.font=28/devicePixelRatio+"px Arial",f.textAlign="right";let p=Ke(i);f.fillText(`${p[0]} ${p[1]}`,(e-5)*this._canvasScale,(this.clientHeight-7)*this._canvasScale)}get clientWidth(){return this.$canvas?this.$canvas.width/this._canvasScale:0}get clientHeight(){return this.$canvas?this.$canvas.height/this._canvasScale:0}_resize(){this.el&&(this.$canvas.width=this.el.clientWidth*this._canvasScale,this.$canvas.height=this.el.clientHeight*this._canvasScale,this.$canvas.style.width=`${this.el.clientWidth}px`,this.$canvas.style.height=`${this.el.clientHeight}px`,this.$pointerCanvas.width=this.el.clientWidth*this._canvasScale,this.$pointerCanvas.height=this.el.clientHeight*this._canvasScale,this.$pointerCanvas.style.width=`${this.el.clientWidth}px`,this.$pointerCanvas.style.height=`${this.el.clientHeight}px`,this._customFrame&&(this._pixelsInMeter_x=this._canvasScale*this.clientWidth/(this._rightDistance-this._leftDistance)))}clearPointerCanvas(){this._pointerCtx.fillStyle="rgba(0,0,0,0)",this._pointerCtx.clearRect(0,0,this.clientWidth*this._canvasScale,this.clientHeight*this._canvasScale)}clearCanvas(){const e=this._ctx.createLinearGradient(0,0,0,this.clientHeight*this._canvasScale);e.addColorStop(0,"black"),e.addColorStop(1,this.fillStyle),this._ctx.fillStyle=e,this._ctx.fillRect(0,0,this.clientWidth*this._canvasScale,this.clientHeight*this._canvasScale)}setFrame(e,t){this._leftDistance=e,this._rightDistance=t,this._customFrame=!0,this._pixelsInMeter_x=this._canvasScale*this.clientWidth/(this._rightDistance-this._leftDistance),this.model.setRange(e,t),this.draw()}_updateUnits(){this._customFrame||(this._pixelsInMeter_x=this._canvasScale*this.clientWidth/(this.model.maxX-this.model.minX)),this._pixelsInMeter_y=this._canvasScale*this.clientHeight/(this.model.maxY-this.model.minY)}clear(){this.model.clear(),this.clearCanvas()}draw(){let e=this.model.drawData[0];if(e.length>1){this._updateUnits(),this.clearCanvas();let t=this.model.drawData[1];this._drawTrack(e,t),this._drawTerrain(t),this._drawWarningAndCollision(t),this._drawLabels(e,t)}else this.clearCanvas()}_drawLabels(e,t){let i=this._ctx;if(i){let s=e[0];const n=this.model.maxY;let r=(-this._leftDistance+s[0])*this._pixelsInMeter_x,o=(n-s[1])*this._pixelsInMeter_y;t[s[2]][1],this._pixelsInMeter_y,i.beginPath(),i.fillStyle="#F7F718",i.fillRect(r-4,o-4,8,8),i.stroke(),i.fillStyle="white",i.font=26/devicePixelRatio+"px Arial",i.textBaseline="bottom",i.textAlign="left",i.fillText(`${Math.round(s[1]-t[s[2]][1]).toString()} m`,r+1,o-10),i.stroke();for(let s=1,a=e.length;s<a;s++){let a=e[s];r=(-this._leftDistance+a[0])*this._pixelsInMeter_x,o=(n-a[1])*this._pixelsInMeter_y,t[a[2]][1],this._pixelsInMeter_y,i.beginPath(),i.fillStyle="#F7F718",i.fillRect(r-4,o-4,8,8),i.stroke(),i.fillStyle="white",i.fillText(`${Math.round(a[1]-t[a[2]][1]).toString()} m`,r+1,o-10),i.stroke()}}}_drawTrack(e,t){let i=e[0],s=this._ctx;if(s){const n=this.model.maxY;s.lineWidth=5,s.strokeStyle="rgb(0, 255, 50)",s.beginPath(),s.moveTo((-this._leftDistance+i[0])*this._pixelsInMeter_x,(n-i[1])*this._pixelsInMeter_y);let r=0;for(let t=1,i=e.length;t<i;t++){let i=e[t];s.lineTo((-this._leftDistance+i[0])*this._pixelsInMeter_x,(n-i[1])*this._pixelsInMeter_y);let o=e[t-1],a=i[0]-o[0],l=i[1]-o[1],h=a*a,c=l*l;r+=Math.sqrt(h+c)}s.stroke(),s.lineWidth=2,s.strokeStyle="rgba(255,255,255,0.7)",s.beginPath();let o=(-this._leftDistance+i[0])*this._pixelsInMeter_x,a=(n-i[1])*this._pixelsInMeter_y,l=(n-t[i[2]][1])*this._pixelsInMeter_y;s.moveTo(o,a),s.lineTo(o,l);for(let i=1,r=e.length;i<r;i++){let r=e[i];o=(-this._leftDistance+r[0])*this._pixelsInMeter_x,a=(n-r[1])*this._pixelsInMeter_y,l=(n-t[r[2]][1])*this._pixelsInMeter_y,s.strokeStyle="rgba(255,255,255,0.7)",s.moveTo(o,a),s.lineTo(o,l)}s.stroke(),this.events.dispatch(this.events.tracklength,r)}}_drawTerrain(e){let t=e[0],i=this._ctx;if(i){const s=this.model.maxY;i.lineWidth=5,i.strokeStyle=Cr,i.beginPath(),i.moveTo((-this._leftDistance+t[0])*this._pixelsInMeter_x,this.$canvas.height),i.lineTo((-this._leftDistance+t[0])*this._pixelsInMeter_x,(s-t[1])*this._pixelsInMeter_y);let n=0;for(let t=1,r=e.length;t<r;t++){let r=e[t];i.lineTo((-this._leftDistance+r[0])*this._pixelsInMeter_x,(s-r[1])*this._pixelsInMeter_y);let o=e[t-1],a=r[0]-o[0],l=r[1]-o[1],h=a*a,c=l*l;n+=Math.sqrt(h+c)}i.lineTo((-this._leftDistance+e[e.length-1][0])*this._pixelsInMeter_x,this.$canvas.height),i.closePath(),i.stroke(),i.save(),i.fillStyle="rgb(64, 68, 82)",i.globalAlpha=.5,i.fill(),i.restore(),i.globalAlpha=1,this.events.dispatch(this.events.groundlength,n)}}_drawWarningAndCollision(e){let t=this._ctx;if(t&&e.length>1){let i=this.model.maxY;t.lineWidth=5,t.beginPath();let s=0,n=0;for(let r=0,o=e.length-1;r<o;r++){let o=e[r],a=e[r+1];if(0!==o[2]&&0!==a[2]){let e=a[0]-o[0],r=a[1]-o[1],l=e*e,h=r*r;2===o[2]?(t.stroke(),t.beginPath(),t.strokeStyle=Tr[2],n+=Math.sqrt(l+h)):1===o[2]&&(t.stroke(),t.beginPath(),t.strokeStyle=Tr[1],s+=Math.sqrt(l+h)),t.moveTo((-this._leftDistance+o[0])*this._pixelsInMeter_x,(i-o[1])*this._pixelsInMeter_y),t.lineTo((-this._leftDistance+a[0])*this._pixelsInMeter_x,(i-a[1])*this._pixelsInMeter_y)}}t.stroke(),this.events.dispatch(this.events.warninglength,s),this.events.dispatch(this.events.collisionlength,n)}}}let Ar=mi.createCylinder(.33,0,1,20,1,!0,!1,0,0,0),Pr=mi.createCylinder(.33,.33,1.1,20,1,!0,!0,0,-.55,0);const Sr={startPosition:new oe,endPosition:new oe,startColor:"rgba(255,131,0,0.2)",endColor:"rgba(255,131,0,1.0)",thickness:2.7},Mr={src:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjEuNBNAaMQAAAiLSURBVHhe7Z0r0BxFEMcjIhAIRERERAQCgUAgEBEIBAIRiUAgIiIQiAgEIlUREQgEIgIREYFAIBCIiAgEIiIiAoGIoHimqPAKz5CP/t23/8vcbe89d/dmZ/pf9avLdZK72e6+ee3M7Imjo6Opc8o4b7xn3DIeGEOJz+Y7+C6+k+/2yjQZXOMEOGdcNe4anv4wvjV+m73bT3wGn8VneqIMlIUyeWXNGteYKTj4feNrI9W/xi/HfxxVfCffnYqyUcbJJINrzIjTxjvGV0aqn43fj/+YhSgLZUpFmd81uAbv2rLANWbAC8ZHxp+GxC8ufZ+rKGNaI1FLcC1ck3etB8U1HhCqzk8N6T/jENV7X6LsXIN008iqeXCNB+B54zND+tt4ePzHIsS1cE0SicA1e74YFdc4IgyjrhvqTP3TvJas9Bq59oP2EVzjCJw03jI0TCMBcurUDS1qBCU9PnjbwCeerwbFNQ4MVd9tQ5pyG7+v0mvHJ6N3FF3jgFwy1JPvmlipUfIFvmHY6/luEFzjANDO0fGRfm1eQ0+UzlriqzOG58tecY0985LxnYH+al5D3ZKP8Bm+83zaG66xRy4a6uzU3NZvK/nqkUEH0fNtL7jGHqBH+4EhTWEGL2ddMwYZJbjGPaGgHxuIDA7tJ/mQGdLek8A17sHTxucGiva+P6kGxbf42PP9TrjGHUmDH1V+/xokCVzjDkTwx1HvSeAat4R2SWP8CP7wko9ZmrZ3n8A1bok6fBH88SRf4/u9ksA1bgFr4ZDG+qHxpLuKLFD1YrMRrnFDLhjocfMaGl8aIjLh5sVoLa5xA140+lhxG+pHNAk7TRu7xjXQ+9TK3Jru4ecqxYB7B88YXsw6cY1rUKcv7ujlI907YLbQi1knrnEFavej05ef1ClkpZUXOxfX2AH3p6Pdz1/E6FnDi2EL19iBVu3Gbd18pdgwU+jFsIVrdHjDQHGDJ39pkojm2ovlAq5xCXqWWtETmo7uG2t3L7vGJTTbF73+6UhNARtVvZjOcY0JZ42Y45+uGK2t7BC6xoQbBoqO3/SkGpt5Gy+2M1xjw3MGGZRubgxNS5qv6dxw4hob9OuPsf90pWnizlrANRpM+sSvvwypFqBGb8W6ZWjgHjOKtn/6Ug3OMv1WrFsG4ykjqv3yxGiudbdw4U2DbvjEuL8cqSZv7TJaeNOg1b2h8nTHWIj3whuDSQOUHmcSKkPagr5wNE0afLhioOj8lSc16QvTw2nwYfk8vlB5YjnfPOZp8FX9x8kd5Uqju3kzkCYAPUQU1X+5UjPACaatBEiPcAmVrfmKIQU/Jn/qEpNCs82lSgCOL0U/Na+hcvVD8/qKMU8AjiZDsdGjfCnGl415AnyCJVSVZptIlAD3sISqEgt9ZwnAHSIU07/1SMv7T5EA7CpFPzavofKljuA5EkCbPmICqB4p1m+SAPQGQ3XqMgnAQwtCdeo6CRBTwPXqJgnAKpFQnbpDAsQcQL26RwLEzt96dZ8ECFWsSIDKFQlQuSIBKlckQOUiAThLJlSnZqOAmAeoV7N5gJgJrFd3SQCePBGqU7dIgLgbWK9mdwO1ITRUn66QADoQIlYE1SPF+gIJEGsC69PCmkDOk0WxKrgeaQf4aRIA9AiYUD2a7wuA2BlUn1gKOE8A9ouj2BtYvh42r4z+5gnATlEUHcHy9X3z+poxT4A4H6Aecfxv63wAiOXh9ah1QgioHxAnhJYr1fKz9h/SBOA0aRSnhJUrJQCP/m0lAMQ5geWr85xA0I2haAbKk4b4K08KVTMQ08LlSU37vPqHNPgiVgiVK5r4hXgvvGm4aKC4PVyOFMuNnhfABEFMCpWnjZ8YAjxfBkUiTF/q/LH0rxXrlqFBJ4friVOh6Uod+oUHRYiWIYFnzaG4QzhdqefPo/+9GK9MAJ42SQ0QtcB0pV//wtAvxTUmqBaIiaHpSff9Z0fCduEaE+gLxBNEpyliRuzctl+4xiU0Ioh5gelIsfrQ8GI6xzUuwdjxgRGalojZacOL6RzX6KDNI0wmhPKWev6tWT8P19jBFwaKDmG+0pD9tnHS8OK4gGvsgDuFUQPkr7UdvxTXuAI9Wk7nzYfykX6clwwvdi6ucQ3MKqEYFeQjxYKFvRtV/cI1roG9hDpdNNYPHl6KAWc9re31L+MaN4DHzMUUcT4iFi8bXqxW4ho3RP2Bx81raHw9al557J8Xo7W4xi24ZqAYHYwv+XztbN8qXOMW0OFQpzBuG48n+XrrTt8yrnFLWELGViMUSTC85GN8Ptvftw+ucQcYGTD7hCIJhpN8y8rtrXv8Hq5xR7hpdNdAkQT9Sz7Fx70EH1zjHlAl6Z5BdAz7k3xJLdta2bsPrnFP0j5BzBXsL/mwlzZ/GdfYA/RMbxgo5gl2l3yHL/fq7XfhGnskfSpp3DvYXKmvZs/5HwrX2DOcP6QVRVqoGOqWfMSmnFcNz6e94RoH4IyhziGLFeMmUlv4RItv8RU+83zZK65xIGjDOH9AnZoYKj6RfIFvrhqDtPcernFg2KTwpSHVvMQsvXa2bnNus+ezwXCNI6DaQOPbGoeLumZ8gC9G+9WnuMYRYeOJdh+hGiaP0mvkiF584PlmFFzjAWAxgzqJqMRESK+Ja91pAUffuMYDwvGlaSJQTU65j0DZ0+aNaztveNd+EFxjBjB3QPWYOm9Kh1WkZeUa2KDJNXnXelBcY0bQPnKs2fIj7nOsFZbLRJkp+0Hb+HW4xgzhMGuqTubEl2sC9igcYpqZ71zeH0HZKCNlpczetWSFa8wcJQO7lrtONiUQ3xh9TDbxGXxWVxNEGSjLZIKe4honxlnjdYMFqnSyhhxB8Nl8B9/Fd/LdXpkmg2ssANpdfpEsXacdZq6BJ6Tya+VZyWnnUsLG3/Fv+Lf8H/4vn8FnZd2W78bRif8BxMOwtJg5Ph4AAAAASUVORK5CYII=",color:"rgb(255,131,0)",size:[8,8]},Rr={text:"",face:"arial",size:10.5,color:"rgba(455,455,455,1.0)",outlineColor:"rgba(0,0,0,0.34)",outline:.23,align:"left",offset:[5,15,-5]},Br={face:"arial",text:"",size:10.5,color:"rgba(455,455,455,1.0)",outlineColor:"rgba(0,0,0,0.34)",outline:.23,align:"right",offset:[-47,25,0]},kr={instanced:!0,tag:"ground-pointer",color:"rgb(0,305,0)",object3d:Ar},Ir={instanced:!0,tag:"head-pointer",color:"rgb(305,305,0)",object3d:Pr};class zr extends Ri{constructor(e={}){super("ElevationProfileScene"),this._onLClick=e=>{let t=this._planet.getCartesianFromPixelTerrain(e.pos);t&&this.addGroundPoint3vAsync(t)},this._onMouseMove=e=>{if(this._planet.getCartesianFromMouseTerrain(),this._pickedGroundEntity){let t=new ae(e.x,e.y).sub(this._startClickPos),i=this._startEntityPos.add(t),s=this._planet.getCartesianFromPixelTerrain(i);s&&this.setGroundPointCartesian3v(this._pickedGroundEntity.properties.index,s)}else if(this._pickedHeadEntity){let t=this._planet.camera,i=this._pickedHeadEntity.properties.groundEntity.getCartesian(),s=this._planet.ellipsoid.getSurfaceNormal3v(i),n=i.add(s),r=i.add(t.getRight()),o=new oe;if(new ui(t.eye,e.direction).hitPlaneRes(_i.fromPoints(i,n,r),o)===ui.INSIDE){let e=oe.proj_b_to_a(o,i),t=e.sub(i).dot(i),n=i.add(s.scale(Math.sign(t)*e.distance(i)));this.setHeadPointCartesian3v(this._pickedHeadEntity.properties.index,n)}}},this._onLUp=e=>{},this._onGroundPointerEnter=e=>{e.renderer.handler.canvas.style.cursor="pointer"},this._onGroundPointerLeave=e=>{e.renderer.handler.canvas.style.cursor="default"},this._onGroundPointerLDown=e=>{this._clampToGround=!1,this.renderer.controls.mouseNavigation.deactivate(),this._pickedGroundEntity=e.pickingObject;const t=this._pickedGroundEntity.getCartesian();this._startClickPos.set(e.x,e.y),this._startEntityPos=this._planet.getPixelFromCartesian(t)},this._onGroundPointerLUp=e=>{this._clampToGround=!0,this.renderer.controls.mouseNavigation.activate(),this._pickedGroundEntity=null},this._onHeadPointerEnter=e=>{e.renderer.handler.canvas.style.cursor="pointer"},this._onHeadPointerLeave=e=>{e.renderer.handler.canvas.style.cursor="default"},this._onHeadPointerLDown=e=>{this.renderer.controls.mouseNavigation.deactivate(),this._pickedHeadEntity=e.pickingObject},this._onHeadPointerLUp=e=>{this.renderer.controls.mouseNavigation.activate(),this._pickedHeadEntity=null},this.events=Mt(Dr),this._planet=e.planet||null,this._pickedGroundEntity=null,this._pickedHeadEntity=null,this._startClickPos=new ae,this._startEntityPos=new ae,this._clampToGround=!0,this._trackLayer=new qs("track",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-1,relativeToGround:!0,hideInLayerSwitcher:!0}),this._groundPointersLayer=new qs("ground-pointers",{entities:[],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[1,5e3,.02],pickingScale:1.5}),this._headPointersLayer=new qs("head-pointers",{entities:[],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[1,1e4,.02],pickingScale:1}),this._columnPointersLayer=new qs("column-pointers",{entities:[],pickingEnabled:!1,hideInLayerSwitcher:!0}),this._trackEntity=new Si({polyline:{path3v:[],thickness:3.8,color:"rgba(0,305,0,0.8)",isClosed:!1}}),this._trackLayer=new qs("column-pointers",{entities:[this._trackEntity],pickingEnabled:!1,hideInLayerSwitcher:!0}),this._heightsLayer=new qs("heights-labels",{entities:[],pickingEnabled:!1,hideInLayerSwitcher:!0}),this._pointerHeadEntity=new Si({cartesian:new oe,billboard:Mr}),this._pointerLabelEntity=new Si({cartesian:new oe,label:Rr}),this._pointerRayEntity=new Si({cartesian:new oe,ray:Sr}),this._pointerLayer=new qs("pointer",{entities:[this._pointerHeadEntity,this._pointerLabelEntity,this._pointerRayEntity],pickingEnabled:!1,hideInLayerSwitcher:!0})}flyExtent(){let e=this._headPointersLayer.getEntities(),t=180,i=180,s=-180,n=-180,r=-1e6;if(e.length>1){for(let o=0;o<e.length;o++){let a=e[o].getLonLat();a.lon<t&&(t=a.lon),a.lat<i&&(i=a.lat),a.lon>s&&(s=a.lon),a.lat>n&&(n=a.lat),a.height>r&&(r=a.height)}this._planet.camera.flyExtent(new te(new I(t,i),new I(s,n)),r,null,0)}}get planet(){return this._planet}_createGroundPointer(e,t=10){let i=this.ellipsoid.getSurfaceNormal3v(e),s=e.add(i.scale(t)),n=new Si({ray:{startPosition:e,endPosition:s,startColor:"rgba(255,255,255,0.2)",endColor:"rgba(355,355,355,1.0)",thickness:3.2}}),r=new Si({cartesian:e,geoObject:kr}),o=new Si({cartesian:s,geoObject:Ir,properties:{}}),a=new Si({cartesian:s,label:Br});a.appendChild(new Si({cartesian:s,label:{...Br,offset:[-47,45,0]}}));const l=this._groundPointersLayer.getEntities().length;return n.properties=r.properties=o.properties={index:l,altitude:t,lonLatEll:new I,headEntity:o,groundEntity:r,columnEntity:n,heightLabelEntity:a},{headEntity:o,groundEntity:r,columnEntity:n,heightLabelEntity:a}}setPointerCartesian3v(e,t){this._pointerLabelEntity.setCartesian3v(e),this._pointerLabelEntity.label.setText(`${Math.round(t).toString()} m`),this._pointerRayEntity.ray.setEndPosition3v(e);let i=this._planet.ellipsoid.getSurfaceNormal3v(e);this._pointerRayEntity.ray.setStartPosition3v(e.add(i.scale(-t))),this._pointerHeadEntity.setCartesian3v(e)}bindPlanet(e){this._planet=e}init(){this._activate()}onremove(){this._deactivate()}_activate(){this._planet.addLayer(this._trackLayer),this._planet.addLayer(this._groundPointersLayer),this._planet.addLayer(this._columnPointersLayer),this._planet.addLayer(this._headPointersLayer),this._planet.addLayer(this._heightsLayer),this._planet.addLayer(this._pointerLayer),this.renderer.events.on("ldblclick",this._onLClick),this.renderer.events.on("mousemove",this._onMouseMove),this.renderer.events.on("lup",this._onLUp),this._groundPointersLayer.events.on("mouseenter",this._onGroundPointerEnter),this._groundPointersLayer.events.on("mouseleave",this._onGroundPointerLeave),this._groundPointersLayer.events.on("ldown",this._onGroundPointerLDown),this._groundPointersLayer.events.on("lup",this._onGroundPointerLUp),this._headPointersLayer.events.on("mouseenter",this._onHeadPointerEnter),this._headPointersLayer.events.on("mouseleave",this._onHeadPointerLeave),this._headPointersLayer.events.on("ldown",this._onHeadPointerLDown),this._headPointersLayer.events.on("lup",this._onHeadPointerLUp),this.setPointerVisibility(!1)}getPointLonLat(e){let t=this._headPointersLayer.getEntities()[e];if(t)return t.getLonLat()}getPointsLonLat(){let e=this._headPointersLayer.getEntities(),t=new Array(e.length);for(let i=0,s=t.length;i<s;i++){let s=e[i];t[i]=s.getLonLat()}return t}getHeightMSL(e){return this._planet&&this._planet.terrain.geoid?this._planet.terrain.geoid.getHeightLonLat(e):0}getHeightELLAsync(e){return new Promise(((t,i)=>{this._planet.terrain.getHeightAsync(e,(s=>{if(this._planet){let i=this.getHeightMSL(e);t(s+i)}else i()}))}))}addPointLonLatArrayAsync(e,t=!1){if(!this._planet)throw new Error("Planet is not defined");let i=this._planet.ellipsoid;for(let t=0,s=e.length-1;t<s;t++){let s=i.lonLatToCartesian(e[t]),n=i.lonLatToCartesian(e[t+1]);if(s.distance(n)>1e5)throw new Error("Track is too long! 100 km is maximum.")}let s=new Array(e.length);for(let t=0,i=e.length;t<i;t++)s[t]=this.addPointLonLatAsync(e[t],!0);return Promise.all(s).then((()=>{t||this.events.dispatch(this.events.change,this)})),s}addPointLonLatAsync(e,t=!1){let i=this._planet.ellipsoid.lonLatToCartesian(e),s=this._planet.ellipsoid.getSurfaceNormal3v(i),n=new I(e.lon,e.lat),r=this._planet.ellipsoid.lonLatToCartesian(n),{headEntity:o,groundEntity:a,columnEntity:l,heightLabelEntity:h}=this._createGroundPointer(r);return this._groundPointersLayer.add(a),this._columnPointersLayer.add(l),this._headPointersLayer.add(o),this._heightsLayer.add(h),this._trackEntity.polyline.appendPoint3v(o.getCartesian()),a.properties.lonLatEll.lon=n.lon,a.properties.lonLatEll.lat=n.lat,a.properties.lonLatEll.height=n.height,new Promise((n=>{this.getHeightELLAsync(e).then((r=>{a.properties.lonLatEll.height=r;let l,c=10;0===e.height?(l=i.add(s.scaleTo(r)),i=l.add(s.scaleTo(c))):(c=e.height-r,l=i.sub(s.scaleTo(c))),a.setCartesian3v(l),h.setCartesian3v(i),h.label.setText(`${r.toFixed(1)} m`),h.childEntities[0].label.setText(`${c.toFixed(1)} m`),o.properties.altitude=c,o.setCartesian3v(i),o.properties.columnEntity.ray.setStartPosition3v(l),o.properties.columnEntity.ray.setEndPosition3v(i),this._trackEntity.polyline?.setPoint3v(i,o.properties.index),t||(this.events.dispatch(this.events.addpoint,o,this),this.events.dispatch(this.events.change,this)),n(o)}))}))}addGroundPointLonLatAsync(e,t=10,i=!1){let s=this._planet.ellipsoid.lonLatToCartesian(e);return this._addPoint(s,e,t,i)}addGroundPoint3vAsync(e,t=10,i=!1){let s=this._planet.ellipsoid.cartesianToLonLat(e);return this._addPoint(e,s,t,i)}_addPoint(e,t,i,s=!1){return new Promise(((n,r)=>{let{headEntity:o,groundEntity:a,columnEntity:l,heightLabelEntity:h}=this._createGroundPointer(e,i);this._groundPointersLayer.add(a),this._columnPointersLayer.add(l),this._headPointersLayer.add(o),this._heightsLayer.add(h),this._trackEntity.polyline.appendPoint3v(o.getCartesian()),a.properties.lonLatEll.lon=t.lon,a.properties.lonLatEll.lat=t.lat,a.properties.lonLatEll.height=t.height,this.getHeightELLAsync(t).then((e=>{a.properties.lonLatEll.height=t.height=e;let r=this._planet.ellipsoid.lonLatToCartesian(t),l=this._planet.ellipsoid.getSurfaceNormal3v(r),c=r.add(l.scale(i));h.setCartesian3v(c),h.label.setText(`${e.toFixed(1)} m`),h.childEntities[0].label.setText(`${i.toFixed(1)} m`),o.setCartesian3v(c),o.properties.columnEntity.ray.setEndPosition3v(c),this._trackEntity.polyline?.setPoint3v(c,o.properties.index),s||(this.events.dispatch(this.events.addpoint,o,this),this.events.dispatch(this.events.change,this)),n(o)}))}))}setHeadPointCartesian3v(e,t){const i=this._headPointersLayer.getEntities()[e];if(i){let s=this._planet.ellipsoid.lonLatToCartesian(i.properties.lonLatEll),n=t.length()-s.length();n<=0&&(t=s,n=0),i.properties.altitude=n,i.setCartesian3v(t),i.properties.columnEntity.ray.setEndPosition3v(t),i.properties.heightLabelEntity.setCartesian3v(t),i.properties.heightLabelEntity.childEntities[0].label.setText(`${n.toFixed(1)} m`),this._trackEntity.polyline.setPoint3v(t,e),this.events.dispatch(this.events.change,this._pickedHeadEntity)}}setGroundPointCartesian3v(e,t){let i=this._groundPointersLayer.getEntities()[e];if(i){let e=this._planet.ellipsoid.cartesianToLonLat(t);i.properties.lonLatEll.lon=e.lon,i.properties.lonLatEll.lat=e.lat,i.properties.lonLatEll.height=e.height;let s=this._planet.ellipsoid.getSurfaceNormal3v(t),n=i.properties.headEntity,r=i.properties.heightLabelEntity,o=i.properties.altitude;i.setCartesian3v(t);let a=t.add(s.scale(o));n.setCartesian3v(a),n.properties.columnEntity.ray.setStartPosition3v(t),n.properties.columnEntity.ray.setEndPosition3v(a),this._trackEntity.polyline?.setPoint3v(a,n.properties.index),r.setCartesian3v(a),r.label.setText(`${e.height.toFixed(1)} m`),r.childEntities[0].label.setText(`${o.toFixed(1)} m`),this.events.dispatch(this.events.change,i.properties.headEntity)}}_deactivate(){this.renderer.events.off("ldblclick",this._onLClick),this.renderer.events.off("mousemove",this._onMouseMove),this.renderer.events.off("lup",this._onLUp),this._groundPointersLayer.events.off("mouseenter",this._onGroundPointerEnter),this._groundPointersLayer.events.off("mouseleave",this._onGroundPointerLeave),this._groundPointersLayer.events.off("ldown",this._onGroundPointerLDown),this._groundPointersLayer.events.off("lup",this._onGroundPointerLUp),this._headPointersLayer.events.off("mouseenter",this._onHeadPointerEnter),this._headPointersLayer.events.off("mouseleave",this._onHeadPointerLeave),this._headPointersLayer.events.off("ldown",this._onHeadPointerLDown),this._headPointersLayer.events.off("lup",this._onHeadPointerLUp),this._trackLayer.remove(),this._groundPointersLayer.remove(),this._headPointersLayer.remove(),this._columnPointersLayer.remove(),this._trackLayer.remove(),this._heightsLayer.remove(),this._pointerLayer.remove(),this.clear()}setPointerVisibility(e){this._pointerLayer.setVisibility(e)}setVisibility(e){this._groundPointersLayer.setVisibility(e),this._trackLayer.setVisibility(e),this._columnPointersLayer.setVisibility(e),this._headPointersLayer.setVisibility(e),this._trackLayer.setVisibility(e),this._heightsLayer.setVisibility(e),this._pointerLayer.setVisibility(e)}clear(){this._headPointersLayer.setEntities([]),this._groundPointersLayer.setEntities([]),this._columnPointersLayer.setEntities([]),this._heightsLayer.setEntities([]),this._trackEntity.polyline.setPath3v([])}frame(){if(this._clampToGround){let e=new oe;const t=this._planet._renderedNodes,i=this._groundPointersLayer.getEntities();for(let s=0;s<i.length;s++){let n=i[s];for(let i=0;i<t.length;i++){let s=t[i];if(s.segment.isEntityInside(n)){s.segment.getEntityTerrainPoint(n,e),n.setCartesian3v(e),n.properties.columnEntity.ray.setStartPosition3v(e);break}}}}}get ellipsoid(){return this._planet?this._planet.ellipsoid:null}}const Dr=["change","addpoint"],Fr=["reset","list","location"];class Nr extends kt{constructor(e={}){super({...e,template:'<div class="og-elevationprofile-buttons"></div>'}),this.events=this.events.registerNames(Fr),this.pointListBtn=new Ut({classList:["og-elevationprofile-button"],icon:'<?xml version="1.0" encoding="utf-8"?><svg width="800px" height="800px" viewBox="0 0 32 32" id="icon" xmlns="http://www.w3.org/2000/svg"><defs><style>.cls-1{fill:none;}</style></defs><title>list</title><rect x="10" y="6" width="18" height="2"/><rect x="10" y="24" width="18" height="2"/><rect x="10" y="15" width="18" height="2"/><rect x="4" y="15" width="2" height="2"/><rect x="4" y="6" width="2" height="2"/><rect x="4" y="24" width="2" height="2"/></svg>',title:"Point List"}),this.pointListBtn.events.on("change",(e=>{this.events.dispatch(this.events.list,e)}))}render(e){super.render(e);let t=new zt({classList:["og-elevationprofile-button"],icon:'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg width="30" height="30" viewBox="0 0 30 30" version="1.1">\n <g transform="translate(0,-289.0625)">\n <path d="M 15 6 C 10.041282 6 6 10.04128 6 15 C 6 19.95872 10.041282 24 15 24 C 16.586491 24 18.07668 23.58246 19.373047 22.857422 L 17.888672 21.375 C 17.00816 21.772814 16.032235 22 15 22 C 11.122162 22 8 18.87784 8 15 C 8 11.12216 11.122162 8 15 8 C 18.877838 8 22 11.12216 22 15 L 19 15 L 23 20 L 27 15 L 24 15 C 24 10.04128 19.958718 6 15 6 z " transform="translate(0,289.0625)" />\n </g>\n</svg>',title:"Reset"});t.appendTo(this.el),t.events.on("click",(()=>{this.model.clear(),this.events.dispatch(this.events.reset,this)})),this.pointListBtn.appendTo(this.el);let i=new zt({classList:["og-elevationprofile-button","og-elevationprofile-button__location"],icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Svg Vector Icons : http://www.onlinewebfonts.com/icon --\x3e\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 256 256" enable-background="new 0 0 256 256" xml:space="preserve">\n<metadata> Svg Vector Icons : http://www.onlinewebfonts.com/icon </metadata>\n<g><g><path fill="#000000" d="M127,169.4c23.7,0,42.8-18.3,42.8-41s-19.2-41-42.8-41c-23.7,0-42.8,18.4-42.8,41S103.4,169.4,127,169.4z"/><path fill="#000000" d="M221.7,120.2c-3.8-44-40.9-78.9-87-82V15h-16.3v23.6c-44.8,4-80.3,38.5-84.1,81.7H10v15.6h24.3c3.8,43.1,39.3,77.4,84.1,81.7V241h16.3v-23.2c46-3.1,83.2-37.9,87-82H246v-15.6H221.7L221.7,120.2L221.7,120.2z M128,201.6c-42.5,0-76.7-33-76.7-73.4c0-40.4,34.5-73.4,76.7-73.4c42.5,0,76.7,33,76.7,73.4C204.7,168.5,170.5,201.6,128,201.6L128,201.6z"/></g></g>\n</svg>',title:"View bounds"});return i.appendTo(this.el),i.events.on("click",(()=>{this.events.dispatch(this.events.location,this)})),this}}class Hr extends Ot{constructor(e){super({title:"Points List",visible:!1,resizable:!0,useHide:!0,top:150,left:200,width:400,height:300,minHeight:100,minWidth:100,...e}),this._onApplyClick=()=>{try{this.model.clear();let e=JSON.parse(this.$textarea.value),t=new Array(e.length);for(let i=0;i<e.length;i++){let s=e[i];t[i]=new I(s[0],s[1],s[2])}this.model.addPointLonLatArrayAsync(t)}catch(e){console.error(e)}},this.$textarea=null}render(e){super.render(e);let t=new kt({template:'<div class="og-elevationprofile-list">\n <textarea placeholder="[[lon, lat, height], [lon, lat, height], ..., [lon, lat, height]]"></textarea>\n <div class="og-elevationprofile-list-buttons"></div>\n </div>'});t.appendTo(this.container);let i=new zt({classList:["og-elevationprofile-list-apply"],icon:"Apply"});return i.appendTo(t.select(".og-elevationprofile-list-buttons")),i.events.on("click",this._onApplyClick),this.$textarea=t.select("textarea"),this}}class Or extends kt{constructor(e={}){super({...e,template:'<div class="og-elevationprofile-legend">\n <div class="og-elevationprofile-legend__row og-elevationprofile-legend__track">\n <div class="og-elevationprofile-square"></div>\n <div class="og-elevationprofile-value">0</div>\n <div class="og-elevationprofile-units">m</div>\n </div>\n <div class="og-elevationprofile-legend__row og-elevationprofile-legend__ground">\n <div class="og-elevationprofile-square"></div>\n <div class="og-elevationprofile-value">0</div>\n <div class="og-elevationprofile-units">m</div>\n </div>\n <div class="og-elevationprofile-legend__row og-elevationprofile-legend__warning"> \n <div class="og-elevationprofile-square"></div>\n <div class="og-elevationprofile-value">0</div>\n <div class="og-elevationprofile-units">m</div>\n </div>\n <div class="og-elevationprofile-legend__row og-elevationprofile-legend__collision">\n <div class="og-elevationprofile-square"></div>\n <div class="og-elevationprofile-value">0</div>\n <div class="og-elevationprofile-units">m</div>\n </div>\n </div>'}),this.$groundValue=null,this.$trackValue=null,this.$warningValue=null,this.$collisionValue=null,this.$trackUnits=null,this.$groundUnits=null,this.$warningUnits=null,this.$collisionUnits=null}render(e){return super.render(e),this.$trackValue=this.select(".og-elevationprofile-legend__track .og-elevationprofile-value"),this.$groundValue=this.select(".og-elevationprofile-legend__ground .og-elevationprofile-value"),this.$warningValue=this.select(".og-elevationprofile-legend__warning .og-elevationprofile-value"),this.$collisionValue=this.select(".og-elevationprofile-legend__collision .og-elevationprofile-value"),this.$trackUnits=this.select(".og-elevationprofile-legend__track .og-elevationprofile-units"),this.$groundUnits=this.select(".og-elevationprofile-legend__ground .og-elevationprofile-units"),this.$warningUnits=this.select(".og-elevationprofile-legend__warning .og-elevationprofile-units"),this.$collisionUnits=this.select(".og-elevationprofile-legend__collision .og-elevationprofile-units"),this}clear(){this.$trackValue&&(this.$trackValue.innerText="0"),this.$trackUnits&&(this.$trackUnits.innerText="m"),this.$groundValue&&(this.$groundValue.innerText="0"),this.$groundUnits&&(this.$groundUnits.innerText="m"),this.$warningValue&&(this.$warningValue.innerText="0"),this.$warningUnits&&(this.$warningUnits.innerText="m"),this.$collisionValue&&(this.$collisionValue.innerText="0"),this.$collisionUnits&&(this.$collisionUnits.innerText="m")}setTrackLength(e){let t=Ke(e);this.$trackValue.innerText=t[0],this.$trackUnits.innerText=t[1]}setGroundLength(e){let t=Ke(e);this.$groundValue.innerText=t[0],this.$groundUnits.innerText=t[1]}setWarningLength(e){let t=Ke(e);this.$warningValue.innerText=t[0],this.$warningUnits.innerText=t[1]}setCollisionLength(e){let t=Ke(e);this.$collisionValue.innerText=t[0],this.$collisionUnits.innerText=t[1]}}const Vr="rgb(253,77,77)",Ur="rgb(248,115,115)",Gr="rgb(73,73,239)",Yr="rgb(90,90,253)",jr="rgb(26,122,26)",Wr="rgb(55,191,55)",qr="rgba(255,255,255,0.8)",$r=.1,Xr=new oe($r,$r,$r),Zr=.17,Kr=.0095,Qr=mi.createCylinder(Kr,Kr,.83).scale(Xr),Jr=mi.createCylinder(0,.04,Zr,16,16,!1,!0,0,-.17).scale(Xr);class eo extends Si{constructor(e={}){super({independentPicking:!0,yaw:e.yaw||0,pitch:e.pitch||0,roll:e.roll||0,forceGlobalPosition:!0,geoObject:{color:e.color||Vr,scale:1,tag:"line",object3d:Qr},properties:e.properties}),this._size=null!=e.size?e.size:1,this.appendChild(new Si({yaw:e.yaw||0,pitch:e.pitch||0,roll:e.roll||0,forceGlobalPosition:!0,geoObject:{color:e.color||Vr,scale:1,tag:"tip",object3d:Jr},properties:e.properties}))}setSize(e){this._size=e;const t=new oe(1,(this._size-Zr)/.83,1),i=new oe(0,this._size*$r,0);let s=this.childEntities[0];this.setScale3v(t),s.geoObject.setTranslate3v(i)}setColorHTML(e){let t=this.childEntities[0];this.geoObject.setColorHTML(e),t.geoObject.setColorHTML(e)}}class to extends Si{constructor(e={}){super(e),this._size=null!=e.size?e.size:1,this.childEntities=[],this._init()}_init(){let e=new eo({color:Vr,yaw:0,pitch:0,roll:90*l,properties:{opName:"move_x",noEdit:!0,style:{color:Vr,selectColor:Ur}}}),t=new eo({color:Gr,yaw:0,pitch:0,roll:0,properties:{opName:"move_y",noEdit:!0,style:{color:Gr,selectColor:Yr}}}),i=new eo({color:jr,yaw:0,pitch:90*l,roll:0,properties:{opName:"move_z",noEdit:!0,style:{color:jr,selectColor:Wr}}});this.appendChild(e),this.appendChild(t),this.appendChild(i),this.setSize(this._size)}setSize(e){this.childEntities[0].setSize(e),this.childEntities[1].setSize(e),this.childEntities[2].setSize(e)}setPitch(e){let t=this.childEntities[0],i=t.childEntities[0];t.setPitch(e),i.setPitch(e),t=this.childEntities[1],i=t.childEntities[0],t.setPitch(e),i.setPitch(e),t=this.childEntities[2],i=t.childEntities[0],t.setPitch(e+90),i.setPitch(e+90)}setYaw(e){let t=this.childEntities[0],i=t.childEntities[0];t.setYaw(e),i.setYaw(e),t=this.childEntities[1],i=t.childEntities[0],t.setYaw(e),i.setYaw(e),t=this.childEntities[2],i=t.childEntities[0],t.setYaw(e),i.setYaw(e)}setRoll(e){let t=this.childEntities[0],i=t.childEntities[0];t.setRoll(e+90),i.setRoll(e+90),t=this.childEntities[1],i=t.childEntities[0],t.setRoll(e),i.setRoll(e)}getY(){return this.childEntities[1].getAbsoluteRotation().mulVec3(oe.UP).normalize()}}const io=mi.createPlane(1,1,-.5,0,.5);class so extends Si{constructor(e={}){super(e),this._init()}_init(){let e=new Si({independentPicking:!0,scale:.025,forceGlobalPosition:!0,geoObject:{color:qr,tag:"plane",object3d:io},properties:{opName:"move_xz",noEdit:!0,style:{color:qr,selectColor:"rgba(255,255,255,1.0)"}}});this.appendChild(e)}}const no=360,ro=.95,oo=new Array(no),ao=new Array(no),lo=new Array(no);class ho extends Si{constructor(e={}){super(e),this._init()}_init(){const e=no;let t=new Si({independentPicking:!0,polyline:{path3v:[Array.from({length:e},((e,t)=>new oe))],thickness:3.1,color:Vr,isClosed:!0},properties:{opName:"rotate_pitch",noEdit:!0,style:{color:Vr,selectColor:Ur}}}),i=new Si({independentPicking:!0,polyline:{path3v:[Array.from({length:e},((e,t)=>new oe))],thickness:2.5,color:Gr,isClosed:!0},properties:{opName:"rotate_yaw",noEdit:!0,style:{color:Gr,selectColor:Yr}}}),s=new Si({independentPicking:!0,polyline:{path3v:[Array.from({length:e},((e,t)=>new oe))],thickness:2.5,color:jr,isClosed:!0},properties:{opName:"rotate_roll",noEdit:!0,style:{color:jr,selectColor:Wr}}});this.appendChild(t),this.appendChild(i),this.appendChild(s)}setCartesian3v(e,t=0){if(super.setCartesian3v(e),this._entityCollection&&this._entityCollection.renderNode){let i=this._entityCollection.renderNode,s=i.renderer.activeCamera,n=i.getFrameRotation(e).conjugate(),r=.15*s.eye.distance(e),o=re.xRotation(0),a=re.yRotation(t),h=re.zRotation(0).mul(o).mul(a).mul(i.getFrameRotation(e)).conjugate();for(let t=0,i=0,s=1;t<no;t+=s,i++){let s=t*l,o=Math.cos(s),a=Math.sin(s),c=h.mulVec3(new oe(0,a,o)).normalize().scale(r).add(e),d=n.mulVec3(new oe(o,0,a)).normalize().scale(r).add(e),_=h.mulVec3(new oe(o,a,0)).normalize().scale(r).add(e);oo[i]=c,ao[i]=d,lo[i]=_}this.childEntities[0].polyline.setPath3v([oo],void 0,!0),this.childEntities[1].polyline.setPath3v([ao],void 0,!0),this.childEntities[2].polyline.setPath3v([lo],void 0,!0);let c=h.mulVec3(new oe(1,0,0)).normalize(),d=n.mulVec3(new oe(0,1,0)).normalize(),_=h.mulVec3(new oe(0,0,1)).normalize();this.childEntities[0].polyline.setVisibleSphere(e,Math.abs(c.dot(s.getForward()))>ro?0:r),this.childEntities[1].polyline.setVisibleSphere(e,Math.abs(d.dot(s.getForward()))>ro?0:r),this.childEntities[2].polyline.setVisibleSphere(e,Math.abs(_.dot(s.getForward()))>ro?0:r)}}}class co extends Si{constructor(e={}){super({...e,forceGlobalPosition:!0}),this._init()}_init(){let e=[],t=[],i=[],s=xe(Ur),n=xe(Yr),r=xe(Wr);for(let o=0;o<20;o++){let a=1;if(o<5){let e=o/5;a=.5*(1-Math.cos(Math.PI*e))}else if(o>15){let e=(o-15)/5;a=1-.5*(1-Math.cos(Math.PI*e))}t.push([r[0],r[1],r[2],a]),e.push([s[0],s[1],s[2],a]),i.push([n[0],n[1],n[2],a])}let o=new Si({polyline:{path3v:[Array.from({length:20},((e,t)=>new oe))],thickness:2.5,pathColors:[e],isClosed:!1}}),a=new Si({polyline:{path3v:[Array.from({length:20},((e,t)=>new oe))],thickness:2.5,pathColors:[i],isClosed:!1}}),l=new Si({polyline:{path3v:[Array.from({length:20},((e,t)=>new oe))],thickness:2.5,pathColors:[t],isClosed:!1}});this.appendChild(o),this.appendChild(a),this.appendChild(l)}setCartesian3v(e){if(super.setCartesian3v(e),this._entityCollection&&this._entityCollection.renderNode){let t=this._entityCollection.renderNode,i=.05*t.renderer.activeCamera.eye.distance(e);if(t.planet){let s=[],n=[],r=[],o=t.planet.ellipsoid.getSurfaceNormal3v(e),a=this._lonLat,l=10;for(let t=-l;t<l;t++)r.push(new I(a.lon,a.lat+t,a.height)),n.push(new I(a.lon+t,a.lat,a.height)),s.push(e.add(o.scaleTo(t*i)));this.childEntities[0].polyline.setPathLonLatFast([n]),this.childEntities[1].polyline.setPath3vFast([s]),this.childEntities[2].polyline.setPathLonLatFast([r])}else{let t=[],s=[],n=[],r=oe.UNIT_Y,o=oe.UNIT_X,a=oe.UNIT_Z,l=10;for(let h=-l;h<l;h++)s.push(e.add(o.scaleTo(h*i))),n.push(e.add(r.scaleTo(h*i))),t.push(e.add(a.scaleTo(h*i)));this.childEntities[0].polyline.setPath3vFast([s]),this.childEntities[1].polyline.setPath3vFast([n]),this.childEntities[2].polyline.setPath3vFast([t])}}}}function _o(e,t,i,s,n,r){let o=n.add(oe.UP),a=n.add(e),l=new oe;if(new ui(t,i).hitPlaneRes(_i.fromPoints(n,o,a),l)===ui.INSIDE){let i=oe.proj_b_to_a(l,e);if(new ui(t,s).hitPlaneRes(_i.fromPoints(n,o,a),l)===ui.INSIDE){let t=oe.proj_b_to_a(l,e).sub(i);r.copy(n.add(t))}}}class uo extends Ri{constructor(e={}){super(e.name||"GeoObjectEditorScene"),this._onAxisLayerMouseEnter=e=>{this.renderer.handler.canvas.style.cursor="pointer",e.pickingObject.setColorHTML(e.pickingObject.properties.style.selectColor)},this._onAxisLayerMouseLeave=e=>{this.renderer.handler.canvas.style.cursor="default",e.pickingObject.setColorHTML(e.pickingObject.properties.style.color)},this._onAxisLayerLUp=e=>{this._selectedMove=null,this._navActivate(),this._setAxisTrackVisibility(!1)},this._onAxisLayerLDown=e=>{this._clickPos=e.pos.clone(),this._selectedEntity&&(this._selectedEntityCart=this._selectedEntity.getAbsoluteCartesian(),this._setAxisTrackVisibility(!0)),this._selectedMove=e.pickingObject.properties.opName,this._navDeactivate()},this._onPlaneLayerMouseEnter=e=>{this.renderer.handler.canvas.style.cursor="pointer",e.pickingObject.geoObject.setColorHTML(e.pickingObject.properties.style.selectColor)},this._onPlaneLayerMouseLeave=e=>{this.renderer.handler.canvas.style.cursor="default",e.pickingObject.geoObject.setColorHTML(e.pickingObject.properties.style.color)},this._onPlaneLayerLUp=e=>{this._selectedMove=null,this._navActivate(),this._setAxisTrackVisibility(!1)},this._onPlaneLayerLDown=e=>{this._clickPos=e.pos.clone(),this._selectedEntity&&(this._selectedEntityCart=this._selectedEntity.getAbsoluteCartesian(),this._setAxisTrackVisibility(!0)),this._selectedMove=e.pickingObject.properties.opName,this._navDeactivate()},this._onRotateLayerMouseEnter=e=>{this.renderer.handler.canvas.style.cursor="pointer",e.pickingObject.polyline.setColorHTML(e.pickingObject.properties.style.selectColor)},this._onRotateLayerMouseLeave=e=>{this.renderer.handler.canvas.style.cursor="default",e.pickingObject.polyline.setColorHTML(e.pickingObject.properties.style.color)},this._onRotateLayerLUp=e=>{this._selectedMove=null,this._navActivate()},this._onRotateLayerLDown=e=>{this._clickPos=e.pos.clone(),this._selectedEntity&&(this._selectedEntityCart=this._selectedEntity.getAbsoluteCartesian(),this._selectedEntity&&(this._selectedEntityPitch=this._selectedEntity.getAbsolutePitch(),this._selectedEntityYaw=this._selectedEntity.getAbsoluteYaw(),this._selectedEntityRoll=this._selectedEntity.getAbsoluteRoll())),this._selectedMove=e.pickingObject.properties.opName,this._navDeactivate()},this._onMouseMove=e=>{this._selectedEntity&&this._selectedMove&&this._ops[this._selectedMove]&&this._ops[this._selectedMove](e)},this._onLclick=e=>{e.pickingObject&&e.pickingObject instanceof Si&&this.select(e.pickingObject)},this._moveX=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=t.unproject(this._clickPos.x,this._clickPos.y),n=new oe;if(this.planet){let r=new ui(t.eye,s).hitSphere(new Pt(i.length(),new oe)),o=new ui(t.eye,e.direction).hitSphere(new Pt(i.length(),new oe));if(!o)return;if(n=re.getRotationBetweenVectors(r.normal(),o.normal()).mulVec3(i),this._ellipsoid){let e=this._ellipsoid.cartesianToLonLat(i),t=this._ellipsoid.cartesianToLonLat(n);this._ellipsoid.lonLatToCartesianRes(new I(t.lon,e.lat,e.height),n)}}else _o(oe.UNIT_X,t.eye,s,e.direction,i,n);this._selectedEntity.setAbsoluteCartesian3v(n),this.events.dispatch(this.events.position,n,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)},this._moveY=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=oe.UP;this.planet&&(s=this._axisEntity.getY());let n=i.add(s),r=i.add(t.getRight()),o=new oe,a=t.unproject(this._clickPos.x,this._clickPos.y);if(new ui(t.eye,a).hitPlaneRes(_i.fromPoints(i,n,r),o)===ui.INSIDE){let a=oe.proj_b_to_a(o,s);if(new ui(t.eye,e.direction).hitPlaneRes(_i.fromPoints(i,n,r),o)===ui.INSIDE){let e=oe.proj_b_to_a(o,s).sub(a),t=this._selectedEntityCart.add(e);this._selectedEntity.setAbsoluteCartesian3v(t),this.events.dispatch(this.events.position,o,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)}}},this._moveZ=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=t.unproject(this._clickPos.x,this._clickPos.y),n=new oe;if(this.planet){let r=new ui(t.eye,s).hitSphere(new Pt(i.length(),new oe)),o=new ui(t.eye,e.direction).hitSphere(new Pt(i.length(),new oe));if(!o)return;if(n=re.getRotationBetweenVectors(r.normal(),o.normal()).mulVec3(i),this._ellipsoid){let e=this._ellipsoid.cartesianToLonLat(i),t=this._ellipsoid.cartesianToLonLat(n);this._ellipsoid.lonLatToCartesianRes(new I(e.lon,t.lat,e.height),n)}}else _o(oe.UNIT_Z,t.eye,s,e.direction,i,n);this._selectedEntity.setAbsoluteCartesian3v(n),this.events.dispatch(this.events.position,n,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)},this._moveXZ=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=t.unproject(this._clickPos.x,this._clickPos.y),n=new oe;if(this.planet){let r=new ui(t.eye,s).hitSphere(new Pt(i.length(),new oe)),o=new ui(t.eye,e.direction).hitSphere(new Pt(i.length(),new oe));if(!o)return;if(n=re.getRotationBetweenVectors(r.normal(),o.normal()).mulVec3(i),this._ellipsoid){let e=this._ellipsoid.cartesianToLonLat(n),t=this._selectedEntity.getLonLat().height;this._ellipsoid.lonLatToCartesianRes(new I(e.lon,e.lat,t),n)}}else{let r=i.add(oe.UNIT_X),o=i.add(oe.UNIT_Z),a=new oe,l=new oe;if(new ui(t.eye,s).hitPlaneRes(_i.fromPoints(i,r,o),a)===ui.INSIDE&&new ui(t.eye,e.direction).hitPlaneRes(_i.fromPoints(i,r,o),l)===ui.INSIDE){let e=l.sub(a);n=i.add(e)}}this._selectedEntity.setAbsoluteCartesian3v(n),this.events.dispatch(this.events.position,n,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)},this._moveXY=e=>{console.log("moveXY")},this._moveZY=e=>{console.log("moveZY")},this._rotatePitch=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=re.xRotation(0),n=re.yRotation(this._selectedEntity.getYaw()),r=re.zRotation(0).mul(s).mul(n).mul(this.getFrameRotation(i)).conjugate().mulVec3(new oe(1,0,0)).normalize(),o=t.unproject(this._clickPos.x,this._clickPos.y),a=new _i(i,r),l=new oe,h=new oe;if(new ui(t.eye,o).hitPlaneRes(a,l)===ui.INSIDE&&new ui(t.eye,e.direction).hitPlaneRes(a,h)===ui.INSIDE){let e=l.sub(i).normalize(),t=h.sub(i).normalize(),s=Math.sign(e.cross(t).dot(r)),n=Math.acos(e.dot(t)),o=this._selectedEntityPitch+s*n;this._selectedEntity.setAbsolutePitch(o),this.events.dispatch(this.events.pitch,o,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)}},this._rotateYaw=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=this.getFrameRotation(i).conjugate().mulVec3(new oe(0,1,0)).normalize(),n=t.unproject(this._clickPos.x,this._clickPos.y),r=new _i(i,s),o=new oe,a=new oe;if(new ui(t.eye,n).hitPlaneRes(r,o)===ui.INSIDE&&new ui(t.eye,e.direction).hitPlaneRes(r,a)===ui.INSIDE){let e=o.sub(i).normalize(),t=a.sub(i).normalize(),n=Math.sign(t.cross(e).dot(s)),r=Math.acos(e.dot(t)),l=this._selectedEntityYaw+n*r;this._selectedEntity.setAbsoluteYaw(l),this.events.dispatch(this.events.yaw,l,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)}},this._rotateRoll=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart;this.getFrameRotation(i).conjugate();let s=re.xRotation(0),n=re.yRotation(this._selectedEntity.getYaw()),r=re.zRotation(0).mul(s).mul(n).mul(this.getFrameRotation(i)).conjugate().mulVec3(new oe(0,0,1)).normalize(),o=t.unproject(this._clickPos.x,this._clickPos.y),a=new _i(i,r),l=new oe,h=new oe;if(new ui(t.eye,o).hitPlaneRes(a,l)===ui.INSIDE&&new ui(t.eye,e.direction).hitPlaneRes(a,h)===ui.INSIDE){let e=l.sub(i).normalize(),t=h.sub(i).normalize(),s=Math.sign(e.cross(t).dot(r)),n=Math.acos(e.dot(t)),o=this._selectedEntityRoll+s*n;this._selectedEntity.setAbsoluteRoll(o),this.events.dispatch(this.events.roll,o,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)}},this._scale=e=>{this.events.dispatch(this.events.scale,1,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)},this._scaleX=e=>{},this._scaleY=e=>{},this._scaleZ=e=>{},this.events=Mt(go),this._planet=e.planet||null,this._startPos=null,this._startClick=new ae,this._axisEntity=new to,this._planeEntity=new so,this._rotateEntity=new ho,this._axisTrackEntity=new co,this._moveLayer=new fs({scaleByDistance:[.1,r,.1],useLighting:!1,pickingScale:[5,1.1,5],visibility:!1,depthOrder:1e3}),this._planeLayer=new fs({scaleByDistance:[.1,r,.1],useLighting:!1,visibility:!1,depthOrder:1e3}),this._rotateLayer=new fs({useLighting:!1,visibility:!1,depthOrder:1e3,pickingScale:5}),this._selectedEntity=null,this._clickPos=new ae,this._selectedEntityCart=new oe,this._selectedEntityPitch=0,this._selectedEntityYaw=0,this._selectedEntityRoll=0,this._selectedMove=null,this._axisTrackVisibility=!1,this._axisTrackLayer=new fs({useLighting:!1,visibility:!1,pickingScale:5,pickingEnabled:!1,opacity:.6}),this._ops={move_x:this._moveX,move_y:this._moveY,move_z:this._moveZ,move_xz:this._moveXZ,move_xy:this._moveXY,move_zy:this._moveZY,rotate_pitch:this._rotatePitch,rotate_yaw:this._rotateYaw,rotate_roll:this._rotateRoll,scale:this._scale,scale_x:this._scaleX,scale_y:this._scaleY,scale_z:this._scaleZ}}get planet(){return this._planet}bindPlanet(e){this._planet=e}init(){this.activate()}onremove(){this.deactivate()}_addAxisLayers(){this._moveLayer.addTo(this),this._planeLayer.addTo(this),this._rotateLayer.addTo(this),this._axisTrackLayer.addTo(this),this._moveLayer.add(this._axisEntity),this._moveLayer.events.on("mouseenter",this._onAxisLayerMouseEnter),this._moveLayer.events.on("mouseleave",this._onAxisLayerMouseLeave),this._moveLayer.events.on("lup",this._onAxisLayerLUp),this._moveLayer.events.on("ldown",this._onAxisLayerLDown),this._planeLayer.add(this._planeEntity),this._planeLayer.events.on("mouseenter",this._onPlaneLayerMouseEnter),this._planeLayer.events.on("mouseleave",this._onPlaneLayerMouseLeave),this._planeLayer.events.on("lup",this._onPlaneLayerLUp),this._planeLayer.events.on("ldown",this._onPlaneLayerLDown),this._rotateLayer.add(this._rotateEntity),this._rotateLayer.events.on("mouseenter",this._onRotateLayerMouseEnter),this._rotateLayer.events.on("mouseleave",this._onRotateLayerMouseLeave),this._rotateLayer.events.on("lup",this._onRotateLayerLUp),this._rotateLayer.events.on("ldown",this._onRotateLayerLDown),this._axisTrackLayer.add(this._axisTrackEntity)}_navActivate(){this.renderer&&(this.renderer.controls.mouseNavigation&&this.renderer.controls.mouseNavigation.activate(),this.renderer.controls.SimpleNavigation&&this.renderer.controls.SimpleNavigation.activate())}_navDeactivate(){this.renderer&&(this.renderer.controls.mouseNavigation&&this.renderer.controls.mouseNavigation.deactivate(),this.renderer.controls.SimpleNavigation&&this.renderer.controls.SimpleNavigation.deactivate())}_removeAxisLayers(){this._moveLayer.remove(),this._planeLayer.remove(),this._rotateLayer.remove()}activate(){this.renderer.events.on("lclick",this._onLclick),this.renderer.events.on("mousemove",this._onMouseMove),this._addAxisLayers()}deactivate(){this.renderer.events.off("lclick",this._onLclick),this.renderer.events.off("mousemove",this._onMouseMove),this._removeAxisLayers(),this.clear()}_setAxisTrackVisibility(e){e!==this._axisTrackVisibility&&(this._axisTrackVisibility=e,this._axisTrackLayer.setVisibility(e))}setVisibility(e){this._moveLayer.setVisibility(e),this._planeLayer.setVisibility(e),this._rotateLayer.setVisibility(e),this.unlockView()}readyToEdit(e){return!e.properties||!e.properties.noEdit}select(e){(!this._selectedEntity||this._selectedEntity&&!e.isEqual(this._selectedEntity))&&this.readyToEdit(e)&&(this._selectedEntity&&this.unselect(),this._selectedEntity=e,this.renderer&&this.renderer.setRelativeCenter(),this.setVisibility(!0),this.events.dispatch(this.events.select,this._selectedEntity))}unselect(){this.setVisibility(!1);let e=this._selectedEntity;this._selectedEntity=null,this.events.dispatch(this.events.unselect,e)}clear(){this.removeEntityCollection(this._moveLayer),this.removeEntityCollection(this._planeLayer),this.removeEntityCollection(this._rotateLayer)}frame(){if(this._selectedEntity){let e=this._selectedEntity.getAbsoluteCartesian();this._axisEntity.setCartesian3v(e),this._planeEntity.setCartesian3v(e),this._rotateEntity.setCartesian3v(e,this._selectedEntity.getAbsoluteYaw()),this._axisTrackEntity.setCartesian3v(e)}}get _ellipsoid(){return this._planet?this._planet.ellipsoid:null}getFrameRotation(e){return this._planet?this._planet.getFrameRotation(e):super.getFrameRotation(e)}getSelectedEntity(){return this._selectedEntity}lockView(){if(this.renderer&&this._selectedEntity){this.renderer.controls.CameraLock.lockView(this._selectedEntity)}}unlockView(){if(this.renderer&&this._selectedEntity){let e=this.renderer.controls.CameraLock;e&&e.unlockView()}}}const go=["mousemove","mouseenter","mouseleave","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchmove","touchstart","touchend","doubletouch","touchleave","touchenter","select","unselect","change","position","pitch","yaw","roll","scale"],fo=["change"];class po extends kt{constructor(e={}){super({template:we('<div class="og-input">\n <div class="og-input-label">{label}</div>\n <input type="{type}"/>\n </div>',{label:e.label||"",type:e.type||"text"})}),this._onResize=()=>{},this._onMouseWheel=e=>{(e=e||window.event).preventDefault(),e.stopPropagation()},this._onMouseWheelFF=e=>{this._onMouseWheel(e)},this._onInput=e=>{(e=e||window.event).preventDefault(),e.stopPropagation(),this._setValue(e.target.value)},this.events=this.events.registerNames(fo),this._value=e.value||"",this._maxFixed=null!=e.maxFixed?e.maxFixed:-1,this.$label=null,this.$input=null}render(e){return super.render(e),this.$label=this.select(".og-input-label"),""===this.$label.innerHTML&&(this.$label.style.display="none"),this.$input=this.select("input"),this._initEvents(),this}set value(e){e!==this._value&&(this._value="number"==typeof e?Je(e,this._maxFixed):e,this.$input&&(this.$input.value=this._value),this.events.dispatch(this.events.change,this._value,this))}_setValue(e){e!==this._value&&(this._value="number"==typeof e?Je(e,this._maxFixed):e,this.events.dispatch(this.events.change,this._value,this))}get value(){return this._value}_initEvents(){this.el.addEventListener("mousewheel",this._onMouseWheel),this.el.addEventListener("wheel",this._onMouseWheelFF),this.$input.addEventListener("input",this._onInput)}_clearEvents(){this.el.removeEventListener("mousewheel",this._onMouseWheel),this.el.removeEventListener("wheel",this._onMouseWheelFF),this.$input.removeEventListener("input",this._onInput)}remove(){this._clearEvents(),super.remove()}set visibility(e){this.el&&(this.el.style.display=e?"":"none")}}const mo=["change"];class vo extends kt{constructor(e={}){super({template:we('<div class="og-checkbox">\n <div class="og-input-label">{label}</div>\n <div class="og-checkbox-input">\n <input type="checkbox" {checked}/>\n </div>\n </div>',{label:e.label||"",checked:e.checked?"checked":""})}),this._onResize=()=>{},this._onMouseWheel=e=>{(e=e||window.event).preventDefault(),e.stopPropagation()},this._onMouseWheelFF=e=>{this._onMouseWheel(e)},this._onClick=e=>{(e=e||window.event).stopPropagation(),this.checked=!this._checked},this._checked=e.checked||!1,this._disabled=e.disabled||!1,this.events=this.events.registerNames(mo),this.$label=null,this.$input=null}set disabled(e){this._disabled=e,this._updateDisabled()}_updateDisabled(){this.el&&(this._disabled?this.el.classList.add("og-input-disabled"):this.el.classList.remove("og-input-disabled"))}get disabled(){return this._disabled}render(e){return super.render(e),this.$label=this.select(".og-input-label"),""===this.$label.innerHTML&&(this.$label.style.display="none"),this.$input=this.select("input"),this.$input.checked=this._checked,this._updateDisabled(),this._initEvents(),this}set checked(e){e!==this._checked&&(this._checked=e,this.$input&&(this.$input.checked=this._checked),this.events.dispatch(this.events.change,this._checked,this))}get checked(){return this._checked}_initEvents(){this.el.addEventListener("mousewheel",this._onMouseWheel),this.el.addEventListener("wheel",this._onMouseWheelFF),this.$input.addEventListener("click",this._onClick)}_clearEvents(){this.el.removeEventListener("mousewheel",this._onMouseWheel),this.el.removeEventListener("wheel",this._onMouseWheelFF),this.$input.removeEventListener("click",this._onClick)}remove(){this._clearEvents(),super.remove()}set visibility(e){this.el&&(this.el.style.display=e?"":"none")}}class yo extends Ot{constructor(e){super({title:"GeoObject Properties",visible:!1,resizable:!0,useHide:!0,top:25,right:85,width:252,height:480,minHeight:100,minWidth:100,model:e.model}),this._onVisibility=e=>{this.model.setVisibility(e)},this._onSelect=e=>{this.show(),this._refresh(e)},this._onUnselect=e=>{this.hide()},this._onChangeRelativePosition=e=>{let t=this.model.getSelectedEntity();t&&(t.relativePosition=e,this._refresh(t))},this._onPosition=(e,t)=>{this._refresh(t)},this._onPitch=(e,t)=>{this._pitchView.stopPropagation(),this._pitchView.value=t.getPitch()*h,this._absolutePitchView.stopPropagation(),this._absolutePitchView.value=t.getAbsolutePitch()*h},this._onYaw=(e,t)=>{this._yawView.stopPropagation(),this._yawView.value=t.getYaw()*h,this._absoluteYawView.stopPropagation(),this._absoluteYawView.value=t.getAbsoluteYaw()*h},this._onRoll=(e,t)=>{this._rollView.stopPropagation(),this._rollView.value=t.getRoll()*h,this._absoluteRollView.stopPropagation(),this._absoluteRollView.value=t.getAbsoluteRoll()*h},this._onChangeLon=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getLonLat();t.setLonLat2(parseFloat(e),i.lat,i.height),this._refresh(t)}},this._onChangeLat=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getLonLat();t.setLonLat2(i.lon,parseFloat(e),i.height),this._refresh(t)}},this._onChangeHeight=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getLonLat();t.setLonLat2(i.lon,i.lat,parseFloat(e)),this._refresh(t)}},this._onChangeX=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getCartesian();t.setCartesian(parseFloat(e),i.y,i.z),this._refresh(t)}},this._onChangeY=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getCartesian();t.setCartesian(i.x,parseFloat(e),i.z),this._refresh(t)}},this._onChangeZ=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getCartesian();t.setCartesian(i.x,i.y,parseFloat(e)),this._refresh(t)}},this._onChangeAbsoluteX=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getAbsoluteCartesian();t.setAbsoluteCartesian(parseFloat(e),i.y,i.z),this._refresh(t)}},this._onChangeAbsoluteY=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getAbsoluteCartesian();t.setAbsoluteCartesian(i.x,parseFloat(e),i.z),this._refresh(t)}},this._onChangeAbsoluteZ=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getAbsoluteCartesian();t.setAbsoluteCartesian(i.x,i.y,parseFloat(e)),this._refresh(t)}},this._onChangePitch=e=>{let t=this.model.getSelectedEntity();t&&(t.setPitch(parseFloat(e)*l),this._refresh(t))},this._onChangeYaw=e=>{let t=this.model.getSelectedEntity();t&&(t.setYaw(parseFloat(e)*l),this._refresh(t))},this._onChangeRoll=e=>{let t=this.model.getSelectedEntity();t&&(t.setRoll(parseFloat(e)*l),this._refresh(t))},this._onChangeAbsolutePitch=e=>{let t=this.model.getSelectedEntity();t&&(t.setAbsolutePitch(parseFloat(e)*l),this._refresh(t))},this._onChangeAbsoluteYaw=e=>{let t=this.model.getSelectedEntity();t&&(t.setAbsoluteYaw(parseFloat(e)*l),this._refresh(t))},this._onChangeAbsoluteRoll=e=>{let t=this.model.getSelectedEntity();t&&(t.setAbsoluteRoll(parseFloat(e)*l),this._refresh(t))},this._onChangeScale=e=>{let t=this.model.getSelectedEntity();if(t){let i=parseFloat(e);t.setScale(i),this._scaleXView.stopPropagation(),this._scaleYView.stopPropagation(),this._scaleZView.stopPropagation(),this._scaleXView.value=i,this._scaleYView.value=i,this._scaleZView.value=i}},this._onChangeScaleX=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getScale();t.setScale3v(new oe(parseFloat(e),i.y,i.z))}},this._onChangeScaleY=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getScale();t.setScale3v(new oe(i.x,parseFloat(e),i.z))}},this._onChangeScaleZ=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getScale();t.setScale3v(new oe(i.x,i.y,parseFloat(e)))}},this._onGround=()=>{let e=this.model.getSelectedEntity();e&&this.model.planet&&(this.model.planet.terrain?this.model.planet.terrain.getHeightAsync(e.getLonLat(),(e=>{this._heightView.value=e})):this._heightView.value=0)},this._relativePositionView=new vo({label:"Relative position"}),this._lonView=new po({label:"Lon",type:"number",min:-180,max:180,maxFixed:10}),this._latView=new po({label:"Lat",type:"number",min:-90,max:90,maxFixed:10}),this._heightView=new po({label:"Height",type:"number",maxFixed:4}),this._xView=new po({label:"X",type:"number",maxFixed:10}),this._yView=new po({label:"Y",type:"number"}),this._zView=new po({label:"Z",type:"number"}),this._absXView=new po({label:"Absolute X",type:"number",maxFixed:10}),this._absYView=new po({label:"Absolute Y",type:"number"}),this._absZView=new po({label:"Absolute Z",type:"number"}),this._pitchView=new po({label:"Pitch",type:"number",maxFixed:2}),this._yawView=new po({label:"Yaw",type:"number",maxFixed:2}),this._rollView=new po({label:"Roll",type:"number",maxFixed:2}),this._absolutePitchView=new po({label:"Absolute pitch",type:"number",maxFixed:2}),this._absoluteYawView=new po({label:"Absolute yaw",type:"number",maxFixed:2}),this._absoluteRollView=new po({label:"Absolute roll",type:"number",maxFixed:2}),this._scaleView=new po({label:"Scale",type:"number",maxFixed:2}),this._scaleXView=new po({label:"Scale X",type:"number",maxFixed:2}),this._scaleYView=new po({label:"Scale Y",type:"number",maxFixed:2}),this._scaleZView=new po({label:"Scale Z",type:"number",maxFixed:2}),this._groundBtn=new zt({text:"Ground",title:"Put on the ground",name:"ground",classList:["og-editor-ground_button"]})}render(e){super.render(e),this._initSceneEvents();let t=document.createElement("div");t.classList.add("og-editor_toolbar"),this.container?.appendChild(t);let i=new Ut({classList:["og-editor_toolbar-button"],icon:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" id="filter-center-focus">\n <path d="M5 15H3v4c0 1.1.9 2 2 2h4v-2H5v-4zM5 5h4V3H5c-1.1 0-2 .9-2 2v4h2V5zm14-2h-4v2h4v4h2V5c0-1.1-.9-2-2-2zm0 16h-4v2h4c1.1 0 2-.9 2-2v-4h-2v4zM12 9c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"/>\n</svg>',title:"Lock/Unlock camera view"});return i.appendTo(t),i.events.on("change",(e=>{e?this.model.lockView():this.model.unlockView()})),this.events.on("visibility",(e=>{e||(i.events.stopPropagation(),i.setActive(!1))})),this.events.on("visibility",this._onVisibility),this._relativePositionView.appendTo(this.container),this.model.planet&&(this._lonView.appendTo(this.container),this._latView.appendTo(this.container),this._heightView.appendTo(this.container)),this._xView.appendTo(this.container),this._yView.appendTo(this.container),this._zView.appendTo(this.container),this._absXView.appendTo(this.container),this._absYView.appendTo(this.container),this._absZView.appendTo(this.container),this._pitchView.appendTo(this.container),this._yawView.appendTo(this.container),this._rollView.appendTo(this.container),this._absolutePitchView.appendTo(this.container),this._absoluteYawView.appendTo(this.container),this._absoluteRollView.appendTo(this.container),this._scaleView.appendTo(this.container),this._scaleXView.appendTo(this.container),this._scaleYView.appendTo(this.container),this._scaleZView.appendTo(this.container),this.model.planet&&this._groundBtn.appendTo(this.container),this._relativePositionView.events.on("change",this._onChangeRelativePosition),this._lonView.events.on("change",this._onChangeLon),this._latView.events.on("change",this._onChangeLat),this._heightView.events.on("change",this._onChangeHeight),this._xView.events.on("change",this._onChangeX),this._yView.events.on("change",this._onChangeY),this._zView.events.on("change",this._onChangeZ),this._absXView.events.on("change",this._onChangeAbsoluteX),this._absYView.events.on("change",this._onChangeAbsoluteY),this._absZView.events.on("change",this._onChangeAbsoluteZ),this._pitchView.events.on("change",this._onChangePitch),this._yawView.events.on("change",this._onChangeYaw),this._rollView.events.on("change",this._onChangeRoll),this._absolutePitchView.events.on("change",this._onChangeAbsolutePitch),this._absoluteYawView.events.on("change",this._onChangeAbsoluteYaw),this._absoluteRollView.events.on("change",this._onChangeAbsoluteRoll),this._scaleView.events.on("change",this._onChangeScale),this._scaleXView.events.on("change",this._onChangeScaleX),this._scaleYView.events.on("change",this._onChangeScaleY),this._scaleZView.events.on("change",this._onChangeScaleZ),this._groundBtn.appendTo(this.container),this._groundBtn.events.on("click",this._onGround),this}remove(){super.remove(),this._clearSceneEvents()}_initSceneEvents(){this.model.events.on("select",this._onSelect),this.model.events.on("unselect",this._onUnselect),this.model.events.on("position",this._onPosition),this.model.events.on("pitch",this._onPitch),this.model.events.on("yaw",this._onYaw),this.model.events.on("roll",this._onRoll)}_clearSceneEvents(){this.model.events.off("select",this._onSelect),this.model.events.off("unselect",this._onUnselect),this.model.events.off("position",this._onPosition),this.model.events.off("pitch",this._onPitch),this.model.events.off("yaw",this._onYaw),this.model.events.off("roll",this._onRoll)}_refresh(e){e.parent?this._relativePositionView.disabled=!1:this._relativePositionView.disabled=!0,this._relativePositionView.checked=e.relativePosition;let t=e.getLonLat();this._lonView.stopPropagation(),this._latView.stopPropagation(),this._heightView.stopPropagation(),this._lonView.value=t.lon,this._latView.value=t.lat,this._heightView.value=t.height;let i=e.getCartesian();this._xView.stopPropagation(),this._yView.stopPropagation(),this._zView.stopPropagation(),this._xView.value=i.x,this._yView.value=i.y,this._zView.value=i.z,i=e.getAbsoluteCartesian(),this._absXView.stopPropagation(),this._absYView.stopPropagation(),this._absZView.stopPropagation(),this._absXView.value=i.x,this._absYView.value=i.y,this._absZView.value=i.z,this._pitchView.stopPropagation(),this._yawView.stopPropagation(),this._rollView.stopPropagation(),this._pitchView.value=e.getPitch()*h,this._yawView.value=e.getYaw()*h,this._rollView.value=e.getRoll()*h,this._absolutePitchView.stopPropagation(),this._absoluteYawView.stopPropagation(),this._absoluteRollView.stopPropagation(),this._absolutePitchView.value=e.getAbsolutePitch()*h,this._absoluteYawView.value=e.getAbsoluteYaw()*h,this._absoluteRollView.value=e.getAbsoluteRoll()*h,this._scaleView.stopPropagation();let s=e.getScale();s.x===s.y&&s.y===s.z?this._scaleView.value=s.x:this._scaleView.value=1,this._scaleXView.stopPropagation(),this._scaleYView.stopPropagation(),this._scaleZView.stopPropagation(),this._scaleXView.value=s.x,this._scaleYView.value=s.y,this._scaleZView.value=s.z}hide(){super.hide(),this.model.events.stopPropagation(),this.model.unselect()}}const xo=["lockview","unlockview"];class bo extends Dt{constructor(e={}){super(e),this._onLockViewDraw=()=>{this.renderer&&this._lockEntity&&(this._isFromTheBack||this.renderer.activeCamera.viewDistance(this._lockEntity.getAbsoluteCartesian(),this._lockDistance))},this._onMouseWheel=e=>{if(this.renderer&&this._lockEntity)if(this._isFromTheBack);else{let t=this.renderer.activeCamera.eye.distance(this._lockEntity.getAbsoluteCartesian());this._lockDistance-=.33*t*Math.sign(e.wheelDelta),this._lockDistance<.001&&(this._lockDistance=.001),this.renderer.activeCamera.viewDistance(this._lockEntity.getAbsoluteCartesian(),this._lockDistance)}},this._onMouseMove=e=>{if(this._lockEntity&&this.renderer&&(e.rightButtonDown||this.renderer.events.isKeyPressed(Cn.KEY_ALT))){let t=this._lockEntity.getAbsoluteCartesian(),i=this.renderer.activeCamera,s=.5/l;s>.007&&(s=.007),this.planet?i.rotateHorizontal(s*(e.x-e.prev_x),!1,t,t.isZero()?oe.UP:t.normal()):i.rotateHorizontal(s*(e.x-e.prev_x),!1,t,oe.UP),i.rotateVertical(s*(e.y-e.prev_y),t),this._viewDir=t.sub(i.eye).normalize()}},this.events=Mt(xo),this._name="CameraLock",this.planet=e.planet||null,this._lockDistance=0,this._isFromTheBack=!1,this._lockEntity=null,this._viewDir=new oe(0,0,0)}onactivate(){this.renderer}ondeactivate(){this.renderer&&this.unlockView()}oninit(){this.activate(),this.renderer}flyCartesian(e,t=120){if(!e.isZero()&&this.renderer)if(this.unlockView(),this.planet){let i=this.planet.camera;this.isVisibleDistance(e)&&i.flyDistance(e,t),i.eye.distance(e)<1e6?i.flyDistance(e,t):i.viewDistance(e,t)}else this.renderer.activeCamera.viewDistance(e,t)}lockView(e,t=!1){if(!this.renderer)return;this._lockDistance=this._getDistance(e,this._lockEntity),this._isFromTheBack=t,this._deactivateLockViewEvents(),this._lockEntity=e;let i=this.renderer.activeCamera;this.planet&&this.planet.camera.stopFlying(),i.viewDistance(e.getAbsoluteCartesian(),this._lockDistance),this._deactivateNav(),this._activateLockViewEvents(),this._viewDir=e.getAbsoluteCartesian().sub(i.eye).normalize(),this.events.dispatch(this.events.lockview,this._lockEntity,t)}_activateNav(){this.renderer&&this.renderer.controls.mouseNavigation&&this.renderer.controls.mouseNavigation.activate(),this.renderer&&this.renderer.controls.simpleNavigation&&this.renderer.controls.simpleNavigation.activate()}_deactivateNav(){this.renderer&&this.renderer.controls.mouseNavigation&&(this.renderer.controls.mouseNavigation.deactivate(),this.renderer.controls.mouseNavigation.stop()),this.renderer&&this.renderer.controls.simpleNavigation&&this.renderer.controls.simpleNavigation.deactivate()}unlockView(){this._lockEntity&&(this._deactivateLockViewEvents(),this._activateNav(),this.events.dispatch(this.events.unlockview,this._lockEntity),this._lockEntity=null)}_getCenterDist(){return this.renderer&&this.renderer.getDistanceFromPixel(this.renderer.handler.getCenter())||0}_getDistance(e,t){if(this.renderer){let i=e.getAbsoluteCartesian(),s=this.renderer.activeCamera,n=s.eye.distance(i);return t&&(n=s.eye.distance(t.getAbsoluteCartesian())),this.isVisibleDistance(i)?n:s.eye.distance(i)<1e6?this._getCenterDist():120}return 0}isVisibleDistance(e,t=0){if(this.planet){let i=this.planet.ellipsoid.equatorialSize,s=this.planet.camera.eye;return s.distance(e)<Math.sqrt(s.length2()-i*i)+t}return!0}get lockEntity(){return this._lockEntity}flyLonLat(e,t=120){if(this.planet){let i=this.planet.ellipsoid.lonLatToCartesian(e);this.flyCartesian(i,t)}}_activateLockViewEvents(){this.renderer&&(this.renderer.events.on("mousewheel",this._onMouseWheel),this.renderer.events.on("mousemove",this._onMouseMove),this.renderer.events.on("draw",this._onLockViewDraw))}_deactivateLockViewEvents(){this.renderer&&(this.renderer.events.off("mousewheel",this._onMouseWheel),this.renderer.events.off("mousemove",this._onMouseMove),this._lockEntity&&this.renderer.events.off("draw",this._onLockViewDraw))}}var wo=Object.freeze({__proto__:null,AtmosphereConfig:class extends Dt{constructor(e={}){super(e),this.$maxOpacity=null,this.$minOpacity=null,this.$rayleight=null,this.$mie=null,this.$height=null,this.$bottomRadius=null,this.$mieScatteringCoefficient=null,this.$mieExtinctionCoefficient=null,this.$rayleighScatteringCoefficientA=null,this.$rayleighScatteringCoefficientB=null,this.$rayleighScatteringCoefficientC=null,this.$ozoneAbsorptionCoefficientA=null,this.$ozoneAbsorptionCoefficientB=null,this.$ozoneAbsorptionCoefficientC=null,this.$sunAngularRadius=null,this.$sunIntensity=null,this.$groundAlbedo=null,this.$ozoneDensityHeight=null,this.$ozoneDensityWide=null,this._toggleBtn=new Ut({classList:["og-map-button","og-atmosphere_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<svg width="800px" height="800px" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path fill="#000000" d="M135.688 18.5c-6.798 74.842-23.842 85.39-107.907 59.656 84.85 52.022 73.57 64.954-6.843 96.938 87.743-10.27 103.29 4.89 70.75 87.594 17.805-27.56 32.5-44.498 46.282-54.47-11.813 28.26-18.345 59.274-18.345 91.813 0 84.184 43.71 157.96 109.656 200.376-41.624-43.834-67.686-102.7-67.686-167.875 0-134.923 109.45-244.405 244.375-244.405 30.92 0 60.76 5.762 88 16.25-38.584-26.87-85.517-42.625-136.064-42.625-55.257 0-106.14 18.802-146.562 50.375 4.627-18.783 17.39-38.073 41.03-60.906C190.18 90.942 153.53 95.634 135.69 18.5zm10.03 77.188c5.67.002 11.428 1.247 16.876 3.874 14.506 6.998 22.72 21.81 22 36.938-10.26 10.87-19.507 22.696-27.594 35.344-9.035 2.753-19.075 2.27-28.25-2.156-19.37-9.343-27.5-32.6-18.156-51.97 6.715-13.92 20.638-22.036 35.125-22.03z"/></svg>'}),this._dialog=new Ot({title:"Atmosphere Parameters",visible:!1,useHide:!0,top:60,left:60,width:720}),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e)})),this._panel=new kt({template:'<div class="og-atmosphere og-options-container">\n \n <div class="og-option og-atmosphere-maxOpacity"></div> \n <div class="og-option og-atmosphere-minOpacity"></div>\n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-rayleight"></div>\n <div class="og-option og-atmosphere-mie"></div>\n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-height"></div> \n <div class="og-option og-atmosphere-bottomRadius"></div>\n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-mieScatteringCoefficient"></div> \n <div class="og-option og-atmosphere-mieExtinctionCoefficient"></div>\n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-rayleighScatteringCoefficientA"></div> \n <div class="og-option og-atmosphere-rayleighScatteringCoefficientB"></div> \n <div class="og-option og-atmosphere-rayleighScatteringCoefficientC"></div>\n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-ozoneAbsorptionCoefficientA"></div> \n <div class="og-option og-atmosphere-ozoneAbsorptionCoefficientB"></div> \n <div class="og-option og-atmosphere-ozoneAbsorptionCoefficientC"></div>\n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-ozoneDensityHeight"></div> \n <div class="og-option og-atmosphere-ozoneDensityWide"></div> \n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-sunAngularRadius"></div> \n <div class="og-option og-atmosphere-sunIntensity"></div> \n <div class="og-option og-atmosphere-earthAlbedo"></div>\n \n </div>'}),this._maxOpacity=new An({label:"Max.opacity",max:5}),this._minOpacity=new An({label:"Min.opacity",max:5}),this._rayleight=new An({label:"Rayleight Scale",min:-10,max:10}),this._mie=new An({label:"Mie Scale",min:-10,max:10}),this._height=new An({label:"Height",max:1e6}),this._bottomRadius=new An({label:"Planet Radius",max:31783761.571225896}),this._mieScatteringCoefficient=new An({label:"Mie Scattering Coefficient e-6",min:-39.96,max:39.96}),this._mieExtinctionCoefficient=new An({label:"Mie Extinction Coef.e-6",min:4.44*-10,max:10*4.44}),this._rayleighScatteringCoefficientA=new An({label:"Rayleight Scattering Coef A.e-6",min:5.802*-10,max:10*5.802}),this._rayleighScatteringCoefficientB=new An({label:"Rayleight Scattering Coef B.e-6",min:13.558*-10,max:10*13.558}),this._rayleighScatteringCoefficientC=new An({label:"Rayleight Scattering Coef C.e-6",min:-331,max:331}),this._ozoneAbsorptionCoefficientA=new An({label:"Ozone absorbtion Coef A.e-6",min:-6.5,max:6.5}),this._ozoneAbsorptionCoefficientB=new An({label:"Ozone absorbtion Coef B.e-6",min:-6.5,max:18.81}),this._ozoneAbsorptionCoefficientC=new An({label:"Ozone absorbtion Coef C.e-6",min:.085*-10,max:10*.085}),this._ozoneDensityHeight=new An({label:"Ozone Density Height",max:25e5}),this._ozoneDensityWide=new An({label:"Ozone Density Wide",max:25e5}),this._sunAngularRadius=new An({label:"Sun Angular Radius",max:4.685}),this._sunIntensity=new An({label:"Sun Intensity",max:10}),this._groundAlbedo=new An({label:"Earth Albedo",max:.5}),this._parameters={ATMOS_HEIGHT:0,RAYLEIGH_SCALE:0,MIE_SCALE:0,GROUND_ALBEDO:0,BOTTOM_RADIUS:0,rayleighScatteringCoefficient:[0,0,0],mieScatteringCoefficient:0,mieExtinctionCoefficient:0,ozoneAbsorptionCoefficient:[0,0,0],SUN_ANGULAR_RADIUS:0,SUN_INTENSITY:0,ozoneDensityHeight:0,ozoneDensityWide:0}}oninit(){this._toggleBtn.appendTo(this.renderer.div),this._dialog.appendTo(this.renderer.div),this._panel.appendTo(this._dialog.container),this._panel.el&&(this.$height=this._panel.el.querySelector(".og-option.og-atmosphere-height"),this.$maxOpacity=this._panel.el.querySelector(".og-option.og-atmosphere-maxOpacity"),this.$minOpacity=this._panel.el.querySelector(".og-option.og-atmosphere-minOpacity"),this.$rayleight=this._panel.el.querySelector(".og-option.og-atmosphere-rayleight"),this.$mie=this._panel.el.querySelector(".og-option.og-atmosphere-mie"),this.$bottomRadius=this._panel.el.querySelector(".og-option.og-atmosphere-bottomRadius"),this.$mieScatteringCoefficient=this._panel.el.querySelector(".og-option.og-atmosphere-mieScatteringCoefficient"),this.$mieExtinctionCoefficient=this._panel.el.querySelector(".og-option.og-atmosphere-mieExtinctionCoefficient"),this.$rayleighScatteringCoefficientA=this._panel.el.querySelector(".og-option.og-atmosphere-rayleighScatteringCoefficientA"),this.$rayleighScatteringCoefficientB=this._panel.el.querySelector(".og-option.og-atmosphere-rayleighScatteringCoefficientB"),this.$rayleighScatteringCoefficientC=this._panel.el.querySelector(".og-option.og-atmosphere-rayleighScatteringCoefficientC"),this.$ozoneAbsorptionCoefficientA=this._panel.el.querySelector(".og-option.og-atmosphere-ozoneAbsorptionCoefficientA"),this.$ozoneAbsorptionCoefficientB=this._panel.el.querySelector(".og-option.og-atmosphere-ozoneAbsorptionCoefficientB"),this.$ozoneAbsorptionCoefficientC=this._panel.el.querySelector(".og-option.og-atmosphere-ozoneAbsorptionCoefficientC"),this.$sunAngularRadius=this._panel.el.querySelector(".og-option.og-atmosphere-sunAngularRadius"),this.$sunIntensity=this._panel.el.querySelector(".og-option.og-atmosphere-sunIntensity"),this.$groundAlbedo=this._panel.el.querySelector(".og-option.og-atmosphere-earthAlbedo"),this.$ozoneDensityHeight=this._panel.el.querySelector(".og-option.og-atmosphere-ozoneDensityHeight"),this.$ozoneDensityWide=this._panel.el.querySelector(".og-option.og-atmosphere-ozoneDensityWide")),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e)})),this._maxOpacity.appendTo(this.$maxOpacity),this._minOpacity.appendTo(this.$minOpacity),this._height.appendTo(this.$height),this._rayleight.appendTo(this.$rayleight),this._mie.appendTo(this.$mie),this._bottomRadius.appendTo(this.$bottomRadius),this._mieScatteringCoefficient.appendTo(this.$mieScatteringCoefficient),this._mieExtinctionCoefficient.appendTo(this.$mieExtinctionCoefficient),this._rayleighScatteringCoefficientA.appendTo(this.$rayleighScatteringCoefficientA),this._rayleighScatteringCoefficientB.appendTo(this.$rayleighScatteringCoefficientB),this._rayleighScatteringCoefficientC.appendTo(this.$rayleighScatteringCoefficientC),this._ozoneAbsorptionCoefficientA.appendTo(this.$ozoneAbsorptionCoefficientA),this._ozoneAbsorptionCoefficientB.appendTo(this.$ozoneAbsorptionCoefficientB),this._ozoneAbsorptionCoefficientC.appendTo(this.$ozoneAbsorptionCoefficientC),this._sunAngularRadius.appendTo(this.$sunAngularRadius),this._sunIntensity.appendTo(this.$sunIntensity),this._groundAlbedo.appendTo(this.$groundAlbedo),this._ozoneDensityHeight.appendTo(this.$ozoneDensityHeight),this._ozoneDensityWide.appendTo(this.$ozoneDensityWide),this.planet&&(this._parameters=this.planet.atmosphereControl.parameters,this._height.value=this._parameters.ATMOS_HEIGHT,this._rayleight.value=this._parameters.RAYLEIGH_SCALE,this._mie.value=this._parameters.MIE_SCALE,this._bottomRadius.value=this._parameters.BOTTOM_RADIUS,this._mieScatteringCoefficient.value=this._parameters.mieScatteringCoefficient,this._mieExtinctionCoefficient.value=this._parameters.mieExtinctionCoefficient,this._rayleighScatteringCoefficientA.value=this._parameters.rayleighScatteringCoefficient[0],this._rayleighScatteringCoefficientB.value=this._parameters.rayleighScatteringCoefficient[1],this._rayleighScatteringCoefficientC.value=this._parameters.rayleighScatteringCoefficient[2],this._ozoneAbsorptionCoefficientA.value=this._parameters.ozoneAbsorptionCoefficient[0],this._ozoneAbsorptionCoefficientB.value=this._parameters.ozoneAbsorptionCoefficient[1],this._ozoneAbsorptionCoefficientC.value=this._parameters.ozoneAbsorptionCoefficient[2],this._sunAngularRadius.value=this._parameters.SUN_ANGULAR_RADIUS,this._sunIntensity.value=this._parameters.SUN_INTENSITY,this._groundAlbedo.value=this._parameters.GROUND_ALBEDO,this._ozoneDensityHeight.value=this._parameters.ozoneDensityHeight,this._ozoneDensityWide.value=this._parameters.ozoneDensityWide),this._minOpacity.value=this.planet.atmosphereMinOpacity,this._minOpacity.events.on("change",(e=>{this.planet.atmosphereMinOpacity=e})),this._maxOpacity.value=this.planet.atmosphereMaxOpacity,this._maxOpacity.events.on("change",(e=>{this.planet.atmosphereMaxOpacity=e})),this._rayleight.events.on("change",(e=>{this._parameters.RAYLEIGH_SCALE=e,this._update()})),this._mie.events.on("change",(e=>{this._parameters.MIE_SCALE=e,this._update()})),this._height.events.on("change",(e=>{this._parameters.ATMOS_HEIGHT=e,this._update()})),this._bottomRadius.events.on("change",(e=>{this._parameters.BOTTOM_RADIUS=e,this._update()})),this._mieScatteringCoefficient.events.on("change",(e=>{this._parameters.mieScatteringCoefficient=e,this._update()})),this._mieExtinctionCoefficient.events.on("change",(e=>{this._parameters.mieExtinctionCoefficient=e,this._update()})),this._rayleighScatteringCoefficientA.events.on("change",(e=>{this._parameters.rayleighScatteringCoefficient[0]=e,this._update()})),this._rayleighScatteringCoefficientB.events.on("change",(e=>{this._parameters.rayleighScatteringCoefficient[1]=e,this._update()})),this._rayleighScatteringCoefficientC.events.on("change",(e=>{this._parameters.rayleighScatteringCoefficient[2]=e,this._update()})),this._ozoneAbsorptionCoefficientA.events.on("change",(e=>{this._parameters.ozoneAbsorptionCoefficient[0]=e,this._update()})),this._ozoneAbsorptionCoefficientB.events.on("change",(e=>{this._parameters.ozoneAbsorptionCoefficient[1]=e,this._update()})),this._ozoneAbsorptionCoefficientC.events.on("change",(e=>{this._parameters.ozoneAbsorptionCoefficient[2]=e,this._update()})),this._sunAngularRadius.events.on("change",(e=>{this._parameters.SUN_ANGULAR_RADIUS=e,this._update()})),this._sunIntensity.events.on("change",(e=>{this._parameters.SUN_INTENSITY=e,this._update()})),this._groundAlbedo.events.on("change",(e=>{this._parameters.GROUND_ALBEDO=e,this._update()})),this._ozoneDensityHeight.events.on("change",(e=>{this._parameters.ozoneDensityHeight=e,this._update()})),this._ozoneDensityWide.events.on("change",(e=>{this._parameters.ozoneDensityWide=e,this._update()}))}_update(){this.planet&&this.planet.atmosphereControl.setParameters(this._parameters)}},CameraLock:bo,CompassButton:Ft,Control:Dt,DebugInfo:class extends Dt{constructor(e={}){e.name&&""!==e.name||(e.name="DebugInfo"),super(e),this.el=null,this._watch=e.watch||[],this._toggleBtn=new Ut({classList:["og-map-button","og-debuginfo_button"],icon:'<?xml version="1.0" encoding="iso-8859-1"?>\n\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg fill="#000000" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" \n\t width="800px" height="800px" viewBox="0 0 932.179 932.179"\n\t xml:space="preserve">\n<g>\n\t<path d="M61.2,341.538c4.9,16.8,11.7,33,20.3,48.2l-24.5,30.9c-8,10.1-7.1,24.5,1.9,33.6l42.2,42.2c9.1,9.1,23.5,9.899,33.6,1.899\n\t\tl30.7-24.3c15.8,9.101,32.6,16.2,50.1,21.2l4.6,39.5c1.5,12.8,12.3,22.4,25.1,22.4h59.7c12.8,0,23.6-9.601,25.1-22.4l4.4-38.1\n\t\tc18.8-4.9,36.8-12.2,53.7-21.7l29.7,23.5c10.1,8,24.5,7.1,33.6-1.9l42.2-42.2c9.1-9.1,9.9-23.5,1.9-33.6l-23.1-29.3\n\t\tc9.6-16.601,17.1-34.3,22.1-52.8l35.6-4.1c12.801-1.5,22.4-12.3,22.4-25.1v-59.7c0-12.8-9.6-23.6-22.4-25.1l-35.1-4.1\n\t\tc-4.801-18.3-12-35.8-21.199-52.2l21.6-27.3c8-10.1,7.1-24.5-1.9-33.6l-42.1-42.1c-9.1-9.1-23.5-9.9-33.6-1.9l-26.5,21\n\t\tc-17.2-10.1-35.601-17.8-54.9-23l-4-34.3c-1.5-12.8-12.3-22.4-25.1-22.4h-59.7c-12.8,0-23.6,9.6-25.1,22.4l-4,34.3\n\t\tc-19.8,5.3-38.7,13.3-56.3,23.8l-27.5-21.8c-10.1-8-24.5-7.1-33.6,1.9l-42.2,42.2c-9.1,9.1-9.9,23.5-1.9,33.6l23,29.1\n\t\tc-9.2,16.6-16.2,34.3-20.8,52.7l-36.8,4.2c-12.8,1.5-22.4,12.3-22.4,25.1v59.7c0,12.8,9.6,23.6,22.4,25.1L61.2,341.538z\n\t\t M277.5,180.038c54.4,0,98.7,44.3,98.7,98.7s-44.3,98.7-98.7,98.7c-54.399,0-98.7-44.3-98.7-98.7S223.1,180.038,277.5,180.038z"/>\n\t<path d="M867.699,356.238l-31.5-26.6c-9.699-8.2-24-7.8-33.199,0.9l-17.4,16.3c-14.699-7.1-30.299-12.1-46.4-15l-4.898-24\n\t\tc-2.5-12.4-14-21-26.602-20l-41.1,3.5c-12.6,1.1-22.5,11.4-22.9,24.1l-0.799,24.4c-15.801,5.7-30.701,13.5-44.301,23.3\n\t\tl-20.799-13.8c-10.602-7-24.701-5-32.9,4.7l-26.6,31.7c-8.201,9.7-7.801,24,0.898,33.2l18.201,19.399\n\t\tc-6.301,14.2-10.801,29.101-13.4,44.4l-26,5.3c-12.4,2.5-21,14-20,26.601l3.5,41.1c1.1,12.6,11.4,22.5,24.1,22.9l28.1,0.899\n\t\tc5.102,13.4,11.801,26.101,19.9,38l-15.699,23.7c-7,10.6-5,24.7,4.699,32.9l31.5,26.6c9.701,8.2,24,7.8,33.201-0.9l20.6-19.3\n\t\tc13.5,6.3,27.699,11,42.299,13.8l5.701,28.2c2.5,12.4,14,21,26.6,20l41.1-3.5c12.6-1.1,22.5-11.399,22.9-24.1l0.9-27.601\n\t\tc15-5.3,29.199-12.5,42.299-21.399l22.701,15c10.6,7,24.699,5,32.9-4.7l26.6-31.5c8.199-9.7,7.799-24-0.9-33.2l-18.301-19.399\n\t\tc6.701-14.2,11.602-29.2,14.4-44.601l25-5.1c12.4-2.5,21-14,20-26.601l-3.5-41.1c-1.1-12.6-11.4-22.5-24.1-22.9l-25.1-0.8\n\t\tc-5.201-14.6-12.201-28.399-20.9-41.2l13.699-20.6C879.4,378.638,877.4,364.438,867.699,356.238z M712.801,593.837\n\t\tc-44.4,3.801-83.602-29.3-87.301-73.699c-3.801-44.4,29.301-83.601,73.699-87.301c44.4-3.8,83.602,29.301,87.301,73.7\n\t\tC790.301,550.938,757.199,590.138,712.801,593.837z"/>\n\t<path d="M205,704.438c-12.6,1.3-22.3,11.899-22.4,24.6l-0.3,25.3c-0.2,12.7,9.2,23.5,21.8,25.101l18.6,2.399\n\t\tc3.1,11.301,7.5,22.101,13.2,32.301l-12,14.8c-8,9.899-7.4,24.1,1.5,33.2l17.7,18.1c8.9,9.1,23.1,10.1,33.2,2.3l14.899-11.5\n\t\tc10.5,6.2,21.601,11.101,33.2,14.5l2,19.2c1.3,12.6,11.9,22.3,24.6,22.4l25.301,0.3c12.699,0.2,23.5-9.2,25.1-21.8l2.3-18.2\n\t\tc12.601-3.101,24.601-7.8,36-14l14,11.3c9.9,8,24.101,7.4,33.201-1.5l18.1-17.7c9.1-8.899,10.1-23.1,2.301-33.2L496.6,818.438\n\t\tc6.6-11,11.701-22.7,15.201-35l16.6-1.7c12.6-1.3,22.299-11.9,22.4-24.6l0.299-25.301c0.201-12.699-9.199-23.5-21.799-25.1\n\t\tl-16.201-2.1c-3.1-12.2-7.699-24-13.699-35l10.1-12.4c8-9.9,7.4-24.1-1.5-33.2l-17.699-18.1c-8.9-9.101-23.102-10.101-33.201-2.3\n\t\tl-12.101,9.3c-11.399-6.9-23.6-12.2-36.399-15.8l-1.601-15.7c-1.3-12.601-11.899-22.3-24.6-22.4l-25.3-0.3\n\t\tc-12.7-0.2-23.5,9.2-25.101,21.8l-2,15.601c-13.199,3.399-25.899,8.6-37.699,15.399l-12.5-10.2c-9.9-8-24.101-7.399-33.201,1.5\n\t\tl-18.2,17.801c-9.1,8.899-10.1,23.1-2.3,33.199l10.7,13.801c-6.2,11-11.1,22.699-14.3,35L205,704.438z M368.3,675.837\n\t\tc36.3,0.4,65.399,30.301,65,66.601c-0.4,36.3-30.301,65.399-66.601,65c-36.3-0.4-65.399-30.3-65-66.601\n\t\tC302.1,704.538,332,675.438,368.3,675.837z"/>\n</g>\n</svg>'}),this._dialog=new Ot({title:"Debug Info",visible:!1,useHide:!0,top:120,left:60,width:480}),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e)})),this._canvasTiles=new Kt("Tile grid",{visibility:!0,isBaseLayer:!1,hideInLayerSwitcher:!0,drawTile:function(e,t){let i,s=document.createElement("canvas"),n=s.getContext("2d");s.width=256,s.height=256,n.clearRect(0,0,s.width,s.height),n.beginPath(),n.rect(0,0,s.width,s.height),n.lineWidth=2,n.strokeStyle="black",n.stroke(),i=e.segment.tileZoom>14?"26":"32",n.fillStyle="black",n.font="normal "+i+"px Verdana",n.textAlign="center",n.fillText(e.segment.tileX+","+e.segment.tileY+","+e.segment.tileZoom,s.width/2,s.height/2),t(s)}})}addWatches(e){for(let t=0;t<e.length;t++)this.addWatch(e[t])}addWatch(e){this._watch.push(e);let t=document.createElement("div");t.classList.add("og-watch-line"),t.innerHTML=`<div class="og-watch-label">${e.label}</div><div class="og-watch-value"></div>`,e.valEl=t.querySelector(".og-watch-value"),this.el.appendChild(t)}oninit(){this._toggleBtn.appendTo(this.renderer.div),this._dialog.appendTo(this.renderer.div),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e)})),this.el=document.createElement("div"),this.el.className="og-debug-info";let e=document.createElement("div");e.classList.add("og-debuginfo_controls"),this.el.appendChild(e);let t=this._watch;this._watch=[];for(let e=0;e<t.length;e++)this.addWatch(t[e]);this._dialog.container?.appendChild(this.el),this.renderer.events.on("draw",this._frame,this);let i=this.planet;i&&this.addWatches([{label:"Nodes count",frame:()=>i._renderedNodes.length},{label:"Planet._fadingNodes",frame:()=>i._fadingNodes.size},{label:"createdNodes",frame:()=>i._createdNodesCount},{label:"indexesCache",frame:()=>i._indexesCacheToRemoveCounter},{label:"distBeforeMemClear",frame:()=>Math.round(i._distBeforeMemClear)},{label:"maxZoom/minZoom",frame:()=>i.maxCurrZoom+" / "+i?.minCurrZoom},{label:"viewExtent",frame:()=>i.getViewExtent().toString()},{label:"Mouse distance, m",frame:()=>{let e=i.getCartesianFromMouseTerrain();return e?i.camera.eye.distance(e).toFixed(3):""}},{label:"lodSize",frame:()=>Math.round(i.lodSize)},{label:"deltaTime/FPS",frame:()=>`<div style="width:70px"><div style="width:20px; float: left;">\n ${Math.round(i.renderer.handler.deltaTime)}\n </div> <div style="float: left">\n ${Math.round(1e3/i.renderer.handler.deltaTime)}\n </div></div>`},{label:"-------------------------"},{label:"Pitch, deg",frame:()=>(i.camera.getPitch()*h).toFixed(2)},{label:"Yaw, deg",frame:()=>(i.camera.getYaw()*h).toFixed(2)},{label:"Roll, deg",frame:()=>(i.camera.getRoll()*h).toFixed(2)},{label:"Lon, Lat",frame:()=>`<div style="width:190px">${i.camera._lonLat.lon.toFixed(7)}, ${i.camera._lonLat.lon.toFixed(7)}</div>`},{label:"height/alt, m",frame:()=>`<div style="width:190px">${i.camera._lonLat.height.toFixed(2)+" / "+i.camera.getAltitude().toFixed(2)}</div>`},{label:"cam.slope",frame:()=>i.camera.slope.toFixed(3)},{label:"-------------------------"},{label:"_renderCompleted / renderCompletedActivated",frame:()=>`${i._renderCompleted} / ${i._renderCompletedActivated}`},{label:"_terrainCompleted / terrainCompletedActivated",frame:()=>`${i._terrainCompleted} / ${i._terrainCompletedActivated}`},{label:"PlainWorker",frame:()=>i._plainSegmentWorker.pendingQueue.length},{label:"TileLoader",frame:()=>`${i._tileLoader.loading} ${i._tileLoader.queue.length}`},{label:"TerrainLoader",frame:()=>i.terrain&&!i.terrain.isEmpty?`${i.terrain.loader.loading} ${i.terrain.loader.queue.length}`:""},{label:"TerrainWorker",frame:()=>i._terrainWorker.pendingQueue.length},{label:"NormalMapCreator",frame:()=>i._normalMapCreator.queueSize},{label:"VectorTileCreator",frame:()=>i._vectorTileCreator.queueSize}]);let s=new Ut({classList:["og-debuginfo_controls-button"],icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<svg fill="#000000" width="800px" height="800px" viewBox="-7.5 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg">\n<title>lock</title>\n<path d="M14.625 15.156h2.094c0.281 0 0.5 0.25 0.5 0.531v11c0 0.281-0.219 0.5-0.5 0.5h-16.219c-0.281 0-0.5-0.219-0.5-0.5v-11c0-0.281 0.219-0.531 0.5-0.531h2.031v-5.125c0-2.875 1.844-5.25 4.688-5.25h2.688c2.875 0 4.719 2.375 4.719 5.25v5.125zM5.188 15.156h6.813v-4.875c0-1.594-1.313-2.938-2.938-2.938h-0.969c-1.594 0-2.906 1.344-2.906 2.938v4.875zM7.156 24h2.906l-0.719-3.156c0.5-0.25 0.844-0.781 0.844-1.375 0-0.906-0.719-1.594-1.594-1.594s-1.563 0.688-1.563 1.594c0 0.594 0.344 1.125 0.844 1.375z"></path>\n</svg>',title:"Lock/Unlock quad tree"});s.appendTo(e),s.events.on("change",(e=>{e?i.lockQuadTree():i.unlockQuadTree()}));let n=new Ut({classList:["og-debuginfo_controls-button"],icon:'<?xml version="1.0"?>\n<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">\n <path d="M 4 4 L 4 8 L 8 8 L 8 4 L 4 4 z M 10 4 L 10 8 L 14 8 L 14 4 L 10 4 z M 16 4 L 16 8 L 20 8 L 20 4 L 16 4 z M 4 10 L 4 14 L 8 14 L 8 10 L 4 10 z M 10 10 L 10 14 L 14 14 L 14 10 L 10 10 z M 16 10 L 16 14 L 20 14 L 20 10 L 16 10 z M 4 16 L 4 20 L 8 20 L 8 16 L 4 16 z M 10 16 L 10 20 L 14 20 L 14 16 L 10 16 z M 16 16 L 16 20 L 20 20 L 20 16 L 16 16 z"/>\n</svg>',title:"Show/Hide grid"});n.appendTo(e),n.events.on("change",(e=>{e?this.planet.addLayer(this._canvasTiles):this._canvasTiles.remove()}))}_frame(){this._watch.forEach((e=>{e.valEl&&(e.valEl.innerHTML=e.frame?String(e.frame()):"")}))}},DrawingControl:rn,DrawingSwitcher:class extends Dt{constructor(e={}){super({name:"DrawingSwitcher",...e}),this.drawingControl=new rn}oninit(){this.planet.addControl(this.drawingControl),this._createMenu()}onactivate(){this.drawingControl.activate()}ondeactivate(){this.drawingControl.deactivate()}_createMenu(){let e=new Ut({classList:["og-map-button","og-drawing-default_button"],icon:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M4 0l16 12.279-6.951 1.17 4.325 8.817-3.596 1.734-4.35-8.879-5.428 4.702z"/></svg>',name:"default",isActive:!0}),t=new Ut({classList:["og-map-button","og-drawing-polygon_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Generator: Adobe Illustrator 24.1.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) --\x3e\n<svg version="1.1" id="Layer_2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"\n\t viewBox="0 0 1024 1024" style="enable-background:new 0 0 1024 1024;" xml:space="preserve">\n<g>\n\t<path d="M926.03,321.16c-16.02,0-31.11,3.94-44.48,10.79l-263.43-191.4c2.69-8.94,4.18-18.4,4.18-28.2\n\t\tc0-54.02-43.95-97.97-97.97-97.97c-54.03,0-97.98,43.95-97.98,97.97c0,9.81,1.49,19.27,4.18,28.21L155.75,340.18\n\t\tc-16.22-11.91-36.16-19.03-57.78-19.03C43.95,321.16,0,365.11,0,419.13c0,52.58,41.67,95.5,93.71,97.75l102.63,315.86\n\t\tc-24.28,17.85-40.13,46.52-40.13,78.9c0,54.02,43.95,97.98,97.98,97.98c37.54,0,70.18-21.25,86.62-52.34h367.26\n\t\tc16.44,31.08,49.08,52.34,86.63,52.34c54.03,0,97.98-43.95,97.98-97.98c0-32.46-15.94-61.21-40.33-79.05l104.11-320.4\n\t\tc39.15-12.84,67.54-49.68,67.54-93.07C1024,365.11,980.05,321.16,926.03,321.16z M828.05,911.65c0,8.5-3.3,16.19-8.55,22.09\n\t\tc-6.11,6.85-14.9,11.26-24.79,11.26c-13.65,0-25.37-8.26-30.52-20.02c-1.79-4.09-2.82-8.58-2.82-13.33\n\t\tc0-18.39,14.95-33.35,33.34-33.35c2.93,0,5.72,0.5,8.43,1.21c13.27,3.49,23.21,14.91,24.59,28.9\n\t\tC827.83,909.5,828.05,910.54,828.05,911.65z M790.48,813.89c-45.63,1.96-83.27,35.16-91.87,78.77H350.28\n\t\tc-8.62-43.69-46.38-76.93-92.11-78.79L155.59,498.19c24.41-17.84,40.36-46.59,40.36-79.06c0-8.9-1.3-17.49-3.53-25.7L468.57,192.8\n\t\tc15.84,11.01,35.05,17.52,55.76,17.52c20.71,0,39.92-6.5,55.76-17.52l256.56,186.4c-5.48,12.21-8.59,25.7-8.59,39.93\n\t\tc0,41.02,25.36,76.17,61.21,90.75L790.48,813.89z M254.19,945c-10.11,0-19.07-4.62-25.19-11.75c-5.01-5.84-8.15-13.32-8.15-21.6\n\t\tc0-0.91,0.2-1.76,0.27-2.66c1.14-14.18,11.08-25.8,24.43-29.41c2.78-0.75,5.64-1.28,8.65-1.28c18.38,0,33.33,14.96,33.33,33.35\n\t\tc0,4.74-1.03,9.24-2.82,13.33C279.55,936.74,267.83,945,254.19,945z M64.88,421.49c-0.06-0.79-0.24-1.55-0.24-2.35\n\t\tc0-16.41,11.93-30.01,27.55-32.76c1.89-0.33,3.8-0.58,5.78-0.58c11.94,0,22.35,6.36,28.24,15.81c3.18,5.11,5.11,11.09,5.11,17.53\n\t\tc0,15.47-10.63,28.39-24.94,32.14c-2.7,0.71-5.48,1.2-8.4,1.2C80.4,452.47,66.11,438.76,64.88,421.49z M549.41,90.62\n\t\tc5.07,5.85,8.25,13.39,8.25,21.72c0,7.32-2.44,14.03-6.45,19.54c-6.07,8.33-15.82,13.81-26.88,13.81\n\t\tc-11.07,0-20.83-5.48-26.89-13.81c-4.01-5.51-6.45-12.22-6.45-19.54c0-8.33,3.17-15.86,8.24-21.71\n\t\tc6.12-7.07,15.04-11.64,25.1-11.64C534.38,79,543.29,83.57,549.41,90.62z M959.36,419.13c0,11.94-6.36,22.35-15.82,28.24\n\t\tc-5.1,3.18-11.07,5.1-17.52,5.1c-6.08,0-11.71-1.76-16.62-4.61c-9.71-5.64-16.33-15.94-16.64-27.89c-0.01-0.29-0.09-0.56-0.09-0.85\n\t\tc0-11.75,6.14-22.05,15.36-28c5.2-3.35,11.35-5.35,17.99-5.35C944.41,385.78,959.36,400.75,959.36,419.13z"/>\n</g>\n</svg>',name:"polygon"}),i=new Ut({classList:["og-map-button","og-drawing-linestring_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\x3c!-- License: MIT. Made by Esri: https://github.com/Esri/calcite-ui-icons --\x3e\n <svg width="800px" height="800px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M21 6h.046l-5.25 9h-.944L10 9.455V7H7v2.926L1.862 18H0v3h3v-2.926L8.138 10h1.01L14 15.545V18h3v-3h-.046l5.25-9H24V3h-3zM8 8h1v1H8zM2 20H1v-1h1zm14-3h-1v-1h1zm7-13v1h-1V4z"/></svg>',name:"linestring"});new Jt({buttons:[e,t,i]}).events.on("change",(e=>{switch(this.drawingControl.deactivate(),e.name){case"polygon":this.drawingControl.activatePolygonDrawing();break;case"linestring":this.drawingControl.activateLineStringDrawing()}})),e.appendTo(this.renderer.div),t.appendTo(this.renderer.div),i.appendTo(this.renderer.div)}},EarthCoordinates:xn,ElevationProfileControl:class extends Dt{constructor(e={}){super({name:"ElevationProfileControl",...e}),this._onSceneChange=()=>{this._collectProfileThrottled()},this._onElevationProfilePointer=(e,t,i,s,n,r,o,a)=>{let l=this._elevationProfileScene.getPointLonLat(r),h=this._elevationProfileScene.getPointLonLat(r+1),c=this.planet.ellipsoid.lonLatToCartesian(l),d=this.planet.ellipsoid.lonLatToCartesian(h),_=(e-t[0])/(i[0]-t[0]),u=d.sub(c);this._elevationProfileScene.setPointerCartesian3v(c.add(u.scale(_)),a)},this._onElevationProfileDblClick=(e,t,i,s,n,r,o,a)=>{let l=this._elevationProfileScene.getPointLonLat(r),h=this._elevationProfileScene.getPointLonLat(r+1),c=this.planet.ellipsoid.lonLatToCartesian(l),d=this.planet.ellipsoid.lonLatToCartesian(h),_=(e-t[0])/(i[0]-t[0]),u=d.sub(c),g=c.add(u.scale(_));this.planet.camera.flyDistance(g,this.planet.camera.eye.distance(g))},this._onElevationProfileMouseEnter=()=>{this._elevationProfileView.model.pointsReady&&this._elevationProfileScene.setPointerVisibility(!0)},this._onElevationProfileMouseLeave=()=>{},this._elevationProfileScene=new zr,this._elevationProfileView=new Lr,this._elevationProfileLegend=new Or,this._elevationProfileButtonsView=new Nr({model:this._elevationProfileView.model}),this._elevationProfileView.events.on("pointer",this._onElevationProfilePointer),this._elevationProfileView.events.on("dblclick",this._onElevationProfileDblClick),this._elevationProfileView.events.on("mouseenter",this._onElevationProfileMouseEnter),this._elevationProfileView.events.on("mouseleave",this._onElevationProfileMouseLeave),this._dialog=new Ot({title:"Elevation Profile",visible:!1,resizable:!0,useHide:!0,top:175,left:65,width:400,height:200,minHeight:100,minWidth:100}),this._graphView=new kt({template:'<div class="og-elevationprofile__container">\n <div class="og-elevationprofile__menu"></div>\n <div class="og-elevationprofile__graph"></div>\n </div>'}),this._poiListDialog=new Hr({model:this._elevationProfileScene}),this._toggleBtn=new Ut({classList:["og-map-button","og-elevationprofile_button"],icon:'<svg style="width: 2em; height: 2em;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M128 896v-158.293333l331.946667-191.573334 160.853333 93.866667L896 480V896H128M896 381.44l-275.2 159.146667-160.853333-92.586667L128 640v-94.293333l331.946667-191.573334 160.853333 93.866667L896 288v93.44z" fill="" /></svg>'}),this._collectProfileThrottled=Ne((()=>{let e=this._elevationProfileScene.getPointsLonLat();this._elevationProfileView.model.collectProfile(e)}),250)}oninit(){this._dialog.appendTo(this.planet.renderer.div),this._graphView.appendTo(this._dialog.container),this._toggleBtn.appendTo(this.renderer.div),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e),e?(this.activate(),this._elevationProfileView.resize()):this.deactivate()})),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e)})),this._elevationProfileView.appendTo(this._graphView.select(".og-elevationprofile__graph")),this._elevationProfileView.model.bindPlanet(this.planet),this._elevationProfileView.model.events.on("clear",(()=>{this._elevationProfileScene.clear(),this._elevationProfileLegend.clear()})),this._elevationProfileView.model.events.on("startcollecting",(()=>{this._elevationProfileScene.setPointerVisibility(!1)})),this._elevationProfileView.events.on("tracklength",(e=>{this._elevationProfileLegend.setTrackLength(e)})),this._elevationProfileView.events.on("groundlength",(e=>{this._elevationProfileLegend.setGroundLength(e)})),this._elevationProfileView.events.on("warninglength",(e=>{this._elevationProfileLegend.setWarningLength(e)})),this._elevationProfileView.events.on("collisionlength",(e=>{this._elevationProfileLegend.setCollisionLength(e)})),this._poiListDialog.appendTo(this.planet.renderer.div),this._poiListDialog.events.on("visibility",(e=>{this._elevationProfileButtonsView.pointListBtn.setActive(e,!0)})),this._elevationProfileLegend.appendTo(this._graphView.select(".og-elevationprofile__menu")),this._elevationProfileButtonsView.appendTo(this._graphView.select(".og-elevationprofile__menu")),this._elevationProfileButtonsView.events.on("list",(e=>{this._poiListDialog.setVisibility(e)})),this._elevationProfileButtonsView.events.on("location",(e=>{this._elevationProfileScene.flyExtent()})),this._elevationProfileButtonsView.events.on("reset",(e=>{this._elevationProfileScene.setPointerVisibility(!1)})),this._elevationProfileScene.events.on("change",this._onSceneChange)}onactivate(){this.renderer.controls.mouseNavigation.deactivateDoubleClickZoom(),this.planet&&this._elevationProfileScene.bindPlanet(this.planet),this.renderer&&this.renderer.addNode(this._elevationProfileScene)}ondeactivate(){this._poiListDialog.setVisibility(!1),this._elevationProfileView.model.clear(),this.renderer.controls.mouseNavigation.activateDoubleClickZoom(),this.renderer&&this.renderer.removeNode(this._elevationProfileScene),this._dialog.hide()}},GeoImageDragControl:class extends Dt{constructor(e={}){super(e),this._cornerIndex=-1,this._catchCorner=!1,this._toggleBtn=new Ut({classList:["og-map-button","og-geoimagegrag_button"],icon:'<?xml version="1.0" encoding="UTF-8" standalone="no"?> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path d="M16 13l6.964 4.062-2.973.85 2.125 3.681-1.732 1-2.125-3.68-2.223 2.15L16 13zm-2-7h2v2h5a1 1 0 0 1 1 1v4h-2v-3H10v10h4v2H9a1 1 0 0 1-1-1v-5H6v-2h2V9a1 1 0 0 1 1-1h5V6zM4 14v2H2v-2h2zm0-4v2H2v-2h2zm0-4v2H2V6h2zm0-4v2H2V2h2zm4 0v2H6V2h2zm4 0v2h-2V2h2zm4 0v2h-2V2h2z" fill="#000"/></svg>'})}oninit(){this._toggleBtn.appendTo(this.renderer.div),this.planet.events.on("layeradd",(e=>{this.isActive()&&this._bindLayer(e)}),this),this._toggleBtn.events.on("change",(e=>{e?this.activate():this.deactivate()}))}onactivate(){super.onactivate();const e=this.planet;for(let t=0;t<e.layers.length;t++)this._bindLayer(e.layers[t])}ondeactivate(){super.ondeactivate();const e=this.planet;for(let t=0;t<e.layers.length;t++)this._unbindLayer(e.layers[t])}_bindLayer(e){e instanceof wn&&(e.events.on("mousemove",this._onMouseMove,this),e.events.on("mouseleave",this._onMouseLeave,this),e.events.on("ldown",this._onLDown,this),e.events.on("lup",this._onLUp,this))}_unbindLayer(e){e instanceof wn&&(e.events.off("mousemove",this._onMouseMove),e.events.off("mouseleave",this._onMouseLeave),e.events.off("ldown",this._onLDown),e.events.off("lup",this._onLUp))}_onLUp(e){this._catchCorner=!1,e.renderer.controls.mouseNavigation.activate()}_onLDown(e){-1!==this._cornerIndex&&(this._catchCorner=!0,e.renderer.controls.mouseNavigation.deactivate())}_onMouseLeave(){document.body.style.cursor="auto"}_onMouseMove(e){let t=e.pickingObject;const i=this.planet;if(this._catchCorner){let s=t.getCornersLonLat();s[this._cornerIndex]=i.getLonLatFromPixelTerrain(e),t.setCornersLonLat(s)}else{this._cornerIndex=-1;for(let s=0;s<t._cornersWgs84.length;s++){let n=i.getLonLatFromPixelTerrain(e);if(n&&i.ellipsoid.getGreatCircleDistance(t._cornersWgs84[s],n)/i.getDistanceFromPixel(e)<=.05){this._cornerIndex=s,document.body.style.cursor="move";break}document.body.style.cursor="auto"}}}},GeoObjectEditor:class extends Dt{constructor(e={}){super(e),this._geoObjectEditopScene=new uo({name:`geoObjectEditorScene:${this.__id}`}),this._dialog=new yo({model:this._geoObjectEditopScene})}oninit(){this.renderer&&(this.renderer.addControl(new bo({planet:this.planet})),this._geoObjectEditopScene.bindPlanet(this.planet),this._dialog.appendTo(this.renderer.div||document.body),this.activate())}onactivate(){this.renderer&&this.renderer.addNode(this._geoObjectEditopScene)}ondeactivate(){this.renderer&&this.renderer.removeNode(this._geoObjectEditopScene),this._dialog.hide()}},HeightRuler:$n,KeyboardNavigation:class extends Dt{constructor(e={}){e=e||{},super({name:"KeyboardNavigation",...e}),this.step=e.step||25e3}onactivate(){let e=this.renderer;e.events.on("keypress",Cn.KEY_PGUP,this.onCameraMoveForward,this),e.events.on("keypress",Cn.KEY_PGDN,this.onCameraMoveBackward,this),e.events.on("keypress",Cn.KEY_PLUS,this.onCameraMoveForward,this),e.events.on("keypress",Cn.KEY_EQUALS,this.onCameraMoveForward,this),e.events.on("keypress",Cn.KEY_MINUS,this.onCameraMoveBackward,this),e.events.on("keypress",Cn.KEY_W,this.onCameraMoveForward,this),e.events.on("keypress",Cn.KEY_S,this.onCameraMoveBackward,this),e.events.on("keypress",Cn.KEY_A,this.onCameraStrifeLeft,this),e.events.on("keypress",Cn.KEY_D,this.onCameraStrifeRight,this),e.events.on("keypress",Cn.KEY_UP,this.onCameraLookUp,this),e.events.on("keypress",Cn.KEY_DOWN,this.onCameraLookDown,this),e.events.on("keypress",Cn.KEY_LEFT,this.onCameraLookLeft,this),e.events.on("keypress",Cn.KEY_RIGHT,this.onCameraLookRight,this),e.events.on("keypress",Cn.KEY_Q,this.onCameraRollLeft,this),e.events.on("keypress",Cn.KEY_E,this.onCameraRollRight,this),e.events.on("keypress",Cn.KEY_N,this.onCameraRollNorth,this)}ondeactivate(){let e=this.renderer;e.events.off("keypress",Cn.KEY_PGUP,this.onCameraMoveForward),e.events.off("keypress",Cn.KEY_PGDN,this.onCameraMoveBackward),e.events.off("keypress",Cn.KEY_PLUS,this.onCameraMoveForward),e.events.off("keypress",Cn.KEY_EQUALS,this.onCameraMoveForward),e.events.off("keypress",Cn.KEY_MINUS,this.onCameraMoveBackward),e.events.off("keypress",Cn.KEY_W,this.onCameraMoveForward),e.events.off("keypress",Cn.KEY_S,this.onCameraMoveBackward),e.events.off("keypress",Cn.KEY_A,this.onCameraStrifeLeft),e.events.off("keypress",Cn.KEY_D,this.onCameraStrifeRight),e.events.off("keypress",Cn.KEY_UP,this.onCameraLookUp),e.events.off("keypress",Cn.KEY_DOWN,this.onCameraLookDown),e.events.off("keypress",Cn.KEY_LEFT,this.onCameraLookLeft),e.events.off("keypress",Cn.KEY_RIGHT,this.onCameraLookRight),e.events.off("keypress",Cn.KEY_Q,this.onCameraRollLeft),e.events.off("keypress",Cn.KEY_E,this.onCameraRollRight),e.events.off("keypress",Cn.KEY_N,this.onCameraRollNorth)}oninit(){this.activate()}onCameraMoveForward(){let e=this.planet.camera;e.slide(0,0,-e.getAltitude()/this.step)}onCameraMoveBackward(){let e=this.planet.camera;e.slide(0,0,e.getAltitude()/this.step)}onCameraStrifeLeft(){let e=this.planet.camera;e.slide(-e.getAltitude()/this.step,0,0)}onCameraStrifeRight(){let e=this.planet.camera;e.slide(e.getAltitude()/this.step,0,0)}onCameraLookUp(){let e=this.planet.camera;this.renderer.events.isKeyPressed(Cn.KEY_SHIFT)?e.setPitch(15/this.renderer.handler.deltaTime):e.rotateVertical(e.getAltitude()/3e6*l,oe.ZERO)}onCameraLookDown(){let e=this.planet.camera;this.renderer.events.isKeyPressed(Cn.KEY_SHIFT)?e.setPitch(-15/this.renderer.handler.deltaTime):e.rotateVertical(-e.getAltitude()/3e6*l,oe.ZERO)}onCameraLookLeft(){let e=this.planet.camera;this.renderer.events.isKeyPressed(Cn.KEY_SHIFT)?e.setRoll(15/this.renderer.handler.deltaTime):e.rotateHorizontal(e.getAltitude()/3e6*l)}onCameraLookRight(){let e=this.planet.camera;this.renderer.events.isKeyPressed(Cn.KEY_SHIFT)?e.setRoll(-15/this.renderer.handler.deltaTime):e.rotateHorizontal(-e.getAltitude()/3e6*l)}onCameraTurnLeft(){let e=this.planet.camera;this.renderer.events.isKeyPressed(Cn.KEY_SHIFT)?e.setYaw(15/this.renderer.handler.deltaTime):e.rotateHorizontal(e.getAltitude()/3e6*l)}onCameraTurnRight(){let e=this.planet.camera;this.renderer.events.isKeyPressed(Cn.KEY_SHIFT)?e.setYaw(-15/this.renderer.handler.deltaTime):e.rotateHorizontal(-e.getAltitude()/3e6*l,!1,oe.ZERO)}onCameraRollNorth(){let e=this.planet.getCartesianFromPixelTerrain(this.renderer.handler.getCenter());e?this.planet.flyCartesian(e.normal().scaleTo(e.length()+e.distance(this.planet.camera.eye)),null,null,0,null,null,(()=>{this.planet.camera.look})):this.planet.flyCartesian(this.planet.camera.eye)}onCameraRollLeft(){this.planet.camera.setRoll(-15/this.renderer.handler.deltaTime)}onCameraRollRight(){this.planet.camera.setRoll(15/this.renderer.handler.deltaTime)}},LayerAnimation:class extends Dt{constructor(e={}){super(e),this._currVisibleIndex=0,this._onViewchange=()=>{this._timeoutStart=performance.now()},this._onVisibilityChange=e=>{e||this.pause()},this._onLayerLoadend=e=>{let t=this._layersArr[this._currentIndex];if(t&&t.isEqual(e)){let e=this._getFrameIndex(this._currentIndex)*this._frameSize,i=this._currentIndex;for(let t=e;t<i;t++){let e=this._layersArr[t];e.opacity=0,e.setVisibility(!1)}t.opacity=1;let s=this._layersArr[this._currVisibleIndex];if(s){s.opacity=0,s.setVisibility(!1);let e=this._getFrameIndex(this._currVisibleIndex);this._getFrameIndex(this._currentIndex)!==e&&this._removeFrameFromPlanet(e)}this.events.dispatch(this.events.idle,t)}},this.events=Mt(Tn),this._name=e.name||`layerAnimation-${this.__id}`,this._layersArr=e.layers?[].concat(e.layers):[],this._currentIndex=-1,this._playInterval=e.playInterval||120,this._playIntervalHandler=-1,this._playIndex=0,this._frameSize=e.frameSize||50,this.repeat=null==e.repeat||e.repeat,this.skipTimeout=e.skipTimeout||5e3,this._timeoutStart=0}_getFramesNum(){return Math.ceil(this._layersArr.length/this._frameSize)}_setFrame(e){for(let t=0,i=this._getFramesNum();t<i;t++)t!==e?this._removeFrameFromPlanet(t):this._appendFrameToPlanet(t)}_getFrameIndex(e){return Math.floor(e/this._frameSize)}_appendFrameToPlanet(e){if(this.planet){let t=e*this._frameSize,i=t+this._frameSize;for(let e=t,s=i>this._layersArr.length?this._layersArr.length:i;e<s;e++)this.planet.addLayer(this._layersArr[e])}}_removeFrameFromPlanet(e){if(this.planet){let t=e*this._frameSize,i=t+this._frameSize;for(let e=t,s=i>this._layersArr.length?this._layersArr.length:i;e<s;e++)this._layersArr[e].abortLoading(),this._layersArr[e].remove(),this._layersArr[e].setVisibility(!1)}}oninit(){super.oninit(),this.onactivate(),this._initLayers(),this.planet.events.on("layerloadend",this._onLayerLoadend),this._setCurrentIndexAsync(0,!1,!0)}onactivate(){super.onactivate(),this.planet.camera.events.on("viewchange",this._onViewchange),this.planet.renderer.handler.events.on("visibilitychange",this._onVisibilityChange)}ondeactivate(){super.ondeactivate(),this.planet.camera.events.off("viewchange",this._onViewchange);for(let e=0;e<this._layersArr.length;e++)this._layersArr[e].setVisibility(!1);this.planet.events.off("layerloadend",this._onLayerLoadend),this.planet.renderer.handler.events.off("visibilitychange",this._onVisibilityChange)}clear(){this.stop(),this._currentIndex=-1,this._currVisibleIndex=-1;let e=this._layersArr;this._layersArr=[];for(let t=0;t<e.length;t++)e[t].remove()}_initLayers(){if(this.planet){for(let e=0,t=this._layersArr.length;e<t;e++){let t=this._layersArr[e];t.setVisibility(!1),t.setBaseLayer(!1),t.opacity=0}this._appendFrameToPlanet(0)}}setLayers(e){this.clear(),this._layersArr=[].concat(e),this._initLayers()}appendLayer(e){this._layersArr.push(e),e.setVisibility(!1),e.setBaseLayer(!1),e.opacity=0,this.planet?.addLayer(e)}get isIdle(){let e=this._layersArr[this._currentIndex];return e&&e.isIdle||!e}get playInterval(){return this._playInterval}set playInterval(e){e!==this._playInterval&&(this._playInterval=e,this.isPlaying&&(this.pause(),this.play()))}get isPlaying(){return-1!==this._playIntervalHandler}get layers(){return this._layersArr}_checkEnd(){this._playIndex>this._layersArr.length&&(this.repeat?this._playIndex=0:this.pause())}play(){this.isPlaying||(this._currentIndex>=this._layersArr.length-1&&this.stop(),this._timeoutStart=performance.now(),this._playIntervalHandler=setInterval((()=>{this._checkEnd(),this._setCurrentIndexAsync(this._playIndex,!1,!1),requestAnimationFrame((()=>{(this.isIdle||performance.now()-this._timeoutStart>this.skipTimeout)&&(this._playIndex++,this._timeoutStart=performance.now())}))}),this._playInterval),this.events.dispatch(this.events.play))}stop(){this._playIndex>0&&(this._clearInterval(),this._playIndex=0,this.setCurrentIndex(0),this.events.dispatch(this.events.stop))}pause(){this.isPlaying&&(this._clearInterval(),this.events.dispatch(this.events.pause))}_clearInterval(){clearInterval(this._playIntervalHandler),this._playIntervalHandler=-1}setCurrentIndex(e,t=!1){this._setCurrentIndexAsync(e,!0,t)}_setCurrentIndexAsync(e,t=!1,i=!1){if(e!=this._currentIndex&&e>=0&&e<this._layersArr.length){let s=this._currentIndex;this._currentIndex=e,this._playIndex=e;let n=this._getFrameIndex(s),r=this._getFrameIndex(this._currentIndex),o=this._layersArr[s],a=this._layersArr[e],l=r!=n;l&&this._appendFrameToPlanet(r),o&&(o.isIdle?this._currVisibleIndex=s:(o.opacity=0,o.setVisibility(!1))),a&&(a.opacity=0,a.setVisibility(!0),requestAnimationFrame((()=>{if(a.isIdle||t){a.opacity=1,l&&this._removeFrameFromPlanet(n),o&&(o.opacity=0,o.setVisibility(!1));let e=this._layersArr[this._currVisibleIndex];e&&(e.opacity=0,e.setVisibility(!1))}})),i||this.events.dispatch(this.events.change,this._currentIndex,s))}}},LayerSwitcher:class extends Dt{constructor(e={}){super({name:"LayerSwitcher",...e}),this.addLayer=e=>{if(!e.hideInLayerSwitcher){let t=this._createLayerButton(e);this._layerViews.push(t),e.isBaseLayer()?t.appendTo(this.$baseLayers):t.appendTo(this.$overlays)}},this.removeLayer=e=>{for(let t=0;t<this._layerViews.length;t++){let i=this._layerViews[t];if(i.model.isEqual(e)){i.remove(),this._layerViews.splice(t,1);break}}},this._dialog=new Ot({title:"Layer Switcher",top:15,useHide:!0,visible:!1,width:300,maxHeight:500}),this._panel=new kt({template:'<div class="og-layerSwitcher">\n <div class="og-layerSwitcher__title">Base Layers</div>\n <div class="og-layerSwitcher__list og-layerSwitcher__baseLayers"></div> \n \n <div class="og-layerSwitcher__title">Overlays</div>\n <div class="og-layerSwitcher__list og-layerSwitcher__overlays"></div>\n \n </div>'}),this._toggleBtn=new Ut({classList:["og-map-button","og-layerSwitcher_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Svg Vector Icons : http://www.onlinewebfonts.com/icon --\x3e\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve">\n<metadata> Svg Vector Icons : http://www.onlinewebfonts.com/icon </metadata>\n<g><path d="M500,573.5c-3.2,0-6.5-0.6-9.5-1.9L25,375.6c-9.1-3.8-15-12.7-15-22.6s5.9-18.8,15-22.6l465.5-196c6.1-2.5,12.9-2.5,19,0l465.5,196c9.1,3.8,15,12.7,15,22.6s-5.9,18.8-15,22.6l-465.5,196C506.5,572.9,503.2,573.5,500,573.5L500,573.5z M97.6,353L500,522.4L902.4,353L500,183.6L97.6,353L97.6,353z"/><path d="M500,720.5c-3.2,0-6.5-0.6-9.5-1.9L25,522.6c-12.4-5.2-18.3-19.6-13.1-32.1c5.2-12.5,19.6-18.3,32.1-13.1l456,192l456-192c12.4-5.2,26.9,0.6,32.1,13.1s-0.6,26.9-13.1,32.1l-465.5,196C506.5,719.9,503.2,720.5,500,720.5L500,720.5z"/><path d="M500,867.5c-3.2,0-6.5-0.6-9.5-1.9L25,669.6c-12.4-5.2-18.3-19.6-13.1-32.1c5.2-12.5,19.6-18.3,32.1-13.1l456,192l456-192c12.4-5.2,26.9,0.6,32.1,13.1c5.2,12.5-0.6,26.8-13.1,32.1l-465.5,196C506.5,866.9,503.2,867.5,500,867.5L500,867.5z"/></g>\n</svg>'}),this.$baseLayers=null,this.$overlays=null,this._layerViews=[]}oninit(){this._toggleBtn.appendTo(this.renderer.div),this._dialog.appendTo(this.planet.renderer.div),this._panel.appendTo(this._dialog.container),this.$baseLayers=this._panel.el.querySelector(".og-layerSwitcher__baseLayers"),this.$overlays=this._panel.el.querySelector(".og-layerSwitcher__overlays"),this._dialog.setPosition(this.planet.renderer.div.clientWidth-this._dialog.width-67),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e)})),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e)})),this.planet.events.on("layeradd",this.addLayer,this),this.planet.events.on("layerremove",this.removeLayer,this),this._initLayers()}_initLayers(){let e=this.planet.layers;for(let t=0;t<e.length;t++)this.addLayer(e[t])}_createLayerButton(e){return new En({model:e})}onactivate(){}ondeactivate(){this._dialog.hide()}},Lighting:class extends Dt{constructor(e={}){super(e),this._selectedLayer=null,this._toggleBtn=new Ut({classList:["og-map-button","og-lighting_button"],icon:'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="256" height="256" viewBox="0 0 256 256" xml:space="preserve">\n\n<defs>\n</defs>\n<g style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; opacity: 1;" transform="translate(1.4065934065934016 1.4065934065934016) scale(2.81 2.81)" >\n\t<path d="M 45 68 c -12.682 0 -23 -10.317 -23 -23 c 0 -12.682 10.318 -23 23 -23 c 12.683 0 23 10.318 23 23 C 68 57.683 57.683 68 45 68 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 45 17.556 c -1.657 0 -3 -1.343 -3 -3 V 3 c 0 -1.657 1.343 -3 3 -3 c 1.657 0 3 1.343 3 3 v 11.556 C 48 16.212 46.657 17.556 45 17.556 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 45 90 c -1.657 0 -3 -1.343 -3 -3 V 75.444 c 0 -1.657 1.343 -3 3 -3 c 1.657 0 3 1.343 3 3 V 87 C 48 88.657 46.657 90 45 90 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 14.556 48 H 3 c -1.657 0 -3 -1.343 -3 -3 c 0 -1.657 1.343 -3 3 -3 h 11.556 c 1.657 0 3 1.343 3 3 C 17.556 46.657 16.212 48 14.556 48 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 87 48 H 75.444 c -1.657 0 -3 -1.343 -3 -3 c 0 -1.657 1.343 -3 3 -3 H 87 c 1.657 0 3 1.343 3 3 C 90 46.657 88.657 48 87 48 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 66.527 26.473 c -0.768 0 -1.535 -0.293 -2.121 -0.878 c -1.172 -1.172 -1.172 -3.071 0 -4.243 l 8.171 -8.171 c 1.172 -1.172 3.07 -1.171 4.242 0 c 1.172 1.172 1.172 3.071 0 4.243 l -8.171 8.171 C 68.063 26.18 67.295 26.473 66.527 26.473 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 15.302 77.698 c -0.768 0 -1.536 -0.293 -2.121 -0.879 c -1.172 -1.171 -1.172 -3.071 0 -4.242 l 8.171 -8.171 c 1.171 -1.172 3.071 -1.172 4.242 0 c 1.172 1.171 1.172 3.071 0 4.242 l -8.171 8.171 C 16.837 77.405 16.069 77.698 15.302 77.698 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 23.473 26.473 c -0.768 0 -1.536 -0.293 -2.121 -0.878 l -8.171 -8.171 c -1.172 -1.172 -1.172 -3.071 0 -4.243 c 1.172 -1.172 3.072 -1.171 4.243 0 l 8.171 8.171 c 1.172 1.172 1.172 3.071 0 4.243 C 25.008 26.18 24.24 26.473 23.473 26.473 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 74.698 77.698 c -0.768 0 -1.535 -0.293 -2.121 -0.879 l -8.171 -8.171 c -1.172 -1.171 -1.172 -3.071 0 -4.242 c 1.172 -1.172 3.07 -1.172 4.242 0 l 8.171 8.171 c 1.172 1.171 1.172 3.071 0 4.242 C 76.233 77.405 75.466 77.698 74.698 77.698 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n</g>\n</svg>'}),this._dialog=new Ot({title:"Lighting Parameters",visible:!1,useHide:!0,top:60,left:60,width:600}),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e)})),this._panel=new kt({template:'<div class="og-lighing og-options-container">\n\n <div class="og-option">\n <div class="og-suncontrol"></div>\n </div> \n \n <div class="og-option og-atmosphere-opacity">\n </div>\n \n <div class="og-option og-simpleskybackground">\n </div>\n \n <div class="og-lighting-emptyline"></div>\n\n <div class="og-option og-gamma"></div> \n <div class="og-option og-exposure"></div>\n \n <div class="og-lighting-emptyline"></div>\n\n <div class="og-option">\n <div class="og-layers">\n <div class="og-caption">Select layer:</div>\n <select id="layers"></select>\n </div>\n </div>\n\n <div class="og-option og-opacity">\n </div>\n \n <div class="og-option og-night">\n </div>\n \n <div class="og-lighting-emptyline"></div>\n\n <div class="og-option og-diffuse">\n </div>\n \n <div class="og-option og-ambient">\n </div>\n\n <div class="og-option og-specular">\n </div> \n\n </div>'}),this.$gamma=null,this.$exposure=null,this.$night=null,this.$opacity=null,this.$diffuse=null,this.$ambient=null,this.$specular=null,this.$atmosphereOpacity=null,this.$simpleSkyBackground=null,this._atmosphereMaxOpacity=new An({label:"Max.opacity",max:5}),this._atmosphereMinOpacity=new An({label:"Min.opacity",max:5}),this._simpleSkyBackgroundColorOne=new Mn({label:"Color One"}),this._simpleSkyBackgroundColorTwo=new Mn({label:"Color Two"}),this._gamma=new An({label:"Gamma",max:5}),this._exposure=new An({label:"Exposure",max:5}),this._night=new An({label:"Nightlight",max:5}),this._opacity=new An({label:"Opacity",max:1}),this._diffuse_r=new An({label:"Diffuse R",max:5}),this._diffuse_g=new An({label:"Diffuse G",max:5}),this._diffuse_b=new An({label:"Diffuse B",max:5}),this._ambient_r=new An({label:"Ambient R",max:5}),this._ambient_g=new An({label:"Ambient G",max:5}),this._ambient_b=new An({label:"Ambient B",max:5}),this._specular_r=new An({label:"Specular R",max:.2}),this._specular_g=new An({label:"Specular G",max:.2}),this._specular_b=new An({label:"Specular B",max:.2}),this._shininess=new An({label:"Shininess",max:100})}bindLayer(e){this._selectedLayer=e,this._opacity.value=e.opacity,this._update()}oninit(){this._toggleBtn.appendTo(this.renderer.div),this._dialog.appendTo(this.renderer.div),this._panel.appendTo(this._dialog.container),this._panel.el&&(this.$atmosphereOpacity=this._panel.el.querySelector(".og-atmosphere-opacity"),this.$simpleSkyBackground=this._panel.el.querySelector(".og-simpleskybackground"),this.$gamma=this._panel.el.querySelector(".og-option.og-gamma"),this.$exposure=this._panel.el.querySelector(".og-option.og-exposure"),this.$opacity=this._panel.el.querySelector(".og-option.og-opacity"),this.$diffuse=this._panel.el.querySelector(".og-option.og-diffuse"),this.$ambient=this._panel.el.querySelector(".og-option.og-ambient"),this.$specular=this._panel.el.querySelector(".og-option.og-specular"),this.$night=this._panel.el.querySelector(".og-option.og-night")),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e)}));let e=this._dialog.select(".og-suncontrol"),t=new Ut({classList:["og-suncontrol-button"],isActive:!0,icon:'<?xml version="1.0" encoding="utf-8"?><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 122.88 70.41" style="enable-background:new 0 0 122.88 70.41" xml:space="preserve"><g><path d="M60.91,19.12c6.95,0,13.24,2.95,17.8,7.72c4.55,4.77,7.37,11.37,7.37,18.64c0,1.94-0.2,3.83-0.58,5.65h31.61 c2.1,0,2.62,1.16,2.62,2.59c0,1.43-0.52,2.59-2.62,2.59H7.09c-2.1,0-2.62-1.16-2.62-2.59c0-1.43,0.52-2.59,2.62-2.59h29.23 c-0.38-1.82-0.58-3.71-0.58-5.65c0-7.28,2.82-13.87,7.37-18.64C47.67,22.08,53.96,19.12,60.91,19.12L60.91,19.12L60.91,19.12z M63.4,70.41c-2.1,0-2.62-1.16-2.62-2.59s0.52-2.59,2.62-2.59h56.86c2.1,0,2.62,1.16,2.62,2.59s-0.52,2.59-2.62,2.59H63.4 L63.4,70.41z M2.62,70.41c-2.1,0-2.62-1.16-2.62-2.59s0.52-2.59,2.62-2.59h29.51c2.1,0,2.62,1.16,2.62,2.59s-0.52,2.59-2.62,2.59 H2.62L2.62,70.41z M38.39,9.46c-0.78-1.35-0.32-3.07,1.03-3.85c1.35-0.78,3.07-0.32,3.85,1.03l3.62,6.27 c0.78,1.35,0.32,3.07-1.03,3.85c-1.35,0.78-3.07,0.32-3.85-1.03L38.39,9.46L38.39,9.46L38.39,9.46z M58.67,2.83 c0-1.56,1.27-2.83,2.83-2.83c1.56,0,2.83,1.27,2.83,2.83v7.24c0,1.56-1.27,2.83-2.83,2.83c-1.56,0-2.83-1.26-2.83-2.83V2.83 L58.67,2.83L58.67,2.83z M79.56,7.23c0.77-1.35,2.49-1.81,3.84-1.04c1.35,0.77,1.81,2.49,1.04,3.84l-3.62,6.27 c-0.77,1.35-2.49,1.81-3.84,1.04c-1.35-0.77-1.81-2.49-1.04-3.84L79.56,7.23L79.56,7.23L79.56,7.23z M95.45,21.48 c1.35-0.78,3.07-0.32,3.85,1.03c0.78,1.35,0.32,3.07-1.03,3.85L92,29.98c-1.35,0.78-3.07,0.32-3.85-1.03 c-0.78-1.35-0.32-3.07,1.03-3.85L95.45,21.48L95.45,21.48L95.45,21.48z M102.08,41.76c1.56,0,2.83,1.27,2.83,2.83 c0,1.56-1.27,2.83-2.83,2.83h-7.24c-1.56,0-2.83-1.26-2.83-2.83s1.26-2.83,2.83-2.83H102.08L102.08,41.76L102.08,41.76z M19.74,46.25c-1.56,0-2.83-1.27-2.83-2.83c0-1.56,1.27-2.83,2.83-2.83h7.24c1.56,0,2.83,1.26,2.83,2.83s-1.27,2.83-2.83,2.83 H19.74L19.74,46.25L19.74,46.25z M24.14,25.35c-1.35-0.77-1.81-2.49-1.04-3.84c0.77-1.35,2.49-1.81,3.84-1.04l6.27,3.62 c1.35,0.77,1.81,2.49,1.04,3.84c-0.77,1.35-2.49,1.81-3.84,1.04L24.14,25.35L24.14,25.35L24.14,25.35z"/></g></svg>',title:"Star/stop the Sun from following the camera"});t.appendTo(e);let i=new Ut({classList:["og-suncontrol-button"],isActive:!0,icon:'<?xml version="1.0"?>\n<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">\n <path style="text-indent:0;text-align:start;line-height:normal;text-transform:none;block-progression:tb;-inkscape-font-specification:Sans" d="M 16 4 C 9.3844277 4 4 9.3844277 4 16 C 4 22.615572 9.3844277 28 16 28 C 22.615572 28 28 22.615572 28 16 C 28 9.3844277 22.615572 4 16 4 z M 16 6 C 16.389823 6 16.778223 6.0506339 17.15625 6.09375 C 18.631659 7.6568432 21 10.9245 21 16 C 21 21.0755 18.631659 24.343157 17.15625 25.90625 C 16.778223 25.949366 16.389823 26 16 26 C 10.465308 26 6 21.534692 6 16 C 6 10.465308 10.465308 6 16 6 z" overflow="visible" font-family="Sans"/>\n</svg>\n',title:"Activate/deactivate the Sun current time positioning"});i.appendTo(e),t.events.on("change",(e=>{const t=this.planet.renderer.controls.sun;e?t.start():t.stop()})),i.events.on("change",(e=>{const t=this.planet.renderer.controls.sun;e?t.activate():t.deactivate()}));let s=new Ut({classList:["og-suncontrol-button"],isActive:this.planet.lightEnabled,icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Generated by IcoMoon.io --\x3e\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="512" height="512" viewBox="0 0 512 512">\n<g>\n</g>\n\t<path d="M257.894 156.948c-53.258 0-96.42 43.561-96.42 97.26 0 53.719 43.161 97.249 96.42 97.249 53.197 0 96.379-43.53 96.379-97.25 0-53.698-43.182-97.26-96.379-97.26zM257.894 309.873c-30.464 0-55.163-24.945-55.163-55.665s24.699-55.624 55.163-55.624c30.423 0 55.101 24.904 55.101 55.624s-24.688 55.665-55.101 55.665z" fill="#000000" />\n\t<path d="M241.808 43.499h32.144v79.575h-32.144v-79.575z" fill="#000000" />\n\t<path d="M417.209 115.897l-22.723-22.917-55.757 56.279 22.723 22.907z" fill="#000000" />\n\t<path d="M389.468 238.407h78.899v32.389h-78.899v-32.389z" fill="#000000" />\n\t<path d="M396.012 416.86l22.723-22.917-55.767-56.259-22.712 22.897z" fill="#000000" />\n\t<path d="M242.473 388.915h32.144v79.575h-32.144v-79.575z" fill="#000000" />\n\t<path d="M96.266 396.073l22.722 22.938 55.778-56.289-22.692-22.928z" fill="#000000" />\n\t<path d="M43.633 240.537h78.879v32.43h-78.879v-32.43z" fill="#000000" />\n\t<path d="M115.394 93.051l-22.681 22.907 55.757 56.258 22.702-22.917z" fill="#000000" />\n</svg>',title:"Enable/disable planet lighting"});s.appendTo(e),s.events.on("change",(e=>{this.planet.lightEnabled=e}));let n=new Ut({classList:["og-suncontrol-button"],isActive:this.planet.atmosphereEnabled,icon:'<?xml version="1.0" encoding="utf-8"?>\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<svg width="800px" height="800px" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path fill="#000000" d="M135.688 18.5c-6.798 74.842-23.842 85.39-107.907 59.656 84.85 52.022 73.57 64.954-6.843 96.938 87.743-10.27 103.29 4.89 70.75 87.594 17.805-27.56 32.5-44.498 46.282-54.47-11.813 28.26-18.345 59.274-18.345 91.813 0 84.184 43.71 157.96 109.656 200.376-41.624-43.834-67.686-102.7-67.686-167.875 0-134.923 109.45-244.405 244.375-244.405 30.92 0 60.76 5.762 88 16.25-38.584-26.87-85.517-42.625-136.064-42.625-55.257 0-106.14 18.802-146.562 50.375 4.627-18.783 17.39-38.073 41.03-60.906C190.18 90.942 153.53 95.634 135.69 18.5zm10.03 77.188c5.67.002 11.428 1.247 16.876 3.874 14.506 6.998 22.72 21.81 22 36.938-10.26 10.87-19.507 22.696-27.594 35.344-9.035 2.753-19.075 2.27-28.25-2.156-19.37-9.343-27.5-32.6-18.156-51.97 6.715-13.92 20.638-22.036 35.125-22.03z"/></svg>',title:"Enable/disable atmosphere scattering"});n.appendTo(e),this.planet.atmosphereEnabled?(this.$atmosphereOpacity.style.display="block",this.$simpleSkyBackground.style.display="none"):(this.$atmosphereOpacity.style.display="none",this.$simpleSkyBackground.style.display="flex"),n.events.on("change",(e=>{this.planet.atmosphereEnabled=e,this.planet.atmosphereEnabled?(this.$atmosphereOpacity.style.display="block",this.$simpleSkyBackground.style.display="none"):(this.$atmosphereOpacity.style.display="none",this.$simpleSkyBackground.style.display="flex")})),this._atmosphereMaxOpacity.appendTo(this.$atmosphereOpacity),this._atmosphereMinOpacity.appendTo(this.$atmosphereOpacity),this._simpleSkyBackgroundColorOne.appendTo(this.$simpleSkyBackground),this._simpleSkyBackgroundColorTwo.appendTo(this.$simpleSkyBackground),this._gamma.appendTo(this.$gamma),this._exposure.appendTo(this.$exposure),this._night.appendTo(this.$night),this._opacity.appendTo(this.$opacity),this._diffuse_r.appendTo(this.$diffuse),this._diffuse_g.appendTo(this.$diffuse),this._diffuse_b.appendTo(this.$diffuse),this._ambient_r.appendTo(this.$ambient),this._ambient_g.appendTo(this.$ambient),this._ambient_b.appendTo(this.$ambient),this._specular_r.appendTo(this.$specular),this._specular_g.appendTo(this.$specular),this._specular_b.appendTo(this.$specular),this._shininess.appendTo(this.$specular),this._gamma.value=this.planet.renderer.gamma,this._gamma.events.on("change",(e=>{this.planet.renderer.gamma=e})),this._exposure.value=this.planet.renderer.exposure,this._exposure.events.on("change",(e=>{this.planet.renderer.exposure=e})),this._atmosphereMinOpacity.value=this.planet.atmosphereMinOpacity,this._atmosphereMinOpacity.events.on("change",(e=>{this.planet.atmosphereMinOpacity=e})),this._atmosphereMaxOpacity.value=this.planet.atmosphereMaxOpacity,this._atmosphereMaxOpacity.events.on("change",(e=>{this.planet.atmosphereMaxOpacity=e,this.planet.renderer.controls.Atmosphere.opacity=e}));let r=this.planet.renderer.controls.SimpleSkyBackground;r&&(this._simpleSkyBackgroundColorOne.value=r.colorOne,this._simpleSkyBackgroundColorTwo.value=r.colorTwo),this._simpleSkyBackgroundColorOne.events.on("input",(e=>{let t=this.planet.renderer.controls.SimpleSkyBackground;t&&(t.colorOne=e)})),this._simpleSkyBackgroundColorTwo.events.on("input",(e=>{let t=this.planet.renderer.controls.SimpleSkyBackground;t&&(t.colorTwo=e)})),this._panel.el.querySelector("#layers").addEventListener("change",(e=>{const t=this.planet.getLayerByName(e.target.value);t&&this.bindLayer(t)})),this._night.events.on("change",(e=>{this._selectedLayer&&(this._selectedLayer.nightTextureCoefficient=e)})),this._opacity.events.on("change",(e=>{this._selectedLayer&&(this._selectedLayer.opacity=e)})),this._ambient_r.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._ambient&&(this._selectedLayer._ambient[0]=e)})),this._ambient_g.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._ambient&&(this._selectedLayer._ambient[1]=e)})),this._ambient_b.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._ambient&&(this._selectedLayer._ambient[2]=e)})),this._diffuse_r.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._diffuse&&(this._selectedLayer._diffuse[0]=e)})),this._diffuse_g.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._diffuse&&(this._selectedLayer._diffuse[1]=e)})),this._diffuse_b.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._diffuse&&(this._selectedLayer._diffuse[2]=e)})),this._specular_r.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._specular&&(this._selectedLayer._specular[0]=e)})),this._specular_g.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._specular&&(this._selectedLayer._specular[1]=e)})),this._specular_b.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._specular&&(this._selectedLayer._specular[2]=e)})),this._shininess.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._specular&&(this._selectedLayer._specular[3]=e)})),this.planet&&(this.planet.events.on("layeradd",this._onLayerAdd,this),this.planet.events.on("layerremove",this._onLayerRemove,this)),this._fetchLayers()}_update(){let e=this._selectedLayer;this._opacity.value=e&&e.opacity?e.opacity:0,this._night.value=e&&e.nightTextureCoefficient?e.nightTextureCoefficient:this.planet.nightTextureCoefficient;let t=e&&e._ambient?e._ambient:this.planet._ambient;this._ambient_r.value=t[0],this._ambient_g.value=t[1],this._ambient_b.value=t[2];let i=e&&e._diffuse?e._diffuse:this.planet._diffuse;this._diffuse_r.value=i[0],this._diffuse_g.value=i[1],this._diffuse_b.value=i[2];let s=e&&e._specular?e._specular:this.planet._specular;this._specular_r.value=s[0],this._specular_g.value=s[1],this._specular_b.value=s[2],this._shininess.value=s[3]}_fetchLayers(){if(this.planet)for(let e=0;e<this.planet.layers.length;e++)this._onLayerAdd(this.planet.layers[e])}_onLayerAdd(e){this.bindLayer(e);let t=document.createElement("option");t.value=e.name,t.innerText=e.name,this._panel.el.querySelector("#layers").appendChild(t),this._panel.el.querySelector("#layers").value=e.name}_onLayerRemove(e){}},MouseNavigation:zn,OldMouseNavigation:kn,Ruler:Un,RulerSwitcher:class extends Dt{constructor(e={}){super({name:"RulerSwitcher",...e}),this.ruler=new $n({ignoreTerrain:e.ignoreTerrain})}oninit(){this.planet.addControl(this.ruler),this._createMenuBtn()}onactivate(){this.ruler.activate()}ondeactivate(){this.ruler.deactivate()}_createMenuBtn(){let e=new Ut({classList:["og-map-button","og-ruler_button"],icon:'<?xml version="1.0" encoding="iso-8859-1"?>\n\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<svg fill="#000000" height="800px" width="800px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" \n\t viewBox="0 0 512 512" xml:space="preserve">\n<g>\n\t<g>\n\t\t<path d="M369.151,0L0.001,369.15L142.85,512l369.149-369.15L369.151,0z M47.286,369.15l10.908-10.908l47.782,47.782l23.642-23.642\n\t\t\tL81.837,334.6l10.909-10.909l23.711,23.711L140.1,323.76l-23.711-23.711l10.909-10.909l23.711,23.711l23.642-23.642\n\t\t\tl-23.711-23.711l10.909-10.909l47.782,47.782l23.642-23.642l-47.782-47.782l10.908-10.908l23.71,23.71l23.642-23.642l-23.71-23.71\n\t\t\tl10.908-10.908l23.711,23.711l23.642-23.642l-23.711-23.711l10.909-10.909l47.782,47.782l23.642-23.642l-47.782-47.782\n\t\t\tl10.908-10.908l23.71,23.711l23.642-23.642l-23.711-23.71L334.6,81.837l23.711,23.71l23.642-23.642l-23.711-23.712l10.908-10.908\n\t\t\tl95.564,95.564L142.85,464.714L47.286,369.15z"/>\n\t</g>\n</g>\n</svg>'});e.appendTo(this.renderer.div),e.events.on("change",(e=>{e?this.onactivate():this.ondeactivate()}))}},ScaleControl:Zn,Selection:class extends Dt{constructor(e={}){super(e),this._selectorScene=new rr({name:`selectionScene:${this.__id}`,ignoreTerrain:e.ignoreTerrain,onSelect:e.onSelect,autoSelectionHide:e.autoSelectionHide}),this._toggleBtn=new Ut({classList:["og-map-button","og-selection_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<svg width="800px" height="800px" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--gis" preserveAspectRatio="xMidYMid meet"><path d="M2.1 0v1.914H0v6h3V3h5.1V0h-6zm9 0v3h6V0h-6zm9 0v3h6V0h-6zm9 0v3h6V0h-6zm9 0v3h6V0h-6zm9 0v3h6V0h-6zm9 0v3h6V0h-6zm9 0v3h1.8v1.2h3V0h-4.8zm1.8 7.2v6h3v-6h-3zM0 10.913v6h3v-6H0zM66.9 16.2v6h3v-6h-3zM0 19.914v6h3v-6H0zM66.9 25.2v6h3v-6h-3zM0 28.914v6h3v-6H0zM66.9 34.2v6h3v-6h-3zM0 37.914v6h3v-6H0zM66.9 43.2v6h3v-6h-3zM0 46.914v6h3v-6H0zM66.9 52.2v6h3v-6h-3zM0 55.914v5.191h3.809v-3H3v-2.19H0zm6.809 2.191v3h6v-3h-6zm9 0v3h6v-3h-6zm9 0v3h6v-3h-6zm9 0v3h6v-3h-6zm9 0v3h6v-3h-6zm9 0v3h6v-3h-6zm9 0v3h6v-3h-6zm9.648 1.899a2.076 2.076 0 0 0-2.19 2.324l3.137 33.676c.2 1.635 2.135 2.399 3.397 1.34l6.623-5.371l2.969 5.142c1.707 2.958 4.417 3.684 7.375 1.977c2.957-1.708 3.684-4.417 1.976-7.375l-2.959-5.125l7.848-3.008c1.548-.564 1.855-2.62.539-3.611L71.576 60.416a2.073 2.073 0 0 0-1.119-.412z" fill="#000000"></path></svg>'})}set ignoreTerrain(e){this._selectorScene.ignoreTerrain=e}oninit(){this._toggleBtn.appendTo(this.renderer.div),this._toggleBtn.events.on("change",(e=>{e?this.activate():this.deactivate()})),this._selectorScene.bindPlanet(this.planet)}onactivate(){this.renderer.addNode(this._selectorScene)}ondeactivate(){this.renderer.removeNode(this._selectorScene)}},ShowFps:class extends Dt{constructor(e){super(e)}oninit(){let e=document.createElement("div");e.className="defaultText ",e.id="ogShowFpsControl",document.body.appendChild(e),this.renderer.events.on("draw",this._draw,this)}_draw(){Te("ogShowFpsControl",(1e3/this.renderer.handler.deltaTime).toFixed(1),this.renderer.handler.canvas.clientWidth-60,0)}},SimpleNavigation:class extends Dt{constructor(e={}){super({name:"SimpleNavigation",autoActivate:!0,...e}),this._onMouseLeftButtonClick=e=>{this._active&&this.renderer&&(this.renderer.handler.canvas.classList.add("ogGrabbingPoiner"),this._grabbedPoint=this.renderer.getCartesianFromPixel(e),this._grabbedPoint&&this._eye0.copy(this.renderer.activeCamera.eye))},this._onMouseLeftButtonUp=e=>{this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner"),e.x===e.prev_x&&(e.y,e.prev_y)},this._onMouseLeftButtonDown=e=>{if(this._active&&this.renderer){if(!this._grabbedPoint)return;if(e.moving){let t,i,s=this.renderer.activeCamera,n=Math.abs(s.getForward().dot(oe.UP)),r=this._grabbedPoint;n>.7?(t=oe.add(r,oe.LEFT),i=oe.add(r,s.getRight())):(t=oe.add(r,s.getRight()),i=oe.add(r,oe.UP));let o=new oe;new ui(s.eye,e.direction).hitPlaneRes(_i.fromPoints(r,t,i),o)===ui.INSIDE&&(s.eye=this._eye0.addA(o.subA(r).negate()))}}},this._onRHold=e=>{if(this._lookPos&&e.moving&&this.renderer){const t=this.renderer.activeCamera;this.renderer.controlsBag.scaleRot=1;let i=.5/t.eye.distance(this._lookPos)*l;i>.007?i=.007:i<.003&&(i=.003),t.rotateHorizontal(i*(e.x-e.prev_x),!1,this._lookPos,this._up),t.rotateVertical(i*(e.y-e.prev_y),this._lookPos)}},this._onRDown=e=>{this.renderer&&(this._lookPos=this.renderer.getCartesianFromPixel(e.pos),this._lookPos&&(this._up=oe.UP))},this._onMouseWheel=e=>{if(this.renderer){let t=this.renderer.getCartesianFromPixel(e),i=10;t&&(i=this.renderer.activeCamera.eye.distance(t)),this.force.addA(e.direction.scale(e.wheelDelta)).normalize().scale(i)}},this.onCameraMoveForward=()=>{this.force.addA(this.renderer.activeCamera.getForward()).normalize()},this.onCameraMoveBackward=()=>{this.force.addA(this.renderer.activeCamera.getBackward()).normalize()},this.onCameraStrifeLeft=()=>{this.force.addA(this.renderer.activeCamera.getLeft()).normalize()},this.onCameraStrifeRight=()=>{this.force.addA(this.renderer.activeCamera.getRight()).normalize()},this.onCameraLookUp=()=>{let e=this.renderer.activeCamera;e.setPitch(.5),e.update()},this.onCameraLookDown=()=>{let e=this.renderer.activeCamera;e.setPitch(-.5),e.update()},this.onCameraTurnLeft=()=>{let e=this.renderer.activeCamera;e.setYaw(.5),e.update()},this.onCameraTurnRight=()=>{let e=this.renderer.activeCamera;e.setYaw(-.5),e.update()},this.onCameraRollLeft=()=>{let e=this.renderer.activeCamera;e.setRoll(-.5),e.update()},this.onCameraRollRight=()=>{let e=this.renderer.activeCamera;e.setRoll(.5),e.update()},this.speed=e.speed||1,this.force=new oe,this.vel=new oe,this.mass=1,this._lookPos=void 0,this._grabbedPoint=void 0,this._up=null,this._eye0=new oe}oninit(){}onactivate(){super.onactivate();let e=this.renderer;e.events.on("mousewheel",this._onMouseWheel),e.events.on("keypress",Cn.KEY_W,this.onCameraMoveForward,this),e.events.on("keypress",Cn.KEY_S,this.onCameraMoveBackward,this),e.events.on("keypress",Cn.KEY_A,this.onCameraStrifeLeft,this),e.events.on("keypress",Cn.KEY_D,this.onCameraStrifeRight,this),e.events.on("keypress",Cn.KEY_UP,this.onCameraLookUp,this),e.events.on("keypress",Cn.KEY_DOWN,this.onCameraLookDown,this),e.events.on("keypress",Cn.KEY_LEFT,this.onCameraTurnLeft,this),e.events.on("keypress",Cn.KEY_RIGHT,this.onCameraTurnRight,this),e.events.on("keypress",Cn.KEY_Q,this.onCameraRollLeft,this),e.events.on("keypress",Cn.KEY_E,this.onCameraRollRight,this),e.events.on("rhold",this._onRHold,this),e.events.on("rdown",this._onRDown,this),e.events.on("lhold",this._onMouseLeftButtonDown),e.events.on("ldown",this._onMouseLeftButtonClick),e.events.on("lup",this._onMouseLeftButtonUp),e.events.on("draw",this.onDraw,this,-1e3)}ondeactivate(){super.ondeactivate();let e=this.renderer;e.events.off("mousewheel",this._onMouseWheel),e.events.off("keypress",Cn.KEY_W,this.onCameraMoveForward),e.events.off("keypress",Cn.KEY_S,this.onCameraMoveBackward),e.events.off("keypress",Cn.KEY_A,this.onCameraStrifeLeft),e.events.off("keypress",Cn.KEY_D,this.onCameraStrifeRight),e.events.off("keypress",Cn.KEY_UP,this.onCameraLookUp),e.events.off("keypress",Cn.KEY_DOWN,this.onCameraLookDown),e.events.off("keypress",Cn.KEY_LEFT,this.onCameraTurnLeft),e.events.off("keypress",Cn.KEY_RIGHT,this.onCameraTurnRight),e.events.off("keypress",Cn.KEY_Q,this.onCameraRollLeft),e.events.off("keypress",Cn.KEY_E,this.onCameraRollRight),e.events.off("rhold",this._onRHold),e.events.off("rdown",this._onRDown),e.events.off("lhold",this._onMouseLeftButtonDown),e.events.off("ldown",this._onMouseLeftButtonClick),e.events.off("lup",this._onMouseLeftButtonUp),e.events.off("draw",this.onDraw)}get dt(){return.001*this.renderer.handler.deltaTime}onDraw(){if(this.renderer){let e=this.force.scale(1/this.mass);this.vel.addA(e),this.vel.scale(.96),this.force.set(0,0,0);let t=this.renderer.activeCamera;t.eye=t.eye.add(this.vel.scaleTo(this.dt)),t.update()}}},SimpleSkyBackground:Kn,Sun:tr,TimelineControl:class extends Dt{constructor(e={}){super({name:"timeline",...e});let t=e.current||new Date,i=e.rangeStart||yr(t,-12),s=e.rangeEnd||yr(t,12);this._timelineView=new vr({rangeStart:i,rangeEnd:s,currentDate:t}),this._toggleBtn=new Ut({classList:["og-map-button","og-timeline_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Svg Vector Icons : http://www.onlinewebfonts.com/icon --\x3e\n <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve">\n <metadata> Svg Vector Icons : http://www.onlinewebfonts.com/icon </metadata>\n <g><path d="M500,10C229.4,10,10,229.4,10,500s219.4,490,490,490s490-219.4,490-490S770.6,10,500,10z M800.3,800.3c-39,39-84.5,69.7-135,91C613,913.5,557.4,924.7,500,924.7s-112.9-11.2-165.3-33.3c-50.5-21.3-95.9-52-135-91c-39-39-69.7-84.5-91-135C86.5,612.9,75.3,557.4,75.3,500s11.2-112.9,33.3-165.3c21.3-50.5,52-95.9,91-135c39-39,84.5-69.7,135-91C387.1,86.5,442.6,75.3,500,75.3s112.9,11.2,165.3,33.3c50.5,21.3,95.9,52,135,91c39,39,69.7,84.5,91,135c22.1,52.3,33.3,107.9,33.3,165.3s-11.2,112.9-33.3,165.3C869.9,715.8,839.3,761.2,800.3,800.3z"/><path d="M761.3,532.7H532.7V304c0-18.1-14.6-32.7-32.7-32.7s-32.7,14.6-32.7,32.7v261.3l0,0c0,18.1,14.6,32.7,32.7,32.7h261.3c18.1,0,32.7-14.6,32.7-32.7l0,0C794,547.3,779.4,532.7,761.3,532.7z"/></g>\n</svg>'}),this._dialog=new Ot({title:"Timeline",visible:!1,resizable:!0,useHide:!0,top:10,left:60,width:600,height:115,minHeight:115,maxHeight:110}),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e)}))}oninit(){let e=this.renderer.div;this._toggleBtn.appendTo(e),this._dialog.appendTo(e),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e),e&&this._timelineView.resize()})),this._timelineView.appendTo(this._dialog.container),this._timelineView.events.on("setcurrent",(e=>{this.renderer&&this.renderer.handler.defaultClock.setDate(e)})),this._timelineView.events.on("startdrag",(()=>{this.planet?.sun.stop(),this.renderer&&this.renderer.controls.mouseNavigation.deactivate()})),this._timelineView.events.on("stopdrag",(()=>{this.renderer&&this.renderer.controls.mouseNavigation.activate()})),this._timelineView.events.on("startdragcurrent",(()=>{this.planet?.sun.stop(),this.renderer&&this.renderer.controls.mouseNavigation.deactivate()})),this._timelineView.events.on("stopdragcurrent",(()=>{this.renderer&&this.renderer.controls.mouseNavigation.activate()}))}},ToggleWireframe:class extends Dt{constructor(e={}){super(e),this._isActive=!1,this.toogleWireframe=()=>{this.renderer&&this.renderer.handler.gl&&(this.planet.drawMode===this.renderer.handler.gl.LINE_STRIP?this.planet.setDrawMode(this.renderer.handler.gl.TRIANGLE_STRIP):this.planet.setDrawMode(this.renderer.handler.gl.LINE_STRIP))},this._isActive=e.isActive||!1}oninit(){this.renderer.events.on("charkeypress",Cn.KEY_X,this.toogleWireframe,this),this._isActive&&this.planet.setDrawMode(this.renderer.handler.gl.LINE_STRIP)}},TouchNavigation:sr,ZoomControl:nr});function Co(e){return new Uint32Array(e)}function To(e){let t=[],i=0,s=0,n=0;for(let r=1;r<e-1-1;r++){for(let o=1;o<e-1;o++)i=r*e+o,n=(r+1)*e,s=n+o,t.push(i,s);t.push(s,n+1)}return t.push(t[t.length-1],e*e-e),Co(t)}function Eo(e,t){let i=[];const s=(e-1)/t,n=e*e-e;let r=0;for(let t=0;t<e-2;t++){t%s==0&&(r=t);let o=n-e*t-e+1,a=n-e*r;i.push(a,o)}return t===e-1&&(i.push(e),i.push(0)),Co(i)}function Lo(e,t){let i=[];const s=(e-1)/t;let n=0;for(let t=0;t<e-2;t++){t%s==0&&(n=t);let r=e+t+1,o=n;i.push(o,r)}return t===e-1&&(i.push(e-2),i.push(e-1)),Co(i)}function Ao(e,t){let i=[];const s=(e-1)/t;let n=0;for(let t=0;t<e-2;t++){t%s==0&&(n=t);let r=e*(t+1)+e-2,o=e+e*n-1;i.push(o,r)}return t===e-1&&(i.push(e*(e-1)-1),i.push(e*e-1)),Co(i)}function Po(e,t){let i=[];const s=(e-1)/t;let n=0;const r=e*(e-1)-2,o=e*e-1;for(let t=0;t<e-2;t++){t%s==0&&(n=t);let e=r-t,a=o-n;i.push(a,e)}return t===e-1&&i.push(e*e-e+1),i.push(e*e-e),Co(i)}function So(e){let t=[[],[],[],[]];for(let i=0;i<=e;i++){let s=Math.pow(2,i)+1;t[0][i]=[],t[3][i]=[],t[2][i]=[],t[1][i]=[];for(let n=0;n<=e;n++){let e=Math.pow(2,n);t[3][i][n]=Eo(s,e),t[0][i][n]=Lo(s,e),t[1][i][n]=Ao(s,e),t[2][i][n]=Po(s,e)}}return t}function Mo(e){let t=[];for(let i=0;i<=e;i++){const e=Math.pow(2,i);t[i]=To(e+1)}return t}function Ro(e){let t=new Uint16Array((e+1)*(e+1)*2),i=0;for(let s=0;s<=e;s++)for(let n=0;n<=e;n++)t[i++]=n/e*65535,t[i++]=s/e*65535;return t}let Bo=new class{constructor(e=0){this._maxGridSize=e,this.centerIndexesTable=Mo(this._maxGridSize),this.skirtsIndexesTable=So(this._maxGridSize)}get maxGridSize(){return this._maxGridSize}init(){this.centerIndexesTable=Mo(this._maxGridSize),this.skirtsIndexesTable=So(this._maxGridSize)}setMaxGridSize(e){this._maxGridSize=e,this.init()}createSegmentIndexes(e,t){if(e){let i=this.centerIndexesTable[e],s=this.skirtsIndexesTable[3][e][t[3]],n=this.skirtsIndexesTable[0][e][t[0]],r=this.skirtsIndexesTable[1][e][t[1]],o=this.skirtsIndexesTable[2][e][t[2]],a=function(e){return new Uint32Array(e)}(i.length+s.length+n.length+r.length+o.length);return a.set(i,0),a.set(s,i.length),a.set(n,i.length+s.length),a.set(r,i.length+s.length+n.length),a.set(o,i.length+s.length+n.length+r.length),a}return Co([0,2,1,3])}initTextureCoordsTable(e){let t=[];for(let i=0;i<=e;i++){const e=Math.pow(2,i);t[i]=Ro(e)}return t}};function ko(){return Bo}const Io={ATMOS_HEIGHT:1e5,RAYLEIGH_SCALE:.08,MIE_SCALE:.012,GROUND_ALBEDO:.05,BOTTOM_RADIUS:6356752.314245179,rayleighScatteringCoefficient:[5.802,13.558,33.1],mieScatteringCoefficient:3.996,mieExtinctionCoefficient:4.44,ozoneAbsorptionCoefficient:[.65,1.881,.085],SUN_ANGULAR_RADIUS:.004685,SUN_INTENSITY:1,ozoneDensityHeight:25e3,ozoneDensityWide:15e3},zo=(e=Io)=>` \n ${ds}\n \n #define PI 3.1415926538\n #define ATMOS_HEIGHT ${e.ATMOS_HEIGHT.toFixed(2)}\n #define RAYLEIGH_SCALE ${e.RAYLEIGH_SCALE.toFixed(5)}\n #define MIE_SCALE ${e.MIE_SCALE.toFixed(5)}\n \n #define SAMPLE_COUNT 16\n #define SQRT_SAMPLE_COUNT 4\n \n const float GROUND_ALBEDO = ${e.GROUND_ALBEDO.toFixed(2)} / PI;\n\n // Sphere\n const float BOTTOM_RADIUS = ${e.BOTTOM_RADIUS.toFixed(10)};\n const float TOP_RADIUS = BOTTOM_RADIUS + ATMOS_HEIGHT; \n const float EQUATORIAL_RADIUS = 6378137.0;\n \n // Ellipsoid\n const vec3 bottomRadii = vec3(EQUATORIAL_RADIUS, EQUATORIAL_RADIUS, BOTTOM_RADIUS); \n const vec3 topRadii = bottomRadii + ATMOS_HEIGHT;\n \n const vec3 SPHERE_TO_ELLIPSOID_SCALE = vec3(BOTTOM_RADIUS) / bottomRadii; \n \n const vec2 rayleighMieHeights = vec2(RAYLEIGH_SCALE, MIE_SCALE) * ATMOS_HEIGHT;\n \n const vec3 rayleighScatteringCoefficient = vec3(${e.rayleighScatteringCoefficient[0].toFixed(5)}, ${e.rayleighScatteringCoefficient[1].toFixed(5)}, ${e.rayleighScatteringCoefficient[2].toFixed(5)}) * 1e-6;\n \n const float mieScatteringCoefficient = ${e.mieScatteringCoefficient.toFixed(3)} * 1e-6;\n const float mieExtinctionCoefficient = ${e.mieExtinctionCoefficient.toFixed(3)} * 1e-6;\n const vec3 ozoneAbsorptionCoefficient = vec3(${e.ozoneAbsorptionCoefficient[0].toFixed(5)}, ${e.ozoneAbsorptionCoefficient[1].toFixed(5)}, ${e.ozoneAbsorptionCoefficient[2].toFixed(5)}) * 1e-6;\n \n const float SUN_ANGULAR_RADIUS = ${e.SUN_ANGULAR_RADIUS.toFixed(10)};\n const float SUN_INTENSITY = ${e.SUN_INTENSITY.toFixed(2)}; \n \n const float ozoneDensityHeight = ${e.ozoneDensityHeight.toFixed(1)};//25e3;\n const float ozoneDensityWide = ${e.ozoneDensityWide.toFixed(1)};//15e3;\n \n vec3 sunWithBloom(vec3 rayDir, vec3 sunDir) \n {\n float minSunCosTheta = cos(SUN_ANGULAR_RADIUS); \n float cosTheta = dot(rayDir, sunDir);\n if (cosTheta >= minSunCosTheta) return vec3(1.0); \n float offset = minSunCosTheta - cosTheta;\n float gaussianBloom = exp(-offset*15000.0)*0.7;\n float invBloom = 1.0/(0.09 + offset*200.0)*0.01;\n return vec3(gaussianBloom + invBloom);\n }\n \n float rayleighPhase(float angle) \n {\n return 3.0 / (16.0 * PI) * (1.0 + (angle * angle));\n }\n \n float miePhase(float angle) \n {\n float g = 0.8;\n return 3.0 / (8.0 * PI) * ((1.0 - g * g) * (1.0 + angle * angle)) / ((2.0 + g * g) * pow(1.0 + g * g - 2.0 * g * angle, 1.5));\n }\n \n vec3 opticalDepth(float height, float angle) \n {\n vec3 rayOrigin = vec3(0.0, BOTTOM_RADIUS + height, 0.0);\n vec3 rayDirection = vec3(sqrt(1.0 - angle * angle), angle, 0.0);\n float t1, t2;\n intersectSphere(rayOrigin, rayDirection, TOP_RADIUS, t1, t2);\n float segmentLength = t2 / float(SAMPLE_COUNT);\n \n float t = segmentLength * 0.5;\n vec3 opticalDepth = vec3(0.0);\n \n for (int i = 0; i < SAMPLE_COUNT; i++) \n {\n vec3 position = rayOrigin + t * rayDirection;\n float height = length(position) - BOTTOM_RADIUS;\n opticalDepth.xy += exp(-height / rayleighMieHeights) * segmentLength;\n opticalDepth.z += (1.0 - min(abs(height - ozoneDensityHeight) / ozoneDensityWide, 1.0)) * segmentLength; \n t += segmentLength;\n }\n \n return opticalDepth;\n }\n \n vec3 transmittance(float height, float angle) \n {\n vec3 opticalDepth = opticalDepth(height, angle);\n return exp(-(rayleighScatteringCoefficient * opticalDepth.x + mieExtinctionCoefficient * opticalDepth.y + ozoneAbsorptionCoefficient * opticalDepth.z));\n }`;const Do="const vec3 nightStep = 10.0 * vec3(0.58, 0.48, 0.25);",Fo="#define blend(DEST, SAMPLER, OFFSET, OPACITY) src = texture( SAMPLER, OFFSET.xy + vTextureCoord.xy * OFFSET.zw ); DEST = DEST * (1.0 - src.a * OPACITY) + src * OPACITY;",No="#define blend(DEST, SAMPLER, OFFSET, OPACITY) src = texture2D( SAMPLER, OFFSET.xy + vTextureCoord.xy * OFFSET.zw ); DEST = DEST * (1.0 - src.a * OPACITY) + src * OPACITY;";function Ho(){return new Ni("drawnode_screen_wl",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",height:"float",uGlobalTextureCoord:"vec4",uNormalMapBias:"vec3",samplerCount:"int",tileOffsetArr:"vec4",layerOpacityArr:"float",samplerArr:"sampler2darray",defaultTexture:"sampler2d",uNormalMap:"sampler2d",nightTexture:"sampler2d",specularTexture:"sampler2d",lightPosition:"vec3",diffuse:"vec3",ambient:"vec3",specular:"vec4",camHeight:"float",nightTextureCoefficient:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"\n attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n attribute vec2 aTextureCoord;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec4 uGlobalTextureCoord;\n uniform vec3 uNormalMapBias;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n varying vec4 vTextureCoord;\n varying vec3 v_vertex;\n varying vec3 cameraPosition;\n varying vec2 vGlobalTextureCoord;\n varying float v_height;\n\n void main(void) {\n\n vec3 aVertexPosition = aVertexPositionHigh + aVertexPositionLow; \n vec3 nh = height * normalize(aVertexPosition);\n\n vTextureCoord.xy = aTextureCoord;\n vGlobalTextureCoord = uGlobalTextureCoord.xy + (uGlobalTextureCoord.zw - uGlobalTextureCoord.xy) * aTextureCoord;\n vTextureCoord.zw = uNormalMapBias.z * ( aTextureCoord + uNormalMapBias.xy );\n\n cameraPosition = eyePositionHigh + eyePositionLow;\n \n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n v_height = height;\n v_vertex = aVertexPosition + nh;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:`\n precision highp float;\n \n #define SLICE_SIZE 5\n\n uniform vec4 specular;\n uniform vec3 diffuse;\n uniform vec3 ambient;\n\n uniform sampler2D uNormalMap;\n uniform sampler2D nightTexture;\n uniform sampler2D specularTexture;\n uniform sampler2D defaultTexture;\n uniform sampler2D samplerArr[SLICE_SIZE];\n\n uniform vec4 tileOffsetArr[SLICE_SIZE];\n uniform vec3 lightPosition;\n uniform float layerOpacityArr[SLICE_SIZE];\n\n uniform int samplerCount;\n uniform float nightTextureCoefficient; \n uniform float camHeight;\n\n varying vec4 vTextureCoord;\n varying vec3 v_vertex;\n varying vec3 cameraPosition;\n varying vec2 vGlobalTextureCoord;\n varying float v_height;\n\n vec3 sunPos;\n\n ${Do}\n\n ${No}\n \n ${ds}\n \n void main(void) {\n \n sunPos = lightPosition;\n \n vec3 texNormal = texture2D(uNormalMap, vTextureCoord.zw).rgb;\n vec3 normal = normalize((texNormal - 0.5) * 2.0);\n \n float minH = 1200000.0;\n float maxH = minH * 3.0;\n float nightCoef = getLerpValue(minH, maxH, camHeight) * nightTextureCoefficient;\n \n // if(camHeight > 6000000.0)\n // {\n // normal = normalize(v_vertex);\n // }\n \n vec3 lightDir = normalize(sunPos);\n vec3 viewDir = normalize(cameraPosition - v_vertex);\n \n float overGround = 1.0 - step(0.1, v_height);\n\n float shininess = texture2D( specularTexture, vGlobalTextureCoord.st ).r * 255.0 * overGround;\n vec3 reflectionDirection = reflect(-lightDir, normal);\n float reflection = max( dot(reflectionDirection, viewDir), 0.0);\n vec3 spec = specular.rgb * pow( reflection, specular.w) * shininess; \n float diffuseLightWeighting = max(dot(normal, lightDir), 0.0); \n vec4 nightImageColor = texture2D( nightTexture, vGlobalTextureCoord.st );\n vec3 night = nightStep * (.18 - diffuseLightWeighting * 3.0) * nightImageColor.rgb * nightCoef;\n night *= overGround * step(0.0, night); \n vec4 lightWeighting = vec4(ambient + diffuse * diffuseLightWeighting + night, 1.0);\n \n gl_FragColor = texture2D( defaultTexture, vTextureCoord.xy );\n if( samplerCount == 0 ) {\n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n return;\n }\n\n vec4 src;\n\n blend(gl_FragColor, samplerArr[0], tileOffsetArr[0], layerOpacityArr[0]);\n if( samplerCount == 1 ) { \n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n return;\n }\n\n blend(gl_FragColor, samplerArr[1], tileOffsetArr[1], layerOpacityArr[1]);\n if( samplerCount == 2 ) {\n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n return;\n }\n\n blend(gl_FragColor, samplerArr[2], tileOffsetArr[2], layerOpacityArr[2]);\n if( samplerCount == 3 ) {\n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n return;\n }\n\n blend(gl_FragColor, samplerArr[3], tileOffsetArr[3], layerOpacityArr[3]);\n if( samplerCount == 4 ) {\n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n return;\n }\n\n blend(gl_FragColor, samplerArr[4], tileOffsetArr[4], layerOpacityArr[4]);\n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n }`})}function Oo(e){return new Ni("drawnode_screen_wl",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",height:"float",uGlobalTextureCoord:"vec4",uNormalMapBias:"vec3",samplerCount:"int",tileOffsetArr:"vec4",layerOpacityArr:"float",samplerArr:"sampler2darray",defaultTexture:"sampler2d",uNormalMap:"sampler2d",nightTexture:"sampler2d",specularTexture:"sampler2d",lightPosition:"vec3",diffuse:"vec3",ambient:"vec3",specular:"vec4",transmittanceTexture:"sampler2D",scatteringTexture:"sampler2D",camHeight:"float",nightTextureCoefficient:"float",maxMinOpacity:"vec2",transitionOpacity:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"#version 300 es\n\n precision highp float;\n\n in vec3 aVertexPositionHigh;\n in vec3 aVertexPositionLow;\n in vec2 aTextureCoord;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec4 uGlobalTextureCoord;\n uniform vec3 uNormalMapBias;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n out vec4 vTextureCoord;\n out vec3 v_vertex;\n out vec3 cameraPosition;\n out vec2 vGlobalTextureCoord;\n out float v_height;\n\n void main(void) {\n\n vec3 aVertexPosition = aVertexPositionHigh + aVertexPositionLow; \n vec3 nh = height * normalize(aVertexPosition);\n\n vTextureCoord.xy = aTextureCoord;\n vGlobalTextureCoord = uGlobalTextureCoord.xy + (uGlobalTextureCoord.zw - uGlobalTextureCoord.xy) * aTextureCoord;\n vTextureCoord.zw = uNormalMapBias.z * ( aTextureCoord + uNormalMapBias.xy );\n\n cameraPosition = eyePositionHigh + eyePositionLow;\n \n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n v_height = height;\n v_vertex = aVertexPosition + nh;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:`#version 300 es\n\n precision highp float;\n \n #define SLICE_SIZE 5\n\n uniform vec4 specular;\n uniform vec3 diffuse;\n uniform vec3 ambient;\n\n uniform vec3 lightPosition;\n\n uniform sampler2D uNormalMap;\n uniform sampler2D nightTexture;\n uniform sampler2D specularTexture;\n uniform sampler2D transmittanceTexture;\n uniform sampler2D scatteringTexture;\n uniform sampler2D defaultTexture;\n uniform sampler2D samplerArr[SLICE_SIZE];\n\n uniform vec4 tileOffsetArr[SLICE_SIZE];\n uniform float layerOpacityArr[SLICE_SIZE];\n\n uniform int samplerCount;\n uniform float nightTextureCoefficient;\n \n uniform vec2 maxMinOpacity; \n uniform float camHeight;\n \n uniform float transitionOpacity;\n\n in vec4 vTextureCoord;\n in vec3 v_vertex;\n in vec3 cameraPosition;\n in vec2 vGlobalTextureCoord;\n in float v_height;\n\n vec3 sunPos;\n\n layout(location = 0) out vec4 diffuseColor;\n\n ${Do}\n\n ${Fo}\n \n ${zo(e)} \n \n vec3 transmittanceFromTexture(float height, float angle) \n {\n float u = (angle + 1.0) * 0.5;\n float v = height / ATMOS_HEIGHT;\n return texture(transmittanceTexture, vec2(u, v)).xyz;\n }\n\n vec3 multipleScatteringContributionFromTexture(float height, float angle) \n {\n float u = (angle + 1.0) * 0.5;\n float v = height / ATMOS_HEIGHT;\n return texture(scatteringTexture, vec2(u, v)).xyz;\n }\n \n void getSunIlluminance(in vec3 point, in vec3 lightDir, out vec3 sunIlluminance)\n {\n // float r = length(point);\n // float mu_s = dot(point, sun_direction) / r;\n // float height = r - BOTTOM_RADIUS;\n \n float mu_s = dot(normalize(point), lightDir);\n float height = length(point) - BOTTOM_RADIUS;\n sunIlluminance = SUN_INTENSITY * transmittanceFromTexture(height, mu_s);\n }\n \n void atmosGroundColor(out vec4 fragColor, in vec3 normal)\n { \n vec3 cameraPosition = cameraPosition; \n \n if(length(cameraPosition * SPHERE_TO_ELLIPSOID_SCALE) < BOTTOM_RADIUS + 1.0){\n cameraPosition = normalize(cameraPosition * SPHERE_TO_ELLIPSOID_SCALE) * (BOTTOM_RADIUS + 1.0) / SPHERE_TO_ELLIPSOID_SCALE;\n } \n \n vec3 rayDirection = normalize(v_vertex - cameraPosition);\n vec3 lightDir = normalize(sunPos);\n \n rayDirection = normalize(rayDirection * SPHERE_TO_ELLIPSOID_SCALE);\n vec3 camPos = cameraPosition * SPHERE_TO_ELLIPSOID_SCALE;\n lightDir = normalize(lightDir * SPHERE_TO_ELLIPSOID_SCALE);\n \n\n vec3 light = vec3(0.0);\n vec3 transmittanceFromCameraToSpace = vec3(1.0);\n float offset = 0.0;\n float distanceToSpace = 0.0;\n \n intersectSphere(camPos, rayDirection, TOP_RADIUS, offset, distanceToSpace);\n \n vec3 rayOrigin = camPos;\n \n // above atmosphere\n if (offset > 0.0) \n {\n // intersection of camera ray with atmosphere\n rayOrigin += rayDirection * offset;\n }\n \n float height = length(rayOrigin) - BOTTOM_RADIUS;\n float rayAngle = dot(rayOrigin, rayDirection) / length(rayOrigin);\n bool cameraBelow = rayAngle < 0.0;\n \n transmittanceFromCameraToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n \n float phaseAngle = dot(lightDir, rayDirection);\n float rayleighPhase = rayleighPhase(phaseAngle);\n float miePhase = miePhase(phaseAngle);\n \n float distanceToGround = 0.0;\n \n bool hitGround = intersectSphere(camPos, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0; \n //intersectSphere(camPos, rayDirection, BOTTOM_RADIUS, distanceToGround);\n \n\n if(length(v_vertex * SPHERE_TO_ELLIPSOID_SCALE) > BOTTOM_RADIUS){\n distanceToGround = distance(camPos, v_vertex * SPHERE_TO_ELLIPSOID_SCALE);\n }\n \n float segmentLength = (distanceToGround - max(offset, 0.0)) / float(SAMPLE_COUNT);\n \n float t = segmentLength * 0.5;\n \n vec3 transmittanceCamera; \n vec3 transmittanceLight; \n \n for (int i = 0; i < SAMPLE_COUNT; i++) \n {\n vec3 position = rayOrigin + t * rayDirection;\n float height = length(position) - BOTTOM_RADIUS;\n vec3 up = position / length(position);\n float rayAngle = dot(up, rayDirection);\n float lightAngle = dot(up, lightDir); \n vec3 transmittanceToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n transmittanceCamera = cameraBelow ? (transmittanceToSpace / transmittanceFromCameraToSpace) : (transmittanceFromCameraToSpace / transmittanceToSpace);\n transmittanceLight = transmittanceFromTexture(height, lightAngle);\n vec2 opticalDensity = exp(-height / rayleighMieHeights);\n vec3 scatteredLight = transmittanceLight * (rayleighScatteringCoefficient * opticalDensity.x * rayleighPhase + mieScatteringCoefficient * opticalDensity.y * miePhase);\n scatteredLight += multipleScatteringContributionFromTexture(height, lightAngle) * (rayleighScatteringCoefficient * opticalDensity.x + mieScatteringCoefficient * opticalDensity.y); \n light += transmittanceCamera * scatteredLight * segmentLength;\n t += segmentLength;\n }\n \n light *= SUN_INTENSITY;\n \n vec3 hitPoint = camPos + rayDirection * distanceToGround;\n vec3 up = normalize(hitPoint);\n float diffuseAngle = max(dot(up, lightDir), 0.0); \n \n float lightAngle = dot(normal, lightDir);\n vec3 tA = transmittanceCamera * GROUND_ALBEDO * SUN_INTENSITY; \n vec3 scatteringLight = multipleScatteringContributionFromTexture(height, lightAngle);\n vec3 diffuseTransmittanceLight = transmittanceLight * diffuseAngle; \n light += tA * (scatteringLight + diffuseTransmittanceLight);\n \n fragColor = vec4(pow(light * 8.0, vec3(1.0 / 2.2)), 1.0);\n }\n\n void getAtmosFadingOpacity(out float opacity)\n { \n float c = length(cameraPosition);\n float maxDist = sqrt(c * c - BOTTOM_RADIUS * BOTTOM_RADIUS);\n float minDist = c - BOTTOM_RADIUS;\n float vertDist = distance(cameraPosition, v_vertex); \n opacity = clamp(maxMinOpacity.y + ( maxMinOpacity.x - maxMinOpacity.y) * getLerpValue(minDist, maxDist, vertDist), 0.0, 1.0);\n }\n\n void main(void) {\n \n sunPos = lightPosition;\n \n vec3 texNormal = texture(uNormalMap, vTextureCoord.zw).rgb;\n vec3 normal = normalize((texNormal - 0.5) * 2.0);\n \n float minH = 1200000.0;\n float maxH = minH * 3.0;\n float nightCoef = getLerpValue(minH, maxH, camHeight) * nightTextureCoefficient;\n \n // if(camHeight > 6000000.0)\n // {\n // normal = normalize(v_vertex);\n // }\n \n vec3 lightDir = normalize(sunPos);\n vec3 viewDir = normalize(cameraPosition - v_vertex);\n \n vec4 atmosColor;\n atmosGroundColor(atmosColor, normal);\n \n vec3 sunIlluminance; \n getSunIlluminance(v_vertex * SPHERE_TO_ELLIPSOID_SCALE, lightDir * SPHERE_TO_ELLIPSOID_SCALE, sunIlluminance);\n \n float overGround = 1.0 - step(0.1, v_height);\n\n float shininess = texture( specularTexture, vGlobalTextureCoord.st ).r * 255.0 * overGround;\n vec3 reflectionDirection = reflect(-lightDir, normal);\n float reflection = max( dot(reflectionDirection, viewDir), 0.0);\n vec3 spec = sunIlluminance * specular.rgb * pow( reflection, specular.w) * shininess; \n float diffuseLightWeighting = max(dot(normal, lightDir), 0.0);\n \n vec4 nightImageColor = texture( nightTexture, vGlobalTextureCoord.st );\n vec3 night = nightStep * (.18 - diffuseLightWeighting * 3.0) * nightImageColor.rgb * nightCoef;\n night *= overGround * step(0.0, night); \n vec4 lightWeighting = vec4(ambient + sunIlluminance * diffuse * diffuseLightWeighting + night, 1.0);\n \n float fadingOpacity;\n getAtmosFadingOpacity(fadingOpacity);\n \n getSunIlluminance(cameraPosition, viewDir * SPHERE_TO_ELLIPSOID_SCALE, sunIlluminance);\n \n spec *= sunIlluminance;\n\n diffuseColor = texture( defaultTexture, vTextureCoord.xy );\n if( samplerCount == 0 ) {\n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n vec4 src;\n\n blend(diffuseColor, samplerArr[0], tileOffsetArr[0], layerOpacityArr[0]);\n if( samplerCount == 1 ) { \n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[1], tileOffsetArr[1], layerOpacityArr[1]);\n if( samplerCount == 2 ) {\n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[2], tileOffsetArr[2], layerOpacityArr[2]);\n if( samplerCount == 3 ) {\n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[3], tileOffsetArr[3], layerOpacityArr[3]);\n if( samplerCount == 4 ) {\n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[4], tileOffsetArr[4], layerOpacityArr[4]);\n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n }`})}class Vo{constructor(e,t={}){this.handler=e,this._fbo=null,this._width=t.width||e.canvas.width,this._height=t.height||e.canvas.height,this._depthComponent=null!=t.depthComponent?t.depthComponent:"DEPTH_COMPONENT16",this._useDepth=null==t.useDepth||t.useDepth,this._active=!1,this._size=t.size||1,this._depthRenderbuffer=null,this._filter=t.filter||"NEAREST"}get width(){return this._width}get height(){return this._height}setSize(e,t,i=!1){this._width=e,this._height=t,this._active&&this.handler.gl.viewport(0,0,this._width,this._height),(this._useDepth||i)&&(this.destroy(),this.init())}init(){}destroy(){}isComplete(){let e=this.handler.gl;return e.checkFramebufferStatus(e.FRAMEBUFFER)===e.FRAMEBUFFER_COMPLETE}checkStatus(){let e=this.handler.gl;return e.checkFramebufferStatus(e.FRAMEBUFFER)}activate(){let e=this.handler.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindFramebuffer(e.FRAMEBUFFER,this._fbo),e.viewport(0,0,this._width,this._height),this._active=!0;let t=this.handler.framebufferStack.current().data;return t&&(t._active=!1),this.handler.framebufferStack.push(this),this}deactivate(){let e=this.handler,t=e.gl;t.bindFramebuffer(t.FRAMEBUFFER,null),this._active=!1;let i=this.handler.framebufferStack.popPrev();i?(t.bindFramebuffer(t.FRAMEBUFFER,i._fbo),t.viewport(0,0,i._width,i._height)):t.viewport(0,0,e.canvas.width,e.canvas.height)}}class Uo{constructor(e=256,t=256){this._canvas=document.createElement("canvas"),this._canvas.width=e,this._canvas.height=t,this._context=this._canvas.getContext("2d",{willReadFrequently:!0})}getCanvas(){return this._canvas}getContext(){return this._context}fillEmpty(){let e=this._context.getImageData(0,0,this._canvas.width,this._canvas.height),t=e.data;for(let e=0,i=t.length;e<i;e+=4)t[e]=t[e+1]=t[e+2]=t[e+3]=0;this._context.putImageData(e,0,0)}fill(e){this._context.fillStyle=e,this._context.fill()}getData(){return this._context.getImageData(0,0,this._canvas.width,this._canvas.height).data}fillColor(e){this._context.fillStyle=e,this._context.fillRect(0,0,this._canvas.width,this._canvas.height)}setData(e){let t=this._context.createImageData(this._canvas.width,this._canvas.height);t.data.set(e),this._context.putImageData(t,0,0)}resize(e,t){this._canvas.width=e,this._canvas.height=t,this._context=this._canvas.getContext("2d")}drawImage(e,t,i,s,n){this._context.drawImage(e,t||0,i||0,s||e.width,n||e.height)}getImage(){let e=new Image;return e.width=this.getWidth(),e.height=this.getHeight(),e.src=this._canvas.toDataURL("image/png"),e}getTextWidth(e){let t=this._context.measureText(e);return Math.round(t.width)}drawText(e,t=0,i=14,s="normal 14px Verdana",n="black"){this._context.fillStyle=n,this._context.font=s,this._context.fillText(e,t,i)}getWidth(){return this._canvas.width}getHeight(){return this._canvas.height}load(e,t){let i=new Image,s=this;i.onload=function(){s.resize(i.width,i.height),s._context.drawImage(i,0,0,i.width,i.height),t&&t(i)},i.src=e}openImage(){let e=this.getImage(),t="<!DOCTYPE html>";t+="<html>",t+="<head><title>Print</title></head>",t+="<body>",t+='<img src="'+e.src+'">',t+="</body>",t+="</html>";let i=window.open("","","width="+e.width+"px ,height="+e.height+"px");i&&(i.document.open(),i.document.write(t),i.document.close(),i.focus())}destroy(){this._canvas.width=1,this._canvas.height=1,this._canvas=null,this._context=null}}const Go={UNSIGNED_BYTE:Uint8Array,FLOAT:Float32Array};class Yo extends Vo{constructor(e,t={}){super(e,t),this.readPixelBuffersAsync=()=>{const e=this.handler.gl;if(this._skipFrame)return;this._skipFrame=!0;let t=this.width,i=this.height,s=this.pixelBuffers;this.activate();for(let n=0;n<s.length;n++){let r=s[n];e.bindBuffer(e.PIXEL_PACK_BUFFER,r.buffer),e.bufferData(e.PIXEL_PACK_BUFFER,r.data.byteLength,e.STREAM_READ),e.readBuffer(r.glAttachment),e.readPixels(0,0,t,i,e.RGBA,r.glType,0),e.bindBuffer(e.PIXEL_PACK_BUFFER,null)}this.deactivate();const n=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0);e.flush(),function(e,t,i){return new Promise(((s,n)=>{!function r(){const o=e.clientWaitSync(t,i,0);o==e.WAIT_FAILED?n():o==e.TIMEOUT_EXPIRED?requestAnimationFrame(r):s()}()}))}(e,n,0).then((()=>{this._skipFrame=!1,e.deleteSync(n);for(let t=0;t<s.length;t++){let i=s[t];i.data&&(e.bindBuffer(e.PIXEL_PACK_BUFFER,i.buffer),e.getBufferSubData(e.PIXEL_PACK_BUFFER,0,i.data))}e.bindBuffer(e.PIXEL_PACK_BUFFER,null)}))},this._targets=Yo.createTargets(t.targets),this._size=this._targets.length,this._renderbufferTarget=null!=t.renderbufferTarget?t.renderbufferTarget:"DEPTH_ATTACHMENT",this.textures=t.textures||new Array(this._size),this.pixelBuffers=[],this._skipFrame=!1}static createTargets(e){let t=0,i=0;return e?e.map((e=>{let s=e.attachment||"COLOR_ATTACHMENT";"COLOR_ATTACHMENT"===s&&(s="COLOR_ATTACHMENT"+t++);let n=e.type||"UNSIGNED_BYTE";return{internalFormat:e.internalFormat||"RGBA",format:e.format||"RGBA",type:n,attachment:s,filter:e.filter||"NEAREST",pixelBufferIndex:e.readAsync?i++:-1,TypeArrayConstructor:Go[n]}})):[{internalFormat:"RGBA",format:"RGBA",type:"UNSIGNED_BYTE",attachment:"COLOR_ATTACHMENT0",filter:"NEAREST",pixelBufferIndex:-1,TypeArrayConstructor:Go.UNSIGNED_BYTE}]}destroy(){let e=this.handler.gl;if(e){for(let t=0;t<this.textures.length;t++)e.deleteTexture(this.textures[t]);this.textures=new Array(this._size);for(let t=0;t<this.pixelBuffers.length;t++)this.pixelBuffers[t].data=null,e.deleteBuffer(this.pixelBuffers[t].buffer);this.pixelBuffers=[],e.deleteFramebuffer(this._fbo),e.deleteRenderbuffer(this._depthRenderbuffer),this._depthRenderbuffer=null,this._fbo=null,this._active=!1}}init(){let e=this.handler.gl;if(!e)return;this._fbo=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this._fbo);let t=[];for(let i=0;i<this._targets.length;i++){let s=this._targets[i],n=this.textures[i]||this.handler.createEmptyTexture2DExt(this._width,this._height,s.filter,s.internalFormat,s.format,s.type),r=e[s.attachment];n&&(this.bindOutputTexture(n,r),this.textures[i]=n),"DEPTH_ATTACHMENT"!==s.attachment&&t.push(r),-1!==s.pixelBufferIndex&&this._createPixelBuffer(s)}e.drawBuffers&&e.drawBuffers(t),this._useDepth&&(this._depthRenderbuffer=e.createRenderbuffer(),e.bindRenderbuffer(e.RENDERBUFFER,this._depthRenderbuffer),e.renderbufferStorage(e.RENDERBUFFER,e[this._depthComponent],this._width,this._height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e[this._renderbufferTarget],e.RENDERBUFFER,this._depthRenderbuffer),e.bindRenderbuffer(e.RENDERBUFFER,null)),e.bindFramebuffer(e.FRAMEBUFFER,null)}getPixelBufferData(e){let t=this._targets[e].pixelBufferIndex;return-1!==t?this.pixelBuffers[t].data:null}_createPixelBuffer(e){let t=this.handler.gl,i=e.pixelBufferIndex,s=this.pixelBuffers[i];s||(s=this.pixelBuffers[i]={buffer:null,data:null,glType:-1,glAttachment:-1});let n=this.width*this.height*4;s.data=null,s.data=new e.TypeArrayConstructor(n),s.buffer=t.createBuffer(),t.bindBuffer(t.PIXEL_PACK_BUFFER,s.buffer),t.bufferData(t.PIXEL_PACK_BUFFER,n,t.STREAM_READ),t.bindBuffer(t.PIXEL_PACK_BUFFER,null),s.glType=t[e.type],s.glAttachment=t[e.attachment]}bindOutputTexture(e,t){let i=this.handler.gl;i.bindTexture(i.TEXTURE_2D,e),i.framebufferTexture2D(i.FRAMEBUFFER,t||i.COLOR_ATTACHMENT0,i.TEXTURE_2D,e,0),i.bindTexture(i.TEXTURE_2D,null)}readPixels(e,t,i,s=0,n=1,r=1){let o=this.handler.gl;o.bindFramebuffer(o.FRAMEBUFFER,this._fbo),o.readBuffer&&o.readBuffer(o.COLOR_ATTACHMENT0+s||0),o.readPixels(t*this._width,i*this._height,n,r,o.RGBA,o[this._targets[s].type],e),o.bindFramebuffer(o.FRAMEBUFFER,null)}readAllPixels(e,t=0){let i=this.handler.gl;i.bindFramebuffer(i.FRAMEBUFFER,this._fbo),i.readBuffer&&i.readBuffer(i.COLOR_ATTACHMENT0+t),i.readPixels(0,0,this._width,this._height,i.RGBA,i[this._targets[t].type],e),i.bindFramebuffer(i.FRAMEBUFFER,null)}getImage(){let e=new Uint8Array(4*this._width*this._height);this.readAllPixels(e);let t=new Uo(this._width,this._height);return t.setData(e),t.getImage()}}class jo extends Dt{constructor(e={}){super({name:"Atmosphere",...e}),this._transmittanceBuffer=null,this._scatteringBuffer=null,this.opacity=1,this._parameters={ATMOS_HEIGHT:e.height||1e5,RAYLEIGH_SCALE:e.rayleighScale||.08,MIE_SCALE:e.mieScale||.012,GROUND_ALBEDO:e.groundAlbedo||.05,BOTTOM_RADIUS:e.bottomRadius||6356752.314245179,rayleighScatteringCoefficient:e.rayleighScatteringCoefficient||[5.802,13.558,33.1],mieScatteringCoefficient:e.mieScatteringCoefficient||3.996,mieExtinctionCoefficient:e.mieExtinctionCoefficient||4.44,ozoneAbsorptionCoefficient:e.ozoneAbsorptionCoefficient||[.65,1.881,.085],SUN_ANGULAR_RADIUS:e.sunAngularRadius||.004685,SUN_INTENSITY:e.sunIntensity||1,ozoneDensityHeight:e.ozoneDensityHeight||25e3,ozoneDensityWide:e.ozoneDensityWide||15e3}}setParameters(e){this._parameters=JSON.parse(JSON.stringify(e)),this.initLookupTexturesShaders(),this.drawLookupTextures(),this.removeLookupTexturesShaders(),this.initPlanetAtmosphereShader()}get parameters(){return JSON.parse(JSON.stringify(this._parameters))}initPlanetAtmosphereShader(){this.planet?.initAtmosphereShader(this._parameters)}oninit(){this.renderer&&(this._initLookupTextures(),this.initLookupTexturesShaders(),this.drawLookupTextures(),this.removeLookupTexturesShaders(),this.initBackgroundShader(),this.activate())}initLookupTexturesShaders(){var e;this.renderer&&(this.renderer.handler.addProgram((e=this._parameters,new Ni("transmittance",{uniforms:{iResolution:"vec2"},attributes:{a_position:"vec2"},vertexShader:"\n attribute vec2 a_position;\n \n void main(void) \n {\n gl_Position = vec4(a_position, 0.0, 1.0);\n }",fragmentShader:`\n precision highp float;\n \n ${zo(e)}\n \n uniform vec2 iResolution;\n \n void main(void) \n {\n vec2 uv = gl_FragCoord.xy / iResolution.xy;\n float height = uv.y * ATMOS_HEIGHT;\n float angle = uv.x * 2.0 - 1.0;\n gl_FragColor = vec4(transmittance(height, angle), 1.0);\n }`})),!0),this.renderer.handler.addProgram(function(e){return new Ni("scattering",{uniforms:{iResolution:"vec2",transmittanceTexture:"sampler2d"},attributes:{a_position:"vec2"},vertexShader:" \n attribute vec2 a_position; \n \n void main(void) \n {\n gl_Position = vec4(a_position, 0.0, 1.0);\n }",fragmentShader:` \n precision highp float;\n \n uniform sampler2D transmittanceTexture;\n uniform vec2 iResolution;\n \n ${zo(e)}\n \n vec3 transmittanceFromTexture(float height, float angle) \n {\n float u = (angle + 1.0) * 0.5;\n float v = height / ATMOS_HEIGHT;\n return texture2D(transmittanceTexture, vec2(u, v)).xyz;\n }\n \n void main(void) \n {\n vec2 uv = gl_FragCoord.xy / iResolution.xy;\n \n float height = uv.y * ATMOS_HEIGHT;\n float angle = uv.x * 2.0 - 1.0;\n \n vec3 rayOrigin = vec3(0.0, BOTTOM_RADIUS + height, 0.0);\n vec3 up = rayOrigin / length(rayOrigin);\n vec3 lightDirection = vec3(sqrt(1.0 - angle * angle), angle, 0.0);\n \n const float isotropicPhase = 1.0 / (4.0 * PI);\n \n vec3 light = vec3(0.0);\n vec3 lightTransferFactor = vec3(0.0);\n \n for (int i = 0; i < SQRT_SAMPLE_COUNT; i++)\n {\n for (int j = 0; j < SQRT_SAMPLE_COUNT; j++)\n {\n float u = ((0.5 + float(i)) / float(SQRT_SAMPLE_COUNT)) * 2.0 - 1.0;\n float v = (0.5 + float(j)) / float(SQRT_SAMPLE_COUNT);\n float r = sqrt(1.0 - u * u);\n float theta = 2.0 * PI * v;\n vec3 rayDirection = vec3(cos(theta) * r, sin(theta) * r, u);\n \n float rayAngle = dot(up, rayDirection);\n bool cameraBelow = rayAngle < 0.0;\n \n vec3 transmittanceFromCameraToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n \n float offset = 0.0;\n float distanceToSpace = 0.0;\n \n intersectSphere(rayOrigin, rayDirection, TOP_RADIUS, offset, distanceToSpace);\n \n float distanceToGround = 0.0;\n bool hitGround = intersectSphere(rayOrigin, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0; \n float segmentLength = (hitGround ? distanceToGround : distanceToSpace) / float(SAMPLE_COUNT);\n float t = segmentLength * 0.5;\n \n vec3 transmittanceCamera;\n vec3 transmittanceLight;\n \n for (int k = 0; k < SAMPLE_COUNT; k++) \n {\n vec3 position = rayOrigin + t * rayDirection;\n float height = length(position) - BOTTOM_RADIUS;\n vec3 up = position / length(position);\n float rayAngle = dot(up, rayDirection);\n float lightAngle = dot(up, lightDirection);\n \n float distanceToGround;\n float shadow = intersectSphere(position, lightDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround >= 0.0 ? 0.0 : 1.0;\n vec3 transmittanceToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n \n transmittanceCamera = cameraBelow ? (transmittanceToSpace / transmittanceFromCameraToSpace) : (transmittanceFromCameraToSpace / transmittanceToSpace);\n transmittanceLight = transmittanceFromTexture(height, lightAngle);\n \n vec2 opticalDensity = exp(-height / rayleighMieHeights); \n vec3 scatteredLight = transmittanceLight * (rayleighScatteringCoefficient * opticalDensity.x + mieScatteringCoefficient * opticalDensity.y) * isotropicPhase;\n \n light += shadow * transmittanceCamera * scatteredLight * segmentLength;\n lightTransferFactor += transmittanceCamera * (rayleighScatteringCoefficient * opticalDensity.x + mieScatteringCoefficient * opticalDensity.y) * segmentLength;\n \n t += segmentLength;\n }\n \n if (hitGround) \n {\n vec3 hitPoint = rayOrigin + rayDirection * distanceToGround;\n vec3 normal = normalize(hitPoint);\n float diffuseAngle = max(dot(normal, lightDirection), 0.0); \n light += transmittanceCamera * transmittanceLight * GROUND_ALBEDO * diffuseAngle;\n }\n }\n }\n \n light /= float(SAMPLE_COUNT);\n lightTransferFactor /= float(SAMPLE_COUNT);\n vec3 color = light / (1.0 - lightTransferFactor); \n gl_FragColor = vec4(color, 1.0);\n }`})}(this._parameters),!0))}initBackgroundShader(){var e;this.renderer&&this.renderer.handler.addProgram((e=this._parameters,new Ni("atmosphereBackground",{uniforms:{iResolution:"vec2",fov:"float",camPos:"vec3",viewMatrix:"mat4",transmittanceTexture:"sampler2D",scatteringTexture:"sampler2D",sunPos:"vec3",opacity:"float"},attributes:{corners:"vec3"},vertexShader:" \n attribute vec2 corners;\n \n void main(void) {\n gl_Position = vec4(corners, 0.0, 1.0);\n }",fragmentShader:` \n precision lowp float;\n \n ${zo(e)}\n \n uniform mat4 viewMatrix;\n uniform vec3 sunPos;\n uniform vec3 camPos; \n uniform vec2 iResolution;\n uniform float fov;\n uniform float opacity;\n \n uniform sampler2D transmittanceTexture;\n uniform sampler2D scatteringTexture;\n \n vec3 transmittanceFromTexture(float height, float angle) \n {\n float u = (angle + 1.0) * 0.5;\n float v = height / ATMOS_HEIGHT;\n return texture2D(transmittanceTexture, vec2(u, v)).xyz;\n }\n \n vec3 multipleScatteringContributionFromTexture(float height, float angle) \n {\n float u = (angle + 1.0) * 0.5;\n float v = height / ATMOS_HEIGHT;\n return texture2D(scatteringTexture, vec2(u, v)).xyz; \n }\n\n bool intersectEllipsoidToSphere(in vec3 ro, in vec3 rd, in vec3 ellRadii, in float sphereRadius, out float t1, out float t2) \n {\n float offset = 0.0,\n distanceToSpace = 0.0;\n \n if(intersectEllipsoid(ro, rd, ellRadii, offset, distanceToSpace)){\n vec3 hitEll = ro + rd * offset;\n vec3 nEll = normalEllipsoid(hitEll, ellRadii);\n float t = 0.0;\n bool intersectsSphere = intersectSphere(hitEll, nEll, sphereRadius, t);\n vec3 hitSphere = hitEll + nEll * t;\n t1 = length(hitSphere - ro);\n \n hitEll = ro + rd * distanceToSpace;\n nEll = normalEllipsoid(hitEll, ellRadii);\n t = 0.0;\n intersectsSphere = intersectSphere(hitEll, nEll, sphereRadius, t);\n hitSphere = hitEll + nEll * t;\n t2 = length(hitSphere - ro);\n \n return true; \n }\n return false; \n }\n \n mat4 transpose(in mat4 m) \n {\n vec4 i0 = m[0];\n vec4 i1 = m[1];\n vec4 i2 = m[2];\n vec4 i3 = m[3];\n \n mat4 outMatrix = mat4(\n vec4(i0.x, i1.x, i2.x, i3.x),\n vec4(i0.y, i1.y, i2.y, i3.y),\n vec4(i0.z, i1.z, i2.z, i3.z),\n vec4(i0.w, i1.w, i2.w, i3.w)\n );\n \n return outMatrix;\n }\n \n void mainImage(out vec4 fragColor) \n { \n vec3 cameraPosition = camPos;\n \n vec3 lightDirection = normalize(sunPos); \n \n vec2 uv = (2.0 * gl_FragCoord.xy - iResolution.xy) / iResolution.y;\n float fieldOfView = fov;\n float z = 1.0 / tan(fieldOfView * 0.5 * PI / 180.0);\n vec3 rayDirection = normalize(vec3(uv, -z));\n vec4 rd = transpose(viewMatrix) * vec4(rayDirection, 1.0);\n rayDirection = rd.xyz; \n \n vec3 light = vec3(0.0);\n vec3 transmittanceFromCameraToSpace = vec3(1.0);\n float offset = 0.0;\n float distanceToSpace = 0.0;\n \n rayDirection = normalize(rayDirection * SPHERE_TO_ELLIPSOID_SCALE);\n cameraPosition *= SPHERE_TO_ELLIPSOID_SCALE;\n lightDirection = normalize(lightDirection * SPHERE_TO_ELLIPSOID_SCALE);\n \n if(length(cameraPosition) < BOTTOM_RADIUS + 100.0){\n cameraPosition = normalize(cameraPosition) * (BOTTOM_RADIUS + 100.0); \n }\n \n if (intersectSphere(cameraPosition, rayDirection, TOP_RADIUS, offset, distanceToSpace)) \n { \n vec3 rayOrigin = cameraPosition;\n \n // above atmosphere \n if (offset > 0.0) {\n // intersection of camera ray with atmosphere\n rayOrigin = cameraPosition + rayDirection * offset;\n } \n \n float height = length(rayOrigin) - BOTTOM_RADIUS;\n float rayAngle = dot(rayOrigin, rayDirection) / length(rayOrigin);\n bool cameraBelow = rayAngle < 0.0;\n \n transmittanceFromCameraToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n \n float phaseAngle = dot(lightDirection, rayDirection);\n float rayleighPhase = rayleighPhase(phaseAngle);\n float miePhase = miePhase(phaseAngle);\n \n float distanceToGround = 0.0;\n \n bool hitGround = intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0;\n \n if(intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS - 100000.0, distanceToGround) && hitGround)\n {\n discard;\n }\n \n float segmentLength = ((hitGround ? distanceToGround : distanceToSpace) - max(offset, 0.0)) / float(SAMPLE_COUNT);\n \n float t = segmentLength * 0.5;\n \n vec3 transmittanceCamera; \n vec3 transmittanceLight; \n \n for (int i = 0; i < SAMPLE_COUNT; i++) \n {\n vec3 position = rayOrigin + t * rayDirection;\n float height = length(position) - BOTTOM_RADIUS; \n vec3 up = position / length(position);\n float rayAngle = dot(up, rayDirection);\n float lightAngle = dot(up, lightDirection);\n vec3 transmittanceToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n transmittanceCamera = cameraBelow ? (transmittanceToSpace / transmittanceFromCameraToSpace) : (transmittanceFromCameraToSpace / transmittanceToSpace);\n transmittanceLight = transmittanceFromTexture(height, lightAngle);\n vec2 opticalDensity = exp(-height / rayleighMieHeights);\n vec3 scatteredLight = transmittanceLight * (rayleighScatteringCoefficient * opticalDensity.x * rayleighPhase + mieScatteringCoefficient * opticalDensity.y * miePhase);\n scatteredLight += multipleScatteringContributionFromTexture(height, lightAngle) * (rayleighScatteringCoefficient * opticalDensity.x + mieScatteringCoefficient * opticalDensity.y); \n light += transmittanceCamera * scatteredLight * segmentLength;\n t += segmentLength;\n }\n \n light *= SUN_INTENSITY;\n \n if (hitGround) \n {\n vec3 hitPoint = cameraPosition + rayDirection * distanceToGround;\n vec3 up = hitPoint / length(hitPoint);\n float diffuseAngle = max(dot(up, lightDirection), 0.0);\n float lightAngle = dot(up, lightDirection);\n light += transmittanceCamera * GROUND_ALBEDO * multipleScatteringContributionFromTexture(height, lightAngle) * SUN_INTENSITY;\n light += transmittanceCamera * transmittanceLight * GROUND_ALBEDO * diffuseAngle * SUN_INTENSITY;\n }\n }\n \n // sun disk\n // float distanceToGround;\n // bool hitGround = intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0;\n // if (!hitGround) {\n // float angle = dot(rayDirection, lightDirection);\n // if (angle > cos(SUN_ANGULAR_RADIUS)) {\n // light = SUN_INTENSITY * transmittanceFromCameraToSpace;\n // }\n // }\n \n float distanceToGround = 0.0;\n bool hitGround = intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0;\n if(!hitGround)\n {\n vec3 sunLum = sunWithBloom(rayDirection, lightDirection) * vec3(1.0,1.0,0.8);\n // limit the bloom effect\n sunLum = smoothstep(0.002, 1.0, sunLum);\n light += sunLum * SUN_INTENSITY * transmittanceFromCameraToSpace;\n }\n \n fragColor = vec4(pow(light * 8.0, vec3(1.0 / 2.2)), clamp(opacity, 0.0, 1.0)); \n }\n \n void main(void) \n { \n mainImage(gl_FragColor); \n }`})),!0)}removeBackgroundShader(){this.renderer&&this.renderer.handler.removeProgram("atmosphereBackground")}removeLookupTexturesShaders(){if(this.renderer){let e=this.renderer.handler;this._scatteringBuffer?.isComplete()&&e.removeProgram("scattering"),this._transmittanceBuffer?.isComplete()&&e.removeProgram("transmittance")}}onactivate(){super.onactivate(),this.planet&&this.planet.events.on("draw",this._drawBackground,this)}ondeactivate(){super.ondeactivate(),this.planet&&this.planet.events.off("draw",this._drawBackground)}_initLookupTextures(){this._transmittanceBuffer=new Yo(this.renderer.handler,{width:1024,height:1024,useDepth:!1,targets:[{filter:"LINEAR",type:"FLOAT",internalFormat:"RGBA16F"}]}),this._transmittanceBuffer.init(),this._scatteringBuffer=new Yo(this.renderer.handler,{width:1024,height:1024,useDepth:!1,targets:[{filter:"LINEAR",type:"FLOAT",internalFormat:"RGBA16F"}]}),this._scatteringBuffer.init()}_renderLookupTextures(){if(!this.renderer)return;let e=this.renderer.screenFramePositionBuffer,t=this.renderer.handler,i=t.gl;if(this._transmittanceBuffer){this._transmittanceBuffer.activate();let s=t.programs.transmittance,n=s._program.attributes,r=s._program.uniforms;s.activate(),i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),i.uniform2fv(r.iResolution,[this._transmittanceBuffer.width,this._transmittanceBuffer.height]),i.bindBuffer(i.ARRAY_BUFFER,e),i.vertexAttribPointer(n.a_position,e.itemSize,i.FLOAT,!1,0,0),i.drawArrays(i.TRIANGLE_STRIP,0,e.numItems),this._transmittanceBuffer.deactivate()}if(this._scatteringBuffer&&this._transmittanceBuffer){this._scatteringBuffer.activate();let s=t.programs.scattering,n=s._program.attributes,r=s._program.uniforms;s.activate(),i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),i.uniform2fv(r.iResolution,[this._scatteringBuffer.width,this._scatteringBuffer.height]),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this._transmittanceBuffer.textures[0]),i.uniform1i(r.transmittanceTexture,0),i.bindBuffer(i.ARRAY_BUFFER,e),i.vertexAttribPointer(n.a_position,e.itemSize,i.FLOAT,!1,0,0),i.drawArrays(i.TRIANGLE_STRIP,0,e.numItems),this._scatteringBuffer.deactivate()}}drawLookupTextures(){this._renderLookupTextures()}_drawBackground(){let e=this.renderer.handler,t=e.programs.atmosphereBackground,i=t._program,s=i.uniforms,n=e.gl,r=this.renderer,o=this.planet.camera;n.disable(n.DEPTH_TEST),t.activate(),n.bindBuffer(n.ARRAY_BUFFER,r.screenFramePositionBuffer),n.vertexAttribPointer(i.attributes.corners,2,n.FLOAT,!1,0,0),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,this._transmittanceBuffer.textures[0]),n.uniform1i(s.transmittanceTexture,0),n.activeTexture(n.TEXTURE1),n.bindTexture(n.TEXTURE_2D,this._scatteringBuffer.textures[0]),n.uniform1i(s.scatteringTexture,1),n.uniformMatrix4fv(s.viewMatrix,!1,o.getViewMatrix());let a=this.planet.sunPos;n.uniform3fv(s.sunPos,[a.x,a.y,a.z]),n.uniform3fv(s.camPos,[o.eye.x,o.eye.y,o.eye.z]),n.uniform2fv(s.iResolution,[r.sceneFramebuffer.width,r.sceneFramebuffer.height]),n.uniform1f(s.fov,o.getViewAngle()),n.uniform1f(s.opacity,this.opacity),n.drawArrays(n.TRIANGLE_STRIP,0,4),n.enable(n.DEPTH_TEST)}}const Wo="degrees",qo="m";let $o=0;class Xo{constructor(e){this.id=$o++,this.code=e.code,this.units=e.units}equal(e){return e.id===this.id}}const Zo=new Xo({code:"epsg:3857",units:qo});class Ko{constructor(e){this.segment=e,this.layers=[],this.tileOffsetArr=new Float32Array(e.planet.SLICE_SIZE_4),this.layerOpacityArr=new Float32Array(e.planet.SLICE_SIZE)}clear(){this.layers=null,this.tileOffsetArr=null,this.layerOpacityArr=null}append(e,t){let i=this.layers.length;this.layers.push(e),this.layerOpacityArr[i]=e.screenOpacity;let s=4*i,n=e.applyMaterial(t);this.tileOffsetArr[s]=n[0],this.tileOffsetArr[s+1]=n[1],this.tileOffsetArr[s+2]=n[2],this.tileOffsetArr[s+3]=n[3]}}function Qo(e,t,i){return Math.floor(Math.abs(i-e)/t)}function Jo(e,t,i,s){let n=1/(1<<i),r=s.getWidth()*n,o=s.getHeight()*n,a=s.southWest.lon+e*r,l=s.northEast.lat-t*o;return new te(new I(a,l-o),new I(a+r,l))}const ea=20,ta=300;let ia=new oe,sa=new oe,na=new oe,ra=new oe,oa=new oe,aa=new oe,la=new ui,ha=new ui;const ca=new Array(4);ca[0]=0,ca[1]=1,ca[2]=1,ca[3]=0;const da=new Array(4);da[0]=!1,da[1]=!0,da[2]=!1,da[3]=!0;class _a{constructor(e,t,i,s){this.isPole=!1,this._tileGroup=0,this._projection=Zo,this.node=e,this.planet=t,this.handler=t.renderer.handler,this.bsphere=new Pt,this._plainRadius=0,this.bbox=new At,this._sw=new oe,this._nw=new oe,this._se=new oe,this._ne=new oe,this.centerNormal=new oe,this._extent=this._extentMerc=s,this._extentLonLat=new te,this.gridSize=t.terrain.gridSizeByZoom[i],this.fileGridSize=0,this.tileZoom=i,this.powTileZoom=1<<i,this.tileX=0,this.tileXE=0,this.tileXW=0,this.tileYN=0,this.tileYS=0,this.tileY=0,this.tileIndex="",this.elevationData=null,this._assignTileIndexes(),this.materials=[],this.plainReady=!1,this.initialized=!1,this.normalMapReady=!1,this.terrainReady=!1,this.terrainIsLoading=!1,this.terrainExists=!1,this.passReady=!1,this.plainVertices=null,this.plainVerticesHigh=null,this.plainVerticesLow=null,this.plainNormals=null,this.terrainVertices=null,this.terrainVerticesHigh=null,this.terrainVerticesLow=null,this.noDataVertices=null,this.tempVertices=null,this.tempVerticesHigh=null,this.tempVerticesLow=null,this.normalMapTexture=null,this.normalMapTextureBias=new Float32Array(3),this.normalMapVertices=null,this.normalMapVerticesHigh=null,this.normalMapVerticesLow=null,this.normalMapNormals=null,this.vertexNormalBuffer=null,this.vertexPositionBuffer=null,this.vertexPositionBufferHigh=null,this.vertexPositionBufferLow=null,this.vertexTextureCoordBuffer=null,this._globalTextureCoordinates=new Float32Array(4),this._inTheQueue=!1,this._appliedNeighborsZoom=[0,0,0,0],this._slices=[],this._indexBuffer=null,this.readyToEngage=!1,this.plainProcessing=!1,this.normalMapTexturePtr=null,this._transitionOpacity=1,this._transitionTimestamp=0}checkZoom(){return this.tileZoom<this.planet.terrain._maxNodeZoom}getEntityTerrainPoint(e,t){return this.getTerrainPoint(e._cartesian,this.getInsideLonLat(e),t)}getInsideLonLat(e){return e._lonLatMerc}isEntityInside(e){return this._extentLonLat.isInside(e._lonLat)}getTerrainPoint(e,t,i){let s=this.tempVertices;if(s&&s.length){let n=this.planet.ellipsoid.getSurfaceNormal3v(e);la.set(e,n.negateTo());let r=this._extent.northEast,o=this._extent.southWest,a=Math.sqrt(s.length/3)-1,l=r.lon,h=r.lat,c=o.lon,d=o.lat,_=(l-c)/a,u=(h-d)/a,g=t.lon-c,f=t.lat-d,p=Math.floor(g/_),m=Math.floor(a-f/u),v=3*((a+1)*m+p),y=3*((a+1)*(m+1)+p);na.set(s[v],s[v+1],s[v+2]),ra.set(s[v+3],s[v+4],s[v+5]),oa.set(s[y],s[y+1],s[y+2]);let x=la.hitTriangleRes(na,ra,oa,i);if(x===ui.INSIDE)return e.distance(i);if(x===ui.AWAY){if(ha.set(e,n),ha.hitTriangleRes(na,ra,oa,i)===ui.INSIDE)return-e.distance(i)}if(aa.set(s[y+3],s[y+4],s[y+5]),x=la.hitTriangleRes(ra,aa,oa,i),x===ui.INSIDE)return e.distance(i);if(x===ui.AWAY){if(ha.set(e,n),ha.hitTriangleRes(ra,aa,oa,i)===ui.INSIDE)return-e.distance(i)}return x===ui.AWAY?-e.distance(i):e.distance(i)}return e.distance(this.planet.ellipsoid.hitRay(la.origin,la.direction))}projectNative(e){return e.forwardMercator()}loadTerrain(e=!1){this.tileZoom<this.planet.terrain.minZoom||this.planet.terrain.isEmpty?(this.terrainIsLoading=!0,this.elevationsNotExists(),this._inTheQueue||this.planet._normalMapCreator.queue(this)):this.tileZoom>this.planet.terrain.maxZoom?this.elevationsNotExists():this.terrainIsLoading||this.terrainReady||this.planet.terrain.loadTerrain(this,e)}elevationsExists(e){if(this.plainReady&&this.terrainIsLoading){let t=new Float32Array(e.length);t.set(e),this.elevationData=new Float32Array(e.length),this.elevationData.set(e),this.planet._terrainWorker.make({segment:this,elevations:t}),this.plainVerticesHigh=null,this.plainVerticesLow=null,this.normalMapVerticesHigh=null,this.normalMapVerticesLow=null,this.planet.terrain.equalizeVertices||(this.tempVerticesHigh=null,this.tempVerticesLow=null)}}elevationsNotExists(){if(this.planet&&this.tileZoom<=this.planet.terrain.maxNativeZoom){if(this.plainReady&&this.terrainIsLoading){this.terrainIsLoading=!1;let e=this.node;e.appliedTerrainNodeId=this.node.nodeId,e.equalizedSideWithNodeId[0]=e.equalizedSideWithNodeId[1]=e.equalizedSideWithNodeId[2]=e.equalizedSideWithNodeId[3]=e.appliedTerrainNodeId,this.planet.lightEnabled&&!this._inTheQueue&&this.planet._normalMapCreator.queue(this),this.readyToEngage=!0}this.terrainVertices=this.plainVertices,this.terrainVerticesHigh=this.plainVerticesHigh,this.terrainVerticesLow=this.plainVerticesLow,this.tempVertices=this.terrainVertices,this.tempVerticesHigh=this.terrainVerticesHigh,this.tempVerticesLow=this.terrainVerticesLow,this.noDataVertices=null,this.fileGridSize=Math.sqrt(this.terrainVertices.length/3)-1,this.gridSize=this.fileGridSize,this.terrainReady=!0,this.terrainExists=!1}else if(this.plainReady&&this.terrainIsLoading){this.terrainIsLoading=!1;let e=this.node;e.appliedTerrainNodeId=this.node.nodeId,e.equalizedSideWithNodeId[0]=e.equalizedSideWithNodeId[1]=e.equalizedSideWithNodeId[2]=e.equalizedSideWithNodeId[3]=e.appliedTerrainNodeId,this.readyToEngage=!0,this.terrainReady=!0,this.passReady=!0,this.terrainExists=!1}}_checkEqualization(e,t){return t&&t.segment&&this.tileZoom>=t.segment.tileZoom&&this.node.equalizedSideWithNodeId[e]!==t.equalizedSideWithNodeId[Gt[e]]}equalize(){if(this.tileZoom<2||this.gridSize<2)return;this.readyToEngage=!0;let e=this.node.neighbors,t=this.tempVertices,i=this.tempVerticesHigh,s=this.tempVerticesLow,n=this.gridSize,r=n+1,o=e[0][0];if(this._checkEqualization(0,o)){this.node.equalizedSideWithNodeId[0]=o.equalizedSideWithNodeId[2],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(o,0),a=o.segment.tempVertices,l=o.segment.tempVerticesHigh,h=o.segment.tempVerticesLow,c=o.segment.gridSize,d=c+1,_=1/(1<<this.tileZoom-o.segment.tileZoom),u=Math.max(n/(c*_),1),g=Math.max(c*_/n,1);for(let n=0,o=e*c;n<r;n+=u,o+=g){const e=3*n,r=3*(d*c+o);t[e]=a[r],t[e+1]=a[r+1],t[e+2]=a[r+2],i[e]=l[r],i[e+1]=l[r+1],i[e+2]=l[r+2],s[e]=h[r],s[e+1]=h[r+1],s[e+2]=h[r+2]}}if(o=e[1][0],this._checkEqualization(1,o)){this.node.equalizedSideWithNodeId[1]=o.equalizedSideWithNodeId[3],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(o,1),a=o.segment.tempVertices,l=o.segment.tempVerticesHigh,h=o.segment.tempVerticesLow,c=o.segment.gridSize,d=c+1,_=1/(1<<this.tileZoom-o.segment.tileZoom),u=Math.max(n/(c*_),1),g=Math.max(c*_/n,1);for(let o=0,_=e*c;o<r;o+=u,_+=g){const e=3*(r*o+n),c=d*_*3;t[e]=a[c],t[e+1]=a[c+1],t[e+2]=a[c+2],i[e]=l[c],i[e+1]=l[c+1],i[e+2]=l[c+2],s[e]=h[c],s[e+1]=h[c+1],s[e+2]=h[c+2]}}if(o=e[2][0],this._checkEqualization(2,o)){this.node.equalizedSideWithNodeId[2]=o.equalizedSideWithNodeId[0],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(o,2),a=o.segment.tempVertices,l=o.segment.tempVerticesHigh,h=o.segment.tempVerticesLow,c=o.segment.gridSize,d=1/(1<<this.tileZoom-o.segment.tileZoom),_=Math.max(n/(c*d),1),u=Math.max(c*d/n,1);for(let o=0,d=e*c;o<r;o+=_,d+=u){const e=3*(r*n+o),c=3*d;t[e]=a[c],t[e+1]=a[c+1],t[e+2]=a[c+2],i[e]=l[c],i[e+1]=l[c+1],i[e+2]=l[c+2],s[e]=h[c],s[e+1]=h[c+1],s[e+2]=h[c+2]}}if(o=e[3][0],this._checkEqualization(3,o)){this.node.equalizedSideWithNodeId[3]=o.equalizedSideWithNodeId[1],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(o,3),a=o.segment.tempVertices,l=o.segment.tempVerticesHigh,h=o.segment.tempVerticesLow,c=o.segment.gridSize,d=c+1,_=1/(1<<this.tileZoom-o.segment.tileZoom),u=Math.max(n/(c*_),1),g=Math.max(c*_/n,1);for(let n=0,o=e*c;n<r;n+=u,o+=g){const e=r*n*3,_=3*(d*o+c);t[e]=a[_],t[e+1]=a[_+1],t[e+2]=a[_+2],i[e]=l[_],i[e+1]=l[_+1],i[e+2]=l[_+2],s[e]=h[_],s[e+1]=h[_+1],s[e+2]=h[_+2]}}}engage(){this.readyToEngage=!1,this.createCoordsBuffers(this.tempVerticesHigh,this.tempVerticesLow,this.gridSize)}_terrainWorkerCallback(e){if(this.plainReady){this.readyToEngage=!0,this.normalMapNormals=null,this.normalMapVertices=null,this.normalMapVerticesHigh=null,this.normalMapVerticesLow=null,this.terrainVertices=null,this.terrainVerticesHigh=null,this.terrainVerticesLow=null,this.noDataVertices=null,this.tempVertices=null,this.tempVerticesHigh=null,this.tempVerticesLow=null,this.normalMapNormals=e.normalMapNormals,this.normalMapVertices=e.normalMapVertices,this.normalMapVerticesHigh=e.normalMapVerticesHigh,this.normalMapVerticesLow=e.normalMapVerticesLow,this.terrainVertices=e.terrainVertices,this.terrainVerticesHigh=e.terrainVerticesHigh,this.terrainVerticesLow=e.terrainVerticesLow,this.noDataVertices=e.noDataVertices,this.tempVertices=this.terrainVertices,this.tempVerticesHigh=this.terrainVerticesHigh,this.tempVerticesLow=this.terrainVerticesLow,this.setBoundingVolumeArr(e.bounds),this.gridSize=Math.sqrt(this.terrainVertices.length/3)-1;let t=this.node;if(t.appliedTerrainNodeId=t.nodeId,t.equalizedSideWithNodeId[0]=t.equalizedSideWithNodeId[1]=t.equalizedSideWithNodeId[2]=t.equalizedSideWithNodeId[3]=t.appliedTerrainNodeId,this.terrainReady=!0,this.terrainIsLoading=!1,this.terrainExists=!0,!this.normalMapTexturePtr){const e=this.planet._normalMapCreator;this.normalMapTexturePtr=this.planet.renderer.handler.createEmptyTexture_l(e.width,e.height)}this.planet.lightEnabled&&this.planet._normalMapCreator.queue(this)}}_normalMapEdgeEqualize(e){let t=this.node.neighbors,i=t[e],s=i&&i[0],n=this.planet.terrain.maxZoom;this.tileZoom===n&&i&&!(t[0].length||t[1].length||t[2].length||t[3].length)&&(s=this.node.getEqualNeighbor(e));let r=s&&s.segment,o=this;if(s&&r&&r.terrainReady&&r.terrainExists&&r.tileZoom<=n&&o._appliedNeighborsZoom[e]!==r.tileZoom){o._appliedNeighborsZoom[e]=r.tileZoom;let t=o.normalMapNormals,i=r.normalMapNormals;if(!t||!i)return;let s=o.normalMapNormals,n=r.normalMapNormals,a=Math.sqrt(t.length/3),l=a-1;const h=l*ca[e];let c,d,_,u;if(o.tileZoom===r.tileZoom){const g=l-h;if(da[e])for(let e=0;e<a;e++){let r=3*(e*a+h),o=3*(e*a+g);c=s[r]+n[o],d=s[r+1]+n[o+1],_=s[r+2]+n[o+2],u=1/Math.sqrt(c*c+d*d+_*_),i[o]=t[r]=c*u,i[o+1]=t[r+1]=d*u,i[o+2]=t[r+2]=_*u}else for(let e=0;e<a;e++){let r=3*(h*a+e),o=3*(g*a+e);c=s[r]+n[o],d=s[r+1]+n[o+1],_=s[r+2]+n[o+2],u=1/Math.sqrt(c*c+d*d+_*_),i[o]=t[r]=c*u,i[o+1]=t[r+1]=d*u,i[o+2]=t[r+2]=_*u}r._inTheQueue||r._appliedNeighborsZoom[Gt[e]]===o.tileZoom||(r._appliedNeighborsZoom[Gt[e]]=o.tileZoom,o.planet._normalMapCreator.queue(r))}}}applyTerrain(e){e?this.elevationsExists(e):this.elevationsNotExists()}deleteBuffers(){const e=this.handler.gl;e.deleteBuffer(this.vertexNormalBuffer),e.deleteBuffer(this.vertexPositionBuffer),e.deleteBuffer(this.vertexPositionBufferHigh),e.deleteBuffer(this.vertexPositionBufferLow),this.vertexNormalBuffer=null,this.vertexPositionBuffer=null,this.vertexPositionBufferHigh=null,this.vertexPositionBufferLow=null,this.vertexTextureCoordBuffer=null}deleteMaterials(){let e=this.materials;for(let t=0;t<e.length;t++){let i=e[t];i&&i.clear()}this.materials.length=0}deleteElevations(){this.terrainExists=!1,this.terrainReady=!1,this.terrainIsLoading=!1,this.normalMapVertices=null,this.normalMapVerticesHigh=null,this.normalMapVerticesLow=null,this.normalMapNormals=null,this.tempVertices=null,this.tempVerticesHigh=null,this.tempVerticesLow=null,this.terrainVertices=null,this.terrainVerticesHigh=null,this.terrainVerticesLow=null,this.noDataVertices=null,this.plainVertices=null,this.plainVerticesHigh=null,this.plainVerticesLow=null,this.plainNormals=null,this.normalMapReady&&(this.handler.gl.deleteTexture(this.normalMapTexture),this.normalMapReady=!1),this._appliedNeighborsZoom=[0,0,0,0],this.normalMapTextureBias[0]=0,this.normalMapTextureBias[1]=0,this.normalMapTextureBias[2]=1,this._inTheQueue=!1}clearSegment(){this.plainReady=!1,this.initialized=!1,this.deleteBuffers(),this.deleteMaterials(),this.deleteElevations()}childrenInitialized(){let e=this.node.nodes;return 4===e.length&&e[0].segment.initialized&&e[1].segment.initialized&&e[2].segment.initialized&&e[3].segment.initialized}destroySegment(){this.clearSegment();let e=this._slices.length;for(;e--;)this._slices[e].clear();this._slices=null,this.node=null,this.planet=null,this.handler=null,this.bbox=null,this.bsphere=null,this._extent=null,this.materials=null,this.plainVertices=null,this.plainVerticesHigh=null,this.plainVerticesLow=null,this.plainNormals=null,this.terrainVertices=null,this.terrainVerticesHigh=null,this.terrainVerticesLow=null,this.noDataVertices=null,this.tempVertices=null,this.tempVerticesHigh=null,this.tempVerticesLow=null,this.normalMapTextureBias=null,this.normalMapTexture=null,this.normalMapVertices=null,this.normalMapVerticesHigh=null,this.normalMapVerticesLow=null,this.normalMapNormals=null,this.vertexNormalBuffer=null,this.vertexPositionBuffer=null,this.vertexPositionBufferHigh=null,this.vertexPositionBufferLow=null,this.vertexTextureCoordBuffer=null,this._projection=null,this._appliedNeighborsZoom=null,this._globalTextureCoordinates=null}_setExtentLonLat(){this._extentLonLat=this._extent.inverseMercator()}_createExtentNormals(){const e=this.planet.ellipsoid,t=this._extentLonLat,i=e.geodeticToCartesian(t.southWest.lon,t.southWest.lat),s=e.geodeticToCartesian(t.northEast.lon,t.northEast.lat),n=e.geodeticToCartesian(t.southWest.lon,t.northEast.lat),r=e.geodeticToCartesian(t.northEast.lon,t.southWest.lat);this._sw.copy(i),this._nw.copy(n),this._ne.copy(s),this._se.copy(r)}createBoundsByExtent(){this._createExtentNormals(),this.setBoundingVolume3v(this._sw,this._ne)}createBoundsByParent(){let e=this.node;for(;e.parentNode&&!e.segment.terrainReady;)e=e.parentNode;let t=1<<this.tileZoom-e.segment.tileZoom,i=this.tileX-e.segment.tileX*t,s=this.tileY-e.segment.tileY*t;if(e.segment.terrainReady&&e.segment.tileZoom>=this.planet.terrain.minZoom){let n=e.segment.gridSize/t;if(n>=1){this.bsphere.center.x=e.segment.bsphere.center.x,this.bsphere.center.y=e.segment.bsphere.center.y,this.bsphere.center.z=e.segment.bsphere.center.z,this.bsphere.radius=e.segment.bsphere.radius;let t=n*s,r=n*i,o=e.segment.gridSize+1,a=3*((t+n)*o+r),l=3*(t*o+r),h=3*(t*o+r+n),c=3*((t+n)*o+r+n),d=e.segment.tempVertices,_=new oe(d[a],d[a+1],d[a+2]),u=new oe(d[h],d[h+1],d[h+2]),g=new oe(d[l],d[l+1],d[l+2]),f=new oe(d[c],d[c+1],d[c+2]);this._sw.copy(_),this._nw.copy(g),this._ne.copy(u),this._se.copy(f)}else{let t,r=e.segment,o=Math.floor(n*s),a=Math.floor(n*i),l=1/n,h=s-l*o,c=i-l*a;t=1===r.gridSize?r.tempVertices:je(r.tempVertices,r.gridSize,o,a,1);let d,_,u=new oe(t[0],t[1],t[2]),g=new oe(t[9],t[10],t[11]),f=new oe(t[3]-t[0],t[4]-t[1],t[5]-t[2]),p=new oe(t[6]-t[0],t[7]-t[1],t[8]-t[2]),m=new oe(t[3]-t[9],t[4]-t[10],t[5]-t[11]),v=new oe(t[6]-t[9],t[7]-t[10],t[8]-t[11]),y=h,x=c;d=y+x<l?oe.add(f.scaleTo(x/l),p.scaleTo(y/l)).addA(u):oe.add(v.scaleTo(1-x/l),m.scaleTo(1-y/l)).addA(g),y=h+1,x=c+1,_=y+x<l?oe.add(f.scaleTo(x/l),p.scaleTo(y/l)).addA(u):oe.add(v.scaleTo(1-x/l),m.scaleTo(1-y/l)).addA(g),this._createExtentNormals(),this.setBoundingVolume3v(d,_)}}else this.createBoundsByExtent()}setBoundingSphere(e,t,i,s){this.bsphere.center.x=e,this.bsphere.center.y=t,this.bsphere.center.z=i,this.bsphere.radius=this.bsphere.center.distance(s)}setBoundingVolume(e,t,i,s,n,r){this.bbox.setFromBoundsArr([e,t,i,s,n,r]);let o=e+.5*(s-e),a=t+.5*(n-t),l=i+.5*(r-i);this.bsphere.center.set(o,a,l),this.bsphere.radius=this.bsphere.center.distance(new oe(e,t,i))}setBoundingVolume3v(e,t){this.bbox.setFromBoundsArr([e.x,e.y,e.z,t.x,t.y,t.z]);let i=e.x+.5*(t.x-e.x),s=e.y+.5*(t.y-e.y),n=e.z+.5*(t.z-e.z);this.bsphere.center.set(i,s,n),this.bsphere.radius=this.bsphere.center.distance(new oe(e.x,e.y,e.z))}setBoundingVolumeArr(e){this.bbox.setFromBoundsArr(e);let t=e[0]+.5*(e[3]-e[0]),i=e[1]+.5*(e[4]-e[1]),s=e[2]+.5*(e[5]-e[2]);this.bsphere.center.set(t,i,s),this.bsphere.radius=this.bsphere.center.distance(new oe(e[0],e[1],e[2]))}createCoordsBuffers(e,t,i){const s=(i+1)*(i+1),n=this.handler;this.vertexPositionBufferHigh&&this.vertexPositionBufferHigh.numItems===s?(n.setStreamArrayBuffer(this.vertexPositionBufferHigh,e),n.setStreamArrayBuffer(this.vertexPositionBufferLow,t)):(n.gl.deleteBuffer(this.vertexPositionBufferHigh),n.gl.deleteBuffer(this.vertexPositionBufferLow),this.vertexTextureCoordBuffer=this.planet._textureCoordsBufferCache[Math.log2(i)],this.vertexPositionBufferHigh=n.createArrayBuffer(e,3,s),this.vertexPositionBufferLow=n.createArrayBuffer(t,3,s))}_addViewExtent(){const e=this._extentLonLat;let t=this.planet._viewExtent;e.southWest.lon<t.southWest.lon&&(t.southWest.lon=e.southWest.lon),e.northEast.lon>t.northEast.lon&&(t.northEast.lon=e.northEast.lon),e.southWest.lat<t.southWest.lat&&(t.southWest.lat=e.southWest.lat),e.northEast.lat>t.northEast.lat&&(t.northEast.lat=e.northEast.lat)}_assignTileIndexes(){this._tileGroup=0;const e=this.tileZoom,t=this._extent,i=z;this.tileX=Qo(t.getCenter().lon,t.getWidth(),-i),this.tileY=Qo(t.getCenter().lat,t.getHeight(),i);const s=this.powTileZoom;this.tileXE=(this.tileX+1)%s,this.tileXW=(s+this.tileX-1)%s,this.tileYN=this.tileY-1,this.tileYS=this.tileY+1,this.tileIndex=$t.getTileIndex(this.tileX,this.tileY,e,this._tileGroup)}initialize(){const e=this.planet,t=this.node;if(this.gridSize=e.terrain.gridSizeByZoom[this.tileZoom]||e.terrain.plainGridSize,t.sideSizeLog2[0]=t.sideSizeLog2[1]=t.sideSizeLog2[2]=t.sideSizeLog2[3]=Math.log2(this.gridSize),this.tileZoom<=e.terrain.maxZoom){const t=this.planet._normalMapCreator;this.normalMapTexturePtr=e.renderer.handler.createEmptyTexture_l(t.width,t.height)}this.normalMapTexture=this.planet.transparentTexture,this._assignGlobalTextureCoordinates(),this.initialized=!0}_assignGlobalTextureCoordinates(){const e=this._extent;this._globalTextureCoordinates[0]=(e.southWest.lon+z)*W,this._globalTextureCoordinates[1]=(z-e.northEast.lat)*W,this._globalTextureCoordinates[2]=(e.northEast.lon+z)*W,this._globalTextureCoordinates[3]=(z-e.southWest.lat)*W}createPlainSegmentAsync(){let e=this.planet,t=e.terrain;t.isReady()&&!this.plainReady&&this.tileZoom<=t.maxZoom&&(this.plainProcessing=!0,e._plainSegmentWorker.make(this))}_plainSegmentWorkerCallback(e){this.plainProcessing=!1,this.initialized&&!this.terrainReady&&(this.plainReady=!0,this.plainVertices=e.plainVertices,this.plainVerticesHigh=e.plainVerticesHigh,this.plainVerticesLow=e.plainVerticesLow,this.plainNormals=e.plainNormals,this._plainRadius=e.plainRadius,this.normalMapNormals=e.normalMapNormals,this.normalMapVertices=e.normalMapVertices,this.normalMapVerticesHigh=e.normalMapVerticesHigh,this.normalMapVerticesLow=e.normalMapVerticesLow,this.fileGridSize=Math.sqrt(e.normalMapVertices.length/3)-1)}createPlainSegment(){this.initialize(),this._createPlainVertices(),this.readyToEngage=!0}_projToDeg(e,t){return I.inverseMercator(e,t)}_createPlainVertices(){const e=this.planet.terrain.gridSizeByZoom[this.tileZoom],t=this.planet.terrain.plainGridSize,i=Math.max(t,e),s=this._extent,n=s.getWidth()/i,r=s.getHeight()/i,o=s.southWest.lon,a=s.northEast.lat,l=Math.max(t/e,1),h=i+1,c=this.planet.ellipsoid._invRadii2,d=h*h,_=(e+1)*(e+1)*3;let u=0,g=0;this.plainNormals=new Float32Array(_),this.plainVertices=new Float64Array(_),this.plainVerticesHigh=new Float32Array(_),this.plainVerticesLow=new Float32Array(_),this.normalMapNormals=new Float32Array(3*d),this.normalMapVertices=new Float64Array(3*d),this.normalMapVerticesHigh=new Float32Array(3*d),this.normalMapVerticesLow=new Float32Array(3*d);let f=this.plainVertices,p=this.plainVerticesHigh,m=this.plainVerticesLow,v=this.plainNormals,y=this.normalMapVertices,x=this.normalMapVerticesHigh,b=this.normalMapVerticesLow,w=this.normalMapNormals;for(let e=0;e<d;e++){let t=e%h,i=~~(e/h),s=this.planet.ellipsoid.lonLatToCartesian(this._projToDeg(o+t*n,a-i*r)),d=s.x*c.x,_=s.y*c.y,C=s.z*c.z,T=1/Math.sqrt(d*d+_*_+C*C),E=d*T,L=_*T,A=C*T;oe.doubleToTwoFloats(s,ia,sa),y[g]=s.x,x[g]=ia.x,b[g]=sa.x,w[g++]=E,y[g]=s.y,x[g]=ia.y,b[g]=sa.y,w[g++]=L,y[g]=s.z,x[g]=ia.z,b[g]=sa.z,w[g++]=A,i%l==0&&t%l==0&&(f[u]=s.x,p[u]=ia.x,m[u]=sa.x,v[u++]=E,f[u]=s.y,p[u]=ia.y,m[u]=sa.y,v[u++]=L,f[u]=s.z,p[u]=ia.z,m[u]=sa.z,v[u++]=A)}this.terrainVertices=f,this.terrainVerticesHigh=p,this.terrainVerticesLow=m,this.plainReady=!0}getMaterialByLayer(e){return this.materials[e.__id]}_getLayerExtentOffset(e){const t=e._extentMerc,i=this._extent,s=t.northEast.lon-t.southWest.lon,n=t.northEast.lat-t.southWest.lat;return[(i.southWest.lon-t.southWest.lon)/s,(t.northEast.lat-i.northEast.lat)/n,(i.northEast.lon-i.southWest.lon)/s,(i.northEast.lat-i.southWest.lat)/n]}initSlice(e){let t=this._slices[e];return t?t.layers=[]:t=this._slices[e]=new Ko(this),t}screenRendering(e,t,i,s,n=!1,r){const o=this.handler.gl,a=e.attributes,l=e.uniforms,h=this.materials,c=this.planet;let d,_;t&&t.length?(_=t[0],d=_._height):d=0,o.activeTexture(o.TEXTURE0+c.SLICE_SIZE+2),o.bindTexture(o.TEXTURE_2D,s||this.getDefaultTexture()),o.uniform1i(l.defaultTexture,c.SLICE_SIZE+2);let u=0,g=0,f=!1,p=this.initSlice(i);for(this._indexBuffer=this._getIndexBuffer();_;){if(this.layerOverlap(_)&&(_._fading&&_._fadingOpacity>0||(_.minZoom>=c.minCurrZoom||_.maxZoom>=c.minCurrZoom)&&(_.minZoom<=c.maxCurrZoom||_.maxZoom<=c.maxCurrZoom))){f=!0;let e=h[_.__id];e||(e=h[_.__id]=_.createMaterial(this)),e.isReady||(this.planet._renderCompleted=!1),p.append(_,e),c._samplerArr[u]=u,o.activeTexture(o.TEXTURE0+u),o.bindTexture(o.TEXTURE_2D,e.texture||c.transparentTexture),u++}g++,_=t[g]}!f&&n||(o.uniform1f(l.transitionOpacity,r||this._transitionOpacity>1?1:this._transitionOpacity),o.uniform1i(l.samplerCount,u),o.uniform1f(l.height,d),o.uniform1iv(l.samplerArr,c._samplerArr),o.uniform4fv(l.tileOffsetArr,p.tileOffsetArr),o.uniform1fv(l.layerOpacityArr,p.layerOpacityArr),c.lightEnabled&&(o.activeTexture(o.TEXTURE0+c.SLICE_SIZE+3),o.bindTexture(o.TEXTURE_2D,this.normalMapTexture||c.transparentTexture),o.uniform1i(l.uNormalMap,c.SLICE_SIZE+3),o.uniform3fv(l.uNormalMapBias,this.normalMapTextureBias),o.uniform4fv(l.uGlobalTextureCoord,this._globalTextureCoordinates)),o.bindBuffer(o.ARRAY_BUFFER,this.vertexPositionBufferHigh),o.vertexAttribPointer(a.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,o.FLOAT,!1,0,0),o.bindBuffer(o.ARRAY_BUFFER,this.vertexPositionBufferLow),o.vertexAttribPointer(a.aVertexPositionLow,this.vertexPositionBufferLow.itemSize,o.FLOAT,!1,0,0),o.bindBuffer(o.ARRAY_BUFFER,this.vertexTextureCoordBuffer),o.vertexAttribPointer(a.aTextureCoord,2,o.UNSIGNED_SHORT,!0,0,0),o.bindBuffer(o.ELEMENT_ARRAY_BUFFER,this._indexBuffer),o.drawElements(c.drawMode,this._indexBuffer.numItems,o.UNSIGNED_INT,0))}heightPickingRendering(e,t){const i=this.handler.gl,s=e.attributes,n=e.uniforms;let r;r=t&&t.length?t[0]._height:0,i.uniform1f(n.height,r),i.bindBuffer(i.ARRAY_BUFFER,this.vertexPositionBufferHigh),i.vertexAttribPointer(s.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this.vertexPositionBufferLow),i.vertexAttribPointer(s.aVertexPositionLow,this.vertexPositionBufferLow.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,this._indexBuffer),i.drawElements(i.TRIANGLE_STRIP,this._indexBuffer.numItems,i.UNSIGNED_INT,0)}increaseTransitionOpacity(){this._transitionOpacity+=(window.performance.now()-this._transitionTimestamp)/this.planet.transitionTime,this._transitionTimestamp=window.performance.now(),this._transitionOpacity>2&&(this._transitionOpacity=2);let e=this.node._fadingNodes.length;for(;e--;){let t=this.node._fadingNodes[e];if(!t.segment){this._transitionOpacity=1;break}t.segment._transitionOpacity>0&&!this.planet._fadingNodes.has(t.__id)&&(this.planet._fadingNodes.set(t.__id,t),t.segment._transitionOpacity=2-this._transitionOpacity,0===t.segment._transitionOpacity&&this.node._fadingNodes.splice(e,1))}}fadingTransitionOpacity(){this._transitionOpacity-=.01,this._transitionTimestamp=window.performance.now(),this._transitionOpacity<0&&(this._transitionOpacity=0)}colorPickingRendering(e,t,i,s,n=!1){const r=this.handler.gl,o=e.attributes,a=e.uniforms;let l,h=this.materials,c=this.planet;l=t&&t.length?t[0]._height:0;let d=!1,_=this._slices[i],u=_.layers.length;for(let e=0;e<u;e++){d=!0;let t=_.layers[e],i=4*e;c._pickingColorArr[i]=t._pickingColor.x/255,c._pickingColorArr[i+1]=t._pickingColor.y/255,c._pickingColorArr[i+2]=t._pickingColor.z/255,c._pickingColorArr[i+3]=Number(t._pickingEnabled),c._samplerArr[e]=e,r.activeTexture(r.TEXTURE0+e),r.bindTexture(r.TEXTURE_2D,h[t.__id].texture||this.planet.transparentTexture),c._pickingMaskArr[e]=e+c.SLICE_SIZE,r.activeTexture(r.TEXTURE0+e+c.SLICE_SIZE),r.bindTexture(r.TEXTURE_2D,h[t.__id].pickingMask||this.planet.transparentTexture)}!d&&n||(r.uniform1i(a.samplerCount,u),r.uniform1f(a.height,l),r.uniform1iv(a.samplerArr,c._samplerArr),r.uniform1iv(a.pickingMaskArr,c._pickingMaskArr),r.uniform4fv(a.pickingColorArr,c._pickingColorArr),r.uniform4fv(a.tileOffsetArr,_.tileOffsetArr),r.uniform1fv(a.layerOpacityArr,_.layerOpacityArr),r.bindBuffer(r.ARRAY_BUFFER,this.vertexPositionBufferHigh),r.vertexAttribPointer(o.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this.vertexPositionBufferLow),r.vertexAttribPointer(o.aVertexPositionLow,this.vertexPositionBufferLow.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this.vertexTextureCoordBuffer),r.vertexAttribPointer(o.aTextureCoord,2,r.UNSIGNED_SHORT,!0,0,0),r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,this._indexBuffer),r.drawElements(r.TRIANGLE_STRIP,this._indexBuffer.numItems,r.UNSIGNED_INT,0))}depthRendering(e,t){const i=this.handler.gl,s=e.attributes,n=e.uniforms;var r;r=t&&t.length?t[0]._height:0,i.uniform1f(n.height,r),i.bindBuffer(i.ARRAY_BUFFER,this.vertexPositionBufferHigh),i.vertexAttribPointer(s.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this.vertexPositionBufferLow),i.vertexAttribPointer(s.aVertexPositionLow,this.vertexPositionBufferLow.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,this._indexBuffer),i.drawElements(i.TRIANGLE_STRIP,this._indexBuffer.numItems,i.UNSIGNED_INT,0)}_getIndexBuffer(){const e=this.node.sideSizeLog2;let t=this.planet._indexesCache[Math.log2(this.gridSize)][e[0]][e[1]][e[2]][e[3]];if(!t.buffer){let i=ko().createSegmentIndexes(Math.log2(this.gridSize),[e[0],e[1],e[2],e[3]]);t.buffer=this.planet.renderer.handler.createElementArrayBuffer(i,1),this.planet._indexesCacheToRemoveCounter++}return t.buffer}layerOverlap(e){return this._extent.overlaps(e._extentMerc)}getDefaultTexture(){return this.planet.solidTextureOne}getExtentLonLat(){return this._extentLonLat}getExtentMerc(){return this._extentMerc}getExtent(){return this._extent}getNeighborSide(e){if(this.tileY===e.tileY){if(this.tileX===e.tileXE)return 3;if(this.tileX===e.tileXW)return 1}else if(this.tileX===e.tileX){if(this.tileY===e.tileYS)return 0;if(this.tileY===e.tileYN)return 2}return-1}}let ua=new oe,ga=new oe;const fa=[new ae(0,0),new ae(1,0),new ae(0,1),new ae(1,1)],pa=Math.sqrt(fa.length)-1;let ma={xmin:0,ymin:0,zmin:0,xmax:0,ymax:0,zmax:0},va=0,ya=class e{constructor(e,t,i,s,n,r){t._createdNodesCount++,this.__id=va++,this.SegmentPrototype=e,this.planet=t,this.parentNode=s,this.partId=i,this.nodeId=i+(s?4*s.nodeId+1:0),this.state=null,this.prevState=null,this.appliedTerrainNodeId=-1,this.sideSizeLog2=[0,0,0,0],this.ready=!1,this.neighbors=[[],[],[],[]],this.equalizedSideWithNodeId=[this.nodeId,this.nodeId,this.nodeId,this.nodeId],this.nodes=[],this.segment=new e(this,t,n,r),this._cameraInside=!1,this.inFrustum=0,this._fadingNodes=[],this.createBounds()}createChildNodes(){this.ready=!0;const t=this.planet,i=this.segment,s=i._extent,n=i.tileZoom+1,r=.5*s.getWidth(),o=.5*s.getHeight(),a=s.northEast,l=s.southWest,h=new I(l.lon+r,l.lat+o),c=this.nodes;c[0]=new e(this.SegmentPrototype,t,0,this,n,new te(new I(l.lon,l.lat+o),new I(l.lon+r,a.lat))),c[1]=new e(this.SegmentPrototype,t,1,this,n,new te(h,new I(a.lon,a.lat))),c[2]=new e(this.SegmentPrototype,t,2,this,n,new te(new I(l.lon,l.lat),h)),c[3]=new e(this.SegmentPrototype,t,3,this,n,new te(new I(l.lon+r,l.lat),new I(a.lon,l.lat+o)))}createBounds(){let e=this.segment;e._setExtentLonLat(),0===e.tileZoom?e.setBoundingSphere(0,0,0,new oe(0,0,e.planet.ellipsoid.equatorialSize)):e.tileZoom<e.planet.terrain.minZoom?e.createBoundsByExtent():e.createBoundsByParent();let t=e.bsphere.center.x,i=e.bsphere.center.y,s=e.bsphere.center.z,n=1/Math.sqrt(t*t+i*i+s*s);e.centerNormal.x=t*n,e.centerNormal.y=i*n,e.centerNormal.z=s*n}getState(){if(-1===this.state)return this.state;let e=this.parentNode;for(;e;){if(2!==e.state)return 0;e=e.parentNode}return this.state}getEqualNeighbor(e){let t=this,i=Yt[e][t.partId];if(-1!==i)return t.parentNode.nodes[i];{let s=[];for(;t.parentNode;)if(s.push(t.partId),i=Yt[e][t.partId],t=t.parentNode,-1!==i){let n=s.length;for(e=Gt[e];t&&n--;)i=jt[e][s[n]],t=t.nodes[i];return t}}}traverseNodes(e,t,i,s,n){this.ready||this.createChildNodes();let r=this.nodes;r[0].renderTree(e,t,i,s,n),r[1].renderTree(e,t,i,s,n),r[2].renderTree(e,t,i,s,n),r[3].renderTree(e,t,i,s,n)}renderTree(e,t,i,s,n){if(this.planet._renderedNodes.length>=1e3)return;(!t||n&&this.segment.tileZoom>n.segment.tileZoom)&&(this.prevState=this.state),this.state=2,this.clearNeighbors();let r=this.segment,o=this.planet;if(this._cameraInside=!1,!this.parentNode||this.parentNode._cameraInside){let t;t=r._projection.id===Zo.id?r._extent.isInside(e._lonLatMerc):r._extent.isInside(e._lonLat),t&&(e._insideSegment=r,this._cameraInside=!0)}this.inFrustum=0;let a=e.frustums,l=a.length;if(r.tileZoom<6)for(let e=0;e<l;e++)a[e].containsSphere(r.bsphere)&&(this.inFrustum|=1<<e);else for(let e=0;e<l;e++)r.terrainReady?a[e].containsBox(r.bbox)&&(this.inFrustum|=1<<e):a[e].containsSphere(r.bsphere)&&(this.inFrustum|=1<<e);if(this.inFrustum||this._cameraInside||r.tileZoom<3){let a=Math.abs(e._lonLat.height),l=e.eye.length2()-o.ellipsoid.polarSizeSqr;l=l<106876472875.63281*o._heightFactor?106876472875.63281*o._heightFactor:l;let h=r.tileZoom<2||r.tileZoom>19||r.tileZoom<6&&!r.terrainReady;h=h||e.eye.distance2(r._sw)<l||e.eye.distance2(r._nw)<l||e.eye.distance2(r._ne)<l||e.eye.distance2(r._se)<l,(this.inFrustum&&(h||a>1e4)||this._cameraInside)&&o.quadTreeStrategy.collectVisibleNode(this),r.tileZoom<2?this.traverseNodes(e,t,i,s,n):r.terrainReady&&(!t&&e.projectedSize(r.bsphere.center,r._plainRadius)<o.lodSize||t&&(r.tileZoom===t||!h))?h?(r.passReady=!0,this.renderNode(this.inFrustum,!this.inFrustum,i,s)):this.state=0:r.terrainReady&&r.checkZoom()&&(!t||e.projectedSize(r.bsphere.center,r.bsphere.radius)>this.planet._maxLodSize)?this.traverseNodes(e,t,r,s,n):h?(r.passReady=!!t&&r.terrainReady,this.renderNode(this.inFrustum,!this.inFrustum,i,s)):this.state=0}else this.state=0}renderNode(e,t,i,s){let n=this.segment;n.terrainReady||(n.initialized||n.initialize(),this.whileTerrainLoading(i),n.plainProcessing||n.createPlainSegmentAsync(),n.plainReady&&!s&&n.loadTerrain()),n.planet.lightEnabled&&!n.normalMapReady&&this.whileNormalMapCreating(),t?this.state=-1:(!this._cameraInside&&n.tileZoom>this.planet.maxCurrZoom&&(this.planet.maxCurrZoom=n.tileZoom),n.tileZoom<this.planet.minCurrZoom&&(this.planet.minCurrZoom=n.tileZoom),n._addViewExtent(),this.addToRender(e))}childrenPrevStateEquals(e){let t=this.nodes;return 4===t.length&&t[0].prevState===e&&t[1].prevState===e&&t[2].prevState===e&&t[3].prevState===e}isFading(){let e=this.nodes;return 2===this.state&&this.segment._transitionOpacity>0&&4===e.length&&1===e[0].state&&1===e[1].state&&1===e[2].state&&1===e[3].state}_collectFadingNodes(){if(this.segment.tileZoom<3)this.segment._transitionOpacity=1;else if(1!==this.prevState){this.segment._transitionOpacity=0,this._fadingNodes=[];let e=window.performance.now();if(this.segment._transitionTimestamp=e,this.parentNode)if(1===this.parentNode.prevState){let t=this.parentNode.parentNode;for(;t;){if(t.isFading()){for(let e=0;e<t.nodes.length;e++)t.nodes[e].segment._transitionOpacity=1,t.nodes[e]._fadingNodes=[];t.segment._transitionOpacity=0;break}t=t.parentNode}this.parentNode.whileTerrainLoading(),this._fadingNodes.push(this.parentNode),this.parentNode.segment._transitionOpacity=2,this.parentNode.segment._transitionTimestamp=e}else if(this.segment.childrenInitialized()&&this.childrenPrevStateEquals(1))for(let t=0;t<this.nodes.length;t++){let i=this.nodes[t];i.whileTerrainLoading(),this._fadingNodes.push(i),i.segment._transitionOpacity=2,i.segment._transitionTimestamp=e,i.prevState=i.state,i.state=0}}}clearNeighbors(){this.neighbors&&(this.neighbors[0]=this.neighbors[1]=this.neighbors[2]=this.neighbors[3]=null,this.neighbors[0]=[],this.neighbors[1]=[],this.neighbors[2]=[],this.neighbors[3]=[])}_refreshTransitionOpacity(){if(0===this._fadingNodes.length)this.segment._transitionOpacity=1;else if(4!==this._fadingNodes.length||this.childrenPrevStateEquals(1)){for(let e=0;e<this._fadingNodes.length;e++)this.segment._transitionOpacity<1&&0===this._fadingNodes[e].segment._transitionOpacity&&(this._fadingNodes[e].segment._transitionOpacity=0,this.segment._transitionOpacity=1);this.segment.increaseTransitionOpacity()}else this.segment._transitionOpacity=1,this._fadingNodes=[]}addToRender(e){this.state=1;let t=this.planet._renderedNodes;this.planet._transitionOpacityEnabled?Ie(t,this,((e,t)=>e.segment.tileZoom-t.segment.tileZoom)):(this.getRenderedNodesNeighbors(t),t.push(this)),this.segment.terrainReady||(this.planet._renderCompleted=!1,this.planet._terrainCompleted=!1);let i=0,s=this.planet._renderedNodesInFrustum;for(;e;)1&e&&s[i].push(this),i++,e>>=1}applyNeighbor(e,t){const i=Gt[t];if(0===this.neighbors[t].length||0===e.neighbors[i].length){const s=this.segment,n=e.segment,r=s.gridSize/(n.gridSize*Math.pow(2,n.tileZoom-s.tileZoom));let o=s.gridSize,a=n.gridSize;r>1?(o=Math.ceil(s.gridSize/r),a=n.gridSize):r<1&&(o=s.gridSize,a=Math.ceil(n.gridSize*r)),this.sideSizeLog2[t]=Math.log2(o),e.sideSizeLog2[i]=Math.log2(a)}this.neighbors[t].push(e),e.neighbors[i].push(this)}getRenderedNodesNeighbors(e){for(let t=e.length-1;t>=0;--t){let i=e[t],s=this.getCommonSide(i);-1!==s&&this.applyNeighbor(i,s)}}getCommonSide(e){const t=this.segment,i=e.segment;if(t.tileZoom===i.tileZoom&&t._tileGroup===i._tileGroup)return t.getNeighborSide(i);{const e=t._extentLonLat,s=i._extentLonLat;let n=e.northEast,r=e.southWest,o=s.northEast,a=s.southWest,l=n.lon,h=n.lat,c=r.lon,d=r.lat,_=o.lon,u=o.lat,g=a.lon,f=a.lat;if(t._tileGroup===i._tileGroup){if(l===g&&(h<=u&&d>=f||h>=u&&d<=f))return 1;if(c===_&&(h<=u&&d>=f||h>=u&&d<=f))return 3;if(h===f&&(c>=g&&l<=_||c<=g&&l>=_))return 0;if(d===u&&(c>=g&&l<=_||c<=g&&l>=_))return 2;if(0===i.tileX&&g===-l&&(h<=u&&d>=f||h>=u&&d<=f))return 1;if(0===t.tileX&&c===-_&&(h<=u&&d>=f||h>=u&&d<=f))return 3}if(0===t._tileGroup&&i._tileGroup===ea&&0===t.tileY&&i.tileY===i.powTileZoom-1&&(c>=g&&l<=_||c<=g&&l>=_))return 0;if(0===t._tileGroup&&i._tileGroup===ta&&t.tileY===t.powTileZoom-1&&0===i.tileY&&(c>=g&&l<=_||c<=g&&l>=_))return 2;if(t._tileGroup===ta&&0===i._tileGroup&&0===t.tileY&&i.tileY===i.powTileZoom-1&&(c>=g&&l<=_||c<=g&&l>=_))return 0;if(t._tileGroup===ea&&0===i._tileGroup&&t.tileY===t.powTileZoom-1&&0===i.tileY&&(c>=g&&l<=_||c<=g&&l>=_))return 2}return-1}whileNormalMapCreating(){const e=this.segment;e.terrainIsLoading||!e.terrainExists||e._inTheQueue||e.planet._normalMapCreator.queue(e);let t=this;for(;t.parentNode&&!t.segment.normalMapReady;)t=t.parentNode;const i=2<<e.tileZoom-t.segment.tileZoom-1;e.normalMapTexture=t.segment.normalMapTexture,e.normalMapTextureBias[0]=e.tileX-t.segment.tileX*i,e.normalMapTextureBias[1]=e.tileY-t.segment.tileY*i,e.normalMapTextureBias[2]=1/i}whileTerrainLoading(e){const t=this.segment;let i=this;if(e&&e.terrainReady)i=e.node;else for(;i.parentNode&&!i.segment.terrainReady;)i=i.parentNode;if(i.segment.terrainReady&&this.appliedTerrainNodeId!==i.nodeId){let e=2<<t.tileZoom-i.segment.tileZoom-1,s=t.tileX-i.segment.tileX*e,n=t.tileY-i.segment.tileY*e;const r=i.segment;let l,h,c,d;this.appliedTerrainNodeId=i.nodeId,this.equalizedSideWithNodeId[0]=this.equalizedSideWithNodeId[1]=this.equalizedSideWithNodeId[2]=this.equalizedSideWithNodeId[3]=this.appliedTerrainNodeId;let _=i.segment.gridSize/e,u=i.segment.fileGridSize/e;if(ma.xmin=o,ma.xmax=a,ma.ymin=o,ma.ymax=a,ma.zmin=o,ma.zmax=a,_>=1){t.gridSize=_;let e=(_+1)*(_+1)*3;l=new Float64Array(e),h=new Float32Array(e),c=new Float32Array(e),r.noDataVertices&&(d=new Uint8Array(e/3)),qe(r.terrainVertices,r.terrainVerticesHigh,r.terrainVerticesLow,r.noDataVertices,r.gridSize,_*n,_*s,_,l,h,c,ma,d)}else if(u>=1&&i.segment.terrainExists){t.gridSize=u;let e=(u+1)*(u+1)*3;l=new Float64Array(e),h=new Float32Array(e),c=new Float32Array(e),r.noDataVertices&&(d=new Uint8Array(e/3)),qe(r.normalMapVertices,r.normalMapVerticesHigh,r.normalMapVerticesLow,r.noDataVertices,i.segment.fileGridSize,u*n,u*s,u,l,h,c,ma,d)}else{t.gridSize=pa;let e,i=Math.floor(_*n),o=Math.floor(_*s);e=1===r.gridSize?r.terrainVertices:je(r.terrainVertices,r.gridSize,i,o,1);let a=1/_,d=n-a*i,u=s-a*o,g=new oe(e[0],e[1],e[2]),f=new oe(e[9],e[10],e[11]),p=new oe(e[3]-e[0],e[4]-e[1],e[5]-e[2]),m=new oe(e[6]-e[0],e[7]-e[1],e[8]-e[2]),v=new oe(e[3]-e[9],e[4]-e[10],e[5]-e[11]),y=new oe(e[6]-e[9],e[7]-e[10],e[8]-e[11]),x=new oe;l=new Float64Array(3*fa.length),h=new Float32Array(3*fa.length),c=new Float32Array(3*fa.length);for(let e=0;e<fa.length;e++){let t=fa[e].y+d,i=fa[e].x+u,s=i*_,n=t*_;x=t+i<a?p.scaleTo(s).addA(m.scaleTo(n)).addA(g):y.scaleTo(1-s).addA(v.scaleTo(1-n)).addA(f),oe.doubleToTwoFloats(x,ua,ga);let r=3*e;l[r]=x.x,l[r+1]=x.y,l[r+2]=x.z,h[r]=ua.x,h[r+1]=ua.y,h[r+2]=ua.z,c[r]=ga.x,c[r+1]=ga.y,c[r+2]=ga.z,x.x<ma.xmin&&(ma.xmin=x.x),x.x>ma.xmax&&(ma.xmax=x.x),x.y<ma.ymin&&(ma.ymin=x.y),x.y>ma.ymax&&(ma.ymax=x.y),x.z<ma.zmin&&(ma.zmin=x.z),x.z>ma.zmax&&(ma.zmax=x.z)}}if(t.readyToEngage=!0,t.terrainVertices=l,t.terrainVerticesHigh=h,t.terrainVerticesLow=c,t.tempVertices=l,t.tempVerticesHigh=h,t.tempVerticesLow=c,t.noDataVertices=d,t.setBoundingVolume(ma.xmin,ma.ymin,ma.zmin,ma.xmax,ma.ymax,ma.zmax),t.tileZoom>t.planet.terrain.maxZoom&&i.segment.tileZoom>=t.planet.terrain.maxZoom&&(t._plainRadius=i.segment._plainRadius/e,t.terrainReady=!0,t.terrainIsLoading=!1,t.terrainVertices=l,t.terrainVerticesHigh=h,t.terrainVerticesLow=c,t.passReady=!0,this.appliedTerrainNodeId=this.nodeId,this.equalizedSideWithNodeId[0]=this.equalizedSideWithNodeId[1]=this.equalizedSideWithNodeId[2]=this.equalizedSideWithNodeId[3]=this.appliedTerrainNodeId,i.segment.terrainExists)){t.normalMapVertices=l,t.fileGridSize=Math.sqrt(l.length/3)-1;let i=Math.sqrt(r.normalMapNormals.length/3)-1,o=i/e;t.normalMapNormals=i>1?We(r.normalMapNormals,i,o*n,o*s,o):r.normalMapNormals}}}destroy(){this.prevState=this.state=0,this.segment.destroySegment();let e=this.neighbors;for(let t=0,i=e.length;t<i;t++){let i=e[t];if(i)for(let e=0;e<i.length;e++){let t=i[e];t&&t.neighbors&&t.clearNeighbors()}}this.neighbors=null,this.parentNode=null,this.sideSizeLog2=null,this.segment=null}clearTree(){const e=this.getState();if(0===e||1===e)this.destroyBranches();else for(let e=0;e<this.nodes.length;e++)this.nodes[e]&&this.nodes[e].clearTree()}clearBranches(){for(let e=0;e<this.nodes.length;e++)this.nodes[e].clearBranches(),this.nodes[e].segment.deleteMaterials()}destroyBranches(){if(this.ready){let e,t=[];for(e=0;e<this.nodes.length;e++)t[e]=this.nodes[e];for(this.ready=!1,this.nodes=[],e=0;e<t.length;e++)t[e].destroyBranches(),t[e].destroy(),t[e]=null;t.length=0,t=null}}traverseTree(e){if(e(this),this.ready)for(let t=0;t<this.nodes.length;t++)this.nodes[t].traverseTree(e)}getOffsetOppositeNeighbourSide(e,t){let i=this,s=e.segment.tileZoom,n=0;for(;i.segment.tileZoom>s;)n+=Wt[i.partId][t]/(1<<i.segment.tileZoom-s),i=i.parentNode;return n}};class xa{constructor(e=2048){this._size=e,this._array=new Array(this._size),this._popIndex=Math.floor(.5*this._size),this._shiftIndex=this._popIndex,this.length=0}reset(){this._popIndex=Math.floor(.5*this._size),this._shiftIndex=this._popIndex,this.length=0}clear(){this._array.length=0,this._array=new Array(this._size),this._popIndex=Math.floor(.5*this._size),this._shiftIndex=this._popIndex,this.length=0}push(e){this.length++,this._array[this._popIndex++]=e}pop(){if(this.length){this.length--;let e=this._array[--this._popIndex];return this._array[this._popIndex]=null,this._array[this._popIndex-1]||(this._popIndex=Math.floor(.5*this._size),this._shiftIndex=this._popIndex),e}}unshift(e){this.length++,this._array[--this._shiftIndex]=e}shift(){if(this.length){this.length--;let e=this._array[this._shiftIndex];return this._array[this._shiftIndex++]=null,this._array[this._shiftIndex]||(this._popIndex=Math.floor(.5*this._size),this._shiftIndex=this._popIndex),e}}forEach(e){for(let t=this._shiftIndex;t<this._popIndex;t++)e(this._array[t])}}class ba{constructor(e,t){this._layer=e,this._nodeCapacity=t,this._secondPASS=[],this._counter=0,this._deferredEntitiesPendingQueue=new xa,this._renderingNodes={}}insertEntity(e,t=!1){}setPickingEnabled(e){}dispose(){}insertEntities(e){}collectVisibleEntityCollections(e){}_queueDeferredNode(e){this._layer.getVisibility()&&(e._inTheQueue=!0,this._counter>=1?this._deferredEntitiesPendingQueue.push(e):this._execDeferredNode(e))}_execDeferredNode(e){this._counter++,requestAnimationFrame((()=>{if(e.applyCollection(),this._counter--,this._deferredEntitiesPendingQueue.length&&this._counter<1)for(;this._deferredEntitiesPendingQueue.length;){let e=this._deferredEntitiesPendingQueue.pop();if(e._inTheQueue=!1,e.isVisible())return void this._execDeferredNode(e)}}))}}class wa{constructor(e,t="",i=Zo){this.name=t,this.projection=i,this._planet=e,this._quadTreeList=[],this._visibleNodes={}}createEntitiCollectionsTreeStrategy(e,t){return new ba(e,t)}destroyBranches(){for(let e=0,t=this._quadTreeList.length;e<t;e++)this._quadTreeList[e].destroyBranches()}clearLayerMaterial(e){let t=e.__id;for(let e=0,i=this._quadTreeList.length;e<i;e++)this._quadTreeList[e].traverseTree((function(e){let i=e.segment.materials;i[t]&&(i[t].clear(),i[t]=null)}))}get planet(){return this._planet}init(){}preRender(){for(let e=0;e<this._quadTreeList.length;e++){let t=this._quadTreeList[e];t.createChildNodes(),t.segment.createPlainSegment();for(let e=0;e<t.nodes.length;e++)t.nodes[e].segment.createPlainSegment()}}preLoad(){for(let e=0;e<this._quadTreeList.length;e++){let t=this._quadTreeList[e];t.segment.passReady=!0,t.renderNode(1),this._planet.normalMapCreator.drawSingle(t.segment);for(let e=0;e<t.nodes.length;e++)t.nodes[e].segment.passReady=!0,t.nodes[e].renderNode(1),this._planet._normalMapCreator.drawSingle(t.nodes[e].segment)}}_clearVisibleNodes(){this._visibleNodes={}}collectRenderNodes(){this._clearVisibleNodes();for(let e=0;e<this._quadTreeList.length;e++)this._quadTreeList[e].renderTree(this._planet.camera,0,null)}clear(){for(let e=0;e<this._quadTreeList.length;e++)this._quadTreeList[e].clearTree()}get quadTreeList(){return this._quadTreeList}getTileXY(e,t){let i=t,s=-1,n=-1,r=1<<i;return s=Qo(e.lon,360/r,-180),n=Qo(e.lat,180/r,90),[s,n,i,0]}getLonLatTileOffset(e,t,i,s,n){let r=e,o=new te;o=Jo(t,i,s,te.createFromArray([-180,-90,180,90]));let a=o.getWidth()/(n-1),l=o.getHeight()/(n-1);return[n-Math.ceil((r.lat-o.southWest.lat)/l)-1,Math.floor((r.lon-o.southWest.lon)/a)]}collectVisibleNode(e){this._visibleNodes[e.nodeId]=e}}const Ca=new Xo({code:"epsg:4326",units:Wo}),Ta=(90-Q)/Math.pow(2,7);class Ea extends _a{constructor(e,t,i,s){super(e,t,i,s),this._projection=Ca,this._extentLonLat=this._extent,this._extentMerc=new te(s.southWest.forwardMercatorEPS01(),s.northEast.forwardMercatorEPS01()),this._isNorth=this._extent.northEast.lat>0,this.isPole=!0}_setExtentLonLat(){this._extentLonLat=this._extent}projectNative(e){return e}getInsideLonLat(e){return e._lonLat}_getMaxZoom(){let e=0;if(this._isNorth){let t=Math.floor((90-this._extent.northEast.lat)/Ta);e=Math.floor(t/16)+7}else{let t=Math.floor((J-this._extent.northEast.lat)/Ta);e=12-Math.floor(t/16)}return e}checkZoom(){return super.checkZoom()&&this.tileZoom<=this._getMaxZoom()}_assignTileIndexes(){this._assignTileXIndexes(this._extent),this._assignTileYIndexes(this._extent),this.tileIndex=$t.getTileIndex(this.tileX,this.tileY,this.tileZoom,this._tileGroup)}_assignTileXIndexes(e){this.tileX=Qo(e.getCenter().lon,e.getWidth(),-180);let t=1<<this.tileZoom;this.tileXE=(this.tileX+1)%t,this.tileXW=(t+this.tileX-1)%t}_assignTileYIndexes(e){const t=e.getCenter().lat;t>0?(this._tileGroup=ea,this.tileY=Qo(t,e.getHeight(),90)):(this._tileGroup=ta,this.tileY=Qo(t,e.getHeight(),J)),this.tileYN=this.tileY-1,this.tileYS=this.tileY+1}_projToDeg(e,t){return new I(e,t)}_assignGlobalTextureCoordinates(){const e=this._extent;this._globalTextureCoordinates[0]=(e.southWest.lon+180)/360,this._globalTextureCoordinates[1]=(90-e.northEast.lat)/180,this._globalTextureCoordinates[2]=(e.northEast.lon+180)/360,this._globalTextureCoordinates[3]=(90-e.southWest.lat)/180}_getLayerExtentOffset(e){const t=e._extent,i=this._extent,s=t.northEast.lon-t.southWest.lon,n=t.northEast.lat-t.southWest.lat;return[(i.southWest.lon-t.southWest.lon)/s,(t.northEast.lat-i.northEast.lat)/n,(i.northEast.lon-i.southWest.lon)/s,(i.northEast.lat-i.southWest.lat)/n]}layerOverlap(e){return this._extent.overlaps(e._extent)}getDefaultTexture(){return this._isNorth?this.planet.solidTextureOne:this.planet.solidTextureTwo}getExtentLonLat(){return this._extent}}class La{constructor(e,t,i,s,n,r){this.strategy=e,this.layer=e._layer,this.parentNode=i,this.childNodes=[],this.partId=t,this.nodeId=t+(i?4*i.nodeId+1:0),this.state=null,this.extent=s,this.count=0,this.deferredEntities=[],this.entityCollection=null,this.zoom=r,this._inTheQueue=!1,this.bsphere=new Pt,n&&this._setExtentBounds()}insertEntity(e,t=!1){this.buildTree([e],t)}_addEntitiesToCollection(e,t=!1){if(e.length){const i=this.layer,s=i._planet;let n=this.entityCollection;n||(n=new fs({pickingEnabled:i._pickingEnabled,labelMaxLetters:i.labelMaxLetters}),n._layer=this.layer,n.addTo(s,!0),n._quadNode=this,i._bindEventsDefault(n),this.entityCollection=n),t||!i.async?this.entityCollection.addEntities(e):this.deferredEntities.push.apply(this.deferredEntities,e)}}_setExtentBounds(){this.nodeId?this.bsphere.setFromExtent(this.layer._planet.ellipsoid,this.extent.inverseMercator()):(this.bsphere.radius=this.layer._planet.ellipsoid.equatorialSize,this.bsphere.center=new oe)}__setLonLat__(e){return e._lonLat.isZero()&&!e._cartesian.isZero()&&(e._lonLat=this.layer._planet.ellipsoid.cartesianToLonLat(e._cartesian)),Math.abs(e._lonLat.lat)<Q?e._lonLatMerc=e._lonLat.forwardMercator():e._lonLatMerc=new I,e._lonLatMerc}buildTree(e,t=!1){if(this.count+=e.length,e.length>this.layer._nodeCapacity){const i=this.childNodes;i.length||this.createChildNodes();let s=[],n=[],r=[],o=[],a=e.length;for(;a--;){const t=e[a];i[0].isInside(t)?(t._nodePtr=i[0],s.push(t)):i[1].isInside(t)?(t._nodePtr=i[1],n.push(t)):i[2].isInside(t)?(t._nodePtr=i[2],r.push(t)):i[3].isInside(t)&&(t._nodePtr=i[3],o.push(t))}s.length&&i[0].buildTree(s,t),n.length&&i[1].buildTree(n,t),r.length&&i[2].buildTree(r,t),o.length&&i[3].buildTree(o,t)}else this._addEntitiesToCollection(e,t)}isInside(e){return!!e._lonLatMerc&&this.extent.isInside(e._lonLatMerc)}createChildNodes(){const e=this.strategy,t=this.extent,i=.5*t.getWidth(),s=.5*t.getHeight(),n=t.northEast,r=t.southWest,o=new I(r.lon+i,r.lat+s),a=this.childNodes,l=this.layer._planet,h=this.zoom+1;a[0]=new La(e,0,this,new te(new I(r.lon,r.lat+s),new I(r.lon+i,n.lat)),l,h),a[1]=new La(e,1,this,new te(o,new I(n.lon,n.lat)),l,h),a[2]=new La(e,2,this,new te(new I(r.lon,r.lat),o),l,h),a[3]=new La(e,3,this,new te(new I(r.lon+i,r.lat),new I(n.lon,r.lat+s)),l,h)}collectRenderCollectionsPASS1(e,t){const i=e[this.nodeId];if(i){const s=this.childNodes;this.entityCollection?this.renderCollection(t,e):s.length&&(1===i.state?this.strategy._secondPASS.push(this):(s[0].collectRenderCollectionsPASS1(e,t),s[1].collectRenderCollectionsPASS1(e,t),s[2].collectRenderCollectionsPASS1(e,t),s[3].collectRenderCollectionsPASS1(e,t)))}}collectRenderCollectionsPASS2(e,t,i){const s=this.layer._planet.camera,n=s.eye.distance(this.bsphere.center)-this.bsphere.radius<3570*Math.sqrt(s._lonLat.height)||s._lonLat.height>1e4;if(this.count>0&&n&&s.containsSphere(this.bsphere)){const s=this.childNodes;this.entityCollection?this.renderCollection(t,e,i):s.length&&(s[0].collectRenderCollectionsPASS2(e,t,i),s[1].collectRenderCollectionsPASS2(e,t,i),s[2].collectRenderCollectionsPASS2(e,t,i),s[3].collectRenderCollectionsPASS2(e,t,i))}}applyCollection(){this.entityCollection.addEntities(this.deferredEntities),this.deferredEntities.length=0,this.deferredEntities=[],this._inTheQueue=!1}traverseTree(e){const t=this.childNodes;this.entityCollection?e(this):t.length&&(t[0].traverseTree(e),t[1].traverseTree(e),t[2].traverseTree(e),t[3].traverseTree(e))}renderCollection(e,t,i){const s=this.strategy;s._renderingNodes[this.nodeId]=!0,this.deferredEntities.length&&!this._inTheQueue&&(this.layer.async?s._queueDeferredNode(this):this.applyCollection());let n=this.entityCollection,r=this.layer;if(n._fadingOpacity=r._fadingOpacity,n.scaleByDistance=r.scaleByDistance,n.pickingScale=r.pickingScale,n.polygonOffsetUnits=r.polygonOffsetUnits,e.push(n),r.clampToGround||r.relativeToGround){const e=n._entities;let s=e.length;if(t[this.nodeId]&&1===t[this.nodeId].state)for(;s--;){let i=e[s];this.alignEntityToTheGround(i,t[this.nodeId].segment)}else if(i)for(;s--;){let n=e[s];this.alignEntityToTheGround(n,t[i].segment)}else{const t=r._planet._renderedNodes;for(;s--;){let i=e[s],n=t.length;for(;n--;)if(t[n].segment.isEntityInside(i)){this.alignEntityToTheGround(i,t[n].segment);break}}}}}alignEntityToTheGround(e,t){let i=new oe;t.getEntityTerrainPoint(e,i);let s=Number(this.layer.relativeToGround)&&e._altitude||0;if(s){let t=this.layer._planet.ellipsoid.getSurfaceNormal3v(i);e._setCartesian3vSilent(i.addA(t.scale(s)))}else e._setCartesian3vSilent(i)}isVisible(){return!!this.strategy._renderingNodes[this.nodeId]}}class Aa extends La{constructor(e,t,i,s,n,r){super(e,t,i,s,n,r),this.strategy=e,this.isNorth=!1}createChildNodes(){const e=this.strategy,t=this.extent,i=.5*t.getWidth(),s=.5*t.getHeight(),n=t.northEast,r=t.southWest,o=new I(r.lon+i,r.lat+s),a=this.childNodes,l=this.layer._planet,h=this.zoom+1;a[0]=new Aa(e,0,this,new te(new I(r.lon,r.lat+s),new I(r.lon+i,n.lat)),l,h),a[1]=new Aa(e,1,this,new te(o,new I(n.lon,n.lat)),l,h),a[2]=new Aa(e,2,this,new te(new I(r.lon,r.lat),o),l,h),a[3]=new Aa(e,3,this,new te(new I(r.lon+i,r.lat),new I(n.lon,r.lat+s)),l,h)}_setExtentBounds(){this.extent.northEast.lat>0&&(this.isNorth=!0),this.bsphere.setFromExtent(this.layer._planet.ellipsoid,this.extent)}__setLonLat__(e){return e._lonLat.isZero()&&(e._lonLat=this.layer._planet.ellipsoid.cartesianToLonLat(e._cartesian)),e._lonLat}isVisible(){return!(!this.isNorth||!this.strategy._renderingNodesNorth[this.nodeId])||!!this.strategy._renderingNodesSouth[this.nodeId]}isInside(e){return this.extent.isInside(e._lonLat)}renderCollection(e,t,i){this.isNorth?this.strategy._renderingNodesNorth[this.nodeId]=!0:this.strategy._renderingNodesSouth[this.nodeId]=!0,this.deferredEntities.length&&!this._inTheQueue&&(this.layer.async?this.strategy._queueDeferredNode(this):this.applyCollection());const s=this.entityCollection;s._fadingOpacity=this.layer._fadingOpacity,s.scaleByDistance=this.layer.scaleByDistance,s.pickingScale=this.layer.pickingScale,s.isEmpty()||e.push(s)}}class Pa extends ba{constructor(e,t){super(e,t);let i=e._planet;this._entityCollectionsTree=new La(this,0,null,te.createFromArray([-20037508.34,-20037508.34,20037508.34,20037508.34]),i,0),this._entityCollectionsTreeNorth=new Aa(this,0,null,te.createFromArray([-180,Q,180,90]),i,0),this._entityCollectionsTreeSouth=new Aa(this,0,null,te.createFromArray([-180,-90,180,J]),i,0),this._renderingNodes={},this._renderingNodesNorth={},this._renderingNodesSouth={}}insertEntity(e,t=!1){e._lonLat.lat>Q?(this._entityCollectionsTreeNorth.__setLonLat__(e),this._entityCollectionsTreeNorth.insertEntity(e,t)):e._lonLat.lat<J?(this._entityCollectionsTreeSouth.__setLonLat__(e),this._entityCollectionsTreeSouth.insertEntity(e,t)):(this._entityCollectionsTree.__setLonLat__(e),this._entityCollectionsTree.insertEntity(e,t))}setPickingEnabled(e){this._entityCollectionsTree&&this._entityCollectionsTree.traverseTree((t=>{t.entityCollection.setPickingEnabled(e)})),this._entityCollectionsTreeNorth&&this._entityCollectionsTreeNorth.traverseTree((t=>{t.entityCollection.setPickingEnabled(e)})),this._entityCollectionsTreeSouth&&this._entityCollectionsTreeSouth.traverseTree((t=>{t.entityCollection.setPickingEnabled(e)}))}dispose(){this._entityCollectionsTree=null,this._entityCollectionsTreeNorth=null,this._entityCollectionsTreeSouth=null,this._renderingNodes={},this._renderingNodesNorth={},this._renderingNodesSouth={}}insertEntities(e){let t=[],i=[],s=[];for(let n=0,r=e.length;n<r;n++){let r=e[n];r._lonLat.lat>Q?(t.push(r),this._entityCollectionsTreeNorth.__setLonLat__(r)):r._lonLat.lat<J?(i.push(r),this._entityCollectionsTreeSouth.__setLonLat__(r)):(s.push(r),this._entityCollectionsTree.__setLonLat__(r))}this._entityCollectionsTree.buildTree(s),this._entityCollectionsTreeNorth.buildTree(t),this._entityCollectionsTreeSouth.buildTree(i)}collectVisibleEntityCollections(e){this._renderingNodes={},this._renderingNodesNorth={},this._renderingNodesSouth={};let t=this._layer._planet.quadTreeStrategy;this._secondPASS=[],this._entityCollectionsTree.collectRenderCollectionsPASS1(t._visibleNodes,e);let i=this._secondPASS.length;for(;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodes,e,this._secondPASS[i].nodeId);for(this._secondPASS=[],this._entityCollectionsTreeNorth.collectRenderCollectionsPASS1(t._visibleNodesNorth,e),i=this._secondPASS.length;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodesNorth,e,this._secondPASS[i].nodeId);for(this._secondPASS=[],this._entityCollectionsTreeSouth.collectRenderCollectionsPASS1(t._visibleNodesSouth,e),i=this._secondPASS.length;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodesSouth,e,this._secondPASS[i].nodeId)}}class Sa extends wa{constructor(e){super(e,"Earth"),this._visibleNodesNorth={},this._visibleNodesSouth={}}collectVisibleNode(e){let t=e.segment._tileGroup;t===ea?this._visibleNodesNorth[e.nodeId]=e:t===ta?this._visibleNodesSouth[e.nodeId]=e:this._visibleNodes[e.nodeId]=e}_clearVisibleNodes(){super._clearVisibleNodes(),this._visibleNodesNorth={},this._visibleNodesSouth={}}createEntitiCollectionsTreeStrategy(e,t){return new Pa(e,t)}init(){this._quadTreeList=[new ya(_a,this.planet,0,null,0,te.createFromArray([-20037508.34,-20037508.34,20037508.34,20037508.34])),new ya(Ea,this.planet,0,null,0,te.createFromArray([-180,Q,180,90])),new ya(Ea,this.planet,0,null,0,te.createFromArray([-180,-90,180,J]))]}getTileXY(e,t){let i=function(e,t=Q){return e>t?ea:e<-t?ta:0}(e.lat,Q),s=t,n=-1,r=-1,o=1<<s;if(i===ea)n=Qo(e.lon,360/o,-180),r=Qo(e.lat,(90-Q)/o,90);else if(i===ta)n=Qo(e.lon,360/o,-180),r=Qo(e.lat,(90-Q)/o,J);else{let t=q(e);n=Qo(t.lon,D/o,-z),r=Qo(t.lat,D/o,z)}return[n,r,s,i]}getLonLatTileOffset(e,t,i,s,n){let r=e,o=new te;if(e.lat>Q){o=Jo(t,i,s,te.createFromArray([-180,Q,180,90]))}else if(e.lat<J){o=Jo(t,i,s,te.createFromArray([-180,-90,180,J]))}else r=q(e),o=K(t,i,s);let a=o.getWidth()/(n-1),l=o.getHeight()/(n-1);return[n-Math.ceil((r.lat-o.southWest.lat)/l)-1,Math.floor((r.lon-o.southWest.lon)/a)]}}class Ma{constructor(e={}){this.model=e.model||null,this.src=e.src||null,this._cached_ix=0,this._cached_iy=0,this._v00=0,this._v01=0,this._v10=0,this._v11=0,this._t=0}static loadModel(e){return e?fetch(e,{}).then((e=>{if(!e.ok)throw Error("Geoid model file: HTTP error "+e.status);return e.arrayBuffer()})).then((t=>{if(t)return new Uint8Array(t);throw Error("Geoid model file: no data from "+e)})).then((function(e){if(80!==e[0]||53!==e[1]||(13!==e[2]||10!==e[3])&&10!==e[2])throw new Error("Geoid model file: no PGM header");var t,i,s=13===e[2]?4:3,n=null,r=null;function o(){let t=s;for(var i=s;;i++){if(i>=e.length)throw new Error("Geoid model file: missing newline in header");if(10===e[i]){s=i+1;break}}return i>t&&13===e[i-1]&&i--,String.fromCharCode.apply(null,e.slice(t,i))}for(;"#"===(i=o())[0];)if(t=i.match(/^# Offset (.*)$/)){if(n=parseInt(t[1],10),!isFinite(n))throw new Error("Geoid model file: bad offset "+t[1])}else if((t=i.match(/^# Scale (.*)$/))&&(r=parseFloat(t[1]),!isFinite(r)))throw new Error("Geoid model file: bad scale "+t[1]);let a=0,l=0;if((t=i.match(/^\s*(\d+)\s+(\d+)\s*$/))&&(a=parseInt(t[1],10),l=parseInt(t[2],10)),!(t&&a>=0&&l>=0))throw new Error("Geoid model file: bad PGM width&height line");if(65535!=parseInt(o()))throw new Error("Geoid model file: PGM file must have 65535 gray levels");if(null===n)throw new Error("Geoid model file: PGM file does not contain offset");if(null===r)throw new Error("Geoid model file: PGM file does not contain scale");if(a<2||l<2)throw new Error("Geoid model file: Raster size too small");if(e.length-s!==a*l*2)throw new Error("Geoid model file: File has the wrong length");return{scale:r,offset:n,width:a,height:l,rlonres:a/360,rlatres:(l-1)/180,i:s,rawfile:e}})):new Promise((e=>{e(null)}))}setModel(e){this.model=e}_rawval(e,t){let i=this.model;t<0?(t=-t,e+=i.width/2):t>=i.height&&(t=2*(i.height-1)-t,e+=i.width/2),e<0?e+=i.width:e>=i.width&&(e-=i.width);let s=2*(t*i.width+e)+i.i;return i.rawfile[s]<<8|i.rawfile[s+1]}getHeightLonLat(e){return this.getHeight(e.lon,e.lat)}getHeight(e,t){if(!this.model)return 0;let i=this.model;e<0&&(e+=360);let s=(90-t)*i.rlatres,n=e*i.rlonres,r=Math.floor(s),o=Math.floor(n);n-=o,s-=r,r===i.height-1&&r--,this._cached_ix===o&&this._cached_iy===r||(this._cached_ix=o,this._cached_iy=r,this._v00=this._rawval(o,r),this._v01=this._rawval(o+1,r),this._v10=this._rawval(o,r+1),this._v11=this._rawval(o+1,r+1));let a=(1-s)*((1-n)*this._v00+n*this._v01)+s*((1-n)*this._v10+n*this._v11);return i.offset+i.scale*a}}class Ra{constructor(e,t=5){this.MAX_FRAMES=t,this._gridSize=64,this._planet=e,this._framebuffer=null,this._framebufferMercProj=null,this._texCoordsBuffer=null,this._indexBuffer=null,this._currentFrame=0,this._queue=[],this._animate=[],this._quadTexCoordsBuffer=null,this._quadVertexBuffer=null}init(){this._initShaders(),this._initBuffers()}createGridBuffer(e,t=!1){let i=this._gridSize,s=new I((e[3].lon-e[0].lon)/i,(e[3].lat-e[0].lat)/i),n=new I((e[2].lon-e[1].lon)/i,(e[2].lat-e[1].lat)/i),r=new I((e[1].lon-e[0].lon)/i,(e[1].lat-e[0].lat)/i),o=new I((e[2].lon-e[3].lon)/i,(e[2].lat-e[3].lat)/i);const a=(i+1)*(i+1)*2,l=a/2;let h=new Float32Array(a),c=new Float32Array(a),d=new Array(l),_=0,u=0,g=0,f=new Float32Array(2);for(let t=0;t<=i;t++){let a=new I(e[0].lon+t*s.lon,e[0].lat+t*s.lat),l=new I(e[1].lon+t*n.lon,e[1].lat+t*n.lat);for(let t=0;t<=i;t++){let i=ze(a,l,new I(e[0].lon+t*r.lon,e[0].lat+t*r.lat),new I(e[3].lon+t*o.lon,e[3].lat+t*o.lat));ms(i.lon,f),h[_++]=f[0],c[u++]=f[1],ms(i.lat,f),h[_++]=f[0],c[u++]=f[1],d[g++]=i}}if(t)for(let e=0;e<l;e++){let t=d[e].forwardMercator();ms(t.lon,f),h[2*e]=f[0],c[2*e]=f[1],ms(t.lat,f),h[2*e+1]=f[0],c[2*e+1]=f[1]}return[this._planet.renderer.handler.createArrayBuffer(h,2,l),this._planet.renderer.handler.createArrayBuffer(c,2,l)]}frame(){let e=this.MAX_FRAMES;for(;e--&&this._queue.length;){const e=this._queue.shift();e._isRendering=!1,e.rendering(),e.events.dispatch(e.events.loadend)}for(e=this._animate.length;e--;)this._animate[e].rendering()}add(e){e._isRendering||(e._isRendering=!0,e._animate?this._animate.push(e):this._queue.push(e))}remove(e){if(e._isRendering){let t;e._creationProceeding=!1,e._isRendering=!1,t=e._animate?this._animate:this._queue;for(let i=0;i<t.length;i++)if(t[i].isEqual(e))return void t.splice(i,1)}}_initBuffers(){let e=this._planet.renderer.handler;this._framebuffer=new Yo(e,{width:2,height:2,useDepth:!1}),this._framebuffer.init(),this._framebufferMercProj=new Yo(e,{width:2,height:2,useDepth:!1}),this._framebufferMercProj.init();let t=Math.log2(this._gridSize);this._texCoordsBuffer=this._planet._textureCoordsBufferCache[t],this._indexBuffer=this._planet._indexesCache[t][t][t][t][t].buffer,this._quadTexCoordsBuffer=e.createArrayBuffer(new Float32Array([0,1,1,1,0,0,1,0]),2,4),this._quadVertexBuffer=e.createArrayBuffer(new Float32Array([-1,1,1,1,-1,-1,1,-1]),2,4)}_initShaders(){this._planet.renderer.handler.addProgram(new Ni("geoImageTransform",{uniforms:{sourceTexture:"sampler2d",extentParamsHigh:"vec4",extentParamsLow:"vec4",isFullExtent:"bool"},attributes:{cornersHigh:"vec2",cornersLow:"vec2",texCoords:"vec2"},vertexShader:"attribute vec2 cornersHigh; \n attribute vec2 cornersLow;\n attribute vec2 texCoords; \n uniform vec4 extentParamsHigh; \n uniform vec4 extentParamsLow; \n varying vec2 v_texCoords;\n void main() { \n v_texCoords = texCoords; \n vec2 highDiff = cornersHigh - extentParamsHigh.xy;\n vec2 lowDiff = cornersLow - extentParamsLow.xy; \n gl_Position = vec4((-1.0 + (highDiff * step(1.0, length(highDiff)) + lowDiff) * extentParamsHigh.zw) * vec2(1.0, -1.0), 0.0, 1.0); \n }",fragmentShader:"precision highp float;\n uniform sampler2D sourceTexture;\n uniform bool isFullExtent;\n varying vec2 v_texCoords;\n void main () {\n if(!isFullExtent && (v_texCoords.x <= 0.001 || v_texCoords.x >= 0.999 ||\n v_texCoords.y <= 0.001 || v_texCoords.y >= 0.999)) {\n discard;\n }\n gl_FragColor = texture2D(sourceTexture, v_texCoords);\n }"}))}}const Ba=["loadend","layerloadend"];class ka{constructor(e=24){this.MAX_REQUESTS=e,this.events=Mt(Ba),this._loading=0,this._queue=[],this._senderRequestCounter=[],this._promises={json:e=>e.json(),blob:e=>e.blob(),arrayBuffer:e=>e.arrayBuffer(),imageBitmap:e=>e.blob().then((e=>createImageBitmap(e,{premultiplyAlpha:"premultiply"}))),text:e=>e.text()}}load(e,t){e.sender&&(this._senderRequestCounter[e.sender.__id]||(this._senderRequestCounter[e.sender.__id]={sender:e.sender,counter:0,__requestCounterFrame__:0}),this._senderRequestCounter[e.sender.__id].counter++),this._queue.push({params:e,callback:t}),this._exec()}fetch(e){return fetch(e.src,e.options||{}).then((t=>{if(!t.ok)throw Error(`Unable to load '${e.src}'`);return this._promises[e.type||"blob"](t)})).then((e=>({status:"ready",data:e}))).catch((e=>({status:"error",msg:e.toString()})))}getRequestCounter(e){if(e){let t=this._senderRequestCounter[e.__id];if(t)return t.counter}return 0}isIdle(e){return e.isIdle}_checkLoadend(e,t){0!==e.counter||t._planet&&!t._planet._terrainCompletedActivated?e.__requestCounterFrame__=requestAnimationFrame((()=>{this._checkLoadend(e,t)})):(t.events.dispatch(t.events.loadend,t),this.events.dispatch(this.events.layerloadend,t),e.__requestCounterFrame__=0)}_handleResponse(e,t){e.callback(t);let i=e.params.sender;if(i&&(i.events.loadend.handlers.length||this.events.layerloadend.handlers.length)){let e=this._senderRequestCounter[i.__id];e&&e.counter>0&&(e.counter--,cancelAnimationFrame(e.__requestCounterFrame__),e.__requestCounterFrame__=requestAnimationFrame((()=>{this._checkLoadend(e,i)})))}this._exec()}_exec(){if(this._queue.length>0&&this._loading<this.MAX_REQUESTS){let e=this._queue.pop();if(!e)return;let t=e.params;if(!t.filter||t.filter(t))return this._loading++,fetch(t.src,t.options||{}).then((e=>{if(!e.ok)throw Error(`Unable to load '${t.src}'`);return this._promises[t.type||"blob"](e)})).then((t=>{this._loading--,this._handleResponse(e,{status:"ready",data:t})})).catch((t=>{this._loading--,this._handleResponse(e,{status:"error",msg:t.toString()})}));this._handleResponse(e,{status:"abort"})}else 0===this._loading&&this.events.dispatch(this.events.loadend)}abort(e){this._senderRequestCounter[e.__id]&&(this._senderRequestCounter[e.__id].counter=0,cancelAnimationFrame(this._senderRequestCounter[e.__id].__requestCounterFrame__),this._senderRequestCounter[e.__id].__requestCounterFrame__=0);for(let t=0,i=this._queue.length;t<i;t++){let i=this._queue[t];i&&i.params.sender&&e.isEqual(i.params.sender)&&(i.callback({status:"abort"}),this._queue[t]=null)}}abortAll(){for(let e=0,t=this._queue.length;e<t;e++){let t=this._queue[e];if(t){let i=t.params.sender;i&&this._senderRequestCounter[i.__id]&&(this._senderRequestCounter[i.__id].counter=0,cancelAnimationFrame(this._senderRequestCounter[i.__id].__requestCounterFrame__),this._senderRequestCounter[i.__id].__requestCounterFrame__=0),t.callback({status:"abort"}),this._queue[e]=null}}this._queue=[]}get loading(){return this._loading}get queue(){return this._queue}}class Ia{constructor(e,t={}){this._minTabelSize=t.minTableSize||1,this._maxTableSize=t.maxTableSize||8,this._planet=e,this._handler=null,this._verticesBufferArray=[],this._indexBufferArray=[],this._positionBuffer=null,this._framebuffer=null,this._normalMapVerticesTexture=null,this._width=t.width||128,this._height=t.height||128,this._queue=new xa(1024),this._lock=new Rn}get width(){return this._width}get height(){return this._height}init(){this._maxTableSize=this._planet.maxGridSize||8,this._handler=this._planet.renderer.handler;const e=new Ni("normalMapBlur",{attributes:{a_position:"vec2"},uniforms:{s_texture:"sampler2d"},vertexShader:`attribute vec2 a_position;\n attribute vec2 a_texCoord;\n\n varying vec2 blurCoordinates[5];\n\n void main() {\n vec2 vt = a_position * 0.5 + 0.5; \n \n gl_Position = vec4(a_position, 0.0, 1.0);\n blurCoordinates[0] = vt;\n blurCoordinates[1] = vt + ${1/this._width*1.407333};\n blurCoordinates[2] = vt - ${1/this._height*1.407333};\n blurCoordinates[3] = vt + ${1/this._width*3.294215};\n blurCoordinates[4] = vt - ${1/this._height*3.294215};\n }`,fragmentShader:"precision lowp float;\n uniform sampler2D s_texture; \n varying vec2 blurCoordinates[5]; \n\n void main() {\n lowp vec4 sum = vec4(0.0);\n //if(blurCoordinates[0].x <= 0.01 || blurCoordinates[0].x >= 0.99 ||\n // blurCoordinates[0].y <= 0.01 || blurCoordinates[0].y >= 0.99){\n // sum = texture2D(s_texture, blurCoordinates[0]);\n //} else {\n sum += texture2D(s_texture, blurCoordinates[0]) * 0.204164;\n sum += texture2D(s_texture, blurCoordinates[1]) * 0.304005;\n sum += texture2D(s_texture, blurCoordinates[2]) * 0.304005;\n sum += texture2D(s_texture, blurCoordinates[3]) * 0.093913;\n sum += texture2D(s_texture, blurCoordinates[4]) * 0.093913;\n //}\n gl_FragColor = sum;\n }"}),t=new Ni("normalMap",{attributes:{a_position:"vec2",a_normal:"vec3"},uniforms:{},vertexShader:"attribute vec2 a_position;\n attribute vec3 a_normal;\n \n varying vec3 v_color;\n \n void main() {\n gl_Position = vec4(a_position, 0, 1);\n v_color = normalize(a_normal) * 0.5 + 0.5;\n }",fragmentShader:"precision highp float;\n \n varying vec3 v_color;\n \n void main () {\n gl_FragColor = vec4(v_color, 1.0);\n }"});this._handler.addProgram(e),this._handler.addProgram(t),this._framebuffer=new Yo(this._handler,{width:this._width,height:this._height,useDepth:!1}),this._framebuffer.init(),this._normalMapVerticesTexture=this._handler.createEmptyTexture_l(this._width,this._height);for(let e=this._minTabelSize;e<=this._maxTableSize;e++){const t=1<<e,i=t/2;let s=new Float32Array((t+1)*(t+1)*2);for(let e=0;e<=t;e++)for(let n=0;n<=t;n++){let r=2*(e*(t+1)+n);s[r]=n/i-1,s[r+1]=e/i-1}this._verticesBufferArray[t]=this._handler.createArrayBuffer(s,2,s.length/2),this._indexBufferArray[t]=this._planet._indexesCache[Math.log2(t)][Math.log2(t)][Math.log2(t)][Math.log2(t)][Math.log2(t)].buffer}const i=new Float32Array([-1,-1,1,-1,-1,1,1,1]);this._positionBuffer=this._handler.createArrayBuffer(i,2,i.length/2)}_drawNormalMapBlur(e){let t=e.normalMapNormals;if(e.node&&0!==e.node.getState()&&t&&t.length){const i=t.length/3,s=Math.sqrt(i)-1;let n=this._verticesBufferArray[s];if(n){e.planet.terrain.equalizeNormals&&(e._normalMapEdgeEqualize(0),e._normalMapEdgeEqualize(2),e._normalMapEdgeEqualize(3),e._normalMapEdgeEqualize(1));let r=e.normalMapTexturePtr;const o=this._handler,a=o.gl;let l=o.createArrayBuffer(t,3,i,a.DYNAMIC_DRAW);const h=this._framebuffer;let c=o.programs.normalMap,d=c._program.attributes;return h.bindOutputTexture(this._normalMapVerticesTexture),c.activate(),a.bindBuffer(a.ARRAY_BUFFER,n),a.vertexAttribPointer(d.a_position,n.itemSize,a.FLOAT,!1,0,0),a.bindBuffer(a.ARRAY_BUFFER,l),a.vertexAttribPointer(d.a_normal,l.itemSize,a.FLOAT,!1,0,0),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this._indexBufferArray[s]),a.drawElements(a.TRIANGLE_STRIP,this._indexBufferArray[s].numItems,a.UNSIGNED_INT,0),a.deleteBuffer(l),h.bindOutputTexture(r),c=o.programs.normalMapBlur,c.activate(),a.bindBuffer(a.ARRAY_BUFFER,this._positionBuffer),a.vertexAttribPointer(c._program.attributes.a_position,this._positionBuffer.itemSize,a.FLOAT,!1,0,0),a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D,this._normalMapVerticesTexture),a.uniform1i(c._program.uniforms.s_texture,0),a.drawArrays(a.TRIANGLE_STRIP,0,this._positionBuffer.numItems),!0}return!0}return!1}_drawNormalMapNoBlur(e){let t=e.normalMapNormals;if(e.node&&0!==e.node.getState()&&t&&t.length){const i=t.length/3,s=Math.sqrt(i)-1;let n=this._verticesBufferArray[s];if(n){e.planet.terrain.equalizeNormals&&(e._normalMapEdgeEqualize(0),e._normalMapEdgeEqualize(2),e._normalMapEdgeEqualize(3),e._normalMapEdgeEqualize(1));let r=e.normalMapTexturePtr;const o=this._handler,a=o.gl;let l=o.createArrayBuffer(t,3,i,a.DYNAMIC_DRAW);const h=this._framebuffer,c=o.programs.normalMap,d=c._program.attributes;return h.bindOutputTexture(r),c.activate(),a.bindBuffer(a.ARRAY_BUFFER,n),a.vertexAttribPointer(d.a_position,n.itemSize,a.FLOAT,!1,0,0),a.bindBuffer(a.ARRAY_BUFFER,l),a.vertexAttribPointer(d.a_normal,l.itemSize,a.FLOAT,!1,0,0),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this._indexBufferArray[s]),a.drawElements(a.TRIANGLE_STRIP,this._indexBufferArray[s].numItems,a.UNSIGNED_INT,0),a.deleteBuffer(l),!0}return!0}return!1}_drawNormalMap(e){return e.planet.terrain.isBlur(e)?this._drawNormalMapBlur(e):this._drawNormalMapNoBlur(e)}drawSingle(e){const t=this._handler.gl;this._framebuffer.activate(),t.disable(t.CULL_FACE),t.disable(t.DEPTH_TEST),t.disable(t.BLEND),e.terrainReady&&this._drawNormalMap(e)&&(e.normalMapReady=!0,e.normalMapTexture=e.normalMapTexturePtr,e.normalMapTextureBias[0]=0,e.normalMapTextureBias[1]=0,e.normalMapTextureBias[2]=1),e._inTheQueue=!1,t.enable(t.DEPTH_TEST),t.enable(t.CULL_FACE),t.enable(t.BLEND),this._framebuffer.deactivate()}frame(){if(this._queue.length){const e=this._handler.gl;this._framebuffer.activate(),e.disable(e.CULL_FACE),e.disable(e.DEPTH_TEST),e.disable(e.BLEND);let t=0,i=window.performance.now();for(;this._lock.isFree()&&this._queue.length&&t<.25;){const e=this._queue.shift();e.terrainReady&&this._drawNormalMap(e)&&(e.normalMapReady=!0,e.normalMapTexture=e.normalMapTexturePtr,e.normalMapTextureBias[0]=0,e.normalMapTextureBias[1]=0,e.normalMapTextureBias[2]=1),e._inTheQueue=!1,t=window.performance.now()-i}e.enable(e.BLEND),e.enable(e.DEPTH_TEST),e.enable(e.CULL_FACE),this._framebuffer.deactivate()}}get queueSize(){return this._queue.length}queue(e){e._inTheQueue=!0,this._queue.push(e)}unshift(e){e._inTheQueue=!0,this._queue.unshift(e)}remove(e){}clear(){for(;this._queue.length;){this._queue.pop()._inTheQueue=!1}}lock(e){this._lock.lock(e)}free(e){this._lock.free(e)}}const za=new Xo({code:"equi",units:Wo});class Da extends ei{constructor(e=2){super(e,Fa)}_onMessage(e){this._source.get(e.data.id)._plainSegmentWorkerCallback(e.data),e.data.plainVertices=null,e.data.plainVerticesHigh=null,e.data.plainVerticesLow=null,e.data.plainNormals=null,e.data.normalMapNormals=null,e.data.normalMapVertices=null,e.data.normalMapVerticesHigh=null,e.data.normalMapVerticesLow=null,this._source.delete(e.data.id)}setGeoid(e){if(e.model){let t=e.model,i={scale:t.scale,offset:t.offset,width:t.width,height:t.height,rlonres:t.rlonres,rlatres:t.rlatres,i:t.i};this._workerQueue.forEach((e=>{let s=new Uint8Array(t.rawfile.length);s.set(t.rawfile),e.postMessage({model:i,rawfile:s},[s.buffer])}))}else this._workerQueue.forEach((e=>{e.postMessage({model:null})}))}make(e){if(e.initialized)if(this._workerQueue.length){let t=this._workerQueue.pop();this._source.set(this._sourceId,e);let i=e._projection.id===Ca.id||e._projection.id===za.id?1:0,s=new Float64Array([this._sourceId,i,e.planet.terrain.gridSizeByZoom[e.tileZoom],e.planet.terrain.plainGridSize,e._extent.southWest.lon,e._extent.southWest.lat,e._extent.northEast.lon,e._extent.northEast.lat,e.planet.ellipsoid._e2,e.planet.ellipsoid.equatorialSize,e.planet.ellipsoid._invRadii2.x,e.planet.ellipsoid._invRadii2.y,e.planet.ellipsoid._invRadii2.z,e.planet._heightFactor]);this._sourceId++,t.postMessage({params:s},[s.buffer])}else this._pendingQueue.push(e);else this.check()}}const Fa="\n 'use strict';\n \n let model = null;\n\n let cached_ix = null;\n let cached_iy = null;\n let v00 = null;\n let v01 = null;\n let v10 = null;\n let v11 = null;\n let t = null;\n\n function rawval(ix, iy) {\n\n if (iy < 0) {\n iy = -iy;\n ix += model.width / 2;\n } else if (iy >= model.height) {\n iy = 2 * (model.height - 1) - iy;\n ix += model.width / 2;\n }\n\n if (ix < 0) {\n ix += model.width;\n } else if (ix >= model.width) {\n ix -= model.width;\n }\n\n var k = (iy * model.width + ix) * 2 + model.i;\n\n return (model.rawfile[k] << 8) | model.rawfile[k + 1];\n };\n\n function getHeightMSL(lon, lat) {\n\n if (!model) return 0;\n\n if (lon < 0) lon += 360.0;\n\n var fy = (90 - lat) * model.rlatres;\n var fx = lon * model.rlonres;\n var iy = Math.floor(fy);\n var ix = Math.floor(fx);\n\n fx -= ix;\n fy -= iy;\n\n if (iy === (model.height - 1)) {\n iy--;\n }\n\n if ((cached_ix !== ix) || (cached_iy !== iy)) {\n\n cached_ix = ix;\n cached_iy = iy;\n\n v00 = rawval(ix, iy);\n v01 = rawval(ix + 1, iy);\n v10 = rawval(ix, iy + 1);\n v11 = rawval(ix + 1, iy + 1);\n }\n\n let h = null;\n\n var a = (1 - fx) * v00 + fx * v01;\n var b = (1 - fx) * v10 + fx * v11;\n\n h = (1 - fy) * a + fy * b;\n\n return model.offset + model.scale * h;\n };\n\n const HALF_PI = Math.PI * 0.5;\n const POLE = 20037508.34;\n const PI_BY_POLE = Math.PI / POLE;\n const INV_POLE_BY_180 = 180.0 / POLE;\n const INV_PI_BY_180 = 180.0 / Math.PI;\n const INV_PI_BY_180_HALF_PI = INV_PI_BY_180 * HALF_PI;\n const RADIANS = Math.PI / 180.0;\n const INV_PI_BY_360 = INV_PI_BY_180 * 2.0;\n\n let E2 = 0.0,\n A = 0.0;\n\n let _projFunc = null;\n\n const Vec3 = function (x, y, z) {\n this.x = x;\n this.y = y;\n this.z = z;\n };\n\n var geodeticToCartesian = function (lon, lat, heightFactor, res) {\n\n let h = getHeightMSL(lon, lat) * heightFactor;\n\n let latrad = RADIANS * lat,\n lonrad = RADIANS * lon;\n\n let slt = Math.sin(latrad);\n\n let N = A / Math.sqrt(1.0 - E2 * slt * slt);\n let nc = (N + h) * Math.cos(latrad); \n \n res.x = nc * Math.cos(lonrad);\n res.y = nc * Math.sin(lonrad);\n res.z = (N * (1 - E2) + h) * slt;\n };\n\n var geodeticToCartesianInverse = function (lon, lat, heightFactor, res){\n geodeticToCartesian(\n lon * INV_POLE_BY_180,\n INV_PI_BY_360 * Math.atan(Math.exp(lat * PI_BY_POLE)) - INV_PI_BY_180_HALF_PI,\n heightFactor,\n res);\n };\n\n var v = new Vec3(0.0, 0.0, 0.0);\n var _tempHigh = new Vec3(0.0, 0.0, 0.0);\n var _tempLow = new Vec3(0.0, 0.0, 0.0);\n\n var doubleToTwoFloats = function(v, high, low) {\n\n let x = v.x, y = v.y, z = v.z;\n \n if (x >= 0.0) {\n var doubleHigh = Math.floor(x / 65536.0) * 65536.0;\n high.x = Math.fround(doubleHigh);\n low.x = Math.fround(x - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-x / 65536.0) * 65536.0;\n high.x = Math.fround(-doubleHigh);\n low.x = Math.fround(x + doubleHigh);\n }\n\n if (y >= 0.0) {\n var doubleHigh = Math.floor(y / 65536.0) * 65536.0;\n high.y = Math.fround(doubleHigh);\n low.y = Math.fround(y - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-y / 65536.0) * 65536.0;\n high.y = Math.fround(-doubleHigh);\n low.y = Math.fround(y + doubleHigh);\n }\n\n if (z >= 0.0) {\n var doubleHigh = Math.floor(z / 65536.0) * 65536.0;\n high.z = Math.fround(doubleHigh);\n low.z = Math.fround(z - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-z / 65536.0) * 65536.0;\n high.z = Math.fround(-doubleHigh);\n low.z = Math.fround(z + doubleHigh);\n }\n };\n\n self.onmessage = function (msg) {\n if(msg.data.model) {\n model = msg.data.model;\n model.rawfile = msg.data.rawfile;\n } else if(msg.data.params) {\n\n let xmin = 549755748352.0, xmax = -549755748352.0, \n ymin = 549755748352.0, ymax = -549755748352.0, \n zmin = 549755748352.0, zmax = -549755748352.0;\n\n E2 = msg.data.params[8];\n A = msg.data.params[9];\n\n let gridSize = msg.data.params[2],\n fgs = msg.data.params[3],\n r2_x = msg.data.params[10],\n r2_y = msg.data.params[11],\n r2_z = msg.data.params[12];\n\n let heightFactor = msg.data.params[13];\n \n if(msg.data.params[1] === 0.0){\n _projFunc = geodeticToCartesianInverse;\n }else{\n _projFunc = geodeticToCartesian;\n }\n\n let maxFgs = Math.max(fgs, gridSize);\n let llStep = (msg.data.params[6] - msg.data.params[4]) / maxFgs;\n let ltStep = (msg.data.params[7] - msg.data.params[5]) / maxFgs;\n\n let esw_lon = msg.data.params[4],\n ene_lat = msg.data.params[7];\n\n let dg = Math.max(fgs / gridSize, 1.0),\n gs = maxFgs + 1;\n \n const gsgs = gs * gs;\n\n const gridSize3 = (gridSize + 1) * (gridSize + 1) * 3;\n\n let plainNormals = new Float32Array(gridSize3);\n\n let plainVertices = new Float64Array(gridSize3);\n let plainVerticesHigh = new Float32Array(gridSize3);\n let plainVerticesLow = new Float32Array(gridSize3);\n\n let normalMapNormals = new Float32Array(gsgs * 3);\n\n let normalMapVertices = new Float64Array(gsgs * 3);\n let normalMapVerticesHigh = new Float32Array(gsgs * 3);\n let normalMapVerticesLow = new Float32Array(gsgs * 3);\n\n let ind = 0,\n nmInd = 0;\n\n for (let k = 0; k < gsgs; k++) {\n\n let j = k % gs,\n i = ~~(k / gs);\n\n _projFunc(esw_lon + j * llStep, ene_lat - i * ltStep, heightFactor, v);\n\n let nx = v.x * r2_x, ny = v.y * r2_y, nz = v.z * r2_z;\n let l = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz); \n let nxl = nx * l,\n nyl = ny * l,\n nzl = nz * l;\n\n doubleToTwoFloats(v, _tempHigh, _tempLow);\n\n normalMapVertices[nmInd] = v.x;\n normalMapVerticesHigh[nmInd] = _tempHigh.x;\n normalMapVerticesLow[nmInd] = _tempLow.x;\n normalMapNormals[nmInd++] = nxl;\n\n normalMapVertices[nmInd] = v.y;\n normalMapVerticesHigh[nmInd] = _tempHigh.y;\n normalMapVerticesLow[nmInd] = _tempLow.y;\n normalMapNormals[nmInd++] = nyl;\n\n normalMapVertices[nmInd] = v.z;\n normalMapVerticesHigh[nmInd] = _tempHigh.z;\n normalMapVerticesLow[nmInd] = _tempLow.z;\n normalMapNormals[nmInd++] = nzl;\n\n if (i % dg === 0 && j % dg === 0) {\n plainVertices[ind] = v.x;\n plainVerticesHigh[ind] = _tempHigh.x;\n plainVerticesLow[ind] = _tempLow.x;\n plainNormals[ind++] = nxl;\n\n plainVertices[ind] = v.y;\n plainVerticesHigh[ind] = _tempHigh.y;\n plainVerticesLow[ind] = _tempLow.y;\n plainNormals[ind++] = nyl;\n\n plainVertices[ind] = v.z;\n plainVerticesHigh[ind] = _tempHigh.z;\n plainVerticesLow[ind] = _tempLow.z;\n plainNormals[ind++] = nzl;\n\n if (v.x < xmin) xmin = v.x; if (v.x > xmax) xmax = v.x;\n if (v.y < ymin) ymin = v.y; if (v.y > ymax) ymax = v.y;\n if (v.z < zmin) zmin = v.z; if (v.z > zmax) zmax = v.z;\n }\n }\n\n let x = (xmax - xmin) * 0.5,\n y = (ymax - ymin) * 0.5,\n z = (zmax - zmin) * 0.5;\n\n let plainRadius = Math.sqrt(x * x + y * y + z * z);\n\n self.postMessage({\n id: msg.data.params[0],\n plainVertices: plainVertices,\n plainVerticesHigh: plainVerticesHigh,\n plainVerticesLow: plainVerticesLow,\n plainNormals: plainNormals,\n normalMapNormals: normalMapNormals,\n normalMapVertices: normalMapVertices,\n normalMapVerticesHigh: normalMapVerticesHigh,\n normalMapVerticesLow: normalMapVerticesLow,\n plainRadius: plainRadius\n }, [\n plainVertices.buffer,\n plainVerticesHigh.buffer,\n plainVerticesLow.buffer,\n plainNormals.buffer,\n normalMapNormals.buffer,\n normalMapVertices.buffer,\n normalMapVerticesHigh.buffer,\n normalMapVerticesLow.buffer\n ]);\n }\n }";function Na(e){let t=1/Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);e[0]*=t,e[1]*=t,e[2]*=t,e[3]*=t}class Ha{constructor(e={}){this._pickingColorU=new Float32Array([0,0,0]),this._f=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]],this.projectionMatrix=new ne,this.inverseProjectionMatrix=new ne,this.projectionViewMatrix=new ne,this.projectionViewRTEMatrix=new ne,this.inverseProjectionViewMatrix=new ne,this.left=0,this.right=0,this.bottom=0,this.top=0,this.near=0,this.far=0,this.cameraFrustumIndex=null!=e.cameraFrustumIndex?e.cameraFrustumIndex:-1,this.setProjectionMatrix(e.fov||30,e.aspect||1,e.near||1,e.far||1e3)}getRightPlane(){return this._f[0]}getLeftPlane(){return this._f[1]}getBottomPlane(){return this._f[2]}getTopPlane(){return this._f[3]}getBackwardPlane(){return this._f[4]}getForwardPlane(){return this._f[5]}getProjectionViewMatrix(){return this.projectionViewMatrix._m}getProjectionViewRTEMatrix(){return this.projectionViewRTEMatrix._m}getProjectionMatrix(){return this.projectionMatrix._m}getInverseProjectionMatrix(){return this.inverseProjectionMatrix._m}setProjectionMatrix(e,t,i,s){this.top=i*Math.tan(e*d),this.bottom=-this.top,this.right=this.top*t,this.left=-this.right,this.near=i,this.far=s,this.projectionMatrix.setPerspective(this.left,this.right,this.bottom,this.top,i,s),this.projectionMatrix.inverseTo(this.inverseProjectionMatrix)}setProjectionViewRTEMatrix(e){this.projectionViewRTEMatrix=this.projectionMatrix.mul(e)}setViewMatrix(e){this.projectionViewMatrix=this.projectionMatrix.mul(e),this.projectionViewMatrix.inverseTo(this.inverseProjectionViewMatrix);let t=this.projectionViewMatrix._m;this._f[0][0]=t[3]-t[0],this._f[0][1]=t[7]-t[4],this._f[0][2]=t[11]-t[8],this._f[0][3]=t[15]-t[12],Na(this._f[0]),this._f[1][0]=t[3]+t[0],this._f[1][1]=t[7]+t[4],this._f[1][2]=t[11]+t[8],this._f[1][3]=t[15]+t[12],Na(this._f[1]),this._f[2][0]=t[3]+t[1],this._f[2][1]=t[7]+t[5],this._f[2][2]=t[11]+t[9],this._f[2][3]=t[15]+t[13],Na(this._f[2]),this._f[3][0]=t[3]-t[1],this._f[3][1]=t[7]-t[5],this._f[3][2]=t[11]-t[9],this._f[3][3]=t[15]-t[13],Na(this._f[3]),this._f[4][0]=t[3]-t[2],this._f[4][1]=t[7]-t[6],this._f[4][2]=t[11]-t[10],this._f[4][3]=t[15]-t[14],Na(this._f[4]),this._f[5][0]=t[3]+t[2],this._f[5][1]=t[7]+t[6],this._f[5][2]=t[11]+t[10],this._f[5][3]=t[15]+t[14],Na(this._f[5])}containsPoint(e){for(let t=0;t<6;t++){if(e.dotArr(this._f[t])+this._f[t][3]<=0)return!1}return!0}containsSphereBottomExc(e){let t=-e.radius,i=this._f;return!(e.center.dotArr(i[0])+i[0][3]<=t)&&(!(e.center.dotArr(i[1])+i[1][3]<=t)&&(!(e.center.dotArr(i[3])+i[3][3]<=t)&&(!(e.center.dotArr(i[4])+i[4][3]<=t)&&!(e.center.dotArr(i[5])+i[5][3]<=t))))}containsSphereButtom(e){let t=-e.radius,i=this._f;return!(e.center.dotArr(i[2])+i[2][3]<=t)}containsSphere(e){let t=-e.radius,i=this._f;return!(e.center.dotArr(i[0])+i[0][3]<=t)&&(!(e.center.dotArr(i[1])+i[1][3]<=t)&&(!(e.center.dotArr(i[2])+i[2][3]<=t)&&(!(e.center.dotArr(i[3])+i[3][3]<=t)&&(!(e.center.dotArr(i[4])+i[4][3]<=t)&&!(e.center.dotArr(i[5])+i[5][3]<=t)))))}containsSphere2(e,t){let i=-t;return!(e.dotArr(this._f[0])+this._f[0][3]<=i)&&(!(e.dotArr(this._f[1])+this._f[1][3]<=i)&&(!(e.dotArr(this._f[2])+this._f[2][3]<=i)&&(!(e.dotArr(this._f[3])+this._f[3][3]<=i)&&(!(e.dotArr(this._f[4])+this._f[4][3]<=i)&&!(e.dotArr(this._f[5])+this._f[5][3]<=i)))))}containsBox(e){let t,i,s=!0;for(let n=0;n<6;n++){t=0,i=0;for(let s=0;s<8&&(0===i||0===t);s++){e.vertices[s].dotArr(this._f[n])+this._f[n][3]<0?t++:i++}if(0===i)return!1;t>0&&(s=!0)}return s}}const Oa=["viewchange","moveend"];class Va{constructor(e,t={}){if(this.renderer=e,this.events=Mt(Oa,this),this.eye=t.eye||new oe,this.eyeHigh=new Float32Array(3),this.eyeLow=new Float32Array(3),this._aspect=t.aspect||1,this._viewAngle=t.viewAngle||47,this._viewMatrix=new ne,this._viewMatrixRTE=new ne,this._normalMatrix=new ie,this._r=new oe(1,0,0),this._u=new oe(0,1,0),this._b=new oe(0,0,1),this._f=this._b.negateTo(),this._pr=this._r.clone(),this._pu=this._u.clone(),this._pb=this._b.clone(),this._peye=this.eye.clone(),this.isMoving=!1,this._tanViewAngle_hrad=0,this._tanViewAngle_hradOneByHeight=0,this.frustums=[],this.frustumColors=[],t.frustums)for(let e=0,i=t.frustums.length;e<i;e++){let i=t.frustums[e],s=new Ha({fov:this._viewAngle,aspect:this._aspect,near:i[0],far:i[1]});s.cameraFrustumIndex=this.frustums.length,this.frustums.push(s),this.frustumColors.push(s._pickingColorU[0],s._pickingColorU[1],s._pickingColorU[2])}else{let e=.1,t=1e3,i=new Ha({fov:this._viewAngle,aspect:this._aspect,near:e,far:t});i.cameraFrustumIndex=this.frustums.length,this.frustums.push(i),this.frustumColors.push(i._pickingColorU[0],i._pickingColorU[1],i._pickingColorU[2])}this.FARTHEST_FRUSTUM_INDEX=this.frustums.length-1,this.currentFrustumIndex=0,this.frustumColorIndex=0,this.isFirstPass=!1,this._projSizeConst=0,this.set(t.eye||new oe(0,0,1),t.look||new oe,t.up||new oe(0,1,0))}checkMoveEnd(){let e=this._r,t=this._u,i=this._b,s=this.eye;this._peye.equal(s)&&this._pr.equal(e)&&this._pu.equal(t)&&this._pb.equal(i)?(this.isMoving&&this.events.dispatch(this.events.moveend,this),this.isMoving=!1):this.isMoving=!0,this._pr.copy(e),this._pu.copy(t),this._pb.copy(i),this._peye.copy(s)}bindRenderer(e){this.renderer=e;for(let e=0;e<this.frustums.length;e++)this.renderer.assignPickingColor(this.frustums[e]);this._aspect=this.renderer.handler.getClientAspect(),this._setProj(this._viewAngle,this._aspect)}_init(e){this._setProj(this._viewAngle,this._aspect),this.set(e.eye||new oe(0,0,1),e.look||new oe,e.up||new oe(0,1,0))}getUp(){return this._u.clone()}getDown(){return this._u.negateTo()}getRight(){return this._r.clone()}getLeft(){return this._r.negateTo()}getForward(){return this._f.clone()}getBackward(){return this._b.clone()}update(){let e=this._r,t=this._u,i=this._b,s=this.eye;oe.doubleToTwoFloat32Array(s,this.eyeHigh,this.eyeLow),this._viewMatrix.set([e.x,t.x,i.x,0,e.y,t.y,i.y,0,e.z,t.z,i.z,0,-s.dot(e),-s.dot(t),-s.dot(i),1]),this._viewMatrixRTE.set([e.x,t.x,i.x,0,e.y,t.y,i.y,0,e.z,t.z,i.z,0,0,0,0,1]);for(let e=0,t=this.frustums.length;e<t;e++)this.frustums[e].setViewMatrix(this._viewMatrix),this.frustums[e].setProjectionViewRTEMatrix(this._viewMatrixRTE);this.events.dispatch(this.events.viewchange,this)}refresh(){this._setProj(this._viewAngle,this._aspect),this.update()}setAspectRatio(e){this._aspect=e,this.refresh()}getAspectRatio(){return this._aspect}_setProj(e,t){this._viewAngle=e,this._aspect=t,this._tanViewAngle_hrad=Math.tan(e*d),this._tanViewAngle_hradOneByHeight=this._tanViewAngle_hrad*this.renderer.handler._oneByHeight;let i=this.renderer.handler.canvas;this._projSizeConst=Math.min(i.clientWidth<512?512:i.clientWidth,i.clientHeight<512?512:i.clientHeight)/(e*l);for(let i=0,s=this.frustums.length;i<s;i++)this.frustums[i].setProjectionMatrix(e,t,this.frustums[i].near,this.frustums[i].far)}setViewAngle(e){this._viewAngle=e,this.refresh()}getViewAngle(){return this._viewAngle}get viewAngle(){return this._viewAngle}set(e,t,i){return this.eye.x=e.x,this.eye.y=e.y,this.eye.z=e.z,t=t||this._b,i=i||this._u,this._b.x=e.x-t.x,this._b.y=e.y-t.y,this._b.z=e.z-t.z,this._r.copy(i.cross(this._b)),this._b.normalize(),this._r.normalize(),this._u.copy(this._b.cross(this._r)),this._f.set(-this._b.x,-this._b.y,-this._b.z),this}look(e,t){this._b.set(this.eye.x-e.x,this.eye.y-e.y,this.eye.z-e.z),this._r.copy((t||this._u).cross(this._b)),this._b.normalize(),this._f.set(-this._b.x,-this._b.y,-this._b.z),this._r.normalize(),this._u.copy(this._b.cross(this._r))}slide(e,t,i){this.eye.x+=e*this._r.x+t*this._u.x+i*this._b.x,this.eye.y+=e*this._r.y+t*this._u.y+i*this._b.y,this.eye.z+=e*this._r.z+t*this._u.z+i*this._b.z}setRoll(e){let t=Math.cos(e),i=Math.sin(e),s=this._r.clone();this._r.set(t*s.x-i*this._u.x,t*s.y-i*this._u.y,t*s.z-i*this._u.z),this._u.set(i*s.x+t*this._u.x,i*s.y+t*this._u.y,i*s.z+t*this._u.z)}setPitch(e){let t=Math.cos(e),i=Math.sin(e),s=this._b;this._b.set(t*s.x-i*this._u.x,t*s.y-i*this._u.y,t*s.z-i*this._u.z),this._u.set(i*s.x+t*this._u.x,i*s.y+t*this._u.y,i*s.z+t*this._u.z)}setYaw(e){let t=Math.cos(e),i=Math.sin(e),s=this._r;this._r.set(t*s.x-i*this._b.x,t*s.y-i*this._b.y,t*s.z-i*this._b.z),this._b.set(i*s.x+t*this._b.x,i*s.y+t*this._b.y,i*s.z+t*this._b.z)}setPitchYawRoll(e,t,i){let s=new re;s.setPitchYawRoll(e,t,i),this.setRotation(s)}getPitch(){return this.getRotation().getPitch()}getYaw(){return this.getRotation().getYaw()}getRoll(){return this.getRotation().getRoll()}getRotation(){return re.getLookRotation(this._f,this._u).conjugate()}setRotation(e,t,i,s){e.mulVec3Res(t||new oe(0,1,0),this._u),e.mulVec3Res(i||new oe(1,0,0),this._r),e.mulVec3Res(s||new oe(0,0,1),this._b),this._f.set(-this._b.x,-this._b.y,-this._b.z)}rotate(e){e.mulVec3Res(this._u,this._u),e.mulVec3Res(this._r,this._r),e.mulVec3Res(this._b,this._b),this._f.set(-this._b.x,-this._b.y,-this._b.z)}unproject2v(e){return this.unproject(e.x,e.y)}unproject(e,t){let i=this.renderer.handler.canvas,s=.5*i.width,n=.5*i.height,r=(e-s)/s,o=-(t-n)/n,a=this.frustums[0].inverseProjectionViewMatrix.mulVec4(new se(r,o,-1,1)).affinity();return this.frustums[0].inverseProjectionViewMatrix.mulVec4(new se(r,o,0,1)).affinity().subA(a).toVec3().normalize()}project3v(e){return this.project(e.x,e.y,e.z)}project(e,t,i){let s=this.frustums[0].projectionViewMatrix.mulVec4(new se(e,t,i,1)),n=this.renderer.handler.canvas;return new ae((1+s.x/s.w)*n.width*.5,(1-s.y/s.w)*n.height*.5)}rotateAround(e,t=!1,i=oe.ZERO,s=oe.UP){s=t?this._u:s;let n=ne.getRotation(e,s),r=ne.getRotationAroundPoint(e,i,s);this.eye=r.mulVec3(this.eye),this._u=n.mulVec3(this._u).normalize(),this._r=n.mulVec3(this._r).normalize(),this._b=n.mulVec3(this._b).normalize(),this._f.set(-this._b.x,-this._b.y,-this._b.z)}rotateHorizontal(e,t,i,s){this.rotateAround(e,t,i,s)}rotateVertical(e,t){this.rotateAround(e,!1,t,this._r)}projectedSize(e,t){return Math.atan(t/this.eye.distance(e))*this._projSizeConst}getViewMatrix(){return this._viewMatrix._m}getNormalMatrix(){return this._normalMatrix._m}setCurrentFrustum(e){this.currentFrustumIndex=e,this.frustumColorIndex=10*(e+1)/255,this.isFirstPass=e===this.FARTHEST_FRUSTUM_INDEX}getCurrentFrustum(){return this.currentFrustumIndex}containsSphere(e){for(let t=0;t<this.frustums.length;t++)if(this.frustums[t].containsSphere(e))return!0;return!1}get frustum(){return this.frustums[this.currentFrustumIndex]}getProjectionMatrix(){return this.frustum.projectionMatrix._m}getProjectionViewMatrix(){return this.frustum.projectionViewMatrix._m}getProjectionViewRTEMatrix(){return this.frustum.projectionViewRTEMatrix._m}getInverseProjectionViewMatrix(){return this.frustum.inverseProjectionViewMatrix._m}getInverseProjectionMatrix(){return this.frustum.inverseProjectionMatrix._m}viewDistance(e,t=1e4){let i=this.eye.add(this.getForward().scaleTo(t));re.getRotationBetweenVectors(i.getNormal(),e.getNormal());let s=e.add(this.getBackward().scaleTo(t));this.set(s,e),this.update()}}class Ua extends Va{constructor(e,t={}){super(e.renderer,{...t,frustums:t.frustums||[[1,100.075],[100,1000.075],[1e3,101e4],[1e6,1e9]]}),this.planet=e,this.minAltitude=t.minAltitude||1,this.maxAltitude=t.maxAltitude||2e7,this._lonLat=this.planet.ellipsoid.cartesianToLonLat(this.eye),this._lonLatMerc=this._lonLat.forwardMercator(),this._terrainAltitude=this._lonLat.height,this._terrainPoint=new oe,this._insideSegment=null,this.slope=0,this._keyLock=new Bn,this._framesArr=[],this._framesCounter=0,this._numFrames=50,this._completeCallback=null,this._frameCallback=null,this._flying=!1,this._checkTerrainCollision=!0,this.eyeNorm=this.eye.getNormal()}setTerrainCollisionActivity(e){this._checkTerrainCollision=e}update(){this.events.stopPropagation();let e=this.maxAltitude+this.planet.ellipsoid.getEquatorialSize();this.eye.length()>e&&this.eye.copy(this.eye.getNormal().scale(e)),super.update(),this.updateGeodeticPosition(),this.eyeNorm=this.eye.getNormal(),this.slope=this._b.dot(this.eyeNorm),this.events.dispatch(this.events.viewchange,this)}updateGeodeticPosition(){this.planet.ellipsoid.cartesianToLonLatRes(this.eye,this._lonLat),Math.abs(this._lonLat.lat)<=Q&&I.forwardMercatorRes(this._lonLat,this._lonLatMerc)}setAltitude(e){let t=this._terrainPoint,i=this.planet.ellipsoid.getSurfaceNormal3v(this.eye);this.eye.x=i.x*e+t.x,this.eye.y=i.y*e+t.y,this.eye.z=i.z*e+t.z,this._terrainAltitude=e}getAltitude(){return this._terrainAltitude}setLonLat(e,t,i){this.stopFlying(),this._lonLat.set(e.lon,e.lat,e.height||this._lonLat.height);let s=this.planet.ellipsoid,n=s.lonLatToCartesian(this._lonLat),r=t?s.lonLatToCartesian(t):oe.ZERO;this.set(n,r,i||oe.NORTH),this.update()}getLonLat(){return this._lonLat}getHeight(){return this._lonLat.height}getExtentPosition(e,t){t=t||0;let i=e.getNorth(),s=e.getSouth(),n=e.getEast(),r=e.getWest();r>n&&(n+=360);let o=this.planet.ellipsoid,a=new I(n,i),h=o.lonLatToCartesian(a);a.lat=s;let c=o.lonLatToCartesian(a);a.lon=r;let d=o.lonLatToCartesian(a);a.lat=i;let _=o.lonLatToCartesian(a),u=oe.sub(h,d).scale(.5).addA(d),g=u.length();g<1e-6&&(a.lon=.5*(n+r),a.lat=.5*(i+s),u=o.lonLatToCartesian(a)),_.subA(u),c.subA(u),h.subA(u),d.subA(u);let f=u.getNormal(),p=f.cross(oe.NORTH).normalize(),m=p.cross(f).normalize(),v=Math.max(Math.abs(m.dot(_)),Math.abs(m.dot(c)),Math.abs(m.dot(h)),Math.abs(m.dot(d))),y=Math.max(Math.abs(p.dot(_)),Math.abs(p.dot(c)),Math.abs(p.dot(h)),Math.abs(p.dot(d))),x=Math.tan(this._viewAngle*l*.5),b=this._aspect*x,w=Math.max(y/b,v/x);return u.normalize(),u.scale(g+w+t),u}viewExtent(e,t){this.stopFlying(),this.set(this.getExtentPosition(e,t),oe.ZERO,oe.NORTH),this.update()}flyExtent(e,t,i,s,n,r,o){this.flyCartesian(this.getExtentPosition(e,t),oe.ZERO,i,null==s?1:s,n,r,o)}viewDistance(e,t=1e4){let i=this.eye.add(this.getForward().scaleTo(t)),s=re.getRotationBetweenVectors(i.getNormal(),e.getNormal());if(s.isZero()){let i=e.add(this.getBackward().scaleTo(t));this.set(i,e)}else{let i=e.add(s.mulVec3(this.getBackward()).scale(t)),n=s.mulVec3(this.getUp());this.set(i,e,n)}this.update()}flyDistance(e,t=1e4,i=0,s,n,r){let o=this.eye.add(this.getForward().scaleTo(t)),a=re.getRotationBetweenVectors(o.getNormal(),e.getNormal());if(a.isZero()){let i=e.add(this.getBackward().scaleTo(t));this.set(i,e)}else{let o=e.add(a.mulVec3(this.getBackward()).scale(t)),l=a.mulVec3(this.getUp());this.flyCartesian(o,e,l,i,s,n,r)}}flyCartesian(e,t=oe.ZERO,i=oe.NORTH,s=1,n=(()=>{}),r=(()=>{}),o=(()=>{})){this.stopFlying(),t=t||oe.ZERO,i=i||oe.NORTH,this._completeCallback=n,this._frameCallback=o,r&&r.call(this),t instanceof I&&(t=this.planet.ellipsoid.lonLatToCartesian(t));let a=this.planet.ellipsoid.lonLatToCartesian(new I(this._lonLat.lon,this._lonLat.lat)),l=this._u,h=this._b,c=this.planet.ellipsoid.cartesianToLonLat(e),d=i,u=this.planet.ellipsoid.lonLatToCartesian(new I(c.lon,c.lat,0)),g=oe.sub(e,t),f=d.cross(g);g.normalize(),f.normalize();let p=g.cross(f),m=a.getNormal(),v=u.getNormal(),y=1-m.dot(v),x=s*_*Math.sqrt(y>0?y:0),b=6639613,w=Math.max(this._lonLat.height,c.height);w>b&&(b=w);let C=w+2.5*x*(b-w),T=oe.ZERO;for(let e=0;e<=this._numFrames;e++){let t=1-e/this._numFrames;t=t*t*(3-2*t),t*=t;let i=a.smerp(u,t).normalize(),s=this.planet.getRayIntersectionEllipsoid(new ui(T,i)),n=1-t,r=this._lonLat.height*t*t*t+3*C*t*t*n+3*C*t*n*n+c.height*n*n*n,o=s.addA(i.scale(r)),d=l.smerp(p,t),_=oe.add(o,h.smerp(g,t).negateTo()),f=new oe(o.x-_.x,o.y-_.y,o.z-_.z),m=d.cross(f);f.normalize(),m.normalize();let v=f.cross(m);this._framesArr[e]={eye:o,n:f,u:m,v:v}}this._framesCounter=this._numFrames,this._flying=!0}flyLonLat(e,t,i,s,n,r,o){let a=new I(e.lon,e.lat,e.height||this._lonLat.height);this.flyCartesian(this.planet.ellipsoid.lonLatToCartesian(a),t,i,s,n,r,o)}stopFlying(){this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet.normalMapCreator.free(this._keyLock),this._flying=!1,this._framesArr.length=0,this._framesArr=[],this._framesCounter=-1,this._frameCallback=null,this.planet.stopDragging()}isFlying(){return this._flying}rotateLeft(e,t){this.rotateHorizontal(e,!0!==t,oe.ZERO),this.update()}rotateRight(e,t){this.rotateHorizontal(-e,!0!==t,oe.ZERO),this.update()}rotateUp(e){this.rotateVertical(e,oe.ZERO),this.update()}rotateDown(e){this.rotateVertical(-e,oe.ZERO),this.update()}rotateVertical(e,t,i=0){let s=(new ne).setRotation(this._r,e),n=(new ne).setIdentity().translate(t),r=(new ne).setIdentity().translate(t.negateTo()),o=n.mul(s).mul(r).mulVec3(this.eye),a=s.mulVec3(this._u).normalize(),l=s.mulVec3(this._r).normalize(),h=s.mulVec3(this._b).normalize(),c=o.getNormal(),d=h.dot(c);if(i){let e=d-this.slope;if(d<i&&e<0)return;(d>.1&&a.dot(c)>0||this.slope<=.1||this._u.dot(this.eye.getNormal())<=0)&&(this.eye=o,this._u=a,this._r=l,this._b=h,this._f.set(-h.x,-h.y,-h.z))}else this.eye=o,this._u=a,this._r=l,this._b=h,this._f.set(-h.x,-h.y,-h.z)}checkFly(){if(this._flying){let e=this._numFrames-this._framesCounter;this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet.normalMapCreator.lock(this._keyLock),this.eye=this._framesArr[e].eye,this._r=this._framesArr[e].u,this._u=this._framesArr[e].v,this._b=this._framesArr[e].n,this._f.set(-this._b.x,-this._b.y,-this._b.z),this._frameCallback&&this._frameCallback(),this.update(),this._framesCounter--,this._framesCounter<0&&(this.stopFlying(),this._completeCallback&&(this._completeCallback(),this._completeCallback=null))}}checkTerrainCollision(){if(this._terrainAltitude=this._lonLat.height,this._insideSegment&&this._insideSegment.planet)return this._terrainAltitude=this._insideSegment.getTerrainPoint(this.eye,this._insideSegment.getInsideLonLat(this),this._terrainPoint),this._terrainAltitude<this.minAltitude&&this._checkTerrainCollision&&this.setAltitude(this.minAltitude),this._terrainPoint}getSurfaceVisibleDistance(e){let t=this.planet.ellipsoid.equatorialSize;return t*Math.acos(t/(t+this._lonLat.height+e))}getHeading(){let e=this.eye.getNormal(),t=oe.proj_b_to_plane(this.slope>=.97?this.getUp():this.getForward(),e).normalize(),i=oe.proj_b_to_plane(oe.NORTH,e).normalize(),s=Math.sign(e.dot(t.cross(i)))*Math.acos(t.dot(i))*h;return s<0?360+s:s}isVisible(e){let t=this.eye.length();return this.eye.distance(e)<Math.sqrt(t*t-this.planet.ellipsoid.equatorialSizeSqr)}getPitch(){return this.planet.getFrameRotation(this.eye).conjugate().inverse().mul(this.getRotation()).getPitch()}getYaw(){return this.planet.getFrameRotation(this.eye).conjugate().inverse().mul(this.getRotation()).getYaw()}getRoll(){return this.planet.getFrameRotation(this.eye).conjugate().inverse().mul(this.getRotation()).getRoll()}setPitch(e){let t=this.planet.getFrameRotation(this.eye),i=new re;i.setPitchYawRoll(e,this.getYaw(),this.getRoll(),t),this.setRotation(i)}setYaw(e){let t=this.planet.getFrameRotation(this.eye),i=new re;i.setPitchYawRoll(this.getYaw(),e,this.getRoll(),t),this.setRotation(i)}setRoll(e){let t=this.planet.getFrameRotation(this.eye),i=new re;i.setPitchYawRoll(this.getPitch(),this.getYaw(),e,t),this.setRotation(i)}setPitchYawRoll(e,t,i){let s=this.planet.getFrameRotation(this.eye),n=new re;n.setPitchYawRoll(e,t,i,s).conjugate(),this.setRotation(n)}}class Ga extends ei{constructor(e=2){super(e,Ya)}_onMessage(e){this._source.get(e.data.id).segment._terrainWorkerCallback(e.data),this._source.delete(e.data.id),e.data.normalMapNormals=null,e.data.normalMapVertices=null,e.data.normalMapVerticesHigh=null,e.data.normalMapVerticesLow=null,e.data.terrainVertices=null,e.data.terrainVerticesHigh=null,e.data.terrainVerticesLow=null}make(e){if(e.segment.plainReady&&e.segment.terrainIsLoading)if(this._workerQueue.length){const t=this._workerQueue.pop();this._source.set(this._sourceId,e);let i=e.segment;t.postMessage({elevations:e.elevations,this_plainVertices:i.plainVertices,this_plainNormals:i.plainNormals,this_normalMapVertices:i.normalMapVertices,this_normalMapNormals:i.normalMapNormals,heightFactor:i.planet._heightFactor,gridSize:i.planet.terrain.gridSizeByZoom[i.tileZoom],noDataValues:i.planet.terrain.noDataValues,id:this._sourceId},[e.elevations.buffer,i.plainVertices.buffer,i.plainNormals.buffer,i.normalMapVertices.buffer,i.normalMapNormals.buffer]),this._sourceId++}else this._pendingQueue.push(e);else this.check()}}const Ya="'use strict';\n //\n //Terrain worker\n //\n\n function binarySearchFast(arr, x) {\n let start = 0,\n end = arr.length - 1;\n while (start <= end) {\n let k = Math.floor((start + end) * 0.5); \n if (Math.abs(arr[k] - x) < 1e-3)\n return k;\n else if (arr[k] < x)\n start = k + 1;\n else\n end = k - 1;\n }\n return -1;\n };\n\n function checkNoDataValue(noDataValues, value) {\n return binarySearchFast(noDataValues, value) !== -1;\n };\n\n\n var Vec3 = function(x, y, z) {\n this.x = x;\n this.y = y;\n this.z = z;\n };\n\n var doubleToTwoFloats = function(v, high, low) {\n\n let x = v.x, y = v.y, z = v.z;\n \n if (x >= 0.0) {\n var doubleHigh = Math.floor(x / 65536.0) * 65536.0;\n high.x = Math.fround(doubleHigh);\n low.x = Math.fround(x - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-x / 65536.0) * 65536.0;\n high.x = Math.fround(-doubleHigh);\n low.x = Math.fround(x + doubleHigh);\n }\n\n if (y >= 0.0) {\n var doubleHigh = Math.floor(y / 65536.0) * 65536.0;\n high.y = Math.fround(doubleHigh);\n low.y = Math.fround(y - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-y / 65536.0) * 65536.0;\n high.y = Math.fround(-doubleHigh);\n low.y = Math.fround(y + doubleHigh);\n }\n\n if (z >= 0.0) {\n var doubleHigh = Math.floor(z / 65536.0) * 65536.0;\n high.z = Math.fround(doubleHigh);\n low.z = Math.fround(z - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-z / 65536.0) * 65536.0;\n high.z = Math.fround(-doubleHigh);\n low.z = Math.fround(z + doubleHigh);\n }\n };\n\n Vec3.prototype.sub = function(v) {\n return new Vec3(this.x - v.x, this.y - v.y, this.z - v.z);\n };\n\n Vec3.prototype.add = function(v) {\n return new Vec3(this.x + v.x, this.y + v.y, this.z + v.z);\n };\n\n Vec3.prototype.cross = function(v) {\n return new Vec3(\n this.y * v.z - this.z * v.y,\n this.z * v.x - this.x * v.z,\n this.x * v.y - this.y * v.x\n );\n };\n\n Vec3.prototype.normalize = function(v) {\n var x = this.x, y = this.y, z = this.z;\n var length = 1.0 / Math.sqrt(x * x + y * y + z * z);\n this.x = x * length;\n this.y = y * length;\n this.z = z * length;\n return this;\n };\n\n Vec3.prototype.distance = function(v) {\n return this.sub(v).length();\n };\n\n Vec3.prototype.length = function () {\n return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);\n };\n\n var blerp = function(x, y, fQ11, fQ21, fQ12, fQ22) {\n return (fQ11 * (1.0 - x) * (1.0 - y) + fQ21 * x * (1.0 - y) + fQ12 * (1.0 - x) * y + fQ22 * x * y);\n };\n \n var slice = function (t, h1, h0) {\n return t * (h1 - h0);\n };\n\n var _tempVec = new Vec3(0.0, 0.0, 0.0);\n\n var _tempHigh = new Vec3(0.0, 0.0, 0.0),\n _tempLow = new Vec3(0.0, 0.0, 0.0);\n\n self.onmessage = function (e) {\n var elevations = e.data.elevations,\n this_plainVertices = e.data.this_plainVertices,\n this_plainNormals = e.data.this_plainNormals,\n this_normalMapVertices = e.data.this_normalMapVertices,\n this_normalMapNormals = e.data.this_normalMapNormals,\n heightFactor = e.data.heightFactor,\n gridSize = e.data.gridSize,\n noDataValues = e.data.noDataValues,\n id = e.data.id;\n \n var xmin = 549755748352.0, xmax = -549755748352.0, \n ymin = 549755748352.0, ymax = -549755748352.0, \n zmin = 549755748352.0, zmax = -549755748352.0;\n\n const fileGridSize = Math.sqrt(elevations.length) - 1;\n\n const fileGridSize_one = fileGridSize + 1;\n const fileGridSize_one_x2 = fileGridSize_one * fileGridSize_one;\n const tgs = gridSize;\n const dg = fileGridSize / tgs;\n const gs = tgs + 1;\n const hf = heightFactor;\n\n var nmvInd = 0,\n vInd = 0,\n noDataInd = 0;\n\n var gsgs3 = gs * gs * 3;\n\n var terrainVertices = new Float64Array(gsgs3),\n terrainVerticesHigh = new Float32Array(gsgs3),\n terrainVerticesLow = new Float32Array(gsgs3),\n noDataVertices = new Uint8Array(gs * gs);\n\n var normalMapNormals,\n normalMapVertices,\n normalMapVerticesHigh,\n normalMapVerticesLow;\n\n var nv = this_normalMapVertices,\n nn = this_normalMapNormals;\n\n if (fileGridSize >= tgs) {\n\n normalMapNormals = new Float32Array(fileGridSize_one_x2 * 3);\n normalMapVertices = new Float64Array(fileGridSize_one_x2 * 3);\n normalMapVerticesHigh = new Float32Array(fileGridSize_one_x2 * 3);\n normalMapVerticesLow = new Float32Array(fileGridSize_one_x2 * 3);\n\n for (let k = 0; k < fileGridSize_one_x2; k++) {\n\n var j = k % fileGridSize_one,\n i = ~~(k / fileGridSize_one);\n\n //\n // V0\n //\n var hInd0 = k;\n var vInd0 = hInd0 * 3;\n var currElv = elevations[hInd0];\n if(checkNoDataValue(noDataValues, currElv)) {\n currElv = 0.0;\n }\n var h0 = hf * currElv;\n var v0 = new Vec3(nv[vInd0] + h0 * nn[vInd0], nv[vInd0 + 1] + h0 * nn[vInd0 + 1], nv[vInd0 + 2] + h0 * nn[vInd0 + 2]);\n \n doubleToTwoFloats(v0, _tempHigh, _tempLow);\n\n normalMapVertices[vInd0] = v0.x;\n normalMapVertices[vInd0 + 1] = v0.y;\n normalMapVertices[vInd0 + 2] = v0.z;\n\n normalMapVerticesHigh[vInd0] = _tempHigh.x;\n normalMapVerticesHigh[vInd0 + 1] = _tempHigh.y;\n normalMapVerticesHigh[vInd0 + 2] = _tempHigh.z;\n\n normalMapVerticesLow[vInd0] = _tempLow.x;\n normalMapVerticesLow[vInd0 + 1] = _tempLow.y;\n normalMapVerticesLow[vInd0 + 2] = _tempLow.z;\n\n //\n // The vertex goes into screen buffer\n if (i % dg === 0 && j % dg === 0) {\n\n let currVert = new Vec3(nv[vInd0], nv[vInd0 + 1], nv[vInd0 + 2]);\n let nextVert = new Vec3(nv[vInd0 + 3], nv[vInd0 + 4], nv[vInd0 + 5]);\n\n let nextElv = elevations[hInd0 + 1];\n if(checkNoDataValue(noDataValues, nextElv)) {\n nextElv = 0.0;\n }\n \n let eps = false;\n if(noDataValues.length === 0){\n let step = currVert.distance(nextVert);\n let deltaElv = Math.abs(currElv - nextElv);\n eps = ((deltaElv / step) > 10.0) || (currElv < -5000);\n }\n\n if(eps){\n noDataVertices[noDataInd] = 1;\n } else {\n noDataVertices[noDataInd] = 0;\n if (v0.x < xmin) xmin = v0.x; if (v0.x > xmax) xmax = v0.x;\n if (v0.y < ymin) ymin = v0.y; if (v0.y > ymax) ymax = v0.y;\n if (v0.z < zmin) zmin = v0.z; if (v0.z > zmax) zmax = v0.z;\n }\n\n terrainVerticesHigh[vInd] = _tempHigh.x;\n terrainVerticesLow[vInd] = _tempLow.x;\n terrainVertices[vInd++] = v0.x;\n\n terrainVerticesHigh[vInd] = _tempHigh.y;\n terrainVerticesLow[vInd] = _tempLow.y;\n terrainVertices[vInd++] = v0.y;\n\n terrainVerticesHigh[vInd] = _tempHigh.z;\n terrainVerticesLow[vInd] = _tempLow.z;\n terrainVertices[vInd++] = v0.z;\n\n noDataInd++;\n }\n\n if (i !== fileGridSize && j !== fileGridSize) {\n\n //\n // V1\n //\n var hInd1 = k + 1;\n var vInd1 = hInd1 * 3;\n var elv = elevations[hInd1];\n if(checkNoDataValue(noDataValues, elv)) {\n elv = 0.0;\n }\n var h1 = hf * elv;\n var v1 = new Vec3(nv[vInd1] + h1 * nn[vInd1], nv[vInd1 + 1] + h1 * nn[vInd1 + 1], nv[vInd1 + 2] + h1 * nn[vInd1 + 2]);\n\n doubleToTwoFloats(v1, _tempHigh, _tempLow);\n\n normalMapVertices[vInd1] = v1.x;\n normalMapVertices[vInd1 + 1] = v1.y;\n normalMapVertices[vInd1 + 2] = v1.z;\n\n normalMapVerticesHigh[vInd1] = _tempHigh.x;\n normalMapVerticesHigh[vInd1 + 1] = _tempHigh.y;\n normalMapVerticesHigh[vInd1 + 2] = _tempHigh.z;\n\n normalMapVerticesLow[vInd1] = _tempLow.x;\n normalMapVerticesLow[vInd1 + 1] = _tempLow.y;\n normalMapVerticesLow[vInd1 + 2] = _tempLow.z;\n\n //\n // V2\n //\n var hInd2 = k + fileGridSize_one;\n var vInd2 = hInd2 * 3;\n var elv = elevations[hInd2];\n if(checkNoDataValue(noDataValues, elv)) {\n elv = 0.0;\n }\n var h2 = hf * elv;\n var v2 = new Vec3(nv[vInd2] + h2 * nn[vInd2], nv[vInd2 + 1] + h2 * nn[vInd2 + 1], nv[vInd2 + 2] + h2 * nn[vInd2 + 2]);\n\n doubleToTwoFloats(v2, _tempHigh, _tempLow);\n\n normalMapVertices[vInd2] = v2.x;\n normalMapVertices[vInd2 + 1] = v2.y;\n normalMapVertices[vInd2 + 2] = v2.z;\n\n normalMapVerticesHigh[vInd2] = _tempHigh.x;\n normalMapVerticesHigh[vInd2 + 1] = _tempHigh.y;\n normalMapVerticesHigh[vInd2 + 2] = _tempHigh.z;\n\n normalMapVerticesLow[vInd2] = _tempLow.x;\n normalMapVerticesLow[vInd2 + 1] = _tempLow.y;\n normalMapVerticesLow[vInd2 + 2] = _tempLow.z;\n\n //\n // V3\n //\n var hInd3 = k + fileGridSize_one + 1;\n var vInd3 = hInd3 * 3;\n var elv = elevations[hInd3];\n if(checkNoDataValue(noDataValues, elv)) {\n elv = 0.0;\n }\n var h3 = hf * elv;\n var v3 = new Vec3(nv[vInd3] + h3 * nn[vInd3], nv[vInd3 + 1] + h3 * nn[vInd3 + 1], nv[vInd3 + 2] + h3 * nn[vInd3 + 2]);\n\n doubleToTwoFloats(v3, _tempHigh, _tempLow);\n\n normalMapVertices[vInd3] = v3.x;\n normalMapVertices[vInd3 + 1] = v3.y;\n normalMapVertices[vInd3 + 2] = v3.z;\n\n normalMapVerticesHigh[vInd3] = _tempHigh.x;\n normalMapVerticesHigh[vInd3 + 1] = _tempHigh.y;\n normalMapVerticesHigh[vInd3 + 2] = _tempHigh.z;\n\n normalMapVerticesLow[vInd3] = _tempLow.x;\n normalMapVerticesLow[vInd3 + 1] = _tempLow.y;\n normalMapVerticesLow[vInd3 + 2] = _tempLow.z;\n\n //\n // Normal\n //\n var e10 = v1.sub(v0),\n e20 = v2.sub(v0),\n e30 = v3.sub(v0);\n var sw = e20.cross(e30).normalize();\n var ne = e30.cross(e10).normalize();\n var n0 = ne.add(sw).normalize();\n\n normalMapNormals[vInd0] += n0.x;\n normalMapNormals[vInd0 + 1] += n0.y;\n normalMapNormals[vInd0 + 2] += n0.z;\n\n normalMapNormals[vInd1] += ne.x;\n normalMapNormals[vInd1 + 1] += ne.y;\n normalMapNormals[vInd1 + 2] += ne.z;\n\n normalMapNormals[vInd2] += sw.x;\n normalMapNormals[vInd2 + 1] += sw.y;\n normalMapNormals[vInd2 + 2] += sw.z;\n\n normalMapNormals[vInd3] += n0.x;\n normalMapNormals[vInd3 + 1] += n0.y;\n normalMapNormals[vInd3 + 2] += n0.z;\n }\n }\n\n } else {\n\n normalMapNormals = new Float32Array(gsgs3);\n normalMapVertices = new Float64Array(gsgs3);\n normalMapVerticesHigh = new Float32Array(gsgs3);\n normalMapVerticesLow = new Float32Array(gsgs3);\n normalMapNormals = new Float32Array(gsgs3);\n\n var oneSize = tgs / fileGridSize;\n var h, inside_i, inside_j, v_i, v_j;\n var gsgs = gsgs3 / 3;\n var fgsOne = fileGridSize + 1;\n\n for(let i = 0; i < gsgs; i++) {\n let ii = Math.floor(i / gs),\n ij = i % gs;\n \n let qii = ii % oneSize,\n qij = ij % oneSize;\n\n let hlt_ind = Math.floor(ii / oneSize) * fgsOne + Math.floor(ij / oneSize);\n\n if (ij === tgs) {\n hlt_ind -= 1;\n qij = oneSize;\n }\n\n if (ii === tgs) {\n hlt_ind -= fgsOne;\n qii = oneSize;\n }\n\n let hrt_ind = hlt_ind + 1,\n hlb_ind = hlt_ind + fgsOne,\n hrb_ind = hlb_ind + 1;\n\n let h_lt = elevations[hlt_ind],\n h_rt = elevations[hrt_ind],\n h_lb = elevations[hlb_ind],\n h_rb = elevations[hrb_ind];\n\n if(checkNoDataValue(noDataValues, h_lt)) {\n h_lt = 0.0;\n }\n\n if(checkNoDataValue(noDataValues, h_rt)) {\n h_rt = 0.0;\n }\n\n if(checkNoDataValue(noDataValues, h_lb)) {\n h_lb = 0.0;\n }\n\n if(checkNoDataValue(noDataValues, h_rb)) {\n h_rb = 0.0;\n }\n\n let hi = blerp(qij / oneSize, qii / oneSize, h_lt, h_rt, h_lb, h_rb);\n\n let i3 = i * 3;\n\n _tempVec.x = this_plainVertices[i3] + hi * this_plainNormals[i3],\n _tempVec.y = this_plainVertices[i3 + 1] + hi * this_plainNormals[i3 + 1],\n _tempVec.z = this_plainVertices[i3 + 2] + hi * this_plainNormals[i3 + 2];\n\n doubleToTwoFloats(_tempVec, _tempHigh, _tempLow);\n\n terrainVertices[i3] = _tempVec.x;\n terrainVertices[i3 + 1] = _tempVec.y;\n terrainVertices[i3 + 2] = _tempVec.z;\n\n terrainVerticesHigh[i3] = _tempHigh.x;\n terrainVerticesHigh[i3 + 1] = _tempHigh.y;\n terrainVerticesHigh[i3 + 2] = _tempHigh.z;\n\n terrainVerticesLow[i3] = _tempLow.x;\n terrainVerticesLow[i3 + 1] = _tempLow.y;\n terrainVerticesLow[i3 + 2] = _tempLow.z;\n\n if (_tempVec.x < xmin) xmin = _tempVec.x; if (_tempVec.x > xmax) xmax = _tempVec.x;\n if (_tempVec.y < ymin) ymin = _tempVec.y; if (_tempVec.y > ymax) ymax = _tempVec.y;\n if (_tempVec.z < zmin) zmin = _tempVec.z; if (_tempVec.z > zmax) zmax = _tempVec.z;\n }\n\n normalMapVertices.set(terrainVertices);\n normalMapVerticesHigh.set(terrainVerticesHigh);\n normalMapVerticesLow.set(terrainVerticesLow);\n\n for (let k = 0; k < gsgs; k++) {\n\n var j = k % gs,\n i = ~~(k / gs);\n\n if (i !== tgs && j !== tgs) {\n var v0ind = k * 3,\n v1ind = v0ind + 3,\n v2ind = v0ind + gs * 3,\n v3ind = v2ind + 3;\n\n\n var v0 = new Vec3(terrainVertices[v0ind], terrainVertices[v0ind + 1], terrainVertices[v0ind + 2]),\n v1 = new Vec3(terrainVertices[v1ind], terrainVertices[v1ind + 1], terrainVertices[v1ind + 2]),\n v2 = new Vec3(terrainVertices[v2ind], terrainVertices[v2ind + 1], terrainVertices[v2ind + 2]),\n v3 = new Vec3(terrainVertices[v3ind], terrainVertices[v3ind + 1], terrainVertices[v3ind + 2]);\n\n var e10 = v1.sub(v0).normalize(),\n e20 = v2.sub(v0).normalize(),\n e30 = v3.sub(v0).normalize();\n\n var sw = e20.cross(e30).normalize();\n var ne = e30.cross(e10).normalize();\n var n0 = ne.add(sw).normalize();\n\n normalMapNormals[v0ind] += n0.x;\n normalMapNormals[v0ind + 1] += n0.y;\n normalMapNormals[v0ind + 2] += n0.z;\n\n normalMapNormals[v1ind] += ne.x;\n normalMapNormals[v1ind + 1] += ne.y;\n normalMapNormals[v1ind + 2] += ne.z;\n\n normalMapNormals[v2ind] += sw.x;\n normalMapNormals[v2ind + 1] += sw.y;\n normalMapNormals[v2ind + 2] += sw.z;\n\n normalMapNormals[v3ind] += n0.x;\n normalMapNormals[v3ind + 1] += n0.y;\n normalMapNormals[v3ind + 2] += n0.z;\n }\n }\n }\n\n self.postMessage({\n id: id,\n normalMapNormals: normalMapNormals,\n normalMapVertices: normalMapVertices,\n normalMapVerticesHigh: normalMapVerticesHigh,\n normalMapVerticesLow: normalMapVerticesLow,\n terrainVertices: terrainVertices,\n terrainVerticesHigh: terrainVerticesHigh,\n terrainVerticesLow: terrainVerticesLow,\n noDataVertices: noDataVertices,\n //bounds: [xmin, xmax, ymin, ymax, zmin, zmax]\n bounds: [xmin, ymin, zmin, xmax, ymax, zmax]\n }, [\n normalMapNormals.buffer, \n normalMapVertices.buffer, \n normalMapVerticesHigh.buffer, \n normalMapVerticesLow.buffer, \n terrainVertices.buffer,\n terrainVerticesHigh.buffer,\n terrainVerticesLow.buffer,\n noDataVertices.buffer\n ]);\n }";let ja=new Float32Array(2);class Wa{constructor(e,t=512,i=512){this._width=t,this._height=i,this._planet=e,this._framebuffer=null,this._queue=[],this._handler=null}init(){this._handler=this._planet.renderer.handler,this._handler.programs.vectorTileLineRasterization||this._handler.addProgram(new Ni("vectorTileLineRasterization",{uniforms:{viewport:"vec2",thicknessOutline:"float",alpha:"float",extentParamsHigh:"vec4",extentParamsLow:"vec4"},attributes:{prevHigh:"vec2",currentHigh:"vec2",nextHigh:"vec2",prevLow:"vec2",currentLow:"vec2",nextLow:"vec2",order:"float",color:"vec4",thickness:"float"},vertexShader:"attribute vec2 prevHigh;\n attribute vec2 currentHigh;\n attribute vec2 nextHigh;\n\n attribute vec2 prevLow;\n attribute vec2 currentLow;\n attribute vec2 nextLow;\n\n attribute float order;\n attribute float thickness;\n attribute vec4 color;\n uniform float thicknessOutline;\n uniform vec2 viewport;\n uniform vec4 extentParamsHigh;\n uniform vec4 extentParamsLow;\n varying vec4 vColor;\n \n vec2 proj(vec2 coordHigh, vec2 coordLow) {\n vec2 highDiff = coordHigh - extentParamsHigh.xy;\n vec2 lowDiff = coordLow - extentParamsLow.xy; \n return vec2(-1.0 + (highDiff * step(1.0, length(highDiff)) + lowDiff) * extentParamsHigh.zw) * vec2(1.0, -1.0);\n }\n \n void main(){\n vColor = color;\n\n vec2 vNext = proj(nextHigh, nextLow),\n vCurrent = proj(currentHigh, currentLow),\n vPrev = proj(prevHigh, prevLow);\n\n vec2 _next = vNext;\n vec2 _prev = vPrev;\n vec2 _current = vCurrent;\n\n if(_prev == _current){\n if(_next == _current){\n _next = _current + vec2(1.0, 0.0);\n _prev = _current - _next;\n }else{\n _prev = _current + normalize(_current - _next);\n }\n }\n\n if(_next == _current){\n _next = _current + normalize(_current - _prev);\n }\n\n vec2 sNext = _next;\n vec2 sCurrent = _current;\n vec2 sPrev = _prev;\n \n vec2 dirNext = normalize(sNext - sCurrent);\n vec2 dirPrev = normalize(sPrev - sCurrent);\n float dotNP = dot(dirNext, dirPrev);\n \n vec2 normalNext = normalize(vec2(-dirNext.y, dirNext.x));\n vec2 normalPrev = normalize(vec2(dirPrev.y, -dirPrev.x));\n vec2 d = (thickness + thicknessOutline) * 0.5 * sign(order) / viewport;\n \n vec2 m;\n if(dotNP >= 0.99991){\n m = sCurrent - normalPrev * d;\n }else{\n vec2 dir = normalPrev + normalNext;\n m = sCurrent + dir * d / (dirNext.x * dir.y - dirNext.y * dir.x);\n \n if( dotNP > 0.5 && dot(dirNext + dirPrev, m - sCurrent) < 0.0 ){\n float occw = order * sign(dirNext.x * dirPrev.y - dirNext.y * dirPrev.x);\n if(occw == -1.0){\n m = sCurrent + normalPrev * d;\n }else if(occw == 1.0){\n m = sCurrent + normalNext * d;\n }else if(occw == -2.0){\n m = sCurrent + normalNext * d;\n }else if(occw == 2.0){\n m = sCurrent + normalPrev * d;\n }\n }else if(distance(sCurrent, m) > min(distance(sCurrent, sNext), distance(sCurrent, sPrev))){\n m = sCurrent + normalNext * d;\n }\n }\n gl_Position = vec4(m.x, m.y, 0.0, 1.0);\n }",fragmentShader:"precision highp float;\n uniform float alpha;\n varying vec4 vColor;\n void main() {\n gl_FragColor = vec4(vColor.rgb, alpha * vColor.a);\n }"})),this._handler.programs.vectorTilePolygonRasterization||this._handler.addProgram(new Ni("vectorTilePolygonRasterization",{uniforms:{extentParamsHigh:"vec4",extentParamsLow:"vec4"},attributes:{coordinatesHigh:"vec2",coordinatesLow:"vec2",colors:"vec4"},vertexShader:"attribute vec2 coordinatesHigh;\n attribute vec2 coordinatesLow; \n attribute vec4 colors; \n uniform vec4 extentParamsHigh; \n uniform vec4 extentParamsLow; \n varying vec4 color;\n\n vec2 proj(vec2 coordHigh, vec2 coordLow) {\n vec2 highDiff = coordHigh - extentParamsHigh.xy;\n vec2 lowDiff = coordLow - extentParamsLow.xy;\n return vec2(-1.0 + (highDiff * step(1.0, length(highDiff)) + lowDiff) * extentParamsHigh.zw) * vec2(1.0, -1.0);\n }\n\n void main() { \n color = colors;\n gl_Position = vec4(proj(coordinatesHigh, coordinatesLow), 0.0, 1.0); \n }",fragmentShader:"precision highp float;\n varying vec4 color;\n void main () { \n gl_FragColor = color; \n }"})),this._framebuffer=new Yo(this._handler,{width:this._width,height:this._height,useDepth:!1}),this._framebuffer.init()}frame(){if(this._planet.layerLock.isFree()&&this._queue.length){let e=this._handler,t=e.gl;t.disable(t.CULL_FACE),t.disable(t.DEPTH_TEST);let i=e.programs.vectorTileLineRasterization,s=e.programs.vectorTilePolygonRasterization,n=this._width,r=this._height,o=n,a=r,l=o<<1,h=a<<1,c=new Float32Array(4),d=new Float32Array(4),_=this._framebuffer.activate(),u=0,g=window.performance.now();for(;this._queue.length&&u<25;){let f=this._queue.shift();if(f.isLoading&&1===f.segment.node.getState()){let u=f.layer._pickingEnabled;f.segment.tileZoom<4?(o=l,a=h):(o=n,a=r);let g=f._updateTexture||e.createEmptyTexture_l(o,a),p=u?f._updatePickingMask||e.createEmptyTexture_n(o,a):null;f.applyTexture(g,p),_.setSize(o,a),_.bindOutputTexture(g),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT);let m=f.segment.getExtentMerc();ms(m.southWest.lon,ja),c[0]=ja[0],d[0]=ja[1],ms(m.southWest.lat,ja),c[1]=ja[0],d[1]=ja[1],c[2]=2/m.getWidth(),c[3]=2/m.getHeight(),s.activate();let v=s._program,y=v.attributes,x=v.uniforms,b=f.layer._geometryHandler;t.uniform4fv(x.extentParamsHigh,c),t.uniform4fv(x.extentParamsLow,d),t.bindBuffer(t.ARRAY_BUFFER,b._polyVerticesHighBufferMerc),t.vertexAttribPointer(y.coordinatesHigh,b._polyVerticesHighBufferMerc.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,b._polyVerticesLowBufferMerc),t.vertexAttribPointer(y.coordinatesLow,b._polyVerticesLowBufferMerc.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,b._polyColorsBuffer),t.vertexAttribPointer(y.colors,b._polyColorsBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,b._polyIndexesBuffer),t.drawElements(t.TRIANGLES,b._polyIndexesBuffer.numItems,t.UNSIGNED_INT,0),u&&(_.bindOutputTexture(p),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),t.bindBuffer(t.ARRAY_BUFFER,b._polyPickingColorsBuffer),t.vertexAttribPointer(y.colors,b._polyPickingColorsBuffer.itemSize,t.FLOAT,!1,0,0),t.drawElements(t.TRIANGLES,b._polyIndexesBuffer.numItems,t.UNSIGNED_INT,0)),_.bindOutputTexture(g),i.activate(),v=i._program,y=v.attributes,x=v.uniforms,t.uniform2fv(x.viewport,[o,a]),t.uniform4fv(x.extentParamsHigh,c),t.uniform4fv(x.extentParamsLow,d);let w=b._lineVerticesHighBufferMerc;t.bindBuffer(t.ARRAY_BUFFER,w),t.vertexAttribPointer(y.prevHigh,w.itemSize,t.FLOAT,!1,8,0),t.vertexAttribPointer(y.currentHigh,w.itemSize,t.FLOAT,!1,8,32),t.vertexAttribPointer(y.nextHigh,w.itemSize,t.FLOAT,!1,8,64),w=b._lineVerticesLowBufferMerc,t.bindBuffer(t.ARRAY_BUFFER,w),t.vertexAttribPointer(y.prevLow,w.itemSize,t.FLOAT,!1,8,0),t.vertexAttribPointer(y.currentLow,w.itemSize,t.FLOAT,!1,8,32),t.vertexAttribPointer(y.nextLow,w.itemSize,t.FLOAT,!1,8,64),t.bindBuffer(t.ARRAY_BUFFER,b._lineOrdersBuffer),t.vertexAttribPointer(y.order,b._lineOrdersBuffer.itemSize,t.FLOAT,!1,4,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,b._lineIndexesBuffer),t.bindBuffer(t.ARRAY_BUFFER,b._lineStrokesBuffer),t.vertexAttribPointer(y.thickness,b._lineStrokesBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,b._lineStrokeColorsBuffer),t.vertexAttribPointer(y.color,b._lineStrokeColorsBuffer.itemSize,t.FLOAT,!1,0,0),t.uniform1f(x.thicknessOutline,2),t.uniform1f(x.alpha,.54),t.drawElements(t.TRIANGLE_STRIP,b._lineIndexesBuffer.numItems,t.UNSIGNED_INT,0),t.uniform1f(x.thicknessOutline,1),t.uniform1f(x.alpha,1),t.drawElements(t.TRIANGLE_STRIP,b._lineIndexesBuffer.numItems,t.UNSIGNED_INT,0),t.bindBuffer(t.ARRAY_BUFFER,b._lineThicknessBuffer),t.vertexAttribPointer(y.thickness,b._lineThicknessBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,b._lineColorsBuffer),t.vertexAttribPointer(y.color,b._lineColorsBuffer.itemSize,t.FLOAT,!1,0,0),t.uniform1f(x.thicknessOutline,2),t.uniform1f(x.alpha,.54),t.drawElements(t.TRIANGLE_STRIP,b._lineIndexesBuffer.numItems,t.UNSIGNED_INT,0),t.uniform1f(x.thicknessOutline,1),t.uniform1f(x.alpha,1),t.drawElements(t.TRIANGLE_STRIP,b._lineIndexesBuffer.numItems,t.UNSIGNED_INT,0),u&&(_.bindOutputTexture(p),t.uniform1f(x.thicknessOutline,8),t.bindBuffer(t.ARRAY_BUFFER,b._linePickingColorsBuffer),t.vertexAttribPointer(y.color,b._linePickingColorsBuffer.itemSize,t.FLOAT,!1,0,0),t.drawElements(t.TRIANGLE_STRIP,b._lineIndexesBuffer.numItems,t.UNSIGNED_INT,0))}else f.isLoading=!1;u=window.performance.now()-g}t.enable(t.DEPTH_TEST),t.enable(t.CULL_FACE),_.deactivate()}}add(e){this._queue.push(e)}remove(e){}get queueSize(){return this._queue.length}}class qa extends Ri{constructor(e={}){super(e.name),this._renderingFadingNodes=(e,t,i,s,n,r,o)=>{let a=0===n,l=this.terrain.equalizeVertices;for(let h=0,c=i._fadingNodes.length;h<c;h++){let c=i._fadingNodes[h].segment;this._fadingNodes.has(i._fadingNodes[0].__id)&&!e.has(c.node.__id)&&(e.set(c.node.__id,!0),c._transitionOpacity<1?r.push(c):a?(l&&c.equalize(),c.readyToEngage&&c.engage(),c.screenRendering(t,s,n),o.push(c)):c.screenRendering(t,s,n,this.transparentTexture,!0))}},this._renderingFadingNodesNoDepth=(e,t,i,s,n,r)=>{let o=0===n,a=this.terrain.equalizeVertices,l=t.gl;l.disable(l.DEPTH_TEST);for(let l=0,h=i._fadingNodes.length;l<h;l++){let h=i._fadingNodes[l].segment;this._fadingNodes.has(i._fadingNodes[0].__id)&&!e.has(h.node.__id)&&(e.set(h.node.__id,!0),o?(a&&h.equalize(),h.readyToEngage&&h.engage(),h.screenRendering(t,s,n),r.push(h)):h.screenRendering(t,s,n,this.transparentTexture,!0))}l.enable(l.DEPTH_TEST)},this._atmosphere=new jo(e.atmosphereParameters),this._prevNodes=new Map,this._currNodes=new Map,this.transitionTime=580,this.ellipsoid=e.ellipsoid||ce,this.lightEnabled=!0,this._planetRadius2=(this.ellipsoid.getPolarSize()-1e4)*(this.ellipsoid.getPolarSize()-1e4),this._layers=[],this._updateLayer=!1,this.visibleTileLayers=[],this.visibleVectorLayers=[],this._visibleVectorLayersByDepthOrder=[],this._visibleTileLayerSlices=[],this._visibleEntityCollections=[[]],this.baseLayer=null,this.terrain=null,this.camera=new Ua(this,{frustums:e.frustums,eye:new oe(25e6,0,0),look:oe.ZERO,up:oe.NORTH,minAltitude:e.minAltitude,maxAltitude:e.maxAltitude}),this.maxEqualZoomAltitude=e.maxEqualZoomAltitude||15e6,this.minEqualZoomAltitude=e.minEqualZoomAltitude||1e4,this.minEqualZoomCameraSlope=e.minEqualZoomCameraSlope||.8,this.mousePositionOnEarth=new oe,this.emptyTexture=null,this.transparentTexture=null,this.defaultTexture=null,this.minCurrZoom=o,this.maxCurrZoom=a,this._viewExtent=new te(new I(180,180),new I(-180,-180)),this._skipPreRender=!1,this._initialViewExtent=null,this._createdNodesCount=0,this._renderedNodes=[],this._renderedNodesInFrustum=[],this._fadingNodes=new Map,this._fadingNodesInFrustum=[],this._fadingOpaqueSegments=[],this.layerLock=new Rn,this.terrainLock=new Rn,this._heightFactor=1,this._indexesCache=[],this._indexesCacheToRemove=[],this._indexesCacheToRemoveCounter=0,this._textureCoordsBufferCache=[],this.quadTreeStrategy=e.quadTreeStrategyPrototype?new e.quadTreeStrategyPrototype(this):new Sa(this),this._nightTexture=null,this._specularTexture=null;let t=Se(e.ambient,new oe(.2,.2,.3)),i=Se(e.diffuse,new oe(1,1,1)),s=Se(e.specular,new oe(63e-5,55e-5,32e-5)),n=e.shininess||18;this._ambient=new Float32Array([t.x,t.y,t.z]),this._diffuse=new Float32Array([i.x,i.y,i.z]),this._specular=new Float32Array([s.x,s.y,s.z,n]),this._maxGridSize=Math.log2(e.maxGridSize||256),this.SLICE_SIZE=4,this.SLICE_SIZE_4=4*this.SLICE_SIZE,this.SLICE_SIZE_3=3*this.SLICE_SIZE,this._lodSize=250,this._curLodSize=250,this._minLodSize=312,this._maxLodSize=190,this._pickingColorArr=new Float32Array(this.SLICE_SIZE_4),this._samplerArr=new Int32Array(this.SLICE_SIZE),this._pickingMaskArr=new Int32Array(this.SLICE_SIZE),this._geoImageCreator=new Ra(this),this._vectorTileCreator=new Wa(this),this._normalMapCreator=new Ia(this),this._terrainWorker=new Ga(3),this._plainSegmentWorker=new Da(3),this._tileLoader=new ka(e.maxLoadingRequests||12),this._memKey=new Bn,this.events=Mt($a),this._distBeforeMemClear=0,this._prevCamEye=new oe,this._initialized=!1,this.always=[],this._renderCompleted=!1,this._renderCompletedActivated=!1,this._terrainCompleted=!1,this._terrainCompletedActivated=!1,this._collectRenderNodesIsActive=!0,this.nightTextureCoefficient=2,this._renderScreenNodesPASS=this._renderScreenNodesPASSNoAtmos,this._renderScreenNodesWithHeightPASS=this._renderScreenNodesWithHeightPASSNoAtmos,this._atmosphereEnabled=e.atmosphereEnabled||!1,this._atmosphereMaxMinOpacity=new Float32Array([.95,.28]),this.solidTextureOne=null,this.solidTextureTwo=null,this._nightTextureSrc=e.nightTextureSrc||null,this._specularTextureSrc=e.specularTextureSrc||null,this._transitionOpacityEnabled=null==e.transitionOpacityEnabled||e.transitionOpacityEnabled}get terrainReady(){return this._terrainCompleted&&this._terrainCompletedActivated}get maxGridSize(){return this._maxGridSize}getNorthFrameRotation(e){return this.getFrameRotation(e)}getFrameRotation(e){return this.ellipsoid.getNorthFrameRotation(e)}set atmosphereMaxOpacity(e){this._atmosphereMaxMinOpacity[0]=e}get atmosphereMaxOpacity(){return this._atmosphereMaxMinOpacity[0]}set atmosphereMinOpacity(e){this._atmosphereMaxMinOpacity[1]=e}get atmosphereMinOpacity(){return this._atmosphereMaxMinOpacity[1]}set atmosphereEnabled(e){e!=this._atmosphereEnabled&&(this._atmosphereEnabled=e,this._initializeAtmosphere())}get atmosphereEnabled(){return this._atmosphereEnabled}set diffuse(e){let t=Se(e);this._diffuse=new Float32Array(t.toArray())}set ambient(e){let t=Se(e);this._ambient=new Float32Array(t.toArray())}set specular(e){let t=Se(e);this._specular=new Float32Array([t.x,t.y,t.y,this._specular[3]])}set shininess(e){this._specular[3]=e}get normalMapCreator(){return this._normalMapCreator}get layers(){return[...this._layers]}getLayers(){return this.layers}get sun(){if(this.renderer&&this.renderer.controls.sun)return this.renderer.controls.sun}get sunPos(){return this.sun.sunlight.getPosition()}addControl(e){e.planet=this,e.addTo(this.renderer)}get lodSize(){return this._lodSize}setLodSize(e,t,i){this._maxLodSize=i||this._maxLodSize,this._minLodSize=t||this._minLodSize,this._curLodSize=e,this._renderCompletedActivated=!1,this._terrainCompletedActivated=!1}addControls(e){for(let t=0;t<e.length;t++)this.addControl(e[t])}getLayerByName(e){for(let t=0,i=this._layers.length;t<i;t++)if(e===this._layers[t].name)return this._layers[t]}addLayer(e){e.addTo(this)}_onLayerVisibilityChanged(e){this.events.dispatch(this.events.layervisibilitychange,e)}addLayers(e){for(let t=0,i=e.length;t<i;t++)this.addLayer(e[t])}removeLayer(e){e.remove()}_clearLayerMaterial(e){this.quadTreeStrategy.clearLayerMaterial(e)}setBaseLayer(e){this.baseLayer?this.baseLayer.isEqual(e)||(this.baseLayer.setVisibility(!1),this.baseLayer=e,e.setVisibility(!0),this.events.dispatch(this.events.baselayerchange,e)):(this.baseLayer=e,this.baseLayer.setVisibility(!0),this.events.dispatch(this.events.baselayerchange,e))}setHeightFactor(e){this._renderCompletedActivated=!1,this._terrainCompletedActivated=!1,this._heightFactor!==e&&(this._heightFactor=e,this.quadTreeStrategy.destroyBranches(),this._clearRenderedNodeList(),this._clearRenderNodesInFrustum())}getHeightFactor(){return this._heightFactor}setTerrain(e){this._renderCompletedActivated=!1,this._terrainCompletedActivated=!1,this._initialized&&this.memClear(),this.terrain&&(this.terrain.abortLoading(),this.terrain.clearCache(),this.terrain._planet=null),this.terrain=e,this.terrain._planet=this,this.quadTreeStrategy.destroyBranches(),e._geoid.model?(this._plainSegmentWorker.setGeoid(e.getGeoid()),e._isReady=!0):Ma.loadModel(e.geoid.src).then((t=>{e.geoid.setModel(t),this._plainSegmentWorker.setGeoid(e.getGeoid()),e._isReady=!0})).catch((e=>{console.warn(e)}))}initAtmosphereShader(e){if(this.renderer&&this.renderer.handler&&this._atmosphereEnabled){let t=this.renderer.handler;t.isWebGl2()?(t.removeProgram("drawnode_screen_wl"),t.addProgram(Oo(e),!0)):console.warn("Atmosphere WebGL2 only")}}get atmosphereControl(){return this._atmosphere}_initializeAtmosphere(){if(!this.renderer)return;let e=this.renderer.handler;e.removeProgram("drawnode_screen_wl"),this._atmosphereEnabled?(this._renderScreenNodesPASS=this._renderScreenNodesPASSAtmos,this._renderScreenNodesWithHeightPASS=this._renderScreenNodesWithHeightPASSAtmos,this.renderer.controls.Atmosphere||this.addControl(this._atmosphere),this._atmosphere.activate(),e.isWebGl2()?e.addProgram(Oo(this._atmosphere.parameters),!0):e.addProgram(Ho(),!0),this.renderer.controls.SimpleSkyBackground&&this.renderer.controls.SimpleSkyBackground.deactivate()):(this._renderScreenNodesPASS=this._renderScreenNodesPASSNoAtmos,this._renderScreenNodesWithHeightPASS=this._renderScreenNodesWithHeightPASSNoAtmos,this._atmosphere.deactivate(),this.renderer.controls.SimpleSkyBackground?this.renderer.controls.SimpleSkyBackground.activate():this.addControl(new Kn),e.isWebGl2()?e.addProgram(new Ni("drawnode_screen_wl",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",height:"float",uGlobalTextureCoord:"vec4",uNormalMapBias:"vec3",samplerCount:"int",tileOffsetArr:"vec4",layerOpacityArr:"float",samplerArr:"sampler2darray",defaultTexture:"sampler2d",uNormalMap:"sampler2d",nightTexture:"sampler2d",specularTexture:"sampler2d",lightPosition:"vec3",diffuse:"vec3",ambient:"vec3",specular:"vec4",camHeight:"float",nightTextureCoefficient:"float",transitionOpacity:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"#version 300 es\n\n precision highp float;\n\n in vec3 aVertexPositionHigh;\n in vec3 aVertexPositionLow;\n in vec2 aTextureCoord;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec4 uGlobalTextureCoord;\n uniform vec3 uNormalMapBias;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n out vec4 vTextureCoord;\n out vec3 v_vertex;\n out vec3 cameraPosition;\n out vec2 vGlobalTextureCoord;\n out float v_height;\n\n void main(void) {\n\n vec3 aVertexPosition = aVertexPositionHigh + aVertexPositionLow; \n vec3 nh = height * normalize(aVertexPosition);\n \n vTextureCoord.xy = aTextureCoord;\n vGlobalTextureCoord = uGlobalTextureCoord.xy + (uGlobalTextureCoord.zw - uGlobalTextureCoord.xy) * aTextureCoord;\n vTextureCoord.zw = uNormalMapBias.z * ( aTextureCoord + uNormalMapBias.xy );\n\n cameraPosition = eyePositionHigh + eyePositionLow;\n \n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n v_height = height;\n v_vertex = aVertexPosition + nh;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:`#version 300 es\n\n precision highp float;\n \n\n #define SLICE_SIZE 5\n\n uniform vec4 specular;\n uniform vec3 diffuse;\n uniform vec3 ambient; \n\n uniform sampler2D uNormalMap;\n uniform sampler2D nightTexture;\n uniform sampler2D specularTexture;\n uniform sampler2D defaultTexture;\n uniform sampler2D samplerArr[SLICE_SIZE];\n\n uniform vec4 tileOffsetArr[SLICE_SIZE];\n uniform vec3 lightPosition;\n uniform float layerOpacityArr[SLICE_SIZE];\n\n uniform int samplerCount;\n uniform float nightTextureCoefficient;\n \n uniform float transitionOpacity;\n \n uniform float camHeight;\n\n in vec4 vTextureCoord;\n in vec3 v_vertex;\n in vec3 cameraPosition;\n in vec2 vGlobalTextureCoord;\n in float v_height;\n\n vec3 sunPos;\n\n layout(location = 0) out vec4 diffuseColor;\n\n ${Do}\n\n ${Fo}\n \n ${ds}\n \n void main(void) {\n \n sunPos = lightPosition;\n \n vec3 texNormal = texture(uNormalMap, vTextureCoord.zw).rgb;\n vec3 normal = normalize((texNormal - 0.5) * 2.0);\n \n float minH = 1200000.0;\n float maxH = minH * 3.0;\n float nightCoef = getLerpValue(minH, maxH, camHeight) * nightTextureCoefficient;\n \n // if(camHeight > 6000000.0)\n // {\n // normal = normalize(v_vertex);\n // }\n \n vec3 lightDir = normalize(sunPos);\n vec3 viewDir = normalize(cameraPosition - v_vertex);\n \n float overGround = 1.0 - step(0.1, v_height);\n\n float shininess = texture( specularTexture, vGlobalTextureCoord.st ).r * 255.0 * overGround;\n vec3 reflectionDirection = reflect(-lightDir, normal);\n float reflection = max( dot(reflectionDirection, viewDir), 0.0);\n vec3 spec = specular.rgb * pow( reflection, specular.w) * shininess; \n float diffuseLightWeighting = max(dot(normal, lightDir), 0.0); \n vec4 nightImageColor = texture( nightTexture, vGlobalTextureCoord.st );\n vec3 night = nightStep * (.18 - diffuseLightWeighting * 3.0) * nightImageColor.rgb * nightCoef;\n night *= overGround * step(0.0, night); \n vec4 lightWeighting = vec4(ambient + diffuse * diffuseLightWeighting + night, 1.0);\n \n diffuseColor = texture( defaultTexture, vTextureCoord.xy );\n \n if( samplerCount == 0 ) {\n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n vec4 src;\n\n blend(diffuseColor, samplerArr[0], tileOffsetArr[0], layerOpacityArr[0]);\n if( samplerCount == 1 ) { \n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[1], tileOffsetArr[1], layerOpacityArr[1]);\n if( samplerCount == 2 ) {\n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[2], tileOffsetArr[2], layerOpacityArr[2]);\n if( samplerCount == 3 ) {\n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[3], tileOffsetArr[3], layerOpacityArr[3]);\n if( samplerCount == 4 ) {\n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[4], tileOffsetArr[4], layerOpacityArr[4]);\n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n }`}),!0):e.addProgram(Ho(),!0))}_initializeShaders(){let e=this.renderer.handler;e.addProgram(new Ni("drawnode_screen_nl",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",samplerCount:"int",tileOffsetArr:"vec4",layerOpacityArr:"float",samplerArr:"sampler2darray",defaultTexture:"sampler2d",height:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"precision highp float;\n \n attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n attribute vec2 aTextureCoord;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n varying vec2 vTextureCoord;\n\n void main(void) {\n\n vTextureCoord = aTextureCoord;\n vec3 nh = height * normalize(aVertexPositionHigh + aVertexPositionLow);\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n mat4 m = projectionMatrix * viewMatrixRTE;\n \n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n \n // This is works for Mac Chrome, prevent some weird optimization I suppose\n gl_Position = m * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:`precision highp float;\n #define SLICE_SIZE 5\n uniform vec4 tileOffsetArr[SLICE_SIZE];\n uniform float layerOpacityArr[SLICE_SIZE];\n uniform sampler2D defaultTexture;\n uniform sampler2D samplerArr[SLICE_SIZE];\n uniform int samplerCount;\n varying vec2 vTextureCoord;\n\n ${No}\n\n void main(void) {\n gl_FragColor = texture2D( defaultTexture, vTextureCoord );\n if( samplerCount == 0 ) return;\n\n vec4 src;\n\n blend(gl_FragColor, samplerArr[0], tileOffsetArr[0], layerOpacityArr[0]);\n if( samplerCount == 1 ) return;\n\n blend(gl_FragColor, samplerArr[1], tileOffsetArr[1], layerOpacityArr[1]);\n if( samplerCount == 2 ) return;\n\n blend(gl_FragColor, samplerArr[2], tileOffsetArr[2], layerOpacityArr[2]);\n if( samplerCount == 3 ) return;\n\n blend(gl_FragColor, samplerArr[3], tileOffsetArr[3], layerOpacityArr[3]);\n if( samplerCount == 4 ) return;\n\n blend(gl_FragColor, samplerArr[4], tileOffsetArr[4], layerOpacityArr[4]);\n }`}),!0),e.addProgram(new Ni("drawnode_colorPicking",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",samplerCount:"int",tileOffsetArr:"vec4",samplerArr:"sampler2darray",pickingMaskArr:"sampler2darray",pickingColorArr:"vec4",height:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"precision highp float;\n \n attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n attribute vec2 aTextureCoord;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n varying vec2 vTextureCoord;\n\n void main(void) {\n\n vTextureCoord = aTextureCoord;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n mat4 m = projectionMatrix * viewMatrixRTE;\n\n vec3 nh = height * normalize(aVertexPositionHigh + aVertexPositionLow);\n\n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n\n gl_Position = m * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:"precision highp float;\n #define SLICE_SIZE 5\n uniform vec4 tileOffsetArr[SLICE_SIZE];\n uniform vec4 pickingColorArr[SLICE_SIZE];\n uniform sampler2D samplerArr[SLICE_SIZE];\n uniform sampler2D pickingMaskArr[SLICE_SIZE];\n uniform int samplerCount;\n varying vec2 vTextureCoord;\n\n #define blendPicking(DEST, OFFSET, SAMPLER, MASK, COLOR, OPACITY) tc = OFFSET.xy + vTextureCoord.xy * OFFSET.zw; t = texture2D(SAMPLER, tc); p = texture2D(MASK, tc); DEST = mix(DEST, vec4(max(COLOR.rgb, p.rgb), OPACITY), (t.a == 0.0 ? 0.0 : 1.0) * COLOR.a);\n\n void main(void) {\n gl_FragColor = vec4(0.0);\n if( samplerCount == 0 ) return;\n\n vec2 tc;\n vec4 t;\n vec4 p;\n\n blendPicking(gl_FragColor, tileOffsetArr[0], samplerArr[0], pickingMaskArr[0], pickingColorArr[0], 1.0);\n if( samplerCount == 1 ) return;\n\n blendPicking(gl_FragColor, tileOffsetArr[1], samplerArr[1], pickingMaskArr[1], pickingColorArr[1], 1.0);\n if( samplerCount == 2 ) return;\n\n blendPicking(gl_FragColor, tileOffsetArr[2], samplerArr[2], pickingMaskArr[2], pickingColorArr[2], 1.0);\n if( samplerCount == 3 ) return;\n\n blendPicking(gl_FragColor, tileOffsetArr[3], samplerArr[3], pickingMaskArr[3], pickingColorArr[3], 1.0);\n if( samplerCount == 4 ) return;\n\n blendPicking(gl_FragColor, tileOffsetArr[4], samplerArr[4], pickingMaskArr[4], pickingColorArr[4], 1.0);\n }"}),!0),e.addProgram(new Ni("drawnode_depth",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",height:"float",eyePositionHigh:"vec3",eyePositionLow:"vec3",frustumPickingColor:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3"},vertexShader:"#version 300 es\n \n precision highp float;\n\n in vec3 aVertexPositionHigh;\n in vec3 aVertexPositionLow;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n void main(void) {\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n mat4 m = projectionMatrix * viewMatrixRTE;\n\n vec3 nh = height * normalize(aVertexPositionHigh + aVertexPositionLow);\n\n vec3 eyePosition = eyePositionHigh + eyePositionLow;\n vec3 vertexPosition = aVertexPositionHigh + aVertexPositionLow;\n\n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n \n gl_Position = m * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0); \n }",fragmentShader:"#version 300 es\n \n precision highp float;\n \n uniform float frustumPickingColor;\n\n layout(location = 0) out vec4 frustumColor;\n layout(location = 1) out vec4 depthColor;\n\n void main(void) {\n frustumColor = vec4(frustumPickingColor, frustumPickingColor, frustumPickingColor, 1.0);\n depthColor = vec4(gl_FragCoord.z, gl_FragCoord.z, gl_FragCoord.z, 1.0);\n }"}),!0),e.addProgram(new Ni("drawnode_heightPicking",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",height:"float",eyePositionHigh:"vec3",eyePositionLow:"vec3"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3"},vertexShader:"precision highp float;\n\n attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n \n varying vec4 vert;\n\n void main(void) {\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 nh = height * normalize(aVertexPositionHigh + aVertexPositionLow);\n\n vec3 eyePosition = eyePositionHigh + eyePositionLow;\n vec3 vertexPosition = aVertexPositionHigh + aVertexPositionLow;\n\n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n \n vert = viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n \n gl_Position = projectionMatrix * vert; \n }",fragmentShader:"precision highp float;\n \n varying vec4 vert;\n\n vec3 encode24(highp float f) {\n float F = abs(f);\n float s = step( 0.0, -f );\n float e = floor( log2(F) );\n float m = exp2(- e) * F;\n e = floor( log2(F) + 127.0 ) + floor( log2(m) );\n return vec3(\n ( 128.0 * s + floor( e * exp2(-1.0) ) ) / 255.0,\n ( 128.0 * mod( e, 2.0 ) + mod( floor( m * 128.0 ), 128.0 ) ) / 255.0,\n floor( mod( floor( m * exp2( 23.0 - 8.0) ), exp2(8.0) ) ) / 255.0);\n }\n\n void main(void) {\n gl_FragColor = vec4(encode24(length(vert.xyz)), 1.0);\n }"}),!0),this.renderer.addPickingCallback(this,this._renderColorPickingFramebufferPASS),this.renderer.addDepthCallback(this,this._renderDepthFramebufferPASS)}_onLayerLoadend(e){this.events.dispatch(this.events.layerloadend,e)}init(){this._tileLoader.events.on("layerloadend",this._onLayerLoadend,this),ko().setMaxGridSize(this._maxGridSize);const e=this._maxGridSize;let t=0;for(let i=0;i<=e;i++){!this._indexesCache[i]&&(this._indexesCache[i]=new Array(e));for(let s=0;s<=e;s++){!this._indexesCache[i][s]&&(this._indexesCache[i][s]=new Array(e));for(let n=0;n<=e;n++){!this._indexesCache[i][s][n]&&(this._indexesCache[i][s][n]=new Array(e));for(let r=0;r<=e;r++){!this._indexesCache[i][s][n][r]&&(this._indexesCache[i][s][n][r]=new Array(e));for(let o=0;o<=e;o++){let e={buffer:null};if(i>=1&&i===s&&i===n&&i===r&&i===o){let t=ko().createSegmentIndexes(i,[s,n,r,o]);e.buffer=this.renderer.handler.createElementArrayBuffer(t,1)}else this._indexesCacheToRemove[t++]=e;this._indexesCache[i][s][n][r][o]=e}}}}}this.renderer.events.on("resize",(()=>{this._renderCompletedActivated=!1,this._terrainCompletedActivated=!1})),this.renderer.events.on("drawtransparent",(()=>{this._renderScreenNodesWithHeightPASS()})),this._textureCoordsBufferCache=[];let i=ko().initTextureCoordsTable(e+1);for(let t=0;t<=e;t++)this._textureCoordsBufferCache[t]=this.renderer.handler.createArrayBuffer(i[t],2,(1+(1<<t))*(1+(1<<t)));this.renderer.handler.createDefaultTexture(null,(e=>{this.solidTextureOne=e,this.solidTextureTwo=e})),this.transparentTexture=this.renderer.handler.transparentTexture,this._renderedNodesInFrustum=new Array(this.camera.frustums.length);for(let e=0,t=this._renderedNodesInFrustum.length;e<t;e++)this._renderedNodesInFrustum[e]=[];if(this.quadTreeStrategy.init(),this.drawMode=this.renderer.handler.gl.TRIANGLE_STRIP,this._initializeShaders(),this._initializeAtmosphere(),this._updateVisibleLayers(),this._nightTextureSrc){let e=new Image;e.crossOrigin="Anonymous",e.onload=()=>{this._nightTexture=this.renderer.handler.createTextureDefault(e),this._nightTexture.default=!0},e.src=this._nightTextureSrc}if(this._specularTextureSrc){let e=new Image;e.crossOrigin="Anonymous",e.onload=()=>{this._specularTexture=this.renderer.handler.createTextureDefault(e),this._specularTexture.default=!0},e.src=this._specularTextureSrc}this._geoImageCreator.init(),this._vectorTileCreator.init(),this._normalMapCreator.init(),this.renderer.events.on("draw",this._globalPreDraw,this,-100),this._preRender(),this.renderer.events.on("postdraw",(()=>{this._checkRendercompleted()})),this.initLayers(),this._initialized=!0,this._initialViewExtent&&this.viewExtent(this._initialViewExtent),this.renderer.activeCamera=this.camera,this.camera.bindRenderer(this.renderer),this.camera.update()}initLayers(){let e=[...this._layers];for(let t=0;t<e.length;t++)this.removeLayer(e[t]),this.addLayer(e[t])}_clearIndexesCache(){this._indexesCacheToRemoveCounter=0;let e=this._indexesCacheToRemove,t=this.renderer.handler.gl;for(let i=0,s=e.length;i<s;i++){let s=e[i];t.deleteBuffer(s.buffer),s.buffer=null}}_preRender(){this.quadTreeStrategy.preRender(),this._preLoad()}_preLoad(){this._clearRenderedNodeList(),this._skipPreRender=!1,this.quadTreeStrategy.preLoad()}createDefaultTextures(e,t){this.renderer.handler.gl.deleteTexture(this.solidTextureOne),this.renderer.handler.gl.deleteTexture(this.solidTextureTwo),this.renderer.handler.createDefaultTexture(e,(e=>{this.solidTextureOne=e})),this.renderer.handler.createDefaultTexture(t,(e=>{this.solidTextureTwo=e}))}_getLayerAttributionHTML(e){return`<div class="og-attribution__layer">${e.getAttribution()}</div>`}updateAttributionsList(){let e="";for(let t=0,i=this._layers.length;t<i;t++){let i=this._layers[t];i.getVisibility()&&i.getAttribution().length&&(e+=this._getLayerAttributionHTML(i))}this._applyAttribution(e)}updateVisibleLayers(){this._updateLayer=!0}_updateVisibleLayers(){this.visibleTileLayers=[],this.visibleTileLayers.length=0,this.visibleVectorLayers=[],this.visibleVectorLayers.length=0;let e="";for(let t=0,i=this._layers.length;t<i;t++){let i=this._layers[t];i.getVisibility()?(i.isBaseLayer()&&(this.createDefaultTextures(i._defaultTextures[0],i._defaultTextures[1]),this.baseLayer=i),i.hasImageryTiles()&&this.visibleTileLayers.push(i),i.isVector&&this.visibleVectorLayers.push(i),i.getAttribution().length&&(e+=this._getLayerAttributionHTML(i))):i._fading&&i._fadingOpacity>0&&(i.hasImageryTiles()&&this.visibleTileLayers.push(i),i.isVector&&this.visibleVectorLayers.push(i))}this._applyAttribution(e),this._sortLayers()}_applyAttribution(e){this.renderer&&this.renderer.div&&(e.length?this.renderer.div.attributions.innerHTML!==e&&(this.renderer.div.attributions.innerHTML=e):this.renderer.div.attributions.innerHTML="")}_sortLayers(){this.visibleVectorLayers.sort(((e,t)=>e.getZIndex()-t.getZIndex()||e.getHeight()-t.getHeight()));let e={0:[]};for(const t of this.visibleVectorLayers)e[t.depthOrder]||(e[t.depthOrder]=[]),e[t.depthOrder].push(t);if(this._visibleVectorLayersByDepthOrder.length=0,this._visibleVectorLayersByDepthOrder=[],this._visibleVectorLayersByDepthOrder=Object.keys(e).sort(((e,t)=>Number(e)-Number(t))).map((t=>e[Number(t)])),this._visibleTileLayerSlices=[],this._visibleTileLayerSlices.length=0,this.visibleTileLayers.length){this.visibleTileLayers.sort(((e,t)=>e.getHeight()-t.getHeight()||e.getZIndex()-t.getZIndex()));let e=-1,t=this.visibleTileLayers[0].getHeight();for(let i=0,s=this.visibleTileLayers.length;i<s;i++)i%this.SLICE_SIZE!=0&&this.visibleTileLayers[i].getHeight()===t||(e++,this._visibleTileLayerSlices[e]=[],t=this.visibleTileLayers[i].getHeight()),this._visibleTileLayerSlices[e].push(this.visibleTileLayers[i])}}_clearRenderedNodeList(){this._renderedNodes.length=0,this._renderedNodes=[]}_clearRenderNodesInFrustum(){for(let e=0,t=this._renderedNodesInFrustum.length;e<t;e++)this._renderedNodesInFrustum[e].length=0,this._renderedNodesInFrustum[e]=[]}_collectRenderedNodesMaxZoom(e){if(e.slope>this.minEqualZoomCameraSlope&&e._lonLat.height<this.maxEqualZoomAltitude&&e._lonLat.height>this.minEqualZoomAltitude){this.minCurrZoom=this.maxCurrZoom;let t=this._renderedNodes,i=this._renderedNodesInFrustum,s=[];this._clearRenderNodesInFrustum(),this._renderedNodes=[];for(let n=0,r=t.length;n<r;n++){let r=t[n],o=r.segment.centerNormal.dot(e.getBackward());if(r.segment.tileZoom===this.maxCurrZoom||o<.81){this._renderedNodes.push(r);let e=0,t=r.inFrustum;for(;t;)1&t&&i[e].push(r),e++,t>>=1}else s.push(r)}for(let t=0,i=s.length;t<i;t++)s[t].renderTree(e,this.maxCurrZoom,null,!1,s[t])}}set transitionOpacityEnabled(e){this._transitionOpacityEnabled=e}get transitionOpacityEnabled(){return this._transitionOpacityEnabled}_collectRenderNodes(e){if(this._lodSize=T(e.slope<0?0:e.slope,this._curLodSize,this._minLodSize),e._insideSegment=null,this._clearRenderedNodeList(),this._clearRenderNodesInFrustum(),this._viewExtent.southWest.set(180,180),this._viewExtent.northEast.set(-180,-180),this.minCurrZoom=o,this.maxCurrZoom=a,this.quadTreeStrategy.collectRenderNodes(),this._collectRenderedNodesMaxZoom(e),this._fadingNodes.clear(),this._transitionOpacityEnabled){let e=[];for(let t=0;t<this._renderedNodes.length;t++){let i=this._renderedNodes[t];if(i._collectFadingNodes(),i._refreshTransitionOpacity(),i.segment._transitionOpacity>=1)i.clearNeighbors(),i.getRenderedNodesNeighbors(e),e.push(i);else for(let t=0;t<i._fadingNodes.length;t++){let s=i._fadingNodes[t];s.segment&&s.segment._transitionOpacity>=1&&(s.clearNeighbors(),s.getRenderedNodesNeighbors(e),e.push(s))}}}}_renderScreenNodesPASSNoAtmos(){let e=this.renderer.activeCamera,t=this._setUniformsNoAtmos(e);this._renderingScreenNodes(t,e,this._renderedNodesInFrustum[e.currentFrustumIndex])}_renderScreenNodesPASSAtmos(){let e=this.renderer.activeCamera,t=this._setUniformsAtmos(e);this._renderingScreenNodes(t,e,this._renderedNodesInFrustum[e.currentFrustumIndex])}_renderScreenNodesWithHeightPASSNoAtmos(){let e=this.renderer.activeCamera,t=this._setUniformsNoAtmos(e);this._renderingScreenNodesWithHeight(t,e,this._renderedNodesInFrustum[e.currentFrustumIndex])}_renderScreenNodesWithHeightPASSAtmos(){let e=this.renderer.activeCamera,t=this._setUniformsAtmos(e);this._renderingScreenNodesWithHeight(t,e,this._renderedNodesInFrustum[e.currentFrustumIndex])}_globalPreDraw(){let e=this.camera;this._distBeforeMemClear+=this._prevCamEye.distance(e.eye),this._prevCamEye.copy(e.eye),e.checkFly(),this._createdNodesCount>200&&this._distBeforeMemClear>1e3&&(this.terrain.clearCache(),this.memClear()),this._indexesCacheToRemoveCounter>600&&this._clearIndexesCache()}preFrame(){this._updateLayer&&(this._updateLayer=!1,this._updateVisibleLayers()),this.camera.isFirstPass&&(this.camera.update(),this._skipPreRender&&this._collectRenderNodesIsActive&&this._collectRenderNodes(this.camera),this._skipPreRender=!0,this._normalMapCreator.frame(),this._geoImageCreator.frame(),this._vectorTileCreator.frame(),this.camera.checkTerrainCollision(),this.camera.update(),this.events.dispatch(this.events.draw,this),this._collectVectorLayerCollections());for(let e=0;e<this._visibleEntityCollections.length;e++)this.drawEntityCollections(this._visibleEntityCollections[e],e)}frame(){this._renderScreenNodesPASS()}_checkRendercompleted(){this._renderCompleted?this._renderCompletedActivated||(this._renderCompletedActivated=!0,this.events.dispatch(this.events.rendercompleted,!0)):this._renderCompletedActivated=!1,this._renderCompleted=!0,this._terrainCompleted?this._terrainCompletedActivated||(this._terrainCompletedActivated=!0,this.events.dispatch(this.events.terraincompleted,!0)):this._terrainCompletedActivated=!1,this._terrainCompleted=!0}lockQuadTree(){this._collectRenderNodesIsActive=!1,this.camera.setTerrainCollisionActivity(!1)}unlockQuadTree(){this._collectRenderNodesIsActive=!0,this.camera.setTerrainCollisionActivity(!0)}_setUniformsNoAtmos(e){let t,i,s=this.renderer,n=s.handler,r=n.gl;return r.enable(r.CULL_FACE),s.enableBlendOneSrcAlpha(),this.lightEnabled?(n.programs.drawnode_screen_wl.activate(),t=n.programs.drawnode_screen_wl._program,i=t.uniforms,r.uniform3fv(i.lightPosition,this._lightPosition),r.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),r.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix()),this.baseLayer?(r.uniform3fv(i.diffuse,this.baseLayer._diffuse||this._diffuse),r.uniform3fv(i.ambient,this.baseLayer._ambient||this._ambient),r.uniform4fv(i.specular,this.baseLayer._specular||this._specular),r.uniform1f(i.nightTextureCoefficient,this.baseLayer.nightTextureCoefficient||this.nightTextureCoefficient)):(r.uniform3fv(i.diffuse,this._diffuse),r.uniform3fv(i.ambient,this._ambient),r.uniform4fv(i.specular,this._specular),r.uniform1f(i.nightTextureCoefficient,this.nightTextureCoefficient)),r.activeTexture(r.TEXTURE0+this.SLICE_SIZE),r.bindTexture(r.TEXTURE_2D,this._nightTexture||this.transparentTexture),r.uniform1i(i.nightTexture,this.SLICE_SIZE),r.activeTexture(r.TEXTURE0+this.SLICE_SIZE+1),r.bindTexture(r.TEXTURE_2D,this._specularTexture||this.transparentTexture),r.uniform1i(i.specularTexture,this.SLICE_SIZE+1),r.uniform1f(i.camHeight,e.getHeight())):(n.programs.drawnode_screen_nl.activate(),t=n.programs.drawnode_screen_nl._program,i=t.uniforms,r.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),r.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix())),r.uniform3fv(i.eyePositionHigh,e.eyeHigh),r.uniform3fv(i.eyePositionLow,e.eyeLow),t}_setUniformsAtmos(e){let t,i,s=this.renderer,n=s.handler,r=n.gl;return r.enable(r.CULL_FACE),s.enableBlendOneSrcAlpha(),this.lightEnabled?(n.programs.drawnode_screen_wl.activate(),t=n.programs.drawnode_screen_wl._program,i=t.uniforms,r.uniform3fv(i.lightPosition,this._lightPosition),r.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),r.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix()),this.baseLayer?(r.uniform3fv(i.diffuse,this.baseLayer._diffuse||this._diffuse),r.uniform3fv(i.ambient,this.baseLayer._ambient||this._ambient),r.uniform4fv(i.specular,this.baseLayer._specular||this._specular),r.uniform1f(i.nightTextureCoefficient,this.baseLayer.nightTextureCoefficient||this.nightTextureCoefficient)):(r.uniform3fv(i.diffuse,this._diffuse),r.uniform3fv(i.ambient,this._ambient),r.uniform4fv(i.specular,this._specular),r.uniform1f(i.nightTextureCoefficient,this.nightTextureCoefficient)),r.uniform2fv(i.maxMinOpacity,this._atmosphereMaxMinOpacity),r.activeTexture(r.TEXTURE0+this.SLICE_SIZE),r.bindTexture(r.TEXTURE_2D,this._nightTexture||this.transparentTexture),r.uniform1i(i.nightTexture,this.SLICE_SIZE),r.activeTexture(r.TEXTURE0+this.SLICE_SIZE+1),r.bindTexture(r.TEXTURE_2D,this._specularTexture||this.transparentTexture),r.uniform1i(i.specularTexture,this.SLICE_SIZE+1),r.activeTexture(r.TEXTURE0+this.SLICE_SIZE+4),r.bindTexture(r.TEXTURE_2D,s.controls.Atmosphere._transmittanceBuffer.textures[0]),r.uniform1i(i.transmittanceTexture,this.SLICE_SIZE+4),r.activeTexture(r.TEXTURE0+this.SLICE_SIZE+5),r.bindTexture(r.TEXTURE_2D,s.controls.Atmosphere._scatteringBuffer.textures[0]),r.uniform1i(i.scatteringTexture,this.SLICE_SIZE+5),r.uniform1f(i.camHeight,e.getHeight())):(n.programs.drawnode_screen_nl.activate(),t=n.programs.drawnode_screen_nl._program,i=t.uniforms,r.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),r.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix())),r.uniform3fv(i.eyePositionHigh,e.eyeHigh),r.uniform3fv(i.eyePositionLow,e.eyeLow),t}_renderingScreenNodes(e,t,i){let s=t.isFirstPass,n=this._visibleTileLayerSlices;if(n.length){let e=n[0];for(let t=e.length-1;t>=0;--t){let i=e[t];i._fading&&s&&i._refreshFadingOpacity()&&e.splice(t,1)}}let r=new Map,o=[],a=this.terrain.equalizeVertices,l=i.length;if(this._fadingOpaqueSegments=[],t.slope>.8||!this.terrain||this.terrain.isEmpty)for(;l--;){let t=i[l],s=t.segment;this._renderingFadingNodesNoDepth(r,e,t,n[0],0,this._fadingOpaqueSegments),a&&s.equalize(),s.readyToEngage&&s.engage(),s.screenRendering(e,n[0],0)}else{for(;l--;){let t=i[l],s=t.segment;this._renderingFadingNodes(r,e,t,n[0],0,o,this._fadingOpaqueSegments),s._transitionOpacity<1?o.push(s):(a&&s.equalize(),s.readyToEngage&&s.engage(),s.screenRendering(e,n[0],0))}for(let t=0;t<o.length;t++){let i=o[t];a&&i.equalize(),i.readyToEngage&&i.engage(),i.screenRendering(e,n[0],0)}}}_renderingScreenNodesWithHeight(e,t,i){let s=this.renderer.handler.gl,n=t.isFirstPass,r=this._visibleTileLayerSlices;s.enable(s.POLYGON_OFFSET_FILL),s.disable(s.CULL_FACE);let o=new Map,a=[];for(let t=1,l=r.length;t<l;t++){let l=r[t];for(let e=l.length-1;e>=0;--e){let t=l[e];t._fading&&n&&t._refreshFadingOpacity()&&l.splice(e,1)}s.polygonOffset(0,-t);let h=i.length;for(;h--;){let s=i[h];this._renderingFadingNodes(o,e,s,r[t],t,a),s.segment._transitionOpacity<1?s.segment.initSlice(t):s.segment.screenRendering(e,r[t],t,this.transparentTexture,!0)}}s.disable(s.POLYGON_OFFSET_FILL),s.enable(s.CULL_FACE)}_renderColorPickingFramebufferPASS(){let e,t=this.renderer,i=t.handler,s=i.gl;i.programs.drawnode_colorPicking.activate(),e=i.programs.drawnode_colorPicking._program;let n=e.uniforms,r=t.activeCamera;s.enable(s.CULL_FACE),s.uniformMatrix4fv(n.viewMatrix,!1,r.getViewMatrix()),s.uniformMatrix4fv(n.projectionMatrix,!1,r.getProjectionMatrix()),s.uniform3fv(n.eyePositionHigh,r.eyeHigh),s.uniform3fv(n.eyePositionLow,r.eyeLow);let o=this._renderedNodesInFrustum[r.getCurrentFrustum()],a=this._visibleTileLayerSlices,l=o.length;for(;l--;)o[l].segment._transitionOpacity>=1&&o[l].segment.colorPickingRendering(e,a[0],0);for(let t=0;t<this._fadingOpaqueSegments.length;++t)this._fadingOpaqueSegments[t].colorPickingRendering(e,a[0],0);t.enableBlendDefault(),s.enable(s.POLYGON_OFFSET_FILL);for(let t=1,i=a.length;t<i;t++)for(l=o.length,s.polygonOffset(0,-t);l--;)o[l].segment.colorPickingRendering(e,a[t],t,this.transparentTexture,!0);s.disable(s.POLYGON_OFFSET_FILL)}_renderDepthFramebufferPASS(){let e,t=this.renderer,i=t.handler,s=i.gl;i.programs.drawnode_depth.activate(),e=i.programs.drawnode_depth._program;let n=e.uniforms,r=t.activeCamera;s.disable(s.BLEND),s.disable(s.POLYGON_OFFSET_FILL),s.uniformMatrix4fv(n.viewMatrix,!1,r.getViewMatrix()),s.uniformMatrix4fv(n.projectionMatrix,!1,r.getProjectionMatrix()),s.uniform3fv(n.eyePositionHigh,r.eyeHigh),s.uniform3fv(n.eyePositionLow,r.eyeLow),s.uniform1f(n.frustumPickingColor,r.frustumColorIndex);let o=this._renderedNodesInFrustum[r.getCurrentFrustum()],a=this._visibleTileLayerSlices,l=o.length;for(;l--;)o[l].segment._transitionOpacity>=1&&o[l].segment.depthRendering(e,a[0]);for(let t=0;t<this._fadingOpaqueSegments.length;++t)this._fadingOpaqueSegments[t].depthRendering(e,a[0]);s.enable(s.BLEND)}_collectVectorLayerCollections(){let e=this._visibleVectorLayersByDepthOrder.length;this._visibleEntityCollections.length=0,this._visibleEntityCollections=new Array(e);for(let e=0;e<this._visibleEntityCollections.length;e++)this._visibleEntityCollections[e]=[];for(;e--;){let t=this._visibleVectorLayersByDepthOrder[e],i=t.length;for(;i--;){let s=t[i];s._fading&&s._refreshFadingOpacity()&&(t.splice(i,1),0===t.length&&this._visibleVectorLayersByDepthOrder.splice(e,1)),s.collectVisibleCollections(this._visibleEntityCollections[e]),s.update()}}}memClear(){this._distBeforeMemClear=0,this.camera._insideSegment=null,this.layerLock.lock(this._memKey),this.terrainLock.lock(this._memKey),this._normalMapCreator.lock(this._memKey),this._normalMapCreator.clear(),this.terrain.abortLoading(),this._tileLoader.abortAll(),this.quadTreeStrategy.clear(),this.layerLock.free(this._memKey),this.terrainLock.free(this._memKey),this._normalMapCreator.free(this._memKey),this._createdNodesCount=0}getRayIntersectionEllipsoid(e){return this.ellipsoid.hitRay(e.origin,e.direction)}getCartesianFromPixelEllipsoid(e){let t=this.renderer.activeCamera;return this.ellipsoid.hitRay(t.eye,t.unproject(e.x,e.y))}getLonLatFromPixelEllipsoid(e){let t=this.getCartesianFromPixelEllipsoid(e);if(t)return this.ellipsoid.cartesianToLonLat(t)}getCartesianFromMouseTerrain(){let e=this.renderer.events.mouseState,t=this.getDistanceFromPixel(e);if(t)return e.direction.scaleTo(t).addA(this.renderer.activeCamera.eye)}getCartesianFromPixelTerrain(e){let t=this.getDistanceFromPixel(e);if(t){return(e.direction||this.renderer.activeCamera.unproject(e.x,e.y)).scaleTo(t).addA(this.renderer.activeCamera.eye)}}getLonLatFromPixelTerrain(e){let t=this.getCartesianFromPixelTerrain(e);if(t)return this.ellipsoid.cartesianToLonLat(t)}getPixelFromCartesian(e){return this.renderer.activeCamera.project3v(e)}getPixelFromLonLat(e){let t=this.ellipsoid.lonLatToCartesian(e);if(t)return this.renderer.activeCamera.project3v(t)}getDistanceFromPixelEllipsoid(e){let t=this.getCartesianFromPixelEllipsoid(e);if(t)return t.distance(this.renderer.activeCamera.eye)}getDistanceFromPixel(e){return this.renderer.getDistanceFromPixel(e)||this.getDistanceFromPixelEllipsoid(e)||0}viewExtent(e){this.camera?this.camera.viewExtent(e):this._initialViewExtent=e}viewExtentArr(e){this.viewExtent(new te(new I(e[0],e[1]),new I(e[2],e[3])))}getViewExtent(){if(this.renderer){let e=this.renderer.handler.getWidth(),t=this.renderer.handler.getHeight(),i=[this.getLonLatFromPixelTerrain(new ae(0,0)),this.getLonLatFromPixelTerrain(new ae(e,0)),this.getLonLatFromPixelTerrain(new ae(e,t)),this.getLonLatFromPixelTerrain(new ae(0,t))];if(i[0]&&i[1]&&i[2]&&i[3]){let e=i[0].lon,t=i[2].lat,s=i[1].lon,n=i[0].lat;for(let r=0;r<i.length;r++)i[r].lon>s&&(s=i[r].lon),i[r].lat>n&&(n=i[r].lat),i[r].lon<e&&(e=i[r].lon),i[r].lat<t&&(t=i[r].lat);return new te(new I(e,t),new I(s,n))}}return this._viewExtent}viewLonLat(e,t,i){this.camera.setLonLat(e,t,i)}flyExtent(e,t,i,s,n,r){this.camera.flyExtent(e,t,i,s,n,r)}flyCartesian(e,t,i,s,n,r,o){this.camera.flyCartesian(e,t,i,s,n,r,o)}flyLonLat(e,t,i,s,n,r,o){this.camera.flyLonLat(e,t,i,s,n,r,o)}stopFlying(){this.camera.stopFlying()}updateBillboardsTexCoords(){for(let e=0;e<this.entityCollections.length;e++)this.entityCollections[e].billboardHandler.refreshTexCoordsArr();let e={};for(let t=0;t<this._layers.length;t++){let i=this._layers[t];i instanceof qs&&i.each((function(t){t._entityCollection&&!e[t._entityCollection.id]&&(t._entityCollection.billboardHandler.refreshTexCoordsArr(),e[t._entityCollection.id]=!0)}))}}getEntityTerrainPoint(e,t){let i=this._renderedNodes,s=i.length;for(;s--;)if(i[s].segment.isEntityInside(e))return i[s].segment.getEntityTerrainPoint(e,t)}async getHeightDefault(e){return new Promise((t=>{this.terrain?this.terrain.getHeightAsync(e.clone(),(e=>{t(e)})):t(0)}))}async getHeightAboveELL(e){return new Promise((t=>{this.terrain?this.terrain.getHeightAsync(e.clone(),(i=>{t(i+this.terrain.geoid.getHeightLonLat(e))})):t(0)}))}onremove(){this.memClear(),this.quadTreeStrategy.destroyBranches(),this._renderedNodes=[]}stopDragging(){this.renderer&&this.renderer.controls.EarthNavigation&&this.renderer.controls.EarthNavigation.stop()}}const $a=["draw","layeradd","baselayerchange","layerremove","layervisibilitychange","rendercompleted","terraincompleted","layerloadend"];class Xa extends Ri{constructor(e){super("skybox"),this.params=e,this.vertexPositionBuffer=null,this.texture=null}static createDefault(e){return new Xa({nx:e+"skybox/gal/_nx.jpg",px:e+"skybox/gal/_px.jpg",py:e+"skybox/gal/_py.jpg",ny:e+"skybox/gal/_ny.jpg",pz:e+"skybox/gal/_pz.jpg",nz:e+"skybox/gal/_nz.jpg"})}init(){this.renderer.handler.addProgram(new Ni("skybox",{uniforms:{projectionViewMatrix:{type:Ii.MAT4},uSampler:{type:Ii.SAMPLERCUBE},pos:{type:Ii.VEC3}},attributes:{aVertexPosition:{type:Ii.VEC3,enableArray:!0}},vertexShader:"attribute vec3 aVertexPosition;\n uniform mat4 projectionViewMatrix;\n uniform vec3 pos;\n varying vec3 vTextureCoord;\n void main(void) {\n vTextureCoord = aVertexPosition;\n gl_Position = projectionViewMatrix * vec4(aVertexPosition + pos, 1.0);\n }",fragmentShader:"precision lowp float;\n varying vec3 vTextureCoord;\n uniform samplerCube uSampler;\n void main(void) {\n gl_FragColor = textureCube(uSampler, vTextureCoord);\n }"}),!0),this.texture=this.renderer.handler.loadCubeMapTexture(this.params),this._createBuffers(),this.drawMode=this.renderer.handler.gl.TRIANGLES}frame(){let e=this.renderer.handler,t=e.gl,i=this.renderer.activeCamera;t.disable(t.DEPTH_TEST),e.programs.skybox.activate();let s=e.programs.skybox._program,n=s.uniforms;t.uniformMatrix4fv(n.projectionViewMatrix,!1,i.getProjectionViewMatrix()),t.uniform3fv(n.pos,i.eye.toArray()),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_CUBE_MAP,this.texture),t.uniform1i(n.uSampler,0);let r=this.vertexPositionBuffer;t.bindBuffer(t.ARRAY_BUFFER,r),t.vertexAttribPointer(s.attributes.aVertexPosition,r.itemSize,t.FLOAT,!1,0,0),t.drawArrays(this.drawMode,0,r.numItems),t.enable(t.DEPTH_TEST)}_createBuffers(){const e=new Float32Array([-1e8,1e8,-1e8,-1e8,-1e8,-1e8,1e8,-1e8,-1e8,1e8,-1e8,-1e8,1e8,1e8,-1e8,-1e8,1e8,-1e8,-1e8,-1e8,1e8,-1e8,-1e8,-1e8,-1e8,1e8,-1e8,-1e8,1e8,-1e8,-1e8,1e8,1e8,-1e8,-1e8,1e8,1e8,-1e8,-1e8,1e8,-1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,-1e8,1e8,-1e8,-1e8,-1e8,-1e8,1e8,-1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,-1e8,1e8,-1e8,-1e8,1e8,-1e8,1e8,-1e8,1e8,1e8,-1e8,1e8,1e8,1e8,1e8,1e8,1e8,-1e8,1e8,1e8,-1e8,1e8,-1e8,-1e8,-1e8,-1e8,-1e8,-1e8,1e8,1e8,-1e8,-1e8,1e8,-1e8,-1e8,-1e8,-1e8,1e8,1e8,-1e8,1e8]);this.vertexPositionBuffer=this.renderer.handler.createArrayBuffer(e,3,e.length/3)}}var Za=Object.freeze({__proto__:null,Axes:class extends Ri{constructor(e=100){super("Axes"),this.size=e,this.axesBuffer=null,this.axesColorBuffer=null}init(){this.createAxesBuffer(this.size),this.drawMode=this.renderer.handler.gl.LINES,this.renderer.handler.addProgram(new Ni("axesShader",{uniforms:{projectionViewMatrix:"mat4"},attributes:{aVertexPosition:"vec3",aVertexColor:"vec4"},vertexShader:"attribute vec3 aVertexPosition;\n attribute vec4 aVertexColor;\n uniform mat4 projectionViewMatrix;\n varying vec4 vColor;\n void main(void) {\n gl_Position = projectionViewMatrix * vec4(aVertexPosition, 1.0);\n vColor = aVertexColor;\n }",fragmentShader:"precision highp float;\n varying vec4 vColor;\n void main(void) {\n gl_FragColor = vColor;\n }"}))}frame(){this.renderer.handler.programs.axesShader.activate().set({projectionViewMatrix:this.renderer.activeCamera.getProjectionViewMatrix(),aVertexPosition:this.axesBuffer,aVertexColor:this.axesColorBuffer}),this.renderer.handler.programs.axesShader.drawArrays(this.drawMode,this.axesBuffer.numItems)}createAxesBuffer(e){const t=[0,0,0,e-1,0,0,0,0,0,0,e-1,0,0,0,0,0,0,e-1];this.axesBuffer=this.renderer.handler.createArrayBuffer(new Float32Array(t),3,6),this.axesColorBuffer=this.renderer.handler.createArrayBuffer(new Float32Array([1,0,0,1,1,0,0,1,0,0,1,1,0,0,1,1,0,1,0,1,0,1,0,1]),4,6)}},Planet:qa,RenderNode:Ri,SkyBox:Xa});class Ka{constructor(e={}){this.__id=Ka.__counter__++,this.equalizeVertices=e.equalizeVertices||!1,this.equalizeNormals=!1,this.isEmpty=!0,this.name=e.name||"empty",this.minZoom=e.minZoom||2,this.maxZoom=e.maxZoom||19,this.maxNativeZoom=e.maxNativeZoom||this.maxZoom,this.gridSizeByZoom=e.gridSizeByZoom||[64,32,16,8,4,4,4,4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2],this._maxNodeZoom=this.gridSizeByZoom.length-1,this.plainGridSize=2,this.noDataValues=[],this._planet=null,this._geoid=e.geoid||new Ma({src:e.geoidSrc||null}),this._isReady=!1}setUrlRewriteCallback(e){}get isIdle(){return!0}isEqual(e){return e.__id===this.__id}static checkNoDataValue(e,t){return-1!==Be(e,t)}isBlur(e){return!1}set maxNodeZoom(e){e>this.gridSizeByZoom.length-1&&(e=this.gridSizeByZoom.length-1),this._maxNodeZoom=e}get maxNodeZoom(){return this._maxNodeZoom}set geoid(e){this._geoid=e}get geoid(){return this._geoid}getGeoid(){return this._geoid}handleSegmentTerrain(e){e.terrainIsLoading=!1,e.terrainReady=!0,e.terrainExists=!0}isReady(){return this._isReady}abortLoading(){}clearCache(){}getHeightAsync(e,t){return t(0),!0}loadTerrain(e,t=!1){}}Ka.__counter__=0;class Qa extends Ka{constructor(e="",t={}){super({geoidSrc:"https://openglobus.org/geoid/egm84-30.pgm",maxNativeZoom:t.maxNativeZoom||14,...t}),this._s=t.subdomains||["a","b","c"],this.events=Mt(Ja,this),this._requestCount=0,this._requestsPeerSubdomain=4,this.isEmpty=!1,this.equalizeNormals=!0,this.name=e||"openglobus",this.url=t.url||"https://{s}.srtm3.openglobus.org/{z}/{y}/{x}.ddm",this.gridSizeByZoom=t.gridSizeByZoom||[64,32,32,16,16,8,8,8,16,16,16,32,32,32,32,16,8,4,2,2,2,2,2,2],this._heightFactor=null!=t.heightFactor?t.heightFactor:1,this.noDataValues=t.noDataValues||[];for(let e=0;e<this.noDataValues.length;e++)this.noDataValues[e]*=this._heightFactor;this.plainGridSize=t.plainGridSize||32,this._extent=Me(t.extent,new te(new I(-180,-90),new I(180,90))),this._dataType="arrayBuffer",this._maxNodeZoom=this.gridSizeByZoom.length-1,this._elevationCache={},this._fetchCache={},this._loader=new ka,this._urlRewriteCallback=t.urlRewrite||null}get loader(){return this._loader}clearCache(){for(let e in this._elevationCache)this._elevationCache[e].heights=null,this._elevationCache[e].extent=null,delete this._elevationCache[e];this._elevationCache=null,this._elevationCache={};for(let e in this._fetchCache)this._fetchCache[e]=null,delete this._fetchCache[e];this._fetchCache=null,this._fetchCache={}}isBlur(e){return e.tileZoom>=6}setElevationCache(e,t){this._elevationCache[e]=t}getElevationCache(e){return this._elevationCache[e]}getHeightAsync(e,t,i,s){if(!e||e.lat>Q||e.lat<J)return t(0),!0;s=null==s||s;const[n,r,o,a]=this._planet.quadTreeStrategy.getTileXY(e,i||this.maxZoom);let l=$t.getTileIndex(n,r,o,a),h=this.getElevationCache(l),c=q(e);if(h)return h.heights?t(this._getGroundHeightMerc(c,h)):t(0),!0;{let i=this._fetchCache[l];i||(i=this._loader.fetch({src:this.buildURL(n,r,o,a),type:this._dataType}),this._fetchCache[l]=i),i.then((i=>{let h=K(n,r,o);if("ready"===i.status){let e={heights:this._createHeights(i.data,null,a,n,r,o,h),extent:h};this.setElevationCache(l,e),t(this._getGroundHeightMerc(c,e))}else if("error"===i.status){if(s&&o>this.maxNativeZoom)return s=!1,void this.getHeightAsync(e,t,this.maxNativeZoom,!1);this.setElevationCache(l,{heights:null,extent:h}),t(0)}else this._fetchCache[l]=null,delete this._fetchCache[l]}))}return!1}_getGroundHeightMerc(e,t){if(!t.extent||!t.heights)return 0;let i=t.extent.getWidth(),s=Math.sqrt(t.heights.length),n=i/(s-1),r=s-Math.ceil((e.lat-t.extent.southWest.lat)/n)-1,o=Math.floor((e.lon-t.extent.southWest.lon)/n),a=(r+1)*s+o,l=a+1,h=r*s+o,c=h+1,d=t.heights[a],_=t.heights[l],u=t.heights[h],g=t.heights[c],f=new oe(t.extent.southWest.lon+n*o,d,t.extent.northEast.lat-n*r-n),p=new oe(f.x+n,_,f.z),m=new oe(f.x,u,f.z+n),v=new oe(f.x+n,g,f.z+n),y=new oe(e.lon,1e5,e.lat),x=new ui(y,new oe(0,-1,0)),b=new oe,w=x.hitTriangleRes(f,p,m,b);return w===ui.INSIDE?b.y:(w=x.hitTriangleRes(p,v,m,b),w===ui.INSIDE?b.y:0)}abortLoading(){this._loader.abortAll()}setUrl(e){this.url=e}setName(e){this.name=e}isReadyToLoad(e){return 0===e._tileGroup&&this._extent.overlaps(e.getExtentLonLat())}loadTerrain(e,t=!1){if(this._planet.terrainLock.isFree())if(e.terrainReady=!1,e.terrainIsLoading=!0,this.isReadyToLoad(e)){let i=this.getElevationCache(e.tileIndex);i?this._applyElevationsData(e,i.heights):this._loader.load({sender:this,src:this._getHTTPRequestString(e),segment:e,type:this._dataType,filter:()=>e.plainReady&&0!==e.node.getState()||t},(t=>{if("ready"===t.status){let i=this._createHeights(t.data,e,e._tileGroup,e.tileX,e.tileY,e.tileZoom,e.getExtent(),e.tileZoom===this.maxZoom);this.setElevationCache(e.tileIndex,{heights:i,extent:e.getExtent()}),this._applyElevationsData(e,i)}else"abort"===t.status?e.terrainIsLoading=!1:"error"===t.status?this._applyElevationsData(e,null):e.terrainIsLoading=!1}))}else e.elevationsNotExists();else e.terrainIsLoading=!1}_getSubdomain(){return this._requestCount++,this._s[Math.floor(this._requestCount%(this._requestsPeerSubdomain*this._s.length)/this._requestsPeerSubdomain)]}buildURL(e,t,i,s){return we(this.url,{s:this._getSubdomain(),x:e.toString(),y:t.toString(),z:i.toString()})}_createUrl(e){return this.buildURL(e.tileX,e.tileY,e.tileZoom,e._tileGroup)}_getHTTPRequestString(e){return this._urlRewriteCallback&&this._urlRewriteCallback(e.tileX,e.tileY,e.tileZoom,e._tileGroup)||this._createUrl(e)}setUrlRewriteCallback(e){this._urlRewriteCallback=e}_createHeights(e,t,i,s,n,r,o,a){if(1!==this._heightFactor){let t=new Float32Array(e);for(let e=0,i=t.length;e<i;e++)t[e]=t[e]*this._heightFactor;return t}return new Float32Array(e)}_applyElevationsData(e,t){if(e){let i=this.events.load;i.handlers.length&&this.events.dispatch(i,{elevations:t,segment:e}),e.applyTerrain(t)}}}const Ja=["load","loadend"];class el extends $t{constructor(e,t={}){super(e,t),this.events=this.events.registerNames(tl),this.url=t.url||"",this._s=t.subdomains||["a","b","c"],this.minNativeZoom=t.minNativeZoom||0,this.maxNativeZoom=t.maxNativeZoom||19,this._urlRewriteCallback=t.urlRewrite||null,this._requestsPeerSubdomains=4,this._requestCount=0}get isIdle(){return super.isIdle&&0===this._planet._tileLoader.getRequestCounter(this)}get instanceName(){return"XYZ"}abortLoading(){this._planet&&this._planet._tileLoader.abort(this)}setVisibility(e){e!==this._visibility&&(super.setVisibility(e),e||this.abortLoading())}remove(){return this.abortLoading(),super.remove(),this}setUrl(e){this.url=e}_checkSegment(e){return e._projection.id===this._planet.quadTreeStrategy.projection.id}loadMaterial(e,t=!1){let i=e.segment;this._isBaseLayer?e.texture=i.getDefaultTexture():e.texture=i.planet.transparentTexture,(this._planet.layerLock.isFree()||e.segment.tileZoom<2)&&(e.isReady=!1,e.isLoading=!0,this._checkSegment(i)?(e.loadingAttempts++,this._planet._tileLoader.load({sender:this,src:this._getHTTPRequestString(e.segment),type:"imageBitmap",filter:()=>i.initialized&&1===i.node.getState()||t,options:{}},(t=>{if("ready"===t.status){if(e.isLoading){let i=this.events.load;i.handlers.length&&this.events.dispatch(i,e),e.applyImage(t.data),t.data=null}}else"abort"===t.status?e.isLoading=!1:"error"===t.status&&e.isLoading&&e.textureNotExists()}))):e.textureNotExists())}_createUrl(e){return we(this.url,{s:this._getSubdomain(),x:e.tileX.toString(),y:e.tileY.toString(),z:e.tileZoom.toString()})}_getSubdomain(){return this._requestCount++,this._s[Math.floor(this._requestCount%(this._requestsPeerSubdomains*this._s.length)/this._requestsPeerSubdomains)]}_getHTTPRequestString(e){return this._urlRewriteCallback?this._urlRewriteCallback(e,this.url):this._createUrl(e)}setUrlRewriteCallback(e){this._urlRewriteCallback=e}applyMaterial(e,t=!1){if(e.isReady)return e.texOffset;if(e.segment.tileZoom<this.minNativeZoom)e.textureNotExists();else{let i=e.segment,s=i.node,n=!1,r=this.__id,o=e;for(;s.parentNode;)if(s=s.parentNode,o=s.segment.materials[r],o&&o.textureExists){n=!0;break}if(i.passReady){let n=e.layer.maxNativeZoom;if(s.segment.tileZoom===n)e.textureNotExists();else if(e.segment.tileZoom<=n)!e.isLoading&&!e.isReady&&this.loadMaterial(e,t);else{let t=i.node;for(;t.segment.tileZoom>e.layer.maxNativeZoom;)t=t.parentNode;let s=t.segment.materials[e.layer.__id];s?!s.isLoading&&!s.isReady&&this.loadMaterial(s,!0):(s=t.segment.materials[e.layer.__id]=e.layer.createMaterial(t.segment),this.loadMaterial(s,!0))}}if(n){e.appliedNode=s,e.appliedNodeId=s.nodeId,e.texture=o.texture;let t=1/(2<<i.tileZoom-s.segment.tileZoom-1);e.texOffset[0]=i.tileX*t-s.segment.tileX,e.texOffset[1]=i.tileY*t-s.segment.tileY,e.texOffset[2]=t,e.texOffset[3]=t}else e.texture=i.planet.transparentTexture,e.texOffset[0]=0,e.texOffset[1]=0,e.texOffset[2]=1,e.texOffset[3]=1}return e.texOffset}clearMaterial(e){e.isReady&&e.textureExists&&(!e.texture.default&&e.segment.handler.gl.deleteTexture(e.texture),e.texture=null),e.isReady=!1,e.textureExists=!1,e.isLoading=!1}_correctFullExtent(){let e=this._extent,t=this._extentMerc,i=z+5e4,s=z+5e4;90===e.northEast.lat&&(t.northEast.lat=s),180===e.northEast.lon&&(t.northEast.lon=i),-90===e.southWest.lat&&(t.southWest.lat=-s),-180===e.southWest.lon&&(t.southWest.lon=-i)}}const tl=["load","loadend"];class il extends el{constructor(e,t){super(e,t),this._extra=new URLSearchParams(t.extra).toString(),t.extent||this.setExtent(new te(new I(-180,-90),new I(180,90))),this.layers=t.layers,this.imageWidth=t.imageWidth||256,this.imageHeight=t.imageHeight||256,this._getBbox=il.get_bbox_v1_1_1,this._version="",this.setVersion(t.version)}static createRequestUrl(e,t,i="image/png",s="1.1.1",n="GetMap",r,o,a=256,l=256,h){return`${e}/?LAYERS=${t}&FORMAT=${i}&SERVICE=WMS&VERSION=${s}&REQUEST=${n}&SRS=${r}&BBOX=${o}&WIDTH=${a}&HEIGHT=${l}`+(h?`&${h}`:"")}static get_bbox_v1_1_1(e){return`${e.getWest()},${e.getSouth()},${e.getEast()},${e.getNorth()}`}static get_bbox_v1_3_0(e){return`${e.getSouth()},${e.getWest()},${e.getNorth()},${e.getEast()}`}_checkSegment(e){return!0}get instanceName(){return"WMS"}_createUrl(e){return il.createRequestUrl(this.url,this.layers,"image/png",this._version,"GetMap",e._projection.code,this._getBbox(e.getExtent()),this.imageWidth,this.imageHeight,this._extra)}setVersion(e){this._version=e||"1.1.1","1.1.1"===this._version?this._getBbox=il.get_bbox_v1_1_1:"1.3.0"===e&&(this._getBbox=il.get_bbox_v1_3_0)}_correctFullExtent(){const e=this._extent,t=this._extentMerc,i=z+5e4,s=z+5e4;90===e.northEast.lat&&(t.northEast.lat=s),180===e.northEast.lon&&(t.northEast.lon=i),-90===e.southWest.lat&&(t.southWest.lat=-s),-180===e.southWest.lon&&(t.southWest.lon=-i)}}class sl extends Qa{constructor(e={}){super("BilTerrain",e),this.equalizeVertices=!0,this.equalizeNormals=!0,this.minZoom=e.minZoom||2,this.maxZoom=e.maxZoom||14,this.noDataValues=e.noDataValues||[-9999,32767],this.url=e.url||"",this._format="application/bil16",this._layers=e.layers||"",this._imageSize=e.imageSize||256,this.plainGridSize=null!=e.plainGridSize?e.plainGridSize:v(this._imageSize)?this._imageSize/2:y(this._imageSize)/2,this._dataType="arrayBuffer"}isBlur(e){return e.tileZoom>=18}_createUrl(e){return il.createRequestUrl(this.url,this._layers,this._format,"1.1.1","GetMap",e._projection.code,il.get_bbox_v1_1_1(e.getExtent()),this._imageSize,this._imageSize)}_createHeights(e,t,i,s,n,r,o,a){let l=new Int16Array(e);if(!v(this._imageSize)){let e=new Float32Array(l.length);return function(e,t){for(let i=0,s=t.length;i<s;i++)t[i]=e[i]}(l,e),e}let h=(this.plainGridSize+1)*(this.plainGridSize+1),c=new Array(4);for(let e=0;e<4;e++){c[e]=[];for(let t=0;t<4;t++)c[e][t]=new Float32Array(h)}let d=new Float32Array(h);!function(e,t,i,s){let n=Math.sqrt(i.length)-1,r=n+1,o=Math.sqrt(e.length),a=o/n,l=0,h=0;for(let c=0,d=0,_=e.length;c<_;c++){let _=e[c],u=sl.checkNoDataValue(t,_),g=!1,f=!1,p=Math.floor(c/o),m=c%o,v=Math.floor(m/n),y=Math.floor(p/n),x=s[y][v],b=p%n,w=m%n,C=(b+y)*r+w+v;if(x[C]=_,(p+y)%a==0&&(m+v)%a==0&&(i[d++]=_),(m+1)%n==0&&m!==o-1){l=e[c],g=sl.checkNoDataValue(t,l);let o=_;u||g||(o=.5*(_+l)),C=(b+y)*r+w+1,x[C]=o,(p+y)%a==0&&(i[d++]=o);let h=(b+y)*r+(w+1)%n;s[y][v+1][h]=o}if((p+1)%n==0&&p!==o-1){h=e[c+o],f=sl.checkNoDataValue(t,h);let l=_;u||f||(l=.5*(_+h)),C=(b+1)*r+w+v,x[C]=l,(m+v)%a==0&&(i[d++]=l);let g=(b+1)%n*r+w+v;s[y+1][v][g]=l}if((m+1)%n==0&&m!==o-1&&(p+1)%n==0&&p!==o-1){let a=e[c+o+1],p=sl.checkNoDataValue(t,a),m=_;u||g||f||p||(m=.25*(_+l+h+a)),C=(b+1)*r+(w+1),x[C]=m,i[d++]=m;let T=(b+1)*r;s[y][v+1][T]=m;let E=n;s[y+1][v][E]=m;let L=0;s[y+1][v+1][L]=m}}}(l,this.noDataValues,d,c);let _=$t.getTileIndex(s,n,r,i);this.setElevationCache(_,{heights:d,extent:o});let u=this._imageSize/this.plainGridSize;for(let e=0;e<u;e++)for(let t=0;t<u;t++){let o=2*s+t,a=2*n+e,l=r+1,h=$t.getTileIndex(o,a,l,i);this.setElevationCache(h,{heights:c[e][t],extent:K(o,a,l)})}return d}}class nl extends Qa{constructor(e,t={}){super(e||"RgbTerrain",{equalizeVertices:null==t.equalizeVertices||t.equalizeVertices,maxZoom:t.maxZoom||17,noDataValues:t.noDataValues||[null!=t.minHeight?t.minHeight:-1e4],plainGridSize:t.plainGridSize||128,url:null!=t.url?t.url:`//api.mapbox.com/v4/mapbox.terrain-rgb/{z}/{x}/{y}.pngraw?access_token=${t.key||"<key>"}`,gridSizeByZoom:t.gridSizeByZoom||[64,32,16,8,8,8,16,16,16,32,32,32,32,32,32,64,64,64,32,32,16,8],...t}),this.equalizeNormals=t.equalizeNormals||!1,this._dataType="imageBitmap",this._imageSize=t.imageSize||256,this._ctx=this._createTemporalCanvas(this._imageSize),this._imageDataCache={},this._minHeight=t.minHeight||-1e4,this._resolution=t.resolution||.1}static checkNoDataValue(e,t){return t>5e4||-1!==Be(e,t)}rgb2Height(e,t,i){return 255===e?this._minHeight:this._minHeight+this._resolution*(256*e*256+256*t+i)}isBlur(e){return e.tileZoom>=16}_createTemporalCanvas(e){let t=document.createElement("canvas");return t.width=e,t.height=e,t.getContext("2d",{willReadFrequently:!0})}_createHeights(e,t,i,s,n,r,o,a){this._ctx.clearRect(0,0,this._imageSize,this._imageSize),this._ctx.drawImage(e,0,0);let l=this._ctx.getImageData(0,0,this._imageSize,this._imageSize).data;const h=e.width;let c=0,d=0,_=0,u=null,g=!1;if(t&&t.tileZoom>this.maxNativeZoom){let e=t.node;for(;e&&!e.segment.terrainExists;)e=e.parentNode;e&&(c=e.segment.tileX,d=e.segment.tileY,_=e.segment.tileZoom,u=e.segment.elevationData,g=_<=8)}if(!v(this._imageSize)&&h===this._imageSize){let e=new Float32Array(h*h);return this.extractElevationTilesRgbNonPowerOfTwo(l,e,this._heightFactor),e}if(this._imageSize===this.plainGridSize){let e=(this.plainGridSize+1)*(this.plainGridSize+1),i=new Float32Array(e),[s,n,r]=t?rl(t.tileX,t.tileY,t.tileZoom,c,d,_):[0,0,0];return this.extractElevationSimple(l,this.noDataValues,u,s,n,r,g,i,this._heightFactor,this._imageSize),i}let f=(this.plainGridSize+1)*(this.plainGridSize+1),p=h/this.plainGridSize,m=new Float32Array(f),y=new Array(p);for(let e=0;e<p;e++){y[e]=[];for(let t=0;t<p;t++)y[e][t]=new Float32Array(f)}if(a)this.extractElevationTilesRgbNoChildren(l,this._heightFactor,this.noDataValues,u,c,d,_,t?t.tileX:0,t?t.tileY:0,t?t.tileZoom:0,g,m);else{this.extractElevationTilesRgb(l,this._heightFactor,this.noDataValues,u,c,d,_,t?t.tileX:0,t?t.tileY:0,t?t.tileZoom:0,g,m,y);for(let e=0;e<p;e++)for(let t=0;t<p;t++){let[o,a,l]=[2*s+t,2*n+e,r+1],h=$t.getTileIndex(o,a,l,i);this.setElevationCache(h,{heights:y[e][t],extent:K(o,a,l)})}}let x=$t.getTileIndex(s,n,r,i);return this.setElevationCache(x,{heights:m,extent:o}),m}getHeightAsync(e,t,i){if(0===(i=null!=i?i:this.maxZoom))return t(0),!0;const s=this._planet.quadTreeStrategy,[n,r,o,a]=s.getTileXY(e,i),[l,h]=s.getLonLatTileOffset(e,n,r,o,this._imageSize),c=4*(l*this._imageSize+h),d=$t.getTileIndex(n,r,o,a);if(this._imageDataCache[d]){let s=this._imageDataCache[d],n=this._heightFactor*this.rgb2Height(s[c],s[c+1],s[c+2]);return nl.checkNoDataValue(this.noDataValues,n)?this.getHeightAsync(e,t,i-1):(t(this._heightFactor*this.rgb2Height(s[c],s[c+1],s[c+2])),!0)}let _=this._fetchCache[d];return _||(_=this._loader.fetch({src:this._urlRewriteCallback&&this._urlRewriteCallback(n,r,o,a)||this.buildURL(n,r,o,a),type:this._dataType}),this._fetchCache[d]=_),_.then((s=>{if("ready"===s.status){this._ctx.clearRect(0,0,this._imageSize,this._imageSize),this._ctx.drawImage(s.data,0,0);let n=this._ctx.getImageData(0,0,256,256).data;this._imageDataCache[d]=n;let r=this._heightFactor*this.rgb2Height(n[c],n[c+1],n[c+2]);if(nl.checkNoDataValue(this.noDataValues,r))return this.getHeightAsync(e,t,i-1);t(this._heightFactor*this.rgb2Height(n[c],n[c+1],n[c+2]))}else{if("error"===s.status)return this.getHeightAsync(e,t,i-1);this._fetchCache[d]=null,delete this._fetchCache[d]}})),!1}extractElevationSimple(e,t,i=null,s,n,r,o,a,l=1,h){for(let c=0,d=h*h;c<d;c++){let d=c%h,_=Math.floor(c/h),u=4*c,g=l*this.rgb2Height(e[u],e[u+1],e[u+2]);(nl.checkNoDataValue(t,g)||0===g)&&i&&(g=ol(r,s,n,i,_,d,o)),a[_*(h+1)+d]=g}for(let c=0,d=h;c<d;c++){let d=h-1,_=4*(c*h+d),u=l*this.rgb2Height(e[_],e[_+1],e[_+2]);(nl.checkNoDataValue(t,u)||0===u)&&i&&(u=ol(r,s,n,i,c,d,o)),a[c*(h+1)+h]=u}for(let c=0,d=h;c<d;c++){let d=h-1,_=4*(d*h+c),u=l*this.rgb2Height(e[_],e[_+1],e[_+2]);(nl.checkNoDataValue(t,u)||0===u)&&i&&(u=ol(r,s,n,i,d,c,o)),a[h*(h+1)+c]=u}let c=l*this.rgb2Height(e[e.length-4],e[e.length-3],e[e.length-2]);(nl.checkNoDataValue(t,c)||0===c)&&i&&(c=ol(r,s,n,i,h-1,h-1,o)),a[a.length-1]=c}extractElevationTilesRgbNonPowerOfTwo(e,t,i=1){for(let s=0,n=t.length;s<n;s++){let n=4*s;t[s]=i*this.rgb2Height(e[n],e[n+1],e[n+2])}}extractElevationTilesRgb(e,t,i,s=null,n,r,o,a,l,h,c,d,_){let u=Math.sqrt(d.length)-1,g=u+1,f=Math.sqrt(e.length/4),p=f/u,m=0,v=0,y=0,[x,b,w]=rl(a,l,h,n,r,o);for(let n=0,r=0,o=e.length/4;n<o;n++){let o=4*n,a=t*this.rgb2Height(e[o],e[o+1],e[o+2]),l=nl.checkNoDataValue(i,a),h=!1,C=!1,T=Math.floor(n/f),E=n%f;(l||0===a)&&s&&(a=ol(w,x,b,s,Math.floor(T/p),Math.floor(E/p),c));let L=Math.floor(E/u),A=Math.floor(T/u),P=_[A][L],S=T%u,M=E%u,R=(S+A)*g+M+L;if(P[R]=a,(T+A)%p==0&&(E+L)%p==0&&(d[r++]=a),(E+1)%u==0&&E!==f-1){m=t*this.rgb2Height(e[o+4],e[o+5],e[o+6]),h=nl.checkNoDataValue(i,m),(h||0===m)&&s&&(m=ol(w,x,b,s,Math.floor(T/p),Math.floor((E+1)/p),c));let n=a;l||h||(n=.5*(a+m)),R=(S+A)*g+M+1,P[R]=n,(T+A)%p==0&&(d[r++]=n);let f=(S+A)*g+(M+1)%u;_[A][L+1][f]=n}if((T+1)%u==0&&T!==f-1){y=4*f,v=t*this.rgb2Height(e[o+y],e[o+y+1],e[o+y+2]),C=nl.checkNoDataValue(i,v),(C||0===v)&&s&&(v=ol(w,x,b,s,Math.floor((T+1)/p),Math.floor(E/p),c));let n=.5*(a+v);l||C||(n=.5*(a+v)),R=(S+1)*g+M+L,P[R]=n,(E+L)%p==0&&(d[r++]=n);let h=(S+1)%u*g+M+L;_[A+1][L][h]=n}if((E+1)%u==0&&E!==f-1&&(T+1)%u==0&&T!==f-1){let n=t*this.rgb2Height(e[o+y+4],e[o+y+5],e[o+y+6]),f=nl.checkNoDataValue(i,n);(f||0===n)&&s&&(n=ol(w,x,b,s,Math.floor((T+1)/p),Math.floor((E+1)/p),c));let B=a;l||h||C||f||(B=.25*(a+m+v+n)),R=(S+1)*g+(M+1),P[R]=B,d[r++]=B;let k=(S+1)*g;_[A][L+1][k]=B;let I=u;_[A+1][L][I]=B;let z=0;_[A+1][L+1][z]=B}}}extractElevationTilesRgbNoChildren(e,t,i,s=null,n,r,o,a,l,h,c,d){let _=Math.sqrt(d.length)-1,u=_+1,g=Math.sqrt(e.length/4),f=g/_,p=0,m=0,v=0,[y,x,b]=rl(a,l,h,n,r,o);for(let n=0,r=0,o=e.length/4;n<o;n++){let o=4*n,a=t*this.rgb2Height(e[o],e[o+1],e[o+2]),l=nl.checkNoDataValue(i,a),h=!1,w=!1,C=Math.floor(n/g),T=n%g;(l||0===a)&&s&&(a=ol(b,y,x,s,Math.floor(r/u),r%u,c));let E=Math.floor(T/_),L=Math.floor(C/_);if((C+L)%f==0&&(T+E)%f==0&&(d[r++]=a),(T+1)%_==0&&T!==g-1){p=t*this.rgb2Height(e[o+4],e[o+5],e[o+6]),h=nl.checkNoDataValue(i,p),(h||0===p)&&s&&(p=ol(b,y,x,s,Math.floor(r/u),r%u,c));let n=a;l||h||(n=.5*(a+p)),(C+L)%f==0&&(d[r++]=n)}if((C+1)%_==0&&C!==g-1){v=4*g,m=t*this.rgb2Height(e[o+v],e[o+v+1],e[o+v+2]),w=nl.checkNoDataValue(i,m),(w||0===m)&&s&&(m=ol(b,y,x,s,Math.floor(r/u),r%u,c));let n=.5*(a+m);l||w||(n=.5*(a+m)),(T+E)%f==0&&(d[r++]=n)}if((T+1)%_==0&&T!==g-1&&(C+1)%_==0&&C!==g-1){let n=t*this.rgb2Height(e[o+v+4],e[o+v+5],e[o+v+6]),_=nl.checkNoDataValue(i,n);(_||0===n)&&s&&(n=ol(b,y,x,s,Math.floor(r/u),r%u,c));let g=a;l||h||w||_||(g=.25*(a+p+m+n)),d[r++]=g}}}}function rl(e,t,i,s,n,r){let o=2<<i-r-1;return[e-o*s,t-o*n,1/o]}function ol(e,t,i,s,n,r,o){let a=Math.sqrt(s.length),l=s[Math.floor(i*e*a+n*e)*a+Math.floor(t*e*a+r*e)];return o&&l>0?0:l}const al={[ea]:"north",[ta]:"south"},ll=(e,t,i,s)=>{let n=al[s];if(n)return`https://terrain.openglobus.org/poles/${n}/${i}/${e}/${t}.png`};class hl extends nl{constructor(e,t){super(e||"GlobusEarthRgb",{maxNativeZoom:6,maxZoom:17,url:"https://{s}.terrain.openglobus.org/all/{z}/{x}/{y}.png",urlRewrite:ll,...t})}isReadyToLoad(e){return this._extent.overlaps(e.getExtentLonLat())}}var cl=Object.freeze({__proto__:null,BilTerrain:sl,EmptyTerrain:Ka,GlobusRgbTerrain:hl,GlobusTerrain:Qa,RgbTerrain:nl});class dl extends wn{constructor(e,t={}){super(e,t),this._image=t.image||null,this._src=t.src||null,this._onLoad_=null}get instanceName(){return"GeoImage"}abortLoading(){this._image instanceof HTMLImageElement&&(this._image.src="")}setSrc(e){this._planet&&this._planet._geoImageCreator.remove(this),this._src=e,this._sourceReady=!1,this._sourceCreated=!1,this._image=new Image,this._image.crossOrigin="Anonymous",this._onLoad_=this._onLoad.bind(this),this._image.addEventListener("load",this._onLoad_),this._image.src=e}setImage(e){this._planet&&this._planet._geoImageCreator.remove(this),this._sourceCreated=!1,this._sourceReady=!1,this._image=e,this._image.crossOrigin="Anonymous",this._src=e.src,Ze(this._image)?this._applyImage(this._image):(this._onLoad_=this._onLoad.bind(this),this._image.addEventListener("load",this._onLoad_))}_createSourceTexture(){!this._sourceCreated&&this._image&&(this._sourceTexture=this._planet.renderer.handler.createTexture_l(this._image),this._sourceCreated=!0)}_onLoad(e){this._applyImage(this._image),this._image instanceof HTMLImageElement&&this._image.removeEventListener("load",this._onLoad_),this._onLoad_=null}_applyImage(e){e&&(this._frameWidth=y(2*e.width,4096),this._frameHeight=y(3*e.height,4096),this._sourceReady=!0,this._planet&&this._planet._geoImageCreator.add(this))}loadMaterial(e){e.isLoading=!0,this._creationProceeding=!0,!this._sourceReady&&this._src?this._image?this._image instanceof HTMLImageElement&&(Ze(this._image)?this._applyImage(this._image):(this._onLoad_=this._onLoad.bind(this),this._image.addEventListener("load",this._onLoad_))):(this._image=new Image,this._image.crossOrigin="Anonymous",this._onLoad_=this._onLoad.bind(this),this._image.addEventListener("load",this._onLoad_),this._image.src=this._src):this._planet&&this._planet._geoImageCreator.add(this)}abortMaterialLoading(e){this._image&&this._image instanceof HTMLImageElement&&(this._image.src=""),this._creationProceeding=!1,e.isLoading=!1,e.isReady=!1}}class _l extends wn{constructor(e,t={}){super(e,t),this._sourceTexture=t.texture||null,t.texture&&(this._sourceReady=!0,this._sourceCreated=!0),this._frameWidth=null!=t.frameWidth?y(t.frameWidth):256,this._frameHeight=null!=t.frameHeight?y(t.frameHeight):256,this._animate=!0}get instanceName(){return"GeoTexture2d"}loadMaterial(e){this._planet._geoImageCreator.add(this)}bindTexture(e){this._sourceReady=!0,this._sourceCreated=!0,this._sourceTexture=e}setSize(e,t){this._frameWidth=e,this._frameHeight=t,this._frameCreated=!1}abortMaterialLoading(e){this._creationProceeding=!1,e.isLoading=!1,e.isReady=!1}}class ul extends wn{constructor(e,t={}){super(e,t),this._animate=!0,this._video=t.videoElement||null,this._src=t.src||null}get instanceName(){return"GeoVideo"}setSrc(e){this._planet&&this._planet._geoImageCreator.remove(this),this._src=e,this._sourceReady=!1}setVideoElement(e){this._planet&&this._planet._geoImageCreator.remove(this),this._video=e,this._src=e.src,this._sourceReady=!1}setVisibility(e){e!=this._visibility&&(super.setVisibility(e),this._planet&&(e?(this._sourceReady&&this._planet._geoImageCreator.add(this),this._video&&this._video.play()):(this._sourceReady&&this._planet._geoImageCreator.remove(this),this._video&&this._video.pause())))}_createSourceTexture(){let e=this._planet.renderer.handler.gl;this._sourceCreated?(e.bindTexture(e.TEXTURE_2D,this._sourceTexture),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this._video)):(this._sourceTexture=this._planet.renderer.handler.createTexture_n_webgl1(this._video),this._sourceCreated=!0)}_onCanPlay(e){this._frameWidth=e.videoWidth,this._frameHeight=e.videoHeight,e.width=e.videoWidth,e.height=e.videoHeight,e.play(),this._sourceReady=!0,this._planet._geoImageCreator.add(this)}_onError(e){let t="unknown error";switch(e.error.code){case 1:t="video loading aborted";break;case 2:t="network loading error";break;case 3:t="video decoding failed / corrupted data or unsupported codec";break;case 4:t="video not supported"}console.warn(`Error: ${t} error-code=${e.error.code})`)}loadMaterial(e){if(e.isLoading=!0,this._creationProceeding=!0,!this._sourceReady&&this._src){if(this._video){if(this._video.readyState===this._video.HAVE_ENOUGH_DATA)this._onCanPlay(this._video);else if(this._video.src){let e=this;this._video.addEventListener("canplay",(function(t){e._onCanPlay(this)}))}}else{this._video=document.createElement("video"),this._video.crossOrigin="Anonymous";let e=this;this._video.addEventListener("canplay",(function(){e._onCanPlay(this)})),this._video.addEventListener("error",(function(){e._onError(this)}))}this._video.autoplay=!0,this._video.loop=!0,this._video.src=this._src,this._video.muted=!0,this._video.setAttribute("playsinline","true"),this._video.setAttribute("webkit-playsinline","true")}else this._planet._geoImageCreator.add(this)}abortMaterialLoading(e){this._video&&(this._video.src=""),this._creationProceeding=!1,e.isLoading=!1,e.isReady=!1}}class gl extends qs{constructor(e,t={}){super(e,t),this._billboard=t.billboard||{src:"https://openglobus.org/examples/billboards/carrot.png"},this._color=t.color||"#6689db"}get instanceName(){return"KML"}_extractCoordonatesFromKml(e){return Array.from(e.getElementsByTagName("coordinates")).map((e=>e.textContent.trim())).map((e=>e.replace(/\n/g," ").replace(/\t/g," ").replace(/ +/g," ").split(" ").map((e=>e.split(",").map(parseFloat)))))}_AGBRtoRGBA(e){if(!e||8!=e.length)return;const t=parseInt(e.slice(0,2),16)/255,i=parseInt(e.slice(2,4),16),s=parseInt(e.slice(4,6),16);return`rgba(${parseInt(e.slice(6,8),16)},${s},${i},${t})`}_parseKMLcoordinates(e){return e.innerHTML.trim().replace(/\n/g," ").replace(/\t/g," ").replace(/ +/g," ").split(" ").map((e=>e.split(",").map(parseFloat)))}_kmlPlacemarkToEntity(e,t){if(!e)return;const i=Array.from(e.getElementsByTagName("name")),s=i&&i.length>0?i[0].innerHTML.trim():"",{iconHeading:n,iconURL:r,iconColor:o,lineWidth:a,lineColor:l}=this._extractStyle(e),h=[];for(const i of e.getElementsByTagName("coordinates")){const e=this._parseKMLcoordinates(i)||[[0,0,0]];for(const i of e){const[e,s,n]=i;h.push(new I(e,s,n)),e<t.southWest.lon&&(t.southWest.lon=e),s<t.southWest.lat&&(t.southWest.lat=s),e>t.northEast.lon&&(t.northEast.lon=e),s>t.northEast.lat&&(t.northEast.lat=s)}}if(1===h.length){const e=.01745329*n;return new Si({name:s,lonlat:h[0],billboard:{src:r,size:[24,24],color:o,rotation:e},properties:{color:o,heading:n}})}return new Si({polyline:{pathLonLat:[h],thickness:a,color:l,isClosed:!1}})}_extractStyle(e){let t,i,s,n,r;const o=e.getElementsByTagName("Style")[0];if(o){let e=o.getElementsByTagName("IconStyle")[0];if(e){let n=e.getElementsByTagName("color")[0];n&&(t=this._AGBRtoRGBA(n.innerHTML.trim()));let r=e.getElementsByTagName("heading")[0];if(r){const e=parseFloat(r.innerHTML.trim());e>=0&&e<=360&&(i=e%360)}let o=e.getElementsByTagName("Icon")[0];if(o){let e=o.getElementsByTagName("href")[0];e&&(s=e.innerHTML.trim())}}let a=o.getElementsByTagName("LineStyle")[0];if(a){let e=a.getElementsByTagName("color")[0];e&&(n=this._AGBRtoRGBA(e.innerHTML.trim()));let t=a.getElementsByTagName("width")[0];void 0!==t&&(r=parseFloat(t.innerHTML.trim()))}}return t||(t="#FFFFFF"),i||(i=0),s||(s="https://openglobus.org/examples/billboards/carrot.png"),n||(n="#FFFFFF"),r||(r=1),{iconHeading:i,iconURL:s,iconColor:t,lineWidth:r,lineColor:n}}_parseKML(e,t,i){if(i||(i=[]),"kml"!==e.documentElement.nodeName)return i;for(const s of e.getElementsByTagName("Placemark")){const e=this._kmlPlacemarkToEntity(s,t);e&&i.push(e)}return i}_convertKMLintoEntities(e){const t=new te(new I(180,90),new I(-180,-90));return{entities:this._parseKML(e,t),extent:t}}_convertCoordonatesIntoEntities(e,t,i){const s=new te(new I(180,90),new I(-180,-90)),n=e=>{const t=e[0],i=e[1];t<s.southWest.lon&&(s.southWest.lon=t),i<s.southWest.lat&&(s.southWest.lat=i),t>s.northEast.lon&&(s.northEast.lon=t),i>s.northEast.lat&&(s.northEast.lat=i)},r=[];e.forEach((e=>e.forEach((e=>r.push(e)))));return{entities:r.map((e=>{if(1===e.length){const t=e[0],s=new Si({lonlat:t,billboard:i});return n(t),s}if(e.length>1){const i=e.map((e=>(n(e),new I(e[0],e[1],e[2]))));return new Si({polyline:{pathLonLat:[i],thickness:3,color:t,isClosed:!1}})}})),extent:s}}_getXmlContent(e){return new Promise((t=>{const i=new FileReader;i.onload=async e=>t((new DOMParser).parseFromString(e.target.result,"text/xml")),i.readAsText(e)}))}_expandExtents(e,t){return e?(t.southWest.lon<e.southWest.lon&&(e.southWest.lon=t.southWest.lon),t.southWest.lat<e.southWest.lat&&(e.southWest.lat=t.southWest.lat),t.northEast.lon>e.northEast.lon&&(e.northEast.lon=t.northEast.lon),t.northEast.lat>e.northEast.lat&&(e.northEast.lat=t.northEast.lat),e):t}async addKmlFromFiles(e,t,i){if(!Array.isArray(e))return null;const s=(await Promise.all(e.map(this._getXmlContent))).map(this._extractCoordonatesFromKml),{entities:n,extent:r}=this._convertCoordonatesIntoEntities(s,t||this._color,i||this._billboard);return this._extent=this._expandExtents(this._extent,r),n.forEach(this.add.bind(this)),{entities:n,extent:r}}setColor(e){this._color=e,this._billboard.color=e}_getKmlFromUrl(e){return new Promise(((t,i)=>{const s=new XMLHttpRequest;s.open("GET",e,!0),s.responseType="document",s.overrideMimeType("text/xml"),s.onload=()=>{s.readyState===s.DONE&&200===s.status?t(s.responseXML):i(new Error("no valid kml file"))},s.send()}))}async addKmlFromUrl(e,t,i){const s=await this._getKmlFromUrl(e),{entities:n,extent:r}=this._convertKMLintoEntities(s);return this._extent=this._expandExtents(this._extent,r),n.forEach(this.add.bind(this)),{entities:n,extent:r}}}class fl extends el{constructor(e,t={}){super(e||"OpenStreetMap",{iconSrc:"https://tile.openstreetmap.org/8/138/95.png",url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",attribution:"Data @ OpenStreetMap contributors, ODbL",isBaseLayer:!0,maxNativeZoom:19,defaultTextures:[{color:"#AAD3DF"},{color:"#F2EFE9"}],isSRGB:!1,shininess:18,specular:[63e-5,55e-5,32e-5],ambient:[.2,.2,.3],diffuse:[.9,.9,.7],...t})}}function pl(e,t,i){var s="";for(let o=i;o>0;o--){var n=0,r=1<<o-1;e&r&&n++,t&r&&(n+=2),s+=n.toString()}return s}class ml extends el{constructor(e,t={}){super(e||"Bing",{iconSrc:"https://ecn.t0.tiles.virtualearth.net/tiles/a120.jpeg?n=z&g=7146",subdomains:["t0","t1","t2","t3"],url:"https://ecn.{s}.tiles.virtualearth.net/tiles/a{quad}.jpeg?n=z&g=7146",isBaseLayer:!0,textureFilter:"LINEAR",maxNativeZoom:17,defaultTextures:[{color:"#001522"},{color:"#E4E6F3"}],attribution:'<div style="transform: scale(0.8); margin-top:-2px;"><a href="https://www.bing.com" target="_blank"><img style="position: relative; top: 2px;" title="Bing Imagery" src="https://sandcastle.cesium.com/CesiumUnminified/Assets/Images/bing_maps_credit.png"></a> © 2021 Microsoft Corporation</div>',urlRewrite:(e,t)=>we(t,{s:this._getSubdomain(),quad:pl(e.tileX,e.tileY,e.tileZoom)}),specular:[63e-5,55e-5,32e-5],ambient:[.35,.35,.35],diffuse:[1.5,1.5,1.5],shininess:20,nightTextureCoefficient:2.7,...t})}}var vl=Object.freeze({__proto__:null,Bing:ml,CanvasTiles:Kt,GeoImage:dl,GeoTexture2d:_l,GeoVideo:ul,KML:gl,LAYER_EVENTS:Xt,Layer:$t,Material:qt,OpenStreetMap:fl,Vector:qs,WMS:il,XYZ:el});const yl=["tick","end","start","stop"];class xl{constructor(e={}){this.__handler=null,this.active=!0,this.__id=xl.__counter__++,this.events=Mt(yl,this),this.name=e.name||"",this.startDate=e.startDate||0,this.endDate=e.endDate||0;let t=e.currentDate||mt(new Date);e.startDate&&t<e.startDate&&(t=e.startDate),e.endDate&&t>e.endDate&&(t=e.endDate),this.currentDate=t,this._multiplier=void 0!==e.multiplier?e.multiplier:1,this._running=1,this.deltaTicks=0,this.active=!0,this._intervalDelay=0,this._intervalStart=0,this._intervalCallback=null}clearInterval(){this._intervalDelay=0,this._intervalStart=0,this._intervalCallback=null}setInterval(e,t){this._intervalStart=this.currentDate,this._intervalDelay=e*ut,this._intervalCallback=t}setDate(e){let t=mt(e);this.startDate&&t<this.startDate&&(t=this.startDate),this.endDate&&t>this.endDate&&(t=this.endDate),this.currentDate=t}getDate(){return xt(this.currentDate)}reset(){this.startDate&&(this.currentDate=this.startDate)}tick(e){let t=this._multiplier*this._running;if(this.deltaTicks=e*t,this.active){let e=bt(this.currentDate,this.deltaTicks);t>0?this.endDate&&e>this.endDate?(this.currentDate=this.startDate,this.events.dispatch(this.events.end,this)):this.currentDate=e:this.startDate&&e<this.startDate?(this.currentDate=this.endDate,this.events.dispatch(this.events.end,this)):this.currentDate=e,this._intervalCallback&&this.currentDate-this._intervalStart>=this._intervalDelay&&(this._intervalStart=this.currentDate,this._intervalCallback(this)),this.events.dispatch(this.events.tick,this)}}isEqual(e){return this.__id===e.__id}start(){0===this._running&&(this._running=1,this.events.dispatch(this.events.start,this))}get multiplier(){return this._multiplier}set multiplier(e){this._multiplier=e}stop(){1===this._running&&(this._running=0,this.events.dispatch(this.events.stop,this))}}xl.__counter__=0;class bl{constructor(e,t){this._program=t,this._handler=e,this._activated=!1}initialize(){this._handler.gl&&this._program.createProgram(this._handler.gl)}getProgram(){return this._program}activate(){if(!this._activated){this._handler.activeProgram.deactivate(),this._handler.activeProgram=this;let e=this._program;this._activated=!0,e.enableAttribArrays(),e.use()}return this}remove(){let e=this._handler.programs;e[this._program.name]&&(this._activated&&this.deactivate(),this._program.delete(),delete e[this._program.name])}deactivate(){this._program.disableAttribArrays(),this._activated=!1}isActive(){return this._activated}set(e){return this.activate(),this._program.set(e),this}drawIndexBuffer(e,t){return this._program.drawIndexBuffer(e,t),this}drawArrays(e,t){return this._program.drawArrays(e,t),this}}class wl{constructor(){this.next=null,this.prev=null,this.data=null}}class Cl{constructor(e=256){this._current=new wl,this._head=this._current;for(let t=0;t<e;t++){let e=new wl;e.prev=this._current,this._current.next=e,this._current=e}this._current=this._head}current(){return this._current}push(e){this._current=this._current.next,this._current.data=e}pop(){let e=this._current.data;return this._current=this._current.prev,e}popPrev(){return this._current=this._current.prev,this._current.data}}const Tl=["","WEBKIT_","MOZ_"],El=["webgl2","webgl"];class Ll{constructor(e,t={}){this.framebufferStack=new Cl,this._requestAnimationFrameId=0,this.drawFrame=()=>{let e=window.performance.now(),t=this.deltaTime;this.deltaTime=.5*(e-this._lastAnimationFrameTime+this.prevDeltaTime),this.deltaTime>3?this.deltaTime=3:this.deltaTime<1&&(this.deltaTime=1),this.prevDeltaTime=t,this._lastAnimationFrameTime=e,this.defaultClock.tick(this.deltaTime);for(let e=0;e<this._clocks.length;e++)this._clocks[e].tick(this.deltaTime);let i=this.canvas;Math.floor(i.clientWidth*this._params.pixelRatio)===i.width&&Math.floor(i.clientHeight*this._params.pixelRatio)===i.height||(0===i.clientWidth||0===i.clientHeight?this.stop():document.hidden||(this.start(),this.setSize(i.clientWidth,i.clientHeight))),this._frameCallback()},this.events=Mt(["visibilitychange","resize"]),this._throttledDrawFrame=this.drawFrame,this.defaultClock=new xl,this._clocks=[],this.prevDeltaTime=0,this.deltaTime=0,this.canvas=null,this.gl=null,this.programs={},this.activeProgram=null,this._canvasSize=[0,0],this._params={anisotropy:t.anisotropy||4,width:t.width||256,height:t.height||256,pixelRatio:Qe("og_dpi")||t.pixelRatio||1,extensions:t.extensions||[],context:t.context||{}},this._oneByHeight=1/(this._params.height*this._params.pixelRatio),this.extensions={},this._canvasTarget=e,this._lastAnimationFrameTime=0,this._initialized=!1,this._frameCallback=function(){},this.transparentTexture=null,this.defaultTexture=null,this.framebufferStack=new Cl,this.createTexture_n=this.createTexture_n_webgl2.bind(this),this.createTexture_l=this.createTexture_l_webgl2.bind(this),this.createTexture_mm=this.createTexture_mm_webgl2.bind(this),this.createTexture_a=this.createTexture_a_webgl2.bind(this),this.createTexture={NEAREST:this.createTexture_n,LINEAR:this.createTexture_l,MIPMAP:this.createTexture_mm,ANISOTROPIC:this.createTexture_a},this.createTextureDefault=this.createTexture_n,this.ONCANVASRESIZE=null,this._createCanvas(),(t.autoActivate||_e(t.autoActivate))&&this.initialize()}set frameDelay(e){this._throttledDrawFrame=0===e?this.drawFrame:Ne(this.drawFrame,e)}isInitialized(){return this._initialized}_createCanvas(){this._canvasTarget?this._canvasTarget instanceof HTMLElement?this.canvas=this._canvasTarget:this.canvas=document.getElementById(this._canvasTarget)||document.querySelector(this._canvasTarget):(this.canvas=document.createElement("canvas"),this.canvas.width=this._params.width,this.canvas.height=this._params.height)}static getExtension(e,t){if(!e)return;let i,s;for(i in Tl)if(s=e.getExtension(Tl[i]+t),s)return s}static getContext(e,t){let i=null;try{let s=new URLSearchParams(location.search).get("og_ver");if(s)i=e.getContext(s,t),i&&(i.type=s);else for(let s=0;s<El.length;s++)if(i=e.getContext(El[s],t),i){i.type=El[s];break}}catch(e){Bi.logErr("exception during the GL context initialization")}return i||Bi.logErr("could not initialise WebGL"),i}setFrameCallback(e){e&&(this._frameCallback=e)}createEmptyTexture2DExt(e=1,t=1,i="NEAREST",s="RGBA",n="RGBA",r="UNSIGNED_BYTE",o="CLAMP_TO_EDGE",a=0){let l=this.gl,h=l.createTexture();return l.bindTexture(l.TEXTURE_2D,h),l.texImage2D(l.TEXTURE_2D,a,l[s.toUpperCase()],e,t,0,l[n.toUpperCase()],l[r.toUpperCase()],null),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l[i.toUpperCase()]),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l[i.toUpperCase()]),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l[o.toUpperCase()]),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l[o.toUpperCase()]),l.bindTexture(l.TEXTURE_2D,null),h}createEmptyTexture_n(e,t,i,s){let n=this.gl,r=n.createTexture();return n.bindTexture(n.TEXTURE_2D,r),n.texImage2D(n.TEXTURE_2D,0,i||n.RGBA,e,t,0,n.RGBA,n.UNSIGNED_BYTE,null),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,s||n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,s||n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),r}createEmptyTexture_l(e,t,i,s){let n=this.gl,r=n.createTexture();return n.bindTexture(n.TEXTURE_2D,r),n.texImage2D(n.TEXTURE_2D,0,i||n.RGBA,e,t,0,n.RGBA,n.UNSIGNED_BYTE,null),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,s||n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,s||n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),r}createTexture_n_webgl1(e,t,i,s=null){let n=this.gl;return s=s||n.createTexture(),n.bindTexture(n.TEXTURE_2D,s),n.texImage2D(n.TEXTURE_2D,0,t||n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,i||n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,i||n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),s}createTexture_l_webgl1(e,t,i,s=null){let n=this.gl;return s=s||n.createTexture(),n.bindTexture(n.TEXTURE_2D,s),n.texImage2D(n.TEXTURE_2D,0,t||n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,i||n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,i||n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),s}createTexture_mm_webgl1(e,t,i,s=null){let n=this.gl;return s=s||n.createTexture(),n.bindTexture(n.TEXTURE_2D,s),n.texImage2D(n.TEXTURE_2D,0,t||n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e),n.generateMipmap(n.TEXTURE_2D),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR_MIPMAP_LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,i||n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,i||n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),s}createTexture_a_webgl1(e,t,i,s=null){let n=this.gl;return s=s||n.createTexture(),n.bindTexture(n.TEXTURE_2D,s),n.texImage2D(n.TEXTURE_2D,0,t||n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e),n.generateMipmap(n.TEXTURE_2D),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR_MIPMAP_LINEAR),n.texParameterf(n.TEXTURE_2D,this.extensions.EXT_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT,this._params.anisotropy),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,i||n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,i||n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),s}createTexture_n_webgl2(e,t,i,s=null){let n=this.gl;return s=s||n.createTexture(),n.bindTexture(n.TEXTURE_2D,s),n.texStorage2D(n.TEXTURE_2D,1,t||n.RGBA8,e.width,e.height),n.texSubImage2D(n.TEXTURE_2D,0,0,0,e.width,e.height,n.RGBA,n.UNSIGNED_BYTE,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,i||n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,i||n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),s}createTexture_l_webgl2(e,t,i,s=null){let n=this.gl;return s=s||n.createTexture(),n.bindTexture(n.TEXTURE_2D,s),n.texStorage2D(n.TEXTURE_2D,1,t||n.RGBA8,e.width,e.height),n.texSubImage2D(n.TEXTURE_2D,0,0,0,e.width,e.height,n.RGBA,n.UNSIGNED_BYTE,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,i||n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,i||n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),s}createTexture_mm_webgl2(e,t,i,s=null){let n=this.gl;return s=s||n.createTexture(),n.bindTexture(n.TEXTURE_2D,s),n.texStorage2D(n.TEXTURE_2D,2,t||n.RGBA8,e.width,e.height),n.texSubImage2D(n.TEXTURE_2D,0,0,0,e.width,e.height,n.RGBA,n.UNSIGNED_BYTE,e),n.generateMipmap(n.TEXTURE_2D),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR_MIPMAP_LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,i||n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,i||n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),s}createTexture_a_webgl2(e,t,i,s=null){let n=this.gl;return s=s||n.createTexture(),n.bindTexture(n.TEXTURE_2D,s),n.texStorage2D(n.TEXTURE_2D,2,t||n.RGBA8,e.width,e.height),n.texSubImage2D(n.TEXTURE_2D,0,0,0,e.width,e.height,n.RGBA,n.UNSIGNED_BYTE,e),n.generateMipmap(n.TEXTURE_2D),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR_MIPMAP_LINEAR),n.texParameterf(n.TEXTURE_2D,this.extensions.EXT_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT,this._params.anisotropy),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,i||n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,i||n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),s}loadCubeMapTexture(e){let t=this.gl,i=t.createTexture();t.bindTexture(t.TEXTURE_CUBE_MAP,i),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MAG_FILTER,t.LINEAR);let s=[[e.px,t.TEXTURE_CUBE_MAP_POSITIVE_X],[e.nx,t.TEXTURE_CUBE_MAP_NEGATIVE_X],[e.py,t.TEXTURE_CUBE_MAP_POSITIVE_Y],[e.ny,t.TEXTURE_CUBE_MAP_NEGATIVE_Y],[e.pz,t.TEXTURE_CUBE_MAP_POSITIVE_Z],[e.nz,t.TEXTURE_CUBE_MAP_NEGATIVE_Z]],n=new Uo;n.fillEmpty();let r=n.getImage();for(let e=0;e<s.length;e++){let n=s[e][1];t.bindTexture(t.TEXTURE_CUBE_MAP,i),t.texImage2D(n,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,r)}for(let e=0;e<s.length;e++){let n=s[e][1],r=new Image;r.crossOrigin="",r.onload=function(e,i,s){return function(){t&&e&&(t.bindTexture(t.TEXTURE_CUBE_MAP,e),t.texImage2D(i,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,s))}}(i,n,r),r.src=s[e][0]}return i}addProgram(e,t=!1){if(this.programs[e.name])console.warn(`Shader program: "${e.name}" already exists.`);else{let i=new bl(this,e);this.programs[e.name]=i,this._initProgramController(i),t&&(i._activated=!1)}return e}removeProgram(e){this.programs[e]&&this.programs[e].remove()}addPrograms(e){for(let t=0;t<e.length;t++)this.addProgram(e[t])}_initProgramController(e){this._initialized&&(e.initialize(),this.activeProgram?(e.deactivate(),this.activeProgram._program.enableAttribArrays(),this.activeProgram._program.use()):(this.activeProgram=e,e.activate()))}_initPrograms(){for(let e in this.programs)this._initProgramController(this.programs[e])}initializeExtension(e,t=!1){if(!this.extensions||!this.extensions[e]){let i=Ll.getExtension(this.gl,e);i?this.extensions[e]=i:t&&console.warn("og.webgl.Handler: extension '"+e+"' doesn't initialize.")}return this.extensions&&this.extensions[e]}initialize(){if(this._initialized)return;if(!this.canvas)return;if(this.gl=Ll.getContext(this.canvas,this._params.context),!this.gl)return;this._initialized=!0,this._params.extensions.push("EXT_texture_filter_anisotropic"),"webgl"===this.gl.type?(this._params.extensions.push("OES_standard_derivatives"),this._params.extensions.push("OES_element_index_uint"),this._params.extensions.push("WEBGL_depth_texture"),this._params.extensions.push("ANGLE_instanced_arrays")):(this._params.extensions.push("EXT_color_buffer_float"),this._params.extensions.push("OES_texture_float_linear"));let e=this._params.extensions.length;for(;e--;)this.initializeExtension(this._params.extensions[e],!0);"webgl"===this.gl.type?(this.createTexture_n=this.createTexture_n_webgl1.bind(this),this.createTexture_l=this.createTexture_l_webgl1.bind(this),this.createTexture_mm=this.createTexture_mm_webgl1.bind(this),this.createTexture_a=this.createTexture_a_webgl1.bind(this)):(this.createTexture_n=this.createTexture_n_webgl2.bind(this),this.createTexture_l=this.createTexture_l_webgl2.bind(this),this.createTexture_mm=this.createTexture_mm_webgl2.bind(this),this.createTexture_a=this.createTexture_a_webgl2.bind(this)),this.createTexture.NEAREST=this.createTexture_n,this.createTexture.LINEAR=this.createTexture_l,this.createTexture.MIPMAP=this.createTexture_mm,this.createTexture.ANISOTROPIC=this.createTexture_a,this.extensions.EXT_texture_filter_anisotropic?this.createTextureDefault=this.createTexture_a:this.createTextureDefault=this.createTexture_mm,this._initPrograms(),this._setDefaults(),this.intersectionObserver=new IntersectionObserver((e=>{this._toggleVisibilityChange(e[e.length-1].isIntersecting)}),{threshold:0}),this.intersectionObserver.observe(this.canvas),this.resizeObserver=new ResizeObserver((e=>{this._toggleVisibilityChange(0!==e[0].contentRect.width&&0!==e[0].contentRect.height)})),this.resizeObserver.observe(this.canvas),document.addEventListener("visibilitychange",(()=>{this._toggleVisibilityChange("visible"===document.visibilityState)}))}_toggleVisibilityChange(e){e?(this.start(),this.ONCANVASRESIZE&&this.ONCANVASRESIZE(),this.events.dispatch(this.events.visibilitychange,!0)):(this.events.dispatch(this.events.visibilitychange,!1),this.stop())}_setDefaults(){let e=this.gl;e&&this.canvas&&(e.depthFunc(e.LESS),e.enable(e.DEPTH_TEST),this.setSize(this.canvas.clientWidth||this._params.width,this.canvas.clientHeight||this._params.height),e.frontFace(e.CCW),e.cullFace(e.BACK),e.enable(e.CULL_FACE),e.disable(e.BLEND),this.createDefaultTexture({color:"rgba(0,0,0,0.0)"},(e=>{this.transparentTexture=e})),this.createDefaultTexture({color:"rgba(255, 255, 255, 1.0)"},(e=>{this.defaultTexture=e})))}getCanvasSize(){return this._canvasSize}createStreamArrayBuffer(e,t,i,s=4){let n=this.gl,r=n.createBuffer();return n.bindBuffer(n.ARRAY_BUFFER,r),n.bufferData(n.ARRAY_BUFFER,t*e*s,i||n.STREAM_DRAW),n.bindBuffer(n.ARRAY_BUFFER,null),r.itemSize=e,r.numItems=t,r}setStreamArrayBuffer(e,t,i=0){let s=this.gl;return s.bindBuffer(s.ARRAY_BUFFER,e),s.bufferSubData(s.ARRAY_BUFFER,i,t),s.bindBuffer(s.ARRAY_BUFFER,null),e}createArrayBuffer(e,t,i,s){let n=this.gl,r=n.createBuffer();return n.bindBuffer(n.ARRAY_BUFFER,r),n.bufferData(n.ARRAY_BUFFER,e,s||n.STATIC_DRAW),n.bindBuffer(n.ARRAY_BUFFER,null),r.itemSize=t,r.numItems=i,r}createArrayBufferLength(e,t){let i=this.gl,s=i.createBuffer();return i.bindBuffer(i.ARRAY_BUFFER,s),i.bufferData(i.ARRAY_BUFFER,e,t||i.STATIC_DRAW),i.bindBuffer(i.ARRAY_BUFFER,null),s.itemSize=1,s.numItems=e,s}createElementArrayBuffer(e,t,i,s){let n=this.gl,r=n.createBuffer();return n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,r),n.bufferData(n.ELEMENT_ARRAY_BUFFER,e,s||n.STATIC_DRAW),n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,null),r.itemSize=t,r.numItems=i||e.length,r}setSize(e,t){this._params.width=e,this._params.height=t,this.canvas&&(this.canvas.width=e*this._params.pixelRatio,this.canvas.height=t*this._params.pixelRatio,this._canvasSize[0]=this.canvas.width,this._canvasSize[1]=this.canvas.height,this._oneByHeight=1/this.canvas.height,this.gl&&this.gl.viewport(0,0,e,t),this.ONCANVASRESIZE&&this.ONCANVASRESIZE(this.canvas),this.events.dispatch(this.events.resize,this))}get pixelRatio(){return this._params.pixelRatio}set pixelRatio(e){this._params.pixelRatio=e,this.setSize(this._params.width,this._params.height)}getWidth(){return this.canvas?this.canvas.width:0}getHeight(){return this.canvas?this.canvas.height:0}getClientAspect(){return this.canvas?this.canvas.clientWidth/this.canvas.clientHeight:0}getCenter(){let e=this.canvas;return e?new ae(Math.round(.5*e.width),Math.round(.5*e.height)):new ae}clearFrame(){let e=this.gl;e.clearColor(0,0,0,1),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)}start(){!this._requestAnimationFrameId&&this._initialized&&this._animationFrameCallback()}stop(){this._requestAnimationFrameId&&(window.cancelAnimationFrame(this._requestAnimationFrameId),this._requestAnimationFrameId=0)}isStopped(){return!this._requestAnimationFrameId}isWebGl2(){return!!this.gl&&"webgl2"===this.gl.type}_animationFrameCallback(){this._requestAnimationFrameId=window.requestAnimationFrame((()=>{this._throttledDrawFrame(),this._requestAnimationFrameId&&this._animationFrameCallback()}))}createDefaultTexture(e,t){let i,s;if(e&&e.color)i=new Uo(2,2),i.fillColor(e.color),s=this.createTexture_n(i.getCanvas()),s.default=!0,t(s);else if(e&&e.url){let i=new Image,n=this;i.onload=function(){s=n.createTextureDefault(i),s.default=!0,t(s)},i.src=e.url}else i=new Uo(2,2),i.fillColor("#C5C5C5"),s=this.createTexture_n(i.getCanvas()),s.default=!0,t(s)}deleteTexture(e){e&&!e.default&&this.gl.deleteTexture(e)}destroy(){this.resizeObserver?.disconnect(),this.intersectionObserver?.disconnect(),this.stop();for(let e in this.programs)this.removeProgram(e);let e=this.gl;if(e){e.deleteTexture(this.transparentTexture),this.transparentTexture=null,e.deleteTexture(this.defaultTexture),this.defaultTexture=null,this.framebufferStack=new Cl;let t=e.getParameter(e.MAX_VERTEX_ATTRIBS),i=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,i);for(let i=0;i<t;++i)e.disableVertexAttribArray(i),e.vertexAttribPointer(i,4,e.FLOAT,!1,0,0),e.vertexAttrib1f(i,0);e.deleteBuffer(i);let s=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS);for(let t=0;t<s;++t)e.activeTexture(e.TEXTURE0+t),e.bindTexture(e.TEXTURE_CUBE_MAP,null),e.bindTexture(e.TEXTURE_2D,null);e.activeTexture(e.TEXTURE0),e.useProgram(null),e.bindBuffer(e.ARRAY_BUFFER,null),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindRenderbuffer(e.RENDERBUFFER,null),e.disable(e.BLEND),e.disable(e.CULL_FACE),e.disable(e.DEPTH_TEST),e.disable(e.DITHER),e.disable(e.SCISSOR_TEST),e.blendColor(0,0,0,0),e.blendEquation(e.FUNC_ADD),e.blendFunc(e.ONE,e.ZERO),e.clearColor(0,0,0,0),e.clearDepth(1),e.clearStencil(-1)}this.canvas&&(this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas),this.canvas.width=1,this.canvas.height=1,this.canvas=null),this.gl=null,this._initialized=!1}addClock(e){e.__handler||(e.__handler=this,this._clocks.push(e))}addClocks(e){for(let t=0;t<e.length;t++)this.addClock(e[t])}removeClock(e){if(e.__handler){let t=this._clocks,i=t.length;for(;i--;)if(t[i].isEqual(e)){e.__handler=null,t.splice(i,1);break}}}}class Al extends Vo{constructor(e,t={}){super(e,t),this._internalFormat=t.internalFormat?t.internalFormat.toUpperCase():"RGBA8",this._msaa=null!=t.msaa?t.msaa:4,this._glFilter=0,this.renderbuffers=new Array(this._size)}destroy(){let e=this.handler.gl;if(e){for(let t=0;t<this.renderbuffers.length;t++)e.deleteRenderbuffer(this.renderbuffers[t]);this.renderbuffers=new Array(this._size),e.deleteFramebuffer(this._fbo),e.deleteRenderbuffer(this._depthRenderbuffer),this._depthRenderbuffer=null,this._fbo=null,this._active=!1}}init(){let e=this.handler.gl;if(!e)return;this._glFilter=e[this._filter],this._fbo=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this._fbo);let t=[];for(let i=0;i<this.renderbuffers.length;i++){let s=e.createRenderbuffer();e.bindRenderbuffer(e.RENDERBUFFER,s),this._msaa>0?e.renderbufferStorageMultisample(e.RENDERBUFFER,this._msaa,e[this._internalFormat],this._width,this._height):e.renderbufferStorage(e.RENDERBUFFER,e[this._internalFormat],this._width,this._height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+i,e.RENDERBUFFER,s),t.push(e.COLOR_ATTACHMENT0+i),this.renderbuffers[i]=s,e.bindRenderbuffer(e.RENDERBUFFER,null)}e.drawBuffers(t),this._useDepth&&(this._depthRenderbuffer=e.createRenderbuffer(),e.bindRenderbuffer(e.RENDERBUFFER,this._depthRenderbuffer),e.renderbufferStorageMultisample(e.RENDERBUFFER,this._msaa,e[this._depthComponent],this._width,this._height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,this._depthRenderbuffer),e.bindRenderbuffer(e.RENDERBUFFER,null)),e.bindFramebuffer(e.FRAMEBUFFER,null)}blitTo(e,t=0){let i=this.handler.gl;i.bindFramebuffer(i.READ_FRAMEBUFFER,this._fbo),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,e._fbo),i.readBuffer(i.COLOR_ATTACHMENT0+t),i.clearBufferfv(i.COLOR,0,[0,0,0,1]),i.blitFramebuffer(0,0,this._width,this._height,0,0,e._width,e._height,i.COLOR_BUFFER_BIT,this._glFilter),i.bindFramebuffer(i.FRAMEBUFFER,null),i.bindFramebuffer(i.READ_FRAMEBUFFER,null),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,null)}}var Pl=Object.freeze({__proto__:null,Framebuffer:Yo,Handler:Ll,Multisample:Al,Program:Ni,types:Ii});const Sl=function(e,t){return Number(e.priority<t.priority)};class Ml{constructor(){this._currentlyPressedKeys={},this._pressedKeysCallbacks={},this._unpressedKeysCallbacks={},this._charkeysCallbacks={},this._anykeyCallback=null,this._event=null,this._active=!0,this._stampCache={},document.onkeydown=e=>{this._event=e,this._active&&this.handleKeyDown()},document.onkeyup=e=>{this._event=e,this._active&&this.handleKeyUp()}}getcurrentlyPressedKeys(){return this._currentlyPressedKeys}getPressedKeysCallbacks(){return this._pressedKeysCallbacks}getUnpressedKeysCallbacks(){return this._unpressedKeysCallbacks}getCharkeysCallbacks(){return this._charkeysCallbacks}removeEvent(e,t,i){let s=this._getStamp(e,t,i._openglobus_id);i._openglobus_id&&this._stampCache[s]&&(delete this._stampCache[s],"keypress"===e?this._removeCallback(this._pressedKeysCallbacks[t],i):"keyfree"===e?this._removeCallback(this._unpressedKeysCallbacks[t],i):"charkeypress"===e&&this._removeCallback(this._charkeysCallbacks[t],i))}_removeCallback(e,t){for(let i=0;i<e.length;i++)e[i].callback._openglobus_id===t._openglobus_id&&e.splice(i,1)}_getStamp(e,t,i){return`${e}_${t}_${i}`}_stamp(e,t,i){const s=fe(i),n=this._getStamp(e,t,s);return!this._stampCache[n]&&(this._stampCache[n]=s,!0)}setActivity(e){this._active=e}releaseKeys(){this._currentlyPressedKeys={}}addEvent(e,t,i,s,n){if(this._stamp(e,t,i))switch(void 0===n&&(n=1600),e){case"keyfree":this._unpressedKeysCallbacks[t]||(this._unpressedKeysCallbacks[t]=[]),this._unpressedKeysCallbacks[t].push({callback:i,sender:s,priority:n}),this._unpressedKeysCallbacks[t].sort(Sl);break;case"keypress":null==t?this._anykeyCallback={callback:i,sender:s||this}:(this._pressedKeysCallbacks[t]||(this._pressedKeysCallbacks[t]=[]),this._pressedKeysCallbacks[t].push({callback:i,sender:s,priority:n}),this._pressedKeysCallbacks[t].sort(Sl));break;case"charkeypress":this._charkeysCallbacks[t]||(this._charkeysCallbacks[t]=[]),this._charkeysCallbacks[t].push({callback:i,sender:s,priority:n}),this._charkeysCallbacks[t].sort(Sl)}}isKeyPressed(e){return this._currentlyPressedKeys[e]}handleKeyDown(){this._anykeyCallback&&this._anykeyCallback.callback.call(this._anykeyCallback.sender,this._event),this._currentlyPressedKeys[this._event.keyCode]=!0;for(let e in this._charkeysCallbacks)if(String.fromCharCode(this._event.keyCode)===String.fromCharCode(Number(e))){let t=this._charkeysCallbacks[e];for(let e=0;e<t.length;e++)t[e].callback.call(t[e].sender,this._event)}this._event.keyCode!=Cn.KEY_ALT&&this._event.keyCode!=Cn.KEY_SHIFT||this._event.preventDefault()}handleKeyUp(){if(this._currentlyPressedKeys[this._event.keyCode]||this._event.keyCode===Cn.KEY_PRINTSCREEN)for(let e in this._unpressedKeysCallbacks)if(this._currentlyPressedKeys[e]||this._event.keyCode===Cn.KEY_PRINTSCREEN&&Number(e)===Cn.KEY_PRINTSCREEN){let t=this._unpressedKeysCallbacks[e];for(let e=0;e<t.length;e++)t[e].callback.call(t[e].sender,this._event)}this._currentlyPressedKeys[this._event.keyCode]=!1}handleEvents(){for(let e in this._pressedKeysCallbacks)if(this._currentlyPressedKeys[e]){let t=this._pressedKeysCallbacks[e];for(let e=0;e<t.length;e++)t[e].callback.call(t[e].sender,this._event)}}}class Rl{constructor(e){this._htmlObject=e}setEvent(e,t,i){switch(e){case"mousewheel":this._htmlObject.addEventListener("wheel",(e=>{let s=e.deltaY||e.detail||e.wheelDelta||0;var n;null==e.wheelDelta&&(e.wheelDelta=-120*s),e.isTouchPad=0===(n=e).deltaMode&&Math.abs(n.deltaY)<50,i.call(t,e),e.preventDefault()}),!1);break;case"mousedown":this._htmlObject.addEventListener("mousedown",(function(e){let s=this.getBoundingClientRect();i.call(t,e,{button:e.button,clientX:e.clientX-s.left,clientY:e.clientY-s.top})})),this._htmlObject.addEventListener("contextmenu",(function(e){return e.preventDefault(),!1}));break;case"mouseup":this._htmlObject.addEventListener("mouseup",(function(e){let s=this.getBoundingClientRect();i.call(t,e,{button:e.button,clientX:e.clientX-s.left,clientY:e.clientY-s.top})}));break;case"mousemove":this._htmlObject.addEventListener("mousemove",(function(e){let s=this.getBoundingClientRect();i.call(t,e,{clientX:e.clientX-s.left,clientY:e.clientY-s.top})}));break;case"mouseleave":this._htmlObject.addEventListener("mouseleave",(function(e){i.call(t,e)}));break;case"mouseout":this._htmlObject.addEventListener("mouseout",(function(e){i.call(t,e)}));break;case"mouseover":this._htmlObject.addEventListener("mouseover",(function(e){i.call(t,e)}));break;case"mouseenter":this._htmlObject.addEventListener("mouseenter",(function(e){i.call(t,e)}))}}}class Bl{constructor(e){this._htmlObject=e}setEvent(e,t,i){switch(e){case"touchcancel":this._htmlObject.addEventListener("touchcancel",(function(e){e.preventDefault();const s=this.getBoundingClientRect(),n=Object.assign(e,{offsetLeft:s.left,offsetTop:s.top});i.call(t,n)}));break;case"touchstart":this._htmlObject.addEventListener("touchstart",(function(e){e.preventDefault();const s=this.getBoundingClientRect(),n=Object.assign(e,{offsetLeft:s.left,offsetTop:s.top});i.call(t,n)}));break;case"touchend":this._htmlObject.addEventListener("touchend",(function(e){e.preventDefault();const s=this.getBoundingClientRect(),n=Object.assign(e,{offsetLeft:s.left,offsetTop:s.top});i.call(t,n)}));break;case"touchmove":this._htmlObject.addEventListener("touchmove",(function(e){e.preventDefault();const s=this.getBoundingClientRect(),n=Object.assign(e,{offsetLeft:s.left,offsetTop:s.top});i.call(t,n)}))}}}let kl=new Uint8Array(4),Il=new Uint8Array(4),zl=new Uint8Array(4);class Dl extends Rt{constructor(e){super(Fl),this.renderer=e,this._touchHandler=new Bl(e.handler.canvas),this._mouseHandler=new Rl(e.handler.canvas),this._keyboardHandler=new Ml,this._active=!0,this.clickRadius=15,this.mouseState={clientX:0,clientY:0,pos:new ae,x:0,y:0,nx:0,ny:0,prev_x:0,prev_y:0,direction:new oe,leftButtonUp:!1,rightButtonUp:!1,middleButtonUp:!1,leftButtonDown:!1,rightButtonDown:!1,middleButtonDown:!1,leftButtonHold:!1,rightButtonHold:!1,middleButtonHold:!1,leftButtonDoubleClick:!1,rightButtonDoubleClick:!1,middleButtonDoubleClick:!1,leftButtonClick:!1,rightButtonClick:!1,middleButtonClick:!1,moving:!1,justStopped:!1,doubleClickDelay:500,clickDelay:200,wheelDelta:0,sys:null,pickingObject:null,renderer:e,isTouchPad:!1},this.touchState={moving:!1,touchEnd:!1,touchStart:!1,touchCancel:!1,doubleTouch:!1,doubleTouchDelay:550,doubleTouchRadius:10,clientX:0,clientY:0,pos:new ae,x:0,y:0,nx:0,ny:0,prev_x:0,prev_y:0,direction:new oe,sys:null,pickingObject:null,renderer:e},this._isMouseInside=!0,this._entityPickingEventsActive=!0,this._dblTchCoords=new ae,this._oneTouchStart=!1,this._dblTchBegins=0,this._mousestopThread=null,this._ldblClkBegins=0,this._rdblClkBegins=0,this._mdblClkBegins=0,this._lClkBegins=0,this._rClkBegins=0,this._mClkBegins=0,this._lclickX=0,this._lclickY=0,this._rclickX=0,this._rclickY=0,this._mclickX=0,this._mclickY=0}pointerEvent(){let e=this.mouseState,t=this.touchState;return e.moving||e.justStopped||t.moving||t.touchStart||t.touchEnd||0!==e.wheelDelta}get active(){return this._active}set active(e){this._active=e,this._keyboardHandler.setActivity(e)}handleEvents(){this._active&&(this.mouseState.direction=this.renderer.activeCamera.unproject(this.mouseState.x,this.mouseState.y),this.touchState.direction=this.renderer.activeCamera.unproject(this.touchState.x,this.touchState.y),this._keyboardHandler.handleEvents(),this.handleMouseEvents(),this.handleTouchEvents(),this.entityPickingEvents())}on(e,t,i,s,n){"keypress"===e||"charkeypress"===e||"keyfree"===e?this._keyboardHandler.addEvent(e,t,i,s,n):super.on(e,t,i,s)}off(e,t,i){"keypress"===e||"charkeypress"===e||"keyfree"===e?this._keyboardHandler.removeEvent(e,t,i):super.off(e,t)}isKeyPressed(e){return this._keyboardHandler.isKeyPressed(e)}releaseKeys(){this._keyboardHandler.releaseKeys()}initialize(){this._mouseHandler.setEvent("mouseup",this,this.onMouseUp),this._mouseHandler.setEvent("mousemove",this,this.onMouseMove),this._mouseHandler.setEvent("mousedown",this,this.onMouseDown),this._mouseHandler.setEvent("mousewheel",this,this.onMouseWheel),this._mouseHandler.setEvent("mouseleave",this,this.onMouseLeave),this._mouseHandler.setEvent("mouseenter",this,this.onMouseEnter),this._touchHandler.setEvent("touchstart",this,this.onTouchStart),this._touchHandler.setEvent("touchend",this,this.onTouchEnd),this._touchHandler.setEvent("touchcancel",this,this.onTouchCancel),this._touchHandler.setEvent("touchmove",this,this.onTouchMove)}onMouseWheel(e){this.mouseState.isTouchPad=e.isTouchPad||!1,this.mouseState.sys=e,this.mouseState.wheelDelta=e.wheelDelta||0}updateButtonsStates(e){let t=this.mouseState;1&e&&t.leftButtonDown?t.leftButtonDown=!0:(t.leftButtonHold=!1,t.leftButtonDown=!1),2&e&&t.rightButtonDown?t.rightButtonDown=!0:(t.rightButtonHold=!1,t.rightButtonDown=!1),4&e&&t.middleButtonDown?t.middleButtonDown=!0:(t.middleButtonHold=!1,t.middleButtonDown=!1)}onMouseMove(e,t){let i=this.mouseState;this.updateButtonsStates(e.buttons),i.sys=e;let s=t.clientX,n=t.clientY,r=this.clickRadius;if(Math.abs(this._lclickX-s)>=r&&Math.abs(this._lclickY-n)>=r&&(this._ldblClkBegins=0,this._lClkBegins=0),Math.abs(this._rclickX-s)>=r&&Math.abs(this._rclickY-n)>=r&&(this._rdblClkBegins=0,this._rClkBegins=0),Math.abs(this._mclickX-s)>=r&&Math.abs(this._mclickY-n)>=r&&(this._mdblClkBegins=0,this._mClkBegins=0),i.clientX===t.clientX&&i.clientY===t.clientY)return;i.clientX=t.clientX,i.clientY=t.clientY;let o=this.renderer.handler;i.pos.x=i.x=t.clientX*o.pixelRatio,i.pos.y=i.y=t.clientY*o.pixelRatio,i.nx=i.x/o.canvas.width,i.ny=i.y/o.canvas.height,i.moving=!0,clearTimeout(this._mousestopThread),this._mousestopThread=setTimeout((function(){i.justStopped=!0}),100)}onMouseLeave(e){this._isMouseInside=!1,this.mouseState.sys=e,this.dispatch(this.mouseleave,this.mouseState)}onMouseEnter(e){this._isMouseInside=!0,this.mouseState.sys=e,this.dispatch(this.mouseenter,this.mouseState)}onMouseDown(e,t){t.button===Cn.MB_LEFT?(this._lClkBegins=window.performance.now(),this._lclickX=t.clientX,this._lclickY=t.clientY,this.mouseState.sys=e,this.mouseState.leftButtonDown=!0):t.button===Cn.MB_RIGHT?(this._rClkBegins=window.performance.now(),this._rclickX=t.clientX,this._rclickY=t.clientY,this.mouseState.sys=e,this.mouseState.rightButtonDown=!0):t.button===Cn.MB_MIDDLE&&(this._mClkBegins=window.performance.now(),this._mclickX=t.clientX,this._mclickY=t.clientY,this.mouseState.sys=e,this.mouseState.middleButtonDown=!0)}onMouseUp(e,t){let i=this.mouseState;i.sys=e;let s=window.performance.now();if(t.button===Cn.MB_LEFT){if(i.leftButtonDown=!1,i.leftButtonUp=!0,Math.abs(this._lclickX-t.clientX)<this.clickRadius&&Math.abs(this._lclickY-t.clientY)<this.clickRadius&&s-this._lClkBegins<=i.clickDelay){if(this._ldblClkBegins){window.performance.now()-this._ldblClkBegins<=i.doubleClickDelay&&(i.leftButtonDoubleClick=!0),this._ldblClkBegins=0}else this._ldblClkBegins=window.performance.now();i.leftButtonClick=!0,this._lClkBegins=0}}else if(t.button===Cn.MB_RIGHT){if(i.rightButtonDown=!1,i.rightButtonUp=!0,Math.abs(this._rclickX-t.clientX)<this.clickRadius&&Math.abs(this._rclickY-t.clientY)<this.clickRadius&&s-this._rClkBegins<=i.clickDelay){if(this._rdblClkBegins){window.performance.now()-this._rdblClkBegins<=i.doubleClickDelay&&(i.rightButtonDoubleClick=!0),this._rdblClkBegins=0}else this._rdblClkBegins=window.performance.now();i.rightButtonClick=!0,this._rClkBegins=0}}else if(t.button===Cn.MB_MIDDLE&&(i.middleButtonDown=!1,i.middleButtonUp=!0,Math.abs(this._mclickX-t.clientX)<this.clickRadius&&Math.abs(this._mclickY-t.clientY)<this.clickRadius&&s-this._mClkBegins<=i.clickDelay)){if(this._mdblClkBegins){window.performance.now()-this._mdblClkBegins<=i.doubleClickDelay&&(i.middleButtonDoubleClick=!0),this._mdblClkBegins=0}else this._mdblClkBegins=window.performance.now();i.middleButtonClick=!0,this._mClkBegins=0}}onTouchStart(e){let t=this.touchState;t.sys=e,t.clientX=e.touches.item(0).clientX-e.offsetLeft,t.clientY=e.touches.item(0).clientY-e.offsetTop;let i=this.renderer.handler;t.pos.x=t.x=t.clientX*i.pixelRatio,t.pos.y=t.y=t.clientY*i.pixelRatio,t.nx=t.x/i.canvas.width,t.ny=t.y/i.canvas.height,t.prev_x=t.x,t.prev_y=t.y,t.touchStart=!0,1===e.touches.length?(this._dblTchCoords.x=t.x,this._dblTchCoords.y=t.y,this._oneTouchStart=!0):this._oneTouchStart=!1}onTouchEnd(e){let t=this.touchState;if(t.sys=e,t.touchEnd=!0,0===e.touches.length&&(t.prev_x=t.x,t.prev_y=t.y,this._oneTouchStart)){if(this._dblTchBegins){window.performance.now()-this._dblTchBegins<=t.doubleTouchDelay&&(t.doubleTouch=!0),this._dblTchBegins=0}this._dblTchBegins=window.performance.now(),this._oneTouchStart=!1}}onTouchCancel(e){let t=this.touchState;t.sys=e,t.touchCancel=!0}onTouchMove(e){let t=this.touchState;t.clientX=e.touches.item(0).clientX-e.offsetLeft,t.clientY=e.touches.item(0).clientY-e.offsetTop;let i=this.renderer.handler;t.x=t.clientX*i.pixelRatio,t.y=t.clientY*i.pixelRatio,t.nx=t.x/i.canvas.width,t.ny=t.y/i.canvas.height,t.sys=e,t.moving=!0;let s=t.x-t.prev_x,n=t.y-t.prev_y;(Math.abs(s)>9||Math.abs(n)>9)&&(this._dblTchBegins=0,this._oneTouchStart=!1)}entityPickingEvents(){let e=this.touchState,t=this.mouseState;if(this._isMouseInside!==this._entityPickingEventsActive&&(this._entityPickingEventsActive=this._isMouseInside,!this._entityPickingEventsActive)){let i=this.renderer,s=kl,n=i.getPickingObjectArr(s);if(n){let i=n.rendererEvents;t.pickingObject=n,i&&i.dispatch(i.mouseleave,t),e.pickingObject=n,i&&i.dispatch(i.touchleave,e)}kl[0]=kl[1]=kl[2]=kl[3]=zl[0]=zl[1]=zl[2]=zl[3]=Il[0]=Il[1]=Il[2]=Il[3]=0}if(this._isMouseInside&&!(t.leftButtonHold||t.rightButtonHold||t.middleButtonHold)){let i=this.renderer,s=kl,n=zl,r=Il;e.x||e.y?i.readPickingColor(e.nx,1-e.ny,r):i.readPickingColor(t.nx,1-t.ny,r),n[0]=s[0],n[1]=s[1],n[2]=s[2],s[0]=r[0],s[1]=r[1],s[2]=r[2],t.pickingObject=null,e.pickingObject=null;let o=i.getPickingObjectArr(s);if(t.pickingObject=o,e.pickingObject=o,s[0]!==n[0]||s[1]!==n[1]||s[2]!==n[2])if((e=>!(e[0]||e[1]||e[2]))(s)){let s=i.getPickingObjectArr(n);if(s){let i=s.rendererEvents;t.pickingObject=s,i&&i.dispatch(i.mouseleave,t),e.pickingObject=s,i&&i.dispatch(i.touchleave,e)}}else{if((e=>!!(e[0]||e[1]||e[2]))(n)){let s=i.getPickingObjectArr(n);if(s){let i=s.rendererEvents;t.pickingObject=s,i&&i.dispatch(i.mouseleave,t),e.pickingObject=s,i&&i.dispatch(i.touchleave,e)}}if(o){let i=o.rendererEvents;t.pickingObject=o,i&&i.dispatch(i.mouseenter,t),e.pickingObject=o,i&&i.dispatch(i.touchenter,e)}}}}handleMouseEvents(){let e=this,t=this.mouseState,i=t.pickingObject,s=null;t.leftButtonClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.lclick,t)),this.dispatch(e.lclick,t),t.leftButtonClick=!1),t.rightButtonClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.rclick,t)),this.dispatch(e.rclick,t),t.rightButtonClick=!1),t.middleButtonClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.mclick,t)),this.dispatch(e.mclick,t),t.middleButtonClick=!1),t.leftButtonDown&&(t.leftButtonHold?(i&&(s=i.rendererEvents,s&&s.dispatch(s.lhold,t)),this.dispatch(e.lhold,t)):(t.leftButtonHold=!0,i&&(s=i.rendererEvents,s&&s.dispatch(s.ldown,t)),this.dispatch(e.ldown,t))),t.rightButtonDown&&(t.rightButtonHold?(i&&(s=i.rendererEvents,s&&s.dispatch(s.rhold,t)),this.dispatch(e.rhold,t)):(t.rightButtonHold=!0,i&&(s=i.rendererEvents,s&&s.dispatch(s.rdown,t)),this.dispatch(e.rdown,t))),t.middleButtonDown&&(t.middleButtonHold?(i&&(s=i.rendererEvents,s&&s.dispatch(s.mhold,t)),this.dispatch(e.mhold,t)):(t.middleButtonHold=!0,i&&(s=i.rendererEvents,s&&s.dispatch(s.mdown,t)),this.dispatch(e.mdown,t))),t.leftButtonUp&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.lup,t)),this.dispatch(e.lup,t),t.leftButtonUp=!1,t.leftButtonHold=!1),t.rightButtonUp&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.rup,t)),this.dispatch(e.rup,t),t.rightButtonUp=!1,t.rightButtonHold=!1),t.middleButtonUp&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.mup,t)),this.dispatch(e.mup,t),t.middleButtonUp=!1,t.middleButtonHold=!1),t.leftButtonDoubleClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.ldblclick,t)),this.dispatch(e.ldblclick,t),t.leftButtonDoubleClick=!1),t.rightButtonDoubleClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.rdblclick,t)),this.dispatch(e.rdblclick,t),t.rightButtonDoubleClick=!1),t.middleButtonDoubleClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.mdblclick,t)),this.dispatch(e.mdblclick,t),t.middleButtonDoubleClick=!1),t.wheelDelta&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.mousewheel,t)),this.dispatch(e.mousewheel,t)),t.moving&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.mousemove,t)),this.dispatch(e.mousemove,t),t.prev_x=t.x,t.prev_y=t.y),t.justStopped&&this.dispatch(e.mousestop,t)}handleTouchEvents(){let e=this,t=this.touchState,i=t.pickingObject,s=null;if(t.touchCancel&&(this.dispatch(e.touchcancel,t),t.touchCancel=!1),t.touchStart){let n=this.renderer;n.readPickingColor(t.nx,1-t.ny,kl);let r=n.getPickingObjectArr(kl);i=t.pickingObject=r,i&&(s=i.rendererEvents,s&&s.dispatch(s.touchstart,t)),this.dispatch(e.touchstart,t),t.touchStart=!1}t.doubleTouch&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.doubletouch,t)),this.dispatch(e.doubletouch,t),t.doubleTouch=!1),t.touchEnd&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.touchend,t)),this.dispatch(e.touchend,t),t.x=0,t.y=0,t.touchEnd=!1),t.moving&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.touchmove,t)),this.dispatch(e.touchmove,t),t.prev_x=t.x,t.prev_y=t.y)}}const Fl=["changerelativecenter","draw","drawtransparent","postdraw","resize","resizeend","mouseenter","mouseleave","mousemove","mousestop","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchstart","touchend","touchcancel","touchmove","doubletouch","touchleave","touchenter"];class Nl{constructor(e=0,t=0,i=0,s=0){this.left=e,this.right=i,this.top=t,this.bottom=s}set(e=0,t=0,i=0,s=0){this.left=e,this.right=i,this.top=t,this.bottom=s}clone(){return new Nl(this.left,this.top,this.right,this.bottom)}getWidth(){return Math.abs(this.right-this.left)}getHeight(){return Math.abs(this.bottom-this.top)}getSquare(){return this.getHeight()*this.getWidth()}getDiagonal(){let e=this.getWidth(),t=this.getHeight();return Math.sqrt(t*t+e*e)}fit(e,t){return this.getWidth()===e&&this.getHeight()===t}isInside(e,t){return e>=this.left&&e<=this.right&&t>=this.top&&t<=this.bottom}}class Hl{constructor(){this.imagesCache={},this._counter=0,this._pendingsQueue=new xa,this._imageIndexCounter=0}load(e,t){if(this.imagesCache[e])t(this.imagesCache[e]);else{let i={src:e,success:t};this._counter>=1?this._pendingsQueue.unshift(i):this._exec(i)}}_exec(e){this._counter++;const t=this;let i=new Image;i.crossOrigin="",i.onload=function(){t.imagesCache[e.src]=i,i.__nodeIndex=t._imageIndexCounter++,e.success(i),t._dequeueRequest()},i.onerror=function(){t._dequeueRequest()},i.src=e.src}_dequeueRequest(){if(this._counter--,this._pendingsQueue.length&&this._counter<1)for(;this._pendingsQueue.length;){let e=this._pendingsQueue.pop();if(e){if(!this.imagesCache[e.src]){this._exec(e);break}this._counter<=0?this._counter=0:this._counter--,e.success(this.imagesCache[e.src])}}}}class Ol{constructor(e=1024,t=1024){this.nodes=new Map,this.texture=null,this.canvas=new Uo(e,t),this.clearCanvas(),this._handler=null,this._images=[],this._btree=null,this._imagesCacheManager=new Hl,this.borderSize=4}getImage(){return this.canvas.getImage()}getCanvas(){return this.canvas.getCanvas()}clearCanvas(){this.canvas.fillEmpty()}assignHandler(e){this._handler=e,this.createTexture()}getDiagonal(e){let t=e.atlasWidth||e.width,i=e.atlasHeight||e.height;return Math.sqrt(t*t+i*i)}addImage(e,t=!1){if(e.width&&e.height)return this._images.push(e),this._makeAtlas(t),null!=e.__nodeIndex?this.get(e.__nodeIndex):void 0}_completeNode(e,t){if(t){let i=this.canvas.getWidth(),s=this.canvas.getHeight(),n=t.image,r=t.rect,o=Math.round(.5*this.borderSize);this.canvas.drawImage(n,r.left+o,r.top+o,n.atlasWidth||0,n.atlasHeight||0);let a=t.texCoords;a[0]=(r.left+o)/i,a[1]=(r.top+o)/s,a[2]=(r.left+o)/i,a[3]=(r.bottom-o)/s,a[4]=(r.right-o)/i,a[5]=(r.bottom-o)/s,a[6]=(r.right-o)/i,a[7]=(r.bottom-o)/s,a[8]=(r.right-o)/i,a[9]=(r.top+o)/s,a[10]=(r.left+o)/i,a[11]=(r.top+o)/s,e.set(n.__nodeIndex,t)}}_makeAtlas(e=!1){if(e&&this._btree){let e=this._images[this._images.length-1];this._completeNode(this.nodes,this._btree.insert(e))}else{let e=this._images.slice(0);e.sort((function(e,t){return(t.atlasWidth||t.width)-(e.atlasWidth||e.width)||(t.atlasHeight||t.height)-(e.atlasHeight||e.height)})),this._btree=new Vl(new Nl(0,0,this.canvas.getWidth(),this.canvas.getHeight())),this._btree.atlas=this,this.clearCanvas();let t=new Map;for(let i=0;i<e.length;i++)this._completeNode(t,this._btree.insert(e[i]));this.nodes=null,this.nodes=t}}get(e){return this.nodes.get(e)}set(e,t){this.nodes.set(e,t)}createTexture(e,t){this._handler&&(this._handler.gl.deleteTexture(this.texture),e&&(this.canvas.resize(e.width,e.height),this.canvas.drawImage(e,0,0,e.width,e.height)),this.texture=this._handler.createTexture_l(this.canvas.getCanvas(),t))}loadImage(e,t){this._imagesCacheManager.load(e,t)}getImageTexCoordinates(e){if(null!=e.__nodeIndex){let t=this.get(e.__nodeIndex);if(t)return t.texCoords}}}class Vl{constructor(e,t){this.childNodes=null,this.image=null,this.rect=e||new Nl,this.texCoords=t||[],this.atlas=null}insert(e){if(this.childNodes){let t=this.childNodes[0].insert(e);return t||this.childNodes[1].insert(e)}{if(null!=this.image)return;let t=this.rect;const i=(e.atlasWidth||e.width)+this.atlas.borderSize,s=(e.atlasHeight||e.height)+this.atlas.borderSize;if(i>t.getWidth()||s>t.getHeight())return;if(t.fit(i,s))return this.image=e,this;this.childNodes=new Array(2),this.childNodes[0]=new Vl,this.childNodes[0].atlas=this.atlas,this.childNodes[1]=new Vl,this.childNodes[1].atlas=this.atlas;return t.getWidth()-i>t.getHeight()-s?(this.childNodes[0].rect.set(t.left,t.top,t.left+i,t.bottom),this.childNodes[1].rect.set(t.left+i,t.top,t.right,t.bottom)):(this.childNodes[0].rect.set(t.left,t.top,t.right,t.top+s),this.childNodes[1].rect.set(t.left,t.top+s,t.right,t.bottom)),this.childNodes[0].insert(e)}}}class Ul extends Ol{constructor(e,t){super(e,t),this.width=0,this.height=0,this.gliphSize=0,this.distanceRange=0,this.nodes=new Map,this.kernings={}}get(e){return this.nodes.get(e)}}class Gl extends Vl{constructor(e,t){super(e,t),this.emptySize=1,this.metrics={id:0,char:"",width:0,height:0,x:0,y:0,chnl:0,index:0,page:0,xadvance:0,xoffset:0,yoffset:0,nChar:"",nCode:0,nWidth:0,nHeight:0,nAdvance:0,nXOffset:0,nYOffset:0}}}class Yl{constructor(e){this.atlasesArr=[],this.atlasIndexes={},this.atlasIndexesDeferred={},this.tokenImageSize=64,this.samplerArr=new Uint32Array(11),this.sdfParamsArr=new Float32Array(44),this._handler=null,this.catalogSrc=e||"./"}assignHandler(e){this._handler=e}getFontIndex(e){let t=this.getFullIndex(e);return this.atlasIndexes[t]||this.loadFont(e,this.catalogSrc,`${e}.json`),this.atlasIndexesDeferred[t]||(this.atlasIndexesDeferred[t]=new xr),this.atlasIndexesDeferred[t].promise}getFullIndex(e){return e.trim().toLowerCase()}_applyFontDataToAtlas(e,t,i=0){let s=t.chars;e.height=t.common.scaleH,e.width=t.common.scaleW,e.gliphSize=t.info.size,e.distanceRange=t.distanceField.distanceRange;let n=e.width,r=e.height,o=e.gliphSize;this.sdfParamsArr[4*i]=n,this.sdfParamsArr[4*i+1]=r,this.sdfParamsArr[4*i+2]=o,this.sdfParamsArr[4*i+3]=e.distanceRange;let a={};for(let t=0;t<s.length;t++){let i=s[t],l=i.char;a[i.id]=l;let h=new Nl(i.x,i.y,i.x+i.width,i.y+i.height),c=new Array(12);c[0]=h.left/n,c[1]=h.top/r,c[2]=h.left/n,c[3]=h.bottom/r,c[4]=h.right/n,c[5]=h.bottom/r,c[6]=h.right/n,c[7]=h.bottom/r,c[8]=h.right/n,c[9]=h.top/r,c[10]=h.left/n,c[11]=h.top/r;let d=new Gl(h,c),_=i.char.normalize("NFKC"),u=_.charCodeAt(0),g=d.metrics;g.id=i.id,g.char=i.char,g.width=i.width,g.height=i.height,g.x=i.x,g.y=i.y,g.chnl=i.chnl,g.index=i.index,g.page=i.page,g.xadvance=i.xadvance,g.xoffset=i.xoffset,g.yoffset=i.yoffset,g.nChar=_,g.nCode=u,g.nWidth=d.metrics.width/o,g.nHeight=d.metrics.height/o,g.nAdvance=d.metrics.xadvance/o,g.nXOffset=d.metrics.xoffset/o,g.nYOffset=1-d.metrics.yoffset/o,d.emptySize=1,e.nodes.set(_.charCodeAt(0),d)}e.kernings={};for(let i=0;i<t.kernings.length;i++){let s=t.kernings[i],n=s.first,r=s.second;e.kernings[n]||(e.kernings[n]={}),e.kernings[n][r]=s.amount/o}}initFont(e,t,i){let s=this.atlasesArr.length,n=this.getFullIndex(e);this.atlasIndexes[n]=s;let r=this.atlasIndexesDeferred[n];r||(r=this.atlasIndexesDeferred[n]=new xr),this.samplerArr[this.atlasesArr.length]=s;let o=new Ul;o.height=0,o.width=0,o.gliphSize=0,o.distanceRange=0,o.kernings={},o.assignHandler(this._handler),this.atlasesArr[s]=o,this._applyFontDataToAtlas(o,t,s);let a=new Image;a.onload=()=>{this._createTexture(o,a),r.resolve(s)},a.src=i}_createTexture(e,t){e.createTexture(t)}loadFont(e,t,i){let s=this.atlasesArr.length,n=this.getFullIndex(e);this.atlasIndexes[n]=s;let r=this.atlasIndexesDeferred[n];r||(r=this.atlasIndexesDeferred[n]=new xr),this.samplerArr[this.atlasesArr.length]=s;let o=new Ul;o.height=0,o.width=0,o.gliphSize=0,o.distanceRange=0,o.kernings={},o.assignHandler(this._handler),this.atlasesArr[s]=o,fetch(`${t}/${i}`).then((e=>{if(!e.ok)throw Error(`Unable to load "${t}/${i}"`);return e.json()})).then((e=>{this._applyFontDataToAtlas(o,e,s);let i=new Image;i.onload=()=>{this._createTexture(o,i),r.resolve(s)},i.src=`${t}/${e.pages[0]}`,i.crossOrigin="Anonymous"})).catch((e=>(r.reject(),{status:"error",msg:e.toString()})))}}let jl=0,Wl=0,ql=new Float32Array(2);class $l{constructor(e,t={}){if(this.div=null,this.handler=e instanceof Ll?e:new Ll(e,{pixelRatio:t.dpi||window.devicePixelRatio+.15,autoActivate:!0}),this.exposure=t.exposure||3.01,this.gamma=t.gamma||.47,this.whitepoint=1,this.brightThreshold=.9,this._renderNodesArr=[],this.renderNodes={},this.activeCamera=new Va(this,{eye:new oe(0,0,0),look:new oe(0,0,-1),up:new oe(0,1,0)}),this.events=new Dl(this),this.controls={},t.controls)for(let e in t.controls)this.controls[t.controls[e].name]=t.controls[e];this.controlsBag={},this.colorObjects=new Map,this._pickingCallbacks=[],this.pickingFramebuffer=null,this._depthCallbacks=[],this.depthFramebuffer=null;let i=new URLSearchParams(location.search),s=i.get("og_msaa");this._msaa=s?Number(i.get("og_msaa")):null!=t.msaa?t.msaa:0,this._internalFormat="RGBA16F",this._format="RGBA",this._type="FLOAT",this.sceneFramebuffer=null,this.blitFramebuffer=null,this.toneMappingFramebuffer=null,this._initialized=!1,this.billboardsTextureAtlas=new Ol,this.geoObjectsTextureAtlas=new Ol,this.fontAtlas=new Yl(t.fontsSrc),this._entityCollections=[[]],this._currentOutput="screen",this._fnScreenFrame=null,this.labelWorker=new si(4),this.screenDepthFramebuffer=null,this.screenFramePositionBuffer=null,this.screenTexture={},this.outputTexture=null,this._readPickingBuffer=this._readPickingBuffer_webgl2,(t.autoActivate||_e(t.autoActivate))&&this.start()}enableBlendOneSrcAlpha(){let e=this.handler.gl;e.enable(e.BLEND),e.blendEquation(e.FUNC_ADD),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA)}enableBlendDefault(){let e=this.handler.gl;e.enable(e.BLEND),e.blendEquation(e.FUNC_ADD),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE)}setRelativeCenter(e){this.events.dispatch(this.events.changerelativecenter,e||this.activeCamera.eye)}setEventsActivity(e){this.events.active=e}addDepthCallback(e,t){let i=Wl++;return this._depthCallbacks.push({id:i,callback:t,sender:e}),i}removeDepthCallback(e){for(let t=0;t<this._depthCallbacks.length;t++)if(e===this._depthCallbacks[t].id){this._depthCallbacks.splice(t,1);break}}addPickingCallback(e,t){let i=jl++;return this._pickingCallbacks.push({id:i,callback:t,sender:e}),i}removePickingCallback(e){for(let t=0;t<this._pickingCallbacks.length;t++)if(e===this._pickingCallbacks[t].id){this._pickingCallbacks.splice(t,1);break}}getPickingObject(e,t,i){return this.colorObjects.get(`${e}_${t}_${i}`)}getPickingObjectArr(e){return this.colorObjects.get(`${e[0]}_${e[1]}_${e[2]}`)}getPickingObject3v(e){return this.colorObjects.get(`${e.x}_${e.y}_${e.z}`)}assignPickingColor(e){if(!e._pickingColor||e._pickingColor.isZero()){let t=0,i=0,s=0,n="0_0_0";for(;!(t||i||s)||this.colorObjects.has(n);)t=x(1,255),i=x(1,255),s=x(1,255),n=`${t}_${i}_${s}`;e._pickingColor?e._pickingColor.set(t,i,s):e._pickingColor=new oe(t,i,s),e._pickingColorU=new Float32Array([t/255,i/255,s/255]),this.colorObjects.set(n,e)}}clearPickingColor(e){if(e._pickingColor&&!e._pickingColor.isZero()){let t=e._pickingColor;t.isZero()||(this.colorObjects.delete(`${t.x}_${t.y}_${t.z}`),t.x=t.y=t.z=0)}}getWidth(){return this.handler.canvas.clientWidth}getHeight(){return this.handler.canvas.clientHeight}getCenter(){let e=this.handler.canvas;return new ae(Math.round(.5*e.width),Math.round(.5*e.height))}getClientCenter(){let e=this.handler.canvas;return new ae(Math.round(.5*e.clientWidth),Math.round(.5*e.clientHeight))}addControl(e){e.addTo(this)}addControls(e){for(let t=0;t<e.length;t++)e[t].addTo(this)}removeControl(e){e.remove()}isInitialized(){return this._initialized}initialize(){if(!this._initialized){if(this._initialized=!0,this.handler.initialize(),this.billboardsTextureAtlas.assignHandler(this.handler),this.geoObjectsTextureAtlas.assignHandler(this.handler),this.fontAtlas.assignHandler(this.handler),this.handler.setFrameCallback((()=>{this.draw()})),this.events.initialize(),this.events.on("charkeypress",Cn.KEY_APOSTROPHE,(function(){Bi.setVisibility(!Bi.getVisibility())})),this.handler.addProgram(new Ni("screenFrame",{uniforms:{texture:"sampler2d"},attributes:{corners:"vec3"},vertexShader:"attribute vec2 corners;\n \n varying vec2 tc;\n void main(void) {\n gl_Position = vec4(corners, 0.0, 1.0);\n tc = corners * 0.5 + 0.5;\n }",fragmentShader:"precision highp float;\n uniform sampler2D texture;\n \n varying vec2 tc;\n \n void main(void) {\n gl_FragColor = texture2D( texture, tc );\n }"})),this.pickingFramebuffer=new Yo(this.handler,{width:640,height:480,targets:[{readAsync:!0}]}),this.pickingFramebuffer.init(),this.depthFramebuffer=new Yo(this.handler,{width:640,height:480,targets:[{internalFormat:"RGBA",type:"UNSIGNED_BYTE",attachment:"COLOR_ATTACHMENT",readAsync:!0},{internalFormat:"RGBA16F",type:"FLOAT",attachment:"COLOR_ATTACHMENT",readAsync:!0}],useDepth:!0}),this.depthFramebuffer.init(),this.screenDepthFramebuffer=new Yo(this.handler,{useDepth:!1}),this.screenDepthFramebuffer.init(),"webgl"===this.handler.gl.type)this._readPickingBuffer=this._readPickingBuffer_webgl1,this.sceneFramebuffer=new Yo(this.handler),this.sceneFramebuffer.init(),this._fnScreenFrame=this._screenFrameNoMSAA,this.screenTexture={screen:this.sceneFramebuffer.textures[0],picking:this.pickingFramebuffer.textures[0],depth:this.screenDepthFramebuffer.textures[0]};else{let e=this.getMaxMSAA(this._internalFormat);this._msaa>e&&(this._msaa=e),this.handler.addPrograms([new Ni("toneMapping",{uniforms:{hdrBuffer:"sampler2d",exposure:"float",gamma:"float",whitepoint:"float"},attributes:{corners:"vec3"},vertexShader:"#version 300 es\n \n in vec2 corners;\n \n out vec2 tc;\n\n void main(void) {\n gl_Position = vec4(corners, 0.0, 1.0);\n tc = corners * 0.5 + 0.5;\n }",fragmentShader:"#version 300 es\n\n precision highp float;\n\n #ifndef saturate\n #define saturate(a) clamp(a, 0.0, 1.0)\n #endif\n\n uniform sampler2D hdrBuffer;\n\n uniform float whitepoint;\n uniform float exposure;\n uniform float gamma;\n\n vec3 LinearToneMapping(vec3 color) {\n return exposure * color;\n }\n\n vec3 ReinhardToneMapping2(vec3 color) {\n return vec3(1.0) - exp(-color * exposure);\n }\n\n vec3 ReinhardToneMapping(vec3 color) {\n color *= exposure;\n return saturate(color / (vec3(1.0) + color));\n }\n\n #define Uncharted2Helper(x) max(((x * (0.15 * x + 0.10 * 0.50) + 0.20 * 0.02) / (x * (0.15 * x + 0.50) + 0.20 * 0.30)) - 0.02 / 0.30, vec3(0.0))\n\n vec3 Uncharted2ToneMapping(vec3 color) {\n color *= exposure;\n return saturate(Uncharted2Helper(color) / Uncharted2Helper(vec3(whitepoint)));\n }\n\n vec3 OptimizedCineonToneMapping(vec3 color) {\n color *= exposure;\n color = max(vec3(0.0), color - 0.004);\n return pow((color * (6.2 * color + 0.5)) / (color * (6.2 * color + 1.7) + 0.06), vec3(2.2));\n }\n\n vec3 ACESFilmicToneMapping(vec3 color) {\n color *= exposure;\n return saturate((color * (2.51 * color + 0.03)) / (color * (2.43 * color + 0.59) + 0.14));\n }\n\n in vec2 tc;\n\n layout(location = 0) out vec4 fragColor;\n \n void main(void) {\n vec4 hdrColor = texture(hdrBuffer, tc).rgba;\n \n float oneByGamma = gamma / gamma;\n float oneByWhitePoint = whitepoint / whitepoint;\n vec3 mapped = ReinhardToneMapping2(hdrColor.rgb) * oneByGamma * oneByWhitePoint;\n //vec3 mapped = ACESFilmicToneMapping(hdrColor.rgb) * oneByGamma * oneByWhitePoint;\n\n mapped = pow(mapped, vec3(1.0 / gamma));\n \n fragColor = vec4(mapped, hdrColor.a);\n }"})]),this.handler.addPrograms([new Ni("depth",{uniforms:{depthTexture:"sampler2D"},attributes:{corners:"vec2"},vertexShader:"#version 300 es\n \n in vec2 corners;\n \n out vec2 tc;\n\n void main(void) {\n gl_Position = vec4(corners, 0.0, 1.0);\n tc = corners * 0.5 + 0.5;\n }",fragmentShader:"#version 300 es\n\n precision highp float;\n\n uniform sampler2D depthTexture;\n \n in vec2 tc;\n\n layout(location = 0) out vec4 fragColor;\n\n float LinearizeDepth(in vec2 uv)\n {\n return texture(depthTexture, tc).r;\n }\n \n void main(void) {\n float c = LinearizeDepth(tc);\n fragColor = vec4(c, c, c, 1.0);\n }"})]),this.sceneFramebuffer=new Al(this.handler,{size:1,msaa:this._msaa,internalFormat:this._internalFormat,filter:"LINEAR"}),this.sceneFramebuffer.init(),this.blitFramebuffer=new Yo(this.handler,{size:1,useDepth:!1,targets:[{internalFormat:this._internalFormat,format:this._format,type:this._type,filter:"NEAREST"}]}),this.blitFramebuffer.init(),this.toneMappingFramebuffer=new Yo(this.handler,{useDepth:!1}),this.toneMappingFramebuffer.init(),this._fnScreenFrame=this._screenFrameMSAA,this.screenTexture={screen:this.toneMappingFramebuffer.textures[0],picking:this.pickingFramebuffer.textures[0],depth:this.screenDepthFramebuffer.textures[0],frustum:this.depthFramebuffer.textures[0]}}this.handler.ONCANVASRESIZE=()=>{this._resizeStart(),this.events.dispatch(this.events.resize,this.handler.canvas),this._resizeEnd(),this.events.dispatch(this.events.resizeend,this.handler.canvas)},this.screenFramePositionBuffer=this.handler.createArrayBuffer(new Float32Array([1,1,-1,1,1,-1,-1,-1]),2,4),this.outputTexture=this.screenTexture.screen,this._initializeRenderNodes(),this._initializeControls()}}_initializeControls(){let e=this.controls;this.controls={};for(let t in e)this.addControl(e[t])}resize(){this._resizeEnd()}setCurrentScreen(e){this._currentOutput=e,this.screenTexture[e]&&(this.outputTexture=this.screenTexture[e])}_resizeStart(){let e=this.handler.canvas;this.activeCamera.setAspectRatio(e.width/e.height),this.sceneFramebuffer.setSize(.5*e.width,.5*e.height),this.blitFramebuffer&&this.blitFramebuffer.setSize(.5*e.width,.5*e.height,!0)}_resizeEnd(){let e=this.handler.canvas;this.activeCamera.setAspectRatio(e.width/e.height),this.sceneFramebuffer.setSize(e.width,e.height),this.blitFramebuffer&&this.blitFramebuffer.setSize(e.width,e.height,!0),this.toneMappingFramebuffer&&this.toneMappingFramebuffer.setSize(e.width,e.height,!0),this.screenDepthFramebuffer&&this.screenDepthFramebuffer.setSize(e.clientWidth,e.clientHeight,!0),"webgl"===this.handler.gl.type?(this.screenTexture.screen=this.sceneFramebuffer.textures[0],this.screenTexture.picking=this.pickingFramebuffer.textures[0],this.screenTexture.depth=this.screenDepthFramebuffer.textures[0],this.screenTexture.frustum=this.depthFramebuffer.textures[0]):(this.screenTexture.screen=this.toneMappingFramebuffer.textures[0],this.screenTexture.picking=this.pickingFramebuffer.textures[0],this.screenTexture.depth=this.screenDepthFramebuffer.textures[0],this.screenTexture.frustum=this.depthFramebuffer.textures[0]),this.setCurrentScreen(this._currentOutput)}removeNode(e){e.remove()}addNode(e){this.renderNodes[e.name]?Bi.logWrn(`Node name ${e.name} already exists.`):(e.assign(this),this._renderNodesArr.unshift(e),this.renderNodes[e.name]=e)}_initializeRenderNodes(){for(let e=0;e<this._renderNodesArr.length;e++)this._renderNodesArr[e].initialize()}addNodeBefore(e,t){if(this.renderNodes[e.name])Bi.logWrn(`Node name ${e.name} already exists.`);else{e.assign(this),this.renderNodes[e.name]=e;for(let i=0;i<this._renderNodesArr.length;i++)if(this._renderNodesArr[i].isEqual(t)){this._renderNodesArr.splice(i,0,e);break}this._renderNodesArr.unshift(e)}}addNodes(e){for(let t=0;t<e.length;t++)this.addNode(e[t])}getMaxMSAA(e){let t=this.handler.gl;return t.getInternalformatParameter(t.RENDERBUFFER,t[e],t.SAMPLES)[0]}getMSAA(){return this._msaa}enqueueEntityCollectionsToDraw(e,t=0){this._entityCollections[t]||(this._entityCollections[t]=[]),this._entityCollections[t].push(...e)}_drawEntityCollections(e){let t=this._entityCollections[e];if(t.length){let e=this.handler.gl;this.enableBlendDefault();let i=t.length;for(;i--;)t[i]._fadingOpacity&&t[i].pointCloudHandler.draw();for(i=t.length;i--;){let e=t[i];t[i]._fadingOpacity&&(e.events.dispatch(e.events.draw,e),t[i].geoObjectHandler.draw())}for(e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.billboardsTextureAtlas.texture),i=t.length;i--;){let e=t[i];e._fadingOpacity&&e.billboardHandler.draw()}let s=this.fontAtlas.atlasesArr;for(i=0;i<s.length;i++)e.activeTexture(e.TEXTURE0+i),e.bindTexture(e.TEXTURE_2D,s[i].texture);for(i=t.length;i--;)t[i]._fadingOpacity&&t[i].labelHandler.draw();for(i=t.length;i--;)t[i]._fadingOpacity&&t[i].rayHandler.draw();for(i=t.length;i--;)t[i]._fadingOpacity&&t[i].polylineHandler.draw();for(i=t.length;i--;)t[i]._fadingOpacity&&t[i].stripHandler.draw()}}_drawPickingEntityCollections(e){let t=this._entityCollections[e];if(t.length){let e=t.length;for(;e--;)t[e]._fadingOpacity&&t[e].billboardHandler.drawPicking();for(e=t.length;e--;)t[e]._fadingOpacity&&t[e].geoObjectHandler.drawPicking();for(e=t.length;e--;)t[e]._fadingOpacity&&t[e].labelHandler.drawPicking();for(e=t.length;e--;)t[e]._fadingOpacity&&t[e].rayHandler.drawPicking();for(e=t.length;e--;)t[e]._visibility&&t[e].polylineHandler.drawPicking();for(e=t.length;e--;)t[e]._visibility&&t[e].stripHandler.drawPicking()}}_drawDepthEntityCollections(e){let t=this._entityCollections[e];if(t.length){let e=t.length;for(;e--;)t[e]._fadingOpacity&&t[e].geoObjectHandler.drawDepth()}}_clearEntityCollectionQueue(e){this._entityCollections[e].length=0,this._entityCollections[e]=[]}draw(){this.activeCamera.checkMoveEnd();let e=this.events;e.handleEvents();let t=this.sceneFramebuffer;t.activate();let i=this.handler.gl;i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),this.enableBlendDefault(),e.dispatch(e.draw,this);let s=this.activeCamera.frustums,n=e.pointerEvent(),r=!e.mouseState.leftButtonDown&&!e.mouseState.rightButtonDown,o=this._renderNodesArr,a=s.length;for(;a--;){this.activeCamera.setCurrentFrustum(a),i.clear(i.DEPTH_BUFFER_BIT);let t=o.length;for(;t--;)o[t].preDrawNode();for(t=o.length;t--;)this.enableBlendDefault(),o[t].drawNode();this._drawEntityCollections(0),e.dispatch(e.drawtransparent,this),n&&r&&this._drawPickingBuffer(0),this._drawDepthBuffer(0),this._clearEntityCollectionQueue(0)}for(let e=1;e<this._entityCollections.length;e++){i.clear(i.DEPTH_BUFFER_BIT);let t=s.length;for(;t--;)this.activeCamera.setCurrentFrustum(t),this._drawEntityCollections(e),n&&r&&this._drawPickingBuffer(e),this._drawDepthBuffer(e);this._clearEntityCollectionQueue(e)}t.deactivate(),this.blitFramebuffer&&t.blitTo(this.blitFramebuffer,0),n&&r&&this._readPickingBuffer(),r&&this._readDepthBuffer(),this._fnScreenFrame(),e.dispatch(e.postdraw,this),e.mouseState.wheelDelta=0,e.mouseState.justStopped=!1,e.mouseState.moving=!1,e.touchState.moving=!1}getImageDataURL(e="image/png",t=1){return this.draw(),this.handler.canvas?this.handler.canvas.toDataURL(e,t):""}_screenFrameMSAA(){let e=this.handler,t=e.programs.toneMapping,i=t._program,s=e.gl;s.disable(s.DEPTH_TEST),s.bindBuffer(s.ARRAY_BUFFER,this.screenFramePositionBuffer),s.vertexAttribPointer(i.attributes.corners,2,s.FLOAT,!1,0,0),this.toneMappingFramebuffer.activate(),t.activate(),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,this.blitFramebuffer.textures[0]),s.uniform1i(i.uniforms.hdrBuffer,0),s.uniform1f(i.uniforms.gamma,this.gamma),s.uniform1f(i.uniforms.exposure,this.exposure),s.uniform1f(i.uniforms.whitepoint,this.whitepoint),s.drawArrays(s.TRIANGLE_STRIP,0,4),this.toneMappingFramebuffer.deactivate(),t=e.programs.screenFrame,i=t._program,t.activate(),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,this.outputTexture),s.uniform1i(i.uniforms.texture,0),s.drawArrays(s.TRIANGLE_STRIP,0,4),s.enable(s.DEPTH_TEST)}_screenFrameNoMSAA(){let e=this.handler,t=e.programs.screenFrame,i=t._program,s=e.gl;s.disable(s.DEPTH_TEST),t.activate(),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,this.outputTexture),s.uniform1i(i.uniforms.texture,0),s.bindBuffer(s.ARRAY_BUFFER,this.screenFramePositionBuffer),s.vertexAttribPointer(i.attributes.corners,2,s.FLOAT,!1,0,0),s.drawArrays(s.TRIANGLE_STRIP,0,4),s.enable(s.DEPTH_TEST)}_drawPickingBuffer(e){this.pickingFramebuffer.activate();let t=this.handler.gl;if(this.activeCamera.isFirstPass&&0===e?(t.clearColor(0,0,0,1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT)):t.clear(t.DEPTH_BUFFER_BIT),t.disable(t.BLEND),0===e){let e=this._pickingCallbacks;for(let t=0,i=e.length;t<i;t++)e[t].callback.call(e[t].sender)}this._drawPickingEntityCollections(e),t.enable(t.BLEND),this.pickingFramebuffer.deactivate()}_drawDepthBuffer(e){this.depthFramebuffer.activate();let t=this.handler,i=t.gl;if(i.disable(i.BLEND),this.activeCamera.isFirstPass&&0===e?(i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT)):i.clear(i.DEPTH_BUFFER_BIT),0===e){let e=this._depthCallbacks,t=e.length;for(;t--;)e[t].callback.call(e[t].sender)}if(this._drawDepthEntityCollections(e),this.depthFramebuffer.deactivate(),"depth"===this._currentOutput||"frustum"===this._currentOutput){this.screenDepthFramebuffer.activate();let e=t.programs.depth,s=e._program;i.bindBuffer(i.ARRAY_BUFFER,this.screenFramePositionBuffer),i.vertexAttribPointer(s.attributes.corners,2,i.FLOAT,!1,0,0),e.activate(),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this.depthFramebuffer.textures[1]),i.uniform1i(s.uniforms.depthTexture,0),i.drawArrays(i.TRIANGLE_STRIP,0,4),this.screenDepthFramebuffer.deactivate(),i.enable(i.BLEND)}}_readDepthBuffer(){this.depthFramebuffer.readPixelBuffersAsync()}_readPickingBuffer_webgl1(){this.pickingFramebuffer.readPixelBuffersAsync()}_readPickingBuffer_webgl2(){this.pickingFramebuffer.readPixelBuffersAsync()}readPickingColor(e,t,i){let s=this.pickingFramebuffer.width,n=this.pickingFramebuffer.height;e=Math.round(e*s);let r=4*((t=Math.round(t*n))*s+e),o=this.pickingFramebuffer?.pixelBuffers[0].data;o&&(i[0]=o[r],i[1]=o[r+1],i[2]=o[r+2])}readDepth(e,t,i){let s=this.depthFramebuffer.width,n=this.depthFramebuffer.height;e=Math.round(e*s);let r=4*((t=Math.round(t*n))*s+e),o=this.depthFramebuffer?.pixelBuffers[1].data,a=this.depthFramebuffer?.pixelBuffers[0].data;o&&(i[0]=o[r],i[1]=Math.round(a[r]/10)-1)}getDistanceFromPixel(e,t){t=t||this.activeCamera;let i=this,s=i.handler.canvas,n=e.x/s.width,r=(s.height-e.y)/s.height;ql[0]=ql[1]=0;let o=0;if(i.readDepth(n,r,ql),-1===ql[1])return;let a=ql[0],l=t.frustums[ql[1]];if(!l)return;let h=new se(2*n-1,2*r-1,2*a-1,1),c=l.inverseProjectionMatrix.mulVec4(h),d=e.direction||i.activeCamera.unproject(e.x,e.y);return o=-c.z/c.w/d.dot(i.activeCamera.getForward()),o}getCartesianFromPixel(e){let t=this.getDistanceFromPixel(e);if(t){return(e.direction||this.activeCamera.unproject(e.x,e.y)).scaleTo(t).addA(this.activeCamera.eye)}}start(){this._initialized||this.initialize(),this.handler.start()}destroy(){for(let e in this.controls)this.controls[e].remove();for(let e=0;e<this._renderNodesArr.length;e++)this._renderNodesArr[e].remove();this.div=null,this._renderNodesArr=[],this.renderNodes={},this.activeCamera=null,this.controls={},this.controlsBag={},this.colorObjects.clear(),this.colorObjects=null,this._pickingCallbacks=[],this.pickingFramebuffer=null,this._tempPickingPix_=null,this._depthCallbacks=[],this.depthFramebuffer=null,this.sceneFramebuffer=null,this.blitFramebuffer=null,this.toneMappingFramebuffer=null,this._entityCollections=[[]],this.handler.ONCANVASRESIZE=null,this.handler.destroy(),this.handler=null,this._initialized=!1}}const Xl="/res";class Zl{constructor(e){this.$target=null,this._instanceID=`__globus${Zl.__counter__++?Zl.__counter__:""}__`,window[this._instanceID]=this,this._canvas=document.createElement("canvas"),this._canvas.id=`canvas${this._instanceID}`,this._canvas.style.width="100%",this._canvas.style.height="100%",this._canvas.style.display="block",this._canvas.style.opacity="0.0",this._canvas.style.transition="opacity 150ms",this.$inner=document.createElement("div"),this.$inner.classList.add("og-inner"),this.$inner.appendChild(this._canvas),this.$inner.attributions=document.createElement("div"),e.attributionContainer?e.attributionContainer.appendChild(this.$inner.attributions):(this.$inner.attributions.classList.add("og-attribution"),this.$inner.appendChild(this.$inner.attributions)),e.target&&this.attachTo(e.target);const t=e=>{e.preventDefault()};this._canvas.onmouseenter=function(){document.addEventListener("mousewheel",t,{capture:!1,passive:!1})},this._canvas.onmouseleave=function(){document.removeEventListener("mousewheel",t)},this.renderer=new $l(new Ll(this._canvas,{autoActivate:!1,pixelRatio:e.dpi||window.devicePixelRatio+.15,context:{antialias:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!1}}),{autoActivate:!1,msaa:e.msaa,fontsSrc:e.fontsSrc,gamma:e.gamma,exposure:e.exposure}),this.renderer.div=this.$inner,e.skybox&&this.renderer.addNode(e.skybox),this._planetName=e.name?e.name:"globus_planet_"+Zl.__counter__,this.planet=new qa({name:this._planetName,frustums:e.frustums,ellipsoid:e.ellipsoid,maxGridSize:e.maxGridSize,nightTextureSrc:null===e.nightTextureSrc?null:e.nightTextureSrc||`${e.resourcesSrc||Xl}/night.png`,specularTextureSrc:null===e.specularTextureSrc?null:e.specularTextureSrc||`${e.resourcesSrc||Xl}/spec.png`,minAltitude:e.minAltitude,maxAltitude:e.maxAltitude||15e6,maxEqualZoomAltitude:e.maxEqualZoomAltitude,minEqualZoomAltitude:e.minEqualZoomAltitude,minEqualZoomCameraSlope:e.minEqualZoomCameraSlope,quadTreeStrategyPrototype:e.quadTreeStrategyPrototype,maxLoadingRequests:e.maxLoadingRequests,atmosphereEnabled:e.atmosphereEnabled,transitionOpacityEnabled:e.transitionOpacityEnabled,atmosphereParameters:e.atmosphereParameters}),e.terrain?Array.isArray(e.terrain)?this.planet.setTerrain(e.terrain[0]):this.planet.setTerrain(e.terrain):this.planet.setTerrain(new Ka),this.renderer.addNode(this.planet),e.controls?this.planet.addControls(e.controls):this.planet.addControls([new nr,new zn,new sr,new xn,new Zn,new Ft]);const i=this.renderer.controls;let s;for(let e in i)if(i[e]instanceof tr){s=i[e];break}s?this.sun=s:(this.sun=new tr,this.planet.addControl(this.sun)),e.sun&&(void 0===e.sun.active||e.sun.active||this.sun.deactivate(),!0===e.sun.stopped&&this.sun.stop()),e.layers&&this.planet.addLayers(e.layers);let n=e.viewExtent;n&&(n instanceof Array?this.planet.viewExtentArr(n):this.planet.viewExtent(n)),(e.autoActivate||_e(e.autoActivate))&&this.start()}start(){this.renderer.start(),this.fadeIn()}fadeIn(){this._canvas.style.opacity="1.0"}fadeOut(){this._canvas.style.opacity="0"}attachTo(e,t){let i;this.detach(),i=e instanceof HTMLElement?e:document.getElementById(e)||document.querySelector(e),i?(this.$target=i,t&&this.$target.firstChild?this.$target.insertBefore(this.$inner,this.$target.firstChild):i.appendChild(this.$inner)):console.warn(`Target container not found. Provided target: ${e}`)}detach(){this.$target&&(this.$target.removeChild(this.$inner),this.$target=null)}destroy(){this.detach(),this.planet.layers.forEach((e=>e.remove())),this.planet.destroy(),this.renderer.destroy(),window[this._instanceID]=null}}Zl.__counter__=0;const Kl=new he(3396200,3389508),Ql=new he(1737400,1737400),Jl=`<div class="og-popup {className}">\n <div class="og-popup-content-wrapper">\n <div class="og-popup-content"></div>\n </div>\n <div class="og-popup-tip-container">\n <div class="og-popup-tip"></div>\n </div>\n <div class="og-popup-toolbar">\n <div class="og-popup-btn og-popup-close">${Nt}</div>\n </div>\n <div class="og-popup-title">{title}</div>\n </div>`,eh=["open","close"];const th=5/Math.pow(2,5);class ih extends Ea{constructor(e,t,i,s){super(e,t,i,s),this._projection=za,this.isPole=!1,this._tileGroup=0}_getMaxZoom(){let e=0;if(this._extent.northEast.lat>85){let t=Math.floor((90-this._extent.northEast.lat)/th);e=Math.floor(t/16)+5}else if(this._extent.southWest.lat<-85){let t=Math.floor((90+this._extent.southWest.lat)/th);e=Math.floor(t/16)+5}else e=50;return e}_assignTileYIndexes(e){const t=e.getCenter().lat;this.tileY=Qo(t,e.getHeight(),90),this.tileYN=this.tileY-1,this.tileYS=this.tileY+1}_assignTileXIndexes(e){let t=e.getCenter().lon;this.tileX=Qo(t,e.getWidth(),-180);let i=2*(1<<this.tileZoom);this.tileXE=(this.tileX+1)%i,this.tileXW=(i+this.tileX-1)%i}getDefaultTexture(){return this.planet.solidTextureOne}}class sh extends La{constructor(e,t,i,s,n,r){super(e,t,i,s,n,r),this.strategy=e}createChildNodes(){const e=this.strategy,t=this.extent,i=.5*t.getWidth(),s=.5*t.getHeight(),n=t.northEast,r=t.southWest,o=new I(r.lon+i,r.lat+s),a=this.childNodes,l=this.layer._planet,h=this.zoom+1;a[0]=new sh(e,0,this,new te(new I(r.lon,r.lat+s),new I(r.lon+i,n.lat)),l,h),a[1]=new sh(e,1,this,new te(o,new I(n.lon,n.lat)),l,h),a[2]=new sh(e,2,this,new te(new I(r.lon,r.lat),o),l,h),a[3]=new sh(e,3,this,new te(new I(r.lon+i,r.lat),new I(n.lon,r.lat+s)),l,h)}_setExtentBounds(){this.bsphere.setFromExtent(this.layer._planet.ellipsoid,this.extent)}__setLonLat__(e){return e._lonLat.isZero()&&(e._lonLat=this.layer._planet.ellipsoid.cartesianToLonLat(e._cartesian)),e._lonLat}isVisible(){return!!this.strategy._renderingNodesWest[this.nodeId]||!!this.strategy._renderingNodesEast[this.nodeId]}isInside(e){return this.extent.isInside(e._lonLat)}renderCollection(e,t,i){this.extent.southWest.lon<0?this.strategy._renderingNodesWest[this.nodeId]=!0:this.strategy._renderingNodesEast[this.nodeId]=!0,this.deferredEntities.length&&!this._inTheQueue&&(this.layer.async?this.strategy._queueDeferredNode(this):this.applyCollection());const s=this.entityCollection;s._fadingOpacity=this.layer._fadingOpacity,s.scaleByDistance=this.layer.scaleByDistance,s.pickingScale=this.layer.pickingScale,s.isEmpty()||e.push(s)}}class nh extends ba{constructor(e,t){super(e,t);let i=e._planet;this._entityCollectionsTreeWest=new sh(this,0,null,te.createFromArray([-180,-90,0,90]),i,0),this._entityCollectionsTreeEast=new sh(this,0,null,te.createFromArray([0,-90,180,90]),i,0),this._renderingNodesWest={},this._renderingNodesEast={}}insertEntity(e,t=!1){e._lonLat.lon<0?(this._entityCollectionsTreeWest.__setLonLat__(e),this._entityCollectionsTreeWest.insertEntity(e,t)):(this._entityCollectionsTreeEast.__setLonLat__(e),this._entityCollectionsTreeEast.insertEntity(e,t))}setPickingEnabled(e){this._entityCollectionsTreeWest.traverseTree((t=>{t.entityCollection.setPickingEnabled(e)})),this._entityCollectionsTreeEast.traverseTree((t=>{t.entityCollection.setPickingEnabled(e)}))}dispose(){this._entityCollectionsTreeWest=null,this._entityCollectionsTreeEast=null,this._renderingNodesWest={},this._renderingNodesEast={}}insertEntities(e){let t=[],i=[];for(let s=0,n=e.length;s<n;s++){let n=e[s];n._lonLat.lon<0?(t.push(n),this._entityCollectionsTreeWest.__setLonLat__(n)):(i.push(n),this._entityCollectionsTreeEast.__setLonLat__(n))}this._entityCollectionsTreeWest.buildTree(t),this._entityCollectionsTreeEast.buildTree(i)}collectVisibleEntityCollections(e){this._renderingNodesWest={},this._renderingNodesEast={};let t=this._layer._planet.quadTreeStrategy;this._secondPASS=[],this._entityCollectionsTreeWest.collectRenderCollectionsPASS1(t._visibleNodesWest,e);let i=this._secondPASS.length;for(;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodesWest,e,this._secondPASS[i].nodeId);for(this._secondPASS=[],this._entityCollectionsTreeEast.collectRenderCollectionsPASS1(t._visibleNodesEast,e),i=this._secondPASS.length;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodesEast,e,this._secondPASS[i].nodeId)}}class rh extends wa{constructor(e){super(e,"Mars",za),this._westExtent=te.createFromArray([-180,-90,0,90]),this._eastExtent=te.createFromArray([0,-90,180,90]),this._visibleNodesWest={},this._visibleNodesEast={}}init(){this._quadTreeList=[new ya(ih,this.planet,0,null,0,this._westExtent),new ya(ih,this.planet,0,null,0,this._eastExtent)]}getTileXY(e,t){let i=t,s=-1,n=-1,r=1<<i;return s=e.lon>0?Qo(e.lon,180/r,0)+r:Qo(e.lon,180/r,-180),n=Qo(e.lat,180/r,90),[s,n,i,0]}getLonLatTileOffset(e,t,i,s,n){let r=e,o=new te;o=e.lon>0?Jo(t-(1<<s),i,s,this._eastExtent):Jo(t,i,s,this._westExtent);let a=o.getWidth()/(n-1),l=o.getHeight()/(n-1);return[n-Math.ceil((r.lat-o.southWest.lat)/l)-1,Math.floor((r.lon-o.southWest.lon)/a)]}createEntitiCollectionsTreeStrategy(e,t){return new nh(e,t)}collectVisibleNode(e){e.segment.getExtent().southWest.lon<0?this._visibleNodesWest[e.nodeId]=e:this._visibleNodesEast[e.nodeId]=e}_clearVisibleNodes(){this._visibleNodesWest={},this._visibleNodesEast={}}}class oh extends wa{constructor(e){super(e,"wgs84",Ca)}init(){this._quadTreeList=[new ya(ih,this.planet,0,null,0,te.createFromArray([-180,-90,180,90]))]}}const ah={epsg4326:class extends wa{constructor(e){super(e,"EPSG4326",Ca)}init(){this._quadTreeList=[new ya(ih,this.planet,0,null,0,te.createFromArray([-180,-90,0,90])),new ya(ih,this.planet,0,null,0,te.createFromArray([0,-90,180,90]))]}},earth:Sa,equi:rh,wgs84:oh};e.ALIGN=xi,e.BilTerrain=sl,e.Billboard=oi,e.Bing=ml,e.Camera=Va,e.CanvasTiles=Kt,e.Clock=xl,e.Control=Dt,e.EarthQuadTreeStrategy=Sa,e.Ellipsoid=he,e.EmptyTerrain=Ka,e.Entity=Si,e.EntityCollection=fs,e.EquiQuadTreeStrategy=rh,e.Events=Rt,e.Extent=te,e.Framebuffer=Yo,e.GeoImage=dl,e.GeoObject=yi,e.GeoTexture2d=_l,e.GeoVideo=ul,e.Geoid=Ma,e.Geometry=hi,e.Globe=Zl,e.GlobusRgbTerrain=hl,e.GlobusTerrain=Qa,e.Handler=Ll,e.KML=gl,e.LAYER_EVENTS=Xt,e.LOCAL_FORWARD=vi,e.Label=wi,e.Layer=$t,e.LightSource=er,e.Line2=ci,e.Line3=di,e.LonLat=I,e.Mat3=ie,e.Mat4=ne,e.Material=qt,e.MoveAxisEntity=to,e.Multisample=Al,e.Object3d=mi,e.OpenStreetMap=fl,e.Plane=_i,e.Planet=qa,e.PlanetCamera=Ua,e.PointCloud=Ci,e.Polyline=Ti,e.Popup=class extends kt{constructor(e){super({template:we(Jl,{title:e.title||""}),classList:e.className?[e.className]:[],...e}),this.events=this.events.registerNames(eh),this._content=e.content||"",this.$content=null,this.$tip=null,this.$title=null,this._planet=e.planet,this._offset=e.offset||[0,0],this._lonLat=Re(e.lonLat),this._cartPos=new oe,this._visibility=e.visibility||!1,this.render()}_updatePosition(){this.setCartesian3v(this._cartPos)}setScreen(e){if(this._planet){let t=this._planet.renderer.handler.pixelRatio;this.el.style.transform=`translate(${e.x/t-.5*this.clientWidth}px, ${e.y/t-this._planet.renderer.handler.canvas.clientHeight-this.$tip.clientHeight}px)`}}get clientWidth(){return this.el?this.el.clientWidth:0}get clientHeight(){return this.el?this.el.clientHeight:0}setOffset(e=0,t=0){return this._offset[0]=e,this._offset[1]=t,this.el&&(this.el.style.left=`${e}px`,this.el.style.bottom=`${t}px`),this}render(e){return super.render(e),this.$content=this.select(".og-popup-content"),this.$title=this.select(".og-popup-title"),this.$tip=this.select(".og-popup-tip-container"),this.setOffset(this._offset[0],this._offset[1]),this.setContent(this._content),this.setLonLat(this._lonLat),this.setVisibility(this._visibility),this.select(".og-popup-close").addEventListener("click",(()=>{this.hide()})),this}setVisibility(e){return e?this.show():this.hide(),this}getContainer(){return this.$content}getToolbarContainer(){return this.select(".og-popup-toolbar")}show(){return this._visibility=!0,this._planet&&(this._planet.events.on("draw",this._updatePosition,this),this.appendTo(this._planet.renderer.div),this.events.dispatch(this.events.open,this)),this}hide(){return this._visibility=!1,this.el&&this.el.parentNode&&(this._planet.events.off("draw",this._updatePosition),this.el.parentNode.removeChild(this.el),this.events.dispatch(this.events.close,this)),this}setCartesian3v(e,t=0){if(this._cartPos=e,this._planet){let i=this._planet.camera,s=this._planet.ellipsoid.equatorialSize+t,n=i._lonLat.height,r=e.sub(i.eye);Math.sqrt((s+n)*(s+n)-s*s)>r.length()&&i.getForward().dot(r.normalize())>0?(this.el.style.display="block",this.setScreen(i.project3v(e))):this.el.style.display="none"}return this}setTitle(e){this.$title&&(this.$title.innerHTML=e)}setLonLat(e){this._lonLat=e,this._planet&&this.setCartesian3v(this._planet.ellipsoid.lonLatToCartesian(e),e.height)}setContent(e){e&&(this.clear(),this._content=e,this.$content&&("string"==typeof e?this.$content.innerHTML=e:this.$content.appendChild(e)))}clear(){this._content=null,this.$content&&(this.$content.innerHTML="")}},e.Program=Ni,e.QuadTreeStrategy=wa,e.Quat=re,e.Ray=ui,e.RenderNode=Ri,e.Renderer=$l,e.RgbTerrain=nl,e.Strip=Pi,e.Vec2=ae,e.Vec3=oe,e.Vec4=se,e.Vector=qs,e.WMS=il,e.Wgs84QuadTreeStrategy=oh,e.XYZ=el,e.bv=St,e.control=wo,e.input=Cn,e.jd=Lt,e.layer=vl,e.mars=Kl,e.math=P,e.mercator=ee,e.moon=Ql,e.quadTreeStrategyType=ah,e.scene=Za,e.terrain=cl,e.utils=et,e.webgl=Pl,e.wgs84=ce}));
|
|
1
|
+
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).og={})}(this,(function(e){"use strict";const t=2*Math.PI,i=Math.PI/2,s=Number.MAX_VALUE||17976931348623157e292,n=Math.log(2),r=2147483647,o=549755748352,a=-o,l=Math.PI/180,h=180/Math.PI,c=2*h,d=.5*l,_=Math.sqrt(.5),u=1e-5,g=1e-10,f=1e-12,p=1e-14;function m(e,t,i){return Math.max(t,Math.min(e,i))}function v(e){return!(e&e-1)}function y(e,t=4096){--e;for(let t=1;t<32;t<<=1)e|=e>>t;return e+1>t?t:e+1}function x(e=0,t=1){return Math.floor(Math.random()*(t-e))+e}function b(e,t){return(e%t+t)%t}function w(e){const i=b(e,t);return Math.abs(i)<p&&Math.abs(e)>p?t:i}function C(e){const t=Math.abs(e);return t-Math.floor(t)}function T(e,t,i){return i+e*(t-i)}function E(e){return e*e*e}function L(e){return e*e}function A(e){return e-360*Math.floor(e/360)}var P=Object.freeze({__proto__:null,ARCSECONDS_TO_RADIANS:484813681109536e-20,DEG2RAD:function(e){return e*l},DEGREES:h,DEGREES_DOUBLE:c,DEGREES_TO_HOURS:1/15,EPS1:.1,EPS10:g,EPS11:1e-11,EPS12:f,EPS13:1e-13,EPS14:p,EPS15:1e-15,EPS16:1e-16,EPS17:1e-17,EPS18:1e-18,EPS19:1e-19,EPS2:.01,EPS20:1e-20,EPS3:.001,EPS4:1e-4,EPS5:u,EPS6:1e-6,EPS7:1e-7,EPS8:1e-8,EPS9:1e-9,HOURS_TO_DEGREES:15,HOURS_TO_RADIANS:.26179938779914946,LOG2:n,MAX:o,MAX32:r,MAX_FLOAT:s,MIN:a,PI_TWO:i,RAD2DEG:function(e){return e*h},RADIANS:l,RADIANS_HALF:d,RADIANS_TO_HOURS:3.819718634205488,SQRT_HALF:_,TWO_PI:t,W:3,X:0,Y:1,Z:2,bezier1v:function(e,t,i,s,n){return E(1-e)*t+3*L(1-e)*e*i+3*(1-e)*L(e)*s+E(e)*n},bezier3v:function(e,t,i,s,n){let r=1-e,o=e*e,a=r*r,l=a*r,h=o*e;return t.scaleTo(l).addA(i.scaleTo(3*a*e)).addA(s.scaleTo(3*r*o)).addA(n.scaleTo(h))},clamp:m,cube:E,degToDec:function(e,t,i,s){return s?e+t/60+i/3600:-e-t/60-i/3600},exp2:function(e){return Math.pow(2,e)},frac:C,getAngleBetweenAzimuths:function(e,t){return(((e=w(e))-(t=w(t)))%360+360+180)%360-180},isPowerOfTwo:v,lerp:T,log:function(e,t){return Math.log(e)/Math.log(t)},log2:function(e){return Math.log(e)/n},mod:b,negativePItoPI:function(e){return w(e+Math.PI)-Math.PI},nextHighestPowerOfTwo:y,norm_lon:function(e){return e>180?(e+180)%360-180:e<-180?(e-180)%360+180:e},pow2i:function(e){return 2<<e-1},random:function(e=0,t=1){return Math.random()*(t-e)+e},randomi:x,rev:A,slice:function(e,t,i){return e*(t-i)},solve_iteration:function(e,t,i,s=50){let n=0,r=t;for(let t=0;t<s;t++)if(n=r,r=e(n),Math.abs(r-n)<i)return r;return r},solve_iteration_fixed:function(e,t,i){let s=0,n=t;for(let t=0;t<i;t++)s=n,n=e(s);return n},square:L,step:function(e,t){return t<e?0:1},zeroTwoPI:w});const S=.5*Math.PI,M=180/Math.PI,R=2*M,B=Math.PI/360,k=M*S;class I{constructor(e=0,t=0,i=0){this.lon=0,this.lat=0,this.height=0,this.lon=e,this.lat=t,this.height=i}isZero(){return 0===this.lon&&0===this.lat&&0===this.height}static join(e){let t=[];for(let i=0;i<e.length;i++){let s=e[i];t[i]=new I(s[0],s[1],s[2])}return t}static createFromArray(e){return new I(e[0],e[1],e[2])}static toArray(e){return[e.lon,e.lat,e.height]}toArray(){return I.toArray(this)}static forwardMercator(e,t,i){return new I(e*O,Math.log(Math.tan((90+t)*B))*N,i)}static forwardMercatorRes(e,t){return t.lon=e.lon*O,t.lat=Math.log(Math.tan((90+e.lat)*B))*N,t.height=e.height,t}static inverseMercator(e,t,i=0){return new I(e*V,R*Math.atan(Math.exp(t*F))-k,i)}set(e=0,t=0,i=0){return this.lon=e,this.lat=t,this.height=i,this}copy(e){return this.lon=e.lon,this.lat=e.lat,this.height=e.height,this}clone(){return new I(this.lon,this.lat,this.height)}forwardMercator(){return I.forwardMercator(this.lon,this.lat,this.height)}forwardMercatorEPS01(){let e=this.lat;return e>89.9?e=89.9:e<-89.9&&(e=-89.9),new I(this.lon*O,Math.log(Math.tan((90+e)*B))*N)}inverseMercator(){return I.inverseMercator(this.lon,this.lat,this.height)}equal(e){return e.height?this.lon===e.lon&&this.lat===e.lat&&this.height===e.height:this.lon===e.lon&&this.lat===e.lat}}const z=20037508.34,D=2*z,F=Math.PI/z,N=z/Math.PI,H=.5*Math.PI,O=z/180,V=180/z,U=Math.PI/360,G=Math.PI/180,Y=180/Math.PI,j=2*z,W=1/j;function q(e){return new I(e.lon*z/180,Math.log(Math.tan((90+e.lat)*U))*N,e.height)}function $(e){return e*z/180}function X(e){return Math.log(Math.tan((90+e)*U))*N}function Z(e){return Y*(2*Math.atan(Math.exp(e*F))-H)}function K(e,t,i){let s=D/(1<<i),n=new I(e*s-z,z-t*s-s);return new te(n,new I(n.lon+s,n.lat+s))}const Q=Z(z),J=-Q;var ee=Object.freeze({__proto__:null,INV_POLE_BY_180:V,MAX_LAT:Q,MIN_LAT:J,ONE_BY_POLE_DOUBLE:W,PI_BY_POLE:F,POLE:z,POLE2:D,POLE_BY_180:O,POLE_BY_PI:N,POLE_DOUBLE:j,forward:q,forwardArray:function(e){let t=[];for(let i=0;i<e.length;i++)t.push(e[i].forwardMercator());return t},forward_lat:X,forward_lon:$,getTileExtent:K,getTileX:function(e,t){return Math.floor((e+180)/360*Math.pow(2,t))},getTileY:function(e,t){return Math.floor(.5*(1-Math.log(Math.tan(e*G)+1/Math.cos(e*G))/Math.PI)*Math.pow(2,t))},inverse_lat:Z,inverse_lon:function(e){return 180*e/z}});class te{constructor(e=new I,t=new I){this.southWest=e,this.northEast=t}static createFromArray(e){return new te(new I(e[0],e[1]),new I(e[2],e[3]))}static createByCoordinates(e){let t=o,i=a,s=o,n=a;for(let r=0;r<e.length;r++){const o=e[r];o.lon<t&&(t=o.lon),o.lon>i&&(i=o.lon),o.lat<s&&(s=o.lat),o.lat>n&&(n=o.lat)}return new te(new I(t,s),new I(i,n))}static createByCoordinatesArr(e){let t=o,i=a,s=o,n=a;for(let r=0;r<e.length;r++){const o=e[r];o[0]<t&&(t=o[0]),o[0]>i&&(i=o[0]),o[1]<s&&(s=o[1]),o[1]>n&&(n=o[1])}return new te(new I(t,s),new I(i,n))}static fromTile(e,t,i,s=j,n=j){const r=1<<i,o=s/r,a=n/r,l=.5*-s+e*o,h=.5*n-t*a,c=l+o;return new te(new I(l,h-a),new I(c,h))}setByCoordinates(e){let t=o,i=a,s=o,n=a;for(let r=0;r<e.length;r++){const o=e[r];o.lon<t&&(t=o.lon),o.lon>i&&(i=o.lon),o.lat<s&&(s=o.lat),o.lat>n&&(n=o.lat)}return this.southWest.lon=t,this.southWest.lat=s,this.northEast.lon=i,this.northEast.lat=n,this}isInside(e){const t=this.southWest,i=this.northEast;return e.lon>=t.lon&&e.lon<=i.lon&&e.lat>=t.lat&&e.lat<=i.lat}overlaps(e){const t=this.southWest,i=this.northEast;return t.lon<=e.northEast.lon&&i.lon>=e.southWest.lon&&t.lat<=e.northEast.lat&&i.lat>=e.southWest.lat}getWidth(){return this.northEast.lon-this.southWest.lon}getHeight(){return this.northEast.lat-this.southWest.lat}clone(){return new te(this.southWest.clone(),this.northEast.clone())}getCenter(){const e=this.southWest,t=this.northEast;return new I(e.lon+.5*(t.lon-e.lon),e.lat+.5*(t.lat-e.lat))}getNorthWest(){return new I(this.southWest.lon,this.northEast.lat)}getNorthEast(){return new I(this.northEast.lon,this.northEast.lat)}getSouthWest(){return new I(this.southWest.lon,this.southWest.lat)}getSouthEast(){return new I(this.northEast.lon,this.southWest.lat)}getNorth(){return this.northEast.lat}getEast(){return this.northEast.lon}getWest(){return this.southWest.lon}getSouth(){return this.southWest.lat}equals(e){return this.southWest.lon===e.southWest.lon&&this.southWest.lat===e.southWest.lat&&this.northEast.lon===e.northEast.lon&&this.northEast.lat===e.northEast.lat}forwardMercator(){return new te(this.southWest.forwardMercator(),this.northEast.forwardMercator())}inverseMercator(){return new te(this.southWest.inverseMercator(),this.northEast.inverseMercator())}getCartesianBounds(e){let t=o,i=a,s=o,n=a,r=o,l=a;const h=[new I(this.southWest.lon,this.southWest.lat),new I(this.southWest.lon,this.northEast.lat),new I(this.northEast.lon,this.northEast.lat),new I(this.northEast.lon,this.southWest.lat)];for(let o=0;o<h.length;o++){const a=e.lonLatToCartesian(h[o]),c=a.x,d=a.y,_=a.z;c<t&&(t=c),c>i&&(i=c),d<s&&(s=d),d>n&&(n=d),_<r&&(r=_),_>l&&(l=_)}return[t,s,r,i,n,l]}toString(){return`[${this.southWest.lon.toFixed(5)}, ${this.southWest.lat.toFixed(5)}, ${this.northEast.lon.toFixed(5)}, ${this.northEast.lat.toFixed(5)}]`}}class ie{constructor(){this._m=[0,0,0,0,0,0,0,0,0]}set(e){return this._m[0]=e[0],this._m[1]=e[1],this._m[2]=e[2],this._m[3]=e[3],this._m[4]=e[4],this._m[5]=e[5],this._m[6]=e[6],this._m[7]=e[7],this._m[8]=e[8],this}clone(){let e=new ie;return e.set(this._m),e}copy(e){return this.set(e._m)}transposeTo(){let e=new ie,t=this._m;return e._m[0]=t[0],e._m[1]=t[3],e._m[2]=t[6],e._m[3]=t[1],e._m[4]=t[4],e._m[5]=t[7],e._m[6]=t[2],e._m[7]=t[5],e._m[8]=t[8],e}setIdentity(){return this._m[0]=1,this._m[1]=0,this._m[2]=0,this._m[3]=0,this._m[4]=1,this._m[5]=0,this._m[6]=0,this._m[7]=0,this._m[8]=1,this}mulVec(e){let t=e.x,i=e.y,s=e.z,n=this._m;return new oe(n[0]*t+n[3]*i+n[6]*s,n[1]*t+n[4]*i+n[7]*s,n[2]*t+n[5]*i+n[8]*s)}getMat4(){let e=new ne,t=e._m,i=this._m;return t[0]=i[0],t[1]=i[1],t[2]=i[2],t[3]=0,t[4]=i[3],t[5]=i[4],t[6]=i[5],t[7]=0,t[8]=i[6],t[9]=i[7],t[10]=i[8],t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,e}}class se{constructor(e=0,t=0,i=0,s=0){this.x=e,this.y=t,this.z=i,this.w=s}static get identity(){return new se(0,0,0,1)}static fromVec(e){return new se(e[0],e[1],e[2],e[3])}toVec3(){return new oe(this.x,this.y,this.z)}clone(){return new se(this.x,this.y,this.z,this.w)}equal(e){return this.x===e.x&&this.y===e.y&&this.z===e.z&&this.w===e.w}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this}toArray(){return[this.x,this.y,this.z,this.w]}toArray3(){return[this.x,this.y,this.z]}set(e,t,i,s){return this.x=e,this.y=t,this.z=i,this.w=s,this}addA(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this.w+=e.w,this}subA(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this.w-=e.w,this}scale(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}affinity(){let e=1/this.w;return this.x*=e,this.y*=e,this.z*=e,this.w=1,this}scaleTo(e){return new se(this.x*e,this.y*e,this.z*e,this.w*e)}getStep(e){return new se(this.x<e?0:1,this.y<e?0:1,this.z<e?0:1,this.w<e?0:1)}getFrac(e){return new se(C(e.x),C(e.y),C(e.z),C(e.w))}dot(e){return e.x*this.x+e.y*this.y+e.z*this.z+e.w*this.w}isZero(){return!(this.x||this.y||this.z||this.w)}}class ne{constructor(){this._m=[0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]}static identity(){let e=new ne;return e._m[0]=1,e._m[1]=0,e._m[2]=0,e._m[3]=0,e._m[4]=0,e._m[5]=1,e._m[6]=0,e._m[7]=0,e._m[8]=0,e._m[9]=0,e._m[10]=1,e._m[11]=0,e._m[12]=0,e._m[13]=0,e._m[14]=0,e._m[15]=1,e}static getRotationAroundPoint(e,t=oe.ZERO,i=oe.UP){let s=ne.getRotation(e,i),n=(new ne).setIdentity().translate(t),r=(new ne).setIdentity().translate(t.negateTo());return n.mul(s).mul(r)}static getRotation(e,t=oe.UP){return(new ne).setRotation(t,e)}set(e){return this._m[0]=e[0],this._m[1]=e[1],this._m[2]=e[2],this._m[3]=e[3],this._m[4]=e[4],this._m[5]=e[5],this._m[6]=e[6],this._m[7]=e[7],this._m[8]=e[8],this._m[9]=e[9],this._m[10]=e[10],this._m[11]=e[11],this._m[12]=e[12],this._m[13]=e[13],this._m[14]=e[14],this._m[15]=e[15],this}clone(){let e=new ne;return e.set(this._m),e}copy(e){return this.set(e._m)}getMat3(){let e=new ie,t=this._m,i=e._m;return i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[4],i[4]=t[5],i[5]=t[6],i[6]=t[8],i[7]=t[9],i[8]=t[10],e}mulVec3(e){let t=e.x,i=e.y,s=e.z;return new oe(this._m[0]*t+this._m[4]*i+this._m[8]*s+this._m[12],this._m[1]*t+this._m[5]*i+this._m[9]*s+this._m[13],this._m[2]*t+this._m[6]*i+this._m[10]*s+this._m[14])}mulVec4(e){let t=e.x,i=e.y,s=e.z,n=e.w;return new se(this._m[0]*t+this._m[4]*i+this._m[8]*s+this._m[12]*n,this._m[1]*t+this._m[5]*i+this._m[9]*s+this._m[13]*n,this._m[2]*t+this._m[6]*i+this._m[10]*s+this._m[14]*n,this._m[3]*t+this._m[7]*i+this._m[11]*s+this._m[15]*n)}toInverseMatrix3(){let e=this._m,t=e[0],i=e[1],s=e[2],n=e[4],r=e[5],o=e[6],a=e[8],l=e[9],h=e[10],c=h*r-o*l,d=-h*n+o*a,_=l*n-r*a,u=t*c+i*d+s*_;if(!u)return;u=1/u;let g=new ie;return g._m[0]=c*u,g._m[1]=(-h*i+s*l)*u,g._m[2]=(o*i-s*r)*u,g._m[3]=d*u,g._m[4]=(h*t-s*a)*u,g._m[5]=(-o*t+s*n)*u,g._m[6]=_*u,g._m[7]=(-l*t+i*a)*u,g._m[8]=(r*t-i*n)*u,g}inverseTo(e=new ne){let t=this._m[0],i=this._m[1],s=this._m[2],n=this._m[3],r=this._m[4],o=this._m[5],a=this._m[6],l=this._m[7],h=this._m[8],c=this._m[9],d=this._m[10],_=this._m[11],u=this._m[12],g=this._m[13],f=this._m[14],p=this._m[15],m=t*o-i*r,v=t*a-s*r,y=t*l-n*r,x=i*a-s*o,b=i*l-n*o,w=s*l-n*a,C=h*g-c*u,T=h*f-d*u,E=h*p-_*u,L=c*f-d*g,A=c*p-_*g,P=d*p-_*f,S=1/(m*P-v*A+y*L+x*E-b*T+w*C);return e._m[0]=(o*P-a*A+l*L)*S,e._m[1]=(-i*P+s*A-n*L)*S,e._m[2]=(g*w-f*b+p*x)*S,e._m[3]=(-c*w+d*b-_*x)*S,e._m[4]=(-r*P+a*E-l*T)*S,e._m[5]=(t*P-s*E+n*T)*S,e._m[6]=(-u*w+f*y-p*v)*S,e._m[7]=(h*w-d*y+_*v)*S,e._m[8]=(r*A-o*E+l*C)*S,e._m[9]=(-t*A+i*E-n*C)*S,e._m[10]=(u*b-g*y+p*m)*S,e._m[11]=(-h*b+c*y-_*m)*S,e._m[12]=(-r*L+o*T-a*C)*S,e._m[13]=(t*L-i*T+s*C)*S,e._m[14]=(-u*x+g*v-f*m)*S,e._m[15]=(h*x-c*v+d*m)*S,e}transposeTo(){let e=new ne;return e._m[0]=this._m[0],e._m[1]=this._m[4],e._m[2]=this._m[8],e._m[3]=this._m[12],e._m[4]=this._m[1],e._m[5]=this._m[5],e._m[6]=this._m[9],e._m[7]=this._m[13],e._m[8]=this._m[2],e._m[9]=this._m[6],e._m[10]=this._m[10],e._m[11]=this._m[14],e._m[12]=this._m[3],e._m[13]=this._m[7],e._m[14]=this._m[11],e._m[15]=this._m[15],e}setIdentity(){return this._m[0]=1,this._m[1]=0,this._m[2]=0,this._m[3]=0,this._m[4]=0,this._m[5]=1,this._m[6]=0,this._m[7]=0,this._m[8]=0,this._m[9]=0,this._m[10]=1,this._m[11]=0,this._m[12]=0,this._m[13]=0,this._m[14]=0,this._m[15]=1,this}mul(e){let t=this._m[0],i=this._m[1],s=this._m[2],n=this._m[3],r=this._m[4],o=this._m[5],a=this._m[6],l=this._m[7],h=this._m[8],c=this._m[9],d=this._m[10],_=this._m[11],u=this._m[12],g=this._m[13],f=this._m[14],p=this._m[15],m=e._m[0],v=e._m[1],y=e._m[2],x=e._m[3],b=e._m[4],w=e._m[5],C=e._m[6],T=e._m[7],E=e._m[8],L=e._m[9],A=e._m[10],P=e._m[11],S=e._m[12],M=e._m[13],R=e._m[14],B=e._m[15],k=new ne;return k._m[0]=m*t+v*r+y*h+x*u,k._m[1]=m*i+v*o+y*c+x*g,k._m[2]=m*s+v*a+y*d+x*f,k._m[3]=m*n+v*l+y*_+x*p,k._m[4]=b*t+w*r+C*h+T*u,k._m[5]=b*i+w*o+C*c+T*g,k._m[6]=b*s+w*a+C*d+T*f,k._m[7]=b*n+w*l+C*_+T*p,k._m[8]=E*t+L*r+A*h+P*u,k._m[9]=E*i+L*o+A*c+P*g,k._m[10]=E*s+L*a+A*d+P*f,k._m[11]=E*n+L*l+A*_+P*p,k._m[12]=S*t+M*r+R*h+B*u,k._m[13]=S*i+M*o+R*c+B*g,k._m[14]=S*s+M*a+R*d+B*f,k._m[15]=S*n+M*l+R*_+B*p,k}translate(e){let t=e.x,i=e.y,s=e.z,n=this._m;return n[12]=n[0]*t+n[4]*i+n[8]*s+n[12],n[13]=n[1]*t+n[5]*i+n[9]*s+n[13],n[14]=n[2]*t+n[6]*i+n[10]*s+n[14],n[15]=n[3]*t+n[7]*i+n[11]*s+n[15],this}translateToPosition(e){let t=this._m;return t[12]=e.x,t[13]=e.y,t[14]=e.z,this}rotate(e,t){let i=Math.cos(t),s=Math.sin(t),n=new ne,r=n._m;return r[0]=i+(1-i)*e.x*e.x,r[1]=(1-i)*e.y*e.x-s*e.z,r[2]=(1-i)*e.z*e.x+s*e.y,r[3]=0,r[4]=(1-i)*e.x*e.y+s*e.z,r[5]=i+(1-i)*e.y*e.y,r[6]=(1-i)*e.z*e.y-s*e.x,r[7]=0,r[8]=(1-i)*e.x*e.z-s*e.y,r[9]=(1-i)*e.y*e.z+s*e.x,r[10]=i+(1-i)*e.z*e.z,r[11]=0,r[12]=0,r[13]=0,r[14]=0,r[15]=1,this.mul(n)}setRotation(e,t){let i=Math.cos(t),s=Math.sin(t),n=this._m;return n[0]=i+(1-i)*e.x*e.x,n[1]=(1-i)*e.y*e.x-s*e.z,n[2]=(1-i)*e.z*e.x+s*e.y,n[3]=0,n[4]=(1-i)*e.x*e.y+s*e.z,n[5]=i+(1-i)*e.y*e.y,n[6]=(1-i)*e.z*e.y-s*e.x,n[7]=0,n[8]=(1-i)*e.x*e.z-s*e.y,n[9]=(1-i)*e.y*e.z+s*e.x,n[10]=i+(1-i)*e.z*e.z,n[11]=0,n[12]=0,n[13]=0,n[14]=0,n[15]=1,this}rotateBetweenVectors(e,t){return re.getRotationBetweenVectors(e,t).getMat4()}scale(e){let t=this._m;return t[0]=t[0]*e.x,t[1]=t[1]*e.x,t[2]=t[2]*e.x,t[3]=t[3]*e.x,t[4]=t[4]*e.y,t[5]=t[5]*e.y,t[6]=t[6]*e.y,t[7]=t[7]*e.y,t[8]=t[8]*e.z,t[9]=t[9]*e.z,t[10]=t[10]*e.z,t[11]=t[11]*e.z,this}setPerspective(e,t,i,s,n,r){let o=t-e,a=s-i,l=n-r,h=2*n,c=this._m;return c[0]=h/o,c[1]=0,c[2]=0,c[3]=0,c[4]=0,c[5]=h/a,c[6]=0,c[7]=0,c[8]=(t+e)/o,c[9]=(s+i)/a,c[10]=(r+n)/l,c[11]=-1,c[12]=0,c[13]=0,c[14]=h*r/l,c[15]=0,this}setOrtho(e,t,i,s,n,r){let o=1/(e-t),a=1/(i-s),l=1/(n-r),h=this._m;return h[0]=-2*o,h[1]=0,h[2]=0,h[3]=0,h[4]=0,h[5]=-2*a,h[6]=0,h[7]=0,h[8]=0,h[9]=0,h[10]=2*l,h[11]=0,h[12]=(e+t)*o,h[13]=(s+i)*a,h[14]=(r+n)*l,h[15]=1,this}eulerToMatrix(e,t,i){let s=Math.cos(e),n=Math.sin(e),r=Math.cos(t),o=Math.sin(t),a=Math.cos(i),l=Math.sin(i),h=s*o,c=n*o,d=this._m;return d[0]=r*a,d[1]=-r*l,d[2]=-o,d[4]=-c*a+s*l,d[5]=c*l+s*a,d[6]=-n*r,d[8]=h*a+n*l,d[9]=-h*l+n*a,d[10]=s*r,d[3]=d[7]=d[11]=d[12]=d[13]=d[14]=0,d[15]=1,this}}class re{constructor(e=0,t=0,i=0,s=0){this.x=e,this.y=t,this.z=i,this.w=s}static get IDENTITY(){return new re(0,0,0,1)}static xRotation(e){return e*=.5,new re(Math.sin(e),0,0,Math.cos(e))}static yRotation(e){return e*=.5,new re(0,Math.sin(e),0,Math.cos(e))}static zRotation(e){return e*=.5,new re(0,0,Math.sin(e),Math.cos(e))}static axisAngleToQuat(e,t=0){let i=e.getNormal(),s=.5*t,n=Math.sin(s);return new re(i.x*n,i.y*n,i.z*n,Math.cos(s))}static getLookRotation(e,t){let i=e.getNormal().negate(),s=t.cross(i).normalize(),n=i.cross(s),r=1+s.x+n.y+i.z;if(r>1e-6){let e=1/(2*Math.sqrt(r));return new re((i.y-n.z)*e,(s.z-i.x)*e,(n.x-s.y)*e,.25/e)}if(s.x>n.y&&s.x>i.z){let e=1/(2*Math.sqrt(1+s.x-n.y-i.z));return new re(.25/e,(n.x+s.y)*e,(s.z+i.x)*e,(i.y-n.z)*e)}if(n.y>i.z){let e=1/(2*Math.sqrt(1+n.y-s.x-i.z));return new re((n.x+s.y)*e,.25/e,(i.y+n.z)*e,(s.z-i.x)*e)}let o=1/(2*Math.sqrt(1+i.z-s.x-n.y));return new re((s.z+i.x)*o,(i.y+n.z)*o,.25/o,(n.x-s.y)*o)}static getLookAtSourceDest(e,t){let i=t.subA(e).normalize(),s=oe.FORWARD.dot(i);if(Math.abs(s- -1)<1e-6)return re.axisAngleToQuat(oe.UP,Math.PI);if(Math.abs(s-1)<1e-6)return new re(0,0,0,1);let n=Math.acos(s),r=oe.FORWARD.cross(i).normalize();return re.axisAngleToQuat(r,n)}static getRotationBetweenVectors(e,t){let i=e.cross(t);return new re(i.x,i.y,i.z,1+e.dot(t)).normalize()}static getRotationBetweenVectorsRes(e,t,i){let s=e.cross(t);return i.set(s.x,s.y,s.z,1+e.dot(t)),i.normalize()}static getRotationBetweenVectorsUp(e,t,i){let s=e.dot(t);if(Math.abs(s+1)<1e-6)return re.axisAngleToQuat(i,Math.PI);if(Math.abs(s-1)<1e-6)return new re(0,0,0,1);let n=Math.acos(s),r=e.cross(t).normalize();return re.axisAngleToQuat(r,n)}isZero(){return 0===this.x&&0===this.y&&0===this.z&&0===this.w}isNaN(){return isNaN(this.x)||isNaN(this.y)||isNaN(this.z)||isNaN(this.w)}clear(){return this.x=this.y=this.z=this.w=0,this}set(e,t,i,s){return this.x=e,this.y=t,this.z=i,this.w=s,this}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this.w=e.w,this}setIdentity(){return this.x=0,this.y=0,this.z=0,this.w=1,this}clone(){return new re(this.x,this.y,this.z,this.w)}add(e){return new re(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)}addRes(e,t){return t.set(this.x+e.x,this.y+e.y,this.z+e.z,this.w+e.w)}sub(e){return new re(this.x-e.x,this.y-e.y,this.z-e.z,this.w-e.w)}scaleTo(e){return new re(this.x*e,this.y*e,this.z*e,this.w*e)}scale(e){return this.x*=e,this.y*=e,this.z*=e,this.w*=e,this}toVec(){return[this.x,this.y,this.z,this.w]}get xyz(){return new oe(this.x,this.y,this.z)}setLookRotation(e,t){let i=e.getNormal().negate(),s=t.cross(i).normalize(),n=i.cross(s),r=1+s.x+n.y+i.z;if(r>1e-6){let e=1/(2*Math.sqrt(r));this.x=(i.y-n.z)*e,this.y=(s.z-i.x)*e,this.z=(n.x-s.y)*e,this.w=.25/e}else if(s.x>n.y&&s.x>i.z){let e=1/(2*Math.sqrt(1+s.x-n.y-i.z));this.x=.25/e,this.y=(n.x+s.y)*e,this.z=(s.z+i.x)*e,this.w=(i.y-n.z)*e}else if(n.y>i.z){let e=1/(2*Math.sqrt(1+n.y-s.x-i.z));this.x=(n.x+s.y)*e,this.y=.25/e,this.z=(i.y+n.z)*e,this.w=(s.z-i.x)*e}else{let e=1/(2*Math.sqrt(1+i.z-s.x-n.y));this.x=(s.z+i.x)*e,this.y=(i.y+n.z)*e,this.z=.25/e,this.w=(n.x-s.y)*e}return this}setFromSphericalCoords(e,t,i){let s=Math.sin(i/2),n=Math.cos(i/2),r=Math.sin(e),o=Math.cos(e),a=Math.sin(t),l=Math.cos(t);return this.x=s*o*a,this.y=s*r,this.z=s*r*l,this.w=n,this}getSphericalCoords(){let e=this.w,t=Math.sqrt(1-e*e);Math.abs(t)<5e-4&&(t=1);let i,s=this.x/t,n=this.y/t,r=this.z/t,o=-Math.asin(n);return i=s*s+r*r<5e-4?0:Math.atan2(s,r),i<0&&(i+=360),{lat:o,lon:i,alpha:Math.acos(e)}}setFromAxisAngle(e,t){let i=e.getNormal(),s=.5*t,n=Math.sin(s);return this.set(i.x*n,i.y*n,i.z*n,Math.cos(s)),this}getAxisAngle(){let e,t,i=this.x,s=this.y,n=this.z,r=this.w,o=Math.sqrt(i*i+s*s+n*n);if(o>1e-7){let a=1/o;e=new oe(i*a,s*a,n*a),t=r<0?2*Math.atan2(-o,-r):2*Math.atan2(o,r)}else e=new oe(0,0,0),t=0;return{axis:e,angle:t}}getPitch(){let e=-2*(this.y*this.z-this.w*this.x);return Math.abs(e)>=1?Math.sign(e)*i:Math.asin(e)}getYaw(){return-Math.atan2(2*(this.x*this.z+this.w*this.y),1-2*(this.y*this.y+this.x*this.x))}getRoll(){return Math.atan2(2*(this.x*this.y+this.w*this.z),1-2*(this.z*this.z+this.x*this.x))}setPitchYawRoll(e,t,i,s=re.IDENTITY){let n=re.xRotation(-e),r=re.yRotation(t),o=re.zRotation(-i);return this.copy(o.mul(n).mul(r).mul(s).conjugate())}setFromEulerAngles(e,t,i){let s=e*d,n=t*d,r=i*d,o=Math.cos(s),a=Math.cos(n),l=Math.cos(r),h=Math.sin(s),c=Math.sin(n),_=Math.sin(r),u=a*l,g=c*_;return this.w=o*u+h*g,this.x=h*u-o*g,this.y=o*c*l+h*a*_,this.z=o*a*_-h*c*l,this.normalize()}getEulerAngles(){let e=this.x,t=this.y,i=this.z,s=this.w,n=t*t,r=s*t-i*e;return r<-1?r=-1:r>1&&(r=1),{roll:Math.atan2(2*(s*e+t*i),1-2*(e*e+n)),pitch:Math.asin(2*r),yaw:Math.atan2(2*(s*i+e*t),1-2*(n+i*i))}}setFromMatrix4(e){let t,i,s,n,r,o=[],a=e._m,l=[1,2,0];return t=a[0]+a[5]+a[10],t>0?(i=Math.sqrt(t+1),this.w=i/2,i=.5/i,this.x=(a[6]-a[9])*i,this.y=(a[8]-a[2])*i,this.z=(a[1]-a[4])*i):(s=0,a[5]>a[0]&&(s=1),a[10]>a[5*s]&&(s=2),n=l[s],r=l[n],i=Math.sqrt(a[5*s]-(a[5*n]+a[5*r])+1),o[s]=.5*i,0!==i&&(i=.5/i),o[3]=(a[4*n+r]-a[4*r+n])*i,o[n]=(a[4*s+n]+a[4*n+s])*i,o[r]=(a[4*s+r]+a[4*r+s])*i,this.x=o[0],this.y=o[1],this.z=o[2],this.w=o[3]),this}getMat4(e=new ne){let t=this.x+this.x,i=this.y+this.y,s=this.z+this.z,n=this.w*t,r=this.w*i,o=this.w*s,a=this.x*t,l=this.x*i,h=this.x*s,c=this.y*i,d=this.y*s,_=this.z*s;return e.set([1-(c+_),l-o,h+r,0,l+o,1-(a+_),d-n,0,h-r,d+n,1-(a+c),0,0,0,0,1])}getMat3(){let e=new ie,t=e._m,i=this.x,s=this.y,n=this.z,r=this.w,o=i+i,a=s+s,l=n+n,h=i*o,c=i*a;i*=l;let d=s*a;return s*=l,n*=l,o*=r,a*=r,r*=l,t[0]=1-(d+n),t[1]=c-r,t[2]=i+a,t[3]=c+r,t[4]=1-(h+n),t[5]=s-o,t[6]=i-a,t[7]=s+o,t[8]=1-(h+d),e}mulVec3(e){let t=e.x,i=e.y,s=e.z,n=this.x,r=this.y,o=this.z,a=this.w,l=a*t+r*s-o*i,h=a*i+o*t-n*s,c=a*s+n*i-r*t;return t=-n*t-r*i-o*s,new oe(l*a+t*-n+h*-o-c*-r,h*a+t*-r+c*-n-l*-o,c*a+t*-o+l*-r-h*-n)}mulVec3Res(e,t){let i=e.x,s=e.y,n=e.z,r=this.x,o=this.y,a=this.z,l=this.w,h=l*i+o*n-a*s,c=l*s+a*i-r*n,d=l*n+r*s-o*i;return i=-r*i-o*s-a*n,t.set(h*l+i*-r+c*-a-d*-o,c*l+i*-o+d*-r-h*-a,d*l+i*-a+h*-o-c*-r)}mul(e){let t=this.x,i=this.y,s=this.z,n=this.w,r=e.x,o=e.y,a=e.z,l=e.w;return new re(t*l+n*r+i*a-s*o,i*l+n*o+s*r-t*a,s*l+n*a+t*o-i*r,n*l-t*r-i*o-s*a)}mulRes(e,t){let i=this.x,s=this.y,n=this.z,r=this.w,o=e.x,a=e.y,l=e.z,h=e.w;return t.set(i*h+r*o+s*l-n*a,s*h+r*a+n*o-i*l,n*h+r*l+i*a-s*o,r*h-i*o-s*a-n*l)}mulA(e){let t=this.x,i=this.y,s=this.z,n=this.w,r=e.x,o=e.y,a=e.z,l=e.w;return this.x=t*l+n*r+i*a-s*o,this.y=i*l+n*o+s*r-t*a,this.z=s*l+n*a+t*o-i*r,this.w=n*l-t*r-i*o-s*a,this}conjugate(){return new re(-this.x,-this.y,-this.z,this.w)}inverse(){let e=1/this.magnitude2();return new re(-this.x*e,-this.y*e,-this.z*e,this.w*e)}magnitude(){let e=this.x,t=this.y,i=this.z,s=this.w;return Math.sqrt(e*e+t*t+i*i+s*s)}magnitude2(){let e=this.x,t=this.y,i=this.z,s=this.w;return e*e+t*t+i*i+s*s}dot(e){return this.x*e.x+this.y*e.y+this.z*e.z}normalize(){let e=this.x,t=this.y,i=this.z,s=this.w,n=Math.sqrt(e*e+t*t+i*i+s*s);return 0===n?(this.x=0,this.y=0,this.z=0,this.w=0,this):(n=1/n,this.x=e*n,this.y=t*n,this.z=i*n,this.w=s*n,this)}isEqual(e){let t=this.dot(e);return Math.abs(t-1)<.001}slerp(e,t){let i,s,n,r,o,a=this.x,l=this.y,h=this.z,c=this.w,d=e.x,_=e.y,u=e.z,g=e.w;return s=a*d+l*_+h*u+c*g,s<0&&(s=-s,d=-d,_=-_,u=-u,g=-g),1-s>1e-6?(i=Math.acos(s),n=Math.sin(i),r=Math.sin((1-t)*i)/n,o=Math.sin(t*i)/n):(r=1-t,o=t),new re(r*a+o*d,r*l+o*_,r*h+o*u,r*c+o*g)}}class oe{constructor(e=0,t=0,i=0){this.x=e,this.y=t,this.z=i}static get UP(){return new oe(0,1,0)}static get DOWN(){return new oe(0,-1,0)}static get RIGHT(){return new oe(1,0,0)}static get LEFT(){return new oe(-1,0,0)}static get FORWARD(){return new oe(0,0,-1)}static get BACKWARD(){return new oe(0,0,1)}static get ZERO(){return new oe}static get UNIT_X(){return new oe(1,0,0)}static get UNIT_Y(){return new oe(0,1,0)}static get UNIT_Z(){return new oe(0,0,1)}static get NORTH(){return oe.UNIT_Z}static doubleToTwoFloats(e,t,i){let s=e.x,n=e.y,r=e.z;if(s>=0){let e=65536*Math.floor(s/65536);t.x=Math.fround(e),i.x=Math.fround(s-e)}else{let e=65536*Math.floor(-s/65536);t.x=Math.fround(-e),i.x=Math.fround(s+e)}if(n>=0){let e=65536*Math.floor(n/65536);t.y=Math.fround(e),i.y=Math.fround(n-e)}else{let e=65536*Math.floor(-n/65536);t.y=Math.fround(-e),i.y=Math.fround(n+e)}if(r>=0){let e=65536*Math.floor(r/65536);t.z=Math.fround(e),i.z=Math.fround(r-e)}else{let e=65536*Math.floor(-r/65536);t.z=Math.fround(-e),i.z=Math.fround(r+e)}}static doubleToTwoFloat32Array(e,t,i){let s=e.x,n=e.y,r=e.z;if(s>=0){let e=65536*Math.floor(s/65536);t[0]=Math.fround(e),i[0]=Math.fround(s-e)}else{let e=65536*Math.floor(-s/65536);t[0]=Math.fround(-e),i[0]=Math.fround(s+e)}if(n>=0){let e=65536*Math.floor(n/65536);t[1]=Math.fround(e),i[1]=Math.fround(n-e)}else{let e=65536*Math.floor(-n/65536);t[1]=Math.fround(-e),i[1]=Math.fround(n+e)}if(r>=0){let e=65536*Math.floor(r/65536);t[2]=Math.fround(e),i[2]=Math.fround(r-e)}else{let e=65536*Math.floor(-r/65536);t[2]=Math.fround(-e),i[2]=Math.fround(r+e)}}static fromVec(e){return new oe(e[0],e[1],e[2])}static angle(e,t){let i=e.dot(t),s=e.cross(t).length();return Math.atan2(s,i)}static lerp(e,t,i){return new oe(e.x+(t.x-e.x)*i,e.y+(t.y-e.y)*i,e.z+(t.z-e.z)*i)}static add(e,t){let i=new oe(e.x,e.y,e.z);return i.addA(t),i}static sub(e,t){let i=new oe(e.x,e.y,e.z);return i.subA(t),i}static scale(e,t){return e.scaleTo(t)}static mul(e,t){let i=new oe(e.x,e.y,e.z);return i.mulA(t),i}static noncollinear(e,t){return Boolean(e.y*t.z-e.z*t.y||e.z*t.x-e.x*t.z||e.x*t.y-e.y*t.z)}static proj_b_to_plane(e,t,i){let s=e.sub(t.scaleTo(t.dot(e)/t.dot(t)));return i&&s.isZero()?new oe(i.x,i.y,i.z):s}static proj_b_to_a(e,t){return t.scaleTo(t.dot(e)/t.dot(t))}static orthoNormalize(e,t){return(e=e.getNormal()).scale(t.dot(e)),t.subA(e).normalize()}static div(e,t){let i=new oe(e.x,e.y,e.z);return i.divA(t),i}static length2(e){return e.length2()}static dot(e,t){return e.dot(t)}toVec4(){return new se(this.x,this.y,this.z,1)}clone(){return new oe(this.x,this.y,this.z)}toString(){return`(${this.x},${this.y},${this.z})`}isZero(){return!(this.x||this.y||this.z)}projToVec(e){return e.scaleTo(e.dot(this)/e.dot(e))}equal(e){return this.x===e.x&&this.y===e.y&&this.z===e.z}copy(e){return this.x=e.x,this.y=e.y,this.z=e.z,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)}length2(){return this.x*this.x+this.y*this.y+this.z*this.z}getQuat(){return new re(this.x,this.y,this.z)}addA(e){return this.x+=e.x,this.y+=e.y,this.z+=e.z,this}add(e){return new oe(this.x+e.x,this.y+e.y,this.z+e.z)}addRes(e,t){return t.set(this.x+e.x,this.y+e.y,this.z+e.z)}subA(e){return this.x-=e.x,this.y-=e.y,this.z-=e.z,this}sub(e){return new oe(this.x-e.x,this.y-e.y,this.z-e.z)}scale(e){return this.x*=e,this.y*=e,this.z*=e,this}scaleTo(e){return new oe(this.x*e,this.y*e,this.z*e)}mulA(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}mul(e){return new oe(this.x*e.x,this.y*e.y,this.z*e.z)}mulRes(e,t){return t.set(this.x*e.x,this.y*e.y,this.z*e.z)}divA(e){return this.x/=e.x,this.y/=e.y,this.z/=e.z,this}div(e){return new oe(this.x/e.x,this.y/e.y,this.z/e.z)}dot(e){return e.x*this.x+e.y*this.y+e.z*this.z}dotArr(e){return e[0]*this.x+e[1]*this.y+e[2]*this.z}cross(e){return new oe(this.y*e.z-this.z*e.y,this.z*e.x-this.x*e.z,this.x*e.y-this.y*e.x)}clear(){return this.x=this.y=this.z=0,this}getNormal(){let e=new oe;e.copy(this);let t=1/e.length();return e.x*=t,e.y*=t,e.z*=t,e}normal(){let e=new oe;e.copy(this);let t=1/e.length();return e.x*=t,e.y*=t,e.z*=t,e}normalNegate(){let e=new oe;e.copy(this);let t=-1/e.length();return e.x*=t,e.y*=t,e.z*=t,e}normalNegateScale(e){let t=new oe;t.copy(this);let i=-e/t.length();return t.x*=i,t.y*=i,t.z*=i,t}normalScale(e){let t=new oe;t.copy(this);let i=e/t.length();return t.x*=i,t.y*=i,t.z*=i,t}normalize(){let e=1/this.length();return this.x*=e,this.y*=e,this.z*=e,this}toVec(){return[this.x,this.y,this.z]}toArray(){return[this.x,this.y,this.z]}distance(e){let t=this.x-e.x,i=this.y-e.y,s=this.z-e.z;return Math.sqrt(t*t+i*i+s*s)}distance2(e){let t=this.x-e.x,i=this.y-e.y,s=this.z-e.z;return t*t+i*i+s*s}set(e,t,i){return this.x=e,this.y=t,this.z=i,this}negate(){return this.x=-this.x,this.y=-this.y,this.z=-this.z,this}negateTo(){return new oe(-this.x,-this.y,-this.z)}projToRay(e,t){let i=oe.proj_b_to_a(oe.sub(this,e),t);return i.addA(e),i}angle(e){return oe.angle(this,e)}lerp(e,t){return new oe(this.x+(e.x-this.x)*t,this.y+(e.y-this.y)*t,this.z+(e.z-this.z)*t)}smerp(e,t){let i=1-t;return new oe(this.x*t+e.x*i,this.y*t+e.y*i,this.z*t+e.z*i)}static get LERP_DELTA(){return 1e-6}slerp(e,t){let i,s,n,r,o=new oe;if(t<=0)return o.copy(this),o;if(t>=1)return o.copy(e),o;let a=this.dot(e);return 1-a>oe.LERP_DELTA?(i=Math.acos(a),s=Math.sin(i),n=Math.sin((1-t)*i)/s,r=Math.sin(t*i)/s):(n=1-t,r=t),oe.add(this.scaleTo(n),e.scale(r))}mulVecA(e){return this.x*=e.x,this.y*=e.y,this.z*=e.z,this}getRotationTo(e,t){let i=this.clone(),s=e.clone();i.normalize(),s.normalize();let n=i.dot(s);if(n>=1)return re.IDENTITY.clone();if(n<-.999999){if(t.equal(oe.ZERO)){let e=oe.UNIT_X.cross(i);return e.isZero()&&(e=oe.UNIT_Y.cross(i)),e.normalize(),re.axisAngleToQuat(e,Math.PI)}return re.axisAngleToQuat(t,Math.PI)}{let e=Math.sqrt(2*(1+n)),t=1/e,r=i.cross(s),o=new re(r.x*t,r.y*t,r.z*t,.5*e);return o.normalize(),o}}}class ae{constructor(e=0,t=0){this.x=e,this.y=t}static get UP(){return new ae(0,1)}static get DOWN(){return new ae(0,-1)}static get RIGHT(){return new ae(1,0)}static get LEFT(){return new ae(-1,0)}static get ZERO(){return new ae}static add(e,t){const i=new ae(e.x,e.y);return i.addA(t),i}static sub(e,t){var i=new ae(e.x,e.y);return i.subA(t),i}static scale(e,t){let i=new ae(e.x,e.y);return i.scale(t),i}static mul(e,t){let i=new ae(e.x,e.y);return i.mulA(t),i}static div(e,t){let i=new ae(e.x,e.y);return i.divA(t),i}static proj_b_to_a(e,t){return t.scaleTo(t.dot(e)/t.dot(t))}static angle(e,t){return Math.acos(e.dot(t)/Math.sqrt(e.length2()*t.length2()))}static orthoNormalize(e,t){return(e=e.normal()).scale(t.dot(e)),t.sub(e).normalize()}static proj_b_to_plane(e,t,i){let s=e.sub(t.scaleTo(t.dot(e)/t.dot(t)));return i&&s.isZero()?new ae(i.x,i.y):s}toVector3(){return new oe(this.x,this.y,0)}clone(){return new ae(this.x,this.y)}equal(e){return this.x===e.x&&this.y===e.y}copy(e){return this.x=e.x,this.y=e.y,this}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}length2(){return this.x*this.x+this.y*this.y}addA(e){return this.x+=e.x,this.y+=e.y,this}add(e){return new ae(this.x+e.x,this.y+e.y)}subA(e){return this.x-=e.x,this.y-=e.y,this}sub(e){return new ae(this.x-e.x,this.y-e.y)}scale(e){return this.x*=e,this.y*=e,this}scaleTo(e){return new ae(this.x*e,this.y*e)}mulA(e){return this.x*=e.x,this.y*=e.y,this}mul(e){return new ae(this.x*e.x,this.y*e.y)}divA(e){return this.x/=e.x,this.y/=e.y,this}dot(e){return e.x*this.x+e.y*this.y}dotArr(e){return e[0]*this.x+e[1]*this.y}cross(e){return this.x*e.y-this.y*e.x}clear(){return this.x=this.y=0,this}normal(){return this.getNormal()}getNormal(){let e=new ae;e.copy(this);let t=1/e.length();return e.x*=t,e.y*=t,e}normalize(){let e=1/this.length();return this.x*=e,this.y*=e,this}toVec(){return[this.x,this.y]}distance(e){return ae.sub(this,e).length()}set(e,t){return this.x=e,this.y=t,this}negate(){return this.x=-this.x,this.y=-this.y,this}negateTo(){return new ae(-this.x,-this.y)}projToRay(e,t){let i=ae.proj_b_to_a(ae.sub(this,e),t);return i.add(e),i}angle(e){return ae.angle(this,e)}lerp(e,t,i){let s=this.clone();return i<=0?s.copy(e):i>=1?s.copy(t):s=ae.add(e,ae.sub(t,e).scale(i)),s}static get LERP_DELTA(){return 1e-6}slerp(e,t){let i,s,n,r,o=new ae;if(t<=0)return o.copy(this),o;if(t>=1)return o.copy(e),o;let a=this.dot(e);return 1-a>ae.LERP_DELTA?(i=Math.acos(a),s=Math.sin(i),n=Math.sin((1-t)*i)/s,r=Math.sin(t*i)/s):(n=1-t,r=t),ae.add(this.scale(n),e.scale(r))}isZero(){return!(this.x||this.y)}}const le={aliceblue:"#f0f8ff",antiquewhite:"#faebd7",aqua:"#00ffff",aquamarine:"#7fffd4",azure:"#f0ffff",beige:"#f5f5dc",bisque:"#ffe4c4",black:"#000000",blanchedalmond:"#ffebcd",blue:"#0000ff",blueviolet:"#8a2be2",brown:"#a52a2a",burlywood:"#deb887",cadetblue:"#5f9ea0",chartreuse:"#7fff00",chocolate:"#d2691e",coral:"#ff7f50",cornflowerblue:"#6495ed",cornsilk:"#fff8dc",crimson:"#dc143c",cyan:"#00ffff",darkblue:"#00008b",darkcyan:"#008b8b",darkgoldenrod:"#b8860b",darkgray:"#a9a9a9",darkgreen:"#006400",darkkhaki:"#bdb76b",darkmagenta:"#8b008b",darkolivegreen:"#556b2f",darkorange:"#ff8c00",darkorchid:"#9932cc",darkred:"#8b0000",darksalmon:"#e9967a",darkseagreen:"#8fbc8f",darkslateblue:"#483d8b",darkslategray:"#2f4f4f",darkturquoise:"#00ced1",darkviolet:"#9400d3",deeppink:"#ff1493",deepskyblue:"#00bfff",dimgray:"#696969",dodgerblue:"#1e90ff",firebrick:"#b22222",floralwhite:"#fffaf0",forestgreen:"#228b22",fuchsia:"#ff00ff",gainsboro:"#dcdcdc",ghostwhite:"#f8f8ff",gold:"#ffd700",goldenrod:"#daa520",gray:"#808080",green:"#008000",greenyellow:"#adff2f",honeydew:"#f0fff0",hotpink:"#ff69b4","indianred ":"#cd5c5c",indigo:"#4b0082",ivory:"#fffff0",khaki:"#f0e68c",lavender:"#e6e6fa",lavenderblush:"#fff0f5",lawngreen:"#7cfc00",lemonchiffon:"#fffacd",lightblue:"#add8e6",lightcoral:"#f08080",lightcyan:"#e0ffff",lightgoldenrodyellow:"#fafad2",lightgrey:"#d3d3d3",lightgreen:"#90ee90",lightpink:"#ffb6c1",lightsalmon:"#ffa07a",lightseagreen:"#20b2aa",lightskyblue:"#87cefa",lightslategray:"#778899",lightsteelblue:"#b0c4de",lightyellow:"#ffffe0",lime:"#00ff00",limegreen:"#32cd32",linen:"#faf0e6",magenta:"#ff00ff",maroon:"#800000",mediumaquamarine:"#66cdaa",mediumblue:"#0000cd",mediumorchid:"#ba55d3",mediumpurple:"#9370d8",mediumseagreen:"#3cb371",mediumslateblue:"#7b68ee",mediumspringgreen:"#00fa9a",mediumturquoise:"#48d1cc",mediumvioletred:"#c71585",midnightblue:"#191970",mintcream:"#f5fffa",mistyrose:"#ffe4e1",moccasin:"#ffe4b5",navajowhite:"#ffdead",navy:"#000080",oldlace:"#fdf5e6",olive:"#808000",olivedrab:"#6b8e23",orange:"#ffa500",orangered:"#ff4500",orchid:"#da70d6",palegoldenrod:"#eee8aa",palegreen:"#98fb98",paleturquoise:"#afeeee",palevioletred:"#d87093",papayawhip:"#ffefd5",peachpuff:"#ffdab9",peru:"#cd853f",pink:"#ffc0cb",plum:"#dda0dd",powderblue:"#b0e0e6",purple:"#800080",rebeccapurple:"#663399",red:"#ff0000",rosybrown:"#bc8f8f",royalblue:"#4169e1",saddlebrown:"#8b4513",salmon:"#fa8072",sandybrown:"#f4a460",seagreen:"#2e8b57",seashell:"#fff5ee",sienna:"#a0522d",silver:"#c0c0c0",skyblue:"#87ceeb",slateblue:"#6a5acd",slategray:"#708090",snow:"#fffafa",springgreen:"#00ff7f",steelblue:"#4682b4",tan:"#d2b48c",teal:"#008080",thistle:"#d8bfd8",tomato:"#ff6347",turquoise:"#40e0d0",violet:"#ee82ee",wheat:"#f5deb3",white:"#ffffff",whitesmoke:"#f5f5f5",yellow:"#ffff00",yellowgreen:"#9acd32"};class he{constructor(e=1,t=1){this._a=e,this._b=t,this._flattening=(e-t)/e,this._f=1/this._flattening,this._a2=e*e,this._b2=t*t;const i=Math.sqrt(this._a2-this._b2);this._e=i/e,this._e2=this._e*this._e,this._e22=this._e2*this._e2,this._k=i/t,this._k2=this._k*this._k,this._radii=new oe(e,e,t),this._radii2=new oe(this._a2,this._a2,this._b2),this._invRadii=new oe(1/e,1/e,1/t),this._invRadii2=new oe(1/this._a2,1/this._a2,1/this._b2)}rhumbDistanceTo(e,t){const i=e.lat*l,s=t.lat*l,n=s-i;let r=Math.abs(t.lon-e.lon)*l;Math.abs(r)>Math.PI&&(r=r>0?-(2*Math.PI-r):2*Math.PI+r);const o=Math.log(Math.tan(s/2+Math.PI/4)/Math.tan(i/2+Math.PI/4)),a=Math.abs(o)>1e-11?n/o:Math.cos(i);return Math.sqrt(n*n+a*a*r*r)*this._a}getIntermediatePointOnGreatCircle(e,t,i){if(0==i)return e.clone();if(1==i)return t.clone();const s=this.inverse(e,t),n=s.distance,r=s.initialAzimuth;return isNaN(r)?e:this.getGreatCircleDestination(e,r,n*i)}static getBearing(e,t){let i=e.lat*l,s=e.lon*l,n=t.lat*l,r=t.lon*l,o=Math.sin(r-s)*Math.cos(n),a=Math.cos(i)*Math.sin(n)-Math.sin(i)*Math.cos(n)*Math.cos(r-s);return Math.atan2(o,a)*h}getFlattening(){return this._flattening}getEquatorialSize(){return this._a}get equatorialSize(){return this._a}get equatorialSizeSqr(){return this._a2}getPolarSize(){return this._b}get polarSize(){return this._b}get polarSizeSqr(){return this._b2}lonLatToCartesian(e){return this.geodeticToCartesian(e.lon,e.lat,e.height)}lonLatToCartesianRes(e,t){return this.geodeticToCartesian(e.lon,e.lat,e.height,t)}geodeticToCartesian(e,t,i=0,s=new oe){let n=l*t,r=l*e,o=Math.sin(n),a=this._a/Math.sqrt(1-this._e2*o*o),h=(a+i)*Math.cos(n);return s.x=h*Math.cos(r),s.y=h*Math.sin(r),s.z=(a*(1-this._e2)+i)*o,s}projToSurface(e){let t=e.x||0,i=e.y||0,s=e.z||0,n=Math.sqrt(t*t+i*i+s*s);if(0===n)return this.lonLatToCartesian(new I);let r=this._invRadii2.x,o=this._invRadii2.y,a=this._invRadii2.z,l=t*t*r,h=i*i*o,c=s*s*a,d=l+h+c,_=Math.sqrt(1/d),u=e.scaleTo(_);if(d<.1)return Number.isFinite(_)?u:new oe;let g=(1-_)*n/u.mulA(this._invRadii2).length(),p=0,m=0,v=0;for(;;){p=1/(1+g*r),m=1/(1+g*o),v=1/(1+g*a);let e=p*p,t=m*m,i=v*v,s=l*e+h*t+c*i-1;if(Math.abs(s)<f)break;g+=.5*s/(l*(e*p)*r+h*(t*m)*o+c*(i*v)*a)}return new oe(t*p,i*m,s*v)}cartesianToLonLat(e){return this.cartesianToLonLatRes(e)}cartesianToLonLatRes(e,t=new I){let i=this.projToSurface(e),s=this.getSurfaceNormal3v(i),n=e.sub(i);return t.lon=Math.atan2(s.y,s.x)*h,t.lat=Math.asin(s.z)*h,t.height=Math.sign(n.dot(e))*n.length(),t}getSurfaceNormal3v(e){let t=this._invRadii2,i=e.x*t.x,s=e.y*t.y,n=e.z*t.z,r=1/Math.sqrt(i*i+s*s+n*n);return new oe(i*r,s*r,n*r)}getGreatCircleDistance(e,t){return this.inverse(e,t).distance}getGreatCircleDestination(e,t,i){return this.direct(e,t,i).destination}inverse(e,t){let i=this._a,s=this._b,n=this._flattening;const r=e.lat*l,o=e.lon*l,a=t.lat*l,c=t.lon*l-o,d=(1-n)*Math.tan(r),_=1/Math.sqrt(1+d*d),u=d*_,g=(1-n)*Math.tan(a),p=1/Math.sqrt(1+g*g),m=g*p,v=Math.abs(c)>Math.PI/2||Math.abs(a-r)>Math.PI/2;let y=c,x=null,b=null,C=v?Math.PI:0,T=0,E=v?-1:1,L=null,A=1,P=1,S=null,M=0;do{if(x=Math.sin(y),b=Math.cos(y),L=(p*x)**2+(_*m-u*p*b)**2,Math.abs(L)<1e-24)break;T=Math.sqrt(L),E=u*m+_*p*b,C=Math.atan2(T,E);const e=_*p*x/T;P=1-e*e,A=0!=P?E-2*u*m/P:0;const t=n/16*P*(4+n*(4-3*P));S=y,y=c+(1-t)*n*e*(C+t*T*(A+t*E*(2*A*A-1)))}while(Math.abs(y-S)>f&&++M<1e3);const R=P*(i*i-s*s)/(s*s),B=R/1024*(256+R*(R*(74-47*R)-128)),k=s*(1+R/16384*(4096+R*(R*(320-175*R)-768)))*(C-B*T*(A+B/4*(E*(2*A*A-1)-B/6*A*(4*T*T-3)*(4*A*A-3)))),I=Math.abs(L)<Number.EPSILON?0:Math.atan2(p*x,_*m-u*p*b),z=Math.abs(L)<Number.EPSILON?Math.PI:Math.atan2(_*x,-u*p+_*m*b);return{distance:k,initialAzimuth:Math.abs(k)<Number.EPSILON?NaN:w(I)*h,finalAzimuth:Math.abs(k)<Number.EPSILON?NaN:w(z)*h}}direct(e,t,i){let s=e.lon,n=e.lat,r=this._a,o=this._b,a=this._flattening,c=i,d=t*l,_=Math.sin(d),u=Math.cos(d),g=(1-a)*Math.tan(n*l),f=1/Math.sqrt(1+g*g),p=g*f,m=Math.atan2(g,u),v=f*_,y=1-v*v,x=y*(r*r-o*o)/(o*o),b=1+x/16384*(4096+x*(x*(320-175*x)-768)),w=x/1024*(256+x*(x*(74-47*x)-128)),C=c/(o*b),T=2*Math.PI,E=0,L=0,A=0,P=0;for(;Math.abs(C-T)>1e-12;)E=Math.cos(2*m+C),L=Math.sin(C),A=Math.cos(C),P=w*L*(E+w/4*(A*(2*E*E-1)-w/6*E*(4*L*L-3)*(4*E*E-3))),T=C,C=c/(o*b)+P;let S=p*L-f*A*u,M=Math.atan2(p*A+f*L*u,(1-a)*Math.sqrt(v*v+S*S)),R=a/16*y*(4+a*(4-3*y)),B=Math.atan2(L*_,f*A-p*L*u)-(1-R)*a*v*(C+R*L*(E+R*A*(2*E*E-1))),k=Math.atan2(v,-S);return{destination:new I(s+B*h,M*h),finalAzimuth:k*h}}hitRay(e,t){let i,s,n,r,o,a=this._invRadii.mul(e),l=this._invRadii.mul(t),h=a.dot(a),c=a.dot(l);if(h>1){if(c>=0)return;var d=c*c;if(i=h-1,s=l.dot(l),n=s*i,Math.abs(d-n)>1e-15&&d<n)return;if(d>n){r=c*c-n,o=-c+Math.sqrt(r);var _=o/s,u=i/o;return _<u?e.add(t.scaleTo(_)):e.add(t.scaleTo(u))}var g=Math.sqrt(i/s);return e.add(t.scaleTo(g))}return h<1?(i=h-1,s=l.dot(l),n=s*i,r=c*c-n,o=-c+Math.sqrt(r),e.add(t.scaleTo(o/s))):c<0?(s=l.dot(l),e.add(t.scaleTo(-c/s))):void 0}getNorthFrameRotation(e){let t=this.getSurfaceNormal3v(e),i=oe.proj_b_to_plane(oe.NORTH,t);return re.getLookRotation(i,t)}getBearingDestination(e,t=0,i=0){t*=l;var s=(e.lon+540)%360-180,n=e.lat*l,r=s*l,o=i/this._a,a=Math.asin(Math.sin(n)*Math.cos(o)+Math.cos(n)*Math.sin(o)*Math.cos(t));return new I((r+Math.atan2(Math.sin(t)*Math.sin(o)*Math.cos(n),Math.cos(o)-Math.sin(n)*Math.sin(a)))*h,a*h)}static getIntermediatePointOnGreatCircle(e,t,i){var s=e.lat*l,n=e.lon*l,r=t.lat*l,o=t.lon*l,a=Math.sin(s),c=Math.cos(s),d=Math.sin(n),_=Math.cos(n),u=Math.sin(r),g=Math.cos(r),f=Math.sin(o),p=Math.cos(o),m=r-s,v=o-n,y=Math.sin(m/2)*Math.sin(m/2)+Math.cos(s)*Math.cos(r)*Math.sin(v/2)*Math.sin(v/2),x=2*Math.atan2(Math.sqrt(y),Math.sqrt(1-y)),b=Math.sin((1-i)*x)/Math.sin(x),w=Math.sin(i*x)/Math.sin(x),C=b*c*_+w*g*p,T=b*c*d+w*g*f,E=b*a+w*u,L=Math.atan2(E,Math.sqrt(C*C+T*T)),A=Math.atan2(T,C);return new I((A*h+540)%360-180,L*h)}static getRhumbBearing(e,t){var i=(t.lon-e.lon)*l,s=Math.log(Math.tan(t.lat*l/2+Math.PI/4)/Math.tan(e.lat*l/2+Math.PI/4));return Math.abs(i)>Math.PI&&(i=i>0?-1*(2*Math.PI-i):2*Math.PI+i),(Math.atan2(i,s)*h+360)%360}getLonLatVisibilitySimple(e,t,i){const s=this.lonLatToCartesian(t),n=t.height,r=this.polarSize+n,o=Math.max(e.length()-this.polarSize,0),a=s.sub(e);let l;return l=o>0?Math.sqrt((r+o)**2-r**2):r,l>a.length()&&(!i||i.dot(a.normalize())>0)}}const ce=new he(6378137,6356752.314245179);function de(e,t){return null!=e?e:t}function _e(e){return null==e}function ue(e){return void 0===e}let ge=0;function fe(e){let t=e._openglobus_id;return t||(t=e._openglobus_id=++ge),t}function pe(e){return"string"==typeof e||e instanceof String}function me(e){return e.toString(16).padStart(2,"0")}function ve(e){let t,i,s;return e instanceof Array?(t=me(e[0]),i=me(e[1]),s=me(e[2])):(t=me(e.x),i=me(e.y),s=me(e.z)),`#${t}${i}${s}`}function ye(e,t){let i=le[e];if(i&&(e=i),"#"===e[0]){let i=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,s=e.replace(i,(function(e,t,i,s){return t+t+i+i+s+s})),n=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(s);return n?new se(parseInt(n[1],16)/255,parseInt(n[2],16)/255,parseInt(n[3],16)/255,_e(t)?1:t):new se}{_e(t)&&(t=1);let i=e.split(",");return new se(parseInt(i[0].split("(")[1])/255,parseInt(i[1])/255,parseInt(i[2])/255,_e(i[3])?t:parseFloat(i[3]))}}function xe(e,t){let i=ye(e,t);return new Float32Array([i.x,i.y,i.z,i.w])}function be(e){let t=le[e];if(t&&(e=t),"#"===e[0]){let t=/^#?([a-f\d])([a-f\d])([a-f\d])$/i,i=e.replace(t,(function(e,t,i,s){return t+t+i+i+s+s})),s=/^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(i);return s?new oe(parseInt(s[1],16)/255,parseInt(s[2],16)/255,parseInt(s[3],16)/255):new oe}{let t=e.split(",");return new oe(parseInt(t[0].split("(")[1])/255,parseInt(t[1])/255,parseInt(t[2])/255)}}function we(e,t){return e.replace(/{[^{}]+}/g,(function(e){return t[e.replace(/[{}]+/g,"")]||""}))}function Ce(e){let t=document.createElement("div");t.innerHTML=e;let i=[];for(let e=0;e<t.childNodes.length;e++)i.push(t.childNodes[e]),t.removeChild(t.childNodes[e]);return i}function Te(e,t,i,s){let n=document.getElementById(e);n||(n=document.createElement("div"),n.id=e,n.classList.add("defaultText"),document.body.appendChild(n)),n.innerHTML=t,n.style.left=`${i}px`,n.style.top=`${s}px`}function Ee(e){return"number"==typeof e}function Le(e,t=""){return e?e.trim():t}function Ae(e,t){if(e){if(Ee(e))return new oe(e,e,e);if(e instanceof oe)return e.clone();if(e instanceof Array)return oe.fromVec(e);if(e instanceof ae)return new oe(e.x,e.y,0)}else if(t)return t;return new oe}function Pe(e,t){if(e){if(pe(e))return ye(e);if(e instanceof Array)return se.fromVec(e);if(e instanceof se)return e.clone()}else if(t)return t;return new se(1,1,1,1)}function Se(e,t){if(e){if(pe(e))return be(e);if(e instanceof Array)return oe.fromVec(e);if(e instanceof oe)return e.clone()}else if(t)return t;return new oe(1,1,1)}function Me(e,t){if(e){if(e instanceof Array)return new te(Re(e[0]),Re(e[1]));if(e instanceof te)return e.clone()}else if(t)return t;return new te}function Re(e,t){if(e){if(e instanceof Array)return new I(e[0],e[1],e[2]);if(e instanceof I)return e.clone()}else if(t)return t;return new I}function Be(e,t){let i=0,s=e.length-1;for(;i<=s;){let n=Math.floor(.5*(i+s));if(Math.abs(e[n]-t)<.001)return n;e[n]<t?i=n+1:s=n-1}return-1}function ke(e,t,i){let s=0,n=e.length-1;for(;s<=n;){let r=n+s>>1,o=i(t,e[r],r);if(o>0)s=r+1;else{if(!(o<0))return r;n=r-1}}return-s-1}function Ie(e,t,i){let s=ke(e,t,i);return s<0&&(s=~s),e.splice(s,0,t),s}function ze(e,t,i,s,n=!1){let r=new I(t.lon-e.lon,t.lat-e.lat),o=new I(s.lon-i.lon,s.lat-i.lat),a=-r.lat,l=+r.lon,h=-(a*e.lon+l*e.lat),c=-o.lat,d=+o.lon,_=-(c*i.lon+d*i.lat),u=c*e.lon+d*e.lat+_,g=c*t.lon+d*t.lat+_,f=a*i.lon+l*i.lat+h,p=a*s.lon+l*s.lat+h;if(n&&(u*g>0||f*p>0))return;let m=u/(u-g);return new I(e.lon+m*r.lon,e.lat+m*r.lat)}const De={string:function(e){return _e(e)?e:e.toString()},date:function(e){return _e(e)?e:new Date(1e3*e)},datetime:function(e){return _e(e)?e:new Date(1e3*e)},time:function(e){return _e(e)?e:parseInt(e)},integer:function(e){return _e(e)?e:parseInt(e)},float:function(e){return _e(e)?e:parseFloat(e)},boolean:function(e){if(null===e)return e;if("boolean"==typeof e)return!0===e;if("string"==typeof e){if(""===e)return!1;if("true"===(e=e.replace(/^\s+|\s+$/g,"")).toLowerCase()||"yes"===e.toLowerCase())return!0;e=(e=e.replace(/,/g,".")).replace(/^\s*\-\s*/g,"-")}return!isNaN(e)&&0!==parseFloat(e)}};function Fe(e,t=""){let i=1024,s=atob(e),n=s.length,r=Math.ceil(n/i),o=new Array(r);for(let e=0;e<r;++e){let t=e*i,r=Math.min(t+i,n),a=new Array(r-t);for(let e=t,i=0;e<r;++i,++e)a[i]=s[e].charCodeAt(0);o[e]=new Uint8Array(a)}return new Blob(o,{type:t})}function Ne(e,t,i=!1){let s,n=0;return function(){const r=arguments;n?(i&&clearTimeout(s),s=setTimeout((()=>{Date.now()-n>=t&&(e.apply(null,r),n=Date.now())}),t-(Date.now()-n))):(e.apply(null,r),n=Date.now())}}function He(e,t){let i=new e.constructor(e.length+t.length);return i.set(e,0),i.set(t,e.length),i}function Oe(e=[],t=[]){if(ArrayBuffer.isView(e))return He(e,t);for(let i=0;i<t.length;i++)e.push(t[i]);return e}function Ve(e,t=Float32Array){if(ArrayBuffer.isView(e))return e;{const i=new t(e.length);return i.set(e,0),i}}function Ue(e){return ArrayBuffer.isView(e)?Array.from(e):e}function Ge(e,t,i,s){if(ArrayBuffer.isView(e))return t<0&&(i=Math.abs(t),t+=e.length),Ye(e,t,i,s);{let n;return n=t<0?e.splice(t):e.splice(t,i),s&&(s.result=n),e}}function Ye(e,t,i,s){if(0===e.length)return e;const n=e.length-i,r=new e.constructor(n);return r.set(e.subarray(0,t)),r.set(e.subarray(t+i),t),s&&(s.result=e.subarray(t,t+i)),r}function je(e,t,i,s,n){const r=n+1,o=i+r,a=s+r;let l=new Float64Array(r*r*3),h=0;for(let n=i;n<o;n++)for(let i=s;i<a;i++){let s=3*(n*(t+1)+i);l[h++]=e[s],l[h++]=e[s+1],l[h++]=e[s+2]}return l}function We(e,t,i,s,n){const r=n+1,o=i+r,a=s+r;let l=new Float32Array(r*r*3),h=0;for(let n=i;n<o;n++)for(let i=s;i<a;i++){let s=3*(n*(t+1)+i);l[h++]=e[s],l[h++]=e[s+1],l[h++]=e[s+2]}return l}function qe(e,t,i,s,n,r,o,a,l,h,c,d,_){const u=r+a+1,g=o+a+1;n+=1;let f=0,p=0;for(let a=r;a<u;a++)for(let r=o;r<g;r++){let o=a*n+r,u=3*o,g=e[u],m=e[u+1],v=e[u+2];s&&0!==s[o]?_[p]=1:(g<d.xmin&&(d.xmin=g),g>d.xmax&&(d.xmax=g),m<d.ymin&&(d.ymin=m),m>d.ymax&&(d.ymax=m),v<d.zmin&&(d.zmin=v),v>d.zmax&&(d.zmax=v)),p++,l[f]=g,c[f]=i[u],h[f++]=t[u],l[f]=m,c[f]=i[u+1],h[f++]=t[u+1],l[f]=v,c[f]=i[u+2],h[f++]=t[u+2]}}function $e(e){return e.map((e=>Array.isArray(e)?$e(e):e))}async function Xe(e){return new Promise((t=>{const i=new Image;return i.addEventListener("load",(()=>{t(i)})),i.src=e,i.crossOrigin="",i}))}function Ze(e){return e.complete&&0!==e.naturalHeight}function Ke(e){if(e>1e3){return 0!==e-Math.floor(e)?[(e/1e3).toFixed(2),"km"]:[(e/1e3).toFixed(0),"km"]}return e>9?[Math.round(e).toString(),"m"]:e<=.01?["0","m"]:[e.toFixed(1),"m"]}function Qe(e){let t=new URLSearchParams(location.search).get(e);if(t)return Number(t)}function Je(e,t=-1){if(t<0)return e.toString();const i=Math.pow(10,t);return(Math.round(e*i)/i).toString()}var et=Object.freeze({__proto__:null,base64StringToBlog:function(e){let t=e.split(";"),i=t[0].split(":")[1];return Fe(t[1].split(",")[1],i)},base64toBlob:Fe,binaryInsert:Ie,binarySearch:ke,binarySearchFast:Be,blerp:function(e,t,i,s,n,r,o=0,a=1,l=0,h=1){return(i*(a-e)*(h-t)+s*(e-o)*(h-t)+n*(a-e)*(t-l)+r*(e-o)*(t-l))/((a-o)*(h-l))},blerp2:function(e,t,i,s,n,r){return i*(1-e)*(1-t)+s*e*(1-t)+n*(1-e)*t+r*e*t},castType:De,cloneArray:$e,concatArrays:Oe,concatTypedArrays:He,createColorRGB:Se,createColorRGBA:Pe,createExtent:Me,createLonLat:Re,createVector3:Ae,createVector4:function(e,t){if(e){if(e instanceof se)return e.clone();if(e instanceof Array)return se.fromVec(e)}else if(t)return t;return new se},defaultString:Le,distanceFormat:function(e){return e>1e3?`${(e/1e3).toFixed(2)} km`:e>9?`${Math.round(e)} m`:`${e.toFixed(1)} m`},distanceFormatExt:Ke,extractElevationTiles:function(e,t,i){let s=Math.sqrt(t.length)-1,n=s+1,r=Math.sqrt(e.length/4),o=r/s,a=0,l=0;for(let h=0,c=0,d=e.length/4;h<d;h++){let d=e[4*h],_=Math.floor(h/r),u=h%r,g=Math.floor(u/s),f=Math.floor(_/s),p=i[f][g],m=_%s,v=u%s,y=(m+f)*n+v+g;if(p[y]=d,(_+f)%o==0&&(u+g)%o==0&&(t[c++]=d),(u+1)%s==0&&u!==r-1){a=e[4*(h+1)];let r=.5*(d+a);y=(m+f)*n+v+1,p[y]=r,(_+f)%o==0&&(t[c++]=r);let l=(m+f)*n+(v+1)%s;i[f][g+1][l]=r}if((_+1)%s==0&&_!==r-1){l=e[4*(h+r)];let a=.5*(d+l);y=(m+1)*n+v+g,p[y]=a,(u+g)%o==0&&(t[c++]=a);let _=(m+1)%s*n+v+g;i[f+1][g][_]=a}if((u+1)%s==0&&u!==r-1&&(_+1)%s==0&&_!==r-1){let o=.25*(d+a+l+e[4*(h+r+1)]);y=(m+1)*n+(v+1),p[y]=o,t[c++]=o;let _=(m+1)*n;i[f][g+1][_]=o;let u=s;i[f+1][g][u]=o;let x=0;i[f+1][g+1][x]=o}}},getDefault:de,getHTML:function(e,t){return we(e,t)},getLinesIntersection2v:function(e,t,i,s,n){let r=t.sub(e),o=s.sub(i),a=-r.y,l=+r.x,h=-(a*e.x+l*e.y),c=-o.y,d=+o.x,_=-(c*i.x+d*i.y),u=c*e.x+d*e.y+_,g=c*t.x+d*t.y+_,f=a*i.x+l*i.y+h,p=a*s.x+l*s.y+h;if(n&&(u*g>0||f*p>0))return;let m=u/(u-g);return new ae(e.x+m*r.x,e.y+m*r.y)},getLinesIntersectionLonLat:ze,getMatrixSubArray32:We,getMatrixSubArray64:je,getMatrixSubArrayBoundsExt:qe,getTileImageResolution:function(e,t,i,s=256,n=ce){let r=K(e,t,i),o=r.getSouthWest().inverseMercator(),a=r.getNorthEast().inverseMercator();return[n.getGreatCircleDistance(o,new I(a.lon,o.lat))/s,n.getGreatCircleDistance(o,new I(o.lon,a.lat))/s]},getUrlParam:Qe,htmlColorToFloat32Array:xe,htmlColorToRgb:be,htmlColorToRgba:ye,isEmpty:_e,isImageLoaded:Ze,isNumber:Ee,isString:pe,isUndef:ue,isUndefExt:function(e,t){return ue(e)?t:e},loadImage:Xe,makeArray:Ue,makeArrayTyped:Ve,parseHTML:Ce,print2d:Te,rgbToStringHTML:ve,spliceArray:Ge,spliceTypedArray:Ye,stamp:fe,stringTemplate:we,throttle:Ne,toFixedMax:Je,xmlToJson:function e(t){let i={};if(1===t.nodeType){if(t.attributes.length>0){i["@attributes"]={};for(let e=0;e<t.attributes.length;e++){let s=t.attributes.item(e);i["@attributes"][s.nodeName]=s.nodeValue}}}else 3===t.nodeType&&(i=t.nodeValue);if(t.hasChildNodes())for(let s=0;s<t.childNodes.length;s++){let n=t.childNodes.item(s),r=n.nodeName;if(void 0===i[r])i[r]=e(n);else{if(void 0===i[r].push){let e=i[r];i[r]=[],i[r].push(e)}i[r].push(e(n))}}return i}});const tt=.001,it=1e3,st=60,nt=1/st,rt=1/24,ot=3600,at=1/ot,lt=12*ot,ht=1440,ct=1/ht,dt=86400,_t=864e5,ut=1.1574074074074074e-8,gt=1/dt,ft=2451545;function pt(e,t,i){let s=(t-14)/12|0,n=e+4800+s;return(1461*n/4|0)+(367*(t-2-12*s)/12|0)-(3*((n+100)/100|0)/4|0)+i-32075}function mt(e){let t=pt(e.getUTCFullYear(),e.getUTCMonth()+1,e.getUTCDate()),i=e.getUTCHours()-12;i<0&&(i+=24);let s=e.getUTCSeconds()+i*ot+e.getUTCMinutes()*st+e.getUTCMilliseconds()*tt;s>=lt&&t--;let n=s*gt|0;return t+=n,s-=dt*n,s<0&&(t--,s+=dt),t+s*gt}function vt(e){let t=Tt,i=ke(t,e,(function(e,t){return e-t.jd}));i<0&&(i=~i),i>=t.length&&(i=t.length-1);let s=t[i].leapSeconds;return 0!==i&&(t[i].jd-e)*dt>s&&(s=t[i-1].leapSeconds),e+s*gt}function yt(e){let t=Tt,i=ke(t,e,(function(e,t){return e-t.jd}));if(i<0&&(i=~i),i>=t.length)return e-t[i-1].leapSeconds*gt;if(0===i)return e-t[0].leapSeconds*gt;let s=(t[i].jd-e)*dt;return 0===s?e-t[i].leapSeconds*gt:s<=1?void 0:e-t[i-1].leapSeconds*gt}function xt(e){let t=0|e,i=(e-t)*dt;i>=lt&&t++;let s=t+68569|0,n=4*s/146097|0;s=s-((146097*n+3)/4|0)|0;let r=4e3*(s+1)/1461001|0;s=s-(1461*r/4|0)+31|0;let o=80*s/2447|0,a=s-(2447*o/80|0)|0;s=o/11|0;let l=o+2-12*s|0,h=100*(n-49)+r+s|0,c=i*at|0,d=i-c*ot,_=d*nt|0;d-=_*st;let u=0|d,g=(d-u)*it|0;return c+=12,c>23&&(c-=24),new Date(Date.UTC(h,l-1,a,c,_,u,g))}function bt(e,t){return e+t*ut}function wt(e,t){return e+t*gt}function Ct(e,t){return{jd:e,leapSeconds:t}}const Tt=[Ct(2441317.5,10),Ct(2441499.5,11),Ct(2441683.5,12),Ct(2442048.5,13),Ct(2442413.5,14),Ct(2442778.5,15),Ct(2443144.5,16),Ct(2443509.5,17),Ct(2443874.5,18),Ct(2444239.5,19),Ct(2444786.5,20),Ct(2445151.5,21),Ct(2445516.5,22),Ct(2446247.5,23),Ct(2447161.5,24),Ct(2447892.5,25),Ct(2448257.5,26),Ct(2448804.5,27),Ct(2449169.5,28),Ct(2449534.5,29),Ct(2450083.5,30),Ct(2450630.5,31),Ct(2451179.5,32),Ct(2453736.5,33),Ct(2454832.5,34),Ct(2456109.5,35),Ct(2457204.5,36)],Et=vt(ft);var Lt=Object.freeze({__proto__:null,DAYS_PER_JULIAN_CENTURY:36525,DAYS_PER_JULIAN_YEAR:365.25,DateToTAI:function(e){return vt(mt(e))},DateToUTC:mt,HOURS_PER_DAY:24,J2000:ft,J2000TAI:Et,MILLISECONDS_PER_DAY:_t,MILLISECONDS_PER_SECOND:it,MINUTES_PER_DAY:ht,MINUTES_PER_HOUR:60,MODIFIED_JULIAN_DATE_DIFFERENCE:2400000.5,ONE_BY_HOURS_PER_DAY:rt,ONE_BY_MILLISECONDS_PER_DAY:ut,ONE_BY_MINUTES_PER_DAY:ct,ONE_BY_SECONDS_PER_DAY:gt,ONE_BY_SECONDS_PER_HOUR:at,ONE_BY_SECONDS_PER_MINUTE:nt,PICOSECOND:1e-9,SECONDS_PER_12_HOURS:lt,SECONDS_PER_DAY:dt,SECONDS_PER_HOUR:ot,SECONDS_PER_MILLISECOND:tt,SECONDS_PER_MINUTE:st,T:function(e){return(e-ft)/36525},TAItoDate:function(e){let t=yt(e);return t||(t=yt(wt(e,-1)),console.trace(`TAItoDate - can't convert ${e.toString()} to utc.`)),xt(t)},TAItoUTC:yt,UTCtoDate:xt,UTCtoTAI:vt,addDays:function(e,t){return e+t},addHours:function(e,t){return e+t*rt},addMilliseconds:bt,addMinutes:function(e,t){return e+t*ht},addSeconds:wt,daysToSeconds:function(e){return e*dt},getDayNumber:pt,getDays:function(e){return 0|e},getHours:function(e){let t=(e-(0|e))*dt,i=t*at|0,s=t-i*ot,n=s*nt|0;s-=n*st;let r=0|s;return i+=12+n/60+r/3600+((s-r)*it|0)/1e3,i>23&&(i-=24),i},getMilliseconds:function(e){let t=e-(0|e);return t*=dt,(t-(0|t))*it|0},getMinutes:function(e){return(e-(0|e))*ht|0},getSeconds:function(e){return(e-(0|e))*dt},secondsToDays:function(e){return e*gt}});class At{constructor(e){this.vertices=[new oe,new oe,new oe,new oe,new oe,new oe,new oe,new oe],e&&this.setFromBoundsArr(e)}copy(e){for(let t=0,i=this.vertices.length;t<i;t++)this.vertices[t].copy(e.vertices[t])}setFromBoundsArr(e){let t=e[0],i=e[3],s=e[1],n=e[4],r=e[2],o=e[5],a=this.vertices;a[0].set(t,s,r),a[1].set(i,s,r),a[2].set(i,s,o),a[3].set(t,s,o),a[4].set(t,n,r),a[5].set(i,n,r),a[6].set(i,n,o),a[7].set(t,n,o)}setFromExtent(e,t){this.setFromBoundsArr(t.getCartesianBounds(e))}}class Pt{constructor(e=0,t){this.radius=e,this.center=t?t.clone():new oe}setFromBounds(e){let t=new oe(e[0],e[1],e[2]);this.center.set(t.x+.5*(e[3]-t.x),t.y+.5*(e[3]-t.y),t.z+.5*(e[5]-t.z)),this.radius=this.center.distance(t)}setFromExtent(e,t){this.setFromBounds(t.getCartesianBounds(e))}}var St=Object.freeze({__proto__:null,Box:At,Sphere:Pt});function Mt(e,t){return new Rt(e,t)}class Rt{constructor(e,t){this.__id=Rt.__counter__++,this._eventNames=[],e&&this.registerNames(e),this._sender=t||this,this._stopPropagation=!1,this._stampCache={}}bindSender(e){this._sender=e||this}registerNames(e){for(let t=0;t<e.length;t++)this[e[t]]={active:!0,handlers:[]},this._eventNames.push(e[t]);return this}_getStamp(e,t,i){return`${e}_${t}_${i}`}_stamp(e,t){let i=fe(t),s=this._getStamp(e,this.__id,i);return!this._stampCache[s]&&(this._stampCache[s]=i,!0)}on(e,t,i,s=0){if(this._stamp(e,t)&&this[e]){let n=t.bind(i||this._sender);n._openglobus_id=t._openglobus_id,n._openglobus_priority=s,Ie(this[e].handlers,n,((e,t)=>(t._openglobus_priority||0)-(e._openglobus_priority||0)))}}off(e,t){if(t){let i=this._getStamp(e,this.__id,t._openglobus_id);if(t._openglobus_id&&this._stampCache[i]){let s=this[e].handlers,n=s.length,r=-1;for(;n--;){if(s[n]._openglobus_id===t._openglobus_id){r=n;break}}-1!==r&&(s.splice(r,1),this._stampCache[i]=void 0,delete this._stampCache[i])}}}dispatch(e,...t){let i=!0;if(e&&e.active&&!this._stopPropagation){let s=e.handlers.slice(0),n=s.length;for(;n--;)!1===s[n](...t)&&(i=!1)}return this._stopPropagation=!1,i}stopPropagation(){this._stopPropagation=!0}clear(){for(let e=0;e<this._eventNames.length;e++){let t=this[this._eventNames[e]];t.handlers.length=0,t.handlers=[]}this._eventNames.length=0,this._eventNames=[]}}Rt.__counter__=0;const Bt=["render"];class kt{constructor(e={}){this.__id=kt.__counter__++,this.events=Mt(Bt),this.model=e.model||null,this.template=e.template||"",this.parent=e.parent||null,this._classList=e.classList||[],this.el=null}on(e,t,i,s){this.events.on(e,t,i,s)}off(e,t){this.events.off(e,t)}static getHTML(e,t){return we(e,t)}static parseHTML(e){return Ce(e)}static insertAfter(e,t){Array.isArray(e)||(e=[e]);for(let i=0;i<e.length;i++)t.parentNode&&t.parentNode.insertBefore(e[i],t.nextSibling);return e}static insertBefore(e,t){Array.isArray(e)||(e=[e]);for(let i=0;i<e.length;i++)t.parentNode&&t.parentNode.insertBefore(e[i],t);return e}insertBefore(e){this.el||this.render(),this.el&&(e instanceof HTMLElement&&e.parentNode&&kt.insertBefore(this.el,e),e instanceof kt&&e.el&&e.el.parentNode&&kt.insertBefore(this.el,e.el))}insertAfter(e){this.el||this.render(),this.el&&(e instanceof HTMLElement&&e.parentNode&&kt.insertAfter(this.el,e),e instanceof kt&&e.el&&e.el.parentNode&&kt.insertAfter(this.el,e.el))}isEqual(e){return e.__id===this.__id}appendTo(e,t=!1,i=!1){return e&&(this.el||(this.beforeRender(e),this.render()),this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el),t&&(e.innerHTML=""),this.el&&(i&&e.childNodes[0]?kt.insertBefore(this.el,e.childNodes[0]):e.appendChild(this.el)),this.afterRender(e)),this}afterRender(e){}beforeRender(e){}stopPropagation(){this.events.stopPropagation()}renderTemplate(e){return kt.parseHTML(kt.getHTML(this.template,e||{}))[0]}render(e){this.el=this.renderTemplate(e);for(let e=0,t=this._classList.length;e<t;e++)this.el.classList.add(this._classList[e]);return this.events.dispatch(this.events.render,this),this}select(e){return this.el?this.el.querySelector(e):null}selectRemove(e){if(this.el){let t=this.select(e);if(t&&t.parentNode)return t.parentNode.removeChild(t),t}}selectAll(e,t){if(this.el){const i=this.el.querySelectorAll(e);if(t)for(let e=0,s=i.length;e<s;e++)t(i[e],e);return i}}remove(){this.el&&this.el.parentNode&&this.el.parentNode.removeChild(this.el)}}kt.__counter__=0;const It=["click","mousedown","mouseup","touchstart","touchend","touchcancel"];class zt extends kt{constructor(e={}){super({template:we('<div class="og-button" title="{title}">\n <div class="og-button-icon">{icon}</div>\n <div class="og-button-text">{text}</div>\n </div>',{icon:e.icon||"",text:e.text||"",title:e.title||""}),...e}),this._onMouseDown=e=>{e.preventDefault(),this.events.dispatch(this.events.mousedown,this,e)},this._onMouseUp=e=>{e.preventDefault(),this.events.dispatch(this.events.mouseup,this,e)},this._onTouchStart=e=>{e.preventDefault(),this.events.dispatch(this.events.touchstart,this,e)},this._onTouchEnd=e=>{e.preventDefault(),this.events.dispatch(this.events.touchend,this,e)},this._onTouchCancel=e=>{e.preventDefault(),this.events.dispatch(this.events.touchcancel,this,e)},this._onMouseClick=e=>{this._mouseClickHandler(e)},this.events=this.events.registerNames(It),this.el=null,this.name=e.name||"",this.$icon=null,this.$text=null}render(e){return super.render(e),this.$icon=this.select(".og-button-icon"),this.$text=this.select(".og-button-text"),this.el.__og_button__=this,this._initEvents(),this}_initEvents(){this.el&&(this.el.addEventListener("click",this._onMouseClick),this.el.addEventListener("mousedown",this._onMouseDown),this.el.addEventListener("mouseup",this._onMouseUp),this.el.addEventListener("touchstart",this._onTouchStart),this.el.addEventListener("touchend",this._onTouchEnd),this.el.addEventListener("touchcancel",this._onTouchCancel))}_mouseClickHandler(e){e.preventDefault(),this.events.dispatch(this.events.click,this,e)}remove(){this._clearEvents(),super.remove()}_clearEvents(){this.el&&this.el.removeEventListener("click",this._onMouseClick)}}class Dt{constructor(e={}){this.__id=Dt.__counter__++,this._name=e.name||`_control_${this.__id.toString()}`,this.planet=null,this._initialized=!1,this.renderer=null,this.autoActivate=e.autoActivate||!1,this._active=!1,this._deferredActive=!0}get name(){return this._name}oninit(){}onadd(){}onremove(){}onactivate(){}ondeactivate(){}addTo(e){e&&(this.renderer=e,e.controls[this.name]=this,this.onadd&&this.onadd(),e.isInitialized()&&!this._initialized&&(this._initialized=!0,this.oninit&&this.oninit(),this.autoActivate&&this.activate()))}remove(){this.deactivate(),this.onremove&&this.onremove();let e=this.renderer,t=this.name;if(!e)return;let i=e.controls[t];i&&this.isEqual(i)&&delete e.controls[t],this.renderer=null,this._active=!1,this._initialized=!1}activate(){this._active||(this._initialized||(this._initialized=!0,this.oninit&&this.oninit()),this._deferredActive?(this._active=!0,this.onactivate&&this.onactivate()):this._deferredActive=!0)}deactivate(){this._active?(this._active=!1,this.ondeactivate&&this.ondeactivate()):this._initialized||(this._deferredActive=!1)}isActive(){return this._active}isEqual(e){return e.__id===this.__id}}Dt.__counter__=0;class Ft extends Dt{constructor(e={}){super(e),this._heading=0,this._svg=null}oninit(){let e=new zt({classList:["og-map-button","og-compass-button"],icon:'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg\n xmlns:dc="http://purl.org/dc/elements/1.1/"\n xmlns:cc="http://creativecommons.org/ns#"\n xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"\n xmlns:svg="http://www.w3.org/2000/svg"\n xmlns="http://www.w3.org/2000/svg"\n xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"\n xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"\n viewBox="0 0 110.6 110.3"\n version="1.1"\n id="svg21"\n sodipodi:docname="aaa.svg"\n inkscape:version="0.92.3 (2405546, 2018-03-11)">\n <metadata\n id="metadata11">\n <rdf:RDF>\n <cc:Work\n rdf:about="">\n <dc:format>image/svg+xml</dc:format>\n <dc:type\n rdf:resource="http://purl.org/dc/dcmitype/StillImage" />\n </cc:Work>\n </rdf:RDF>\n </metadata>\n <defs\n id="defs25" />\n <sodipodi:namedview\n pagecolor="#ffffff"\n bordercolor="#666666"\n borderopacity="1"\n objecttolerance="10"\n gridtolerance="10"\n guidetolerance="10"\n inkscape:pageopacity="0"\n inkscape:pageshadow="2"\n inkscape:window-width="1920"\n inkscape:window-height="1001"\n id="namedview23"\n showgrid="false"\n inkscape:zoom="9.4900968"\n inkscape:cx="28.376998"\n inkscape:cy="60.17054"\n inkscape:window-x="-9"\n inkscape:window-y="-9"\n inkscape:window-maximized="1"\n inkscape:current-layer="svg21" />\n <g\n id="Layer_2"\n data-name="Layer 2"\n transform="matrix(1,0,0,-1,0,110.3)">\n <g\n id="Слой_1"\n data-name="Слой 1">\n <g\n id="_Group_"\n data-name="<Group>">\n <g\n id="_Group_7"\n data-name="<Group>">\n <polygon\n id="_Path_7"\n data-name="<Path>"\n points="55.2,97.6 55.3,97.4 55.3,97.6 55.3,97.2 65.3,55.1 55.3,55.1 55.2,55.1 45.3,55.1 55.2,97.2 "\n style="fill:#ff2b45" />\n <polygon\n id="_Path_8"\n data-name="<Path>"\n points="55.3,12.7 55.3,12.9 55.2,12.7 55.2,13.1 45.3,55.1 55.2,55.1 55.3,55.1 65.3,55.1 55.3,13.1 "\n style="fill:#cecece;" />\n </g>\n </g>\n </g>\n </g>\n</svg>'});e.appendTo(this.renderer.div),e.events.on("click",this._onClick,this),this._svg=e.select("svg"),this.renderer.events.on("draw",this._draw,this)}_onClick(){const e=this.planet;let t=e.getCartesianFromPixelTerrain(this.renderer.handler.getCenter());t?e.flyCartesian(t.normal().scaleTo(t.length()+t.distance(e.camera.eye)),null,null,0,null,null,(()=>{e.camera.look(t)})):e.flyCartesian(e.camera.eye)}_draw(){this.setHeading(this.planet.camera.getHeading())}setHeading(e){this._heading!==e&&(this._heading=e,this._svg.style.transform=`rotateZ(${-e}deg)`)}}const Nt='<svg className="svg-icon" style="width: 1em; height: 1em;vertical-align: middle;fill: currentColor; overflow: hidden;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg">\n <path d="M777.856 280.192l-33.92-33.952-231.872 231.872-231.84-231.872-33.984 33.888 231.872 231.904-231.84 231.84 33.888 33.984 231.904-231.904 231.84 231.872 33.952-33.888-231.872-231.904z"/>\n</svg>',Ht=["resize","focus","visibility","dragstart","dragend"];class Ot extends kt{constructor(e={}){super({template:we('<div class="og-ddialog" \n style="display:{display}; resize:{resize}; width: {width}px; {height}; top: {top}px; left: {left}px; min-height: {minHeight}; max-height: {maxHeight}; min-width: {minWidth}; max-width: {maxWidth};">\n <div class="og-ddialog-header">\n <div class="og-ddialog-header__title">{title}</div> \n <div class="og-ddialog-header__buttons"></div> \n </div>\n <div class="og-ddialog-container"></div>\n </div>>',{title:e.title||"",display:de(e.visible,!0)?"flex":"none",resize:de(e.resizable,!0)?"both":"none",width:e.width||300,height:e.height?`height: ${e.height||200}px`:"",left:e.left||0,top:e.top||0,minHeight:e.minHeight?`${e.minHeight}px`:"unset",maxHeight:e.maxHeight?`${e.maxHeight}px`:"unset",minWidth:e.minWidth?`${e.minWidth}px`:"unset",maxWidth:e.maxWidth?`${e.maxWidth}px`:"unset"}),...e}),this._onCloseBtnClick=()=>{this.close()},this._onMouseDownAll=()=>{this.bringToFront()},this._onMouseDown=e=>{e.preventDefault(),this._startDragging(),this._startPosX=e.clientX,this._startPosY=e.clientY,document.addEventListener("mousemove",this._onMouseMove),document.addEventListener("mouseup",this._onMouseUp)},this._onMouseMove=e=>{e.preventDefault();let t=this._startPosX-e.clientX,i=this._startPosY-e.clientY;this._startPosX=e.clientX,this._startPosY=e.clientY,this.setPosition(this.el.offsetLeft-t,this.el.offsetTop-i)},this._onMouseUp=()=>{this._clearDragging(),document.removeEventListener("mouseup",this._onMouseUp),document.removeEventListener("mousemove",this._onMouseMove)},this.events=this.events.registerNames(Ht),this._startPosX=0,this._startPosY=0,this.$header=null,this.$title=null,this.$container=null,this.$buttons=null,this._closeBtn=new zt({icon:Nt,classList:["og-button-size__20"]}),this.useHide=e.useHide||!1,this._visibility=de(e.visible,!0),this._right=null!=e.right?e.right:null}setContainer(e){this.$container.innerHTML=e}get container(){return this.$container}get width(){return this.el?parseFloat(this.el.style.width):0}get height(){return this.el?parseFloat(this.el.style.height):0}bringToFront(){this.el.style.zIndex=String(Ot.__zIndex__++)}render(e){if(super.render(e),this.bringToFront(),this.$header=this.select(".og-ddialog-header"),this.$title=this.select(".og-ddialog-header__title"),this.$container=this.select(".og-ddialog-container"),this.$buttons=this.select(".og-ddialog-header__buttons"),this._initEvents(),this._initButtons(),null!=this._right){this.el.style.visibility="hidden";new IntersectionObserver(((e,t)=>{e.forEach((e=>{e.isIntersecting&&(this.el.style.visibility="visible",this.el.parentNode&&(this.setPosition(this.el.parentNode.clientWidth-this.el.clientWidth-this._right),t.disconnect()))}))})).observe(this.el)}return this}show(){this._visibility||(this._visibility=!0,this.el.style.display="flex",this.bringToFront(),this.events.dispatch(this.events.visibility,!0,this))}hide(){this._visibility&&(this._visibility=!1,this.el.style.display="none",this.events.dispatch(this.events.visibility,!1,this))}close(){this.useHide?this.hide():this.remove()}setVisibility(e){e?this.show():this.hide()}getVisibility(){return this._visibility}_initButtons(){this._closeBtn.events.on("click",this._onCloseBtnClick),this._closeBtn.appendTo(this.$buttons)}_initEvents(){this.$header.addEventListener("mousedown",this._onMouseDown),this.el.addEventListener("mousedown",this._onMouseDownAll)}setPosition(e,t){null!=e&&(this.el.style.left=`${e}px`),null!=t&&(this.el.style.top=`${t}px`)}_startDragging(){this.el.classList.contains("dragging")||(this.el.classList.add("dragging"),this.events.dispatch(this.events.dragstart,this))}_clearDragging(){this.el.classList.contains("dragging")&&(this.events.dispatch(this.events.dragend,this),this.el.classList.remove("dragging"))}remove(){this._clearDragging(),this._clearEvents(),super.remove()}_clearEvents(){this._closeBtn.events.off("click",this._onCloseBtnClick),document.removeEventListener("mouseup",this._onMouseUp),document.removeEventListener("mousemove",this._onMouseMove),this.$header.removeEventListener("mousedown",this._onMouseDown),this.el.removeEventListener("mousedown",this._onMouseDownAll)}}Ot.__zIndex__=0;const Vt=["change"];class Ut extends zt{constructor(e){super({...e}),this._onMouseClick=e=>{this.preventClick||(this._mouseClickHandler(e),this.setActive(!this.isActive))},this.events=this.events.registerNames(Vt),this._isActive=e.isActive||!1,this.preventClick=e.preventClick||!1}setActive(e,t=!1){e!==this._isActive&&(this._isActive=e,this._toggle(),t||this.events.dispatch(this.events.change,e,this))}_toggle(){this.el&&this.el.classList.toggle("og-button__active")}get isActive(){return this._isActive}render(e){return super.render(e),this._isActive&&this._toggle(),this}}const Gt=[2,3,0,1],Yt=[[-1,-1,0,1],[1,-1,3,-1],[2,3,-1,-1],[-1,0,-1,2]],jt=[[2,3,0,1],[1,0,3,2],[2,3,0,1],[1,0,3,2]],Wt=[[0,1,0,0],[1,0,0,0],[0,1,0,1],[1,1,1,1]];class qt{constructor(e,t){this.segment=e,this.layer=t,this.isReady=!1,this.isLoading=!1,this.texture=null,this.pickingMask=null,this.textureExists=!1,this.appliedNodeId=0,this.appliedNode=null,this.texOffset=[0,0,1,1],this.loadingAttempts=0,this._updateTexture=null,this._updatePickingMask=null,this.pickingReady=!1}abortLoading(){this.layer.abortMaterialLoading(this)}_createTexture(e){return this.layer._planet&&this.layer.createTexture(e,this.layer._internalFormat,this.isReady?this.texture:null)}applyImage(e){this.segment.initialized&&(this._updateTexture=null,this.texture=this._createTexture(e),this.isReady=!0,this.pickingReady=!0,this.textureExists=!0,this.isLoading=!1,this.appliedNodeId=this.segment.node.nodeId,this.texOffset=[0,0,1,1])}applyTexture(e,t){this.segment.initialized&&(this.texture=e,this._updateTexture=null,this.pickingMask=t||null,this._updatePickingMask=null,this.isReady=!0,this.pickingReady=!0,this.textureExists=!0,this.isLoading=!1,this.appliedNodeId=this.segment.node.nodeId,this.texOffset=[0,0,1,1])}textureNotExists(){this.segment.initialized&&(this.pickingReady=!0,this.isLoading=!1,this.isReady=!0,this.textureExists=!1)}clear(){this.loadingAttempts=0,this.layer.clearMaterial(this)}}class $t{constructor(e,t={}){if(this.isVector=!1,this.__id=$t.__counter__++,this._iconSrc=t.iconSrc||null,this.events=Mt(Xt,this),this.name=e||"noname",this.properties=t.properties||{},this.hideInLayerSwitcher=t.hideInLayerSwitcher||!1,this._hasImageryTiles=!0,this._opacity=null!=t.opacity?t.opacity:1,this.minZoom=t.minZoom||0,this.maxZoom=null!=t.maxZoom?t.maxZoom:50,this._planet=null,this.isVector=!1,this._attribution=t.attribution||"",this._zIndex=t.zIndex||0,this._isBaseLayer=t.isBaseLayer||!1,this._defaultTextures=t.defaultTextures||[null,null],this._visibility=void 0===t.visibility||t.visibility,this._fading=t.fading||!1,this._fadingFactor=this._opacity/30,this._fading?this._fadingOpacity=0:this._fadingOpacity=this._opacity,this._height=t.height||0,this._extent=new te,this.createTexture=null,this._textureFilter=t.textureFilter?t.textureFilter.trim().toUpperCase():"MIPMAP",this._isSRGB=null!=t.isSRGB&&t.isSRGB,this._internalFormat=null,this._extentMerc=new te,this.setExtent(Me(t.extent,new te(new I(-180,-90),new I(180,90)))),this._pickingColor=new oe,this._pickingEnabled=void 0===t.pickingEnabled||t.pickingEnabled,this._isPreloadDone=!1,this._preLoadZoomLevels=t.preLoadZoomLevels||[0,1],this._ambient=null,this._diffuse=null,this._specular=null,t.ambient){let e=Se(t.ambient,new oe(.2,.2,.2));this._ambient=new Float32Array([e.x,e.y,e.z])}if(t.diffuse){let e=Se(t.diffuse,new oe(.8,.8,.8));this._diffuse=new Float32Array([e.x,e.y,e.z])}if(t.specular){let e=Se(t.specular,new oe(3e-4,3e-4,3e-4)),i=t.shininess||20;this._specular=new Float32Array([e.x,e.y,e.z,i])}this.nightTextureCoefficient=t.nightTextureCoefficient||1}get iconSrc(){return this._iconSrc}set iconSrc(e){this._iconSrc=e}set diffuse(e){if(e){let t=Se(e);this._diffuse=new Float32Array(t.toArray())}else this._diffuse=null}set ambient(e){if(e){let t=Se(e);this._ambient=new Float32Array(t.toArray())}else this._ambient=null}set specular(e){if(e){let t=Se(e);this._specular=new Float32Array([t.x,t.y,t.y,this._specular?this._specular[3]:0])}else this._specular=null}set shininess(e){this._specular&&(this._specular[3]=e)}static getTMS(e,t,i){return{x:e,y:(1<<i)-t-1,z:i}}static getTileIndex(e,t,i,s){return`${s}::${e}_${t}_${i}`}get instanceName(){return"Layer"}get rendererEvents(){return this.events}set opacity(e){e!==this._opacity&&(this._fading?e>this._opacity?this._fadingFactor=(e-this._opacity)/30:e<this._opacity&&(this._fadingFactor=(this._opacity-e)/30):this._fadingOpacity=e,this._opacity=e)}set pickingEnabled(e){this._pickingEnabled=e}get pickingEnabled(){return this._pickingEnabled}hasImageryTiles(){return this._hasImageryTiles}getID(){return this.__id}get id(){return this.__id}get _id(){return this.__id}isEqual(e){return e.__id===this.__id}_assignPlanet(e){this._planet=e,e._layers.push(this),e.renderer&&e.renderer.isInitialized()&&(this._isSRGB?this._internalFormat=e.renderer.handler.gl.SRGB8_ALPHA8:this._internalFormat=e.renderer.handler.gl.RGBA8,this.createTexture=e.renderer.handler.createTexture[this._textureFilter],this.events.on("visibilitychange",e._onLayerVisibilityChanged,e),this._isBaseLayer&&this._visibility&&e.setBaseLayer(this),e.events.dispatch(e.events.layeradd,this),this.events.dispatch(this.events.add,e),e.updateVisibleLayers(),this._bindPicking(),this._visibility&&this.hasImageryTiles()&&this._preLoad())}get isIdle(){return this._planet&&this._planet._terrainCompletedActivated||!1}_bindPicking(){this._planet&&this._planet.renderer&&this._planet.renderer.assignPickingColor(this)}addTo(e){this._planet||this._assignPlanet(e)}remove(){let e=this._planet;if(e)for(let t=0;t<e._layers.length;t++)if(this.isEqual(e._layers[t]))return e.renderer&&e.renderer.clearPickingColor(this),e._layers.splice(t,1),e.updateVisibleLayers(),this.clear(),e.events.dispatch(e.events.layerremove,this),this.events.dispatch(this.events.remove,e),this._planet=null,this._internalFormat=null,this.createTexture=null,this;return this}clear(){this._planet&&this._planet._clearLayerMaterial(this)}get planet(){return this._planet}setAttribution(e){this._attribution!==e&&(this._attribution=e,this._planet&&this._planet.updateAttributionsList())}getAttribution(){return this._attribution}setHeight(e){this._height=e,this._planet&&this._planet.updateVisibleLayers()}getHeight(){return this._height}setZIndex(e){this._zIndex=e,this._planet&&this._planet.updateVisibleLayers()}getZIndex(){return this._zIndex}bringToFront(){if(this._planet){let e=this._planet.visibleTileLayers,t=e[e.length-1];t.isEqual(this)||this.setZIndex(t.getZIndex()+1)}}isBaseLayer(){return this._isBaseLayer}setBaseLayer(e){this._isBaseLayer=e,this._planet&&(!e&&this._planet.baseLayer&&this.isEqual(this._planet.baseLayer)&&(this._planet.baseLayer=null),this._planet.updateVisibleLayers())}setVisibility(e){e!==this._visibility&&(this._visibility=e,this._planet&&(this._isBaseLayer&&e&&this._planet.setBaseLayer(this),this._planet.updateVisibleLayers(),!e||this._isPreloadDone||this.isVector||(this._isPreloadDone=!0,this._preLoad())),this.events.dispatch(this.events.visibilitychange,this))}_forceMaterialApply(e){let t=e.materials,i=t[this.__id];i||(i=t[this.__id]=this.createMaterial(e)),i.isReady||(this._planet._renderCompleted=!1),this.applyMaterial(i,!0)}clearMaterial(e){}loadMaterial(e,t=!1){}applyMaterial(e,t=!1){return[0,0,1,1]}_preLoadRecursive(e,t){if(!(e.segment.tileZoom>t)){this._preLoadZoomLevels.includes(e.segment.tileZoom)&&this._forceMaterialApply(e.segment);for(let i=0,s=e.nodes.length;i<s;i++)e.nodes[i]&&this._preLoadRecursive(e.nodes[i],t)}}_preLoad(){if(this._planet&&this._preLoadZoomLevels.length){let e=this._planet,t=Math.max(...this._preLoadZoomLevels);for(let i=0,s=e.quadTreeStrategy.quadTreeList.length;i<s;i++)this._preLoadRecursive(e.quadTreeStrategy.quadTreeList[i],t)}}getVisibility(){return this._visibility}setExtent(e){let t=e.southWest.clone(),i=e.northEast.clone();t.lat<J&&(t.lat=J),i.lat>Q&&(i.lat=Q),this._extent=e.clone(),this._extentMerc=new te(t.forwardMercator(),i.forwardMercator()),this._correctFullExtent()}getExtent(){return this._extent}getExtentMerc(){return this._extentMerc}flyExtent(){this._planet?.flyExtent(this.getExtent())}viewExtent(){this._planet?.viewExtent(this.getExtent())}_correctFullExtent(){}get opacity(){return this._opacity}get screenOpacity(){return this._fading?this._fadingOpacity:this._opacity}_refreshFadingOpacity(){let e=this._planet;return this._visibility&&e.getViewExtent().overlaps(this._extent)&&e.maxCurrZoom>=this.minZoom&&e.minCurrZoom<=this.maxZoom?(this._fadingOpacity+=this._fadingFactor,(this._fadingFactor>0&&this._fadingOpacity>this._opacity||this._fadingFactor<0&&this._fadingOpacity<this._opacity)&&(this._fadingOpacity=this._opacity),!1):(this._fadingOpacity-=this._fadingFactor,this._fadingOpacity<=0&&(this._fadingOpacity=0),!1)}createMaterial(e){return new qt(e,this)}redraw(){this._planet?.quadTreeStrategy.clearLayerMaterial(this)}abortMaterialLoading(e){}abortLoading(){}}$t.__counter__=0;const Xt=["visibilitychange","add","remove","mousemove","mouseenter","mouseleave","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchmove","touchstart","touchend","doubletouch","touchleave","touchenter"],Zt=["load","loadend"];class Kt extends $t{constructor(e,t){super(e,t),this.events=this.events.registerNames(Zt),this.animated=t.animated||!1,this.minNativeZoom=t.minNativeZoom||0,this.maxNativeZoom=t.maxNativeZoom||100,this._counter=0,this._pendingsQueue=[],this.drawTile=t.drawTile,this._onLoadend_=null}addTo(e){return this._onLoadend_=this._onLoadend.bind(this),this.events.on("loadend",this._onLoadend_,this),super.addTo(e)}remove(){return this.events.off("loadend",this._onLoadend_),this._onLoadend_=null,super.remove()}_onLoadend(){this._planet&&this._planet._terrainCompletedActivated&&this._planet.events.dispatch(this._planet.events.layerloadend,this)}get instanceName(){return"CanvasTiles"}get isIdle(){return super.isIdle&&0===this._counter}abortLoading(){this._pendingsQueue.forEach((e=>{this.abortMaterialLoading(e)})),this._pendingsQueue=[]}setVisibility(e){e!==this._visibility&&(super.setVisibility(e),e||this.abortLoading())}loadMaterial(e){let t=e.segment;this._isBaseLayer?e.texture=t.getDefaultTexture():e.texture=t.planet.transparentTexture,(this._planet.layerLock.isFree()||e.segment.tileZoom<2)&&(e.isReady=!1,e.isLoading=!0,Kt.__requestsCounter>=Kt.MAX_REQUESTS&&this._counter?this._pendingsQueue.push(e):this._exec(e))}_exec(e){Kt.__requestsCounter++,this._counter++;const t=this.events.load;t.handlers.length&&this.events.dispatch(t,e),requestAnimationFrame((()=>{this.drawTile(e,(t=>{this._counter--,Kt.__requestsCounter--,this._correctCounter(),e.isLoading&&e.applyImage(t),this._dequeueRequest()}))}))}_correctCounter(){this._counter<0&&(this._counter=0),Kt.__requestsCounter<0&&(Kt.__requestsCounter=0)}abortMaterialLoading(e){e.isLoading&&(this._counter--,Kt.__requestsCounter--,this._correctCounter(),this._dequeueRequest()),e.isLoading=!1,e.isReady=!1}_dequeueRequest(){if(this._pendingsQueue.length){if(Kt.__requestsCounter<Kt.MAX_REQUESTS){const e=this._whilePendings();e&&this._exec(e)}}else 0===this._counter&&this._planet&&this._planet._terrainCompletedActivated&&this.events.dispatch(this.events.loadend)}_whilePendings(){for(;this._pendingsQueue.length;){const e=this._pendingsQueue.pop();if(e&&e.segment&&e.segment.node){if(e.segment.initialized&&1===e.segment.node.getState())return e;e.isLoading=!1}}return null}applyMaterial(e){if(e.isReady)return e.layer.animated&&requestAnimationFrame((()=>{this.drawTile(e,(function(t){e.applyImage(t)}))})),e.texOffset;if(e.segment.tileZoom<this.minNativeZoom)e.textureNotExists();else{let t=e.segment,i=t.node,s=!1,n=e.layer.maxNativeZoom;t.passReady&&!e.isLoading&&t.tileZoom<=n&&this.loadMaterial(e);let r=this._id,o=e;for(;i.parentNode;)if(i=i.parentNode,o=i.segment.materials[r],o&&o.textureExists){s=!0;break}if(t.passReady)if(i.segment.tileZoom===n)t.tileZoom>n&&e.textureNotExists();else if(i.segment.tileZoom<n){let i=t.node;for(;i.segment.tileZoom>n;)i=i.parentNode;let s=i.segment.materials[r];s?!s.isLoading&&!s.isReady&&this.loadMaterial(s):(s=i.segment.materials[e.layer._id]=e.layer.createMaterial(i.segment),this.loadMaterial(s))}if(s){e.layer.animated&&requestAnimationFrame((()=>{this.drawTile(e,(function(t){e.applyImage(t)}))})),e.appliedNodeId=i.nodeId,e.texture=o.texture;let s=1/(2<<t.tileZoom-i.segment.tileZoom-1);e.texOffset[0]=t.tileX*s-i.segment.tileX,e.texOffset[1]=t.tileY*s-i.segment.tileY,e.texOffset[2]=s,e.texOffset[3]=s}else e.texture=t.planet.transparentTexture,e.texOffset[0]=0,e.texOffset[1]=0,e.texOffset[2]=1,e.texOffset[3]=1}return e.texOffset}clearMaterial(e){e.isReady&&(e.isReady=!1,e.textureExists&&e.texture&&!e.texture.default&&(e.segment.handler.gl.deleteTexture(e.texture),e.texture=null)),this.abortMaterialLoading(e),e.isLoading=!1,e.textureExists=!1,e.layer=null,e.segment=null}}Kt.MAX_REQUESTS=20,Kt.__requestsCounter=0;const Qt=["change"];class Jt{constructor(e={}){this._onChange=(e,t)=>{if(e){t.preventClick=!0;for(let e=0;e<this._buttons.length;e++){let i=this._buttons[e];i.isEqual(t)||(i.setActive(!1),i.preventClick=!1)}this.events.dispatch(this.events.change,t)}},this.events=Mt(Qt),this._buttons=e.buttons||[];for(let e=0;e<this._buttons.length;e++)this._bindButton(this._buttons[e])}_bindButton(e){e.events.on("change",this._onChange)}add(e){this._buttons.push(e),this._bindButton(e)}remove(e){for(let t=0;t<this._buttons.length;t++)if(this._buttons[t].isEqual(e))return this._buttons.splice(t),void e.events.off("change",this._onChange)}}class ei{constructor(e=2,t){this._sourceId=0,this._source=new Map,this._pendingQueue=[],this._numWorkers=e,this._workerQueue=[],t&&this.setProgram(t)}check(){this._pendingQueue.length&&this.make(this._pendingQueue.pop())}setProgram(e){let t=new Blob([e],{type:"application/javascript"});for(let e=0;e<this._numWorkers;e++){let e=new Worker(URL.createObjectURL(t));e.onmessage=e=>{this._onMessage(e),this._workerQueue&&this._workerQueue.unshift(e.target),this.check()},this._workerQueue.push(e)}}make(e){}_onMessage(e){}destroy(){for(let e=0;e<this._workerQueue.length;e++){const t=this._workerQueue[e];t.onmessage=null,t.terminate()}this._pendingQueue=null,this._workerQueue=null}get pendingQueue(){return this._pendingQueue}}const ti=-2,ii=-1;class si extends ei{constructor(e=4){super(e,ni)}_onMessage(e){let t=this._source.get(e.data.id);t.label._lockId===ti?requestAnimationFrame((()=>{this.make({handler:t.handler,label:t.label})})):t.handler.workerCallback(e.data,t.label),this._source.delete(e.data.id)}make(e){let t=e.label;if(e.handler._entityCollection){let i=t.serializeWorkerData(this._sourceId);if(i)if(this._workerQueue.length){let s=this._workerQueue.pop();this._source.set(this._sourceId,e),t._lockId=this._sourceId,this._sourceId++,s.postMessage({labelData:i},[i.buffer])}else this._pendingQueue.push(e)}}}const ni="'use strict';\n\n function concatTypedArrays(dest, index, source) {\n let len = source.length,\n offset = index * len;\n for(let i = 0; i < len; i++) {\n dest[offset + i] = source[i];\n }\n }\n\n self.onmessage = function (e) {\n var labelData = e.data.labelData,\n id = labelData[0],\n maxLetters = labelData[1],\n isVisible = labelData[2],\n /*3, 4, 5*/_positionHigh_x = labelData[3], _positionHigh_y = labelData[4], _positionHigh_z = labelData[5],\n /*6, 7, 8*/_positionLow_x = labelData[6], _positionLow_y = labelData[7], _positionLow_z = labelData[8],\n /*9*/_size = labelData[9],\n /*10, 11, 12*/_offset_x = labelData[10], _offset_y = labelData[11], _offset_z = labelData[12],\n /*13, 14, 15, 16*/_color_x = labelData[13], _color_y = labelData[14], _color_z = labelData[15], _color_w = labelData[16],\n /*17*/_rotation = labelData[17],\n /*18, 19, 20*/_alignedAxis_x = labelData[18], _alignedAxis_y = labelData[19], _alignedAxis_z = labelData[20],\n /*21*/_fontIndex = labelData[21],\n /*22*/_outline = labelData[22],\n /*23, 24, 25, 26*/_outlineColor_x = labelData[23], _outlineColor_y = labelData[24], _outlineColor_z = labelData[25], _outlineColor_w = labelData[26],\n /*27, 28, 29*/_pickingColor_x = labelData[27], _pickingColor_y = labelData[28], _pickingColor_z = labelData[29]\n \n\n let _vertexArr = new Float32Array(maxLetters * 12),\n _texCoordArr = new Float32Array(maxLetters * 24),\n _gliphParamArr = new Float32Array(maxLetters * 24),\n _positionHighArr = new Float32Array(maxLetters * 18),\n _positionLowArr = new Float32Array(maxLetters * 18),\n _sizeArr = new Float32Array(maxLetters * 6),\n _offsetArr = new Float32Array(maxLetters * 18),\n _rgbaArr = new Float32Array(maxLetters * 24),\n _rotationArr = new Float32Array(maxLetters * 6),\n _alignedAxisArr = new Float32Array(maxLetters * 18),\n _fontIndexArr = new Float32Array(maxLetters * 6),\n _outlineArr = new Float32Array(maxLetters * 6),\n _outlineColorArr = new Float32Array(maxLetters * 24),\n _pickingColorArr = new Float32Array(maxLetters * 18);\n \n for (let i = 0; i < maxLetters; i++) {\n if (isVisible !== 0) {\n concatTypedArrays(_vertexArr, i, [0, 0, 0, -1, 1, -1, 1, -1, 1, 0, 0, 0]);\n } else {\n concatTypedArrays(_vertexArr, i, [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]);\n }\n\n concatTypedArrays(_texCoordArr, i, [0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 0, -1, 0]);\n concatTypedArrays(_gliphParamArr, i, [1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0, 1, 1, 0, 0]);\n\n var x = _positionHigh_x, y = _positionHigh_y, z = _positionHigh_z, w;\n concatTypedArrays(_positionHighArr, i, [x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y, z]);\n\n x = _positionLow_x; y = _positionLow_y; z = _positionLow_z;\n concatTypedArrays(_positionLowArr, i, [x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y, z]);\n\n x = _size;\n concatTypedArrays(_sizeArr, i, [x, x, x, x, x, x]);\n\n x = _offset_x; y = _offset_y; z = _offset_z;\n concatTypedArrays(_offsetArr, i, [x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y, z]);\n\n x = _color_x; y = _color_y; z = _color_z; w = _color_w;\n concatTypedArrays(_rgbaArr, i, [x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w]);\n\n x = _rotation;\n concatTypedArrays(_rotationArr, i, [x, x, x, x, x, x]);\n\n x = _alignedAxis_x; y = _alignedAxis_y; z = _alignedAxis_z;\n concatTypedArrays(_alignedAxisArr, i, [x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y, z]);\n\n x = _fontIndex;\n concatTypedArrays(_fontIndexArr, i, [x, x, x, x, x, x]);\n\n x = _outline;\n concatTypedArrays(_outlineArr, i, [x, x, x, x, x, x]);\n\n x = _outlineColor_x; y = _outlineColor_y; z = _outlineColor_z; w = _outlineColor_w;\n concatTypedArrays(_outlineColorArr, i, [x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w, x, y, z, w]);\n\n x = _pickingColor_x / 255; y = _pickingColor_y / 255; z = _pickingColor_z / 255;\n concatTypedArrays(_pickingColorArr, i, [x, y, z, x, y, z, x, y, z, x, y, z, x, y, z, x, y, z]);\n }\n\n self.postMessage({\n id: id,\n vertexArr: _vertexArr,\n texCoordArr: _texCoordArr,\n gliphParamArr: _gliphParamArr,\n positionHighArr: _positionHighArr,\n positionLowArr: _positionLowArr,\n sizeArr: _sizeArr,\n offsetArr: _offsetArr,\n rgbaArr: _rgbaArr,\n rotationArr: _rotationArr,\n alignedAxisArr: _alignedAxisArr,\n fontIndexArr: _fontIndexArr,\n outlineArr: _outlineArr,\n outlineColorArr: _outlineColorArr,\n pickingColorArr: _pickingColorArr\n }, [\n _vertexArr.buffer,\n _texCoordArr.buffer,\n _gliphParamArr.buffer,\n _positionHighArr.buffer,\n _positionLowArr.buffer,\n _sizeArr.buffer,\n _offsetArr.buffer,\n _rgbaArr.buffer,\n _rotationArr.buffer,\n _alignedAxisArr.buffer,\n _fontIndexArr.buffer,\n _outlineArr.buffer,\n _outlineColorArr.buffer,\n _pickingColorArr.buffer\n ]);\n }";class ri{constructor(e={}){this.__id=ri.__counter__++,this._position=Ae(e.position),this._positionHigh=new oe,this._positionLow=new oe,oe.doubleToTwoFloats(this._position,this._positionHigh,this._positionLow),this._rotation=e.rotation||0,this._color=Pe(e.color),this._alignedAxis=Ae(e.alignedAxis),this._offset=Ae(e.offset),this._visibility=null==e.visibility||e.visibility,this._entity=null,this._handler=null,this._handlerIndex=-1,this._isReady=!1,this._lockId=ii}setPosition(e,t,i){this._position.x=e,this._position.y=t,this._position.z=i,oe.doubleToTwoFloats(this._position,this._positionHigh,this._positionLow),this._isReady&&this._handler?this._handler.setPositionArr(this._handlerIndex,this._positionHigh,this._positionLow):this._lockId!==ii&&(this._lockId=ti)}setPosition3v(e){this._position.x=e.x,this._position.y=e.y,this._position.z=e.z,oe.doubleToTwoFloats(e,this._positionHigh,this._positionLow),this._isReady&&this._handler?this._handler.setPositionArr(this._handlerIndex,this._positionHigh,this._positionLow):this._lockId!==ii&&(this._lockId=ti)}getPosition(){return this._position}setOffset(e,t,i){this._offset.x=e,this._offset.y=t,null!=i&&(this._offset.z=i),this._isReady&&this._handler?this._handler.setOffsetArr(this._handlerIndex,this._offset):this._lockId!==ii&&(this._lockId=ti)}setOffset3v(e){this.setOffset(e.x,e.y,e.z)}getOffset(){return this._offset}setRotation(e){e!==this._rotation&&(this._rotation=e,this._isReady&&this._handler?this._handler.setRotationArr(this._handlerIndex,e):this._lockId!==ii&&(this._lockId=ti))}getRotation(){return this._rotation}setOpacity(e){e!==this._color.w&&(null!=e&&(this._color.w=e),this._isReady&&this._handler?this._handler.setRgbaArr(this._handlerIndex,this._color):this._lockId!==ii&&(this._lockId=ti))}setColor(e,t,i,s){s===this._color.w&&e===this._color.x&&t===this._color.y&&this._color.z===i||(this._color.x=e,this._color.y=t,this._color.z=i,null!=s&&(this._color.w=s),this._isReady&&this._handler?this._handler.setRgbaArr(this._handlerIndex,this._color):this._lockId!==ii&&(this._lockId=ti))}setColor4v(e){this.setColor(e.x,e.y,e.z,e.w)}setColorHTML(e){this.setColor4v(ye(e))}getColor(){return this._color}setVisibility(e){e!==this._visibility&&(this._visibility=e,this._isReady&&this._handler?this._handler.setVisibility(this._handlerIndex,e):this._lockId!==ii&&(this._lockId=ti))}getVisibility(){return this._visibility}setAlignedAxis(e,t,i){this._alignedAxis.x=e,this._alignedAxis.y=t,this._alignedAxis.z=i,this._isReady&&this._handler?this._handler.setAlignedAxisArr(this._handlerIndex,this._alignedAxis):this._lockId!==ii&&(this._lockId=ti)}setAlignedAxis3v(e){this.setAlignedAxis(e.x,e.y,e.z)}getAlignedAxis(){return this._alignedAxis}remove(){this._entity=null,this._handler&&this._handler.remove(this)}setPickingColor3v(e){this._isReady&&this._handler?this._handler.setPickingColorArr(this._handlerIndex,e):this._lockId!==ii&&(this._lockId=ti)}serializeWorkerData(e){return this._handler?new Float32Array([]):null}}ri.__counter__=0;class oi extends ri{constructor(e={}){super(e),this._handler=null,this._src=e.src||null,this._image=e.image||null,this._scale=1,this._width=e.width||(e.size?e.size[0]:30),this._height=e.height||(e.size?e.size[1]:30)}setSrc(e){this._src=e;let t=this._handler;if(t&&e&&e.length){let i=t._entityCollection.renderNode;if(i&&i.renderer){let s=i.renderer.billboardsTextureAtlas,n=this;s.loadImage(e,(function(e){null!=e.__nodeIndex&&s.get(e.__nodeIndex)?(n._image=e,t.setTexCoordArr(n._handlerIndex,s.get(n._image.__nodeIndex).texCoords)):(s.addImage(e),s.createTexture(),n._image=e,i.updateBillboardsTexCoords())}))}}}getSrc(){return this._src}setImage(e){this.setSrc(e.src)}getImage(){return this._image}setSize(e,t){this._width=e,this._height=t,this._handler&&this._handler.setSizeArr(this._handlerIndex,e*this._scale,t*this._scale)}getSize(){return{width:this._width,height:this._height}}setWidth(e){this.setSize(e,this._height)}getWidth(){return this._width}setHeight(e){this.setSize(this._width,e)}getHeight(){return this._height}}var ai;e.GeometryTypeEnum=void 0,(ai=e.GeometryTypeEnum||(e.GeometryTypeEnum={}))[ai.POINT=1]="POINT",ai[ai.LINESTRING=2]="LINESTRING",ai[ai.POLYGON=3]="POLYGON",ai[ai.MULTIPOLYGON=4]="MULTIPOLYGON",ai[ai.MULTILINESTRING=5]="MULTILINESTRING";const li={POINT:1,LINESTRING:2,POLYGON:3,MULTIPOLYGON:4,MULTILINESTRING:5};class hi{constructor(t={}){this.__id=hi.__counter__++,this._entity=null,this._handler=null,this._handlerIndex=-1,this._polyVerticesHighMerc=[],this._polyVerticesLowMerc=[],this._polyVerticesLength=-1,this._polyIndexesLength=-1,this._polyVerticesHandlerIndex=-1,this._polyIndexesHandlerIndex=-1,this._lineVerticesHighMerc=[],this._lineVerticesLowMerc=[],this._lineVerticesLength=-1,this._lineOrdersLength=-1,this._lineIndexesLength=-1,this._lineColorsLength=-1,this._lineThicknessLength=-1,this._lineVerticesHandlerIndex=-1,this._lineOrdersHandlerIndex=-1,this._lineIndexesHandlerIndex=-1,this._lineThicknessHandlerIndex=-1,this._lineColorsHandlerIndex=-1,this._type=t.type&&hi.getType(t.type)||e.GeometryTypeEnum.POINT,this._coordinates=t.coordinates||[],this._extent=hi.getExtent({type:t.type||"POINT",coordinates:t.coordinates||[]},this._coordinates),t.style=t.style||{},this._style={fillColor:Pe(t.style.fillColor,new se(.19,.62,.85,.4)),lineColor:Pe(t.style.lineColor,new se(.19,.62,.85,1)),strokeColor:Pe(t.style.strokeColor,new se(1,1,1,.95)),lineWidth:t.style.lineWidth||3,strokeWidth:t.style.strokeWidth||0},this._visibility=t.visibility||!0,this._pickingReady=!1}get id(){return this.__id}get type(){return this._type}static getType(e){return li[e.toUpperCase()]}static getExtent(t,i){let s=new te(new I(180,90),new I(-180,-90)),n=hi.getType(t.type);if(n===e.GeometryTypeEnum.POINT){let e=t.coordinates[0],n=t.coordinates[1];s.southWest.lon=e,s.southWest.lat=n,s.northEast.lon=e,s.northEast.lat=n,i&&(i[0]=e)&&(i[1]=n)}else if(n===e.GeometryTypeEnum.LINESTRING){let e=t.coordinates;for(let t=0;t<e.length;t++){let n=e[t][0],r=e[t][1];n<s.southWest.lon&&(s.southWest.lon=n),r<s.southWest.lat&&(s.southWest.lat=r),n>s.northEast.lon&&(s.northEast.lon=n),r>s.northEast.lat&&(s.northEast.lat=r),i&&(i[t]=[n,r])}}else if(n===e.GeometryTypeEnum.POLYGON){let e=t.coordinates;for(let t=0;t<e.length;t++){let n=e[t];i&&(i[t]=[]);for(let e=0;e<n.length;e++){let r=n[e],o=r[0],a=r[1];o<s.southWest.lon&&(s.southWest.lon=o),a<s.southWest.lat&&(s.southWest.lat=a),o>s.northEast.lon&&(s.northEast.lon=o),a>s.northEast.lat&&(s.northEast.lat=a),i&&(i[t][e]=[o,a])}}}else if(n===e.GeometryTypeEnum.MULTIPOLYGON){let e=t.coordinates;for(let t=0;t<e.length;t++){let n=e[t];i&&(i[t]=[]);for(let e=0;e<n.length;e++){let r=n[e];i&&(i[t][e]=[]);for(let n=0;n<r.length;n++){let o=r[n],a=o[0],l=o[1];a<s.southWest.lon&&(s.southWest.lon=a),l<s.southWest.lat&&(s.southWest.lat=l),a>s.northEast.lon&&(s.northEast.lon=a),l>s.northEast.lat&&(s.northEast.lat=l),i&&(i[t][e][n]=[a,l])}}}}else if(n===e.GeometryTypeEnum.MULTILINESTRING){let e=t.coordinates;for(let t=0;t<e.length;t++){let n=e[t];i&&(i[t]=[]);for(let e=0;e<n.length;e++){let r=n[e],o=r[0],a=r[1];o<s.southWest.lon&&(s.southWest.lon=o),a<s.southWest.lat&&(s.southWest.lat=a),o>s.northEast.lon&&(s.northEast.lon=o),a>s.northEast.lat&&(s.northEast.lat=a),i&&(i[t][e]=[o,a])}}}else s.southWest.lon=s.southWest.lat=s.northEast.lon=s.northEast.lat=0,i&&(i[0]=0)&&(i[1]=0);return s}setGeometry(e){let t=this._handler;return t&&(this.remove(),this._type=hi.getType(e.type||"Point"),this._extent=hi.getExtent(e,this._coordinates),t.add(this)),this}setFillColor(e,t,i,s=1){let n=this._style.fillColor;return(0===n.w&&0!==s||0!==n.w&&0===s)&&(this._pickingReady=!1),n.x=e,n.y=t,n.z=i,n.w=s,this._handler&&this._handler.setPolyColorArr(this,n),this}overlaps(e){return this._extent.overlaps(e)}setFillColor4v(e){return this.setFillColor(e.x,e.y,e.z,e.w)}setStrokeColor(e,t,i,s=1){let n=this._style.strokeColor;return(0===n.w&&0!==s||0!==n.w&&0===s)&&(this._pickingReady=!1),n.x=e,n.y=t,n.z=i,n.w=s,this._handler&&this._handler.setLineStrokeColorArr(this,n),this}setLineColor(e,t,i,s=1){let n=this._style.lineColor;return(0===n.w&&0!==s||0!==n.w&&0===s)&&(this._pickingReady=!1),n.x=e,n.y=t,n.z=i,n.w=s,this._handler&&this._handler.setLineColorArr(this,n),this}setStrokeColor4v(e){return this.setStrokeColor(e.x,e.y,e.z,e.w)}setLineColor4v(e){return this.setLineColor(e.x,e.y,e.z,e.w)}setStrokeOpacity(e){let t=this._style.strokeColor;return t.w=e,this.setStrokeColor(t.x,t.y,t.z,e)}setLineOpacity(e){let t=this._style.lineColor;return t.w=e,this.setLineColor(t.x,t.y,t.z,e)}setStrokeWidth(e){return this._style.strokeWidth=e,this._pickingReady=!1,this._handler&&this._handler.setLineStrokeArr(this,e),this}bringToFront(){return this._handler&&this._handler.bringToFront(this),this}setLineWidth(e){return this._style.lineWidth=e,this._pickingReady=!1,this._handler&&this._handler.setLineThicknessArr(this,e),this}setFillOpacity(e){let t=this._style.fillColor;return(0===t.w&&0!==e||0!==t.w&&0===e)&&(this._pickingReady=!1),t.w=e,this._handler&&this._handler.setPolyColorArr(this,t),this}setVisibility(e){return this._visibility=e,this._handler&&this._handler.setGeometryVisibility(this),this}getVisibility(){return this._visibility}remove(){this._handler&&this._handler.remove(this)}getExtent(){return this._extent.clone()}getType(){return this._type}}hi.__counter__=0;class ci{constructor(e=0,t=0,i=0){this.a=e,this.b=t,this.c=i}static get(e,t){return new ci(t.y-e.y,e.x-t.x,t.x*e.y-e.x*t.y)}static getParallel(e,t){return new ci(e.a,e.b,-e.a*t.x-e.b*t.y)}static getIntersection(e,t){let i=(t.b*e.c-e.b*t.c)/(e.b*t.a-t.b*e.a);return new ae(i,-(e.c+e.a*i)/e.b)}intersects(e){return ci.getIntersection(this,e)}}class di{constructor(e,t){this.p0=e||new oe,this.p1=t||new oe}getMagnitude(){return this.p0.distance(this.p1)}getSphereIntersection(e){let t=this.p0,i=this.p1,s=e.center.x,n=e.center.y,r=e.center.z,o=t.x,a=t.y,l=t.z,h=i.x-o,c=i.y-a,d=i.z-l,_=h*h+c*c+d*d,u=2*(o*h+a*c+l*d-h*s-c*n-d*r),g=u*u-4*_*(o*o-2*o*s+s*s+a*a-2*a*n+n*n+l*l-2*l*r+r*r-e.radius*e.radius);if(g<0)return[];let f=(-u-Math.sqrt(g))/(2*_),p=new oe(t.x*(1-f)+f*i.x,t.y*(1-f)+f*i.y,t.z*(1-f)+f*i.z);if(0==g)return[p];let m=(-u+Math.sqrt(g))/(2*_),v=new oe(t.x*(1-m)+m*i.x,t.y*(1-m)+m*i.y,t.z*(1-m)+m*i.z);return Math.abs(f-.5)<Math.abs(m-.5)?[p,v]:[v,p]}intersects(e,t,i){let s=this.p0.sub(e.p0),n=e.p1.sub(e.p0);if(Math.abs(n.x)<g&&Math.abs(n.y)<g&&Math.abs(n.z)<g)return!1;let r=this.p1.sub(this.p0);if(Math.abs(r.x)<g&&Math.abs(r.y)<g&&Math.abs(r.z)<g)return!1;let o=s.x*n.x+s.y*n.y+s.z*n.z,a=n.x*r.x+n.y*r.y+n.z*r.z,l=s.x*r.x+s.y*r.y+s.z*r.z,h=n.x*n.x+n.y*n.y+n.z*n.z,c=(r.x*r.x+r.y*r.y+r.z*r.z)*h-a*a;if(Math.abs(c)<g)return!1;let d=(o*a-l*h)/c;if(t.x=this.p0.x+d*r.x,t.y=this.p0.y+d*r.y,t.z=this.p0.z+d*r.z,i){let t=(o+a*d)/h;i.x=e.p0.x+t*n.x,i.y=e.p0.y+t*n.y,i.z=e.p0.z+t*n.z}return!0}getNearestDistancePoint(e,t){let i=this.p0,s=this.p1,n=this.getMagnitude(),r=((e.x-i.x)*(s.x-i.x)+(e.y-i.y)*(s.y-i.y)+(e.z-i.z)*(s.z-i.z))/(n*n);return t.x=i.x+r*(s.x-i.x),t.y=i.y+r*(s.y-i.y),t.z=i.z+r*(s.z-i.z),!(r<0||r>1)}}class _i{constructor(e,t){this.p=e?e.clone():new oe,this.n=t?t.clone():this.p.isZero()?oe.UP:this.p.getNormal()}setByPoints(e,t,i){let s=oe.sub(t,e),n=oe.sub(i,e);return this.n=s.cross(n),this.p.copy(e),this}static fromPoints(e,t,i){return(new _i).setByPoints(e,t,i)}set(e,t){this.p.copy(e),this.n.copy(t)}getNormal(){return this.n.clone()}distance(e){let t=this.getProjection(e);return e.distance(t)}getProjection(e,t){return oe.proj_b_to_plane(e,this.n,t)}getProjectionPoint(e,t){let i=e.sub(this.p),s=this.n,n=i.dot(s);return t?t.copy(s.scale(n)):t=s.scale(n),e.sub(t)}getIntersection(e,t,i){let s,n=e.n.cross(t.n),r=n.x>=0?n.x:-n.x,o=n.y>=0?n.y:-n.y,a=n.z>=0?n.z:-n.z;if(r+o+a<u){let i=t.p.sub(e.p);return 0==e.n.dot(i)?1:0}s=r>o?r>a?1:3:o>a?2:3;let l,h,c=new oe;return l=-e.n.dot(e.p),h=-t.n.dot(t.p),1===s?(c.x=0,c.y=(h*e.n.z-l*t.n.z)/n.x,c.z=(l*t.n.y-h*e.n.y)/n.x):2===s?(c.x=(l*t.n.z-h*e.n.z)/n.y,c.y=0,c.z=(h*e.n.x-l*t.n.x)/n.y):3===s&&(c.x=(h*e.n.y-l*t.n.y)/n.z,c.y=(l*t.n.x-h*e.n.x)/n.z,c.z=0),i.p0.copy(c),i.p1.copy(c.add(n)),2}}let ui=class e{constructor(e=oe.ZERO,t=oe.ZERO){this.origin=e,this.direction=t}static get OUTSIDE(){return 0}static get INSIDE(){return 1}static get INPLANE(){return 2}static get AWAY(){return 3}set(e,t){return this.origin=e,this.direction=t,this}getPoint(e){return oe.add(this.origin,this.direction.scaleTo(e))}hitTriangleRes(t,i,s,n){let r=i.sub(t),o=s.sub(t),a=r.cross(o),l=this.origin.sub(t),h=-a.dot(l),c=a.dot(this.direction);if(Math.abs(c)<g)return 0===h?(n.copy(this.origin),e.INPLANE):e.OUTSIDE;let d=h/c;if(n.copy(this.origin.add(this.direction.scaleTo(d))),d<0)return e.AWAY;let _=r.dot(r),u=r.dot(o),f=o.dot(o),p=n.sub(t),m=p.dot(r),v=p.dot(o),y=u*u-_*f,x=(u*v-f*m)/y;if(x<0||x>1)return e.OUTSIDE;let b=(u*m-_*v)/y;return b<0||x+b>1?e.OUTSIDE:e.INSIDE}hitPlaneRes(t,i){const s=this.direction.dot(t.n);if(Math.abs(s)<g)return e.OUTSIDE;const n=t.p.sub(this.origin).dot(t.n)/s;return n<0?e.AWAY:(i.copy(this.getPoint(n)),e.INSIDE)}hitSphere(e){let t=e.radius,i=e.center,s=this.origin,n=this.direction,r=oe.sub(i,s);if(r.dot(n)<0){var o=r.length();if(o>t)return null;if(o===t)return s.clone();let e=i.projToRay(s,r);var a=oe.sub(e,i).length();let l=Math.sqrt(t*t-a*a)-oe.sub(e,s).length();return oe.add(s,n.scaleTo(l))}{let o=i.projToRay(s,n);var l=oe.sub(i,o).length();if(l>e.radius)return null;{let e,i=Math.sqrt(t*t-l*l);return o.subA(s),e=r.length()>t?o.length()-i:o.length()+i,oe.add(s,n.scaleTo(e))}}}hitBox(e){}};function gi(e){let t=e.split("/"),i=t[t.length-1],s=t[t.length-2];return`${s?s+"/":""}${i}`}class fi{constructor(){this.objPositions=[],this.objTexcoords=[],this.objNormals=[],this.objVertexData=[this.objPositions,this.objTexcoords,this.objNormals],this.vertexData=[[],[],[]],this._materialLibs=[],this.geometries=[],this.geometry=null,this.materials={},this.material={},this.object="default",this.groups=["default"],this._path="",this.keywords={v:e=>{this.objPositions.push(e.map(parseFloat))},vn:e=>{this.objNormals.push(e.map(parseFloat))},vt:e=>{this.objTexcoords.push([parseFloat(e[0]),1-parseFloat(e[1])])},f:e=>{this.setGeometry();const t=e.length-2;for(let i=0;i<t;++i)this.addVertex(e[0]),this.addVertex(e[i+1]),this.addVertex(e[i+2])},s:()=>{},mtllib:(e,t)=>{this._materialLibs.push(t)},usemtl:(e,t)=>{this.newGeometry(),this.setGeometry(),this.geometry&&(this.geometry.material=t)},g:e=>{this.groups=e,this.newGeometry()},o:(e,t)=>{this.object=t,this.newGeometry()},newmtl:(e,t)=>{const i={};this.material=i,this.materials[t]=i},Ns:(e,t)=>{this.material.shininess=parseFloat(t)},Ni:(e,t)=>{},Ka:(e,t)=>{this.material.ambient=e.map((e=>parseFloat(e)))},Kd:(e,t)=>{this.material.diffuse=e.map((e=>parseFloat(e)))},Ks:(e,t)=>{this.material.specular=e.map((e=>parseFloat(e)))},Ke:(e,t)=>{this.material.color=e.map((e=>parseFloat(e)))},illum:(e,t)=>{this.material.illum=parseFloat(t)},d:(e,t)=>{this.material.opacity=parseFloat(t)},Tr:(e,t)=>{this.material.opacity=parseFloat(t)},Tf:(e,t)=>{},map_Ka:(e,t)=>{},map_Kd:(e,t)=>{this.material.colorTexture=`${this._path}/${gi(t)}`},map_Bump:(e,t)=>{this.material.normalTexture=`${this._path}/${gi(t)}`},map_Ns:(e,t)=>{this.material.metallicRoughnessTexture=`${this._path}/${gi(t)}`}}}newGeometry(){this.geometry&&this.geometry.data.vertices.length&&(this.geometry=null)}setGeometry(){if(!this.geometry){const e=[],t=[],i=[];this.vertexData=[e,t,i],this.geometry={object:this.object,groups:this.groups,material:"",data:{vertices:e,texCoords:t,normals:i}},this.geometries.push(this.geometry)}}addVertex(e){let t=e.split("/");for(let e=0;e<t.length;e++){let i=t[e];if(!i)continue;let s=parseInt(i)-1,n=this.vertexData[e],r=n.length,o=this.objVertexData[e][s],a=o.length;this.vertexData[e].length=r+a;for(let e=0;e<a;e++)n[r+e]=o[e]}}_innerParser(e,t){const i=/(\w*)(?: )*(.*)/,s=e.split("\n");for(let e=0;e<s.length;++e){const n=s[e].trim();if(""===n||n.startsWith("#"))continue;const r=i.exec(n);if(!r)continue;const[,o,a]=r,l=n.split(/\s+/).slice(1),h=this.keywords[o];h?h(l,a):console.warn(`Unknown keyword '${o}' in '${t}:${e}'`)}}get data(){return{geometries:this.geometries,materials:this.materials}}async load(e){this._path=e.substring(0,e.lastIndexOf("/"));const t=await fetch(e);if(!t.ok)throw new Error(`Unable to load '${e}'`);const i=t.body.getReader(),s=new TextDecoder;let{value:n,done:r}=await i.read(),o="";for(;!r;){const t=(o+s.decode(n,{stream:!0})).split("\n");o=t.pop();for(const i of t)this._innerParser(i,e);({value:n,done:r}=await i.read())}o&&this._innerParser(o,e),this._cleanupGeometryArrays();let a=this._materialLibs.map((e=>(e=`${this._path}/${e}`,fetch(e).then((e=>e.text())).then((t=>({text:t,filename:e}))))));return await Promise.all(a).then((e=>{e.forEach((e=>this._innerParser(e.text,e.filename)))})),this.data}async _readAndParse(e){const t=e.stream().getReader(),i=new TextDecoder;let{value:s,done:n}=await t.read(),r="";for(;!n;){const o=(r+i.decode(s,{stream:!0})).split("\n");r=o.pop();for(const t of o)this._innerParser(t,e.name);({value:s,done:n}=await t.read())}r&&this._innerParser(r,e.name)}async readFile(e,t){return this._path="",await this._readAndParse(e),this._cleanupGeometryArrays(),t&&await this._readAndParse(t),this.data}_cleanupGeometryArrays(){for(const e of this.geometries)e.data=Object.fromEntries(Object.entries(e.data).filter((([e,t])=>t.length>0)))}}function pi(e){let t=new Float32Array([1,1,1]);if(e instanceof Array)t[0]=e[0],t[1]=e[1],t[2]=e[2];else if("string"==typeof e){let i=xe(e);t[0]=i[0],t[1]=i[1],t[2]=i[2]}return t}class mi{constructor(e={}){var t;if(this._name=e.name||"noname",this._vertices=e.vertices||[],this._numVertices=this._vertices.length/3,this._texCoords=e.texCoords||new Array(2*this._numVertices),this.color=(t=e.color)instanceof Array?new Float32Array(t):"string"==typeof t?xe(t):new Float32Array([1,1,1,1]),this.ambient=pi(e.ambient),this.diffuse=pi(e.diffuse),this.specular=pi(e.specular),this.shininess=e.shininess||100,this.colorTexture=e.colorTexture||"",this.normalTexture=e.normalTexture||"",this.metallicRoughnessTexture=e.metallicRoughnessTexture||"",e.scale){let t,i=e.scale;t="number"==typeof i?new oe(i,i,i):i,mi.scale(this._vertices,t)}if(e.center&&mi.centering(this._vertices),this.center=mi.getCenter(this._vertices),e.indices)this._indices=e.indices,this._normals=e.normals||[];else{this._normals=e.normals||mi.getNormals(this._vertices),this._indices=new Array(this._vertices.length/3);for(let e=0,t=this._indices.length;e<t;e++)this._indices[e]=e}}static getCenter(e){let t=o,i=o,s=o,n=a,r=a,l=a;for(let o=0,a=e.length;o<a;o+=3){let a=e[o],h=e[o+1],c=e[o+2];a<t&&(t=a),h<i&&(i=h),c<s&&(s=c),a>n&&(n=a),h>r&&(r=h),c>l&&(l=c)}return new oe(t+.5*(n-t),i+.5*(r-i),s+.5*(l-s))}static centering(e){let t=mi.getCenter(e);for(let i=0,s=e.length;i<s;i+=3)e[i]-=t.x,e[i+1]-=t.y,e[i+2]-=t.z}centering(){return mi.centering(this._vertices),this}applyMat4(e){for(let t=0,i=this._vertices.length;t<i;t+=3){let i=new oe(this._vertices[t],this._vertices[t+1],this._vertices[t+2]),s=new oe(this._normals[t],this._normals[t+1],this._normals[t+2]);i=e.mulVec3(i),s=e.mulVec3(s),this._vertices[t]=i.x,this._vertices[t+1]=i.y,this._vertices[t+2]=i.z,this._normals[t]=s.x,this._normals[t+1]=s.y,this._normals[t+2]=s.z}return this}scale(e){return mi.scale(this._vertices,e),this}translate(e){for(let t=0,i=this._vertices.length;t<i;t+=3)this._vertices[t]+=e.x,this._vertices[t+1]+=e.y,this._vertices[t+2]+=e.z;return this}get name(){return this._name}get vertices(){return this._vertices}get normals(){return this._normals}get indices(){return this._indices}get texCoords(){return this._texCoords}get numVertices(){return this._numVertices}static scale(e,t){for(let i=0;i<e.length;i+=3)e[i]*=t.x,e[i+1]*=t.y,e[i+2]*=t.z}static centroid(e){let t=1e3,i=1e3,s=1e3,n=-1e3,r=-1e3,o=-1e3;for(let a=0;a<e.length;a+=3){let l=e[a],h=e[a+1],c=e[a+2];l<t&&(t=l),h<i&&(i=h),c<s&&(s=c),l>n&&(n=l),h>r&&(r=h),c>o&&(o=c)}return[t+.5*(n-t),i+.5*(r-i),s+.5*(o-s)]}static translate(e,t){for(let i=0;i<e.length;i+=3)e[i]+=t[0],e[i+1]+=t[1],e[i+2]+=t[2]}static getNormals(e){let t=new Array(e.length);for(let i=0;i<e.length;i+=9){let s=i,n=i+3,r=i+6,o=e[s],a=e[s+1],l=e[s+2],h=e[n]-o,c=e[n+1]-a,d=e[n+2]-l,_=e[r]-o,u=e[r+1]-a,g=e[r+2]-l,f=c*g-d*u,p=d*_-h*g,m=h*u-c*_,v=Math.sqrt(f*f+p*p+m*m);f/=v,p/=v,m/=v,t[s]=f,t[s+1]=p,t[s+2]=m,t[n]=f,t[n+1]=p,t[n+2]=m,t[r]=f,t[r+1]=p,t[r+2]=m}return t}static createSphere(e=16,t=16,i=1,s=0,n=0,r=0){let o=[],a=[],l=[];for(let a=0;a<=t;a++){let h=a*Math.PI/t,c=Math.sin(h),d=Math.cos(h);for(let t=0;t<=e;t++){let a=2*t*Math.PI/e,h=Math.sin(a),_=Math.cos(a)*c+s,u=d+n,g=h*c+r;l.push(_),l.push(u),l.push(g),o.push(i*_),o.push(i*u),o.push(i*g)}}for(let i=0;i<t;i++)for(let t=0;t<e;t++){let s=i*(e+1)+t,n=s+e+1;a.push(s),a.push(s+1),a.push(n),a.push(n),a.push(s+1),a.push(n+1)}return new mi({vertices:o,normals:l,indices:a})}static createDisc(e=1,t=0,i=8,s=!0,n=0,r=0,o=0,a=0){let l=[],h=[],c=[],d=2*Math.PI,_=s?1:-1,u=n;for(let e=1;e<=i;e++)l.push(r,t*_+o,a),c.push(0,_,0),n++;let g=n;for(let s=0;s<=i;s++){let h=s/i*d+0,u=Math.cos(h),g=Math.sin(h);l.push(e*g+r,t*_+o,e*u+a),c.push(0,_,0),n++}for(let e=0;e<i;e++){let t=u+e,i=g+e;s?h.push(i,i+1,t):h.push(i+1,i,t)}return new mi({vertices:l,normals:c,indices:h})}static getFrustumScaleByCameraAngles(e,t,i){return new oe(2*e*Math.tan(d*t),2*e*Math.tan(d*i),e)}static getFrustumScaleByCameraAspectRatio(e,t,i){let s=c*Math.atan(Math.tan(d*t)/i);return mi.getFrustumScaleByCameraAngles(e,t,s)}static createFrustum(e=1,t=1,i=1,s=0,n=0,r=0){return new mi({vertices:[0+s,0+n,0+r,-1*(t*=.5)+s,1*(i*=.5)+n,-1*e+r,1*t+s,1*i+n,-1*e+r,0+s,0+n,0+r,1*t+s,-1*i+n,-1*e+r,-1*t+s,-1*i+n,-1*e+r,0+s,0+n,0+r,1*t+s,1*i+n,-1*e+r,1*t+s,-1*i+n,-1*e+r,0+s,0+n,0+r,-1*t+s,-1*i+n,-1*e+r,-1*t+s,1*i+n,-1*e+r,0+s,0+n,0+r,1*t+s,1*i+n,-1*e+r,-1*t+s,1*i+n,-1*e+r,0+s,0+n,0+r,-1*t+s,-1*i+n,-1*e+r,1*t+s,-1*i+n,-1*e+r,0+s,0+n,0+r,1*t+s,-1*i+n,-1*e+r,1*t+s,1*i+n,-1*e+r,0+s,0+n,0+r,-1*t+s,1*i+n,-1*e+r,-1*t+s,-1*i+n,-1*e+r]})}static createCylinder(e=1,t=1,i=1,s=32,n=1,r=!0,o=!0,a=0,l=0,h=0){let c=[],d=[],_=[],u=2*Math.PI,g=0,f=[],p=new oe,m=(t-e)/i;for(let r=0;r<=n;r++){let o=[],d=r/n,v=d*(t-e)+e;for(let e=0;e<=s;e++){let t=e/s*u+0,n=Math.sin(t),r=Math.cos(t);c.push(v*n+a,-d*i+i+l,v*r+h),p.set(n,m,r).normalize(),_.push(p.x,p.y,p.z),o.push(g++)}f.push(o)}for(let e=0;e<s;e++)for(let t=0;t<n;t++){let i=f[t][e],s=f[t+1][e],n=f[t+1][e+1],r=f[t][e+1];d.push(i,s,r),d.push(s,n,r)}if(0!==e&&r){let t=mi.createDisc(e,i,s,!0,g,a,l,h);c.push(...t.vertices),_.push(...t.normals),d.push(...t.indices)}if(0!==t&&o){let e=mi.createDisc(t,0,s,!1,g+(r?1+2*s:0),a,l,h);c.push(...e.vertices),_.push(...e.normals),d.push(...e.indices)}return new mi({vertices:c,normals:_,indices:d})}static createCube(e=1,t=1,i=1,s=0,n=0,r=0){let o=.5*e+s,a=.5*t+n,l=.5*i+r;return new mi({vertices:[-o,-a,l,o,-a,-l,o,-a,l,-o,-a,l,-o,-a,-l,o,-a,-l,-o,a,l,o,a,l,o,a,-l,-o,a,l,o,a,-l,-o,a,-l,-o,-a,l,o,-a,l,-o,a,l,-o,a,l,o,-a,l,o,a,l,-o,-a,-l,-o,a,-l,o,-a,-l,-o,a,-l,o,a,-l,o,-a,-l,o,-a,l,o,-a,-l,o,a,l,o,a,l,o,-a,-l,o,a,-l,-o,-a,l,-o,a,l,-o,-a,-l,-o,a,l,-o,a,-l,-o,-a,-l]})}static createPlane(e=1,t=1,i=0,s=0,n=0){let r=.5*e,o=.5*t;return new mi({vertices:[-r+i,s,o+n,r+i,s,-o+n,r+i,s,o+n,-r+i,s,o+n,-r+i,s,-o+n,r+i,s,-o+n,-r+i,s,o+n,r+i,s,o+n,r+i,s,-o+n,-r+i,s,o+n,r+i,s,-o+n,-r+i,s,-o+n]})}static createArrow(e=0,t=2.1,i=-15){return new mi({vertices:[0,t,0,7,0,6,0,0,i,0,0,e,7,0,6,0,t,0,-7,0,6,0,0,e,0,t,0,-7,0,6,0,t,0,0,0,i,-7,0,6,0,0,i,0,0,e,0,0,e,0,0,i,7,0,6]})}static async readFileObj(e,t){let i=new fi;const s=await i.readFile(e,t);let n=s.materials;return s.geometries.map((e=>{let t=n[e.material]||{};return new mi({name:e.object,vertices:e.data.vertices,normals:e.data.normals,texCoords:e.data.texCoords,ambient:t.ambient,diffuse:t.diffuse,specular:t.specular,shininess:t.shininess,color:t.color,colorTexture:t.colorTexture,normalTexture:t.normalTexture,metallicRoughnessTexture:t.metallicRoughnessTexture})}))}static async loadObj(e){let t=new fi;const i=await t.load(e);let s=i.materials;return i.geometries.map((e=>{let t=s[e.material]||{};return new mi({name:e.object,vertices:e.data.vertices,normals:e.data.normals,texCoords:e.data.texCoords,ambient:t.ambient,diffuse:t.diffuse,specular:t.specular,shininess:t.shininess,color:t.color,colorTexture:t.colorTexture,normalTexture:t.normalTexture,metallicRoughnessTexture:t.metallicRoughnessTexture})}))}merge(e){const t=this._vertices.length/3;let i=this._vertices.length;this._vertices.length=i+e._vertices.length;for(let t=0;t<e._vertices.length;t++)this._vertices[i+t]=e._vertices[t];i=this._normals.length,this._normals.length=i+e._normals.length;for(let t=0;t<e._normals.length;t++)this._normals[i+t]=e._normals[t];i=this._texCoords.length,this._texCoords.length=i+e._texCoords.length;for(let t=0;t<e._texCoords.length;t++)this._texCoords[i+t]=e._texCoords[t];i=this._indices.length,this._indices.length=i+e._indices.length;for(let s=0;s<e._indices.length;s++)this._indices[i+s]=e._indices[s]+t;return this._numVertices=this._vertices.length/3,this}static merge(e,t){let i=new mi,s=t||e.length;for(let t=0;t<s;t++)i.merge(e[t]);return i}}const vi=new oe(0,0,-1);class yi{constructor(e){this._handlerIndex=-1,this._tag=e.tag||"tag_"+yi.__counter__++,this._entity=null,this._position=Ae(e.position),this._rtcPositionHigh=new oe,this._rtcPositionLow=new oe,this._scale=Ae(e.scale,new oe(1,1,1)),this._translate=Ae(e.translate,new oe),this._localPosition=new oe,this._color=Pe(e.color,new se(.15,.15,.15,1)),this._handler=null,this._handlerIndex=-1,this._tagData=null,this._tagDataIndex=-1;let t=e.object3d;e.object3d&&0!==e.object3d?.vertices.length||(t=new mi),e.objSrc&&(this.setObjectSrc(e.objSrc),this._objectSrc=e.objSrc),this._object3d=t,this._visibility=null==e.visibility||e.visibility,this._children=[],this._direction=new oe,this._qFrame=new re,this._qRot=re.IDENTITY}get tag(){return this._tag}getPosition(){return this._position}get object3d(){return this._object3d}get vertices(){return this._object3d.vertices}get normals(){return this._object3d.normals}get texCoords(){return this._object3d.texCoords}get indices(){return this._object3d.indices}setOpacity(e){this._color.w=e,this.setColor(this._color.x,this._color.y,this._color.z,e)}getOpacity(){return this._color.w}setColor(e,t,i,s){this._color.x=e,this._color.y=t,this._color.z=i,null!=s&&(this._color.w=s),this._handler&&this._handler.setRgbaArr(this._tagData,this._tagDataIndex,this._color)}setColor4v(e){this._color.x=e.x,this._color.y=e.y,this._color.z=e.z,null!=e.w&&(this._color.w=e.w),this._handler&&this._handler.setRgbaArr(this._tagData,this._tagDataIndex,this._color)}setVisibility(e){this._visibility=e,this._handler&&this._handler.setVisibility(this._tagData,this._tagDataIndex,e)}getVisibility(){return this._visibility}setPosition(e,t,i){this._position.x=e,this._position.y=t,this._position.z=i,this.updateRTCPosition(),this.updateRotation()}updateRTCPosition(){this._handler&&(this._handler.getRTCPosition(this._position,this._rtcPositionHigh,this._rtcPositionLow),this._handler.setRTCPositionArr(this._tagData,this._tagDataIndex,this._rtcPositionHigh,this._rtcPositionLow))}setPosition3v(e){this.setPosition(e.x,e.y,e.z)}setObject(e){this._object3d=e}setObjectSrc(e){this._objectSrc=e,this._handler&&this._handler.setObjectSrc(e,this.tag)}setColorHTML(e){this.setColor4v(ye(e))}setScale(e){this._scale.x=this._scale.y=this._scale.z=e,this._handler&&this._handler.setScaleArr(this._tagData,this._tagDataIndex,this._scale)}setScale3v(e){this._scale.copy(e),this._handler&&this._handler.setScaleArr(this._tagData,this._tagDataIndex,e)}getScale(){return this._scale}setTranslate3v(e){this._translate.copy(e),this._handler&&this._handler.setTranslateArr(this._tagData,this._tagDataIndex,e)}getTranslate(){return this._translate.clone()}setLocalPosition3v(e){this._localPosition.copy(e),this._handler&&this._handler.setLocalPositionArr(this._tagData,this._tagDataIndex,e)}getLocalPosition(){return this._localPosition.clone()}remove(){this._entity=null,this._handler&&this._handler.remove(this)}setPickingColor3v(e){this._handler&&this._handler.setPickingColorArr(this._tagData,this._tagDataIndex,e)}setRotation(e){this._qRot.copy(e),this._qRot.mulVec3Res(vi,this._direction).normalize(),this.updateRotation()}getRotation(){return this._qRot}updateRotation(){this._handler&&this._handler.setQRotArr(this._tagData,this._tagDataIndex,this._qRot)}getDirection(){return this._direction.clone()}}yi.__counter__=0;const xi={RIGHT:0,LEFT:1,CENTER:2},bi={left:xi.LEFT,right:xi.RIGHT,center:xi.CENTER};class wi extends ri{constructor(e={}){super(e),this._handler=null,this._text=e.text||"",this._face=Le(e.face,"arial"),this._size=e.size||24,this._outline=null!=e.outline?e.outline:0,this._outlineColor=Pe(e.outlineColor,new se(0,0,0,1)),this._align=e.align&&bi[e.align.trim().toLowerCase()]||xi.RIGHT,this._fontIndex=0,this._fontAtlas=null,this._isRTL=e.isRTL||!1,this._letterSpacing=e.letterSpacing||0}setText(e){this._text=e.toString(),this._isReady&&this._handler&&this._handler.setText(this._handlerIndex,e,this._fontIndex,this._align,this._letterSpacing,this._isRTL)}setLetterSpacing(e){this._letterSpacing=e,this._isReady&&this._handler&&this._handler.setText(this._handlerIndex,this._text,this._fontIndex,this._align,e,this._isRTL)}getLetterSpacing(){return this._letterSpacing}setRtl(e){this._isRTL=e,this._isReady&&this._handler&&this._handler.setText(this._handlerIndex,this._text,this._fontIndex,this._align,this._letterSpacing,this._isRTL)}getText(){return this._text}setAlign(e){this._align=bi[e.trim().toLowerCase()],this._isReady&&this._handler?this._handler.setText(this._handlerIndex,this._text,this._fontIndex,this._align,this._letterSpacing,this._isRTL):this._lockId!==ii&&(this._lockId=ti)}getAlign(){return this._align}setFace(e){this._face=e.trim(),this.update()}getFace(){return this._face}setSize(e){e!==this._size&&(this._size=e,this._isReady&&this._handler?this._handler.setSizeArr(this._handlerIndex,e):this._lockId!==ii&&(this._lockId=ti))}getSize(){return this._size}setOutline(e){this._outline=e,this._isReady&&this._handler?this._handler.setOutlineArr(this._handlerIndex,e):this._lockId!==ii&&(this._lockId=ti)}getOutline(){return this._outline}setOpacity(e){super.setOpacity(e),this.setOutlineOpacity(e)}setOutlineColor(e,t,i,s){s===this._outlineColor.w&&e===this._outlineColor.x&&t===this._outlineColor.y&&i===this._outlineColor.z||(this._outlineColor.x=e,this._outlineColor.y=t,this._outlineColor.z=i,this._outlineColor.w=s,this._isReady&&this._handler?this._handler.setOutlineColorArr(this._handlerIndex,this._outlineColor):this._lockId!==ii&&(this._lockId=ti))}setOutlineColor4v(e){this.setOutlineColor(e.x,e.y,e.z,e.w)}setOutlineColorHTML(e){this.setOutlineColor4v(ye(e))}getOutlineColor(){return this._outlineColor}setOutlineOpacity(e){e!==this._outlineColor.w&&(this._outlineColor.w=e,this._isReady&&this._handler?this._handler.setOutlineColorArr(this._handlerIndex,this._outlineColor):this._lockId!==ii&&(this._lockId=ti))}getOutlineOpacity(){return this._outlineColor.w}async update(){if(this._fontAtlas){const e=await this._fontAtlas.getFontIndex(this._face);this._applyFontIndex(e)}}_applyFontIndex(e){this._fontIndex=e,this._isReady&&this._handler?(this._handler.setFontIndexArr(this._handlerIndex,this._fontIndex),this._handler.setText(this._handlerIndex,this._text,this._fontIndex,this._align,this._letterSpacing,this._isRTL)):this._lockId!==ii&&(this._lockId=ti)}assignFontAtlas(e){this._fontAtlas||(this._fontAtlas=e),this.update()}serializeWorkerData(e){return this._handler?new Float32Array([e,this._handler._maxLetters,this.getVisibility()?1:0,this._positionHigh.x,this._positionHigh.y,this._positionHigh.z,this._positionLow.x,this._positionLow.y,this._positionLow.z,this._size,this._offset.x,this._offset.y,this._offset.z,this._color.x,this._color.y,this._color.z,this._color.w,this._rotation,this._alignedAxis.x,this._alignedAxis.y,this._alignedAxis.z,this._fontIndex,this._outline,this._outlineColor.x,this._outlineColor.y,this._outlineColor.z,this._outlineColor.w,this._entity._pickingColor.x,this._entity._pickingColor.y,this._entity._pickingColor.z]):null}}class Ci{constructor(e={}){this.__id=Ci.__counter__++,this.visibility=null==e.visibility||e.visibility,this.pointSize=e.pointSize||3,this.pickingScale=e.pickingScale||0,this._renderNode=null,this._entity=null,this._points=[],this._coordinatesData=[],this._colorData=[],this._pickingColorData=[],this._coordinatesBuffer=null,this._colorBuffer=null,this._pickingColorBuffer=null,this._handler=null,this._handlerIndex=-1,this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[0]=this._createCoordinatesBuffer,this._buffersUpdateCallbacks[1]=this._createColorBuffer,this._buffersUpdateCallbacks[2]=this._createPickingColorBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length),e.points&&this.setPoints(e.points)}clear(){this._points.length=0,this._points=[],this._coordinatesData.length=0,this._coordinatesData=[],this._colorData.length=0,this._colorData=[],this._pickingColorData.length=0,this._pickingColorData=[],this._deleteBuffers()}setVisibility(e){this.visibility=e}getVisibility(){return this.visibility}setRenderNode(e){this._renderNode=e,this._setPickingColors()}remove(){this._entity=null,this._handler&&this._handler.remove(this)}setPoints(e){this.clear();for(let t=0;t<e.length;t++){let i=e[t],s=new oe(i[0],i[1],i[2]),n=new se(i[3],i[4],i[5],null==i[6]?255:i[6]);this._coordinatesData.push(s.x,s.y,s.z),this._colorData.push(n.x/255,n.y/255,n.z/255,n.w/255);let r={_entity:this._entity,_pickingColor:new oe,_entityCollection:this._entity?this._entity._entityCollection:null,index:t,position:s,color:n,pointCloud:this,properties:i[7]||{}};this._points.push(r),this._renderNode&&this._renderNode.renderer&&(this._renderNode.renderer.assignPickingColor(r),this._pickingColorData.push(r._pickingColor.x/255,r._pickingColor.y/255,r._pickingColor.z/255,1))}this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}setPointPosition(e,t,i,s){this._changedBuffers[0]=!0}setPointColor(e,t,i,s,n){this._changedBuffers[1]=!0}addPoints(e){this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}addPoint(e,t){this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}getPoint(e){return this._points[e]}removePoint(e){this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}insertPoint(e,t){this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0}draw(){if(this.visibility&&this._coordinatesData.length){this._update();let e=this._renderNode.renderer,t=e.handler.programs.pointCloud,i=t._program,s=e.handler.gl,n=i.attributes,r=i.uniforms;t.activate(),s.uniformMatrix4fv(r.projectionViewMatrix,!1,e.activeCamera.getProjectionViewMatrix()),s.uniform1f(r.opacity,this._handler._entityCollection._fadingOpacity),s.uniform1f(r.pointSize,this.pointSize),s.bindBuffer(s.ARRAY_BUFFER,this._coordinatesBuffer),s.vertexAttribPointer(n.coordinates,this._coordinatesBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._colorBuffer),s.vertexAttribPointer(n.colors,this._colorBuffer.itemSize,s.FLOAT,!1,0,0),s.drawArrays(s.POINTS,0,this._coordinatesBuffer.numItems)}}drawPicking(){if(this.visibility&&this._coordinatesData.length){let e=this._renderNode.renderer,t=e.handler.programs.pointCloud,i=t._program,s=e.handler.gl,n=i.attributes,r=i.uniforms;t.activate(),s.uniformMatrix4fv(r.projectionViewMatrix,!1,e.activeCamera.getProjectionViewMatrix()),s.uniform1f(r.opacity,this._handler._entityCollection._fadingOpacity),s.uniform1f(r.pointSize,this.pointSize+this.pickingScale),s.bindBuffer(s.ARRAY_BUFFER,this._coordinatesBuffer),s.vertexAttribPointer(n.coordinates,this._coordinatesBuffer.itemSize,s.FLOAT,!1,0,0),s.bindBuffer(s.ARRAY_BUFFER,this._pickingColorBuffer),s.vertexAttribPointer(n.colors,this._pickingColorBuffer.itemSize,s.FLOAT,!1,0,0),s.drawArrays(s.POINTS,0,this._coordinatesBuffer.numItems)}}_update(){if(this._renderNode){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1)}}_deleteBuffers(){if(this._renderNode){let e=this._renderNode.renderer.handler.gl;e.deleteBuffer(this._coordinatesBuffer),e.deleteBuffer(this._colorBuffer),e.deleteBuffer(this._pickingColorBuffer)}this._coordinatesBuffer=null,this._colorBuffer=null,this._pickingColorBuffer=null}_createCoordinatesBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._coordinatesBuffer),this._coordinatesBuffer=e.createArrayBuffer(new Float32Array(this._coordinatesData),3,this._coordinatesData.length/3)}_createColorBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._colorBuffer),this._colorBuffer=e.createArrayBuffer(new Float32Array(this._colorData),4,this._colorData.length/4)}_createPickingColorBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._pickingColorBuffer),this._pickingColorBuffer=e.createArrayBuffer(new Float32Array(this._pickingColorData),4,this._pickingColorData.length/4)}_setPickingColors(){if(this._renderNode&&this._renderNode.renderer){for(let e=0;e<this._points.length;e++){let t=this._points[e];t._entity=this._entity,t._entityCollection=this._entity._entityCollection,this._renderNode.renderer.assignPickingColor(t),this._pickingColorData.push(t._pickingColor.x/255,t._pickingColor.y/255,t._pickingColor.z/255,1)}this._changedBuffers[2]=!0}}}Ci.__counter__=0;class Ti{constructor(e={}){this.__id=Ti.__counter__++,this.__doubleToTwoFloats=oe.doubleToTwoFloats,this.altitude=e.altitude||0,this.thickness=e.thickness||1.5,this._opacity=null!=e.opacity?e.opacity:1,this._defaultColor=xe(e.color||"#0000FF",e.opacity),this.visibility=null==e.visibility||e.visibility,this._closedLine=e.isClosed||!1,this._path3v=[],this._pathLengths=[],this._pathLonLat=[],this._pathLonLatMerc=[],this._pathColors=e.pathColors?$e(e.pathColors):[],this._extent=new te,this._verticesHigh=[],this._verticesLow=[],this._orders=[],this._indexes=[],this._colors=[],this._verticesHighBuffer=null,this._verticesLowBuffer=null,this._ordersBuffer=null,this._indexesBuffer=null,this._colorsBuffer=null,this._pickingColor=[0,0,0],this._renderNode=null,this._entity=null,this._handler=null,this._handlerIndex=-1,this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[0]=this._createVerticesBuffer,this._buffersUpdateCallbacks[1]=this._createIndexBuffer,this._buffersUpdateCallbacks[2]=this._createColorsBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length);let t=Ae(e.visibleSpherePosition).toArray(),i=e.visibleSphereRadius||0;this._visibleSphere=new Float32Array([...t,i]),e.pathLonLat?this.setPathLonLat(e.pathLonLat):e.path3v&&this.setPath3v(e.path3v),this._refresh()}__appendLineData3v(e,t,i,s,n,r,o,a,l,h,c,d,_,u){var g=0,f=new oe,p=new oe;_&&(_.southWest.set(180,90),_.northEast.set(-180,-90)),a.length>0?(g=a[a.length-5]+9,a.push(g,g)):a.push(0,0);for(let L=0,A=e.length;L<A;L++){var m=e[L],v=t[L];if(h[L]=[],d[L]=[],c[L]=[],0===m.length)continue;var y,x=g;if(s)(y=m[m.length-1])instanceof Array&&(y=new oe(y[0],y[1],y[2]));else{var b=m[0],w=m[1]||b;b instanceof Array&&(b=new oe(b[0],b[1],b[2])),w instanceof Array&&(w=new oe(w[0],w[1],w[2])),y=new oe(b.x+b.x-w.x,b.y+b.y-w.y,b.z+b.z-w.z)}let A=i;v&&v[0]&&(A=v[0]),this.__doubleToTwoFloats(y,f,p),n.push(f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z),r.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z);let P=A[0],S=A[1],M=A[2],R=null!=A[3]?A[3]:1;L>0&&u.push(P,S,M,R,P,S,M,R,P,S,M,R,P,S,M,R),o.push(1,-1,2,-2);for(let e=0,t=m.length;e<t;e++){var C=m[e];if(C instanceof Array&&(C=new oe(C[0],C[1],C[2])),c[L].push(C),l){var T=l.cartesianToLonLat(C);h[L].push(T),d[L].push(T.forwardMercator()),T.lon<_.southWest.lon&&(_.southWest.lon=T.lon),T.lat<_.southWest.lat&&(_.southWest.lat=T.lat),T.lon>_.northEast.lon&&(_.northEast.lon=T.lon),T.lat>_.northEast.lat&&(_.northEast.lat=T.lat)}v&&v[e]&&(A=v[e]),P=A[0],S=A[1],M=A[2],R=null!=A[3]?A[3]:1,this.__doubleToTwoFloats(C,f,p),n.push(f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z),r.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z),u.push(P,S,M,R,P,S,M,R,P,S,M,R,P,S,M,R),o.push(1,-1,2,-2),a.push(g++,g++,g++,g++)}var E;if(s)(E=m[0])instanceof Array&&(E=new oe(E[0],E[1],E[2])),a.push(x,x+1,x+1,x+1);else{let e=m[m.length-1],t=m[m.length-2]||e;e instanceof Array&&(e=new oe(e[0],e[1],e[2])),t instanceof Array&&(t=new oe(t[0],t[1],t[2])),E=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z),a.push(g-1,g-1,g-1,g-1)}v&&v[m.length-1]&&(A=v[m.length-1]),P=A[0],S=A[1],M=A[2],R=null!=A[3]?A[3]:1,this.__doubleToTwoFloats(E,f,p),n.push(f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z),r.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z),u.push(P,S,M,R,P,S,M,R,P,S,M,R,P,S,M,R),o.push(1,-1,2,-2),L<e.length-1&&0!==e[L+1].length&&(g+=8,a.push(g,g))}}__appendPoint3v(e,t,i,s,n,r,o,a,l,h,c,d,_,u){var g=new oe,f=new oe,p=h.length-4,m=h[p-1]+1;0===e.length?(e.push([]),i[0]||(i[0]=[])):i[e.length-1]||(i[e.length-1]=[]);var v=e[e.length-1],y=v.length;v.push(t);let x=s[0],b=s[1],w=s[2],C=null!=s[3]?s[3]:1,T=i[e.length-1];if(T[y]?(T[y][0]=x,T[y][1]=b,T[y][2]=w,T[y][3]=C):T.push(s),1===y){var E;if(n)(E=v[y-1])instanceof Array&&(E=new oe(E[0],E[1],E[2]));else{let e=v[0],t=v[1]||e;e instanceof Array&&(e=new oe(e[0],e[1],e[2])),t instanceof Array&&(t=new oe(t[0],t[1],t[2])),E=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}this.__doubleToTwoFloats(E,g,f);let e=r.length-36;r[e]=g.x,r[e+1]=g.y,r[e+2]=g.z,r[e+3]=g.x,r[e+4]=g.y,r[e+5]=g.z,r[e+6]=g.x,r[e+7]=g.y,r[e+8]=g.z,r[e+9]=g.x,r[e+10]=g.y,r[e+11]=g.z,o[e]=f.x,o[e+1]=f.y,o[e+2]=f.z,o[e+3]=f.x,o[e+4]=f.y,o[e+5]=f.z,o[e+6]=f.x,o[e+7]=f.y,o[e+8]=f.z,o[e+9]=f.x,o[e+10]=f.y,o[e+11]=f.z}var L=m;if(c){0===d.length&&d.push([]),0===_.length&&_.push([]);var A=d[d.length-1],P=_[_.length-1];let e=c.cartesianToLonLat(t);A.push(e),P.push(e.forwardMercator()),e.lon<u.southWest.lon&&(u.southWest.lon=e.lon),e.lat<u.southWest.lat&&(u.southWest.lat=e.lat),e.lon>u.northEast.lon&&(u.northEast.lon=e.lon),e.lat>u.northEast.lat&&(u.northEast.lat=e.lat)}this.__doubleToTwoFloats(t,g,f);let S=r.length-12;r[S]=g.x,r[S+1]=g.y,r[S+2]=g.z,r[S+3]=g.x,r[S+4]=g.y,r[S+5]=g.z,r[S+6]=g.x,r[S+7]=g.y,r[S+8]=g.z,r[S+9]=g.x,r[S+10]=g.y,r[S+11]=g.z,o[S]=f.x,o[S+1]=f.y,o[S+2]=f.z,o[S+3]=f.x,o[S+4]=f.y,o[S+5]=f.z,o[S+6]=f.x,o[S+7]=f.y,o[S+8]=f.z,o[S+9]=f.x,o[S+10]=f.y,o[S+11]=f.z;let M=a.length-16;var R;if(a[M]=x,a[M+1]=b,a[M+2]=w,a[M+3]=C,a[M+4]=x,a[M+5]=b,a[M+6]=w,a[M+7]=C,a[M+8]=x,a[M+9]=b,a[M+10]=w,a[M+11]=C,a[M+12]=x,a[M+13]=b,a[M+14]=w,a[M+15]=C,h[p]=m++,h[p+1]=m++,h[p+2]=m++,h[p+3]=m++,n)R=v[0],h.push(L,L+1,L+1,L+1);else{let e=v[v.length-1],t=v[v.length-2]||e;R=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z),h.push(m-1,m-1,m-1,m-1)}this.__doubleToTwoFloats(R,g,f),r.push(g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z,g.x,g.y,g.z),o.push(f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z),a.push(x,b,w,C,x,b,w,C,x,b,w,C,x,b,w,C),l.push(1,-1,2,-2)}static setPathColors(e,t,i,s){for(let a=0,l=e.length;a<l;a++){var n=e[a],r=t[a];if(0===n.length)continue;let l=i;r&&r[0]&&(l=r[0]);let h=l[0],c=l[1],d=l[2],_=null!=l[3]?l[3]:1;a>0&&s.push(h,c,d,_,h,c,d,_,h,c,d,_,h,c,d,_);for(let e=0,t=n.length;e<t;e++){var o=n[e];o instanceof Array&&(o=new I(o[0],o[1],o[2])),r&&r[e]&&(l=r[e]),h=l[0],c=l[1],d=l[2],_=null!=l[3]?l[3]:1,s.push(h,c,d,_,h,c,d,_,h,c,d,_,h,c,d,_)}r&&r[n.length-1]&&(l=r[n.length-1]),h=l[0],c=l[1],d=l[2],_=null!=l[3]?l[3]:1,s.push(h,c,d,_,h,c,d,_,h,c,d,_,h,c,d,_)}}__appendLineDataLonLat(e,t,i,s,n,r,o,a,l,h,c,d,_,u){var g=0,f=new oe,p=new oe;_&&(_.southWest.set(180,90),_.northEast.set(-180,-90)),a.length>0?(g=a[a.length-5]+9,a.push(g)):a.push(0);for(let T=0,E=e.length;T<E;T++){var m=e[T],v=t[T];if(h[T]=[],d[T]=[],c[T]=[],0===m.length)continue;var y,x=g;if(s){let e=m[m.length-1];y=e instanceof Array?l.lonLatToCartesian(new I(e[0],e[1],e[2])):l.lonLatToCartesian(e)}else{let e,t,i=m[0];e=i instanceof Array?l.lonLatToCartesian(new I(i[0],i[1],i[2])):l.lonLatToCartesian(i),i=m[1],i||(i=m[0]),t=i instanceof Array?l.lonLatToCartesian(new I(i[0],i[1],i[2])):l.lonLatToCartesian(i),y=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}let E=i;v&&v[0]&&(E=v[0]),this.__doubleToTwoFloats(y,f,p),n.push(f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z),r.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z);let L=E[0],A=E[1],P=E[2],S=null!=E[3]?E[3]:1;T>0&&u.push(L,A,P,S,L,A,P,S,L,A,P,S,L,A,P,S),o.push(1,-1,2,-2);for(let e=0,t=m.length;e<t;e++){var b=m[e];b instanceof Array&&(b=new I(b[0],b[1],b[2])),v&&v[e]&&(E=v[e]),L=E[0],A=E[1],P=E[2],S=null!=E[3]?E[3]:1;var w=l.lonLatToCartesian(b);h[T].push(w),c[T].push(b),d[T].push(b.forwardMercator()),this.__doubleToTwoFloats(w,f,p),n.push(f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z),r.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z),u.push(L,A,P,S,L,A,P,S,L,A,P,S,L,A,P,S),o.push(1,-1,2,-2),a.push(g++,g++,g++,g++),b.lon<_.southWest.lon&&(_.southWest.lon=b.lon),b.lat<_.southWest.lat&&(_.southWest.lat=b.lat),b.lon>_.northEast.lon&&(_.northEast.lon=b.lon),b.lat>_.northEast.lat&&(_.northEast.lat=b.lat)}var C;if(s){let e=m[0];C=e instanceof Array?l.lonLatToCartesian(new I(e[0],e[1],e[2])):l.lonLatToCartesian(e),a.push(x,x+1,x+1,x+1)}else{let e,t,i=m[m.length-1];e=i instanceof Array?l.lonLatToCartesian(new I(i[0],i[1],i[2])):l.lonLatToCartesian(i),i=m[m.length-2],i||(i=m[0]),t=i instanceof Array?l.lonLatToCartesian(new I(i[0],i[1],i[2])):l.lonLatToCartesian(i),C=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z),a.push(g-1,g-1,g-1,g-1)}v&&v[m.length-1]&&(E=v[m.length-1]),L=E[0],A=E[1],P=E[2],S=null!=E[3]?E[3]:1,this.__doubleToTwoFloats(C,f,p),n.push(f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z,f.x,f.y,f.z),r.push(p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z,p.x,p.y,p.z),u.push(L,A,P,S,L,A,P,S,L,A,P,S,L,A,P,S),o.push(1,-1,2,-2),T<e.length-1&&0!==e[T+1].length&&(g+=8,a.push(g,g))}}_setEqualPath3v(e){var t=this._extent;t.southWest.set(180,90),t.northEast.set(-180,-90);var i=new oe,s=new oe,n=this._verticesHigh,r=this._verticesLow,o=this._pathLonLat,a=this._pathLonLatMerc,l=0,h=this._renderNode.ellipsoid;for(let m=0;m<e.length;m++){var c,d,_=e[m];c=this._closedLine?_[_.length-1]:new oe(_[0].x+_[0].x-_[1].x,_[0].y+_[0].y-_[1].y,_[0].z+_[0].z-_[1].z),this.__doubleToTwoFloats(c,i,s),n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z,n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z,n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z,n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z;for(let e=0;e<_.length;e++){var u=_[e],g=this._path3v[m][e];if(g.x=u.x,g.y=u.y,g.z=u.z,h){var f=h.cartesianToLonLat(u);this._pathLonLat[m][e]=f,o[m][e]=f,a[m][e]=f.forwardMercator(),f.lon<t.southWest.lon&&(t.southWest.lon=f.lon),f.lat<t.southWest.lat&&(t.southWest.lat=f.lat),f.lon>t.northEast.lon&&(t.northEast.lon=f.lon),f.lat>t.northEast.lat&&(t.northEast.lat=f.lat)}this.__doubleToTwoFloats(u,i,s),n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z,n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z,n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z,n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z}if(this._closedLine)d=_[0];else{var p=_.length-1;d=new oe(_[p].x+_[p].x-_[p-1].x,_[p].y+_[p].y-_[p-1].y,_[p].z+_[p].z-_[p-1].z)}this.__doubleToTwoFloats(d,i,s),n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z,n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z,n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z,n[l]=i.x,r[l++]=s.x,n[l]=i.y,r[l++]=s.y,n[l]=i.z,r[l++]=s.z}}_setEqualPathLonLat(e){var t=this._extent;t.southWest.set(180,90),t.northEast.set(-180,-90);var i=new oe,s=new oe,n=this._verticesHigh,r=this._verticesLow,o=this._pathLonLat,a=this._pathLonLatMerc,l=this._path3v,h=0,c=this._renderNode.ellipsoid;for(let p=0;p<e.length;p++){var d,_,u=e[p];if(this._closedLine)d=c.lonLatToCartesian(u[u.length-1]);else{let e=c.lonLatToCartesian(u[0]),t=c.lonLatToCartesian(u[1]);d=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}this.__doubleToTwoFloats(d,i,s),n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z,n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z,n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z,n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z;for(let e=0;e<u.length;e++){var g=u[e],f=c.lonLatToCartesian(g);l[p][e]=f,a[p][e]=g.forwardMercator(),o[p][e]=g,this.__doubleToTwoFloats(f,i,s),n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z,n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z,n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z,n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z,g.lon<t.southWest.lon&&(t.southWest.lon=g.lon),g.lat<t.southWest.lat&&(t.southWest.lat=g.lat),g.lon>t.northEast.lon&&(t.northEast.lon=g.lon),g.lat>t.northEast.lat&&(t.northEast.lat=g.lat)}if(this._closedLine)_=c.lonLatToCartesian(u[0]);else{let e=c.lonLatToCartesian(u[u.length-1]),t=c.lonLatToCartesian(u[u.length-2]);_=new oe(e.x+e.x-t.x,e.y+e.y-t.y,e.z+e.z-t.z)}this.__doubleToTwoFloats(_,i,s),n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z,n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z,n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z,n[h]=i.x,r[h++]=s.x,n[h]=i.y,r[h++]=s.y,n[h]=i.z,r[h++]=s.z}}setPointLonLat(e,t,i){if(this._renderNode&&this._renderNode.ellipsoid){let a=this._pathLonLat,l=this._pathLonLatMerc;a[i][t]=e,l[i][t]=e.forwardMercator();var s=this._extent;s.southWest.set(180,90),s.northEast.set(-180,-90);for(let e=0;e<a.length;e++){var n=a[e];for(let e=0;e<n.length;e++){var r=n[e].lon,o=n[e].lat;r>s.northEast.lon&&(s.northEast.lon=r),o>s.northEast.lat&&(s.northEast.lat=o),r<s.southWest.lon&&(s.southWest.lon=r),o<s.southWest.lat&&(s.southWest.lat=o)}}this.setPoint3v(this._renderNode.ellipsoid.lonLatToCartesian(e),t,i,!0)}else{let s=this._pathLonLat[i];s[t].lon=e.lon,s[t].lat=e.lat,s[t].height=e.height}}setPoint3v(e,t=0,i=0,s=!1){if(this._renderNode){var n,r=new oe,o=new oe,a=this._verticesHigh,l=this._verticesLow,h=this._pathLonLat,c=this._pathLonLatMerc,d=0;n=12*this._pathLengths[i]+24*i;let x=this._path3v[i];x[t].x=e.x,x[t].y=e.y,x[t].z=e.z;let b=this._closedLine||1===x.length;var _;if(0===t||1===t)_=b?x[x.length-1]:new oe(x[0].x+x[0].x-x[1].x,x[0].y+x[0].y-x[1].y,x[0].z+x[0].z-x[1].z),d=n,this.__doubleToTwoFloats(_,r,o),a[d]=r.x,a[d+1]=r.y,a[d+2]=r.z,a[d+3]=r.x,a[d+4]=r.y,a[d+5]=r.z,a[d+6]=r.x,a[d+7]=r.y,a[d+8]=r.z,a[d+9]=r.x,a[d+10]=r.y,a[d+11]=r.z,l[d]=o.x,l[d+1]=o.y,l[d+2]=o.z,l[d+3]=o.x,l[d+4]=o.y,l[d+5]=o.z,l[d+6]=o.x,l[d+7]=o.y,l[d+8]=o.z,l[d+9]=o.x,l[d+10]=o.y,l[d+11]=o.z;if(!s&&this._renderNode.ellipsoid){var u=this._renderNode.ellipsoid.cartesianToLonLat(e);h[i][t]=u,c[i][t]=u.forwardMercator();var g=this._extent;g.southWest.set(180,90),g.northEast.set(-180,-90);for(let e=0;e<h.length;e++){var f=h[e];for(let e=0;e<f.length;e++){var p=f[e].lon,m=f[e].lat;p>g.northEast.lon&&(g.northEast.lon=p),m>g.northEast.lat&&(g.northEast.lat=m),p<g.southWest.lon&&(g.southWest.lon=p),m<g.southWest.lat&&(g.southWest.lat=m)}}}if(d=n+12*t+12,this.__doubleToTwoFloats(e,r,o),a[d]=r.x,a[d+1]=r.y,a[d+2]=r.z,a[d+3]=r.x,a[d+4]=r.y,a[d+5]=r.z,a[d+6]=r.x,a[d+7]=r.y,a[d+8]=r.z,a[d+9]=r.x,a[d+10]=r.y,a[d+11]=r.z,l[d]=o.x,l[d+1]=o.y,l[d+2]=o.z,l[d+3]=o.x,l[d+4]=o.y,l[d+5]=o.z,l[d+6]=o.x,l[d+7]=o.y,l[d+8]=o.z,l[d+9]=o.x,l[d+10]=o.y,l[d+11]=o.z,t===x.length-1||t===x.length-2){var v;if(b)v=x[0];else{var y=x.length-1;v=new oe(x[y].x+x[y].x-x[y-1].x,x[y].y+x[y].y-x[y-1].y,x[y].z+x[y].z-x[y-1].z)}d=n+12*x.length+12,this.__doubleToTwoFloats(v,r,o),a[d]=r.x,a[d+1]=r.y,a[d+2]=r.z,a[d+3]=r.x,a[d+4]=r.y,a[d+5]=r.z,a[d+6]=r.x,a[d+7]=r.y,a[d+8]=r.z,a[d+9]=r.x,a[d+10]=r.y,a[d+11]=r.z,l[d]=o.x,l[d+1]=o.y,l[d+2]=o.z,l[d+3]=o.x,l[d+4]=o.y,l[d+5]=o.z,l[d+6]=o.x,l[d+7]=o.y,l[d+8]=o.z,l[d+9]=o.x,l[d+10]=o.y,l[d+11]=o.z}this._changedBuffers[0]=!0}else{let s=this._path3v[i];s[t].x=e.x,s[t].y=e.y,s[t].z=e.z}}_resizePathLengths(e=0){this._pathLengths[0]=0;for(let t=e+1,i=this._path3v.length;t<=i;t++)this._pathLengths[t]=this._pathLengths[t-1]+this._path3v[t-1].length}removeSegment(e){this._path3v.splice(e,1),this.setPath3v([].concat(this._path3v))}removePoint(e,t=0){this._path3v[t].splice(e,1),0===this._path3v[t].length&&this._path3v.splice(t,1),this.setPath3v([].concat(this._path3v))}insertPoint3v(e,t=0,i,s=0){let n=[].concat(this._path3v),r=n[s];if(r){let o=[].concat(this._pathColors);if(r.splice(t,0,e),i){let e=o[s];e||(e=new Array(r.length)),e.splice(t,0,i)}this.setPath3v(n,o)}else this.addPoint3v(e,s)}appendPoint3v(e,t,i){0!==this._path3v.length&&this._renderNode?(this._verticesHigh=Ue(this._verticesHigh),this._verticesLow=Ue(this._verticesLow),this._colors=Ue(this._colors),this._orders=Ue(this._orders),this._indexes=Ue(this._indexes),this.__appendPoint3v(this._path3v,e,this._pathColors,t||this._defaultColor,this._closedLine,this._verticesHigh,this._verticesLow,this._colors,this._orders,this._indexes,i?null:this._renderNode.ellipsoid,this._pathLonLat,this._pathLonLatMerc,this._extent),this._pathLengths[this._path3v.length]+=1,this._changedBuffers[0]=!0,this._changedBuffers[2]=!0,this._changedBuffers[1]=!0):(this._pathColors.push([t||this._defaultColor]),this.addPoint3v(e))}addPoint3v(e,t=0){t>=this._path3v.length&&this._path3v.push([]),this._path3v[t].push(e),this.setPath3v([].concat(this._path3v))}addPointLonLat(e,t=0){t>=this._pathLonLat.length&&this._pathLonLat.push([]),this._pathLonLat[t].push(e),this.setPathLonLat([].concat(this._pathLonLat))}clear(){this._clearData()}setPointColor(e,t=0,i=0){if(this._renderNode&&t<this._path3v[i].length){let s=this._pathColors[i];if(!s){if(!(this._path3v[i]&&t<this._path3v[i].length))return;this._pathColors[i]=new Array(this._path3v[i].length)}s[t]?(s[t][0]=e[0],s[t][1]=e[1],s[t][2]=e[2],s[t][3]=e[3]||1):s[t]=[e[0],e[1],e[2],e[3]||1];let n=this._colors,r=16*t+16*this._pathLengths[i]+32*i;n[r]=n[r+4]=n[r+8]=n[r+12]=e[0],n[r+1]=n[r+5]=n[r+9]=n[r+13]=e[1],n[r+2]=n[r+6]=n[r+10]=n[r+14]=e[2],n[r+3]=n[r+7]=n[r+11]=n[r+15]=e[3]||1,this._changedBuffers[2]=!0}else{this._pathColors[i][t]=e}}setOpacity(e){this._opacity=e}getOpacity(){return this._opacity}setAltitude(e){this.altitude=e}setThickness(e){this.thickness=e}getThickness(){return this.thickness}setVisibility(e){this.visibility=e}getVisibility(){return this.visibility}setRenderNode(e){e&&(this._renderNode=e,this._pathLonLat.length?this._createDataLonLat([].concat(this._pathLonLat)):this._createData3v([].concat(this._path3v)),this._refresh(),e.renderer&&e.renderer.isInitialized()&&this._update())}_clearData(){this._verticesHigh=null,this._verticesLow=null,this._orders=null,this._indexes=null,this._colors=null,this._verticesHigh=[],this._verticesLow=[],this._orders=[],this._indexes=[],this._colors=[],this._path3v.length=0,this._pathLonLat.length=0,this._pathLonLatMerc.length=0,this._path3v=[],this._pathLonLat=[],this._pathLonLatMerc=[]}_createData3v(e){this._clearData(),this.__appendLineData3v(e,this._pathColors,this._defaultColor,this._closedLine,this._verticesHigh,this._verticesLow,this._orders,this._indexes,this._renderNode.ellipsoid,this._pathLonLat,this._path3v,this._pathLonLatMerc,this._extent,this._colors),this._resizePathLengths(0)}_createDataLonLat(e){this._clearData(),this.__appendLineDataLonLat(e,this._pathColors,this._defaultColor,this._closedLine,this._verticesHigh,this._verticesLow,this._orders,this._indexes,this._renderNode.ellipsoid,this._path3v,this._pathLonLat,this._pathLonLatMerc,this._extent,this._colors),this._resizePathLengths(0)}remove(){this._entity=null,this._pathColors.length=0,this._pathColors=[],this._verticesHigh=null,this._verticesLow=null,this._orders=null,this._indexes=null,this._colors=null,this._verticesHigh=[],this._verticesLow=[],this._orders=[],this._indexes=[],this._colors=[],this._deleteBuffers(),this._handler&&this._handler.remove(this)}setPickingColor3v(e){this._pickingColor[0]=e.x/255,this._pickingColor[1]=e.y/255,this._pickingColor[2]=e.z/255}getExtent(){return this._extent.clone()}getPath3v(){return this._path3v}getPathLonLat(){return this._pathLonLat}getPathColors(){return this._pathColors}setPathColors(e){e&&(this._colors=[],this._pathColors=[].concat(e),Ti.setPathColors(this._pathLonLat,e,this._defaultColor,this._colors),this._changedBuffers[2]=!0)}setColorHTML(e){this._defaultColor=xe(e);let t=ye(e),i=this._pathColors;for(let e=0,s=i.length;e<s;e++){let s=i[e];for(let e=0,i=s.length;e<i;e++)s[e][0]=t.x,s[e][1]=t.y,s[e][2]=t.z,s[e][3]=t.w}let s=this._colors;for(let e=0,i=s.length;e<i;e+=4)s[e]=t.x,s[e+1]=t.y,s[e+2]=t.z,s[e+3]=t.w;this._changedBuffers[2]=!0}setPathLonLatFast(e,t){this.setPathLonLat(e,t,!0)}setPath3vFast(e,t){this.setPath3v(e,t,!0)}setPathLonLat(e,t,i=!1){t&&(this._pathColors=[].concat(t)),this._renderNode&&this._renderNode.ellipsoid?i?(this._setEqualPathLonLat(e),this._changedBuffers[0]=!0,this._changedBuffers[2]=!0):(this._createDataLonLat(e),this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0):this._pathLonLat=[].concat(e)}getSize(e=0){return this._path3v[e].length}setPath3v(e,t,i=!1){t&&(this._pathColors=[].concat(t)),this._renderNode?i?(this._setEqualPath3v(e),this._changedBuffers[0]=!0,this._changedBuffers[2]=!0):(this._createData3v(e),this._changedBuffers[0]=!0,this._changedBuffers[1]=!0,this._changedBuffers[2]=!0):this._path3v=[].concat(e)}draw(){if(this.visibility&&this._path3v.length){this._update();let e=this._renderNode.renderer,t=e.handler.programs.polyline_screen,i=t._program,s=e.handler.gl,n=i.attributes,r=i.uniforms,o=this._handler._entityCollection;t.activate(),s.disable(s.CULL_FACE),s.uniform1f(r.depthOffset,o.polygonOffsetUnits),s.uniformMatrix4fv(r.proj,!1,e.activeCamera.getProjectionMatrix()),s.uniformMatrix4fv(r.view,!1,e.activeCamera.getViewMatrix()),s.uniform3fv(r.rtcEyePositionHigh,this._handler._rtcEyePositionHigh),s.uniform3fv(r.rtcEyePositionLow,this._handler._rtcEyePositionLow),s.uniform4fv(r.visibleSphere,this._visibleSphere),s.uniform2fv(r.viewport,[e.handler.canvas.width,e.handler.canvas.height]),s.uniform1f(r.thickness,.5*this.thickness),s.uniform1f(r.opacity,this._opacity*o._fadingOpacity),s.bindBuffer(s.ARRAY_BUFFER,this._colorsBuffer),s.vertexAttribPointer(n.color,this._colorsBuffer.itemSize,s.FLOAT,!1,0,0);let a=this._verticesHighBuffer;s.bindBuffer(s.ARRAY_BUFFER,a),s.vertexAttribPointer(n.prevHigh,a.itemSize,s.FLOAT,!1,12,0),s.vertexAttribPointer(n.currentHigh,a.itemSize,s.FLOAT,!1,12,48),s.vertexAttribPointer(n.nextHigh,a.itemSize,s.FLOAT,!1,12,96),a=this._verticesLowBuffer,s.bindBuffer(s.ARRAY_BUFFER,a),s.vertexAttribPointer(n.prevLow,a.itemSize,s.FLOAT,!1,12,0),s.vertexAttribPointer(n.currentLow,a.itemSize,s.FLOAT,!1,12,48),s.vertexAttribPointer(n.nextLow,a.itemSize,s.FLOAT,!1,12,96),s.bindBuffer(s.ARRAY_BUFFER,this._ordersBuffer),s.vertexAttribPointer(n.order,this._ordersBuffer.itemSize,s.FLOAT,!1,4,0),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,this._indexesBuffer),s.drawElements(s.TRIANGLE_STRIP,this._indexesBuffer.numItems,s.UNSIGNED_INT,0),s.enable(s.CULL_FACE)}}drawPicking(){if(this.visibility&&this._path3v.length){let e=this._renderNode.renderer,t=e.handler.programs.polyline_picking,i=t._program,s=e.handler.gl,n=i.attributes,r=i.uniforms,o=this._handler._entityCollection;t.activate(),s.disable(s.CULL_FACE),s.uniform1f(r.depthOffset,o.polygonOffsetUnits),s.uniformMatrix4fv(r.proj,!1,e.activeCamera.getProjectionMatrix()),s.uniformMatrix4fv(r.view,!1,e.activeCamera.getViewMatrix()),s.uniform4fv(r.color,[this._pickingColor[0],this._pickingColor[1],this._pickingColor[2],1]),s.uniform3fv(r.rtcEyePositionHigh,this._handler._rtcEyePositionHigh),s.uniform3fv(r.rtcEyePositionLow,this._handler._rtcEyePositionLow),s.uniform4fv(r.visibleSphere,this._visibleSphere),s.uniform2fv(r.viewport,[e.handler.canvas.width,e.handler.canvas.height]),s.uniform1f(r.thickness,.5*this.thickness*o.pickingScale[0]);let a=this._verticesHighBuffer;s.bindBuffer(s.ARRAY_BUFFER,a),s.vertexAttribPointer(n.prevHigh,a.itemSize,s.FLOAT,!1,12,0),s.vertexAttribPointer(n.currentHigh,a.itemSize,s.FLOAT,!1,12,48),s.vertexAttribPointer(n.nextHigh,a.itemSize,s.FLOAT,!1,12,96),a=this._verticesLowBuffer,s.bindBuffer(s.ARRAY_BUFFER,a),s.vertexAttribPointer(n.prevLow,a.itemSize,s.FLOAT,!1,12,0),s.vertexAttribPointer(n.currentLow,a.itemSize,s.FLOAT,!1,12,48),s.vertexAttribPointer(n.nextLow,a.itemSize,s.FLOAT,!1,12,96),s.bindBuffer(s.ARRAY_BUFFER,this._ordersBuffer),s.vertexAttribPointer(n.order,this._ordersBuffer.itemSize,s.FLOAT,!1,4,0),s.bindBuffer(s.ELEMENT_ARRAY_BUFFER,this._indexesBuffer),s.drawElements(s.TRIANGLE_STRIP,this._indexesBuffer.numItems,s.UNSIGNED_INT,0),s.enable(s.CULL_FACE)}}_refresh(){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]=!0}_update(){if(this._renderNode){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1)}}_deleteBuffers(){if(this._renderNode){let e=this._renderNode.renderer.handler.gl;e.deleteBuffer(this._verticesHighBuffer),e.deleteBuffer(this._verticesLowBuffer),e.deleteBuffer(this._ordersBuffer),e.deleteBuffer(this._indexesBuffer),e.deleteBuffer(this._colorsBuffer),this._verticesHighBuffer=null,this._verticesLowBuffer=null,this._ordersBuffer=null,this._indexesBuffer=null,this._colorsBuffer=null}}_createVerticesBuffer(){let e=this._renderNode.renderer.handler,t=this._verticesHigh.length/3;this._verticesHighBuffer&&this._verticesHighBuffer.numItems===t||(e.gl.deleteBuffer(this._verticesHighBuffer),e.gl.deleteBuffer(this._verticesLowBuffer),this._verticesHighBuffer=e.createStreamArrayBuffer(3,t),this._verticesLowBuffer=e.createStreamArrayBuffer(3,t)),this._verticesHigh=Ve(this._verticesHigh),this._verticesLow=Ve(this._verticesLow),e.setStreamArrayBuffer(this._verticesHighBuffer,this._verticesHigh),e.setStreamArrayBuffer(this._verticesLowBuffer,this._verticesLow)}_createIndexBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._ordersBuffer),e.gl.deleteBuffer(this._indexesBuffer),this._orders=Ve(this._orders),this._ordersBuffer=e.createArrayBuffer(this._orders,1,this._orders.length/2),this._indexes=Ve(this._indexes,Uint32Array),this._indexesBuffer=e.createElementArrayBuffer(this._indexes,1,this._indexes.length)}_createColorsBuffer(){let e=this._renderNode.renderer.handler;e.gl.deleteBuffer(this._colorsBuffer),this._colors=Ve(this._colors),this._colorsBuffer=e.createArrayBuffer(new Float32Array(this._colors),4,this._colors.length/4)}setVisibleSphere(e,t){this._handler&&(this._visibleSphere[0]=e.x-this._handler._relativeCenter.x,this._visibleSphere[1]=e.y-this._handler._relativeCenter.y,this._visibleSphere[2]=e.z-this._handler._relativeCenter.z),this._visibleSphere[3]=t}updateRTCPosition(){this._handler&&this._renderNode&&(this._visibleSphere[0]=this._visibleSphere[0]-this._handler._relativeCenter.x,this._visibleSphere[1]=this._visibleSphere[1]-this._handler._relativeCenter.y,this._visibleSphere[2]=this._visibleSphere[2]-this._handler._relativeCenter.z,this._setEqualPath3v(this._path3v)),this._changedBuffers[0]=!0}}Ti.__counter__=0;class Ei{constructor(e={}){this.__id=Ei.__counter__++,this._thickness=e.thickness||2,this._startPosition=Ae(e.startPosition),this._startPositionHigh=new oe,this._startPositionLow=new oe,oe.doubleToTwoFloats(this._startPosition,this._startPositionHigh,this._startPositionLow),this._endPosition=Ae(e.endPosition),this._endPositionHigh=new oe,this._endPositionLow=new oe,oe.doubleToTwoFloats(this._endPosition,this._endPositionHigh,this._endPositionLow),this._startColor=Pe(e.startColor),this._endColor=Pe(e.endColor),this._visibility=null==e.visibility||e.visibility,this._entity=null,this._handler=null,this._handlerIndex=-1}setStartPosition(e,t,i){this._startPosition.x=e,this._startPosition.y=t,this._startPosition.z=i,oe.doubleToTwoFloats(this._startPosition,this._startPositionHigh,this._startPositionLow),this._handler&&this._handler.setStartPositionArr(this._handlerIndex,this._startPositionHigh,this._startPositionLow)}getLength(){return this._startPosition.distance(this._endPosition)}setStartPosition3v(e){this._startPosition.x=e.x,this._startPosition.y=e.y,this._startPosition.z=e.z,oe.doubleToTwoFloats(this._startPosition,this._startPositionHigh,this._startPositionLow),this._handler&&this._handler.setStartPositionArr(this._handlerIndex,this._startPositionHigh,this._startPositionLow)}setEndPosition(e,t,i){this._endPosition.x=e,this._endPosition.y=t,this._endPosition.z=i,oe.doubleToTwoFloats(this._endPosition,this._endPositionHigh,this._endPositionLow),this._handler&&this._handler.setEndPositionArr(this._handlerIndex,this._endPositionHigh,this._endPositionLow)}setEndPosition3v(e){this._endPosition.x=e.x,this._endPosition.y=e.y,this._endPosition.z=e.z,oe.doubleToTwoFloats(this._endPosition,this._endPositionHigh,this._endPositionLow),this._handler&&this._handler.setEndPositionArr(this._handlerIndex,this._endPositionHigh,this._endPositionLow)}setThickness(e){this._thickness=e,this._handler&&this._handler.setThicknessArr(this._handlerIndex,e)}setColors4v(e,t){e&&(this._startColor.x=e.x,this._startColor.y=e.y,this._startColor.z=e.z,this._startColor.w=e.w),t&&(this._endColor.x=t.x,this._endColor.y=t.y,this._endColor.z=t.z,this._endColor.w=t.w),this._handler&&this._handler.setRgbaArr(this._handlerIndex,this._startColor,this._endColor)}setColorsHTML(e,t){e&&(this._startColor=ye(e)),t&&(this._endColor=ye(t)),this._handler&&this._handler.setRgbaArr(this._handlerIndex,this._startColor,this._endColor)}getStartPosition(){return this._startPosition}getEndPosition(){return this._endPosition}setVisibility(e){this._visibility=e,this._handler&&this._handler.setVisibility(this._handlerIndex,e)}getVisibility(){return this._visibility}remove(){this._entity=null,this._handler&&this._handler.remove(this)}setPickingColor3v(e){this._handler&&this._handler.setPickingColorArr(this._handlerIndex,e)}}Ei.__counter__=0;let Li=new oe,Ai=new oe;class Pi{constructor(e={}){if(this.__id=Pi.__counter__++,this.visibility=null==e.visibility||e.visibility,this.color=new Float32Array([1,1,1,.5]),e.color){let t=Pe(e.color);this.setColor(t.x,t.y,t.z,t.w)}e.opacity&&this.setOpacity(e.opacity),this._renderNode=null,this._entity=null,this._verticesHighBuffer=null,this._verticesLowBuffer=null,this._indexBuffer=null,this._verticesHigh=[],this._verticesLow=[],this._indexes=[],this._path=[],this._pickingColor=new Float32Array(4),this._gridSize=1,this._handler=null,this._handlerIndex=-1,e.path&&this.setPath(e.path)}setPickingColor3v(e){this._pickingColor[0]=e.x/255,this._pickingColor[1]=e.y/255,this._pickingColor[2]=e.z/255,this._pickingColor[3]=1}clear(){this._path.length=0,this._path=[],this._verticesHigh.length=0,this._verticesHigh=[],this._verticesLow.length=0,this._verticesLow=[],this._indexes.length=0,this._indexes=[],this._deleteBuffers()}setColor4v(e){this.setColor(e.x,e.y,e.z,e.w)}setColorHTML(e){this.setColor4v(ye(e))}setColor(e,t,i,s){s=s||this.color[3],this.color[0]=e,this.color[1]=t,this.color[2]=i,this.color[3]=s}setOpacity(e){this.color[3]=e||0}setVisibility(e){this.visibility=e}getVisibility(){return this.visibility}setRenderNode(e){this._renderNode=e,this._createBuffers()}remove(){this._entity=null,this._handler&&this._handler.remove(this)}draw(){if(this.visibility&&this._verticesHigh.length){let e=this._renderNode.renderer,t=e.handler.gl,i=e.handler.programs.strip,s=i._program,n=s.attributes,r=s.uniforms;i.activate(),t.disable(t.CULL_FACE),t.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),t.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),t.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),t.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),t.uniform4fv(r.uColor,this.color),t.uniform1f(r.uOpacity,this._entity._entityCollection._fadingOpacity),t.bindBuffer(t.ARRAY_BUFFER,this._verticesHighBuffer),t.vertexAttribPointer(n.aVertexPositionHigh,this._verticesHighBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._verticesLowBuffer),t.vertexAttribPointer(n.aVertexPositionLow,this._verticesLowBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this._indexBuffer),t.drawElements(e.handler.gl.TRIANGLE_STRIP,this._indexBuffer.numItems,t.UNSIGNED_INT,0),t.enable(t.CULL_FACE)}}drawPicking(){if(this.visibility&&this._verticesHigh.length){let e=this._renderNode.renderer,t=e.handler.gl,i=e.handler.programs.strip,s=i._program,n=s.attributes,r=s.uniforms;i.activate(),t.disable(t.CULL_FACE),t.uniformMatrix4fv(r.viewMatrix,!1,e.activeCamera.getViewMatrix()),t.uniformMatrix4fv(r.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),t.uniform3fv(r.eyePositionHigh,e.activeCamera.eyeHigh),t.uniform3fv(r.eyePositionLow,e.activeCamera.eyeLow),t.uniform1f(r.uOpacity,0!=this._entity._entityCollection._fadingOpacity?1:0),t.uniform4fv(r.uColor,this._pickingColor),t.bindBuffer(t.ARRAY_BUFFER,this._verticesHighBuffer),t.vertexAttribPointer(n.aVertexPositionHigh,this._verticesHighBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._verticesLowBuffer),t.vertexAttribPointer(n.aVertexPositionLow,this._verticesLowBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this._indexBuffer),t.drawElements(e.handler.gl.TRIANGLE_STRIP,this._indexBuffer.numItems,t.UNSIGNED_INT,0),t.enable(t.CULL_FACE)}}_deleteBuffers(){if(this._renderNode&&this._renderNode.renderer){let e=this._renderNode.renderer.handler.gl;e.deleteBuffer(this._indexBuffer),e.deleteBuffer(this._verticesHighBuffer),e.deleteBuffer(this._verticesLowBuffer)}this._verticesHighBuffer=null,this._verticesLowBuffer=null,this._indexBuffer=null}_createBuffers(){if(this._renderNode&&this._renderNode.renderer&&this._renderNode.renderer.isInitialized()){let e=this._renderNode.renderer.handler.gl;e.deleteBuffer(this._indexBuffer),e.deleteBuffer(this._verticesHighBuffer),e.deleteBuffer(this._verticesLowBuffer),this._verticesHighBuffer=this._renderNode.renderer.handler.createArrayBuffer(new Float32Array(this._verticesHigh),3,this._verticesHigh.length/3),this._verticesLowBuffer=this._renderNode.renderer.handler.createArrayBuffer(new Float32Array(this._verticesLow),3,this._verticesLow.length/3),this._indexBuffer=this._renderNode.renderer.handler.createElementArrayBuffer(new Uint32Array(this._indexes),1,this._indexes.length)}}addEdge3v(e,t){let i=this._path.length;if(0===i)this._path.push([e.clone(),t.clone()]);else{let s=this._path[i-1][0],n=this._path[i-1][1];this._path.push([e.clone(),t.clone()]);let r=this._verticesHigh,o=this._verticesLow,a=this._gridSize,l=a+1,h=new oe,c=this._verticesHigh.length/3,d=c,_=Math.abs(s.sub(n).normal().dot(e.sub(s).normal()));for(let i=0;i<l;i++){let u=i/a,g=s.lerp(e,u),f=n.lerp(t,u);for(let u=0;u<l;u++){let p=u/a,m=s.lerp(n,p),v=e.lerp(t,p);1!==_?new di(g,f).intersects(new di(m,v),h):h=v,d=c+i*l+u,oe.doubleToTwoFloats(h,Li,Ai);let y=3*d;r[y]=Li.x,r[y+1]=Li.y,r[y+2]=Li.z,o[y]=Ai.x,o[y+1]=Ai.y,o[y+2]=Ai.z,i<a&&this._indexes.push(d,d+l)}i<a&&this._indexes.push(d+l,d+1)}this._createBuffers()}}setEdge3v(e,t,i){if(i!==this._path.length)if(this._path[i]){if(this._path[i][0]=e,this._path[i][1]=t,this._path.length>1){let s=this._gridSize,n=s+1,r=n*n,o=new oe,a=this._verticesHigh,l=this._verticesLow;if(i===this._path.length-1){let h=this._path[i-1][0],c=this._path[i-1][1],d=this._verticesHigh.length/3-r,_=d,u=Math.abs(h.sub(c).normal().dot(e.sub(h).normal()));for(let i=0;i<n;i++){let r=i/s,g=h.lerp(e,r),f=c.lerp(t,r);for(let r=0;r<n;r++){let p=r/s,m=h.lerp(c,p),v=e.lerp(t,p);1!==u?new di(g,f).intersects(new di(m,v),o):o=v,_=d+i*n+r,oe.doubleToTwoFloats(o,Li,Ai);let y=3*_;a[y]=Li.x,a[y+1]=Li.y,a[y+2]=Li.z,l[y]=Ai.x,l[y+1]=Ai.y,l[y+2]=Ai.z}}}else if(0===i){let i=0,r=e,h=t;e=this._path[1][0],t=this._path[1][1];for(let c=0;c<n;c++){let d=c/s,_=r.lerp(e,d),u=h.lerp(t,d);for(let d=0;d<n;d++){let g=d/s,f=r.lerp(h,g),p=e.lerp(t,g);new di(_,u).intersects(new di(f,p),o),i=c*n+d,oe.doubleToTwoFloats(o,Li,Ai);let m=3*i;a[m]=Li.x,a[m+1]=Li.y,a[m+2]=Li.z,l[m]=Ai.x,l[m+1]=Ai.y,l[m+2]=Ai.z}}}else if(i>0&&i<this._path.length){let h=this._path[i-1][0],c=this._path[i-1][1],d=this._path[i+1][0],_=this._path[i+1][1],u=i*r,g=(i-1)*r,f=g;for(let i=0;i<n;i++){let r=i/s,p=h.lerp(e,r),m=t.lerp(_,r),v=e.lerp(d,r),y=c.lerp(t,r);for(let r=0;r<n;r++){let x=r/s,b=h.lerp(c,x),w=e.lerp(t,x);new di(p,y).intersects(new di(b,w),o);let C=i*n+r;f=g+C,oe.doubleToTwoFloats(o,Li,Ai);let T=3*f;a[T]=Li.x,a[T+1]=Li.y,a[T+2]=Li.z,l[T]=Ai.x,l[T+1]=Ai.y,l[T+2]=Ai.z;let E=d.lerp(_,x);w=e.lerp(t,x),new di(v,m).intersects(new di(w,E),o),f=u+C,oe.doubleToTwoFloats(o,Li,Ai),T=3*f,a[T]=Li.x,a[T+1]=Li.y,a[T+2]=Li.z,l[T]=Ai.x,l[T+1]=Ai.y,l[T+2]=Ai.z}}}this._createBuffers()}}else console.warn(`strip index ${i} is out of range`);else this.addEdge3v(e,t)}removeEdge(e){this._path.splice(e,1),this.setPath([].concat(this._path))}setGridSize(e){this._gridSize=e,this.setPath([].concat(this._path))}getPath(){return this._path}setPath(e){this._verticesHigh=[],this._verticesLow=[],this._indexes=[],this._path=[];for(let t=0;t<e.length;t++){let i=e[t][0],s=e[t][1];i instanceof Array&&(i=new oe(i[0],i[1],i[2])),s instanceof Array&&(s=new oe(s[0],s[1],s[2])),this.addEdge3v(i,s)}}insertEdge3v(e,t,i){if(i<this._path.length){let s=[].concat(this._path);s.splice(i,0,[e,t]),this.setPath(s)}else i===this._path.length&&this.addEdge3v(e,t)}}Pi.__counter__=0;class Si{constructor(e={}){e.properties=e.properties||{},this.__id=Si.__counter__++,this.properties=e.properties||{},this.properties.name=null!=this.properties.name?this.properties.name:"",this.childEntities=[],this.parent=null,this.forceGlobalPosition=e.forceGlobalPosition||!1,this.forceGlobalRotation=e.forceGlobalRotation||!1,this.forceGlobalScale=e.forceGlobalScale||!1,this._cartesian=Ae(e.cartesian),this._rootCartesian=new oe,this._localPosition=Ae(e.localPosition),this._absoluteLocalPosition=new oe,this._lonLat=Re(e.lonlat),this._lonLatMerc=new I,this._altitude=e.altitude||0,this._visibility=null==e.visibility||e.visibility,this._entityCollection=null,this._entityCollectionIndex=-1,this._layer=null,this._layerIndex=-1,this._pickingColor=new oe(0,0,0),this._independentPicking=e.independentPicking||!1,this._relativePosition=e.relativePosition||!1,this._pitchRad=e.pitch||0,this._yawRad=e.yaw||0,this._rollRad=e.roll||0,this._scale=Ae(e.scale,new oe(1,1,1)),this._qFrame=re.IDENTITY,this._qRot=re.IDENTITY,this._absoluteQRot=re.IDENTITY,this._featureConstructorArray={billboard:[oi,this.setBillboard],label:[wi,this.setLabel],polyline:[Ti,this.setPolyline],pointCloud:[Ci,this.setPointCloud],geometry:[hi,this.setGeometry],geoObject:[yi,this.setGeoObject],strip:[Pi,this.setStrip],ray:[Ei,this.setRay]},this.billboard=this._createOptionFeature("billboard",e.billboard),this.label=this._createOptionFeature("label",e.label),this.polyline=this._createOptionFeature("polyline",e.polyline),this.ray=this._createOptionFeature("ray",e.ray),this.pointCloud=this._createOptionFeature("pointCloud",e.pointCloud),this.geometry=this._createOptionFeature("geometry",e.geometry),this.geoObject=this._createOptionFeature("geoObject",e.geoObject),this.strip=this._createOptionFeature("strip",e.strip)}get rootEntity(){let e=this;for(;e;){if(!e.parent)return e;e=e.parent}return this}set relativePosition(e){if(e!==this._relativePosition){let t=this.getAbsoluteCartesian(),i=this.getAbsolutePitch(),s=this.getAbsoluteYaw(),n=this.getAbsoluteRoll();this._relativePosition=e,this.parent&&this._rootCartesian.copy(this.parent._rootCartesian),e?this.parent&&(this.setAbsoluteCartesian3v(t),this.setAbsolutePitch(i),this.setAbsoluteYaw(s),this.setAbsoluteRoll(n)):(this.setCartesian3v(t),this.setPitch(i),this.setYaw(s),this.setRoll(n))}}get relativePosition(){return this._relativePosition}get entityCollection(){return this._entityCollection}get id(){return this.__id}isEqual(e){return this.__id===e.__id}get layerIndex(){return this._layerIndex}get instanceName(){return"Entity"}_createOptionFeature(e,t){if(t){let i=this._featureConstructorArray[e];return i[1].call(this,new i[0](t))}return null}getCollectionIndex(){return this._entityCollectionIndex}addTo(e,t=!1){return e.add(this,t),this}remove(){this._layer&&this._layer.removeEntity(this),this._entityCollection&&this._entityCollection.removeEntity(this)}setVisibility(e){this._visibility=e,this.billboard&&this.billboard.setVisibility(e),this.geoObject&&this.geoObject.setVisibility(e),this.label&&this.label.setVisibility(e),this.polyline&&this.polyline.setVisibility(e),this.ray&&this.ray.setVisibility(e),this.geometry&&this.geometry.setVisibility(e);for(let t=0;t<this.childEntities.length;t++)this.childEntities[t].setVisibility(e)}getVisibility(){return this._visibility}setCartesian3v(e){this.setCartesian(e.x,e.y,e.z)}getScale(){return this._scale}setScale3v(e){this._scale.copy(e),this.geoObject&&this.geoObject.setScale3v(this._scale);for(let e=0;e<this.childEntities.length;e++){let t=this.childEntities[e];t.forceGlobalScale?t.setScale3v(this._scale):t.setScale3v(this.childEntities[e].getScale())}}setScale(e){this._scale.set(e,e,e),this.geoObject&&this.geoObject.setScale(e);for(let t=0;t<this.childEntities.length;t++){let i=this.childEntities[t];i.forceGlobalScale?i.setScale(e):i.setScale3v(this.childEntities[t].getScale())}}getAbsoluteRotation(){return this._absoluteQRot.clone()}getRotation(){return this._qRot}setLook3v(e){let t,i=new re,s=this.getAbsoluteCartesian();if(this._entityCollection){let n=this._entityCollection.renderNode.ellipsoid.getSurfaceNormal3v(s);t=i.setLookRotation(e.sub(s),n).conjugate()}else t=i.setLookRotation(e.sub(s),oe.UP).conjugate();this.setAbsoluteRotation(t)}setLookLonLat(e){if(this._entityCollection){let t=this._entityCollection.renderNode.ellipsoid.lonLatToCartesian(e);this.setLook3v(t)}}setAbsoluteRotation(e){this._absoluteQRot.copy(e),this._updatePitchYawRoll()}setRotation(e){}setPitch(e){this._pitchRad=e,this._updateAbsolutePosition()}setYaw(e){this._yawRad=e,this._updateAbsolutePosition()}setRoll(e){this._rollRad=e,this._updateAbsolutePosition()}getPitch(){return this._pitchRad}getYaw(){return this._yawRad}getRoll(){return this._rollRad}setAbsolutePitch(e){this._relativePosition?(this._absoluteQRot.setPitchYawRoll(e,this.getAbsoluteYaw(),this.getAbsoluteRoll(),this._qFrame),this._updatePitchYawRoll()):this.setPitch(e)}setAbsoluteYaw(e){this._relativePosition?(this._absoluteQRot.setPitchYawRoll(this.getAbsolutePitch(),e,this.getAbsoluteRoll(),this._qFrame),this._updatePitchYawRoll()):this.setYaw(e)}setAbsoluteRoll(e){this._relativePosition?(this._absoluteQRot.setPitchYawRoll(this.getAbsolutePitch(),this.getAbsoluteYaw(),e,this._qFrame),this._updatePitchYawRoll()):this.setRoll(e)}getAbsolutePitch(){return this.parent&&this._relativePosition?this._qFrame.conjugate().inverse().mul(this._absoluteQRot).getPitch():this._pitchRad}getAbsoluteYaw(){return this.parent&&this._relativePosition?this._qFrame.conjugate().inverse().mul(this._absoluteQRot).getYaw():this._yawRad}getAbsoluteRoll(){return this.parent&&this._relativePosition?this._qFrame.conjugate().inverse().mul(this._absoluteQRot).getRoll():this._rollRad}_getScaleByDistance(){let e=1;if(this._entityCollection){let t=this._entityCollection.scaleByDistance,i=1;this._entityCollection.renderNode&&this._entityCollection.renderNode.renderer&&(i=this._entityCollection.renderNode.renderer.activeCamera.eye.distance(this._rootCartesian)),e=t[2]*m(i,t[0],t[1])/t[0]}return e}setAbsoluteCartesian(e,t,i){this.setAbsoluteCartesian3v(new oe(e,t,i))}setAbsoluteCartesian3v(e){let t=e;if(this.parent&&this._relativePosition){let i=this._getScaleByDistance();t=e.sub(this.parent.getAbsoluteCartesian()).scale(1/i),t=this.parent._absoluteQRot.conjugate().mulVec3(t)}this.setCartesian3v(t)}getAbsoluteCartesian(){if(this.parent&&this._relativePosition){let e=this._getScaleByDistance();return this._rootCartesian.add(this._absoluteLocalPosition.scaleTo(e))}return this._cartesian.clone()}setCartesian(e,t,i){this._cartesian.set(e,t,i),this._updateAbsolutePosition();for(let s=0;s<this.childEntities.length;s++){let n=this.childEntities[s];n._relativePosition?n.setCartesian3v(n.getCartesian()):n.forceGlobalPosition&&n.setCartesian(e,t,i)}this._updateLonLat()}_updatePitchYawRoll(){if(this.parent){this._qRot=this.parent._absoluteQRot.conjugate().mul(this._absoluteQRot),this._pitchRad=this._qRot.getPitch(),this._yawRad=this._qRot.getYaw(),this._rollRad=this._qRot.getRoll(),this.geoObject&&this.geoObject.setRotation(this._absoluteQRot);for(let e=0;e<this.childEntities.length;e++)this.childEntities[e]._updateAbsolutePosition()}}_updateAbsolutePosition(){let e=this.parent;if(e&&this._relativePosition){this._qFrame.copy(e._qFrame),this._rootCartesian.copy(e._rootCartesian),this._qRot.setPitchYawRoll(this._pitchRad,this._yawRad,this._rollRad),e._absoluteQRot.mulRes(this._qRot,this._absoluteQRot);let t=e._absoluteQRot.mulVec3(this._cartesian.add(this._localPosition));e._absoluteLocalPosition.addRes(t,this._absoluteLocalPosition)}else this._qFrame=re.IDENTITY,this._entityCollection&&this._entityCollection.renderNode&&(this._qFrame=this._entityCollection.renderNode.getFrameRotation(this._cartesian)),e&&this.forceGlobalRotation?this._qRot.setPitchYawRoll(e._pitchRad,e._yawRad,e._rollRad,this._qFrame):this._qRot.setPitchYawRoll(this._pitchRad,this._yawRad,this._rollRad,this._qFrame),this._absoluteQRot.copy(this._qRot),this._rootCartesian.copy(this._cartesian),this._absoluteLocalPosition.copy(this._localPosition);this.geoObject&&(this.geoObject.setRotation(this._absoluteQRot),this.geoObject.setPosition3v(this._rootCartesian),this.geoObject.setLocalPosition3v(this._absoluteLocalPosition)),this.billboard&&this.billboard.setPosition3v(this._rootCartesian),this.label&&this.label.setPosition3v(this._rootCartesian);for(let e=0,t=this.childEntities.length;e<t;e++)this.childEntities[e]._updateAbsolutePosition();this._updateLonLat()}_setCartesian3vSilent(e,t=!1){this._cartesian.copy(e),this._updateAbsolutePosition();for(let e=0;e<this.childEntities.length;e++)this.childEntities[e].setCartesian(this._cartesian.x,this._cartesian.y,this._cartesian.z);t||this._updateLonLat()}_updateLonLat(){let e=this._entityCollection;e&&e.renderNode&&e.renderNode.ellipsoid&&(this._lonLat=e.renderNode.ellipsoid.cartesianToLonLat(this.getAbsoluteCartesian()),Math.abs(this._lonLat.lat)<Q?this._lonLatMerc=this._lonLat.forwardMercator():this._lonLatMerc.lon=this._lonLatMerc.lat=0)}getLonLat(){return this._lonLat.clone()}setLonLat(e){let t=this._lonLat;t.lon=e.lon,t.lat=e.lat,t.height=e.height;let i=this._entityCollection;if(i&&i.renderNode&&i.renderNode.ellipsoid){Math.abs(t.lat)<Q&&(this._lonLatMerc=t.forwardMercator());let e=new oe;i.renderNode.ellipsoid.lonLatToCartesianRes(t,e),this.setAbsoluteCartesian3v(e)}}setLonLat2(e,t,i){let s=this._lonLat;s.lon=e,s.lat=t,s.height=null!=i?i:s.height;let n=this._entityCollection;if(n&&n.renderNode&&n.renderNode.ellipsoid){Math.abs(s.lat)<Q?this._lonLatMerc=s.forwardMercator():this._lonLatMerc.lon=this._lonLatMerc.lat=this._lonLatMerc.height=0;let e=new oe;n.renderNode.ellipsoid.lonLatToCartesianRes(s,e),this.setAbsoluteCartesian3v(e)}}setAltitude(e){this._altitude=e}getAltitude(){return this._altitude}getCartesian(){return this._cartesian.clone()}setBillboard(e){return this.billboard&&this.billboard.remove(),this.billboard=e,this.billboard._entity=this,this.billboard.setPosition3v(this._cartesian),this.billboard.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.billboardHandler.add(e),e}setLabel(e){return this.label&&this.label.remove(),this.label=e,this.label._entity=this,this.label.setPosition3v(this._cartesian),this.label.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.labelHandler.add(e),e}setRay(e){return this.ray&&this.ray.remove(),this.ray=e,this.ray._entity=this,this.ray.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.rayHandler.add(e),e}setPolyline(e){return this.polyline&&this.polyline.remove(),this.polyline=e,this.polyline._entity=this,this.polyline.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.polylineHandler.add(e),e}setPointCloud(e){return this.pointCloud&&this.pointCloud.remove(),this.pointCloud=e,this.pointCloud._entity=this,this.pointCloud.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.pointCloudHandler.add(e),e}setGeometry(e){this.geometry&&this.geometry.remove(),this.geometry=e,this.geometry._entity=this,this.geometry.setVisibility(this._visibility);let t=this._layer;return this._layer&&this._layer.removeEntity(this),t&&t.add(this),e}setGeoObject(e){return this.geoObject&&this.geoObject.remove(),this.geoObject=e,this.geoObject._entity=this,this.geoObject.setPosition3v(this._cartesian),this.geoObject.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.geoObjectHandler.add(e),e}setStrip(e){return this.strip&&this.strip.remove(),this.strip=e,this.strip._entity=this,this.strip.setVisibility(this._visibility),this._entityCollection&&this._entityCollection.stripHandler.add(e),e}get layer(){return this._layer}get rendererEvents(){return this._layer?this._layer.events:this._entityCollection?this._entityCollection.events:null}appendChild(e){e._entityCollection=this._entityCollection,e._independentPicking||(e._pickingColor=this._pickingColor),e.parent=this,this.childEntities.push(e),this._entityCollection&&this._entityCollection.appendChildEntity(e)}setPickingColor(){let e=this._pickingColor;this.billboard&&this.billboard.setPickingColor3v(e),this.label&&this.label.setPickingColor3v(e),this.polyline&&this.polyline.setPickingColor3v(e),this.ray&&this.ray.setPickingColor3v(e),this.strip&&this.strip.setPickingColor3v(e),this.geoObject&&this.geoObject.setPickingColor3v(e);for(let e=0;e<this.childEntities.length;e++)this.childEntities[e].setPickingColor()}getExtent(){let e,t=this._lonLat;e=this.billboard||this.label?new te(new I(t.lon,t.lat),new I(t.lon,t.lat)):new te(new I(180,90),new I(-180,-90));let i=e.southWest,s=e.northEast;if(this.polyline){let e=this.polyline.getExtent();e.southWest.lon<i.lon&&(i.lon=e.southWest.lon),e.southWest.lat<i.lat&&(i.lat=e.southWest.lat),e.northEast.lon>s.lon&&(s.lon=e.northEast.lon),e.northEast.lat>s.lat&&(s.lat=e.northEast.lat)}if(this.geometry){let e=this.geometry.getExtent();e.southWest.lon<i.lon&&(i.lon=e.southWest.lon),e.southWest.lat<i.lat&&(i.lat=e.southWest.lat),e.northEast.lon>s.lon&&(s.lon=e.northEast.lon),e.northEast.lat>s.lat&&(s.lat=e.northEast.lat)}for(let e=0;e<this.childEntities.length;e++){let t=this.childEntities[e].getExtent();t.southWest.lon<i.lon&&(i.lon=t.southWest.lon),t.southWest.lat<i.lat&&(i.lat=t.southWest.lat),t.northEast.lon>s.lon&&(s.lon=t.northEast.lon),t.northEast.lat>s.lat&&(s.lat=t.northEast.lat)}return e}}Si.__counter__=0;class Mi{constructor(e){this.__id=Mi.__counter__++,this._name=e||`nonameNode:${this.__id}`,this.topNode=this,this._dictionary={},this._dictionary[this._name]=this,this.childNodes=[],this.parentNode=null}get name(){return this._name}addNode(e){null==this.parentNode?e.topNode=this:e.topNode=this.topNode,e.parentNode=this,e._dictionary=this.topNode._dictionary,this.childNodes.push(e),this.topNode._dictionary[e.name]=e}destroy(){for(let e=0;e<this.childNodes.length;e++)this.childNodes[e].destroy();this._clear()}getNodeByName(e){return this._dictionary[e]}_clear(){this.parentNode=null,this.topNode=this,this.childNodes.length=0}isEqual(e){return e.__id===this.__id}}Mi.__counter__=0;class Ri extends Mi{constructor(e){super(e),this.childNodes=[],this.renderer=null,this.drawMode=0,this.show=!0,this._isActive=!0,this.lightEnabled=!1,this._lightPosition=new Float32Array([100,100,100]),this._lightParams=new Float32Array(9),this._lightShininess=100,this.entityCollections=[],this._entityCollectionsByDepthOrder=[],this._pickingId=-1}getFrameRotation(e){return re.IDENTITY}addNode(e){super.addNode(e),this.renderer&&e.assign(this.renderer)}assign(e){this.renderer=e,this._pickingId=e.addPickingCallback(this,this._entityCollectionPickingCallback),this.initialize()}initialize(){if(this.renderer&&this.renderer.isInitialized()){for(let e=0;e<this.entityCollections.length;e++)this.entityCollections[e].bindRenderNode(this);this.init()}}init(){}onremove(){}remove(){let e=this.renderer,t=this.name;if(e){e.renderNodes[t]&&e.renderNodes[t].isEqual(this)&&(e.renderNodes[t]=null,delete e.renderNodes[t]);for(let t=0;t<e._renderNodesArr.length;t++)if(e._renderNodesArr[t].isEqual(this)){e._renderNodesArr.splice(t,1);break}e.removePickingCallback(this._pickingId),this._pickingId=-1,this.onremove&&this.onremove()}}addEntityCollection(e,t){e.renderNode||(e.renderNode=this,t||(this.entityCollections.push(e),this.updateEntityCollectionsDepthOrder()),this.ellipsoid&&e._updateGeodeticCoordinates(this.ellipsoid),e.bindRenderNode(this),e.events.dispatch(e.events.add,this))}removeEntityCollection(e){for(let t=0;t<this.entityCollections.length;t++)if(this.entityCollections[t].isEqual(e))return this.entityCollections.splice(t,1),void this.updateEntityCollectionsDepthOrder()}updateEntityCollectionsDepthOrder(){let e={0:[]};for(const t of this.entityCollections)t.getVisibility()&&(e[t.depthOrder]||(e[t.depthOrder]=[]),e[t.depthOrder].push(t));this._entityCollectionsByDepthOrder.length=0,this._entityCollectionsByDepthOrder=[],this._entityCollectionsByDepthOrder=Object.keys(e).sort(((e,t)=>Number(e)-Number(t))).map((t=>e[Number(t)]))}addLight(e){return e.addTo(this),this}preDrawNode(){this._isActive&&this._preDrawNodes()}drawNode(){this._isActive&&this._drawNodes()}isActive(){return this._isActive}setActive(e){this._isActive=e,this.renderer&&(this._isActive&&-1===this._pickingId?this._pickingId=this.renderer.addPickingCallback(this,this._entityCollectionPickingCallback):this._isActive||-1===this._pickingId||(this.renderer.removePickingCallback(this._pickingId),this._pickingId=-1));for(let t=0;t<this.childNodes.length;t++)this.childNodes[t].setActive(e)}setDrawMode(e){this.drawMode=e;for(let t=0;t<this.childNodes.length;t++)this.childNodes[t].setDrawMode(e)}updateBillboardsTexCoords(){for(let e=0;e<this.entityCollections.length;e++)this.entityCollections[e].billboardHandler.refreshTexCoordsArr()}frame(){}preFrame(){}_preDrawNodes(){for(let e=0;e<this.childNodes.length;e++)this.childNodes[e]._isActive&&this.childNodes[e]._preDrawNodes();if(this.show){this.preFrame();for(let e=0;e<this._entityCollectionsByDepthOrder.length;e++)this.drawEntityCollections(this._entityCollectionsByDepthOrder[e],e)}}_drawNodes(){for(let e=0;e<this.childNodes.length;e++)this.childNodes[e]._isActive&&this.childNodes[e]._drawNodes();this.show&&this.frame()}drawEntityCollections(e,t=0){this.renderer.enqueueEntityCollectionsToDraw(e,t)}drawPickingEntityCollections(e){if(e.length){let t=e.length;for(;t--;)e[t]._fadingOpacity&&e[t].billboardHandler.drawPicking();for(t=e.length;t--;)e[t]._fadingOpacity&&e[t].geoObjectHandler.drawPicking();for(t=e.length;t--;)e[t]._fadingOpacity&&e[t].labelHandler.drawPicking();for(t=e.length;t--;)e[t]._fadingOpacity&&e[t].rayHandler.drawPicking();for(t=e.length;t--;)e[t]._visibility&&e[t].polylineHandler.drawPicking();for(t=e.length;t--;)e[t]._visibility&&e[t].stripHandler.drawPicking()}}_entityCollectionPickingCallback(){}}const Bi=new class{constructor(){this._container=document.createElement("div"),this._container.classList.add("ogConsole"),this._container.style.display="none",document.body&&document.body.appendChild(this._container),this._visibility=!1}getVisibility(){return this._visibility}setVisibility(e){this._visibility!=e&&(this._visibility=e,this._visibility?this.show():this.hide())}show(){this._container.parentNode||document.body&&document.body.appendChild(this._container),this._container.style.display="block",this._visibility=!0}hide(){this._container.style.display="none",this._visibility=!1}logErr(e){let t=document.createElement("div");t.classList.add("ogConsole-text"),t.classList.add("ogConsole-error"),t.innerHTML="error: "+e,console.trace(t.innerHTML),this._container.appendChild(t),this.show()}logWrn(e){let t=document.createElement("div");t.classList.add("ogConsole-text"),t.classList.add("ogConsole-warning"),t.innerHTML="warning: "+e,console.trace(t.innerHTML),this._container.appendChild(t),this.show()}log(e){let t=document.createElement("div");t.classList.add("ogConsole-text"),t.innerHTML=e,console.trace(e),this._container.appendChild(t),this.show()}};let ki=["FLOAT","DOUBLE","BOOL","INT","UINT","VEC2","VEC3","VEC4","DVEC2","DVEC3","DVEC4","BVEC2","BVEC3","BVEC4","IVEC2","IVEC3","IVEC4","UVEC2","UVEC3","UVEC4","MAT2","DMAT2","MAT3","DMAT3","MAT4","DMAT4","MAT2X3","MAT2X4","MAT3X2","MAT3X4","MAT4X2","MAT4X3","DMAT2X3","DMAT2X4","DMAT3X2","DMAT3X4","DMAT4X2","DMAT4X3","SAMPLER1D","SAMPLER2D","SAMPLER3D","SAMPLERCUBE","SAMPLER2DSHADOW","SAMPLER2DARRAY","INTXX","FLOATXX"];const Ii={};for(let e=0;e<ki.length;e++)Ii[ki[e]]=e;const zi={};for(let e=0;e<ki.length;e++)zi[ki[e].toLowerCase()]=Ii[ki[e]];const Di={u:[],a:[]};Di.u[Ii.MAT4]=function(e,t){e.gl.uniformMatrix4fv(t._pName,!1,t.value)},Di.u[Ii.MAT3]=function(e,t){e.gl.uniformMatrix3fv(t._pName,!1,t.value)},Di.u[Ii.FLOAT]=function(e,t){e.gl.uniform1f(t._pName,t.value)},Di.u[Ii.INT]=function(e,t){e.gl.uniform1i(t._pName,t.value)},Di.u[Ii.VEC2]=function(e,t){e.gl.uniform2fv(t._pName,t.value)},Di.u[Ii.VEC3]=function(e,t){e.gl.uniform3fv(t._pName,t.value)},Di.u[Ii.VEC4]=function(e,t){e.gl.uniform4fv(t._pName,t.value)},Di.u[Ii.SAMPLER2D]=function(e,t){let i=e.gl;i.activeTexture(i.TEXTURE0+e._textureID),i.bindTexture(i.TEXTURE_2D,t.value),i.uniform1i(t._pName,e._textureID),e._textureID++},Di.u[Ii.SAMPLERCUBE]=function(e,t){let i=e.gl;i.activeTexture(i.TEXTURE0+e._textureID),i.bindTexture(i.TEXTURE_CUBE_MAP,t.value),i.uniform1i(t._pName,e._textureID),e._textureID++},Di.u[Ii.SAMPLER2DARRAY]=function(e,t){let i=t.value,s=e.gl,n=i.length,r=new Int32Array(n);for(let t=0;t<n;t++)s.activeTexture(s.TEXTURE0+e._textureID+t),s.bindTexture(s.TEXTURE_2D,i[t]),r[t]=t;s.uniform1iv(t._pName,r)},Di.u[Ii.INTXX]=function(e,t){e.gl.uniform1iv(t._pName,t.value)},Di.u[Ii.FLOATXX]=function(e,t){e.gl.uniform1fv(t._pName,t.value)},Di.a[Ii.FLOAT]=function(e,t){e.gl.vertexAttrib1f(t._pName,t.value)},Di.a[Ii.VEC2]=function(e,t){e.gl.vertexAttrib2fv(t._pName,t.value)},Di.a[Ii.VEC3]=function(e,t){e.gl.vertexAttrib3fv(t._pName,t.value)};const Fi=["BYTE","SHORT","UNSIGNED_BYTE","UNSIGNED_SHORT","FLOAT","HALF_FLOAT"];class Ni{constructor(e,t){this.name=e,this._attributes={};for(let e in t.attributes)"string"==typeof t.attributes[e]||"number"==typeof t.attributes[e]?this._attributes[e]={type:t.attributes[e]}:this._attributes[e]=t.attributes[e];this._uniforms={};for(let e in t.uniforms)"string"==typeof t.uniforms[e]||"number"==typeof t.uniforms[e]?this._uniforms[e]={type:t.uniforms[e]}:this._uniforms[e]=t.uniforms[e];this.vertexShader=t.vertexShader,this.fragmentShader=t.fragmentShader,this.gl=null,this._variables={},this._p=null,this._textureID=0,this._attribArrays=[],this._attribDivisor=[],this.attributes={},this.uniforms={},this.vertexAttribDivisor=null,this.drawElementsInstanced=null}static bindBuffer(e,t){let i=e.gl;i&&(i.bindBuffer(i.ARRAY_BUFFER,t.value),i.vertexAttribPointer(t._pName,t.value.itemSize,t.itemType,t.normalized,0,0))}use(){this.gl&&this.gl.useProgram(this._p)}set(e){this._textureID=0;for(let t in e)this._variables[t].value=e[t],this._variables[t].func(this,this._variables[t])}apply(){this._textureID=0;let e=this._variables;for(let t in e)e[t].func(this,e[t])}drawIndexBuffer(e,t){let i=this.gl;i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,t),i.drawElements(e,t.numItems,i.UNSIGNED_SHORT,0)}drawArrays(e,t){this.gl.drawArrays(e,0,t)}_getShaderCompileStatus(e,t){return!!this.gl&&(this.gl.shaderSource(e,t),this.gl.compileShader(e),!!this.gl.getShaderParameter(e,this.gl.COMPILE_STATUS)||(Bi.logErr(`Shader program "${this.name}":${this.gl.getShaderInfoLog(e)}.`),!1))}_createVertexShader(e){if(!this.gl)return;let t=this.gl.createShader(this.gl.VERTEX_SHADER);return t&&this._getShaderCompileStatus(t,e)?t:void 0}_createFragmentShader(e){if(!this.gl)return;let t=this.gl.createShader(this.gl.FRAGMENT_SHADER);return t&&this._getShaderCompileStatus(t,e)?t:void 0}disableAttribArrays(){let e=this.gl,t=this._attribArrays;for(let i=0,s=t.length;i<s;i++)e.disableVertexAttribArray(t[i]),this.vertexAttribDivisor(t[i],0)}enableAttribArrays(){let e=this.gl,t=this._attribArrays,i=this._attribDivisor;for(let s=0,n=t.length;s<n;s++)e.enableVertexAttribArray(t[s]),this.vertexAttribDivisor(t[s],i[s])}delete(){this.gl&&this.gl.deleteProgram(this._p)}createProgram(e){if(this.gl=e,this._p=this.gl.createProgram(),!this._p)return;let t=this._createFragmentShader(this.fragmentShader),i=this._createVertexShader(this.vertexShader);if(t&&i){if(e.attachShader(this._p,t),e.attachShader(this._p,i),e.linkProgram(this._p),!this.drawElementsInstanced)if(e.drawElementsInstanced)this.drawElementsInstanced=e.drawElementsInstanced.bind(e);else{let t=e.getExtension("ANGLE_instanced_arrays");t&&(this.drawElementsInstanced=t.drawElementsInstancedANGLE.bind(t))}if(!this.vertexAttribDivisor)if(e.vertexAttribDivisor)this.vertexAttribDivisor=e.vertexAttribDivisor.bind(e);else{let t=e.getExtension("ANGLE_instanced_arrays");t&&(this.vertexAttribDivisor=t.vertexAttribDivisorANGLE.bind(t))}if(!e.getProgramParameter(this._p,e.LINK_STATUS))return Bi.logErr(`Shader program "${this.name}": initialization failed. ${e.getProgramInfoLog(this._p)}.`),void e.deleteProgram(this._p);this.use();for(let t in this._attributes){this._variables[t]=this._attributes[t],this._attributes[t].func=Ni.bindBuffer;let i=this._attributes[t].itemType,s=i?i.trim().toUpperCase():"FLOAT";if(-1==Fi.indexOf(s)?(Bi.logErr(`Shader program "${this.name}": attribute '${t}', item type '${this._attributes[t].itemType}' not exists.`),this._attributes[t].itemType=e.FLOAT):this._attributes[t].itemType=e[s],this._attributes[t].normalized=this._attributes[t].normalized||!1,this._attributes[t].divisor=this._attributes[t].divisor||0,this._p[t]=e.getAttribLocation(this._p,t),null==this._p[t])return Bi.logErr(`Shader program "${this.name}": attribute '${t}' not exists.`),void e.deleteProgram(this._p);let n=this._attributes[t].type;"string"==typeof n&&(n=zi[n.trim().toLowerCase()]);let r=this._attributes[t].divisor;if(n===Ii.MAT4){let e=this._p[t];this._attribArrays.push(e,e+1,e+2,e+3),this._attribDivisor.push(r,r,r,r)}else this._attribArrays.push(this._p[t]),this._attribDivisor.push(r);e.enableVertexAttribArray(this._p[t]),this._attributes[t]._pName=this._p[t],this.attributes[t]=this._p[t]}for(let t in this._uniforms){if("string"==typeof this._uniforms[t].type){let e=this._uniforms[t].type;this._uniforms[t].func=Di.u[zi[e.trim().toLowerCase()]]}else this._uniforms[t].func=Di.u[this._uniforms[t].type];if(this._variables[t]=this._uniforms[t],this._p[t]=e.getUniformLocation(this._p,t),null==this._p[t])return Bi.logErr(`Shader program "${this.name}": uniform '${t}' not exists.`),void e.deleteProgram(this._p);this._uniforms[t]._pName=this._p[t],this.uniforms[t]=this._p[t]}e.detachShader(this._p,t),e.detachShader(this._p,i),e.deleteShader(t),e.deleteShader(i)}}}const Hi="vec2 project(vec4 p) {\n return (0.5 * p.xyz / p.w + 0.5).xy * viewport;\n }",Oi="mat2 rotate2d(float angle) {\n return mat2(cos(angle), -sin(angle),\n sin(angle), cos(angle));\n }";class Vi{constructor(e){this.__id=Vi.__counter__++,this.pickingEnabled=!0,this._entityCollection=e,this._renderer=null,this._billboards=[],this._positionHighBuffer=null,this._positionLowBuffer=null,this._sizeBuffer=null,this._offsetBuffer=null,this._rgbaBuffer=null,this._rotationBuffer=null,this._texCoordBuffer=null,this._vertexBuffer=null,this._pickingColorBuffer=null,this._texCoordArr=new Float32Array([]),this._vertexArr=new Float32Array([]),this._positionHighArr=new Float32Array([]),this._positionLowArr=new Float32Array([]),this._sizeArr=new Float32Array([]),this._offsetArr=new Float32Array([]),this._rgbaArr=new Float32Array([]),this._rotationArr=new Float32Array([]),this._pickingColorArr=new Float32Array([]),this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[0]=this.createPickingColorBuffer,this._buffersUpdateCallbacks[1]=this.createPositionBuffer,this._buffersUpdateCallbacks[2]=this.createSizeBuffer,this._buffersUpdateCallbacks[3]=this.createOffsetBuffer,this._buffersUpdateCallbacks[4]=this.createRgbaBuffer,this._buffersUpdateCallbacks[5]=this.createRotationBuffer,this._buffersUpdateCallbacks[6]=this.createTexCoordBuffer,this._buffersUpdateCallbacks[7]=this.createVertexBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length)}isEqual(e){return e&&e.__id===this.__id}static concArr(e,t){for(let i=0;i<t.length;i++)e.push(t[i])}initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.billboard||this._renderer.handler.addProgram(new Ni("billboard",{uniforms:{viewport:"vec2",u_texture:"sampler2d",projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",planetRadius:"float",uScaleByDistance:"vec3",opacity:"float",depthOffset:"float"},attributes:{a_vertices:"vec2",a_texCoord:"vec2",a_positionsHigh:"vec3",a_positionsLow:"vec3",a_offset:"vec3",a_size:"vec2",a_rotation:"float",a_rgba:"vec4"},vertexShader:`precision highp float;\n attribute vec2 a_vertices;\n attribute vec2 a_texCoord;\n attribute vec3 a_positionsHigh;\n attribute vec3 a_positionsLow;\n attribute vec3 a_offset;\n attribute vec2 a_size;\n attribute float a_rotation;\n attribute vec4 a_rgba;\n\n varying vec2 v_texCoords;\n varying vec4 v_rgba;\n\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform vec3 uScaleByDistance;\n uniform float opacity;\n uniform float planetRadius;\n uniform vec2 viewport;\n uniform float depthOffset;\n\n const vec3 ZERO3 = vec3(0.0);\n\n ${Hi}\n\n ${Oi}\n\n void main() {\n \n vec3 a_positions = a_positionsHigh + a_positionsLow;\n vec3 cameraPos = eyePositionHigh + eyePositionLow;\n\n v_texCoords = a_texCoord;\n vec3 look = a_positions - cameraPos;\n float lookDist = length(look);\n v_rgba = a_rgba;\n\n if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){\n return;\n }\n\n //vec3 up = vec3( viewMatrix[0][1], viewMatrix[1][1], viewMatrix[2][1] );\n //vec3 right = vec3( viewMatrix[0][0], viewMatrix[1][0], viewMatrix[2][0] );\n\n float scd = (1.0 - smoothstep(uScaleByDistance[0], uScaleByDistance[1], lookDist)) * (1.0 - step(uScaleByDistance[2], lookDist));\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = a_positionsHigh - eyePositionHigh;\n vec3 lowDiff = a_positionsLow - eyePositionLow;\n vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n vec4 projPos = projectionMatrix * posRTE;\n \n float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos)); \n if(camSlope > 0.5) {\n float dist = dot(look, normalize(cameraPos));\n projPos.z += dist * 0.02;\n }else{\n projPos.z += -(abs(projPos.z)) * 0.002; \n }\n \n projPos.z += depthOffset + a_offset.z;\n \n vec2 screenPos = project(projPos);\n\n vec2 v = screenPos + rotate2d(a_rotation) * (a_vertices * a_size * scd + a_offset.xy);\n\n gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);\n }`,fragmentShader:"precision highp float;\n uniform sampler2D u_texture;\n varying vec2 v_texCoords;\n varying vec4 v_rgba;\n void main () {\n vec4 color = texture2D(u_texture, v_texCoords);\n if(color.a < 0.1)\n discard;\n gl_FragColor = color * v_rgba;\n }"})),this._renderer.handler.programs.billboardPicking||this._renderer.handler.addProgram(new Ni("billboardPicking",{uniforms:{viewport:"vec2",projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",planetRadius:"float",uScaleByDistance:"vec3",opacity:"float",depthOffset:"float"},attributes:{a_vertices:"vec2",a_positionsHigh:"vec3",a_positionsLow:"vec3",a_offset:"vec3",a_size:"vec2",a_rotation:"float",a_rgba:"vec4"},vertexShader:`precision highp float;\n attribute vec2 a_vertices;\n attribute vec3 a_positionsHigh;\n attribute vec3 a_positionsLow;\n attribute vec3 a_offset;\n attribute vec2 a_size;\n attribute float a_rotation;\n attribute vec4 a_rgba;\n\n varying vec3 v_rgb;\n\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform vec3 uScaleByDistance;\n uniform float opacity;\n uniform float planetRadius;\n uniform vec2 viewport;\n uniform float depthOffset;\n\n const vec3 ZERO3 = vec3(0.0);\n\n ${Hi}\n\n ${Oi}\n\n void main() {\n\n vec3 a_positions = a_positionsHigh + a_positionsLow;\n vec3 cameraPos = eyePositionHigh + eyePositionLow;\n\n vec3 look = a_positions - cameraPos;\n float lookDist = length(look);\n v_rgb = a_rgba.rgb;\n\n if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){\n return;\n }\n\n //vec3 up = vec3( viewMatrix[0][1], viewMatrix[1][1], viewMatrix[2][1] );\n //vec3 right = vec3( viewMatrix[0][0], viewMatrix[1][0], viewMatrix[2][0] );\n\n float scd = (1.0 - smoothstep(uScaleByDistance[0], uScaleByDistance[1], lookDist)) * (1.0 - step(uScaleByDistance[2], lookDist));\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = a_positionsHigh - eyePositionHigh;\n vec3 lowDiff = a_positionsLow - eyePositionLow;\n vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n vec4 projPos = projectionMatrix * posRTE;\n \n float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos)); \n if(camSlope > 0.5) {\n float dist = dot(look, normalize(cameraPos));\n projPos.z += dist * 0.02;\n }else{\n projPos.z += -(abs(projPos.z)) * 0.002; \n }\n \n projPos.z += depthOffset + a_offset.z;\n \n vec2 screenPos = project(projPos);\n\n vec2 v = screenPos + rotate2d(a_rotation) * (a_vertices * a_size * scd + a_offset.xy);\n\n gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);\n }`,fragmentShader:"precision highp float;\n varying vec3 v_rgb;\n void main () {\n gl_FragColor = vec4(v_rgb, 1.0);\n }"})))}setRenderer(e){this._renderer=e,this.initProgram()}refresh(){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]=!0}_removeBillboards(){let e=this._billboards.length;for(;e--;){let t=this._billboards[e];t._handlerIndex=-1,t._handler=null,t._isReady=!1,t._lockId=ii}this._billboards.length=0,this._billboards=[]}clear(){this._texCoordArr=null,this._vertexArr=null,this._positionHighArr=null,this._positionLowArr=null,this._sizeArr=null,this._offsetArr=null,this._rgbaArr=null,this._rotationArr=null,this._pickingColorArr=null,this._texCoordArr=new Float32Array([]),this._vertexArr=new Float32Array([]),this._positionHighArr=new Float32Array([]),this._positionLowArr=new Float32Array([]),this._sizeArr=new Float32Array([]),this._offsetArr=new Float32Array([]),this._rgbaArr=new Float32Array([]),this._rotationArr=new Float32Array([]),this._pickingColorArr=new Float32Array([]),this._removeBillboards(),this._deleteBuffers(),this.refresh()}_deleteBuffers(){if(this._renderer){let e=this._renderer.handler.gl;e.deleteBuffer(this._positionHighBuffer),e.deleteBuffer(this._positionLowBuffer),e.deleteBuffer(this._sizeBuffer),e.deleteBuffer(this._offsetBuffer),e.deleteBuffer(this._rgbaBuffer),e.deleteBuffer(this._rotationBuffer),e.deleteBuffer(this._vertexBuffer),e.deleteBuffer(this._texCoordBuffer),e.deleteBuffer(this._pickingColorBuffer)}this._positionHighBuffer=null,this._positionLowBuffer=null,this._sizeBuffer=null,this._offsetBuffer=null,this._rgbaBuffer=null,this._rotationBuffer=null,this._vertexBuffer=null,this._texCoordBuffer=null,this._pickingColorBuffer=null}update(){if(this._renderer){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1)}}add(e){-1==e._handlerIndex&&(e._isReady=!0,e._handler=this,e._handlerIndex=this._billboards.length,this._billboards.push(e))}_displayPASS(){let e=this._renderer,t=e.handler;t.programs.billboard.activate();let i=t.programs.billboard._program,s=i.attributes,n=i.uniforms,r=t.gl,o=this._entityCollection;r.disable(r.CULL_FACE),r.uniform1f(n.depthOffset,o.polygonOffsetUnits),r.uniform1i(n.u_texture,0),r.uniformMatrix4fv(n.viewMatrix,!1,e.activeCamera.getViewMatrix()),r.uniformMatrix4fv(n.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),r.uniform3fv(n.eyePositionHigh,e.activeCamera.eyeHigh),r.uniform3fv(n.eyePositionLow,e.activeCamera.eyeLow),r.uniform3fv(n.uScaleByDistance,o.scaleByDistance),r.uniform1f(n.opacity,o._fadingOpacity),r.bindBuffer(r.ARRAY_BUFFER,this._texCoordBuffer),r.vertexAttribPointer(s.a_texCoord,this._texCoordBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._vertexBuffer),r.vertexAttribPointer(s.a_vertices,this._vertexBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._positionHighBuffer),r.vertexAttribPointer(s.a_positionsHigh,this._positionHighBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._positionLowBuffer),r.vertexAttribPointer(s.a_positionsLow,this._positionLowBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._rgbaBuffer),r.vertexAttribPointer(s.a_rgba,this._rgbaBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._sizeBuffer),r.vertexAttribPointer(s.a_size,this._sizeBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._offsetBuffer),r.vertexAttribPointer(s.a_offset,this._offsetBuffer.itemSize,r.FLOAT,!1,0,0),r.uniform1f(n.planetRadius,o.renderNode._planetRadius2||0),r.uniform2fv(n.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),r.bindBuffer(r.ARRAY_BUFFER,this._rotationBuffer),r.vertexAttribPointer(s.a_rotation,this._rotationBuffer.itemSize,r.FLOAT,!1,0,0),r.drawArrays(r.TRIANGLES,0,this._vertexBuffer.numItems),r.enable(r.CULL_FACE)}_pickingPASS(){let e=this._renderer,t=e.handler;t.programs.billboardPicking.activate();let i=t.programs.billboardPicking._program,s=i.attributes,n=i.uniforms,r=t.gl,o=this._entityCollection;r.disable(r.CULL_FACE),r.uniform1f(n.depthOffset,o.polygonOffsetUnits),r.uniformMatrix4fv(n.viewMatrix,!1,e.activeCamera.getViewMatrix()),r.uniformMatrix4fv(n.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),r.uniform3fv(n.eyePositionHigh,e.activeCamera.eyeHigh),r.uniform3fv(n.eyePositionLow,e.activeCamera.eyeLow),r.uniform3fv(n.uScaleByDistance,o.scaleByDistance),r.uniform1f(n.opacity,o._fadingOpacity),r.bindBuffer(r.ARRAY_BUFFER,this._vertexBuffer),r.vertexAttribPointer(s.a_vertices,this._vertexBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._positionHighBuffer),r.vertexAttribPointer(s.a_positionsHigh,this._positionHighBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._positionLowBuffer),r.vertexAttribPointer(s.a_positionsLow,this._positionLowBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._pickingColorBuffer),r.vertexAttribPointer(s.a_rgba,this._pickingColorBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._sizeBuffer),r.vertexAttribPointer(s.a_size,this._sizeBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._offsetBuffer),r.vertexAttribPointer(s.a_offset,this._offsetBuffer.itemSize,r.FLOAT,!1,0,0),r.uniform1f(n.planetRadius,o.renderNode._planetRadius2||0),r.uniform2fv(n.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),r.bindBuffer(r.ARRAY_BUFFER,this._rotationBuffer),r.vertexAttribPointer(s.a_rotation,this._rotationBuffer.itemSize,r.FLOAT,!1,0,0),r.drawArrays(r.TRIANGLES,0,this._vertexBuffer.numItems),r.enable(r.CULL_FACE)}draw(){this._billboards.length&&(this.update(),this._displayPASS())}drawPicking(){this._billboards.length&&this.pickingEnabled&&this._pickingPASS()}reindexBillboardsArray(e){let t=this._billboards;for(let i=e;i<t.length;i++)t[i]._handlerIndex=i}_removeBillboard(e){let t=e._handlerIndex;this._billboards.splice(t,1);let i=24*t;this._rgbaArr=Ye(this._rgbaArr,i,24),i=18*t,this._positionHighArr=Ye(this._positionHighArr,i,18),this._positionLowArr=Ye(this._positionLowArr,i,18),this._offsetArr=Ye(this._offsetArr,i,18),this._pickingColorArr=Ye(this._pickingColorArr,i,18),i=12*t,this._vertexArr=Ye(this._vertexArr,i,12),this._sizeArr=Ye(this._sizeArr,i,12),this._texCoordArr=Ye(this._texCoordArr,i,12),i=6*t,this._rotationArr=Ye(this._rotationArr,i,6),this.reindexBillboardsArray(t),this.refresh(),e._handlerIndex=-1,e._handler=null,e._isReady=!1,e._lockId=ii}setAlignedAxisArr(e,t){}remove(e){e._handler&&(e._isReady&&this.__id===e._handler.__id?this._removeBillboard(e):e._handler=null)}setPositionArr(e,t,i){let s=18*e,n=this._positionHighArr,r=t.x,o=t.y,a=t.z;n[s]=r,n[s+1]=o,n[s+2]=a,n[s+3]=r,n[s+4]=o,n[s+5]=a,n[s+6]=r,n[s+7]=o,n[s+8]=a,n[s+9]=r,n[s+10]=o,n[s+11]=a,n[s+12]=r,n[s+13]=o,n[s+14]=a,n[s+15]=r,n[s+16]=o,n[s+17]=a,n=this._positionLowArr,r=i.x,o=i.y,a=i.z,n[s]=r,n[s+1]=o,n[s+2]=a,n[s+3]=r,n[s+4]=o,n[s+5]=a,n[s+6]=r,n[s+7]=o,n[s+8]=a,n[s+9]=r,n[s+10]=o,n[s+11]=a,n[s+12]=r,n[s+13]=o,n[s+14]=a,n[s+15]=r,n[s+16]=o,n[s+17]=a,this._changedBuffers[1]=!0}setPickingColorArr(e,t){let i=18*e,s=this._pickingColorArr,n=t.x/255,r=t.y/255,o=t.z/255;s[i]=n,s[i+1]=r,s[i+2]=o,s[i+3]=n,s[i+4]=r,s[i+5]=o,s[i+6]=n,s[i+7]=r,s[i+8]=o,s[i+9]=n,s[i+10]=r,s[i+11]=o,s[i+12]=n,s[i+13]=r,s[i+14]=o,s[i+15]=n,s[i+16]=r,s[i+17]=o,this._changedBuffers[0]=!0}setSizeArr(e,t,i){let s=12*e,n=this._sizeArr,r=t,o=i;n[s]=r,n[s+1]=o,n[s+2]=r,n[s+3]=o,n[s+4]=r,n[s+5]=o,n[s+6]=r,n[s+7]=o,n[s+8]=r,n[s+9]=o,n[s+10]=r,n[s+11]=o,this._changedBuffers[2]=!0}setOffsetArr(e,t){let i=18*e,s=this._offsetArr,n=t.x,r=t.y,o=t.z;s[i]=n,s[i+1]=r,s[i+2]=o,s[i+3]=n,s[i+4]=r,s[i+5]=o,s[i+6]=n,s[i+7]=r,s[i+8]=o,s[i+9]=n,s[i+10]=r,s[i+11]=o,s[i+12]=n,s[i+13]=r,s[i+14]=o,s[i+15]=n,s[i+16]=r,s[i+17]=o,this._changedBuffers[3]=!0}setRgbaArr(e,t){let i=24*e,s=this._rgbaArr,n=t.x,r=t.y,o=t.z,a=t.w;s[i]=n,s[i+1]=r,s[i+2]=o,s[i+3]=a,s[i+4]=n,s[i+5]=r,s[i+6]=o,s[i+7]=a,s[i+8]=n,s[i+9]=r,s[i+10]=o,s[i+11]=a,s[i+12]=n,s[i+13]=r,s[i+14]=o,s[i+15]=a,s[i+16]=n,s[i+17]=r,s[i+18]=o,s[i+19]=a,s[i+20]=n,s[i+21]=r,s[i+22]=o,s[i+23]=a,this._changedBuffers[4]=!0}setRotationArr(e,t){let i=6*e,s=this._rotationArr;s[i]=t,s[i+1]=t,s[i+2]=t,s[i+3]=t,s[i+4]=t,s[i+5]=t,this._changedBuffers[5]=!0}setTexCoordArr(e,t){let i=12*e,s=this._texCoordArr;s[i]=t[0],s[i+1]=t[1],s[i+2]=t[2],s[i+3]=t[3],s[i+4]=t[4],s[i+5]=t[5],s[i+6]=t[6],s[i+7]=t[7],s[i+8]=t[8],s[i+9]=t[9],s[i+10]=t[10],s[i+11]=t[11],this._changedBuffers[6]=!0}setVisibility(e,t){let i;i=t?[-.5,.5,-.5,-.5,.5,-.5,.5,-.5,.5,.5,-.5,.5]:[0,0,0,0,0,0,0,0,0,0,0,0],this.setVertexArr(e,i)}setVertexArr(e,t){let i=12*e,s=this._vertexArr;s[i]=t[0],s[i+1]=t[1],s[i+2]=t[2],s[i+3]=t[3],s[i+4]=t[4],s[i+5]=t[5],s[i+6]=t[6],s[i+7]=t[7],s[i+8]=t[8],s[i+9]=t[9],s[i+10]=t[10],s[i+11]=t[11],this._changedBuffers[7]=!0}createPositionBuffer(){let e=this._renderer.handler,t=this._positionHighArr.length/3;this._positionHighBuffer&&this._positionHighBuffer.numItems===t||(e.gl.deleteBuffer(this._positionHighBuffer),e.gl.deleteBuffer(this._positionLowBuffer),this._positionHighBuffer=e.createStreamArrayBuffer(3,t),this._positionLowBuffer=e.createStreamArrayBuffer(3,t)),e.setStreamArrayBuffer(this._positionHighBuffer,this._positionHighArr),e.setStreamArrayBuffer(this._positionLowBuffer,this._positionLowArr)}createSizeBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._sizeBuffer),this._sizeBuffer=e.createArrayBuffer(this._sizeArr,2,this._sizeArr.length/2)}createOffsetBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._offsetBuffer),this._offsetBuffer=e.createArrayBuffer(this._offsetArr,3,this._offsetArr.length/3)}createRgbaBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._rgbaBuffer),this._rgbaBuffer=e.createArrayBuffer(this._rgbaArr,4,this._rgbaArr.length/4)}createRotationBuffer(){let e=this._renderer.handler;this._rotationBuffer&&this._rotationBuffer.numItems===this._rotationArr.length||(e.gl.deleteBuffer(this._rotationBuffer),this._rotationBuffer=e.createStreamArrayBuffer(1,this._rotationArr.length)),e.setStreamArrayBuffer(this._rotationBuffer,this._rotationArr)}createVertexBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._vertexBuffer),this._vertexBuffer=e.createArrayBuffer(this._vertexArr,2,this._vertexArr.length/2)}createTexCoordBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._texCoordBuffer),this._texCoordBuffer=e.createArrayBuffer(this._texCoordArr,2,this._texCoordArr.length/2)}createPickingColorBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._pickingColorBuffer),this._pickingColorBuffer=e.createArrayBuffer(this._pickingColorArr,3,this._pickingColorArr.length/3)}refreshTexCoordsArr(){}}Vi.__counter__=0;class Ui extends Vi{constructor(e){super(e),this._billboards=[]}add(e){if(-1==e._handlerIndex){super.add(e),this._addBillboardToArrays(e),this.refresh();let t=e.getSrc()||e.getImage()&&e.getImage().src;t&&e.setSrc(t)}}_addBillboardToArrays(e){e.getVisibility()?this._vertexArr=He(this._vertexArr,[-.5,.5,-.5,-.5,.5,-.5,.5,-.5,.5,.5,-.5,.5]):this._vertexArr=He(this._vertexArr,[0,0,0,0,0,0,0,0,0,0,0,0]),this._texCoordArr=He(this._texCoordArr,[0,0,0,0,0,0,0,0,0,0,0,0]);let t,i=e._positionHigh.x,s=e._positionHigh.y,n=e._positionHigh.z;this._positionHighArr=He(this._positionHighArr,[i,s,n,i,s,n,i,s,n,i,s,n,i,s,n,i,s,n]),i=e._positionLow.x,s=e._positionLow.y,n=e._positionLow.z,this._positionLowArr=He(this._positionLowArr,[i,s,n,i,s,n,i,s,n,i,s,n,i,s,n,i,s,n]),i=e._width,s=e._height,this._sizeArr=He(this._sizeArr,[i,s,i,s,i,s,i,s,i,s,i,s]),i=e._offset.x,s=e._offset.y,n=e._offset.z,this._offsetArr=He(this._offsetArr,[i,s,n,i,s,n,i,s,n,i,s,n,i,s,n,i,s,n]),i=e._color.x,s=e._color.y,n=e._color.z,t=e._color.w,this._rgbaArr=He(this._rgbaArr,[i,s,n,t,i,s,n,t,i,s,n,t,i,s,n,t,i,s,n,t,i,s,n,t]),i=e._rotation,this._rotationArr=He(this._rotationArr,[i,i,i,i,i,i]),i=e._entity._pickingColor.x/255,s=e._entity._pickingColor.y/255,n=e._entity._pickingColor.z/255,this._pickingColorArr=He(this._pickingColorArr,[i,s,n,i,s,n,i,s,n,i,s,n,i,s,n,i,s,n])}get billboards(){return this._billboards}refreshTexCoordsArr(){if(this._entityCollection&&this._renderer){let e=this._renderer.billboardsTextureAtlas;for(let t=0;t<this._billboards.length;t++){let i=this._billboards[t],s=i.getImage();if(s){let t=e.get(s.__nodeIndex);t&&this.setTexCoordArr(i._handlerIndex,t.texCoords)}}}}}const Gi="vec3 qRotate(vec4 q, vec3 v){\n return v + 2.0 * cross(q.xyz, cross(q.xyz, v) + q.w * v);\n}";class Yi{constructor(e){this.isFree=!0,this._geoObjectHandler=e,this.geoObjects=[],this.numInstances=0,this._colorTexture=null,this._colorTextureSrc=null,this._normalTexture=null,this._normalTextureSrc=null,this._metallicRoughnessTexture=null,this._metallicRoughnessTextureSrc=null,this._sizeArr=[],this._translateArr=[],this._vertexArr=[],this._rtcPositionHighArr=[],this._rtcPositionLowArr=[],this._qRotArr=[],this._rgbaArr=[],this._normalsArr=[],this._indicesArr=[],this._pickingColorArr=[],this._visibleArr=[],this._texCoordArr=[],this._localPositionArr=[],this._sizeBuffer=null,this._translateBuffer=null,this._vertexBuffer=null,this._rtcPositionHighBuffer=null,this._rtcPositionLowBuffer=null,this._qRotBuffer=null,this._rgbaBuffer=null,this._normalsBuffer=null,this._indicesBuffer=null,this._pickingColorBuffer=null,this._visibleBuffer=null,this._texCoordBuffer=null,this._localPositionBuffer=null,this._materialParams=new Float32Array(9),this._materialShininess=0,this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[Qi]=this.createPickingColorBuffer,this._buffersUpdateCallbacks[$i]=this.createNormalsBuffer,this._buffersUpdateCallbacks[qi]=this.createRgbaBuffer,this._buffersUpdateCallbacks[Xi]=this.createIndicesBuffer,this._buffersUpdateCallbacks[ji]=this.createVertexBuffer,this._buffersUpdateCallbacks[Ki]=this.createSizeBuffer,this._buffersUpdateCallbacks[Ji]=this.createVisibleBuffer,this._buffersUpdateCallbacks[es]=this.createTexCoordBuffer,this._buffersUpdateCallbacks[Zi]=this.createQRotBuffer,this._buffersUpdateCallbacks[ts]=this.createTranslateBuffer,this._buffersUpdateCallbacks[Wi]=this.createRTCPositionBuffer,this._buffersUpdateCallbacks[is]=this.createLocalPositionBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length)}setMaterialAmbient(e,t,i){this._materialParams[0]=e,this._materialParams[1]=t,this._materialParams[2]=i}setMaterialDiffuse(e,t,i){this._materialParams[3]=e,this._materialParams[4]=t,this._materialParams[5]=i}setMaterialSpecular(e,t,i){this._materialParams[6]=e,this._materialParams[7]=t,this._materialParams[8]=i}setMaterialShininess(e){this._materialShininess=e}setMaterialParams(e,t,i,s){this.setMaterialAmbient(e[0],e[1],e[2]),this.setMaterialDiffuse(t[0],t[1],t[2]),this.setMaterialSpecular(i[0],i[1],i[2]),this.setMaterialShininess(s)}drawOpaque(e){let t=e.gl,i=e.uniforms,s=e.attributes;t.bindBuffer(t.ARRAY_BUFFER,this._qRotBuffer),t.vertexAttribPointer(s.qRot,this._qRotBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._sizeBuffer),t.vertexAttribPointer(s.aScale,this._sizeBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._translateBuffer),t.vertexAttribPointer(s.aTranslate,this._translateBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._localPositionBuffer),t.vertexAttribPointer(s.aLocalPosition,this._localPositionBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._visibleBuffer),t.vertexAttribPointer(s.aDispose,this._visibleBuffer.itemSize,t.FLOAT,!1,0,0),t.uniform1f(i.uUseTexture,this._colorTexture?1:0),t.bindBuffer(t.ARRAY_BUFFER,this._rgbaBuffer),t.vertexAttribPointer(s.aColor,this._rgbaBuffer.itemSize,t.FLOAT,!1,0,0),t.uniform3fv(i.materialParams,this._materialParams),t.uniform1f(i.materialShininess,this._materialShininess),this._drawElementsInstanced(e)}drawTransparent(e){let t=e.gl,i=e.uniforms,s=e.attributes;t.bindBuffer(t.ARRAY_BUFFER,this._qRotBuffer),t.vertexAttribPointer(s.qRot,this._qRotBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._sizeBuffer),t.vertexAttribPointer(s.aScale,this._sizeBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._translateBuffer),t.vertexAttribPointer(s.aTranslate,this._translateBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._localPositionBuffer),t.vertexAttribPointer(s.aLocalPosition,this._localPositionBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._visibleBuffer),t.vertexAttribPointer(s.aDispose,this._visibleBuffer.itemSize,t.FLOAT,!1,0,0),t.uniform1f(i.uUseTexture,this._colorTexture?1:0),t.uniform3fv(i.materialParams,this._materialParams),t.uniform1f(i.materialShininess,this._materialShininess),t.bindBuffer(t.ARRAY_BUFFER,this._rgbaBuffer),t.vertexAttribPointer(s.aColor,this._rgbaBuffer.itemSize,t.FLOAT,!1,0,0),this._drawElementsInstanced(e)}_drawElementsInstanced(e){let t=e.gl,i=e.uniforms,s=e.attributes,n=this._geoObjectHandler._renderer;t.bindBuffer(t.ARRAY_BUFFER,this._rtcPositionHighBuffer),t.vertexAttribPointer(s.aRTCPositionHigh,this._rtcPositionHighBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._rtcPositionLowBuffer),t.vertexAttribPointer(s.aRTCPositionLow,this._rtcPositionLowBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._normalsBuffer),t.vertexAttribPointer(s.aVertexNormal,this._normalsBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,this._vertexBuffer),t.vertexAttribPointer(s.aVertexPosition,this._vertexBuffer.itemSize,t.FLOAT,!1,0,0),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this._colorTexture||n.handler.defaultTexture),t.uniform1i(i.uTexture,0),t.bindBuffer(t.ARRAY_BUFFER,this._texCoordBuffer),t.vertexAttribPointer(s.aTexCoord,this._texCoordBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,this._indicesBuffer),e.drawElementsInstanced(t.TRIANGLES,this._indicesBuffer.numItems,t.UNSIGNED_INT,0,this.numInstances)}createColorTexture(e){if(this._geoObjectHandler&&this._geoObjectHandler._renderer){let t=this._geoObjectHandler._renderer.handler;this._colorTexture=t.createTextureDefault(e,null,t.gl.REPEAT)}}createNormalTexture(e){if(this._geoObjectHandler&&this._geoObjectHandler._renderer){let t=this._geoObjectHandler._renderer.handler;this._normalTexture=t.createTextureDefault(e,null,t.gl.REPEAT)}}createMetallicRoughnessTexture(e){if(this._geoObjectHandler&&this._geoObjectHandler._renderer){let t=this._geoObjectHandler._renderer.handler;this._metallicRoughnessTexture=t.createTextureDefault(e,null,t.gl.REPEAT)}}clear(){this.numInstances=0,this.geoObjects=[],this._sizeArr=[],this._translateArr=[],this._vertexArr=[],this._rtcPositionHighArr=[],this._rtcPositionLowArr=[],this._qRotArr=[],this._rgbaArr=[],this._normalsArr=[],this._indicesArr=[],this._pickingColorArr=[],this._visibleArr=[],this._texCoordArr=[],this._localPositionArr=[],this._deleteBuffers(),this.isFree=!1}_deleteBuffers(){if(this._geoObjectHandler&&this._geoObjectHandler._renderer){let e=this._geoObjectHandler._renderer.handler,t=e.gl;e.deleteTexture(this._colorTexture),e.deleteTexture(this._normalTexture),e.deleteTexture(this._metallicRoughnessTexture),this._colorTexture=null,this._normalTexture=null,this._metallicRoughnessTexture=null,t.deleteBuffer(this._sizeBuffer),t.deleteBuffer(this._translateBuffer),t.deleteBuffer(this._vertexBuffer),t.deleteBuffer(this._rtcPositionHighBuffer),t.deleteBuffer(this._rtcPositionLowBuffer),t.deleteBuffer(this._qRotBuffer),t.deleteBuffer(this._rgbaBuffer),t.deleteBuffer(this._normalsBuffer),t.deleteBuffer(this._indicesBuffer),t.deleteBuffer(this._pickingColorBuffer),t.deleteBuffer(this._visibleBuffer),t.deleteBuffer(this._texCoordBuffer),t.deleteBuffer(this._localPositionBuffer)}this._sizeBuffer=null,this._translateBuffer=null,this._vertexBuffer=null,this._rtcPositionHighBuffer=null,this._rtcPositionLowBuffer=null,this._qRotBuffer=null,this._rgbaBuffer=null,this._normalsBuffer=null,this._indicesBuffer=null,this._pickingColorBuffer=null,this._visibleBuffer=null,this._texCoordBuffer=null,this._localPositionBuffer=null}createVertexBuffer(){const e=this._geoObjectHandler._renderer.handler;e.gl.deleteBuffer(this._vertexBuffer),this._vertexArr=Ve(this._vertexArr),this._vertexBuffer=e.createArrayBuffer(this._vertexArr,3,this._vertexArr.length/3)}createVisibleBuffer(){const e=this._geoObjectHandler._renderer.handler,t=this._visibleArr.length;this._visibleBuffer&&this._visibleBuffer.numItems===t||(e.gl.deleteBuffer(this._visibleBuffer),this._visibleBuffer=e.createStreamArrayBuffer(1,t)),this._visibleArr=Ve(this._visibleArr),e.setStreamArrayBuffer(this._visibleBuffer,this._visibleArr)}createSizeBuffer(){let e=this._geoObjectHandler._renderer.handler,t=this._sizeArr.length/3;this._sizeBuffer&&this._sizeBuffer.numItems===t||(e.gl.deleteBuffer(this._sizeBuffer),this._sizeBuffer=e.createStreamArrayBuffer(3,t)),this._sizeArr=Ve(this._sizeArr),e.setStreamArrayBuffer(this._sizeBuffer,this._sizeArr)}createTranslateBuffer(){let e=this._geoObjectHandler._renderer.handler,t=this._translateArr.length/3;this._translateBuffer&&this._translateBuffer.numItems===t||(e.gl.deleteBuffer(this._translateBuffer),this._translateBuffer=e.createStreamArrayBuffer(3,t)),this._translateArr=Ve(this._translateArr),e.setStreamArrayBuffer(this._translateBuffer,this._translateArr)}createLocalPositionBuffer(){let e=this._geoObjectHandler._renderer.handler,t=this._localPositionArr.length/3;this._localPositionBuffer&&this._localPositionBuffer.numItems===t||(e.gl.deleteBuffer(this._localPositionBuffer),this._localPositionBuffer=e.createStreamArrayBuffer(3,t)),this._localPositionArr=Ve(this._localPositionArr),e.setStreamArrayBuffer(this._localPositionBuffer,this._localPositionArr)}createTexCoordBuffer(){const e=this._geoObjectHandler._renderer.handler;e.gl.deleteBuffer(this._texCoordBuffer),this._texCoordArr=Ve(this._texCoordArr),this._texCoordBuffer=e.createArrayBuffer(this._texCoordArr,2,this._texCoordArr.length/2)}createRTCPositionBuffer(){let e=this._geoObjectHandler._renderer.handler,t=this._rtcPositionHighArr.length/3;this._rtcPositionHighBuffer&&this._rtcPositionHighBuffer.numItems===t||(e.gl.deleteBuffer(this._rtcPositionHighBuffer),e.gl.deleteBuffer(this._rtcPositionLowBuffer),this._rtcPositionHighBuffer=e.createStreamArrayBuffer(3,t),this._rtcPositionLowBuffer=e.createStreamArrayBuffer(3,t)),this._rtcPositionHighArr=Ve(this._rtcPositionHighArr),this._rtcPositionLowArr=Ve(this._rtcPositionLowArr),e.setStreamArrayBuffer(this._rtcPositionHighBuffer,this._rtcPositionHighArr),e.setStreamArrayBuffer(this._rtcPositionLowBuffer,this._rtcPositionLowArr)}createRgbaBuffer(){let e=this._geoObjectHandler._renderer.handler,t=this._rgbaArr.length/4;this._rgbaBuffer&&this._rgbaBuffer.numItems===t||(e.gl.deleteBuffer(this._rgbaBuffer),this._rgbaBuffer=e.createStreamArrayBuffer(4,t)),this._rgbaArr=Ve(this._rgbaArr),e.setStreamArrayBuffer(this._rgbaBuffer,this._rgbaArr)}createQRotBuffer(){let e=this._geoObjectHandler._renderer.handler,t=this._qRotArr.length/4;this._qRotBuffer&&this._qRotBuffer.numItems===t||(e.gl.deleteBuffer(this._qRotBuffer),this._qRotBuffer=e.createStreamArrayBuffer(4,t)),this._qRotArr=Ve(this._qRotArr),e.setStreamArrayBuffer(this._qRotBuffer,this._qRotArr)}createNormalsBuffer(){const e=this._geoObjectHandler._renderer.handler;e.gl.deleteBuffer(this._normalsBuffer),this._normalsArr=Ve(this._normalsArr),this._normalsBuffer=e.createArrayBuffer(this._normalsArr,3,this._normalsArr.length/3)}createIndicesBuffer(){const e=this._geoObjectHandler._renderer.handler;e.gl.deleteBuffer(this._indicesBuffer),this._indicesArr=Ve(this._indicesArr,Uint32Array),this._indicesBuffer=e.createElementArrayBuffer(this._indicesArr,1,this._indicesArr.length)}createPickingColorBuffer(){const e=this._geoObjectHandler._renderer.handler;e.gl.deleteBuffer(this._pickingColorBuffer),this._pickingColorArr=Ve(this._pickingColorArr),this._pickingColorBuffer=e.createArrayBuffer(this._pickingColorArr,3,this._pickingColorArr.length/3)}refresh(){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]=!0}update(){if(this._geoObjectHandler._renderer){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1);this.isFree=!0}}}const ji=0,Wi=1,qi=2,$i=3,Xi=4,Zi=5,Ki=6,Qi=7,Ji=8,es=9,ts=10,is=11;function ss(e,t=0,i=0,s=1,...n){const r=t*i;for(let t=r,o=r+i;t<o;t++)e[t]=n[t%s];return e}class ns{constructor(e){this.__id=ns.__counter__++,this.pickingEnabled=!0,this._entityCollection=e,this._renderNode=null,this._renderer=null,this._geoObjects=[],this._instanceDataMap=new Map,this._instanceDataMapValues=[],this._dataTagUpdateQueue=[],this._relativeCenter=new oe,this._rtcEyePositionHigh=new Float32Array([0,0,0]),this._rtcEyePositionLow=new Float32Array([0,0,0])}initProgram(){this._renderer&&(this._renderer.handler.programs.geo_object||this._renderer.handler.addProgram(new Ni("geo_object",{uniforms:{viewMatrix:"mat4",projectionMatrix:"mat4",uScaleByDistance:"vec3",eyePositionHigh:"vec3",eyePositionLow:"vec3",rtcEyePositionHigh:"vec3",rtcEyePositionLow:"vec3",sunPosition:"vec3",materialParams:"vec3",materialShininess:"float",uTexture:"sampler2d",uUseTexture:"float",useLighting:"float"},attributes:{aVertexPosition:"vec3",aVertexNormal:"vec3",aTexCoord:"vec2",aLocalPosition:{type:"vec3",divisor:1},aRTCPositionHigh:{type:"vec3",divisor:1},aRTCPositionLow:{type:"vec3",divisor:1},aColor:{type:"vec4",divisor:1},aScale:{type:"vec3",divisor:1},aTranslate:{type:"vec3",divisor:1},aDispose:{type:"float",divisor:1},qRot:{type:"vec4",divisor:1}},vertexShader:`precision highp float;\n \n attribute vec3 aVertexPosition;\n attribute vec3 aVertexNormal; \n \n attribute vec3 aRTCPositionHigh;\n attribute vec3 aRTCPositionLow; \n \n attribute vec4 aColor;\n attribute vec3 aScale;\n attribute vec3 aTranslate;\n attribute float aDispose;\n attribute float aUseTexture;\n attribute vec2 aTexCoord;\n attribute vec4 qRot;\n attribute vec3 aLocalPosition;\n \n uniform vec3 uScaleByDistance;\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n \n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n \n uniform vec3 rtcEyePositionHigh;\n uniform vec3 rtcEyePositionLow;\n\n varying vec3 cameraPosition;\n varying vec3 vNormal;\n varying vec3 v_vertex; \n varying vec4 vColor;\n varying float vDispose;\n varying vec2 vTexCoords;\n \n ${Gi}\n \n void main(void) {\n \n if (aDispose == 0.0) {\n return;\n }\n \n vColor = aColor;\n vTexCoords = aTexCoord; \n \n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n \n vec3 highDiff = aRTCPositionHigh - rtcEyePositionHigh;\n vec3 lowDiff = aRTCPositionLow - rtcEyePositionLow;\n \n cameraPosition = eyePositionHigh + eyePositionLow;\n \n highDiff = highDiff * step(1.0, length(highDiff));\n \n vec4 positionInViewSpace = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n float lookLength = length(positionInViewSpace.xyz);\n \n vNormal = normalize(qRotate(qRot, aVertexNormal));\n \n float scd = uScaleByDistance[2] * clamp(lookLength, uScaleByDistance[0], uScaleByDistance[1]) / uScaleByDistance[0];\n vec3 vert = qRotate(qRot, scd * (aVertexPosition * aScale + aTranslate)) + scd * aLocalPosition;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff + lowDiff + vert, 1.0);\n \n v_vertex = positionInViewSpace.xyz + vert;\n }`,fragmentShader:"precision highp float;\n \n uniform vec3 sunPosition;\n uniform vec3 materialParams[3];\n uniform float materialShininess;\n uniform sampler2D uTexture;\n uniform float uUseTexture;\n uniform float useLighting; \n \n varying vec3 cameraPosition;\n varying vec3 v_vertex; \n varying vec4 vColor;\n varying vec3 vNormal;\n varying vec2 vTexCoords;\n \n void main(void) { \n \n vec3 lightWeighting = vec3(1.0);\n \n if(useLighting != 0.0){\n vec3 normal = vNormal;\n vec3 lightDir = normalize(sunPosition);\n vec3 viewDir = normalize(cameraPosition - v_vertex); \n vec3 reflectionDirection = reflect(-lightDir, normal);\n float reflection = max( dot(reflectionDirection, viewDir), 0.0);\n float specularLightWeighting = pow( reflection, materialShininess); \n float diffuseLightWeighting = max(dot(normal, lightDir), 0.0);\n lightWeighting = vColor.rgb * materialParams[0] + materialParams[1] * diffuseLightWeighting + materialParams[2] * specularLightWeighting;\n } else {\n lightWeighting = vColor.rgb;\n }\n \n if(uUseTexture > 0.0) {\n vec4 texColor = texture2D(uTexture, vTexCoords);\n gl_FragColor = vec4(texColor.rgb * lightWeighting, texColor.a);\n } else {\n gl_FragColor = vec4(lightWeighting, vColor.a);\n }\n }"})),this._renderer.handler.programs.geo_object_picking||this._renderer.handler.addProgram(new Ni("geo_object_picking",{uniforms:{viewMatrix:"mat4",projectionMatrix:"mat4",uScaleByDistance:"vec3",pickingScale:"vec3",rtcEyePositionHigh:"vec3",rtcEyePositionLow:"vec3"},attributes:{aVertexPosition:"vec3",aRTCPositionHigh:{type:"vec3",divisor:1},aRTCPositionLow:{type:"vec3",divisor:1},aPickingColor:{type:"vec3",divisor:1},aScale:{type:"vec3",divisor:1},aTranslate:{type:"vec3",divisor:1},aLocalPosition:{type:"vec3",divisor:1},aDispose:{type:"float",divisor:1},qRot:{type:"vec4",divisor:1}},vertexShader:`precision highp float;\n\n attribute vec3 aVertexPosition;\n attribute vec3 aRTCPositionHigh;\n attribute vec3 aRTCPositionLow;\n attribute vec3 aPickingColor; \n attribute vec3 aScale;\n attribute vec3 aTranslate;\n attribute float aDispose;\n attribute vec4 qRot;\n \n attribute vec3 aLocalPosition;\n \n uniform vec3 rtcEyePositionHigh;\n uniform vec3 rtcEyePositionLow;\n \n uniform vec3 uScaleByDistance;\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 pickingScale;\n\n varying vec3 vColor;\n \n ${Gi}\n\n void main(void) {\n\n if (aDispose == 0.0) {\n return;\n } \n \n vColor = aPickingColor;\n \n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n \n vec3 highDiff = aRTCPositionHigh - rtcEyePositionHigh;\n vec3 lowDiff = aRTCPositionLow - rtcEyePositionLow; \n \n highDiff = highDiff * step(1.0, length(highDiff));\n \n vec4 positionInViewSpace = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n float lookLength = length(positionInViewSpace.xyz);\n \n float scd = uScaleByDistance[2] * clamp(lookLength, uScaleByDistance[0], uScaleByDistance[1]) / uScaleByDistance[0];\n\n vec3 vert = qRotate(qRot, scd * pickingScale * (aVertexPosition * aScale + aTranslate)) + scd * aLocalPosition;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff + lowDiff + vert, 1.0);\n }`,fragmentShader:"precision highp float;\n varying vec3 vColor;\n void main () {\n gl_FragColor = vec4(vColor, 1.0);\n }"})),this._renderer.handler.programs.geo_object_depth||this._renderer.handler.addProgram(new Ni("geo_object_depth",{uniforms:{viewMatrix:"mat4",projectionMatrix:"mat4",uScaleByDistance:"vec3",rtcEyePositionHigh:"vec3",rtcEyePositionLow:"vec3",frustumPickingColor:"float"},attributes:{aVertexPosition:"vec3",aRTCPositionHigh:{type:"vec3",divisor:1},aRTCPositionLow:{type:"vec3",divisor:1},aScale:{type:"vec3",divisor:1},aTranslate:{type:"vec3",divisor:1},aDispose:{type:"float",divisor:1},qRot:{type:"vec4",divisor:1},aLocalPosition:{type:"vec3",divisor:1}},vertexShader:`#version 300 es\n precision highp float;\n\n in vec3 aVertexPosition;\n in vec3 aRTCPositionHigh;\n in vec3 aRTCPositionLow;\n in vec3 aScale;\n in vec3 aTranslate;\n in float aDispose;\n in vec4 qRot;\n in vec3 aLocalPosition;\n \n uniform vec3 rtcEyePositionHigh;\n uniform vec3 rtcEyePositionLow;\n uniform vec3 uScaleByDistance;\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n \n ${Gi}\n\n void main(void) {\n\n if (aDispose == 0.0) {\n return;\n }\n \n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n \n vec3 highDiff = aRTCPositionHigh - rtcEyePositionHigh;\n vec3 lowDiff = aRTCPositionLow - rtcEyePositionLow; \n \n highDiff = highDiff * step(1.0, length(highDiff));\n \n vec4 positionInViewSpace = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n float lookLength = length(positionInViewSpace.xyz);\n \n float scd = uScaleByDistance[2] * clamp(lookLength, uScaleByDistance[0], uScaleByDistance[1]) / uScaleByDistance[0];\n\n vec3 vert = qRotate(qRot, scd * (aVertexPosition * aScale + aTranslate)) + scd * aLocalPosition;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff + lowDiff + vert, 1.0);\n }`,fragmentShader:"#version 300 es\n precision highp float;\n \n uniform float frustumPickingColor;\n \n layout(location = 0) out vec4 frustumColor;\n layout(location = 1) out vec4 depthColor;\n \n void main () {\n frustumColor = vec4(frustumPickingColor, frustumPickingColor, frustumPickingColor, 1.0);\n depthColor = vec4(gl_FragCoord.z, gl_FragCoord.z, gl_FragCoord.z, 1.0);\n }"})))}setRenderNode(e){this._renderNode=e,this._renderer=e.renderer,this.initProgram();for(let e=0;e<this._instanceDataMapValues.length;e++)this._loadColorTexture(this._instanceDataMapValues[e]),this._loadNormalTexture(this._instanceDataMapValues[e]),this._loadMetallicRoughnessTexture(this._instanceDataMapValues[e]);for(let e=0;e<this._geoObjects.length;e++)this._geoObjects[e].updateRotation();this.update()}setColorTextureTag(e,t){const i=this._instanceDataMap.get(t);i&&(i._colorTextureSrc=e,this._instanceDataMap.set(t,i),this._loadColorTexture(i))}setNormalTextureTag(e,t){const i=this._instanceDataMap.get(t);i&&(i._normalTextureSrc=e,this._instanceDataMap.set(t,i),this._loadNormalTexture(i))}setMetallicRoughnessTextureTag(e,t){const i=this._instanceDataMap.get(t);i&&(i._metallicRoughnessTextureSrc=e,this._instanceDataMap.set(t,i),this._loadMetallicRoughnessTexture(i))}setObjectSrc(e,t){const i=this._instanceDataMap.get(t);e&&i&&i._objectSrc!==e&&(i._objectSrc=e,mi.loadObj(e).then((e=>{this._updateInstanceData(e[0],t)})))}_updateInstanceData(e,t){const i=this._instanceDataMap.get(t);i&&(e.vertices.length!==i._vertexArr.length&&(i._vertexArr=e.vertices,i._changedBuffers[ji]=!0),e.normals.length!==i._normalsArr.length&&(i._normalsArr=e.normals,i._changedBuffers[$i]=!0),e.indices.length!==i._indicesArr.length&&(i._indicesArr=e.indices,i._changedBuffers[Xi]=!0),e.texCoords.length!==i._texCoordArr.length&&(i._texCoordArr=e.texCoords,i._changedBuffers[es]=!0),i._colorTextureSrc=e.colorTexture,i._normalTextureSrc=e.normalTexture,i._metallicRoughnessTexture=e.metallicRoughnessTexture,this._loadColorTexture(i),this._loadNormalTexture(i),this._loadMetallicRoughnessTexture(i),this._updateTag(i),this._instanceDataMapValues=Array.from(this._instanceDataMap.values()))}_addGeoObjectToArray(e){const t=e.tag;let i=this._instanceDataMap.get(t);i||(i=new Yi(this),this._instanceDataMap.set(t,i),this._instanceDataMapValues=Array.from(this._instanceDataMap.values()),i._vertexArr=e.vertices,i._normalsArr=e.normals,i._indicesArr=e.indices,i._texCoordArr=e.texCoords,i._colorTextureSrc=e.object3d.colorTexture,i._normalTextureSrc=e.object3d.normalTexture,i._metallicRoughnessTextureSrc=e.object3d.metallicRoughnessTexture,i.setMaterialParams(e.object3d.ambient,e.object3d.diffuse,e.object3d.specular,e.object3d.shininess),this._loadColorTexture(i),this._loadNormalTexture(i),this._loadMetallicRoughnessTexture(i)),e._tagDataIndex=i.numInstances++,e._tagData=i,i.geoObjects.push(e);let s=3;i._visibleArr=Oe(i._visibleArr,ss([],0,1,1,e.getVisibility()?1:0)),this.getRTCPosition(e.getPosition(),e._rtcPositionHigh,e._rtcPositionLow);let n,r=e._rtcPositionHigh.x,o=e._rtcPositionHigh.y,a=e._rtcPositionHigh.z;i._rtcPositionHighArr=Oe(i._rtcPositionHighArr,ss([],0,s,s,r,o,a)),r=e._rtcPositionLow.x,o=e._rtcPositionLow.y,a=e._rtcPositionLow.z,i._rtcPositionLowArr=Oe(i._rtcPositionLowArr,ss([],0,s,s,r,o,a)),r=e._entity._pickingColor.x/255,o=e._entity._pickingColor.y/255,a=e._entity._pickingColor.z/255,i._pickingColorArr=Oe(i._pickingColorArr,ss([],0,s,s,r,o,a)),s=4,r=e._qRot.x,o=e._qRot.y,a=e._qRot.z,n=e._qRot.w,i._qRotArr=Oe(i._qRotArr,ss([],0,s,s,r,o,a,n)),r=e._color.x,o=e._color.y,a=e._color.z,n=e._color.w,i._rgbaArr=Oe(i._rgbaArr,ss([],0,s,s,r,o,a,n)),s=3;let l=e.getScale();r=l.x,o=l.y,a=l.z,i._sizeArr=Oe(i._sizeArr,ss([],0,s,s,r,o,a));let h=e.getTranslate();r=h.x,o=h.y,a=h.z,i._translateArr=Oe(i._translateArr,ss([],0,s,s,r,o,a));let c=e.getLocalPosition();r=c.x,o=c.y,a=c.z,i._localPositionArr=Oe(i._localPositionArr,ss([],0,s,s,r,o,a))}_bindCommon(){let e=this._renderer,t=e.handler.programs.geo_object._program.uniforms,i=e.handler.gl,s=this._entityCollection;i.uniform3fv(t.uScaleByDistance,s.scaleByDistance),i.uniform1f(t.useLighting,s._useLighting),i.uniform3fv(t.eyePositionHigh,e.activeCamera.eyeHigh),i.uniform3fv(t.eyePositionLow,e.activeCamera.eyeLow),i.uniform3fv(t.rtcEyePositionHigh,this._rtcEyePositionHigh),i.uniform3fv(t.rtcEyePositionLow,this._rtcEyePositionLow),i.uniformMatrix4fv(t.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),i.uniformMatrix4fv(t.viewMatrix,!1,e.activeCamera.getViewMatrix()),i.uniform3fv(t.sunPosition,this._renderNode._lightPosition)}_displayOpaquePASS(){let e=this._renderer.handler.programs.geo_object,t=e._program;e.activate(),this._bindCommon();for(let e=0;e<this._instanceDataMapValues.length;e++){this._instanceDataMapValues[e].drawOpaque(t)}}_displayTransparentPASS(){let e=this._renderer.handler.programs.geo_object,t=e._program;e.activate(),this._bindCommon();for(let e=0;e<this._instanceDataMapValues.length;e++)this._instanceDataMapValues[e].drawTransparent(t)}_depthPASS(){let e=this._renderer,t=e.handler.programs.geo_object_depth,i=t._program,s=i.uniforms,n=i.attributes,r=e.handler.gl,o=this._entityCollection,a=e.activeCamera;t.activate(),r.uniform3fv(s.uScaleByDistance,o.scaleByDistance),r.uniform3fv(s.rtcEyePositionHigh,this._rtcEyePositionHigh),r.uniform3fv(s.rtcEyePositionLow,this._rtcEyePositionLow),r.uniformMatrix4fv(s.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),r.uniformMatrix4fv(s.viewMatrix,!1,e.activeCamera.getViewMatrix()),r.uniform1f(s.frustumPickingColor,a.frustumColorIndex);for(let e=0;e<this._instanceDataMapValues.length;e++){let t=this._instanceDataMapValues[e];r.bindBuffer(r.ARRAY_BUFFER,t._qRotBuffer),r.vertexAttribPointer(n.qRot,t._qRotBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._sizeBuffer),r.vertexAttribPointer(n.aScale,t._sizeBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._translateBuffer),r.vertexAttribPointer(n.aTranslate,t._translateBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._localPositionBuffer),r.vertexAttribPointer(n.aLocalPosition,t._localPositionBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._rtcPositionHighBuffer),r.vertexAttribPointer(n.aRTCPositionHigh,t._rtcPositionHighBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._rtcPositionLowBuffer),r.vertexAttribPointer(n.aRTCPositionLow,t._rtcPositionLowBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._visibleBuffer),r.vertexAttribPointer(n.aDispose,t._visibleBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._vertexBuffer),r.vertexAttribPointer(n.aVertexPosition,t._vertexBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,t._indicesBuffer),i.drawElementsInstanced(r.TRIANGLES,t._indicesBuffer.numItems,r.UNSIGNED_INT,0,t.numInstances)}}drawDepth(){this._geoObjects.length&&this._depthPASS()}drawPicking(){this._geoObjects.length&&this.pickingEnabled&&this._pickingPASS()}_pickingPASS(){let e=this._renderer,t=e.handler.programs.geo_object_picking,i=t._program,s=i.uniforms,n=i.attributes,r=e.handler.gl,o=this._entityCollection;t.activate(),r.uniform3fv(s.uScaleByDistance,o.scaleByDistance),r.uniform3fv(s.pickingScale,o.pickingScale),r.uniform3fv(s.rtcEyePositionHigh,this._rtcEyePositionHigh),r.uniform3fv(s.rtcEyePositionLow,this._rtcEyePositionLow),r.uniformMatrix4fv(s.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),r.uniformMatrix4fv(s.viewMatrix,!1,e.activeCamera.getViewMatrix());for(let e=0;e<this._instanceDataMapValues.length;e++){let t=this._instanceDataMapValues[e];r.bindBuffer(r.ARRAY_BUFFER,t._qRotBuffer),r.vertexAttribPointer(n.qRot,t._qRotBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._sizeBuffer),r.vertexAttribPointer(n.aScale,t._sizeBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._translateBuffer),r.vertexAttribPointer(n.aTranslate,t._translateBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._localPositionBuffer),r.vertexAttribPointer(n.aLocalPosition,t._localPositionBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._pickingColorBuffer),r.vertexAttribPointer(n.aPickingColor,t._pickingColorBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._rtcPositionHighBuffer),r.vertexAttribPointer(n.aRTCPositionHigh,t._rtcPositionHighBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._rtcPositionLowBuffer),r.vertexAttribPointer(n.aRTCPositionLow,t._rtcPositionLowBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._visibleBuffer),r.vertexAttribPointer(n.aDispose,t._visibleBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,t._vertexBuffer),r.vertexAttribPointer(n.aVertexPosition,t._vertexBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,t._indicesBuffer),i.drawElementsInstanced(r.TRIANGLES,t._indicesBuffer.numItems,r.UNSIGNED_INT,0,t.numInstances)}}async _loadColorTexture(e){if(this._renderer&&e._colorTextureSrc){const t=await Xe(e._colorTextureSrc);e.createColorTexture(t)}}async _loadNormalTexture(e){if(this._renderer&&e._normalTextureSrc){const t=await Xe(e._normalTextureSrc);e.createNormalTexture(t)}}async _loadMetallicRoughnessTexture(e){if(this._renderer&&e._metallicRoughnessTextureSrc){const t=await Xe(e._metallicRoughnessTextureSrc);e.createMetallicRoughnessTexture(t)}}setQRotArr(e,t,i){ss(e._qRotArr,t,4,4,i.x,i.y,i.z,i.w),e._changedBuffers[Zi]=!0,this._updateTag(e)}setVisibility(e,t,i){ss(e._visibleArr,t,1,1,i?1:0),e._changedBuffers[Ji]=!0,this._updateTag(e)}setRTCPositionArr(e,t,i,s){ss(e._rtcPositionHighArr,t,3,3,i.x,i.y,i.z),ss(e._rtcPositionLowArr,t,3,3,s.x,s.y,s.z),e._changedBuffers[Wi]=!0,this._updateTag(e)}setRgbaArr(e,t,i){ss(e._rgbaArr,t,4,4,i.x,i.y,i.z,i.w),e._changedBuffers[qi]=!0,this._updateTag(e)}setPickingColorArr(e,t,i){ss(e._pickingColorArr,t,3,3,i.x/255,i.y/255,i.z/255),e._changedBuffers[Qi]=!0,this._updateTag(e)}setScaleArr(e,t,i){ss(e._sizeArr,t,3,3,i.x,i.y,i.z),e._changedBuffers[Ki]=!0,this._updateTag(e)}setTranslateArr(e,t,i){ss(e._translateArr,t,3,3,i.x,i.y,i.z),e._changedBuffers[ts]=!0,this._updateTag(e)}setLocalPositionArr(e,t,i){ss(e._localPositionArr,t,3,3,i.x,i.y,i.z),e._changedBuffers[is]=!0,this._updateTag(e)}_updateTag(e){e.isFree&&(e.isFree=!1,this._dataTagUpdateQueue.push(e))}update(){for(let e=0,t=this._dataTagUpdateQueue.length;e<t;e++)this._dataTagUpdateQueue[e].update();this._dataTagUpdateQueue=[]}_removeAll(){let e=this._geoObjects.length;for(;e--;){const t=this._geoObjects[e];t._tagDataIndex=-1,t._tagData=null,t._handlerIndex=-1,t._handler=null}this._geoObjects.length=0,this._geoObjects=[];for(let e=0;e<this._instanceDataMapValues.length;e++)this._instanceDataMapValues[e].clear();this._instanceDataMap.clear(),this._instanceDataMapValues=[]}clear(){this._removeAll()}getRTCPosition(e,t,i){let s=e.sub(this._relativeCenter);oe.doubleToTwoFloats(s,t,i)}setRelativeCenter(e){this._relativeCenter.copy(e);for(let e=0;e<this._instanceDataMapValues.length;e++){let t=this._instanceDataMapValues[e].geoObjects;for(let e=0;e<t.length;e++)t[e].updateRTCPosition()}}_updateRTCEyePosition(){let e=this._renderer;if(e.activeCamera.isFirstPass){let t=e.activeCamera.eye.sub(this._relativeCenter);oe.doubleToTwoFloat32Array(t,this._rtcEyePositionHigh,this._rtcEyePositionLow)}}draw(){this._geoObjects.length&&(this._updateRTCEyePosition(),this.update(),this._displayOpaquePASS())}drawTransparent(){this._geoObjects.length&&this._displayTransparentPASS()}add(e){-1===e._handlerIndex&&(e._handler=this,e._handlerIndex=this._geoObjects.length,this._geoObjects.push(e),this._addGeoObjectToArray(e),e.updateRotation(),e._tagData.refresh(),this._updateTag(e._tagData),e.setObjectSrc(e._objectSrc))}remove(e){e._handler&&this.__id==e._handler.__id&&this._removeGeoObject(e)}_clearDataTagQueue(){this._dataTagUpdateQueue=[]}_removeGeoObject(e){let t=e._tagData,i=e.tag;t.numInstances--;let s=!1;0===t.numInstances&&(t.clear(),this._instanceDataMap.delete(i),this._instanceDataMapValues=[],this._clearDataTagQueue(),s=!0),this._geoObjects.splice(e._handlerIndex,1);for(let t=e._handlerIndex,i=this._geoObjects.length;t<i;t++){let e=this._geoObjects[t];e._handlerIndex=e._handlerIndex-1}let n=e._tagDataIndex;t.geoObjects.splice(n,1);for(let i=e._tagDataIndex,s=t.geoObjects.length;i<s;i++){let e=t.geoObjects[i];e._tagDataIndex=e._tagDataIndex-1}t._rgbaArr=Ge(t._rgbaArr,4*n,4),t._rtcPositionHighArr=Ge(t._rtcPositionHighArr,3*n,3),t._rtcPositionLowArr=Ge(t._rtcPositionLowArr,3*n,3),t._qRotArr=Ge(t._qRotArr,4*n,4),t._pickingColorArr=Ge(t._pickingColorArr,3*n,3),t._sizeArr=Ge(t._sizeArr,3*n,3),t._translateArr=Ge(t._translateArr,3*n,3),t._localPositionArr=Ge(t._localPositionArr,3*n,3),t._visibleArr=Ge(t._visibleArr,n,1),e._handlerIndex=-1,e._handler=null,e._tagDataIndex=-1,e._tagData=null,s||(t.refresh(),this._updateTag(t))}}ns.__counter__=0;const rs="\n#define EMPTY -1.0\n#define RTL 1.0",os="vec2 project(vec4 p) {\n return (0.5 * p.xyz / p.w + 0.5).xy * viewport;\n }",as="mat2 rotate2d(float angle) {\n return mat2(cos(angle), -sin(angle),\n sin(angle), cos(angle));\n }";const ls=-1;class hs extends Vi{constructor(e,t=21){super(e),this._billboards=[],this._gliphParamBuffer=null,this._fontIndexBuffer=null,this._outlineBuffer=null,this._outlineColorBuffer=null,this._gliphParamArr=new Float32Array([]),this._fontIndexArr=new Float32Array([]),this._outlineArr=new Float32Array([]),this._outlineColorArr=new Float32Array([]),this._buffersUpdateCallbacks[8]=this.createFontIndexBuffer,this._buffersUpdateCallbacks[9]=this.createOutlineBuffer,this._buffersUpdateCallbacks[10]=this.createOutlineColorBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length),this._maxLetters=t}initProgram(){this._renderer&&this._renderer.handler&&this._renderer.handler.gl&&(this._renderer.handler.programs.label||("webgl2"===this._renderer.handler.gl.type?this._renderer.handler.addProgram(new Ni("label",{uniforms:{viewport:"vec2",fontTextureArr:"sampler2darray",sdfParamsArr:"vec4",projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",planetRadius:"float",scaleByDistance:"vec3",opacity:"float",isOutlinePass:"int",depthOffset:"float"},attributes:{a_outline:"float",a_gliphParam:"vec4",a_vertices:"vec2",a_texCoord:"vec4",a_positionsHigh:"vec3",a_positionsLow:"vec3",a_size:"float",a_rotation:"float",a_rgba:"vec4",a_offset:"vec3",a_fontIndex:"float"},vertexShader:`#version 300 es\n \n ${rs}\n \n in float a_outline;\n in vec4 a_gliphParam;\n in vec2 a_vertices;\n in vec4 a_texCoord;\n in vec3 a_positionsHigh;\n in vec3 a_positionsLow;\n in vec3 a_offset;\n in float a_size;\n in float a_rotation;\n in vec4 a_rgba;\n in float a_fontIndex;\n\n out vec2 v_uv;\n out vec4 v_rgba;\n flat out int v_fontIndex; \n out vec4 v_outlineColor;\n flat out float v_outline;\n\n uniform vec2 viewport;\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float planetRadius;\n uniform vec3 scaleByDistance;\n uniform float opacity;\n uniform float depthOffset;\n\n const vec3 ZERO3 = vec3(0.0);\n \n ${os}\n\n ${as}\n\n void main() {\n\n if(a_texCoord.w == EMPTY) {\n gl_Position = vec4(0.0);\n v_fontIndex = -1;\n return;\n }\n \n vec3 a_positions = a_positionsHigh + a_positionsLow;\n vec3 cameraPos = eyePositionHigh + eyePositionLow;\n\n v_outline = a_outline;\n\n v_fontIndex = int(a_fontIndex);\n v_uv = a_texCoord.xy;\n vec3 look = a_positions - cameraPos;\n float lookDist = length(look);\n v_rgba = a_rgba;\n \n if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){\n return;\n }\n\n float scd = (1.0 - smoothstep(scaleByDistance[0], scaleByDistance[1], lookDist)) * (1.0 - step(scaleByDistance[2], lookDist));\n\n v_rgba.a *= opacity;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = a_positionsHigh - eyePositionHigh;\n vec3 lowDiff = a_positionsLow - eyePositionLow;\n vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n vec4 projPos = projectionMatrix * posRTE;\n \n float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos)); \n if(camSlope > 0.5) {\n float dist = dot(look, normalize(cameraPos));\n projPos.z += dist * 0.02; \n }else{\n projPos.z += -(abs(projPos.z)) * 0.002; \n }\n \n projPos.z += depthOffset + a_offset.z;\n \n vec2 screenPos = project(projPos);\n \n vec2 vert = a_vertices; \n vec4 gp = a_gliphParam; \n if(a_texCoord.w == RTL){\n vert.x = step(vert.x * 0.5 + 1.0, 1.0);\n gp.x = -a_gliphParam.x;\n gp.z = -(a_gliphParam.z + a_texCoord.z);\n }else{\n gp.z = a_gliphParam.z + a_texCoord.z;\n }\n \n vec2 v = screenPos + rotate2d(a_rotation) * ((vert * gp.xy + gp.zw) * a_size * scd + a_offset.xy);\n\n gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);\n }`,fragmentShader:"#version 300 es\n\n uniform int isOutlinePass;\n \n precision highp float;\n\n const int MAX_SIZE = 11;\n\n // x - ATLAS_WIDTH = 512.0;\n // y - ATLAS_HEIGHT = 512.0;\n // z - ATLAS_GLYPH_SIZE = 32.0;\n // w - ATLAS_FIELD_RANGE = 8.0;\n\n uniform sampler2D fontTextureArr[MAX_SIZE];\n uniform vec4 sdfParamsArr[MAX_SIZE];\n\n flat in int v_fontIndex;\n in vec2 v_uv;\n in vec4 v_rgba; \n\n flat in float v_outline;\n\n in vec3 v_pickingColor;\n\n layout(location = 0) out vec4 outScreen;\n\n float median(float r, float g, float b) {\n return max(min(r, g), min(max(r, g), b));\n }\n\n float getDistance() {\n vec3 msdf;\n if(v_fontIndex == 0) {\n msdf = texture(fontTextureArr[0], v_uv).rgb;\n } else if(v_fontIndex == 1){\n msdf = texture(fontTextureArr[1], v_uv).rgb;\n } else if(v_fontIndex == 2){\n msdf = texture(fontTextureArr[2], v_uv).rgb;\n } else if(v_fontIndex == 3){\n msdf = texture(fontTextureArr[3], v_uv).rgb;\n } else if(v_fontIndex == 4){\n msdf = texture(fontTextureArr[4], v_uv).rgb;\n } else if(v_fontIndex == 5){\n msdf = texture(fontTextureArr[5], v_uv).rgb;\n } else if(v_fontIndex == 6){\n msdf = texture(fontTextureArr[6], v_uv).rgb;\n } else if(v_fontIndex == 7){\n msdf = texture(fontTextureArr[7], v_uv).rgb;\n } else if(v_fontIndex == 8){\n msdf = texture(fontTextureArr[8], v_uv).rgb;\n } else if(v_fontIndex == 9){\n msdf = texture(fontTextureArr[9], v_uv).rgb;\n } else if(v_fontIndex == 10){\n msdf = texture(fontTextureArr[10], v_uv).rgb;\n }\n return median(msdf.r, msdf.g, msdf.b);\n }\n \n void main () {\n \n if(v_fontIndex == -1) {\n return;\n }\n \n vec4 sdfParams = sdfParamsArr[v_fontIndex];\n float sd = getDistance(); \n vec2 dxdy = fwidth(v_uv) * sdfParams.xy;\n\n if(isOutlinePass == 0){ \n float dist = sd + min(0.001, 0.5 - 1.0 / sdfParams.w) - 0.5;\n float opacity = clamp(dist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0);\n if(opacity <= 0.1){\n discard;\n }\n outScreen = vec4(v_rgba.rgb, opacity * v_rgba.a);\n } else { \n float dist = sd + min(v_outline, 0.5 - 1.0 / sdfParams.w) - 0.5;\n float opacity = clamp(dist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0); \n if(opacity <= 0.1){\n discard;\n }\n outScreen = vec4(v_rgba.rgb, opacity * v_rgba.a);\n //outScreen = v_rgba * strokeAlpha * (0.5 - opacity) * 2.0;\n } \n }"})):this._renderer.handler.addProgram(new Ni("label",{uniforms:{viewport:"vec2",fontTextureArr:"sampler2darray",sdfParamsArr:"vec4",projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",planetRadius:"float",scaleByDistance:"vec3",opacity:"float",isOutlinePass:"int",depthOffset:"float"},attributes:{a_outline:"float",a_gliphParam:"vec4",a_vertices:"vec2",a_texCoord:"vec4",a_positionsHigh:"vec3",a_positionsLow:"vec3",a_size:"float",a_rotation:"float",a_rgba:"vec4",a_offset:"vec3",a_fontIndex:"float"},vertexShader:` \n ${rs}\n \n attribute float a_outline;\n attribute vec4 a_gliphParam;\n attribute vec2 a_vertices;\n attribute vec4 a_texCoord;\n attribute vec3 a_positionsHigh;\n attribute vec3 a_positionsLow;\n attribute vec3 a_offset;\n attribute float a_size;\n attribute float a_rotation;\n attribute vec4 a_rgba;\n attribute float a_fontIndex;\n\n varying float v_outline;\n varying vec2 v_uv;\n varying vec4 v_rgba;\n varying float v_fontIndex; \n\n uniform vec2 viewport;\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float planetRadius;\n uniform vec3 scaleByDistance;\n uniform float opacity;\n uniform float depthOffset;\n\n const vec3 ZERO3 = vec3(0.0);\n\n ${os}\n\n ${as}\n\n void main() {\n\n if(a_texCoord.w == EMPTY) {\n gl_Position = vec4(0.0);\n v_fontIndex = -1.0;\n return;\n }\n \n vec3 a_positions = a_positionsHigh + a_positionsLow;\n vec3 cameraPos = eyePositionHigh + eyePositionLow;\n\n v_outline = a_outline;\n v_uv = vec2(a_texCoord.xy);\n v_rgba = a_rgba;\n v_fontIndex = a_fontIndex;\n \n vec3 look = a_positions - cameraPos;\n float lookDist = length(look);\n \n if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){\n return;\n }\n\n float scd = (1.0 - smoothstep(scaleByDistance[0], scaleByDistance[1], lookDist)) * (1.0 - step(scaleByDistance[2], lookDist));\n\n v_rgba.a *= opacity;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = a_positionsHigh - eyePositionHigh;\n vec3 lowDiff = a_positionsLow - eyePositionLow;\n vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n vec4 projPos = projectionMatrix * posRTE;\n \n float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos)); \n if(camSlope > 0.5) {\n float dist = dot(look, normalize(cameraPos));\n projPos.z += dist * 0.02; \n }else{\n projPos.z += -(abs(projPos.z)) * 0.002; \n }\n \n projPos.z += depthOffset + a_offset.z;\n \n vec2 screenPos = project(projPos);\n \n vec2 vert = a_vertices; \n vec4 gp = a_gliphParam; \n if(a_texCoord.w == RTL){\n vert.x = step(vert.x * 0.5 + 1.0, 1.0);\n gp.x = -a_gliphParam.x;\n gp.z = -(a_gliphParam.z + a_texCoord.z);\n }else{\n gp.z = a_gliphParam.z + a_texCoord.z;\n }\n \n vec2 v = screenPos + rotate2d(a_rotation) * ((vert * gp.xy + gp.zw) * a_size * scd + a_offset.xy);\n \n gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);\n }`,fragmentShader:"#extension GL_OES_standard_derivatives : enable\n\n precision highp float;\n precision highp int;\n\n const int MAX_SIZE = 11;\n\n // x - ATLAS_WIDTH = 512.0;\n // y - ATLAS_HEIGHT = 512.0;\n // z - ATLAS_GLYPH_SIZE = 32.0;\n // w - ATLAS_FIELD_RANGE = 8.0;\n\n uniform sampler2D fontTextureArr[MAX_SIZE];\n uniform vec4 sdfParamsArr[MAX_SIZE];\n uniform int isOutlinePass;\n \n varying float v_outline;\n varying vec2 v_uv;\n varying vec4 v_rgba; \n varying float v_fontIndex;\n \n float fontIndex;\n\n float median(float r, float g, float b) {\n return max(min(r, g), min(max(r, g), b));\n }\n\n float getDistance() {\n vec3 msdf;\n if(fontIndex >= 0.0 && fontIndex < 1.0) {\n msdf = texture2D(fontTextureArr[0], v_uv).rgb;\n } else if(fontIndex >= 1.0 && fontIndex < 2.0){\n msdf = texture2D(fontTextureArr[1], v_uv).rgb;\n } else if(fontIndex >= 2.0 && fontIndex < 3.0){\n msdf = texture2D(fontTextureArr[2], v_uv).rgb;\n } else if(fontIndex >= 3.0 && fontIndex < 4.0){\n msdf = texture2D(fontTextureArr[3], v_uv).rgb;\n } else if(fontIndex >= 4.0 && fontIndex < 5.0){\n msdf = texture2D(fontTextureArr[4], v_uv).rgb;\n } else if(fontIndex >= 5.0 && fontIndex < 6.0){\n msdf = texture2D(fontTextureArr[5], v_uv).rgb;\n } else if(fontIndex >= 6.0 && fontIndex < 7.0){\n msdf = texture2D(fontTextureArr[6], v_uv).rgb;\n } else if(fontIndex >= 7.0 && fontIndex < 8.0){\n msdf = texture2D(fontTextureArr[7], v_uv).rgb;\n } else if(fontIndex >= 8.0 && fontIndex < 9.0){\n msdf = texture2D(fontTextureArr[8], v_uv).rgb;\n } else if(fontIndex >= 9.0 && fontIndex < 10.0){\n msdf = texture2D(fontTextureArr[9], v_uv).rgb;\n } else if(fontIndex >= 10.0 && fontIndex < 11.0){\n msdf = texture2D(fontTextureArr[10], v_uv).rgb;\n }\n return median(msdf.r, msdf.g, msdf.b);\n }\n\n\n vec4 getSDFParams() {\n if(fontIndex >= 0.0 && fontIndex < 1.0) {\n return sdfParamsArr[0];\n } else if(fontIndex >= 1.0 && fontIndex < 2.0){\n return sdfParamsArr[1];\n } else if(fontIndex >= 2.0 && fontIndex < 3.0){\n return sdfParamsArr[2];\n } else if(fontIndex >= 3.0 && fontIndex < 4.0){\n return sdfParamsArr[3];\n } else if(fontIndex >= 4.0 && fontIndex < 5.0){\n return sdfParamsArr[4];\n } else if(fontIndex >= 5.0 && fontIndex < 6.0){\n return sdfParamsArr[5];\n } else if(fontIndex >= 6.0 && fontIndex < 7.0){\n return sdfParamsArr[6];\n } else if(fontIndex >= 7.0 && fontIndex < 8.0){\n return sdfParamsArr[7];\n } else if(fontIndex >= 8.0 && fontIndex < 9.0){\n return sdfParamsArr[8];\n } else if(fontIndex >= 9.0 && fontIndex < 10.0){\n return sdfParamsArr[9];\n } else if(fontIndex >= 10.0 && fontIndex < 11.0){\n return sdfParamsArr[10];\n }\n }\n \n void main () {\n\n fontIndex = v_fontIndex + 0.1;\n \n if(v_fontIndex < 0.0){\n return;\n }\n \n vec4 sdfParams = getSDFParams();\n float sd = getDistance(); \n vec2 dxdy = fwidth(v_uv) * sdfParams.xy;\n float dist = sd + min(0.001, 0.5 - 1.0 / sdfParams.w) - 0.5;\n float opacity = clamp(dist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0);\n\n if(isOutlinePass == 0){ \n //gl_FragColor = vec4(v_rgba.rgb, opacity * v_rgba.a);\n } else { \n float strokeDist = sd + min(v_outline, 0.5 - 1.0 / sdfParams.w) - 0.5;\n float strokeAlpha = v_rgba.a * clamp(strokeDist * sdfParams.w / length(dxdy) + 0.5, 0.0, 1.0); \n if(strokeAlpha < 0.1){\n discard;\n }\n //gl_FragColor = v_rgba * strokeAlpha * (0.5 - opacity) * 2.0;\n }\n }"}))),this._renderer.handler.programs.labelPicking||this._renderer.handler.addProgram(new Ni("labelPicking",{uniforms:{viewport:"vec2",projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",planetRadius:"float",scaleByDistance:"vec3",opacity:"float",depthOffset:"float"},attributes:{a_gliphParam:"vec4",a_vertices:"vec2",a_texCoord:"vec4",a_positionsHigh:"vec3",a_positionsLow:"vec3",a_offset:"vec3",a_size:"float",a_rotation:"float",a_rgba:"vec4"},vertexShader:`\n \n ${rs}\n \n attribute vec4 a_gliphParam;\n attribute vec2 a_vertices;\n attribute vec4 a_texCoord;\n attribute vec3 a_positionsHigh;\n attribute vec3 a_positionsLow;\n attribute vec3 a_offset;\n attribute float a_size;\n attribute float a_rotation;\n attribute vec4 a_rgba;\n\n varying vec4 v_rgba;\n\n uniform vec2 viewport;\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float planetRadius;\n uniform vec3 scaleByDistance;\n uniform float opacity;\n uniform float depthOffset;\n\n const vec3 ZERO3 = vec3(0.0);\n\n ${os}\n\n ${as}\n\n void main() {\n vec3 a_positions = a_positionsHigh + a_positionsLow;\n vec3 cameraPos = eyePositionHigh + eyePositionLow;\n v_rgba = a_rgba;\n \n if(a_texCoord.w == EMPTY) {\n v_rgba.a = 0.0;\n gl_Position = vec4(0.0);\n return;\n }\n\n vec3 look = a_positions - cameraPos;\n float lookDist = length(look);\n if(opacity * step(lookDist, sqrt(dot(cameraPos,cameraPos) - planetRadius) + sqrt(dot(a_positions,a_positions) - planetRadius)) == 0.0){\n return;\n }\n\n float scd = (1.0 - smoothstep(scaleByDistance[0], scaleByDistance[1], lookDist)) * (1.0 - step(scaleByDistance[2], lookDist));\n\n v_rgba.a *= opacity;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff = a_positionsHigh - eyePositionHigh;\n vec3 lowDiff = a_positionsLow - eyePositionLow;\n vec4 posRTE = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n vec4 projPos = projectionMatrix * posRTE;\n \n float camSlope = dot(vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]), normalize(cameraPos)); \n if(camSlope > 0.5) {\n float dist = dot(look, normalize(cameraPos));\n projPos.z += dist * 0.02; \n }else{\n projPos.z += -(abs(projPos.z)) * 0.002; \n }\n \n projPos.z += depthOffset + a_offset.z;\n \n vec2 screenPos = project(projPos);\n \n vec2 vert = a_vertices; \n vec4 gp = a_gliphParam; \n if(a_texCoord.w == RTL){\n vert.x = step(vert.x * 0.5 + 1.0, 1.0);\n gp.x = -a_gliphParam.x;\n gp.z = -(a_gliphParam.z + a_texCoord.z);\n }else{\n gp.z = a_gliphParam.z + a_texCoord.z;\n }\n \n vec2 v = screenPos + rotate2d(a_rotation) * ((vert * gp.xy + gp.zw) * a_size * scd + a_offset.xy);\n \n gl_Position = vec4((2.0 * v / viewport - 1.0) * projPos.w, projPos.z, projPos.w);\n }`,fragmentShader:"precision highp float;\n\n varying vec4 v_rgba;\n\n varying vec3 v_pickingColor;\n\n void main () {\n\n vec4 color = v_rgba;\n if (color.a < 0.05) {\n return;\n }\n\n gl_FragColor = vec4(v_rgba.rgb, v_rgba.a);\n }"})))}get labels(){return this._billboards}add(e){e._handler||(e._handler=this,this.assignFontAtlas(e),this.refresh())}updateFonts(){let e=[...this._billboards];this._billboards=[];for(let t=0;t<e.length;t++)this.assignFontAtlas(e[t])}_addLabelToArrays(e){this._renderer&&this._renderer.labelWorker.make({handler:this,label:e})}assignFontAtlas(e){this._entityCollection&&this._renderer?(e.assignFontAtlas(this._renderer.fontAtlas),this._addLabelToArrays(e)):this._billboards.push(e)}workerCallback(e,t){t._lockId!==ii&&t._handler&&this.isEqual(t._handler)&&(t._isReady=!0,t._lockId=ii,t._handlerIndex=this._billboards.length,this._billboards.push(t),this._vertexArr=He(this._vertexArr,e.vertexArr),this._texCoordArr=He(this._texCoordArr,e.texCoordArr),this._gliphParamArr=He(this._gliphParamArr,e.gliphParamArr),this._positionHighArr=He(this._positionHighArr,e.positionHighArr),this._positionLowArr=He(this._positionLowArr,e.positionLowArr),this._sizeArr=He(this._sizeArr,e.sizeArr),this._offsetArr=He(this._offsetArr,e.offsetArr),this._rgbaArr=He(this._rgbaArr,e.rgbaArr),this._rotationArr=He(this._rotationArr,e.rotationArr),this._fontIndexArr=He(this._fontIndexArr,e.fontIndexArr),this._outlineArr=He(this._outlineArr,e.outlineArr),this._outlineColorArr=He(this._outlineColorArr,e.outlineColorArr),this._pickingColorArr=He(this._pickingColorArr,e.pickingColorArr),t.update(),this.refresh())}clear(){this._texCoordArr=null,this._gliphParamArr=null,this._vertexArr=null,this._positionHighArr=null,this._positionLowArr=null,this._sizeArr=null,this._offsetArr=null,this._rgbaArr=null,this._rotationArr=null,this._fontIndexArr=null,this._outlineArr=null,this._outlineColorArr=null,this._texCoordArr=new Float32Array([]),this._gliphParamArr=new Float32Array([]),this._vertexArr=new Float32Array([]),this._positionHighArr=new Float32Array([]),this._positionLowArr=new Float32Array([]),this._sizeArr=new Float32Array([]),this._offsetArr=new Float32Array([]),this._rgbaArr=new Float32Array([]),this._rotationArr=new Float32Array([]),this._fontIndexArr=new Float32Array([]),this._outlineArr=new Float32Array([]),this._outlineColorArr=new Float32Array([]),this._removeBillboards(),this._deleteBuffers(),this.refresh()}_deleteBuffers(){if(this._renderer){let e=this._renderer.handler.gl;e.deleteBuffer(this._gliphParamBuffer),e.deleteBuffer(this._sizeBuffer),e.deleteBuffer(this._fontIndexBuffer),e.deleteBuffer(this._texCoordBuffer),e.deleteBuffer(this._outlineBuffer),e.deleteBuffer(this._outlineColorBuffer),e.deleteBuffer(this._positionHighBuffer),e.deleteBuffer(this._positionLowBuffer),e.deleteBuffer(this._sizeBuffer),e.deleteBuffer(this._offsetBuffer),e.deleteBuffer(this._rgbaBuffer),e.deleteBuffer(this._rotationBuffer),e.deleteBuffer(this._vertexBuffer),e.deleteBuffer(this._texCoordBuffer),e.deleteBuffer(this._pickingColorBuffer),this._gliphParamBuffer=null,this._sizeBuffer=null,this._fontIndexBuffer=null,this._texCoordBuffer=null,this._outlineBuffer=null,this._outlineColorBuffer=null,this._positionHighBuffer=null,this._positionLowBuffer=null,this._sizeBuffer=null,this._offsetBuffer=null,this._rgbaBuffer=null,this._rotationBuffer=null,this._vertexBuffer=null,this._texCoordBuffer=null,this._pickingColorBuffer=null}}_displayPASS(){let e=this._renderer,t=e.handler;t.programs.label.activate();let i=t.programs.label._program,s=i.attributes,n=i.uniforms,r=t.gl,o=this._entityCollection;r.disable(r.CULL_FACE),r.uniform1iv(n.fontTextureArr,e.fontAtlas.samplerArr),r.uniform4fv(n.sdfParamsArr,e.fontAtlas.sdfParamsArr),r.uniformMatrix4fv(n.viewMatrix,!1,e.activeCamera.getViewMatrix()),r.uniformMatrix4fv(n.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),r.uniform3fv(n.eyePositionHigh,e.activeCamera.eyeHigh),r.uniform3fv(n.eyePositionLow,e.activeCamera.eyeLow),r.uniform3fv(n.scaleByDistance,o.scaleByDistance),r.uniform1f(n.opacity,o._fadingOpacity),r.uniform1f(n.planetRadius,o.renderNode._planetRadius2||0),r.uniform2fv(n.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),r.bindBuffer(r.ARRAY_BUFFER,this._texCoordBuffer),r.vertexAttribPointer(s.a_texCoord,this._texCoordBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._gliphParamBuffer),r.vertexAttribPointer(s.a_gliphParam,this._gliphParamBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._vertexBuffer),r.vertexAttribPointer(s.a_vertices,this._vertexBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._positionHighBuffer),r.vertexAttribPointer(s.a_positionsHigh,this._positionHighBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._positionLowBuffer),r.vertexAttribPointer(s.a_positionsLow,this._positionLowBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._sizeBuffer),r.vertexAttribPointer(s.a_size,this._sizeBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._rotationBuffer),r.vertexAttribPointer(s.a_rotation,this._rotationBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._offsetBuffer),r.vertexAttribPointer(s.a_offset,this._offsetBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._fontIndexBuffer),r.vertexAttribPointer(s.a_fontIndex,this._fontIndexBuffer.itemSize,r.FLOAT,!1,0,0),r.uniform1i(n.isOutlinePass,1),r.uniform1f(n.depthOffset,o.polygonOffsetUnits),r.bindBuffer(r.ARRAY_BUFFER,this._outlineColorBuffer),r.vertexAttribPointer(s.a_rgba,this._outlineColorBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._outlineBuffer),r.vertexAttribPointer(s.a_outline,this._outlineBuffer.itemSize,r.FLOAT,!1,0,0),r.drawArrays(r.TRIANGLES,0,this._vertexBuffer.numItems),r.depthFunc(r.EQUAL),r.uniform1i(n.isOutlinePass,0),r.uniform1f(n.depthOffset,o.polygonOffsetUnits),r.bindBuffer(r.ARRAY_BUFFER,this._rgbaBuffer),r.vertexAttribPointer(s.a_rgba,this._rgbaBuffer.itemSize,r.FLOAT,!1,0,0),r.drawArrays(r.TRIANGLES,0,this._vertexBuffer.numItems),r.depthFunc(r.LESS),r.enable(r.CULL_FACE)}_pickingPASS(){let e=this._renderer,t=e.handler;t.programs.labelPicking.activate();let i=t.programs.labelPicking._program,s=i.attributes,n=i.uniforms,r=t.gl,o=this._entityCollection,a=o.renderNode;r.disable(r.CULL_FACE),r.uniformMatrix4fv(n.viewMatrix,!1,e.activeCamera.getViewMatrix()),r.uniformMatrix4fv(n.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),r.uniform3fv(n.eyePositionHigh,e.activeCamera.eyeHigh),r.uniform3fv(n.eyePositionLow,e.activeCamera.eyeLow),r.uniform3fv(n.scaleByDistance,o.scaleByDistance),r.uniform1f(n.opacity,o._fadingOpacity),r.uniform1f(n.planetRadius,a._planetRadius2||0),r.uniform2fv(n.viewport,[t.canvas.clientWidth,t.canvas.clientHeight]),r.bindBuffer(r.ARRAY_BUFFER,this._texCoordBuffer),r.vertexAttribPointer(s.a_texCoord,this._texCoordBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._gliphParamBuffer),r.vertexAttribPointer(s.a_gliphParam,this._gliphParamBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._vertexBuffer),r.vertexAttribPointer(s.a_vertices,this._vertexBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._positionHighBuffer),r.vertexAttribPointer(s.a_positionsHigh,this._positionHighBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._positionLowBuffer),r.vertexAttribPointer(s.a_positionsLow,this._positionLowBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._sizeBuffer),r.vertexAttribPointer(s.a_size,this._sizeBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._rotationBuffer),r.vertexAttribPointer(s.a_rotation,this._rotationBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._offsetBuffer),r.vertexAttribPointer(s.a_offset,this._offsetBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._pickingColorBuffer),r.vertexAttribPointer(s.a_rgba,this._pickingColorBuffer.itemSize,r.FLOAT,!1,0,0),r.uniform1f(n.depthOffset,o.polygonOffsetUnits),r.drawArrays(r.TRIANGLES,0,this._vertexBuffer.numItems),r.enable(r.CULL_FACE)}_removeBillboard(e){let t=e._handlerIndex;this._billboards.splice(t,1);let i=24*this._maxLetters,s=t*i;this._rgbaArr=Ye(this._rgbaArr,s,i),this._outlineColorArr=Ye(this._outlineColorArr,s,i),this._texCoordArr=Ye(this._texCoordArr,s,i),this._gliphParamArr=Ye(this._gliphParamArr,s,i),i=18*this._maxLetters,s=t*i,this._positionHighArr=Ye(this._positionHighArr,s,i),this._positionLowArr=Ye(this._positionLowArr,s,i),this._offsetArr=Ye(this._offsetArr,s,i),this._pickingColorArr=Ye(this._pickingColorArr,s,i),i=12*this._maxLetters,s=t*i,this._vertexArr=Ye(this._vertexArr,s,i),i=6*this._maxLetters,s=t*i,this._sizeArr=Ye(this._sizeArr,s,i),this._rotationArr=Ye(this._rotationArr,s,i),this._fontIndexArr=Ye(this._fontIndexArr,s,i),this._outlineArr=Ye(this._outlineArr,s,i),this.reindexBillboardsArray(t),this.refresh(),e._handlerIndex=-1,e._handler=null,e._isReady=!1}setText(e,t,i,s,n=0,r=!1){t=t.normalize("NFKC");let o=this._renderer.fontAtlas.atlasesArr[i];if(!o)return;let a=24*e*this._maxLetters,l=this._texCoordArr,h=this._gliphParamArr,c=0,d=Math.min(this._maxLetters,t.length),_=0;r&&(_=1);let u=0,g=o.kernings;for(c=0;c<d;c++){let e=a+24*c,i=t[c],s=o.get(i.charCodeAt(0))||o.get(" ".charCodeAt(0));if(!s)continue;let r=s.texCoords,d=s.metrics;l[e]=r[0],l[e+1]=r[1],l[e+2]=u,l[e+3]=_,l[e+4]=r[2],l[e+5]=r[3],l[e+6]=u,l[e+7]=_,l[e+8]=r[4],l[e+9]=r[5],l[e+10]=u,l[e+11]=_,l[e+12]=r[6],l[e+13]=r[7],l[e+14]=u,l[e+15]=_,l[e+16]=r[8],l[e+17]=r[9],l[e+18]=u,l[e+19]=_,l[e+20]=r[10],l[e+21]=r[11],l[e+22]=u,l[e+23]=_,h[e]=d.nWidth,h[e+1]=d.nHeight,h[e+2]=d.nXOffset,h[e+3]=d.nYOffset,h[e+4]=d.nWidth,h[e+5]=d.nHeight,h[e+6]=d.nXOffset,h[e+7]=d.nYOffset,h[e+8]=d.nWidth,h[e+9]=d.nHeight,h[e+10]=d.nXOffset,h[e+11]=d.nYOffset,h[e+12]=d.nWidth,h[e+13]=d.nHeight,h[e+14]=d.nXOffset,h[e+15]=d.nYOffset,h[e+16]=d.nWidth,h[e+17]=d.nHeight,h[e+18]=d.nXOffset,h[e+19]=d.nYOffset,h[e+20]=d.nWidth,h[e+21]=d.nHeight,h[e+22]=d.nXOffset,h[e+23]=d.nYOffset;let f=g[i.charCodeAt(0)];if(f&&t[c+1]){let e=f[t[c+1].charCodeAt(0)];u+=e?d.nAdvance+e+n:d.nAdvance+n}else u+=d.nAdvance+n}if(s===xi.CENTER)for(u*=-.5,c=0;c<d;c++){let e=a+24*c;l[e+2]+=u,l[e+6]+=u,l[e+10]+=u,l[e+14]+=u,l[e+18]+=u,l[e+22]+=u}for(;c<this._maxLetters;c++){let e=a+24*c;l[e+3]=ls,l[e+7]=ls,l[e+11]=ls,l[e+15]=ls,l[e+19]=ls,l[e+23]=ls}this._changedBuffers[6]=!0}setPositionArr(e,t,i){let s=18*e*this._maxLetters,n=this._positionHighArr,r=t.x,o=t.y,a=t.z,l=this._positionLowArr,h=i.x,c=i.y,d=i.z;for(let e=0;e<this._maxLetters;e++){let t=s+18*e;n[t]=r,n[t+1]=o,n[t+2]=a,n[t+3]=r,n[t+4]=o,n[t+5]=a,n[t+6]=r,n[t+7]=o,n[t+8]=a,n[t+9]=r,n[t+10]=o,n[t+11]=a,n[t+12]=r,n[t+13]=o,n[t+14]=a,n[t+15]=r,n[t+16]=o,n[t+17]=a,l[t]=h,l[t+1]=c,l[t+2]=d,l[t+3]=h,l[t+4]=c,l[t+5]=d,l[t+6]=h,l[t+7]=c,l[t+8]=d,l[t+9]=h,l[t+10]=c,l[t+11]=d,l[t+12]=h,l[t+13]=c,l[t+14]=d,l[t+15]=h,l[t+16]=c,l[t+17]=d}this._changedBuffers[1]=!0}setPickingColorArr(e,t){let i=18*e*this._maxLetters,s=this._pickingColorArr,n=t.x/255,r=t.y/255,o=t.z/255;for(let e=0;e<this._maxLetters;e++){let t=i+18*e;s[t]=n,s[t+1]=r,s[t+2]=o,s[t+3]=n,s[t+4]=r,s[t+5]=o,s[t+6]=n,s[t+7]=r,s[t+8]=o,s[t+9]=n,s[t+10]=r,s[t+11]=o,s[t+12]=n,s[t+13]=r,s[t+14]=o,s[t+15]=n,s[t+16]=r,s[t+17]=o}this._changedBuffers[0]=!0}setSizeArr(e,t){let i=6*e*this._maxLetters,s=this._sizeArr;for(let e=0;e<this._maxLetters;e++){let n=i+6*e;s[n]=t,s[n+1]=t,s[n+2]=t,s[n+3]=t,s[n+4]=t,s[n+5]=t}this._changedBuffers[2]=!0}setOffsetArr(e,t){let i=18*e*this._maxLetters,s=this._offsetArr,n=t.x,r=t.y,o=t.z;for(let e=0;e<this._maxLetters;e++){let t=i+18*e;s[t]=n,s[t+1]=r,s[t+2]=o,s[t+3]=n,s[t+4]=r,s[t+5]=o,s[t+6]=n,s[t+7]=r,s[t+8]=o,s[t+9]=n,s[t+10]=r,s[t+11]=o,s[t+12]=n,s[t+13]=r,s[t+14]=o,s[t+15]=n,s[t+16]=r,s[t+17]=o}this._changedBuffers[3]=!0}setRgbaArr(e,t){let i=24*e*this._maxLetters,s=this._rgbaArr,n=t.x,r=t.y,o=t.z,a=t.w;for(let e=0;e<this._maxLetters;e++){let t=i+24*e;s[t]=n,s[t+1]=r,s[t+2]=o,s[t+3]=a,s[t+4]=n,s[t+5]=r,s[t+6]=o,s[t+7]=a,s[t+8]=n,s[t+9]=r,s[t+10]=o,s[t+11]=a,s[t+12]=n,s[t+13]=r,s[t+14]=o,s[t+15]=a,s[t+16]=n,s[t+17]=r,s[t+18]=o,s[t+19]=a,s[t+20]=n,s[t+21]=r,s[t+22]=o,s[t+23]=a}this._changedBuffers[4]=!0}setOutlineColorArr(e,t){let i=24*e*this._maxLetters,s=this._outlineColorArr,n=t.x,r=t.y,o=t.z,a=t.w;for(let e=0;e<this._maxLetters;e++){let t=i+24*e;s[t]=n,s[t+1]=r,s[t+2]=o,s[t+3]=a,s[t+4]=n,s[t+5]=r,s[t+6]=o,s[t+7]=a,s[t+8]=n,s[t+9]=r,s[t+10]=o,s[t+11]=a,s[t+12]=n,s[t+13]=r,s[t+14]=o,s[t+15]=a,s[t+16]=n,s[t+17]=r,s[t+18]=o,s[t+19]=a,s[t+20]=n,s[t+21]=r,s[t+22]=o,s[t+23]=a}this._changedBuffers[10]=!0}setOutlineArr(e,t){let i=6*e*this._maxLetters,s=this._outlineArr;for(let e=0;e<this._maxLetters;e++){let n=i+6*e;s[n]=t,s[n+1]=t,s[n+2]=t,s[n+3]=t,s[n+4]=t,s[n+5]=t}this._changedBuffers[9]=!0}setRotationArr(e,t){let i=6*e*this._maxLetters,s=this._rotationArr;for(let e=0;e<this._maxLetters;e++){let n=i+6*e;s[n]=t,s[n+1]=t,s[n+2]=t,s[n+3]=t,s[n+4]=t,s[n+5]=t}this._changedBuffers[5]=!0}setVisibility(e,t){let i;i=t?[0,0,0,-1,1,-1,1,-1,1,0,0,0]:[0,0,0,0,0,0,0,0,0,0,0,0],this.setVertexArr(e,i)}setVertexArr(e,t){let i=12*e*this._maxLetters,s=this._vertexArr;for(let e=0;e<this._maxLetters;e++){let n=i+12*e;s[n]=t[0],s[n+1]=t[1],s[n+2]=t[2],s[n+3]=t[3],s[n+4]=t[4],s[n+5]=t[5],s[n+6]=t[6],s[n+7]=t[7],s[n+8]=t[8],s[n+9]=t[9],s[n+10]=t[10],s[n+11]=t[11]}this._changedBuffers[7]=!0}setFontIndexArr(e,t){let i=6*e*this._maxLetters,s=this._fontIndexArr;for(let e=0;e<this._maxLetters;e++){let n=i+6*e;s[n]=t,s[n+1]=t,s[n+2]=t,s[n+3]=t,s[n+4]=t,s[n+5]=t}this._changedBuffers[8]=!0}createSizeBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._sizeBuffer),this._sizeBuffer=e.createArrayBuffer(this._sizeArr,1,this._sizeArr.length)}createFontIndexBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._fontIndexBuffer),this._fontIndexBuffer=e.createArrayBuffer(this._fontIndexArr,1,this._fontIndexArr.length)}createTexCoordBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._texCoordBuffer),this._texCoordBuffer=e.createArrayBuffer(this._texCoordArr,4,this._texCoordArr.length/4),e.gl.deleteBuffer(this._gliphParamBuffer),this._gliphParamBuffer=e.createArrayBuffer(this._gliphParamArr,4,this._gliphParamArr.length/4)}createOutlineBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._outlineBuffer),this._outlineBuffer=e.createArrayBuffer(this._outlineArr,1,this._outlineArr.length)}createOutlineColorBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._outlineColorBuffer),this._outlineColorBuffer=e.createArrayBuffer(this._outlineColorArr,4,this._outlineColorArr.length/4)}setMaxLetters(e){this._maxLetters=e}}class cs{constructor(e){this.pickingEnabled=!0,this.__id=cs.__counter__++,this.pickingEnabled=!0,this._entityCollection=e,this._renderer=null,this._pointClouds=[]}_initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.pointCloud||this._renderer.handler.addProgram(new Ni("pointCloud",{uniforms:{projectionViewMatrix:"mat4",opacity:"float",pointSize:"float"},attributes:{coordinates:"vec3",colors:"vec3"},vertexShader:"attribute vec3 coordinates;\n attribute vec4 colors;\n uniform mat4 projectionViewMatrix;\n uniform float opacity;\n uniform float pointSize;\n varying vec4 color;\n void main() {\n color = colors;\n color.a *= opacity;\n gl_Position = projectionViewMatrix * vec4(coordinates, 1.0);\n gl_PointSize = pointSize;\n }",fragmentShader:"precision highp float;\n varying vec4 color;\n void main(void) {\n gl_FragColor = color;\n }"})))}setRenderNode(e){this._renderer=e.renderer,this._initProgram();for(let t=0;t<this._pointClouds.length;t++)this._pointClouds[t].setRenderNode(e)}add(e){-1===e._handlerIndex&&(e._handler=this,e._handlerIndex=this._pointClouds.length,this._pointClouds.push(e),this._entityCollection&&this._entityCollection.renderNode&&e.setRenderNode(this._entityCollection.renderNode))}remove(e){let t=e._handlerIndex;-1!==t&&(e._deleteBuffers(),e._handlerIndex=-1,e._handler=null,this._pointClouds.splice(t,1),this._reindexPointCloudArray(t))}_reindexPointCloudArray(e){let t=this._pointClouds;for(let i=e;i<t.length;i++)t[i]._handlerIndex=i}draw(){let e=this._pointClouds.length;for(;e--;)this._pointClouds[e].draw()}drawPicking(){if(this.pickingEnabled){let e=this._pointClouds.length;for(;e--;)this._pointClouds[e].drawPicking()}}clear(){let e=this._pointClouds.length;for(;e--;)this._pointClouds[e]._deleteBuffers(),this._pointClouds[e]._handler=null,this._pointClouds[e]._handlerIndex=-1;this._pointClouds.length=0,this._pointClouds=[]}}cs.__counter__=0;const ds="\n float getLerpValue(in float min, in float max, in float between)\n {\n return (clamp(between, min, max) - min) / (max - min);\n }\n \n vec3 aces(vec3 color) \n {\n float a = 2.51;\n float b = 0.03;\n float c = 2.43;\n float d = 0.59;\n float e = 0.14;\n return clamp((color * (a * color + b)) / (color * (c * color + d ) + e), 0.0, 1.0);\n }\n \n bool intersectSphere(vec3 rayOrigin, vec3 rayDirection, float radius, inout float t1, inout float t2) \n {\n float b = dot(rayDirection, rayOrigin);\n float c = dot(rayOrigin, rayOrigin) - radius * radius;\n float d = b * b - c;\n if (d < 0.0) {\n return false;\n }\n t1 = -b - sqrt(d);\n t2 = -b + sqrt(d);\n return true;\n }\n \n bool intersectSphere(vec3 rayOrigin, vec3 rayDirection, float radius, inout float t) \n {\n float b = dot(rayDirection, rayOrigin);\n float c = dot(rayOrigin, rayOrigin) - radius * radius;\n float d = b * b - c;\n if (d < 0.0) {\n return false;\n }\n t = -b - sqrt(d);\n return true;\n }\n \n float intersectSphere( vec3 ro, vec3 rd, vec4 sph )\n {\n vec3 oc = ro - sph.xyz;\n float b = dot( oc, rd );\n float c = dot( oc, oc ) - sph.w*sph.w;\n float h = b*b - c;\n if( h<0.0 ) return -1.0;\n h = sqrt( h );\n return -b - h;\n }\n \n bool intersectEllipsoid( in vec3 ro, in vec3 rd, in vec3 ra, inout float t )\n {\n vec3 ocn = ro/ra;\n vec3 rdn = rd/ra;\n float a = dot( rdn, rdn );\n float b = dot( ocn, rdn );\n float c = dot( ocn, ocn );\n float h = b*b - a*(c-1.0);\n \n if (h < 0.0) \n { \n return false; \n }\n \n t = (-b-sqrt(h))/a;\n \n return true;\n }\n \n bool intersectEllipsoid( in vec3 ro, in vec3 rd, in vec3 ra, inout float t1, inout float t2)\n {\n vec3 ocn = ro/ra;\n vec3 rdn = rd/ra;\n float a = dot( rdn, rdn );\n float b = dot( ocn, rdn );\n float c = dot( ocn, ocn );\n float h = b*b - a*(c-1.0);\n \n if (h < 0.0) \n { \n return false; \n }\n \n h = sqrt(h);\n t1 = (-b-h)/a;\n t2 = (-b+h)/a;\n \n return true;\n }\n \n vec3 normalEllipsoid( in vec3 pos, in vec3 ra )\n {\n return normalize( pos/(ra*ra) );\n }\n";class _s{constructor(e){this.__id=_s.__counter__++,this._entityCollection=e,this._renderer=null,this._polylines=[],this.pickingEnabled=!0,this._relativeCenter=new oe,this._rtcEyePositionHigh=new Float32Array([0,0,0]),this._rtcEyePositionLow=new Float32Array([0,0,0])}_initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.polyline_screen||this._renderer.handler.addProgram(new Ni("polyline_screen",{uniforms:{viewport:"vec2",proj:"mat4",view:"mat4",rtcEyePositionHigh:"vec3",rtcEyePositionLow:"vec3",thickness:"float",opacity:"float",depthOffset:"float",visibleSphere:"vec4"},attributes:{prevHigh:"vec3",currentHigh:"vec3",nextHigh:"vec3",prevLow:"vec3",currentLow:"vec3",nextLow:"vec3",order:"float",color:"vec4"},vertexShader:"precision highp float;\n\n attribute vec3 prevHigh;\n attribute vec3 currentHigh;\n attribute vec3 nextHigh;\n\n attribute vec3 prevLow;\n attribute vec3 currentLow;\n attribute vec3 nextLow;\n\n attribute float order;\n\n attribute vec4 color;\n\n uniform float thickness;\n uniform mat4 proj;\n uniform mat4 view;\n uniform vec2 viewport;\n uniform vec3 rtcEyePositionHigh;\n uniform vec3 rtcEyePositionLow;\n uniform float opacity;\n uniform float depthOffset;\n \n\n varying vec4 vColor;\n varying vec3 vPos;\n varying vec3 uCamPos;\n\n const float NEAR = -1.0;\n\n vec2 getIntersection(vec2 start1, vec2 end1, vec2 start2, vec2 end2){\n vec2 dir = end2 - start2;\n vec2 perp = vec2(-dir.y, dir.x);\n float d2 = dot(perp, start2);\n float seg = dot(perp, start1) - d2;\n float prl = seg - dot(perp, end1) + d2;\n if(prl > -1.0 && prl < 1.0){\n return start1;\n }\n float u = seg / prl;\n return start1 + u * (end1 - start1);\n }\n\n vec2 project(vec4 p){\n return (0.5 * p.xyz / p.w + 0.5).xy * viewport;\n }\n\n void main(){\n\n uCamPos = rtcEyePositionHigh + rtcEyePositionLow;\n vPos = currentHigh + currentLow;\n \n vColor = vec4(color.rgb, color.a * opacity);\n\n mat4 viewMatrixRTE = view;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 highDiff, lowDiff;\n\n highDiff = currentHigh - rtcEyePositionHigh;\n highDiff = highDiff * step(1.0, length(highDiff));\n lowDiff = currentLow - rtcEyePositionLow; \n vec4 vCurrent = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n highDiff = prevHigh - rtcEyePositionHigh;\n highDiff = highDiff * step(1.0, length(highDiff));\n lowDiff = prevLow - rtcEyePositionLow;\n vec4 vPrev = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n highDiff = nextHigh - rtcEyePositionHigh;\n highDiff = highDiff * step(1.0, length(highDiff));\n lowDiff = nextLow - rtcEyePositionLow;\n vec4 vNext = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n /*Clip near plane, the point behind view plane*/\n if(vCurrent.z > NEAR) {\n if(vPrev.z < NEAR && abs(order) == 1.0){\n vCurrent = vPrev + (vCurrent - vPrev) * (NEAR - vPrev.z) / (vCurrent.z - vPrev.z);\n } else if(vNext.z < NEAR && abs(order) == 2.0){\n vCurrent = vNext + (vCurrent - vNext) * (NEAR - vNext.z) / (vCurrent.z - vNext.z);\n }\n }\n\n vec4 dCurrent = proj * vCurrent;\n vec2 _next = project(proj * vNext);\n vec2 _prev = project(proj * vPrev);\n vec2 _current = project(dCurrent);\n\n if(_prev == _current){\n if(_next == _current){\n _next = _current + vec2(1.0, 0.0);\n _prev = _current - _next;\n }else{\n _prev = _current + normalize(_current - _next);\n }\n }\n\n if(_next == _current){\n _next = _current + normalize(_current - _prev);\n }\n\n vec2 sNext = _next,\n sCurrent = _current,\n sPrev = _prev;\n\n vec2 dirNext = normalize(sNext - sCurrent);\n vec2 dirPrev = normalize(sPrev - sCurrent);\n float dotNP = dot(dirNext, dirPrev);\n\n vec2 normalNext = normalize(vec2(-dirNext.y, dirNext.x));\n vec2 normalPrev = normalize(vec2(dirPrev.y, -dirPrev.x));\n\n float d = thickness * sign(order);\n\n vec2 m;\n if(dotNP >= 0.99991){\n m = sCurrent - normalPrev * d;\n }else{\n m = getIntersection( sCurrent + normalPrev * d, sPrev + normalPrev * d,\n sCurrent + normalNext * d, sNext + normalNext * d );\n\n if( dotNP > 0.5 && dot(dirNext + dirPrev, m - sCurrent) < 0.0 ){\n float occw = order * sign(dirNext.x * dirPrev.y - dirNext.y * dirPrev.x);\n if(occw == -1.0){\n m = sCurrent + normalPrev * d;\n }else if(occw == 1.0){\n m = sCurrent + normalNext * d;\n }else if(occw == -2.0){\n m = sCurrent + normalNext * d;\n }else if(occw == 2.0){\n m = sCurrent + normalPrev * d;\n }\n }else if(distance(sCurrent, m) > min(distance(sCurrent, sNext), distance(sCurrent, sPrev))){\n m = sCurrent + normalNext * d;\n }\n }\n\n gl_Position = vec4((2.0 * m / viewport - 1.0) * dCurrent.w, dCurrent.z + depthOffset, dCurrent.w);\n }",fragmentShader:`precision highp float;\n \n uniform vec4 visibleSphere;\n \n varying vec3 uCamPos;\n varying vec4 vColor;\n varying vec3 vPos; \n \n ${ds}\n \n void main() {\n \n if(visibleSphere.w != 0.0) { \n vec3 cam_dir = normalize(vPos - uCamPos);\n vec3 sph_dir = normalize(vPos - visibleSphere.xyz);\n if( dot(cam_dir, sph_dir) > 0.11 ){\n discard;\n }\n }\n \n gl_FragColor = vec4(vColor.rgb, vColor.a);\n }`})),this._renderer.handler.programs.polyline_picking||this._renderer.handler.addProgram(new Ni("polyline_picking",{uniforms:{viewport:"vec2",proj:"mat4",view:"mat4",rtcEyePositionHigh:"vec3",rtcEyePositionLow:"vec3",color:"vec4",thickness:"float",depthOffset:"float",visibleSphere:"vec4"},attributes:{prevHigh:"vec3",currentHigh:"vec3",nextHigh:"vec3",prevLow:"vec3",currentLow:"vec3",nextLow:"vec3",order:"float"},vertexShader:"precision highp float;\n \n attribute vec3 prevHigh;\n attribute vec3 currentHigh;\n attribute vec3 nextHigh;\n \n attribute vec3 prevLow;\n attribute vec3 currentLow;\n attribute vec3 nextLow;\n\n attribute float order;\n\n uniform float thickness;\n uniform vec4 color;\n uniform mat4 proj;\n uniform mat4 view;\n uniform vec2 viewport;\n uniform vec3 rtcEyePositionHigh;\n uniform vec3 rtcEyePositionLow;\n uniform float depthOffset;\n\n varying vec4 vColor;\n varying vec3 vPos;\n varying vec3 uCamPos;\n \n \n const float NEAR = -1.0;\n \n vec2 getIntersection(vec2 start1, vec2 end1, vec2 start2, vec2 end2){\n vec2 dir = end2 - start2;\n vec2 perp = vec2(-dir.y, dir.x);\n float d2 = dot(perp, start2);\n float seg = dot(perp, start1) - d2;\n float prl = seg - dot(perp, end1) + d2;\n if(prl > -1.0 && prl < 1.0){\n return start1;\n }\n float u = seg / prl;\n return start1 + u * (end1 - start1);\n }\n \n vec2 project(vec4 p){\n return (0.5 * p.xyz / p.w + 0.5).xy * viewport;\n }\n \n void main(){\n\n uCamPos = rtcEyePositionHigh + rtcEyePositionLow;\n vPos = currentHigh + currentLow;\n vColor = color; \n\n vec3 highDiff, lowDiff;\n\n mat4 viewMatrixRTE = view;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n \n highDiff = currentHigh - rtcEyePositionHigh;\n highDiff = highDiff * step(1.0, length(highDiff));\n lowDiff = currentLow - rtcEyePositionLow;\n vec4 vCurrent = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n highDiff = prevHigh - rtcEyePositionHigh;\n highDiff = highDiff * step(1.0, length(highDiff));\n lowDiff = prevLow - rtcEyePositionLow; \n vec4 vPrev = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n highDiff = nextHigh - rtcEyePositionHigh;\n highDiff = highDiff * step(1.0, length(highDiff));\n lowDiff = nextLow - rtcEyePositionLow; \n vec4 vNext = viewMatrixRTE * vec4(highDiff + lowDiff, 1.0);\n\n /*Clip near plane*/\n if(vCurrent.z > NEAR) {\n if(vPrev.z < NEAR && abs(order) == 1.0){\n vCurrent = vPrev + (vCurrent - vPrev) * (NEAR - vPrev.z) / (vCurrent.z - vPrev.z);\n } else if(vNext.z < NEAR && abs(order) == 2.0){\n vCurrent = vNext + (vCurrent - vNext) * (NEAR - vNext.z) / (vCurrent.z - vNext.z);\n }\n }\n \n vec4 dCurrent = proj * vCurrent;\n vec2 _next = project(proj * vNext);\n vec2 _prev = project(proj * vPrev);\n vec2 _current = project(dCurrent);\n if(_prev == _current){\n if(_next == _current){\n _next = _current + vec2(1.0, 0.0);\n _prev = _current - _next;\n }else{\n _prev = _current + normalize(_current - _next);\n }\n }\n if(_next == _current){\n _next = _current + normalize(_current - _prev);\n }\n \n vec2 sNext = _next,\n sCurrent = _current,\n sPrev = _prev;\n\n vec2 dirNext = normalize(sNext - sCurrent);\n vec2 dirPrev = normalize(sPrev - sCurrent);\n float dotNP = dot(dirNext, dirPrev);\n \n vec2 normalNext = normalize(vec2(-dirNext.y, dirNext.x));\n vec2 normalPrev = normalize(vec2(dirPrev.y, -dirPrev.x));\n \n float d = thickness * sign(order);\n \n vec2 m;\n if(dotNP >= 0.99991){\n m = sCurrent - normalPrev * d;\n }else{\n m = getIntersection( sCurrent + normalPrev * d, sPrev + normalPrev * d,\n sCurrent + normalNext * d, sNext + normalNext * d );\n \n if( dotNP > 0.5 && dot(dirNext + dirPrev, m - sCurrent) < 0.0 ){\n float occw = order * sign(dirNext.x * dirPrev.y - dirNext.y * dirPrev.x);\n if(occw == -1.0){\n m = sCurrent + normalPrev * d;\n }else if(occw == 1.0){\n m = sCurrent + normalNext * d;\n }else if(occw == -2.0){\n m = sCurrent + normalNext * d;\n }else if(occw == 2.0){\n m = sCurrent + normalPrev * d;\n }\n }\n else if(distance(sCurrent, m) > min(distance(sCurrent, sNext), distance(sCurrent, sPrev))){\n m = sCurrent + normalNext * d;\n }\n }\n gl_Position = vec4((2.0 * m / viewport - 1.0) * dCurrent.w, dCurrent.z + depthOffset, dCurrent.w);\n }",fragmentShader:"precision highp float;\n \n uniform vec4 visibleSphere;\n \n varying vec3 uCamPos;\n varying vec4 vColor;\n varying vec3 vPos;\n \n void main() {\n if(visibleSphere.w != 0.0) { \n vec3 cam_dir = normalize(vPos - uCamPos);\n vec3 sph_dir = normalize(vPos - visibleSphere.xyz);\n if( dot(cam_dir, sph_dir) > 0.11 ){\n discard;\n }\n } \n gl_FragColor = vec4(vColor.rgb, vColor.a);\n }"})))}setRenderNode(e){this._renderer=e.renderer,this._initProgram();for(let t=0;t<this._polylines.length;t++)this._polylines[t].setRenderNode(e)}add(e){-1===e._handlerIndex&&(e._handler=this,e._handlerIndex=this._polylines.length,e.__doubleToTwoFloats=this.getRTCPosition.bind(this),this._polylines.push(e),this._entityCollection&&this._entityCollection.renderNode&&(e.setRenderNode(this._entityCollection.renderNode),e.updateRTCPosition()))}remove(e){let t=e._handlerIndex;-1!==t&&(e._deleteBuffers(),e._handlerIndex=-1,e._handler=null,this._polylines.splice(t,1),this.reindexPolylineArray(t))}reindexPolylineArray(e){let t=this._polylines;for(let i=e;i<t.length;i++)t[i]._handlerIndex=i}draw(){this._updateRTCEyePosition();let e=this._polylines.length;for(;e--;)this._polylines[e].draw()}drawPicking(){if(this.pickingEnabled){let e=this._polylines.length;for(;e--;)this._polylines[e].drawPicking()}}clear(){let e=this._polylines.length;for(;e--;)this._polylines[e]._deleteBuffers(),this._polylines[e]._handler=null,this._polylines[e]._handlerIndex=-1;this._polylines.length=0,this._polylines=[]}getRTCPosition(e,t,i){let s=e.sub(this._relativeCenter);oe.doubleToTwoFloats(s,t,i)}setRelativeCenter(e){this._relativeCenter.copy(e);for(let e=0;e<this._polylines.length;e++)this._polylines[e].updateRTCPosition()}_updateRTCEyePosition(){let e=this._renderer;if(e.activeCamera.isFirstPass){let t=e.activeCamera.eye.sub(this._relativeCenter);oe.doubleToTwoFloat32Array(t,this._rtcEyePositionHigh,this._rtcEyePositionLow)}}}_s.__counter__=0;class us{constructor(e){this.__id=us.__counter__++,this.pickingEnabled=!0,this._entityCollection=e,this._renderer=null,this._rays=[],this._vertexBuffer=null,this._startPositionHighBuffer=null,this._startPositionLowBuffer=null,this._endPositionHighBuffer=null,this._endPositionLowBuffer=null,this._thicknessBuffer=null,this._rgbaBuffer=null,this._pickingColorBuffer=null,this._vertexArr=[],this._startPositionHighArr=[],this._startPositionLowArr=[],this._endPositionHighArr=[],this._endPositionLowArr=[],this._thicknessArr=[],this._rgbaArr=[],this._pickingColorArr=[],this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[5]=this.createVertexBuffer,this._buffersUpdateCallbacks[1]=this.createStartPositionBuffer,this._buffersUpdateCallbacks[2]=this.createEndPositionBuffer,this._buffersUpdateCallbacks[4]=this.createThicknessBuffer,this._buffersUpdateCallbacks[3]=this.createRgbaBuffer,this._buffersUpdateCallbacks[0]=this.createPickingColorBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length)}static concArr(e,t){for(let i=0;i<t.length;i++)e.push(t[i])}initProgram(){this._renderer&&this._renderer.handler&&(this._renderer.handler.programs.rayScreen||this._renderer.handler.addProgram(new Ni("rayScreen",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",resolution:"float",uOpacity:"float"},attributes:{a_vertices:"vec2",a_startPosHigh:"vec3",a_startPosLow:"vec3",a_endPosHigh:"vec3",a_endPosLow:"vec3",a_thickness:"float",a_rgba:"vec4"},vertexShader:"precision highp float;\n\n attribute vec4 a_rgba;\n attribute vec3 a_startPosHigh;\n attribute vec3 a_startPosLow;\n attribute vec3 a_endPosHigh;\n attribute vec3 a_endPosLow;\n attribute vec2 a_vertices;\n attribute float a_thickness;\n\n varying vec4 v_rgba;\n\n uniform mat4 viewMatrix;\n uniform mat4 projectionMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float resolution;\n uniform float uOpacity;\n\n void main() {\n\n v_rgba = vec4(a_rgba.rgb, a_rgba.a * uOpacity);\n\n vec3 v = (a_endPosHigh - a_startPosHigh) + (a_endPosLow - a_startPosLow);\n\n vec3 look = (a_startPosHigh - eyePositionHigh) + (a_startPosLow - eyePositionLow) + v * a_vertices.y;\n vec3 up = normalize(normalize(v));\n vec3 right = normalize(cross(look,up));\n \n float dist = dot(look, vec3(viewMatrix[0][2], viewMatrix[1][2], viewMatrix[2][2]));\n float focalSize = 2.0 * dist * resolution;\n vec3 vert = right * a_thickness * focalSize * a_vertices.x;\n\n vec3 highDiff;\n if(a_vertices.y == 0.0){\n highDiff = a_startPosHigh - eyePositionHigh;\n vert += a_startPosLow - eyePositionLow;\n }else{\n highDiff = a_endPosHigh - eyePositionHigh;\n vert += a_endPosLow - eyePositionLow;\n }\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n \n // Hack for iMac M1, looks like it doesnt \n // work correctly with zeroes in highDiff\n // if(length(highDiff) < 1.0){\n // highDiff = vec3(0.0);\n // }\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + vert, 1.0);\n }",fragmentShader:"precision highp float;\n varying vec4 v_rgba;\n void main () {\n gl_FragColor = v_rgba;\n }"})))}setRenderer(e){this._renderer=e,this.initProgram()}refresh(){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]=!0}_removeRays(){let e=this._rays.length;for(;e--;){let t=this._rays[e];t._handlerIndex=-1,t._handler=null}this._rays.length=0,this._rays=[]}clear(){this._vertexArr=null,this._startPositionHighArr=null,this._startPositionLowArr=null,this._endPositionHighArr=null,this._endPositionLowArr=null,this._thicknessArr=null,this._rgbaArr=null,this._vertexArr=new Float32Array([]),this._startPositionHighArr=new Float32Array([]),this._startPositionLowArr=new Float32Array([]),this._endPositionHighArr=new Float32Array([]),this._endPositionLowArr=new Float32Array([]),this._thicknessArr=new Float32Array([]),this._rgbaArr=new Float32Array([]),this._removeRays(),this._deleteBuffers(),this.refresh()}_deleteBuffers(){if(this._renderer){let e=this._renderer.handler.gl;e&&(e.deleteBuffer(this._startPositionHighBuffer),e.deleteBuffer(this._startPositionLowBuffer),e.deleteBuffer(this._endPositionHighBuffer),e.deleteBuffer(this._endPositionLowBuffer),e.deleteBuffer(this._thicknessBuffer),e.deleteBuffer(this._rgbaBuffer),e.deleteBuffer(this._vertexBuffer)),this._startPositionHighBuffer=null,this._startPositionLowBuffer=null,this._endPositionHighBuffer=null,this._endPositionLowBuffer=null,this._thicknessBuffer=null,this._rgbaBuffer=null,this._vertexBuffer=null}}update(){if(this._renderer){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]&&(this._buffersUpdateCallbacks[e].call(this),this._changedBuffers[e]=!1)}}add(e){-1==e._handlerIndex&&(e._handler=this,e._handlerIndex=this._rays.length,this._rays.push(e),this._addRayToArrays(e),this.refresh())}_addRayToArrays(e){e.getVisibility()?this._vertexArr=Oe(this._vertexArr,[-.5,1,-.5,0,.5,0,.5,0,.5,1,-.5,1]):this._vertexArr=Oe(this._vertexArr,[0,0,0,0,0,0,0,0,0,0,0,0]);let t=e._startPositionHigh.x,i=e._startPositionHigh.y,s=e._startPositionHigh.z;this._startPositionHighArr=Oe(this._startPositionHighArr,[t,i,s,t,i,s,t,i,s,t,i,s,t,i,s,t,i,s]),t=e._startPositionLow.x,i=e._startPositionLow.y,s=e._startPositionLow.z,this._startPositionLowArr=Oe(this._startPositionLowArr,[t,i,s,t,i,s,t,i,s,t,i,s,t,i,s,t,i,s]),t=e._endPositionHigh.x,i=e._endPositionHigh.y,s=e._endPositionHigh.z,this._endPositionHighArr=Oe(this._endPositionHighArr,[t,i,s,t,i,s,t,i,s,t,i,s,t,i,s,t,i,s]),t=e._endPositionLow.x,i=e._endPositionLow.y,s=e._endPositionLow.z,this._endPositionLowArr=Oe(this._endPositionLowArr,[t,i,s,t,i,s,t,i,s,t,i,s,t,i,s,t,i,s]),t=e._thickness,this._thicknessArr=Oe(this._thicknessArr,[t,t,t,t,t,t]);let n=e._startColor.x,r=e._startColor.y,o=e._startColor.z,a=e._startColor.w,l=e._endColor.x,h=e._endColor.y,c=e._endColor.z,d=e._endColor.w;this._rgbaArr=Oe(this._rgbaArr,[l,h,c,d,n,r,o,a,n,r,o,a,n,r,o,a,l,h,c,d,l,h,c,d]),t=e._entity._pickingColor.x/255,i=e._entity._pickingColor.y/255,s=e._entity._pickingColor.z/255,this._pickingColorArr=Oe(this._pickingColorArr,[t,i,s,t,i,s,t,i,s,t,i,s,t,i,s,t,i,s])}_displayPASS(){let e=this._renderer,t=e.handler;t.programs.rayScreen.activate();let i=t.programs.rayScreen._program,s=i.attributes,n=i.uniforms,r=t.gl,o=this._entityCollection;r.disable(r.CULL_FACE),r.uniform1f(n.uOpacity,o._fadingOpacity),r.uniformMatrix4fv(n.viewMatrix,!1,e.activeCamera.getViewMatrix()),r.uniformMatrix4fv(n.projectionMatrix,!1,e.activeCamera.getProjectionMatrix()),r.uniform3fv(n.eyePositionHigh,e.activeCamera.eyeHigh),r.uniform3fv(n.eyePositionLow,e.activeCamera.eyeLow),r.uniform1f(n.resolution,e.activeCamera._tanViewAngle_hradOneByHeight),r.bindBuffer(r.ARRAY_BUFFER,this._startPositionHighBuffer),r.vertexAttribPointer(s.a_startPosHigh,this._startPositionHighBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._startPositionLowBuffer),r.vertexAttribPointer(s.a_startPosLow,this._startPositionLowBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._endPositionHighBuffer),r.vertexAttribPointer(s.a_endPosHigh,this._endPositionHighBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._endPositionLowBuffer),r.vertexAttribPointer(s.a_endPosLow,this._endPositionLowBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._rgbaBuffer),r.vertexAttribPointer(s.a_rgba,this._rgbaBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._thicknessBuffer),r.vertexAttribPointer(s.a_thickness,this._thicknessBuffer.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this._vertexBuffer),r.vertexAttribPointer(s.a_vertices,this._vertexBuffer.itemSize,r.FLOAT,!1,0,0),r.drawArrays(r.TRIANGLES,0,this._vertexBuffer.numItems),r.enable(r.CULL_FACE)}_pickingPASS(){}draw(){this._rays.length&&(this.update(),this._displayPASS())}drawPicking(){this._rays.length&&this.pickingEnabled&&this._pickingPASS()}reindexRaysArray(e){let t=this._rays;for(let i=e;i<t.length;i++)t[i]._handlerIndex=i}_removeRay(e){let t=e._handlerIndex;this._rays.splice(t,1);let i=24*t;this._rgbaArr=Ge(this._rgbaArr,i,24),i=18*t,this._startPositionHighArr=Ge(this._startPositionHighArr,i,18),this._startPositionLowArr=Ge(this._startPositionLowArr,i,18),this._endPositionHighArr=Ge(this._endPositionHighArr,i,18),this._endPositionLowArr=Ge(this._endPositionLowArr,i,18),this._pickingColorArr=Ge(this._pickingColorArr,i,18),i=12*t,this._vertexArr=Ge(this._vertexArr,i,12),i=6*t,this._thicknessArr=Ge(this._thicknessArr,i,6),this.reindexRaysArray(t),this.refresh(),e._handlerIndex=-1,e._handler=null}remove(e){e._handler&&this.__id===e._handler.__id&&this._removeRay(e)}setStartPositionArr(e,t,i){let s=18*e,n=this._startPositionHighArr,r=t.x,o=t.y,a=t.z;n[s]=r,n[s+1]=o,n[s+2]=a,n[s+3]=r,n[s+4]=o,n[s+5]=a,n[s+6]=r,n[s+7]=o,n[s+8]=a,n[s+9]=r,n[s+10]=o,n[s+11]=a,n[s+12]=r,n[s+13]=o,n[s+14]=a,n[s+15]=r,n[s+16]=o,n[s+17]=a,n=this._startPositionLowArr,r=i.x,o=i.y,a=i.z,n[s]=r,n[s+1]=o,n[s+2]=a,n[s+3]=r,n[s+4]=o,n[s+5]=a,n[s+6]=r,n[s+7]=o,n[s+8]=a,n[s+9]=r,n[s+10]=o,n[s+11]=a,n[s+12]=r,n[s+13]=o,n[s+14]=a,n[s+15]=r,n[s+16]=o,n[s+17]=a,this._changedBuffers[1]=!0}setEndPositionArr(e,t,i){let s=18*e,n=this._endPositionHighArr,r=t.x,o=t.y,a=t.z;n[s]=r,n[s+1]=o,n[s+2]=a,n[s+3]=r,n[s+4]=o,n[s+5]=a,n[s+6]=r,n[s+7]=o,n[s+8]=a,n[s+9]=r,n[s+10]=o,n[s+11]=a,n[s+12]=r,n[s+13]=o,n[s+14]=a,n[s+15]=r,n[s+16]=o,n[s+17]=a,n=this._endPositionLowArr,r=i.x,o=i.y,a=i.z,n[s]=r,n[s+1]=o,n[s+2]=a,n[s+3]=r,n[s+4]=o,n[s+5]=a,n[s+6]=r,n[s+7]=o,n[s+8]=a,n[s+9]=r,n[s+10]=o,n[s+11]=a,n[s+12]=r,n[s+13]=o,n[s+14]=a,n[s+15]=r,n[s+16]=o,n[s+17]=a,this._changedBuffers[2]=!0}setPickingColorArr(e,t){let i=18*e,s=this._pickingColorArr,n=t.x/255,r=t.y/255,o=t.z/255;s[i]=n,s[i+1]=r,s[i+2]=o,s[i+3]=n,s[i+4]=r,s[i+5]=o,s[i+6]=n,s[i+7]=r,s[i+8]=o,s[i+9]=n,s[i+10]=r,s[i+11]=o,s[i+12]=n,s[i+13]=r,s[i+14]=o,s[i+15]=n,s[i+16]=r,s[i+17]=o,this._changedBuffers[0]=!0}setRgbaArr(e,t,i){let s=24*e,n=this._rgbaArr,r=t.x,o=t.y,a=t.z,l=t.w,h=i.x,c=i.y,d=i.z,_=i.w;n[s]=h,n[s+1]=c,n[s+2]=d,n[s+3]=_,n[s+4]=r,n[s+5]=o,n[s+6]=a,n[s+7]=l,n[s+8]=r,n[s+9]=o,n[s+10]=a,n[s+11]=l,n[s+12]=r,n[s+13]=o,n[s+14]=a,n[s+15]=l,n[s+16]=h,n[s+17]=c,n[s+18]=d,n[s+19]=_,n[s+20]=h,n[s+21]=c,n[s+22]=d,n[s+23]=_,this._changedBuffers[3]=!0}setThicknessArr(e,t){let i=6*e,s=this._thicknessArr;s[i]=t,s[i+1]=t,s[i+2]=t,s[i+3]=t,s[i+4]=t,s[i+5]=t,this._changedBuffers[4]=!0}setVisibility(e,t){let i;i=t?[-.5,1,-.5,0,.5,0,.5,0,.5,1,-.5,1]:[0,0,0,0,0,0,0,0,0,0,0,0],this.setVertexArr(e,i)}setVertexArr(e,t){let i=12*e,s=this._vertexArr;s[i]=t[0],s[i+1]=t[1],s[i+2]=t[2],s[i+3]=t[3],s[i+4]=t[4],s[i+5]=t[5],s[i+6]=t[6],s[i+7]=t[7],s[i+8]=t[8],s[i+9]=t[9],s[i+10]=t[10],s[i+11]=t[11],this._changedBuffers[5]=!0}createStartPositionBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._startPositionHighBuffer),this._startPositionHighArr=Ve(this._startPositionHighArr),this._startPositionHighBuffer=e.createArrayBuffer(this._startPositionHighArr,3,this._startPositionHighArr.length/3,e.gl.DYNAMIC_DRAW),e.gl.deleteBuffer(this._startPositionLowBuffer),this._startPositionLowArr=Ve(this._startPositionLowArr),this._startPositionLowBuffer=e.createArrayBuffer(this._startPositionLowArr,3,this._startPositionLowArr.length/3,e.gl.DYNAMIC_DRAW)}createEndPositionBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._endPositionHighBuffer),this._endPositionHighArr=Ve(this._endPositionHighArr),this._endPositionHighBuffer=e.createArrayBuffer(this._endPositionHighArr,3,this._endPositionHighArr.length/3,e.gl.DYNAMIC_DRAW),e.gl.deleteBuffer(this._endPositionLowBuffer),this._endPositionLowArr=Ve(this._endPositionLowArr),this._endPositionLowBuffer=e.createArrayBuffer(this._endPositionLowArr,3,this._endPositionLowArr.length/3,e.gl.DYNAMIC_DRAW)}createRgbaBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._rgbaBuffer),this._rgbaArr=Ve(this._rgbaArr),this._rgbaBuffer=e.createArrayBuffer(this._rgbaArr,4,this._rgbaArr.length/4)}createThicknessBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._thicknessBuffer),this._thicknessArr=Ve(this._thicknessArr),this._thicknessBuffer=e.createArrayBuffer(this._thicknessArr,1,this._thicknessArr.length,e.gl.DYNAMIC_DRAW)}createVertexBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._vertexBuffer),this._vertexArr=Ve(this._vertexArr),this._vertexBuffer=e.createArrayBuffer(this._vertexArr,2,this._vertexArr.length/2,e.gl.DYNAMIC_DRAW)}createPickingColorBuffer(){let e=this._renderer.handler;e.gl.deleteBuffer(this._pickingColorBuffer),this._pickingColorArr=Ve(this._pickingColorArr),this._pickingColorBuffer=e.createArrayBuffer(this._pickingColorArr,3,this._pickingColorArr.length/3)}}us.__counter__=0;class gs{constructor(e){this.__id=gs.__counter__++,this.pickingEnabled=!0,this._entityCollection=e,this._renderer=null,this._strips=[]}_initProgram(){this._renderer&&this._renderer.handler&&!this._renderer.handler.programs.strip&&this._renderer.handler.addProgram(new Ni("strip",{uniforms:{projectionMatrix:{type:"mat4"},viewMatrix:{type:"mat4"},eyePositionHigh:"vec3",eyePositionLow:"vec3",uColor:{type:"vec4"},uOpacity:{type:"float"}},attributes:{aVertexPositionHigh:{type:"vec3"},aVertexPositionLow:{type:"vec3"}},vertexShader:"attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n void main(void) {\n\n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:"precision highp float;\n uniform vec4 uColor;\n uniform float uOpacity;\n void main(void) {\n gl_FragColor = vec4(uColor.rgb, uColor.a * uOpacity);\n }"}))}setRenderNode(e){this._renderer=e.renderer,this._initProgram();for(let t=0;t<this._strips.length;t++)this._strips[t].setRenderNode(e)}add(e){-1===e._handlerIndex&&(e._handler=this,e._handlerIndex=this._strips.length,this._strips.push(e),this._entityCollection&&this._entityCollection.renderNode&&e.setRenderNode(this._entityCollection.renderNode))}remove(e){let t=e._handlerIndex;-1!==t&&(e._deleteBuffers(),e._handlerIndex=-1,e._handler=null,this._strips.splice(t,1),this.reindexStripArray(t))}reindexStripArray(e){let t=this._strips;for(let i=e;i<t.length;i++)t[i]._handlerIndex=i}draw(){let e=this._strips.length;for(;e--;)this._strips[e].draw()}drawPicking(){if(this.pickingEnabled){let e=this._strips.length;for(;e--;)this._strips[e].drawPicking()}}clear(){let e=this._strips.length;for(;e--;)this._strips[e]._deleteBuffers(),this._strips[e]._handler=null,this._strips[e]._handlerIndex=-1;this._strips.length=0,this._strips=[]}}gs.__counter__=0;class fs{constructor(e={}){this._onChangeRelativeCenter=e=>{this.geoObjectHandler.setRelativeCenter(e),this.polylineHandler.setRelativeCenter(e)},this.__id=fs.__counter__++,this.renderNode=null,this._visibility=null==e.visibility||e.visibility,this.polygonOffsetUnits=null!=e.polygonOffsetUnits?e.polygonOffsetUnits:0,this.billboardHandler=new Ui(this),this.labelHandler=new hs(this,e.labelMaxLetters),this.polylineHandler=new _s(this),this.rayHandler=new us(this),this.pointCloudHandler=new cs(this),this.stripHandler=new gs(this),this.geoObjectHandler=new ns(this),null!=e.pickingEnabled&&this.setPickingEnabled(e.pickingEnabled),this._entities=[],this.scaleByDistance=e.scaleByDistance||[1,1,1];let t=new Float32Array([1,1,1]);void 0!==e.pickingScale&&(e.pickingScale instanceof Array?(t[0]=e.pickingScale[0]||t[0],t[1]=e.pickingScale[1]||t[1],t[2]=e.pickingScale[2]||t[2]):"number"==typeof e.pickingScale&&(t[0]=e.pickingScale,t[1]=e.pickingScale,t[2]=e.pickingScale)),this._depthOrder=e.depthOrder||0,this.pickingScale=t,this._opacity=null==e.opacity?1:e.opacity,this._fadingOpacity=this._opacity,this.events=this.rendererEvents=Mt(ps,this),this._useLighting=null!=e.useLighting?e.useLighting?1:0:1,e.entities&&this.addEntities(e.entities)}get depthOrder(){return this._depthOrder}set depthOrder(e){this._depthOrder=e,this.renderNode&&this.renderNode.updateEntityCollectionsDepthOrder()}isEmpty(){return 0==this._entities.length}get id(){return this.__id}get useLighting(){return Boolean(this._useLighting)}set useLighting(e){this._useLighting=Number(e)}isEqual(e){return null!==e&&this.__id===e.__id}setVisibility(e){this._visibility=e,this._fadingOpacity=this._opacity*(e?1:0),this.renderNode?.updateEntityCollectionsDepthOrder(),this.events.dispatch(this.events.visibilitychange,this)}getVisibility(){return this._visibility}setOpacity(e){this._opacity=e}setPickingEnabled(e){this.billboardHandler.pickingEnabled=e,this.labelHandler.pickingEnabled=e,this.polylineHandler.pickingEnabled=e,this.rayHandler.pickingEnabled=e,this.pointCloudHandler.pickingEnabled=e,this.stripHandler.pickingEnabled=e,this.geoObjectHandler.pickingEnabled=e}getOpacity(){return this._opacity}setScaleByDistance(e,t,i){this.scaleByDistance[0]=e,this.scaleByDistance[1]=t,this.scaleByDistance[2]=i||r}appendChildEntity(e){this._addRecursively(e)}_addRecursively(e){let t=this.renderNode;t&&(e._independentPicking||!e.parent?t&&t.renderer&&t.renderer.assignPickingColor(e):e._pickingColor=e.parent._pickingColor,t.renderer&&t.renderer.assignPickingColor(e),t.ellipsoid&&e._cartesian.isZero()&&e.setCartesian3v(t.ellipsoid.lonLatToCartesian(e._lonLat))),e.setPickingColor(),e._updateAbsolutePosition(),e.setScale3v(e.getScale()),e.billboard&&this.billboardHandler.add(e.billboard),e.label&&this.labelHandler.add(e.label),e.polyline&&this.polylineHandler.add(e.polyline),e.ray&&this.rayHandler.add(e.ray),e.pointCloud&&this.pointCloudHandler.add(e.pointCloud),e.strip&&this.stripHandler.add(e.strip),e.geoObject&&this.geoObjectHandler.add(e.geoObject),this.events.dispatch(this.events.entityadd,e);for(let t=0;t<e.childEntities.length;t++)e.childEntities[t]._entityCollection=this,e.childEntities[t]._entityCollectionIndex=e._entityCollectionIndex,this._addRecursively(e.childEntities[t])}add(e){return e._entityCollection||(e._entityCollection=this,e._entityCollectionIndex=this._entities.length,this._entities.push(e),this._addRecursively(e)),this}addEntities(e){for(let t=0,i=e.length;t<i;t++)this.add(e[t]);return this}belongs(e){return this.isEqual(e._entityCollection)}_removeRecursively(e){e._entityCollection=null,e._entityCollectionIndex=-1,e.billboard&&this.billboardHandler.remove(e.billboard),e.label&&this.labelHandler.remove(e.label),e.polyline&&this.polylineHandler.remove(e.polyline),e.ray&&this.rayHandler.remove(e.ray),e.pointCloud&&this.pointCloudHandler.remove(e.pointCloud),e.strip&&this.stripHandler.remove(e.strip),e.geoObject&&this.geoObjectHandler.remove(e.geoObject);for(let t=0;t<e.childEntities.length;t++)this._removeRecursively(e.childEntities[t])}removeEntity(e){this._entities.splice(e._entityCollectionIndex,1),this.reindexEntitiesArray(e._entityCollectionIndex),this.renderNode&&this.renderNode.renderer&&(this.renderNode.renderer.clearPickingColor(e),e._pickingColor.clear()),this.belongs(e)&&this._removeRecursively(e),this.events.dispatch(this.events.entityremove,e)}_removeEntitySilent(e){this._entities.splice(e._entityCollectionIndex,1),this.reindexEntitiesArray(e._entityCollectionIndex),this.renderNode&&this.renderNode.renderer&&(this.renderNode.renderer.clearPickingColor(e),e._pickingColor.clear()),this.belongs(e)&&this._removeRecursively(e)}createPickingColors(){if(!this.renderNode||!this.renderNode.renderer)return;let e=this._entities;for(let t=0;t<e.length;t++)e[t].parent||(this.renderNode.renderer.assignPickingColor(e[t]),e[t].setPickingColor())}reindexEntitiesArray(e){let t=this._entities;for(let i=e;i<t.length;i++)t[i]._entityCollectionIndex=i}addTo(e,t=!1){return this.renderNode||e.addEntityCollection(this,t),this}bindRenderNode(e){e.renderer&&e.renderer.isInitialized()&&(this.billboardHandler.setRenderer(e.renderer),this.labelHandler.setRenderer(e.renderer),this.rayHandler.setRenderer(e.renderer),this.geoObjectHandler.setRenderNode(e),this.polylineHandler.setRenderNode(e),this.pointCloudHandler.setRenderNode(e),this.stripHandler.setRenderNode(e),e.renderer.events.on("changerelativecenter",this._onChangeRelativeCenter),this.updateBillboardsTextureAtlas(),this.updateLabelsFontAtlas(),this.createPickingColors())}_updateGeodeticCoordinates(e){let t=this._entities,i=t.length;for(;i--;){let s=t[i];s._lonLat&&s.setCartesian3v(e.lonLatToCartesian(s._lonLat))}}updateBillboardsTextureAtlas(){let e=this.billboardHandler.billboards;for(let t=0;t<e.length;t++)e[t].setSrc(e[t].getSrc())}updateLabelsFontAtlas(){this.renderNode&&this.labelHandler.updateFonts()}remove(){this.renderNode&&(this.renderNode.removeEntityCollection(this),this.renderNode.renderer?.events.off("changerelativecenter",this._onChangeRelativeCenter),this.renderNode=null,this.events.dispatch(this.events.remove,this))}getEntities(){return[].concat(this._entities)}each(e){let t=this._entities.length;for(;t--;){let i=this._entities[t];i&&e(i)}}clear(){this.billboardHandler.clear(),this.labelHandler.clear(),this.polylineHandler.clear(),this.rayHandler.clear(),this.pointCloudHandler.clear(),this.stripHandler.clear(),this.geoObjectHandler.clear();let e=this._entities.length;for(;e--;){let t=this._entities[e];this.renderNode&&this.renderNode.renderer&&(this.renderNode.renderer.clearPickingColor(t),t._pickingColor.clear()),this._clearEntity(t)}this._entities.length=0,this._entities=[]}_clearEntity(e){e._entityCollection=null,e._entityCollectionIndex=-1;for(let t=0;t<e.childEntities.length;t++)this._clearEntity(e.childEntities[t])}}fs.__counter__=0;const ps=["draw","drawend","add","remove","entityadd","entityremove","visibilitychange","mousemove","mouseenter","mouseleave","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchmove","touchstart","touchend","doubletouch","touchleave","touchenter"];function ms(e,t){if(e>=0){let i=65536*Math.floor(e/65536);t[0]=Math.fround(i),t[1]=Math.fround(e-i)}else{let i=65536*Math.floor(-e/65536);t[0]=Math.fround(-i),t[1]=Math.fround(e+i)}return t}function vs(e,t){if(e>=0){let i=65536*Math.floor(e/65536);t.x=Math.fround(i),t.y=Math.fround(e-i)}else{let i=65536*Math.floor(-e/65536);t.x=Math.fround(-i),t.y=Math.fround(e+i)}return t}function ys(e,t,i){i=i||2;var s,n,r,o,a,l,h,c=t&&t.length,d=c?t[0]*i:e.length,_=xs(e,0,d,i,!0),u=[];if(!_)return u;if(c&&(_=function(e,t,i,s){var n,r,o,a=[];for(n=0,r=t.length;n<r;n++)(o=xs(e,t[n]*s,n<r-1?t[n+1]*s:e.length,s,!1))===o.next&&(o.steiner=!0),a.push(Ms(o));for(a.sort(As),n=0;n<a.length;n++)Ps(a[n],i),i=bs(i,i.next);return i}(e,t,_,i)),e.length>80*i){s=r=e[0],n=o=e[1];for(let t=i;t<d;t+=i)(a=e[t])<s&&(s=a),(l=e[t+1])<n&&(n=l),a>r&&(r=a),l>o&&(o=l);h=Math.max(r-s,o-n)}return ws(_,u,i,s,n,h),u}function xs(e,t,i,s,n){var r,o;if(n===function(e,t,i,s){var n=0;for(let r=t,o=i-s;r<i;r+=s)n+=(e[o]-e[r])*(e[r+1]+e[o+1]),o=r;return n}(e,t,i,s)>0)for(r=t;r<i;r+=s)o=Ns(r,e[r],e[r+1],o);else for(r=i-s;r>=t;r-=s)o=Ns(r,e[r],e[r+1],o);return o&&Is(o,o.next)&&(Hs(o),o=o.next),o}function bs(e,t){if(!e)return e;t||(t=e);var i,s=e;do{if(i=!1,s.steiner||!Is(s,s.next)&&0!==ks(s.prev,s,s.next))s=s.next;else{if(Hs(s),(s=t=s.prev)===s.next)return null;i=!0}}while(i||s!==t);return t}function ws(e,t,i,s,n,r,o){if(e){!o&&r&&function(e,t,i,s){var n=e;do{null===n.z&&(n.z=Ss(n.x,n.y,t,i,s)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next}while(n!==e);n.prevZ.nextZ=null,n.prevZ=null,function(e){var t,i,s,n,r,o,a,l,h=1;do{for(i=e,e=null,r=null,o=0;i;){for(o++,s=i,a=0,t=0;t<h&&(a++,s=s.nextZ);t++);for(l=h;a>0||l>0&&s;)0!==a&&(0===l||!s||i.z<=s.z)?(n=i,i=i.nextZ,a--):(n=s,s=s.nextZ,l--),r?r.nextZ=n:e=n,n.prevZ=r,r=n;i=s}r.nextZ=null,h*=2}while(o>1)}(n)}(e,s,n,r);for(var a,l,h=e;e.prev!==e.next;)if(a=e.prev,l=e.next,r?Ts(e,s,n,r):Cs(e))t.push(a.i/i),t.push(e.i/i),t.push(l.i/i),Hs(e),e=l.next,h=l.next;else if((e=l)===h){o?1===o?ws(e=Es(e,t,i),t,i,s,n,r,2):2===o&&Ls(e,t,i,s,n,r):ws(bs(e),t,i,s,n,r,1);break}}}function Cs(e){var t=e.prev,i=e,s=e.next;if(ks(t,i,s)>=0)return!1;for(var n=e.next.next;n!==e.prev;){if(Rs(t.x,t.y,i.x,i.y,s.x,s.y,n.x,n.y)&&ks(n.prev,n,n.next)>=0)return!1;n=n.next}return!0}function Ts(e,t,i,s){var n=e.prev,r=e,o=e.next;if(ks(n,r,o)>=0)return!1;for(var a=n.x<r.x?n.x<o.x?n.x:o.x:r.x<o.x?r.x:o.x,l=n.y<r.y?n.y<o.y?n.y:o.y:r.y<o.y?r.y:o.y,h=n.x>r.x?n.x>o.x?n.x:o.x:r.x>o.x?r.x:o.x,c=n.y>r.y?n.y>o.y?n.y:o.y:r.y>o.y?r.y:o.y,d=Ss(a,l,t,i,s),_=Ss(h,c,t,i,s),u=e.nextZ;u&&u.z<=_;){if(u!==e.prev&&u!==e.next&&Rs(n.x,n.y,r.x,r.y,o.x,o.y,u.x,u.y)&&ks(u.prev,u,u.next)>=0)return!1;u=u.nextZ}for(u=e.prevZ;u&&u.z>=d;){if(u!==e.prev&&u!==e.next&&Rs(n.x,n.y,r.x,r.y,o.x,o.y,u.x,u.y)&&ks(u.prev,u,u.next)>=0)return!1;u=u.prevZ}return!0}function Es(e,t,i){var s=e;do{var n=s.prev,r=s.next.next;!Is(n,r)&&zs(n,s,s.next,r)&&Ds(n,r)&&Ds(r,n)&&(t.push(n.i/i),t.push(s.i/i),t.push(r.i/i),Hs(s),Hs(s.next),s=e=r),s=s.next}while(s!==e);return s}function Ls(e,t,i,s,n,r){var o=e;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&Bs(o,a)){var l=Fs(o,a);return o=bs(o,o.next),l=bs(l,l.next),ws(o,t,i,s,n,r),void ws(l,t,i,s,n,r)}a=a.next}o=o.next}while(o!==e)}function As(e,t){return e.x-t.x}function Ps(e,t){if(t=function(e,t){var i,s=t,n=e.x,r=e.y,o=-1/0;do{if(r<=s.y&&r>=s.next.y&&s.next.y!==s.y){var a=s.x+(r-s.y)*(s.next.x-s.x)/(s.next.y-s.y);if(a<=n&&a>o){if(o=a,a===n){if(r===s.y)return s;if(r===s.next.y)return s.next}i=s.x<s.next.x?s:s.next}}s=s.next}while(s!==t);if(!i)return null;if(n===o)return i.prev;var l,h=i,c=i.x,d=i.y,_=1/0;s=i.next;for(;s!==h;)n>=s.x&&s.x>=c&&n!==s.x&&Rs(r<d?n:o,r,c,d,r<d?o:n,r,s.x,s.y)&&((l=Math.abs(r-s.y)/(n-s.x))<_||l===_&&s.x>i.x)&&Ds(s,e)&&(i=s,_=l),s=s.next;return i}(e,t),t){var i=Fs(t,e);bs(i,i.next)}}function Ss(e,t,i,s,n){return(e=1431655765&((e=858993459&((e=252645135&((e=16711935&((e=32767*(e-i)/n)|e<<8))|e<<4))|e<<2))|e<<1))|(t=1431655765&((t=858993459&((t=252645135&((t=16711935&((t=32767*(t-s)/n)|t<<8))|t<<4))|t<<2))|t<<1))<<1}function Ms(e){var t=e,i=e;do{t.x<i.x&&(i=t),t=t.next}while(t!==e);return i}function Rs(e,t,i,s,n,r,o,a){return(n-o)*(t-a)-(e-o)*(r-a)>=0&&(e-o)*(s-a)-(i-o)*(t-a)>=0&&(i-o)*(r-a)-(n-o)*(s-a)>=0}function Bs(e,t){return e.next.i!==t.i&&e.prev.i!==t.i&&!function(e,t){var i=e;do{if(i.i!==e.i&&i.next.i!==e.i&&i.i!==t.i&&i.next.i!==t.i&&zs(i,i.next,e,t))return!0;i=i.next}while(i!==e);return!1}(e,t)&&Ds(e,t)&&Ds(t,e)&&function(e,t){var i=e,s=!1,n=(e.x+t.x)/2,r=(e.y+t.y)/2;do{i.y>r!=i.next.y>r&&i.next.y!==i.y&&n<(i.next.x-i.x)*(r-i.y)/(i.next.y-i.y)+i.x&&(s=!s),i=i.next}while(i!==e);return s}(e,t)}function ks(e,t,i){return(t.y-e.y)*(i.x-t.x)-(t.x-e.x)*(i.y-t.y)}function Is(e,t){return e.x===t.x&&e.y===t.y}function zs(e,t,i,s){return!!(Is(e,t)&&Is(i,s)||Is(e,s)&&Is(i,t))||ks(e,t,i)>0!=ks(e,t,s)>0&&ks(i,s,e)>0!=ks(i,s,t)>0}function Ds(e,t){return ks(e.prev,e,e.next)<0?ks(e,t,e.next)>=0&&ks(e,e.prev,t)>=0:ks(e,t,e.prev)<0||ks(e,e.next,t)<0}function Fs(e,t){var i=new Os(e.i,e.x,e.y),s=new Os(t.i,t.x,t.y),n=e.next,r=t.prev;return e.next=t,t.prev=e,i.next=n,n.prev=i,s.next=i,i.prev=s,r.next=s,s.prev=r,s}function Ns(e,t,i,s){var n=new Os(e,t,i);return s?(n.next=s.next,n.prev=s,s.next.prev=n,s.next=n):(n.prev=n,n.next=n),n}function Hs(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ)}function Os(e,t,i){this.i=e,this.x=t,this.y=i,this.prev=null,this.next=null,this.z=null,this.prevZ=null,this.nextZ=null,this.steiner=!1}function Vs(e){var t=e[0][0].length,i={vertices:[],holes:[],dimensions:t},s=0;for(let n=0;n<e.length;n++){for(let s=0;s<e[n].length;s++)for(let r=0;r<t;r++)i.vertices.push(e[n][s][r]);n>0&&(s+=e[n-1].length,i.holes.push(s))}return i}function Us(e,t,i){let s=e[0],n=e[1];if(s>=0){let e=65536*Math.floor(s/65536);t.x=Math.fround(e),i.x=Math.fround(s-e)}else{let e=65536*Math.floor(-s/65536);t.x=Math.fround(-e),i.x=Math.fround(s+e)}if(n>=0){let e=65536*Math.floor(n/65536);t.y=Math.fround(e),i.y=Math.fround(n-e)}else{let e=65536*Math.floor(-n/65536);t.y=Math.fround(-e),i.y=Math.fround(n+e)}}let Gs=new ae,Ys=new ae,js=new ae;class Ws{constructor(e){this.__id=Ws.__counter__++,this._layer=e,this._handler=null,this._geometries=[],this._updatedGeometryArr=[],this._updatedGeometry={},this._removeGeometryExtentArr=[],this._removeGeometryExtents={},this._polyVerticesHighMerc=[],this._polyVerticesLowMerc=[],this._polyColors=[],this._polyPickingColors=[],this._polyIndexes=[],this._lineVerticesHighMerc=[],this._lineVerticesLowMerc=[],this._lineOrders=[],this._lineIndexes=[],this._lineColors=[],this._linePickingColors=[],this._lineThickness=[],this._lineStrokes=[],this._lineStrokeColors=[],this._polyVerticesHighBufferMerc=null,this._polyVerticesLowBufferMerc=null,this._polyColorsBuffer=null,this._polyPickingColorsBuffer=null,this._polyIndexesBuffer=null,this._lineVerticesHighBufferMerc=null,this._lineVerticesLowBufferMerc=null,this._lineColorsBuffer=null,this._linePickingColorsBuffer=null,this._lineThicknessBuffer=null,this._lineStrokesBuffer=null,this._lineStrokeColorsBuffer=null,this._lineOrdersBuffer=null,this._lineIndexesBuffer=null,this._buffersUpdateCallbacks=[],this._buffersUpdateCallbacks[0]=this.createPolyVerticesBuffer,this._buffersUpdateCallbacks[1]=this.createPolyIndexesBuffer,this._buffersUpdateCallbacks[2]=this.createPolyColorsBuffer,this._buffersUpdateCallbacks[3]=this.createLineVerticesBuffer,this._buffersUpdateCallbacks[4]=this.createLineIndexesBuffer,this._buffersUpdateCallbacks[5]=this.createLineOrdersBuffer,this._buffersUpdateCallbacks[6]=this.createLineColorsBuffer,this._buffersUpdateCallbacks[7]=this.createLineThicknessBuffer,this._buffersUpdateCallbacks[8]=this.createLineStrokesBuffer,this._buffersUpdateCallbacks[9]=this.createLineStrokeColorsBuffer,this._buffersUpdateCallbacks[10]=this.createPolyPickingColorsBuffer,this._buffersUpdateCallbacks[11]=this.createLinePickingColorsBuffer,this._changedBuffers=new Array(this._buffersUpdateCallbacks.length)}static appendLineData(e,t,i,s,n,r,o,a,l,h,c,d,_,u,g,f,p,m){var v=0;c.length>0?(v=c[c.length-5]+9,c.push(v,v)):c.push(0,0);var y=n,x=[i.x,i.y,i.z,i.w],b=o,w=[r.x,r.y,r.z,r.w],C=[s.x,s.y,s.z,1];for(let i=0;i<e.length;i++){var T=e[i];if(0===T.length)continue;let s,n,r=v;if(t)s=T[T.length-1];else{let e=T[0],t=T[1];t||(t=e),s=[e[0]+e[0]-t[0],e[1]+e[1]-t[1]]}Us(s,Gs,Ys),a.push(Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y),l.push(Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y),p.push(Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y),m.push(Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y),h.push(1,-1,2,-2),u.push(y,y,y,y),f.push(b,b,b,b),d.push(x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3]),g.push(w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3]),_.push(C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3]);for(let e=0;e<T.length;e++){Us(T[e],Gs,Ys),a.push(Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y),l.push(Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y),p.push(Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y),m.push(Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y),h.push(1,-1,2,-2),u.push(y,y,y,y),f.push(b,b,b,b),d.push(x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3]),g.push(w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3]),_.push(C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3]),c.push(v++,v++,v++,v++)}if(t)n=T[0],c.push(r,r+1,r+1,r+1);else{let e=T[T.length-1],t=T[T.length-2];t||(t=e),n=[e[0]+e[0]-t[0],e[1]+e[1]-t[1]],c.push(v-1,v-1,v-1,v-1)}Us(n,Gs,Ys),a.push(Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y),l.push(Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y),p.push(Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y,Gs.x,Gs.y),m.push(Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y,Ys.x,Ys.y),h.push(1,-1,2,-2),u.push(y,y,y,y),f.push(b,b,b,b),d.push(x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3],x[0],x[1],x[2],x[3]),g.push(w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3],w[0],w[1],w[2],w[3]),_.push(C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3],C[0],C[1],C[2],C[3]),i<e.length-1&&(v+=8,c.push(v,v))}}assignHandler(e){this._handler=e,this.refresh(),e.isInitialized()&&this.update()}add(t){if(-1===t._handlerIndex){t._handler=this,t._handlerIndex=this._geometries.length,this._geometries.push(t);let i=t._entity._pickingColor.scaleTo(1/255);if(t._polyVerticesHighMerc=[],t._polyVerticesLowMerc=[],t._lineVerticesHighMerc=[],t._lineVerticesLowMerc=[],t._coordinates[0].length)if(t.type===e.GeometryTypeEnum.POLYGON){let e=t._coordinates,s=[];for(let t=0;t<e.length;t++){s[t]=[];for(let i=0;i<e[t].length;i++)s[t][i]=[$(e[t][i][0]),X(e[t][i][1])]}let n=Vs(s),r=ys(n.vertices,n.holes,2);t._polyVerticesHandlerIndex=this._polyVerticesHighMerc.length,t._polyIndexesHandlerIndex=this._polyIndexes.length;for(let e=0;e<r.length;e++)this._polyIndexes.push(r[e]+.5*t._polyVerticesHandlerIndex);let o=t._style.fillColor,a=[],l=[];for(let e=0;e<.5*n.vertices.length;e++)this._polyColors.push(o.x,o.y,o.z,o.w),this._polyPickingColors.push(i.x,i.y,i.z,1);for(let e=0;e<n.vertices.length;e++)vs(n.vertices[e],js),a[e]=js.x,l[e]=js.y;t._polyVerticesHighMerc=a,t._polyVerticesLowMerc=l,this._polyVerticesHighMerc.push.apply(this._polyVerticesHighMerc,a),this._polyVerticesLowMerc.push.apply(this._polyVerticesLowMerc,l),t._polyVerticesLength=n.vertices.length,t._polyIndexesLength=r.length,t._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,t._lineOrdersHandlerIndex=this._lineOrders.length,t._lineIndexesHandlerIndex=this._lineIndexes.length,t._lineColorsHandlerIndex=this._lineColors.length,t._lineThicknessHandlerIndex=this._lineThickness.length,Ws.appendLineData(s,!0,t._style.lineColor,i,t._style.lineWidth,t._style.strokeColor,t._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,t._lineVerticesHighMerc,t._lineVerticesLowMerc),t._lineVerticesLength=this._lineVerticesHighMerc.length-t._lineVerticesHandlerIndex,t._lineOrdersLength=this._lineOrders.length-t._lineOrdersHandlerIndex,t._lineIndexesLength=this._lineIndexes.length-t._lineIndexesHandlerIndex,t._lineColorsLength=this._lineColors.length-t._lineColorsHandlerIndex,t._lineThicknessLength=this._lineThickness.length-t._lineThicknessHandlerIndex}else if(t.type===e.GeometryTypeEnum.MULTIPOLYGON){let e=t._coordinates,s=[],n=[];t._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,t._lineOrdersHandlerIndex=this._lineOrders.length,t._lineIndexesHandlerIndex=this._lineIndexes.length,t._lineColorsHandlerIndex=this._lineColors.length,t._lineThicknessHandlerIndex=this._lineThickness.length;for(let r=0;r<e.length;r++){let o=e[r],a=[];for(let t=0;t<o.length;t++){a[t]=[];for(let i=0;i<e[r][t].length;i++)a[t][i]=[$(o[t][i][0]),X(o[t][i][1])]}let l=Vs(a),h=ys(l.vertices,l.holes,2);for(let e=0;e<h.length;e++)n.push(h[e]+.5*s.length);s.push.apply(s,l.vertices),Ws.appendLineData(a,!0,t._style.lineColor,i,t._style.lineWidth,t._style.strokeColor,t._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,t._lineVerticesHighMerc,t._lineVerticesLowMerc)}t._polyVerticesHandlerIndex=this._polyVerticesHighMerc.length,t._polyIndexesHandlerIndex=this._polyIndexes.length;for(let e=0;e<n.length;e++)this._polyIndexes.push(n[e]+.5*t._polyVerticesHandlerIndex);let r=t._style.fillColor,o=[],a=[];for(let e=0;e<.5*s.length;e++)this._polyColors.push(r.x,r.y,r.z,r.w),this._polyPickingColors.push(i.x,i.y,i.z,1);for(let e=0;e<s.length;e++)vs(s[e],js),o[e]=js.x,a[e]=js.y;t._polyVerticesHighMerc=o,t._polyVerticesLowMerc=a,this._polyVerticesHighMerc.push.apply(this._polyVerticesHighMerc,o),this._polyVerticesLowMerc.push.apply(this._polyVerticesLowMerc,a),t._polyVerticesLength=s.length,t._polyIndexesLength=n.length,t._lineVerticesLength=this._lineVerticesHighMerc.length-t._lineVerticesHandlerIndex,t._lineOrdersLength=this._lineOrders.length-t._lineOrdersHandlerIndex,t._lineIndexesLength=this._lineIndexes.length-t._lineIndexesHandlerIndex,t._lineColorsLength=this._lineColors.length-t._lineColorsHandlerIndex,t._lineThicknessLength=this._lineThickness.length-t._lineThicknessHandlerIndex}else if(t.type===e.GeometryTypeEnum.LINESTRING){let e=t._coordinates,s=new Array(e.length);for(let t=0;t<e.length;t++)s[t]=[$(e[t][0]),X(e[t][1])];t._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,t._lineOrdersHandlerIndex=this._lineOrders.length,t._lineIndexesHandlerIndex=this._lineIndexes.length,t._lineColorsHandlerIndex=this._lineColors.length,t._lineThicknessHandlerIndex=this._lineThickness.length,Ws.appendLineData([s],!1,t._style.lineColor,i,t._style.lineWidth,t._style.strokeColor,t._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,t._lineVerticesHighMerc,t._lineVerticesLowMerc),t._lineVerticesLength=this._lineVerticesHighMerc.length-t._lineVerticesHandlerIndex,t._lineOrdersLength=this._lineOrders.length-t._lineOrdersHandlerIndex,t._lineIndexesLength=this._lineIndexes.length-t._lineIndexesHandlerIndex,t._lineColorsLength=this._lineColors.length-t._lineColorsHandlerIndex,t._lineThicknessLength=this._lineThickness.length-t._lineThicknessHandlerIndex}else if(t.type===e.GeometryTypeEnum.MULTILINESTRING){let e=t._coordinates,s=[];for(let t=0;t<e.length;t++){s[t]=[];for(let i=0;i<e[t].length;i++)s[t][i]=[$(e[t][i][0]),X(e[t][i][1])]}t._lineVerticesHandlerIndex=this._lineVerticesHighMerc.length,t._lineOrdersHandlerIndex=this._lineOrders.length,t._lineIndexesHandlerIndex=this._lineIndexes.length,t._lineColorsHandlerIndex=this._lineColors.length,t._lineThicknessHandlerIndex=this._lineThickness.length,Ws.appendLineData(s,!1,t._style.lineColor,i,t._style.lineWidth,t._style.strokeColor,t._style.strokeWidth,this._lineVerticesHighMerc,this._lineVerticesLowMerc,this._lineOrders,this._lineIndexes,this._lineColors,this._linePickingColors,this._lineThickness,this._lineStrokeColors,this._lineStrokes,t._lineVerticesHighMerc,t._lineVerticesLowMerc),t._lineVerticesLength=this._lineVerticesHighMerc.length-t._lineVerticesHandlerIndex,t._lineOrdersLength=this._lineOrders.length-t._lineOrdersHandlerIndex,t._lineIndexesLength=this._lineIndexes.length-t._lineIndexesHandlerIndex,t._lineColorsLength=this._lineColors.length-t._lineColorsHandlerIndex,t._lineThicknessLength=this._lineThickness.length-t._lineThicknessHandlerIndex}this.setGeometryVisibility(t),!this._updatedGeometry[t.__id]&&this._updatedGeometryArr.push(t),this._updatedGeometry[t.__id]=!0,this.refresh()}}remove(e){const t=e._handlerIndex;if(-1!==t){this._geometries.splice(t,1),this._polyVerticesHighMerc.splice(e._polyVerticesHandlerIndex,e._polyVerticesLength),this._polyVerticesLowMerc.splice(e._polyVerticesHandlerIndex,e._polyVerticesLength),this._polyColors.splice(2*e._polyVerticesHandlerIndex,2*e._polyVerticesLength),this._polyPickingColors.splice(2*e._polyVerticesHandlerIndex,2*e._polyVerticesLength),this._polyIndexes.splice(e._polyIndexesHandlerIndex,e._polyIndexesLength);let i=.5*e._polyVerticesLength;for(let t=e._polyIndexesHandlerIndex;t<this._polyIndexes.length;t++)this._polyIndexes[t]-=i;this._lineVerticesHighMerc.splice(e._lineVerticesHandlerIndex,e._lineVerticesLength),this._lineVerticesLowMerc.splice(e._lineVerticesHandlerIndex,e._lineVerticesLength),this._lineOrders.splice(e._lineOrdersHandlerIndex,e._lineOrdersLength),this._lineColors.splice(e._lineColorsHandlerIndex,e._lineColorsLength),this._linePickingColors.splice(e._lineColorsHandlerIndex,e._lineColorsLength),this._lineStrokeColors.splice(e._lineColorsHandlerIndex,e._lineColorsLength),this._lineThickness.splice(e._lineThicknessHandlerIndex,e._lineThicknessLength),this._lineStrokes.splice(e._lineThicknessHandlerIndex,e._lineThicknessLength),this._lineIndexes.splice(e._lineIndexesHandlerIndex,e._lineIndexesLength),i=.5*e._lineVerticesLength;for(let t=e._lineIndexesHandlerIndex;t<this._lineIndexes.length;t++)this._lineIndexes[t]-=i;let s=this._geometries;for(let i=t;i<s.length;i++){let t=s[i];t._handlerIndex=i,t._polyVerticesHandlerIndex-=e._polyVerticesLength,t._polyIndexesHandlerIndex-=e._polyIndexesLength,t._lineVerticesHandlerIndex-=e._lineVerticesLength,t._lineOrdersHandlerIndex-=e._lineOrdersLength,t._lineColorsHandlerIndex-=e._lineColorsLength,t._lineThicknessHandlerIndex-=e._lineThicknessLength,t._lineIndexesHandlerIndex-=e._lineIndexesLength}e._pickingReady=!1,e._handler=null,e._handlerIndex=-1,e._polyVerticesHighMerc=[],e._polyVerticesLowMerc=[],e._polyVerticesLength=-1,e._polyIndexesLength=-1,e._polyVerticesHandlerIndex=-1,e._polyIndexesHandlerIndex=-1,e._lineVerticesHighMerc=[],e._lineVerticesLowMerc=[],e._lineVerticesLength=-1,e._lineOrdersLength=-1,e._lineIndexesLength=-1,e._lineColorsLength=-1,e._lineThicknessLength=-1,e._lineVerticesHandlerIndex=-1,e._lineOrdersHandlerIndex=-1,e._lineIndexesHandlerIndex=-1,e._lineThicknessHandlerIndex=-1,e._lineColorsHandlerIndex=-1,!this._removeGeometryExtents[e.__id]&&this._removeGeometryExtentArr.push(e.getExtent()),this._removeGeometryExtents[e.__id]=!0,this.refresh()}}_refreshRecursevely(e,t){if(t.ready){let i=this._layer._id;for(let s=0;s<t.nodes.length;s++){let n=t.nodes[s];if(e.overlaps(n.segment.getExtentLonLat())){this._refreshRecursevely(e,n);let t=n.segment.materials[i];t&&t.isReady&&(1!==t.segment.node.getState()?t.layer.clearMaterial(t):(t.pickingReady=t.pickingReady&&e._pickingReady,t.isReady=!1,t._updateTexture=t.texture,t._updatePickingMask=t.pickingMask),e._pickingReady=!0)}}}}_refreshRecursevelyExt(e,t){if(t.ready){let i=this._layer.__id;for(let s=0;s<t.nodes.length;s++){let n=t.nodes[s];if(e.overlaps(n.segment.getExtentLonLat())){this._refreshRecursevelyExt(e,n);let t=n.segment.materials[i];t&&t.isReady&&t.layer.clearMaterial(t)}}}}_refreshPlanetNode(e){let t,i=this._removeGeometryExtentArr;for(t=0;t<i.length;t++)this._refreshRecursevelyExt(i[t],e);let s=this._updatedGeometryArr;for(t=0;t<s.length;t++)this._refreshRecursevely(s[t],e)}_updatePlanet(){let e=this._layer._planet;if(e){let t=e.quadTreeStrategy.quadTreeList;for(let e=0;e<t.length;e++)this._refreshPlanetNode(t[e])}this._updatedGeometryArr.length=0,this._updatedGeometryArr=[],this._updatedGeometry={},this._removeGeometryExtentArr.length=0,this._removeGeometryExtentArr=[],this._removeGeometryExtents={}}refresh(){let e=this._changedBuffers.length;for(;e--;)this._changedBuffers[e]=!0}update(){if(this._handler){let e=!1,t=this._changedBuffers.length;for(;t--;)this._changedBuffers[t]&&(e=!0,this._buffersUpdateCallbacks[t].call(this),this._changedBuffers[t]=!1);e&&this._updatePlanet()}}setGeometryVisibility(e){let t=e.getVisibility()?1:0,i=this._polyVerticesHighMerc,s=this._polyVerticesLowMerc,n=e._polyVerticesLength,r=e._polyVerticesHandlerIndex;for(let o=0;o<n;o++)i[r+o]=e._polyVerticesHighMerc[o]*t,s[r+o]=e._polyVerticesLowMerc[o]*t;i=this._lineVerticesHighMerc,s=this._lineVerticesLowMerc,n=e._lineVerticesLength,r=e._lineVerticesHandlerIndex;for(let o=0;o<n;o++)i[r+o]=e._lineVerticesHighMerc[o]*t,s[r+o]=e._lineVerticesLowMerc[o]*t;this._changedBuffers[0]=!0,this._changedBuffers[3]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}setPolyColorArr(e,t){let i=2*e._polyVerticesHandlerIndex,s=i+2*e._polyVerticesLength,n=this._polyColors;for(let e=i;e<s;e+=4)n[e]=t.x,n[e+1]=t.y,n[e+2]=t.z,n[e+3]=t.w;this._changedBuffers[2]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}setLineStrokeColorArr(e,t){let i=e._lineColorsHandlerIndex,s=i+e._lineColorsLength,n=this._lineStrokeColors;for(let e=i;e<s;e+=4)n[e]=t.x,n[e+1]=t.y,n[e+2]=t.z,n[e+3]=t.w;this._changedBuffers[9]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}setLineColorArr(e,t){let i=e._lineColorsHandlerIndex,s=i+e._lineColorsLength,n=this._lineColors;for(let e=i;e<s;e+=4)n[e]=t.x,n[e+1]=t.y,n[e+2]=t.z,n[e+3]=t.w;this._changedBuffers[6]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}setLineStrokeArr(e,t){}setLineThicknessArr(e,t){let i=e._lineThicknessHandlerIndex,s=i+e._lineThicknessLength,n=this._lineThickness;for(let e=i;e<s;e++)n[e]=t;this._changedBuffers[7]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}bringToFront(e){let t=this._polyIndexes.splice(e._polyIndexesHandlerIndex,e._polyIndexesLength),i=this._lineIndexes.splice(e._lineIndexesHandlerIndex,e._lineIndexesLength);this._geometries.splice(e._handlerIndex,1);let s=this._geometries;for(let t=e._handlerIndex;t<s.length;t++){let i=s[t];i._handlerIndex=t,i._polyIndexesHandlerIndex-=e._polyIndexesLength,i._lineIndexesHandlerIndex-=e._lineIndexesLength}e._polyIndexesHandlerIndex=this._polyIndexes.length,e._lineIndexesHandlerIndex=this._lineIndexes.length,e._handlerIndex=this._geometries.length,this._geometries.push(e),this._polyIndexes.push.apply(this._polyIndexes,t),this._lineIndexes.push.apply(this._lineIndexes,i),this._changedBuffers[1]=!0,this._changedBuffers[4]=!0,!this._updatedGeometry[e.__id]&&this._updatedGeometryArr.push(e),this._updatedGeometry[e.__id]=!0}createPolyVerticesBuffer(){let e=this._handler;e.gl.deleteBuffer(this._polyVerticesHighBufferMerc),this._polyVerticesHighBufferMerc=e.createArrayBuffer(new Float32Array(this._polyVerticesHighMerc),2,this._polyVerticesHighMerc.length/2),e.gl.deleteBuffer(this._polyVerticesLowBufferMerc),this._polyVerticesLowBufferMerc=e.createArrayBuffer(new Float32Array(this._polyVerticesLowMerc),2,this._polyVerticesLowMerc.length/2)}createPolyIndexesBuffer(){let e=this._handler;e.gl.deleteBuffer(this._polyIndexesBuffer),this._polyIndexesBuffer=e.createElementArrayBuffer(new Uint32Array(this._polyIndexes),1,this._polyIndexes.length)}createPolyColorsBuffer(){let e=this._handler;e.gl.deleteBuffer(this._polyColorsBuffer),this._polyColorsBuffer=e.createArrayBuffer(new Float32Array(this._polyColors),4,this._polyColors.length/4)}createPolyPickingColorsBuffer(){let e=this._handler;e.gl.deleteBuffer(this._polyPickingColorsBuffer),this._polyPickingColorsBuffer=e.createArrayBuffer(new Float32Array(this._polyPickingColors),4,this._polyPickingColors.length/4)}createLineVerticesBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineVerticesHighBufferMerc),this._lineVerticesHighBufferMerc=e.createArrayBuffer(new Float32Array(this._lineVerticesHighMerc),2,this._lineVerticesHighMerc.length/2),e.gl.deleteBuffer(this._lineVerticesLowBufferMerc),this._lineVerticesLowBufferMerc=e.createArrayBuffer(new Float32Array(this._lineVerticesLowMerc),2,this._lineVerticesLowMerc.length/2)}createLineIndexesBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineIndexesBuffer),this._lineIndexesBuffer=e.createElementArrayBuffer(new Uint32Array(this._lineIndexes),1,this._lineIndexes.length)}createLineOrdersBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineOrdersBuffer),this._lineOrdersBuffer=e.createArrayBuffer(new Float32Array(this._lineOrders),1,this._lineOrders.length/2)}createLineColorsBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineColorsBuffer),this._lineColorsBuffer=e.createArrayBuffer(new Float32Array(this._lineColors),4,this._lineColors.length/4)}createLinePickingColorsBuffer(){let e=this._handler;e.gl.deleteBuffer(this._linePickingColorsBuffer),this._linePickingColorsBuffer=e.createArrayBuffer(new Float32Array(this._linePickingColors),4,this._linePickingColors.length/4)}createLineThicknessBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineThicknessBuffer),this._lineThicknessBuffer=e.createArrayBuffer(new Float32Array(this._lineThickness),1,this._lineThickness.length)}createLineStrokesBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineStrokesBuffer),this._lineStrokesBuffer=e.createArrayBuffer(new Float32Array(this._lineStrokes),1,this._lineStrokes.length)}createLineStrokeColorsBuffer(){let e=this._handler;e.gl.deleteBuffer(this._lineStrokeColorsBuffer),this._lineStrokeColorsBuffer=e.createArrayBuffer(new Float32Array(this._lineStrokeColors),4,this._lineStrokeColors.length/4)}clear(){this._geometries=[],this._polyVerticesHighMerc=[],this._polyVerticesLowMerc=[],this._polyIndexes=[],this._polyColors=[],this._polyPickingColors=[],this._lineVerticesHighMerc=[],this._lineVerticesLowMerc=[],this._lineOrders=[],this._lineIndexes=[],this._lineColors=[],this._linePickingColors=[],this._lineThickness=[],this._lineStrokeColors=[],this._lineStrokes=[],this._deleteBuffers(),this._polyVerticesHighBufferMerc=null,this._polyVerticesLowBufferMerc=null,this._polyIndexesBuffer=null,this._polyColorsBuffer=null,this._polyPickingColorsBuffer=null,this._lineVerticesHighBufferMerc=null,this._lineVerticesLowBufferMerc=null,this._lineIndexesBuffer=null,this._lineOrdersBuffer=null,this._lineColorsBuffer=null,this._linePickingColorsBuffer=null,this._lineThicknessBuffer=null,this._lineStrokeColorsBuffer=null,this._lineStrokesBuffer=null,this._updatedGeometryArr=[],this._updatedGeometry={},this._removeGeometryExtentArr=[],this._removeGeometryExtents={},this.refresh()}_deleteBuffers(){if(this._layer._planet&&this._layer._planet.renderer){let e=this._layer._planet.renderer.handler.gl;e&&(e.deleteBuffer(this._polyVerticesHighBufferMerc),e.deleteBuffer(this._polyVerticesLowBufferMerc),e.deleteBuffer(this._polyIndexesBuffer),e.deleteBuffer(this._polyColorsBuffer),e.deleteBuffer(this._polyPickingColorsBuffer),e.deleteBuffer(this._lineVerticesHighBufferMerc),e.deleteBuffer(this._lineVerticesLowBufferMerc),e.deleteBuffer(this._lineIndexesBuffer),e.deleteBuffer(this._lineOrdersBuffer),e.deleteBuffer(this._lineColorsBuffer),e.deleteBuffer(this._linePickingColorsBuffer),e.deleteBuffer(this._lineThicknessBuffer),e.deleteBuffer(this._lineStrokeColorsBuffer),e.deleteBuffer(this._lineStrokesBuffer))}}}Ws.__counter__=0;class qs extends $t{constructor(e,t={}){super(e,t),this.events=this.events.registerNames($s),this.isVector=!0,this._hasImageryTiles=!1,this.scaleByDistance=t.scaleByDistance||[r,r,r],this._useLighting=void 0===t.useLighting||t.useLighting;let i=new Float32Array([1,1,1]);void 0!==t.pickingScale&&(t.pickingScale instanceof Array?(i[0]=t.pickingScale[0]||i[0],i[1]=t.pickingScale[1]||i[1],i[2]=t.pickingScale[2]||i[2]):"number"==typeof t.pickingScale&&(i[0]=t.pickingScale,i[1]=t.pickingScale,i[2]=t.pickingScale)),this.pickingScale=i,this.async=void 0===t.async||t.async,this.clampToGround=t.clampToGround||!1,this.relativeToGround=t.relativeToGround||!1,this._entities=function(e){let t=[];for(let i=0;i<e.length;i++){let s=e[i];"Entity"===s.instanceName?t.push(s):t.push(new Si(s))}return t}(t.entities||[]),this._labelMaxLetters=t.labelMaxLetters||24,this._stripEntityCollection=new fs({pickingEnabled:this.pickingEnabled}),this._bindEventsDefault(this._stripEntityCollection),this._polylineEntityCollection=new fs({pickingEnabled:this.pickingEnabled}),this._bindEventsDefault(this._polylineEntityCollection),this._geoObjectEntityCollection=new fs({pickingEnabled:this.pickingEnabled,useLighting:this._useLighting}),this._bindEventsDefault(this._geoObjectEntityCollection),this._geometryHandler=new Ws(this),this._nodeCapacity=t.nodeCapacity||60,this._entityCollectionsTreeStrategy=null,this.setEntities(this._entities),this.polygonOffsetUnits=null!=t.polygonOffsetUnits?t.polygonOffsetUnits:0,this.pickingEnabled=this._pickingEnabled,this._depthOrder=t.depthOrder||0}get depthOrder(){return this._depthOrder}set depthOrder(e){e!==this._depthOrder&&(this._depthOrder=e,this._planet&&this._planet.updateVisibleLayers())}get useLighting(){return this._useLighting}set useLighting(e){e!==this._useLighting&&(this._geoObjectEntityCollection.useLighting=e,this._useLighting=e)}get labelMaxLetters(){return this._labelMaxLetters}get instanceName(){return"Vector"}_bindPicking(){this._pickingColor.clear()}addTo(e){this._planet||(this._assignPlanet(e),this._geometryHandler.assignHandler(e.renderer.handler),this._polylineEntityCollection.addTo(e,!0),this._stripEntityCollection.addTo(e,!0),this._geoObjectEntityCollection.addTo(e,!0),this._polylineEntityCollection._layer=this,this._stripEntityCollection._layer=this,this._geoObjectEntityCollection._layer=this,this.setEntities(this._entities))}remove(){return super.remove(),this._polylineEntityCollection.remove(),this._stripEntityCollection.remove(),this._geoObjectEntityCollection.remove(),this._polylineEntityCollection._layer=void 0,this._stripEntityCollection._layer=void 0,this._geoObjectEntityCollection._layer=void 0,this}getEntities(){return[].concat(this._entities)}add(e,t=!1){return e._layer||e._entityCollection||(e._layer=this,e._layerIndex=this._entities.length,this._entities.push(e),this._proceedEntity(e,t)),this}insert(e,t,i=!1){if(!e._layer&&!e._entityCollection){e._layer=this,e._layerIndex=t,this._entities.splice(t,0,e);for(let e=t+1,i=this._entities.length;e<i;e++)this._entities[e]._layerIndex=e;this._proceedEntity(e,i)}return this}_proceedEntity(e,t=!1){let i=this._hasImageryTiles,s=!(e.strip||e.polyline||e.ray||e.geoObject||e.geometry);e.strip&&this._stripEntityCollection.add(e),(e.polyline||e.ray)&&this._polylineEntityCollection.add(e),(e.geoObject||s)&&this._geoObjectEntityCollection.add(e),e.geometry&&(this._hasImageryTiles=!0,this._planet&&(this._planet.renderer.assignPickingColor(e),this._geometryHandler.add(e.geometry))),this._planet&&((e.billboard||e.label||e.geoObject||s)&&(e._cartesian.isZero()&&!e._lonLat.isZero()?e._setCartesian3vSilent(this._planet.ellipsoid.lonLatToCartesian(e._lonLat)):(e._lonLat=this._planet.ellipsoid.cartesianToLonLat(e._cartesian),Math.abs(e._lonLat.lat)<Q?e._lonLatMerc=e._lonLat.forwardMercator():e._lonLatMerc.lon=e._lonLatMerc.lat=e._lonLatMerc.height=0)),(e.billboard||e.label)&&this._entityCollectionsTreeStrategy?.insertEntity(e)),this._planet&&this._hasImageryTiles!==i&&this._planet.updateVisibleLayers(),this.events.dispatch(this.events.entityadd,e)}addEntities(e,t=!1){let i=e.length;for(;i--;)this.add(e[i],t);return this}removeEntity(e){if(e._layer&&this.isEqual(e._layer)){if(this._entities.splice(e._layerIndex,1),this._reindexEntitiesArray(e._layerIndex),e._layer=null,e._layerIndex=-1,e._entityCollection){e._entityCollection._removeEntitySilent(e);let t=e._nodePtr;for(;t;)t.count--,t=t.parentNode;e._nodePtr&&0===e._nodePtr.count&&0===e._nodePtr.deferredEntities.length&&(e._nodePtr.entityCollection=null)}else if(e._nodePtr&&e._nodePtr.deferredEntities.length){let t=e._nodePtr.deferredEntities,i=t.length;for(;i--;)if(t[i].id===e.id){t.splice(i,1);let s=e._nodePtr;for(;s;)s.count--,s=s.parentNode;break}}this._planet&&e.geometry&&(this._geometryHandler.remove(e.geometry),this._planet.renderer.clearPickingColor(e)),e._nodePtr=void 0,this.events.dispatch(this.events.entityremove,e)}return this}set pickingEnabled(e){this._pickingEnabled=e,this._stripEntityCollection.setPickingEnabled(e),this._polylineEntityCollection.setPickingEnabled(e),this._geoObjectEntityCollection.setPickingEnabled(e),this._entityCollectionsTreeStrategy?.setPickingEnabled(e)}_reindexEntitiesArray(e){const t=this._entities;for(let i=e;i<t.length;i++)t[i]._layerIndex=i}removeEntities(e){let t=e.length;for(;t--;)this.removeEntity(e[t]);return this}clear(){super.clear();let e=new Array(this._entities.length);for(let t=0;t<e.length;t++)e[t]=this._entities[t];let t=this._entities.length;for(;t--;)this._entities[t].remove();this._entities.length=0,this._entities=[];for(let t=0;t<e.length;t++)this._entities[t]=e[t];this._entityCollectionsTreeStrategy?.dispose(),this._entityCollectionsTreeStrategy=null,this._geometryHandler.clear()}each(e){let t=this._entities,i=t.length;for(;i--;)e(t[i],i)}setEntities(e){let t=new Array(e.length);for(let i=0,s=e.length;i<s;i++)t[i]=e[i];this.clear(),this._entities=new Array(t.length);let i=[];for(let e=0;e<t.length;e++){let s=t[e];s._layer=this,s._layerIndex=e;let n=!(s.strip||s.polyline||s.ray||s.geoObject||s.billboard||s.label);s.strip?this._stripEntityCollection.add(s):s.polyline||s.ray?this._polylineEntityCollection.add(s):s.geoObject||n?this._geoObjectEntityCollection.add(s):(s.billboard||s.label)&&i.push(s),s.geometry&&(this._hasImageryTiles=!0,this._planet&&(this._planet.renderer.assignPickingColor(s),this._geometryHandler.add(s.geometry))),this._entities[e]=s}return this._createEntityCollectionsTree(i),this}_createEntityCollectionsTree(e){this._planet&&(this._entityCollectionsTreeStrategy=this._planet.quadTreeStrategy.createEntitiCollectionsTreeStrategy(this,this._nodeCapacity),this._entityCollectionsTreeStrategy.insertEntities(e))}_bindEventsDefault(e){let t=this.events;e.events.on("mousemove",(e=>{t.dispatch(t.mousemove,e)})),e.events.on("mouseenter",(e=>{t.dispatch(t.mouseenter,e)})),e.events.on("mouseleave",(e=>{t.dispatch(t.mouseleave,e)})),e.events.on("lclick",(e=>{t.dispatch(t.lclick,e)})),e.events.on("rclick",(e=>{t.dispatch(t.rclick,e)})),e.events.on("mclick",(e=>{t.dispatch(t.mclick,e)})),e.events.on("ldblclick",(e=>{t.dispatch(t.ldblclick,e)})),e.events.on("rdblclick",(e=>{t.dispatch(t.rdblclick,e)})),e.events.on("mdblclick",(e=>{t.dispatch(t.mdblclick,e)})),e.events.on("lup",(e=>{t.dispatch(t.lup,e)})),e.events.on("rup",(e=>{t.dispatch(t.rup,e)})),e.events.on("mup",(e=>{t.dispatch(t.mup,e)})),e.events.on("ldown",(e=>{t.dispatch(t.ldown,e)})),e.events.on("rdown",(e=>{t.dispatch(t.rdown,e)})),e.events.on("mdown",(e=>{t.dispatch(t.mdown,e)})),e.events.on("lhold",(e=>{t.dispatch(t.lhold,e)})),e.events.on("rhold",(e=>{t.dispatch(t.rhold,e)})),e.events.on("mhold",(e=>{t.dispatch(t.mhold,e)})),e.events.on("mousewheel",(e=>{t.dispatch(t.mousewheel,e)})),e.events.on("touchmove",(e=>{t.dispatch(t.touchmove,e)})),e.events.on("touchstart",(e=>{t.dispatch(t.touchstart,e)})),e.events.on("touchend",(e=>{t.dispatch(t.touchend,e)})),e.events.on("doubletouch",(e=>{t.dispatch(t.doubletouch,e)})),e.events.on("touchleave",(e=>{t.dispatch(t.touchleave,e)})),e.events.on("touchenter",(e=>{t.dispatch(t.touchenter,e)}))}_collectStripCollectionPASS(e){let t=this._stripEntityCollection;t._fadingOpacity=this._fadingOpacity,t.scaleByDistance=this.scaleByDistance,t.pickingScale=this.pickingScale,t.polygonOffsetUnits=this.polygonOffsetUnits,e.push(t)}_collectPolylineCollectionPASS(e){let t=this._polylineEntityCollection;if(t._fadingOpacity=this._fadingOpacity,t.scaleByDistance=this.scaleByDistance,t.pickingScale=this.pickingScale,t.polygonOffsetUnits=this.polygonOffsetUnits,e.push(t),this.clampToGround||this.relativeToGround){let e=Number(this.relativeToGround);const i=this._planet._renderedNodes,s=this._planet.getViewExtent();let n=t._entities,r=n.length,o=new oe;for(;r--;){let t=n[r].polyline;if(t&&s.overlaps(t._extent)){let s=t._pathLonLatMerc,n=s.length;for(;n--;){let r=s[n].length;for(;r--;){let a=s[n][r],l=i.length;for(;l--;){let s=i[l].segment;if(s._extent.isInside(a)){let i=t._path3v[n][r];s.getTerrainPoint(i,a,o);let l=e&&t.altitude||0;if(l){let e=this._planet.ellipsoid.getSurfaceNormal3v(o);t.setPoint3v(o.addA(e.scale(l)),r,n,!0)}else t.setPoint3v(o,r,n,!0);break}}}}}}}}_collectGeoObjectCollectionPASS(e){let t=this._geoObjectEntityCollection;t._fadingOpacity=this._fadingOpacity,t.scaleByDistance=this.scaleByDistance,t.pickingScale=this.pickingScale,t.polygonOffsetUnits=this.polygonOffsetUnits,e.push(t)}collectVisibleCollections(e){let t=this._planet;(this._fading&&this._fadingOpacity>0||this.minZoom<=t.maxCurrZoom&&this.maxZoom>=t.maxCurrZoom)&&(this._collectStripCollectionPASS(e),this._collectPolylineCollectionPASS(e),this._collectGeoObjectCollectionPASS(e),this._entityCollectionsTreeStrategy&&this._entityCollectionsTreeStrategy.collectVisibleEntityCollections(e))}loadMaterial(e){const t=e.segment;this._isBaseLayer?e.texture=t._isNorth?t.planet.solidTextureOne:t.planet.solidTextureTwo:e.texture=t.planet.transparentTexture,this._planet.layerLock.isFree()&&(e.isReady=!1,e.isLoading=!0,this._planet._vectorTileCreator.add(e))}abortMaterialLoading(e){e.isLoading=!1,e.isReady=!1}applyMaterial(e,t=!1){if(e.isReady)return[0,0,1,1];{!e.isLoading&&this.loadMaterial(e);const t=e.segment;let i=t.node,s=!1,n=this.__id,r=e;for(;i.parentNode;){if(r&&r.isReady){s=!0;break}i=i.parentNode,r=i.segment.materials[n]}if(s){e.appliedNodeId=i.nodeId,e.texture=r.texture,e.pickingMask=r.pickingMask;const s=1/(2<<t.tileZoom-i.segment.tileZoom-1);return[t.tileX*s-i.segment.tileX,t.tileY*s-i.segment.tileY,s,s]}return e.textureExists&&e._updateTexture?(e.texture=e._updateTexture,e.pickingMask=e._updatePickingMask):(e.texture=t.planet.transparentTexture,e.pickingMask=t.planet.transparentTexture),e.pickingReady=!0,[0,0,1,1]}}clearMaterial(e){if(e.isReady){const t=e.segment.handler.gl;e.isReady=!1,e.pickingReady=!1;let i=e.texture;e.texture=null,i&&!i.default&&t.deleteTexture(i),i=e.pickingMask,e.pickingMask=null,i&&!i.default&&t.deleteTexture(i),i=e._updateTexture,e._updateTexture=null,i&&!i.default&&t.deleteTexture(i),i=e._updatePickingMask,e._updatePickingMask=null,i&&!i.default&&t.deleteTexture(i)}this.abortMaterialLoading(e),e.isLoading=!1,e.textureExists=!1}update(){this._geometryHandler.update(),this.events.dispatch(this.events.draw,this)}}const $s=["draw","entityadd","entityremove"],Xs=["change","startpoint"],Zs=mi.createCylinder(1,1,2,20,1,!0,!1,0,-.5,0),Ks=200,Qs=.3,Js={scale:.5,instanced:!0,tag:"corners",color:"rgb(350, 350, 0)",object3d:Zs},en={scale:.4,instanced:!0,tag:"centers",color:"rgb(0, 350, 50)",object3d:Zs},tn={thickness:3.5,color:"rgb(0, 350, 50)"};class sn extends Ri{constructor(e){super(e.name),this._cornerDblClick=!1,this._onChange=e=>{if("POLYGON"===e.geometryType){let t=this.getCoordinates(),i=new Si({geometry:{type:e.geometryType,coordinates:[t],style:{fillColor:"rgba(0,146,247,0.2)"}}});this._geometryLayer.clear(),this._geometryLayer.add(i)}},this._onCornerMouseEnter=e=>{e.renderer.handler.canvas.style.cursor="pointer",this.hideGhostPointer()},this._onCornerMouseLeave=e=>{e.renderer.handler.canvas.style.cursor="default",this.showGhostPointer()},this._onCenterMouseEnter=e=>{e.renderer.handler.canvas.style.cursor="pointer",this.hideGhostPointer()},this._onCenterMouseLeave=e=>{e.renderer.handler.canvas.style.cursor="default",this._pickedCenter||this._pickedCorner||this.showGhostPointer()},this._onLup=e=>{this._planet.renderer.controls.mouseNavigation.activate(),(this._pickedCorner||this._pickedCenter)&&(this.events.dispatch(this.events.change,this),this.setGhostPointerPosition(this._planet.getCartesianFromPixelTerrain(e)),this.showGhostPointer(),this._pickedCorner=null,this._pickedCenter=null)},this._onCornerLdown=e=>{this._pickedCorner=this._getLdown(e)},this._onCenterLdown=e=>{this._pickedCenter=this._getLdown(e)},this._onMouseMove=e=>{this._pickedCenter?this._moveCenterPoint():this._pickedCorner?this._moveCornerPoint(e.pos):this.setGhostPointerPosition(this._planet.getCartesianFromPixelTerrain(e.pos))},this._onCornerLdblclick=e=>{this._cornerDblClick=!0;let t=this.getCoordinates();t.splice(e.pickingObject.layerIndex,1),this.setCoordinates(t)},this._onMouseDblClick=e=>{if(this._cornerDblClick)return void(this._cornerDblClick=!1);if(!this._showGhostPointer)return;let t=this._planet.getCartesianFromPixelTerrain(e);t&&(this._addNew(t),!this._isStartPoint&&this._cornerLayer.getEntities().length>2&&(this._isStartPoint=!0,this.events.dispatch(this.events.startpoint,this)),this.events.dispatch(this.events.change,this))},this.events=Mt(Xs),this._planet=null,this._initCoordinates=e.coordinates||[],this._pickedCorner=null,this._pickedCenter=null,this._startPos=null,this._startClick=new ae,this._geometryLayer=new qs,this._cornerLayer=new qs("corners",{pickingScale:3,pickingEnabled:!0,polygonOffsetUnits:-5,relativeToGround:!0,scaleByDistance:[100,4e6,1]}),this._centerLayer=new qs("centers",{pickingScale:3,pickingEnabled:!0,polygonOffsetUnits:-5,relativeToGround:!0,scaleByDistance:[100,4e6,1]}),this._outlineLayer=new qs("outline",{entities:[new Si({polyline:{path3v:[],isClosed:!1,...tn}})],pickingEnabled:!1,polygonOffsetUnits:-5,relativeToGround:!0}),this._outlineLayer.getEntities()[0].polyline.altitude=Qs,this._ghostCorner=new Si({geoObject:Js}),this._ghostOutlineLayer=new qs("ghost-pointer",{pickingEnabled:!1,polygonOffsetUnits:-5,relativeToGround:!0,scaleByDistance:[100,4e6,1],opacity:.5}),this._showGhostPointer=!1,this._isStartPoint=!1,this._insertCornerIndex=-1}get geometryType(){return"POLYGON"}getCoordinates(){let e=this._cornerLayer.getEntities();return e.length>0?e.map((e=>{let t=e.getLonLat();return[t.lon,t.lat,t.height]})):this._initCoordinates}bindPlanet(e){this._planet=e}init(){this._initEvents(),this._initGhostLayerPointer(),this._initCoordinates.length&&this.setCoordinates(this._initCoordinates),this._planet.addLayer(this._outlineLayer),this._planet.addLayer(this._cornerLayer),this._planet.addLayer(this._centerLayer),this.showGhostPointer(),this.startNewPoint(),this._geometryLayer.addTo(this._planet),this.events.on("change",this._onChange,this)}onremove(){this._clearEvents(),this.hideGhostPointer(),this.stopNewPoint(),this.clear(),this._geometryLayer.remove()}clear(){this._geometryLayer.clear();let e=this._cornerLayer.getEntities(),t=e.length;for(;t--;)e[t].remove();let i=this._centerLayer.getEntities();for(t=i.length;t--;)i[t].remove();let s=this._outlineLayer.getEntities();for(t=s.length;t--;)s[t].polyline.clear(),t>0&&s[t].remove();this._clearGhostPointer()}setCoordinates(e){this.clear();for(let t=0;t<e.length;t++){let i=e[t],s=this._planet.ellipsoid.lonLatToCartesian(new I(i[0],i[1],i[2]));this._appendCart(s)}this.events.dispatch(this.events.change,this)}stopNewPoint(){this.renderer&&this.renderer.events.off("ldblclick",this._onMouseDblClick)}startNewPoint(){this.renderer.events.on("ldblclick",this._onMouseDblClick,this)}showGhostPointer(){this._showGhostPointer=!0,this._planet.addLayer(this._ghostOutlineLayer),this._insertCornerIndex=this._cornerLayer.getEntities().length}hideGhostPointer(){this._showGhostPointer=!1,this._ghostOutlineLayer.remove(),this._insertCornerIndex=-1}setGhostPointerPosition(e){e&&(this._ghostCorner.setCartesian3v(e),this._updateGhostOutlinePointer(e))}_getLdown(e){this._planet.renderer.controls.mouseNavigation.deactivate(),this._startClick.set(e.x,e.y);let t=e.pickingObject.getCartesian();return this._startPos=this._planet.getPixelFromCartesian(t),e.pickingObject}_initEvents(){this._cornerLayer.events.on("ldblclick",this._onCornerLdblclick,this),this._cornerLayer.events.on("ldown",this._onCornerLdown,this),this._centerLayer.events.on("ldown",this._onCenterLdown,this),this.renderer.events.on("lup",this._onLup,this),this.renderer.events.on("mousemove",this._onMouseMove,this),this._cornerLayer.events.on("mouseenter",this._onCornerMouseEnter,this),this._cornerLayer.events.on("mouseleave",this._onCornerMouseLeave,this),this._centerLayer.events.on("mouseenter",this._onCenterMouseEnter,this),this._centerLayer.events.on("mouseleave",this._onCenterMouseLeave,this)}_clearEvents(){this._cornerLayer.events.off("ldblclick",this._onCornerLdblclick),this._cornerLayer.events.off("ldown",this._onCornerLdown),this._centerLayer.events.off("ldown",this._onCenterLdown),this.renderer.events.off("lup",this._onLup),this.renderer.events.off("mousemove",this._onMouseMove),this._cornerLayer.events.off("mouseenter",this._onCornerMouseEnter),this._cornerLayer.events.off("mouseleave",this._onCornerMouseLeave),this._centerLayer.events.off("mouseenter",this._onCenterMouseEnter),this._centerLayer.events.off("mouseleave",this._onCenterMouseLeave)}_drawCorners(){let e=this._cornerLayer.getEntities();for(let t=0;t<e.length;t++){let i=e[t];this._checkTerrainCollision(i)}}_drawCenters(){let e=this._centerLayer.getEntities();for(let t=0;t<e.length;t++){let i=e[t];this._checkTerrainCollision(i)}}_drawGhostCorner(){this._showGhostPointer&&this._checkTerrainCollision(this._ghostCorner)}frame(){this._drawCorners(),this._drawCenters(),this._drawGhostCorner()}_checkTerrainCollision(e){let t=new oe,i=this._planet._renderedNodes;for(let s=0;s<i.length;s++){let n=i[s].segment;if(n&&n._extentLonLat.isInside(e.getLonLat())){n.getEntityTerrainPoint(e,t),e.setCartesian3v(t);break}}}_moveCenterPoint(){let e=this.getCoordinates(),t=this._pickedCenter.layerIndex+1,i=this._pickedCenter.getLonLat(),s=[i.lon,i.lat,i.height];e.splice(t,0,s),this.setCoordinates(e),this._pickedCenter=null,this._pickedCorner=this._cornerLayer.getEntities()[t]}_addNew(e){if(-1===this._insertCornerIndex||this._cornerLayer.getEntities().length<2)this._appendCart(e);else{let t=this.getCoordinates(),i=this._insertCornerIndex,s=this._planet.ellipsoid.cartesianToLonLat(e),n=[s.lon,s.lat,s.height];t.splice(i,0,n),this.clear(),this.setCoordinates(t)}}_appendCart(e){let t=this._cornerLayer.getEntities(),i=t[t.length-1],s=new Si({geoObject:Js});if(s.setCartesian3v(e),s.addTo(this._cornerLayer),this._checkTerrainCollision(s),i){let e=t[0].getCartesian(),n=i.getCartesian(),r=s.getCartesian().sub(n),o=s.getCartesian().sub(e),a=r.length(),l=o.length();r.normalize(),o.normalize();let h=[],c=[];for(let t=0;t<=Ks;t++){let i=r.scaleTo(t*a/Ks).addA(n);h.push(i);let s=o.scaleTo(t*l/Ks).addA(e);c.push(s)}this._outlineLayer.getEntities()[0].polyline.setPath3v([c]);let d=new Si({polyline:{path3v:[h],isClosed:!1,...tn}});d.polyline.altitude=Qs,this._outlineLayer.add(d);let _=this._centerLayer.getEntities(),u=_[_.length-1],g=r.scaleTo(.5*a).addA(n),f=o.scaleTo(.5*l).addA(e),p=new Si({geoObject:en});p.setCartesian3v(g),p.addTo(this._centerLayer),this._checkTerrainCollision(p),u.remove(),u.addTo(this._centerLayer),u.setCartesian3v(f)}else{new Si({geoObject:en}).addTo(this._centerLayer)}}_clearGhostPointer(){const e=this._ghostOutlineLayer;e.getEntities()[0].polyline.clear(),e.getEntities()[1].polyline.clear()}_moveCornerPoint(e){let t=new ae(e.x,e.y).sub(this._startClick),i=this._startPos.add(t),s=this._planet.getCartesianFromPixelTerrain(i);if(s){this._pickedCorner.setCartesian3v(s);let e=this._cornerLayer.getEntities();if(e.length){let t=this._pickedCorner.layerIndex,i=e.length,s=e[0===t?i-1:t-1].getCartesian(),n=e[(t+1)%i].getCartesian(),r=this._pickedCorner.getCartesian().sub(s),o=this._pickedCorner.getCartesian().sub(n),a=r.length(),l=o.length();r.normalize(),o.normalize();let h=[],c=[];for(let e=0;e<=Ks;e++){let t=r.scaleTo(e*a/Ks).addA(s);h.push(t);let i=o.scaleTo(e*l/Ks).addA(n);c.push(i)}let d=this._outlineLayer.getEntities(),_=d[t].polyline,u=d[(t+1)%i].polyline;_?.setPath3v([h]),u?.setPath3v([c]);let g=this._centerLayer.getEntities(),f=g[0===t?i-1:t-1],p=g[t],m=r.scaleTo(.5*a).addA(s),v=o.scaleTo(.5*l).addA(n);f.setCartesian3v(m),this._checkTerrainCollision(f),p.setCartesian3v(v),this._checkTerrainCollision(p)}}}_updateGhostOutlinePointer(e){let t=this._cornerLayer.getEntities(),i=t.length;if(i>0){let s=0,n=o;for(let r=0;r<i;r++){let i=t[r].getCartesian().distance(e);i<n&&(n=i,s=r)}let r=t[s].getCartesian(),a=t[(s+1)%i].getCartesian(),l=t[0===s?i-1:s-1].getCartesian().sub(r).normalize(),h=a.sub(r).normalize(),c=e.sub(r).normalize(),d=l.add(h).normalize(),_=c.cross(d),u=l.cross(h);_.dot(u)>0&&(s--,s<0&&(s=i-1));let g=new oe;for(let r=0;r<i;r++){if(new di(t[r].getCartesian(),t[(r+1)%i].getCartesian()).getNearestDistancePoint(e,g)){let t=g.distance(e);t<n&&(n=t,s=r)}}this._insertCornerIndex=(s+1)%i;let f=t[s%i].getCartesian(),p=t[(s+1)%i].getCartesian(),m=this._ghostCorner.getCartesian().sub(f),v=this._ghostCorner.getCartesian().sub(p),y=m.length(),x=v.length();m.normalize(),v.normalize();let b=[],w=[];for(let e=0;e<=Ks;e++){let t=m.scaleTo(e*y/Ks).addA(f);b.push(t);let i=v.scaleTo(e*x/Ks).addA(p);w.push(i)}let C=this._ghostOutlineLayer.getEntities(),T=C[0].polyline,E=C[1].polyline;T?.setPath3v([b]),E?.setPath3v([w])}}_initGhostLayerPointer(){this._ghostOutlineLayer.setEntities([new Si({polyline:{path3v:[],isClosed:!1,...tn}}),new Si({polyline:{path3v:[],isClosed:!1,...tn}}),this._ghostCorner]);const e=this._ghostOutlineLayer;e.getEntities()[0].polyline.altitude=e.getEntities()[1].polyline.altitude=Qs}}class nn extends sn{constructor(e){super(e)}get geometryType(){return"LineString"}_addNew(e){this._appendCart(e)}_appendCart(e){let t=this._cornerLayer.getEntities(),i=t[t.length-1],s=new Si({geoObject:Js});if(s.setCartesian3v(e),s.addTo(this._cornerLayer),this._checkTerrainCollision(s),i){let e=i.getCartesian(),t=s.getCartesian().sub(e),n=t.length();t.normalize();let r=[];for(let i=0;i<=Ks;i++){let s=t.scaleTo(i*n/Ks).addA(e);r.push(s)}let o=new Si({polyline:{path3v:[r],isClosed:!1,...tn}});o.polyline.altitude=Qs,this._outlineLayer.add(o);let a=t.scaleTo(.5*n).addA(e),l=new Si({geoObject:en});l.setCartesian3v(a),l.addTo(this._centerLayer),this._checkTerrainCollision(l)}}_clearGhostPointer(){this._ghostOutlineLayer.getEntities()[0].polyline.clear()}_moveCorner(e,t,i){let s=this._cornerLayer.getEntities();if(0==s.length)return;1==s.length&&(e=t=i=0);let n=s[e].getCartesian(),r=this._pickedCorner.getCartesian().sub(n),o=r.length();r.normalize();let a=[];for(let e=0;e<=Ks;e++){let t=r.scaleTo(e*o/Ks).addA(n);a.push(t)}let l=this._outlineLayer.getEntities()[t].polyline;l?.setPath3v([a]);let h=this._centerLayer.getEntities()[i];if(h){let e=r.scaleTo(.5*o).addA(n);h.setCartesian3v(e),this._checkTerrainCollision(h)}}_moveCornerPoint(e){let t=new ae(e.x,e.y).sub(this._startClick),i=this._startPos.add(t),s=this._planet.getCartesianFromPixelTerrain(i);if(s){this._pickedCorner.setCartesian3v(s);let e=this._cornerLayer.getEntities();if(e.length){let t=this._pickedCorner.layerIndex;0===t?this._moveCorner(t+1,t+1,t):(t===e.length-1||this._moveCorner(t+1,t+1,t),this._moveCorner(t-1,t,t-1))}}}_updateGhostOutlinePointer(e){let t=this._cornerLayer.getEntities(),i=t.length;if(i>0){let e=i-1;this._insertCornerIndex=e;let s=t[e].getCartesian(),n=this._ghostCorner.getCartesian().sub(s),r=n.length();n.normalize();let o=[];for(let e=0;e<=Ks;e++){let t=n.scaleTo(e*r/Ks).addA(s);o.push(t)}this._ghostOutlineLayer.getEntities()[0].polyline.setPath3v([o])}}_initGhostLayerPointer(){this._ghostOutlineLayer.setEntities([new Si({polyline:{path3v:[],isClosed:!1,...tn}}),this._ghostCorner]),this._ghostOutlineLayer.getEntities()[0].polyline.altitude=Qs}}class rn extends Dt{constructor(e={}){super(e),this._drawingScene=new nn({name:`drawingScene:${this.__id}`})}activatePolygonDrawing(){this.deactivate(),this._drawingScene=new sn({name:`polygonDrawingScene:${this.__id}`}),this.activate()}activateLineStringDrawing(){this.deactivate(),this._drawingScene=new nn({name:`linestringDrawingScene:${this.__id}`}),this.activate()}oninit(){}onactivate(){this.planet&&this._drawingScene.bindPlanet(this.planet),this.renderer&&this.renderer.addNode(this._drawingScene)}ondeactivate(){this.renderer&&this.renderer.removeNode(this._drawingScene)}}const on={ell:0,msl:1,gnd:2},an=.3048,ln=1/an,hn=1/3.6,cn=.001*an,dn=1/cn,_n=["m","km","ft","s","h","m/s","km/h","ft/s"],un=[0,2,0,0,0,0,0,0];let gn=[];function fn(e,t,i){return gn[e][t](i)}function pn(e,t,i,s,n){return e?fn(t,i,s).toFixed(n||un[i]):"--"}function mn(e){return _n[e]}gn[0]=[],gn[0][0]=e=>e,gn[0][1]=e=>.001*e,gn[0][2]=e=>e*ln,gn[2]=[],gn[2][0]=e=>e*an,gn[2][1]=e=>e*cn,gn[2][2]=e=>e,gn[1]=[],gn[1][0]=e=>1e3*e,gn[1][1]=e=>e,gn[1][2]=e=>e*dn,gn[5]=[],gn[5][5]=e=>e,gn[5][6]=e=>3.6*e,gn[5][7]=e=>3.28084*e,gn[6]=[],gn[6][5]=e=>e*hn,gn[6][6]=e=>e;var vn=Object.freeze({__proto__:null,ELL:0,GND:2,MSL:1,_tenth:un,convert:fn,convertExt:pn,ft:2,fts:7,h:4,heightMode:on,km:1,kmh:6,m:0,ms:5,s:3,toString:mn});const yn=['<div class="og-lat-side"></div><div class="og-lat-val"></div>\n <div class="og-lon-side"></div><div class="og-lon-val"></div>\n <div class="og-height"></div>\n <div class="og-units-height"></div>','<div class="og-lat-side"></div><div class="og-lat-val"></div>\n <div class="og-lon-side"></div><div class="og-lon-val"></div>\n <div class="og-height"></div>\n <div class="og-units-height"></div>'];class xn extends Dt{constructor(e={}){super(e),this._type=e.type||0,this._TYPE_FUNC=[this._SHOW_DECIMAL,this._SHOW_DEGREE],this._showFn=null,this._el=null,this._latSideEl=null,this._lonSideEl=null,this._latValEl=null,this._lonValEl=null,this._heightEl=null,this._altUnitVal=e.altitudeUnit||"m",this._heightModeVal=e.heightMode||"ell",this._altUnit=vn[this._altUnitVal],this._heightMode=on[this._heightModeVal],this._lonLat=null,this._centerMode=null==e.centerMode||e.centerMode}_SHOW_DECIMAL(e){if(e){let t=e.lat,i=e.lon;this._latSideEl.innerHTML=t>=0?"N":"S",this._lonSideEl.innerHTML=i>=0?"E":"W",this._latValEl.innerHTML=Math.abs(t).toFixed(7)+"°",this._lonValEl.innerHTML=Math.abs(i).toFixed(7)+"°"}}_SHOW_DEGREE(e){if(e){let t=e.lat,i=e.lon;this._latSideEl.innerHTML=t>=0?"N":"S",this._lonSideEl.innerHTML=i>=0?"E":"W";let s=0,n=t<0?Math.ceil(t):Math.floor(t),r=Math.floor(s=60*Math.abs(t-n)),o=Math.floor(6e3*(s-r))/100;this._latValEl.innerHTML=Math.abs(n)+"°"+r+"'"+o.toFixed(0)+'"',n=i<0?Math.ceil(i):Math.floor(i),r=Math.floor(s=60*Math.abs(i-n)),o=Math.floor(6e3*(s-r))/100,this._lonValEl.innerHTML=Math.abs(n)+"°"+r+"'"+o.toFixed(0)+'"'}}_createCenterEl(){let e=document.createElement("div");return e.className="og-center-icon",e.innerHTML='<svg width="12" height="12"><g><path stroke-width="1" stroke-opacity="1" d="M6 0L6 12M0 6L12 6" stroke="#337ab7"></path></g></svg>',e}_updateUnits(){this._heightMode=on[this._heightModeVal],this._altUnit=vn[this._altUnitVal],this._el.querySelector(".og-units-height").innerHTML=mn(this._altUnit),this._showHeight()}_refreshCoordinates(){this._type>=this._TYPE_FUNC.length&&(this._type=0);let e=this._el;e.innerHTML=yn[this._type],this._latSideEl=e.querySelector(".og-lat-side"),this._lonSideEl=e.querySelector(".og-lon-side"),this._latValEl=e.querySelector(".og-lat-val"),this._lonValEl=e.querySelector(".og-lon-val"),this._heightEl=e.querySelector(".og-height"),this._showFn=this._TYPE_FUNC[this._type],this._showFn(this._lonLat)}oninit(){this._el=document.createElement("div"),this._el.classList.add("og-coordinates"),this.renderer.div.appendChild(this._el),this._el.addEventListener("click",(()=>{this._type++,this._refreshCoordinates(),this._updateUnits(),this._showHeight()})),this._centerMode?(this.renderer.div.appendChild(this._createCenterEl()),this.planet.camera.events.on("moveend",this._grabCoordinates,this),this.planet.camera.events.on("moveend",Ne((()=>this._showHeight()),400,!0),this)):(this.renderer.events.on("mousemove",this._grabCoordinates,this),this.renderer.events.on("mousestop",Ne((()=>this._showHeight()),400,!0),this)),this._refreshCoordinates(),this._updateUnits()}_grabCoordinates(e){let t,i=e.pos,s=this.renderer;t=this._centerMode?s.handler.getCenter():i,this._lonLat=this.planet.getLonLatFromPixelTerrain(t)||null,this._showFn(this._lonLat)}async _showHeight(){if(this._lonLat&&this.planet){let e=0;this._heightEl.style.opacity="0.7",this._heightMode===on.ell?(e=await this.planet.getHeightAboveELL(this._lonLat),e=Number(pn(!0,0,this._altUnit,e))):this._heightMode===on.msl&&(e=await this.planet.getHeightDefault(this._lonLat),e=Number(pn(!0,0,this._altUnit,e))),this._heightEl.style.opacity="1.0",this._heightEl.innerHTML=e.toString()}}}const bn=["loadend"];class wn extends $t{constructor(e,t={}){super(e,t),this.events=this.events.registerNames(bn),this._projType=0,this._frameWidth=256,this._frameHeight=256,this._sourceReady=!1,this._sourceTexture=null,this._materialTexture=null,this._gridBufferLow=null,this._gridBufferHigh=null,this._extentWgs84ParamsHigh=new Float32Array(4),this._extentWgs84ParamsLow=new Float32Array(4),this._extentMercParamsHigh=new Float32Array(4),this._extentMercParamsLow=new Float32Array(4),this._refreshFrame=!0,this._frameCreated=!1,this._sourceCreated=!1,this._animate=!1,this._ready=!1,this._creationProceeding=!1,this._isRendering=!1,this._extentWgs84=new te,this._cornersWgs84=[],this._cornersMerc=[],this._isFullExtent=t.fullExtent?1:0,this.rendering=this._renderingProjType0.bind(this),this._onLoadend_=null,t.corners&&this.setCorners(t.corners)}get isIdle(){return super.isIdle&&this._ready}addTo(e){return this._onLoadend_=this._onLoadend.bind(this),this.events.on("loadend",this._onLoadend_,this),super.addTo(e)}_onLoadend(){this._planet&&this._planet.events.dispatch(this._planet.events.layerloadend,this)}remove(){return this.events.off("loadend",this._onLoadend_),this._onLoadend_=null,super.remove()}get instanceName(){return"BaseGeoImage"}getCornersLonLat(){let e=this._cornersWgs84;return[new I(e[0].lon,e[0].lat),new I(e[1].lon,e[1].lat),new I(e[2].lon,e[2].lat),new I(e[3].lon,e[3].lat)]}getCorners(){let e=this._cornersWgs84;return[[e[0].lon,e[0].lat],[e[1].lon,e[1].lat],[e[2].lon,e[2].lat],[e[3].lon,e[3].lat]]}setCorners(e){this.setCornersLonLat(I.join(e))}setCornersLonLat(e){this._refreshFrame=!0,this._cornersWgs84=[e[0].clone(),e[1].clone(),e[2].clone(),e[3].clone()];for(let e=0;e<this._cornersWgs84.length;e++)this._cornersWgs84[e].lat>=89.9&&(this._cornersWgs84[e].lat=89.9),this._cornersWgs84[e].lat<=-89.9&&(this._cornersWgs84[e].lat=-89.9);this._extent.setByCoordinates(this._cornersWgs84);let t=this._extent;t.southWest.lat>Q||t.northEast.lat<J?(this._projType=0,this.rendering=this._renderingProjType0):(this._projType=1,this.rendering=this._renderingProjType1),this._ready&&!this._creationProceeding&&this._planet._geoImageCreator.add(this)}_createFrame(){this._extentWgs84=this._extent.clone(),this._cornersMerc=[this._cornersWgs84[0].forwardMercatorEPS01(),this._cornersWgs84[1].forwardMercatorEPS01(),this._cornersWgs84[2].forwardMercatorEPS01(),this._cornersWgs84[3].forwardMercatorEPS01()],this._extentMerc=new te(this._extentWgs84.southWest.forwardMercatorEPS01(),this._extentWgs84.northEast.forwardMercatorEPS01());let e=new Float32Array(2);if(0===this._projType?(ms(this._extentWgs84.southWest.lon,e),this._extentWgs84ParamsHigh[0]=e[0],this._extentWgs84ParamsLow[0]=e[1],ms(this._extentWgs84.southWest.lat,e),this._extentWgs84ParamsHigh[1]=e[0],this._extentWgs84ParamsLow[1]=e[1],this._extentWgs84ParamsHigh[2]=2/this._extentWgs84.getWidth(),this._extentWgs84ParamsHigh[3]=2/this._extentWgs84.getHeight()):(ms(this._extentMerc.southWest.lon,e),this._extentMercParamsHigh[0]=e[0],this._extentMercParamsLow[0]=e[1],ms(this._extentMerc.southWest.lat,e),this._extentMercParamsHigh[1]=e[0],this._extentMercParamsLow[1]=e[1],this._extentMercParamsHigh[2]=2/this._extentMerc.getWidth(),this._extentMercParamsHigh[3]=2/this._extentMerc.getHeight()),this._planet){let e=this._planet.renderer.handler;e.gl.deleteTexture(this._materialTexture),this._materialTexture=e.createEmptyTexture_l(this._frameWidth,this._frameHeight);let t=this._planet._geoImageCreator.createGridBuffer(this._cornersWgs84,1===this._projType);this._gridBufferHigh=t[0],this._gridBufferLow=t[1],this._refreshFrame=!1}}abortMaterialLoading(e){this._creationProceeding=!1,e.isLoading=!1,e.isReady=!1}clear(){let e=this._planet;if(e){let t=e.renderer.handler.gl;this._creationProceeding&&e._geoImageCreator.remove(this),e._clearLayerMaterial(this),t&&(t.deleteBuffer(this._gridBufferHigh),t.deleteBuffer(this._gridBufferLow),t.deleteTexture(this._sourceTexture),this._materialTexture&&!this._materialTexture.default&&t.deleteTexture(this._materialTexture))}this._sourceTexture=null,this._materialTexture=null,this._gridBufferHigh=null,this._gridBufferLow=null,this._refreshFrame=!0,this._sourceCreated=!1,this._ready=!1,this._creationProceeding=!1}setVisibility(e){e!==this._visibility&&(super.setVisibility(e),this._planet&&this._sourceReady&&(e?this._planet._geoImageCreator.add(this):this._planet._geoImageCreator.remove(this)))}clearMaterial(e){e.texture=null,e.isLoading=!1,e.isReady=!1}applyMaterial(e){let t,i,s=e.segment;this._ready?e.applyTexture(this._materialTexture):(e.texture=this._planet.transparentTexture,!this._creationProceeding&&this.loadMaterial(e)),0===this._projType?(t=this._extentWgs84,i=s._extent):(t=this._extentMerc,i=s.getExtentMerc());let n=t.northEast.lon-t.southWest.lon,r=t.northEast.lat-t.southWest.lat;return[(i.southWest.lon-t.southWest.lon)/n,(t.northEast.lat-i.northEast.lat)/r,(i.northEast.lon-i.southWest.lon)/n,(i.northEast.lat-i.southWest.lat)/r]}get getFrameWidth(){return this._frameWidth}get getFrameHeight(){return this._frameHeight}_createSourceTexture(){}_renderingProjType1(){let e=this._planet,t=e.renderer.handler,i=t.gl,s=e._geoImageCreator;this._refreshFrame&&this._createFrame(),this._createSourceTexture();let n=s._framebuffer;n.setSize(this._frameWidth,this._frameHeight),n.activate(),t.programs.geoImageTransform.activate();let r=t.programs.geoImageTransform._program,o=r.attributes,a=r.uniforms;i.disable(i.CULL_FACE),n.bindOutputTexture(this._materialTexture),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT),i.uniform1i(a.isFullExtent,this._isFullExtent),i.bindBuffer(i.ARRAY_BUFFER,s._texCoordsBuffer),i.vertexAttribPointer(o.texCoords,2,i.UNSIGNED_SHORT,!0,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferHigh),i.vertexAttribPointer(o.cornersHigh,this._gridBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferLow),i.vertexAttribPointer(o.cornersLow,this._gridBufferLow.itemSize,i.FLOAT,!1,0,0),i.uniform4fv(a.extentParamsHigh,this._extentMercParamsHigh),i.uniform4fv(a.extentParamsLow,this._extentMercParamsLow),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this._sourceTexture),i.uniform1i(a.sourceTexture,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,s._indexBuffer),i.drawElements(i.TRIANGLE_STRIP,s._indexBuffer.numItems,i.UNSIGNED_INT,0),n.deactivate(),i.enable(i.CULL_FACE),this._ready=!0,this._creationProceeding=!1}_renderingProjType0(){let e=this._planet,t=e.renderer.handler,i=t.gl,s=e._geoImageCreator;this._refreshFrame&&this._createFrame(),this._createSourceTexture();let n=s._framebuffer;n.setSize(this._frameWidth,this._frameHeight),n.activate(),t.programs.geoImageTransform.activate();let r=t.programs.geoImageTransform._program,o=r.attributes,a=r.uniforms;i.disable(i.CULL_FACE),n.bindOutputTexture(this._materialTexture),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT),i.bindBuffer(i.ARRAY_BUFFER,s._texCoordsBuffer),i.vertexAttribPointer(o.texCoords,2,i.UNSIGNED_SHORT,!0,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferHigh),i.vertexAttribPointer(o.cornersHigh,this._gridBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this._gridBufferLow),i.vertexAttribPointer(o.cornersLow,this._gridBufferLow.itemSize,i.FLOAT,!1,0,0),i.uniform4fv(a.extentParamsHigh,this._extentWgs84ParamsHigh),i.uniform4fv(a.extentParamsLow,this._extentWgs84ParamsLow),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this._sourceTexture),i.uniform1i(a.sourceTexture,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,s._indexBuffer),i.drawElements(i.TRIANGLE_STRIP,s._indexBuffer.numItems,i.UNSIGNED_INT,0),n.deactivate(),i.enable(i.CULL_FACE),this._ready=!0,this._creationProceeding=!1}}const Cn={MB_LEFT:0,MB_RIGHT:2,MB_MIDDLE:1,KEY_CTRL:17,KEY_ALT:18,KEY_SHIFT:16,KEY_SPACE:32,KEY_PGUP:33,KEY_PGDN:34,KEY_LEFT:37,KEY_UP:38,KEY_RIGHT:39,KEY_DOWN:40,KEY_PRINTSCREEN:44,KEY_EQUALS:61,KEY_A:65,KEY_C:67,KEY_D:68,KEY_E:69,KEY_F:70,KEY_H:72,KEY_I:73,KEY_K:75,KEY_L:76,KEY_N:78,KEY_O:79,KEY_P:80,KEY_Q:81,KEY_R:82,KEY_S:83,KEY_V:86,KEY_W:87,KEY_X:88,KEY_Z:90,KEY_PLUS:107,KEY_F1:112,KEY_MINUS:173,KEY_APOSTROPHE:192,KEY_BACK_SLASH:220,KEY_MORE:190,KEY_SLASH:191,KEY_LESS:188,KEY_LEFT_SQUARE_BRACKET:219,KEY_RIGHT_SQUARE_BRACKET:221,KEY_SINGLE_QUOTE:222};const Tn=["change","idle","play","pause","stop"];class En extends kt{constructor(e){super({template:we('<button title={title} class="og-layerSwitcher__layerButton">{icon}<div class="og-layerSwitcher__name">{name}</div></button>',{title:e.model.name,name:e.model.name,icon:e.model.iconSrc?`<img src="${e.model.iconSrc}" />`:""}),...e}),this._onVisibilityChange=e=>{this.el&&(this.model.getVisibility()?this.el.classList.add("og-layerSwitcher__visible"):this.el.classList.remove("og-layerSwitcher__visible"))},this._onClick=()=>{this.model.isBaseLayer()?this.model.setVisibility(!0):this.model.setVisibility(!this.model.getVisibility())},this._onDblClick=()=>{this.model.flyExtent()}}render(e){return super.render(e),this.model.events.on("visibilitychange",this._onVisibilityChange),this._onVisibilityChange(this.model),this.el.addEventListener("click",this._onClick),this.el.addEventListener("dblclick",this._onDblClick),this}remove(){super.remove(),this.model.events.off("visibilitychange",this._onVisibilityChange)}}const Ln=["change"];class An extends kt{constructor(e={}){super({template:we('<div class="og-slider">\n <div class="og-slider-label">{label}</div>\n <div class="og-slider-panel">\n <div class="og-slider-progress"></div> \n <div class="og-slider-pointer"></div>\n </div>\n <input type="number"/>\n </div>',{label:e.label||""})}),this._onResize=()=>{this._setOffset((this._value-this._min)*this.$panel.clientWidth/(this._max-this._min))},this._onMouseWheel=e=>{(e=e||window.event).preventDefault(),e.stopPropagation(),this.value=this._value+Math.sign(e.wheelDelta)*(this._max-this._min)/100},this._onMouseWheelFF=e=>{this._onMouseWheel(e)},this._onInput=e=>{(e=e||window.event).preventDefault(),e.stopPropagation(),this.value=parseFloat(e.target.value)},this._onMouseDown=e=>{(e=e||window.event).preventDefault(),this._startPosX=e.clientX,this.value=this._min+(this._max-this._min)*(e.offsetX/this.$panel.clientWidth),document.addEventListener("mousemove",this._onMouseMove),document.addEventListener("mouseup",this._onMouseUp)},this._onMouseMove=e=>{(e=e||window.event).preventDefault(),e.stopPropagation();let t=this.$panel.getBoundingClientRect(),i=m(e.clientX,t.left,t.right),s=this._startPosX-i;this._startPosX=i,this.value=this._value-s*(this._max-this._min)/this.$panel.clientWidth},this._onMouseUp=()=>{document.removeEventListener("mouseup",this._onMouseUp),document.removeEventListener("mousemove",this._onMouseMove)},this.events=this.events.registerNames(Ln),this._value=e.value||0,this._min=e.min||0,this._max=e.max||1,this._resizeObserver=new ResizeObserver(this._onResize),this._startPosX=0,this.$label=null,this.$pointer=null,this.$progress=null,this.$input=null,this.$panel=null}render(e){return super.render(e),this.$label=this.select(".og-slider-label"),""===this.$label.innerHTML&&(this.$label.style.display="none"),this.$pointer=this.select(".og-slider-pointer"),this.$progress=this.select(".og-slider-progress"),this.$panel=this.select(".og-slider-panel"),this.$input=this.select("input"),this._resizeObserver.observe(this.el),this._initEvents(),this}set value(e){e!==this._value&&(this._value=m(e,this._min,this._max),this.$input.value=this._value.toString(),this._setOffset((this._value-this._min)*this.$panel.clientWidth/(this._max-this._min)),this.events.dispatch(this.events.change,this._value,this))}get value(){return this._value}_initEvents(){this.$panel.addEventListener("mousedown",this._onMouseDown),this.$panel.addEventListener("mousewheel",this._onMouseWheel),this.$panel.addEventListener("wheel",this._onMouseWheelFF),this.$input.addEventListener("input",this._onInput)}_clearEvents(){this.$panel.removeEventListener("mousedown",this._onMouseDown),this.$panel.removeEventListener("mousewheel",this._onMouseWheel),this.$panel.removeEventListener("wheel",this._onMouseWheelFF),this.$input.removeEventListener("input",this._onInput)}_setOffset(e){e>=0&&e<=this.$panel.clientWidth&&(this.$pointer.style.left=this.$progress.style.width=100*e/this.$panel.clientWidth+"%")}remove(){this._clearEvents(),super.remove()}}const Pn=["input"];let Sn=0;class Mn extends kt{constructor(e={}){super({template:we('<div class="og-color">\n <label for="{id}" class="og-color-label">{label}</label>\n <input type="color" name="{id}" value="{value}"/>\n </div>',{id:"color-"+Sn++,label:e.label||"",value:e.value||"#000000"})}),this._onInput=e=>{this.value=e.target.value},this.events=this.events.registerNames(Pn),this._value=e.value||"blue",this.$label=null,this.$input=null}render(e){return super.render(e),this.$label=this.select(".og-color-label"),""===this.$label.innerHTML&&(this.$label.style.display="none"),this.$input=this.select("input"),this._initEvents(),this}set value(e){e!==this._value&&(this._value=e,this.$input.value=this._value,this.events.dispatch(this.events.input,this._value,this))}get value(){return this._value}_initEvents(){this.$input.addEventListener("input",this._onInput)}_clearEvents(){this.$input.removeEventListener("input",this._onInput)}remove(){this._clearEvents(),super.remove()}}class Rn{constructor(){this._lock=0}lock(e){this._lock|=1<<e.id}free(e){this._lock&=~(1<<e.id)}isFree(){return 0===this._lock}isLocked(){return 0!==this._lock}}class Bn{constructor(){this.__id=Bn.__counter__++}get id(){return this.__id}}Bn.__counter__=0;class kn extends Dt{constructor(e={}){super(e),this._deactivate=!1,this._shiftBusy=!1,this._name="mouseNavigation",this.grabbedPoint=new oe,this._eye0=new oe,this.pointOnEarth=new oe,this.earthUp=new oe,this.inertia=.007,this.grabbedSpheroid=new Pt,this.qRot=new re,this.scaleRot=0,this.distDiff=.3,this.stepsCount=8,this.stepsForward=null,this.stepIndex=0,this._lmbDoubleClickActive=!0,this.minSlope=e.minSlope||.1,this._wheelDirection=1,this._keyLock=new Bn}static getMovePointsFromPixelTerrain(e,t,i,s,n,r,o){const a=[];let l=e.eye.clone(),h=e.getBackward(),c=e.getRight(),d=e.getUp(),_=t.getCartesianFromPixelTerrain(n);if(_||(_=t.getCartesianFromPixelTerrain(t.renderer.handler.getCenter())),_){o||(o=oe.sub(_,e.eye).normalize());let t=s*e.eye.distance(_)/i;t*=r?-1.25:2;const n=h.scaleTo(t);if(o.dot(e.eye.normal().negate())>=.1){const t=new Pt;t.radius=_.length();let s=[],r=[],u=!1;for(let e=0;e<i;e++){l.addA(n);const i=new ui(l,o).hitSphere(t);if(r[e]=l.clone(),!i){u=!0;break}s[e]=(new ne).rotateBetweenVectors(_.normal(),i.normal())}if(u){l=e.eye.clone();for(let e=0;e<i;e++)a[e]={eye:l.addA(n).clone(),v:d,u:c,n:h}}else for(let e=0;e<i;e++){let t=s[e];a[e]={eye:t.mulVec3(r[e]),v:t.mulVec3(d),u:t.mulVec3(c),n:t.mulVec3(h)}}}else for(let e=0;e<i;e++)a[e]={eye:l.addA(o.scaleTo(-t)).clone(),v:d,u:c,n:h};return a}}onactivate(){this.renderer&&(this.renderer.events.on("mousewheel",this.onMouseWheel,this),this.renderer.events.on("lhold",this.onMouseLeftButtonDown,this),this.renderer.events.on("rhold",this.onMouseRightButtonDown,this),this.renderer.events.on("ldown",this.onMouseLeftButtonClick,this),this.renderer.events.on("lup",this.onMouseLeftButtonUp,this),this.renderer.events.on("rdown",this.onMouseRightButtonClick,this),this.renderer.events.on("draw",this.onDraw,this,-1e3),this.renderer.events.on("mousemove",this.onMouseMove,this),this.renderer.events.on("mouseleave",this.onMouseLeave,this),this.renderer.events.on("mouseenter",this.onMouseEnter,this),this._lmbDoubleClickActive&&this.renderer.events.on("ldblclick",this.onMouseLeftButtonDoubleClick,this))}ondeactivate(){this.renderer&&(this.renderer.events.off("mousewheel",this.onMouseWheel),this.renderer.events.off("lhold",this.onMouseLeftButtonDown),this.renderer.events.off("rhold",this.onMouseRightButtonDown),this.renderer.events.off("ldown",this.onMouseLeftButtonClick),this.renderer.events.off("lup",this.onMouseLeftButtonUp),this.renderer.events.off("rdown",this.onMouseRightButtonClick),this.renderer.events.off("draw",this.onDraw),this.renderer.events.off("ldblclick",this.onMouseLeftButtonDoubleClick),this.renderer.events.off("mouseleave",this.onMouseLeave),this.renderer.events.off("mouseenter",this.onMouseEnter))}activateDoubleClickZoom(){this._lmbDoubleClickActive||(this._lmbDoubleClickActive=!0,this.renderer&&this.renderer.events.on("ldblclick",this.onMouseLeftButtonDoubleClick,this))}deactivateDoubleClickZoom(){this._lmbDoubleClickActive&&(this._lmbDoubleClickActive=!1,this.renderer&&this.renderer.events.off("ldblclick",this.onMouseLeftButtonDoubleClick))}onMouseEnter(e){const t=this.renderer.events;t.isKeyPressed(Cn.KEY_ALT)&&t.releaseKeys(),t.updateButtonsStates(e.sys.buttons),t.mouseState.leftButtonDown?this.renderer.handler.canvas.classList.add("ogGrabbingPoiner"):this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner")}onMouseLeave(){this.renderer.events.mouseState.leftButtonDown&&(this.scaleRot=0),this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner")}onMouseWheel(e){this.stepIndex||(this.planet.stopFlying(),this.stopRotation(),this._deactivate=!0,this.lockPlanet(!0),this.stepsForward=kn.getMovePointsFromPixelTerrain(this.planet.camera,this.planet,this.stepsCount,this.distDiff,e.pos,e.wheelDelta>0,e.direction)||null,this._wheelDirection=e.wheelDelta,this.stepsForward&&(this.stepIndex=this.stepsCount))}oninit(){this.activate(),this.renderer&&(this.renderer.events.on("keyfree",Cn.KEY_ALT,this.onShiftFree,this),this.renderer.events.on("keyfree",Cn.KEY_PRINTSCREEN,this.onShiftFree,this))}onMouseLeftButtonDoubleClick(e){this.planet.stopFlying(),this.stopRotation();const t=this.planet.getCartesianFromPixelTerrain(e.pos);if(t){const e=this.planet.camera;let i=e.maxAltitude+this.planet.ellipsoid.polarSize,s=e.minAltitude+this.planet.ellipsoid.polarSize;const n=e.eye.length(),r=this.planet.ellipsoid.cartesianToLonLat(t);if(n>i||n<s)return void this.planet.flyLonLat(new I(r.lon,r.lat));this.renderer.events.isKeyPressed(Cn.KEY_ALT)?this.planet.flyLonLat(new I(r.lon,r.lat,2*e.eye.distance(t))):this.planet.flyLonLat(new I(r.lon,r.lat,.57*e.eye.distance(t)))}}onMouseLeftButtonClick(){this._active&&(this.renderer.handler.canvas.classList.add("ogGrabbingPoiner"),this.grabbedPoint=this.planet.getCartesianFromMouseTerrain(),this.grabbedPoint&&(this._eye0.copy(this.planet.camera.eye),this.grabbedSpheroid.radius=this.grabbedPoint.length(),this.stopRotation()))}stopRotation(){this.qRot.clear(),this.freePlanet()}onMouseLeftButtonUp(e){this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner"),e.x===e.prev_x&&e.y===e.prev_y&&(this.scaleRot=0)}onMouseLeftButtonDown(e){if(this._active){if(!this.grabbedPoint)return;if(this.planet.stopFlying(),e.moving){let t=this.planet.camera;if(t.slope>.2){const i=new ui(t.eye,e.direction).hitSphere(this.grabbedSpheroid);if(i){this.scaleRot=1,this.qRot=re.getRotationBetweenVectors(i.normal(),this.grabbedPoint.normal());let e=this.qRot;t.eye=e.mulVec3(t.eye),t.rotate(e)}}else{let i=this.grabbedPoint,s=oe.add(i,t.getRight()),n=oe.add(i,i.normal()),r=new oe;new ui(t.eye,e.direction).hitPlaneRes(_i.fromPoints(i,s,n),r)===ui.INSIDE&&(t.eye=this._eye0.addA(r.subA(i).negate()))}}}}onMouseRightButtonClick(e){this.stopRotation(),this.planet.stopFlying(),this.pointOnEarth=this.planet.getCartesianFromPixelTerrain(e.pos),this.pointOnEarth&&(this.earthUp=this.pointOnEarth.normal())}onMouseRightButtonDown(e){const t=this.planet.camera;if(this.pointOnEarth&&e.moving){this.renderer.controlsBag.scaleRot=1;let i=.5/t.eye.distance(this.pointOnEarth)*t._lonLat.height*l;i>.007?i=.007:i<.003&&(i=.003),t.rotateHorizontal(i*(e.x-e.prev_x),!1,this.pointOnEarth,this.earthUp),t.rotateVertical(i*(e.y-e.prev_y),this.pointOnEarth,this.minSlope)}}onShiftFree(){this._shiftBusy=!1}onMouseMove(e){this._active&&this.renderer.events.isKeyPressed(Cn.KEY_ALT)&&(this._shiftBusy||(this._shiftBusy=!0,this.onMouseRightButtonClick(e)),this.onMouseRightButtonDown(e))}onDraw(){if(this._active){const e=this.renderer,t=this.planet.camera;let i=t.eye.clone();if(this.stepIndex){e.controlsBag.scaleRot=1;const i=this.stepsForward[this.stepsCount-this.stepIndex--];t.eye=i.eye,t._u=i.v,t._r=i.u,t._b=i.n,t._f.set(-t._b.x,-t._b.y,-t._b.z)}else this._deactivate&&(this._deactivate=!1,this.freePlanet());if(e.events.mouseState.leftButtonDown||!this.scaleRot)return;if(this.scaleRot-=this.inertia,this.scaleRot<=0)this.scaleRot=0;else{e.controlsBag.scaleRot=this.scaleRot;let i=this.qRot.slerp(re.IDENTITY,1-this.scaleRot*this.scaleRot*this.scaleRot).normalize();i.x||i.y||i.z||(this.scaleRot=0),t.eye=i.mulVec3(t.eye),t.rotate(i)}t.eye.distance(i)/t.getAltitude()>.01?this.lockPlanet():this.freePlanet()}}lockPlanet(e){this.planet.layerLock.lock(this._keyLock),!e&&this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock)}freePlanet(){this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock)}}const In=.96;class zn extends Dt{constructor(e={}){super({name:"mouseNavigation",autoActivate:!0,...e}),this._shiftBusy=!1,this._hold=!1,this._prevVel=new oe,this._screenPosIsChanged=!0,this._onShiftFree=()=>{this._shiftBusy=!1},this._onMouseMove=e=>{this._active&&this.renderer.events.isKeyPressed(Cn.KEY_ALT)&&(this._shiftBusy||(this._shiftBusy=!0,this._onRHold(e)),this._onRDown(e))},this._onMouseEnter=e=>{const t=this.renderer.events;t.isKeyPressed(Cn.KEY_ALT)&&t.releaseKeys(),t.updateButtonsStates(e.sys.buttons),t.mouseState.leftButtonDown?this.renderer.handler.canvas.classList.add("ogGrabbingPoiner"):this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner")},this._onMouseLeave=()=>{this.renderer.events.mouseState.leftButtonDown&&this.vel.scale(0),this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner")},this._onRHold=e=>{this._targetRotationPoint&&(this._velInertia=.8,this.force_h=.2*(e.x-e.prev_x),this.force_v=.2*(e.y-e.prev_y))},this._onRDown=e=>{this.planet&&(this.planet.stopFlying(),this._targetRotationPoint=this._getTargetPoint(e.pos),this._targetRotationPoint&&(this._targetZoomPoint=null,this._targetDragPoint=null,this.vel.set(0,0,0),this._tUp=this._targetRotationPoint.getNormal(),this._tRad=this.planet.camera.eye.distance(this._targetRotationPoint)))},this._onMouseWheel=e=>{if(this.planet){this._targetRotationPoint=null,this._targetDragPoint=null;let t=this._getTargetPoint(e.pos);if(!t)return;if(this._targetZoomPoint=t,this._grabbedSphere.radius=this._targetZoomPoint.length(),this._curPitch=this.planet.camera.getPitch(),this._curYaw=this.planet.camera.getYaw(),this._curRoll=this.planet.camera.getRoll(),Math.sign(e.wheelDelta)!==this._wheelDirection)return this.vel.scale(.3),this._currScreenPos.set(e.x,e.y),void(this._wheelDirection=Math.sign(e.wheelDelta));this._currScreenPos.set(e.x,e.y),this._wheelDirection=Math.sign(e.wheelDelta);let i=2;this._isTouchPad=e.isTouchPad,e.isTouchPad?(this._velInertia=.88,i=.5):this._velInertia=In;let s=this.planet.camera.eye.distance(this._targetZoomPoint)*i;this.force=e.direction.scale(Math.sign(this._wheelDirection)).normalize().scale(s),this.force_roll=this._curRoll}},this._onLDown=e=>{this.stop(),this._targetRotationPoint=null,this._targetZoomPoint=null,this.planet&&(this.planet.stopFlying(),this._grabbedPoint=this._getTargetPoint(e.pos),this._grabbedPoint&&(this.renderer.handler.canvas.classList.add("ogGrabbingPoiner"),this._grabbedSphere.radius=this._grabbedPoint.length(),this._eye0=this.planet.camera.eye.clone(),this._grabbedCameraHeight=this._eye0.length(),this._curPitch=this.planet.camera.getPitch(),this._curYaw=this.planet.camera.getYaw(),this._curRoll=this.planet.camera.getRoll(),this._currScreenPos.copy(e.pos),this.planet.camera.getUp().dot(new oe(0,0,1))>.3&&(this.fixedUp=!0)))},this._onLHold=e=>{if(this._grabbedPoint&&this.planet){let t=this.planet.camera;if(t.slope>.2){let i=new ui(t.eye,e.direction).hitSphere(this._grabbedSphere);if(!i)return;this._targetDragPoint=i;let s=new oe,n=re.getRotationBetweenVectors(this._targetDragPoint.getNormal(),this._grabbedPoint.getNormal());s.copy(n.mulVec3(t.eye)),this.force=s.sub(t.eye).scale(70)}else{let i=this._grabbedPoint,s=oe.add(i,t.getRight()),n=oe.add(i,i.getNormal()),r=new oe;new ui(t.eye,e.direction).hitPlaneRes(_i.fromPoints(i,s,n),r);let o=t.eye.add(r.subA(i).negate());this.force=o.sub(t.eye).scale(70),this._targetDragPoint=r}this.vel.set(0,0,0),this._currScreenPos.equal(e.pos)||(this._screenPosIsChanged=!0,this._currScreenPos.copy(e.pos)),this._hold=!0}},this._onLUp=e=>{this._hold=!1,this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner")},this.speed=e.speed||1,this.force=new oe,this.force_h=0,this.force_v=0,this.vel=new oe,this.vel_h=0,this.vel_v=0,this.vel_roll=0,this.force_roll=0,this.mass=1,this._velInertia=In,this._lookPos=void 0,this._grabbedPoint=null,this._targetZoomPoint=null,this._targetDragPoint=null,this._targetRotationPoint=null,this._tUp=new oe,this._tRad=0,this._rotHDir=0,this._rotVDir=0,this._wheelDirection=1,this._currScreenPos=new ae,this._grabbedSphere=new Pt,this.fixedUp=null==e.fixedUp||e.fixedUp,this._rot=new re,this._curPitch=0,this._curYaw=0,this._curRoll=0,this._eye0=new oe,this._newEye=new oe,this._grabbedCameraHeight=0,this._isTouchPad=!1}oninit(){this.renderer&&(this.renderer.events.on("keyfree",Cn.KEY_ALT,this._onShiftFree),this.renderer.events.on("keyfree",Cn.KEY_PRINTSCREEN,this._onShiftFree))}onactivate(){super.onactivate();let e=this.renderer;e.events.on("mousewheel",this._onMouseWheel),e.events.on("rhold",this._onRHold),e.events.on("rdown",this._onRDown),e.events.on("lhold",this._onLHold),e.events.on("ldown",this._onLDown),e.events.on("lup",this._onLUp),e.events.on("draw",this.onDraw,this,-1e3),e.events.on("mousemove",this._onMouseMove),e.events.on("mouseleave",this._onMouseLeave),e.events.on("mouseenter",this._onMouseEnter)}ondeactivate(){super.ondeactivate();let e=this.renderer;e.events.off("mousewheel",this._onMouseWheel),e.events.off("rhold",this._onRHold),e.events.off("rdown",this._onRDown),e.events.off("lhold",this._onLHold),e.events.off("ldown",this._onLDown),e.events.off("lup",this._onLUp),e.events.off("draw",this.onDraw),e.events.off("mousemove",this._onMouseMove),e.events.off("mouseleave",this._onMouseLeave),e.events.off("mouseenter",this._onMouseEnter)}onDraw(){this._updateVel(),this._handleZoom(),this._handleDrag(),this._handleRotation()}_handleRotation(){if(this.planet&&this._targetRotationPoint){let e=this.planet.camera,t=this.vel_h*this.dt,i=this.vel_v*this.dt;e.rotateHorizontal(t,!1,this._targetRotationPoint,this._tUp),e.rotateVertical(i,this._targetRotationPoint,.1),this._curPitch=e.getPitch(),this._curYaw=e.getYaw(),this._curRoll=e.getRoll(),this._velInertia=In}}_getTargetPoint(e){return this.planet?this.planet.camera.getAltitude()>1e4?this.planet.getCartesianFromPixelEllipsoid(e)||null:this.planet.getCartesianFromPixelTerrain(e)||null:null}_handleDrag(){if(this.planet&&this._targetDragPoint&&this._grabbedPoint&&this.vel.length()>0){this._velInertia=In;let e=this.planet.camera;if(Math.abs(e.eyeNorm.dot(oe.NORTH))>.9&&(this.fixedUp=!1),this._screenPosIsChanged||this.vel.length()>this._prevVel.length()&&(this.fixedUp=!1),this._screenPosIsChanged=!1,this._prevVel.copy(this.vel),e.slope>.2){let t=this.vel.scaleTo(this.dt),i=oe.proj_b_to_plane(t,e.eyeNorm),s=e.eye.add(i).normalize().scale(this._grabbedCameraHeight);if(this.fixedUp)e.eye.copy(s),this._corrRoll(),e.setPitchYawRoll(this._curPitch,this._curYaw,this._curRoll);else{let t=re.getRotationBetweenVectors(e.eye.getNormal(),s.getNormal());e.rotate(t),e.eye.copy(s)}}else{let t=this.vel.scaleTo(this.dt),i=e.eye.add(t);e.eye.copy(i),e.checkTerrainCollision()}}}_corrRoll(){this.planet.camera.slope<.5&&(this._curRoll-=this.vel_roll*this.dt,this._curRoll<.01*Math.PI/180&&(this._curRoll=.01*Math.PI/180))}_handleZoom(){if(this._targetZoomPoint&&this.vel.length()>0){let e=this.planet.camera,t=this._targetZoomPoint,i=t.sub(e.eye).normalize(),s=e.eye.clone(),n=Math.sign(this.vel.getNormal().dot(e.getForward())),r=this.vel.scaleTo(this.dt).projToVec(e.getForward().scale(n)),o=e.eye.distance(t);if(10*r.length()>o){let e=r.length();r.normalize().scale(.5*e),this.vel.scale(.5)}s.addA(r);let a=e.maxAltitude+this.planet.ellipsoid.getEquatorialSize();if(s.length()>a)return void s.copy(s.getNormal().scale(a));let l=new ui(s,i).hitSphere(this._grabbedSphere);if(!l)return void this.vel.set(0,0,0);let h=re.getRotationBetweenVectors(l.getNormal(),t.getNormal());if(e.eye=h.mulVec3(s),e.rotate(h),this.fixedUp){this._corrRoll(),e.setPitchYawRoll(this._curPitch,this._curYaw,this._curRoll),e.update();let i=e.unproject2v(this._currScreenPos),s=t.sub(e.eye).normalize(),n=new oe,r=new oe,o=_i.fromPoints(t,t.add(e.getUp()),t.add(e.getRight()));new ui(e.eye,i).hitPlaneRes(o,n),new ui(e.eye,s).hitPlaneRes(o,r);let a=r.sub(n);e.eye=e.eye.add(a)}e.checkTerrainCollision()}}_updateVel(){let e=this.force.scale(1/this.mass);this.vel.addA(e),this.vel.scale(this._velInertia),this.vel.length()<.001&&this.vel.set(0,0,0),this.force.set(0,0,0),this._updateVel_h(),this._updateVel_v(),this._updateVel_roll()}_updateVel_h(){let e=this.force_h/this.mass;this.vel_h+=e,this.vel_h*=this._velInertia,this.force_h=0}_updateVel_v(){let e=this.force_v/this.mass;this.vel_v+=e,this.vel_v*=this._velInertia,this.force_v=0}_updateVel_roll(){let e=this.force_roll/this.mass;this.vel_roll+=e,this.vel_roll*=this._velInertia,this.force_roll=0}get dt(){return.001*this.renderer.handler.deltaTime}stop(){this.vel.set(0,0,0),this.vel_h=0,this.vel_v=0,this._velInertia=In,this._targetZoomPoint=null,this._grabbedPoint=null,this._targetRotationPoint=null,this._targetDragPoint=null}}const Dn=e=>e>1e3?`${(e/1e3).toFixed(1)} km`:e>9?`${Math.round(e)} m`:`${e.toFixed(1)} m`;let Fn=mi.createCylinder(1.1,0,2.7,20,1,!0,!1,0,0,0);const Nn={text:"",size:11,color:"rgba(455,455,455,1.0)",outlineColor:"rgba(0,0,0,0.34)",outline:.23,align:"center",offset:[0,20,0]},Hn={scale:1,instanced:!0,tag:"ruler",color:"rgb(0,305,0)",object3d:Fn};class On extends Ri{constructor(e={}){super(e.name),this._onCornerLdown=e=>{if(!this._startLonLat){this.renderer?.controls.mouseNavigation?.deactivate(),this._startClick.set(e.x,e.y);let t=e.pickingObject.getCartesian();this._startPos=this._planet.getPixelFromCartesian(t),this._pickedCorner=e.pickingObject,"start"==e.pickingObject.properties.name?this._anchorLonLat=this._cornerEntity[1].getLonLat().clone():this._anchorLonLat=this._cornerEntity[0].getLonLat().clone()}},this._onLUp=()=>{this._pickedCorner&&(this.renderer.controls.mouseNavigation?.activate(),this._pickedCorner=null,this._anchorLonLat=null)},this._onCornerLup=()=>{this._onLUp()},this._onCornerEnter=e=>{e.renderer.handler.canvas.style.cursor="pointer"},this._onCornerLeave=e=>{e.renderer.handler.canvas.style.cursor="default"},this._onLdblclick=()=>{this._preventClick=!0},this._onLclick=e=>{let t=this._planet.getLonLatFromPixelTerrain(e.pos);t&&(this._timeout=setTimeout((()=>{this._preventClick||(this._startLonLat?this._startLonLat=null:(this.setVisibility(!0),this._stopDrawing=!1,this._startLonLat=t)),this._preventClick=!1,this._stopDrawing=!1,clearTimeout(this._timeout)}),200),this._startLonLat&&(this._stopDrawing=!0))},this._onMouseMove=e=>{if(this._startLonLat&&!this._stopDrawing){this._propsLabel.label.setVisibility(!0);let t=this._planet.getLonLatFromPixelTerrain(e.pos);if(!t)return;this._drawLine(this._startLonLat,t)}else if(this._pickedCorner){let t=this._planet.getLonLatFromPixelTerrain(e.pos);t&&("start"===this._pickedCorner.properties.name?this._drawLine(t,this._anchorLonLat):this._drawLine(this._anchorLonLat,t))}},this.events=Mt(Vn),this._ignoreTerrain=null==e.ignoreTerrain||e.ignoreTerrain,this._planet=e.planet||null,this._startLonLat=null,this._preventClick=!1,this._stopDrawing=!1,this._pickedCorner=null,this._startPos=null,this._startClick=new ae,this._anchorLonLat=null,this._heading=0,this._trackLayer=new qs("track",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-1,relativeToGround:!0,hideInLayerSwitcher:!0}),this._labelLayer=new qs("ruler-label",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-100,relativeToGround:!0,hideInLayerSwitcher:!0}),this._cornersLayer=new qs("corners",{entities:[],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[100,4e6,1],pickingScale:2}),this._propsLabel=new Si({name:"propsLabel",label:Nn}),this._trackEntity=new Si({polyline:{path3v:[],thickness:4.8,color:"rgb(255,131,0)",isClosed:!1}}),this._trackEntity.polyline.altitude=.01,this._cornerEntity=[new Si({geoObject:Hn,properties:{name:"start"}}),new Si({geoObject:Hn,properties:{name:"end"}})]}set ignoreTerrain(e){this._ignoreTerrain=e}bindPlanet(e){this._planet=e}_createCorners(){this._cornersLayer.addEntities(this._cornerEntity)}init(){this._createCorners(),this._trackLayer.addEntities([this._trackEntity]),this._labelLayer.addEntities([this._propsLabel]),this._planet.addLayer(this._labelLayer),this._planet.addLayer(this._trackLayer),this._planet.addLayer(this._cornersLayer),this._activate()}onremove(){this._deactivate()}_activate(){this._propsLabel.label.setVisibility(!1),this.setVisibility(!1),this.renderer.events.on("lclick",this._onLclick,this),this.renderer.events.on("mousemove",this._onMouseMove,this),this.renderer.events.on("ldblclick",this._onLdblclick,this),this.renderer.events.on("lup",this._onLUp,this),this._cornersLayer.events.on("mouseenter",this._onCornerEnter,this),this._cornersLayer.events.on("mouseleave",this._onCornerLeave,this),this._cornersLayer.events.on("ldown",this._onCornerLdown,this),this._cornersLayer.events.on("lup",this._onCornerLup,this)}_deactivate(){this._startLonLat=null,this._preventClick=!1,this._stopDrawing=!1,this._pickedCorner=null,this.renderer.events.off("lclick",this._onLclick),this.renderer.events.off("mousemove",this._onMouseMove),this.renderer.events.off("lup",this._onLUp),this._cornersLayer.events.off("mouseenter",this._onCornerEnter),this._cornersLayer.events.off("mouseleave",this._onCornerLeave),this._cornersLayer.events.off("ldown",this._onCornerLdown),this._cornersLayer.events.off("lup",this._onCornerLup),this.clear()}setVisibility(e){this._cornersLayer.setVisibility(e),this._trackLayer.setVisibility(e),this._labelLayer.setVisibility(e)}_drawLine(e,t,i){i||(i=this._planet.ellipsoid.lonLatToCartesian(e));let s=this._planet.ellipsoid.lonLatToCartesian(t),n=this._planet.ellipsoid.inverse(e,t),r=n.distance;this._heading=n.initialAzimuth;let o=[],a=s.sub(i),l=a.length();a.normalize();for(let e=0;e<120;e++){let t=a.scaleTo(e*l/120).addA(i);o.push(t)}o.push(s),this._trackEntity.polyline.setPath3v([o]),this._ignoreTerrain&&(this._propsLabel.setCartesian3v(o[Math.floor(o.length/2)]),this._propsLabel.label.setText(`${Dn(r)}, ${Math.round(this._heading)} deg`))}clear(){this._trackEntity.remove(),this._cornerEntity[0].remove(),this._cornerEntity[1].remove(),this._propsLabel.remove(),this._planet.removeLayer(this._trackLayer),this._planet.removeLayer(this._cornersLayer)}isCornersPositionChanged(){let e=this._trackEntity.polyline.getPath3v()[0];if(e){const t=e[0].clone(),i=e[e.length-1].clone();return this._cornerEntity[0].getCartesian().equal(t)&&this._cornerEntity[1].getCartesian().equal(i)}return!1}frame(){let e=this._trackEntity.polyline.getPath3v()[0];if(e){const t=e[0].clone(),i=e[e.length-1].clone();if(!this.isCornersPositionChanged()&&(this._cornerEntity[0].setCartesian3v(t),this._cornerEntity[1].setCartesian3v(i),!this._ignoreTerrain)){let t=0;for(let i=0,s=e.length-1;i<s;i++)t+=e[i+1].distance(e[i]);this._propsLabel.setCartesian3v(e[Math.floor(e.length/2)]),this._propsLabel.label.setText(`${Dn(t)}, ${Math.round(this._heading)} deg`)}}}get ellipsoid(){return this._planet?this._planet.ellipsoid:null}}const Vn=["add","remove","mousemove","mouseenter","mouseleave","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchmove","touchstart","touchend","doubletouch","touchleave","touchenter"];class Un extends Dt{constructor(e={}){super(e),this._rulerScene=new On({name:`rulerScene:${this.__id}`,ignoreTerrain:e.ignoreTerrain})}set ignoreTerrain(e){this._rulerScene.ignoreTerrain=e}oninit(){this._rulerScene.bindPlanet(this.planet)}onactivate(){this.renderer&&this.renderer.addNode(this._rulerScene)}ondeactivate(){this.renderer&&this.renderer.removeNode(this._rulerScene)}}let Gn=mi.createCylinder(1.1,0,2,6,1,!0,!0,0,0,0);const Yn={startColor:"rgb(255,131,0)",endColor:"rgb(255,131,0)",thickness:5},jn={text:"",size:11,color:"rgba(455,455,455,1.0)",outlineColor:"rgba(0,0,0,0.34)",outline:.23,align:"center",offset:[0,18,0]},Wn={scale:1,instanced:!0,tag:"height-ruler",color:"rgb(255,131,0)",object3d:Gn};class qn extends On{constructor(e={}){super(e),this._geoRulerLayer=new qs("rayHeightRuler",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-2,relativeToGround:!1,hideInLayerSwitcher:!0}),this._rayV=new Si({name:"verticalRay",ray:Yn}),this._rayH=new Si({name:"heightRay",ray:Yn}),this._heightLabels=[new Si({name:"startCornerLabel",label:{...jn}}),new Si({name:"endCornerLabel",label:{...jn}}),new Si({name:"deltaLabel",label:{...jn}})]}setVisibility(e){super.setVisibility(e),this._geoRulerLayer.setVisibility(e)}get deltaLabel(){return this._heightLabels[2]}get startLabel(){return this._heightLabels[0]}get endLabel(){return this._heightLabels[1]}get corners(){return this._cornerEntity}get startCorner(){return this.corners[0]}get endCorner(){return this.corners[1]}get startCornerLonLat(){return this.startCorner.getLonLat()}get startCornerHeight(){return this.startCornerLonLat.height}get endCornerLonLat(){return this.endCorner.getLonLat()}get endCornerHeight(){return this.endCornerLonLat.height}get maxHeightCornerLonLat(){return this.startCornerHeight<=this.endCornerHeight?this.endCornerLonLat:this.startCornerLonLat}get minHeightCornerLonLat(){return this.startCornerHeight>this.endCornerHeight?this.endCornerLonLat:this.startCornerLonLat}get deltaHeight(){return Math.abs(this.startCornerHeight-this.endCornerHeight)}_drawLine(e,t,i){super._drawLine(e,t,i),this._updateHeightRaysAndLabels()}async _updateHeightRaysAndLabels(){const e=this.minHeightCornerLonLat.clone();e.height=this.maxHeightCornerLonLat.height,this._rayH.ray.setStartPosition3v(this._planet.ellipsoid.lonLatToCartesian(this.maxHeightCornerLonLat)),this._rayH.ray.setEndPosition3v(this._planet.ellipsoid.lonLatToCartesian(e)),this._rayV.ray.setStartPosition3v(this._planet.ellipsoid.lonLatToCartesian(this.minHeightCornerLonLat)),this._rayV.ray.setEndPosition3v(this._planet.ellipsoid.lonLatToCartesian(e)),e.height=this.minHeightCornerLonLat.height+this.deltaHeight/2,this.deltaLabel.setLonLat(e),this.startLabel.setLonLat(this.startCornerLonLat),this.endLabel.setLonLat(this.endCornerLonLat);const t=await this._planet.getHeightDefault(this.startCornerLonLat),i=await this._planet.getHeightDefault(this.endCornerLonLat);this.deltaLabel.label.setText(`Δ ${Math.abs(t-i).toFixed(1)} m`),this.startLabel.label.setText(`P1 ${t.toFixed(1)} m`),this.endLabel.label.setText(`P2 ${i.toFixed(1)} m`)}clear(){this._rayH.remove(),this._rayV.remove(),this.startCorner.remove(),this.endCorner.remove(),this.startLabel.remove(),this.endLabel.remove(),this.deltaLabel.remove(),super.clear(),this._planet.removeLayer(this._geoRulerLayer)}_createCorners(){this._cornerEntity=[new Si({geoObject:Wn,properties:{name:"start"}}),new Si({geoObject:Wn,properties:{name:"end"}})],this._cornersLayer.setEntities(this._cornerEntity)}init(){super.init(),this._createCorners(),this._labelLayer.addEntities(this._heightLabels),this._geoRulerLayer.addEntities([this._rayH,this._rayV]),this._planet.addLayer(this._geoRulerLayer)}frame(){super.frame(),this._updateHeightRaysAndLabels()}}class $n extends Un{constructor(e={}){super(e),this._rulerScene=new qn({name:`heightRulerScene:${this.__id}`,ignoreTerrain:!1})}}const Xn=[.001,.005,.01,.05,.1,.2,.5,1,2,3,5,10,20,30,50,100,200,300,500,1e3,2e3,3e3,5e3,1e4,2e4,3e4,5e4,1e5,2e5,3e5,5e5,1e6,2e6,3e6,5e6,1e7];class Zn extends Dt{constructor(e={}){e.name&&""!==e.name||(e.name="scaleControl"),super(e),this._template='<div class="og-scale-container">\n <div class="og-scale-label"></div>\n <div class="og-scale-ruler"></div>\n </div>',this._minWidth=100,this._maxWidth=150,this._isCenter=null==e.isCenter||e.isCenter,this._mPx=0,this.currWidth=0,this._metersInMinSize=0,this.el=null,this._scaleLabelEl=null}_renderTemplate(){return Ce(this._template)[0]}oninit(){this.el=this._renderTemplate(),this._scaleLabelEl=this.el.querySelector(".og-scale-label"),this.renderer.div.appendChild(this.el),this._isCenter?(this.planet.camera.events.on("moveend",(()=>{this._drawScreen(this.planet.renderer.handler.getCenter())})),!this.planet.terrain.isEmpty&&this.planet.terrain.events.on("loadend",(()=>{this._drawScreen(this.planet.renderer.handler.getCenter())}))):(this.renderer.events.on("mousemove",(e=>{e.leftButtonHold||e.rightButtonHold||this._drawScreen(e.pos)})),this.planet.camera.events.on("moveend",(()=>{let e=this.renderer.events.mouseState;e.leftButtonHold||e.rightButtonHold||this._drawScreen(e.pos)})))}_drawScreen(e){let t=this.planet.camera,i=e,s=this.planet.getDistanceFromPixel(i)||0;0===s&&(i=t.project3v(oe.ZERO),s=this.planet.getDistanceFromPixel(i)||0);let n=t.getForward().scaleTo(s).addA(t.eye),r=s*Math.tan(t.viewAngle*l),o=n.add(t.getRight().scaleTo(r)),a=t.project3v(o);this._mPx=r/a.distance(i);let h=this._mPx*this._minWidth,c=ke(Xn,h,((e,t)=>e-t));c<0&&(c=~c);let d=Xn[c],_=(d-h)/(Xn[c+1]-d);this.currWidth=this._minWidth+_*(this._maxWidth-this._minWidth),this._scaleLabelEl.innerText=d>=1e3?d/1e3+" km":d>=1?`${d} m`:d>=.01?100*d+" cm":1e3*d+" mm",this._metersInMinSize=h,this.el.style.width=this.currWidth+"px"}}class Kn extends Dt{constructor(e={}){super({name:"SimpleSkyBackground",...e}),this._colorOne=new Float32Array([128/255,223/255,1]),this._colorTwo=new Float32Array([10/255,15/255,56/255])}get colorOne(){let e=this._colorOne;return ve([Math.round(255*e[0]),Math.round(255*e[1]),Math.round(255*e[2])])}get colorTwo(){let e=this._colorTwo;return ve([Math.round(255*e[0]),Math.round(255*e[1]),Math.round(255*e[2])])}set colorOne(e){let t=be(e);this._colorOne[0]=t.x,this._colorOne[1]=t.y,this._colorOne[2]=t.z}set colorTwo(e){let t=be(e);this._colorTwo[0]=t.x,this._colorTwo[1]=t.y,this._colorTwo[2]=t.z}oninit(){this.renderer.handler.addProgram(new Ni("simpleSkyBackground",{uniforms:{iResolution:"vec2",fov:"float",camPos:"vec3",earthRadius:"float",viewMatrix:"mat4",colorOne:"vec3",colorTwo:"vec3"},attributes:{corners:"vec3"},vertexShader:"attribute vec2 corners;\n \n varying vec2 tc;\n \n void main(void) {\n gl_Position = vec4(corners, 0.0, 1.0);\n tc = corners * 0.5 + 0.5;\n }",fragmentShader:"precision highp float;\n \n #define MAX 10e10\n #define PI 3.14159265359\n #define rad(x) x * PI / 180.\n #define ZERO vec3(0.0) \n \n #define RED vec4(1.0, 0.0, 0.0, 1.0)\n #define GREEN vec4(0.0, 1.0, 0.0, 1.0) \n \n uniform vec3 camPos; \n uniform vec2 iResolution;\n uniform float fov;\n uniform float earthRadius;\n uniform mat4 viewMatrix;\n \n uniform vec3 colorOne;\n uniform vec3 colorTwo;\n \n varying vec2 tc;\n \n // compute the view ray in the camera coordinate\n vec3 computeView(vec2 uv){\n float w_h_ratio = iResolution.x / iResolution.y; \n float h = tan(rad(fov/2.));\n return normalize(vec3(-w_h_ratio * h, -h, -1.) + vec3(uv.x * 2. * h * w_h_ratio, uv.y*2.*h, 0.));\n }\n\n // sphere of size ra centered at point ce\n vec2 sphIntersect( in vec3 ro, in vec3 rd, in vec3 ce, float ra )\n {\n vec3 oc = ro - ce;\n float b = dot( oc, rd );\n float c = dot( oc, oc ) - ra * ra;\n float h = b * b - c;\n if( h < 0.0 ) return vec2(MAX); // no intersection\n h = sqrt( h );\n return vec2( -b-h, -b+h );\n }\n \n mat3 transpose(mat3 matrix) {\n vec3 row0 = matrix[0];\n vec3 row1 = matrix[1];\n vec3 row2 = matrix[2];\n mat3 result = mat3(\n vec3(row0.x, row1.x, row2.x),\n vec3(row0.y, row1.y, row2.y),\n vec3(row0.z, row1.z, row2.z)\n );\n return result;\n }\n \n float det(mat2 matrix) {\n return matrix[0].x * matrix[1].y - matrix[0].y * matrix[1].x;\n }\n \n mat3 inverse(mat3 matrix) {\n vec3 row0 = matrix[0];\n vec3 row1 = matrix[1];\n vec3 row2 = matrix[2];\n \n vec3 minors0 = vec3(\n det(mat2(row1.y, row1.z, row2.y, row2.z)),\n det(mat2(row1.z, row1.x, row2.z, row2.x)),\n det(mat2(row1.x, row1.y, row2.x, row2.y))\n );\n vec3 minors1 = vec3(\n det(mat2(row2.y, row2.z, row0.y, row0.z)),\n det(mat2(row2.z, row2.x, row0.z, row0.x)),\n det(mat2(row2.x, row2.y, row0.x, row0.y))\n );\n vec3 minors2 = vec3(\n det(mat2(row0.y, row0.z, row1.y, row1.z)),\n det(mat2(row0.z, row0.x, row1.z, row1.x)),\n det(mat2(row0.x, row0.y, row1.x, row1.y))\n );\n \n mat3 adj = transpose(mat3(minors0, minors1, minors2));\n \n return (1.0 / dot(row0, minors0)) * adj;\n }\n \n void main(void) {\n \n vec3 dir = computeView(tc);\n dir = inverse(mat3(viewMatrix)) * dir;\n \n vec2 ER = sphIntersect(camPos, dir, vec3(0.0), earthRadius);\n \n float bigRadius = earthRadius * 2.5;\n vec3 bigCenter = normalize(camPos) * bigRadius * 1.3; \n \n vec2 BIG = sphIntersect(camPos, dir, bigCenter, bigRadius);\n \n float Ix = distance(camPos + dir * BIG.y, ZERO); \n \n float maxI = sqrt(bigRadius * bigRadius + bigRadius * bigRadius);\n \n gl_FragColor = vec4(mix(colorOne, colorTwo, Ix / maxI), 1.0);\n }"})),this.activate()}onactivate(){super.onactivate(),this.planet.events.on("draw",this._drawBackground,this)}ondeactivate(){super.ondeactivate(),this.planet.events.off("draw",this._drawBackground)}_drawBackground(){let e=this.renderer.handler,t=e.programs.simpleSkyBackground,i=t._program,s=i.uniforms,n=e.gl,r=this.planet.camera;n.disable(n.DEPTH_TEST),t.activate(),n.bindBuffer(n.ARRAY_BUFFER,this.renderer.screenFramePositionBuffer),n.vertexAttribPointer(i.attributes.corners,2,n.FLOAT,!1,0,0),n.uniform3fv(s.camPos,[r.eye.x,r.eye.y,r.eye.z]),n.uniform2fv(s.iResolution,[e.getWidth(),e.getHeight()]),n.uniform1f(s.fov,r.getViewAngle()),n.uniform1f(s.earthRadius,this.planet.ellipsoid.getPolarSize()+1),n.uniform3fv(s.colorOne,this._colorOne),n.uniform3fv(s.colorTwo,this._colorTwo),n.uniformMatrix4fv(s.viewMatrix,!1,r.getViewMatrix()),n.drawArrays(n.TRIANGLE_STRIP,0,4),n.enable(n.DEPTH_TEST)}}const Qn=14959787e4;function Jn(e){var i=e-ft,s=282.9404+470935e-10*i,n=.016709-1.151e-9*i,r=A(356.047+.9856002585*i),o=23.4392911-3.563e-7*i,a=r+h*n*Math.sin(r*l)*(1+n*Math.cos(r*l)),c=Math.cos(a*l)-n,d=Math.sin(a*l)*Math.sqrt(1-n*n),_=Math.sqrt(c*c+d*d),u=A(Math.atan2(d,c)*h+s),g=c=_*Math.cos(u*l),f=(d=_*Math.sin(u*l))*Math.cos(o*l),p=d*Math.sin(o*l),m=t*(24*i/23.9344694-259.853/360);return re.zRotation(-m).mulVec3(new oe(-g*Qn,-f*Qn,p*Qn))}class er{constructor(e){this._renderNode=null,this._position=e.position||new oe,this._ambient=e.ambient||new oe,this._diffuse=e.diffuse||new oe(.8,.8,.8),this._specular=e.specular||new oe(.18,.18,.18),this._shininess=null!=e.shininess?e.shininess:3.3,this._active=!0,this._tempAmbient=this._ambient.clone(),this._tempDiffuse=this._diffuse.clone(),this._tempSpecular=this._specular.clone(),this._tempShininess=this._shininess}isActive(){return this._active}setPosition3v(e){this.setPosition(e.x,e.y,e.z)}setPosition(e,t,i){this._position.x=e,this._position.y=t,this._position.z=i,this._renderNode&&(this._renderNode._lightPosition[0]=e,this._renderNode._lightPosition[1]=t,this._renderNode._lightPosition[2]=i)}getPosition(){return this._position.clone()}setAmbient3v(e){this.setAmbient(e.x,e.y,e.z)}setDiffuse3v(e){this.setDiffuse(e.x,e.y,e.z)}setSpecular3v(e){this.setSpecular(e.x,e.y,e.z)}setAmbient(e,t,i){this._ambient.set(e,t,i);const s=this._renderNode;s&&(s._lightParams[0]=e,s._lightParams[1]=t,s._lightParams[2]=i)}setDiffuse(e,t,i){this._diffuse.set(e,t,i);const s=this._renderNode;s&&(s._lightParams[3]=e,s._lightParams[4]=t,s._lightParams[5]=i)}setSpecular(e,t,i){this._specular.set(e,t,i);const s=this._renderNode;s&&(s._lightParams[6]=e,s._lightParams[7]=t,s._lightParams[8]=i)}setShininess(e){this._shininess=e;const t=this._renderNode;t&&(t._lightShininess=e)}addTo(e){this._renderNode=e,this.setShininess(this._shininess),this.setAmbient3v(this._ambient),this.setDiffuse3v(this._diffuse),this.setSpecular3v(this._specular)}}class tr extends Dt{constructor(e={}){super({autoActivate:!0,...e}),this._name="sun",this.activationHeight=e.activationHeight||12079e3,this.offsetVertical=e.offsetVertical||-5e6,this.offsetHorizontal=e.offsetHorizontal||5e6,this.sunlight=new er({ambient:new oe(.15,.15,.25),diffuse:new oe(.9,.9,.8),specular:new oe(.1,.1,.06),shininess:110}),this._currDate=0,this._prevDate=0,this._clockPtr=null,this._lightOn=!1,this._f=0,this._k=0,this._stopped=e.stopped||!1}oninit(){this.planet.lightEnabled=!0,this.sunlight.addTo(this.planet),this.renderer.events.on("draw",this._draw,this),this._clockPtr||(this._clockPtr=this.renderer.handler.defaultClock)}stop(){this._stopped=!0,this.deactivate()}start(){this._stopped=!1,this.activate()}onactivate(){super.onactivate(),this._stopped=!1}bindClock(e){this._clockPtr=e}_draw(){if(this._clockPtr)if(this._currDate=this._clockPtr.currentDate,this._stopped)this.sunlight.setPosition3v(Jn(this._currDate));else{let e=this.planet.camera;if(e.getHeight()<this.activationHeight||!this._active){this._lightOn=!0,this._f=1;let t=e.eye.normal(),i=e.getForward();i.scale(Math.sign(e.getUp().dot(t))),e.slope>.99&&(i=e.getUp());let s=oe.proj_b_to_plane(i,t,i).normalize().scale(this.offsetVertical),n=oe.proj_b_to_plane(e.getRight(),t,e.getRight()).normalize().scale(this.offsetHorizontal),r=s.add(n),o=e.eye.add(r);if(this._k>0){this._k-=.001;let e=re.getRotationBetweenVectors(this.sunlight._position.normal(),o.normal()).slerp(re.IDENTITY,this._k).normalize();this.sunlight.setPosition3v(e.mulVec3(this.sunlight._position))}else this.sunlight.setPosition3v(o)}else if(this._k=1,this._f>0){this._f-=.001;let e=re.getRotationBetweenVectors(this.sunlight._position.normal(),Jn(this._currDate).normal()).slerp(re.IDENTITY,this._f).normalize();this.sunlight.setPosition3v(e.mulVec3(this.sunlight._position))}else(Math.abs(this._currDate-this._prevDate)>34e-5&&this._active||this._lightOn)&&(this._lightOn=!1,this._prevDate=this._currDate,this.sunlight.setPosition3v(Jn(this._currDate)),this._f=0)}}}class ir{constructor(){this.x=0,this.y=0,this.prev_x=0,this.prev_y=0,this.grabbedPoint=null,this.grabbedSpheroid=new Pt,this._vec=new ae,this._vecPrev=new ae}get dY(){return this.y-this.prev_y}get dX(){return this.x-this.prev_x}get vec(){return this._vec.set(this.x,this.y)}get vecPrev(){return this._vecPrev.set(this.prev_x,this.prev_y)}}class sr extends Dt{constructor(e={}){super(e),this._name="touchNavigation",this.grabbedPoint=new oe,this.inertia=.007,this.grabbedSpheroid=new Pt,this.planet=null,this.qRot=new re,this.scaleRot=0,this.rot=1,this._eye0=new oe,this.pointOnEarth=null,this.earthUp=null,this.touches=[new ir,new ir],this._keyLock=new Bn,this._touching=!1}oninit(){this.renderer&&(this.renderer.events.on("touchstart",this.onTouchStart,this),this.renderer.events.on("touchend",this.onTouchEnd,this),this.renderer.events.on("doubletouch",this.onDoubleTouch,this),this.renderer.events.on("touchcancel",this.onTouchCancel,this),this.renderer.events.on("touchmove",this.onTouchMove,this),this.renderer.events.on("draw",this.onDraw,this))}onTouchStart(e){const t=this.renderer.handler;if(this._touching=!0,2===e.sys.touches.length){const i=this.touches[0],s=this.touches[1];i.x=(e.sys.touches.item(0).clientX-e.sys.offsetLeft)*t.pixelRatio,i.y=(e.sys.touches.item(0).clientY-e.sys.offsetTop)*t.pixelRatio,i.prev_x=i.x,i.prev_y=i.y,i.grabbedPoint=this.planet.getCartesianFromPixelTerrain(new ae(i.x,i.y))||null,s.x=(e.sys.touches.item(1).clientX-e.sys.offsetLeft)*t.pixelRatio,s.y=(e.sys.touches.item(1).clientY-e.sys.offsetTop)*t.pixelRatio,s.prev_x=s.x,s.prev_y=s.y,s.grabbedPoint=this.planet.getCartesianFromPixelTerrain(new ae(s.x,s.y))||null,this.pointOnEarth=this.planet.getCartesianFromPixelTerrain(this.renderer.handler.getCenter())||null,this.pointOnEarth&&(this.earthUp=this.pointOnEarth.normal()),i.grabbedPoint&&s.grabbedPoint&&(i.grabbedSpheroid.radius=i.grabbedPoint.length(),s.grabbedSpheroid.radius=s.grabbedPoint.length(),this.stopRotation())}else 1===e.sys.touches.length&&this._startTouchOne(e)}_startTouchOne(e){const t=this.touches[0],i=this.renderer.handler;t.x=(e.sys.touches.item(0).clientX-e.sys.offsetLeft)*i.pixelRatio,t.y=(e.sys.touches.item(0).clientY-e.sys.offsetTop)*i.pixelRatio,t.prev_x=t.x,t.prev_y=t.y,t.grabbedPoint=this.planet.getCartesianFromPixelTerrain(e)||null,this._eye0.copy(this.planet.camera.eye),t.grabbedPoint&&(t.grabbedSpheroid.radius=t.grabbedPoint.length(),this.stopRotation())}stopRotation(){this.qRot.clear(),this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock)}onDoubleTouch(e){this.planet.stopFlying(),this.stopRotation();const t=this.planet.getCartesianFromPixelTerrain(e);if(t){const e=this.planet.ellipsoid.cartesianToLonLat(t);this.planet.flyLonLat(new I(e.lon,e.lat,.57*this.planet.camera.eye.distance(t)))}}onTouchEnd(e){0===e.sys.touches.length&&(this._touching=!1),1===e.sys.touches.length&&this._startTouchOne(e),Math.abs(this.touches[0].x-this.touches[0].prev_x)<3&&Math.abs(this.touches[0].y-this.touches[0].prev_y)<3&&(this.scaleRot=0)}onTouchCancel(e){}onTouchMove(e){let t=this.planet.camera;const i=this.renderer.handler;if(2===e.sys.touches.length){this.renderer.controlsBag.scaleRot=1;let n=this.touches[0],r=this.touches[1];if(!n.grabbedPoint||!r.grabbedPoint)return;this.planet.stopFlying(),n.prev_x=n.x,n.prev_y=n.y,n.x=(e.sys.touches.item(0).clientX-e.sys.offsetLeft)*i.pixelRatio,n.y=(e.sys.touches.item(0).clientY-e.sys.offsetTop)*i.pixelRatio,r.prev_x=r.x,r.prev_y=r.y,r.x=(e.sys.touches.item(1).clientX-e.sys.offsetLeft)*i.pixelRatio,r.y=(e.sys.touches.item(1).clientY-e.sys.offsetTop)*i.pixelRatio;const o=n.vec.add(r.vec).scale(.5),a=this.planet.getCartesianFromPixelTerrain(o);if(a){this.pointOnEarth=a;const e=Math.atan2(n.prev_y-r.prev_y,n.prev_x-r.prev_x),i=Math.atan2(n.y-r.y,n.x-r.x)-e,o=t.eye.distance(this.pointOnEarth),h=n.vec.sub(r.vec),c=n.vecPrev.sub(r.vecPrev);let d=o*-(1-h.length()/c.length());t.eye.addA(t.getForward().scale(d)),t.rotateAround(-i,!1,this.pointOnEarth,this.earthUp);const _=n.vec.add(r.vec).scale(.5),u=n.vecPrev.add(r.vecPrev).scale(.5),g=_.sub(u).scale(-1);var s=.5/o*t._lonLat.height*l;s>.003&&(s=.003),t.rotateHorizontal(s*-g.x,!1,this.pointOnEarth,this.earthUp),t.rotateVertical(s*-g.y,this.pointOnEarth),t.checkTerrainCollision(),t.update()}this.scaleRot=0}else if(1===e.sys.touches.length){let s=this.touches[0];if(s.prev_x=s.x,s.prev_y=s.y,s.x=(e.sys.touches.item(0).clientX-e.sys.offsetLeft)*i.pixelRatio,s.y=(e.sys.touches.item(0).clientY-e.sys.offsetTop)*i.pixelRatio,!s.grabbedPoint)return;this.planet.stopFlying();let n=e.direction,r=new ui(t.eye,n).hitSphere(s.grabbedSpheroid);if(r)if(t.slope>.2){this.qRot=re.getRotationBetweenVectors(r.normal(),s.grabbedPoint.normal());let e=this.qRot;t.eye=e.mulVec3(t.eye),t.rotate(e),t.checkTerrainCollision(),t.update(),this.scaleRot=1}else{let e=s.grabbedPoint,i=oe.add(e,t.getUp()),n=oe.add(e,e.getNormal()),r=t.unproject(s.x,s.y),o=new oe;new ui(t.eye,r).hitPlaneRes(_i.fromPoints(e,i,n),o)===ui.INSIDE&&(t.eye=this._eye0.addA(o.subA(e).negate()),t.checkTerrainCollision(),t.update(),this.scaleRot=0)}}}onDraw(){const e=this.renderer;if(e.controlsBag.scaleRot=this.scaleRot,this._touching)return;let t=this.planet.camera,i=t.eye.clone();if(!e.events.mouseState.leftButtonDown&&this.scaleRot){if(this.scaleRot-=this.inertia,this.scaleRot<=0)this.scaleRot=0;else{e.controlsBag.scaleRot=this.scaleRot;let i=this.qRot.slerp(re.IDENTITY,1-this.scaleRot*this.scaleRot*this.scaleRot).normalize();i.x||i.y||i.z||(this.scaleRot=0),t.eye=i.mulVec3(t.eye),t.rotate(i),t.checkTerrainCollision(),t.update()}t.eye.distance(i)/t.getAltitude()>.01?(this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock)):(this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock))}}}class nr extends Dt{constructor(e={}){super(e),this._keyLock=new Bn,this._move=0,this._targetPoint=null}oninit(){let e=new zt({classList:["og-map-button","og-zoomin-button"],icon:'<?xml version="1.0"?><svg width=24 height=24 xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> <path d="M 11 5 L 11 11 L 5 11 L 5 13 L 11 13 L 11 19 L 13 19 L 13 13 L 19 13 L 19 11 L 13 11 L 13 5 L 11 5 z"/></svg>'});e.appendTo(this.renderer.div);let t=new zt({classList:["og-map-button","og-zoomout-button"],icon:'<?xml version="1.0"?><svg width=24 height=24 xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"> <path d="M 5 11 L 5 13 L 19 13 L 19 11 L 5 11 z"/></svg>'});t.appendTo(this.renderer.div),e.events.on("mousedown",(()=>this.zoomIn())),e.events.on("mouseup",(()=>this.stopZoom())),t.events.on("mousedown",(()=>this.zoomOut())),t.events.on("mouseup",(()=>this.stopZoom())),e.events.on("touchstart",(()=>this.zoomIn())),e.events.on("touchend",(()=>this.stopZoom())),e.events.on("touchcancel",(()=>this.stopZoom())),t.events.on("touchstart",(()=>this.zoomOut())),t.events.on("touchend",(()=>this.stopZoom())),t.events.on("touchcancel",(()=>this.stopZoom())),this.renderer.events.on("draw",this._draw,this)}zoomIn(){this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock),this._targetPoint=this.renderer.getCenter(),this._move=1}zoomOut(){this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet._normalMapCreator.lock(this._keyLock),this._targetPoint=this.renderer.getCenter(),this._move=-1}stopZoom(){this._move=0,this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet._normalMapCreator.free(this._keyLock)}_draw(e){const t=this.planet.camera;if(0!==this._move){const i=this.planet.getCartesianFromPixelTerrain(e.getCenter());if(i){let e=.035*t.eye.distance(i);t.eye.addA(t.getForward().scale(this._move*e)),t.checkTerrainCollision(),t.update()}}}}class rr extends Ri{constructor(e={}){super(e.name),this._ignoreTerrain=!1,this.events=new Rt(or),this._ignoreTerrain=null==e.ignoreTerrain||e.ignoreTerrain,this._onSelect=e.onSelect||null,this._autoSelectionHide=e.autoSelectionHide||!1,this._planet=e.planet||null,this._startLonLat=null,this._heading=0,this._propsLabel=new Si({name:"propsLabel",label:{text:"",size:11,color:"rgba(455,455,455,1.0)",outlineColor:"rgba(0,0,0,0.34)",outline:.23,align:"center",offset:[0,18]}}),this._propsLabel?.label?.setVisibility(!1),this._trackEntity=new Si({polyline:{path3v:[],thickness:3.8,color:"rgb(455,455,455)",isClosed:!1}}),this._trackEntity.polyline.altitude=.01;let t=mi.createCylinder(1.1,0,2.7,20,1,!0,!1,0,0,0);this._cornerEntity=[new Si({geoObject:{scale:1,instanced:!0,tag:"selection",color:"rgb(0,305,0)",object3d:t},properties:{name:"start"}}),new Si({geoObject:{scale:1,instanced:!0,tag:"selection",color:"rgb(455,0,0)",object3d:t},properties:{name:"end"}})],this._trackLayer=new qs("track",{entities:[this._trackEntity,this._propsLabel],pickingEnabled:!1,polygonOffsetUnits:-1,relativeToGround:!0,hideInLayerSwitcher:!1}),this._cornersLayer=new qs("corners",{entities:[this._cornerEntity[0],this._cornerEntity[1]],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[1,4e6,.01],pickingScale:2})}set ignoreTerrain(e){this._ignoreTerrain=e}bindPlanet(e){this._planet=e}init(){this._activate()}onremove(){this._deactivate()}_activate(){this._propsLabel?.label?.setVisibility(!1),this._onMouseMove_=this._onMouseMove.bind(this),this.renderer?.events.on("mousemove",this._onMouseMove_,this),this._onMouseLdown_=this._onMouseLdown.bind(this),this.renderer?.events.on("ldown",this._onMouseLdown_,this),this._onMouseLup_=this._onMouseLup.bind(this),this.renderer?.events.on("lup",this._onMouseLup_,this),this._planet.addLayer(this._trackLayer),this._planet.addLayer(this._cornersLayer)}_deactivate(){this._startLonLat=null,this._trackLayer.remove(),this._cornersLayer.remove(),this.renderer?.events.off("mousemove",this._onMouseMove_),this.renderer?.events.off("ldown",this._onMouseLdown_),this.renderer?.events.off("lup",this._onMouseLup_),this.clear(),this._onMouseMove_=null,this._onMouseLdown_=null,this._onMouseLup_=null}_onMouseLdown(e){if(e.renderer.handler.canvas.classList.remove("ogGrabbingPoiner"),e.renderer.handler.canvas.style.cursor="pointer",!this._startLonLat){this._propsLabel.label?.setVisibility(!1),this._trackEntity.polyline?.setPath3v([]),this._cornerEntity[0].geoObject?.setVisibility(!0),this._cornerEntity[1].geoObject?.setVisibility(!0),this.renderer?.controls.mouseNavigation?.deactivate(),this._startLonLat=this._planet.getLonLatFromPixelTerrain(e);let t=this._planet.ellipsoid.lonLatToCartesian(this._startLonLat);this._cornerEntity[0].setCartesian3v(t),this._cornerEntity[1].setCartesian3v(t)}}_onMouseLup(e){if(this._startLonLat){if(this._pickedCorner=null,this._anchorLonLat=null,this._propsLabel.label?.setVisibility(!0),this._onSelect&&"function"==typeof this._onSelect){let e=this._cornerEntity[0].getLonLat(),t=this._cornerEntity[1].getLonLat(),i=[Math.min(e.lon,t.lon),Math.min(e.lat,t.lat),Math.max(e.lon,t.lon),Math.max(e.lat,t.lat)];this._onSelect(i)}this._autoSelectionHide&&this.clear(),this._startLonLat=null}e.renderer.handler.canvas.style.cursor="default",this.renderer?.controls.mouseNavigation?.activate()}_drawLine(e,t,i){i||(i=this._planet.ellipsoid.lonLatToCartesian(e));let s=this._planet.ellipsoid.lonLatToCartesian(t),n=this._planet.ellipsoid.direct(e,t);this._heading=n.initialAzimuth;let r=[];this._cornerEntity[0].setCartesian3v(i),this._cornerEntity[1].setCartesian3v(s);let o=[i,this._planet.ellipsoid.lonLatToCartesian(new I(t.lon,e.lat,e.height)),s,this._planet.ellipsoid.lonLatToCartesian(new I(e.lon,t.lat,e.height)),i];r.push(i);let a=(e,t)=>{let i=t.sub(e),s=i.length();i.normalize();for(let t=0;t<120;t++){let n=i.scaleTo(t*s/120).addA(e);r.push(n)}};for(let e=0;e<o.length-1;e++)a(o[e],o[e+1]);this._trackEntity.polyline?.setPath3v([r]),this._ignoreTerrain}_onMouseMove(e){if(this._startLonLat){this._propsLabel.label?.setVisibility(!0);let t=this._planet.getLonLatFromPixelTerrain(e);if(!t)return;this._drawLine(this._startLonLat,t)}}clear(){this._trackEntity.polyline?.clear(),this._cornerEntity[0].geoObject?.setVisibility(!1),this._cornerEntity[1].geoObject?.setVisibility(!1)}frame(){let e=this._trackEntity.polyline?.getPath3v()[0];if(e&&!this._ignoreTerrain){let i=0;for(let t=0,s=e.length-1;t<s;t++)i+=e[t+1].distance(e[t]);this._propsLabel.setCartesian3v(e[Math.floor(e.length/2)]),this._propsLabel.label?.setText(`${t=i,t>1e3?`${(t/1e3).toFixed(1)} km`:t>9?`${Math.round(t)} m`:`${t.toFixed(1)} m`}, ${Math.round(this._heading)} deg`)}var t}get ellipsoid(){return this._planet?this._planet.ellipsoid:null}}const or=["add","remove","mousemove","mouseenter","mouseleave","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchmove","touchstart","touchend","doubletouch","touchleave","touchenter"];function ar(e,t){return new Date(+e+1e3*t)}function lr(e,t=!0,i=!1){let s=_r[e.getMonth()],n=e.getUTCDate(),r=e.getUTCFullYear();if(t){let t=e.getUTCHours().toString().padStart(2,"0"),o=e.getUTCMinutes().toString().padStart(2,"0"),a=e.getUTCSeconds().toString().padStart(2,"0");if(i){return`${s} ${n} ${r} ${t}:${o}:${a}.${e.getUTCMilliseconds().toString().padStart(3,"0")}`}return`${s} ${n} ${r} ${t}:${o}:${a}`}return`${s} ${n} ${r}`}function hr(e,t=0,i=10,s=2,n="white"){e.lineWidth=s,e.strokeStyle=n,e.beginPath(),e.moveTo(t,0),e.lineTo(t,i),e.stroke()}function cr(e,t,i,s,n="12px Arial",r="black",o="left",a="bottom",h=0){e.save(),e.translate(i,s),e.rotate(h*l),e.fillStyle=r,e.textBaseline=a,e.font=n,e.textAlign=o,e.fillText(t,0,0),e.restore()}const dr=[[.001,10],[.002,10],[.005,10],[.01,10],[.02,10],[.05,10],[.1,10],[.25,10],[.5,5],[1,10],[2,10],[5,5],[10,10],[15,15],[30,6],[60,12],[120,12],[300,5],[600,10],[900,15],[1800,6],[3600,12],[7200,10],[14400,4],[21600,6],[43200,12],[86400,24],[172800,2],[345600,4],[604800,7],[1296e3,15],[2592e3,5],[5184e3,6],[7776e3,9],[15552e3,18],[31536e3,12],[63072e3,2],[126144e3,4],[15768e4,5],[31536e4,10],[63072e4,2],[126144e4,4],[15768e5,5],[31536e5,10],[63072e5,2],[126144e5,4],[15768e6,5],[31536e6,10]];const _r=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"],ur=["change","current"];class gr{constructor(e={}){this.events=Mt(ur),this._current=e.current||new Date,this._rangeStart=e.rangeStart||new Date,this._rangeEnd=e.rangeEnd||ar(this._rangeStart,3600),this._range=this._rangeEnd.getTime()-this._rangeStart.getTime(),this._minDate=e.minDate||null,this._maxDate=e.maxDate||null,this.multiplier=null!=e.multiplier?e.multiplier:1,this._requestAnimationFrameId=0,this._prevNow=0,this.dt=0}play(){this._requestAnimationFrameId||(this._prevNow=window.performance.now(),this._animationFrameCallback())}stop(){this._requestAnimationFrameId&&(window.cancelAnimationFrame(this._requestAnimationFrameId),this._requestAnimationFrameId=0)}stopped(){return 0==this._requestAnimationFrameId}_animationFrameCallback(){this._requestAnimationFrameId=window.requestAnimationFrame((()=>{this._frame(),this._animationFrameCallback()}))}_frame(){let e=window.performance.now();this.dt=e-this._prevNow,this._prevNow=e,this.current=new Date(this.currentTime+this.dt*this.multiplier)}get range(){return this._range}set(e,t){e===this._rangeStart&&t===this._rangeEnd||(this._rangeStart=e,this._rangeEnd=t,this._range=this._rangeEnd.getTime()-this._rangeStart.getTime(),this.events.dispatch(this.events.change,e,t))}get current(){return this._current}get rangeStart(){return this._rangeStart}get rangeEnd(){return this._rangeEnd}get rangeStartTime(){return this._rangeStart.getTime()}get rangeEndTime(){return this._rangeEnd.getTime()}get currentTime(){return this._current.getTime()}set current(e){e!==this._current&&(this._maxDate&&e>this._maxDate?this._current=this._maxDate:this._minDate&&e<this._minDate?this._current=this._minDate:this._current=e,this.events.dispatch(this.events.current,this._current))}set rangeStart(e){e!==this._rangeStart&&(this._rangeStart=e,this._range=this._rangeEnd.getTime()-this._rangeStart.getTime(),this.events.dispatch(this.events.change,e))}set rangeEnd(e){e!==this._rangeEnd&&(this._rangeEnd=e,this._range=this._rangeEnd.getTime()-this._rangeStart.getTime(),this.events.dispatch(this.events.change,e))}}const fr=.001,pr=["startdrag","stopdrag","startdragcurrent","stopdragcurrent","setcurrent","reset","play","playback","pause","visibility"],mr="#bfbfbf";class vr extends kt{constructor(e={}){super({template:'<div class="og-timeline">\n\n <div class="og-timeline-top">\n </div>\n\n <div class="og-timeline-frame">\n <div class="og-timeline-current">\n <div class="og-timeline-current-spin">\n <div class="og-timeline-current-arrow"></div>\n </div>\n </div>\n <div class="og-timeline-scale"></div>\n </div>\n\n <div class="og-timeline-bottom">\n <div class="og-timeline-controls">\n </div>\n </div>\n\n</div>',model:new gr({rangeStart:e.rangeStart,rangeEnd:e.rangeEnd,current:e.currentDate,minDate:e.minDate,maxDate:e.maxDate})}),this._onMouseWheel=e=>{if(this._isMouseOver){let t=this._canvasEl.getBoundingClientRect(),i=e.clientX-t.left,s=-(i-.5*this.clientWidth),n=this.model.rangeStartTime+this._millisecondsInPixel*i;this._zoom(n,s,Math.sign(e.wheelDelta))}else if(this._isCurrentMouseOver){let t=-((this.model.currentTime-this.model.rangeStartTime)/this._millisecondsInPixel-.5*this.clientWidth);this._zoom(this.model.currentTime,t,Math.sign(e.wheelDelta))}},this._onMouseWheelFF=e=>{this._onMouseWheel(e)},this._onMouseDown=e=>{this._isMouseOver?(this._isDragging=!0,document.body.classList.add("og-timeline-unselectable"),this._clickPosX=e.clientX,this._clickTime=Date.now(),this._clickRangeStart=this.model.rangeStart,this._clickRangeEnd=this.model.rangeEnd,this.events.dispatch(this.events.startdrag,e)):this._isCurrentMouseOver&&(this._isCurrentDragging=!0,document.body.classList.add("og-timeline-unselectable"),this._clickPosX=e.clientX,this._clickCurrentDate=this.model.current,this.events.dispatch(this.events.startdragcurrent,e))},this._onMouseUp=e=>{if(this._isDragging)if(this._isDragging=!1,document.body.classList.remove("og-timeline-unselectable"),this._clickPosX===e.clientX&&Date.now()-this._clickTime<this._clickDelay){let t=this._canvasEl.getBoundingClientRect(),i=new Date(this.model.rangeStartTime+(e.clientX-t.left)*this._millisecondsInPixel);this.model.current=i,this.events.dispatch(this.events.stopdrag,i),this.events.dispatch(this.events.setcurrent,i)}else this.events.dispatch(this.events.stopdrag,this.model.current);else this._isCurrentDragging&&(this._isCurrentDragging=!1,document.body.classList.remove("og-timeline-unselectable"),this.events.dispatch(this.events.stopdragcurrent,this.model.current))},this._onMouseEnter=()=>{this._isMouseOver=!0},this._onMouseOut=()=>{this._isMouseOver=!1},this._onCurrentMouseEnter=()=>{this._isCurrentMouseOver=!0},this._onCurrentMouseOut=()=>{this._isCurrentMouseOver=!1},this._onMouseMove=e=>{if(this._isDragging){let t=(this._clickPosX-e.clientX)*this._millisecondsInPixel*fr;this.model.set(ar(this._clickRangeStart,t),ar(this._clickRangeEnd,t))}else if(this._isCurrentDragging){let t=(this._clickPosX-e.clientX)*this._millisecondsInPixel*fr,i=ar(this._clickCurrentDate,-t);i>=this.model.rangeStart&&i<=this.model.rangeEnd&&(this.model.current=ar(this._clickCurrentDate,-t))}},this.events=this.events.registerNames(pr),this.fillStyle=e.fillStyle||"rgba(64, 59, 59, 1.0)",this.$controls=null,this._frameEl=null,this._currentEl=null,this._canvasEl=document.createElement("canvas"),this._ctx=this._canvasEl.getContext("2d"),this._isMouseOver=!1,this._isDragging=!1,this._isCurrentDragging=!1,this._isCurrentMouseOver=!1,this._minWidth=330,this._canvasScale=2,this._millisecondsInPixel=0,this._clickPosX=0,this._clickRangeStart=new Date,this._clickRangeEnd=new Date,this._clickCurrentDate=new Date,this._clickTime=0,this._clickDelay=450,this._onResizeObserver_=this._onResizeObserver.bind(this),this._resizeObserver=new ResizeObserver(this._onResizeObserver_),this._pauseBtn=new Ut({classList:["og-timeline-control_button"],icon:'<?xml version="1.0" ?><!DOCTYPE svg PUBLIC \'-//W3C//DTD SVG 1.1//EN\' \'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\'><svg enable-background="new 0 0 512 512" height="512px" version="1.1" viewBox="0 0 512 512" width="512px" xml:space="preserve" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><g id="Layer_6"><rect fill="#252525" height="320" width="60" x="153" y="96"/><rect fill="#252525" height="320" width="60" x="299" y="96"/></g></svg>',name:"pause"}),this._playBtn=new Ut({classList:["og-timeline-control_button"],icon:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M8 5v14l11-7z" style="fill: black;"/></svg>',name:"play"}),this._buttons=new Jt({buttons:[this._pauseBtn,this._playBtn]}),this._visibility=!1}_onResizeObserver(){this.resize()}get canvasScale(){return this._canvasScale}set canvasScale(e){e!==this._canvasScale&&(this._canvasScale=e,this.resize())}resize(){this._resize(),this.draw()}afterRender(e){this.resize()}render(){return super.render(),this.$controls=this.select(".og-timeline-controls"),this._frameEl=this.select(".og-timeline-frame"),this._currentEl=this.select(".og-timeline-current"),this.select(".og-timeline-frame .og-timeline-scale").appendChild(this._canvasEl),this._resizeObserver.observe(this.el),this.model.events.on("change",(()=>{this.draw()})),this.model.events.on("current",(e=>{this._drawCurrent(),this.events.dispatch(this.events.setcurrent,e)})),this._canvasEl.addEventListener("mouseenter",this._onMouseEnter),this._canvasEl.addEventListener("mouseout",this._onMouseOut),this._currentEl.addEventListener("mouseenter",this._onCurrentMouseEnter),this._currentEl.addEventListener("mouseout",this._onCurrentMouseOut),document.body.addEventListener("mousemove",this._onMouseMove),document.body.addEventListener("mousedown",this._onMouseDown),document.body.addEventListener("mouseup",this._onMouseUp),document.body.addEventListener("wheel",this._onMouseWheelFF),this._playBtn.appendTo(this.$controls),this._pauseBtn.appendTo(this.$controls),this.model.stopped()?(this._pauseBtn.setActive(!0,!0),this._pauseBtn.preventClick=!0):(this._playBtn.setActive(!0,!0),this._playBtn.preventClick=!0),this._buttons.events.on("change",(e=>{switch(e.name){case"play":this.play();break;case"pause":this.pause()}})),this.setVisibility(!0),this}setVisibility(e){e!==this._visibility&&(this._visibility=e,this.el&&(this.el.style.display=e?"block":"none"),this.events.dispatch(this.events.visibility,e))}reset(){this.model.stop(),this.events.dispatch(this.events.reset,this.model)}play(){this.model.multiplier=Math.abs(this.model.multiplier),this.model.play(),this.events.dispatch(this.events.play,this.model)}pause(){this.model.stop(),this.events.dispatch(this.events.pause,this.model)}playBack(){this.model.multiplier=-1*Math.abs(this.model.multiplier),this.model.play(),this.events.dispatch(this.events.playback,this.model)}_zoom(e,t,i){let s=(e-(this.model.rangeStartTime+.5*this.model.range))*fr,n=ar(this.model.rangeStart,s),r=ar(this.model.rangeEnd,s),o=(r.getTime()-n.getTime())/20*fr,a=ar(n,o*i),l=ar(r,-o*i),h=(l.getTime()-a.getTime())/this.clientWidth;if(h<31536e6&&h>.1){let e=h*t*fr;this.model.set(ar(a,e),ar(l,e))}}get clientWidth(){return this._canvasEl?this._canvasEl.width/this._canvasScale:0}get clientHeight(){return this._canvasEl?this._canvasEl.height/this._canvasScale:0}_resize(){this._frameEl&&(this._canvasEl.width=this._frameEl.clientWidth*this._canvasScale,this._canvasEl.height=this._frameEl.clientHeight*this._canvasScale,this._canvasEl.style.width=`${this._frameEl.clientWidth}px`,this._canvasEl.style.height=`${this._frameEl.clientHeight}px`)}getOffsetByTime(e){return(e-this.model.rangeStartTime)/this._millisecondsInPixel}remove(){super.remove(),this.model.stop()}_clearCanvas(){this._ctx.fillStyle=this.fillStyle,this._ctx.fillRect(0,0,this.clientWidth*this._canvasScale,this.clientHeight*this._canvasScale)}_drawCurrent(){let e=(this.model.currentTime-this.model.rangeStartTime)/this._millisecondsInPixel;this.model.current<this.model.rangeStart||this.model.current>this.model.rangeEnd?this._currentEl.style.display="none":(this._currentEl.style.display="block",this._currentEl.style.transform=`translateX(${e}px)`)}draw(){this._millisecondsInPixel=this.model.range/this.clientWidth;let e=function(e){for(let t=0,i=dr.length;t<i;t++)if(dr[t][0]>e)return dr[t-1]}(this._minWidth*this._millisecondsInPixel*fr);if(e){this._clearCanvas();let i=1e3*e[0],s=i/this._millisecondsInPixel,n=e[1],r=(t=this.model.rangeStartTime)-t%i,o=e[0]<1,a=e[0]<86400;for(let e=r,t=this.model.rangeEndTime+i;e<t;e+=i){let t=this.getOffsetByTime(e);t>=0&&t<=this.clientWidth*this._canvasScale&&hr(this._ctx,t*this._canvasScale,10*this._canvasScale,2*this._canvasScale,mr);for(let e=1;e<n;e++){let i=t+e*(s/n);i>=0&&i<=this.clientWidth*this._canvasScale&&hr(this._ctx,i*this._canvasScale,5*this._canvasScale,1*this._canvasScale,mr)}cr(this._ctx,lr(new Date(e),a,o),t*this._canvasScale,26*this._canvasScale,"24px monospace","#bfbfbf","center")}this._drawCurrent()}var t}}function yr(e,t){const i=new Date(e);return i.setHours(i.getHours()+t),i}class xr{constructor(){this.resolve=()=>{},this.reject=()=>{},this.promise=new Promise(((e,t)=>{this.resolve=e,this.reject=t})),Object.freeze(this)}}const br=["startcollecting","profilecollected","clear"];class wr{constructor(e={}){this.events=Mt(br),this.planet=e.planet||null,this._warningHeightLevel=5,this._pointsReady=!1,this._isWarning=!1,this._minX=0,this._planeDistance=this._maxX=1e3,this._minY=0,this._maxY=200,this._drawData=[[],[]],this._promiseArr=[],this._promiseCounter=0,this._pMaxY=0,this._pMinY=0,this._pDist=0,this._pTrackCoords=[],this._pGroundCoords=[],this._pIndex=0}bindPlanet(e){this.planet=e}setWarningHeightLevel(e=0){this._warningHeightLevel=e}setRange(e,t,i,s){this._minX=e,this._maxX=t,i&&(this._minY=i),s&&(this._maxY=s)}_getHeightAsync(e,t,i){let s=new xr;if(this.planet){let n=this.planet.terrain.geoid.getHeightLonLat(e);this.planet.terrain.getHeightAsync(e,(r=>{this.planet&&i===this._promiseCounter?(r+=n,this._pGroundCoords[t][1]=r,this._pGroundCoords[t][2]=0,this._pGroundCoords[t][3]=e.height,r>this._pMaxY&&(this._pMaxY=r),r<this._pMinY&&(this._pMinY=r),this._updatePointType(t),s.resolve(r)):s.reject()}))}else s.reject();return s.promise}_collectCoordsBetweenTwoTrackPoints(e,t,i,s,n,r){if(this.planet)for(let o=1;o<=t;o++){this._pDist+=1,this._pIndex++;let t=o*i,a=s.add(n.scaleTo(t)),l=this.planet.ellipsoid.cartesianToLonLat(a);this._pGroundCoords[this._pIndex]=[this._pDist,0,0,0,e],((e,t)=>{this._promiseArr.push(this._getHeightAsync(e,t,r))})(l,this._pIndex)}}_collectAllPoints(e,t){if(!this.planet)return;if(t!==this._promiseCounter)return;let i=new oe,s=new oe;for(let n=1,r=e.length;n<r;n++){let r=e[n-1],o=e[n];this.planet.ellipsoid.lonLatToCartesianRes(r,i),this.planet.ellipsoid.lonLatToCartesianRes(o,s);let a=s.sub(i),l=a.length(),h=this.planet.ellipsoid.getSurfaceNormal3v(i),c=oe.proj_b_to_plane(a,h),d=c.length(),_=Math.floor(d/1),u=1*l/d;this._getGroundElevation(r,n-1,t),c.normalize(),a.normalize(),this._collectCoordsBetweenTwoTrackPoints(n-1,_,u,i,a,t),this._pDist+=d-1*_,this._pIndex++;let g=o.height;g>this._pMaxY&&(this._pMaxY=g),g<this._pMinY&&(this._pMinY=g),this._pTrackCoords[n]=[this._pDist,g,this._pIndex]}}_getGroundElevation(e,t,i){this._pGroundCoords[this._pIndex]=[this._pDist,0,0,0,t],this._promiseArr.push(this._getHeightAsync(e,this._pIndex,i))}_calcPointsAsync(e,t){return new Promise(((i,s)=>{this._pTrackCoords=[[0,e[0].height,0]],this._pMaxY=e[0].height,this._pMinY=this._pMaxY,this._pDist=0,this._pGroundCoords=[],this._pIndex=0,this._promiseArr=[],this._collectAllPoints(e,t),this._getGroundElevation(e[e.length-1],e.length-1,t),Promise.all(this._promiseArr).then((()=>{i({dist:this._pDist,minY:this._pMinY,maxY:this._pMaxY,trackCoords:this._pTrackCoords,groundCoords:this._pGroundCoords})}))}))}get minX(){return this._minX}get planeDistance(){return this._planeDistance}get maxX(){return this._maxX}get minY(){return this._minY}get maxY(){return this._maxY}get pointsReady(){return this._pointsReady}get isWarningOrCollision(){return this._isWarning}get drawData(){return this._drawData}collectProfile(e){let t=new xr;return this.planet||t.reject(),this._pointsReady=!1,this._isWarning=!1,e&&e.length?(this.events.dispatch(this.events.startcollecting,this),this._promiseCounter++,(i=>{this._calcPointsAsync(e,i).then((e=>{i===this._promiseCounter&&(this._planeDistance=e.dist,this.setRange(0,e.dist,e.minY-.1*Math.abs(e.minY),e.maxY+.2*Math.abs(e.maxY)),this._pointsReady=!0,this._drawData=[e.trackCoords,e.groundCoords],this.events.dispatch(this.events.profilecollected,this._drawData,this),t.resolve(this._drawData))}))})(this._promiseCounter),t.promise):(t.reject(),t.promise)}_updatePointType(e){this._pGroundCoords[e][3]>=this._pGroundCoords[e][1]&&this._pGroundCoords[e][3]<this._pGroundCoords[e][1]+this._warningHeightLevel-.1&&(this._pGroundCoords[e][2]=1),this._pGroundCoords[e][3]<=this._pGroundCoords[e][1]+1&&(this._pGroundCoords[e][2]=2),1!==this._pGroundCoords[e][2]&&2!==this._pGroundCoords[e][2]||(this._isWarning=!0)}_setPointsType(){this._isWarning=!1,this._pTrackCoords=this._drawData[0],this._pGroundCoords=this._drawData[1];for(let e=0;e<this._pGroundCoords.length;e++)this._updatePointType(e);this._drawData[1]=this._pGroundCoords,this.events.dispatch(this.events.profilecollected,this._drawData,this)}clear(){this._promiseCounter=0,this._pointsReady=!1,this._isWarning=!1,this._drawData=[[],[]],this._pMaxY=0,this._pMinY=0,this._pDist=0,this._pTrackCoords=[],this._pGroundCoords=[],this._pIndex=0,this.events.dispatch(this.events.clear,this._drawData,this)}}const Cr="rgb(198, 198, 198)",Tr=[Cr,"rgb(255, 255, 0)","rgb(255, 0, 0)"],Er=["startdrag","stopdrag","pointer","mouseenter","mouseleave","dblclick","tracklength","groundlength","warninglength","collisionlength"];class Lr extends kt{constructor(e={}){super({template:'<div class="og-elevationprofile">\n <div class="og-elevationprofile-loading" style="display: none;">\n <div class="loadingio-spinner-bars-r354qqyl5v">\n <div class="ldio-p0v5a1f6oz">\n <div></div>\n <div></div>\n <div></div>\n <div></div>\n </div>\n </div> \n </div> \n </div>',model:new wr}),this._onMouseDblClick=e=>{let t,i=this.$canvas.getBoundingClientRect(),s=e.clientX-i.left,n=this._leftDistance+(this._rightDistance-this._leftDistance)*s/this.clientWidth,r=this.model.drawData[1],o=this.model.drawData[0];n<0?(t=1,n=0,s=(0-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):n>this.model.planeDistance?(t=r.length-1,n=this.model.planeDistance,s=(n-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):t=-1-ke(r,n,((e,t)=>e-t[0]));let a=r[t-1],l=r[t],h=(n-a[0])/(l[0]-a[0]),c=a[1]+h*(l[1]-a[1]),d=a[4],_=o[d],u=o[d+1];h=(n-_[0])/(u[0]-_[0]);let g=_[1]+h*(u[1]-_[1]);this.events.dispatch(this.events.dblclick,n,_,u,a,l,d,t-1,g-c)},this._onMouseEnter=e=>{this._isMouseOver=!0,this.events.dispatch(this.events.mouseenter,e)},this._onMouseOut=e=>{this._isMouseOver=!1,this.events.dispatch(this.events.mouseleave,e)},this._onMouseDown=e=>{this._isMouseOver&&(this._isDragging=!0,document.body.classList.add("og-timeline-unselectable"),this._clickPosX=e.clientX,this._customFrame||(this._leftDistance=this.model.minX,this._rightDistance=this.model.maxX),this._clickLeftDistance=this._leftDistance,this._clickRightDistance=this._rightDistance,this.events.dispatch(this.events.startdrag,e))},this._onMouseUp=e=>{this._isDragging&&(this._isDragging=!1,document.body.classList.remove("og-timeline-unselectable"),this.events.dispatch(this.events.stopdrag,e))},this._onCanvasMouseMove=e=>{if(this.model.pointsReady)if(this._isDragging)this.clearPointerCanvas();else{this._customFrame||(this._leftDistance=this.model.minX,this._rightDistance=this.model.maxX);let t=this.$pointerCanvas.getBoundingClientRect(),i=e.clientX-t.left;this.redrawPointerCanvas(i)}},this._onMouseMove=e=>{if(this._isDragging&&this.model.pointsReady){let t=(this._clickPosX-e.clientX)*this._canvasScale/this._pixelsInMeter_x;this.setFrame(this._clickLeftDistance+t,this._clickRightDistance+t)}},this._onMouseWheelFF=e=>{this._onMouseWheel(e)},this._onMouseWheel=e=>{if(this._isMouseOver&&this.model.pointsReady){this._customFrame||(this._leftDistance=this.model.minX,this._rightDistance=this.model.maxX),this._customFrame=!0;let t=Math.sign(e.wheelDelta)*(this._rightDistance-this._leftDistance)/20,i=this.$canvas.getBoundingClientRect(),s=e.clientX-i.left,n=s-.5*this.$canvas.clientWidth,r=n*this._canvasScale/this._pixelsInMeter_x,o=r+this._leftDistance+t,a=r+this._rightDistance-t;r=-n*(a-o)/this.clientWidth,this.setFrame(o+r,a+r),this.redrawPointerCanvas(s)}},this.events=this.events.registerNames(Er),this.fillStyle=e.fillStyle||"rgb(63, 63, 63)",this._customFrame=!1,this._leftDistance=0,this._rightDistance=0,this._pixelsInMeter_x=0,this._pixelsInMeter_y=0,this._canvasScale=2,this.$canvas=document.createElement("canvas"),this.$canvas.style.position="absolute",this._ctx=this.$canvas.getContext("2d"),this.$pointerCanvas=document.createElement("canvas"),this.$pointerCanvas.style.pointerEvents="none",this.$pointerCanvas.style.position="absolute",this._pointerCtx=this.$pointerCanvas.getContext("2d"),this.$loading=null,this._isMouseOver=!1,this._isDragging=!1,this._clickPosX=0,this._clickLeftDistance=0,this._clickRightDistance=0,this._timeStartHandler=0,this._onResizeObserver_=this._onResizeObserver.bind(this),this._resizeObserver=new ResizeObserver(this._onResizeObserver_)}_onResizeObserver(){this.resize()}get canvasScale(){return this._canvasScale}set canvasScale(e){e!==this._canvasScale&&(this._canvasScale=e,this.resize())}resize(){this._resize(),this.draw()}render(){return super.render(),this._resizeObserver.observe(this.el),this.el.appendChild(this.$canvas),this.el.appendChild(this.$pointerCanvas),this.model.events.on("profilecollected",(e=>{this._hideLoading(),this.clearPointerCanvas(),this.draw()})),this.model.events.on("startcollecting",(()=>{clearTimeout(this._timeStartHandler),this._timeStartHandler=setTimeout((()=>{this._showLoading()}),450)})),this.model.events.on("clear",(()=>{this._customFrame=!1,this._leftDistance=0,this.clearCanvas(),this.clearPointerCanvas()})),this.$loading=this.select(".og-elevationprofile-loading"),this.$canvas.addEventListener("mouseenter",this._onMouseEnter),this.$canvas.addEventListener("mouseout",this._onMouseOut),this.$canvas.addEventListener("dblclick",this._onMouseDblClick),this.$canvas.addEventListener("mousemove",this._onCanvasMouseMove),document.body.addEventListener("mousemove",this._onMouseMove),document.body.addEventListener("mousedown",this._onMouseDown),document.body.addEventListener("mouseup",this._onMouseUp),document.body.addEventListener("wheel",this._onMouseWheelFF),this}_hideLoading(){clearTimeout(this._timeStartHandler),this.$loading.style.display="none"}_showLoading(){this.$loading.style.display="flex"}redrawPointerCanvas(e){this.clearPointerCanvas();let t,i=this._leftDistance+(this._rightDistance-this._leftDistance)*e/this.clientWidth,s=this.model.drawData[1],n=this.model.drawData[0];i<0?(t=1,i=0,e=(0-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):i>this.model.planeDistance?(t=s.length-1,i=this.model.planeDistance,e=(i-this._leftDistance)*this.clientWidth/(this._rightDistance-this._leftDistance)):t=-1-ke(s,i,((e,t)=>e-t[0]));let r=s[t-1],o=s[t],a=(i-r[0])/(o[0]-r[0]),l=r[1]+a*(o[1]-r[1]),h=r[4],c=n[h],d=n[h+1];a=(i-c[0])/(d[0]-c[0]);let _=c[1]+a*(d[1]-c[1]),u=(this.model.maxY-_)*this._pixelsInMeter_y,g=(this.model.maxY-l)*this._pixelsInMeter_y;this.events.dispatch(this.events.pointer,i,c,d,r,o,h,t-1,_-l);let f=this._pointerCtx;f.lineWidth=3,f.strokeStyle="rgba(64,64,64,0.6)",f.beginPath(),f.moveTo(e*this._canvasScale,0),f.lineTo(e*this._canvasScale,this.clientHeight*this._canvasScale),f.stroke(),f.beginPath(),f.arc(e*this._canvasScale,g,4,0,2*Math.PI,!1),f.fillStyle="#FFB277",f.fill(),f.lineWidth=4,f.strokeStyle="#FFB277",f.stroke(),f.beginPath(),f.arc(e*this._canvasScale,u,4,0,2*Math.PI,!1),f.fillStyle="#FFB277",f.fill(),f.lineWidth=4,f.strokeStyle="#FFB277",f.stroke(),f.lineWidth=3,f.strokeStyle="#FFB277",f.beginPath(),f.moveTo(e*this._canvasScale,g),f.lineTo(e*this._canvasScale,u),f.stroke(),f.fillStyle="white",f.font=28/devicePixelRatio+"px Arial",f.textBaseline="middle",f.textAlign="left",f.fillText(`${Math.round(_-l).toString()} m`,(e+5)*this._canvasScale,g+.5*(u-g)),f.fillStyle="white",f.font=28/devicePixelRatio+"px Arial",f.textAlign="right";let p=Ke(i);f.fillText(`${p[0]} ${p[1]}`,(e-5)*this._canvasScale,(this.clientHeight-7)*this._canvasScale)}get clientWidth(){return this.$canvas?this.$canvas.width/this._canvasScale:0}get clientHeight(){return this.$canvas?this.$canvas.height/this._canvasScale:0}_resize(){this.el&&(this.$canvas.width=this.el.clientWidth*this._canvasScale,this.$canvas.height=this.el.clientHeight*this._canvasScale,this.$canvas.style.width=`${this.el.clientWidth}px`,this.$canvas.style.height=`${this.el.clientHeight}px`,this.$pointerCanvas.width=this.el.clientWidth*this._canvasScale,this.$pointerCanvas.height=this.el.clientHeight*this._canvasScale,this.$pointerCanvas.style.width=`${this.el.clientWidth}px`,this.$pointerCanvas.style.height=`${this.el.clientHeight}px`,this._customFrame&&(this._pixelsInMeter_x=this._canvasScale*this.clientWidth/(this._rightDistance-this._leftDistance)))}clearPointerCanvas(){this._pointerCtx.fillStyle="rgba(0,0,0,0)",this._pointerCtx.clearRect(0,0,this.clientWidth*this._canvasScale,this.clientHeight*this._canvasScale)}clearCanvas(){const e=this._ctx.createLinearGradient(0,0,0,this.clientHeight*this._canvasScale);e.addColorStop(0,"black"),e.addColorStop(1,this.fillStyle),this._ctx.fillStyle=e,this._ctx.fillRect(0,0,this.clientWidth*this._canvasScale,this.clientHeight*this._canvasScale)}setFrame(e,t){this._leftDistance=e,this._rightDistance=t,this._customFrame=!0,this._pixelsInMeter_x=this._canvasScale*this.clientWidth/(this._rightDistance-this._leftDistance),this.model.setRange(e,t),this.draw()}_updateUnits(){this._customFrame||(this._pixelsInMeter_x=this._canvasScale*this.clientWidth/(this.model.maxX-this.model.minX)),this._pixelsInMeter_y=this._canvasScale*this.clientHeight/(this.model.maxY-this.model.minY)}clear(){this.model.clear(),this.clearCanvas()}draw(){let e=this.model.drawData[0];if(e.length>1){this._updateUnits(),this.clearCanvas();let t=this.model.drawData[1];this._drawTrack(e,t),this._drawTerrain(t),this._drawWarningAndCollision(t),this._drawLabels(e,t)}else this.clearCanvas()}_drawLabels(e,t){let i=this._ctx;if(i){let s=e[0];const n=this.model.maxY;let r=(-this._leftDistance+s[0])*this._pixelsInMeter_x,o=(n-s[1])*this._pixelsInMeter_y;t[s[2]][1],this._pixelsInMeter_y,i.beginPath(),i.fillStyle="#F7F718",i.fillRect(r-4,o-4,8,8),i.stroke(),i.fillStyle="white",i.font=26/devicePixelRatio+"px Arial",i.textBaseline="bottom",i.textAlign="left",i.fillText(`${Math.round(s[1]-t[s[2]][1]).toString()} m`,r+1,o-10),i.stroke();for(let s=1,a=e.length;s<a;s++){let a=e[s];r=(-this._leftDistance+a[0])*this._pixelsInMeter_x,o=(n-a[1])*this._pixelsInMeter_y,t[a[2]][1],this._pixelsInMeter_y,i.beginPath(),i.fillStyle="#F7F718",i.fillRect(r-4,o-4,8,8),i.stroke(),i.fillStyle="white",i.fillText(`${Math.round(a[1]-t[a[2]][1]).toString()} m`,r+1,o-10),i.stroke()}}}_drawTrack(e,t){let i=e[0],s=this._ctx;if(s){const n=this.model.maxY;s.lineWidth=5,s.strokeStyle="rgb(0, 255, 50)",s.beginPath(),s.moveTo((-this._leftDistance+i[0])*this._pixelsInMeter_x,(n-i[1])*this._pixelsInMeter_y);let r=0;for(let t=1,i=e.length;t<i;t++){let i=e[t];s.lineTo((-this._leftDistance+i[0])*this._pixelsInMeter_x,(n-i[1])*this._pixelsInMeter_y);let o=e[t-1],a=i[0]-o[0],l=i[1]-o[1],h=a*a,c=l*l;r+=Math.sqrt(h+c)}s.stroke(),s.lineWidth=2,s.strokeStyle="rgba(255,255,255,0.7)",s.beginPath();let o=(-this._leftDistance+i[0])*this._pixelsInMeter_x,a=(n-i[1])*this._pixelsInMeter_y,l=(n-t[i[2]][1])*this._pixelsInMeter_y;s.moveTo(o,a),s.lineTo(o,l);for(let i=1,r=e.length;i<r;i++){let r=e[i];o=(-this._leftDistance+r[0])*this._pixelsInMeter_x,a=(n-r[1])*this._pixelsInMeter_y,l=(n-t[r[2]][1])*this._pixelsInMeter_y,s.strokeStyle="rgba(255,255,255,0.7)",s.moveTo(o,a),s.lineTo(o,l)}s.stroke(),this.events.dispatch(this.events.tracklength,r)}}_drawTerrain(e){let t=e[0],i=this._ctx;if(i){const s=this.model.maxY;i.lineWidth=5,i.strokeStyle=Cr,i.beginPath(),i.moveTo((-this._leftDistance+t[0])*this._pixelsInMeter_x,this.$canvas.height),i.lineTo((-this._leftDistance+t[0])*this._pixelsInMeter_x,(s-t[1])*this._pixelsInMeter_y);let n=0;for(let t=1,r=e.length;t<r;t++){let r=e[t];i.lineTo((-this._leftDistance+r[0])*this._pixelsInMeter_x,(s-r[1])*this._pixelsInMeter_y);let o=e[t-1],a=r[0]-o[0],l=r[1]-o[1],h=a*a,c=l*l;n+=Math.sqrt(h+c)}i.lineTo((-this._leftDistance+e[e.length-1][0])*this._pixelsInMeter_x,this.$canvas.height),i.closePath(),i.stroke(),i.save(),i.fillStyle="rgb(64, 68, 82)",i.globalAlpha=.5,i.fill(),i.restore(),i.globalAlpha=1,this.events.dispatch(this.events.groundlength,n)}}_drawWarningAndCollision(e){let t=this._ctx;if(t&&e.length>1){let i=this.model.maxY;t.lineWidth=5,t.beginPath();let s=0,n=0;for(let r=0,o=e.length-1;r<o;r++){let o=e[r],a=e[r+1];if(0!==o[2]&&0!==a[2]){let e=a[0]-o[0],r=a[1]-o[1],l=e*e,h=r*r;2===o[2]?(t.stroke(),t.beginPath(),t.strokeStyle=Tr[2],n+=Math.sqrt(l+h)):1===o[2]&&(t.stroke(),t.beginPath(),t.strokeStyle=Tr[1],s+=Math.sqrt(l+h)),t.moveTo((-this._leftDistance+o[0])*this._pixelsInMeter_x,(i-o[1])*this._pixelsInMeter_y),t.lineTo((-this._leftDistance+a[0])*this._pixelsInMeter_x,(i-a[1])*this._pixelsInMeter_y)}}t.stroke(),this.events.dispatch(this.events.warninglength,s),this.events.dispatch(this.events.collisionlength,n)}}}let Ar=mi.createCylinder(.33,0,1,20,1,!0,!1,0,0,0),Pr=mi.createCylinder(.33,.33,1.1,20,1,!0,!0,0,-.55,0);const Sr={startPosition:new oe,endPosition:new oe,startColor:"rgba(255,131,0,0.2)",endColor:"rgba(255,131,0,1.0)",thickness:2.7},Mr={src:"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAAJcEhZcwAADsMAAA7DAcdvqGQAAAAYdEVYdFNvZnR3YXJlAHBhaW50Lm5ldCA0LjEuNBNAaMQAAAiLSURBVHhe7Z0r0BxFEMcjIhAIRERERAQCgUAgEBEIBAIRiUAgIiIQiAgEIlUREQgEIgIREYFAIBCIiAgEIiIiAoGIoHimqPAKz5CP/t23/8vcbe89d/dmZ/pf9avLdZK72e6+ee3M7Imjo6Opc8o4b7xn3DIeGEOJz+Y7+C6+k+/2yjQZXOMEOGdcNe4anv4wvjV+m73bT3wGn8VneqIMlIUyeWXNGteYKTj4feNrI9W/xi/HfxxVfCffnYqyUcbJJINrzIjTxjvGV0aqn43fj/+YhSgLZUpFmd81uAbv2rLANWbAC8ZHxp+GxC8ufZ+rKGNaI1FLcC1ck3etB8U1HhCqzk8N6T/jENV7X6LsXIN008iqeXCNB+B54zND+tt4ePzHIsS1cE0SicA1e74YFdc4IgyjrhvqTP3TvJas9Bq59oP2EVzjCJw03jI0TCMBcurUDS1qBCU9PnjbwCeerwbFNQ4MVd9tQ5pyG7+v0mvHJ6N3FF3jgFwy1JPvmlipUfIFvmHY6/luEFzjANDO0fGRfm1eQ0+UzlriqzOG58tecY0985LxnYH+al5D3ZKP8Bm+83zaG66xRy4a6uzU3NZvK/nqkUEH0fNtL7jGHqBH+4EhTWEGL2ddMwYZJbjGPaGgHxuIDA7tJ/mQGdLek8A17sHTxucGiva+P6kGxbf42PP9TrjGHUmDH1V+/xokCVzjDkTwx1HvSeAat4R2SWP8CP7wko9ZmrZ3n8A1bok6fBH88SRf4/u9ksA1bgFr4ZDG+qHxpLuKLFD1YrMRrnFDLhjocfMaGl8aIjLh5sVoLa5xA140+lhxG+pHNAk7TRu7xjXQ+9TK3Jru4ecqxYB7B88YXsw6cY1rUKcv7ujlI907YLbQi1knrnEFavej05ef1ClkpZUXOxfX2AH3p6Pdz1/E6FnDi2EL19iBVu3Gbd18pdgwU+jFsIVrdHjDQHGDJ39pkojm2ovlAq5xCXqWWtETmo7uG2t3L7vGJTTbF73+6UhNARtVvZjOcY0JZ42Y45+uGK2t7BC6xoQbBoqO3/SkGpt5Gy+2M1xjw3MGGZRubgxNS5qv6dxw4hob9OuPsf90pWnizlrANRpM+sSvvwypFqBGb8W6ZWjgHjOKtn/6Ug3OMv1WrFsG4ykjqv3yxGiudbdw4U2DbvjEuL8cqSZv7TJaeNOg1b2h8nTHWIj3whuDSQOUHmcSKkPagr5wNE0afLhioOj8lSc16QvTw2nwYfk8vlB5YjnfPOZp8FX9x8kd5Uqju3kzkCYAPUQU1X+5UjPACaatBEiPcAmVrfmKIQU/Jn/qEpNCs82lSgCOL0U/Na+hcvVD8/qKMU8AjiZDsdGjfCnGl415AnyCJVSVZptIlAD3sISqEgt9ZwnAHSIU07/1SMv7T5EA7CpFPzavofKljuA5EkCbPmICqB4p1m+SAPQGQ3XqMgnAQwtCdeo6CRBTwPXqJgnAKpFQnbpDAsQcQL26RwLEzt96dZ8ECFWsSIDKFQlQuSIBKlckQOUiAThLJlSnZqOAmAeoV7N5gJgJrFd3SQCePBGqU7dIgLgbWK9mdwO1ITRUn66QADoQIlYE1SPF+gIJEGsC69PCmkDOk0WxKrgeaQf4aRIA9AiYUD2a7wuA2BlUn1gKOE8A9ouj2BtYvh42r4z+5gnATlEUHcHy9X3z+poxT4A4H6Aecfxv63wAiOXh9ah1QgioHxAnhJYr1fKz9h/SBOA0aRSnhJUrJQCP/m0lAMQ5geWr85xA0I2haAbKk4b4K08KVTMQ08LlSU37vPqHNPgiVgiVK5r4hXgvvGm4aKC4PVyOFMuNnhfABEFMCpWnjZ8YAjxfBkUiTF/q/LH0rxXrlqFBJ4friVOh6Uod+oUHRYiWIYFnzaG4QzhdqefPo/+9GK9MAJ42SQ0QtcB0pV//wtAvxTUmqBaIiaHpSff9Z0fCduEaE+gLxBNEpyliRuzctl+4xiU0Ioh5gelIsfrQ8GI6xzUuwdjxgRGalojZacOL6RzX6KDNI0wmhPKWev6tWT8P19jBFwaKDmG+0pD9tnHS8OK4gGvsgDuFUQPkr7UdvxTXuAI9Wk7nzYfykX6clwwvdi6ucQ3MKqEYFeQjxYKFvRtV/cI1roG9hDpdNNYPHl6KAWc9re31L+MaN4DHzMUUcT4iFi8bXqxW4ho3RP2Bx81raHw9al557J8Xo7W4xi24ZqAYHYwv+XztbN8qXOMW0OFQpzBuG48n+XrrTt8yrnFLWELGViMUSTC85GN8Ptvftw+ucQcYGTD7hCIJhpN8y8rtrXv8Hq5xR7hpdNdAkQT9Sz7Fx70EH1zjHlAl6Z5BdAz7k3xJLdta2bsPrnFP0j5BzBXsL/mwlzZ/GdfYA/RMbxgo5gl2l3yHL/fq7XfhGnskfSpp3DvYXKmvZs/5HwrX2DOcP6QVRVqoGOqWfMSmnFcNz6e94RoH4IyhziGLFeMmUlv4RItv8RU+83zZK65xIGjDOH9AnZoYKj6RfIFvrhqDtPcernFg2KTwpSHVvMQsvXa2bnNus+ezwXCNI6DaQOPbGoeLumZ8gC9G+9WnuMYRYeOJdh+hGiaP0mvkiF584PlmFFzjAWAxgzqJqMRESK+Ja91pAUffuMYDwvGlaSJQTU65j0DZ0+aNaztveNd+EFxjBjB3QPWYOm9Kh1WkZeUa2KDJNXnXelBcY0bQPnKs2fIj7nOsFZbLRJkp+0Hb+HW4xgzhMGuqTubEl2sC9igcYpqZ71zeH0HZKCNlpczetWSFa8wcJQO7lrtONiUQ3xh9TDbxGXxWVxNEGSjLZIKe4honxlnjdYMFqnSyhhxB8Nl8B9/Fd/LdXpkmg2ssANpdfpEsXacdZq6BJ6Tya+VZyWnnUsLG3/Fv+Lf8H/4vn8FnZd2W78bRif8BxMOwtJg5Ph4AAAAASUVORK5CYII=",color:"rgb(255,131,0)",size:[8,8]},Rr={text:"",face:"arial",size:10.5,color:"rgba(455,455,455,1.0)",outlineColor:"rgba(0,0,0,0.34)",outline:.23,align:"left",offset:[5,15,-5]},Br={face:"arial",text:"",size:10.5,color:"rgba(455,455,455,1.0)",outlineColor:"rgba(0,0,0,0.34)",outline:.23,align:"right",offset:[-47,25,0]},kr={instanced:!0,tag:"ground-pointer",color:"rgb(0,305,0)",object3d:Ar},Ir={instanced:!0,tag:"head-pointer",color:"rgb(305,305,0)",object3d:Pr};class zr extends Ri{constructor(e={}){super("ElevationProfileScene"),this._onLClick=e=>{let t=this._planet.getCartesianFromPixelTerrain(e.pos);t&&this.addGroundPoint3vAsync(t)},this._onMouseMove=e=>{if(this._planet.getCartesianFromMouseTerrain(),this._pickedGroundEntity){let t=new ae(e.x,e.y).sub(this._startClickPos),i=this._startEntityPos.add(t),s=this._planet.getCartesianFromPixelTerrain(i);s&&this.setGroundPointCartesian3v(this._pickedGroundEntity.properties.index,s)}else if(this._pickedHeadEntity){let t=this._planet.camera,i=this._pickedHeadEntity.properties.groundEntity.getCartesian(),s=this._planet.ellipsoid.getSurfaceNormal3v(i),n=i.add(s),r=i.add(t.getRight()),o=new oe;if(new ui(t.eye,e.direction).hitPlaneRes(_i.fromPoints(i,n,r),o)===ui.INSIDE){let e=oe.proj_b_to_a(o,i),t=e.sub(i).dot(i),n=i.add(s.scale(Math.sign(t)*e.distance(i)));this.setHeadPointCartesian3v(this._pickedHeadEntity.properties.index,n)}}},this._onLUp=e=>{},this._onGroundPointerEnter=e=>{e.renderer.handler.canvas.style.cursor="pointer"},this._onGroundPointerLeave=e=>{e.renderer.handler.canvas.style.cursor="default"},this._onGroundPointerLDown=e=>{this._clampToGround=!1,this.renderer.controls.mouseNavigation.deactivate(),this._pickedGroundEntity=e.pickingObject;const t=this._pickedGroundEntity.getCartesian();this._startClickPos.set(e.x,e.y),this._startEntityPos=this._planet.getPixelFromCartesian(t)},this._onGroundPointerLUp=e=>{this._clampToGround=!0,this.renderer.controls.mouseNavigation.activate(),this._pickedGroundEntity=null},this._onHeadPointerEnter=e=>{e.renderer.handler.canvas.style.cursor="pointer"},this._onHeadPointerLeave=e=>{e.renderer.handler.canvas.style.cursor="default"},this._onHeadPointerLDown=e=>{this.renderer.controls.mouseNavigation.deactivate(),this._pickedHeadEntity=e.pickingObject},this._onHeadPointerLUp=e=>{this.renderer.controls.mouseNavigation.activate(),this._pickedHeadEntity=null},this.events=Mt(Dr),this._planet=e.planet||null,this._pickedGroundEntity=null,this._pickedHeadEntity=null,this._startClickPos=new ae,this._startEntityPos=new ae,this._clampToGround=!0,this._trackLayer=new qs("track",{entities:[],pickingEnabled:!1,polygonOffsetUnits:-1,relativeToGround:!0,hideInLayerSwitcher:!0}),this._groundPointersLayer=new qs("ground-pointers",{entities:[],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[1,5e3,.02],pickingScale:1.5}),this._headPointersLayer=new qs("head-pointers",{entities:[],pickingEnabled:!0,hideInLayerSwitcher:!0,scaleByDistance:[1,1e4,.02],pickingScale:1}),this._columnPointersLayer=new qs("column-pointers",{entities:[],pickingEnabled:!1,hideInLayerSwitcher:!0}),this._trackEntity=new Si({polyline:{path3v:[],thickness:3.8,color:"rgba(0,305,0,0.8)",isClosed:!1}}),this._trackLayer=new qs("column-pointers",{entities:[this._trackEntity],pickingEnabled:!1,hideInLayerSwitcher:!0}),this._heightsLayer=new qs("heights-labels",{entities:[],pickingEnabled:!1,hideInLayerSwitcher:!0}),this._pointerHeadEntity=new Si({cartesian:new oe,billboard:Mr}),this._pointerLabelEntity=new Si({cartesian:new oe,label:Rr}),this._pointerRayEntity=new Si({cartesian:new oe,ray:Sr}),this._pointerLayer=new qs("pointer",{entities:[this._pointerHeadEntity,this._pointerLabelEntity,this._pointerRayEntity],pickingEnabled:!1,hideInLayerSwitcher:!0})}flyExtent(){let e=this._headPointersLayer.getEntities(),t=180,i=180,s=-180,n=-180,r=-1e6;if(e.length>1){for(let o=0;o<e.length;o++){let a=e[o].getLonLat();a.lon<t&&(t=a.lon),a.lat<i&&(i=a.lat),a.lon>s&&(s=a.lon),a.lat>n&&(n=a.lat),a.height>r&&(r=a.height)}this._planet.camera.flyExtent(new te(new I(t,i),new I(s,n)),r,null,0)}}get planet(){return this._planet}_createGroundPointer(e,t=10){let i=this.ellipsoid.getSurfaceNormal3v(e),s=e.add(i.scale(t)),n=new Si({ray:{startPosition:e,endPosition:s,startColor:"rgba(255,255,255,0.2)",endColor:"rgba(355,355,355,1.0)",thickness:3.2}}),r=new Si({cartesian:e,geoObject:kr}),o=new Si({cartesian:s,geoObject:Ir,properties:{}}),a=new Si({cartesian:s,label:Br});a.appendChild(new Si({cartesian:s,label:{...Br,offset:[-47,45,0]}}));const l=this._groundPointersLayer.getEntities().length;return n.properties=r.properties=o.properties={index:l,altitude:t,lonLatEll:new I,headEntity:o,groundEntity:r,columnEntity:n,heightLabelEntity:a},{headEntity:o,groundEntity:r,columnEntity:n,heightLabelEntity:a}}setPointerCartesian3v(e,t){this._pointerLabelEntity.setCartesian3v(e),this._pointerLabelEntity.label.setText(`${Math.round(t).toString()} m`),this._pointerRayEntity.ray.setEndPosition3v(e);let i=this._planet.ellipsoid.getSurfaceNormal3v(e);this._pointerRayEntity.ray.setStartPosition3v(e.add(i.scale(-t))),this._pointerHeadEntity.setCartesian3v(e)}bindPlanet(e){this._planet=e}init(){this._activate()}onremove(){this._deactivate()}_activate(){this._planet.addLayer(this._trackLayer),this._planet.addLayer(this._groundPointersLayer),this._planet.addLayer(this._columnPointersLayer),this._planet.addLayer(this._headPointersLayer),this._planet.addLayer(this._heightsLayer),this._planet.addLayer(this._pointerLayer),this.renderer.events.on("ldblclick",this._onLClick),this.renderer.events.on("mousemove",this._onMouseMove),this.renderer.events.on("lup",this._onLUp),this._groundPointersLayer.events.on("mouseenter",this._onGroundPointerEnter),this._groundPointersLayer.events.on("mouseleave",this._onGroundPointerLeave),this._groundPointersLayer.events.on("ldown",this._onGroundPointerLDown),this._groundPointersLayer.events.on("lup",this._onGroundPointerLUp),this._headPointersLayer.events.on("mouseenter",this._onHeadPointerEnter),this._headPointersLayer.events.on("mouseleave",this._onHeadPointerLeave),this._headPointersLayer.events.on("ldown",this._onHeadPointerLDown),this._headPointersLayer.events.on("lup",this._onHeadPointerLUp),this.setPointerVisibility(!1)}getPointLonLat(e){let t=this._headPointersLayer.getEntities()[e];if(t)return t.getLonLat()}getPointsLonLat(){let e=this._headPointersLayer.getEntities(),t=new Array(e.length);for(let i=0,s=t.length;i<s;i++){let s=e[i];t[i]=s.getLonLat()}return t}getHeightMSL(e){return this._planet&&this._planet.terrain.geoid?this._planet.terrain.geoid.getHeightLonLat(e):0}getHeightELLAsync(e){return new Promise(((t,i)=>{this._planet.terrain.getHeightAsync(e,(s=>{if(this._planet){let i=this.getHeightMSL(e);t(s+i)}else i()}))}))}addPointLonLatArrayAsync(e,t=!1){if(!this._planet)throw new Error("Planet is not defined");let i=this._planet.ellipsoid;for(let t=0,s=e.length-1;t<s;t++){let s=i.lonLatToCartesian(e[t]),n=i.lonLatToCartesian(e[t+1]);if(s.distance(n)>1e5)throw new Error("Track is too long! 100 km is maximum.")}let s=new Array(e.length);for(let t=0,i=e.length;t<i;t++)s[t]=this.addPointLonLatAsync(e[t],!0);return Promise.all(s).then((()=>{t||this.events.dispatch(this.events.change,this)})),s}addPointLonLatAsync(e,t=!1){let i=this._planet.ellipsoid.lonLatToCartesian(e),s=this._planet.ellipsoid.getSurfaceNormal3v(i),n=new I(e.lon,e.lat),r=this._planet.ellipsoid.lonLatToCartesian(n),{headEntity:o,groundEntity:a,columnEntity:l,heightLabelEntity:h}=this._createGroundPointer(r);return this._groundPointersLayer.add(a),this._columnPointersLayer.add(l),this._headPointersLayer.add(o),this._heightsLayer.add(h),this._trackEntity.polyline.appendPoint3v(o.getCartesian()),a.properties.lonLatEll.lon=n.lon,a.properties.lonLatEll.lat=n.lat,a.properties.lonLatEll.height=n.height,new Promise((n=>{this.getHeightELLAsync(e).then((r=>{a.properties.lonLatEll.height=r;let l,c=10;0===e.height?(l=i.add(s.scaleTo(r)),i=l.add(s.scaleTo(c))):(c=e.height-r,l=i.sub(s.scaleTo(c))),a.setCartesian3v(l),h.setCartesian3v(i),h.label.setText(`${r.toFixed(1)} m`),h.childEntities[0].label.setText(`${c.toFixed(1)} m`),o.properties.altitude=c,o.setCartesian3v(i),o.properties.columnEntity.ray.setStartPosition3v(l),o.properties.columnEntity.ray.setEndPosition3v(i),this._trackEntity.polyline?.setPoint3v(i,o.properties.index),t||(this.events.dispatch(this.events.addpoint,o,this),this.events.dispatch(this.events.change,this)),n(o)}))}))}addGroundPointLonLatAsync(e,t=10,i=!1){let s=this._planet.ellipsoid.lonLatToCartesian(e);return this._addPoint(s,e,t,i)}addGroundPoint3vAsync(e,t=10,i=!1){let s=this._planet.ellipsoid.cartesianToLonLat(e);return this._addPoint(e,s,t,i)}_addPoint(e,t,i,s=!1){return new Promise(((n,r)=>{let{headEntity:o,groundEntity:a,columnEntity:l,heightLabelEntity:h}=this._createGroundPointer(e,i);this._groundPointersLayer.add(a),this._columnPointersLayer.add(l),this._headPointersLayer.add(o),this._heightsLayer.add(h),this._trackEntity.polyline.appendPoint3v(o.getCartesian()),a.properties.lonLatEll.lon=t.lon,a.properties.lonLatEll.lat=t.lat,a.properties.lonLatEll.height=t.height,this.getHeightELLAsync(t).then((e=>{a.properties.lonLatEll.height=t.height=e;let r=this._planet.ellipsoid.lonLatToCartesian(t),l=this._planet.ellipsoid.getSurfaceNormal3v(r),c=r.add(l.scale(i));h.setCartesian3v(c),h.label.setText(`${e.toFixed(1)} m`),h.childEntities[0].label.setText(`${i.toFixed(1)} m`),o.setCartesian3v(c),o.properties.columnEntity.ray.setEndPosition3v(c),this._trackEntity.polyline?.setPoint3v(c,o.properties.index),s||(this.events.dispatch(this.events.addpoint,o,this),this.events.dispatch(this.events.change,this)),n(o)}))}))}setHeadPointCartesian3v(e,t){const i=this._headPointersLayer.getEntities()[e];if(i){let s=this._planet.ellipsoid.lonLatToCartesian(i.properties.lonLatEll),n=t.length()-s.length();n<=0&&(t=s,n=0),i.properties.altitude=n,i.setCartesian3v(t),i.properties.columnEntity.ray.setEndPosition3v(t),i.properties.heightLabelEntity.setCartesian3v(t),i.properties.heightLabelEntity.childEntities[0].label.setText(`${n.toFixed(1)} m`),this._trackEntity.polyline.setPoint3v(t,e),this.events.dispatch(this.events.change,this._pickedHeadEntity)}}setGroundPointCartesian3v(e,t){let i=this._groundPointersLayer.getEntities()[e];if(i){let e=this._planet.ellipsoid.cartesianToLonLat(t);i.properties.lonLatEll.lon=e.lon,i.properties.lonLatEll.lat=e.lat,i.properties.lonLatEll.height=e.height;let s=this._planet.ellipsoid.getSurfaceNormal3v(t),n=i.properties.headEntity,r=i.properties.heightLabelEntity,o=i.properties.altitude;i.setCartesian3v(t);let a=t.add(s.scale(o));n.setCartesian3v(a),n.properties.columnEntity.ray.setStartPosition3v(t),n.properties.columnEntity.ray.setEndPosition3v(a),this._trackEntity.polyline?.setPoint3v(a,n.properties.index),r.setCartesian3v(a),r.label.setText(`${e.height.toFixed(1)} m`),r.childEntities[0].label.setText(`${o.toFixed(1)} m`),this.events.dispatch(this.events.change,i.properties.headEntity)}}_deactivate(){this.renderer.events.off("ldblclick",this._onLClick),this.renderer.events.off("mousemove",this._onMouseMove),this.renderer.events.off("lup",this._onLUp),this._groundPointersLayer.events.off("mouseenter",this._onGroundPointerEnter),this._groundPointersLayer.events.off("mouseleave",this._onGroundPointerLeave),this._groundPointersLayer.events.off("ldown",this._onGroundPointerLDown),this._groundPointersLayer.events.off("lup",this._onGroundPointerLUp),this._headPointersLayer.events.off("mouseenter",this._onHeadPointerEnter),this._headPointersLayer.events.off("mouseleave",this._onHeadPointerLeave),this._headPointersLayer.events.off("ldown",this._onHeadPointerLDown),this._headPointersLayer.events.off("lup",this._onHeadPointerLUp),this._trackLayer.remove(),this._groundPointersLayer.remove(),this._headPointersLayer.remove(),this._columnPointersLayer.remove(),this._trackLayer.remove(),this._heightsLayer.remove(),this._pointerLayer.remove(),this.clear()}setPointerVisibility(e){this._pointerLayer.setVisibility(e)}setVisibility(e){this._groundPointersLayer.setVisibility(e),this._trackLayer.setVisibility(e),this._columnPointersLayer.setVisibility(e),this._headPointersLayer.setVisibility(e),this._trackLayer.setVisibility(e),this._heightsLayer.setVisibility(e),this._pointerLayer.setVisibility(e)}clear(){this._headPointersLayer.setEntities([]),this._groundPointersLayer.setEntities([]),this._columnPointersLayer.setEntities([]),this._heightsLayer.setEntities([]),this._trackEntity.polyline.setPath3v([])}frame(){if(this._clampToGround){let e=new oe;const t=this._planet._renderedNodes,i=this._groundPointersLayer.getEntities();for(let s=0;s<i.length;s++){let n=i[s];for(let i=0;i<t.length;i++){let s=t[i];if(s.segment.isEntityInside(n)){s.segment.getEntityTerrainPoint(n,e),n.setCartesian3v(e),n.properties.columnEntity.ray.setStartPosition3v(e);break}}}}}get ellipsoid(){return this._planet?this._planet.ellipsoid:null}}const Dr=["change","addpoint"],Fr=["reset","list","location"];class Nr extends kt{constructor(e={}){super({...e,template:'<div class="og-elevationprofile-buttons"></div>'}),this.events=this.events.registerNames(Fr),this.pointListBtn=new Ut({classList:["og-elevationprofile-button"],icon:'<?xml version="1.0" encoding="utf-8"?><svg width="800px" height="800px" viewBox="0 0 32 32" id="icon" xmlns="http://www.w3.org/2000/svg"><defs><style>.cls-1{fill:none;}</style></defs><title>list</title><rect x="10" y="6" width="18" height="2"/><rect x="10" y="24" width="18" height="2"/><rect x="10" y="15" width="18" height="2"/><rect x="4" y="15" width="2" height="2"/><rect x="4" y="6" width="2" height="2"/><rect x="4" y="24" width="2" height="2"/></svg>',title:"Point List"}),this.pointListBtn.events.on("change",(e=>{this.events.dispatch(this.events.list,e)}))}render(e){super.render(e);let t=new zt({classList:["og-elevationprofile-button"],icon:'<?xml version="1.0" encoding="UTF-8" standalone="no"?>\n<svg width="30" height="30" viewBox="0 0 30 30" version="1.1">\n <g transform="translate(0,-289.0625)">\n <path d="M 15 6 C 10.041282 6 6 10.04128 6 15 C 6 19.95872 10.041282 24 15 24 C 16.586491 24 18.07668 23.58246 19.373047 22.857422 L 17.888672 21.375 C 17.00816 21.772814 16.032235 22 15 22 C 11.122162 22 8 18.87784 8 15 C 8 11.12216 11.122162 8 15 8 C 18.877838 8 22 11.12216 22 15 L 19 15 L 23 20 L 27 15 L 24 15 C 24 10.04128 19.958718 6 15 6 z " transform="translate(0,289.0625)" />\n </g>\n</svg>',title:"Reset"});t.appendTo(this.el),t.events.on("click",(()=>{this.model.clear(),this.events.dispatch(this.events.reset,this)})),this.pointListBtn.appendTo(this.el);let i=new zt({classList:["og-elevationprofile-button","og-elevationprofile-button__location"],icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Svg Vector Icons : http://www.onlinewebfonts.com/icon --\x3e\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 256 256" enable-background="new 0 0 256 256" xml:space="preserve">\n<metadata> Svg Vector Icons : http://www.onlinewebfonts.com/icon </metadata>\n<g><g><path fill="#000000" d="M127,169.4c23.7,0,42.8-18.3,42.8-41s-19.2-41-42.8-41c-23.7,0-42.8,18.4-42.8,41S103.4,169.4,127,169.4z"/><path fill="#000000" d="M221.7,120.2c-3.8-44-40.9-78.9-87-82V15h-16.3v23.6c-44.8,4-80.3,38.5-84.1,81.7H10v15.6h24.3c3.8,43.1,39.3,77.4,84.1,81.7V241h16.3v-23.2c46-3.1,83.2-37.9,87-82H246v-15.6H221.7L221.7,120.2L221.7,120.2z M128,201.6c-42.5,0-76.7-33-76.7-73.4c0-40.4,34.5-73.4,76.7-73.4c42.5,0,76.7,33,76.7,73.4C204.7,168.5,170.5,201.6,128,201.6L128,201.6z"/></g></g>\n</svg>',title:"View bounds"});return i.appendTo(this.el),i.events.on("click",(()=>{this.events.dispatch(this.events.location,this)})),this}}class Hr extends Ot{constructor(e){super({title:"Points List",visible:!1,resizable:!0,useHide:!0,top:150,left:200,width:400,height:300,minHeight:100,minWidth:100,...e}),this._onApplyClick=()=>{try{this.model.clear();let e=JSON.parse(this.$textarea.value),t=new Array(e.length);for(let i=0;i<e.length;i++){let s=e[i];t[i]=new I(s[0],s[1],s[2])}this.model.addPointLonLatArrayAsync(t)}catch(e){console.error(e)}},this.$textarea=null}render(e){super.render(e);let t=new kt({template:'<div class="og-elevationprofile-list">\n <textarea placeholder="[[lon, lat, height], [lon, lat, height], ..., [lon, lat, height]]"></textarea>\n <div class="og-elevationprofile-list-buttons"></div>\n </div>'});t.appendTo(this.container);let i=new zt({classList:["og-elevationprofile-list-apply"],icon:"Apply"});return i.appendTo(t.select(".og-elevationprofile-list-buttons")),i.events.on("click",this._onApplyClick),this.$textarea=t.select("textarea"),this}}class Or extends kt{constructor(e={}){super({...e,template:'<div class="og-elevationprofile-legend">\n <div class="og-elevationprofile-legend__row og-elevationprofile-legend__track">\n <div class="og-elevationprofile-square"></div>\n <div class="og-elevationprofile-value">0</div>\n <div class="og-elevationprofile-units">m</div>\n </div>\n <div class="og-elevationprofile-legend__row og-elevationprofile-legend__ground">\n <div class="og-elevationprofile-square"></div>\n <div class="og-elevationprofile-value">0</div>\n <div class="og-elevationprofile-units">m</div>\n </div>\n <div class="og-elevationprofile-legend__row og-elevationprofile-legend__warning"> \n <div class="og-elevationprofile-square"></div>\n <div class="og-elevationprofile-value">0</div>\n <div class="og-elevationprofile-units">m</div>\n </div>\n <div class="og-elevationprofile-legend__row og-elevationprofile-legend__collision">\n <div class="og-elevationprofile-square"></div>\n <div class="og-elevationprofile-value">0</div>\n <div class="og-elevationprofile-units">m</div>\n </div>\n </div>'}),this.$groundValue=null,this.$trackValue=null,this.$warningValue=null,this.$collisionValue=null,this.$trackUnits=null,this.$groundUnits=null,this.$warningUnits=null,this.$collisionUnits=null}render(e){return super.render(e),this.$trackValue=this.select(".og-elevationprofile-legend__track .og-elevationprofile-value"),this.$groundValue=this.select(".og-elevationprofile-legend__ground .og-elevationprofile-value"),this.$warningValue=this.select(".og-elevationprofile-legend__warning .og-elevationprofile-value"),this.$collisionValue=this.select(".og-elevationprofile-legend__collision .og-elevationprofile-value"),this.$trackUnits=this.select(".og-elevationprofile-legend__track .og-elevationprofile-units"),this.$groundUnits=this.select(".og-elevationprofile-legend__ground .og-elevationprofile-units"),this.$warningUnits=this.select(".og-elevationprofile-legend__warning .og-elevationprofile-units"),this.$collisionUnits=this.select(".og-elevationprofile-legend__collision .og-elevationprofile-units"),this}clear(){this.$trackValue&&(this.$trackValue.innerText="0"),this.$trackUnits&&(this.$trackUnits.innerText="m"),this.$groundValue&&(this.$groundValue.innerText="0"),this.$groundUnits&&(this.$groundUnits.innerText="m"),this.$warningValue&&(this.$warningValue.innerText="0"),this.$warningUnits&&(this.$warningUnits.innerText="m"),this.$collisionValue&&(this.$collisionValue.innerText="0"),this.$collisionUnits&&(this.$collisionUnits.innerText="m")}setTrackLength(e){let t=Ke(e);this.$trackValue.innerText=t[0],this.$trackUnits.innerText=t[1]}setGroundLength(e){let t=Ke(e);this.$groundValue.innerText=t[0],this.$groundUnits.innerText=t[1]}setWarningLength(e){let t=Ke(e);this.$warningValue.innerText=t[0],this.$warningUnits.innerText=t[1]}setCollisionLength(e){let t=Ke(e);this.$collisionValue.innerText=t[0],this.$collisionUnits.innerText=t[1]}}const Vr="rgb(253,77,77)",Ur="rgb(248,115,115)",Gr="rgb(73,73,239)",Yr="rgb(90,90,253)",jr="rgb(26,122,26)",Wr="rgb(55,191,55)",qr="rgba(255,255,255,0.8)",$r=.1,Xr=new oe($r,$r,$r),Zr=.17,Kr=.0095,Qr=mi.createCylinder(Kr,Kr,.83).scale(Xr),Jr=mi.createCylinder(0,.04,Zr,16,16,!1,!0,0,-.17).scale(Xr);class eo extends Si{constructor(e={}){super({independentPicking:!0,yaw:e.yaw||0,pitch:e.pitch||0,roll:e.roll||0,forceGlobalPosition:!0,geoObject:{color:e.color||Vr,scale:1,tag:"line",object3d:Qr},properties:e.properties}),this._size=null!=e.size?e.size:1,this.appendChild(new Si({yaw:e.yaw||0,pitch:e.pitch||0,roll:e.roll||0,forceGlobalPosition:!0,geoObject:{color:e.color||Vr,scale:1,tag:"tip",object3d:Jr},properties:e.properties}))}setSize(e){this._size=e;const t=new oe(1,(this._size-Zr)/.83,1),i=new oe(0,this._size*$r,0);let s=this.childEntities[0];this.setScale3v(t),s.geoObject.setTranslate3v(i)}setColorHTML(e){let t=this.childEntities[0];this.geoObject.setColorHTML(e),t.geoObject.setColorHTML(e)}}class to extends Si{constructor(e={}){super(e),this._size=null!=e.size?e.size:1,this.childEntities=[],this._init()}_init(){let e=new eo({color:Vr,yaw:0,pitch:0,roll:90*l,properties:{opName:"move_x",noEdit:!0,style:{color:Vr,selectColor:Ur}}}),t=new eo({color:Gr,yaw:0,pitch:0,roll:0,properties:{opName:"move_y",noEdit:!0,style:{color:Gr,selectColor:Yr}}}),i=new eo({color:jr,yaw:0,pitch:90*l,roll:0,properties:{opName:"move_z",noEdit:!0,style:{color:jr,selectColor:Wr}}});this.appendChild(e),this.appendChild(t),this.appendChild(i),this.setSize(this._size)}setSize(e){this.childEntities[0].setSize(e),this.childEntities[1].setSize(e),this.childEntities[2].setSize(e)}setPitch(e){let t=this.childEntities[0],i=t.childEntities[0];t.setPitch(e),i.setPitch(e),t=this.childEntities[1],i=t.childEntities[0],t.setPitch(e),i.setPitch(e),t=this.childEntities[2],i=t.childEntities[0],t.setPitch(e+90),i.setPitch(e+90)}setYaw(e){let t=this.childEntities[0],i=t.childEntities[0];t.setYaw(e),i.setYaw(e),t=this.childEntities[1],i=t.childEntities[0],t.setYaw(e),i.setYaw(e),t=this.childEntities[2],i=t.childEntities[0],t.setYaw(e),i.setYaw(e)}setRoll(e){let t=this.childEntities[0],i=t.childEntities[0];t.setRoll(e+90),i.setRoll(e+90),t=this.childEntities[1],i=t.childEntities[0],t.setRoll(e),i.setRoll(e)}getY(){return this.childEntities[1].getAbsoluteRotation().mulVec3(oe.UP).normalize()}}const io=mi.createPlane(1,1,-.5,0,.5);class so extends Si{constructor(e={}){super(e),this._init()}_init(){let e=new Si({independentPicking:!0,scale:.025,forceGlobalPosition:!0,geoObject:{color:qr,tag:"plane",object3d:io},properties:{opName:"move_xz",noEdit:!0,style:{color:qr,selectColor:"rgba(255,255,255,1.0)"}}});this.appendChild(e)}}const no=360,ro=.95,oo=new Array(no),ao=new Array(no),lo=new Array(no);class ho extends Si{constructor(e={}){super(e),this._init()}_init(){const e=no;let t=new Si({independentPicking:!0,polyline:{path3v:[Array.from({length:e},((e,t)=>new oe))],thickness:3.1,color:Vr,isClosed:!0},properties:{opName:"rotate_pitch",noEdit:!0,style:{color:Vr,selectColor:Ur}}}),i=new Si({independentPicking:!0,polyline:{path3v:[Array.from({length:e},((e,t)=>new oe))],thickness:2.5,color:Gr,isClosed:!0},properties:{opName:"rotate_yaw",noEdit:!0,style:{color:Gr,selectColor:Yr}}}),s=new Si({independentPicking:!0,polyline:{path3v:[Array.from({length:e},((e,t)=>new oe))],thickness:2.5,color:jr,isClosed:!0},properties:{opName:"rotate_roll",noEdit:!0,style:{color:jr,selectColor:Wr}}});this.appendChild(t),this.appendChild(i),this.appendChild(s)}setCartesian3v(e,t=0){if(super.setCartesian3v(e),this._entityCollection&&this._entityCollection.renderNode){let i=this._entityCollection.renderNode,s=i.renderer.activeCamera,n=i.getFrameRotation(e).conjugate(),r=.15*s.eye.distance(e),o=re.xRotation(0),a=re.yRotation(t),h=re.zRotation(0).mul(o).mul(a).mul(i.getFrameRotation(e)).conjugate();for(let t=0,i=0,s=1;t<no;t+=s,i++){let s=t*l,o=Math.cos(s),a=Math.sin(s),c=h.mulVec3(new oe(0,a,o)).normalize().scale(r).add(e),d=n.mulVec3(new oe(o,0,a)).normalize().scale(r).add(e),_=h.mulVec3(new oe(o,a,0)).normalize().scale(r).add(e);oo[i]=c,ao[i]=d,lo[i]=_}this.childEntities[0].polyline.setPath3v([oo],void 0,!0),this.childEntities[1].polyline.setPath3v([ao],void 0,!0),this.childEntities[2].polyline.setPath3v([lo],void 0,!0);let c=h.mulVec3(new oe(1,0,0)).normalize(),d=n.mulVec3(new oe(0,1,0)).normalize(),_=h.mulVec3(new oe(0,0,1)).normalize();this.childEntities[0].polyline.setVisibleSphere(e,Math.abs(c.dot(s.getForward()))>ro?0:r),this.childEntities[1].polyline.setVisibleSphere(e,Math.abs(d.dot(s.getForward()))>ro?0:r),this.childEntities[2].polyline.setVisibleSphere(e,Math.abs(_.dot(s.getForward()))>ro?0:r)}}}class co extends Si{constructor(e={}){super({...e,forceGlobalPosition:!0}),this._init()}_init(){let e=[],t=[],i=[],s=xe(Ur),n=xe(Yr),r=xe(Wr);for(let o=0;o<20;o++){let a=1;if(o<5){let e=o/5;a=.5*(1-Math.cos(Math.PI*e))}else if(o>15){let e=(o-15)/5;a=1-.5*(1-Math.cos(Math.PI*e))}t.push([r[0],r[1],r[2],a]),e.push([s[0],s[1],s[2],a]),i.push([n[0],n[1],n[2],a])}let o=new Si({polyline:{path3v:[Array.from({length:20},((e,t)=>new oe))],thickness:2.5,pathColors:[e],isClosed:!1}}),a=new Si({polyline:{path3v:[Array.from({length:20},((e,t)=>new oe))],thickness:2.5,pathColors:[i],isClosed:!1}}),l=new Si({polyline:{path3v:[Array.from({length:20},((e,t)=>new oe))],thickness:2.5,pathColors:[t],isClosed:!1}});this.appendChild(o),this.appendChild(a),this.appendChild(l)}setCartesian3v(e){if(super.setCartesian3v(e),this._entityCollection&&this._entityCollection.renderNode){let t=this._entityCollection.renderNode,i=.05*t.renderer.activeCamera.eye.distance(e);if(t.planet){let s=[],n=[],r=[],o=t.planet.ellipsoid.getSurfaceNormal3v(e),a=this._lonLat,l=10;for(let t=-l;t<l;t++)r.push(new I(a.lon,a.lat+t,a.height)),n.push(new I(a.lon+t,a.lat,a.height)),s.push(e.add(o.scaleTo(t*i)));this.childEntities[0].polyline.setPathLonLatFast([n]),this.childEntities[1].polyline.setPath3vFast([s]),this.childEntities[2].polyline.setPathLonLatFast([r])}else{let t=[],s=[],n=[],r=oe.UNIT_Y,o=oe.UNIT_X,a=oe.UNIT_Z,l=10;for(let h=-l;h<l;h++)s.push(e.add(o.scaleTo(h*i))),n.push(e.add(r.scaleTo(h*i))),t.push(e.add(a.scaleTo(h*i)));this.childEntities[0].polyline.setPath3vFast([s]),this.childEntities[1].polyline.setPath3vFast([n]),this.childEntities[2].polyline.setPath3vFast([t])}}}}function _o(e,t,i,s,n,r){let o=n.add(oe.UP),a=n.add(e),l=new oe;if(new ui(t,i).hitPlaneRes(_i.fromPoints(n,o,a),l)===ui.INSIDE){let i=oe.proj_b_to_a(l,e);if(new ui(t,s).hitPlaneRes(_i.fromPoints(n,o,a),l)===ui.INSIDE){let t=oe.proj_b_to_a(l,e).sub(i);r.copy(n.add(t))}}}class uo extends Ri{constructor(e={}){super(e.name||"GeoObjectEditorScene"),this._onAxisLayerMouseEnter=e=>{this.renderer.handler.canvas.style.cursor="pointer",e.pickingObject.setColorHTML(e.pickingObject.properties.style.selectColor)},this._onAxisLayerMouseLeave=e=>{this.renderer.handler.canvas.style.cursor="default",e.pickingObject.setColorHTML(e.pickingObject.properties.style.color)},this._onAxisLayerLUp=e=>{this._selectedMove=null,this._navActivate(),this._setAxisTrackVisibility(!1)},this._onAxisLayerLDown=e=>{this._clickPos=e.pos.clone(),this._selectedEntity&&(this._selectedEntityCart=this._selectedEntity.getAbsoluteCartesian(),this._setAxisTrackVisibility(!0)),this._selectedMove=e.pickingObject.properties.opName,this._navDeactivate()},this._onPlaneLayerMouseEnter=e=>{this.renderer.handler.canvas.style.cursor="pointer",e.pickingObject.geoObject.setColorHTML(e.pickingObject.properties.style.selectColor)},this._onPlaneLayerMouseLeave=e=>{this.renderer.handler.canvas.style.cursor="default",e.pickingObject.geoObject.setColorHTML(e.pickingObject.properties.style.color)},this._onPlaneLayerLUp=e=>{this._selectedMove=null,this._navActivate(),this._setAxisTrackVisibility(!1)},this._onPlaneLayerLDown=e=>{this._clickPos=e.pos.clone(),this._selectedEntity&&(this._selectedEntityCart=this._selectedEntity.getAbsoluteCartesian(),this._setAxisTrackVisibility(!0)),this._selectedMove=e.pickingObject.properties.opName,this._navDeactivate()},this._onRotateLayerMouseEnter=e=>{this.renderer.handler.canvas.style.cursor="pointer",e.pickingObject.polyline.setColorHTML(e.pickingObject.properties.style.selectColor)},this._onRotateLayerMouseLeave=e=>{this.renderer.handler.canvas.style.cursor="default",e.pickingObject.polyline.setColorHTML(e.pickingObject.properties.style.color)},this._onRotateLayerLUp=e=>{this._selectedMove=null,this._navActivate()},this._onRotateLayerLDown=e=>{this._clickPos=e.pos.clone(),this._selectedEntity&&(this._selectedEntityCart=this._selectedEntity.getAbsoluteCartesian(),this._selectedEntity&&(this._selectedEntityPitch=this._selectedEntity.getAbsolutePitch(),this._selectedEntityYaw=this._selectedEntity.getAbsoluteYaw(),this._selectedEntityRoll=this._selectedEntity.getAbsoluteRoll())),this._selectedMove=e.pickingObject.properties.opName,this._navDeactivate()},this._onMouseMove=e=>{this._selectedEntity&&this._selectedMove&&this._ops[this._selectedMove]&&this._ops[this._selectedMove](e)},this._onLclick=e=>{e.pickingObject&&e.pickingObject instanceof Si&&this.select(e.pickingObject)},this._moveX=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=t.unproject(this._clickPos.x,this._clickPos.y),n=new oe;if(this.planet){let r=new ui(t.eye,s).hitSphere(new Pt(i.length(),new oe)),o=new ui(t.eye,e.direction).hitSphere(new Pt(i.length(),new oe));if(!o)return;if(n=re.getRotationBetweenVectors(r.normal(),o.normal()).mulVec3(i),this._ellipsoid){let e=this._ellipsoid.cartesianToLonLat(i),t=this._ellipsoid.cartesianToLonLat(n);this._ellipsoid.lonLatToCartesianRes(new I(t.lon,e.lat,e.height),n)}}else _o(oe.UNIT_X,t.eye,s,e.direction,i,n);this._selectedEntity.setAbsoluteCartesian3v(n),this.events.dispatch(this.events.position,n,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)},this._moveY=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=oe.UP;this.planet&&(s=this._axisEntity.getY());let n=i.add(s),r=i.add(t.getRight()),o=new oe,a=t.unproject(this._clickPos.x,this._clickPos.y);if(new ui(t.eye,a).hitPlaneRes(_i.fromPoints(i,n,r),o)===ui.INSIDE){let a=oe.proj_b_to_a(o,s);if(new ui(t.eye,e.direction).hitPlaneRes(_i.fromPoints(i,n,r),o)===ui.INSIDE){let e=oe.proj_b_to_a(o,s).sub(a),t=this._selectedEntityCart.add(e);this._selectedEntity.setAbsoluteCartesian3v(t),this.events.dispatch(this.events.position,o,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)}}},this._moveZ=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=t.unproject(this._clickPos.x,this._clickPos.y),n=new oe;if(this.planet){let r=new ui(t.eye,s).hitSphere(new Pt(i.length(),new oe)),o=new ui(t.eye,e.direction).hitSphere(new Pt(i.length(),new oe));if(!o)return;if(n=re.getRotationBetweenVectors(r.normal(),o.normal()).mulVec3(i),this._ellipsoid){let e=this._ellipsoid.cartesianToLonLat(i),t=this._ellipsoid.cartesianToLonLat(n);this._ellipsoid.lonLatToCartesianRes(new I(e.lon,t.lat,e.height),n)}}else _o(oe.UNIT_Z,t.eye,s,e.direction,i,n);this._selectedEntity.setAbsoluteCartesian3v(n),this.events.dispatch(this.events.position,n,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)},this._moveXZ=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=t.unproject(this._clickPos.x,this._clickPos.y),n=new oe;if(this.planet){let r=new ui(t.eye,s).hitSphere(new Pt(i.length(),new oe)),o=new ui(t.eye,e.direction).hitSphere(new Pt(i.length(),new oe));if(!o)return;if(n=re.getRotationBetweenVectors(r.normal(),o.normal()).mulVec3(i),this._ellipsoid){let e=this._ellipsoid.cartesianToLonLat(n),t=this._selectedEntity.getLonLat().height;this._ellipsoid.lonLatToCartesianRes(new I(e.lon,e.lat,t),n)}}else{let r=i.add(oe.UNIT_X),o=i.add(oe.UNIT_Z),a=new oe,l=new oe;if(new ui(t.eye,s).hitPlaneRes(_i.fromPoints(i,r,o),a)===ui.INSIDE&&new ui(t.eye,e.direction).hitPlaneRes(_i.fromPoints(i,r,o),l)===ui.INSIDE){let e=l.sub(a);n=i.add(e)}}this._selectedEntity.setAbsoluteCartesian3v(n),this.events.dispatch(this.events.position,n,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)},this._moveXY=e=>{console.log("moveXY")},this._moveZY=e=>{console.log("moveZY")},this._rotatePitch=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=re.xRotation(0),n=re.yRotation(this._selectedEntity.getYaw()),r=re.zRotation(0).mul(s).mul(n).mul(this.getFrameRotation(i)).conjugate().mulVec3(new oe(1,0,0)).normalize(),o=t.unproject(this._clickPos.x,this._clickPos.y),a=new _i(i,r),l=new oe,h=new oe;if(new ui(t.eye,o).hitPlaneRes(a,l)===ui.INSIDE&&new ui(t.eye,e.direction).hitPlaneRes(a,h)===ui.INSIDE){let e=l.sub(i).normalize(),t=h.sub(i).normalize(),s=Math.sign(e.cross(t).dot(r)),n=Math.acos(e.dot(t)),o=this._selectedEntityPitch+s*n;this._selectedEntity.setAbsolutePitch(o),this.events.dispatch(this.events.pitch,o,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)}},this._rotateYaw=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart,s=this.getFrameRotation(i).conjugate().mulVec3(new oe(0,1,0)).normalize(),n=t.unproject(this._clickPos.x,this._clickPos.y),r=new _i(i,s),o=new oe,a=new oe;if(new ui(t.eye,n).hitPlaneRes(r,o)===ui.INSIDE&&new ui(t.eye,e.direction).hitPlaneRes(r,a)===ui.INSIDE){let e=o.sub(i).normalize(),t=a.sub(i).normalize(),n=Math.sign(t.cross(e).dot(s)),r=Math.acos(e.dot(t)),l=this._selectedEntityYaw+n*r;this._selectedEntity.setAbsoluteYaw(l),this.events.dispatch(this.events.yaw,l,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)}},this._rotateRoll=e=>{if(!this._selectedEntity)return;let t=this.renderer.activeCamera,i=this._selectedEntityCart;this.getFrameRotation(i).conjugate();let s=re.xRotation(0),n=re.yRotation(this._selectedEntity.getYaw()),r=re.zRotation(0).mul(s).mul(n).mul(this.getFrameRotation(i)).conjugate().mulVec3(new oe(0,0,1)).normalize(),o=t.unproject(this._clickPos.x,this._clickPos.y),a=new _i(i,r),l=new oe,h=new oe;if(new ui(t.eye,o).hitPlaneRes(a,l)===ui.INSIDE&&new ui(t.eye,e.direction).hitPlaneRes(a,h)===ui.INSIDE){let e=l.sub(i).normalize(),t=h.sub(i).normalize(),s=Math.sign(e.cross(t).dot(r)),n=Math.acos(e.dot(t)),o=this._selectedEntityRoll+s*n;this._selectedEntity.setAbsoluteRoll(o),this.events.dispatch(this.events.roll,o,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)}},this._scale=e=>{this.events.dispatch(this.events.scale,1,this._selectedEntity),this.events.dispatch(this.events.change,this._selectedEntity)},this._scaleX=e=>{},this._scaleY=e=>{},this._scaleZ=e=>{},this.events=Mt(go),this._planet=e.planet||null,this._startPos=null,this._startClick=new ae,this._axisEntity=new to,this._planeEntity=new so,this._rotateEntity=new ho,this._axisTrackEntity=new co,this._moveLayer=new fs({scaleByDistance:[.1,r,.1],useLighting:!1,pickingScale:[5,1.1,5],visibility:!1,depthOrder:1e3}),this._planeLayer=new fs({scaleByDistance:[.1,r,.1],useLighting:!1,visibility:!1,depthOrder:1e3}),this._rotateLayer=new fs({useLighting:!1,visibility:!1,depthOrder:1e3,pickingScale:5}),this._selectedEntity=null,this._clickPos=new ae,this._selectedEntityCart=new oe,this._selectedEntityPitch=0,this._selectedEntityYaw=0,this._selectedEntityRoll=0,this._selectedMove=null,this._axisTrackVisibility=!1,this._axisTrackLayer=new fs({useLighting:!1,visibility:!1,pickingScale:5,pickingEnabled:!1,opacity:.6}),this._ops={move_x:this._moveX,move_y:this._moveY,move_z:this._moveZ,move_xz:this._moveXZ,move_xy:this._moveXY,move_zy:this._moveZY,rotate_pitch:this._rotatePitch,rotate_yaw:this._rotateYaw,rotate_roll:this._rotateRoll,scale:this._scale,scale_x:this._scaleX,scale_y:this._scaleY,scale_z:this._scaleZ}}get planet(){return this._planet}bindPlanet(e){this._planet=e}init(){this.activate()}onremove(){this.deactivate()}_addAxisLayers(){this._moveLayer.addTo(this),this._planeLayer.addTo(this),this._rotateLayer.addTo(this),this._axisTrackLayer.addTo(this),this._moveLayer.add(this._axisEntity),this._moveLayer.events.on("mouseenter",this._onAxisLayerMouseEnter),this._moveLayer.events.on("mouseleave",this._onAxisLayerMouseLeave),this._moveLayer.events.on("lup",this._onAxisLayerLUp),this._moveLayer.events.on("ldown",this._onAxisLayerLDown),this._planeLayer.add(this._planeEntity),this._planeLayer.events.on("mouseenter",this._onPlaneLayerMouseEnter),this._planeLayer.events.on("mouseleave",this._onPlaneLayerMouseLeave),this._planeLayer.events.on("lup",this._onPlaneLayerLUp),this._planeLayer.events.on("ldown",this._onPlaneLayerLDown),this._rotateLayer.add(this._rotateEntity),this._rotateLayer.events.on("mouseenter",this._onRotateLayerMouseEnter),this._rotateLayer.events.on("mouseleave",this._onRotateLayerMouseLeave),this._rotateLayer.events.on("lup",this._onRotateLayerLUp),this._rotateLayer.events.on("ldown",this._onRotateLayerLDown),this._axisTrackLayer.add(this._axisTrackEntity)}_navActivate(){this.renderer&&(this.renderer.controls.mouseNavigation&&this.renderer.controls.mouseNavigation.activate(),this.renderer.controls.SimpleNavigation&&this.renderer.controls.SimpleNavigation.activate())}_navDeactivate(){this.renderer&&(this.renderer.controls.mouseNavigation&&this.renderer.controls.mouseNavigation.deactivate(),this.renderer.controls.SimpleNavigation&&this.renderer.controls.SimpleNavigation.deactivate())}_removeAxisLayers(){this._moveLayer.remove(),this._planeLayer.remove(),this._rotateLayer.remove()}activate(){this.renderer.events.on("lclick",this._onLclick),this.renderer.events.on("mousemove",this._onMouseMove),this._addAxisLayers()}deactivate(){this.renderer.events.off("lclick",this._onLclick),this.renderer.events.off("mousemove",this._onMouseMove),this._removeAxisLayers(),this.clear()}_setAxisTrackVisibility(e){e!==this._axisTrackVisibility&&(this._axisTrackVisibility=e,this._axisTrackLayer.setVisibility(e))}setVisibility(e){this._moveLayer.setVisibility(e),this._planeLayer.setVisibility(e),this._rotateLayer.setVisibility(e),this.unlockView()}readyToEdit(e){return!e.properties||!e.properties.noEdit}select(e){(!this._selectedEntity||this._selectedEntity&&!e.isEqual(this._selectedEntity))&&this.readyToEdit(e)&&(this._selectedEntity&&this.unselect(),this._selectedEntity=e,this.renderer&&this.renderer.setRelativeCenter(),this.setVisibility(!0),this.events.dispatch(this.events.select,this._selectedEntity))}unselect(){this.setVisibility(!1);let e=this._selectedEntity;this._selectedEntity=null,this.events.dispatch(this.events.unselect,e)}clear(){this.removeEntityCollection(this._moveLayer),this.removeEntityCollection(this._planeLayer),this.removeEntityCollection(this._rotateLayer)}frame(){if(this._selectedEntity){let e=this._selectedEntity.getAbsoluteCartesian();this._axisEntity.setCartesian3v(e),this._planeEntity.setCartesian3v(e),this._rotateEntity.setCartesian3v(e,this._selectedEntity.getAbsoluteYaw()),this._axisTrackEntity.setCartesian3v(e)}}get _ellipsoid(){return this._planet?this._planet.ellipsoid:null}getFrameRotation(e){return this._planet?this._planet.getFrameRotation(e):super.getFrameRotation(e)}getSelectedEntity(){return this._selectedEntity}lockView(){if(this.renderer&&this._selectedEntity){this.renderer.controls.CameraLock.lockView(this._selectedEntity)}}unlockView(){if(this.renderer&&this._selectedEntity){let e=this.renderer.controls.CameraLock;e&&e.unlockView()}}}const go=["mousemove","mouseenter","mouseleave","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchmove","touchstart","touchend","doubletouch","touchleave","touchenter","select","unselect","change","position","pitch","yaw","roll","scale"],fo=["change"];class po extends kt{constructor(e={}){super({template:we('<div class="og-input">\n <div class="og-input-label">{label}</div>\n <input type="{type}"/>\n </div>',{label:e.label||"",type:e.type||"text"})}),this._onResize=()=>{},this._onMouseWheel=e=>{(e=e||window.event).preventDefault(),e.stopPropagation()},this._onMouseWheelFF=e=>{this._onMouseWheel(e)},this._onInput=e=>{(e=e||window.event).preventDefault(),e.stopPropagation(),this._setValue(e.target.value)},this.events=this.events.registerNames(fo),this._value=e.value||"",this._maxFixed=null!=e.maxFixed?e.maxFixed:-1,this.$label=null,this.$input=null}render(e){return super.render(e),this.$label=this.select(".og-input-label"),""===this.$label.innerHTML&&(this.$label.style.display="none"),this.$input=this.select("input"),this._initEvents(),this}set value(e){e!==this._value&&(this._value="number"==typeof e?Je(e,this._maxFixed):e,this.$input&&(this.$input.value=this._value),this.events.dispatch(this.events.change,this._value,this))}_setValue(e){e!==this._value&&(this._value="number"==typeof e?Je(e,this._maxFixed):e,this.events.dispatch(this.events.change,this._value,this))}get value(){return this._value}_initEvents(){this.el.addEventListener("mousewheel",this._onMouseWheel),this.el.addEventListener("wheel",this._onMouseWheelFF),this.$input.addEventListener("input",this._onInput)}_clearEvents(){this.el.removeEventListener("mousewheel",this._onMouseWheel),this.el.removeEventListener("wheel",this._onMouseWheelFF),this.$input.removeEventListener("input",this._onInput)}remove(){this._clearEvents(),super.remove()}set visibility(e){this.el&&(this.el.style.display=e?"":"none")}}const mo=["change"];class vo extends kt{constructor(e={}){super({template:we('<div class="og-checkbox">\n <div class="og-input-label">{label}</div>\n <div class="og-checkbox-input">\n <input type="checkbox" {checked}/>\n </div>\n </div>',{label:e.label||"",checked:e.checked?"checked":""})}),this._onResize=()=>{},this._onMouseWheel=e=>{(e=e||window.event).preventDefault(),e.stopPropagation()},this._onMouseWheelFF=e=>{this._onMouseWheel(e)},this._onClick=e=>{(e=e||window.event).stopPropagation(),this.checked=!this._checked},this._checked=e.checked||!1,this._disabled=e.disabled||!1,this.events=this.events.registerNames(mo),this.$label=null,this.$input=null}set disabled(e){this._disabled=e,this._updateDisabled()}_updateDisabled(){this.el&&(this._disabled?this.el.classList.add("og-input-disabled"):this.el.classList.remove("og-input-disabled"))}get disabled(){return this._disabled}render(e){return super.render(e),this.$label=this.select(".og-input-label"),""===this.$label.innerHTML&&(this.$label.style.display="none"),this.$input=this.select("input"),this.$input.checked=this._checked,this._updateDisabled(),this._initEvents(),this}set checked(e){e!==this._checked&&(this._checked=e,this.$input&&(this.$input.checked=this._checked),this.events.dispatch(this.events.change,this._checked,this))}get checked(){return this._checked}_initEvents(){this.el.addEventListener("mousewheel",this._onMouseWheel),this.el.addEventListener("wheel",this._onMouseWheelFF),this.$input.addEventListener("click",this._onClick)}_clearEvents(){this.el.removeEventListener("mousewheel",this._onMouseWheel),this.el.removeEventListener("wheel",this._onMouseWheelFF),this.$input.removeEventListener("click",this._onClick)}remove(){this._clearEvents(),super.remove()}set visibility(e){this.el&&(this.el.style.display=e?"":"none")}}class yo extends Ot{constructor(e){super({title:"GeoObject Properties",visible:!1,resizable:!0,useHide:!0,top:25,right:85,width:252,height:480,minHeight:100,minWidth:100,model:e.model}),this._onVisibility=e=>{this.model.setVisibility(e)},this._onSelect=e=>{this.show(),this._refresh(e)},this._onUnselect=e=>{this.hide()},this._onChangeRelativePosition=e=>{let t=this.model.getSelectedEntity();t&&(t.relativePosition=e,this._refresh(t))},this._onPosition=(e,t)=>{this._refresh(t)},this._onPitch=(e,t)=>{this._pitchView.stopPropagation(),this._pitchView.value=t.getPitch()*h,this._absolutePitchView.stopPropagation(),this._absolutePitchView.value=t.getAbsolutePitch()*h},this._onYaw=(e,t)=>{this._yawView.stopPropagation(),this._yawView.value=t.getYaw()*h,this._absoluteYawView.stopPropagation(),this._absoluteYawView.value=t.getAbsoluteYaw()*h},this._onRoll=(e,t)=>{this._rollView.stopPropagation(),this._rollView.value=t.getRoll()*h,this._absoluteRollView.stopPropagation(),this._absoluteRollView.value=t.getAbsoluteRoll()*h},this._onChangeLon=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getLonLat();t.setLonLat2(parseFloat(e),i.lat,i.height),this._refresh(t)}},this._onChangeLat=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getLonLat();t.setLonLat2(i.lon,parseFloat(e),i.height),this._refresh(t)}},this._onChangeHeight=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getLonLat();t.setLonLat2(i.lon,i.lat,parseFloat(e)),this._refresh(t)}},this._onChangeX=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getCartesian();t.setCartesian(parseFloat(e),i.y,i.z),this._refresh(t)}},this._onChangeY=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getCartesian();t.setCartesian(i.x,parseFloat(e),i.z),this._refresh(t)}},this._onChangeZ=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getCartesian();t.setCartesian(i.x,i.y,parseFloat(e)),this._refresh(t)}},this._onChangeAbsoluteX=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getAbsoluteCartesian();t.setAbsoluteCartesian(parseFloat(e),i.y,i.z),this._refresh(t)}},this._onChangeAbsoluteY=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getAbsoluteCartesian();t.setAbsoluteCartesian(i.x,parseFloat(e),i.z),this._refresh(t)}},this._onChangeAbsoluteZ=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getAbsoluteCartesian();t.setAbsoluteCartesian(i.x,i.y,parseFloat(e)),this._refresh(t)}},this._onChangePitch=e=>{let t=this.model.getSelectedEntity();t&&(t.setPitch(parseFloat(e)*l),this._refresh(t))},this._onChangeYaw=e=>{let t=this.model.getSelectedEntity();t&&(t.setYaw(parseFloat(e)*l),this._refresh(t))},this._onChangeRoll=e=>{let t=this.model.getSelectedEntity();t&&(t.setRoll(parseFloat(e)*l),this._refresh(t))},this._onChangeAbsolutePitch=e=>{let t=this.model.getSelectedEntity();t&&(t.setAbsolutePitch(parseFloat(e)*l),this._refresh(t))},this._onChangeAbsoluteYaw=e=>{let t=this.model.getSelectedEntity();t&&(t.setAbsoluteYaw(parseFloat(e)*l),this._refresh(t))},this._onChangeAbsoluteRoll=e=>{let t=this.model.getSelectedEntity();t&&(t.setAbsoluteRoll(parseFloat(e)*l),this._refresh(t))},this._onChangeScale=e=>{let t=this.model.getSelectedEntity();if(t){let i=parseFloat(e);t.setScale(i),this._scaleXView.stopPropagation(),this._scaleYView.stopPropagation(),this._scaleZView.stopPropagation(),this._scaleXView.value=i,this._scaleYView.value=i,this._scaleZView.value=i}},this._onChangeScaleX=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getScale();t.setScale3v(new oe(parseFloat(e),i.y,i.z))}},this._onChangeScaleY=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getScale();t.setScale3v(new oe(i.x,parseFloat(e),i.z))}},this._onChangeScaleZ=e=>{let t=this.model.getSelectedEntity();if(t){let i=t.getScale();t.setScale3v(new oe(i.x,i.y,parseFloat(e)))}},this._onGround=()=>{let e=this.model.getSelectedEntity();e&&this.model.planet&&(this.model.planet.terrain?this.model.planet.terrain.getHeightAsync(e.getLonLat(),(e=>{this._heightView.value=e})):this._heightView.value=0)},this._relativePositionView=new vo({label:"Relative position"}),this._lonView=new po({label:"Lon",type:"number",min:-180,max:180,maxFixed:10}),this._latView=new po({label:"Lat",type:"number",min:-90,max:90,maxFixed:10}),this._heightView=new po({label:"Height",type:"number",maxFixed:4}),this._xView=new po({label:"X",type:"number",maxFixed:10}),this._yView=new po({label:"Y",type:"number"}),this._zView=new po({label:"Z",type:"number"}),this._absXView=new po({label:"Absolute X",type:"number",maxFixed:10}),this._absYView=new po({label:"Absolute Y",type:"number"}),this._absZView=new po({label:"Absolute Z",type:"number"}),this._pitchView=new po({label:"Pitch",type:"number",maxFixed:2}),this._yawView=new po({label:"Yaw",type:"number",maxFixed:2}),this._rollView=new po({label:"Roll",type:"number",maxFixed:2}),this._absolutePitchView=new po({label:"Absolute pitch",type:"number",maxFixed:2}),this._absoluteYawView=new po({label:"Absolute yaw",type:"number",maxFixed:2}),this._absoluteRollView=new po({label:"Absolute roll",type:"number",maxFixed:2}),this._scaleView=new po({label:"Scale",type:"number",maxFixed:2}),this._scaleXView=new po({label:"Scale X",type:"number",maxFixed:2}),this._scaleYView=new po({label:"Scale Y",type:"number",maxFixed:2}),this._scaleZView=new po({label:"Scale Z",type:"number",maxFixed:2}),this._groundBtn=new zt({text:"Ground",title:"Put on the ground",name:"ground",classList:["og-editor-ground_button"]})}render(e){super.render(e),this._initSceneEvents();let t=document.createElement("div");t.classList.add("og-editor_toolbar"),this.container?.appendChild(t);let i=new Ut({classList:["og-editor_toolbar-button"],icon:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" id="filter-center-focus">\n <path d="M5 15H3v4c0 1.1.9 2 2 2h4v-2H5v-4zM5 5h4V3H5c-1.1 0-2 .9-2 2v4h2V5zm14-2h-4v2h4v4h2V5c0-1.1-.9-2-2-2zm0 16h-4v2h4c1.1 0 2-.9 2-2v-4h-2v4zM12 9c-1.66 0-3 1.34-3 3s1.34 3 3 3 3-1.34 3-3-1.34-3-3-3z"/>\n</svg>',title:"Lock/Unlock camera view"});return i.appendTo(t),i.events.on("change",(e=>{e?this.model.lockView():this.model.unlockView()})),this.events.on("visibility",(e=>{e||(i.events.stopPropagation(),i.setActive(!1))})),this.events.on("visibility",this._onVisibility),this._relativePositionView.appendTo(this.container),this.model.planet&&(this._lonView.appendTo(this.container),this._latView.appendTo(this.container),this._heightView.appendTo(this.container)),this._xView.appendTo(this.container),this._yView.appendTo(this.container),this._zView.appendTo(this.container),this._absXView.appendTo(this.container),this._absYView.appendTo(this.container),this._absZView.appendTo(this.container),this._pitchView.appendTo(this.container),this._yawView.appendTo(this.container),this._rollView.appendTo(this.container),this._absolutePitchView.appendTo(this.container),this._absoluteYawView.appendTo(this.container),this._absoluteRollView.appendTo(this.container),this._scaleView.appendTo(this.container),this._scaleXView.appendTo(this.container),this._scaleYView.appendTo(this.container),this._scaleZView.appendTo(this.container),this.model.planet&&this._groundBtn.appendTo(this.container),this._relativePositionView.events.on("change",this._onChangeRelativePosition),this._lonView.events.on("change",this._onChangeLon),this._latView.events.on("change",this._onChangeLat),this._heightView.events.on("change",this._onChangeHeight),this._xView.events.on("change",this._onChangeX),this._yView.events.on("change",this._onChangeY),this._zView.events.on("change",this._onChangeZ),this._absXView.events.on("change",this._onChangeAbsoluteX),this._absYView.events.on("change",this._onChangeAbsoluteY),this._absZView.events.on("change",this._onChangeAbsoluteZ),this._pitchView.events.on("change",this._onChangePitch),this._yawView.events.on("change",this._onChangeYaw),this._rollView.events.on("change",this._onChangeRoll),this._absolutePitchView.events.on("change",this._onChangeAbsolutePitch),this._absoluteYawView.events.on("change",this._onChangeAbsoluteYaw),this._absoluteRollView.events.on("change",this._onChangeAbsoluteRoll),this._scaleView.events.on("change",this._onChangeScale),this._scaleXView.events.on("change",this._onChangeScaleX),this._scaleYView.events.on("change",this._onChangeScaleY),this._scaleZView.events.on("change",this._onChangeScaleZ),this._groundBtn.appendTo(this.container),this._groundBtn.events.on("click",this._onGround),this}remove(){super.remove(),this._clearSceneEvents()}_initSceneEvents(){this.model.events.on("select",this._onSelect),this.model.events.on("unselect",this._onUnselect),this.model.events.on("position",this._onPosition),this.model.events.on("pitch",this._onPitch),this.model.events.on("yaw",this._onYaw),this.model.events.on("roll",this._onRoll)}_clearSceneEvents(){this.model.events.off("select",this._onSelect),this.model.events.off("unselect",this._onUnselect),this.model.events.off("position",this._onPosition),this.model.events.off("pitch",this._onPitch),this.model.events.off("yaw",this._onYaw),this.model.events.off("roll",this._onRoll)}_refresh(e){e.parent?this._relativePositionView.disabled=!1:this._relativePositionView.disabled=!0,this._relativePositionView.checked=e.relativePosition;let t=e.getLonLat();this._lonView.stopPropagation(),this._latView.stopPropagation(),this._heightView.stopPropagation(),this._lonView.value=t.lon,this._latView.value=t.lat,this._heightView.value=t.height;let i=e.getCartesian();this._xView.stopPropagation(),this._yView.stopPropagation(),this._zView.stopPropagation(),this._xView.value=i.x,this._yView.value=i.y,this._zView.value=i.z,i=e.getAbsoluteCartesian(),this._absXView.stopPropagation(),this._absYView.stopPropagation(),this._absZView.stopPropagation(),this._absXView.value=i.x,this._absYView.value=i.y,this._absZView.value=i.z,this._pitchView.stopPropagation(),this._yawView.stopPropagation(),this._rollView.stopPropagation(),this._pitchView.value=e.getPitch()*h,this._yawView.value=e.getYaw()*h,this._rollView.value=e.getRoll()*h,this._absolutePitchView.stopPropagation(),this._absoluteYawView.stopPropagation(),this._absoluteRollView.stopPropagation(),this._absolutePitchView.value=e.getAbsolutePitch()*h,this._absoluteYawView.value=e.getAbsoluteYaw()*h,this._absoluteRollView.value=e.getAbsoluteRoll()*h,this._scaleView.stopPropagation();let s=e.getScale();s.x===s.y&&s.y===s.z?this._scaleView.value=s.x:this._scaleView.value=1,this._scaleXView.stopPropagation(),this._scaleYView.stopPropagation(),this._scaleZView.stopPropagation(),this._scaleXView.value=s.x,this._scaleYView.value=s.y,this._scaleZView.value=s.z}hide(){super.hide(),this.model.events.stopPropagation(),this.model.unselect()}}const xo=["lockview","unlockview"];class bo extends Dt{constructor(e={}){super(e),this._onLockViewDraw=()=>{this.renderer&&this._lockEntity&&(this._isFromTheBack||this.renderer.activeCamera.viewDistance(this._lockEntity.getAbsoluteCartesian(),this._lockDistance))},this._onMouseWheel=e=>{if(this.renderer&&this._lockEntity)if(this._isFromTheBack);else{let t=this.renderer.activeCamera.eye.distance(this._lockEntity.getAbsoluteCartesian());this._lockDistance-=.33*t*Math.sign(e.wheelDelta),this._lockDistance<.001&&(this._lockDistance=.001),this.renderer.activeCamera.viewDistance(this._lockEntity.getAbsoluteCartesian(),this._lockDistance)}},this._onMouseMove=e=>{if(this._lockEntity&&this.renderer&&(e.rightButtonDown||this.renderer.events.isKeyPressed(Cn.KEY_ALT))){let t=this._lockEntity.getAbsoluteCartesian(),i=this.renderer.activeCamera,s=.5/l;s>.007&&(s=.007),this.planet?i.rotateHorizontal(s*(e.x-e.prev_x),!1,t,t.isZero()?oe.UP:t.normal()):i.rotateHorizontal(s*(e.x-e.prev_x),!1,t,oe.UP),i.rotateVertical(s*(e.y-e.prev_y),t),this._viewDir=t.sub(i.eye).normalize()}},this.events=Mt(xo),this._name="CameraLock",this.planet=e.planet||null,this._lockDistance=0,this._isFromTheBack=!1,this._lockEntity=null,this._viewDir=new oe(0,0,0)}onactivate(){this.renderer}ondeactivate(){this.renderer&&this.unlockView()}oninit(){this.activate(),this.renderer}flyCartesian(e,t=120){if(!e.isZero()&&this.renderer)if(this.unlockView(),this.planet){let i=this.planet.camera;this.isVisibleDistance(e)&&i.flyDistance(e,t),i.eye.distance(e)<1e6?i.flyDistance(e,t):i.viewDistance(e,t)}else this.renderer.activeCamera.viewDistance(e,t)}lockView(e,t=!1){if(!this.renderer)return;this._lockDistance=this._getDistance(e,this._lockEntity),this._isFromTheBack=t,this._deactivateLockViewEvents(),this._lockEntity=e;let i=this.renderer.activeCamera;this.planet&&this.planet.camera.stopFlying(),i.viewDistance(e.getAbsoluteCartesian(),this._lockDistance),this._deactivateNav(),this._activateLockViewEvents(),this._viewDir=e.getAbsoluteCartesian().sub(i.eye).normalize(),this.events.dispatch(this.events.lockview,this._lockEntity,t)}_activateNav(){this.renderer&&this.renderer.controls.mouseNavigation&&this.renderer.controls.mouseNavigation.activate(),this.renderer&&this.renderer.controls.simpleNavigation&&this.renderer.controls.simpleNavigation.activate()}_deactivateNav(){this.renderer&&this.renderer.controls.mouseNavigation&&(this.renderer.controls.mouseNavigation.deactivate(),this.renderer.controls.mouseNavigation.stop()),this.renderer&&this.renderer.controls.simpleNavigation&&this.renderer.controls.simpleNavigation.deactivate()}unlockView(){this._lockEntity&&(this._deactivateLockViewEvents(),this._activateNav(),this.events.dispatch(this.events.unlockview,this._lockEntity),this._lockEntity=null)}_getCenterDist(){return this.renderer&&this.renderer.getDistanceFromPixel(this.renderer.handler.getCenter())||0}_getDistance(e,t){if(this.renderer){let i=e.getAbsoluteCartesian(),s=this.renderer.activeCamera,n=s.eye.distance(i);return t&&(n=s.eye.distance(t.getAbsoluteCartesian())),this.isVisibleDistance(i)?n:s.eye.distance(i)<1e6?this._getCenterDist():120}return 0}isVisibleDistance(e,t=0){if(this.planet){let i=this.planet.ellipsoid.equatorialSize,s=this.planet.camera.eye;return s.distance(e)<Math.sqrt(s.length2()-i*i)+t}return!0}get lockEntity(){return this._lockEntity}flyLonLat(e,t=120){if(this.planet){let i=this.planet.ellipsoid.lonLatToCartesian(e);this.flyCartesian(i,t)}}_activateLockViewEvents(){this.renderer&&(this.renderer.events.on("mousewheel",this._onMouseWheel),this.renderer.events.on("mousemove",this._onMouseMove),this.renderer.events.on("draw",this._onLockViewDraw))}_deactivateLockViewEvents(){this.renderer&&(this.renderer.events.off("mousewheel",this._onMouseWheel),this.renderer.events.off("mousemove",this._onMouseMove),this._lockEntity&&this.renderer.events.off("draw",this._onLockViewDraw))}}var wo=Object.freeze({__proto__:null,AtmosphereConfig:class extends Dt{constructor(e={}){super(e),this.$maxOpacity=null,this.$minOpacity=null,this.$rayleight=null,this.$mie=null,this.$height=null,this.$bottomRadius=null,this.$mieScatteringCoefficient=null,this.$mieExtinctionCoefficient=null,this.$rayleighScatteringCoefficientA=null,this.$rayleighScatteringCoefficientB=null,this.$rayleighScatteringCoefficientC=null,this.$ozoneAbsorptionCoefficientA=null,this.$ozoneAbsorptionCoefficientB=null,this.$ozoneAbsorptionCoefficientC=null,this.$sunAngularRadius=null,this.$sunIntensity=null,this.$groundAlbedo=null,this.$ozoneDensityHeight=null,this.$ozoneDensityWide=null,this._toggleBtn=new Ut({classList:["og-map-button","og-atmosphere_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<svg width="800px" height="800px" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path fill="#000000" d="M135.688 18.5c-6.798 74.842-23.842 85.39-107.907 59.656 84.85 52.022 73.57 64.954-6.843 96.938 87.743-10.27 103.29 4.89 70.75 87.594 17.805-27.56 32.5-44.498 46.282-54.47-11.813 28.26-18.345 59.274-18.345 91.813 0 84.184 43.71 157.96 109.656 200.376-41.624-43.834-67.686-102.7-67.686-167.875 0-134.923 109.45-244.405 244.375-244.405 30.92 0 60.76 5.762 88 16.25-38.584-26.87-85.517-42.625-136.064-42.625-55.257 0-106.14 18.802-146.562 50.375 4.627-18.783 17.39-38.073 41.03-60.906C190.18 90.942 153.53 95.634 135.69 18.5zm10.03 77.188c5.67.002 11.428 1.247 16.876 3.874 14.506 6.998 22.72 21.81 22 36.938-10.26 10.87-19.507 22.696-27.594 35.344-9.035 2.753-19.075 2.27-28.25-2.156-19.37-9.343-27.5-32.6-18.156-51.97 6.715-13.92 20.638-22.036 35.125-22.03z"/></svg>'}),this._dialog=new Ot({title:"Atmosphere Parameters",visible:!1,useHide:!0,top:60,left:60,width:720}),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e)})),this._panel=new kt({template:'<div class="og-atmosphere og-options-container">\n \n <div class="og-option og-atmosphere-maxOpacity"></div> \n <div class="og-option og-atmosphere-minOpacity"></div>\n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-rayleight"></div>\n <div class="og-option og-atmosphere-mie"></div>\n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-height"></div> \n <div class="og-option og-atmosphere-bottomRadius"></div>\n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-mieScatteringCoefficient"></div> \n <div class="og-option og-atmosphere-mieExtinctionCoefficient"></div>\n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-rayleighScatteringCoefficientA"></div> \n <div class="og-option og-atmosphere-rayleighScatteringCoefficientB"></div> \n <div class="og-option og-atmosphere-rayleighScatteringCoefficientC"></div>\n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-ozoneAbsorptionCoefficientA"></div> \n <div class="og-option og-atmosphere-ozoneAbsorptionCoefficientB"></div> \n <div class="og-option og-atmosphere-ozoneAbsorptionCoefficientC"></div>\n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-ozoneDensityHeight"></div> \n <div class="og-option og-atmosphere-ozoneDensityWide"></div> \n \n <div class="og-emptyline-2"></div>\n \n <div class="og-option og-atmosphere-sunAngularRadius"></div> \n <div class="og-option og-atmosphere-sunIntensity"></div> \n <div class="og-option og-atmosphere-earthAlbedo"></div>\n \n </div>'}),this._maxOpacity=new An({label:"Max.opacity",max:5}),this._minOpacity=new An({label:"Min.opacity",max:5}),this._rayleight=new An({label:"Rayleight Scale",min:-10,max:10}),this._mie=new An({label:"Mie Scale",min:-10,max:10}),this._height=new An({label:"Height",max:1e6}),this._bottomRadius=new An({label:"Planet Radius",max:31783761.571225896}),this._mieScatteringCoefficient=new An({label:"Mie Scattering Coefficient e-6",min:-39.96,max:39.96}),this._mieExtinctionCoefficient=new An({label:"Mie Extinction Coef.e-6",min:4.44*-10,max:10*4.44}),this._rayleighScatteringCoefficientA=new An({label:"Rayleight Scattering Coef A.e-6",min:5.802*-10,max:10*5.802}),this._rayleighScatteringCoefficientB=new An({label:"Rayleight Scattering Coef B.e-6",min:13.558*-10,max:10*13.558}),this._rayleighScatteringCoefficientC=new An({label:"Rayleight Scattering Coef C.e-6",min:-331,max:331}),this._ozoneAbsorptionCoefficientA=new An({label:"Ozone absorbtion Coef A.e-6",min:-6.5,max:6.5}),this._ozoneAbsorptionCoefficientB=new An({label:"Ozone absorbtion Coef B.e-6",min:-6.5,max:18.81}),this._ozoneAbsorptionCoefficientC=new An({label:"Ozone absorbtion Coef C.e-6",min:.085*-10,max:10*.085}),this._ozoneDensityHeight=new An({label:"Ozone Density Height",max:25e5}),this._ozoneDensityWide=new An({label:"Ozone Density Wide",max:25e5}),this._sunAngularRadius=new An({label:"Sun Angular Radius",max:4.685}),this._sunIntensity=new An({label:"Sun Intensity",max:10}),this._groundAlbedo=new An({label:"Earth Albedo",max:.5}),this._parameters={ATMOS_HEIGHT:0,RAYLEIGH_SCALE:0,MIE_SCALE:0,GROUND_ALBEDO:0,BOTTOM_RADIUS:0,rayleighScatteringCoefficient:[0,0,0],mieScatteringCoefficient:0,mieExtinctionCoefficient:0,ozoneAbsorptionCoefficient:[0,0,0],SUN_ANGULAR_RADIUS:0,SUN_INTENSITY:0,ozoneDensityHeight:0,ozoneDensityWide:0}}oninit(){this._toggleBtn.appendTo(this.renderer.div),this._dialog.appendTo(this.renderer.div),this._panel.appendTo(this._dialog.container),this._panel.el&&(this.$height=this._panel.el.querySelector(".og-option.og-atmosphere-height"),this.$maxOpacity=this._panel.el.querySelector(".og-option.og-atmosphere-maxOpacity"),this.$minOpacity=this._panel.el.querySelector(".og-option.og-atmosphere-minOpacity"),this.$rayleight=this._panel.el.querySelector(".og-option.og-atmosphere-rayleight"),this.$mie=this._panel.el.querySelector(".og-option.og-atmosphere-mie"),this.$bottomRadius=this._panel.el.querySelector(".og-option.og-atmosphere-bottomRadius"),this.$mieScatteringCoefficient=this._panel.el.querySelector(".og-option.og-atmosphere-mieScatteringCoefficient"),this.$mieExtinctionCoefficient=this._panel.el.querySelector(".og-option.og-atmosphere-mieExtinctionCoefficient"),this.$rayleighScatteringCoefficientA=this._panel.el.querySelector(".og-option.og-atmosphere-rayleighScatteringCoefficientA"),this.$rayleighScatteringCoefficientB=this._panel.el.querySelector(".og-option.og-atmosphere-rayleighScatteringCoefficientB"),this.$rayleighScatteringCoefficientC=this._panel.el.querySelector(".og-option.og-atmosphere-rayleighScatteringCoefficientC"),this.$ozoneAbsorptionCoefficientA=this._panel.el.querySelector(".og-option.og-atmosphere-ozoneAbsorptionCoefficientA"),this.$ozoneAbsorptionCoefficientB=this._panel.el.querySelector(".og-option.og-atmosphere-ozoneAbsorptionCoefficientB"),this.$ozoneAbsorptionCoefficientC=this._panel.el.querySelector(".og-option.og-atmosphere-ozoneAbsorptionCoefficientC"),this.$sunAngularRadius=this._panel.el.querySelector(".og-option.og-atmosphere-sunAngularRadius"),this.$sunIntensity=this._panel.el.querySelector(".og-option.og-atmosphere-sunIntensity"),this.$groundAlbedo=this._panel.el.querySelector(".og-option.og-atmosphere-earthAlbedo"),this.$ozoneDensityHeight=this._panel.el.querySelector(".og-option.og-atmosphere-ozoneDensityHeight"),this.$ozoneDensityWide=this._panel.el.querySelector(".og-option.og-atmosphere-ozoneDensityWide")),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e)})),this._maxOpacity.appendTo(this.$maxOpacity),this._minOpacity.appendTo(this.$minOpacity),this._height.appendTo(this.$height),this._rayleight.appendTo(this.$rayleight),this._mie.appendTo(this.$mie),this._bottomRadius.appendTo(this.$bottomRadius),this._mieScatteringCoefficient.appendTo(this.$mieScatteringCoefficient),this._mieExtinctionCoefficient.appendTo(this.$mieExtinctionCoefficient),this._rayleighScatteringCoefficientA.appendTo(this.$rayleighScatteringCoefficientA),this._rayleighScatteringCoefficientB.appendTo(this.$rayleighScatteringCoefficientB),this._rayleighScatteringCoefficientC.appendTo(this.$rayleighScatteringCoefficientC),this._ozoneAbsorptionCoefficientA.appendTo(this.$ozoneAbsorptionCoefficientA),this._ozoneAbsorptionCoefficientB.appendTo(this.$ozoneAbsorptionCoefficientB),this._ozoneAbsorptionCoefficientC.appendTo(this.$ozoneAbsorptionCoefficientC),this._sunAngularRadius.appendTo(this.$sunAngularRadius),this._sunIntensity.appendTo(this.$sunIntensity),this._groundAlbedo.appendTo(this.$groundAlbedo),this._ozoneDensityHeight.appendTo(this.$ozoneDensityHeight),this._ozoneDensityWide.appendTo(this.$ozoneDensityWide),this.planet&&(this._parameters=this.planet.atmosphereControl.parameters,this._height.value=this._parameters.ATMOS_HEIGHT,this._rayleight.value=this._parameters.RAYLEIGH_SCALE,this._mie.value=this._parameters.MIE_SCALE,this._bottomRadius.value=this._parameters.BOTTOM_RADIUS,this._mieScatteringCoefficient.value=this._parameters.mieScatteringCoefficient,this._mieExtinctionCoefficient.value=this._parameters.mieExtinctionCoefficient,this._rayleighScatteringCoefficientA.value=this._parameters.rayleighScatteringCoefficient[0],this._rayleighScatteringCoefficientB.value=this._parameters.rayleighScatteringCoefficient[1],this._rayleighScatteringCoefficientC.value=this._parameters.rayleighScatteringCoefficient[2],this._ozoneAbsorptionCoefficientA.value=this._parameters.ozoneAbsorptionCoefficient[0],this._ozoneAbsorptionCoefficientB.value=this._parameters.ozoneAbsorptionCoefficient[1],this._ozoneAbsorptionCoefficientC.value=this._parameters.ozoneAbsorptionCoefficient[2],this._sunAngularRadius.value=this._parameters.SUN_ANGULAR_RADIUS,this._sunIntensity.value=this._parameters.SUN_INTENSITY,this._groundAlbedo.value=this._parameters.GROUND_ALBEDO,this._ozoneDensityHeight.value=this._parameters.ozoneDensityHeight,this._ozoneDensityWide.value=this._parameters.ozoneDensityWide),this._minOpacity.value=this.planet.atmosphereMinOpacity,this._minOpacity.events.on("change",(e=>{this.planet.atmosphereMinOpacity=e})),this._maxOpacity.value=this.planet.atmosphereMaxOpacity,this._maxOpacity.events.on("change",(e=>{this.planet.atmosphereMaxOpacity=e})),this._rayleight.events.on("change",(e=>{this._parameters.RAYLEIGH_SCALE=e,this._update()})),this._mie.events.on("change",(e=>{this._parameters.MIE_SCALE=e,this._update()})),this._height.events.on("change",(e=>{this._parameters.ATMOS_HEIGHT=e,this._update()})),this._bottomRadius.events.on("change",(e=>{this._parameters.BOTTOM_RADIUS=e,this._update()})),this._mieScatteringCoefficient.events.on("change",(e=>{this._parameters.mieScatteringCoefficient=e,this._update()})),this._mieExtinctionCoefficient.events.on("change",(e=>{this._parameters.mieExtinctionCoefficient=e,this._update()})),this._rayleighScatteringCoefficientA.events.on("change",(e=>{this._parameters.rayleighScatteringCoefficient[0]=e,this._update()})),this._rayleighScatteringCoefficientB.events.on("change",(e=>{this._parameters.rayleighScatteringCoefficient[1]=e,this._update()})),this._rayleighScatteringCoefficientC.events.on("change",(e=>{this._parameters.rayleighScatteringCoefficient[2]=e,this._update()})),this._ozoneAbsorptionCoefficientA.events.on("change",(e=>{this._parameters.ozoneAbsorptionCoefficient[0]=e,this._update()})),this._ozoneAbsorptionCoefficientB.events.on("change",(e=>{this._parameters.ozoneAbsorptionCoefficient[1]=e,this._update()})),this._ozoneAbsorptionCoefficientC.events.on("change",(e=>{this._parameters.ozoneAbsorptionCoefficient[2]=e,this._update()})),this._sunAngularRadius.events.on("change",(e=>{this._parameters.SUN_ANGULAR_RADIUS=e,this._update()})),this._sunIntensity.events.on("change",(e=>{this._parameters.SUN_INTENSITY=e,this._update()})),this._groundAlbedo.events.on("change",(e=>{this._parameters.GROUND_ALBEDO=e,this._update()})),this._ozoneDensityHeight.events.on("change",(e=>{this._parameters.ozoneDensityHeight=e,this._update()})),this._ozoneDensityWide.events.on("change",(e=>{this._parameters.ozoneDensityWide=e,this._update()}))}_update(){this.planet&&this.planet.atmosphereControl.setParameters(this._parameters)}},CameraLock:bo,CompassButton:Ft,Control:Dt,DebugInfo:class extends Dt{constructor(e={}){e.name&&""!==e.name||(e.name="DebugInfo"),super(e),this.el=null,this._watch=e.watch||[],this._toggleBtn=new Ut({classList:["og-map-button","og-debuginfo_button"],icon:'<?xml version="1.0" encoding="iso-8859-1"?>\n\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg fill="#000000" version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" \n\t width="800px" height="800px" viewBox="0 0 932.179 932.179"\n\t xml:space="preserve">\n<g>\n\t<path d="M61.2,341.538c4.9,16.8,11.7,33,20.3,48.2l-24.5,30.9c-8,10.1-7.1,24.5,1.9,33.6l42.2,42.2c9.1,9.1,23.5,9.899,33.6,1.899\n\t\tl30.7-24.3c15.8,9.101,32.6,16.2,50.1,21.2l4.6,39.5c1.5,12.8,12.3,22.4,25.1,22.4h59.7c12.8,0,23.6-9.601,25.1-22.4l4.4-38.1\n\t\tc18.8-4.9,36.8-12.2,53.7-21.7l29.7,23.5c10.1,8,24.5,7.1,33.6-1.9l42.2-42.2c9.1-9.1,9.9-23.5,1.9-33.6l-23.1-29.3\n\t\tc9.6-16.601,17.1-34.3,22.1-52.8l35.6-4.1c12.801-1.5,22.4-12.3,22.4-25.1v-59.7c0-12.8-9.6-23.6-22.4-25.1l-35.1-4.1\n\t\tc-4.801-18.3-12-35.8-21.199-52.2l21.6-27.3c8-10.1,7.1-24.5-1.9-33.6l-42.1-42.1c-9.1-9.1-23.5-9.9-33.6-1.9l-26.5,21\n\t\tc-17.2-10.1-35.601-17.8-54.9-23l-4-34.3c-1.5-12.8-12.3-22.4-25.1-22.4h-59.7c-12.8,0-23.6,9.6-25.1,22.4l-4,34.3\n\t\tc-19.8,5.3-38.7,13.3-56.3,23.8l-27.5-21.8c-10.1-8-24.5-7.1-33.6,1.9l-42.2,42.2c-9.1,9.1-9.9,23.5-1.9,33.6l23,29.1\n\t\tc-9.2,16.6-16.2,34.3-20.8,52.7l-36.8,4.2c-12.8,1.5-22.4,12.3-22.4,25.1v59.7c0,12.8,9.6,23.6,22.4,25.1L61.2,341.538z\n\t\t M277.5,180.038c54.4,0,98.7,44.3,98.7,98.7s-44.3,98.7-98.7,98.7c-54.399,0-98.7-44.3-98.7-98.7S223.1,180.038,277.5,180.038z"/>\n\t<path d="M867.699,356.238l-31.5-26.6c-9.699-8.2-24-7.8-33.199,0.9l-17.4,16.3c-14.699-7.1-30.299-12.1-46.4-15l-4.898-24\n\t\tc-2.5-12.4-14-21-26.602-20l-41.1,3.5c-12.6,1.1-22.5,11.4-22.9,24.1l-0.799,24.4c-15.801,5.7-30.701,13.5-44.301,23.3\n\t\tl-20.799-13.8c-10.602-7-24.701-5-32.9,4.7l-26.6,31.7c-8.201,9.7-7.801,24,0.898,33.2l18.201,19.399\n\t\tc-6.301,14.2-10.801,29.101-13.4,44.4l-26,5.3c-12.4,2.5-21,14-20,26.601l3.5,41.1c1.1,12.6,11.4,22.5,24.1,22.9l28.1,0.899\n\t\tc5.102,13.4,11.801,26.101,19.9,38l-15.699,23.7c-7,10.6-5,24.7,4.699,32.9l31.5,26.6c9.701,8.2,24,7.8,33.201-0.9l20.6-19.3\n\t\tc13.5,6.3,27.699,11,42.299,13.8l5.701,28.2c2.5,12.4,14,21,26.6,20l41.1-3.5c12.6-1.1,22.5-11.399,22.9-24.1l0.9-27.601\n\t\tc15-5.3,29.199-12.5,42.299-21.399l22.701,15c10.6,7,24.699,5,32.9-4.7l26.6-31.5c8.199-9.7,7.799-24-0.9-33.2l-18.301-19.399\n\t\tc6.701-14.2,11.602-29.2,14.4-44.601l25-5.1c12.4-2.5,21-14,20-26.601l-3.5-41.1c-1.1-12.6-11.4-22.5-24.1-22.9l-25.1-0.8\n\t\tc-5.201-14.6-12.201-28.399-20.9-41.2l13.699-20.6C879.4,378.638,877.4,364.438,867.699,356.238z M712.801,593.837\n\t\tc-44.4,3.801-83.602-29.3-87.301-73.699c-3.801-44.4,29.301-83.601,73.699-87.301c44.4-3.8,83.602,29.301,87.301,73.7\n\t\tC790.301,550.938,757.199,590.138,712.801,593.837z"/>\n\t<path d="M205,704.438c-12.6,1.3-22.3,11.899-22.4,24.6l-0.3,25.3c-0.2,12.7,9.2,23.5,21.8,25.101l18.6,2.399\n\t\tc3.1,11.301,7.5,22.101,13.2,32.301l-12,14.8c-8,9.899-7.4,24.1,1.5,33.2l17.7,18.1c8.9,9.1,23.1,10.1,33.2,2.3l14.899-11.5\n\t\tc10.5,6.2,21.601,11.101,33.2,14.5l2,19.2c1.3,12.6,11.9,22.3,24.6,22.4l25.301,0.3c12.699,0.2,23.5-9.2,25.1-21.8l2.3-18.2\n\t\tc12.601-3.101,24.601-7.8,36-14l14,11.3c9.9,8,24.101,7.4,33.201-1.5l18.1-17.7c9.1-8.899,10.1-23.1,2.301-33.2L496.6,818.438\n\t\tc6.6-11,11.701-22.7,15.201-35l16.6-1.7c12.6-1.3,22.299-11.9,22.4-24.6l0.299-25.301c0.201-12.699-9.199-23.5-21.799-25.1\n\t\tl-16.201-2.1c-3.1-12.2-7.699-24-13.699-35l10.1-12.4c8-9.9,7.4-24.1-1.5-33.2l-17.699-18.1c-8.9-9.101-23.102-10.101-33.201-2.3\n\t\tl-12.101,9.3c-11.399-6.9-23.6-12.2-36.399-15.8l-1.601-15.7c-1.3-12.601-11.899-22.3-24.6-22.4l-25.3-0.3\n\t\tc-12.7-0.2-23.5,9.2-25.101,21.8l-2,15.601c-13.199,3.399-25.899,8.6-37.699,15.399l-12.5-10.2c-9.9-8-24.101-7.399-33.201,1.5\n\t\tl-18.2,17.801c-9.1,8.899-10.1,23.1-2.3,33.199l10.7,13.801c-6.2,11-11.1,22.699-14.3,35L205,704.438z M368.3,675.837\n\t\tc36.3,0.4,65.399,30.301,65,66.601c-0.4,36.3-30.301,65.399-66.601,65c-36.3-0.4-65.399-30.3-65-66.601\n\t\tC302.1,704.538,332,675.438,368.3,675.837z"/>\n</g>\n</svg>'}),this._dialog=new Ot({title:"Debug Info",visible:!1,useHide:!0,top:120,left:60,width:480}),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e)})),this._canvasTiles=new Kt("Tile grid",{visibility:!0,isBaseLayer:!1,hideInLayerSwitcher:!0,drawTile:function(e,t){let i,s=document.createElement("canvas"),n=s.getContext("2d");s.width=256,s.height=256,n.clearRect(0,0,s.width,s.height),n.beginPath(),n.rect(0,0,s.width,s.height),n.lineWidth=2,n.strokeStyle="black",n.stroke(),i=e.segment.tileZoom>14?"26":"32",n.fillStyle="black",n.font="normal "+i+"px Verdana",n.textAlign="center",n.fillText(e.segment.tileX+","+e.segment.tileY+","+e.segment.tileZoom,s.width/2,s.height/2),t(s)}})}addWatches(e){for(let t=0;t<e.length;t++)this.addWatch(e[t])}addWatch(e){this._watch.push(e);let t=document.createElement("div");t.classList.add("og-watch-line"),t.innerHTML=`<div class="og-watch-label">${e.label}</div><div class="og-watch-value"></div>`,e.valEl=t.querySelector(".og-watch-value"),this.el.appendChild(t)}oninit(){this._toggleBtn.appendTo(this.renderer.div),this._dialog.appendTo(this.renderer.div),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e)})),this.el=document.createElement("div"),this.el.className="og-debug-info";let e=document.createElement("div");e.classList.add("og-debuginfo_controls"),this.el.appendChild(e);let t=this._watch;this._watch=[];for(let e=0;e<t.length;e++)this.addWatch(t[e]);this._dialog.container?.appendChild(this.el),this.renderer.events.on("draw",this._frame,this);let i=this.planet;i&&this.addWatches([{label:"Nodes count",frame:()=>i._renderedNodes.length},{label:"Planet._fadingNodes",frame:()=>i._fadingNodes.size},{label:"createdNodes",frame:()=>i._createdNodesCount},{label:"indexesCache",frame:()=>i._indexesCacheToRemoveCounter},{label:"distBeforeMemClear",frame:()=>Math.round(i._distBeforeMemClear)},{label:"maxZoom/minZoom",frame:()=>i.maxCurrZoom+" / "+i?.minCurrZoom},{label:"viewExtent",frame:()=>i.getViewExtent().toString()},{label:"Mouse distance, m",frame:()=>{let e=i.getCartesianFromMouseTerrain();return e?i.camera.eye.distance(e).toFixed(3):""}},{label:"lodSize",frame:()=>Math.round(i.lodSize)},{label:"deltaTime/FPS",frame:()=>`<div style="width:70px"><div style="width:20px; float: left;">\n ${Math.round(i.renderer.handler.deltaTime)}\n </div> <div style="float: left">\n ${Math.round(1e3/i.renderer.handler.deltaTime)}\n </div></div>`},{label:"-------------------------"},{label:"Pitch, deg",frame:()=>(i.camera.getPitch()*h).toFixed(2)},{label:"Yaw, deg",frame:()=>(i.camera.getYaw()*h).toFixed(2)},{label:"Roll, deg",frame:()=>(i.camera.getRoll()*h).toFixed(2)},{label:"Lon, Lat",frame:()=>`<div style="width:190px">${i.camera._lonLat.lon.toFixed(7)}, ${i.camera._lonLat.lon.toFixed(7)}</div>`},{label:"height/alt, m",frame:()=>`<div style="width:190px">${i.camera._lonLat.height.toFixed(2)+" / "+i.camera.getAltitude().toFixed(2)}</div>`},{label:"cam.slope",frame:()=>i.camera.slope.toFixed(3)},{label:"-------------------------"},{label:"_renderCompleted / renderCompletedActivated",frame:()=>`${i._renderCompleted} / ${i._renderCompletedActivated}`},{label:"_terrainCompleted / terrainCompletedActivated",frame:()=>`${i._terrainCompleted} / ${i._terrainCompletedActivated}`},{label:"PlainWorker",frame:()=>i._plainSegmentWorker.pendingQueue.length},{label:"TileLoader",frame:()=>`${i._tileLoader.loading} ${i._tileLoader.queue.length}`},{label:"TerrainLoader",frame:()=>i.terrain&&!i.terrain.isEmpty?`${i.terrain.loader.loading} ${i.terrain.loader.queue.length}`:""},{label:"TerrainWorker",frame:()=>i._terrainWorker.pendingQueue.length},{label:"NormalMapCreator",frame:()=>i._normalMapCreator.queueSize},{label:"VectorTileCreator",frame:()=>i._vectorTileCreator.queueSize}]);let s=new Ut({classList:["og-debuginfo_controls-button"],icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<svg fill="#000000" width="800px" height="800px" viewBox="-7.5 0 32 32" version="1.1" xmlns="http://www.w3.org/2000/svg">\n<title>lock</title>\n<path d="M14.625 15.156h2.094c0.281 0 0.5 0.25 0.5 0.531v11c0 0.281-0.219 0.5-0.5 0.5h-16.219c-0.281 0-0.5-0.219-0.5-0.5v-11c0-0.281 0.219-0.531 0.5-0.531h2.031v-5.125c0-2.875 1.844-5.25 4.688-5.25h2.688c2.875 0 4.719 2.375 4.719 5.25v5.125zM5.188 15.156h6.813v-4.875c0-1.594-1.313-2.938-2.938-2.938h-0.969c-1.594 0-2.906 1.344-2.906 2.938v4.875zM7.156 24h2.906l-0.719-3.156c0.5-0.25 0.844-0.781 0.844-1.375 0-0.906-0.719-1.594-1.594-1.594s-1.563 0.688-1.563 1.594c0 0.594 0.344 1.125 0.844 1.375z"></path>\n</svg>',title:"Lock/Unlock quad tree"});s.appendTo(e),s.events.on("change",(e=>{e?i.lockQuadTree():i.unlockQuadTree()}));let n=new Ut({classList:["og-debuginfo_controls-button"],icon:'<?xml version="1.0"?>\n<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24">\n <path d="M 4 4 L 4 8 L 8 8 L 8 4 L 4 4 z M 10 4 L 10 8 L 14 8 L 14 4 L 10 4 z M 16 4 L 16 8 L 20 8 L 20 4 L 16 4 z M 4 10 L 4 14 L 8 14 L 8 10 L 4 10 z M 10 10 L 10 14 L 14 14 L 14 10 L 10 10 z M 16 10 L 16 14 L 20 14 L 20 10 L 16 10 z M 4 16 L 4 20 L 8 20 L 8 16 L 4 16 z M 10 16 L 10 20 L 14 20 L 14 16 L 10 16 z M 16 16 L 16 20 L 20 20 L 20 16 L 16 16 z"/>\n</svg>',title:"Show/Hide grid"});n.appendTo(e),n.events.on("change",(e=>{e?this.planet.addLayer(this._canvasTiles):this._canvasTiles.remove()}))}_frame(){this._watch.forEach((e=>{e.valEl&&(e.valEl.innerHTML=e.frame?String(e.frame()):"")}))}},DrawingControl:rn,DrawingSwitcher:class extends Dt{constructor(e={}){super({name:"DrawingSwitcher",...e}),this.drawingControl=new rn}oninit(){this.planet.addControl(this.drawingControl),this._createMenu()}onactivate(){this.drawingControl.activate()}ondeactivate(){this.drawingControl.deactivate()}_createMenu(){let e=new Ut({classList:["og-map-button","og-drawing-default_button"],icon:'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24"><path d="M4 0l16 12.279-6.951 1.17 4.325 8.817-3.596 1.734-4.35-8.879-5.428 4.702z"/></svg>',name:"default",isActive:!0}),t=new Ut({classList:["og-map-button","og-drawing-polygon_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Generator: Adobe Illustrator 24.1.3, SVG Export Plug-In . SVG Version: 6.00 Build 0) --\x3e\n<svg version="1.1" id="Layer_2" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"\n\t viewBox="0 0 1024 1024" style="enable-background:new 0 0 1024 1024;" xml:space="preserve">\n<g>\n\t<path d="M926.03,321.16c-16.02,0-31.11,3.94-44.48,10.79l-263.43-191.4c2.69-8.94,4.18-18.4,4.18-28.2\n\t\tc0-54.02-43.95-97.97-97.97-97.97c-54.03,0-97.98,43.95-97.98,97.97c0,9.81,1.49,19.27,4.18,28.21L155.75,340.18\n\t\tc-16.22-11.91-36.16-19.03-57.78-19.03C43.95,321.16,0,365.11,0,419.13c0,52.58,41.67,95.5,93.71,97.75l102.63,315.86\n\t\tc-24.28,17.85-40.13,46.52-40.13,78.9c0,54.02,43.95,97.98,97.98,97.98c37.54,0,70.18-21.25,86.62-52.34h367.26\n\t\tc16.44,31.08,49.08,52.34,86.63,52.34c54.03,0,97.98-43.95,97.98-97.98c0-32.46-15.94-61.21-40.33-79.05l104.11-320.4\n\t\tc39.15-12.84,67.54-49.68,67.54-93.07C1024,365.11,980.05,321.16,926.03,321.16z M828.05,911.65c0,8.5-3.3,16.19-8.55,22.09\n\t\tc-6.11,6.85-14.9,11.26-24.79,11.26c-13.65,0-25.37-8.26-30.52-20.02c-1.79-4.09-2.82-8.58-2.82-13.33\n\t\tc0-18.39,14.95-33.35,33.34-33.35c2.93,0,5.72,0.5,8.43,1.21c13.27,3.49,23.21,14.91,24.59,28.9\n\t\tC827.83,909.5,828.05,910.54,828.05,911.65z M790.48,813.89c-45.63,1.96-83.27,35.16-91.87,78.77H350.28\n\t\tc-8.62-43.69-46.38-76.93-92.11-78.79L155.59,498.19c24.41-17.84,40.36-46.59,40.36-79.06c0-8.9-1.3-17.49-3.53-25.7L468.57,192.8\n\t\tc15.84,11.01,35.05,17.52,55.76,17.52c20.71,0,39.92-6.5,55.76-17.52l256.56,186.4c-5.48,12.21-8.59,25.7-8.59,39.93\n\t\tc0,41.02,25.36,76.17,61.21,90.75L790.48,813.89z M254.19,945c-10.11,0-19.07-4.62-25.19-11.75c-5.01-5.84-8.15-13.32-8.15-21.6\n\t\tc0-0.91,0.2-1.76,0.27-2.66c1.14-14.18,11.08-25.8,24.43-29.41c2.78-0.75,5.64-1.28,8.65-1.28c18.38,0,33.33,14.96,33.33,33.35\n\t\tc0,4.74-1.03,9.24-2.82,13.33C279.55,936.74,267.83,945,254.19,945z M64.88,421.49c-0.06-0.79-0.24-1.55-0.24-2.35\n\t\tc0-16.41,11.93-30.01,27.55-32.76c1.89-0.33,3.8-0.58,5.78-0.58c11.94,0,22.35,6.36,28.24,15.81c3.18,5.11,5.11,11.09,5.11,17.53\n\t\tc0,15.47-10.63,28.39-24.94,32.14c-2.7,0.71-5.48,1.2-8.4,1.2C80.4,452.47,66.11,438.76,64.88,421.49z M549.41,90.62\n\t\tc5.07,5.85,8.25,13.39,8.25,21.72c0,7.32-2.44,14.03-6.45,19.54c-6.07,8.33-15.82,13.81-26.88,13.81\n\t\tc-11.07,0-20.83-5.48-26.89-13.81c-4.01-5.51-6.45-12.22-6.45-19.54c0-8.33,3.17-15.86,8.24-21.71\n\t\tc6.12-7.07,15.04-11.64,25.1-11.64C534.38,79,543.29,83.57,549.41,90.62z M959.36,419.13c0,11.94-6.36,22.35-15.82,28.24\n\t\tc-5.1,3.18-11.07,5.1-17.52,5.1c-6.08,0-11.71-1.76-16.62-4.61c-9.71-5.64-16.33-15.94-16.64-27.89c-0.01-0.29-0.09-0.56-0.09-0.85\n\t\tc0-11.75,6.14-22.05,15.36-28c5.2-3.35,11.35-5.35,17.99-5.35C944.41,385.78,959.36,400.75,959.36,419.13z"/>\n</g>\n</svg>',name:"polygon"}),i=new Ut({classList:["og-map-button","og-drawing-linestring_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\x3c!-- License: MIT. Made by Esri: https://github.com/Esri/calcite-ui-icons --\x3e\n <svg width="800px" height="800px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M21 6h.046l-5.25 9h-.944L10 9.455V7H7v2.926L1.862 18H0v3h3v-2.926L8.138 10h1.01L14 15.545V18h3v-3h-.046l5.25-9H24V3h-3zM8 8h1v1H8zM2 20H1v-1h1zm14-3h-1v-1h1zm7-13v1h-1V4z"/></svg>',name:"linestring"});new Jt({buttons:[e,t,i]}).events.on("change",(e=>{switch(this.drawingControl.deactivate(),e.name){case"polygon":this.drawingControl.activatePolygonDrawing();break;case"linestring":this.drawingControl.activateLineStringDrawing()}})),e.appendTo(this.renderer.div),t.appendTo(this.renderer.div),i.appendTo(this.renderer.div)}},EarthCoordinates:xn,ElevationProfileControl:class extends Dt{constructor(e={}){super({name:"ElevationProfileControl",...e}),this._onSceneChange=()=>{this._collectProfileThrottled()},this._onElevationProfilePointer=(e,t,i,s,n,r,o,a)=>{let l=this._elevationProfileScene.getPointLonLat(r),h=this._elevationProfileScene.getPointLonLat(r+1),c=this.planet.ellipsoid.lonLatToCartesian(l),d=this.planet.ellipsoid.lonLatToCartesian(h),_=(e-t[0])/(i[0]-t[0]),u=d.sub(c);this._elevationProfileScene.setPointerCartesian3v(c.add(u.scale(_)),a)},this._onElevationProfileDblClick=(e,t,i,s,n,r,o,a)=>{let l=this._elevationProfileScene.getPointLonLat(r),h=this._elevationProfileScene.getPointLonLat(r+1),c=this.planet.ellipsoid.lonLatToCartesian(l),d=this.planet.ellipsoid.lonLatToCartesian(h),_=(e-t[0])/(i[0]-t[0]),u=d.sub(c),g=c.add(u.scale(_));this.planet.camera.flyDistance(g,this.planet.camera.eye.distance(g))},this._onElevationProfileMouseEnter=()=>{this._elevationProfileView.model.pointsReady&&this._elevationProfileScene.setPointerVisibility(!0)},this._onElevationProfileMouseLeave=()=>{},this._elevationProfileScene=new zr,this._elevationProfileView=new Lr,this._elevationProfileLegend=new Or,this._elevationProfileButtonsView=new Nr({model:this._elevationProfileView.model}),this._elevationProfileView.events.on("pointer",this._onElevationProfilePointer),this._elevationProfileView.events.on("dblclick",this._onElevationProfileDblClick),this._elevationProfileView.events.on("mouseenter",this._onElevationProfileMouseEnter),this._elevationProfileView.events.on("mouseleave",this._onElevationProfileMouseLeave),this._dialog=new Ot({title:"Elevation Profile",visible:!1,resizable:!0,useHide:!0,top:175,left:65,width:400,height:200,minHeight:100,minWidth:100}),this._graphView=new kt({template:'<div class="og-elevationprofile__container">\n <div class="og-elevationprofile__menu"></div>\n <div class="og-elevationprofile__graph"></div>\n </div>'}),this._poiListDialog=new Hr({model:this._elevationProfileScene}),this._toggleBtn=new Ut({classList:["og-map-button","og-elevationprofile_button"],icon:'<svg style="width: 2em; height: 2em;" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg"><path d="M128 896v-158.293333l331.946667-191.573334 160.853333 93.866667L896 480V896H128M896 381.44l-275.2 159.146667-160.853333-92.586667L128 640v-94.293333l331.946667-191.573334 160.853333 93.866667L896 288v93.44z" fill="" /></svg>'}),this._collectProfileThrottled=Ne((()=>{let e=this._elevationProfileScene.getPointsLonLat();this._elevationProfileView.model.collectProfile(e)}),250)}oninit(){this._dialog.appendTo(this.planet.renderer.div),this._graphView.appendTo(this._dialog.container),this._toggleBtn.appendTo(this.renderer.div),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e),e?(this.activate(),this._elevationProfileView.resize()):this.deactivate()})),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e)})),this._elevationProfileView.appendTo(this._graphView.select(".og-elevationprofile__graph")),this._elevationProfileView.model.bindPlanet(this.planet),this._elevationProfileView.model.events.on("clear",(()=>{this._elevationProfileScene.clear(),this._elevationProfileLegend.clear()})),this._elevationProfileView.model.events.on("startcollecting",(()=>{this._elevationProfileScene.setPointerVisibility(!1)})),this._elevationProfileView.events.on("tracklength",(e=>{this._elevationProfileLegend.setTrackLength(e)})),this._elevationProfileView.events.on("groundlength",(e=>{this._elevationProfileLegend.setGroundLength(e)})),this._elevationProfileView.events.on("warninglength",(e=>{this._elevationProfileLegend.setWarningLength(e)})),this._elevationProfileView.events.on("collisionlength",(e=>{this._elevationProfileLegend.setCollisionLength(e)})),this._poiListDialog.appendTo(this.planet.renderer.div),this._poiListDialog.events.on("visibility",(e=>{this._elevationProfileButtonsView.pointListBtn.setActive(e,!0)})),this._elevationProfileLegend.appendTo(this._graphView.select(".og-elevationprofile__menu")),this._elevationProfileButtonsView.appendTo(this._graphView.select(".og-elevationprofile__menu")),this._elevationProfileButtonsView.events.on("list",(e=>{this._poiListDialog.setVisibility(e)})),this._elevationProfileButtonsView.events.on("location",(e=>{this._elevationProfileScene.flyExtent()})),this._elevationProfileButtonsView.events.on("reset",(e=>{this._elevationProfileScene.setPointerVisibility(!1)})),this._elevationProfileScene.events.on("change",this._onSceneChange)}onactivate(){this.planet&&this._elevationProfileScene.bindPlanet(this.planet),this.renderer&&this.renderer.addNode(this._elevationProfileScene)}ondeactivate(){this._poiListDialog.setVisibility(!1),this._elevationProfileView.model.clear(),this.renderer&&this.renderer.removeNode(this._elevationProfileScene),this._dialog.hide()}},GeoImageDragControl:class extends Dt{constructor(e={}){super(e),this._cornerIndex=-1,this._catchCorner=!1,this._toggleBtn=new Ut({classList:["og-map-button","og-geoimagegrag_button"],icon:'<?xml version="1.0" encoding="UTF-8" standalone="no"?> <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24"><path d="M16 13l6.964 4.062-2.973.85 2.125 3.681-1.732 1-2.125-3.68-2.223 2.15L16 13zm-2-7h2v2h5a1 1 0 0 1 1 1v4h-2v-3H10v10h4v2H9a1 1 0 0 1-1-1v-5H6v-2h2V9a1 1 0 0 1 1-1h5V6zM4 14v2H2v-2h2zm0-4v2H2v-2h2zm0-4v2H2V6h2zm0-4v2H2V2h2zm4 0v2H6V2h2zm4 0v2h-2V2h2zm4 0v2h-2V2h2z" fill="#000"/></svg>'})}oninit(){this._toggleBtn.appendTo(this.renderer.div),this.planet.events.on("layeradd",(e=>{this.isActive()&&this._bindLayer(e)}),this),this._toggleBtn.events.on("change",(e=>{e?this.activate():this.deactivate()}))}onactivate(){super.onactivate();const e=this.planet;for(let t=0;t<e.layers.length;t++)this._bindLayer(e.layers[t])}ondeactivate(){super.ondeactivate();const e=this.planet;for(let t=0;t<e.layers.length;t++)this._unbindLayer(e.layers[t])}_bindLayer(e){e instanceof wn&&(e.events.on("mousemove",this._onMouseMove,this),e.events.on("mouseleave",this._onMouseLeave,this),e.events.on("ldown",this._onLDown,this),e.events.on("lup",this._onLUp,this))}_unbindLayer(e){e instanceof wn&&(e.events.off("mousemove",this._onMouseMove),e.events.off("mouseleave",this._onMouseLeave),e.events.off("ldown",this._onLDown),e.events.off("lup",this._onLUp))}_onLUp(e){this._catchCorner=!1,e.renderer.controls.mouseNavigation.activate()}_onLDown(e){-1!==this._cornerIndex&&(this._catchCorner=!0,e.renderer.controls.mouseNavigation.deactivate())}_onMouseLeave(){document.body.style.cursor="auto"}_onMouseMove(e){let t=e.pickingObject;const i=this.planet;if(this._catchCorner){let s=t.getCornersLonLat();s[this._cornerIndex]=i.getLonLatFromPixelTerrain(e),t.setCornersLonLat(s)}else{this._cornerIndex=-1;for(let s=0;s<t._cornersWgs84.length;s++){let n=i.getLonLatFromPixelTerrain(e);if(n&&i.ellipsoid.getGreatCircleDistance(t._cornersWgs84[s],n)/i.getDistanceFromPixel(e)<=.05){this._cornerIndex=s,document.body.style.cursor="move";break}document.body.style.cursor="auto"}}}},GeoObjectEditor:class extends Dt{constructor(e={}){super(e),this._geoObjectEditopScene=new uo({name:`geoObjectEditorScene:${this.__id}`}),this._dialog=new yo({model:this._geoObjectEditopScene})}oninit(){this.renderer&&(this.renderer.addControl(new bo({planet:this.planet})),this._geoObjectEditopScene.bindPlanet(this.planet),this._dialog.appendTo(this.renderer.div||document.body),this.activate())}onactivate(){this.renderer&&this.renderer.addNode(this._geoObjectEditopScene)}ondeactivate(){this.renderer&&this.renderer.removeNode(this._geoObjectEditopScene),this._dialog.hide()}},HeightRuler:$n,KeyboardNavigation:class extends Dt{constructor(e={}){e=e||{},super({name:"KeyboardNavigation",...e}),this.step=e.step||25e3}onactivate(){let e=this.renderer;e.events.on("keypress",Cn.KEY_PGUP,this.onCameraMoveForward,this),e.events.on("keypress",Cn.KEY_PGDN,this.onCameraMoveBackward,this),e.events.on("keypress",Cn.KEY_PLUS,this.onCameraMoveForward,this),e.events.on("keypress",Cn.KEY_EQUALS,this.onCameraMoveForward,this),e.events.on("keypress",Cn.KEY_MINUS,this.onCameraMoveBackward,this),e.events.on("keypress",Cn.KEY_W,this.onCameraMoveForward,this),e.events.on("keypress",Cn.KEY_S,this.onCameraMoveBackward,this),e.events.on("keypress",Cn.KEY_A,this.onCameraStrifeLeft,this),e.events.on("keypress",Cn.KEY_D,this.onCameraStrifeRight,this),e.events.on("keypress",Cn.KEY_UP,this.onCameraLookUp,this),e.events.on("keypress",Cn.KEY_DOWN,this.onCameraLookDown,this),e.events.on("keypress",Cn.KEY_LEFT,this.onCameraLookLeft,this),e.events.on("keypress",Cn.KEY_RIGHT,this.onCameraLookRight,this),e.events.on("keypress",Cn.KEY_Q,this.onCameraRollLeft,this),e.events.on("keypress",Cn.KEY_E,this.onCameraRollRight,this),e.events.on("keypress",Cn.KEY_N,this.onCameraRollNorth,this)}ondeactivate(){let e=this.renderer;e.events.off("keypress",Cn.KEY_PGUP,this.onCameraMoveForward),e.events.off("keypress",Cn.KEY_PGDN,this.onCameraMoveBackward),e.events.off("keypress",Cn.KEY_PLUS,this.onCameraMoveForward),e.events.off("keypress",Cn.KEY_EQUALS,this.onCameraMoveForward),e.events.off("keypress",Cn.KEY_MINUS,this.onCameraMoveBackward),e.events.off("keypress",Cn.KEY_W,this.onCameraMoveForward),e.events.off("keypress",Cn.KEY_S,this.onCameraMoveBackward),e.events.off("keypress",Cn.KEY_A,this.onCameraStrifeLeft),e.events.off("keypress",Cn.KEY_D,this.onCameraStrifeRight),e.events.off("keypress",Cn.KEY_UP,this.onCameraLookUp),e.events.off("keypress",Cn.KEY_DOWN,this.onCameraLookDown),e.events.off("keypress",Cn.KEY_LEFT,this.onCameraLookLeft),e.events.off("keypress",Cn.KEY_RIGHT,this.onCameraLookRight),e.events.off("keypress",Cn.KEY_Q,this.onCameraRollLeft),e.events.off("keypress",Cn.KEY_E,this.onCameraRollRight),e.events.off("keypress",Cn.KEY_N,this.onCameraRollNorth)}oninit(){this.activate()}onCameraMoveForward(){let e=this.planet.camera;e.slide(0,0,-e.getAltitude()/this.step)}onCameraMoveBackward(){let e=this.planet.camera;e.slide(0,0,e.getAltitude()/this.step)}onCameraStrifeLeft(){let e=this.planet.camera;e.slide(-e.getAltitude()/this.step,0,0)}onCameraStrifeRight(){let e=this.planet.camera;e.slide(e.getAltitude()/this.step,0,0)}onCameraLookUp(){let e=this.planet.camera;this.renderer.events.isKeyPressed(Cn.KEY_SHIFT)?e.setPitch(15/this.renderer.handler.deltaTime):e.rotateVertical(e.getAltitude()/3e6*l,oe.ZERO)}onCameraLookDown(){let e=this.planet.camera;this.renderer.events.isKeyPressed(Cn.KEY_SHIFT)?e.setPitch(-15/this.renderer.handler.deltaTime):e.rotateVertical(-e.getAltitude()/3e6*l,oe.ZERO)}onCameraLookLeft(){let e=this.planet.camera;this.renderer.events.isKeyPressed(Cn.KEY_SHIFT)?e.setRoll(15/this.renderer.handler.deltaTime):e.rotateHorizontal(e.getAltitude()/3e6*l)}onCameraLookRight(){let e=this.planet.camera;this.renderer.events.isKeyPressed(Cn.KEY_SHIFT)?e.setRoll(-15/this.renderer.handler.deltaTime):e.rotateHorizontal(-e.getAltitude()/3e6*l)}onCameraTurnLeft(){let e=this.planet.camera;this.renderer.events.isKeyPressed(Cn.KEY_SHIFT)?e.setYaw(15/this.renderer.handler.deltaTime):e.rotateHorizontal(e.getAltitude()/3e6*l)}onCameraTurnRight(){let e=this.planet.camera;this.renderer.events.isKeyPressed(Cn.KEY_SHIFT)?e.setYaw(-15/this.renderer.handler.deltaTime):e.rotateHorizontal(-e.getAltitude()/3e6*l,!1,oe.ZERO)}onCameraRollNorth(){let e=this.planet.getCartesianFromPixelTerrain(this.renderer.handler.getCenter());e?this.planet.flyCartesian(e.normal().scaleTo(e.length()+e.distance(this.planet.camera.eye)),null,null,0,null,null,(()=>{this.planet.camera.look})):this.planet.flyCartesian(this.planet.camera.eye)}onCameraRollLeft(){this.planet.camera.setRoll(-15/this.renderer.handler.deltaTime)}onCameraRollRight(){this.planet.camera.setRoll(15/this.renderer.handler.deltaTime)}},LayerAnimation:class extends Dt{constructor(e={}){super(e),this._currVisibleIndex=0,this._onViewchange=()=>{this._timeoutStart=performance.now()},this._onVisibilityChange=e=>{e||this.pause()},this._onLayerLoadend=e=>{let t=this._layersArr[this._currentIndex];if(t&&t.isEqual(e)){let e=this._getFrameIndex(this._currentIndex)*this._frameSize,i=this._currentIndex;for(let t=e;t<i;t++){let e=this._layersArr[t];e.opacity=0,e.setVisibility(!1)}t.opacity=1;let s=this._layersArr[this._currVisibleIndex];if(s){s.opacity=0,s.setVisibility(!1);let e=this._getFrameIndex(this._currVisibleIndex);this._getFrameIndex(this._currentIndex)!==e&&this._removeFrameFromPlanet(e)}this.events.dispatch(this.events.idle,t)}},this.events=Mt(Tn),this._name=e.name||`layerAnimation-${this.__id}`,this._layersArr=e.layers?[].concat(e.layers):[],this._currentIndex=-1,this._playInterval=e.playInterval||120,this._playIntervalHandler=-1,this._playIndex=0,this._frameSize=e.frameSize||50,this.repeat=null==e.repeat||e.repeat,this.skipTimeout=e.skipTimeout||5e3,this._timeoutStart=0}_getFramesNum(){return Math.ceil(this._layersArr.length/this._frameSize)}_setFrame(e){for(let t=0,i=this._getFramesNum();t<i;t++)t!==e?this._removeFrameFromPlanet(t):this._appendFrameToPlanet(t)}_getFrameIndex(e){return Math.floor(e/this._frameSize)}_appendFrameToPlanet(e){if(this.planet){let t=e*this._frameSize,i=t+this._frameSize;for(let e=t,s=i>this._layersArr.length?this._layersArr.length:i;e<s;e++)this.planet.addLayer(this._layersArr[e])}}_removeFrameFromPlanet(e){if(this.planet){let t=e*this._frameSize,i=t+this._frameSize;for(let e=t,s=i>this._layersArr.length?this._layersArr.length:i;e<s;e++)this._layersArr[e].abortLoading(),this._layersArr[e].remove(),this._layersArr[e].setVisibility(!1)}}oninit(){super.oninit(),this.onactivate(),this._initLayers(),this.planet.events.on("layerloadend",this._onLayerLoadend),this._setCurrentIndexAsync(0,!1,!0)}onactivate(){super.onactivate(),this.planet.camera.events.on("viewchange",this._onViewchange),this.planet.renderer.handler.events.on("visibilitychange",this._onVisibilityChange)}ondeactivate(){super.ondeactivate(),this.planet.camera.events.off("viewchange",this._onViewchange);for(let e=0;e<this._layersArr.length;e++)this._layersArr[e].setVisibility(!1);this.planet.events.off("layerloadend",this._onLayerLoadend),this.planet.renderer.handler.events.off("visibilitychange",this._onVisibilityChange)}clear(){this.stop(),this._currentIndex=-1,this._currVisibleIndex=-1;let e=this._layersArr;this._layersArr=[];for(let t=0;t<e.length;t++)e[t].remove()}_initLayers(){if(this.planet){for(let e=0,t=this._layersArr.length;e<t;e++){let t=this._layersArr[e];t.setVisibility(!1),t.setBaseLayer(!1),t.opacity=0}this._appendFrameToPlanet(0)}}setLayers(e){this.clear(),this._layersArr=[].concat(e),this._initLayers()}appendLayer(e){this._layersArr.push(e),e.setVisibility(!1),e.setBaseLayer(!1),e.opacity=0,this.planet?.addLayer(e)}get isIdle(){let e=this._layersArr[this._currentIndex];return e&&e.isIdle||!e}get playInterval(){return this._playInterval}set playInterval(e){e!==this._playInterval&&(this._playInterval=e,this.isPlaying&&(this.pause(),this.play()))}get isPlaying(){return-1!==this._playIntervalHandler}get layers(){return this._layersArr}_checkEnd(){this._playIndex>this._layersArr.length&&(this.repeat?this._playIndex=0:this.pause())}play(){this.isPlaying||(this._currentIndex>=this._layersArr.length-1&&this.stop(),this._timeoutStart=performance.now(),this._playIntervalHandler=setInterval((()=>{this._checkEnd(),this._setCurrentIndexAsync(this._playIndex,!1,!1),requestAnimationFrame((()=>{(this.isIdle||performance.now()-this._timeoutStart>this.skipTimeout)&&(this._playIndex++,this._timeoutStart=performance.now())}))}),this._playInterval),this.events.dispatch(this.events.play))}stop(){this._playIndex>0&&(this._clearInterval(),this._playIndex=0,this.setCurrentIndex(0),this.events.dispatch(this.events.stop))}pause(){this.isPlaying&&(this._clearInterval(),this.events.dispatch(this.events.pause))}_clearInterval(){clearInterval(this._playIntervalHandler),this._playIntervalHandler=-1}setCurrentIndex(e,t=!1){this._setCurrentIndexAsync(e,!0,t)}_setCurrentIndexAsync(e,t=!1,i=!1){if(e!=this._currentIndex&&e>=0&&e<this._layersArr.length){let s=this._currentIndex;this._currentIndex=e,this._playIndex=e;let n=this._getFrameIndex(s),r=this._getFrameIndex(this._currentIndex),o=this._layersArr[s],a=this._layersArr[e],l=r!=n;l&&this._appendFrameToPlanet(r),o&&(o.isIdle?this._currVisibleIndex=s:(o.opacity=0,o.setVisibility(!1))),a&&(a.opacity=0,a.setVisibility(!0),requestAnimationFrame((()=>{if(a.isIdle||t){a.opacity=1,l&&this._removeFrameFromPlanet(n),o&&(o.opacity=0,o.setVisibility(!1));let e=this._layersArr[this._currVisibleIndex];e&&(e.opacity=0,e.setVisibility(!1))}})),i||this.events.dispatch(this.events.change,this._currentIndex,s))}}},LayerSwitcher:class extends Dt{constructor(e={}){super({name:"LayerSwitcher",...e}),this.addLayer=e=>{if(!e.hideInLayerSwitcher){let t=this._createLayerButton(e);this._layerViews.push(t),e.isBaseLayer()?t.appendTo(this.$baseLayers):t.appendTo(this.$overlays)}},this.removeLayer=e=>{for(let t=0;t<this._layerViews.length;t++){let i=this._layerViews[t];if(i.model.isEqual(e)){i.remove(),this._layerViews.splice(t,1);break}}},this._dialog=new Ot({title:"Layer Switcher",top:15,useHide:!0,visible:!1,width:300,maxHeight:500}),this._panel=new kt({template:'<div class="og-layerSwitcher">\n <div class="og-layerSwitcher__title">Base Layers</div>\n <div class="og-layerSwitcher__list og-layerSwitcher__baseLayers"></div> \n \n <div class="og-layerSwitcher__title">Overlays</div>\n <div class="og-layerSwitcher__list og-layerSwitcher__overlays"></div>\n \n </div>'}),this._toggleBtn=new Ut({classList:["og-map-button","og-layerSwitcher_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Svg Vector Icons : http://www.onlinewebfonts.com/icon --\x3e\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve">\n<metadata> Svg Vector Icons : http://www.onlinewebfonts.com/icon </metadata>\n<g><path d="M500,573.5c-3.2,0-6.5-0.6-9.5-1.9L25,375.6c-9.1-3.8-15-12.7-15-22.6s5.9-18.8,15-22.6l465.5-196c6.1-2.5,12.9-2.5,19,0l465.5,196c9.1,3.8,15,12.7,15,22.6s-5.9,18.8-15,22.6l-465.5,196C506.5,572.9,503.2,573.5,500,573.5L500,573.5z M97.6,353L500,522.4L902.4,353L500,183.6L97.6,353L97.6,353z"/><path d="M500,720.5c-3.2,0-6.5-0.6-9.5-1.9L25,522.6c-12.4-5.2-18.3-19.6-13.1-32.1c5.2-12.5,19.6-18.3,32.1-13.1l456,192l456-192c12.4-5.2,26.9,0.6,32.1,13.1s-0.6,26.9-13.1,32.1l-465.5,196C506.5,719.9,503.2,720.5,500,720.5L500,720.5z"/><path d="M500,867.5c-3.2,0-6.5-0.6-9.5-1.9L25,669.6c-12.4-5.2-18.3-19.6-13.1-32.1c5.2-12.5,19.6-18.3,32.1-13.1l456,192l456-192c12.4-5.2,26.9,0.6,32.1,13.1c5.2,12.5-0.6,26.8-13.1,32.1l-465.5,196C506.5,866.9,503.2,867.5,500,867.5L500,867.5z"/></g>\n</svg>'}),this.$baseLayers=null,this.$overlays=null,this._layerViews=[]}oninit(){this._toggleBtn.appendTo(this.renderer.div),this._dialog.appendTo(this.planet.renderer.div),this._panel.appendTo(this._dialog.container),this.$baseLayers=this._panel.el.querySelector(".og-layerSwitcher__baseLayers"),this.$overlays=this._panel.el.querySelector(".og-layerSwitcher__overlays"),this._dialog.setPosition(this.planet.renderer.div.clientWidth-this._dialog.width-67),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e)})),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e)})),this.planet.events.on("layeradd",this.addLayer,this),this.planet.events.on("layerremove",this.removeLayer,this),this._initLayers()}_initLayers(){let e=this.planet.layers;for(let t=0;t<e.length;t++)this.addLayer(e[t])}_createLayerButton(e){return new En({model:e})}onactivate(){}ondeactivate(){this._dialog.hide()}},Lighting:class extends Dt{constructor(e={}){super(e),this._selectedLayer=null,this._toggleBtn=new Ut({classList:["og-map-button","og-lighting_button"],icon:'<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1" width="256" height="256" viewBox="0 0 256 256" xml:space="preserve">\n\n<defs>\n</defs>\n<g style="stroke: none; stroke-width: 0; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; opacity: 1;" transform="translate(1.4065934065934016 1.4065934065934016) scale(2.81 2.81)" >\n\t<path d="M 45 68 c -12.682 0 -23 -10.317 -23 -23 c 0 -12.682 10.318 -23 23 -23 c 12.683 0 23 10.318 23 23 C 68 57.683 57.683 68 45 68 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 45 17.556 c -1.657 0 -3 -1.343 -3 -3 V 3 c 0 -1.657 1.343 -3 3 -3 c 1.657 0 3 1.343 3 3 v 11.556 C 48 16.212 46.657 17.556 45 17.556 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 45 90 c -1.657 0 -3 -1.343 -3 -3 V 75.444 c 0 -1.657 1.343 -3 3 -3 c 1.657 0 3 1.343 3 3 V 87 C 48 88.657 46.657 90 45 90 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 14.556 48 H 3 c -1.657 0 -3 -1.343 -3 -3 c 0 -1.657 1.343 -3 3 -3 h 11.556 c 1.657 0 3 1.343 3 3 C 17.556 46.657 16.212 48 14.556 48 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 87 48 H 75.444 c -1.657 0 -3 -1.343 -3 -3 c 0 -1.657 1.343 -3 3 -3 H 87 c 1.657 0 3 1.343 3 3 C 90 46.657 88.657 48 87 48 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 66.527 26.473 c -0.768 0 -1.535 -0.293 -2.121 -0.878 c -1.172 -1.172 -1.172 -3.071 0 -4.243 l 8.171 -8.171 c 1.172 -1.172 3.07 -1.171 4.242 0 c 1.172 1.172 1.172 3.071 0 4.243 l -8.171 8.171 C 68.063 26.18 67.295 26.473 66.527 26.473 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 15.302 77.698 c -0.768 0 -1.536 -0.293 -2.121 -0.879 c -1.172 -1.171 -1.172 -3.071 0 -4.242 l 8.171 -8.171 c 1.171 -1.172 3.071 -1.172 4.242 0 c 1.172 1.171 1.172 3.071 0 4.242 l -8.171 8.171 C 16.837 77.405 16.069 77.698 15.302 77.698 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 23.473 26.473 c -0.768 0 -1.536 -0.293 -2.121 -0.878 l -8.171 -8.171 c -1.172 -1.172 -1.172 -3.071 0 -4.243 c 1.172 -1.172 3.072 -1.171 4.243 0 l 8.171 8.171 c 1.172 1.172 1.172 3.071 0 4.243 C 25.008 26.18 24.24 26.473 23.473 26.473 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n\t<path d="M 74.698 77.698 c -0.768 0 -1.535 -0.293 -2.121 -0.879 l -8.171 -8.171 c -1.172 -1.171 -1.172 -3.071 0 -4.242 c 1.172 -1.172 3.07 -1.172 4.242 0 l 8.171 8.171 c 1.172 1.171 1.172 3.071 0 4.242 C 76.233 77.405 75.466 77.698 74.698 77.698 z" style="stroke: none; stroke-width: 1; stroke-dasharray: none; stroke-linecap: butt; stroke-linejoin: miter; stroke-miterlimit: 10; fill-rule: nonzero; opacity: 1;" transform=" matrix(1 0 0 1 0 0) " stroke-linecap="round" />\n</g>\n</svg>'}),this._dialog=new Ot({title:"Lighting Parameters",visible:!1,useHide:!0,top:60,left:60,width:600}),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e)})),this._panel=new kt({template:'<div class="og-lighing og-options-container">\n\n <div class="og-option">\n <div class="og-suncontrol"></div>\n </div> \n \n <div class="og-option og-atmosphere-opacity">\n </div>\n \n <div class="og-option og-simpleskybackground">\n </div>\n \n <div class="og-lighting-emptyline"></div>\n\n <div class="og-option og-gamma"></div> \n <div class="og-option og-exposure"></div>\n \n <div class="og-lighting-emptyline"></div>\n\n <div class="og-option">\n <div class="og-layers">\n <div class="og-caption">Select layer:</div>\n <select id="layers"></select>\n </div>\n </div>\n\n <div class="og-option og-opacity">\n </div>\n \n <div class="og-option og-night">\n </div>\n \n <div class="og-lighting-emptyline"></div>\n\n <div class="og-option og-diffuse">\n </div>\n \n <div class="og-option og-ambient">\n </div>\n\n <div class="og-option og-specular">\n </div> \n\n </div>'}),this.$gamma=null,this.$exposure=null,this.$night=null,this.$opacity=null,this.$diffuse=null,this.$ambient=null,this.$specular=null,this.$atmosphereOpacity=null,this.$simpleSkyBackground=null,this._atmosphereMaxOpacity=new An({label:"Max.opacity",max:5}),this._atmosphereMinOpacity=new An({label:"Min.opacity",max:5}),this._simpleSkyBackgroundColorOne=new Mn({label:"Color One"}),this._simpleSkyBackgroundColorTwo=new Mn({label:"Color Two"}),this._gamma=new An({label:"Gamma",max:5}),this._exposure=new An({label:"Exposure",max:5}),this._night=new An({label:"Nightlight",max:5}),this._opacity=new An({label:"Opacity",max:1}),this._diffuse_r=new An({label:"Diffuse R",max:5}),this._diffuse_g=new An({label:"Diffuse G",max:5}),this._diffuse_b=new An({label:"Diffuse B",max:5}),this._ambient_r=new An({label:"Ambient R",max:5}),this._ambient_g=new An({label:"Ambient G",max:5}),this._ambient_b=new An({label:"Ambient B",max:5}),this._specular_r=new An({label:"Specular R",max:.2}),this._specular_g=new An({label:"Specular G",max:.2}),this._specular_b=new An({label:"Specular B",max:.2}),this._shininess=new An({label:"Shininess",max:100})}bindLayer(e){this._selectedLayer=e,this._opacity.value=e.opacity,this._update()}oninit(){this._toggleBtn.appendTo(this.renderer.div),this._dialog.appendTo(this.renderer.div),this._panel.appendTo(this._dialog.container),this._panel.el&&(this.$atmosphereOpacity=this._panel.el.querySelector(".og-atmosphere-opacity"),this.$simpleSkyBackground=this._panel.el.querySelector(".og-simpleskybackground"),this.$gamma=this._panel.el.querySelector(".og-option.og-gamma"),this.$exposure=this._panel.el.querySelector(".og-option.og-exposure"),this.$opacity=this._panel.el.querySelector(".og-option.og-opacity"),this.$diffuse=this._panel.el.querySelector(".og-option.og-diffuse"),this.$ambient=this._panel.el.querySelector(".og-option.og-ambient"),this.$specular=this._panel.el.querySelector(".og-option.og-specular"),this.$night=this._panel.el.querySelector(".og-option.og-night")),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e)}));let e=this._dialog.select(".og-suncontrol"),t=new Ut({classList:["og-suncontrol-button"],isActive:!0,icon:'<?xml version="1.0" encoding="utf-8"?><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 122.88 70.41" style="enable-background:new 0 0 122.88 70.41" xml:space="preserve"><g><path d="M60.91,19.12c6.95,0,13.24,2.95,17.8,7.72c4.55,4.77,7.37,11.37,7.37,18.64c0,1.94-0.2,3.83-0.58,5.65h31.61 c2.1,0,2.62,1.16,2.62,2.59c0,1.43-0.52,2.59-2.62,2.59H7.09c-2.1,0-2.62-1.16-2.62-2.59c0-1.43,0.52-2.59,2.62-2.59h29.23 c-0.38-1.82-0.58-3.71-0.58-5.65c0-7.28,2.82-13.87,7.37-18.64C47.67,22.08,53.96,19.12,60.91,19.12L60.91,19.12L60.91,19.12z M63.4,70.41c-2.1,0-2.62-1.16-2.62-2.59s0.52-2.59,2.62-2.59h56.86c2.1,0,2.62,1.16,2.62,2.59s-0.52,2.59-2.62,2.59H63.4 L63.4,70.41z M2.62,70.41c-2.1,0-2.62-1.16-2.62-2.59s0.52-2.59,2.62-2.59h29.51c2.1,0,2.62,1.16,2.62,2.59s-0.52,2.59-2.62,2.59 H2.62L2.62,70.41z M38.39,9.46c-0.78-1.35-0.32-3.07,1.03-3.85c1.35-0.78,3.07-0.32,3.85,1.03l3.62,6.27 c0.78,1.35,0.32,3.07-1.03,3.85c-1.35,0.78-3.07,0.32-3.85-1.03L38.39,9.46L38.39,9.46L38.39,9.46z M58.67,2.83 c0-1.56,1.27-2.83,2.83-2.83c1.56,0,2.83,1.27,2.83,2.83v7.24c0,1.56-1.27,2.83-2.83,2.83c-1.56,0-2.83-1.26-2.83-2.83V2.83 L58.67,2.83L58.67,2.83z M79.56,7.23c0.77-1.35,2.49-1.81,3.84-1.04c1.35,0.77,1.81,2.49,1.04,3.84l-3.62,6.27 c-0.77,1.35-2.49,1.81-3.84,1.04c-1.35-0.77-1.81-2.49-1.04-3.84L79.56,7.23L79.56,7.23L79.56,7.23z M95.45,21.48 c1.35-0.78,3.07-0.32,3.85,1.03c0.78,1.35,0.32,3.07-1.03,3.85L92,29.98c-1.35,0.78-3.07,0.32-3.85-1.03 c-0.78-1.35-0.32-3.07,1.03-3.85L95.45,21.48L95.45,21.48L95.45,21.48z M102.08,41.76c1.56,0,2.83,1.27,2.83,2.83 c0,1.56-1.27,2.83-2.83,2.83h-7.24c-1.56,0-2.83-1.26-2.83-2.83s1.26-2.83,2.83-2.83H102.08L102.08,41.76L102.08,41.76z M19.74,46.25c-1.56,0-2.83-1.27-2.83-2.83c0-1.56,1.27-2.83,2.83-2.83h7.24c1.56,0,2.83,1.26,2.83,2.83s-1.27,2.83-2.83,2.83 H19.74L19.74,46.25L19.74,46.25z M24.14,25.35c-1.35-0.77-1.81-2.49-1.04-3.84c0.77-1.35,2.49-1.81,3.84-1.04l6.27,3.62 c1.35,0.77,1.81,2.49,1.04,3.84c-0.77,1.35-2.49,1.81-3.84,1.04L24.14,25.35L24.14,25.35L24.14,25.35z"/></g></svg>',title:"Star/stop the Sun from following the camera"});t.appendTo(e);let i=new Ut({classList:["og-suncontrol-button"],isActive:!0,icon:'<?xml version="1.0"?>\n<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 32 32">\n <path style="text-indent:0;text-align:start;line-height:normal;text-transform:none;block-progression:tb;-inkscape-font-specification:Sans" d="M 16 4 C 9.3844277 4 4 9.3844277 4 16 C 4 22.615572 9.3844277 28 16 28 C 22.615572 28 28 22.615572 28 16 C 28 9.3844277 22.615572 4 16 4 z M 16 6 C 16.389823 6 16.778223 6.0506339 17.15625 6.09375 C 18.631659 7.6568432 21 10.9245 21 16 C 21 21.0755 18.631659 24.343157 17.15625 25.90625 C 16.778223 25.949366 16.389823 26 16 26 C 10.465308 26 6 21.534692 6 16 C 6 10.465308 10.465308 6 16 6 z" overflow="visible" font-family="Sans"/>\n</svg>\n',title:"Activate/deactivate the Sun current time positioning"});i.appendTo(e),t.events.on("change",(e=>{const t=this.planet.renderer.controls.sun;e?t.start():t.stop()})),i.events.on("change",(e=>{const t=this.planet.renderer.controls.sun;e?t.activate():t.deactivate()}));let s=new Ut({classList:["og-suncontrol-button"],isActive:this.planet.lightEnabled,icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Generated by IcoMoon.io --\x3e\n<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="512" height="512" viewBox="0 0 512 512">\n<g>\n</g>\n\t<path d="M257.894 156.948c-53.258 0-96.42 43.561-96.42 97.26 0 53.719 43.161 97.249 96.42 97.249 53.197 0 96.379-43.53 96.379-97.25 0-53.698-43.182-97.26-96.379-97.26zM257.894 309.873c-30.464 0-55.163-24.945-55.163-55.665s24.699-55.624 55.163-55.624c30.423 0 55.101 24.904 55.101 55.624s-24.688 55.665-55.101 55.665z" fill="#000000" />\n\t<path d="M241.808 43.499h32.144v79.575h-32.144v-79.575z" fill="#000000" />\n\t<path d="M417.209 115.897l-22.723-22.917-55.757 56.279 22.723 22.907z" fill="#000000" />\n\t<path d="M389.468 238.407h78.899v32.389h-78.899v-32.389z" fill="#000000" />\n\t<path d="M396.012 416.86l22.723-22.917-55.767-56.259-22.712 22.897z" fill="#000000" />\n\t<path d="M242.473 388.915h32.144v79.575h-32.144v-79.575z" fill="#000000" />\n\t<path d="M96.266 396.073l22.722 22.938 55.778-56.289-22.692-22.928z" fill="#000000" />\n\t<path d="M43.633 240.537h78.879v32.43h-78.879v-32.43z" fill="#000000" />\n\t<path d="M115.394 93.051l-22.681 22.907 55.757 56.258 22.702-22.917z" fill="#000000" />\n</svg>',title:"Enable/disable planet lighting"});s.appendTo(e),s.events.on("change",(e=>{this.planet.lightEnabled=e}));let n=new Ut({classList:["og-suncontrol-button"],isActive:this.planet.atmosphereEnabled,icon:'<?xml version="1.0" encoding="utf-8"?>\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<svg width="800px" height="800px" viewBox="0 0 512 512" xmlns="http://www.w3.org/2000/svg"><path fill="#000000" d="M135.688 18.5c-6.798 74.842-23.842 85.39-107.907 59.656 84.85 52.022 73.57 64.954-6.843 96.938 87.743-10.27 103.29 4.89 70.75 87.594 17.805-27.56 32.5-44.498 46.282-54.47-11.813 28.26-18.345 59.274-18.345 91.813 0 84.184 43.71 157.96 109.656 200.376-41.624-43.834-67.686-102.7-67.686-167.875 0-134.923 109.45-244.405 244.375-244.405 30.92 0 60.76 5.762 88 16.25-38.584-26.87-85.517-42.625-136.064-42.625-55.257 0-106.14 18.802-146.562 50.375 4.627-18.783 17.39-38.073 41.03-60.906C190.18 90.942 153.53 95.634 135.69 18.5zm10.03 77.188c5.67.002 11.428 1.247 16.876 3.874 14.506 6.998 22.72 21.81 22 36.938-10.26 10.87-19.507 22.696-27.594 35.344-9.035 2.753-19.075 2.27-28.25-2.156-19.37-9.343-27.5-32.6-18.156-51.97 6.715-13.92 20.638-22.036 35.125-22.03z"/></svg>',title:"Enable/disable atmosphere scattering"});n.appendTo(e),this.planet.atmosphereEnabled?(this.$atmosphereOpacity.style.display="block",this.$simpleSkyBackground.style.display="none"):(this.$atmosphereOpacity.style.display="none",this.$simpleSkyBackground.style.display="flex"),n.events.on("change",(e=>{this.planet.atmosphereEnabled=e,this.planet.atmosphereEnabled?(this.$atmosphereOpacity.style.display="block",this.$simpleSkyBackground.style.display="none"):(this.$atmosphereOpacity.style.display="none",this.$simpleSkyBackground.style.display="flex")})),this._atmosphereMaxOpacity.appendTo(this.$atmosphereOpacity),this._atmosphereMinOpacity.appendTo(this.$atmosphereOpacity),this._simpleSkyBackgroundColorOne.appendTo(this.$simpleSkyBackground),this._simpleSkyBackgroundColorTwo.appendTo(this.$simpleSkyBackground),this._gamma.appendTo(this.$gamma),this._exposure.appendTo(this.$exposure),this._night.appendTo(this.$night),this._opacity.appendTo(this.$opacity),this._diffuse_r.appendTo(this.$diffuse),this._diffuse_g.appendTo(this.$diffuse),this._diffuse_b.appendTo(this.$diffuse),this._ambient_r.appendTo(this.$ambient),this._ambient_g.appendTo(this.$ambient),this._ambient_b.appendTo(this.$ambient),this._specular_r.appendTo(this.$specular),this._specular_g.appendTo(this.$specular),this._specular_b.appendTo(this.$specular),this._shininess.appendTo(this.$specular),this._gamma.value=this.planet.renderer.gamma,this._gamma.events.on("change",(e=>{this.planet.renderer.gamma=e})),this._exposure.value=this.planet.renderer.exposure,this._exposure.events.on("change",(e=>{this.planet.renderer.exposure=e})),this._atmosphereMinOpacity.value=this.planet.atmosphereMinOpacity,this._atmosphereMinOpacity.events.on("change",(e=>{this.planet.atmosphereMinOpacity=e})),this._atmosphereMaxOpacity.value=this.planet.atmosphereMaxOpacity,this._atmosphereMaxOpacity.events.on("change",(e=>{this.planet.atmosphereMaxOpacity=e,this.planet.renderer.controls.Atmosphere.opacity=e}));let r=this.planet.renderer.controls.SimpleSkyBackground;r&&(this._simpleSkyBackgroundColorOne.value=r.colorOne,this._simpleSkyBackgroundColorTwo.value=r.colorTwo),this._simpleSkyBackgroundColorOne.events.on("input",(e=>{let t=this.planet.renderer.controls.SimpleSkyBackground;t&&(t.colorOne=e)})),this._simpleSkyBackgroundColorTwo.events.on("input",(e=>{let t=this.planet.renderer.controls.SimpleSkyBackground;t&&(t.colorTwo=e)})),this._panel.el.querySelector("#layers").addEventListener("change",(e=>{const t=this.planet.getLayerByName(e.target.value);t&&this.bindLayer(t)})),this._night.events.on("change",(e=>{this._selectedLayer&&(this._selectedLayer.nightTextureCoefficient=e)})),this._opacity.events.on("change",(e=>{this._selectedLayer&&(this._selectedLayer.opacity=e)})),this._ambient_r.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._ambient&&(this._selectedLayer._ambient[0]=e)})),this._ambient_g.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._ambient&&(this._selectedLayer._ambient[1]=e)})),this._ambient_b.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._ambient&&(this._selectedLayer._ambient[2]=e)})),this._diffuse_r.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._diffuse&&(this._selectedLayer._diffuse[0]=e)})),this._diffuse_g.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._diffuse&&(this._selectedLayer._diffuse[1]=e)})),this._diffuse_b.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._diffuse&&(this._selectedLayer._diffuse[2]=e)})),this._specular_r.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._specular&&(this._selectedLayer._specular[0]=e)})),this._specular_g.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._specular&&(this._selectedLayer._specular[1]=e)})),this._specular_b.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._specular&&(this._selectedLayer._specular[2]=e)})),this._shininess.events.on("change",(e=>{this._selectedLayer&&this._selectedLayer._specular&&(this._selectedLayer._specular[3]=e)})),this.planet&&(this.planet.events.on("layeradd",this._onLayerAdd,this),this.planet.events.on("layerremove",this._onLayerRemove,this)),this._fetchLayers()}_update(){let e=this._selectedLayer;this._opacity.value=e&&e.opacity?e.opacity:0,this._night.value=e&&e.nightTextureCoefficient?e.nightTextureCoefficient:this.planet.nightTextureCoefficient;let t=e&&e._ambient?e._ambient:this.planet._ambient;this._ambient_r.value=t[0],this._ambient_g.value=t[1],this._ambient_b.value=t[2];let i=e&&e._diffuse?e._diffuse:this.planet._diffuse;this._diffuse_r.value=i[0],this._diffuse_g.value=i[1],this._diffuse_b.value=i[2];let s=e&&e._specular?e._specular:this.planet._specular;this._specular_r.value=s[0],this._specular_g.value=s[1],this._specular_b.value=s[2],this._shininess.value=s[3]}_fetchLayers(){if(this.planet)for(let e=0;e<this.planet.layers.length;e++)this._onLayerAdd(this.planet.layers[e])}_onLayerAdd(e){this.bindLayer(e);let t=document.createElement("option");t.value=e.name,t.innerText=e.name,this._panel.el.querySelector("#layers").appendChild(t),this._panel.el.querySelector("#layers").value=e.name}_onLayerRemove(e){}},MouseNavigation:zn,OldMouseNavigation:kn,Ruler:Un,RulerSwitcher:class extends Dt{constructor(e={}){super({name:"RulerSwitcher",...e}),this.ruler=new $n({ignoreTerrain:e.ignoreTerrain})}oninit(){this.planet.addControl(this.ruler),this._createMenuBtn()}onactivate(){this.ruler.activate()}ondeactivate(){this.ruler.deactivate()}_createMenuBtn(){let e=new Ut({classList:["og-map-button","og-ruler_button"],icon:'<?xml version="1.0" encoding="iso-8859-1"?>\n\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<svg fill="#000000" height="800px" width="800px" version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" \n\t viewBox="0 0 512 512" xml:space="preserve">\n<g>\n\t<g>\n\t\t<path d="M369.151,0L0.001,369.15L142.85,512l369.149-369.15L369.151,0z M47.286,369.15l10.908-10.908l47.782,47.782l23.642-23.642\n\t\t\tL81.837,334.6l10.909-10.909l23.711,23.711L140.1,323.76l-23.711-23.711l10.909-10.909l23.711,23.711l23.642-23.642\n\t\t\tl-23.711-23.711l10.909-10.909l47.782,47.782l23.642-23.642l-47.782-47.782l10.908-10.908l23.71,23.71l23.642-23.642l-23.71-23.71\n\t\t\tl10.908-10.908l23.711,23.711l23.642-23.642l-23.711-23.711l10.909-10.909l47.782,47.782l23.642-23.642l-47.782-47.782\n\t\t\tl10.908-10.908l23.71,23.711l23.642-23.642l-23.711-23.71L334.6,81.837l23.711,23.71l23.642-23.642l-23.711-23.712l10.908-10.908\n\t\t\tl95.564,95.564L142.85,464.714L47.286,369.15z"/>\n\t</g>\n</g>\n</svg>'});e.appendTo(this.renderer.div),e.events.on("change",(e=>{e?this.onactivate():this.ondeactivate()}))}},ScaleControl:Zn,Selection:class extends Dt{constructor(e={}){super(e),this._selectorScene=new rr({name:`selectionScene:${this.__id}`,ignoreTerrain:e.ignoreTerrain,onSelect:e.onSelect,autoSelectionHide:e.autoSelectionHide}),this._toggleBtn=new Ut({classList:["og-map-button","og-selection_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\x3c!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools --\x3e\n<svg width="800px" height="800px" viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--gis" preserveAspectRatio="xMidYMid meet"><path d="M2.1 0v1.914H0v6h3V3h5.1V0h-6zm9 0v3h6V0h-6zm9 0v3h6V0h-6zm9 0v3h6V0h-6zm9 0v3h6V0h-6zm9 0v3h6V0h-6zm9 0v3h6V0h-6zm9 0v3h1.8v1.2h3V0h-4.8zm1.8 7.2v6h3v-6h-3zM0 10.913v6h3v-6H0zM66.9 16.2v6h3v-6h-3zM0 19.914v6h3v-6H0zM66.9 25.2v6h3v-6h-3zM0 28.914v6h3v-6H0zM66.9 34.2v6h3v-6h-3zM0 37.914v6h3v-6H0zM66.9 43.2v6h3v-6h-3zM0 46.914v6h3v-6H0zM66.9 52.2v6h3v-6h-3zM0 55.914v5.191h3.809v-3H3v-2.19H0zm6.809 2.191v3h6v-3h-6zm9 0v3h6v-3h-6zm9 0v3h6v-3h-6zm9 0v3h6v-3h-6zm9 0v3h6v-3h-6zm9 0v3h6v-3h-6zm9 0v3h6v-3h-6zm9.648 1.899a2.076 2.076 0 0 0-2.19 2.324l3.137 33.676c.2 1.635 2.135 2.399 3.397 1.34l6.623-5.371l2.969 5.142c1.707 2.958 4.417 3.684 7.375 1.977c2.957-1.708 3.684-4.417 1.976-7.375l-2.959-5.125l7.848-3.008c1.548-.564 1.855-2.62.539-3.611L71.576 60.416a2.073 2.073 0 0 0-1.119-.412z" fill="#000000"></path></svg>'})}set ignoreTerrain(e){this._selectorScene.ignoreTerrain=e}oninit(){this._toggleBtn.appendTo(this.renderer.div),this._toggleBtn.events.on("change",(e=>{e?this.activate():this.deactivate()})),this._selectorScene.bindPlanet(this.planet)}onactivate(){this.renderer.addNode(this._selectorScene)}ondeactivate(){this.renderer.removeNode(this._selectorScene)}},ShowFps:class extends Dt{constructor(e){super(e)}oninit(){let e=document.createElement("div");e.className="defaultText ",e.id="ogShowFpsControl",document.body.appendChild(e),this.renderer.events.on("draw",this._draw,this)}_draw(){Te("ogShowFpsControl",(1e3/this.renderer.handler.deltaTime).toFixed(1),this.renderer.handler.canvas.clientWidth-60,0)}},SimpleNavigation:class extends Dt{constructor(e={}){super({name:"SimpleNavigation",autoActivate:!0,...e}),this._onMouseLeftButtonClick=e=>{this._active&&this.renderer&&(this.renderer.handler.canvas.classList.add("ogGrabbingPoiner"),this._grabbedPoint=this.renderer.getCartesianFromPixel(e),this._grabbedPoint&&this._eye0.copy(this.renderer.activeCamera.eye))},this._onMouseLeftButtonUp=e=>{this.renderer.handler.canvas.classList.remove("ogGrabbingPoiner"),e.x===e.prev_x&&(e.y,e.prev_y)},this._onMouseLeftButtonDown=e=>{if(this._active&&this.renderer){if(!this._grabbedPoint)return;if(e.moving){let t,i,s=this.renderer.activeCamera,n=Math.abs(s.getForward().dot(oe.UP)),r=this._grabbedPoint;n>.7?(t=oe.add(r,oe.LEFT),i=oe.add(r,s.getRight())):(t=oe.add(r,s.getRight()),i=oe.add(r,oe.UP));let o=new oe;new ui(s.eye,e.direction).hitPlaneRes(_i.fromPoints(r,t,i),o)===ui.INSIDE&&(s.eye=this._eye0.addA(o.subA(r).negate()))}}},this._onRHold=e=>{if(this._lookPos&&e.moving&&this.renderer){const t=this.renderer.activeCamera;this.renderer.controlsBag.scaleRot=1;let i=.5/t.eye.distance(this._lookPos)*l;i>.007?i=.007:i<.003&&(i=.003),t.rotateHorizontal(i*(e.x-e.prev_x),!1,this._lookPos,this._up),t.rotateVertical(i*(e.y-e.prev_y),this._lookPos)}},this._onRDown=e=>{this.renderer&&(this._lookPos=this.renderer.getCartesianFromPixel(e.pos),this._lookPos&&(this._up=oe.UP))},this._onMouseWheel=e=>{if(this.renderer){let t=this.renderer.getCartesianFromPixel(e),i=10;t&&(i=this.renderer.activeCamera.eye.distance(t)),this.force.addA(e.direction.scale(e.wheelDelta)).normalize().scale(i)}},this.onCameraMoveForward=()=>{this.force.addA(this.renderer.activeCamera.getForward()).normalize()},this.onCameraMoveBackward=()=>{this.force.addA(this.renderer.activeCamera.getBackward()).normalize()},this.onCameraStrifeLeft=()=>{this.force.addA(this.renderer.activeCamera.getLeft()).normalize()},this.onCameraStrifeRight=()=>{this.force.addA(this.renderer.activeCamera.getRight()).normalize()},this.onCameraLookUp=()=>{let e=this.renderer.activeCamera;e.setPitch(.5),e.update()},this.onCameraLookDown=()=>{let e=this.renderer.activeCamera;e.setPitch(-.5),e.update()},this.onCameraTurnLeft=()=>{let e=this.renderer.activeCamera;e.setYaw(.5),e.update()},this.onCameraTurnRight=()=>{let e=this.renderer.activeCamera;e.setYaw(-.5),e.update()},this.onCameraRollLeft=()=>{let e=this.renderer.activeCamera;e.setRoll(-.5),e.update()},this.onCameraRollRight=()=>{let e=this.renderer.activeCamera;e.setRoll(.5),e.update()},this.speed=e.speed||1,this.force=new oe,this.vel=new oe,this.mass=1,this._lookPos=void 0,this._grabbedPoint=void 0,this._up=null,this._eye0=new oe}oninit(){}onactivate(){super.onactivate();let e=this.renderer;e.events.on("mousewheel",this._onMouseWheel),e.events.on("keypress",Cn.KEY_W,this.onCameraMoveForward,this),e.events.on("keypress",Cn.KEY_S,this.onCameraMoveBackward,this),e.events.on("keypress",Cn.KEY_A,this.onCameraStrifeLeft,this),e.events.on("keypress",Cn.KEY_D,this.onCameraStrifeRight,this),e.events.on("keypress",Cn.KEY_UP,this.onCameraLookUp,this),e.events.on("keypress",Cn.KEY_DOWN,this.onCameraLookDown,this),e.events.on("keypress",Cn.KEY_LEFT,this.onCameraTurnLeft,this),e.events.on("keypress",Cn.KEY_RIGHT,this.onCameraTurnRight,this),e.events.on("keypress",Cn.KEY_Q,this.onCameraRollLeft,this),e.events.on("keypress",Cn.KEY_E,this.onCameraRollRight,this),e.events.on("rhold",this._onRHold,this),e.events.on("rdown",this._onRDown,this),e.events.on("lhold",this._onMouseLeftButtonDown),e.events.on("ldown",this._onMouseLeftButtonClick),e.events.on("lup",this._onMouseLeftButtonUp),e.events.on("draw",this.onDraw,this,-1e3)}ondeactivate(){super.ondeactivate();let e=this.renderer;e.events.off("mousewheel",this._onMouseWheel),e.events.off("keypress",Cn.KEY_W,this.onCameraMoveForward),e.events.off("keypress",Cn.KEY_S,this.onCameraMoveBackward),e.events.off("keypress",Cn.KEY_A,this.onCameraStrifeLeft),e.events.off("keypress",Cn.KEY_D,this.onCameraStrifeRight),e.events.off("keypress",Cn.KEY_UP,this.onCameraLookUp),e.events.off("keypress",Cn.KEY_DOWN,this.onCameraLookDown),e.events.off("keypress",Cn.KEY_LEFT,this.onCameraTurnLeft),e.events.off("keypress",Cn.KEY_RIGHT,this.onCameraTurnRight),e.events.off("keypress",Cn.KEY_Q,this.onCameraRollLeft),e.events.off("keypress",Cn.KEY_E,this.onCameraRollRight),e.events.off("rhold",this._onRHold),e.events.off("rdown",this._onRDown),e.events.off("lhold",this._onMouseLeftButtonDown),e.events.off("ldown",this._onMouseLeftButtonClick),e.events.off("lup",this._onMouseLeftButtonUp),e.events.off("draw",this.onDraw)}get dt(){return.001*this.renderer.handler.deltaTime}onDraw(){if(this.renderer){let e=this.force.scale(1/this.mass);this.vel.addA(e),this.vel.scale(.96),this.force.set(0,0,0);let t=this.renderer.activeCamera;t.eye=t.eye.add(this.vel.scaleTo(this.dt)),t.update()}}},SimpleSkyBackground:Kn,Sun:tr,TimelineControl:class extends Dt{constructor(e={}){super({name:"timeline",...e});let t=e.current||new Date,i=e.rangeStart||yr(t,-12),s=e.rangeEnd||yr(t,12);this._timelineView=new vr({rangeStart:i,rangeEnd:s,currentDate:t}),this._toggleBtn=new Ut({classList:["og-map-button","og-timeline_button"],icon:'<?xml version="1.0" encoding="utf-8"?>\n\x3c!-- Svg Vector Icons : http://www.onlinewebfonts.com/icon --\x3e\n <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" viewBox="0 0 1000 1000" enable-background="new 0 0 1000 1000" xml:space="preserve">\n <metadata> Svg Vector Icons : http://www.onlinewebfonts.com/icon </metadata>\n <g><path d="M500,10C229.4,10,10,229.4,10,500s219.4,490,490,490s490-219.4,490-490S770.6,10,500,10z M800.3,800.3c-39,39-84.5,69.7-135,91C613,913.5,557.4,924.7,500,924.7s-112.9-11.2-165.3-33.3c-50.5-21.3-95.9-52-135-91c-39-39-69.7-84.5-91-135C86.5,612.9,75.3,557.4,75.3,500s11.2-112.9,33.3-165.3c21.3-50.5,52-95.9,91-135c39-39,84.5-69.7,135-91C387.1,86.5,442.6,75.3,500,75.3s112.9,11.2,165.3,33.3c50.5,21.3,95.9,52,135,91c39,39,69.7,84.5,91,135c22.1,52.3,33.3,107.9,33.3,165.3s-11.2,112.9-33.3,165.3C869.9,715.8,839.3,761.2,800.3,800.3z"/><path d="M761.3,532.7H532.7V304c0-18.1-14.6-32.7-32.7-32.7s-32.7,14.6-32.7,32.7v261.3l0,0c0,18.1,14.6,32.7,32.7,32.7h261.3c18.1,0,32.7-14.6,32.7-32.7l0,0C794,547.3,779.4,532.7,761.3,532.7z"/></g>\n</svg>'}),this._dialog=new Ot({title:"Timeline",visible:!1,resizable:!0,useHide:!0,top:10,left:60,width:600,height:115,minHeight:115,maxHeight:110}),this._dialog.events.on("visibility",(e=>{this._toggleBtn.setActive(e)}))}oninit(){let e=this.renderer.div;this._toggleBtn.appendTo(e),this._dialog.appendTo(e),this._toggleBtn.events.on("change",(e=>{this._dialog.setVisibility(e),e&&this._timelineView.resize()})),this._timelineView.appendTo(this._dialog.container),this._timelineView.events.on("setcurrent",(e=>{this.renderer&&this.renderer.handler.defaultClock.setDate(e)})),this._timelineView.events.on("startdrag",(()=>{this.planet?.sun.stop(),this.renderer&&this.renderer.controls.mouseNavigation.deactivate()})),this._timelineView.events.on("stopdrag",(()=>{this.renderer&&this.renderer.controls.mouseNavigation.activate()})),this._timelineView.events.on("startdragcurrent",(()=>{this.planet?.sun.stop(),this.renderer&&this.renderer.controls.mouseNavigation.deactivate()})),this._timelineView.events.on("stopdragcurrent",(()=>{this.renderer&&this.renderer.controls.mouseNavigation.activate()}))}},ToggleWireframe:class extends Dt{constructor(e={}){super(e),this._isActive=!1,this.toogleWireframe=()=>{this.renderer&&this.renderer.handler.gl&&(this.planet.drawMode===this.renderer.handler.gl.LINE_STRIP?this.planet.setDrawMode(this.renderer.handler.gl.TRIANGLE_STRIP):this.planet.setDrawMode(this.renderer.handler.gl.LINE_STRIP))},this._isActive=e.isActive||!1}oninit(){this.renderer.events.on("charkeypress",Cn.KEY_X,this.toogleWireframe,this),this._isActive&&this.planet.setDrawMode(this.renderer.handler.gl.LINE_STRIP)}},TouchNavigation:sr,ZoomControl:nr});function Co(e){return new Uint32Array(e)}function To(e){let t=[],i=0,s=0,n=0;for(let r=1;r<e-1-1;r++){for(let o=1;o<e-1;o++)i=r*e+o,n=(r+1)*e,s=n+o,t.push(i,s);t.push(s,n+1)}return t.push(t[t.length-1],e*e-e),Co(t)}function Eo(e,t){let i=[];const s=(e-1)/t,n=e*e-e;let r=0;for(let t=0;t<e-2;t++){t%s==0&&(r=t);let o=n-e*t-e+1,a=n-e*r;i.push(a,o)}return t===e-1&&(i.push(e),i.push(0)),Co(i)}function Lo(e,t){let i=[];const s=(e-1)/t;let n=0;for(let t=0;t<e-2;t++){t%s==0&&(n=t);let r=e+t+1,o=n;i.push(o,r)}return t===e-1&&(i.push(e-2),i.push(e-1)),Co(i)}function Ao(e,t){let i=[];const s=(e-1)/t;let n=0;for(let t=0;t<e-2;t++){t%s==0&&(n=t);let r=e*(t+1)+e-2,o=e+e*n-1;i.push(o,r)}return t===e-1&&(i.push(e*(e-1)-1),i.push(e*e-1)),Co(i)}function Po(e,t){let i=[];const s=(e-1)/t;let n=0;const r=e*(e-1)-2,o=e*e-1;for(let t=0;t<e-2;t++){t%s==0&&(n=t);let e=r-t,a=o-n;i.push(a,e)}return t===e-1&&i.push(e*e-e+1),i.push(e*e-e),Co(i)}function So(e){let t=[[],[],[],[]];for(let i=0;i<=e;i++){let s=Math.pow(2,i)+1;t[0][i]=[],t[3][i]=[],t[2][i]=[],t[1][i]=[];for(let n=0;n<=e;n++){let e=Math.pow(2,n);t[3][i][n]=Eo(s,e),t[0][i][n]=Lo(s,e),t[1][i][n]=Ao(s,e),t[2][i][n]=Po(s,e)}}return t}function Mo(e){let t=[];for(let i=0;i<=e;i++){const e=Math.pow(2,i);t[i]=To(e+1)}return t}function Ro(e){let t=new Uint16Array((e+1)*(e+1)*2),i=0;for(let s=0;s<=e;s++)for(let n=0;n<=e;n++)t[i++]=n/e*65535,t[i++]=s/e*65535;return t}let Bo=new class{constructor(e=0){this._maxGridSize=e,this.centerIndexesTable=Mo(this._maxGridSize),this.skirtsIndexesTable=So(this._maxGridSize)}get maxGridSize(){return this._maxGridSize}init(){this.centerIndexesTable=Mo(this._maxGridSize),this.skirtsIndexesTable=So(this._maxGridSize)}setMaxGridSize(e){this._maxGridSize=e,this.init()}createSegmentIndexes(e,t){if(e){let i=this.centerIndexesTable[e],s=this.skirtsIndexesTable[3][e][t[3]],n=this.skirtsIndexesTable[0][e][t[0]],r=this.skirtsIndexesTable[1][e][t[1]],o=this.skirtsIndexesTable[2][e][t[2]],a=function(e){return new Uint32Array(e)}(i.length+s.length+n.length+r.length+o.length);return a.set(i,0),a.set(s,i.length),a.set(n,i.length+s.length),a.set(r,i.length+s.length+n.length),a.set(o,i.length+s.length+n.length+r.length),a}return Co([0,2,1,3])}initTextureCoordsTable(e){let t=[];for(let i=0;i<=e;i++){const e=Math.pow(2,i);t[i]=Ro(e)}return t}};function ko(){return Bo}const Io={ATMOS_HEIGHT:1e5,RAYLEIGH_SCALE:.08,MIE_SCALE:.012,GROUND_ALBEDO:.05,BOTTOM_RADIUS:6356752.314245179,rayleighScatteringCoefficient:[5.802,13.558,33.1],mieScatteringCoefficient:3.996,mieExtinctionCoefficient:4.44,ozoneAbsorptionCoefficient:[.65,1.881,.085],SUN_ANGULAR_RADIUS:.004685,SUN_INTENSITY:1,ozoneDensityHeight:25e3,ozoneDensityWide:15e3},zo=(e=Io)=>` \n ${ds}\n \n #define PI 3.1415926538\n #define ATMOS_HEIGHT ${e.ATMOS_HEIGHT.toFixed(2)}\n #define RAYLEIGH_SCALE ${e.RAYLEIGH_SCALE.toFixed(5)}\n #define MIE_SCALE ${e.MIE_SCALE.toFixed(5)}\n \n #define SAMPLE_COUNT 16\n #define SQRT_SAMPLE_COUNT 4\n \n const float GROUND_ALBEDO = ${e.GROUND_ALBEDO.toFixed(2)} / PI;\n\n // Sphere\n const float BOTTOM_RADIUS = ${e.BOTTOM_RADIUS.toFixed(10)};\n const float TOP_RADIUS = BOTTOM_RADIUS + ATMOS_HEIGHT; \n const float EQUATORIAL_RADIUS = 6378137.0;\n \n // Ellipsoid\n const vec3 bottomRadii = vec3(EQUATORIAL_RADIUS, EQUATORIAL_RADIUS, BOTTOM_RADIUS); \n const vec3 topRadii = bottomRadii + ATMOS_HEIGHT;\n \n const vec3 SPHERE_TO_ELLIPSOID_SCALE = vec3(BOTTOM_RADIUS) / bottomRadii; \n \n const vec2 rayleighMieHeights = vec2(RAYLEIGH_SCALE, MIE_SCALE) * ATMOS_HEIGHT;\n \n const vec3 rayleighScatteringCoefficient = vec3(${e.rayleighScatteringCoefficient[0].toFixed(5)}, ${e.rayleighScatteringCoefficient[1].toFixed(5)}, ${e.rayleighScatteringCoefficient[2].toFixed(5)}) * 1e-6;\n \n const float mieScatteringCoefficient = ${e.mieScatteringCoefficient.toFixed(3)} * 1e-6;\n const float mieExtinctionCoefficient = ${e.mieExtinctionCoefficient.toFixed(3)} * 1e-6;\n const vec3 ozoneAbsorptionCoefficient = vec3(${e.ozoneAbsorptionCoefficient[0].toFixed(5)}, ${e.ozoneAbsorptionCoefficient[1].toFixed(5)}, ${e.ozoneAbsorptionCoefficient[2].toFixed(5)}) * 1e-6;\n \n const float SUN_ANGULAR_RADIUS = ${e.SUN_ANGULAR_RADIUS.toFixed(10)};\n const float SUN_INTENSITY = ${e.SUN_INTENSITY.toFixed(2)}; \n \n const float ozoneDensityHeight = ${e.ozoneDensityHeight.toFixed(1)};//25e3;\n const float ozoneDensityWide = ${e.ozoneDensityWide.toFixed(1)};//15e3;\n \n vec3 sunWithBloom(vec3 rayDir, vec3 sunDir) \n {\n float minSunCosTheta = cos(SUN_ANGULAR_RADIUS); \n float cosTheta = dot(rayDir, sunDir);\n if (cosTheta >= minSunCosTheta) return vec3(1.0); \n float offset = minSunCosTheta - cosTheta;\n float gaussianBloom = exp(-offset*15000.0)*0.7;\n float invBloom = 1.0/(0.09 + offset*200.0)*0.01;\n return vec3(gaussianBloom + invBloom);\n }\n \n float rayleighPhase(float angle) \n {\n return 3.0 / (16.0 * PI) * (1.0 + (angle * angle));\n }\n \n float miePhase(float angle) \n {\n float g = 0.8;\n return 3.0 / (8.0 * PI) * ((1.0 - g * g) * (1.0 + angle * angle)) / ((2.0 + g * g) * pow(1.0 + g * g - 2.0 * g * angle, 1.5));\n }\n \n vec3 opticalDepth(float height, float angle) \n {\n vec3 rayOrigin = vec3(0.0, BOTTOM_RADIUS + height, 0.0);\n vec3 rayDirection = vec3(sqrt(1.0 - angle * angle), angle, 0.0);\n float t1, t2;\n intersectSphere(rayOrigin, rayDirection, TOP_RADIUS, t1, t2);\n float segmentLength = t2 / float(SAMPLE_COUNT);\n \n float t = segmentLength * 0.5;\n vec3 opticalDepth = vec3(0.0);\n \n for (int i = 0; i < SAMPLE_COUNT; i++) \n {\n vec3 position = rayOrigin + t * rayDirection;\n float height = length(position) - BOTTOM_RADIUS;\n opticalDepth.xy += exp(-height / rayleighMieHeights) * segmentLength;\n opticalDepth.z += (1.0 - min(abs(height - ozoneDensityHeight) / ozoneDensityWide, 1.0)) * segmentLength; \n t += segmentLength;\n }\n \n return opticalDepth;\n }\n \n vec3 transmittance(float height, float angle) \n {\n vec3 opticalDepth = opticalDepth(height, angle);\n return exp(-(rayleighScatteringCoefficient * opticalDepth.x + mieExtinctionCoefficient * opticalDepth.y + ozoneAbsorptionCoefficient * opticalDepth.z));\n }`;const Do="const vec3 nightStep = 10.0 * vec3(0.58, 0.48, 0.25);",Fo="#define blend(DEST, SAMPLER, OFFSET, OPACITY) src = texture( SAMPLER, OFFSET.xy + vTextureCoord.xy * OFFSET.zw ); DEST = DEST * (1.0 - src.a * OPACITY) + src * OPACITY;",No="#define blend(DEST, SAMPLER, OFFSET, OPACITY) src = texture2D( SAMPLER, OFFSET.xy + vTextureCoord.xy * OFFSET.zw ); DEST = DEST * (1.0 - src.a * OPACITY) + src * OPACITY;";function Ho(){return new Ni("drawnode_screen_wl",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",height:"float",uGlobalTextureCoord:"vec4",uNormalMapBias:"vec3",samplerCount:"int",tileOffsetArr:"vec4",layerOpacityArr:"float",samplerArr:"sampler2darray",defaultTexture:"sampler2d",uNormalMap:"sampler2d",nightTexture:"sampler2d",specularTexture:"sampler2d",lightPosition:"vec3",diffuse:"vec3",ambient:"vec3",specular:"vec4",camHeight:"float",nightTextureCoefficient:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"\n attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n attribute vec2 aTextureCoord;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec4 uGlobalTextureCoord;\n uniform vec3 uNormalMapBias;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n varying vec4 vTextureCoord;\n varying vec3 v_vertex;\n varying vec3 cameraPosition;\n varying vec2 vGlobalTextureCoord;\n varying float v_height;\n\n void main(void) {\n\n vec3 aVertexPosition = aVertexPositionHigh + aVertexPositionLow; \n vec3 nh = height * normalize(aVertexPosition);\n\n vTextureCoord.xy = aTextureCoord;\n vGlobalTextureCoord = uGlobalTextureCoord.xy + (uGlobalTextureCoord.zw - uGlobalTextureCoord.xy) * aTextureCoord;\n vTextureCoord.zw = uNormalMapBias.z * ( aTextureCoord + uNormalMapBias.xy );\n\n cameraPosition = eyePositionHigh + eyePositionLow;\n \n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n v_height = height;\n v_vertex = aVertexPosition + nh;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:`\n precision highp float;\n \n #define SLICE_SIZE 5\n\n uniform vec4 specular;\n uniform vec3 diffuse;\n uniform vec3 ambient;\n\n uniform sampler2D uNormalMap;\n uniform sampler2D nightTexture;\n uniform sampler2D specularTexture;\n uniform sampler2D defaultTexture;\n uniform sampler2D samplerArr[SLICE_SIZE];\n\n uniform vec4 tileOffsetArr[SLICE_SIZE];\n uniform vec3 lightPosition;\n uniform float layerOpacityArr[SLICE_SIZE];\n\n uniform int samplerCount;\n uniform float nightTextureCoefficient; \n uniform float camHeight;\n\n varying vec4 vTextureCoord;\n varying vec3 v_vertex;\n varying vec3 cameraPosition;\n varying vec2 vGlobalTextureCoord;\n varying float v_height;\n\n vec3 sunPos;\n\n ${Do}\n\n ${No}\n \n ${ds}\n \n void main(void) {\n \n sunPos = lightPosition;\n \n vec3 texNormal = texture2D(uNormalMap, vTextureCoord.zw).rgb;\n vec3 normal = normalize((texNormal - 0.5) * 2.0);\n \n float minH = 1200000.0;\n float maxH = minH * 3.0;\n float nightCoef = getLerpValue(minH, maxH, camHeight) * nightTextureCoefficient;\n \n // if(camHeight > 6000000.0)\n // {\n // normal = normalize(v_vertex);\n // }\n \n vec3 lightDir = normalize(sunPos);\n vec3 viewDir = normalize(cameraPosition - v_vertex);\n \n float overGround = 1.0 - step(0.1, v_height);\n\n float shininess = texture2D( specularTexture, vGlobalTextureCoord.st ).r * 255.0 * overGround;\n vec3 reflectionDirection = reflect(-lightDir, normal);\n float reflection = max( dot(reflectionDirection, viewDir), 0.0);\n vec3 spec = specular.rgb * pow( reflection, specular.w) * shininess; \n float diffuseLightWeighting = max(dot(normal, lightDir), 0.0); \n vec4 nightImageColor = texture2D( nightTexture, vGlobalTextureCoord.st );\n vec3 night = nightStep * (.18 - diffuseLightWeighting * 3.0) * nightImageColor.rgb * nightCoef;\n night *= overGround * step(0.0, night); \n vec4 lightWeighting = vec4(ambient + diffuse * diffuseLightWeighting + night, 1.0);\n \n gl_FragColor = texture2D( defaultTexture, vTextureCoord.xy );\n if( samplerCount == 0 ) {\n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n return;\n }\n\n vec4 src;\n\n blend(gl_FragColor, samplerArr[0], tileOffsetArr[0], layerOpacityArr[0]);\n if( samplerCount == 1 ) { \n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n return;\n }\n\n blend(gl_FragColor, samplerArr[1], tileOffsetArr[1], layerOpacityArr[1]);\n if( samplerCount == 2 ) {\n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n return;\n }\n\n blend(gl_FragColor, samplerArr[2], tileOffsetArr[2], layerOpacityArr[2]);\n if( samplerCount == 3 ) {\n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n return;\n }\n\n blend(gl_FragColor, samplerArr[3], tileOffsetArr[3], layerOpacityArr[3]);\n if( samplerCount == 4 ) {\n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n return;\n }\n\n blend(gl_FragColor, samplerArr[4], tileOffsetArr[4], layerOpacityArr[4]);\n gl_FragColor = gl_FragColor * lightWeighting + vec4(spec, 0.0);\n }`})}function Oo(e){return new Ni("drawnode_screen_wl",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",height:"float",uGlobalTextureCoord:"vec4",uNormalMapBias:"vec3",samplerCount:"int",tileOffsetArr:"vec4",layerOpacityArr:"float",samplerArr:"sampler2darray",defaultTexture:"sampler2d",uNormalMap:"sampler2d",nightTexture:"sampler2d",specularTexture:"sampler2d",lightPosition:"vec3",diffuse:"vec3",ambient:"vec3",specular:"vec4",transmittanceTexture:"sampler2D",scatteringTexture:"sampler2D",camHeight:"float",nightTextureCoefficient:"float",maxMinOpacity:"vec2",transitionOpacity:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"#version 300 es\n\n precision highp float;\n\n in vec3 aVertexPositionHigh;\n in vec3 aVertexPositionLow;\n in vec2 aTextureCoord;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec4 uGlobalTextureCoord;\n uniform vec3 uNormalMapBias;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n out vec4 vTextureCoord;\n out vec3 v_vertex;\n out vec3 cameraPosition;\n out vec2 vGlobalTextureCoord;\n out float v_height;\n\n void main(void) {\n\n vec3 aVertexPosition = aVertexPositionHigh + aVertexPositionLow; \n vec3 nh = height * normalize(aVertexPosition);\n\n vTextureCoord.xy = aTextureCoord;\n vGlobalTextureCoord = uGlobalTextureCoord.xy + (uGlobalTextureCoord.zw - uGlobalTextureCoord.xy) * aTextureCoord;\n vTextureCoord.zw = uNormalMapBias.z * ( aTextureCoord + uNormalMapBias.xy );\n\n cameraPosition = eyePositionHigh + eyePositionLow;\n \n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n v_height = height;\n v_vertex = aVertexPosition + nh;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:`#version 300 es\n\n precision highp float;\n \n #define SLICE_SIZE 5\n\n uniform vec4 specular;\n uniform vec3 diffuse;\n uniform vec3 ambient;\n\n uniform vec3 lightPosition;\n\n uniform sampler2D uNormalMap;\n uniform sampler2D nightTexture;\n uniform sampler2D specularTexture;\n uniform sampler2D transmittanceTexture;\n uniform sampler2D scatteringTexture;\n uniform sampler2D defaultTexture;\n uniform sampler2D samplerArr[SLICE_SIZE];\n\n uniform vec4 tileOffsetArr[SLICE_SIZE];\n uniform float layerOpacityArr[SLICE_SIZE];\n\n uniform int samplerCount;\n uniform float nightTextureCoefficient;\n \n uniform vec2 maxMinOpacity; \n uniform float camHeight;\n \n uniform float transitionOpacity;\n\n in vec4 vTextureCoord;\n in vec3 v_vertex;\n in vec3 cameraPosition;\n in vec2 vGlobalTextureCoord;\n in float v_height;\n\n vec3 sunPos;\n\n layout(location = 0) out vec4 diffuseColor;\n\n ${Do}\n\n ${Fo}\n \n ${zo(e)} \n \n vec3 transmittanceFromTexture(float height, float angle) \n {\n float u = (angle + 1.0) * 0.5;\n float v = height / ATMOS_HEIGHT;\n return texture(transmittanceTexture, vec2(u, v)).xyz;\n }\n\n vec3 multipleScatteringContributionFromTexture(float height, float angle) \n {\n float u = (angle + 1.0) * 0.5;\n float v = height / ATMOS_HEIGHT;\n return texture(scatteringTexture, vec2(u, v)).xyz;\n }\n \n void getSunIlluminance(in vec3 point, in vec3 lightDir, out vec3 sunIlluminance)\n {\n // float r = length(point);\n // float mu_s = dot(point, sun_direction) / r;\n // float height = r - BOTTOM_RADIUS;\n \n float mu_s = dot(normalize(point), lightDir);\n float height = length(point) - BOTTOM_RADIUS;\n sunIlluminance = SUN_INTENSITY * transmittanceFromTexture(height, mu_s);\n }\n \n void atmosGroundColor(out vec4 fragColor, in vec3 normal)\n { \n vec3 cameraPosition = cameraPosition; \n \n if(length(cameraPosition * SPHERE_TO_ELLIPSOID_SCALE) < BOTTOM_RADIUS + 1.0){\n cameraPosition = normalize(cameraPosition * SPHERE_TO_ELLIPSOID_SCALE) * (BOTTOM_RADIUS + 1.0) / SPHERE_TO_ELLIPSOID_SCALE;\n } \n \n vec3 rayDirection = normalize(v_vertex - cameraPosition);\n vec3 lightDir = normalize(sunPos);\n \n rayDirection = normalize(rayDirection * SPHERE_TO_ELLIPSOID_SCALE);\n vec3 camPos = cameraPosition * SPHERE_TO_ELLIPSOID_SCALE;\n lightDir = normalize(lightDir * SPHERE_TO_ELLIPSOID_SCALE);\n \n\n vec3 light = vec3(0.0);\n vec3 transmittanceFromCameraToSpace = vec3(1.0);\n float offset = 0.0;\n float distanceToSpace = 0.0;\n \n intersectSphere(camPos, rayDirection, TOP_RADIUS, offset, distanceToSpace);\n \n vec3 rayOrigin = camPos;\n \n // above atmosphere\n if (offset > 0.0) \n {\n // intersection of camera ray with atmosphere\n rayOrigin += rayDirection * offset;\n }\n \n float height = length(rayOrigin) - BOTTOM_RADIUS;\n float rayAngle = dot(rayOrigin, rayDirection) / length(rayOrigin);\n bool cameraBelow = rayAngle < 0.0;\n \n transmittanceFromCameraToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n \n float phaseAngle = dot(lightDir, rayDirection);\n float rayleighPhase = rayleighPhase(phaseAngle);\n float miePhase = miePhase(phaseAngle);\n \n float distanceToGround = 0.0;\n \n bool hitGround = intersectSphere(camPos, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0; \n //intersectSphere(camPos, rayDirection, BOTTOM_RADIUS, distanceToGround);\n \n\n if(length(v_vertex * SPHERE_TO_ELLIPSOID_SCALE) > BOTTOM_RADIUS){\n distanceToGround = distance(camPos, v_vertex * SPHERE_TO_ELLIPSOID_SCALE);\n }\n \n float segmentLength = (distanceToGround - max(offset, 0.0)) / float(SAMPLE_COUNT);\n \n float t = segmentLength * 0.5;\n \n vec3 transmittanceCamera; \n vec3 transmittanceLight; \n \n for (int i = 0; i < SAMPLE_COUNT; i++) \n {\n vec3 position = rayOrigin + t * rayDirection;\n float height = length(position) - BOTTOM_RADIUS;\n vec3 up = position / length(position);\n float rayAngle = dot(up, rayDirection);\n float lightAngle = dot(up, lightDir); \n vec3 transmittanceToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n transmittanceCamera = cameraBelow ? (transmittanceToSpace / transmittanceFromCameraToSpace) : (transmittanceFromCameraToSpace / transmittanceToSpace);\n transmittanceLight = transmittanceFromTexture(height, lightAngle);\n vec2 opticalDensity = exp(-height / rayleighMieHeights);\n vec3 scatteredLight = transmittanceLight * (rayleighScatteringCoefficient * opticalDensity.x * rayleighPhase + mieScatteringCoefficient * opticalDensity.y * miePhase);\n scatteredLight += multipleScatteringContributionFromTexture(height, lightAngle) * (rayleighScatteringCoefficient * opticalDensity.x + mieScatteringCoefficient * opticalDensity.y); \n light += transmittanceCamera * scatteredLight * segmentLength;\n t += segmentLength;\n }\n \n light *= SUN_INTENSITY;\n \n vec3 hitPoint = camPos + rayDirection * distanceToGround;\n vec3 up = normalize(hitPoint);\n float diffuseAngle = max(dot(up, lightDir), 0.0); \n \n float lightAngle = dot(normal, lightDir);\n vec3 tA = transmittanceCamera * GROUND_ALBEDO * SUN_INTENSITY; \n vec3 scatteringLight = multipleScatteringContributionFromTexture(height, lightAngle);\n vec3 diffuseTransmittanceLight = transmittanceLight * diffuseAngle; \n light += tA * (scatteringLight + diffuseTransmittanceLight);\n \n fragColor = vec4(pow(light * 8.0, vec3(1.0 / 2.2)), 1.0);\n }\n\n void getAtmosFadingOpacity(out float opacity)\n { \n float c = length(cameraPosition);\n float maxDist = sqrt(c * c - BOTTOM_RADIUS * BOTTOM_RADIUS);\n float minDist = c - BOTTOM_RADIUS;\n float vertDist = distance(cameraPosition, v_vertex); \n opacity = clamp(maxMinOpacity.y + ( maxMinOpacity.x - maxMinOpacity.y) * getLerpValue(minDist, maxDist, vertDist), 0.0, 1.0);\n }\n\n void main(void) {\n \n sunPos = lightPosition;\n \n vec3 texNormal = texture(uNormalMap, vTextureCoord.zw).rgb;\n vec3 normal = normalize((texNormal - 0.5) * 2.0);\n \n float minH = 1200000.0;\n float maxH = minH * 3.0;\n float nightCoef = getLerpValue(minH, maxH, camHeight) * nightTextureCoefficient;\n \n // if(camHeight > 6000000.0)\n // {\n // normal = normalize(v_vertex);\n // }\n \n vec3 lightDir = normalize(sunPos);\n vec3 viewDir = normalize(cameraPosition - v_vertex);\n \n vec4 atmosColor;\n atmosGroundColor(atmosColor, normal);\n \n vec3 sunIlluminance; \n getSunIlluminance(v_vertex * SPHERE_TO_ELLIPSOID_SCALE, lightDir * SPHERE_TO_ELLIPSOID_SCALE, sunIlluminance);\n \n float overGround = 1.0 - step(0.1, v_height);\n\n float shininess = texture( specularTexture, vGlobalTextureCoord.st ).r * 255.0 * overGround;\n vec3 reflectionDirection = reflect(-lightDir, normal);\n float reflection = max( dot(reflectionDirection, viewDir), 0.0);\n vec3 spec = sunIlluminance * specular.rgb * pow( reflection, specular.w) * shininess; \n float diffuseLightWeighting = max(dot(normal, lightDir), 0.0);\n \n vec4 nightImageColor = texture( nightTexture, vGlobalTextureCoord.st );\n vec3 night = nightStep * (.18 - diffuseLightWeighting * 3.0) * nightImageColor.rgb * nightCoef;\n night *= overGround * step(0.0, night); \n vec4 lightWeighting = vec4(ambient + sunIlluminance * diffuse * diffuseLightWeighting + night, 1.0);\n \n float fadingOpacity;\n getAtmosFadingOpacity(fadingOpacity);\n \n getSunIlluminance(cameraPosition, viewDir * SPHERE_TO_ELLIPSOID_SCALE, sunIlluminance);\n \n spec *= sunIlluminance;\n\n diffuseColor = texture( defaultTexture, vTextureCoord.xy );\n if( samplerCount == 0 ) {\n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n vec4 src;\n\n blend(diffuseColor, samplerArr[0], tileOffsetArr[0], layerOpacityArr[0]);\n if( samplerCount == 1 ) { \n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[1], tileOffsetArr[1], layerOpacityArr[1]);\n if( samplerCount == 2 ) {\n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[2], tileOffsetArr[2], layerOpacityArr[2]);\n if( samplerCount == 3 ) {\n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[3], tileOffsetArr[3], layerOpacityArr[3]);\n if( samplerCount == 4 ) {\n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[4], tileOffsetArr[4], layerOpacityArr[4]);\n diffuseColor = mix(diffuseColor * lightWeighting, atmosColor * diffuseColor.a, fadingOpacity) + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n }`})}class Vo{constructor(e,t={}){this.handler=e,this._fbo=null,this._width=t.width||e.canvas.width,this._height=t.height||e.canvas.height,this._depthComponent=null!=t.depthComponent?t.depthComponent:"DEPTH_COMPONENT16",this._useDepth=null==t.useDepth||t.useDepth,this._active=!1,this._size=t.size||1,this._depthRenderbuffer=null,this._filter=t.filter||"NEAREST"}get width(){return this._width}get height(){return this._height}setSize(e,t,i=!1){this._width=e,this._height=t,this._active&&this.handler.gl.viewport(0,0,this._width,this._height),(this._useDepth||i)&&(this.destroy(),this.init())}init(){}destroy(){}isComplete(){let e=this.handler.gl;return e.checkFramebufferStatus(e.FRAMEBUFFER)===e.FRAMEBUFFER_COMPLETE}checkStatus(){let e=this.handler.gl;return e.checkFramebufferStatus(e.FRAMEBUFFER)}activate(){let e=this.handler.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindFramebuffer(e.FRAMEBUFFER,this._fbo),e.viewport(0,0,this._width,this._height),this._active=!0;let t=this.handler.framebufferStack.current().data;return t&&(t._active=!1),this.handler.framebufferStack.push(this),this}deactivate(){let e=this.handler,t=e.gl;t.bindFramebuffer(t.FRAMEBUFFER,null),this._active=!1;let i=this.handler.framebufferStack.popPrev();i?(t.bindFramebuffer(t.FRAMEBUFFER,i._fbo),t.viewport(0,0,i._width,i._height)):t.viewport(0,0,e.canvas.width,e.canvas.height)}}class Uo{constructor(e=256,t=256){this._canvas=document.createElement("canvas"),this._canvas.width=e,this._canvas.height=t,this._context=this._canvas.getContext("2d",{willReadFrequently:!0})}getCanvas(){return this._canvas}getContext(){return this._context}fillEmpty(){let e=this._context.getImageData(0,0,this._canvas.width,this._canvas.height),t=e.data;for(let e=0,i=t.length;e<i;e+=4)t[e]=t[e+1]=t[e+2]=t[e+3]=0;this._context.putImageData(e,0,0)}fill(e){this._context.fillStyle=e,this._context.fill()}getData(){return this._context.getImageData(0,0,this._canvas.width,this._canvas.height).data}fillColor(e){this._context.fillStyle=e,this._context.fillRect(0,0,this._canvas.width,this._canvas.height)}setData(e){let t=this._context.createImageData(this._canvas.width,this._canvas.height);t.data.set(e),this._context.putImageData(t,0,0)}resize(e,t){this._canvas.width=e,this._canvas.height=t,this._context=this._canvas.getContext("2d")}drawImage(e,t,i,s,n){this._context.drawImage(e,t||0,i||0,s||e.width,n||e.height)}getImage(){let e=new Image;return e.width=this.getWidth(),e.height=this.getHeight(),e.src=this._canvas.toDataURL("image/png"),e}getTextWidth(e){let t=this._context.measureText(e);return Math.round(t.width)}drawText(e,t=0,i=14,s="normal 14px Verdana",n="black"){this._context.fillStyle=n,this._context.font=s,this._context.fillText(e,t,i)}getWidth(){return this._canvas.width}getHeight(){return this._canvas.height}load(e,t){let i=new Image,s=this;i.onload=function(){s.resize(i.width,i.height),s._context.drawImage(i,0,0,i.width,i.height),t&&t(i)},i.src=e}openImage(){let e=this.getImage(),t="<!DOCTYPE html>";t+="<html>",t+="<head><title>Print</title></head>",t+="<body>",t+='<img src="'+e.src+'">',t+="</body>",t+="</html>";let i=window.open("","","width="+e.width+"px ,height="+e.height+"px");i&&(i.document.open(),i.document.write(t),i.document.close(),i.focus())}destroy(){this._canvas.width=1,this._canvas.height=1,this._canvas=null,this._context=null}}const Go={UNSIGNED_BYTE:Uint8Array,FLOAT:Float32Array};class Yo extends Vo{constructor(e,t={}){super(e,t),this.readPixelBuffersAsync=()=>{const e=this.handler.gl;if(this._skipFrame)return;this._skipFrame=!0;let t=this.width,i=this.height,s=this.pixelBuffers;this.activate();for(let n=0;n<s.length;n++){let r=s[n];e.bindBuffer(e.PIXEL_PACK_BUFFER,r.buffer),e.bufferData(e.PIXEL_PACK_BUFFER,r.data.byteLength,e.STREAM_READ),e.readBuffer(r.glAttachment),e.readPixels(0,0,t,i,e.RGBA,r.glType,0),e.bindBuffer(e.PIXEL_PACK_BUFFER,null)}this.deactivate();const n=e.fenceSync(e.SYNC_GPU_COMMANDS_COMPLETE,0);e.flush(),function(e,t,i){return new Promise(((s,n)=>{!function r(){const o=e.clientWaitSync(t,i,0);o==e.WAIT_FAILED?n():o==e.TIMEOUT_EXPIRED?requestAnimationFrame(r):s()}()}))}(e,n,0).then((()=>{this._skipFrame=!1,e.deleteSync(n);for(let t=0;t<s.length;t++){let i=s[t];i.data&&(e.bindBuffer(e.PIXEL_PACK_BUFFER,i.buffer),e.getBufferSubData(e.PIXEL_PACK_BUFFER,0,i.data))}e.bindBuffer(e.PIXEL_PACK_BUFFER,null)}))},this._targets=Yo.createTargets(t.targets),this._size=this._targets.length,this._renderbufferTarget=null!=t.renderbufferTarget?t.renderbufferTarget:"DEPTH_ATTACHMENT",this.textures=t.textures||new Array(this._size),this.pixelBuffers=[],this._skipFrame=!1}static createTargets(e){let t=0,i=0;return e?e.map((e=>{let s=e.attachment||"COLOR_ATTACHMENT";"COLOR_ATTACHMENT"===s&&(s="COLOR_ATTACHMENT"+t++);let n=e.type||"UNSIGNED_BYTE";return{internalFormat:e.internalFormat||"RGBA",format:e.format||"RGBA",type:n,attachment:s,filter:e.filter||"NEAREST",pixelBufferIndex:e.readAsync?i++:-1,TypeArrayConstructor:Go[n]}})):[{internalFormat:"RGBA",format:"RGBA",type:"UNSIGNED_BYTE",attachment:"COLOR_ATTACHMENT0",filter:"NEAREST",pixelBufferIndex:-1,TypeArrayConstructor:Go.UNSIGNED_BYTE}]}destroy(){let e=this.handler.gl;if(e){for(let t=0;t<this.textures.length;t++)e.deleteTexture(this.textures[t]);this.textures=new Array(this._size);for(let t=0;t<this.pixelBuffers.length;t++)this.pixelBuffers[t].data=null,e.deleteBuffer(this.pixelBuffers[t].buffer);this.pixelBuffers=[],e.deleteFramebuffer(this._fbo),e.deleteRenderbuffer(this._depthRenderbuffer),this._depthRenderbuffer=null,this._fbo=null,this._active=!1}}init(){let e=this.handler.gl;if(!e)return;this._fbo=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this._fbo);let t=[];for(let i=0;i<this._targets.length;i++){let s=this._targets[i],n=this.textures[i]||this.handler.createEmptyTexture2DExt(this._width,this._height,s.filter,s.internalFormat,s.format,s.type),r=e[s.attachment];n&&(this.bindOutputTexture(n,r),this.textures[i]=n),"DEPTH_ATTACHMENT"!==s.attachment&&t.push(r),-1!==s.pixelBufferIndex&&this._createPixelBuffer(s)}e.drawBuffers&&e.drawBuffers(t),this._useDepth&&(this._depthRenderbuffer=e.createRenderbuffer(),e.bindRenderbuffer(e.RENDERBUFFER,this._depthRenderbuffer),e.renderbufferStorage(e.RENDERBUFFER,e[this._depthComponent],this._width,this._height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e[this._renderbufferTarget],e.RENDERBUFFER,this._depthRenderbuffer),e.bindRenderbuffer(e.RENDERBUFFER,null)),e.bindFramebuffer(e.FRAMEBUFFER,null)}getPixelBufferData(e){let t=this._targets[e].pixelBufferIndex;return-1!==t?this.pixelBuffers[t].data:null}_createPixelBuffer(e){let t=this.handler.gl,i=e.pixelBufferIndex,s=this.pixelBuffers[i];s||(s=this.pixelBuffers[i]={buffer:null,data:null,glType:-1,glAttachment:-1});let n=this.width*this.height*4;s.data=null,s.data=new e.TypeArrayConstructor(n),s.buffer=t.createBuffer(),t.bindBuffer(t.PIXEL_PACK_BUFFER,s.buffer),t.bufferData(t.PIXEL_PACK_BUFFER,n,t.STREAM_READ),t.bindBuffer(t.PIXEL_PACK_BUFFER,null),s.glType=t[e.type],s.glAttachment=t[e.attachment]}bindOutputTexture(e,t){let i=this.handler.gl;i.bindTexture(i.TEXTURE_2D,e),i.framebufferTexture2D(i.FRAMEBUFFER,t||i.COLOR_ATTACHMENT0,i.TEXTURE_2D,e,0),i.bindTexture(i.TEXTURE_2D,null)}readPixels(e,t,i,s=0,n=1,r=1){let o=this.handler.gl;o.bindFramebuffer(o.FRAMEBUFFER,this._fbo),o.readBuffer&&o.readBuffer(o.COLOR_ATTACHMENT0+s||0),o.readPixels(t*this._width,i*this._height,n,r,o.RGBA,o[this._targets[s].type],e),o.bindFramebuffer(o.FRAMEBUFFER,null)}readAllPixels(e,t=0){let i=this.handler.gl;i.bindFramebuffer(i.FRAMEBUFFER,this._fbo),i.readBuffer&&i.readBuffer(i.COLOR_ATTACHMENT0+t),i.readPixels(0,0,this._width,this._height,i.RGBA,i[this._targets[t].type],e),i.bindFramebuffer(i.FRAMEBUFFER,null)}getImage(){let e=new Uint8Array(4*this._width*this._height);this.readAllPixels(e);let t=new Uo(this._width,this._height);return t.setData(e),t.getImage()}}class jo extends Dt{constructor(e={}){super({name:"Atmosphere",...e}),this._transmittanceBuffer=null,this._scatteringBuffer=null,this.opacity=1,this._parameters={ATMOS_HEIGHT:e.height||1e5,RAYLEIGH_SCALE:e.rayleighScale||.08,MIE_SCALE:e.mieScale||.012,GROUND_ALBEDO:e.groundAlbedo||.05,BOTTOM_RADIUS:e.bottomRadius||6356752.314245179,rayleighScatteringCoefficient:e.rayleighScatteringCoefficient||[5.802,13.558,33.1],mieScatteringCoefficient:e.mieScatteringCoefficient||3.996,mieExtinctionCoefficient:e.mieExtinctionCoefficient||4.44,ozoneAbsorptionCoefficient:e.ozoneAbsorptionCoefficient||[.65,1.881,.085],SUN_ANGULAR_RADIUS:e.sunAngularRadius||.004685,SUN_INTENSITY:e.sunIntensity||1,ozoneDensityHeight:e.ozoneDensityHeight||25e3,ozoneDensityWide:e.ozoneDensityWide||15e3}}setParameters(e){this._parameters=JSON.parse(JSON.stringify(e)),this.initLookupTexturesShaders(),this.drawLookupTextures(),this.removeLookupTexturesShaders(),this.initPlanetAtmosphereShader()}get parameters(){return JSON.parse(JSON.stringify(this._parameters))}initPlanetAtmosphereShader(){this.planet?.initAtmosphereShader(this._parameters)}oninit(){this.renderer&&(this._initLookupTextures(),this.initLookupTexturesShaders(),this.drawLookupTextures(),this.removeLookupTexturesShaders(),this.initBackgroundShader(),this.activate())}initLookupTexturesShaders(){var e;this.renderer&&(this.renderer.handler.addProgram((e=this._parameters,new Ni("transmittance",{uniforms:{iResolution:"vec2"},attributes:{a_position:"vec2"},vertexShader:"\n attribute vec2 a_position;\n \n void main(void) \n {\n gl_Position = vec4(a_position, 0.0, 1.0);\n }",fragmentShader:`\n precision highp float;\n \n ${zo(e)}\n \n uniform vec2 iResolution;\n \n void main(void) \n {\n vec2 uv = gl_FragCoord.xy / iResolution.xy;\n float height = uv.y * ATMOS_HEIGHT;\n float angle = uv.x * 2.0 - 1.0;\n gl_FragColor = vec4(transmittance(height, angle), 1.0);\n }`})),!0),this.renderer.handler.addProgram(function(e){return new Ni("scattering",{uniforms:{iResolution:"vec2",transmittanceTexture:"sampler2d"},attributes:{a_position:"vec2"},vertexShader:" \n attribute vec2 a_position; \n \n void main(void) \n {\n gl_Position = vec4(a_position, 0.0, 1.0);\n }",fragmentShader:` \n precision highp float;\n \n uniform sampler2D transmittanceTexture;\n uniform vec2 iResolution;\n \n ${zo(e)}\n \n vec3 transmittanceFromTexture(float height, float angle) \n {\n float u = (angle + 1.0) * 0.5;\n float v = height / ATMOS_HEIGHT;\n return texture2D(transmittanceTexture, vec2(u, v)).xyz;\n }\n \n void main(void) \n {\n vec2 uv = gl_FragCoord.xy / iResolution.xy;\n \n float height = uv.y * ATMOS_HEIGHT;\n float angle = uv.x * 2.0 - 1.0;\n \n vec3 rayOrigin = vec3(0.0, BOTTOM_RADIUS + height, 0.0);\n vec3 up = rayOrigin / length(rayOrigin);\n vec3 lightDirection = vec3(sqrt(1.0 - angle * angle), angle, 0.0);\n \n const float isotropicPhase = 1.0 / (4.0 * PI);\n \n vec3 light = vec3(0.0);\n vec3 lightTransferFactor = vec3(0.0);\n \n for (int i = 0; i < SQRT_SAMPLE_COUNT; i++)\n {\n for (int j = 0; j < SQRT_SAMPLE_COUNT; j++)\n {\n float u = ((0.5 + float(i)) / float(SQRT_SAMPLE_COUNT)) * 2.0 - 1.0;\n float v = (0.5 + float(j)) / float(SQRT_SAMPLE_COUNT);\n float r = sqrt(1.0 - u * u);\n float theta = 2.0 * PI * v;\n vec3 rayDirection = vec3(cos(theta) * r, sin(theta) * r, u);\n \n float rayAngle = dot(up, rayDirection);\n bool cameraBelow = rayAngle < 0.0;\n \n vec3 transmittanceFromCameraToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n \n float offset = 0.0;\n float distanceToSpace = 0.0;\n \n intersectSphere(rayOrigin, rayDirection, TOP_RADIUS, offset, distanceToSpace);\n \n float distanceToGround = 0.0;\n bool hitGround = intersectSphere(rayOrigin, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0; \n float segmentLength = (hitGround ? distanceToGround : distanceToSpace) / float(SAMPLE_COUNT);\n float t = segmentLength * 0.5;\n \n vec3 transmittanceCamera;\n vec3 transmittanceLight;\n \n for (int k = 0; k < SAMPLE_COUNT; k++) \n {\n vec3 position = rayOrigin + t * rayDirection;\n float height = length(position) - BOTTOM_RADIUS;\n vec3 up = position / length(position);\n float rayAngle = dot(up, rayDirection);\n float lightAngle = dot(up, lightDirection);\n \n float distanceToGround;\n float shadow = intersectSphere(position, lightDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround >= 0.0 ? 0.0 : 1.0;\n vec3 transmittanceToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n \n transmittanceCamera = cameraBelow ? (transmittanceToSpace / transmittanceFromCameraToSpace) : (transmittanceFromCameraToSpace / transmittanceToSpace);\n transmittanceLight = transmittanceFromTexture(height, lightAngle);\n \n vec2 opticalDensity = exp(-height / rayleighMieHeights); \n vec3 scatteredLight = transmittanceLight * (rayleighScatteringCoefficient * opticalDensity.x + mieScatteringCoefficient * opticalDensity.y) * isotropicPhase;\n \n light += shadow * transmittanceCamera * scatteredLight * segmentLength;\n lightTransferFactor += transmittanceCamera * (rayleighScatteringCoefficient * opticalDensity.x + mieScatteringCoefficient * opticalDensity.y) * segmentLength;\n \n t += segmentLength;\n }\n \n if (hitGround) \n {\n vec3 hitPoint = rayOrigin + rayDirection * distanceToGround;\n vec3 normal = normalize(hitPoint);\n float diffuseAngle = max(dot(normal, lightDirection), 0.0); \n light += transmittanceCamera * transmittanceLight * GROUND_ALBEDO * diffuseAngle;\n }\n }\n }\n \n light /= float(SAMPLE_COUNT);\n lightTransferFactor /= float(SAMPLE_COUNT);\n vec3 color = light / (1.0 - lightTransferFactor); \n gl_FragColor = vec4(color, 1.0);\n }`})}(this._parameters),!0))}initBackgroundShader(){var e;this.renderer&&this.renderer.handler.addProgram((e=this._parameters,new Ni("atmosphereBackground",{uniforms:{iResolution:"vec2",fov:"float",camPos:"vec3",viewMatrix:"mat4",transmittanceTexture:"sampler2D",scatteringTexture:"sampler2D",sunPos:"vec3",opacity:"float"},attributes:{corners:"vec3"},vertexShader:" \n attribute vec2 corners;\n \n void main(void) {\n gl_Position = vec4(corners, 0.0, 1.0);\n }",fragmentShader:` \n precision lowp float;\n \n ${zo(e)}\n \n uniform mat4 viewMatrix;\n uniform vec3 sunPos;\n uniform vec3 camPos; \n uniform vec2 iResolution;\n uniform float fov;\n uniform float opacity;\n \n uniform sampler2D transmittanceTexture;\n uniform sampler2D scatteringTexture;\n \n vec3 transmittanceFromTexture(float height, float angle) \n {\n float u = (angle + 1.0) * 0.5;\n float v = height / ATMOS_HEIGHT;\n return texture2D(transmittanceTexture, vec2(u, v)).xyz;\n }\n \n vec3 multipleScatteringContributionFromTexture(float height, float angle) \n {\n float u = (angle + 1.0) * 0.5;\n float v = height / ATMOS_HEIGHT;\n return texture2D(scatteringTexture, vec2(u, v)).xyz; \n }\n\n bool intersectEllipsoidToSphere(in vec3 ro, in vec3 rd, in vec3 ellRadii, in float sphereRadius, out float t1, out float t2) \n {\n float offset = 0.0,\n distanceToSpace = 0.0;\n \n if(intersectEllipsoid(ro, rd, ellRadii, offset, distanceToSpace)){\n vec3 hitEll = ro + rd * offset;\n vec3 nEll = normalEllipsoid(hitEll, ellRadii);\n float t = 0.0;\n bool intersectsSphere = intersectSphere(hitEll, nEll, sphereRadius, t);\n vec3 hitSphere = hitEll + nEll * t;\n t1 = length(hitSphere - ro);\n \n hitEll = ro + rd * distanceToSpace;\n nEll = normalEllipsoid(hitEll, ellRadii);\n t = 0.0;\n intersectsSphere = intersectSphere(hitEll, nEll, sphereRadius, t);\n hitSphere = hitEll + nEll * t;\n t2 = length(hitSphere - ro);\n \n return true; \n }\n return false; \n }\n \n mat4 transpose(in mat4 m) \n {\n vec4 i0 = m[0];\n vec4 i1 = m[1];\n vec4 i2 = m[2];\n vec4 i3 = m[3];\n \n mat4 outMatrix = mat4(\n vec4(i0.x, i1.x, i2.x, i3.x),\n vec4(i0.y, i1.y, i2.y, i3.y),\n vec4(i0.z, i1.z, i2.z, i3.z),\n vec4(i0.w, i1.w, i2.w, i3.w)\n );\n \n return outMatrix;\n }\n \n void mainImage(out vec4 fragColor) \n { \n vec3 cameraPosition = camPos;\n \n vec3 lightDirection = normalize(sunPos); \n \n vec2 uv = (2.0 * gl_FragCoord.xy - iResolution.xy) / iResolution.y;\n float fieldOfView = fov;\n float z = 1.0 / tan(fieldOfView * 0.5 * PI / 180.0);\n vec3 rayDirection = normalize(vec3(uv, -z));\n vec4 rd = transpose(viewMatrix) * vec4(rayDirection, 1.0);\n rayDirection = rd.xyz; \n \n vec3 light = vec3(0.0);\n vec3 transmittanceFromCameraToSpace = vec3(1.0);\n float offset = 0.0;\n float distanceToSpace = 0.0;\n \n rayDirection = normalize(rayDirection * SPHERE_TO_ELLIPSOID_SCALE);\n cameraPosition *= SPHERE_TO_ELLIPSOID_SCALE;\n lightDirection = normalize(lightDirection * SPHERE_TO_ELLIPSOID_SCALE);\n \n if(length(cameraPosition) < BOTTOM_RADIUS + 100.0){\n cameraPosition = normalize(cameraPosition) * (BOTTOM_RADIUS + 100.0); \n }\n \n if (intersectSphere(cameraPosition, rayDirection, TOP_RADIUS, offset, distanceToSpace)) \n { \n vec3 rayOrigin = cameraPosition;\n \n // above atmosphere \n if (offset > 0.0) {\n // intersection of camera ray with atmosphere\n rayOrigin = cameraPosition + rayDirection * offset;\n } \n \n float height = length(rayOrigin) - BOTTOM_RADIUS;\n float rayAngle = dot(rayOrigin, rayDirection) / length(rayOrigin);\n bool cameraBelow = rayAngle < 0.0;\n \n transmittanceFromCameraToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n \n float phaseAngle = dot(lightDirection, rayDirection);\n float rayleighPhase = rayleighPhase(phaseAngle);\n float miePhase = miePhase(phaseAngle);\n \n float distanceToGround = 0.0;\n \n bool hitGround = intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0;\n \n if(intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS - 100000.0, distanceToGround) && hitGround)\n {\n discard;\n }\n \n float segmentLength = ((hitGround ? distanceToGround : distanceToSpace) - max(offset, 0.0)) / float(SAMPLE_COUNT);\n \n float t = segmentLength * 0.5;\n \n vec3 transmittanceCamera; \n vec3 transmittanceLight; \n \n for (int i = 0; i < SAMPLE_COUNT; i++) \n {\n vec3 position = rayOrigin + t * rayDirection;\n float height = length(position) - BOTTOM_RADIUS; \n vec3 up = position / length(position);\n float rayAngle = dot(up, rayDirection);\n float lightAngle = dot(up, lightDirection);\n vec3 transmittanceToSpace = transmittanceFromTexture(height, cameraBelow ? -rayAngle : rayAngle);\n transmittanceCamera = cameraBelow ? (transmittanceToSpace / transmittanceFromCameraToSpace) : (transmittanceFromCameraToSpace / transmittanceToSpace);\n transmittanceLight = transmittanceFromTexture(height, lightAngle);\n vec2 opticalDensity = exp(-height / rayleighMieHeights);\n vec3 scatteredLight = transmittanceLight * (rayleighScatteringCoefficient * opticalDensity.x * rayleighPhase + mieScatteringCoefficient * opticalDensity.y * miePhase);\n scatteredLight += multipleScatteringContributionFromTexture(height, lightAngle) * (rayleighScatteringCoefficient * opticalDensity.x + mieScatteringCoefficient * opticalDensity.y); \n light += transmittanceCamera * scatteredLight * segmentLength;\n t += segmentLength;\n }\n \n light *= SUN_INTENSITY;\n \n if (hitGround) \n {\n vec3 hitPoint = cameraPosition + rayDirection * distanceToGround;\n vec3 up = hitPoint / length(hitPoint);\n float diffuseAngle = max(dot(up, lightDirection), 0.0);\n float lightAngle = dot(up, lightDirection);\n light += transmittanceCamera * GROUND_ALBEDO * multipleScatteringContributionFromTexture(height, lightAngle) * SUN_INTENSITY;\n light += transmittanceCamera * transmittanceLight * GROUND_ALBEDO * diffuseAngle * SUN_INTENSITY;\n }\n }\n \n // sun disk\n // float distanceToGround;\n // bool hitGround = intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0;\n // if (!hitGround) {\n // float angle = dot(rayDirection, lightDirection);\n // if (angle > cos(SUN_ANGULAR_RADIUS)) {\n // light = SUN_INTENSITY * transmittanceFromCameraToSpace;\n // }\n // }\n \n float distanceToGround = 0.0;\n bool hitGround = intersectSphere(cameraPosition, rayDirection, BOTTOM_RADIUS, distanceToGround) && distanceToGround > 0.0;\n if(!hitGround)\n {\n vec3 sunLum = sunWithBloom(rayDirection, lightDirection) * vec3(1.0,1.0,0.8);\n // limit the bloom effect\n sunLum = smoothstep(0.002, 1.0, sunLum);\n light += sunLum * SUN_INTENSITY * transmittanceFromCameraToSpace;\n }\n \n fragColor = vec4(pow(light * 8.0, vec3(1.0 / 2.2)), clamp(opacity, 0.0, 1.0)); \n }\n \n void main(void) \n { \n mainImage(gl_FragColor); \n }`})),!0)}removeBackgroundShader(){this.renderer&&this.renderer.handler.removeProgram("atmosphereBackground")}removeLookupTexturesShaders(){if(this.renderer){let e=this.renderer.handler;this._scatteringBuffer?.isComplete()&&e.removeProgram("scattering"),this._transmittanceBuffer?.isComplete()&&e.removeProgram("transmittance")}}onactivate(){super.onactivate(),this.planet&&this.planet.events.on("draw",this._drawBackground,this)}ondeactivate(){super.ondeactivate(),this.planet&&this.planet.events.off("draw",this._drawBackground)}_initLookupTextures(){this._transmittanceBuffer=new Yo(this.renderer.handler,{width:1024,height:1024,useDepth:!1,targets:[{filter:"LINEAR",type:"FLOAT",internalFormat:"RGBA16F"}]}),this._transmittanceBuffer.init(),this._scatteringBuffer=new Yo(this.renderer.handler,{width:1024,height:1024,useDepth:!1,targets:[{filter:"LINEAR",type:"FLOAT",internalFormat:"RGBA16F"}]}),this._scatteringBuffer.init()}_renderLookupTextures(){if(!this.renderer)return;let e=this.renderer.screenFramePositionBuffer,t=this.renderer.handler,i=t.gl;if(this._transmittanceBuffer){this._transmittanceBuffer.activate();let s=t.programs.transmittance,n=s._program.attributes,r=s._program.uniforms;s.activate(),i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),i.uniform2fv(r.iResolution,[this._transmittanceBuffer.width,this._transmittanceBuffer.height]),i.bindBuffer(i.ARRAY_BUFFER,e),i.vertexAttribPointer(n.a_position,e.itemSize,i.FLOAT,!1,0,0),i.drawArrays(i.TRIANGLE_STRIP,0,e.numItems),this._transmittanceBuffer.deactivate()}if(this._scatteringBuffer&&this._transmittanceBuffer){this._scatteringBuffer.activate();let s=t.programs.scattering,n=s._program.attributes,r=s._program.uniforms;s.activate(),i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),i.uniform2fv(r.iResolution,[this._scatteringBuffer.width,this._scatteringBuffer.height]),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this._transmittanceBuffer.textures[0]),i.uniform1i(r.transmittanceTexture,0),i.bindBuffer(i.ARRAY_BUFFER,e),i.vertexAttribPointer(n.a_position,e.itemSize,i.FLOAT,!1,0,0),i.drawArrays(i.TRIANGLE_STRIP,0,e.numItems),this._scatteringBuffer.deactivate()}}drawLookupTextures(){this._renderLookupTextures()}_drawBackground(){let e=this.renderer.handler,t=e.programs.atmosphereBackground,i=t._program,s=i.uniforms,n=e.gl,r=this.renderer,o=this.planet.camera;n.disable(n.DEPTH_TEST),t.activate(),n.bindBuffer(n.ARRAY_BUFFER,r.screenFramePositionBuffer),n.vertexAttribPointer(i.attributes.corners,2,n.FLOAT,!1,0,0),n.activeTexture(n.TEXTURE0),n.bindTexture(n.TEXTURE_2D,this._transmittanceBuffer.textures[0]),n.uniform1i(s.transmittanceTexture,0),n.activeTexture(n.TEXTURE1),n.bindTexture(n.TEXTURE_2D,this._scatteringBuffer.textures[0]),n.uniform1i(s.scatteringTexture,1),n.uniformMatrix4fv(s.viewMatrix,!1,o.getViewMatrix());let a=this.planet.sunPos;n.uniform3fv(s.sunPos,[a.x,a.y,a.z]),n.uniform3fv(s.camPos,[o.eye.x,o.eye.y,o.eye.z]),n.uniform2fv(s.iResolution,[r.sceneFramebuffer.width,r.sceneFramebuffer.height]),n.uniform1f(s.fov,o.getViewAngle()),n.uniform1f(s.opacity,this.opacity),n.drawArrays(n.TRIANGLE_STRIP,0,4),n.enable(n.DEPTH_TEST)}}const Wo="degrees",qo="m";let $o=0;class Xo{constructor(e){this.id=$o++,this.code=e.code,this.units=e.units}equal(e){return e.id===this.id}}const Zo=new Xo({code:"epsg:3857",units:qo});class Ko{constructor(e){this.segment=e,this.layers=[],this.tileOffsetArr=new Float32Array(e.planet.SLICE_SIZE_4),this.layerOpacityArr=new Float32Array(e.planet.SLICE_SIZE)}clear(){this.layers=null,this.tileOffsetArr=null,this.layerOpacityArr=null}append(e,t){let i=this.layers.length;this.layers.push(e),this.layerOpacityArr[i]=e.screenOpacity;let s=4*i,n=e.applyMaterial(t);this.tileOffsetArr[s]=n[0],this.tileOffsetArr[s+1]=n[1],this.tileOffsetArr[s+2]=n[2],this.tileOffsetArr[s+3]=n[3]}}function Qo(e,t,i){return Math.floor(Math.abs(i-e)/t)}function Jo(e,t,i,s){let n=1/(1<<i),r=s.getWidth()*n,o=s.getHeight()*n,a=s.southWest.lon+e*r,l=s.northEast.lat-t*o;return new te(new I(a,l-o),new I(a+r,l))}const ea=20,ta=300;let ia=new oe,sa=new oe,na=new oe,ra=new oe,oa=new oe,aa=new oe,la=new ui,ha=new ui;const ca=new Array(4);ca[0]=0,ca[1]=1,ca[2]=1,ca[3]=0;const da=new Array(4);da[0]=!1,da[1]=!0,da[2]=!1,da[3]=!0;class _a{constructor(e,t,i,s){this.isPole=!1,this._tileGroup=0,this._projection=Zo,this.node=e,this.planet=t,this.handler=t.renderer.handler,this.bsphere=new Pt,this._plainRadius=0,this.bbox=new At,this._sw=new oe,this._nw=new oe,this._se=new oe,this._ne=new oe,this.centerNormal=new oe,this._extent=this._extentMerc=s,this._extentLonLat=new te,this.gridSize=t.terrain.gridSizeByZoom[i],this.fileGridSize=0,this.tileZoom=i,this.powTileZoom=1<<i,this.tileX=0,this.tileXE=0,this.tileXW=0,this.tileYN=0,this.tileYS=0,this.tileY=0,this.tileIndex="",this.elevationData=null,this._assignTileIndexes(),this.materials=[],this.plainReady=!1,this.initialized=!1,this.normalMapReady=!1,this.terrainReady=!1,this.terrainIsLoading=!1,this.terrainExists=!1,this.passReady=!1,this.plainVertices=null,this.plainVerticesHigh=null,this.plainVerticesLow=null,this.plainNormals=null,this.terrainVertices=null,this.terrainVerticesHigh=null,this.terrainVerticesLow=null,this.noDataVertices=null,this.tempVertices=null,this.tempVerticesHigh=null,this.tempVerticesLow=null,this.normalMapTexture=null,this.normalMapTextureBias=new Float32Array(3),this.normalMapVertices=null,this.normalMapVerticesHigh=null,this.normalMapVerticesLow=null,this.normalMapNormals=null,this.vertexNormalBuffer=null,this.vertexPositionBuffer=null,this.vertexPositionBufferHigh=null,this.vertexPositionBufferLow=null,this.vertexTextureCoordBuffer=null,this._globalTextureCoordinates=new Float32Array(4),this._inTheQueue=!1,this._appliedNeighborsZoom=[0,0,0,0],this._slices=[],this._indexBuffer=null,this.readyToEngage=!1,this.plainProcessing=!1,this.normalMapTexturePtr=null,this._transitionOpacity=1,this._transitionTimestamp=0}checkZoom(){return this.tileZoom<this.planet.terrain._maxNodeZoom}getEntityTerrainPoint(e,t){return this.getTerrainPoint(e._cartesian,this.getInsideLonLat(e),t)}getInsideLonLat(e){return e._lonLatMerc}isEntityInside(e){return this._extentLonLat.isInside(e._lonLat)}getTerrainPoint(e,t,i){let s=this.tempVertices;if(s&&s.length){let n=this.planet.ellipsoid.getSurfaceNormal3v(e);la.set(e,n.negateTo());let r=this._extent.northEast,o=this._extent.southWest,a=Math.sqrt(s.length/3)-1,l=r.lon,h=r.lat,c=o.lon,d=o.lat,_=(l-c)/a,u=(h-d)/a,g=t.lon-c,f=t.lat-d,p=Math.floor(g/_),m=Math.floor(a-f/u),v=3*((a+1)*m+p),y=3*((a+1)*(m+1)+p);na.set(s[v],s[v+1],s[v+2]),ra.set(s[v+3],s[v+4],s[v+5]),oa.set(s[y],s[y+1],s[y+2]);let x=la.hitTriangleRes(na,ra,oa,i);if(x===ui.INSIDE)return e.distance(i);if(x===ui.AWAY){if(ha.set(e,n),ha.hitTriangleRes(na,ra,oa,i)===ui.INSIDE)return-e.distance(i)}if(aa.set(s[y+3],s[y+4],s[y+5]),x=la.hitTriangleRes(ra,aa,oa,i),x===ui.INSIDE)return e.distance(i);if(x===ui.AWAY){if(ha.set(e,n),ha.hitTriangleRes(ra,aa,oa,i)===ui.INSIDE)return-e.distance(i)}return x===ui.AWAY?-e.distance(i):e.distance(i)}return e.distance(this.planet.ellipsoid.hitRay(la.origin,la.direction))}projectNative(e){return e.forwardMercator()}loadTerrain(e=!1){this.tileZoom<this.planet.terrain.minZoom||this.planet.terrain.isEmpty?(this.terrainIsLoading=!0,this.elevationsNotExists(),this._inTheQueue||this.planet._normalMapCreator.queue(this)):this.tileZoom>this.planet.terrain.maxZoom?this.elevationsNotExists():this.terrainIsLoading||this.terrainReady||this.planet.terrain.loadTerrain(this,e)}elevationsExists(e){if(this.plainReady&&this.terrainIsLoading){let t=new Float32Array(e.length);t.set(e),this.elevationData=new Float32Array(e.length),this.elevationData.set(e),this.planet._terrainWorker.make({segment:this,elevations:t}),this.plainVerticesHigh=null,this.plainVerticesLow=null,this.normalMapVerticesHigh=null,this.normalMapVerticesLow=null,this.planet.terrain.equalizeVertices||(this.tempVerticesHigh=null,this.tempVerticesLow=null)}}elevationsNotExists(){if(this.planet&&this.tileZoom<=this.planet.terrain.maxNativeZoom){if(this.plainReady&&this.terrainIsLoading){this.terrainIsLoading=!1;let e=this.node;e.appliedTerrainNodeId=this.node.nodeId,e.equalizedSideWithNodeId[0]=e.equalizedSideWithNodeId[1]=e.equalizedSideWithNodeId[2]=e.equalizedSideWithNodeId[3]=e.appliedTerrainNodeId,this.planet.lightEnabled&&!this._inTheQueue&&this.planet._normalMapCreator.queue(this),this.readyToEngage=!0}this.terrainVertices=this.plainVertices,this.terrainVerticesHigh=this.plainVerticesHigh,this.terrainVerticesLow=this.plainVerticesLow,this.tempVertices=this.terrainVertices,this.tempVerticesHigh=this.terrainVerticesHigh,this.tempVerticesLow=this.terrainVerticesLow,this.noDataVertices=null,this.fileGridSize=Math.sqrt(this.terrainVertices.length/3)-1,this.gridSize=this.fileGridSize,this.terrainReady=!0,this.terrainExists=!1}else if(this.plainReady&&this.terrainIsLoading){this.terrainIsLoading=!1;let e=this.node;e.appliedTerrainNodeId=this.node.nodeId,e.equalizedSideWithNodeId[0]=e.equalizedSideWithNodeId[1]=e.equalizedSideWithNodeId[2]=e.equalizedSideWithNodeId[3]=e.appliedTerrainNodeId,this.readyToEngage=!0,this.terrainReady=!0,this.passReady=!0,this.terrainExists=!1}}_checkEqualization(e,t){return t&&t.segment&&this.tileZoom>=t.segment.tileZoom&&this.node.equalizedSideWithNodeId[e]!==t.equalizedSideWithNodeId[Gt[e]]}equalize(){if(this.tileZoom<2||this.gridSize<2)return;this.readyToEngage=!0;let e=this.node.neighbors,t=this.tempVertices,i=this.tempVerticesHigh,s=this.tempVerticesLow,n=this.gridSize,r=n+1,o=e[0][0];if(this._checkEqualization(0,o)){this.node.equalizedSideWithNodeId[0]=o.equalizedSideWithNodeId[2],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(o,0),a=o.segment.tempVertices,l=o.segment.tempVerticesHigh,h=o.segment.tempVerticesLow,c=o.segment.gridSize,d=c+1,_=1/(1<<this.tileZoom-o.segment.tileZoom),u=Math.max(n/(c*_),1),g=Math.max(c*_/n,1);for(let n=0,o=e*c;n<r;n+=u,o+=g){const e=3*n,r=3*(d*c+o);t[e]=a[r],t[e+1]=a[r+1],t[e+2]=a[r+2],i[e]=l[r],i[e+1]=l[r+1],i[e+2]=l[r+2],s[e]=h[r],s[e+1]=h[r+1],s[e+2]=h[r+2]}}if(o=e[1][0],this._checkEqualization(1,o)){this.node.equalizedSideWithNodeId[1]=o.equalizedSideWithNodeId[3],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(o,1),a=o.segment.tempVertices,l=o.segment.tempVerticesHigh,h=o.segment.tempVerticesLow,c=o.segment.gridSize,d=c+1,_=1/(1<<this.tileZoom-o.segment.tileZoom),u=Math.max(n/(c*_),1),g=Math.max(c*_/n,1);for(let o=0,_=e*c;o<r;o+=u,_+=g){const e=3*(r*o+n),c=d*_*3;t[e]=a[c],t[e+1]=a[c+1],t[e+2]=a[c+2],i[e]=l[c],i[e+1]=l[c+1],i[e+2]=l[c+2],s[e]=h[c],s[e+1]=h[c+1],s[e+2]=h[c+2]}}if(o=e[2][0],this._checkEqualization(2,o)){this.node.equalizedSideWithNodeId[2]=o.equalizedSideWithNodeId[0],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(o,2),a=o.segment.tempVertices,l=o.segment.tempVerticesHigh,h=o.segment.tempVerticesLow,c=o.segment.gridSize,d=1/(1<<this.tileZoom-o.segment.tileZoom),_=Math.max(n/(c*d),1),u=Math.max(c*d/n,1);for(let o=0,d=e*c;o<r;o+=_,d+=u){const e=3*(r*n+o),c=3*d;t[e]=a[c],t[e+1]=a[c+1],t[e+2]=a[c+2],i[e]=l[c],i[e+1]=l[c+1],i[e+2]=l[c+2],s[e]=h[c],s[e+1]=h[c+1],s[e+2]=h[c+2]}}if(o=e[3][0],this._checkEqualization(3,o)){this.node.equalizedSideWithNodeId[3]=o.equalizedSideWithNodeId[1],this.readyToEngage=!0;let e=this.node.getOffsetOppositeNeighbourSide(o,3),a=o.segment.tempVertices,l=o.segment.tempVerticesHigh,h=o.segment.tempVerticesLow,c=o.segment.gridSize,d=c+1,_=1/(1<<this.tileZoom-o.segment.tileZoom),u=Math.max(n/(c*_),1),g=Math.max(c*_/n,1);for(let n=0,o=e*c;n<r;n+=u,o+=g){const e=r*n*3,_=3*(d*o+c);t[e]=a[_],t[e+1]=a[_+1],t[e+2]=a[_+2],i[e]=l[_],i[e+1]=l[_+1],i[e+2]=l[_+2],s[e]=h[_],s[e+1]=h[_+1],s[e+2]=h[_+2]}}}engage(){this.readyToEngage=!1,this.createCoordsBuffers(this.tempVerticesHigh,this.tempVerticesLow,this.gridSize)}_terrainWorkerCallback(e){if(this.plainReady){this.readyToEngage=!0,this.normalMapNormals=null,this.normalMapVertices=null,this.normalMapVerticesHigh=null,this.normalMapVerticesLow=null,this.terrainVertices=null,this.terrainVerticesHigh=null,this.terrainVerticesLow=null,this.noDataVertices=null,this.tempVertices=null,this.tempVerticesHigh=null,this.tempVerticesLow=null,this.normalMapNormals=e.normalMapNormals,this.normalMapVertices=e.normalMapVertices,this.normalMapVerticesHigh=e.normalMapVerticesHigh,this.normalMapVerticesLow=e.normalMapVerticesLow,this.terrainVertices=e.terrainVertices,this.terrainVerticesHigh=e.terrainVerticesHigh,this.terrainVerticesLow=e.terrainVerticesLow,this.noDataVertices=e.noDataVertices,this.tempVertices=this.terrainVertices,this.tempVerticesHigh=this.terrainVerticesHigh,this.tempVerticesLow=this.terrainVerticesLow,this.setBoundingVolumeArr(e.bounds),this.gridSize=Math.sqrt(this.terrainVertices.length/3)-1;let t=this.node;if(t.appliedTerrainNodeId=t.nodeId,t.equalizedSideWithNodeId[0]=t.equalizedSideWithNodeId[1]=t.equalizedSideWithNodeId[2]=t.equalizedSideWithNodeId[3]=t.appliedTerrainNodeId,this.terrainReady=!0,this.terrainIsLoading=!1,this.terrainExists=!0,!this.normalMapTexturePtr){const e=this.planet._normalMapCreator;this.normalMapTexturePtr=this.planet.renderer.handler.createEmptyTexture_l(e.width,e.height)}this.planet.lightEnabled&&this.planet._normalMapCreator.queue(this)}}_normalMapEdgeEqualize(e){let t=this.node.neighbors,i=t[e],s=i&&i[0],n=this.planet.terrain.maxZoom;this.tileZoom===n&&i&&!(t[0].length||t[1].length||t[2].length||t[3].length)&&(s=this.node.getEqualNeighbor(e));let r=s&&s.segment,o=this;if(s&&r&&r.terrainReady&&r.terrainExists&&r.tileZoom<=n&&o._appliedNeighborsZoom[e]!==r.tileZoom){o._appliedNeighborsZoom[e]=r.tileZoom;let t=o.normalMapNormals,i=r.normalMapNormals;if(!t||!i)return;let s=o.normalMapNormals,n=r.normalMapNormals,a=Math.sqrt(t.length/3),l=a-1;const h=l*ca[e];let c,d,_,u;if(o.tileZoom===r.tileZoom){const g=l-h;if(da[e])for(let e=0;e<a;e++){let r=3*(e*a+h),o=3*(e*a+g);c=s[r]+n[o],d=s[r+1]+n[o+1],_=s[r+2]+n[o+2],u=1/Math.sqrt(c*c+d*d+_*_),i[o]=t[r]=c*u,i[o+1]=t[r+1]=d*u,i[o+2]=t[r+2]=_*u}else for(let e=0;e<a;e++){let r=3*(h*a+e),o=3*(g*a+e);c=s[r]+n[o],d=s[r+1]+n[o+1],_=s[r+2]+n[o+2],u=1/Math.sqrt(c*c+d*d+_*_),i[o]=t[r]=c*u,i[o+1]=t[r+1]=d*u,i[o+2]=t[r+2]=_*u}r._inTheQueue||r._appliedNeighborsZoom[Gt[e]]===o.tileZoom||(r._appliedNeighborsZoom[Gt[e]]=o.tileZoom,o.planet._normalMapCreator.queue(r))}}}applyTerrain(e){e?this.elevationsExists(e):this.elevationsNotExists()}deleteBuffers(){const e=this.handler.gl;e.deleteBuffer(this.vertexNormalBuffer),e.deleteBuffer(this.vertexPositionBuffer),e.deleteBuffer(this.vertexPositionBufferHigh),e.deleteBuffer(this.vertexPositionBufferLow),this.vertexNormalBuffer=null,this.vertexPositionBuffer=null,this.vertexPositionBufferHigh=null,this.vertexPositionBufferLow=null,this.vertexTextureCoordBuffer=null}deleteMaterials(){let e=this.materials;for(let t=0;t<e.length;t++){let i=e[t];i&&i.clear()}this.materials.length=0}deleteElevations(){this.terrainExists=!1,this.terrainReady=!1,this.terrainIsLoading=!1,this.normalMapVertices=null,this.normalMapVerticesHigh=null,this.normalMapVerticesLow=null,this.normalMapNormals=null,this.tempVertices=null,this.tempVerticesHigh=null,this.tempVerticesLow=null,this.terrainVertices=null,this.terrainVerticesHigh=null,this.terrainVerticesLow=null,this.noDataVertices=null,this.plainVertices=null,this.plainVerticesHigh=null,this.plainVerticesLow=null,this.plainNormals=null,this.normalMapReady&&(this.handler.gl.deleteTexture(this.normalMapTexture),this.normalMapReady=!1),this._appliedNeighborsZoom=[0,0,0,0],this.normalMapTextureBias[0]=0,this.normalMapTextureBias[1]=0,this.normalMapTextureBias[2]=1,this._inTheQueue=!1}clearSegment(){this.plainReady=!1,this.initialized=!1,this.deleteBuffers(),this.deleteMaterials(),this.deleteElevations()}childrenInitialized(){let e=this.node.nodes;return 4===e.length&&e[0].segment.initialized&&e[1].segment.initialized&&e[2].segment.initialized&&e[3].segment.initialized}destroySegment(){this.clearSegment();let e=this._slices.length;for(;e--;)this._slices[e].clear();this._slices=null,this.node=null,this.planet=null,this.handler=null,this.bbox=null,this.bsphere=null,this._extent=null,this.materials=null,this.plainVertices=null,this.plainVerticesHigh=null,this.plainVerticesLow=null,this.plainNormals=null,this.terrainVertices=null,this.terrainVerticesHigh=null,this.terrainVerticesLow=null,this.noDataVertices=null,this.tempVertices=null,this.tempVerticesHigh=null,this.tempVerticesLow=null,this.normalMapTextureBias=null,this.normalMapTexture=null,this.normalMapVertices=null,this.normalMapVerticesHigh=null,this.normalMapVerticesLow=null,this.normalMapNormals=null,this.vertexNormalBuffer=null,this.vertexPositionBuffer=null,this.vertexPositionBufferHigh=null,this.vertexPositionBufferLow=null,this.vertexTextureCoordBuffer=null,this._projection=null,this._appliedNeighborsZoom=null,this._globalTextureCoordinates=null}_setExtentLonLat(){this._extentLonLat=this._extent.inverseMercator()}_createExtentNormals(){const e=this.planet.ellipsoid,t=this._extentLonLat,i=e.geodeticToCartesian(t.southWest.lon,t.southWest.lat),s=e.geodeticToCartesian(t.northEast.lon,t.northEast.lat),n=e.geodeticToCartesian(t.southWest.lon,t.northEast.lat),r=e.geodeticToCartesian(t.northEast.lon,t.southWest.lat);this._sw.copy(i),this._nw.copy(n),this._ne.copy(s),this._se.copy(r)}createBoundsByExtent(){this._createExtentNormals(),this.setBoundingVolume3v(this._sw,this._ne)}createBoundsByParent(){let e=this.node;for(;e.parentNode&&!e.segment.terrainReady;)e=e.parentNode;let t=1<<this.tileZoom-e.segment.tileZoom,i=this.tileX-e.segment.tileX*t,s=this.tileY-e.segment.tileY*t;if(e.segment.terrainReady&&e.segment.tileZoom>=this.planet.terrain.minZoom){let n=e.segment.gridSize/t;if(n>=1){this.bsphere.center.x=e.segment.bsphere.center.x,this.bsphere.center.y=e.segment.bsphere.center.y,this.bsphere.center.z=e.segment.bsphere.center.z,this.bsphere.radius=e.segment.bsphere.radius;let t=n*s,r=n*i,o=e.segment.gridSize+1,a=3*((t+n)*o+r),l=3*(t*o+r),h=3*(t*o+r+n),c=3*((t+n)*o+r+n),d=e.segment.tempVertices,_=new oe(d[a],d[a+1],d[a+2]),u=new oe(d[h],d[h+1],d[h+2]),g=new oe(d[l],d[l+1],d[l+2]),f=new oe(d[c],d[c+1],d[c+2]);this._sw.copy(_),this._nw.copy(g),this._ne.copy(u),this._se.copy(f)}else{let t,r=e.segment,o=Math.floor(n*s),a=Math.floor(n*i),l=1/n,h=s-l*o,c=i-l*a;t=1===r.gridSize?r.tempVertices:je(r.tempVertices,r.gridSize,o,a,1);let d,_,u=new oe(t[0],t[1],t[2]),g=new oe(t[9],t[10],t[11]),f=new oe(t[3]-t[0],t[4]-t[1],t[5]-t[2]),p=new oe(t[6]-t[0],t[7]-t[1],t[8]-t[2]),m=new oe(t[3]-t[9],t[4]-t[10],t[5]-t[11]),v=new oe(t[6]-t[9],t[7]-t[10],t[8]-t[11]),y=h,x=c;d=y+x<l?oe.add(f.scaleTo(x/l),p.scaleTo(y/l)).addA(u):oe.add(v.scaleTo(1-x/l),m.scaleTo(1-y/l)).addA(g),y=h+1,x=c+1,_=y+x<l?oe.add(f.scaleTo(x/l),p.scaleTo(y/l)).addA(u):oe.add(v.scaleTo(1-x/l),m.scaleTo(1-y/l)).addA(g),this._createExtentNormals(),this.setBoundingVolume3v(d,_)}}else this.createBoundsByExtent()}setBoundingSphere(e,t,i,s){this.bsphere.center.x=e,this.bsphere.center.y=t,this.bsphere.center.z=i,this.bsphere.radius=this.bsphere.center.distance(s)}setBoundingVolume(e,t,i,s,n,r){this.bbox.setFromBoundsArr([e,t,i,s,n,r]);let o=e+.5*(s-e),a=t+.5*(n-t),l=i+.5*(r-i);this.bsphere.center.set(o,a,l),this.bsphere.radius=this.bsphere.center.distance(new oe(e,t,i))}setBoundingVolume3v(e,t){this.bbox.setFromBoundsArr([e.x,e.y,e.z,t.x,t.y,t.z]);let i=e.x+.5*(t.x-e.x),s=e.y+.5*(t.y-e.y),n=e.z+.5*(t.z-e.z);this.bsphere.center.set(i,s,n),this.bsphere.radius=this.bsphere.center.distance(new oe(e.x,e.y,e.z))}setBoundingVolumeArr(e){this.bbox.setFromBoundsArr(e);let t=e[0]+.5*(e[3]-e[0]),i=e[1]+.5*(e[4]-e[1]),s=e[2]+.5*(e[5]-e[2]);this.bsphere.center.set(t,i,s),this.bsphere.radius=this.bsphere.center.distance(new oe(e[0],e[1],e[2]))}createCoordsBuffers(e,t,i){const s=(i+1)*(i+1),n=this.handler;this.vertexPositionBufferHigh&&this.vertexPositionBufferHigh.numItems===s?(n.setStreamArrayBuffer(this.vertexPositionBufferHigh,e),n.setStreamArrayBuffer(this.vertexPositionBufferLow,t)):(n.gl.deleteBuffer(this.vertexPositionBufferHigh),n.gl.deleteBuffer(this.vertexPositionBufferLow),this.vertexTextureCoordBuffer=this.planet._textureCoordsBufferCache[Math.log2(i)],this.vertexPositionBufferHigh=n.createArrayBuffer(e,3,s),this.vertexPositionBufferLow=n.createArrayBuffer(t,3,s))}_addViewExtent(){const e=this._extentLonLat;let t=this.planet._viewExtent;e.southWest.lon<t.southWest.lon&&(t.southWest.lon=e.southWest.lon),e.northEast.lon>t.northEast.lon&&(t.northEast.lon=e.northEast.lon),e.southWest.lat<t.southWest.lat&&(t.southWest.lat=e.southWest.lat),e.northEast.lat>t.northEast.lat&&(t.northEast.lat=e.northEast.lat)}_assignTileIndexes(){this._tileGroup=0;const e=this.tileZoom,t=this._extent,i=z;this.tileX=Qo(t.getCenter().lon,t.getWidth(),-i),this.tileY=Qo(t.getCenter().lat,t.getHeight(),i);const s=this.powTileZoom;this.tileXE=(this.tileX+1)%s,this.tileXW=(s+this.tileX-1)%s,this.tileYN=this.tileY-1,this.tileYS=this.tileY+1,this.tileIndex=$t.getTileIndex(this.tileX,this.tileY,e,this._tileGroup)}initialize(){const e=this.planet,t=this.node;if(this.gridSize=e.terrain.gridSizeByZoom[this.tileZoom]||e.terrain.plainGridSize,t.sideSizeLog2[0]=t.sideSizeLog2[1]=t.sideSizeLog2[2]=t.sideSizeLog2[3]=Math.log2(this.gridSize),this.tileZoom<=e.terrain.maxZoom){const t=this.planet._normalMapCreator;this.normalMapTexturePtr=e.renderer.handler.createEmptyTexture_l(t.width,t.height)}this.normalMapTexture=this.planet.transparentTexture,this._assignGlobalTextureCoordinates(),this.initialized=!0}_assignGlobalTextureCoordinates(){const e=this._extent;this._globalTextureCoordinates[0]=(e.southWest.lon+z)*W,this._globalTextureCoordinates[1]=(z-e.northEast.lat)*W,this._globalTextureCoordinates[2]=(e.northEast.lon+z)*W,this._globalTextureCoordinates[3]=(z-e.southWest.lat)*W}createPlainSegmentAsync(){let e=this.planet,t=e.terrain;t.isReady()&&!this.plainReady&&this.tileZoom<=t.maxZoom&&(this.plainProcessing=!0,e._plainSegmentWorker.make(this))}_plainSegmentWorkerCallback(e){this.plainProcessing=!1,this.initialized&&!this.terrainReady&&(this.plainReady=!0,this.plainVertices=e.plainVertices,this.plainVerticesHigh=e.plainVerticesHigh,this.plainVerticesLow=e.plainVerticesLow,this.plainNormals=e.plainNormals,this._plainRadius=e.plainRadius,this.normalMapNormals=e.normalMapNormals,this.normalMapVertices=e.normalMapVertices,this.normalMapVerticesHigh=e.normalMapVerticesHigh,this.normalMapVerticesLow=e.normalMapVerticesLow,this.fileGridSize=Math.sqrt(e.normalMapVertices.length/3)-1)}createPlainSegment(){this.initialize(),this._createPlainVertices(),this.readyToEngage=!0}_projToDeg(e,t){return I.inverseMercator(e,t)}_createPlainVertices(){const e=this.planet.terrain.gridSizeByZoom[this.tileZoom],t=this.planet.terrain.plainGridSize,i=Math.max(t,e),s=this._extent,n=s.getWidth()/i,r=s.getHeight()/i,o=s.southWest.lon,a=s.northEast.lat,l=Math.max(t/e,1),h=i+1,c=this.planet.ellipsoid._invRadii2,d=h*h,_=(e+1)*(e+1)*3;let u=0,g=0;this.plainNormals=new Float32Array(_),this.plainVertices=new Float64Array(_),this.plainVerticesHigh=new Float32Array(_),this.plainVerticesLow=new Float32Array(_),this.normalMapNormals=new Float32Array(3*d),this.normalMapVertices=new Float64Array(3*d),this.normalMapVerticesHigh=new Float32Array(3*d),this.normalMapVerticesLow=new Float32Array(3*d);let f=this.plainVertices,p=this.plainVerticesHigh,m=this.plainVerticesLow,v=this.plainNormals,y=this.normalMapVertices,x=this.normalMapVerticesHigh,b=this.normalMapVerticesLow,w=this.normalMapNormals;for(let e=0;e<d;e++){let t=e%h,i=~~(e/h),s=this.planet.ellipsoid.lonLatToCartesian(this._projToDeg(o+t*n,a-i*r)),d=s.x*c.x,_=s.y*c.y,C=s.z*c.z,T=1/Math.sqrt(d*d+_*_+C*C),E=d*T,L=_*T,A=C*T;oe.doubleToTwoFloats(s,ia,sa),y[g]=s.x,x[g]=ia.x,b[g]=sa.x,w[g++]=E,y[g]=s.y,x[g]=ia.y,b[g]=sa.y,w[g++]=L,y[g]=s.z,x[g]=ia.z,b[g]=sa.z,w[g++]=A,i%l==0&&t%l==0&&(f[u]=s.x,p[u]=ia.x,m[u]=sa.x,v[u++]=E,f[u]=s.y,p[u]=ia.y,m[u]=sa.y,v[u++]=L,f[u]=s.z,p[u]=ia.z,m[u]=sa.z,v[u++]=A)}this.terrainVertices=f,this.terrainVerticesHigh=p,this.terrainVerticesLow=m,this.plainReady=!0}getMaterialByLayer(e){return this.materials[e.__id]}_getLayerExtentOffset(e){const t=e._extentMerc,i=this._extent,s=t.northEast.lon-t.southWest.lon,n=t.northEast.lat-t.southWest.lat;return[(i.southWest.lon-t.southWest.lon)/s,(t.northEast.lat-i.northEast.lat)/n,(i.northEast.lon-i.southWest.lon)/s,(i.northEast.lat-i.southWest.lat)/n]}initSlice(e){let t=this._slices[e];return t?t.layers=[]:t=this._slices[e]=new Ko(this),t}screenRendering(e,t,i,s,n=!1,r){const o=this.handler.gl,a=e.attributes,l=e.uniforms,h=this.materials,c=this.planet;let d,_;t&&t.length?(_=t[0],d=_._height):d=0,o.activeTexture(o.TEXTURE0+c.SLICE_SIZE+2),o.bindTexture(o.TEXTURE_2D,s||this.getDefaultTexture()),o.uniform1i(l.defaultTexture,c.SLICE_SIZE+2);let u=0,g=0,f=!1,p=this.initSlice(i);for(this._indexBuffer=this._getIndexBuffer();_;){if(this.layerOverlap(_)&&(_._fading&&_._fadingOpacity>0||(_.minZoom>=c.minCurrZoom||_.maxZoom>=c.minCurrZoom)&&(_.minZoom<=c.maxCurrZoom||_.maxZoom<=c.maxCurrZoom))){f=!0;let e=h[_.__id];e||(e=h[_.__id]=_.createMaterial(this)),e.isReady||(this.planet._renderCompleted=!1),p.append(_,e),c._samplerArr[u]=u,o.activeTexture(o.TEXTURE0+u),o.bindTexture(o.TEXTURE_2D,e.texture||c.transparentTexture),u++}g++,_=t[g]}!f&&n||(o.uniform1f(l.transitionOpacity,r||this._transitionOpacity>1?1:this._transitionOpacity),o.uniform1i(l.samplerCount,u),o.uniform1f(l.height,d),o.uniform1iv(l.samplerArr,c._samplerArr),o.uniform4fv(l.tileOffsetArr,p.tileOffsetArr),o.uniform1fv(l.layerOpacityArr,p.layerOpacityArr),c.lightEnabled&&(o.activeTexture(o.TEXTURE0+c.SLICE_SIZE+3),o.bindTexture(o.TEXTURE_2D,this.normalMapTexture||c.transparentTexture),o.uniform1i(l.uNormalMap,c.SLICE_SIZE+3),o.uniform3fv(l.uNormalMapBias,this.normalMapTextureBias),o.uniform4fv(l.uGlobalTextureCoord,this._globalTextureCoordinates)),o.bindBuffer(o.ARRAY_BUFFER,this.vertexPositionBufferHigh),o.vertexAttribPointer(a.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,o.FLOAT,!1,0,0),o.bindBuffer(o.ARRAY_BUFFER,this.vertexPositionBufferLow),o.vertexAttribPointer(a.aVertexPositionLow,this.vertexPositionBufferLow.itemSize,o.FLOAT,!1,0,0),o.bindBuffer(o.ARRAY_BUFFER,this.vertexTextureCoordBuffer),o.vertexAttribPointer(a.aTextureCoord,2,o.UNSIGNED_SHORT,!0,0,0),o.bindBuffer(o.ELEMENT_ARRAY_BUFFER,this._indexBuffer),o.drawElements(c.drawMode,this._indexBuffer.numItems,o.UNSIGNED_INT,0))}heightPickingRendering(e,t){const i=this.handler.gl,s=e.attributes,n=e.uniforms;let r;r=t&&t.length?t[0]._height:0,i.uniform1f(n.height,r),i.bindBuffer(i.ARRAY_BUFFER,this.vertexPositionBufferHigh),i.vertexAttribPointer(s.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this.vertexPositionBufferLow),i.vertexAttribPointer(s.aVertexPositionLow,this.vertexPositionBufferLow.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,this._indexBuffer),i.drawElements(i.TRIANGLE_STRIP,this._indexBuffer.numItems,i.UNSIGNED_INT,0)}increaseTransitionOpacity(){this._transitionOpacity+=(window.performance.now()-this._transitionTimestamp)/this.planet.transitionTime,this._transitionTimestamp=window.performance.now(),this._transitionOpacity>2&&(this._transitionOpacity=2);let e=this.node._fadingNodes.length;for(;e--;){let t=this.node._fadingNodes[e];if(!t.segment){this._transitionOpacity=1;break}t.segment._transitionOpacity>0&&!this.planet._fadingNodes.has(t.__id)&&(this.planet._fadingNodes.set(t.__id,t),t.segment._transitionOpacity=2-this._transitionOpacity,0===t.segment._transitionOpacity&&this.node._fadingNodes.splice(e,1))}}fadingTransitionOpacity(){this._transitionOpacity-=.01,this._transitionTimestamp=window.performance.now(),this._transitionOpacity<0&&(this._transitionOpacity=0)}colorPickingRendering(e,t,i,s,n=!1){const r=this.handler.gl,o=e.attributes,a=e.uniforms;let l,h=this.materials,c=this.planet;l=t&&t.length?t[0]._height:0;let d=!1,_=this._slices[i],u=_.layers.length;for(let e=0;e<u;e++){d=!0;let t=_.layers[e],i=4*e;c._pickingColorArr[i]=t._pickingColor.x/255,c._pickingColorArr[i+1]=t._pickingColor.y/255,c._pickingColorArr[i+2]=t._pickingColor.z/255,c._pickingColorArr[i+3]=Number(t._pickingEnabled),c._samplerArr[e]=e,r.activeTexture(r.TEXTURE0+e),r.bindTexture(r.TEXTURE_2D,h[t.__id].texture||this.planet.transparentTexture),c._pickingMaskArr[e]=e+c.SLICE_SIZE,r.activeTexture(r.TEXTURE0+e+c.SLICE_SIZE),r.bindTexture(r.TEXTURE_2D,h[t.__id].pickingMask||this.planet.transparentTexture)}!d&&n||(r.uniform1i(a.samplerCount,u),r.uniform1f(a.height,l),r.uniform1iv(a.samplerArr,c._samplerArr),r.uniform1iv(a.pickingMaskArr,c._pickingMaskArr),r.uniform4fv(a.pickingColorArr,c._pickingColorArr),r.uniform4fv(a.tileOffsetArr,_.tileOffsetArr),r.uniform1fv(a.layerOpacityArr,_.layerOpacityArr),r.bindBuffer(r.ARRAY_BUFFER,this.vertexPositionBufferHigh),r.vertexAttribPointer(o.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this.vertexPositionBufferLow),r.vertexAttribPointer(o.aVertexPositionLow,this.vertexPositionBufferLow.itemSize,r.FLOAT,!1,0,0),r.bindBuffer(r.ARRAY_BUFFER,this.vertexTextureCoordBuffer),r.vertexAttribPointer(o.aTextureCoord,2,r.UNSIGNED_SHORT,!0,0,0),r.bindBuffer(r.ELEMENT_ARRAY_BUFFER,this._indexBuffer),r.drawElements(r.TRIANGLE_STRIP,this._indexBuffer.numItems,r.UNSIGNED_INT,0))}depthRendering(e,t){const i=this.handler.gl,s=e.attributes,n=e.uniforms;var r;r=t&&t.length?t[0]._height:0,i.uniform1f(n.height,r),i.bindBuffer(i.ARRAY_BUFFER,this.vertexPositionBufferHigh),i.vertexAttribPointer(s.aVertexPositionHigh,this.vertexPositionBufferHigh.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ARRAY_BUFFER,this.vertexPositionBufferLow),i.vertexAttribPointer(s.aVertexPositionLow,this.vertexPositionBufferLow.itemSize,i.FLOAT,!1,0,0),i.bindBuffer(i.ELEMENT_ARRAY_BUFFER,this._indexBuffer),i.drawElements(i.TRIANGLE_STRIP,this._indexBuffer.numItems,i.UNSIGNED_INT,0)}_getIndexBuffer(){const e=this.node.sideSizeLog2;let t=this.planet._indexesCache[Math.log2(this.gridSize)][e[0]][e[1]][e[2]][e[3]];if(!t.buffer){let i=ko().createSegmentIndexes(Math.log2(this.gridSize),[e[0],e[1],e[2],e[3]]);t.buffer=this.planet.renderer.handler.createElementArrayBuffer(i,1),this.planet._indexesCacheToRemoveCounter++}return t.buffer}layerOverlap(e){return this._extent.overlaps(e._extentMerc)}getDefaultTexture(){return this.planet.solidTextureOne}getExtentLonLat(){return this._extentLonLat}getExtentMerc(){return this._extentMerc}getExtent(){return this._extent}getNeighborSide(e){if(this.tileY===e.tileY){if(this.tileX===e.tileXE)return 3;if(this.tileX===e.tileXW)return 1}else if(this.tileX===e.tileX){if(this.tileY===e.tileYS)return 0;if(this.tileY===e.tileYN)return 2}return-1}}let ua=new oe,ga=new oe;const fa=[new ae(0,0),new ae(1,0),new ae(0,1),new ae(1,1)],pa=Math.sqrt(fa.length)-1;let ma={xmin:0,ymin:0,zmin:0,xmax:0,ymax:0,zmax:0},va=0,ya=class e{constructor(e,t,i,s,n,r){t._createdNodesCount++,this.__id=va++,this.SegmentPrototype=e,this.planet=t,this.parentNode=s,this.partId=i,this.nodeId=i+(s?4*s.nodeId+1:0),this.state=null,this.prevState=null,this.appliedTerrainNodeId=-1,this.sideSizeLog2=[0,0,0,0],this.ready=!1,this.neighbors=[[],[],[],[]],this.equalizedSideWithNodeId=[this.nodeId,this.nodeId,this.nodeId,this.nodeId],this.nodes=[],this.segment=new e(this,t,n,r),this._cameraInside=!1,this.inFrustum=0,this._fadingNodes=[],this.createBounds()}createChildNodes(){this.ready=!0;const t=this.planet,i=this.segment,s=i._extent,n=i.tileZoom+1,r=.5*s.getWidth(),o=.5*s.getHeight(),a=s.northEast,l=s.southWest,h=new I(l.lon+r,l.lat+o),c=this.nodes;c[0]=new e(this.SegmentPrototype,t,0,this,n,new te(new I(l.lon,l.lat+o),new I(l.lon+r,a.lat))),c[1]=new e(this.SegmentPrototype,t,1,this,n,new te(h,new I(a.lon,a.lat))),c[2]=new e(this.SegmentPrototype,t,2,this,n,new te(new I(l.lon,l.lat),h)),c[3]=new e(this.SegmentPrototype,t,3,this,n,new te(new I(l.lon+r,l.lat),new I(a.lon,l.lat+o)))}createBounds(){let e=this.segment;e._setExtentLonLat(),0===e.tileZoom?e.setBoundingSphere(0,0,0,new oe(0,0,e.planet.ellipsoid.equatorialSize)):e.tileZoom<e.planet.terrain.minZoom?e.createBoundsByExtent():e.createBoundsByParent();let t=e.bsphere.center.x,i=e.bsphere.center.y,s=e.bsphere.center.z,n=1/Math.sqrt(t*t+i*i+s*s);e.centerNormal.x=t*n,e.centerNormal.y=i*n,e.centerNormal.z=s*n}getState(){if(-1===this.state)return this.state;let e=this.parentNode;for(;e;){if(2!==e.state)return 0;e=e.parentNode}return this.state}getEqualNeighbor(e){let t=this,i=Yt[e][t.partId];if(-1!==i)return t.parentNode.nodes[i];{let s=[];for(;t.parentNode;)if(s.push(t.partId),i=Yt[e][t.partId],t=t.parentNode,-1!==i){let n=s.length;for(e=Gt[e];t&&n--;)i=jt[e][s[n]],t=t.nodes[i];return t}}}traverseNodes(e,t,i,s,n){this.ready||this.createChildNodes();let r=this.nodes;r[0].renderTree(e,t,i,s,n),r[1].renderTree(e,t,i,s,n),r[2].renderTree(e,t,i,s,n),r[3].renderTree(e,t,i,s,n)}renderTree(e,t,i,s,n){if(this.planet._renderedNodes.length>=1e3)return;(!t||n&&this.segment.tileZoom>n.segment.tileZoom)&&(this.prevState=this.state),this.state=2,this.clearNeighbors();let r=this.segment,o=this.planet;if(this._cameraInside=!1,!this.parentNode||this.parentNode._cameraInside){let t;t=r._projection.id===Zo.id?r._extent.isInside(e._lonLatMerc):r._extent.isInside(e._lonLat),t&&(e._insideSegment=r,this._cameraInside=!0)}this.inFrustum=0;let a=e.frustums,l=a.length;if(r.tileZoom<6)for(let e=0;e<l;e++)a[e].containsSphere(r.bsphere)&&(this.inFrustum|=1<<e);else for(let e=0;e<l;e++)r.terrainReady?a[e].containsBox(r.bbox)&&(this.inFrustum|=1<<e):a[e].containsSphere(r.bsphere)&&(this.inFrustum|=1<<e);if(this.inFrustum||this._cameraInside||r.tileZoom<3){let a=Math.abs(e._lonLat.height),l=e.eye.length2()-o.ellipsoid.polarSizeSqr;l=l<106876472875.63281*o._heightFactor?106876472875.63281*o._heightFactor:l;let h=r.tileZoom<2||r.tileZoom>19||r.tileZoom<6&&!r.terrainReady;h=h||e.eye.distance2(r._sw)<l||e.eye.distance2(r._nw)<l||e.eye.distance2(r._ne)<l||e.eye.distance2(r._se)<l,(this.inFrustum&&(h||a>1e4)||this._cameraInside)&&o.quadTreeStrategy.collectVisibleNode(this),r.tileZoom<2?this.traverseNodes(e,t,i,s,n):r.terrainReady&&(!t&&e.projectedSize(r.bsphere.center,r._plainRadius)<o.lodSize||t&&(r.tileZoom===t||!h))?h?(r.passReady=!0,this.renderNode(this.inFrustum,!this.inFrustum,i,s)):this.state=0:r.terrainReady&&r.checkZoom()&&(!t||e.projectedSize(r.bsphere.center,r.bsphere.radius)>this.planet._maxLodSize)?this.traverseNodes(e,t,r,s,n):h?(r.passReady=!!t&&r.terrainReady,this.renderNode(this.inFrustum,!this.inFrustum,i,s)):this.state=0}else this.state=0}renderNode(e,t,i,s){let n=this.segment;n.terrainReady||(n.initialized||n.initialize(),this.whileTerrainLoading(i),n.plainProcessing||n.createPlainSegmentAsync(),n.plainReady&&!s&&n.loadTerrain()),n.planet.lightEnabled&&!n.normalMapReady&&this.whileNormalMapCreating(),t?this.state=-1:(!this._cameraInside&&n.tileZoom>this.planet.maxCurrZoom&&(this.planet.maxCurrZoom=n.tileZoom),n.tileZoom<this.planet.minCurrZoom&&(this.planet.minCurrZoom=n.tileZoom),n._addViewExtent(),this.addToRender(e))}childrenPrevStateEquals(e){let t=this.nodes;return 4===t.length&&t[0].prevState===e&&t[1].prevState===e&&t[2].prevState===e&&t[3].prevState===e}isFading(){let e=this.nodes;return 2===this.state&&this.segment._transitionOpacity>0&&4===e.length&&1===e[0].state&&1===e[1].state&&1===e[2].state&&1===e[3].state}_collectFadingNodes(){if(this.segment.tileZoom<3)this.segment._transitionOpacity=1;else if(1!==this.prevState){this.segment._transitionOpacity=0,this._fadingNodes=[];let e=window.performance.now();if(this.segment._transitionTimestamp=e,this.parentNode)if(1===this.parentNode.prevState){let t=this.parentNode.parentNode;for(;t;){if(t.isFading()){for(let e=0;e<t.nodes.length;e++)t.nodes[e].segment._transitionOpacity=1,t.nodes[e]._fadingNodes=[];t.segment._transitionOpacity=0;break}t=t.parentNode}this.parentNode.whileTerrainLoading(),this._fadingNodes.push(this.parentNode),this.parentNode.segment._transitionOpacity=2,this.parentNode.segment._transitionTimestamp=e}else if(this.segment.childrenInitialized()&&this.childrenPrevStateEquals(1))for(let t=0;t<this.nodes.length;t++){let i=this.nodes[t];i.whileTerrainLoading(),this._fadingNodes.push(i),i.segment._transitionOpacity=2,i.segment._transitionTimestamp=e,i.prevState=i.state,i.state=0}}}clearNeighbors(){this.neighbors&&(this.neighbors[0]=this.neighbors[1]=this.neighbors[2]=this.neighbors[3]=null,this.neighbors[0]=[],this.neighbors[1]=[],this.neighbors[2]=[],this.neighbors[3]=[])}_refreshTransitionOpacity(){if(0===this._fadingNodes.length)this.segment._transitionOpacity=1;else if(4!==this._fadingNodes.length||this.childrenPrevStateEquals(1)){for(let e=0;e<this._fadingNodes.length;e++)this.segment._transitionOpacity<1&&0===this._fadingNodes[e].segment._transitionOpacity&&(this._fadingNodes[e].segment._transitionOpacity=0,this.segment._transitionOpacity=1);this.segment.increaseTransitionOpacity()}else this.segment._transitionOpacity=1,this._fadingNodes=[]}addToRender(e){this.state=1;let t=this.planet._renderedNodes;this.planet._transitionOpacityEnabled?Ie(t,this,((e,t)=>e.segment.tileZoom-t.segment.tileZoom)):(this.getRenderedNodesNeighbors(t),t.push(this)),this.segment.terrainReady||(this.planet._renderCompleted=!1,this.planet._terrainCompleted=!1);let i=0,s=this.planet._renderedNodesInFrustum;for(;e;)1&e&&s[i].push(this),i++,e>>=1}applyNeighbor(e,t){const i=Gt[t];if(0===this.neighbors[t].length||0===e.neighbors[i].length){const s=this.segment,n=e.segment,r=s.gridSize/(n.gridSize*Math.pow(2,n.tileZoom-s.tileZoom));let o=s.gridSize,a=n.gridSize;r>1?(o=Math.ceil(s.gridSize/r),a=n.gridSize):r<1&&(o=s.gridSize,a=Math.ceil(n.gridSize*r)),this.sideSizeLog2[t]=Math.log2(o),e.sideSizeLog2[i]=Math.log2(a)}this.neighbors[t].push(e),e.neighbors[i].push(this)}getRenderedNodesNeighbors(e){for(let t=e.length-1;t>=0;--t){let i=e[t],s=this.getCommonSide(i);-1!==s&&this.applyNeighbor(i,s)}}getCommonSide(e){const t=this.segment,i=e.segment;if(t.tileZoom===i.tileZoom&&t._tileGroup===i._tileGroup)return t.getNeighborSide(i);{const e=t._extentLonLat,s=i._extentLonLat;let n=e.northEast,r=e.southWest,o=s.northEast,a=s.southWest,l=n.lon,h=n.lat,c=r.lon,d=r.lat,_=o.lon,u=o.lat,g=a.lon,f=a.lat;if(t._tileGroup===i._tileGroup){if(l===g&&(h<=u&&d>=f||h>=u&&d<=f))return 1;if(c===_&&(h<=u&&d>=f||h>=u&&d<=f))return 3;if(h===f&&(c>=g&&l<=_||c<=g&&l>=_))return 0;if(d===u&&(c>=g&&l<=_||c<=g&&l>=_))return 2;if(0===i.tileX&&g===-l&&(h<=u&&d>=f||h>=u&&d<=f))return 1;if(0===t.tileX&&c===-_&&(h<=u&&d>=f||h>=u&&d<=f))return 3}if(0===t._tileGroup&&i._tileGroup===ea&&0===t.tileY&&i.tileY===i.powTileZoom-1&&(c>=g&&l<=_||c<=g&&l>=_))return 0;if(0===t._tileGroup&&i._tileGroup===ta&&t.tileY===t.powTileZoom-1&&0===i.tileY&&(c>=g&&l<=_||c<=g&&l>=_))return 2;if(t._tileGroup===ta&&0===i._tileGroup&&0===t.tileY&&i.tileY===i.powTileZoom-1&&(c>=g&&l<=_||c<=g&&l>=_))return 0;if(t._tileGroup===ea&&0===i._tileGroup&&t.tileY===t.powTileZoom-1&&0===i.tileY&&(c>=g&&l<=_||c<=g&&l>=_))return 2}return-1}whileNormalMapCreating(){const e=this.segment;e.terrainIsLoading||!e.terrainExists||e._inTheQueue||e.planet._normalMapCreator.queue(e);let t=this;for(;t.parentNode&&!t.segment.normalMapReady;)t=t.parentNode;const i=2<<e.tileZoom-t.segment.tileZoom-1;e.normalMapTexture=t.segment.normalMapTexture,e.normalMapTextureBias[0]=e.tileX-t.segment.tileX*i,e.normalMapTextureBias[1]=e.tileY-t.segment.tileY*i,e.normalMapTextureBias[2]=1/i}whileTerrainLoading(e){const t=this.segment;let i=this;if(e&&e.terrainReady)i=e.node;else for(;i.parentNode&&!i.segment.terrainReady;)i=i.parentNode;if(i.segment.terrainReady&&this.appliedTerrainNodeId!==i.nodeId){let e=2<<t.tileZoom-i.segment.tileZoom-1,s=t.tileX-i.segment.tileX*e,n=t.tileY-i.segment.tileY*e;const r=i.segment;let l,h,c,d;this.appliedTerrainNodeId=i.nodeId,this.equalizedSideWithNodeId[0]=this.equalizedSideWithNodeId[1]=this.equalizedSideWithNodeId[2]=this.equalizedSideWithNodeId[3]=this.appliedTerrainNodeId;let _=i.segment.gridSize/e,u=i.segment.fileGridSize/e;if(ma.xmin=o,ma.xmax=a,ma.ymin=o,ma.ymax=a,ma.zmin=o,ma.zmax=a,_>=1){t.gridSize=_;let e=(_+1)*(_+1)*3;l=new Float64Array(e),h=new Float32Array(e),c=new Float32Array(e),r.noDataVertices&&(d=new Uint8Array(e/3)),qe(r.terrainVertices,r.terrainVerticesHigh,r.terrainVerticesLow,r.noDataVertices,r.gridSize,_*n,_*s,_,l,h,c,ma,d)}else if(u>=1&&i.segment.terrainExists){t.gridSize=u;let e=(u+1)*(u+1)*3;l=new Float64Array(e),h=new Float32Array(e),c=new Float32Array(e),r.noDataVertices&&(d=new Uint8Array(e/3)),qe(r.normalMapVertices,r.normalMapVerticesHigh,r.normalMapVerticesLow,r.noDataVertices,i.segment.fileGridSize,u*n,u*s,u,l,h,c,ma,d)}else{t.gridSize=pa;let e,i=Math.floor(_*n),o=Math.floor(_*s);e=1===r.gridSize?r.terrainVertices:je(r.terrainVertices,r.gridSize,i,o,1);let a=1/_,d=n-a*i,u=s-a*o,g=new oe(e[0],e[1],e[2]),f=new oe(e[9],e[10],e[11]),p=new oe(e[3]-e[0],e[4]-e[1],e[5]-e[2]),m=new oe(e[6]-e[0],e[7]-e[1],e[8]-e[2]),v=new oe(e[3]-e[9],e[4]-e[10],e[5]-e[11]),y=new oe(e[6]-e[9],e[7]-e[10],e[8]-e[11]),x=new oe;l=new Float64Array(3*fa.length),h=new Float32Array(3*fa.length),c=new Float32Array(3*fa.length);for(let e=0;e<fa.length;e++){let t=fa[e].y+d,i=fa[e].x+u,s=i*_,n=t*_;x=t+i<a?p.scaleTo(s).addA(m.scaleTo(n)).addA(g):y.scaleTo(1-s).addA(v.scaleTo(1-n)).addA(f),oe.doubleToTwoFloats(x,ua,ga);let r=3*e;l[r]=x.x,l[r+1]=x.y,l[r+2]=x.z,h[r]=ua.x,h[r+1]=ua.y,h[r+2]=ua.z,c[r]=ga.x,c[r+1]=ga.y,c[r+2]=ga.z,x.x<ma.xmin&&(ma.xmin=x.x),x.x>ma.xmax&&(ma.xmax=x.x),x.y<ma.ymin&&(ma.ymin=x.y),x.y>ma.ymax&&(ma.ymax=x.y),x.z<ma.zmin&&(ma.zmin=x.z),x.z>ma.zmax&&(ma.zmax=x.z)}}if(t.readyToEngage=!0,t.terrainVertices=l,t.terrainVerticesHigh=h,t.terrainVerticesLow=c,t.tempVertices=l,t.tempVerticesHigh=h,t.tempVerticesLow=c,t.noDataVertices=d,t.setBoundingVolume(ma.xmin,ma.ymin,ma.zmin,ma.xmax,ma.ymax,ma.zmax),t.tileZoom>t.planet.terrain.maxZoom&&i.segment.tileZoom>=t.planet.terrain.maxZoom&&(t._plainRadius=i.segment._plainRadius/e,t.terrainReady=!0,t.terrainIsLoading=!1,t.terrainVertices=l,t.terrainVerticesHigh=h,t.terrainVerticesLow=c,t.passReady=!0,this.appliedTerrainNodeId=this.nodeId,this.equalizedSideWithNodeId[0]=this.equalizedSideWithNodeId[1]=this.equalizedSideWithNodeId[2]=this.equalizedSideWithNodeId[3]=this.appliedTerrainNodeId,i.segment.terrainExists)){t.normalMapVertices=l,t.fileGridSize=Math.sqrt(l.length/3)-1;let i=Math.sqrt(r.normalMapNormals.length/3)-1,o=i/e;t.normalMapNormals=i>1?We(r.normalMapNormals,i,o*n,o*s,o):r.normalMapNormals}}}destroy(){this.prevState=this.state=0,this.segment.destroySegment();let e=this.neighbors;for(let t=0,i=e.length;t<i;t++){let i=e[t];if(i)for(let e=0;e<i.length;e++){let t=i[e];t&&t.neighbors&&t.clearNeighbors()}}this.neighbors=null,this.parentNode=null,this.sideSizeLog2=null,this.segment=null}clearTree(){const e=this.getState();if(0===e||1===e)this.destroyBranches();else for(let e=0;e<this.nodes.length;e++)this.nodes[e]&&this.nodes[e].clearTree()}clearBranches(){for(let e=0;e<this.nodes.length;e++)this.nodes[e].clearBranches(),this.nodes[e].segment.deleteMaterials()}destroyBranches(){if(this.ready){let e,t=[];for(e=0;e<this.nodes.length;e++)t[e]=this.nodes[e];for(this.ready=!1,this.nodes=[],e=0;e<t.length;e++)t[e].destroyBranches(),t[e].destroy(),t[e]=null;t.length=0,t=null}}traverseTree(e){if(e(this),this.ready)for(let t=0;t<this.nodes.length;t++)this.nodes[t].traverseTree(e)}getOffsetOppositeNeighbourSide(e,t){let i=this,s=e.segment.tileZoom,n=0;for(;i.segment.tileZoom>s;)n+=Wt[i.partId][t]/(1<<i.segment.tileZoom-s),i=i.parentNode;return n}};class xa{constructor(e=2048){this._size=e,this._array=new Array(this._size),this._popIndex=Math.floor(.5*this._size),this._shiftIndex=this._popIndex,this.length=0}reset(){this._popIndex=Math.floor(.5*this._size),this._shiftIndex=this._popIndex,this.length=0}clear(){this._array.length=0,this._array=new Array(this._size),this._popIndex=Math.floor(.5*this._size),this._shiftIndex=this._popIndex,this.length=0}push(e){this.length++,this._array[this._popIndex++]=e}pop(){if(this.length){this.length--;let e=this._array[--this._popIndex];return this._array[this._popIndex]=null,this._array[this._popIndex-1]||(this._popIndex=Math.floor(.5*this._size),this._shiftIndex=this._popIndex),e}}unshift(e){this.length++,this._array[--this._shiftIndex]=e}shift(){if(this.length){this.length--;let e=this._array[this._shiftIndex];return this._array[this._shiftIndex++]=null,this._array[this._shiftIndex]||(this._popIndex=Math.floor(.5*this._size),this._shiftIndex=this._popIndex),e}}forEach(e){for(let t=this._shiftIndex;t<this._popIndex;t++)e(this._array[t])}}class ba{constructor(e,t){this._layer=e,this._nodeCapacity=t,this._secondPASS=[],this._counter=0,this._deferredEntitiesPendingQueue=new xa,this._renderingNodes={}}insertEntity(e,t=!1){}setPickingEnabled(e){}dispose(){}insertEntities(e){}collectVisibleEntityCollections(e){}_queueDeferredNode(e){this._layer.getVisibility()&&(e._inTheQueue=!0,this._counter>=1?this._deferredEntitiesPendingQueue.push(e):this._execDeferredNode(e))}_execDeferredNode(e){this._counter++,requestAnimationFrame((()=>{if(e.applyCollection(),this._counter--,this._deferredEntitiesPendingQueue.length&&this._counter<1)for(;this._deferredEntitiesPendingQueue.length;){let e=this._deferredEntitiesPendingQueue.pop();if(e._inTheQueue=!1,e.isVisible())return void this._execDeferredNode(e)}}))}}class wa{constructor(e,t="",i=Zo){this.name=t,this.projection=i,this._planet=e,this._quadTreeList=[],this._visibleNodes={}}createEntitiCollectionsTreeStrategy(e,t){return new ba(e,t)}destroyBranches(){for(let e=0,t=this._quadTreeList.length;e<t;e++)this._quadTreeList[e].destroyBranches()}clearLayerMaterial(e){let t=e.__id;for(let e=0,i=this._quadTreeList.length;e<i;e++)this._quadTreeList[e].traverseTree((function(e){let i=e.segment.materials;i[t]&&(i[t].clear(),i[t]=null)}))}get planet(){return this._planet}init(){}preRender(){for(let e=0;e<this._quadTreeList.length;e++){let t=this._quadTreeList[e];t.createChildNodes(),t.segment.createPlainSegment();for(let e=0;e<t.nodes.length;e++)t.nodes[e].segment.createPlainSegment()}}preLoad(){for(let e=0;e<this._quadTreeList.length;e++){let t=this._quadTreeList[e];t.segment.passReady=!0,t.renderNode(1),this._planet.normalMapCreator.drawSingle(t.segment);for(let e=0;e<t.nodes.length;e++)t.nodes[e].segment.passReady=!0,t.nodes[e].renderNode(1),this._planet._normalMapCreator.drawSingle(t.nodes[e].segment)}}_clearVisibleNodes(){this._visibleNodes={}}collectRenderNodes(){this._clearVisibleNodes();for(let e=0;e<this._quadTreeList.length;e++)this._quadTreeList[e].renderTree(this._planet.camera,0,null)}clear(){for(let e=0;e<this._quadTreeList.length;e++)this._quadTreeList[e].clearTree()}get quadTreeList(){return this._quadTreeList}getTileXY(e,t){let i=t,s=-1,n=-1,r=1<<i;return s=Qo(e.lon,360/r,-180),n=Qo(e.lat,180/r,90),[s,n,i,0]}getLonLatTileOffset(e,t,i,s,n){let r=e,o=new te;o=Jo(t,i,s,te.createFromArray([-180,-90,180,90]));let a=o.getWidth()/(n-1),l=o.getHeight()/(n-1);return[n-Math.ceil((r.lat-o.southWest.lat)/l)-1,Math.floor((r.lon-o.southWest.lon)/a)]}collectVisibleNode(e){this._visibleNodes[e.nodeId]=e}}const Ca=new Xo({code:"epsg:4326",units:Wo}),Ta=(90-Q)/Math.pow(2,7);class Ea extends _a{constructor(e,t,i,s){super(e,t,i,s),this._projection=Ca,this._extentLonLat=this._extent,this._extentMerc=new te(s.southWest.forwardMercatorEPS01(),s.northEast.forwardMercatorEPS01()),this._isNorth=this._extent.northEast.lat>0,this.isPole=!0}_setExtentLonLat(){this._extentLonLat=this._extent}projectNative(e){return e}getInsideLonLat(e){return e._lonLat}_getMaxZoom(){let e=0;if(this._isNorth){let t=Math.floor((90-this._extent.northEast.lat)/Ta);e=Math.floor(t/16)+7}else{let t=Math.floor((J-this._extent.northEast.lat)/Ta);e=12-Math.floor(t/16)}return e}checkZoom(){return super.checkZoom()&&this.tileZoom<=this._getMaxZoom()}_assignTileIndexes(){this._assignTileXIndexes(this._extent),this._assignTileYIndexes(this._extent),this.tileIndex=$t.getTileIndex(this.tileX,this.tileY,this.tileZoom,this._tileGroup)}_assignTileXIndexes(e){this.tileX=Qo(e.getCenter().lon,e.getWidth(),-180);let t=1<<this.tileZoom;this.tileXE=(this.tileX+1)%t,this.tileXW=(t+this.tileX-1)%t}_assignTileYIndexes(e){const t=e.getCenter().lat;t>0?(this._tileGroup=ea,this.tileY=Qo(t,e.getHeight(),90)):(this._tileGroup=ta,this.tileY=Qo(t,e.getHeight(),J)),this.tileYN=this.tileY-1,this.tileYS=this.tileY+1}_projToDeg(e,t){return new I(e,t)}_assignGlobalTextureCoordinates(){const e=this._extent;this._globalTextureCoordinates[0]=(e.southWest.lon+180)/360,this._globalTextureCoordinates[1]=(90-e.northEast.lat)/180,this._globalTextureCoordinates[2]=(e.northEast.lon+180)/360,this._globalTextureCoordinates[3]=(90-e.southWest.lat)/180}_getLayerExtentOffset(e){const t=e._extent,i=this._extent,s=t.northEast.lon-t.southWest.lon,n=t.northEast.lat-t.southWest.lat;return[(i.southWest.lon-t.southWest.lon)/s,(t.northEast.lat-i.northEast.lat)/n,(i.northEast.lon-i.southWest.lon)/s,(i.northEast.lat-i.southWest.lat)/n]}layerOverlap(e){return this._extent.overlaps(e._extent)}getDefaultTexture(){return this._isNorth?this.planet.solidTextureOne:this.planet.solidTextureTwo}getExtentLonLat(){return this._extent}}class La{constructor(e,t,i,s,n,r){this.strategy=e,this.layer=e._layer,this.parentNode=i,this.childNodes=[],this.partId=t,this.nodeId=t+(i?4*i.nodeId+1:0),this.state=null,this.extent=s,this.count=0,this.deferredEntities=[],this.entityCollection=null,this.zoom=r,this._inTheQueue=!1,this.bsphere=new Pt,n&&this._setExtentBounds()}insertEntity(e,t=!1){this.buildTree([e],t)}_addEntitiesToCollection(e,t=!1){if(e.length){const i=this.layer,s=i._planet;let n=this.entityCollection;n||(n=new fs({pickingEnabled:i._pickingEnabled,labelMaxLetters:i.labelMaxLetters}),n._layer=this.layer,n.addTo(s,!0),n._quadNode=this,i._bindEventsDefault(n),this.entityCollection=n),t||!i.async?this.entityCollection.addEntities(e):this.deferredEntities.push.apply(this.deferredEntities,e)}}_setExtentBounds(){this.nodeId?this.bsphere.setFromExtent(this.layer._planet.ellipsoid,this.extent.inverseMercator()):(this.bsphere.radius=this.layer._planet.ellipsoid.equatorialSize,this.bsphere.center=new oe)}__setLonLat__(e){return e._lonLat.isZero()&&!e._cartesian.isZero()&&(e._lonLat=this.layer._planet.ellipsoid.cartesianToLonLat(e._cartesian)),Math.abs(e._lonLat.lat)<Q?e._lonLatMerc=e._lonLat.forwardMercator():e._lonLatMerc=new I,e._lonLatMerc}buildTree(e,t=!1){if(this.count+=e.length,e.length>this.layer._nodeCapacity){const i=this.childNodes;i.length||this.createChildNodes();let s=[],n=[],r=[],o=[],a=e.length;for(;a--;){const t=e[a];i[0].isInside(t)?(t._nodePtr=i[0],s.push(t)):i[1].isInside(t)?(t._nodePtr=i[1],n.push(t)):i[2].isInside(t)?(t._nodePtr=i[2],r.push(t)):i[3].isInside(t)&&(t._nodePtr=i[3],o.push(t))}s.length&&i[0].buildTree(s,t),n.length&&i[1].buildTree(n,t),r.length&&i[2].buildTree(r,t),o.length&&i[3].buildTree(o,t)}else this._addEntitiesToCollection(e,t)}isInside(e){return!!e._lonLatMerc&&this.extent.isInside(e._lonLatMerc)}createChildNodes(){const e=this.strategy,t=this.extent,i=.5*t.getWidth(),s=.5*t.getHeight(),n=t.northEast,r=t.southWest,o=new I(r.lon+i,r.lat+s),a=this.childNodes,l=this.layer._planet,h=this.zoom+1;a[0]=new La(e,0,this,new te(new I(r.lon,r.lat+s),new I(r.lon+i,n.lat)),l,h),a[1]=new La(e,1,this,new te(o,new I(n.lon,n.lat)),l,h),a[2]=new La(e,2,this,new te(new I(r.lon,r.lat),o),l,h),a[3]=new La(e,3,this,new te(new I(r.lon+i,r.lat),new I(n.lon,r.lat+s)),l,h)}collectRenderCollectionsPASS1(e,t){const i=e[this.nodeId];if(i){const s=this.childNodes;this.entityCollection?this.renderCollection(t,e):s.length&&(1===i.state?this.strategy._secondPASS.push(this):(s[0].collectRenderCollectionsPASS1(e,t),s[1].collectRenderCollectionsPASS1(e,t),s[2].collectRenderCollectionsPASS1(e,t),s[3].collectRenderCollectionsPASS1(e,t)))}}collectRenderCollectionsPASS2(e,t,i){const s=this.layer._planet.camera,n=s.eye.distance(this.bsphere.center)-this.bsphere.radius<3570*Math.sqrt(s._lonLat.height)||s._lonLat.height>1e4;if(this.count>0&&n&&s.containsSphere(this.bsphere)){const s=this.childNodes;this.entityCollection?this.renderCollection(t,e,i):s.length&&(s[0].collectRenderCollectionsPASS2(e,t,i),s[1].collectRenderCollectionsPASS2(e,t,i),s[2].collectRenderCollectionsPASS2(e,t,i),s[3].collectRenderCollectionsPASS2(e,t,i))}}applyCollection(){this.entityCollection.addEntities(this.deferredEntities),this.deferredEntities.length=0,this.deferredEntities=[],this._inTheQueue=!1}traverseTree(e){const t=this.childNodes;this.entityCollection?e(this):t.length&&(t[0].traverseTree(e),t[1].traverseTree(e),t[2].traverseTree(e),t[3].traverseTree(e))}renderCollection(e,t,i){const s=this.strategy;s._renderingNodes[this.nodeId]=!0,this.deferredEntities.length&&!this._inTheQueue&&(this.layer.async?s._queueDeferredNode(this):this.applyCollection());let n=this.entityCollection,r=this.layer;if(n._fadingOpacity=r._fadingOpacity,n.scaleByDistance=r.scaleByDistance,n.pickingScale=r.pickingScale,n.polygonOffsetUnits=r.polygonOffsetUnits,e.push(n),r.clampToGround||r.relativeToGround){const e=n._entities;let s=e.length;if(t[this.nodeId]&&1===t[this.nodeId].state)for(;s--;){let i=e[s];this.alignEntityToTheGround(i,t[this.nodeId].segment)}else if(i)for(;s--;){let n=e[s];this.alignEntityToTheGround(n,t[i].segment)}else{const t=r._planet._renderedNodes;for(;s--;){let i=e[s],n=t.length;for(;n--;)if(t[n].segment.isEntityInside(i)){this.alignEntityToTheGround(i,t[n].segment);break}}}}}alignEntityToTheGround(e,t){let i=new oe;t.getEntityTerrainPoint(e,i);let s=Number(this.layer.relativeToGround)&&e._altitude||0;if(s){let t=this.layer._planet.ellipsoid.getSurfaceNormal3v(i);e._setCartesian3vSilent(i.addA(t.scale(s)))}else e._setCartesian3vSilent(i)}isVisible(){return!!this.strategy._renderingNodes[this.nodeId]}}class Aa extends La{constructor(e,t,i,s,n,r){super(e,t,i,s,n,r),this.strategy=e,this.isNorth=!1}createChildNodes(){const e=this.strategy,t=this.extent,i=.5*t.getWidth(),s=.5*t.getHeight(),n=t.northEast,r=t.southWest,o=new I(r.lon+i,r.lat+s),a=this.childNodes,l=this.layer._planet,h=this.zoom+1;a[0]=new Aa(e,0,this,new te(new I(r.lon,r.lat+s),new I(r.lon+i,n.lat)),l,h),a[1]=new Aa(e,1,this,new te(o,new I(n.lon,n.lat)),l,h),a[2]=new Aa(e,2,this,new te(new I(r.lon,r.lat),o),l,h),a[3]=new Aa(e,3,this,new te(new I(r.lon+i,r.lat),new I(n.lon,r.lat+s)),l,h)}_setExtentBounds(){this.extent.northEast.lat>0&&(this.isNorth=!0),this.bsphere.setFromExtent(this.layer._planet.ellipsoid,this.extent)}__setLonLat__(e){return e._lonLat.isZero()&&(e._lonLat=this.layer._planet.ellipsoid.cartesianToLonLat(e._cartesian)),e._lonLat}isVisible(){return!(!this.isNorth||!this.strategy._renderingNodesNorth[this.nodeId])||!!this.strategy._renderingNodesSouth[this.nodeId]}isInside(e){return this.extent.isInside(e._lonLat)}renderCollection(e,t,i){this.isNorth?this.strategy._renderingNodesNorth[this.nodeId]=!0:this.strategy._renderingNodesSouth[this.nodeId]=!0,this.deferredEntities.length&&!this._inTheQueue&&(this.layer.async?this.strategy._queueDeferredNode(this):this.applyCollection());const s=this.entityCollection;s._fadingOpacity=this.layer._fadingOpacity,s.scaleByDistance=this.layer.scaleByDistance,s.pickingScale=this.layer.pickingScale,s.isEmpty()||e.push(s)}}class Pa extends ba{constructor(e,t){super(e,t);let i=e._planet;this._entityCollectionsTree=new La(this,0,null,te.createFromArray([-20037508.34,-20037508.34,20037508.34,20037508.34]),i,0),this._entityCollectionsTreeNorth=new Aa(this,0,null,te.createFromArray([-180,Q,180,90]),i,0),this._entityCollectionsTreeSouth=new Aa(this,0,null,te.createFromArray([-180,-90,180,J]),i,0),this._renderingNodes={},this._renderingNodesNorth={},this._renderingNodesSouth={}}insertEntity(e,t=!1){e._lonLat.lat>Q?(this._entityCollectionsTreeNorth.__setLonLat__(e),this._entityCollectionsTreeNorth.insertEntity(e,t)):e._lonLat.lat<J?(this._entityCollectionsTreeSouth.__setLonLat__(e),this._entityCollectionsTreeSouth.insertEntity(e,t)):(this._entityCollectionsTree.__setLonLat__(e),this._entityCollectionsTree.insertEntity(e,t))}setPickingEnabled(e){this._entityCollectionsTree&&this._entityCollectionsTree.traverseTree((t=>{t.entityCollection.setPickingEnabled(e)})),this._entityCollectionsTreeNorth&&this._entityCollectionsTreeNorth.traverseTree((t=>{t.entityCollection.setPickingEnabled(e)})),this._entityCollectionsTreeSouth&&this._entityCollectionsTreeSouth.traverseTree((t=>{t.entityCollection.setPickingEnabled(e)}))}dispose(){this._entityCollectionsTree=null,this._entityCollectionsTreeNorth=null,this._entityCollectionsTreeSouth=null,this._renderingNodes={},this._renderingNodesNorth={},this._renderingNodesSouth={}}insertEntities(e){let t=[],i=[],s=[];for(let n=0,r=e.length;n<r;n++){let r=e[n];r._lonLat.lat>Q?(t.push(r),this._entityCollectionsTreeNorth.__setLonLat__(r)):r._lonLat.lat<J?(i.push(r),this._entityCollectionsTreeSouth.__setLonLat__(r)):(s.push(r),this._entityCollectionsTree.__setLonLat__(r))}this._entityCollectionsTree.buildTree(s),this._entityCollectionsTreeNorth.buildTree(t),this._entityCollectionsTreeSouth.buildTree(i)}collectVisibleEntityCollections(e){this._renderingNodes={},this._renderingNodesNorth={},this._renderingNodesSouth={};let t=this._layer._planet.quadTreeStrategy;this._secondPASS=[],this._entityCollectionsTree.collectRenderCollectionsPASS1(t._visibleNodes,e);let i=this._secondPASS.length;for(;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodes,e,this._secondPASS[i].nodeId);for(this._secondPASS=[],this._entityCollectionsTreeNorth.collectRenderCollectionsPASS1(t._visibleNodesNorth,e),i=this._secondPASS.length;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodesNorth,e,this._secondPASS[i].nodeId);for(this._secondPASS=[],this._entityCollectionsTreeSouth.collectRenderCollectionsPASS1(t._visibleNodesSouth,e),i=this._secondPASS.length;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodesSouth,e,this._secondPASS[i].nodeId)}}class Sa extends wa{constructor(e){super(e,"Earth"),this._visibleNodesNorth={},this._visibleNodesSouth={}}collectVisibleNode(e){let t=e.segment._tileGroup;t===ea?this._visibleNodesNorth[e.nodeId]=e:t===ta?this._visibleNodesSouth[e.nodeId]=e:this._visibleNodes[e.nodeId]=e}_clearVisibleNodes(){super._clearVisibleNodes(),this._visibleNodesNorth={},this._visibleNodesSouth={}}createEntitiCollectionsTreeStrategy(e,t){return new Pa(e,t)}init(){this._quadTreeList=[new ya(_a,this.planet,0,null,0,te.createFromArray([-20037508.34,-20037508.34,20037508.34,20037508.34])),new ya(Ea,this.planet,0,null,0,te.createFromArray([-180,Q,180,90])),new ya(Ea,this.planet,0,null,0,te.createFromArray([-180,-90,180,J]))]}getTileXY(e,t){let i=function(e,t=Q){return e>t?ea:e<-t?ta:0}(e.lat,Q),s=t,n=-1,r=-1,o=1<<s;if(i===ea)n=Qo(e.lon,360/o,-180),r=Qo(e.lat,(90-Q)/o,90);else if(i===ta)n=Qo(e.lon,360/o,-180),r=Qo(e.lat,(90-Q)/o,J);else{let t=q(e);n=Qo(t.lon,D/o,-z),r=Qo(t.lat,D/o,z)}return[n,r,s,i]}getLonLatTileOffset(e,t,i,s,n){let r=e,o=new te;if(e.lat>Q){o=Jo(t,i,s,te.createFromArray([-180,Q,180,90]))}else if(e.lat<J){o=Jo(t,i,s,te.createFromArray([-180,-90,180,J]))}else r=q(e),o=K(t,i,s);let a=o.getWidth()/(n-1),l=o.getHeight()/(n-1);return[n-Math.ceil((r.lat-o.southWest.lat)/l)-1,Math.floor((r.lon-o.southWest.lon)/a)]}}class Ma{constructor(e={}){this.model=e.model||null,this.src=e.src||null,this._cached_ix=0,this._cached_iy=0,this._v00=0,this._v01=0,this._v10=0,this._v11=0,this._t=0}static loadModel(e){return e?fetch(e,{}).then((e=>{if(!e.ok)throw Error("Geoid model file: HTTP error "+e.status);return e.arrayBuffer()})).then((t=>{if(t)return new Uint8Array(t);throw Error("Geoid model file: no data from "+e)})).then((function(e){if(80!==e[0]||53!==e[1]||(13!==e[2]||10!==e[3])&&10!==e[2])throw new Error("Geoid model file: no PGM header");var t,i,s=13===e[2]?4:3,n=null,r=null;function o(){let t=s;for(var i=s;;i++){if(i>=e.length)throw new Error("Geoid model file: missing newline in header");if(10===e[i]){s=i+1;break}}return i>t&&13===e[i-1]&&i--,String.fromCharCode.apply(null,e.slice(t,i))}for(;"#"===(i=o())[0];)if(t=i.match(/^# Offset (.*)$/)){if(n=parseInt(t[1],10),!isFinite(n))throw new Error("Geoid model file: bad offset "+t[1])}else if((t=i.match(/^# Scale (.*)$/))&&(r=parseFloat(t[1]),!isFinite(r)))throw new Error("Geoid model file: bad scale "+t[1]);let a=0,l=0;if((t=i.match(/^\s*(\d+)\s+(\d+)\s*$/))&&(a=parseInt(t[1],10),l=parseInt(t[2],10)),!(t&&a>=0&&l>=0))throw new Error("Geoid model file: bad PGM width&height line");if(65535!=parseInt(o()))throw new Error("Geoid model file: PGM file must have 65535 gray levels");if(null===n)throw new Error("Geoid model file: PGM file does not contain offset");if(null===r)throw new Error("Geoid model file: PGM file does not contain scale");if(a<2||l<2)throw new Error("Geoid model file: Raster size too small");if(e.length-s!==a*l*2)throw new Error("Geoid model file: File has the wrong length");return{scale:r,offset:n,width:a,height:l,rlonres:a/360,rlatres:(l-1)/180,i:s,rawfile:e}})):new Promise((e=>{e(null)}))}setModel(e){this.model=e}_rawval(e,t){let i=this.model;t<0?(t=-t,e+=i.width/2):t>=i.height&&(t=2*(i.height-1)-t,e+=i.width/2),e<0?e+=i.width:e>=i.width&&(e-=i.width);let s=2*(t*i.width+e)+i.i;return i.rawfile[s]<<8|i.rawfile[s+1]}getHeightLonLat(e){return this.getHeight(e.lon,e.lat)}getHeight(e,t){if(!this.model)return 0;let i=this.model;e<0&&(e+=360);let s=(90-t)*i.rlatres,n=e*i.rlonres,r=Math.floor(s),o=Math.floor(n);n-=o,s-=r,r===i.height-1&&r--,this._cached_ix===o&&this._cached_iy===r||(this._cached_ix=o,this._cached_iy=r,this._v00=this._rawval(o,r),this._v01=this._rawval(o+1,r),this._v10=this._rawval(o,r+1),this._v11=this._rawval(o+1,r+1));let a=(1-s)*((1-n)*this._v00+n*this._v01)+s*((1-n)*this._v10+n*this._v11);return i.offset+i.scale*a}}class Ra{constructor(e,t=5){this.MAX_FRAMES=t,this._gridSize=64,this._planet=e,this._framebuffer=null,this._framebufferMercProj=null,this._texCoordsBuffer=null,this._indexBuffer=null,this._currentFrame=0,this._queue=[],this._animate=[],this._quadTexCoordsBuffer=null,this._quadVertexBuffer=null}init(){this._initShaders(),this._initBuffers()}createGridBuffer(e,t=!1){let i=this._gridSize,s=new I((e[3].lon-e[0].lon)/i,(e[3].lat-e[0].lat)/i),n=new I((e[2].lon-e[1].lon)/i,(e[2].lat-e[1].lat)/i),r=new I((e[1].lon-e[0].lon)/i,(e[1].lat-e[0].lat)/i),o=new I((e[2].lon-e[3].lon)/i,(e[2].lat-e[3].lat)/i);const a=(i+1)*(i+1)*2,l=a/2;let h=new Float32Array(a),c=new Float32Array(a),d=new Array(l),_=0,u=0,g=0,f=new Float32Array(2);for(let t=0;t<=i;t++){let a=new I(e[0].lon+t*s.lon,e[0].lat+t*s.lat),l=new I(e[1].lon+t*n.lon,e[1].lat+t*n.lat);for(let t=0;t<=i;t++){let i=ze(a,l,new I(e[0].lon+t*r.lon,e[0].lat+t*r.lat),new I(e[3].lon+t*o.lon,e[3].lat+t*o.lat));ms(i.lon,f),h[_++]=f[0],c[u++]=f[1],ms(i.lat,f),h[_++]=f[0],c[u++]=f[1],d[g++]=i}}if(t)for(let e=0;e<l;e++){let t=d[e].forwardMercator();ms(t.lon,f),h[2*e]=f[0],c[2*e]=f[1],ms(t.lat,f),h[2*e+1]=f[0],c[2*e+1]=f[1]}return[this._planet.renderer.handler.createArrayBuffer(h,2,l),this._planet.renderer.handler.createArrayBuffer(c,2,l)]}frame(){let e=this.MAX_FRAMES;for(;e--&&this._queue.length;){const e=this._queue.shift();e._isRendering=!1,e.rendering(),e.events.dispatch(e.events.loadend)}for(e=this._animate.length;e--;)this._animate[e].rendering()}add(e){e._isRendering||(e._isRendering=!0,e._animate?this._animate.push(e):this._queue.push(e))}remove(e){if(e._isRendering){let t;e._creationProceeding=!1,e._isRendering=!1,t=e._animate?this._animate:this._queue;for(let i=0;i<t.length;i++)if(t[i].isEqual(e))return void t.splice(i,1)}}_initBuffers(){let e=this._planet.renderer.handler;this._framebuffer=new Yo(e,{width:2,height:2,useDepth:!1}),this._framebuffer.init(),this._framebufferMercProj=new Yo(e,{width:2,height:2,useDepth:!1}),this._framebufferMercProj.init();let t=Math.log2(this._gridSize);this._texCoordsBuffer=this._planet._textureCoordsBufferCache[t],this._indexBuffer=this._planet._indexesCache[t][t][t][t][t].buffer,this._quadTexCoordsBuffer=e.createArrayBuffer(new Float32Array([0,1,1,1,0,0,1,0]),2,4),this._quadVertexBuffer=e.createArrayBuffer(new Float32Array([-1,1,1,1,-1,-1,1,-1]),2,4)}_initShaders(){this._planet.renderer.handler.addProgram(new Ni("geoImageTransform",{uniforms:{sourceTexture:"sampler2d",extentParamsHigh:"vec4",extentParamsLow:"vec4",isFullExtent:"bool"},attributes:{cornersHigh:"vec2",cornersLow:"vec2",texCoords:"vec2"},vertexShader:"attribute vec2 cornersHigh; \n attribute vec2 cornersLow;\n attribute vec2 texCoords; \n uniform vec4 extentParamsHigh; \n uniform vec4 extentParamsLow; \n varying vec2 v_texCoords;\n void main() { \n v_texCoords = texCoords; \n vec2 highDiff = cornersHigh - extentParamsHigh.xy;\n vec2 lowDiff = cornersLow - extentParamsLow.xy; \n gl_Position = vec4((-1.0 + (highDiff * step(1.0, length(highDiff)) + lowDiff) * extentParamsHigh.zw) * vec2(1.0, -1.0), 0.0, 1.0); \n }",fragmentShader:"precision highp float;\n uniform sampler2D sourceTexture;\n uniform bool isFullExtent;\n varying vec2 v_texCoords;\n void main () {\n if(!isFullExtent && (v_texCoords.x <= 0.001 || v_texCoords.x >= 0.999 ||\n v_texCoords.y <= 0.001 || v_texCoords.y >= 0.999)) {\n discard;\n }\n gl_FragColor = texture2D(sourceTexture, v_texCoords);\n }"}))}}const Ba=["loadend","layerloadend"];class ka{constructor(e=24){this.MAX_REQUESTS=e,this.events=Mt(Ba),this._loading=0,this._queue=[],this._senderRequestCounter=[],this._promises={json:e=>e.json(),blob:e=>e.blob(),arrayBuffer:e=>e.arrayBuffer(),imageBitmap:e=>e.blob().then((e=>createImageBitmap(e,{premultiplyAlpha:"premultiply"}))),text:e=>e.text()}}load(e,t){e.sender&&(this._senderRequestCounter[e.sender.__id]||(this._senderRequestCounter[e.sender.__id]={sender:e.sender,counter:0,__requestCounterFrame__:0}),this._senderRequestCounter[e.sender.__id].counter++),this._queue.push({params:e,callback:t}),this._exec()}fetch(e){return fetch(e.src,e.options||{}).then((t=>{if(!t.ok)throw Error(`Unable to load '${e.src}'`);return this._promises[e.type||"blob"](t)})).then((e=>({status:"ready",data:e}))).catch((e=>({status:"error",msg:e.toString()})))}getRequestCounter(e){if(e){let t=this._senderRequestCounter[e.__id];if(t)return t.counter}return 0}isIdle(e){return e.isIdle}_checkLoadend(e,t){0!==e.counter||t._planet&&!t._planet._terrainCompletedActivated?e.__requestCounterFrame__=requestAnimationFrame((()=>{this._checkLoadend(e,t)})):(t.events.dispatch(t.events.loadend,t),this.events.dispatch(this.events.layerloadend,t),e.__requestCounterFrame__=0)}_handleResponse(e,t){e.callback(t);let i=e.params.sender;if(i&&(i.events.loadend.handlers.length||this.events.layerloadend.handlers.length)){let e=this._senderRequestCounter[i.__id];e&&e.counter>0&&(e.counter--,cancelAnimationFrame(e.__requestCounterFrame__),e.__requestCounterFrame__=requestAnimationFrame((()=>{this._checkLoadend(e,i)})))}this._exec()}_exec(){if(this._queue.length>0&&this._loading<this.MAX_REQUESTS){let e=this._queue.pop();if(!e)return;let t=e.params;if(!t.filter||t.filter(t))return this._loading++,fetch(t.src,t.options||{}).then((e=>{if(!e.ok)throw Error(`Unable to load '${t.src}'`);return this._promises[t.type||"blob"](e)})).then((t=>{this._loading--,this._handleResponse(e,{status:"ready",data:t})})).catch((t=>{this._loading--,this._handleResponse(e,{status:"error",msg:t.toString()})}));this._handleResponse(e,{status:"abort"})}else 0===this._loading&&this.events.dispatch(this.events.loadend)}abort(e){this._senderRequestCounter[e.__id]&&(this._senderRequestCounter[e.__id].counter=0,cancelAnimationFrame(this._senderRequestCounter[e.__id].__requestCounterFrame__),this._senderRequestCounter[e.__id].__requestCounterFrame__=0);for(let t=0,i=this._queue.length;t<i;t++){let i=this._queue[t];i&&i.params.sender&&e.isEqual(i.params.sender)&&(i.callback({status:"abort"}),this._queue[t]=null)}}abortAll(){for(let e=0,t=this._queue.length;e<t;e++){let t=this._queue[e];if(t){let i=t.params.sender;i&&this._senderRequestCounter[i.__id]&&(this._senderRequestCounter[i.__id].counter=0,cancelAnimationFrame(this._senderRequestCounter[i.__id].__requestCounterFrame__),this._senderRequestCounter[i.__id].__requestCounterFrame__=0),t.callback({status:"abort"}),this._queue[e]=null}}this._queue=[]}get loading(){return this._loading}get queue(){return this._queue}}class Ia{constructor(e,t={}){this._minTabelSize=t.minTableSize||1,this._maxTableSize=t.maxTableSize||8,this._planet=e,this._handler=null,this._verticesBufferArray=[],this._indexBufferArray=[],this._positionBuffer=null,this._framebuffer=null,this._normalMapVerticesTexture=null,this._width=t.width||128,this._height=t.height||128,this._queue=new xa(1024),this._lock=new Rn}get width(){return this._width}get height(){return this._height}init(){this._maxTableSize=this._planet.maxGridSize||8,this._handler=this._planet.renderer.handler;const e=new Ni("normalMapBlur",{attributes:{a_position:"vec2"},uniforms:{s_texture:"sampler2d"},vertexShader:`attribute vec2 a_position;\n attribute vec2 a_texCoord;\n\n varying vec2 blurCoordinates[5];\n\n void main() {\n vec2 vt = a_position * 0.5 + 0.5; \n \n gl_Position = vec4(a_position, 0.0, 1.0);\n blurCoordinates[0] = vt;\n blurCoordinates[1] = vt + ${1/this._width*1.407333};\n blurCoordinates[2] = vt - ${1/this._height*1.407333};\n blurCoordinates[3] = vt + ${1/this._width*3.294215};\n blurCoordinates[4] = vt - ${1/this._height*3.294215};\n }`,fragmentShader:"precision lowp float;\n uniform sampler2D s_texture; \n varying vec2 blurCoordinates[5]; \n\n void main() {\n lowp vec4 sum = vec4(0.0);\n //if(blurCoordinates[0].x <= 0.01 || blurCoordinates[0].x >= 0.99 ||\n // blurCoordinates[0].y <= 0.01 || blurCoordinates[0].y >= 0.99){\n // sum = texture2D(s_texture, blurCoordinates[0]);\n //} else {\n sum += texture2D(s_texture, blurCoordinates[0]) * 0.204164;\n sum += texture2D(s_texture, blurCoordinates[1]) * 0.304005;\n sum += texture2D(s_texture, blurCoordinates[2]) * 0.304005;\n sum += texture2D(s_texture, blurCoordinates[3]) * 0.093913;\n sum += texture2D(s_texture, blurCoordinates[4]) * 0.093913;\n //}\n gl_FragColor = sum;\n }"}),t=new Ni("normalMap",{attributes:{a_position:"vec2",a_normal:"vec3"},uniforms:{},vertexShader:"attribute vec2 a_position;\n attribute vec3 a_normal;\n \n varying vec3 v_color;\n \n void main() {\n gl_Position = vec4(a_position, 0, 1);\n v_color = normalize(a_normal) * 0.5 + 0.5;\n }",fragmentShader:"precision highp float;\n \n varying vec3 v_color;\n \n void main () {\n gl_FragColor = vec4(v_color, 1.0);\n }"});this._handler.addProgram(e),this._handler.addProgram(t),this._framebuffer=new Yo(this._handler,{width:this._width,height:this._height,useDepth:!1}),this._framebuffer.init(),this._normalMapVerticesTexture=this._handler.createEmptyTexture_l(this._width,this._height);for(let e=this._minTabelSize;e<=this._maxTableSize;e++){const t=1<<e,i=t/2;let s=new Float32Array((t+1)*(t+1)*2);for(let e=0;e<=t;e++)for(let n=0;n<=t;n++){let r=2*(e*(t+1)+n);s[r]=n/i-1,s[r+1]=e/i-1}this._verticesBufferArray[t]=this._handler.createArrayBuffer(s,2,s.length/2),this._indexBufferArray[t]=this._planet._indexesCache[Math.log2(t)][Math.log2(t)][Math.log2(t)][Math.log2(t)][Math.log2(t)].buffer}const i=new Float32Array([-1,-1,1,-1,-1,1,1,1]);this._positionBuffer=this._handler.createArrayBuffer(i,2,i.length/2)}_drawNormalMapBlur(e){let t=e.normalMapNormals;if(e.node&&0!==e.node.getState()&&t&&t.length){const i=t.length/3,s=Math.sqrt(i)-1;let n=this._verticesBufferArray[s];if(n){e.planet.terrain.equalizeNormals&&(e._normalMapEdgeEqualize(0),e._normalMapEdgeEqualize(2),e._normalMapEdgeEqualize(3),e._normalMapEdgeEqualize(1));let r=e.normalMapTexturePtr;const o=this._handler,a=o.gl;let l=o.createArrayBuffer(t,3,i,a.DYNAMIC_DRAW);const h=this._framebuffer;let c=o.programs.normalMap,d=c._program.attributes;return h.bindOutputTexture(this._normalMapVerticesTexture),c.activate(),a.bindBuffer(a.ARRAY_BUFFER,n),a.vertexAttribPointer(d.a_position,n.itemSize,a.FLOAT,!1,0,0),a.bindBuffer(a.ARRAY_BUFFER,l),a.vertexAttribPointer(d.a_normal,l.itemSize,a.FLOAT,!1,0,0),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this._indexBufferArray[s]),a.drawElements(a.TRIANGLE_STRIP,this._indexBufferArray[s].numItems,a.UNSIGNED_INT,0),a.deleteBuffer(l),h.bindOutputTexture(r),c=o.programs.normalMapBlur,c.activate(),a.bindBuffer(a.ARRAY_BUFFER,this._positionBuffer),a.vertexAttribPointer(c._program.attributes.a_position,this._positionBuffer.itemSize,a.FLOAT,!1,0,0),a.activeTexture(a.TEXTURE0),a.bindTexture(a.TEXTURE_2D,this._normalMapVerticesTexture),a.uniform1i(c._program.uniforms.s_texture,0),a.drawArrays(a.TRIANGLE_STRIP,0,this._positionBuffer.numItems),!0}return!0}return!1}_drawNormalMapNoBlur(e){let t=e.normalMapNormals;if(e.node&&0!==e.node.getState()&&t&&t.length){const i=t.length/3,s=Math.sqrt(i)-1;let n=this._verticesBufferArray[s];if(n){e.planet.terrain.equalizeNormals&&(e._normalMapEdgeEqualize(0),e._normalMapEdgeEqualize(2),e._normalMapEdgeEqualize(3),e._normalMapEdgeEqualize(1));let r=e.normalMapTexturePtr;const o=this._handler,a=o.gl;let l=o.createArrayBuffer(t,3,i,a.DYNAMIC_DRAW);const h=this._framebuffer,c=o.programs.normalMap,d=c._program.attributes;return h.bindOutputTexture(r),c.activate(),a.bindBuffer(a.ARRAY_BUFFER,n),a.vertexAttribPointer(d.a_position,n.itemSize,a.FLOAT,!1,0,0),a.bindBuffer(a.ARRAY_BUFFER,l),a.vertexAttribPointer(d.a_normal,l.itemSize,a.FLOAT,!1,0,0),a.bindBuffer(a.ELEMENT_ARRAY_BUFFER,this._indexBufferArray[s]),a.drawElements(a.TRIANGLE_STRIP,this._indexBufferArray[s].numItems,a.UNSIGNED_INT,0),a.deleteBuffer(l),!0}return!0}return!1}_drawNormalMap(e){return e.planet.terrain.isBlur(e)?this._drawNormalMapBlur(e):this._drawNormalMapNoBlur(e)}drawSingle(e){const t=this._handler.gl;this._framebuffer.activate(),t.disable(t.CULL_FACE),t.disable(t.DEPTH_TEST),t.disable(t.BLEND),e.terrainReady&&this._drawNormalMap(e)&&(e.normalMapReady=!0,e.normalMapTexture=e.normalMapTexturePtr,e.normalMapTextureBias[0]=0,e.normalMapTextureBias[1]=0,e.normalMapTextureBias[2]=1),e._inTheQueue=!1,t.enable(t.DEPTH_TEST),t.enable(t.CULL_FACE),t.enable(t.BLEND),this._framebuffer.deactivate()}frame(){if(this._queue.length){const e=this._handler.gl;this._framebuffer.activate(),e.disable(e.CULL_FACE),e.disable(e.DEPTH_TEST),e.disable(e.BLEND);let t=0,i=window.performance.now();for(;this._lock.isFree()&&this._queue.length&&t<.25;){const e=this._queue.shift();e.terrainReady&&this._drawNormalMap(e)&&(e.normalMapReady=!0,e.normalMapTexture=e.normalMapTexturePtr,e.normalMapTextureBias[0]=0,e.normalMapTextureBias[1]=0,e.normalMapTextureBias[2]=1),e._inTheQueue=!1,t=window.performance.now()-i}e.enable(e.BLEND),e.enable(e.DEPTH_TEST),e.enable(e.CULL_FACE),this._framebuffer.deactivate()}}get queueSize(){return this._queue.length}queue(e){e._inTheQueue=!0,this._queue.push(e)}unshift(e){e._inTheQueue=!0,this._queue.unshift(e)}remove(e){}clear(){for(;this._queue.length;){this._queue.pop()._inTheQueue=!1}}lock(e){this._lock.lock(e)}free(e){this._lock.free(e)}}const za=new Xo({code:"equi",units:Wo});class Da extends ei{constructor(e=2){super(e,Fa)}_onMessage(e){this._source.get(e.data.id)._plainSegmentWorkerCallback(e.data),e.data.plainVertices=null,e.data.plainVerticesHigh=null,e.data.plainVerticesLow=null,e.data.plainNormals=null,e.data.normalMapNormals=null,e.data.normalMapVertices=null,e.data.normalMapVerticesHigh=null,e.data.normalMapVerticesLow=null,this._source.delete(e.data.id)}setGeoid(e){if(e.model){let t=e.model,i={scale:t.scale,offset:t.offset,width:t.width,height:t.height,rlonres:t.rlonres,rlatres:t.rlatres,i:t.i};this._workerQueue.forEach((e=>{let s=new Uint8Array(t.rawfile.length);s.set(t.rawfile),e.postMessage({model:i,rawfile:s},[s.buffer])}))}else this._workerQueue.forEach((e=>{e.postMessage({model:null})}))}make(e){if(e.initialized)if(this._workerQueue.length){let t=this._workerQueue.pop();this._source.set(this._sourceId,e);let i=e._projection.id===Ca.id||e._projection.id===za.id?1:0,s=new Float64Array([this._sourceId,i,e.planet.terrain.gridSizeByZoom[e.tileZoom],e.planet.terrain.plainGridSize,e._extent.southWest.lon,e._extent.southWest.lat,e._extent.northEast.lon,e._extent.northEast.lat,e.planet.ellipsoid._e2,e.planet.ellipsoid.equatorialSize,e.planet.ellipsoid._invRadii2.x,e.planet.ellipsoid._invRadii2.y,e.planet.ellipsoid._invRadii2.z,e.planet._heightFactor]);this._sourceId++,t.postMessage({params:s},[s.buffer])}else this._pendingQueue.push(e);else this.check()}}const Fa="\n 'use strict';\n \n let model = null;\n\n let cached_ix = null;\n let cached_iy = null;\n let v00 = null;\n let v01 = null;\n let v10 = null;\n let v11 = null;\n let t = null;\n\n function rawval(ix, iy) {\n\n if (iy < 0) {\n iy = -iy;\n ix += model.width / 2;\n } else if (iy >= model.height) {\n iy = 2 * (model.height - 1) - iy;\n ix += model.width / 2;\n }\n\n if (ix < 0) {\n ix += model.width;\n } else if (ix >= model.width) {\n ix -= model.width;\n }\n\n var k = (iy * model.width + ix) * 2 + model.i;\n\n return (model.rawfile[k] << 8) | model.rawfile[k + 1];\n };\n\n function getHeightMSL(lon, lat) {\n\n if (!model) return 0;\n\n if (lon < 0) lon += 360.0;\n\n var fy = (90 - lat) * model.rlatres;\n var fx = lon * model.rlonres;\n var iy = Math.floor(fy);\n var ix = Math.floor(fx);\n\n fx -= ix;\n fy -= iy;\n\n if (iy === (model.height - 1)) {\n iy--;\n }\n\n if ((cached_ix !== ix) || (cached_iy !== iy)) {\n\n cached_ix = ix;\n cached_iy = iy;\n\n v00 = rawval(ix, iy);\n v01 = rawval(ix + 1, iy);\n v10 = rawval(ix, iy + 1);\n v11 = rawval(ix + 1, iy + 1);\n }\n\n let h = null;\n\n var a = (1 - fx) * v00 + fx * v01;\n var b = (1 - fx) * v10 + fx * v11;\n\n h = (1 - fy) * a + fy * b;\n\n return model.offset + model.scale * h;\n };\n\n const HALF_PI = Math.PI * 0.5;\n const POLE = 20037508.34;\n const PI_BY_POLE = Math.PI / POLE;\n const INV_POLE_BY_180 = 180.0 / POLE;\n const INV_PI_BY_180 = 180.0 / Math.PI;\n const INV_PI_BY_180_HALF_PI = INV_PI_BY_180 * HALF_PI;\n const RADIANS = Math.PI / 180.0;\n const INV_PI_BY_360 = INV_PI_BY_180 * 2.0;\n\n let E2 = 0.0,\n A = 0.0;\n\n let _projFunc = null;\n\n const Vec3 = function (x, y, z) {\n this.x = x;\n this.y = y;\n this.z = z;\n };\n\n var geodeticToCartesian = function (lon, lat, heightFactor, res) {\n\n let h = getHeightMSL(lon, lat) * heightFactor;\n\n let latrad = RADIANS * lat,\n lonrad = RADIANS * lon;\n\n let slt = Math.sin(latrad);\n\n let N = A / Math.sqrt(1.0 - E2 * slt * slt);\n let nc = (N + h) * Math.cos(latrad); \n \n res.x = nc * Math.cos(lonrad);\n res.y = nc * Math.sin(lonrad);\n res.z = (N * (1 - E2) + h) * slt;\n };\n\n var geodeticToCartesianInverse = function (lon, lat, heightFactor, res){\n geodeticToCartesian(\n lon * INV_POLE_BY_180,\n INV_PI_BY_360 * Math.atan(Math.exp(lat * PI_BY_POLE)) - INV_PI_BY_180_HALF_PI,\n heightFactor,\n res);\n };\n\n var v = new Vec3(0.0, 0.0, 0.0);\n var _tempHigh = new Vec3(0.0, 0.0, 0.0);\n var _tempLow = new Vec3(0.0, 0.0, 0.0);\n\n var doubleToTwoFloats = function(v, high, low) {\n\n let x = v.x, y = v.y, z = v.z;\n \n if (x >= 0.0) {\n var doubleHigh = Math.floor(x / 65536.0) * 65536.0;\n high.x = Math.fround(doubleHigh);\n low.x = Math.fround(x - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-x / 65536.0) * 65536.0;\n high.x = Math.fround(-doubleHigh);\n low.x = Math.fround(x + doubleHigh);\n }\n\n if (y >= 0.0) {\n var doubleHigh = Math.floor(y / 65536.0) * 65536.0;\n high.y = Math.fround(doubleHigh);\n low.y = Math.fround(y - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-y / 65536.0) * 65536.0;\n high.y = Math.fround(-doubleHigh);\n low.y = Math.fround(y + doubleHigh);\n }\n\n if (z >= 0.0) {\n var doubleHigh = Math.floor(z / 65536.0) * 65536.0;\n high.z = Math.fround(doubleHigh);\n low.z = Math.fround(z - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-z / 65536.0) * 65536.0;\n high.z = Math.fround(-doubleHigh);\n low.z = Math.fround(z + doubleHigh);\n }\n };\n\n self.onmessage = function (msg) {\n if(msg.data.model) {\n model = msg.data.model;\n model.rawfile = msg.data.rawfile;\n } else if(msg.data.params) {\n\n let xmin = 549755748352.0, xmax = -549755748352.0, \n ymin = 549755748352.0, ymax = -549755748352.0, \n zmin = 549755748352.0, zmax = -549755748352.0;\n\n E2 = msg.data.params[8];\n A = msg.data.params[9];\n\n let gridSize = msg.data.params[2],\n fgs = msg.data.params[3],\n r2_x = msg.data.params[10],\n r2_y = msg.data.params[11],\n r2_z = msg.data.params[12];\n\n let heightFactor = msg.data.params[13];\n \n if(msg.data.params[1] === 0.0){\n _projFunc = geodeticToCartesianInverse;\n }else{\n _projFunc = geodeticToCartesian;\n }\n\n let maxFgs = Math.max(fgs, gridSize);\n let llStep = (msg.data.params[6] - msg.data.params[4]) / maxFgs;\n let ltStep = (msg.data.params[7] - msg.data.params[5]) / maxFgs;\n\n let esw_lon = msg.data.params[4],\n ene_lat = msg.data.params[7];\n\n let dg = Math.max(fgs / gridSize, 1.0),\n gs = maxFgs + 1;\n \n const gsgs = gs * gs;\n\n const gridSize3 = (gridSize + 1) * (gridSize + 1) * 3;\n\n let plainNormals = new Float32Array(gridSize3);\n\n let plainVertices = new Float64Array(gridSize3);\n let plainVerticesHigh = new Float32Array(gridSize3);\n let plainVerticesLow = new Float32Array(gridSize3);\n\n let normalMapNormals = new Float32Array(gsgs * 3);\n\n let normalMapVertices = new Float64Array(gsgs * 3);\n let normalMapVerticesHigh = new Float32Array(gsgs * 3);\n let normalMapVerticesLow = new Float32Array(gsgs * 3);\n\n let ind = 0,\n nmInd = 0;\n\n for (let k = 0; k < gsgs; k++) {\n\n let j = k % gs,\n i = ~~(k / gs);\n\n _projFunc(esw_lon + j * llStep, ene_lat - i * ltStep, heightFactor, v);\n\n let nx = v.x * r2_x, ny = v.y * r2_y, nz = v.z * r2_z;\n let l = 1.0 / Math.sqrt(nx * nx + ny * ny + nz * nz); \n let nxl = nx * l,\n nyl = ny * l,\n nzl = nz * l;\n\n doubleToTwoFloats(v, _tempHigh, _tempLow);\n\n normalMapVertices[nmInd] = v.x;\n normalMapVerticesHigh[nmInd] = _tempHigh.x;\n normalMapVerticesLow[nmInd] = _tempLow.x;\n normalMapNormals[nmInd++] = nxl;\n\n normalMapVertices[nmInd] = v.y;\n normalMapVerticesHigh[nmInd] = _tempHigh.y;\n normalMapVerticesLow[nmInd] = _tempLow.y;\n normalMapNormals[nmInd++] = nyl;\n\n normalMapVertices[nmInd] = v.z;\n normalMapVerticesHigh[nmInd] = _tempHigh.z;\n normalMapVerticesLow[nmInd] = _tempLow.z;\n normalMapNormals[nmInd++] = nzl;\n\n if (i % dg === 0 && j % dg === 0) {\n plainVertices[ind] = v.x;\n plainVerticesHigh[ind] = _tempHigh.x;\n plainVerticesLow[ind] = _tempLow.x;\n plainNormals[ind++] = nxl;\n\n plainVertices[ind] = v.y;\n plainVerticesHigh[ind] = _tempHigh.y;\n plainVerticesLow[ind] = _tempLow.y;\n plainNormals[ind++] = nyl;\n\n plainVertices[ind] = v.z;\n plainVerticesHigh[ind] = _tempHigh.z;\n plainVerticesLow[ind] = _tempLow.z;\n plainNormals[ind++] = nzl;\n\n if (v.x < xmin) xmin = v.x; if (v.x > xmax) xmax = v.x;\n if (v.y < ymin) ymin = v.y; if (v.y > ymax) ymax = v.y;\n if (v.z < zmin) zmin = v.z; if (v.z > zmax) zmax = v.z;\n }\n }\n\n let x = (xmax - xmin) * 0.5,\n y = (ymax - ymin) * 0.5,\n z = (zmax - zmin) * 0.5;\n\n let plainRadius = Math.sqrt(x * x + y * y + z * z);\n\n self.postMessage({\n id: msg.data.params[0],\n plainVertices: plainVertices,\n plainVerticesHigh: plainVerticesHigh,\n plainVerticesLow: plainVerticesLow,\n plainNormals: plainNormals,\n normalMapNormals: normalMapNormals,\n normalMapVertices: normalMapVertices,\n normalMapVerticesHigh: normalMapVerticesHigh,\n normalMapVerticesLow: normalMapVerticesLow,\n plainRadius: plainRadius\n }, [\n plainVertices.buffer,\n plainVerticesHigh.buffer,\n plainVerticesLow.buffer,\n plainNormals.buffer,\n normalMapNormals.buffer,\n normalMapVertices.buffer,\n normalMapVerticesHigh.buffer,\n normalMapVerticesLow.buffer\n ]);\n }\n }";function Na(e){let t=1/Math.sqrt(e[0]*e[0]+e[1]*e[1]+e[2]*e[2]);e[0]*=t,e[1]*=t,e[2]*=t,e[3]*=t}class Ha{constructor(e={}){this._pickingColorU=new Float32Array([0,0,0]),this._f=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]],this.projectionMatrix=new ne,this.inverseProjectionMatrix=new ne,this.projectionViewMatrix=new ne,this.projectionViewRTEMatrix=new ne,this.inverseProjectionViewMatrix=new ne,this.left=0,this.right=0,this.bottom=0,this.top=0,this.near=0,this.far=0,this.cameraFrustumIndex=null!=e.cameraFrustumIndex?e.cameraFrustumIndex:-1,this.setProjectionMatrix(e.fov||30,e.aspect||1,e.near||1,e.far||1e3)}getRightPlane(){return this._f[0]}getLeftPlane(){return this._f[1]}getBottomPlane(){return this._f[2]}getTopPlane(){return this._f[3]}getBackwardPlane(){return this._f[4]}getForwardPlane(){return this._f[5]}getProjectionViewMatrix(){return this.projectionViewMatrix._m}getProjectionViewRTEMatrix(){return this.projectionViewRTEMatrix._m}getProjectionMatrix(){return this.projectionMatrix._m}getInverseProjectionMatrix(){return this.inverseProjectionMatrix._m}setProjectionMatrix(e,t,i,s){this.top=i*Math.tan(e*d),this.bottom=-this.top,this.right=this.top*t,this.left=-this.right,this.near=i,this.far=s,this.projectionMatrix.setPerspective(this.left,this.right,this.bottom,this.top,i,s),this.projectionMatrix.inverseTo(this.inverseProjectionMatrix)}setProjectionViewRTEMatrix(e){this.projectionViewRTEMatrix=this.projectionMatrix.mul(e)}setViewMatrix(e){this.projectionViewMatrix=this.projectionMatrix.mul(e),this.projectionViewMatrix.inverseTo(this.inverseProjectionViewMatrix);let t=this.projectionViewMatrix._m;this._f[0][0]=t[3]-t[0],this._f[0][1]=t[7]-t[4],this._f[0][2]=t[11]-t[8],this._f[0][3]=t[15]-t[12],Na(this._f[0]),this._f[1][0]=t[3]+t[0],this._f[1][1]=t[7]+t[4],this._f[1][2]=t[11]+t[8],this._f[1][3]=t[15]+t[12],Na(this._f[1]),this._f[2][0]=t[3]+t[1],this._f[2][1]=t[7]+t[5],this._f[2][2]=t[11]+t[9],this._f[2][3]=t[15]+t[13],Na(this._f[2]),this._f[3][0]=t[3]-t[1],this._f[3][1]=t[7]-t[5],this._f[3][2]=t[11]-t[9],this._f[3][3]=t[15]-t[13],Na(this._f[3]),this._f[4][0]=t[3]-t[2],this._f[4][1]=t[7]-t[6],this._f[4][2]=t[11]-t[10],this._f[4][3]=t[15]-t[14],Na(this._f[4]),this._f[5][0]=t[3]+t[2],this._f[5][1]=t[7]+t[6],this._f[5][2]=t[11]+t[10],this._f[5][3]=t[15]+t[14],Na(this._f[5])}containsPoint(e){for(let t=0;t<6;t++){if(e.dotArr(this._f[t])+this._f[t][3]<=0)return!1}return!0}containsSphereBottomExc(e){let t=-e.radius,i=this._f;return!(e.center.dotArr(i[0])+i[0][3]<=t)&&(!(e.center.dotArr(i[1])+i[1][3]<=t)&&(!(e.center.dotArr(i[3])+i[3][3]<=t)&&(!(e.center.dotArr(i[4])+i[4][3]<=t)&&!(e.center.dotArr(i[5])+i[5][3]<=t))))}containsSphereButtom(e){let t=-e.radius,i=this._f;return!(e.center.dotArr(i[2])+i[2][3]<=t)}containsSphere(e){let t=-e.radius,i=this._f;return!(e.center.dotArr(i[0])+i[0][3]<=t)&&(!(e.center.dotArr(i[1])+i[1][3]<=t)&&(!(e.center.dotArr(i[2])+i[2][3]<=t)&&(!(e.center.dotArr(i[3])+i[3][3]<=t)&&(!(e.center.dotArr(i[4])+i[4][3]<=t)&&!(e.center.dotArr(i[5])+i[5][3]<=t)))))}containsSphere2(e,t){let i=-t;return!(e.dotArr(this._f[0])+this._f[0][3]<=i)&&(!(e.dotArr(this._f[1])+this._f[1][3]<=i)&&(!(e.dotArr(this._f[2])+this._f[2][3]<=i)&&(!(e.dotArr(this._f[3])+this._f[3][3]<=i)&&(!(e.dotArr(this._f[4])+this._f[4][3]<=i)&&!(e.dotArr(this._f[5])+this._f[5][3]<=i)))))}containsBox(e){let t,i,s=!0;for(let n=0;n<6;n++){t=0,i=0;for(let s=0;s<8&&(0===i||0===t);s++){e.vertices[s].dotArr(this._f[n])+this._f[n][3]<0?t++:i++}if(0===i)return!1;t>0&&(s=!0)}return s}}const Oa=["viewchange","moveend"];class Va{constructor(e,t={}){if(this.renderer=e,this.events=Mt(Oa,this),this.eye=t.eye||new oe,this.eyeHigh=new Float32Array(3),this.eyeLow=new Float32Array(3),this._aspect=t.aspect||1,this._viewAngle=t.viewAngle||47,this._viewMatrix=new ne,this._viewMatrixRTE=new ne,this._normalMatrix=new ie,this._r=new oe(1,0,0),this._u=new oe(0,1,0),this._b=new oe(0,0,1),this._f=this._b.negateTo(),this._pr=this._r.clone(),this._pu=this._u.clone(),this._pb=this._b.clone(),this._peye=this.eye.clone(),this.isMoving=!1,this._tanViewAngle_hrad=0,this._tanViewAngle_hradOneByHeight=0,this.frustums=[],this.frustumColors=[],t.frustums)for(let e=0,i=t.frustums.length;e<i;e++){let i=t.frustums[e],s=new Ha({fov:this._viewAngle,aspect:this._aspect,near:i[0],far:i[1]});s.cameraFrustumIndex=this.frustums.length,this.frustums.push(s),this.frustumColors.push(s._pickingColorU[0],s._pickingColorU[1],s._pickingColorU[2])}else{let e=.1,t=1e3,i=new Ha({fov:this._viewAngle,aspect:this._aspect,near:e,far:t});i.cameraFrustumIndex=this.frustums.length,this.frustums.push(i),this.frustumColors.push(i._pickingColorU[0],i._pickingColorU[1],i._pickingColorU[2])}this.FARTHEST_FRUSTUM_INDEX=this.frustums.length-1,this.currentFrustumIndex=0,this.frustumColorIndex=0,this.isFirstPass=!1,this._projSizeConst=0,this.set(t.eye||new oe(0,0,1),t.look||new oe,t.up||new oe(0,1,0))}checkMoveEnd(){let e=this._r,t=this._u,i=this._b,s=this.eye;this._peye.equal(s)&&this._pr.equal(e)&&this._pu.equal(t)&&this._pb.equal(i)?(this.isMoving&&this.events.dispatch(this.events.moveend,this),this.isMoving=!1):this.isMoving=!0,this._pr.copy(e),this._pu.copy(t),this._pb.copy(i),this._peye.copy(s)}bindRenderer(e){this.renderer=e;for(let e=0;e<this.frustums.length;e++)this.renderer.assignPickingColor(this.frustums[e]);this._aspect=this.renderer.handler.getClientAspect(),this._setProj(this._viewAngle,this._aspect)}_init(e){this._setProj(this._viewAngle,this._aspect),this.set(e.eye||new oe(0,0,1),e.look||new oe,e.up||new oe(0,1,0))}getUp(){return this._u.clone()}getDown(){return this._u.negateTo()}getRight(){return this._r.clone()}getLeft(){return this._r.negateTo()}getForward(){return this._f.clone()}getBackward(){return this._b.clone()}update(){let e=this._r,t=this._u,i=this._b,s=this.eye;oe.doubleToTwoFloat32Array(s,this.eyeHigh,this.eyeLow),this._viewMatrix.set([e.x,t.x,i.x,0,e.y,t.y,i.y,0,e.z,t.z,i.z,0,-s.dot(e),-s.dot(t),-s.dot(i),1]),this._viewMatrixRTE.set([e.x,t.x,i.x,0,e.y,t.y,i.y,0,e.z,t.z,i.z,0,0,0,0,1]);for(let e=0,t=this.frustums.length;e<t;e++)this.frustums[e].setViewMatrix(this._viewMatrix),this.frustums[e].setProjectionViewRTEMatrix(this._viewMatrixRTE);this.events.dispatch(this.events.viewchange,this)}refresh(){this._setProj(this._viewAngle,this._aspect),this.update()}setAspectRatio(e){this._aspect=e,this.refresh()}getAspectRatio(){return this._aspect}_setProj(e,t){this._viewAngle=e,this._aspect=t,this._tanViewAngle_hrad=Math.tan(e*d),this._tanViewAngle_hradOneByHeight=this._tanViewAngle_hrad*this.renderer.handler._oneByHeight;let i=this.renderer.handler.canvas;this._projSizeConst=Math.min(i.clientWidth<512?512:i.clientWidth,i.clientHeight<512?512:i.clientHeight)/(e*l);for(let i=0,s=this.frustums.length;i<s;i++)this.frustums[i].setProjectionMatrix(e,t,this.frustums[i].near,this.frustums[i].far)}setViewAngle(e){this._viewAngle=e,this.refresh()}getViewAngle(){return this._viewAngle}get viewAngle(){return this._viewAngle}set(e,t,i){return this.eye.x=e.x,this.eye.y=e.y,this.eye.z=e.z,t=t||this._b,i=i||this._u,this._b.x=e.x-t.x,this._b.y=e.y-t.y,this._b.z=e.z-t.z,this._r.copy(i.cross(this._b)),this._b.normalize(),this._r.normalize(),this._u.copy(this._b.cross(this._r)),this._f.set(-this._b.x,-this._b.y,-this._b.z),this}look(e,t){this._b.set(this.eye.x-e.x,this.eye.y-e.y,this.eye.z-e.z),this._r.copy((t||this._u).cross(this._b)),this._b.normalize(),this._f.set(-this._b.x,-this._b.y,-this._b.z),this._r.normalize(),this._u.copy(this._b.cross(this._r))}slide(e,t,i){this.eye.x+=e*this._r.x+t*this._u.x+i*this._b.x,this.eye.y+=e*this._r.y+t*this._u.y+i*this._b.y,this.eye.z+=e*this._r.z+t*this._u.z+i*this._b.z}setRoll(e){let t=Math.cos(e),i=Math.sin(e),s=this._r.clone();this._r.set(t*s.x-i*this._u.x,t*s.y-i*this._u.y,t*s.z-i*this._u.z),this._u.set(i*s.x+t*this._u.x,i*s.y+t*this._u.y,i*s.z+t*this._u.z)}setPitch(e){let t=Math.cos(e),i=Math.sin(e),s=this._b;this._b.set(t*s.x-i*this._u.x,t*s.y-i*this._u.y,t*s.z-i*this._u.z),this._u.set(i*s.x+t*this._u.x,i*s.y+t*this._u.y,i*s.z+t*this._u.z)}setYaw(e){let t=Math.cos(e),i=Math.sin(e),s=this._r;this._r.set(t*s.x-i*this._b.x,t*s.y-i*this._b.y,t*s.z-i*this._b.z),this._b.set(i*s.x+t*this._b.x,i*s.y+t*this._b.y,i*s.z+t*this._b.z)}setPitchYawRoll(e,t,i){let s=new re;s.setPitchYawRoll(e,t,i),this.setRotation(s)}getPitch(){return this.getRotation().getPitch()}getYaw(){return this.getRotation().getYaw()}getRoll(){return this.getRotation().getRoll()}getRotation(){return re.getLookRotation(this._f,this._u).conjugate()}setRotation(e,t,i,s){e.mulVec3Res(t||new oe(0,1,0),this._u),e.mulVec3Res(i||new oe(1,0,0),this._r),e.mulVec3Res(s||new oe(0,0,1),this._b),this._f.set(-this._b.x,-this._b.y,-this._b.z)}rotate(e){e.mulVec3Res(this._u,this._u),e.mulVec3Res(this._r,this._r),e.mulVec3Res(this._b,this._b),this._f.set(-this._b.x,-this._b.y,-this._b.z)}unproject2v(e){return this.unproject(e.x,e.y)}unproject(e,t){let i=this.renderer.handler.canvas,s=.5*i.width,n=.5*i.height,r=(e-s)/s,o=-(t-n)/n,a=this.frustums[0].inverseProjectionViewMatrix.mulVec4(new se(r,o,-1,1)).affinity();return this.frustums[0].inverseProjectionViewMatrix.mulVec4(new se(r,o,0,1)).affinity().subA(a).toVec3().normalize()}project3v(e){return this.project(e.x,e.y,e.z)}project(e,t,i){let s=this.frustums[0].projectionViewMatrix.mulVec4(new se(e,t,i,1)),n=this.renderer.handler.canvas;return new ae((1+s.x/s.w)*n.width*.5,(1-s.y/s.w)*n.height*.5)}rotateAround(e,t=!1,i=oe.ZERO,s=oe.UP){s=t?this._u:s;let n=ne.getRotation(e,s),r=ne.getRotationAroundPoint(e,i,s);this.eye=r.mulVec3(this.eye),this._u=n.mulVec3(this._u).normalize(),this._r=n.mulVec3(this._r).normalize(),this._b=n.mulVec3(this._b).normalize(),this._f.set(-this._b.x,-this._b.y,-this._b.z)}rotateHorizontal(e,t,i,s){this.rotateAround(e,t,i,s)}rotateVertical(e,t){this.rotateAround(e,!1,t,this._r)}projectedSize(e,t){return Math.atan(t/this.eye.distance(e))*this._projSizeConst}getViewMatrix(){return this._viewMatrix._m}getNormalMatrix(){return this._normalMatrix._m}setCurrentFrustum(e){this.currentFrustumIndex=e,this.frustumColorIndex=10*(e+1)/255,this.isFirstPass=e===this.FARTHEST_FRUSTUM_INDEX}getCurrentFrustum(){return this.currentFrustumIndex}containsSphere(e){for(let t=0;t<this.frustums.length;t++)if(this.frustums[t].containsSphere(e))return!0;return!1}get frustum(){return this.frustums[this.currentFrustumIndex]}getProjectionMatrix(){return this.frustum.projectionMatrix._m}getProjectionViewMatrix(){return this.frustum.projectionViewMatrix._m}getProjectionViewRTEMatrix(){return this.frustum.projectionViewRTEMatrix._m}getInverseProjectionViewMatrix(){return this.frustum.inverseProjectionViewMatrix._m}getInverseProjectionMatrix(){return this.frustum.inverseProjectionMatrix._m}viewDistance(e,t=1e4){let i=this.eye.add(this.getForward().scaleTo(t));re.getRotationBetweenVectors(i.getNormal(),e.getNormal());let s=e.add(this.getBackward().scaleTo(t));this.set(s,e),this.update()}}class Ua extends Va{constructor(e,t={}){super(e.renderer,{...t,frustums:t.frustums||[[1,100.075],[100,1000.075],[1e3,101e4],[1e6,1e9]]}),this.planet=e,this.minAltitude=t.minAltitude||1,this.maxAltitude=t.maxAltitude||2e7,this._lonLat=this.planet.ellipsoid.cartesianToLonLat(this.eye),this._lonLatMerc=this._lonLat.forwardMercator(),this._terrainAltitude=this._lonLat.height,this._terrainPoint=new oe,this._insideSegment=null,this.slope=0,this._keyLock=new Bn,this._framesArr=[],this._framesCounter=0,this._numFrames=50,this._completeCallback=null,this._frameCallback=null,this._flying=!1,this._checkTerrainCollision=!0,this.eyeNorm=this.eye.getNormal()}setTerrainCollisionActivity(e){this._checkTerrainCollision=e}update(){this.events.stopPropagation();let e=this.maxAltitude+this.planet.ellipsoid.getEquatorialSize();this.eye.length()>e&&this.eye.copy(this.eye.getNormal().scale(e)),super.update(),this.updateGeodeticPosition(),this.eyeNorm=this.eye.getNormal(),this.slope=this._b.dot(this.eyeNorm),this.events.dispatch(this.events.viewchange,this)}updateGeodeticPosition(){this.planet.ellipsoid.cartesianToLonLatRes(this.eye,this._lonLat),Math.abs(this._lonLat.lat)<=Q&&I.forwardMercatorRes(this._lonLat,this._lonLatMerc)}setAltitude(e){let t=this._terrainPoint,i=this.planet.ellipsoid.getSurfaceNormal3v(this.eye);this.eye.x=i.x*e+t.x,this.eye.y=i.y*e+t.y,this.eye.z=i.z*e+t.z,this._terrainAltitude=e}getAltitude(){return this._terrainAltitude}setLonLat(e,t,i){this.stopFlying(),this._lonLat.set(e.lon,e.lat,e.height||this._lonLat.height);let s=this.planet.ellipsoid,n=s.lonLatToCartesian(this._lonLat),r=t?s.lonLatToCartesian(t):oe.ZERO;this.set(n,r,i||oe.NORTH),this.update()}getLonLat(){return this._lonLat}getHeight(){return this._lonLat.height}getExtentPosition(e,t){t=t||0;let i=e.getNorth(),s=e.getSouth(),n=e.getEast(),r=e.getWest();r>n&&(n+=360);let o=this.planet.ellipsoid,a=new I(n,i),h=o.lonLatToCartesian(a);a.lat=s;let c=o.lonLatToCartesian(a);a.lon=r;let d=o.lonLatToCartesian(a);a.lat=i;let _=o.lonLatToCartesian(a),u=oe.sub(h,d).scale(.5).addA(d),g=u.length();g<1e-6&&(a.lon=.5*(n+r),a.lat=.5*(i+s),u=o.lonLatToCartesian(a)),_.subA(u),c.subA(u),h.subA(u),d.subA(u);let f=u.getNormal(),p=f.cross(oe.NORTH).normalize(),m=p.cross(f).normalize(),v=Math.max(Math.abs(m.dot(_)),Math.abs(m.dot(c)),Math.abs(m.dot(h)),Math.abs(m.dot(d))),y=Math.max(Math.abs(p.dot(_)),Math.abs(p.dot(c)),Math.abs(p.dot(h)),Math.abs(p.dot(d))),x=Math.tan(this._viewAngle*l*.5),b=this._aspect*x,w=Math.max(y/b,v/x);return u.normalize(),u.scale(g+w+t),u}viewExtent(e,t){this.stopFlying(),this.set(this.getExtentPosition(e,t),oe.ZERO,oe.NORTH),this.update()}flyExtent(e,t,i,s,n,r,o){this.flyCartesian(this.getExtentPosition(e,t),oe.ZERO,i,null==s?1:s,n,r,o)}viewDistance(e,t=1e4){let i=this.eye.add(this.getForward().scaleTo(t)),s=re.getRotationBetweenVectors(i.getNormal(),e.getNormal());if(s.isZero()){let i=e.add(this.getBackward().scaleTo(t));this.set(i,e)}else{let i=e.add(s.mulVec3(this.getBackward()).scale(t)),n=s.mulVec3(this.getUp());this.set(i,e,n)}this.update()}flyDistance(e,t=1e4,i=0,s,n,r){let o=this.eye.add(this.getForward().scaleTo(t)),a=re.getRotationBetweenVectors(o.getNormal(),e.getNormal());if(a.isZero()){let i=e.add(this.getBackward().scaleTo(t));this.set(i,e)}else{let o=e.add(a.mulVec3(this.getBackward()).scale(t)),l=a.mulVec3(this.getUp());this.flyCartesian(o,e,l,i,s,n,r)}}flyCartesian(e,t=oe.ZERO,i=oe.NORTH,s=1,n=(()=>{}),r=(()=>{}),o=(()=>{})){this.stopFlying(),t=t||oe.ZERO,i=i||oe.NORTH,this._completeCallback=n,this._frameCallback=o,r&&r.call(this),t instanceof I&&(t=this.planet.ellipsoid.lonLatToCartesian(t));let a=this.planet.ellipsoid.lonLatToCartesian(new I(this._lonLat.lon,this._lonLat.lat)),l=this._u,h=this._b,c=this.planet.ellipsoid.cartesianToLonLat(e),d=i,u=this.planet.ellipsoid.lonLatToCartesian(new I(c.lon,c.lat,0)),g=oe.sub(e,t),f=d.cross(g);g.normalize(),f.normalize();let p=g.cross(f),m=a.getNormal(),v=u.getNormal(),y=1-m.dot(v),x=s*_*Math.sqrt(y>0?y:0),b=6639613,w=Math.max(this._lonLat.height,c.height);w>b&&(b=w);let C=w+2.5*x*(b-w),T=oe.ZERO;for(let e=0;e<=this._numFrames;e++){let t=1-e/this._numFrames;t=t*t*(3-2*t),t*=t;let i=a.smerp(u,t).normalize(),s=this.planet.getRayIntersectionEllipsoid(new ui(T,i)),n=1-t,r=this._lonLat.height*t*t*t+3*C*t*t*n+3*C*t*n*n+c.height*n*n*n,o=s.addA(i.scale(r)),d=l.smerp(p,t),_=oe.add(o,h.smerp(g,t).negateTo()),f=new oe(o.x-_.x,o.y-_.y,o.z-_.z),m=d.cross(f);f.normalize(),m.normalize();let v=f.cross(m);this._framesArr[e]={eye:o,n:f,u:m,v:v}}this._framesCounter=this._numFrames,this._flying=!0}flyLonLat(e,t,i,s,n,r,o){let a=new I(e.lon,e.lat,e.height||this._lonLat.height);this.flyCartesian(this.planet.ellipsoid.lonLatToCartesian(a),t,i,s,n,r,o)}stopFlying(){this.planet.layerLock.free(this._keyLock),this.planet.terrainLock.free(this._keyLock),this.planet.normalMapCreator.free(this._keyLock),this._flying=!1,this._framesArr.length=0,this._framesArr=[],this._framesCounter=-1,this._frameCallback=null,this.planet.stopDragging()}isFlying(){return this._flying}rotateLeft(e,t){this.rotateHorizontal(e,!0!==t,oe.ZERO),this.update()}rotateRight(e,t){this.rotateHorizontal(-e,!0!==t,oe.ZERO),this.update()}rotateUp(e){this.rotateVertical(e,oe.ZERO),this.update()}rotateDown(e){this.rotateVertical(-e,oe.ZERO),this.update()}rotateVertical(e,t,i=0){let s=(new ne).setRotation(this._r,e),n=(new ne).setIdentity().translate(t),r=(new ne).setIdentity().translate(t.negateTo()),o=n.mul(s).mul(r).mulVec3(this.eye),a=s.mulVec3(this._u).normalize(),l=s.mulVec3(this._r).normalize(),h=s.mulVec3(this._b).normalize(),c=o.getNormal(),d=h.dot(c);if(i){let e=d-this.slope;if(d<i&&e<0)return;(d>.1&&a.dot(c)>0||this.slope<=.1||this._u.dot(this.eye.getNormal())<=0)&&(this.eye=o,this._u=a,this._r=l,this._b=h,this._f.set(-h.x,-h.y,-h.z))}else this.eye=o,this._u=a,this._r=l,this._b=h,this._f.set(-h.x,-h.y,-h.z)}checkFly(){if(this._flying){let e=this._numFrames-this._framesCounter;this.planet.layerLock.lock(this._keyLock),this.planet.terrainLock.lock(this._keyLock),this.planet.normalMapCreator.lock(this._keyLock),this.eye=this._framesArr[e].eye,this._r=this._framesArr[e].u,this._u=this._framesArr[e].v,this._b=this._framesArr[e].n,this._f.set(-this._b.x,-this._b.y,-this._b.z),this._frameCallback&&this._frameCallback(),this.update(),this._framesCounter--,this._framesCounter<0&&(this.stopFlying(),this._completeCallback&&(this._completeCallback(),this._completeCallback=null))}}checkTerrainCollision(){if(this._terrainAltitude=this._lonLat.height,this._insideSegment&&this._insideSegment.planet)return this._terrainAltitude=this._insideSegment.getTerrainPoint(this.eye,this._insideSegment.getInsideLonLat(this),this._terrainPoint),this._terrainAltitude<this.minAltitude&&this._checkTerrainCollision&&this.setAltitude(this.minAltitude),this._terrainPoint}getSurfaceVisibleDistance(e){let t=this.planet.ellipsoid.equatorialSize;return t*Math.acos(t/(t+this._lonLat.height+e))}getHeading(){let e=this.eye.getNormal(),t=oe.proj_b_to_plane(this.slope>=.97?this.getUp():this.getForward(),e).normalize(),i=oe.proj_b_to_plane(oe.NORTH,e).normalize(),s=Math.sign(e.dot(t.cross(i)))*Math.acos(t.dot(i))*h;return s<0?360+s:s}isVisible(e){let t=this.eye.length();return this.eye.distance(e)<Math.sqrt(t*t-this.planet.ellipsoid.equatorialSizeSqr)}getPitch(){return this.planet.getFrameRotation(this.eye).conjugate().inverse().mul(this.getRotation()).getPitch()}getYaw(){return this.planet.getFrameRotation(this.eye).conjugate().inverse().mul(this.getRotation()).getYaw()}getRoll(){return this.planet.getFrameRotation(this.eye).conjugate().inverse().mul(this.getRotation()).getRoll()}setPitch(e){let t=this.planet.getFrameRotation(this.eye),i=new re;i.setPitchYawRoll(e,this.getYaw(),this.getRoll(),t),this.setRotation(i)}setYaw(e){let t=this.planet.getFrameRotation(this.eye),i=new re;i.setPitchYawRoll(this.getYaw(),e,this.getRoll(),t),this.setRotation(i)}setRoll(e){let t=this.planet.getFrameRotation(this.eye),i=new re;i.setPitchYawRoll(this.getPitch(),this.getYaw(),e,t),this.setRotation(i)}setPitchYawRoll(e,t,i){let s=this.planet.getFrameRotation(this.eye),n=new re;n.setPitchYawRoll(e,t,i,s).conjugate(),this.setRotation(n)}}class Ga extends ei{constructor(e=2){super(e,Ya)}_onMessage(e){this._source.get(e.data.id).segment._terrainWorkerCallback(e.data),this._source.delete(e.data.id),e.data.normalMapNormals=null,e.data.normalMapVertices=null,e.data.normalMapVerticesHigh=null,e.data.normalMapVerticesLow=null,e.data.terrainVertices=null,e.data.terrainVerticesHigh=null,e.data.terrainVerticesLow=null}make(e){if(e.segment.plainReady&&e.segment.terrainIsLoading)if(this._workerQueue.length){const t=this._workerQueue.pop();this._source.set(this._sourceId,e);let i=e.segment;t.postMessage({elevations:e.elevations,this_plainVertices:i.plainVertices,this_plainNormals:i.plainNormals,this_normalMapVertices:i.normalMapVertices,this_normalMapNormals:i.normalMapNormals,heightFactor:i.planet._heightFactor,gridSize:i.planet.terrain.gridSizeByZoom[i.tileZoom],noDataValues:i.planet.terrain.noDataValues,id:this._sourceId},[e.elevations.buffer,i.plainVertices.buffer,i.plainNormals.buffer,i.normalMapVertices.buffer,i.normalMapNormals.buffer]),this._sourceId++}else this._pendingQueue.push(e);else this.check()}}const Ya="'use strict';\n //\n //Terrain worker\n //\n\n function binarySearchFast(arr, x) {\n let start = 0,\n end = arr.length - 1;\n while (start <= end) {\n let k = Math.floor((start + end) * 0.5); \n if (Math.abs(arr[k] - x) < 1e-3)\n return k;\n else if (arr[k] < x)\n start = k + 1;\n else\n end = k - 1;\n }\n return -1;\n };\n\n function checkNoDataValue(noDataValues, value) {\n return binarySearchFast(noDataValues, value) !== -1;\n };\n\n\n var Vec3 = function(x, y, z) {\n this.x = x;\n this.y = y;\n this.z = z;\n };\n\n var doubleToTwoFloats = function(v, high, low) {\n\n let x = v.x, y = v.y, z = v.z;\n \n if (x >= 0.0) {\n var doubleHigh = Math.floor(x / 65536.0) * 65536.0;\n high.x = Math.fround(doubleHigh);\n low.x = Math.fround(x - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-x / 65536.0) * 65536.0;\n high.x = Math.fround(-doubleHigh);\n low.x = Math.fround(x + doubleHigh);\n }\n\n if (y >= 0.0) {\n var doubleHigh = Math.floor(y / 65536.0) * 65536.0;\n high.y = Math.fround(doubleHigh);\n low.y = Math.fround(y - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-y / 65536.0) * 65536.0;\n high.y = Math.fround(-doubleHigh);\n low.y = Math.fround(y + doubleHigh);\n }\n\n if (z >= 0.0) {\n var doubleHigh = Math.floor(z / 65536.0) * 65536.0;\n high.z = Math.fround(doubleHigh);\n low.z = Math.fround(z - doubleHigh);\n } else {\n var doubleHigh = Math.floor(-z / 65536.0) * 65536.0;\n high.z = Math.fround(-doubleHigh);\n low.z = Math.fround(z + doubleHigh);\n }\n };\n\n Vec3.prototype.sub = function(v) {\n return new Vec3(this.x - v.x, this.y - v.y, this.z - v.z);\n };\n\n Vec3.prototype.add = function(v) {\n return new Vec3(this.x + v.x, this.y + v.y, this.z + v.z);\n };\n\n Vec3.prototype.cross = function(v) {\n return new Vec3(\n this.y * v.z - this.z * v.y,\n this.z * v.x - this.x * v.z,\n this.x * v.y - this.y * v.x\n );\n };\n\n Vec3.prototype.normalize = function(v) {\n var x = this.x, y = this.y, z = this.z;\n var length = 1.0 / Math.sqrt(x * x + y * y + z * z);\n this.x = x * length;\n this.y = y * length;\n this.z = z * length;\n return this;\n };\n\n Vec3.prototype.distance = function(v) {\n return this.sub(v).length();\n };\n\n Vec3.prototype.length = function () {\n return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);\n };\n\n var blerp = function(x, y, fQ11, fQ21, fQ12, fQ22) {\n return (fQ11 * (1.0 - x) * (1.0 - y) + fQ21 * x * (1.0 - y) + fQ12 * (1.0 - x) * y + fQ22 * x * y);\n };\n \n var slice = function (t, h1, h0) {\n return t * (h1 - h0);\n };\n\n var _tempVec = new Vec3(0.0, 0.0, 0.0);\n\n var _tempHigh = new Vec3(0.0, 0.0, 0.0),\n _tempLow = new Vec3(0.0, 0.0, 0.0);\n\n self.onmessage = function (e) {\n var elevations = e.data.elevations,\n this_plainVertices = e.data.this_plainVertices,\n this_plainNormals = e.data.this_plainNormals,\n this_normalMapVertices = e.data.this_normalMapVertices,\n this_normalMapNormals = e.data.this_normalMapNormals,\n heightFactor = e.data.heightFactor,\n gridSize = e.data.gridSize,\n noDataValues = e.data.noDataValues,\n id = e.data.id;\n \n var xmin = 549755748352.0, xmax = -549755748352.0, \n ymin = 549755748352.0, ymax = -549755748352.0, \n zmin = 549755748352.0, zmax = -549755748352.0;\n\n const fileGridSize = Math.sqrt(elevations.length) - 1;\n\n const fileGridSize_one = fileGridSize + 1;\n const fileGridSize_one_x2 = fileGridSize_one * fileGridSize_one;\n const tgs = gridSize;\n const dg = fileGridSize / tgs;\n const gs = tgs + 1;\n const hf = heightFactor;\n\n var nmvInd = 0,\n vInd = 0,\n noDataInd = 0;\n\n var gsgs3 = gs * gs * 3;\n\n var terrainVertices = new Float64Array(gsgs3),\n terrainVerticesHigh = new Float32Array(gsgs3),\n terrainVerticesLow = new Float32Array(gsgs3),\n noDataVertices = new Uint8Array(gs * gs);\n\n var normalMapNormals,\n normalMapVertices,\n normalMapVerticesHigh,\n normalMapVerticesLow;\n\n var nv = this_normalMapVertices,\n nn = this_normalMapNormals;\n\n if (fileGridSize >= tgs) {\n\n normalMapNormals = new Float32Array(fileGridSize_one_x2 * 3);\n normalMapVertices = new Float64Array(fileGridSize_one_x2 * 3);\n normalMapVerticesHigh = new Float32Array(fileGridSize_one_x2 * 3);\n normalMapVerticesLow = new Float32Array(fileGridSize_one_x2 * 3);\n\n for (let k = 0; k < fileGridSize_one_x2; k++) {\n\n var j = k % fileGridSize_one,\n i = ~~(k / fileGridSize_one);\n\n //\n // V0\n //\n var hInd0 = k;\n var vInd0 = hInd0 * 3;\n var currElv = elevations[hInd0];\n if(checkNoDataValue(noDataValues, currElv)) {\n currElv = 0.0;\n }\n var h0 = hf * currElv;\n var v0 = new Vec3(nv[vInd0] + h0 * nn[vInd0], nv[vInd0 + 1] + h0 * nn[vInd0 + 1], nv[vInd0 + 2] + h0 * nn[vInd0 + 2]);\n \n doubleToTwoFloats(v0, _tempHigh, _tempLow);\n\n normalMapVertices[vInd0] = v0.x;\n normalMapVertices[vInd0 + 1] = v0.y;\n normalMapVertices[vInd0 + 2] = v0.z;\n\n normalMapVerticesHigh[vInd0] = _tempHigh.x;\n normalMapVerticesHigh[vInd0 + 1] = _tempHigh.y;\n normalMapVerticesHigh[vInd0 + 2] = _tempHigh.z;\n\n normalMapVerticesLow[vInd0] = _tempLow.x;\n normalMapVerticesLow[vInd0 + 1] = _tempLow.y;\n normalMapVerticesLow[vInd0 + 2] = _tempLow.z;\n\n //\n // The vertex goes into screen buffer\n if (i % dg === 0 && j % dg === 0) {\n\n let currVert = new Vec3(nv[vInd0], nv[vInd0 + 1], nv[vInd0 + 2]);\n let nextVert = new Vec3(nv[vInd0 + 3], nv[vInd0 + 4], nv[vInd0 + 5]);\n\n let nextElv = elevations[hInd0 + 1];\n if(checkNoDataValue(noDataValues, nextElv)) {\n nextElv = 0.0;\n }\n \n let eps = false;\n if(noDataValues.length === 0){\n let step = currVert.distance(nextVert);\n let deltaElv = Math.abs(currElv - nextElv);\n eps = ((deltaElv / step) > 10.0) || (currElv < -5000);\n }\n\n if(eps){\n noDataVertices[noDataInd] = 1;\n } else {\n noDataVertices[noDataInd] = 0;\n if (v0.x < xmin) xmin = v0.x; if (v0.x > xmax) xmax = v0.x;\n if (v0.y < ymin) ymin = v0.y; if (v0.y > ymax) ymax = v0.y;\n if (v0.z < zmin) zmin = v0.z; if (v0.z > zmax) zmax = v0.z;\n }\n\n terrainVerticesHigh[vInd] = _tempHigh.x;\n terrainVerticesLow[vInd] = _tempLow.x;\n terrainVertices[vInd++] = v0.x;\n\n terrainVerticesHigh[vInd] = _tempHigh.y;\n terrainVerticesLow[vInd] = _tempLow.y;\n terrainVertices[vInd++] = v0.y;\n\n terrainVerticesHigh[vInd] = _tempHigh.z;\n terrainVerticesLow[vInd] = _tempLow.z;\n terrainVertices[vInd++] = v0.z;\n\n noDataInd++;\n }\n\n if (i !== fileGridSize && j !== fileGridSize) {\n\n //\n // V1\n //\n var hInd1 = k + 1;\n var vInd1 = hInd1 * 3;\n var elv = elevations[hInd1];\n if(checkNoDataValue(noDataValues, elv)) {\n elv = 0.0;\n }\n var h1 = hf * elv;\n var v1 = new Vec3(nv[vInd1] + h1 * nn[vInd1], nv[vInd1 + 1] + h1 * nn[vInd1 + 1], nv[vInd1 + 2] + h1 * nn[vInd1 + 2]);\n\n doubleToTwoFloats(v1, _tempHigh, _tempLow);\n\n normalMapVertices[vInd1] = v1.x;\n normalMapVertices[vInd1 + 1] = v1.y;\n normalMapVertices[vInd1 + 2] = v1.z;\n\n normalMapVerticesHigh[vInd1] = _tempHigh.x;\n normalMapVerticesHigh[vInd1 + 1] = _tempHigh.y;\n normalMapVerticesHigh[vInd1 + 2] = _tempHigh.z;\n\n normalMapVerticesLow[vInd1] = _tempLow.x;\n normalMapVerticesLow[vInd1 + 1] = _tempLow.y;\n normalMapVerticesLow[vInd1 + 2] = _tempLow.z;\n\n //\n // V2\n //\n var hInd2 = k + fileGridSize_one;\n var vInd2 = hInd2 * 3;\n var elv = elevations[hInd2];\n if(checkNoDataValue(noDataValues, elv)) {\n elv = 0.0;\n }\n var h2 = hf * elv;\n var v2 = new Vec3(nv[vInd2] + h2 * nn[vInd2], nv[vInd2 + 1] + h2 * nn[vInd2 + 1], nv[vInd2 + 2] + h2 * nn[vInd2 + 2]);\n\n doubleToTwoFloats(v2, _tempHigh, _tempLow);\n\n normalMapVertices[vInd2] = v2.x;\n normalMapVertices[vInd2 + 1] = v2.y;\n normalMapVertices[vInd2 + 2] = v2.z;\n\n normalMapVerticesHigh[vInd2] = _tempHigh.x;\n normalMapVerticesHigh[vInd2 + 1] = _tempHigh.y;\n normalMapVerticesHigh[vInd2 + 2] = _tempHigh.z;\n\n normalMapVerticesLow[vInd2] = _tempLow.x;\n normalMapVerticesLow[vInd2 + 1] = _tempLow.y;\n normalMapVerticesLow[vInd2 + 2] = _tempLow.z;\n\n //\n // V3\n //\n var hInd3 = k + fileGridSize_one + 1;\n var vInd3 = hInd3 * 3;\n var elv = elevations[hInd3];\n if(checkNoDataValue(noDataValues, elv)) {\n elv = 0.0;\n }\n var h3 = hf * elv;\n var v3 = new Vec3(nv[vInd3] + h3 * nn[vInd3], nv[vInd3 + 1] + h3 * nn[vInd3 + 1], nv[vInd3 + 2] + h3 * nn[vInd3 + 2]);\n\n doubleToTwoFloats(v3, _tempHigh, _tempLow);\n\n normalMapVertices[vInd3] = v3.x;\n normalMapVertices[vInd3 + 1] = v3.y;\n normalMapVertices[vInd3 + 2] = v3.z;\n\n normalMapVerticesHigh[vInd3] = _tempHigh.x;\n normalMapVerticesHigh[vInd3 + 1] = _tempHigh.y;\n normalMapVerticesHigh[vInd3 + 2] = _tempHigh.z;\n\n normalMapVerticesLow[vInd3] = _tempLow.x;\n normalMapVerticesLow[vInd3 + 1] = _tempLow.y;\n normalMapVerticesLow[vInd3 + 2] = _tempLow.z;\n\n //\n // Normal\n //\n var e10 = v1.sub(v0),\n e20 = v2.sub(v0),\n e30 = v3.sub(v0);\n var sw = e20.cross(e30).normalize();\n var ne = e30.cross(e10).normalize();\n var n0 = ne.add(sw).normalize();\n\n normalMapNormals[vInd0] += n0.x;\n normalMapNormals[vInd0 + 1] += n0.y;\n normalMapNormals[vInd0 + 2] += n0.z;\n\n normalMapNormals[vInd1] += ne.x;\n normalMapNormals[vInd1 + 1] += ne.y;\n normalMapNormals[vInd1 + 2] += ne.z;\n\n normalMapNormals[vInd2] += sw.x;\n normalMapNormals[vInd2 + 1] += sw.y;\n normalMapNormals[vInd2 + 2] += sw.z;\n\n normalMapNormals[vInd3] += n0.x;\n normalMapNormals[vInd3 + 1] += n0.y;\n normalMapNormals[vInd3 + 2] += n0.z;\n }\n }\n\n } else {\n\n normalMapNormals = new Float32Array(gsgs3);\n normalMapVertices = new Float64Array(gsgs3);\n normalMapVerticesHigh = new Float32Array(gsgs3);\n normalMapVerticesLow = new Float32Array(gsgs3);\n normalMapNormals = new Float32Array(gsgs3);\n\n var oneSize = tgs / fileGridSize;\n var h, inside_i, inside_j, v_i, v_j;\n var gsgs = gsgs3 / 3;\n var fgsOne = fileGridSize + 1;\n\n for(let i = 0; i < gsgs; i++) {\n let ii = Math.floor(i / gs),\n ij = i % gs;\n \n let qii = ii % oneSize,\n qij = ij % oneSize;\n\n let hlt_ind = Math.floor(ii / oneSize) * fgsOne + Math.floor(ij / oneSize);\n\n if (ij === tgs) {\n hlt_ind -= 1;\n qij = oneSize;\n }\n\n if (ii === tgs) {\n hlt_ind -= fgsOne;\n qii = oneSize;\n }\n\n let hrt_ind = hlt_ind + 1,\n hlb_ind = hlt_ind + fgsOne,\n hrb_ind = hlb_ind + 1;\n\n let h_lt = elevations[hlt_ind],\n h_rt = elevations[hrt_ind],\n h_lb = elevations[hlb_ind],\n h_rb = elevations[hrb_ind];\n\n if(checkNoDataValue(noDataValues, h_lt)) {\n h_lt = 0.0;\n }\n\n if(checkNoDataValue(noDataValues, h_rt)) {\n h_rt = 0.0;\n }\n\n if(checkNoDataValue(noDataValues, h_lb)) {\n h_lb = 0.0;\n }\n\n if(checkNoDataValue(noDataValues, h_rb)) {\n h_rb = 0.0;\n }\n\n let hi = blerp(qij / oneSize, qii / oneSize, h_lt, h_rt, h_lb, h_rb);\n\n let i3 = i * 3;\n\n _tempVec.x = this_plainVertices[i3] + hi * this_plainNormals[i3],\n _tempVec.y = this_plainVertices[i3 + 1] + hi * this_plainNormals[i3 + 1],\n _tempVec.z = this_plainVertices[i3 + 2] + hi * this_plainNormals[i3 + 2];\n\n doubleToTwoFloats(_tempVec, _tempHigh, _tempLow);\n\n terrainVertices[i3] = _tempVec.x;\n terrainVertices[i3 + 1] = _tempVec.y;\n terrainVertices[i3 + 2] = _tempVec.z;\n\n terrainVerticesHigh[i3] = _tempHigh.x;\n terrainVerticesHigh[i3 + 1] = _tempHigh.y;\n terrainVerticesHigh[i3 + 2] = _tempHigh.z;\n\n terrainVerticesLow[i3] = _tempLow.x;\n terrainVerticesLow[i3 + 1] = _tempLow.y;\n terrainVerticesLow[i3 + 2] = _tempLow.z;\n\n if (_tempVec.x < xmin) xmin = _tempVec.x; if (_tempVec.x > xmax) xmax = _tempVec.x;\n if (_tempVec.y < ymin) ymin = _tempVec.y; if (_tempVec.y > ymax) ymax = _tempVec.y;\n if (_tempVec.z < zmin) zmin = _tempVec.z; if (_tempVec.z > zmax) zmax = _tempVec.z;\n }\n\n normalMapVertices.set(terrainVertices);\n normalMapVerticesHigh.set(terrainVerticesHigh);\n normalMapVerticesLow.set(terrainVerticesLow);\n\n for (let k = 0; k < gsgs; k++) {\n\n var j = k % gs,\n i = ~~(k / gs);\n\n if (i !== tgs && j !== tgs) {\n var v0ind = k * 3,\n v1ind = v0ind + 3,\n v2ind = v0ind + gs * 3,\n v3ind = v2ind + 3;\n\n\n var v0 = new Vec3(terrainVertices[v0ind], terrainVertices[v0ind + 1], terrainVertices[v0ind + 2]),\n v1 = new Vec3(terrainVertices[v1ind], terrainVertices[v1ind + 1], terrainVertices[v1ind + 2]),\n v2 = new Vec3(terrainVertices[v2ind], terrainVertices[v2ind + 1], terrainVertices[v2ind + 2]),\n v3 = new Vec3(terrainVertices[v3ind], terrainVertices[v3ind + 1], terrainVertices[v3ind + 2]);\n\n var e10 = v1.sub(v0).normalize(),\n e20 = v2.sub(v0).normalize(),\n e30 = v3.sub(v0).normalize();\n\n var sw = e20.cross(e30).normalize();\n var ne = e30.cross(e10).normalize();\n var n0 = ne.add(sw).normalize();\n\n normalMapNormals[v0ind] += n0.x;\n normalMapNormals[v0ind + 1] += n0.y;\n normalMapNormals[v0ind + 2] += n0.z;\n\n normalMapNormals[v1ind] += ne.x;\n normalMapNormals[v1ind + 1] += ne.y;\n normalMapNormals[v1ind + 2] += ne.z;\n\n normalMapNormals[v2ind] += sw.x;\n normalMapNormals[v2ind + 1] += sw.y;\n normalMapNormals[v2ind + 2] += sw.z;\n\n normalMapNormals[v3ind] += n0.x;\n normalMapNormals[v3ind + 1] += n0.y;\n normalMapNormals[v3ind + 2] += n0.z;\n }\n }\n }\n\n self.postMessage({\n id: id,\n normalMapNormals: normalMapNormals,\n normalMapVertices: normalMapVertices,\n normalMapVerticesHigh: normalMapVerticesHigh,\n normalMapVerticesLow: normalMapVerticesLow,\n terrainVertices: terrainVertices,\n terrainVerticesHigh: terrainVerticesHigh,\n terrainVerticesLow: terrainVerticesLow,\n noDataVertices: noDataVertices,\n //bounds: [xmin, xmax, ymin, ymax, zmin, zmax]\n bounds: [xmin, ymin, zmin, xmax, ymax, zmax]\n }, [\n normalMapNormals.buffer, \n normalMapVertices.buffer, \n normalMapVerticesHigh.buffer, \n normalMapVerticesLow.buffer, \n terrainVertices.buffer,\n terrainVerticesHigh.buffer,\n terrainVerticesLow.buffer,\n noDataVertices.buffer\n ]);\n }";let ja=new Float32Array(2);class Wa{constructor(e,t=512,i=512){this._width=t,this._height=i,this._planet=e,this._framebuffer=null,this._queue=[],this._handler=null}init(){this._handler=this._planet.renderer.handler,this._handler.programs.vectorTileLineRasterization||this._handler.addProgram(new Ni("vectorTileLineRasterization",{uniforms:{viewport:"vec2",thicknessOutline:"float",alpha:"float",extentParamsHigh:"vec4",extentParamsLow:"vec4"},attributes:{prevHigh:"vec2",currentHigh:"vec2",nextHigh:"vec2",prevLow:"vec2",currentLow:"vec2",nextLow:"vec2",order:"float",color:"vec4",thickness:"float"},vertexShader:"attribute vec2 prevHigh;\n attribute vec2 currentHigh;\n attribute vec2 nextHigh;\n\n attribute vec2 prevLow;\n attribute vec2 currentLow;\n attribute vec2 nextLow;\n\n attribute float order;\n attribute float thickness;\n attribute vec4 color;\n uniform float thicknessOutline;\n uniform vec2 viewport;\n uniform vec4 extentParamsHigh;\n uniform vec4 extentParamsLow;\n varying vec4 vColor;\n \n vec2 proj(vec2 coordHigh, vec2 coordLow) {\n vec2 highDiff = coordHigh - extentParamsHigh.xy;\n vec2 lowDiff = coordLow - extentParamsLow.xy; \n return vec2(-1.0 + (highDiff * step(1.0, length(highDiff)) + lowDiff) * extentParamsHigh.zw) * vec2(1.0, -1.0);\n }\n \n void main(){\n vColor = color;\n\n vec2 vNext = proj(nextHigh, nextLow),\n vCurrent = proj(currentHigh, currentLow),\n vPrev = proj(prevHigh, prevLow);\n\n vec2 _next = vNext;\n vec2 _prev = vPrev;\n vec2 _current = vCurrent;\n\n if(_prev == _current){\n if(_next == _current){\n _next = _current + vec2(1.0, 0.0);\n _prev = _current - _next;\n }else{\n _prev = _current + normalize(_current - _next);\n }\n }\n\n if(_next == _current){\n _next = _current + normalize(_current - _prev);\n }\n\n vec2 sNext = _next;\n vec2 sCurrent = _current;\n vec2 sPrev = _prev;\n \n vec2 dirNext = normalize(sNext - sCurrent);\n vec2 dirPrev = normalize(sPrev - sCurrent);\n float dotNP = dot(dirNext, dirPrev);\n \n vec2 normalNext = normalize(vec2(-dirNext.y, dirNext.x));\n vec2 normalPrev = normalize(vec2(dirPrev.y, -dirPrev.x));\n vec2 d = (thickness + thicknessOutline) * 0.5 * sign(order) / viewport;\n \n vec2 m;\n if(dotNP >= 0.99991){\n m = sCurrent - normalPrev * d;\n }else{\n vec2 dir = normalPrev + normalNext;\n m = sCurrent + dir * d / (dirNext.x * dir.y - dirNext.y * dir.x);\n \n if( dotNP > 0.5 && dot(dirNext + dirPrev, m - sCurrent) < 0.0 ){\n float occw = order * sign(dirNext.x * dirPrev.y - dirNext.y * dirPrev.x);\n if(occw == -1.0){\n m = sCurrent + normalPrev * d;\n }else if(occw == 1.0){\n m = sCurrent + normalNext * d;\n }else if(occw == -2.0){\n m = sCurrent + normalNext * d;\n }else if(occw == 2.0){\n m = sCurrent + normalPrev * d;\n }\n }else if(distance(sCurrent, m) > min(distance(sCurrent, sNext), distance(sCurrent, sPrev))){\n m = sCurrent + normalNext * d;\n }\n }\n gl_Position = vec4(m.x, m.y, 0.0, 1.0);\n }",fragmentShader:"precision highp float;\n uniform float alpha;\n varying vec4 vColor;\n void main() {\n gl_FragColor = vec4(vColor.rgb, alpha * vColor.a);\n }"})),this._handler.programs.vectorTilePolygonRasterization||this._handler.addProgram(new Ni("vectorTilePolygonRasterization",{uniforms:{extentParamsHigh:"vec4",extentParamsLow:"vec4"},attributes:{coordinatesHigh:"vec2",coordinatesLow:"vec2",colors:"vec4"},vertexShader:"attribute vec2 coordinatesHigh;\n attribute vec2 coordinatesLow; \n attribute vec4 colors; \n uniform vec4 extentParamsHigh; \n uniform vec4 extentParamsLow; \n varying vec4 color;\n\n vec2 proj(vec2 coordHigh, vec2 coordLow) {\n vec2 highDiff = coordHigh - extentParamsHigh.xy;\n vec2 lowDiff = coordLow - extentParamsLow.xy;\n return vec2(-1.0 + (highDiff * step(1.0, length(highDiff)) + lowDiff) * extentParamsHigh.zw) * vec2(1.0, -1.0);\n }\n\n void main() { \n color = colors;\n gl_Position = vec4(proj(coordinatesHigh, coordinatesLow), 0.0, 1.0); \n }",fragmentShader:"precision highp float;\n varying vec4 color;\n void main () { \n gl_FragColor = color; \n }"})),this._framebuffer=new Yo(this._handler,{width:this._width,height:this._height,useDepth:!1}),this._framebuffer.init()}frame(){if(this._planet.layerLock.isFree()&&this._queue.length){let e=this._handler,t=e.gl;t.disable(t.CULL_FACE),t.disable(t.DEPTH_TEST);let i=e.programs.vectorTileLineRasterization,s=e.programs.vectorTilePolygonRasterization,n=this._width,r=this._height,o=n,a=r,l=o<<1,h=a<<1,c=new Float32Array(4),d=new Float32Array(4),_=this._framebuffer.activate(),u=0,g=window.performance.now();for(;this._queue.length&&u<25;){let f=this._queue.shift();if(f.isLoading&&1===f.segment.node.getState()){let u=f.layer._pickingEnabled;f.segment.tileZoom<4?(o=l,a=h):(o=n,a=r);let g=f._updateTexture||e.createEmptyTexture_l(o,a),p=u?f._updatePickingMask||e.createEmptyTexture_n(o,a):null;f.applyTexture(g,p),_.setSize(o,a),_.bindOutputTexture(g),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT);let m=f.segment.getExtentMerc();ms(m.southWest.lon,ja),c[0]=ja[0],d[0]=ja[1],ms(m.southWest.lat,ja),c[1]=ja[0],d[1]=ja[1],c[2]=2/m.getWidth(),c[3]=2/m.getHeight(),s.activate();let v=s._program,y=v.attributes,x=v.uniforms,b=f.layer._geometryHandler;t.uniform4fv(x.extentParamsHigh,c),t.uniform4fv(x.extentParamsLow,d),t.bindBuffer(t.ARRAY_BUFFER,b._polyVerticesHighBufferMerc),t.vertexAttribPointer(y.coordinatesHigh,b._polyVerticesHighBufferMerc.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,b._polyVerticesLowBufferMerc),t.vertexAttribPointer(y.coordinatesLow,b._polyVerticesLowBufferMerc.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,b._polyColorsBuffer),t.vertexAttribPointer(y.colors,b._polyColorsBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,b._polyIndexesBuffer),t.drawElements(t.TRIANGLES,b._polyIndexesBuffer.numItems,t.UNSIGNED_INT,0),u&&(_.bindOutputTexture(p),t.clearColor(0,0,0,0),t.clear(t.COLOR_BUFFER_BIT),t.bindBuffer(t.ARRAY_BUFFER,b._polyPickingColorsBuffer),t.vertexAttribPointer(y.colors,b._polyPickingColorsBuffer.itemSize,t.FLOAT,!1,0,0),t.drawElements(t.TRIANGLES,b._polyIndexesBuffer.numItems,t.UNSIGNED_INT,0)),_.bindOutputTexture(g),i.activate(),v=i._program,y=v.attributes,x=v.uniforms,t.uniform2fv(x.viewport,[o,a]),t.uniform4fv(x.extentParamsHigh,c),t.uniform4fv(x.extentParamsLow,d);let w=b._lineVerticesHighBufferMerc;t.bindBuffer(t.ARRAY_BUFFER,w),t.vertexAttribPointer(y.prevHigh,w.itemSize,t.FLOAT,!1,8,0),t.vertexAttribPointer(y.currentHigh,w.itemSize,t.FLOAT,!1,8,32),t.vertexAttribPointer(y.nextHigh,w.itemSize,t.FLOAT,!1,8,64),w=b._lineVerticesLowBufferMerc,t.bindBuffer(t.ARRAY_BUFFER,w),t.vertexAttribPointer(y.prevLow,w.itemSize,t.FLOAT,!1,8,0),t.vertexAttribPointer(y.currentLow,w.itemSize,t.FLOAT,!1,8,32),t.vertexAttribPointer(y.nextLow,w.itemSize,t.FLOAT,!1,8,64),t.bindBuffer(t.ARRAY_BUFFER,b._lineOrdersBuffer),t.vertexAttribPointer(y.order,b._lineOrdersBuffer.itemSize,t.FLOAT,!1,4,0),t.bindBuffer(t.ELEMENT_ARRAY_BUFFER,b._lineIndexesBuffer),t.bindBuffer(t.ARRAY_BUFFER,b._lineStrokesBuffer),t.vertexAttribPointer(y.thickness,b._lineStrokesBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,b._lineStrokeColorsBuffer),t.vertexAttribPointer(y.color,b._lineStrokeColorsBuffer.itemSize,t.FLOAT,!1,0,0),t.uniform1f(x.thicknessOutline,2),t.uniform1f(x.alpha,.54),t.drawElements(t.TRIANGLE_STRIP,b._lineIndexesBuffer.numItems,t.UNSIGNED_INT,0),t.uniform1f(x.thicknessOutline,1),t.uniform1f(x.alpha,1),t.drawElements(t.TRIANGLE_STRIP,b._lineIndexesBuffer.numItems,t.UNSIGNED_INT,0),t.bindBuffer(t.ARRAY_BUFFER,b._lineThicknessBuffer),t.vertexAttribPointer(y.thickness,b._lineThicknessBuffer.itemSize,t.FLOAT,!1,0,0),t.bindBuffer(t.ARRAY_BUFFER,b._lineColorsBuffer),t.vertexAttribPointer(y.color,b._lineColorsBuffer.itemSize,t.FLOAT,!1,0,0),t.uniform1f(x.thicknessOutline,2),t.uniform1f(x.alpha,.54),t.drawElements(t.TRIANGLE_STRIP,b._lineIndexesBuffer.numItems,t.UNSIGNED_INT,0),t.uniform1f(x.thicknessOutline,1),t.uniform1f(x.alpha,1),t.drawElements(t.TRIANGLE_STRIP,b._lineIndexesBuffer.numItems,t.UNSIGNED_INT,0),u&&(_.bindOutputTexture(p),t.uniform1f(x.thicknessOutline,8),t.bindBuffer(t.ARRAY_BUFFER,b._linePickingColorsBuffer),t.vertexAttribPointer(y.color,b._linePickingColorsBuffer.itemSize,t.FLOAT,!1,0,0),t.drawElements(t.TRIANGLE_STRIP,b._lineIndexesBuffer.numItems,t.UNSIGNED_INT,0))}else f.isLoading=!1;u=window.performance.now()-g}t.enable(t.DEPTH_TEST),t.enable(t.CULL_FACE),_.deactivate()}}add(e){this._queue.push(e)}remove(e){}get queueSize(){return this._queue.length}}class qa extends Ri{constructor(e={}){super(e.name),this._renderingFadingNodes=(e,t,i,s,n,r,o)=>{let a=0===n,l=this.terrain.equalizeVertices;for(let h=0,c=i._fadingNodes.length;h<c;h++){let c=i._fadingNodes[h].segment;this._fadingNodes.has(i._fadingNodes[0].__id)&&!e.has(c.node.__id)&&(e.set(c.node.__id,!0),c._transitionOpacity<1?r.push(c):a?(l&&c.equalize(),c.readyToEngage&&c.engage(),c.screenRendering(t,s,n),o.push(c)):c.screenRendering(t,s,n,this.transparentTexture,!0))}},this._renderingFadingNodesNoDepth=(e,t,i,s,n,r)=>{let o=0===n,a=this.terrain.equalizeVertices,l=t.gl;l.disable(l.DEPTH_TEST);for(let l=0,h=i._fadingNodes.length;l<h;l++){let h=i._fadingNodes[l].segment;this._fadingNodes.has(i._fadingNodes[0].__id)&&!e.has(h.node.__id)&&(e.set(h.node.__id,!0),o?(a&&h.equalize(),h.readyToEngage&&h.engage(),h.screenRendering(t,s,n),r.push(h)):h.screenRendering(t,s,n,this.transparentTexture,!0))}l.enable(l.DEPTH_TEST)},this._atmosphere=new jo(e.atmosphereParameters),this._prevNodes=new Map,this._currNodes=new Map,this.transitionTime=580,this.ellipsoid=e.ellipsoid||ce,this.lightEnabled=!0,this._planetRadius2=(this.ellipsoid.getPolarSize()-1e4)*(this.ellipsoid.getPolarSize()-1e4),this._layers=[],this._updateLayer=!1,this.visibleTileLayers=[],this.visibleVectorLayers=[],this._visibleVectorLayersByDepthOrder=[],this._visibleTileLayerSlices=[],this._visibleEntityCollections=[[]],this.baseLayer=null,this.terrain=null,this.camera=new Ua(this,{frustums:e.frustums,eye:new oe(25e6,0,0),look:oe.ZERO,up:oe.NORTH,minAltitude:e.minAltitude,maxAltitude:e.maxAltitude}),this.maxEqualZoomAltitude=e.maxEqualZoomAltitude||15e6,this.minEqualZoomAltitude=e.minEqualZoomAltitude||1e4,this.minEqualZoomCameraSlope=e.minEqualZoomCameraSlope||.8,this.mousePositionOnEarth=new oe,this.emptyTexture=null,this.transparentTexture=null,this.defaultTexture=null,this.minCurrZoom=o,this.maxCurrZoom=a,this._viewExtent=new te(new I(180,180),new I(-180,-180)),this._skipPreRender=!1,this._initialViewExtent=null,this._createdNodesCount=0,this._renderedNodes=[],this._renderedNodesInFrustum=[],this._fadingNodes=new Map,this._fadingNodesInFrustum=[],this._fadingOpaqueSegments=[],this.layerLock=new Rn,this.terrainLock=new Rn,this._heightFactor=1,this._indexesCache=[],this._indexesCacheToRemove=[],this._indexesCacheToRemoveCounter=0,this._textureCoordsBufferCache=[],this.quadTreeStrategy=e.quadTreeStrategyPrototype?new e.quadTreeStrategyPrototype(this):new Sa(this),this._nightTexture=null,this._specularTexture=null;let t=Se(e.ambient,new oe(.2,.2,.3)),i=Se(e.diffuse,new oe(1,1,1)),s=Se(e.specular,new oe(63e-5,55e-5,32e-5)),n=e.shininess||18;this._ambient=new Float32Array([t.x,t.y,t.z]),this._diffuse=new Float32Array([i.x,i.y,i.z]),this._specular=new Float32Array([s.x,s.y,s.z,n]),this._maxGridSize=Math.log2(e.maxGridSize||256),this.SLICE_SIZE=4,this.SLICE_SIZE_4=4*this.SLICE_SIZE,this.SLICE_SIZE_3=3*this.SLICE_SIZE,this._lodSize=250,this._curLodSize=250,this._minLodSize=312,this._maxLodSize=190,this._pickingColorArr=new Float32Array(this.SLICE_SIZE_4),this._samplerArr=new Int32Array(this.SLICE_SIZE),this._pickingMaskArr=new Int32Array(this.SLICE_SIZE),this._geoImageCreator=new Ra(this),this._vectorTileCreator=new Wa(this),this._normalMapCreator=new Ia(this),this._terrainWorker=new Ga(3),this._plainSegmentWorker=new Da(3),this._tileLoader=new ka(e.maxLoadingRequests||12),this._memKey=new Bn,this.events=Mt($a),this._distBeforeMemClear=0,this._prevCamEye=new oe,this._initialized=!1,this.always=[],this._renderCompleted=!1,this._renderCompletedActivated=!1,this._terrainCompleted=!1,this._terrainCompletedActivated=!1,this._collectRenderNodesIsActive=!0,this.nightTextureCoefficient=2,this._renderScreenNodesPASS=this._renderScreenNodesPASSNoAtmos,this._renderScreenNodesWithHeightPASS=this._renderScreenNodesWithHeightPASSNoAtmos,this._atmosphereEnabled=e.atmosphereEnabled||!1,this._atmosphereMaxMinOpacity=new Float32Array([.95,.28]),this.solidTextureOne=null,this.solidTextureTwo=null,this._nightTextureSrc=e.nightTextureSrc||null,this._specularTextureSrc=e.specularTextureSrc||null,this._transitionOpacityEnabled=null==e.transitionOpacityEnabled||e.transitionOpacityEnabled}get terrainReady(){return this._terrainCompleted&&this._terrainCompletedActivated}get maxGridSize(){return this._maxGridSize}getNorthFrameRotation(e){return this.getFrameRotation(e)}getFrameRotation(e){return this.ellipsoid.getNorthFrameRotation(e)}set atmosphereMaxOpacity(e){this._atmosphereMaxMinOpacity[0]=e}get atmosphereMaxOpacity(){return this._atmosphereMaxMinOpacity[0]}set atmosphereMinOpacity(e){this._atmosphereMaxMinOpacity[1]=e}get atmosphereMinOpacity(){return this._atmosphereMaxMinOpacity[1]}set atmosphereEnabled(e){e!=this._atmosphereEnabled&&(this._atmosphereEnabled=e,this._initializeAtmosphere())}get atmosphereEnabled(){return this._atmosphereEnabled}set diffuse(e){let t=Se(e);this._diffuse=new Float32Array(t.toArray())}set ambient(e){let t=Se(e);this._ambient=new Float32Array(t.toArray())}set specular(e){let t=Se(e);this._specular=new Float32Array([t.x,t.y,t.y,this._specular[3]])}set shininess(e){this._specular[3]=e}get normalMapCreator(){return this._normalMapCreator}get layers(){return[...this._layers]}getLayers(){return this.layers}get sun(){if(this.renderer&&this.renderer.controls.sun)return this.renderer.controls.sun}get sunPos(){return this.sun.sunlight.getPosition()}addControl(e){e.planet=this,e.addTo(this.renderer)}get lodSize(){return this._lodSize}setLodSize(e,t,i){this._maxLodSize=i||this._maxLodSize,this._minLodSize=t||this._minLodSize,this._curLodSize=e,this._renderCompletedActivated=!1,this._terrainCompletedActivated=!1}addControls(e){for(let t=0;t<e.length;t++)this.addControl(e[t])}getLayerByName(e){for(let t=0,i=this._layers.length;t<i;t++)if(e===this._layers[t].name)return this._layers[t]}addLayer(e){e.addTo(this)}_onLayerVisibilityChanged(e){this.events.dispatch(this.events.layervisibilitychange,e)}addLayers(e){for(let t=0,i=e.length;t<i;t++)this.addLayer(e[t])}removeLayer(e){e.remove()}_clearLayerMaterial(e){this.quadTreeStrategy.clearLayerMaterial(e)}setBaseLayer(e){this.baseLayer?this.baseLayer.isEqual(e)||(this.baseLayer.setVisibility(!1),this.baseLayer=e,e.setVisibility(!0),this.events.dispatch(this.events.baselayerchange,e)):(this.baseLayer=e,this.baseLayer.setVisibility(!0),this.events.dispatch(this.events.baselayerchange,e))}setHeightFactor(e){this._renderCompletedActivated=!1,this._terrainCompletedActivated=!1,this._heightFactor!==e&&(this._heightFactor=e,this.quadTreeStrategy.destroyBranches(),this._clearRenderedNodeList(),this._clearRenderNodesInFrustum())}getHeightFactor(){return this._heightFactor}setTerrain(e){this._renderCompletedActivated=!1,this._terrainCompletedActivated=!1,this._initialized&&this.memClear(),this.terrain&&(this.terrain.abortLoading(),this.terrain.clearCache(),this.terrain._planet=null),this.terrain=e,this.terrain._planet=this,this.quadTreeStrategy.destroyBranches(),e._geoid.model?(this._plainSegmentWorker.setGeoid(e.getGeoid()),e._isReady=!0):Ma.loadModel(e.geoid.src).then((t=>{e.geoid.setModel(t),this._plainSegmentWorker.setGeoid(e.getGeoid()),e._isReady=!0})).catch((e=>{console.warn(e)}))}initAtmosphereShader(e){if(this.renderer&&this.renderer.handler&&this._atmosphereEnabled){let t=this.renderer.handler;t.isWebGl2()?(t.removeProgram("drawnode_screen_wl"),t.addProgram(Oo(e),!0)):console.warn("Atmosphere WebGL2 only")}}get atmosphereControl(){return this._atmosphere}_initializeAtmosphere(){if(!this.renderer)return;let e=this.renderer.handler;e.removeProgram("drawnode_screen_wl"),this._atmosphereEnabled?(this._renderScreenNodesPASS=this._renderScreenNodesPASSAtmos,this._renderScreenNodesWithHeightPASS=this._renderScreenNodesWithHeightPASSAtmos,this.renderer.controls.Atmosphere||this.addControl(this._atmosphere),this._atmosphere.activate(),e.isWebGl2()?e.addProgram(Oo(this._atmosphere.parameters),!0):e.addProgram(Ho(),!0),this.renderer.controls.SimpleSkyBackground&&this.renderer.controls.SimpleSkyBackground.deactivate()):(this._renderScreenNodesPASS=this._renderScreenNodesPASSNoAtmos,this._renderScreenNodesWithHeightPASS=this._renderScreenNodesWithHeightPASSNoAtmos,this._atmosphere.deactivate(),this.renderer.controls.SimpleSkyBackground?this.renderer.controls.SimpleSkyBackground.activate():this.addControl(new Kn),e.isWebGl2()?e.addProgram(new Ni("drawnode_screen_wl",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",height:"float",uGlobalTextureCoord:"vec4",uNormalMapBias:"vec3",samplerCount:"int",tileOffsetArr:"vec4",layerOpacityArr:"float",samplerArr:"sampler2darray",defaultTexture:"sampler2d",uNormalMap:"sampler2d",nightTexture:"sampler2d",specularTexture:"sampler2d",lightPosition:"vec3",diffuse:"vec3",ambient:"vec3",specular:"vec4",camHeight:"float",nightTextureCoefficient:"float",transitionOpacity:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"#version 300 es\n\n precision highp float;\n\n in vec3 aVertexPositionHigh;\n in vec3 aVertexPositionLow;\n in vec2 aTextureCoord;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec4 uGlobalTextureCoord;\n uniform vec3 uNormalMapBias;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n out vec4 vTextureCoord;\n out vec3 v_vertex;\n out vec3 cameraPosition;\n out vec2 vGlobalTextureCoord;\n out float v_height;\n\n void main(void) {\n\n vec3 aVertexPosition = aVertexPositionHigh + aVertexPositionLow; \n vec3 nh = height * normalize(aVertexPosition);\n \n vTextureCoord.xy = aTextureCoord;\n vGlobalTextureCoord = uGlobalTextureCoord.xy + (uGlobalTextureCoord.zw - uGlobalTextureCoord.xy) * aTextureCoord;\n vTextureCoord.zw = uNormalMapBias.z * ( aTextureCoord + uNormalMapBias.xy );\n\n cameraPosition = eyePositionHigh + eyePositionLow;\n \n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n v_height = height;\n v_vertex = aVertexPosition + nh;\n \n gl_Position = projectionMatrix * viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:`#version 300 es\n\n precision highp float;\n \n\n #define SLICE_SIZE 5\n\n uniform vec4 specular;\n uniform vec3 diffuse;\n uniform vec3 ambient; \n\n uniform sampler2D uNormalMap;\n uniform sampler2D nightTexture;\n uniform sampler2D specularTexture;\n uniform sampler2D defaultTexture;\n uniform sampler2D samplerArr[SLICE_SIZE];\n\n uniform vec4 tileOffsetArr[SLICE_SIZE];\n uniform vec3 lightPosition;\n uniform float layerOpacityArr[SLICE_SIZE];\n\n uniform int samplerCount;\n uniform float nightTextureCoefficient;\n \n uniform float transitionOpacity;\n \n uniform float camHeight;\n\n in vec4 vTextureCoord;\n in vec3 v_vertex;\n in vec3 cameraPosition;\n in vec2 vGlobalTextureCoord;\n in float v_height;\n\n vec3 sunPos;\n\n layout(location = 0) out vec4 diffuseColor;\n\n ${Do}\n\n ${Fo}\n \n ${ds}\n \n void main(void) {\n \n sunPos = lightPosition;\n \n vec3 texNormal = texture(uNormalMap, vTextureCoord.zw).rgb;\n vec3 normal = normalize((texNormal - 0.5) * 2.0);\n \n float minH = 1200000.0;\n float maxH = minH * 3.0;\n float nightCoef = getLerpValue(minH, maxH, camHeight) * nightTextureCoefficient;\n \n // if(camHeight > 6000000.0)\n // {\n // normal = normalize(v_vertex);\n // }\n \n vec3 lightDir = normalize(sunPos);\n vec3 viewDir = normalize(cameraPosition - v_vertex);\n \n float overGround = 1.0 - step(0.1, v_height);\n\n float shininess = texture( specularTexture, vGlobalTextureCoord.st ).r * 255.0 * overGround;\n vec3 reflectionDirection = reflect(-lightDir, normal);\n float reflection = max( dot(reflectionDirection, viewDir), 0.0);\n vec3 spec = specular.rgb * pow( reflection, specular.w) * shininess; \n float diffuseLightWeighting = max(dot(normal, lightDir), 0.0); \n vec4 nightImageColor = texture( nightTexture, vGlobalTextureCoord.st );\n vec3 night = nightStep * (.18 - diffuseLightWeighting * 3.0) * nightImageColor.rgb * nightCoef;\n night *= overGround * step(0.0, night); \n vec4 lightWeighting = vec4(ambient + diffuse * diffuseLightWeighting + night, 1.0);\n \n diffuseColor = texture( defaultTexture, vTextureCoord.xy );\n \n if( samplerCount == 0 ) {\n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n vec4 src;\n\n blend(diffuseColor, samplerArr[0], tileOffsetArr[0], layerOpacityArr[0]);\n if( samplerCount == 1 ) { \n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[1], tileOffsetArr[1], layerOpacityArr[1]);\n if( samplerCount == 2 ) {\n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[2], tileOffsetArr[2], layerOpacityArr[2]);\n if( samplerCount == 3 ) {\n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[3], tileOffsetArr[3], layerOpacityArr[3]);\n if( samplerCount == 4 ) {\n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n return;\n }\n\n blend(diffuseColor, samplerArr[4], tileOffsetArr[4], layerOpacityArr[4]);\n diffuseColor = diffuseColor * lightWeighting + vec4(spec, 0.0);\n diffuseColor *= transitionOpacity;\n }`}),!0):e.addProgram(Ho(),!0))}_initializeShaders(){let e=this.renderer.handler;e.addProgram(new Ni("drawnode_screen_nl",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",samplerCount:"int",tileOffsetArr:"vec4",layerOpacityArr:"float",samplerArr:"sampler2darray",defaultTexture:"sampler2d",height:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"precision highp float;\n \n attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n attribute vec2 aTextureCoord;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n varying vec2 vTextureCoord;\n\n void main(void) {\n\n vTextureCoord = aTextureCoord;\n vec3 nh = height * normalize(aVertexPositionHigh + aVertexPositionLow);\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n mat4 m = projectionMatrix * viewMatrixRTE;\n \n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n \n // This is works for Mac Chrome, prevent some weird optimization I suppose\n gl_Position = m * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:`precision highp float;\n #define SLICE_SIZE 5\n uniform vec4 tileOffsetArr[SLICE_SIZE];\n uniform float layerOpacityArr[SLICE_SIZE];\n uniform sampler2D defaultTexture;\n uniform sampler2D samplerArr[SLICE_SIZE];\n uniform int samplerCount;\n varying vec2 vTextureCoord;\n\n ${No}\n\n void main(void) {\n gl_FragColor = texture2D( defaultTexture, vTextureCoord );\n if( samplerCount == 0 ) return;\n\n vec4 src;\n\n blend(gl_FragColor, samplerArr[0], tileOffsetArr[0], layerOpacityArr[0]);\n if( samplerCount == 1 ) return;\n\n blend(gl_FragColor, samplerArr[1], tileOffsetArr[1], layerOpacityArr[1]);\n if( samplerCount == 2 ) return;\n\n blend(gl_FragColor, samplerArr[2], tileOffsetArr[2], layerOpacityArr[2]);\n if( samplerCount == 3 ) return;\n\n blend(gl_FragColor, samplerArr[3], tileOffsetArr[3], layerOpacityArr[3]);\n if( samplerCount == 4 ) return;\n\n blend(gl_FragColor, samplerArr[4], tileOffsetArr[4], layerOpacityArr[4]);\n }`}),!0),e.addProgram(new Ni("drawnode_colorPicking",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",eyePositionHigh:"vec3",eyePositionLow:"vec3",samplerCount:"int",tileOffsetArr:"vec4",samplerArr:"sampler2darray",pickingMaskArr:"sampler2darray",pickingColorArr:"vec4",height:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3",aTextureCoord:"vec2"},vertexShader:"precision highp float;\n \n attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n attribute vec2 aTextureCoord;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n varying vec2 vTextureCoord;\n\n void main(void) {\n\n vTextureCoord = aTextureCoord;\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n mat4 m = projectionMatrix * viewMatrixRTE;\n\n vec3 nh = height * normalize(aVertexPositionHigh + aVertexPositionLow);\n\n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n\n gl_Position = m * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n }",fragmentShader:"precision highp float;\n #define SLICE_SIZE 5\n uniform vec4 tileOffsetArr[SLICE_SIZE];\n uniform vec4 pickingColorArr[SLICE_SIZE];\n uniform sampler2D samplerArr[SLICE_SIZE];\n uniform sampler2D pickingMaskArr[SLICE_SIZE];\n uniform int samplerCount;\n varying vec2 vTextureCoord;\n\n #define blendPicking(DEST, OFFSET, SAMPLER, MASK, COLOR, OPACITY) tc = OFFSET.xy + vTextureCoord.xy * OFFSET.zw; t = texture2D(SAMPLER, tc); p = texture2D(MASK, tc); DEST = mix(DEST, vec4(max(COLOR.rgb, p.rgb), OPACITY), (t.a == 0.0 ? 0.0 : 1.0) * COLOR.a);\n\n void main(void) {\n gl_FragColor = vec4(0.0);\n if( samplerCount == 0 ) return;\n\n vec2 tc;\n vec4 t;\n vec4 p;\n\n blendPicking(gl_FragColor, tileOffsetArr[0], samplerArr[0], pickingMaskArr[0], pickingColorArr[0], 1.0);\n if( samplerCount == 1 ) return;\n\n blendPicking(gl_FragColor, tileOffsetArr[1], samplerArr[1], pickingMaskArr[1], pickingColorArr[1], 1.0);\n if( samplerCount == 2 ) return;\n\n blendPicking(gl_FragColor, tileOffsetArr[2], samplerArr[2], pickingMaskArr[2], pickingColorArr[2], 1.0);\n if( samplerCount == 3 ) return;\n\n blendPicking(gl_FragColor, tileOffsetArr[3], samplerArr[3], pickingMaskArr[3], pickingColorArr[3], 1.0);\n if( samplerCount == 4 ) return;\n\n blendPicking(gl_FragColor, tileOffsetArr[4], samplerArr[4], pickingMaskArr[4], pickingColorArr[4], 1.0);\n }"}),!0),e.addProgram(new Ni("drawnode_depth",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",height:"float",eyePositionHigh:"vec3",eyePositionLow:"vec3",frustumPickingColor:"float"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3"},vertexShader:"#version 300 es\n \n precision highp float;\n\n in vec3 aVertexPositionHigh;\n in vec3 aVertexPositionLow;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n\n void main(void) {\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n mat4 m = projectionMatrix * viewMatrixRTE;\n\n vec3 nh = height * normalize(aVertexPositionHigh + aVertexPositionLow);\n\n vec3 eyePosition = eyePositionHigh + eyePositionLow;\n vec3 vertexPosition = aVertexPositionHigh + aVertexPositionLow;\n\n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n \n gl_Position = m * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0); \n }",fragmentShader:"#version 300 es\n \n precision highp float;\n \n uniform float frustumPickingColor;\n\n layout(location = 0) out vec4 frustumColor;\n layout(location = 1) out vec4 depthColor;\n\n void main(void) {\n frustumColor = vec4(frustumPickingColor, frustumPickingColor, frustumPickingColor, 1.0);\n depthColor = vec4(gl_FragCoord.z, gl_FragCoord.z, gl_FragCoord.z, 1.0);\n }"}),!0),e.addProgram(new Ni("drawnode_heightPicking",{uniforms:{projectionMatrix:"mat4",viewMatrix:"mat4",height:"float",eyePositionHigh:"vec3",eyePositionLow:"vec3"},attributes:{aVertexPositionHigh:"vec3",aVertexPositionLow:"vec3"},vertexShader:"precision highp float;\n\n attribute vec3 aVertexPositionHigh;\n attribute vec3 aVertexPositionLow;\n\n uniform mat4 projectionMatrix;\n uniform mat4 viewMatrix;\n uniform vec3 eyePositionHigh;\n uniform vec3 eyePositionLow;\n uniform float height;\n \n varying vec4 vert;\n\n void main(void) {\n\n mat4 viewMatrixRTE = viewMatrix;\n viewMatrixRTE[3] = vec4(0.0, 0.0, 0.0, 1.0);\n\n vec3 nh = height * normalize(aVertexPositionHigh + aVertexPositionLow);\n\n vec3 eyePosition = eyePositionHigh + eyePositionLow;\n vec3 vertexPosition = aVertexPositionHigh + aVertexPositionLow;\n\n vec3 highDiff = aVertexPositionHigh - eyePositionHigh;\n vec3 lowDiff = aVertexPositionLow - eyePositionLow + nh;\n \n vert = viewMatrixRTE * vec4(highDiff * step(1.0, length(highDiff)) + lowDiff, 1.0);\n \n gl_Position = projectionMatrix * vert; \n }",fragmentShader:"precision highp float;\n \n varying vec4 vert;\n\n vec3 encode24(highp float f) {\n float F = abs(f);\n float s = step( 0.0, -f );\n float e = floor( log2(F) );\n float m = exp2(- e) * F;\n e = floor( log2(F) + 127.0 ) + floor( log2(m) );\n return vec3(\n ( 128.0 * s + floor( e * exp2(-1.0) ) ) / 255.0,\n ( 128.0 * mod( e, 2.0 ) + mod( floor( m * 128.0 ), 128.0 ) ) / 255.0,\n floor( mod( floor( m * exp2( 23.0 - 8.0) ), exp2(8.0) ) ) / 255.0);\n }\n\n void main(void) {\n gl_FragColor = vec4(encode24(length(vert.xyz)), 1.0);\n }"}),!0),this.renderer.addPickingCallback(this,this._renderColorPickingFramebufferPASS),this.renderer.addDepthCallback(this,this._renderDepthFramebufferPASS)}_onLayerLoadend(e){this.events.dispatch(this.events.layerloadend,e)}init(){this._tileLoader.events.on("layerloadend",this._onLayerLoadend,this),ko().setMaxGridSize(this._maxGridSize);const e=this._maxGridSize;let t=0;for(let i=0;i<=e;i++){!this._indexesCache[i]&&(this._indexesCache[i]=new Array(e));for(let s=0;s<=e;s++){!this._indexesCache[i][s]&&(this._indexesCache[i][s]=new Array(e));for(let n=0;n<=e;n++){!this._indexesCache[i][s][n]&&(this._indexesCache[i][s][n]=new Array(e));for(let r=0;r<=e;r++){!this._indexesCache[i][s][n][r]&&(this._indexesCache[i][s][n][r]=new Array(e));for(let o=0;o<=e;o++){let e={buffer:null};if(i>=1&&i===s&&i===n&&i===r&&i===o){let t=ko().createSegmentIndexes(i,[s,n,r,o]);e.buffer=this.renderer.handler.createElementArrayBuffer(t,1)}else this._indexesCacheToRemove[t++]=e;this._indexesCache[i][s][n][r][o]=e}}}}}this.renderer.events.on("resize",(()=>{this._renderCompletedActivated=!1,this._terrainCompletedActivated=!1})),this.renderer.events.on("drawtransparent",(()=>{this._renderScreenNodesWithHeightPASS()})),this._textureCoordsBufferCache=[];let i=ko().initTextureCoordsTable(e+1);for(let t=0;t<=e;t++)this._textureCoordsBufferCache[t]=this.renderer.handler.createArrayBuffer(i[t],2,(1+(1<<t))*(1+(1<<t)));this.renderer.handler.createDefaultTexture(null,(e=>{this.solidTextureOne=e,this.solidTextureTwo=e})),this.transparentTexture=this.renderer.handler.transparentTexture,this._renderedNodesInFrustum=new Array(this.camera.frustums.length);for(let e=0,t=this._renderedNodesInFrustum.length;e<t;e++)this._renderedNodesInFrustum[e]=[];if(this.quadTreeStrategy.init(),this.drawMode=this.renderer.handler.gl.TRIANGLE_STRIP,this._initializeShaders(),this._initializeAtmosphere(),this._updateVisibleLayers(),this._nightTextureSrc){let e=new Image;e.crossOrigin="Anonymous",e.onload=()=>{this._nightTexture=this.renderer.handler.createTextureDefault(e),this._nightTexture.default=!0},e.src=this._nightTextureSrc}if(this._specularTextureSrc){let e=new Image;e.crossOrigin="Anonymous",e.onload=()=>{this._specularTexture=this.renderer.handler.createTextureDefault(e),this._specularTexture.default=!0},e.src=this._specularTextureSrc}this._geoImageCreator.init(),this._vectorTileCreator.init(),this._normalMapCreator.init(),this.renderer.events.on("draw",this._globalPreDraw,this,-100),this._preRender(),this.renderer.events.on("postdraw",(()=>{this._checkRendercompleted()})),this.initLayers(),this._initialized=!0,this._initialViewExtent&&this.viewExtent(this._initialViewExtent),this.renderer.activeCamera=this.camera,this.camera.bindRenderer(this.renderer),this.camera.update()}initLayers(){let e=[...this._layers];for(let t=0;t<e.length;t++)this.removeLayer(e[t]),this.addLayer(e[t])}_clearIndexesCache(){this._indexesCacheToRemoveCounter=0;let e=this._indexesCacheToRemove,t=this.renderer.handler.gl;for(let i=0,s=e.length;i<s;i++){let s=e[i];t.deleteBuffer(s.buffer),s.buffer=null}}_preRender(){this.quadTreeStrategy.preRender(),this._preLoad()}_preLoad(){this._clearRenderedNodeList(),this._skipPreRender=!1,this.quadTreeStrategy.preLoad()}createDefaultTextures(e,t){this.renderer.handler.gl.deleteTexture(this.solidTextureOne),this.renderer.handler.gl.deleteTexture(this.solidTextureTwo),this.renderer.handler.createDefaultTexture(e,(e=>{this.solidTextureOne=e})),this.renderer.handler.createDefaultTexture(t,(e=>{this.solidTextureTwo=e}))}_getLayerAttributionHTML(e){return`<div class="og-attribution__layer">${e.getAttribution()}</div>`}updateAttributionsList(){let e="";for(let t=0,i=this._layers.length;t<i;t++){let i=this._layers[t];i.getVisibility()&&i.getAttribution().length&&(e+=this._getLayerAttributionHTML(i))}this._applyAttribution(e)}updateVisibleLayers(){this._updateLayer=!0}_updateVisibleLayers(){this.visibleTileLayers=[],this.visibleTileLayers.length=0,this.visibleVectorLayers=[],this.visibleVectorLayers.length=0;let e="";for(let t=0,i=this._layers.length;t<i;t++){let i=this._layers[t];i.getVisibility()?(i.isBaseLayer()&&(this.createDefaultTextures(i._defaultTextures[0],i._defaultTextures[1]),this.baseLayer=i),i.hasImageryTiles()&&this.visibleTileLayers.push(i),i.isVector&&this.visibleVectorLayers.push(i),i.getAttribution().length&&(e+=this._getLayerAttributionHTML(i))):i._fading&&i._fadingOpacity>0&&(i.hasImageryTiles()&&this.visibleTileLayers.push(i),i.isVector&&this.visibleVectorLayers.push(i))}this._applyAttribution(e),this._sortLayers()}_applyAttribution(e){this.renderer&&this.renderer.div&&(e.length?this.renderer.div.attributions.innerHTML!==e&&(this.renderer.div.attributions.innerHTML=e):this.renderer.div.attributions.innerHTML="")}_sortLayers(){this.visibleVectorLayers.sort(((e,t)=>e.getZIndex()-t.getZIndex()||e.getHeight()-t.getHeight()));let e={0:[]};for(const t of this.visibleVectorLayers)e[t.depthOrder]||(e[t.depthOrder]=[]),e[t.depthOrder].push(t);if(this._visibleVectorLayersByDepthOrder.length=0,this._visibleVectorLayersByDepthOrder=[],this._visibleVectorLayersByDepthOrder=Object.keys(e).sort(((e,t)=>Number(e)-Number(t))).map((t=>e[Number(t)])),this._visibleTileLayerSlices=[],this._visibleTileLayerSlices.length=0,this.visibleTileLayers.length){this.visibleTileLayers.sort(((e,t)=>e.getHeight()-t.getHeight()||e.getZIndex()-t.getZIndex()));let e=-1,t=this.visibleTileLayers[0].getHeight();for(let i=0,s=this.visibleTileLayers.length;i<s;i++)i%this.SLICE_SIZE!=0&&this.visibleTileLayers[i].getHeight()===t||(e++,this._visibleTileLayerSlices[e]=[],t=this.visibleTileLayers[i].getHeight()),this._visibleTileLayerSlices[e].push(this.visibleTileLayers[i])}}_clearRenderedNodeList(){this._renderedNodes.length=0,this._renderedNodes=[]}_clearRenderNodesInFrustum(){for(let e=0,t=this._renderedNodesInFrustum.length;e<t;e++)this._renderedNodesInFrustum[e].length=0,this._renderedNodesInFrustum[e]=[]}_collectRenderedNodesMaxZoom(e){if(e.slope>this.minEqualZoomCameraSlope&&e._lonLat.height<this.maxEqualZoomAltitude&&e._lonLat.height>this.minEqualZoomAltitude){this.minCurrZoom=this.maxCurrZoom;let t=this._renderedNodes,i=this._renderedNodesInFrustum,s=[];this._clearRenderNodesInFrustum(),this._renderedNodes=[];for(let n=0,r=t.length;n<r;n++){let r=t[n],o=r.segment.centerNormal.dot(e.getBackward());if(r.segment.tileZoom===this.maxCurrZoom||o<.81){this._renderedNodes.push(r);let e=0,t=r.inFrustum;for(;t;)1&t&&i[e].push(r),e++,t>>=1}else s.push(r)}for(let t=0,i=s.length;t<i;t++)s[t].renderTree(e,this.maxCurrZoom,null,!1,s[t])}}set transitionOpacityEnabled(e){this._transitionOpacityEnabled=e}get transitionOpacityEnabled(){return this._transitionOpacityEnabled}_collectRenderNodes(e){if(this._lodSize=T(e.slope<0?0:e.slope,this._curLodSize,this._minLodSize),e._insideSegment=null,this._clearRenderedNodeList(),this._clearRenderNodesInFrustum(),this._viewExtent.southWest.set(180,180),this._viewExtent.northEast.set(-180,-180),this.minCurrZoom=o,this.maxCurrZoom=a,this.quadTreeStrategy.collectRenderNodes(),this._collectRenderedNodesMaxZoom(e),this._fadingNodes.clear(),this._transitionOpacityEnabled){let e=[];for(let t=0;t<this._renderedNodes.length;t++){let i=this._renderedNodes[t];if(i._collectFadingNodes(),i._refreshTransitionOpacity(),i.segment._transitionOpacity>=1)i.clearNeighbors(),i.getRenderedNodesNeighbors(e),e.push(i);else for(let t=0;t<i._fadingNodes.length;t++){let s=i._fadingNodes[t];s.segment&&s.segment._transitionOpacity>=1&&(s.clearNeighbors(),s.getRenderedNodesNeighbors(e),e.push(s))}}}}_renderScreenNodesPASSNoAtmos(){let e=this.renderer.activeCamera,t=this._setUniformsNoAtmos(e);this._renderingScreenNodes(t,e,this._renderedNodesInFrustum[e.currentFrustumIndex])}_renderScreenNodesPASSAtmos(){let e=this.renderer.activeCamera,t=this._setUniformsAtmos(e);this._renderingScreenNodes(t,e,this._renderedNodesInFrustum[e.currentFrustumIndex])}_renderScreenNodesWithHeightPASSNoAtmos(){let e=this.renderer.activeCamera,t=this._setUniformsNoAtmos(e);this._renderingScreenNodesWithHeight(t,e,this._renderedNodesInFrustum[e.currentFrustumIndex])}_renderScreenNodesWithHeightPASSAtmos(){let e=this.renderer.activeCamera,t=this._setUniformsAtmos(e);this._renderingScreenNodesWithHeight(t,e,this._renderedNodesInFrustum[e.currentFrustumIndex])}_globalPreDraw(){let e=this.camera;this._distBeforeMemClear+=this._prevCamEye.distance(e.eye),this._prevCamEye.copy(e.eye),e.checkFly(),this._createdNodesCount>200&&this._distBeforeMemClear>1e3&&(this.terrain.clearCache(),this.memClear()),this._indexesCacheToRemoveCounter>600&&this._clearIndexesCache()}preFrame(){this._updateLayer&&(this._updateLayer=!1,this._updateVisibleLayers()),this.camera.isFirstPass&&(this.camera.update(),this._skipPreRender&&this._collectRenderNodesIsActive&&this._collectRenderNodes(this.camera),this._skipPreRender=!0,this._normalMapCreator.frame(),this._geoImageCreator.frame(),this._vectorTileCreator.frame(),this.camera.checkTerrainCollision(),this.camera.update(),this.events.dispatch(this.events.draw,this),this._collectVectorLayerCollections());for(let e=0;e<this._visibleEntityCollections.length;e++)this.drawEntityCollections(this._visibleEntityCollections[e],e)}frame(){this._renderScreenNodesPASS()}_checkRendercompleted(){this._renderCompleted?this._renderCompletedActivated||(this._renderCompletedActivated=!0,this.events.dispatch(this.events.rendercompleted,!0)):this._renderCompletedActivated=!1,this._renderCompleted=!0,this._terrainCompleted?this._terrainCompletedActivated||(this._terrainCompletedActivated=!0,this.events.dispatch(this.events.terraincompleted,!0)):this._terrainCompletedActivated=!1,this._terrainCompleted=!0}lockQuadTree(){this._collectRenderNodesIsActive=!1,this.camera.setTerrainCollisionActivity(!1)}unlockQuadTree(){this._collectRenderNodesIsActive=!0,this.camera.setTerrainCollisionActivity(!0)}_setUniformsNoAtmos(e){let t,i,s=this.renderer,n=s.handler,r=n.gl;return r.enable(r.CULL_FACE),s.enableBlendOneSrcAlpha(),this.lightEnabled?(n.programs.drawnode_screen_wl.activate(),t=n.programs.drawnode_screen_wl._program,i=t.uniforms,r.uniform3fv(i.lightPosition,this._lightPosition),r.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),r.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix()),this.baseLayer?(r.uniform3fv(i.diffuse,this.baseLayer._diffuse||this._diffuse),r.uniform3fv(i.ambient,this.baseLayer._ambient||this._ambient),r.uniform4fv(i.specular,this.baseLayer._specular||this._specular),r.uniform1f(i.nightTextureCoefficient,this.baseLayer.nightTextureCoefficient||this.nightTextureCoefficient)):(r.uniform3fv(i.diffuse,this._diffuse),r.uniform3fv(i.ambient,this._ambient),r.uniform4fv(i.specular,this._specular),r.uniform1f(i.nightTextureCoefficient,this.nightTextureCoefficient)),r.activeTexture(r.TEXTURE0+this.SLICE_SIZE),r.bindTexture(r.TEXTURE_2D,this._nightTexture||this.transparentTexture),r.uniform1i(i.nightTexture,this.SLICE_SIZE),r.activeTexture(r.TEXTURE0+this.SLICE_SIZE+1),r.bindTexture(r.TEXTURE_2D,this._specularTexture||this.transparentTexture),r.uniform1i(i.specularTexture,this.SLICE_SIZE+1),r.uniform1f(i.camHeight,e.getHeight())):(n.programs.drawnode_screen_nl.activate(),t=n.programs.drawnode_screen_nl._program,i=t.uniforms,r.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),r.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix())),r.uniform3fv(i.eyePositionHigh,e.eyeHigh),r.uniform3fv(i.eyePositionLow,e.eyeLow),t}_setUniformsAtmos(e){let t,i,s=this.renderer,n=s.handler,r=n.gl;return r.enable(r.CULL_FACE),s.enableBlendOneSrcAlpha(),this.lightEnabled?(n.programs.drawnode_screen_wl.activate(),t=n.programs.drawnode_screen_wl._program,i=t.uniforms,r.uniform3fv(i.lightPosition,this._lightPosition),r.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),r.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix()),this.baseLayer?(r.uniform3fv(i.diffuse,this.baseLayer._diffuse||this._diffuse),r.uniform3fv(i.ambient,this.baseLayer._ambient||this._ambient),r.uniform4fv(i.specular,this.baseLayer._specular||this._specular),r.uniform1f(i.nightTextureCoefficient,this.baseLayer.nightTextureCoefficient||this.nightTextureCoefficient)):(r.uniform3fv(i.diffuse,this._diffuse),r.uniform3fv(i.ambient,this._ambient),r.uniform4fv(i.specular,this._specular),r.uniform1f(i.nightTextureCoefficient,this.nightTextureCoefficient)),r.uniform2fv(i.maxMinOpacity,this._atmosphereMaxMinOpacity),r.activeTexture(r.TEXTURE0+this.SLICE_SIZE),r.bindTexture(r.TEXTURE_2D,this._nightTexture||this.transparentTexture),r.uniform1i(i.nightTexture,this.SLICE_SIZE),r.activeTexture(r.TEXTURE0+this.SLICE_SIZE+1),r.bindTexture(r.TEXTURE_2D,this._specularTexture||this.transparentTexture),r.uniform1i(i.specularTexture,this.SLICE_SIZE+1),r.activeTexture(r.TEXTURE0+this.SLICE_SIZE+4),r.bindTexture(r.TEXTURE_2D,s.controls.Atmosphere._transmittanceBuffer.textures[0]),r.uniform1i(i.transmittanceTexture,this.SLICE_SIZE+4),r.activeTexture(r.TEXTURE0+this.SLICE_SIZE+5),r.bindTexture(r.TEXTURE_2D,s.controls.Atmosphere._scatteringBuffer.textures[0]),r.uniform1i(i.scatteringTexture,this.SLICE_SIZE+5),r.uniform1f(i.camHeight,e.getHeight())):(n.programs.drawnode_screen_nl.activate(),t=n.programs.drawnode_screen_nl._program,i=t.uniforms,r.uniformMatrix4fv(i.viewMatrix,!1,e.getViewMatrix()),r.uniformMatrix4fv(i.projectionMatrix,!1,e.getProjectionMatrix())),r.uniform3fv(i.eyePositionHigh,e.eyeHigh),r.uniform3fv(i.eyePositionLow,e.eyeLow),t}_renderingScreenNodes(e,t,i){let s=t.isFirstPass,n=this._visibleTileLayerSlices;if(n.length){let e=n[0];for(let t=e.length-1;t>=0;--t){let i=e[t];i._fading&&s&&i._refreshFadingOpacity()&&e.splice(t,1)}}let r=new Map,o=[],a=this.terrain.equalizeVertices,l=i.length;if(this._fadingOpaqueSegments=[],t.slope>.8||!this.terrain||this.terrain.isEmpty)for(;l--;){let t=i[l],s=t.segment;this._renderingFadingNodesNoDepth(r,e,t,n[0],0,this._fadingOpaqueSegments),a&&s.equalize(),s.readyToEngage&&s.engage(),s.screenRendering(e,n[0],0)}else{for(;l--;){let t=i[l],s=t.segment;this._renderingFadingNodes(r,e,t,n[0],0,o,this._fadingOpaqueSegments),s._transitionOpacity<1?o.push(s):(a&&s.equalize(),s.readyToEngage&&s.engage(),s.screenRendering(e,n[0],0))}for(let t=0;t<o.length;t++){let i=o[t];a&&i.equalize(),i.readyToEngage&&i.engage(),i.screenRendering(e,n[0],0)}}}_renderingScreenNodesWithHeight(e,t,i){let s=this.renderer.handler.gl,n=t.isFirstPass,r=this._visibleTileLayerSlices;s.enable(s.POLYGON_OFFSET_FILL),s.disable(s.CULL_FACE);let o=new Map,a=[];for(let t=1,l=r.length;t<l;t++){let l=r[t];for(let e=l.length-1;e>=0;--e){let t=l[e];t._fading&&n&&t._refreshFadingOpacity()&&l.splice(e,1)}s.polygonOffset(0,-t);let h=i.length;for(;h--;){let s=i[h];this._renderingFadingNodes(o,e,s,r[t],t,a),s.segment._transitionOpacity<1?s.segment.initSlice(t):s.segment.screenRendering(e,r[t],t,this.transparentTexture,!0)}}s.disable(s.POLYGON_OFFSET_FILL),s.enable(s.CULL_FACE)}_renderColorPickingFramebufferPASS(){let e,t=this.renderer,i=t.handler,s=i.gl;i.programs.drawnode_colorPicking.activate(),e=i.programs.drawnode_colorPicking._program;let n=e.uniforms,r=t.activeCamera;s.enable(s.CULL_FACE),s.uniformMatrix4fv(n.viewMatrix,!1,r.getViewMatrix()),s.uniformMatrix4fv(n.projectionMatrix,!1,r.getProjectionMatrix()),s.uniform3fv(n.eyePositionHigh,r.eyeHigh),s.uniform3fv(n.eyePositionLow,r.eyeLow);let o=this._renderedNodesInFrustum[r.getCurrentFrustum()],a=this._visibleTileLayerSlices,l=o.length;for(;l--;)o[l].segment._transitionOpacity>=1&&o[l].segment.colorPickingRendering(e,a[0],0);for(let t=0;t<this._fadingOpaqueSegments.length;++t)this._fadingOpaqueSegments[t].colorPickingRendering(e,a[0],0);t.enableBlendDefault(),s.enable(s.POLYGON_OFFSET_FILL);for(let t=1,i=a.length;t<i;t++)for(l=o.length,s.polygonOffset(0,-t);l--;)o[l].segment.colorPickingRendering(e,a[t],t,this.transparentTexture,!0);s.disable(s.POLYGON_OFFSET_FILL)}_renderDepthFramebufferPASS(){let e,t=this.renderer,i=t.handler,s=i.gl;i.programs.drawnode_depth.activate(),e=i.programs.drawnode_depth._program;let n=e.uniforms,r=t.activeCamera;s.disable(s.BLEND),s.disable(s.POLYGON_OFFSET_FILL),s.uniformMatrix4fv(n.viewMatrix,!1,r.getViewMatrix()),s.uniformMatrix4fv(n.projectionMatrix,!1,r.getProjectionMatrix()),s.uniform3fv(n.eyePositionHigh,r.eyeHigh),s.uniform3fv(n.eyePositionLow,r.eyeLow),s.uniform1f(n.frustumPickingColor,r.frustumColorIndex);let o=this._renderedNodesInFrustum[r.getCurrentFrustum()],a=this._visibleTileLayerSlices,l=o.length;for(;l--;)o[l].segment._transitionOpacity>=1&&o[l].segment.depthRendering(e,a[0]);for(let t=0;t<this._fadingOpaqueSegments.length;++t)this._fadingOpaqueSegments[t].depthRendering(e,a[0]);s.enable(s.BLEND)}_collectVectorLayerCollections(){let e=this._visibleVectorLayersByDepthOrder.length;this._visibleEntityCollections.length=0,this._visibleEntityCollections=new Array(e);for(let e=0;e<this._visibleEntityCollections.length;e++)this._visibleEntityCollections[e]=[];for(;e--;){let t=this._visibleVectorLayersByDepthOrder[e],i=t.length;for(;i--;){let s=t[i];s._fading&&s._refreshFadingOpacity()&&(t.splice(i,1),0===t.length&&this._visibleVectorLayersByDepthOrder.splice(e,1)),s.collectVisibleCollections(this._visibleEntityCollections[e]),s.update()}}}memClear(){this._distBeforeMemClear=0,this.camera._insideSegment=null,this.layerLock.lock(this._memKey),this.terrainLock.lock(this._memKey),this._normalMapCreator.lock(this._memKey),this._normalMapCreator.clear(),this.terrain.abortLoading(),this._tileLoader.abortAll(),this.quadTreeStrategy.clear(),this.layerLock.free(this._memKey),this.terrainLock.free(this._memKey),this._normalMapCreator.free(this._memKey),this._createdNodesCount=0}getRayIntersectionEllipsoid(e){return this.ellipsoid.hitRay(e.origin,e.direction)}getCartesianFromPixelEllipsoid(e){let t=this.renderer.activeCamera;return this.ellipsoid.hitRay(t.eye,t.unproject(e.x,e.y))}getLonLatFromPixelEllipsoid(e){let t=this.getCartesianFromPixelEllipsoid(e);if(t)return this.ellipsoid.cartesianToLonLat(t)}getCartesianFromMouseTerrain(){let e=this.renderer.events.mouseState,t=this.getDistanceFromPixel(e);if(t)return e.direction.scaleTo(t).addA(this.renderer.activeCamera.eye)}getCartesianFromPixelTerrain(e){let t=this.getDistanceFromPixel(e);if(t){return(e.direction||this.renderer.activeCamera.unproject(e.x,e.y)).scaleTo(t).addA(this.renderer.activeCamera.eye)}}getLonLatFromPixelTerrain(e){let t=this.getCartesianFromPixelTerrain(e);if(t)return this.ellipsoid.cartesianToLonLat(t)}getPixelFromCartesian(e){return this.renderer.activeCamera.project3v(e)}getPixelFromLonLat(e){let t=this.ellipsoid.lonLatToCartesian(e);if(t)return this.renderer.activeCamera.project3v(t)}getDistanceFromPixelEllipsoid(e){let t=this.getCartesianFromPixelEllipsoid(e);if(t)return t.distance(this.renderer.activeCamera.eye)}getDistanceFromPixel(e){return this.renderer.getDistanceFromPixel(e)||this.getDistanceFromPixelEllipsoid(e)||0}viewExtent(e){this.camera?this.camera.viewExtent(e):this._initialViewExtent=e}viewExtentArr(e){this.viewExtent(new te(new I(e[0],e[1]),new I(e[2],e[3])))}getViewExtent(){if(this.renderer){let e=this.renderer.handler.getWidth(),t=this.renderer.handler.getHeight(),i=[this.getLonLatFromPixelTerrain(new ae(0,0)),this.getLonLatFromPixelTerrain(new ae(e,0)),this.getLonLatFromPixelTerrain(new ae(e,t)),this.getLonLatFromPixelTerrain(new ae(0,t))];if(i[0]&&i[1]&&i[2]&&i[3]){let e=i[0].lon,t=i[2].lat,s=i[1].lon,n=i[0].lat;for(let r=0;r<i.length;r++)i[r].lon>s&&(s=i[r].lon),i[r].lat>n&&(n=i[r].lat),i[r].lon<e&&(e=i[r].lon),i[r].lat<t&&(t=i[r].lat);return new te(new I(e,t),new I(s,n))}}return this._viewExtent}viewLonLat(e,t,i){this.camera.setLonLat(e,t,i)}flyExtent(e,t,i,s,n,r){this.camera.flyExtent(e,t,i,s,n,r)}flyCartesian(e,t,i,s,n,r,o){this.camera.flyCartesian(e,t,i,s,n,r,o)}flyLonLat(e,t,i,s,n,r,o){this.camera.flyLonLat(e,t,i,s,n,r,o)}stopFlying(){this.camera.stopFlying()}updateBillboardsTexCoords(){for(let e=0;e<this.entityCollections.length;e++)this.entityCollections[e].billboardHandler.refreshTexCoordsArr();let e={};for(let t=0;t<this._layers.length;t++){let i=this._layers[t];i instanceof qs&&i.each((function(t){t._entityCollection&&!e[t._entityCollection.id]&&(t._entityCollection.billboardHandler.refreshTexCoordsArr(),e[t._entityCollection.id]=!0)}))}}getEntityTerrainPoint(e,t){let i=this._renderedNodes,s=i.length;for(;s--;)if(i[s].segment.isEntityInside(e))return i[s].segment.getEntityTerrainPoint(e,t)}async getHeightDefault(e){return new Promise((t=>{this.terrain?this.terrain.getHeightAsync(e.clone(),(e=>{t(e)})):t(0)}))}async getHeightAboveELL(e){return new Promise((t=>{this.terrain?this.terrain.getHeightAsync(e.clone(),(i=>{t(i+this.terrain.geoid.getHeightLonLat(e))})):t(0)}))}onremove(){this.memClear(),this.quadTreeStrategy.destroyBranches(),this._renderedNodes=[]}stopDragging(){this.renderer&&this.renderer.controls.EarthNavigation&&this.renderer.controls.EarthNavigation.stop()}}const $a=["draw","layeradd","baselayerchange","layerremove","layervisibilitychange","rendercompleted","terraincompleted","layerloadend"];class Xa extends Ri{constructor(e){super("skybox"),this.params=e,this.vertexPositionBuffer=null,this.texture=null}static createDefault(e){return new Xa({nx:e+"skybox/gal/_nx.jpg",px:e+"skybox/gal/_px.jpg",py:e+"skybox/gal/_py.jpg",ny:e+"skybox/gal/_ny.jpg",pz:e+"skybox/gal/_pz.jpg",nz:e+"skybox/gal/_nz.jpg"})}init(){this.renderer.handler.addProgram(new Ni("skybox",{uniforms:{projectionViewMatrix:{type:Ii.MAT4},uSampler:{type:Ii.SAMPLERCUBE},pos:{type:Ii.VEC3}},attributes:{aVertexPosition:{type:Ii.VEC3,enableArray:!0}},vertexShader:"attribute vec3 aVertexPosition;\n uniform mat4 projectionViewMatrix;\n uniform vec3 pos;\n varying vec3 vTextureCoord;\n void main(void) {\n vTextureCoord = aVertexPosition;\n gl_Position = projectionViewMatrix * vec4(aVertexPosition + pos, 1.0);\n }",fragmentShader:"precision lowp float;\n varying vec3 vTextureCoord;\n uniform samplerCube uSampler;\n void main(void) {\n gl_FragColor = textureCube(uSampler, vTextureCoord);\n }"}),!0),this.texture=this.renderer.handler.loadCubeMapTexture(this.params),this._createBuffers(),this.drawMode=this.renderer.handler.gl.TRIANGLES}frame(){let e=this.renderer.handler,t=e.gl,i=this.renderer.activeCamera;t.disable(t.DEPTH_TEST),e.programs.skybox.activate();let s=e.programs.skybox._program,n=s.uniforms;t.uniformMatrix4fv(n.projectionViewMatrix,!1,i.getProjectionViewMatrix()),t.uniform3fv(n.pos,i.eye.toArray()),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_CUBE_MAP,this.texture),t.uniform1i(n.uSampler,0);let r=this.vertexPositionBuffer;t.bindBuffer(t.ARRAY_BUFFER,r),t.vertexAttribPointer(s.attributes.aVertexPosition,r.itemSize,t.FLOAT,!1,0,0),t.drawArrays(this.drawMode,0,r.numItems),t.enable(t.DEPTH_TEST)}_createBuffers(){const e=new Float32Array([-1e8,1e8,-1e8,-1e8,-1e8,-1e8,1e8,-1e8,-1e8,1e8,-1e8,-1e8,1e8,1e8,-1e8,-1e8,1e8,-1e8,-1e8,-1e8,1e8,-1e8,-1e8,-1e8,-1e8,1e8,-1e8,-1e8,1e8,-1e8,-1e8,1e8,1e8,-1e8,-1e8,1e8,1e8,-1e8,-1e8,1e8,-1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,-1e8,1e8,-1e8,-1e8,-1e8,-1e8,1e8,-1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,1e8,-1e8,1e8,-1e8,-1e8,1e8,-1e8,1e8,-1e8,1e8,1e8,-1e8,1e8,1e8,1e8,1e8,1e8,1e8,-1e8,1e8,1e8,-1e8,1e8,-1e8,-1e8,-1e8,-1e8,-1e8,-1e8,1e8,1e8,-1e8,-1e8,1e8,-1e8,-1e8,-1e8,-1e8,1e8,1e8,-1e8,1e8]);this.vertexPositionBuffer=this.renderer.handler.createArrayBuffer(e,3,e.length/3)}}var Za=Object.freeze({__proto__:null,Axes:class extends Ri{constructor(e=100){super("Axes"),this.size=e,this.axesBuffer=null,this.axesColorBuffer=null}init(){this.createAxesBuffer(this.size),this.drawMode=this.renderer.handler.gl.LINES,this.renderer.handler.addProgram(new Ni("axesShader",{uniforms:{projectionViewMatrix:"mat4"},attributes:{aVertexPosition:"vec3",aVertexColor:"vec4"},vertexShader:"attribute vec3 aVertexPosition;\n attribute vec4 aVertexColor;\n uniform mat4 projectionViewMatrix;\n varying vec4 vColor;\n void main(void) {\n gl_Position = projectionViewMatrix * vec4(aVertexPosition, 1.0);\n vColor = aVertexColor;\n }",fragmentShader:"precision highp float;\n varying vec4 vColor;\n void main(void) {\n gl_FragColor = vColor;\n }"}))}frame(){this.renderer.handler.programs.axesShader.activate().set({projectionViewMatrix:this.renderer.activeCamera.getProjectionViewMatrix(),aVertexPosition:this.axesBuffer,aVertexColor:this.axesColorBuffer}),this.renderer.handler.programs.axesShader.drawArrays(this.drawMode,this.axesBuffer.numItems)}createAxesBuffer(e){const t=[0,0,0,e-1,0,0,0,0,0,0,e-1,0,0,0,0,0,0,e-1];this.axesBuffer=this.renderer.handler.createArrayBuffer(new Float32Array(t),3,6),this.axesColorBuffer=this.renderer.handler.createArrayBuffer(new Float32Array([1,0,0,1,1,0,0,1,0,0,1,1,0,0,1,1,0,1,0,1,0,1,0,1]),4,6)}},Planet:qa,RenderNode:Ri,SkyBox:Xa});class Ka{constructor(e={}){this.__id=Ka.__counter__++,this.equalizeVertices=e.equalizeVertices||!1,this.equalizeNormals=!1,this.isEmpty=!0,this.name=e.name||"empty",this.minZoom=e.minZoom||2,this.maxZoom=e.maxZoom||19,this.maxNativeZoom=e.maxNativeZoom||this.maxZoom,this.gridSizeByZoom=e.gridSizeByZoom||[64,32,16,8,4,4,4,4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2],this._maxNodeZoom=this.gridSizeByZoom.length-1,this.plainGridSize=2,this.noDataValues=[],this._planet=null,this._geoid=e.geoid||new Ma({src:e.geoidSrc||null}),this._isReady=!1}setUrlRewriteCallback(e){}get isIdle(){return!0}isEqual(e){return e.__id===this.__id}static checkNoDataValue(e,t){return-1!==Be(e,t)}isBlur(e){return!1}set maxNodeZoom(e){e>this.gridSizeByZoom.length-1&&(e=this.gridSizeByZoom.length-1),this._maxNodeZoom=e}get maxNodeZoom(){return this._maxNodeZoom}set geoid(e){this._geoid=e}get geoid(){return this._geoid}getGeoid(){return this._geoid}handleSegmentTerrain(e){e.terrainIsLoading=!1,e.terrainReady=!0,e.terrainExists=!0}isReady(){return this._isReady}abortLoading(){}clearCache(){}getHeightAsync(e,t){return t(0),!0}loadTerrain(e,t=!1){}}Ka.__counter__=0;class Qa extends Ka{constructor(e="",t={}){super({geoidSrc:"https://openglobus.org/geoid/egm84-30.pgm",maxNativeZoom:t.maxNativeZoom||14,...t}),this._s=t.subdomains||["a","b","c"],this.events=Mt(Ja,this),this._requestCount=0,this._requestsPeerSubdomain=4,this.isEmpty=!1,this.equalizeNormals=!0,this.name=e||"openglobus",this.url=t.url||"https://{s}.srtm3.openglobus.org/{z}/{y}/{x}.ddm",this.gridSizeByZoom=t.gridSizeByZoom||[64,32,32,16,16,8,8,8,16,16,16,32,32,32,32,16,8,4,2,2,2,2,2,2],this._heightFactor=null!=t.heightFactor?t.heightFactor:1,this.noDataValues=t.noDataValues||[];for(let e=0;e<this.noDataValues.length;e++)this.noDataValues[e]*=this._heightFactor;this.plainGridSize=t.plainGridSize||32,this._extent=Me(t.extent,new te(new I(-180,-90),new I(180,90))),this._dataType="arrayBuffer",this._maxNodeZoom=this.gridSizeByZoom.length-1,this._elevationCache={},this._fetchCache={},this._loader=new ka,this._urlRewriteCallback=t.urlRewrite||null}get loader(){return this._loader}clearCache(){for(let e in this._elevationCache)this._elevationCache[e].heights=null,this._elevationCache[e].extent=null,delete this._elevationCache[e];this._elevationCache=null,this._elevationCache={};for(let e in this._fetchCache)this._fetchCache[e]=null,delete this._fetchCache[e];this._fetchCache=null,this._fetchCache={}}isBlur(e){return e.tileZoom>=6}setElevationCache(e,t){this._elevationCache[e]=t}getElevationCache(e){return this._elevationCache[e]}getHeightAsync(e,t,i,s){if(!e||e.lat>Q||e.lat<J)return t(0),!0;s=null==s||s;const[n,r,o,a]=this._planet.quadTreeStrategy.getTileXY(e,i||this.maxZoom);let l=$t.getTileIndex(n,r,o,a),h=this.getElevationCache(l),c=q(e);if(h)return h.heights?t(this._getGroundHeightMerc(c,h)):t(0),!0;{let i=this._fetchCache[l];i||(i=this._loader.fetch({src:this.buildURL(n,r,o,a),type:this._dataType}),this._fetchCache[l]=i),i.then((i=>{let h=K(n,r,o);if("ready"===i.status){let e={heights:this._createHeights(i.data,null,a,n,r,o,h),extent:h};this.setElevationCache(l,e),t(this._getGroundHeightMerc(c,e))}else if("error"===i.status){if(s&&o>this.maxNativeZoom)return s=!1,void this.getHeightAsync(e,t,this.maxNativeZoom,!1);this.setElevationCache(l,{heights:null,extent:h}),t(0)}else this._fetchCache[l]=null,delete this._fetchCache[l]}))}return!1}_getGroundHeightMerc(e,t){if(!t.extent||!t.heights)return 0;let i=t.extent.getWidth(),s=Math.sqrt(t.heights.length),n=i/(s-1),r=s-Math.ceil((e.lat-t.extent.southWest.lat)/n)-1,o=Math.floor((e.lon-t.extent.southWest.lon)/n),a=(r+1)*s+o,l=a+1,h=r*s+o,c=h+1,d=t.heights[a],_=t.heights[l],u=t.heights[h],g=t.heights[c],f=new oe(t.extent.southWest.lon+n*o,d,t.extent.northEast.lat-n*r-n),p=new oe(f.x+n,_,f.z),m=new oe(f.x,u,f.z+n),v=new oe(f.x+n,g,f.z+n),y=new oe(e.lon,1e5,e.lat),x=new ui(y,new oe(0,-1,0)),b=new oe,w=x.hitTriangleRes(f,p,m,b);return w===ui.INSIDE?b.y:(w=x.hitTriangleRes(p,v,m,b),w===ui.INSIDE?b.y:0)}abortLoading(){this._loader.abortAll()}setUrl(e){this.url=e}setName(e){this.name=e}isReadyToLoad(e){return 0===e._tileGroup&&this._extent.overlaps(e.getExtentLonLat())}loadTerrain(e,t=!1){if(this._planet.terrainLock.isFree())if(e.terrainReady=!1,e.terrainIsLoading=!0,this.isReadyToLoad(e)){let i=this.getElevationCache(e.tileIndex);i?this._applyElevationsData(e,i.heights):this._loader.load({sender:this,src:this._getHTTPRequestString(e),segment:e,type:this._dataType,filter:()=>e.plainReady&&0!==e.node.getState()||t},(t=>{if("ready"===t.status){let i=this._createHeights(t.data,e,e._tileGroup,e.tileX,e.tileY,e.tileZoom,e.getExtent(),e.tileZoom===this.maxZoom);this.setElevationCache(e.tileIndex,{heights:i,extent:e.getExtent()}),this._applyElevationsData(e,i)}else"abort"===t.status?e.terrainIsLoading=!1:"error"===t.status?this._applyElevationsData(e,null):e.terrainIsLoading=!1}))}else e.elevationsNotExists();else e.terrainIsLoading=!1}_getSubdomain(){return this._requestCount++,this._s[Math.floor(this._requestCount%(this._requestsPeerSubdomain*this._s.length)/this._requestsPeerSubdomain)]}buildURL(e,t,i,s){return we(this.url,{s:this._getSubdomain(),x:e.toString(),y:t.toString(),z:i.toString()})}_createUrl(e){return this.buildURL(e.tileX,e.tileY,e.tileZoom,e._tileGroup)}_getHTTPRequestString(e){return this._urlRewriteCallback&&this._urlRewriteCallback(e.tileX,e.tileY,e.tileZoom,e._tileGroup)||this._createUrl(e)}setUrlRewriteCallback(e){this._urlRewriteCallback=e}_createHeights(e,t,i,s,n,r,o,a){if(1!==this._heightFactor){let t=new Float32Array(e);for(let e=0,i=t.length;e<i;e++)t[e]=t[e]*this._heightFactor;return t}return new Float32Array(e)}_applyElevationsData(e,t){if(e){let i=this.events.load;i.handlers.length&&this.events.dispatch(i,{elevations:t,segment:e}),e.applyTerrain(t)}}}const Ja=["load","loadend"];class el extends $t{constructor(e,t={}){super(e,t),this.events=this.events.registerNames(tl),this.url=t.url||"",this._s=t.subdomains||["a","b","c"],this.minNativeZoom=t.minNativeZoom||0,this.maxNativeZoom=t.maxNativeZoom||19,this._urlRewriteCallback=t.urlRewrite||null,this._requestsPeerSubdomains=4,this._requestCount=0}get isIdle(){return super.isIdle&&0===this._planet._tileLoader.getRequestCounter(this)}get instanceName(){return"XYZ"}abortLoading(){this._planet&&this._planet._tileLoader.abort(this)}setVisibility(e){e!==this._visibility&&(super.setVisibility(e),e||this.abortLoading())}remove(){return this.abortLoading(),super.remove(),this}setUrl(e){this.url=e}_checkSegment(e){return e._projection.id===this._planet.quadTreeStrategy.projection.id}loadMaterial(e,t=!1){let i=e.segment;this._isBaseLayer?e.texture=i.getDefaultTexture():e.texture=i.planet.transparentTexture,(this._planet.layerLock.isFree()||e.segment.tileZoom<2)&&(e.isReady=!1,e.isLoading=!0,this._checkSegment(i)?(e.loadingAttempts++,this._planet._tileLoader.load({sender:this,src:this._getHTTPRequestString(e.segment),type:"imageBitmap",filter:()=>i.initialized&&1===i.node.getState()||t,options:{}},(t=>{if("ready"===t.status){if(e.isLoading){let i=this.events.load;i.handlers.length&&this.events.dispatch(i,e),e.applyImage(t.data),t.data=null}}else"abort"===t.status?e.isLoading=!1:"error"===t.status&&e.isLoading&&e.textureNotExists()}))):e.textureNotExists())}_createUrl(e){return we(this.url,{s:this._getSubdomain(),x:e.tileX.toString(),y:e.tileY.toString(),z:e.tileZoom.toString()})}_getSubdomain(){return this._requestCount++,this._s[Math.floor(this._requestCount%(this._requestsPeerSubdomains*this._s.length)/this._requestsPeerSubdomains)]}_getHTTPRequestString(e){return this._urlRewriteCallback?this._urlRewriteCallback(e,this.url):this._createUrl(e)}setUrlRewriteCallback(e){this._urlRewriteCallback=e}applyMaterial(e,t=!1){if(e.isReady)return e.texOffset;if(e.segment.tileZoom<this.minNativeZoom)e.textureNotExists();else{let i=e.segment,s=i.node,n=!1,r=this.__id,o=e;for(;s.parentNode;)if(s=s.parentNode,o=s.segment.materials[r],o&&o.textureExists){n=!0;break}if(i.passReady){let n=e.layer.maxNativeZoom;if(s.segment.tileZoom===n)e.textureNotExists();else if(e.segment.tileZoom<=n)!e.isLoading&&!e.isReady&&this.loadMaterial(e,t);else{let t=i.node;for(;t.segment.tileZoom>e.layer.maxNativeZoom;)t=t.parentNode;let s=t.segment.materials[e.layer.__id];s?!s.isLoading&&!s.isReady&&this.loadMaterial(s,!0):(s=t.segment.materials[e.layer.__id]=e.layer.createMaterial(t.segment),this.loadMaterial(s,!0))}}if(n){e.appliedNode=s,e.appliedNodeId=s.nodeId,e.texture=o.texture;let t=1/(2<<i.tileZoom-s.segment.tileZoom-1);e.texOffset[0]=i.tileX*t-s.segment.tileX,e.texOffset[1]=i.tileY*t-s.segment.tileY,e.texOffset[2]=t,e.texOffset[3]=t}else e.texture=i.planet.transparentTexture,e.texOffset[0]=0,e.texOffset[1]=0,e.texOffset[2]=1,e.texOffset[3]=1}return e.texOffset}clearMaterial(e){e.isReady&&e.textureExists&&(!e.texture.default&&e.segment.handler.gl.deleteTexture(e.texture),e.texture=null),e.isReady=!1,e.textureExists=!1,e.isLoading=!1}_correctFullExtent(){let e=this._extent,t=this._extentMerc,i=z+5e4,s=z+5e4;90===e.northEast.lat&&(t.northEast.lat=s),180===e.northEast.lon&&(t.northEast.lon=i),-90===e.southWest.lat&&(t.southWest.lat=-s),-180===e.southWest.lon&&(t.southWest.lon=-i)}}const tl=["load","loadend"];class il extends el{constructor(e,t){super(e,t),this._extra=new URLSearchParams(t.extra).toString(),t.extent||this.setExtent(new te(new I(-180,-90),new I(180,90))),this.layers=t.layers,this.imageWidth=t.imageWidth||256,this.imageHeight=t.imageHeight||256,this._getBbox=il.get_bbox_v1_1_1,this._version="",this.setVersion(t.version)}static createRequestUrl(e,t,i="image/png",s="1.1.1",n="GetMap",r,o,a=256,l=256,h){return`${e}/?LAYERS=${t}&FORMAT=${i}&SERVICE=WMS&VERSION=${s}&REQUEST=${n}&SRS=${r}&BBOX=${o}&WIDTH=${a}&HEIGHT=${l}`+(h?`&${h}`:"")}static get_bbox_v1_1_1(e){return`${e.getWest()},${e.getSouth()},${e.getEast()},${e.getNorth()}`}static get_bbox_v1_3_0(e){return`${e.getSouth()},${e.getWest()},${e.getNorth()},${e.getEast()}`}_checkSegment(e){return!0}get instanceName(){return"WMS"}_createUrl(e){return il.createRequestUrl(this.url,this.layers,"image/png",this._version,"GetMap",e._projection.code,this._getBbox(e.getExtent()),this.imageWidth,this.imageHeight,this._extra)}setVersion(e){this._version=e||"1.1.1","1.1.1"===this._version?this._getBbox=il.get_bbox_v1_1_1:"1.3.0"===e&&(this._getBbox=il.get_bbox_v1_3_0)}_correctFullExtent(){const e=this._extent,t=this._extentMerc,i=z+5e4,s=z+5e4;90===e.northEast.lat&&(t.northEast.lat=s),180===e.northEast.lon&&(t.northEast.lon=i),-90===e.southWest.lat&&(t.southWest.lat=-s),-180===e.southWest.lon&&(t.southWest.lon=-i)}}class sl extends Qa{constructor(e={}){super("BilTerrain",e),this.equalizeVertices=!0,this.equalizeNormals=!0,this.minZoom=e.minZoom||2,this.maxZoom=e.maxZoom||14,this.noDataValues=e.noDataValues||[-9999,32767],this.url=e.url||"",this._format="application/bil16",this._layers=e.layers||"",this._imageSize=e.imageSize||256,this.plainGridSize=null!=e.plainGridSize?e.plainGridSize:v(this._imageSize)?this._imageSize/2:y(this._imageSize)/2,this._dataType="arrayBuffer"}isBlur(e){return e.tileZoom>=18}_createUrl(e){return il.createRequestUrl(this.url,this._layers,this._format,"1.1.1","GetMap",e._projection.code,il.get_bbox_v1_1_1(e.getExtent()),this._imageSize,this._imageSize)}_createHeights(e,t,i,s,n,r,o,a){let l=new Int16Array(e);if(!v(this._imageSize)){let e=new Float32Array(l.length);return function(e,t){for(let i=0,s=t.length;i<s;i++)t[i]=e[i]}(l,e),e}let h=(this.plainGridSize+1)*(this.plainGridSize+1),c=new Array(4);for(let e=0;e<4;e++){c[e]=[];for(let t=0;t<4;t++)c[e][t]=new Float32Array(h)}let d=new Float32Array(h);!function(e,t,i,s){let n=Math.sqrt(i.length)-1,r=n+1,o=Math.sqrt(e.length),a=o/n,l=0,h=0;for(let c=0,d=0,_=e.length;c<_;c++){let _=e[c],u=sl.checkNoDataValue(t,_),g=!1,f=!1,p=Math.floor(c/o),m=c%o,v=Math.floor(m/n),y=Math.floor(p/n),x=s[y][v],b=p%n,w=m%n,C=(b+y)*r+w+v;if(x[C]=_,(p+y)%a==0&&(m+v)%a==0&&(i[d++]=_),(m+1)%n==0&&m!==o-1){l=e[c],g=sl.checkNoDataValue(t,l);let o=_;u||g||(o=.5*(_+l)),C=(b+y)*r+w+1,x[C]=o,(p+y)%a==0&&(i[d++]=o);let h=(b+y)*r+(w+1)%n;s[y][v+1][h]=o}if((p+1)%n==0&&p!==o-1){h=e[c+o],f=sl.checkNoDataValue(t,h);let l=_;u||f||(l=.5*(_+h)),C=(b+1)*r+w+v,x[C]=l,(m+v)%a==0&&(i[d++]=l);let g=(b+1)%n*r+w+v;s[y+1][v][g]=l}if((m+1)%n==0&&m!==o-1&&(p+1)%n==0&&p!==o-1){let a=e[c+o+1],p=sl.checkNoDataValue(t,a),m=_;u||g||f||p||(m=.25*(_+l+h+a)),C=(b+1)*r+(w+1),x[C]=m,i[d++]=m;let T=(b+1)*r;s[y][v+1][T]=m;let E=n;s[y+1][v][E]=m;let L=0;s[y+1][v+1][L]=m}}}(l,this.noDataValues,d,c);let _=$t.getTileIndex(s,n,r,i);this.setElevationCache(_,{heights:d,extent:o});let u=this._imageSize/this.plainGridSize;for(let e=0;e<u;e++)for(let t=0;t<u;t++){let o=2*s+t,a=2*n+e,l=r+1,h=$t.getTileIndex(o,a,l,i);this.setElevationCache(h,{heights:c[e][t],extent:K(o,a,l)})}return d}}class nl extends Qa{constructor(e,t={}){super(e||"RgbTerrain",{equalizeVertices:null==t.equalizeVertices||t.equalizeVertices,maxZoom:t.maxZoom||17,noDataValues:t.noDataValues||[null!=t.minHeight?t.minHeight:-1e4],plainGridSize:t.plainGridSize||128,url:null!=t.url?t.url:`//api.mapbox.com/v4/mapbox.terrain-rgb/{z}/{x}/{y}.pngraw?access_token=${t.key||"<key>"}`,gridSizeByZoom:t.gridSizeByZoom||[64,32,16,8,8,8,16,16,16,32,32,32,32,32,32,64,64,64,32,32,16,8],...t}),this.equalizeNormals=t.equalizeNormals||!1,this._dataType="imageBitmap",this._imageSize=t.imageSize||256,this._ctx=this._createTemporalCanvas(this._imageSize),this._imageDataCache={},this._minHeight=t.minHeight||-1e4,this._resolution=t.resolution||.1}static checkNoDataValue(e,t){return t>5e4||-1!==Be(e,t)}rgb2Height(e,t,i){return 255===e?this._minHeight:this._minHeight+this._resolution*(256*e*256+256*t+i)}isBlur(e){return e.tileZoom>=16}_createTemporalCanvas(e){let t=document.createElement("canvas");return t.width=e,t.height=e,t.getContext("2d",{willReadFrequently:!0})}_createHeights(e,t,i,s,n,r,o,a){this._ctx.clearRect(0,0,this._imageSize,this._imageSize),this._ctx.drawImage(e,0,0);let l=this._ctx.getImageData(0,0,this._imageSize,this._imageSize).data;const h=e.width;let c=0,d=0,_=0,u=null,g=!1;if(t&&t.tileZoom>this.maxNativeZoom){let e=t.node;for(;e&&!e.segment.terrainExists;)e=e.parentNode;e&&(c=e.segment.tileX,d=e.segment.tileY,_=e.segment.tileZoom,u=e.segment.elevationData,g=_<=8)}if(!v(this._imageSize)&&h===this._imageSize){let e=new Float32Array(h*h);return this.extractElevationTilesRgbNonPowerOfTwo(l,e,this._heightFactor),e}if(this._imageSize===this.plainGridSize){let e=(this.plainGridSize+1)*(this.plainGridSize+1),i=new Float32Array(e),[s,n,r]=t?rl(t.tileX,t.tileY,t.tileZoom,c,d,_):[0,0,0];return this.extractElevationSimple(l,this.noDataValues,u,s,n,r,g,i,this._heightFactor,this._imageSize),i}let f=(this.plainGridSize+1)*(this.plainGridSize+1),p=h/this.plainGridSize,m=new Float32Array(f),y=new Array(p);for(let e=0;e<p;e++){y[e]=[];for(let t=0;t<p;t++)y[e][t]=new Float32Array(f)}if(a)this.extractElevationTilesRgbNoChildren(l,this._heightFactor,this.noDataValues,u,c,d,_,t?t.tileX:0,t?t.tileY:0,t?t.tileZoom:0,g,m);else{this.extractElevationTilesRgb(l,this._heightFactor,this.noDataValues,u,c,d,_,t?t.tileX:0,t?t.tileY:0,t?t.tileZoom:0,g,m,y);for(let e=0;e<p;e++)for(let t=0;t<p;t++){let[o,a,l]=[2*s+t,2*n+e,r+1],h=$t.getTileIndex(o,a,l,i);this.setElevationCache(h,{heights:y[e][t],extent:K(o,a,l)})}}let x=$t.getTileIndex(s,n,r,i);return this.setElevationCache(x,{heights:m,extent:o}),m}getHeightAsync(e,t,i){if(0===(i=null!=i?i:this.maxZoom))return t(0),!0;const s=this._planet.quadTreeStrategy,[n,r,o,a]=s.getTileXY(e,i),[l,h]=s.getLonLatTileOffset(e,n,r,o,this._imageSize),c=4*(l*this._imageSize+h),d=$t.getTileIndex(n,r,o,a);if(this._imageDataCache[d]){let s=this._imageDataCache[d],n=this._heightFactor*this.rgb2Height(s[c],s[c+1],s[c+2]);return nl.checkNoDataValue(this.noDataValues,n)?this.getHeightAsync(e,t,i-1):(t(this._heightFactor*this.rgb2Height(s[c],s[c+1],s[c+2])),!0)}let _=this._fetchCache[d];return _||(_=this._loader.fetch({src:this._urlRewriteCallback&&this._urlRewriteCallback(n,r,o,a)||this.buildURL(n,r,o,a),type:this._dataType}),this._fetchCache[d]=_),_.then((s=>{if("ready"===s.status){this._ctx.clearRect(0,0,this._imageSize,this._imageSize),this._ctx.drawImage(s.data,0,0);let n=this._ctx.getImageData(0,0,256,256).data;this._imageDataCache[d]=n;let r=this._heightFactor*this.rgb2Height(n[c],n[c+1],n[c+2]);if(nl.checkNoDataValue(this.noDataValues,r))return this.getHeightAsync(e,t,i-1);t(this._heightFactor*this.rgb2Height(n[c],n[c+1],n[c+2]))}else{if("error"===s.status)return this.getHeightAsync(e,t,i-1);this._fetchCache[d]=null,delete this._fetchCache[d]}})),!1}extractElevationSimple(e,t,i=null,s,n,r,o,a,l=1,h){for(let c=0,d=h*h;c<d;c++){let d=c%h,_=Math.floor(c/h),u=4*c,g=l*this.rgb2Height(e[u],e[u+1],e[u+2]);(nl.checkNoDataValue(t,g)||0===g)&&i&&(g=ol(r,s,n,i,_,d,o)),a[_*(h+1)+d]=g}for(let c=0,d=h;c<d;c++){let d=h-1,_=4*(c*h+d),u=l*this.rgb2Height(e[_],e[_+1],e[_+2]);(nl.checkNoDataValue(t,u)||0===u)&&i&&(u=ol(r,s,n,i,c,d,o)),a[c*(h+1)+h]=u}for(let c=0,d=h;c<d;c++){let d=h-1,_=4*(d*h+c),u=l*this.rgb2Height(e[_],e[_+1],e[_+2]);(nl.checkNoDataValue(t,u)||0===u)&&i&&(u=ol(r,s,n,i,d,c,o)),a[h*(h+1)+c]=u}let c=l*this.rgb2Height(e[e.length-4],e[e.length-3],e[e.length-2]);(nl.checkNoDataValue(t,c)||0===c)&&i&&(c=ol(r,s,n,i,h-1,h-1,o)),a[a.length-1]=c}extractElevationTilesRgbNonPowerOfTwo(e,t,i=1){for(let s=0,n=t.length;s<n;s++){let n=4*s;t[s]=i*this.rgb2Height(e[n],e[n+1],e[n+2])}}extractElevationTilesRgb(e,t,i,s=null,n,r,o,a,l,h,c,d,_){let u=Math.sqrt(d.length)-1,g=u+1,f=Math.sqrt(e.length/4),p=f/u,m=0,v=0,y=0,[x,b,w]=rl(a,l,h,n,r,o);for(let n=0,r=0,o=e.length/4;n<o;n++){let o=4*n,a=t*this.rgb2Height(e[o],e[o+1],e[o+2]),l=nl.checkNoDataValue(i,a),h=!1,C=!1,T=Math.floor(n/f),E=n%f;(l||0===a)&&s&&(a=ol(w,x,b,s,Math.floor(T/p),Math.floor(E/p),c));let L=Math.floor(E/u),A=Math.floor(T/u),P=_[A][L],S=T%u,M=E%u,R=(S+A)*g+M+L;if(P[R]=a,(T+A)%p==0&&(E+L)%p==0&&(d[r++]=a),(E+1)%u==0&&E!==f-1){m=t*this.rgb2Height(e[o+4],e[o+5],e[o+6]),h=nl.checkNoDataValue(i,m),(h||0===m)&&s&&(m=ol(w,x,b,s,Math.floor(T/p),Math.floor((E+1)/p),c));let n=a;l||h||(n=.5*(a+m)),R=(S+A)*g+M+1,P[R]=n,(T+A)%p==0&&(d[r++]=n);let f=(S+A)*g+(M+1)%u;_[A][L+1][f]=n}if((T+1)%u==0&&T!==f-1){y=4*f,v=t*this.rgb2Height(e[o+y],e[o+y+1],e[o+y+2]),C=nl.checkNoDataValue(i,v),(C||0===v)&&s&&(v=ol(w,x,b,s,Math.floor((T+1)/p),Math.floor(E/p),c));let n=.5*(a+v);l||C||(n=.5*(a+v)),R=(S+1)*g+M+L,P[R]=n,(E+L)%p==0&&(d[r++]=n);let h=(S+1)%u*g+M+L;_[A+1][L][h]=n}if((E+1)%u==0&&E!==f-1&&(T+1)%u==0&&T!==f-1){let n=t*this.rgb2Height(e[o+y+4],e[o+y+5],e[o+y+6]),f=nl.checkNoDataValue(i,n);(f||0===n)&&s&&(n=ol(w,x,b,s,Math.floor((T+1)/p),Math.floor((E+1)/p),c));let B=a;l||h||C||f||(B=.25*(a+m+v+n)),R=(S+1)*g+(M+1),P[R]=B,d[r++]=B;let k=(S+1)*g;_[A][L+1][k]=B;let I=u;_[A+1][L][I]=B;let z=0;_[A+1][L+1][z]=B}}}extractElevationTilesRgbNoChildren(e,t,i,s=null,n,r,o,a,l,h,c,d){let _=Math.sqrt(d.length)-1,u=_+1,g=Math.sqrt(e.length/4),f=g/_,p=0,m=0,v=0,[y,x,b]=rl(a,l,h,n,r,o);for(let n=0,r=0,o=e.length/4;n<o;n++){let o=4*n,a=t*this.rgb2Height(e[o],e[o+1],e[o+2]),l=nl.checkNoDataValue(i,a),h=!1,w=!1,C=Math.floor(n/g),T=n%g;(l||0===a)&&s&&(a=ol(b,y,x,s,Math.floor(r/u),r%u,c));let E=Math.floor(T/_),L=Math.floor(C/_);if((C+L)%f==0&&(T+E)%f==0&&(d[r++]=a),(T+1)%_==0&&T!==g-1){p=t*this.rgb2Height(e[o+4],e[o+5],e[o+6]),h=nl.checkNoDataValue(i,p),(h||0===p)&&s&&(p=ol(b,y,x,s,Math.floor(r/u),r%u,c));let n=a;l||h||(n=.5*(a+p)),(C+L)%f==0&&(d[r++]=n)}if((C+1)%_==0&&C!==g-1){v=4*g,m=t*this.rgb2Height(e[o+v],e[o+v+1],e[o+v+2]),w=nl.checkNoDataValue(i,m),(w||0===m)&&s&&(m=ol(b,y,x,s,Math.floor(r/u),r%u,c));let n=.5*(a+m);l||w||(n=.5*(a+m)),(T+E)%f==0&&(d[r++]=n)}if((T+1)%_==0&&T!==g-1&&(C+1)%_==0&&C!==g-1){let n=t*this.rgb2Height(e[o+v+4],e[o+v+5],e[o+v+6]),_=nl.checkNoDataValue(i,n);(_||0===n)&&s&&(n=ol(b,y,x,s,Math.floor(r/u),r%u,c));let g=a;l||h||w||_||(g=.25*(a+p+m+n)),d[r++]=g}}}}function rl(e,t,i,s,n,r){let o=2<<i-r-1;return[e-o*s,t-o*n,1/o]}function ol(e,t,i,s,n,r,o){let a=Math.sqrt(s.length),l=s[Math.floor(i*e*a+n*e)*a+Math.floor(t*e*a+r*e)];return o&&l>0?0:l}const al={[ea]:"north",[ta]:"south"},ll=(e,t,i,s)=>{let n=al[s];if(n)return`https://terrain.openglobus.org/poles/${n}/${i}/${e}/${t}.png`};class hl extends nl{constructor(e,t){super(e||"GlobusEarthRgb",{maxNativeZoom:6,maxZoom:17,url:"https://{s}.terrain.openglobus.org/all/{z}/{x}/{y}.png",urlRewrite:ll,...t})}isReadyToLoad(e){return this._extent.overlaps(e.getExtentLonLat())}}var cl=Object.freeze({__proto__:null,BilTerrain:sl,EmptyTerrain:Ka,GlobusRgbTerrain:hl,GlobusTerrain:Qa,RgbTerrain:nl});class dl extends wn{constructor(e,t={}){super(e,t),this._image=t.image||null,this._src=t.src||null,this._onLoad_=null}get instanceName(){return"GeoImage"}abortLoading(){this._image instanceof HTMLImageElement&&(this._image.src="")}setSrc(e){this._planet&&this._planet._geoImageCreator.remove(this),this._src=e,this._sourceReady=!1,this._sourceCreated=!1,this._image=new Image,this._image.crossOrigin="Anonymous",this._onLoad_=this._onLoad.bind(this),this._image.addEventListener("load",this._onLoad_),this._image.src=e}setImage(e){this._planet&&this._planet._geoImageCreator.remove(this),this._sourceCreated=!1,this._sourceReady=!1,this._image=e,this._image.crossOrigin="Anonymous",this._src=e.src,Ze(this._image)?this._applyImage(this._image):(this._onLoad_=this._onLoad.bind(this),this._image.addEventListener("load",this._onLoad_))}_createSourceTexture(){!this._sourceCreated&&this._image&&(this._sourceTexture=this._planet.renderer.handler.createTexture_l(this._image),this._sourceCreated=!0)}_onLoad(e){this._applyImage(this._image),this._image instanceof HTMLImageElement&&this._image.removeEventListener("load",this._onLoad_),this._onLoad_=null}_applyImage(e){e&&(this._frameWidth=y(2*e.width,4096),this._frameHeight=y(3*e.height,4096),this._sourceReady=!0,this._planet&&this._planet._geoImageCreator.add(this))}loadMaterial(e){e.isLoading=!0,this._creationProceeding=!0,!this._sourceReady&&this._src?this._image?this._image instanceof HTMLImageElement&&(Ze(this._image)?this._applyImage(this._image):(this._onLoad_=this._onLoad.bind(this),this._image.addEventListener("load",this._onLoad_))):(this._image=new Image,this._image.crossOrigin="Anonymous",this._onLoad_=this._onLoad.bind(this),this._image.addEventListener("load",this._onLoad_),this._image.src=this._src):this._planet&&this._planet._geoImageCreator.add(this)}abortMaterialLoading(e){this._image&&this._image instanceof HTMLImageElement&&(this._image.src=""),this._creationProceeding=!1,e.isLoading=!1,e.isReady=!1}}class _l extends wn{constructor(e,t={}){super(e,t),this._sourceTexture=t.texture||null,t.texture&&(this._sourceReady=!0,this._sourceCreated=!0),this._frameWidth=null!=t.frameWidth?y(t.frameWidth):256,this._frameHeight=null!=t.frameHeight?y(t.frameHeight):256,this._animate=!0}get instanceName(){return"GeoTexture2d"}loadMaterial(e){this._planet._geoImageCreator.add(this)}bindTexture(e){this._sourceReady=!0,this._sourceCreated=!0,this._sourceTexture=e}setSize(e,t){this._frameWidth=e,this._frameHeight=t,this._frameCreated=!1}abortMaterialLoading(e){this._creationProceeding=!1,e.isLoading=!1,e.isReady=!1}}class ul extends wn{constructor(e,t={}){super(e,t),this._animate=!0,this._video=t.videoElement||null,this._src=t.src||null}get instanceName(){return"GeoVideo"}setSrc(e){this._planet&&this._planet._geoImageCreator.remove(this),this._src=e,this._sourceReady=!1}setVideoElement(e){this._planet&&this._planet._geoImageCreator.remove(this),this._video=e,this._src=e.src,this._sourceReady=!1}setVisibility(e){e!=this._visibility&&(super.setVisibility(e),this._planet&&(e?(this._sourceReady&&this._planet._geoImageCreator.add(this),this._video&&this._video.play()):(this._sourceReady&&this._planet._geoImageCreator.remove(this),this._video&&this._video.pause())))}_createSourceTexture(){let e=this._planet.renderer.handler.gl;this._sourceCreated?(e.bindTexture(e.TEXTURE_2D,this._sourceTexture),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this._video)):(this._sourceTexture=this._planet.renderer.handler.createTexture_n_webgl1(this._video),this._sourceCreated=!0)}_onCanPlay(e){this._frameWidth=e.videoWidth,this._frameHeight=e.videoHeight,e.width=e.videoWidth,e.height=e.videoHeight,e.play(),this._sourceReady=!0,this._planet._geoImageCreator.add(this)}_onError(e){let t="unknown error";switch(e.error.code){case 1:t="video loading aborted";break;case 2:t="network loading error";break;case 3:t="video decoding failed / corrupted data or unsupported codec";break;case 4:t="video not supported"}console.warn(`Error: ${t} error-code=${e.error.code})`)}loadMaterial(e){if(e.isLoading=!0,this._creationProceeding=!0,!this._sourceReady&&this._src){if(this._video){if(this._video.readyState===this._video.HAVE_ENOUGH_DATA)this._onCanPlay(this._video);else if(this._video.src){let e=this;this._video.addEventListener("canplay",(function(t){e._onCanPlay(this)}))}}else{this._video=document.createElement("video"),this._video.crossOrigin="Anonymous";let e=this;this._video.addEventListener("canplay",(function(){e._onCanPlay(this)})),this._video.addEventListener("error",(function(){e._onError(this)}))}this._video.autoplay=!0,this._video.loop=!0,this._video.src=this._src,this._video.muted=!0,this._video.setAttribute("playsinline","true"),this._video.setAttribute("webkit-playsinline","true")}else this._planet._geoImageCreator.add(this)}abortMaterialLoading(e){this._video&&(this._video.src=""),this._creationProceeding=!1,e.isLoading=!1,e.isReady=!1}}class gl extends qs{constructor(e,t={}){super(e,t),this._billboard=t.billboard||{src:"https://openglobus.org/examples/billboards/carrot.png"},this._color=t.color||"#6689db"}get instanceName(){return"KML"}_extractCoordonatesFromKml(e){return Array.from(e.getElementsByTagName("coordinates")).map((e=>e.textContent.trim())).map((e=>e.replace(/\n/g," ").replace(/\t/g," ").replace(/ +/g," ").split(" ").map((e=>e.split(",").map(parseFloat)))))}_AGBRtoRGBA(e){if(!e||8!=e.length)return;const t=parseInt(e.slice(0,2),16)/255,i=parseInt(e.slice(2,4),16),s=parseInt(e.slice(4,6),16);return`rgba(${parseInt(e.slice(6,8),16)},${s},${i},${t})`}_parseKMLcoordinates(e){return e.innerHTML.trim().replace(/\n/g," ").replace(/\t/g," ").replace(/ +/g," ").split(" ").map((e=>e.split(",").map(parseFloat)))}_kmlPlacemarkToEntity(e,t){if(!e)return;const i=Array.from(e.getElementsByTagName("name")),s=i&&i.length>0?i[0].innerHTML.trim():"",{iconHeading:n,iconURL:r,iconColor:o,lineWidth:a,lineColor:l}=this._extractStyle(e),h=[];for(const i of e.getElementsByTagName("coordinates")){const e=this._parseKMLcoordinates(i)||[[0,0,0]];for(const i of e){const[e,s,n]=i;h.push(new I(e,s,n)),e<t.southWest.lon&&(t.southWest.lon=e),s<t.southWest.lat&&(t.southWest.lat=s),e>t.northEast.lon&&(t.northEast.lon=e),s>t.northEast.lat&&(t.northEast.lat=s)}}if(1===h.length){const e=.01745329*n;return new Si({name:s,lonlat:h[0],billboard:{src:r,size:[24,24],color:o,rotation:e},properties:{color:o,heading:n}})}return new Si({polyline:{pathLonLat:[h],thickness:a,color:l,isClosed:!1}})}_extractStyle(e){let t,i,s,n,r;const o=e.getElementsByTagName("Style")[0];if(o){let e=o.getElementsByTagName("IconStyle")[0];if(e){let n=e.getElementsByTagName("color")[0];n&&(t=this._AGBRtoRGBA(n.innerHTML.trim()));let r=e.getElementsByTagName("heading")[0];if(r){const e=parseFloat(r.innerHTML.trim());e>=0&&e<=360&&(i=e%360)}let o=e.getElementsByTagName("Icon")[0];if(o){let e=o.getElementsByTagName("href")[0];e&&(s=e.innerHTML.trim())}}let a=o.getElementsByTagName("LineStyle")[0];if(a){let e=a.getElementsByTagName("color")[0];e&&(n=this._AGBRtoRGBA(e.innerHTML.trim()));let t=a.getElementsByTagName("width")[0];void 0!==t&&(r=parseFloat(t.innerHTML.trim()))}}return t||(t="#FFFFFF"),i||(i=0),s||(s="https://openglobus.org/examples/billboards/carrot.png"),n||(n="#FFFFFF"),r||(r=1),{iconHeading:i,iconURL:s,iconColor:t,lineWidth:r,lineColor:n}}_parseKML(e,t,i){if(i||(i=[]),"kml"!==e.documentElement.nodeName)return i;for(const s of e.getElementsByTagName("Placemark")){const e=this._kmlPlacemarkToEntity(s,t);e&&i.push(e)}return i}_convertKMLintoEntities(e){const t=new te(new I(180,90),new I(-180,-90));return{entities:this._parseKML(e,t),extent:t}}_convertCoordonatesIntoEntities(e,t,i){const s=new te(new I(180,90),new I(-180,-90)),n=e=>{const t=e[0],i=e[1];t<s.southWest.lon&&(s.southWest.lon=t),i<s.southWest.lat&&(s.southWest.lat=i),t>s.northEast.lon&&(s.northEast.lon=t),i>s.northEast.lat&&(s.northEast.lat=i)},r=[];e.forEach((e=>e.forEach((e=>r.push(e)))));return{entities:r.map((e=>{if(1===e.length){const t=e[0],s=new Si({lonlat:t,billboard:i});return n(t),s}if(e.length>1){const i=e.map((e=>(n(e),new I(e[0],e[1],e[2]))));return new Si({polyline:{pathLonLat:[i],thickness:3,color:t,isClosed:!1}})}})),extent:s}}_getXmlContent(e){return new Promise((t=>{const i=new FileReader;i.onload=async e=>t((new DOMParser).parseFromString(e.target.result,"text/xml")),i.readAsText(e)}))}_expandExtents(e,t){return e?(t.southWest.lon<e.southWest.lon&&(e.southWest.lon=t.southWest.lon),t.southWest.lat<e.southWest.lat&&(e.southWest.lat=t.southWest.lat),t.northEast.lon>e.northEast.lon&&(e.northEast.lon=t.northEast.lon),t.northEast.lat>e.northEast.lat&&(e.northEast.lat=t.northEast.lat),e):t}async addKmlFromFiles(e,t,i){if(!Array.isArray(e))return null;const s=(await Promise.all(e.map(this._getXmlContent))).map(this._extractCoordonatesFromKml),{entities:n,extent:r}=this._convertCoordonatesIntoEntities(s,t||this._color,i||this._billboard);return this._extent=this._expandExtents(this._extent,r),n.forEach(this.add.bind(this)),{entities:n,extent:r}}setColor(e){this._color=e,this._billboard.color=e}_getKmlFromUrl(e){return new Promise(((t,i)=>{const s=new XMLHttpRequest;s.open("GET",e,!0),s.responseType="document",s.overrideMimeType("text/xml"),s.onload=()=>{s.readyState===s.DONE&&200===s.status?t(s.responseXML):i(new Error("no valid kml file"))},s.send()}))}async addKmlFromUrl(e,t,i){const s=await this._getKmlFromUrl(e),{entities:n,extent:r}=this._convertKMLintoEntities(s);return this._extent=this._expandExtents(this._extent,r),n.forEach(this.add.bind(this)),{entities:n,extent:r}}}class fl extends el{constructor(e,t={}){super(e||"OpenStreetMap",{iconSrc:"https://tile.openstreetmap.org/8/138/95.png",url:"https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png",attribution:"Data @ OpenStreetMap contributors, ODbL",isBaseLayer:!0,maxNativeZoom:19,defaultTextures:[{color:"#AAD3DF"},{color:"#F2EFE9"}],isSRGB:!1,shininess:18,specular:[63e-5,55e-5,32e-5],ambient:[.2,.2,.3],diffuse:[.9,.9,.7],...t})}}function pl(e,t,i){var s="";for(let o=i;o>0;o--){var n=0,r=1<<o-1;e&r&&n++,t&r&&(n+=2),s+=n.toString()}return s}class ml extends el{constructor(e,t={}){super(e||"Bing",{iconSrc:"https://ecn.t0.tiles.virtualearth.net/tiles/a120.jpeg?n=z&g=7146",subdomains:["t0","t1","t2","t3"],url:"https://ecn.{s}.tiles.virtualearth.net/tiles/a{quad}.jpeg?n=z&g=7146",isBaseLayer:!0,textureFilter:"LINEAR",maxNativeZoom:17,defaultTextures:[{color:"#001522"},{color:"#E4E6F3"}],attribution:'<div style="transform: scale(0.8); margin-top:-2px;"><a href="https://www.bing.com" target="_blank"><img style="position: relative; top: 2px;" title="Bing Imagery" src="https://sandcastle.cesium.com/CesiumUnminified/Assets/Images/bing_maps_credit.png"></a> © 2021 Microsoft Corporation</div>',urlRewrite:(e,t)=>we(t,{s:this._getSubdomain(),quad:pl(e.tileX,e.tileY,e.tileZoom)}),specular:[63e-5,55e-5,32e-5],ambient:[.35,.35,.35],diffuse:[1.5,1.5,1.5],shininess:20,nightTextureCoefficient:2.7,...t})}}var vl=Object.freeze({__proto__:null,Bing:ml,CanvasTiles:Kt,GeoImage:dl,GeoTexture2d:_l,GeoVideo:ul,KML:gl,LAYER_EVENTS:Xt,Layer:$t,Material:qt,OpenStreetMap:fl,Vector:qs,WMS:il,XYZ:el});const yl=["tick","end","start","stop"];class xl{constructor(e={}){this.__handler=null,this.active=!0,this.__id=xl.__counter__++,this.events=Mt(yl,this),this.name=e.name||"",this.startDate=e.startDate||0,this.endDate=e.endDate||0;let t=e.currentDate||mt(new Date);e.startDate&&t<e.startDate&&(t=e.startDate),e.endDate&&t>e.endDate&&(t=e.endDate),this.currentDate=t,this._multiplier=void 0!==e.multiplier?e.multiplier:1,this._running=1,this.deltaTicks=0,this.active=!0,this._intervalDelay=0,this._intervalStart=0,this._intervalCallback=null}clearInterval(){this._intervalDelay=0,this._intervalStart=0,this._intervalCallback=null}setInterval(e,t){this._intervalStart=this.currentDate,this._intervalDelay=e*ut,this._intervalCallback=t}setDate(e){let t=mt(e);this.startDate&&t<this.startDate&&(t=this.startDate),this.endDate&&t>this.endDate&&(t=this.endDate),this.currentDate=t}getDate(){return xt(this.currentDate)}reset(){this.startDate&&(this.currentDate=this.startDate)}tick(e){let t=this._multiplier*this._running;if(this.deltaTicks=e*t,this.active){let e=bt(this.currentDate,this.deltaTicks);t>0?this.endDate&&e>this.endDate?(this.currentDate=this.startDate,this.events.dispatch(this.events.end,this)):this.currentDate=e:this.startDate&&e<this.startDate?(this.currentDate=this.endDate,this.events.dispatch(this.events.end,this)):this.currentDate=e,this._intervalCallback&&this.currentDate-this._intervalStart>=this._intervalDelay&&(this._intervalStart=this.currentDate,this._intervalCallback(this)),this.events.dispatch(this.events.tick,this)}}isEqual(e){return this.__id===e.__id}start(){0===this._running&&(this._running=1,this.events.dispatch(this.events.start,this))}get multiplier(){return this._multiplier}set multiplier(e){this._multiplier=e}stop(){1===this._running&&(this._running=0,this.events.dispatch(this.events.stop,this))}}xl.__counter__=0;class bl{constructor(e,t){this._program=t,this._handler=e,this._activated=!1}initialize(){this._handler.gl&&this._program.createProgram(this._handler.gl)}getProgram(){return this._program}activate(){if(!this._activated){this._handler.activeProgram.deactivate(),this._handler.activeProgram=this;let e=this._program;this._activated=!0,e.enableAttribArrays(),e.use()}return this}remove(){let e=this._handler.programs;e[this._program.name]&&(this._activated&&this.deactivate(),this._program.delete(),delete e[this._program.name])}deactivate(){this._program.disableAttribArrays(),this._activated=!1}isActive(){return this._activated}set(e){return this.activate(),this._program.set(e),this}drawIndexBuffer(e,t){return this._program.drawIndexBuffer(e,t),this}drawArrays(e,t){return this._program.drawArrays(e,t),this}}class wl{constructor(){this.next=null,this.prev=null,this.data=null}}class Cl{constructor(e=256){this._current=new wl,this._head=this._current;for(let t=0;t<e;t++){let e=new wl;e.prev=this._current,this._current.next=e,this._current=e}this._current=this._head}current(){return this._current}push(e){this._current=this._current.next,this._current.data=e}pop(){let e=this._current.data;return this._current=this._current.prev,e}popPrev(){return this._current=this._current.prev,this._current.data}}const Tl=["","WEBKIT_","MOZ_"],El=["webgl2","webgl"];class Ll{constructor(e,t={}){this.framebufferStack=new Cl,this._requestAnimationFrameId=0,this.drawFrame=()=>{let e=window.performance.now(),t=this.deltaTime;this.deltaTime=.5*(e-this._lastAnimationFrameTime+this.prevDeltaTime),this.deltaTime>3?this.deltaTime=3:this.deltaTime<1&&(this.deltaTime=1),this.prevDeltaTime=t,this._lastAnimationFrameTime=e,this.defaultClock.tick(this.deltaTime);for(let e=0;e<this._clocks.length;e++)this._clocks[e].tick(this.deltaTime);let i=this.canvas;Math.floor(i.clientWidth*this._params.pixelRatio)===i.width&&Math.floor(i.clientHeight*this._params.pixelRatio)===i.height||(0===i.clientWidth||0===i.clientHeight?this.stop():document.hidden||(this.start(),this.setSize(i.clientWidth,i.clientHeight))),this._frameCallback()},this.events=Mt(["visibilitychange","resize"]),this._throttledDrawFrame=this.drawFrame,this.defaultClock=new xl,this._clocks=[],this.prevDeltaTime=0,this.deltaTime=0,this.canvas=null,this.gl=null,this.programs={},this.activeProgram=null,this._canvasSize=[0,0],this._params={anisotropy:t.anisotropy||4,width:t.width||256,height:t.height||256,pixelRatio:Qe("og_dpi")||t.pixelRatio||1,extensions:t.extensions||[],context:t.context||{}},this._oneByHeight=1/(this._params.height*this._params.pixelRatio),this.extensions={},this._canvasTarget=e,this._lastAnimationFrameTime=0,this._initialized=!1,this._frameCallback=function(){},this.transparentTexture=null,this.defaultTexture=null,this.framebufferStack=new Cl,this.createTexture_n=this.createTexture_n_webgl2.bind(this),this.createTexture_l=this.createTexture_l_webgl2.bind(this),this.createTexture_mm=this.createTexture_mm_webgl2.bind(this),this.createTexture_a=this.createTexture_a_webgl2.bind(this),this.createTexture={NEAREST:this.createTexture_n,LINEAR:this.createTexture_l,MIPMAP:this.createTexture_mm,ANISOTROPIC:this.createTexture_a},this.createTextureDefault=this.createTexture_n,this.ONCANVASRESIZE=null,this._createCanvas(),(t.autoActivate||_e(t.autoActivate))&&this.initialize()}set frameDelay(e){this._throttledDrawFrame=0===e?this.drawFrame:Ne(this.drawFrame,e)}isInitialized(){return this._initialized}_createCanvas(){this._canvasTarget?this._canvasTarget instanceof HTMLElement?this.canvas=this._canvasTarget:this.canvas=document.getElementById(this._canvasTarget)||document.querySelector(this._canvasTarget):(this.canvas=document.createElement("canvas"),this.canvas.width=this._params.width,this.canvas.height=this._params.height)}static getExtension(e,t){if(!e)return;let i,s;for(i in Tl)if(s=e.getExtension(Tl[i]+t),s)return s}static getContext(e,t){let i=null;try{let s=new URLSearchParams(location.search).get("og_ver");if(s)i=e.getContext(s,t),i&&(i.type=s);else for(let s=0;s<El.length;s++)if(i=e.getContext(El[s],t),i){i.type=El[s];break}}catch(e){Bi.logErr("exception during the GL context initialization")}return i||Bi.logErr("could not initialise WebGL"),i}setFrameCallback(e){e&&(this._frameCallback=e)}createEmptyTexture2DExt(e=1,t=1,i="NEAREST",s="RGBA",n="RGBA",r="UNSIGNED_BYTE",o="CLAMP_TO_EDGE",a=0){let l=this.gl,h=l.createTexture();return l.bindTexture(l.TEXTURE_2D,h),l.texImage2D(l.TEXTURE_2D,a,l[s.toUpperCase()],e,t,0,l[n.toUpperCase()],l[r.toUpperCase()],null),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MIN_FILTER,l[i.toUpperCase()]),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_MAG_FILTER,l[i.toUpperCase()]),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_S,l[o.toUpperCase()]),l.texParameteri(l.TEXTURE_2D,l.TEXTURE_WRAP_T,l[o.toUpperCase()]),l.bindTexture(l.TEXTURE_2D,null),h}createEmptyTexture_n(e,t,i,s){let n=this.gl,r=n.createTexture();return n.bindTexture(n.TEXTURE_2D,r),n.texImage2D(n.TEXTURE_2D,0,i||n.RGBA,e,t,0,n.RGBA,n.UNSIGNED_BYTE,null),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,s||n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,s||n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),r}createEmptyTexture_l(e,t,i,s){let n=this.gl,r=n.createTexture();return n.bindTexture(n.TEXTURE_2D,r),n.texImage2D(n.TEXTURE_2D,0,i||n.RGBA,e,t,0,n.RGBA,n.UNSIGNED_BYTE,null),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,s||n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,s||n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),r}createTexture_n_webgl1(e,t,i,s=null){let n=this.gl;return s=s||n.createTexture(),n.bindTexture(n.TEXTURE_2D,s),n.texImage2D(n.TEXTURE_2D,0,t||n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,i||n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,i||n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),s}createTexture_l_webgl1(e,t,i,s=null){let n=this.gl;return s=s||n.createTexture(),n.bindTexture(n.TEXTURE_2D,s),n.texImage2D(n.TEXTURE_2D,0,t||n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,i||n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,i||n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),s}createTexture_mm_webgl1(e,t,i,s=null){let n=this.gl;return s=s||n.createTexture(),n.bindTexture(n.TEXTURE_2D,s),n.texImage2D(n.TEXTURE_2D,0,t||n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e),n.generateMipmap(n.TEXTURE_2D),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR_MIPMAP_LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,i||n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,i||n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),s}createTexture_a_webgl1(e,t,i,s=null){let n=this.gl;return s=s||n.createTexture(),n.bindTexture(n.TEXTURE_2D,s),n.texImage2D(n.TEXTURE_2D,0,t||n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e),n.generateMipmap(n.TEXTURE_2D),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR_MIPMAP_LINEAR),n.texParameterf(n.TEXTURE_2D,this.extensions.EXT_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT,this._params.anisotropy),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,i||n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,i||n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),s}createTexture_n_webgl2(e,t,i,s=null){let n=this.gl;return s=s||n.createTexture(),n.bindTexture(n.TEXTURE_2D,s),n.texStorage2D(n.TEXTURE_2D,1,t||n.RGBA8,e.width,e.height),n.texSubImage2D(n.TEXTURE_2D,0,0,0,e.width,e.height,n.RGBA,n.UNSIGNED_BYTE,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.NEAREST),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,i||n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,i||n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),s}createTexture_l_webgl2(e,t,i,s=null){let n=this.gl;return s=s||n.createTexture(),n.bindTexture(n.TEXTURE_2D,s),n.texStorage2D(n.TEXTURE_2D,1,t||n.RGBA8,e.width,e.height),n.texSubImage2D(n.TEXTURE_2D,0,0,0,e.width,e.height,n.RGBA,n.UNSIGNED_BYTE,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,i||n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,i||n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),s}createTexture_mm_webgl2(e,t,i,s=null){let n=this.gl;return s=s||n.createTexture(),n.bindTexture(n.TEXTURE_2D,s),n.texStorage2D(n.TEXTURE_2D,2,t||n.RGBA8,e.width,e.height),n.texSubImage2D(n.TEXTURE_2D,0,0,0,e.width,e.height,n.RGBA,n.UNSIGNED_BYTE,e),n.generateMipmap(n.TEXTURE_2D),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR_MIPMAP_LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,i||n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,i||n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),s}createTexture_a_webgl2(e,t,i,s=null){let n=this.gl;return s=s||n.createTexture(),n.bindTexture(n.TEXTURE_2D,s),n.texStorage2D(n.TEXTURE_2D,2,t||n.RGBA8,e.width,e.height),n.texSubImage2D(n.TEXTURE_2D,0,0,0,e.width,e.height,n.RGBA,n.UNSIGNED_BYTE,e),n.generateMipmap(n.TEXTURE_2D),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR_MIPMAP_LINEAR),n.texParameterf(n.TEXTURE_2D,this.extensions.EXT_texture_filter_anisotropic.TEXTURE_MAX_ANISOTROPY_EXT,this._params.anisotropy),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,i||n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,i||n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),s}loadCubeMapTexture(e){let t=this.gl,i=t.createTexture();t.bindTexture(t.TEXTURE_CUBE_MAP,i),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MIN_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MAG_FILTER,t.LINEAR);let s=[[e.px,t.TEXTURE_CUBE_MAP_POSITIVE_X],[e.nx,t.TEXTURE_CUBE_MAP_NEGATIVE_X],[e.py,t.TEXTURE_CUBE_MAP_POSITIVE_Y],[e.ny,t.TEXTURE_CUBE_MAP_NEGATIVE_Y],[e.pz,t.TEXTURE_CUBE_MAP_POSITIVE_Z],[e.nz,t.TEXTURE_CUBE_MAP_NEGATIVE_Z]],n=new Uo;n.fillEmpty();let r=n.getImage();for(let e=0;e<s.length;e++){let n=s[e][1];t.bindTexture(t.TEXTURE_CUBE_MAP,i),t.texImage2D(n,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,r)}for(let e=0;e<s.length;e++){let n=s[e][1],r=new Image;r.crossOrigin="",r.onload=function(e,i,s){return function(){t&&e&&(t.bindTexture(t.TEXTURE_CUBE_MAP,e),t.texImage2D(i,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,s))}}(i,n,r),r.src=s[e][0]}return i}addProgram(e,t=!1){if(this.programs[e.name])console.warn(`Shader program: "${e.name}" already exists.`);else{let i=new bl(this,e);this.programs[e.name]=i,this._initProgramController(i),t&&(i._activated=!1)}return e}removeProgram(e){this.programs[e]&&this.programs[e].remove()}addPrograms(e){for(let t=0;t<e.length;t++)this.addProgram(e[t])}_initProgramController(e){this._initialized&&(e.initialize(),this.activeProgram?(e.deactivate(),this.activeProgram._program.enableAttribArrays(),this.activeProgram._program.use()):(this.activeProgram=e,e.activate()))}_initPrograms(){for(let e in this.programs)this._initProgramController(this.programs[e])}initializeExtension(e,t=!1){if(!this.extensions||!this.extensions[e]){let i=Ll.getExtension(this.gl,e);i?this.extensions[e]=i:t&&console.warn("og.webgl.Handler: extension '"+e+"' doesn't initialize.")}return this.extensions&&this.extensions[e]}initialize(){if(this._initialized)return;if(!this.canvas)return;if(this.gl=Ll.getContext(this.canvas,this._params.context),!this.gl)return;this._initialized=!0,this._params.extensions.push("EXT_texture_filter_anisotropic"),"webgl"===this.gl.type?(this._params.extensions.push("OES_standard_derivatives"),this._params.extensions.push("OES_element_index_uint"),this._params.extensions.push("WEBGL_depth_texture"),this._params.extensions.push("ANGLE_instanced_arrays")):(this._params.extensions.push("EXT_color_buffer_float"),this._params.extensions.push("OES_texture_float_linear"));let e=this._params.extensions.length;for(;e--;)this.initializeExtension(this._params.extensions[e],!0);"webgl"===this.gl.type?(this.createTexture_n=this.createTexture_n_webgl1.bind(this),this.createTexture_l=this.createTexture_l_webgl1.bind(this),this.createTexture_mm=this.createTexture_mm_webgl1.bind(this),this.createTexture_a=this.createTexture_a_webgl1.bind(this)):(this.createTexture_n=this.createTexture_n_webgl2.bind(this),this.createTexture_l=this.createTexture_l_webgl2.bind(this),this.createTexture_mm=this.createTexture_mm_webgl2.bind(this),this.createTexture_a=this.createTexture_a_webgl2.bind(this)),this.createTexture.NEAREST=this.createTexture_n,this.createTexture.LINEAR=this.createTexture_l,this.createTexture.MIPMAP=this.createTexture_mm,this.createTexture.ANISOTROPIC=this.createTexture_a,this.extensions.EXT_texture_filter_anisotropic?this.createTextureDefault=this.createTexture_a:this.createTextureDefault=this.createTexture_mm,this._initPrograms(),this._setDefaults(),this.intersectionObserver=new IntersectionObserver((e=>{this._toggleVisibilityChange(e[e.length-1].isIntersecting)}),{threshold:0}),this.intersectionObserver.observe(this.canvas),this.resizeObserver=new ResizeObserver((e=>{this._toggleVisibilityChange(0!==e[0].contentRect.width&&0!==e[0].contentRect.height)})),this.resizeObserver.observe(this.canvas),document.addEventListener("visibilitychange",(()=>{this._toggleVisibilityChange("visible"===document.visibilityState)}))}_toggleVisibilityChange(e){e?(this.start(),this.ONCANVASRESIZE&&this.ONCANVASRESIZE(),this.events.dispatch(this.events.visibilitychange,!0)):(this.events.dispatch(this.events.visibilitychange,!1),this.stop())}_setDefaults(){let e=this.gl;e&&this.canvas&&(e.depthFunc(e.LESS),e.enable(e.DEPTH_TEST),this.setSize(this.canvas.clientWidth||this._params.width,this.canvas.clientHeight||this._params.height),e.frontFace(e.CCW),e.cullFace(e.BACK),e.enable(e.CULL_FACE),e.disable(e.BLEND),this.createDefaultTexture({color:"rgba(0,0,0,0.0)"},(e=>{this.transparentTexture=e})),this.createDefaultTexture({color:"rgba(255, 255, 255, 1.0)"},(e=>{this.defaultTexture=e})))}getCanvasSize(){return this._canvasSize}createStreamArrayBuffer(e,t,i,s=4){let n=this.gl,r=n.createBuffer();return n.bindBuffer(n.ARRAY_BUFFER,r),n.bufferData(n.ARRAY_BUFFER,t*e*s,i||n.STREAM_DRAW),n.bindBuffer(n.ARRAY_BUFFER,null),r.itemSize=e,r.numItems=t,r}setStreamArrayBuffer(e,t,i=0){let s=this.gl;return s.bindBuffer(s.ARRAY_BUFFER,e),s.bufferSubData(s.ARRAY_BUFFER,i,t),s.bindBuffer(s.ARRAY_BUFFER,null),e}createArrayBuffer(e,t,i,s){let n=this.gl,r=n.createBuffer();return n.bindBuffer(n.ARRAY_BUFFER,r),n.bufferData(n.ARRAY_BUFFER,e,s||n.STATIC_DRAW),n.bindBuffer(n.ARRAY_BUFFER,null),r.itemSize=t,r.numItems=i,r}createArrayBufferLength(e,t){let i=this.gl,s=i.createBuffer();return i.bindBuffer(i.ARRAY_BUFFER,s),i.bufferData(i.ARRAY_BUFFER,e,t||i.STATIC_DRAW),i.bindBuffer(i.ARRAY_BUFFER,null),s.itemSize=1,s.numItems=e,s}createElementArrayBuffer(e,t,i,s){let n=this.gl,r=n.createBuffer();return n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,r),n.bufferData(n.ELEMENT_ARRAY_BUFFER,e,s||n.STATIC_DRAW),n.bindBuffer(n.ELEMENT_ARRAY_BUFFER,null),r.itemSize=t,r.numItems=i||e.length,r}setSize(e,t){this._params.width=e,this._params.height=t,this.canvas&&(this.canvas.width=e*this._params.pixelRatio,this.canvas.height=t*this._params.pixelRatio,this._canvasSize[0]=this.canvas.width,this._canvasSize[1]=this.canvas.height,this._oneByHeight=1/this.canvas.height,this.gl&&this.gl.viewport(0,0,e,t),this.ONCANVASRESIZE&&this.ONCANVASRESIZE(this.canvas),this.events.dispatch(this.events.resize,this))}get pixelRatio(){return this._params.pixelRatio}set pixelRatio(e){this._params.pixelRatio=e,this.setSize(this._params.width,this._params.height)}getWidth(){return this.canvas?this.canvas.width:0}getHeight(){return this.canvas?this.canvas.height:0}getClientAspect(){return this.canvas?this.canvas.clientWidth/this.canvas.clientHeight:0}getCenter(){let e=this.canvas;return e?new ae(Math.round(.5*e.width),Math.round(.5*e.height)):new ae}clearFrame(){let e=this.gl;e.clearColor(0,0,0,1),e.clear(e.COLOR_BUFFER_BIT|e.DEPTH_BUFFER_BIT)}start(){!this._requestAnimationFrameId&&this._initialized&&this._animationFrameCallback()}stop(){this._requestAnimationFrameId&&(window.cancelAnimationFrame(this._requestAnimationFrameId),this._requestAnimationFrameId=0)}isStopped(){return!this._requestAnimationFrameId}isWebGl2(){return!!this.gl&&"webgl2"===this.gl.type}_animationFrameCallback(){this._requestAnimationFrameId=window.requestAnimationFrame((()=>{this._throttledDrawFrame(),this._requestAnimationFrameId&&this._animationFrameCallback()}))}createDefaultTexture(e,t){let i,s;if(e&&e.color)i=new Uo(2,2),i.fillColor(e.color),s=this.createTexture_n(i.getCanvas()),s.default=!0,t(s);else if(e&&e.url){let i=new Image,n=this;i.onload=function(){s=n.createTextureDefault(i),s.default=!0,t(s)},i.src=e.url}else i=new Uo(2,2),i.fillColor("#C5C5C5"),s=this.createTexture_n(i.getCanvas()),s.default=!0,t(s)}deleteTexture(e){e&&!e.default&&this.gl.deleteTexture(e)}destroy(){this.resizeObserver?.disconnect(),this.intersectionObserver?.disconnect(),this.stop();for(let e in this.programs)this.removeProgram(e);let e=this.gl;if(e){e.deleteTexture(this.transparentTexture),this.transparentTexture=null,e.deleteTexture(this.defaultTexture),this.defaultTexture=null,this.framebufferStack=new Cl;let t=e.getParameter(e.MAX_VERTEX_ATTRIBS),i=e.createBuffer();e.bindBuffer(e.ARRAY_BUFFER,i);for(let i=0;i<t;++i)e.disableVertexAttribArray(i),e.vertexAttribPointer(i,4,e.FLOAT,!1,0,0),e.vertexAttrib1f(i,0);e.deleteBuffer(i);let s=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS);for(let t=0;t<s;++t)e.activeTexture(e.TEXTURE0+t),e.bindTexture(e.TEXTURE_CUBE_MAP,null),e.bindTexture(e.TEXTURE_2D,null);e.activeTexture(e.TEXTURE0),e.useProgram(null),e.bindBuffer(e.ARRAY_BUFFER,null),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,null),e.bindFramebuffer(e.FRAMEBUFFER,null),e.bindRenderbuffer(e.RENDERBUFFER,null),e.disable(e.BLEND),e.disable(e.CULL_FACE),e.disable(e.DEPTH_TEST),e.disable(e.DITHER),e.disable(e.SCISSOR_TEST),e.blendColor(0,0,0,0),e.blendEquation(e.FUNC_ADD),e.blendFunc(e.ONE,e.ZERO),e.clearColor(0,0,0,0),e.clearDepth(1),e.clearStencil(-1)}this.canvas&&(this.canvas.parentNode&&this.canvas.parentNode.removeChild(this.canvas),this.canvas.width=1,this.canvas.height=1,this.canvas=null),this.gl=null,this._initialized=!1}addClock(e){e.__handler||(e.__handler=this,this._clocks.push(e))}addClocks(e){for(let t=0;t<e.length;t++)this.addClock(e[t])}removeClock(e){if(e.__handler){let t=this._clocks,i=t.length;for(;i--;)if(t[i].isEqual(e)){e.__handler=null,t.splice(i,1);break}}}}class Al extends Vo{constructor(e,t={}){super(e,t),this._internalFormat=t.internalFormat?t.internalFormat.toUpperCase():"RGBA8",this._msaa=null!=t.msaa?t.msaa:4,this._glFilter=0,this.renderbuffers=new Array(this._size)}destroy(){let e=this.handler.gl;if(e){for(let t=0;t<this.renderbuffers.length;t++)e.deleteRenderbuffer(this.renderbuffers[t]);this.renderbuffers=new Array(this._size),e.deleteFramebuffer(this._fbo),e.deleteRenderbuffer(this._depthRenderbuffer),this._depthRenderbuffer=null,this._fbo=null,this._active=!1}}init(){let e=this.handler.gl;if(!e)return;this._glFilter=e[this._filter],this._fbo=e.createFramebuffer(),e.bindFramebuffer(e.FRAMEBUFFER,this._fbo);let t=[];for(let i=0;i<this.renderbuffers.length;i++){let s=e.createRenderbuffer();e.bindRenderbuffer(e.RENDERBUFFER,s),this._msaa>0?e.renderbufferStorageMultisample(e.RENDERBUFFER,this._msaa,e[this._internalFormat],this._width,this._height):e.renderbufferStorage(e.RENDERBUFFER,e[this._internalFormat],this._width,this._height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.COLOR_ATTACHMENT0+i,e.RENDERBUFFER,s),t.push(e.COLOR_ATTACHMENT0+i),this.renderbuffers[i]=s,e.bindRenderbuffer(e.RENDERBUFFER,null)}e.drawBuffers(t),this._useDepth&&(this._depthRenderbuffer=e.createRenderbuffer(),e.bindRenderbuffer(e.RENDERBUFFER,this._depthRenderbuffer),e.renderbufferStorageMultisample(e.RENDERBUFFER,this._msaa,e[this._depthComponent],this._width,this._height),e.framebufferRenderbuffer(e.FRAMEBUFFER,e.DEPTH_ATTACHMENT,e.RENDERBUFFER,this._depthRenderbuffer),e.bindRenderbuffer(e.RENDERBUFFER,null)),e.bindFramebuffer(e.FRAMEBUFFER,null)}blitTo(e,t=0){let i=this.handler.gl;i.bindFramebuffer(i.READ_FRAMEBUFFER,this._fbo),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,e._fbo),i.readBuffer(i.COLOR_ATTACHMENT0+t),i.clearBufferfv(i.COLOR,0,[0,0,0,1]),i.blitFramebuffer(0,0,this._width,this._height,0,0,e._width,e._height,i.COLOR_BUFFER_BIT,this._glFilter),i.bindFramebuffer(i.FRAMEBUFFER,null),i.bindFramebuffer(i.READ_FRAMEBUFFER,null),i.bindFramebuffer(i.DRAW_FRAMEBUFFER,null)}}var Pl=Object.freeze({__proto__:null,Framebuffer:Yo,Handler:Ll,Multisample:Al,Program:Ni,types:Ii});const Sl=function(e,t){return Number(e.priority<t.priority)};class Ml{constructor(){this._currentlyPressedKeys={},this._pressedKeysCallbacks={},this._unpressedKeysCallbacks={},this._charkeysCallbacks={},this._anykeyCallback=null,this._event=null,this._active=!0,this._stampCache={},document.onkeydown=e=>{this._event=e,this._active&&this.handleKeyDown()},document.onkeyup=e=>{this._event=e,this._active&&this.handleKeyUp()}}getcurrentlyPressedKeys(){return this._currentlyPressedKeys}getPressedKeysCallbacks(){return this._pressedKeysCallbacks}getUnpressedKeysCallbacks(){return this._unpressedKeysCallbacks}getCharkeysCallbacks(){return this._charkeysCallbacks}removeEvent(e,t,i){let s=this._getStamp(e,t,i._openglobus_id);i._openglobus_id&&this._stampCache[s]&&(delete this._stampCache[s],"keypress"===e?this._removeCallback(this._pressedKeysCallbacks[t],i):"keyfree"===e?this._removeCallback(this._unpressedKeysCallbacks[t],i):"charkeypress"===e&&this._removeCallback(this._charkeysCallbacks[t],i))}_removeCallback(e,t){for(let i=0;i<e.length;i++)e[i].callback._openglobus_id===t._openglobus_id&&e.splice(i,1)}_getStamp(e,t,i){return`${e}_${t}_${i}`}_stamp(e,t,i){const s=fe(i),n=this._getStamp(e,t,s);return!this._stampCache[n]&&(this._stampCache[n]=s,!0)}setActivity(e){this._active=e}releaseKeys(){this._currentlyPressedKeys={}}addEvent(e,t,i,s,n){if(this._stamp(e,t,i))switch(void 0===n&&(n=1600),e){case"keyfree":this._unpressedKeysCallbacks[t]||(this._unpressedKeysCallbacks[t]=[]),this._unpressedKeysCallbacks[t].push({callback:i,sender:s,priority:n}),this._unpressedKeysCallbacks[t].sort(Sl);break;case"keypress":null==t?this._anykeyCallback={callback:i,sender:s||this}:(this._pressedKeysCallbacks[t]||(this._pressedKeysCallbacks[t]=[]),this._pressedKeysCallbacks[t].push({callback:i,sender:s,priority:n}),this._pressedKeysCallbacks[t].sort(Sl));break;case"charkeypress":this._charkeysCallbacks[t]||(this._charkeysCallbacks[t]=[]),this._charkeysCallbacks[t].push({callback:i,sender:s,priority:n}),this._charkeysCallbacks[t].sort(Sl)}}isKeyPressed(e){return this._currentlyPressedKeys[e]}handleKeyDown(){this._anykeyCallback&&this._anykeyCallback.callback.call(this._anykeyCallback.sender,this._event),this._currentlyPressedKeys[this._event.keyCode]=!0;for(let e in this._charkeysCallbacks)if(String.fromCharCode(this._event.keyCode)===String.fromCharCode(Number(e))){let t=this._charkeysCallbacks[e];for(let e=0;e<t.length;e++)t[e].callback.call(t[e].sender,this._event)}this._event.keyCode!=Cn.KEY_ALT&&this._event.keyCode!=Cn.KEY_SHIFT||this._event.preventDefault()}handleKeyUp(){if(this._currentlyPressedKeys[this._event.keyCode]||this._event.keyCode===Cn.KEY_PRINTSCREEN)for(let e in this._unpressedKeysCallbacks)if(this._currentlyPressedKeys[e]||this._event.keyCode===Cn.KEY_PRINTSCREEN&&Number(e)===Cn.KEY_PRINTSCREEN){let t=this._unpressedKeysCallbacks[e];for(let e=0;e<t.length;e++)t[e].callback.call(t[e].sender,this._event)}this._currentlyPressedKeys[this._event.keyCode]=!1}handleEvents(){for(let e in this._pressedKeysCallbacks)if(this._currentlyPressedKeys[e]){let t=this._pressedKeysCallbacks[e];for(let e=0;e<t.length;e++)t[e].callback.call(t[e].sender,this._event)}}}class Rl{constructor(e){this._htmlObject=e}setEvent(e,t,i){switch(e){case"mousewheel":this._htmlObject.addEventListener("wheel",(e=>{let s=e.deltaY||e.detail||e.wheelDelta||0;var n;null==e.wheelDelta&&(e.wheelDelta=-120*s),e.isTouchPad=0===(n=e).deltaMode&&Math.abs(n.deltaY)<50,i.call(t,e),e.preventDefault()}),!1);break;case"mousedown":this._htmlObject.addEventListener("mousedown",(function(e){let s=this.getBoundingClientRect();i.call(t,e,{button:e.button,clientX:e.clientX-s.left,clientY:e.clientY-s.top})})),this._htmlObject.addEventListener("contextmenu",(function(e){return e.preventDefault(),!1}));break;case"mouseup":this._htmlObject.addEventListener("mouseup",(function(e){let s=this.getBoundingClientRect();i.call(t,e,{button:e.button,clientX:e.clientX-s.left,clientY:e.clientY-s.top})}));break;case"mousemove":this._htmlObject.addEventListener("mousemove",(function(e){let s=this.getBoundingClientRect();i.call(t,e,{clientX:e.clientX-s.left,clientY:e.clientY-s.top})}));break;case"mouseleave":this._htmlObject.addEventListener("mouseleave",(function(e){i.call(t,e)}));break;case"mouseout":this._htmlObject.addEventListener("mouseout",(function(e){i.call(t,e)}));break;case"mouseover":this._htmlObject.addEventListener("mouseover",(function(e){i.call(t,e)}));break;case"mouseenter":this._htmlObject.addEventListener("mouseenter",(function(e){i.call(t,e)}))}}}class Bl{constructor(e){this._htmlObject=e}setEvent(e,t,i){switch(e){case"touchcancel":this._htmlObject.addEventListener("touchcancel",(function(e){e.preventDefault();const s=this.getBoundingClientRect(),n=Object.assign(e,{offsetLeft:s.left,offsetTop:s.top});i.call(t,n)}));break;case"touchstart":this._htmlObject.addEventListener("touchstart",(function(e){e.preventDefault();const s=this.getBoundingClientRect(),n=Object.assign(e,{offsetLeft:s.left,offsetTop:s.top});i.call(t,n)}));break;case"touchend":this._htmlObject.addEventListener("touchend",(function(e){e.preventDefault();const s=this.getBoundingClientRect(),n=Object.assign(e,{offsetLeft:s.left,offsetTop:s.top});i.call(t,n)}));break;case"touchmove":this._htmlObject.addEventListener("touchmove",(function(e){e.preventDefault();const s=this.getBoundingClientRect(),n=Object.assign(e,{offsetLeft:s.left,offsetTop:s.top});i.call(t,n)}))}}}let kl=new Uint8Array(4),Il=new Uint8Array(4),zl=new Uint8Array(4);class Dl extends Rt{constructor(e){super(Fl),this.renderer=e,this._touchHandler=new Bl(e.handler.canvas),this._mouseHandler=new Rl(e.handler.canvas),this._keyboardHandler=new Ml,this._active=!0,this.clickRadius=15,this.mouseState={clientX:0,clientY:0,pos:new ae,x:0,y:0,nx:0,ny:0,prev_x:0,prev_y:0,direction:new oe,leftButtonUp:!1,rightButtonUp:!1,middleButtonUp:!1,leftButtonDown:!1,rightButtonDown:!1,middleButtonDown:!1,leftButtonHold:!1,rightButtonHold:!1,middleButtonHold:!1,leftButtonDoubleClick:!1,rightButtonDoubleClick:!1,middleButtonDoubleClick:!1,leftButtonClick:!1,rightButtonClick:!1,middleButtonClick:!1,moving:!1,justStopped:!1,doubleClickDelay:500,clickDelay:200,wheelDelta:0,sys:null,pickingObject:null,renderer:e,isTouchPad:!1},this.touchState={moving:!1,touchEnd:!1,touchStart:!1,touchCancel:!1,doubleTouch:!1,doubleTouchDelay:550,doubleTouchRadius:10,clientX:0,clientY:0,pos:new ae,x:0,y:0,nx:0,ny:0,prev_x:0,prev_y:0,direction:new oe,sys:null,pickingObject:null,renderer:e},this._isMouseInside=!0,this._entityPickingEventsActive=!0,this._dblTchCoords=new ae,this._oneTouchStart=!1,this._dblTchBegins=0,this._mousestopThread=null,this._ldblClkBegins=0,this._rdblClkBegins=0,this._mdblClkBegins=0,this._lClkBegins=0,this._rClkBegins=0,this._mClkBegins=0,this._lclickX=0,this._lclickY=0,this._rclickX=0,this._rclickY=0,this._mclickX=0,this._mclickY=0}pointerEvent(){let e=this.mouseState,t=this.touchState;return e.moving||e.justStopped||t.moving||t.touchStart||t.touchEnd||0!==e.wheelDelta}get active(){return this._active}set active(e){this._active=e,this._keyboardHandler.setActivity(e)}handleEvents(){this._active&&(this.mouseState.direction=this.renderer.activeCamera.unproject(this.mouseState.x,this.mouseState.y),this.touchState.direction=this.renderer.activeCamera.unproject(this.touchState.x,this.touchState.y),this._keyboardHandler.handleEvents(),this.handleMouseEvents(),this.handleTouchEvents(),this.entityPickingEvents())}on(e,t,i,s,n){"keypress"===e||"charkeypress"===e||"keyfree"===e?this._keyboardHandler.addEvent(e,t,i,s,n):super.on(e,t,i,s)}off(e,t,i){"keypress"===e||"charkeypress"===e||"keyfree"===e?this._keyboardHandler.removeEvent(e,t,i):super.off(e,t)}isKeyPressed(e){return this._keyboardHandler.isKeyPressed(e)}releaseKeys(){this._keyboardHandler.releaseKeys()}initialize(){this._mouseHandler.setEvent("mouseup",this,this.onMouseUp),this._mouseHandler.setEvent("mousemove",this,this.onMouseMove),this._mouseHandler.setEvent("mousedown",this,this.onMouseDown),this._mouseHandler.setEvent("mousewheel",this,this.onMouseWheel),this._mouseHandler.setEvent("mouseleave",this,this.onMouseLeave),this._mouseHandler.setEvent("mouseenter",this,this.onMouseEnter),this._touchHandler.setEvent("touchstart",this,this.onTouchStart),this._touchHandler.setEvent("touchend",this,this.onTouchEnd),this._touchHandler.setEvent("touchcancel",this,this.onTouchCancel),this._touchHandler.setEvent("touchmove",this,this.onTouchMove)}onMouseWheel(e){this.mouseState.isTouchPad=e.isTouchPad||!1,this.mouseState.sys=e,this.mouseState.wheelDelta=e.wheelDelta||0}updateButtonsStates(e){let t=this.mouseState;1&e&&t.leftButtonDown?t.leftButtonDown=!0:(t.leftButtonHold=!1,t.leftButtonDown=!1),2&e&&t.rightButtonDown?t.rightButtonDown=!0:(t.rightButtonHold=!1,t.rightButtonDown=!1),4&e&&t.middleButtonDown?t.middleButtonDown=!0:(t.middleButtonHold=!1,t.middleButtonDown=!1)}onMouseMove(e,t){let i=this.mouseState;this.updateButtonsStates(e.buttons),i.sys=e;let s=t.clientX,n=t.clientY,r=this.clickRadius;if(Math.abs(this._lclickX-s)>=r&&Math.abs(this._lclickY-n)>=r&&(this._ldblClkBegins=0,this._lClkBegins=0),Math.abs(this._rclickX-s)>=r&&Math.abs(this._rclickY-n)>=r&&(this._rdblClkBegins=0,this._rClkBegins=0),Math.abs(this._mclickX-s)>=r&&Math.abs(this._mclickY-n)>=r&&(this._mdblClkBegins=0,this._mClkBegins=0),i.clientX===t.clientX&&i.clientY===t.clientY)return;i.clientX=t.clientX,i.clientY=t.clientY;let o=this.renderer.handler;i.pos.x=i.x=t.clientX*o.pixelRatio,i.pos.y=i.y=t.clientY*o.pixelRatio,i.nx=i.x/o.canvas.width,i.ny=i.y/o.canvas.height,i.moving=!0,clearTimeout(this._mousestopThread),this._mousestopThread=setTimeout((function(){i.justStopped=!0}),100)}onMouseLeave(e){this._isMouseInside=!1,this.mouseState.sys=e,this.dispatch(this.mouseleave,this.mouseState)}onMouseEnter(e){this._isMouseInside=!0,this.mouseState.sys=e,this.dispatch(this.mouseenter,this.mouseState)}onMouseDown(e,t){t.button===Cn.MB_LEFT?(this._lClkBegins=window.performance.now(),this._lclickX=t.clientX,this._lclickY=t.clientY,this.mouseState.sys=e,this.mouseState.leftButtonDown=!0):t.button===Cn.MB_RIGHT?(this._rClkBegins=window.performance.now(),this._rclickX=t.clientX,this._rclickY=t.clientY,this.mouseState.sys=e,this.mouseState.rightButtonDown=!0):t.button===Cn.MB_MIDDLE&&(this._mClkBegins=window.performance.now(),this._mclickX=t.clientX,this._mclickY=t.clientY,this.mouseState.sys=e,this.mouseState.middleButtonDown=!0)}onMouseUp(e,t){let i=this.mouseState;i.sys=e;let s=window.performance.now();if(t.button===Cn.MB_LEFT){if(i.leftButtonDown=!1,i.leftButtonUp=!0,Math.abs(this._lclickX-t.clientX)<this.clickRadius&&Math.abs(this._lclickY-t.clientY)<this.clickRadius&&s-this._lClkBegins<=i.clickDelay){if(this._ldblClkBegins){window.performance.now()-this._ldblClkBegins<=i.doubleClickDelay&&(i.leftButtonDoubleClick=!0),this._ldblClkBegins=0}else this._ldblClkBegins=window.performance.now();i.leftButtonClick=!0,this._lClkBegins=0}}else if(t.button===Cn.MB_RIGHT){if(i.rightButtonDown=!1,i.rightButtonUp=!0,Math.abs(this._rclickX-t.clientX)<this.clickRadius&&Math.abs(this._rclickY-t.clientY)<this.clickRadius&&s-this._rClkBegins<=i.clickDelay){if(this._rdblClkBegins){window.performance.now()-this._rdblClkBegins<=i.doubleClickDelay&&(i.rightButtonDoubleClick=!0),this._rdblClkBegins=0}else this._rdblClkBegins=window.performance.now();i.rightButtonClick=!0,this._rClkBegins=0}}else if(t.button===Cn.MB_MIDDLE&&(i.middleButtonDown=!1,i.middleButtonUp=!0,Math.abs(this._mclickX-t.clientX)<this.clickRadius&&Math.abs(this._mclickY-t.clientY)<this.clickRadius&&s-this._mClkBegins<=i.clickDelay)){if(this._mdblClkBegins){window.performance.now()-this._mdblClkBegins<=i.doubleClickDelay&&(i.middleButtonDoubleClick=!0),this._mdblClkBegins=0}else this._mdblClkBegins=window.performance.now();i.middleButtonClick=!0,this._mClkBegins=0}}onTouchStart(e){let t=this.touchState;t.sys=e,t.clientX=e.touches.item(0).clientX-e.offsetLeft,t.clientY=e.touches.item(0).clientY-e.offsetTop;let i=this.renderer.handler;t.pos.x=t.x=t.clientX*i.pixelRatio,t.pos.y=t.y=t.clientY*i.pixelRatio,t.nx=t.x/i.canvas.width,t.ny=t.y/i.canvas.height,t.prev_x=t.x,t.prev_y=t.y,t.touchStart=!0,1===e.touches.length?(this._dblTchCoords.x=t.x,this._dblTchCoords.y=t.y,this._oneTouchStart=!0):this._oneTouchStart=!1}onTouchEnd(e){let t=this.touchState;if(t.sys=e,t.touchEnd=!0,0===e.touches.length&&(t.prev_x=t.x,t.prev_y=t.y,this._oneTouchStart)){if(this._dblTchBegins){window.performance.now()-this._dblTchBegins<=t.doubleTouchDelay&&(t.doubleTouch=!0),this._dblTchBegins=0}this._dblTchBegins=window.performance.now(),this._oneTouchStart=!1}}onTouchCancel(e){let t=this.touchState;t.sys=e,t.touchCancel=!0}onTouchMove(e){let t=this.touchState;t.clientX=e.touches.item(0).clientX-e.offsetLeft,t.clientY=e.touches.item(0).clientY-e.offsetTop;let i=this.renderer.handler;t.x=t.clientX*i.pixelRatio,t.y=t.clientY*i.pixelRatio,t.nx=t.x/i.canvas.width,t.ny=t.y/i.canvas.height,t.sys=e,t.moving=!0;let s=t.x-t.prev_x,n=t.y-t.prev_y;(Math.abs(s)>9||Math.abs(n)>9)&&(this._dblTchBegins=0,this._oneTouchStart=!1)}entityPickingEvents(){let e=this.touchState,t=this.mouseState;if(this._isMouseInside!==this._entityPickingEventsActive&&(this._entityPickingEventsActive=this._isMouseInside,!this._entityPickingEventsActive)){let i=this.renderer,s=kl,n=i.getPickingObjectArr(s);if(n){let i=n.rendererEvents;t.pickingObject=n,i&&i.dispatch(i.mouseleave,t),e.pickingObject=n,i&&i.dispatch(i.touchleave,e)}kl[0]=kl[1]=kl[2]=kl[3]=zl[0]=zl[1]=zl[2]=zl[3]=Il[0]=Il[1]=Il[2]=Il[3]=0}if(this._isMouseInside&&!(t.leftButtonHold||t.rightButtonHold||t.middleButtonHold)){let i=this.renderer,s=kl,n=zl,r=Il;e.x||e.y?i.readPickingColor(e.nx,1-e.ny,r):i.readPickingColor(t.nx,1-t.ny,r),n[0]=s[0],n[1]=s[1],n[2]=s[2],s[0]=r[0],s[1]=r[1],s[2]=r[2],t.pickingObject=null,e.pickingObject=null;let o=i.getPickingObjectArr(s);if(t.pickingObject=o,e.pickingObject=o,s[0]!==n[0]||s[1]!==n[1]||s[2]!==n[2])if((e=>!(e[0]||e[1]||e[2]))(s)){let s=i.getPickingObjectArr(n);if(s){let i=s.rendererEvents;t.pickingObject=s,i&&i.dispatch(i.mouseleave,t),e.pickingObject=s,i&&i.dispatch(i.touchleave,e)}}else{if((e=>!!(e[0]||e[1]||e[2]))(n)){let s=i.getPickingObjectArr(n);if(s){let i=s.rendererEvents;t.pickingObject=s,i&&i.dispatch(i.mouseleave,t),e.pickingObject=s,i&&i.dispatch(i.touchleave,e)}}if(o){let i=o.rendererEvents;t.pickingObject=o,i&&i.dispatch(i.mouseenter,t),e.pickingObject=o,i&&i.dispatch(i.touchenter,e)}}}}handleMouseEvents(){let e=this,t=this.mouseState,i=t.pickingObject,s=null;t.leftButtonClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.lclick,t)),this.dispatch(e.lclick,t),t.leftButtonClick=!1),t.rightButtonClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.rclick,t)),this.dispatch(e.rclick,t),t.rightButtonClick=!1),t.middleButtonClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.mclick,t)),this.dispatch(e.mclick,t),t.middleButtonClick=!1),t.leftButtonDown&&(t.leftButtonHold?(i&&(s=i.rendererEvents,s&&s.dispatch(s.lhold,t)),this.dispatch(e.lhold,t)):(t.leftButtonHold=!0,i&&(s=i.rendererEvents,s&&s.dispatch(s.ldown,t)),this.dispatch(e.ldown,t))),t.rightButtonDown&&(t.rightButtonHold?(i&&(s=i.rendererEvents,s&&s.dispatch(s.rhold,t)),this.dispatch(e.rhold,t)):(t.rightButtonHold=!0,i&&(s=i.rendererEvents,s&&s.dispatch(s.rdown,t)),this.dispatch(e.rdown,t))),t.middleButtonDown&&(t.middleButtonHold?(i&&(s=i.rendererEvents,s&&s.dispatch(s.mhold,t)),this.dispatch(e.mhold,t)):(t.middleButtonHold=!0,i&&(s=i.rendererEvents,s&&s.dispatch(s.mdown,t)),this.dispatch(e.mdown,t))),t.leftButtonUp&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.lup,t)),this.dispatch(e.lup,t),t.leftButtonUp=!1,t.leftButtonHold=!1),t.rightButtonUp&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.rup,t)),this.dispatch(e.rup,t),t.rightButtonUp=!1,t.rightButtonHold=!1),t.middleButtonUp&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.mup,t)),this.dispatch(e.mup,t),t.middleButtonUp=!1,t.middleButtonHold=!1),t.leftButtonDoubleClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.ldblclick,t)),this.dispatch(e.ldblclick,t),t.leftButtonDoubleClick=!1),t.rightButtonDoubleClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.rdblclick,t)),this.dispatch(e.rdblclick,t),t.rightButtonDoubleClick=!1),t.middleButtonDoubleClick&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.mdblclick,t)),this.dispatch(e.mdblclick,t),t.middleButtonDoubleClick=!1),t.wheelDelta&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.mousewheel,t)),this.dispatch(e.mousewheel,t)),t.moving&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.mousemove,t)),this.dispatch(e.mousemove,t),t.prev_x=t.x,t.prev_y=t.y),t.justStopped&&this.dispatch(e.mousestop,t)}handleTouchEvents(){let e=this,t=this.touchState,i=t.pickingObject,s=null;if(t.touchCancel&&(this.dispatch(e.touchcancel,t),t.touchCancel=!1),t.touchStart){let n=this.renderer;n.readPickingColor(t.nx,1-t.ny,kl);let r=n.getPickingObjectArr(kl);i=t.pickingObject=r,i&&(s=i.rendererEvents,s&&s.dispatch(s.touchstart,t)),this.dispatch(e.touchstart,t),t.touchStart=!1}t.doubleTouch&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.doubletouch,t)),this.dispatch(e.doubletouch,t),t.doubleTouch=!1),t.touchEnd&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.touchend,t)),this.dispatch(e.touchend,t),t.x=0,t.y=0,t.touchEnd=!1),t.moving&&(i&&(s=i.rendererEvents,s&&s.dispatch(s.touchmove,t)),this.dispatch(e.touchmove,t),t.prev_x=t.x,t.prev_y=t.y)}}const Fl=["changerelativecenter","draw","drawtransparent","postdraw","resize","resizeend","mouseenter","mouseleave","mousemove","mousestop","lclick","rclick","mclick","ldblclick","rdblclick","mdblclick","lup","rup","mup","ldown","rdown","mdown","lhold","rhold","mhold","mousewheel","touchstart","touchend","touchcancel","touchmove","doubletouch","touchleave","touchenter"];class Nl{constructor(e=0,t=0,i=0,s=0){this.left=e,this.right=i,this.top=t,this.bottom=s}set(e=0,t=0,i=0,s=0){this.left=e,this.right=i,this.top=t,this.bottom=s}clone(){return new Nl(this.left,this.top,this.right,this.bottom)}getWidth(){return Math.abs(this.right-this.left)}getHeight(){return Math.abs(this.bottom-this.top)}getSquare(){return this.getHeight()*this.getWidth()}getDiagonal(){let e=this.getWidth(),t=this.getHeight();return Math.sqrt(t*t+e*e)}fit(e,t){return this.getWidth()===e&&this.getHeight()===t}isInside(e,t){return e>=this.left&&e<=this.right&&t>=this.top&&t<=this.bottom}}class Hl{constructor(){this.imagesCache={},this._counter=0,this._pendingsQueue=new xa,this._imageIndexCounter=0}load(e,t){if(this.imagesCache[e])t(this.imagesCache[e]);else{let i={src:e,success:t};this._counter>=1?this._pendingsQueue.unshift(i):this._exec(i)}}_exec(e){this._counter++;const t=this;let i=new Image;i.crossOrigin="",i.onload=function(){t.imagesCache[e.src]=i,i.__nodeIndex=t._imageIndexCounter++,e.success(i),t._dequeueRequest()},i.onerror=function(){t._dequeueRequest()},i.src=e.src}_dequeueRequest(){if(this._counter--,this._pendingsQueue.length&&this._counter<1)for(;this._pendingsQueue.length;){let e=this._pendingsQueue.pop();if(e){if(!this.imagesCache[e.src]){this._exec(e);break}this._counter<=0?this._counter=0:this._counter--,e.success(this.imagesCache[e.src])}}}}class Ol{constructor(e=1024,t=1024){this.nodes=new Map,this.texture=null,this.canvas=new Uo(e,t),this.clearCanvas(),this._handler=null,this._images=[],this._btree=null,this._imagesCacheManager=new Hl,this.borderSize=4}getImage(){return this.canvas.getImage()}getCanvas(){return this.canvas.getCanvas()}clearCanvas(){this.canvas.fillEmpty()}assignHandler(e){this._handler=e,this.createTexture()}getDiagonal(e){let t=e.atlasWidth||e.width,i=e.atlasHeight||e.height;return Math.sqrt(t*t+i*i)}addImage(e,t=!1){if(e.width&&e.height)return this._images.push(e),this._makeAtlas(t),null!=e.__nodeIndex?this.get(e.__nodeIndex):void 0}_completeNode(e,t){if(t){let i=this.canvas.getWidth(),s=this.canvas.getHeight(),n=t.image,r=t.rect,o=Math.round(.5*this.borderSize);this.canvas.drawImage(n,r.left+o,r.top+o,n.atlasWidth||0,n.atlasHeight||0);let a=t.texCoords;a[0]=(r.left+o)/i,a[1]=(r.top+o)/s,a[2]=(r.left+o)/i,a[3]=(r.bottom-o)/s,a[4]=(r.right-o)/i,a[5]=(r.bottom-o)/s,a[6]=(r.right-o)/i,a[7]=(r.bottom-o)/s,a[8]=(r.right-o)/i,a[9]=(r.top+o)/s,a[10]=(r.left+o)/i,a[11]=(r.top+o)/s,e.set(n.__nodeIndex,t)}}_makeAtlas(e=!1){if(e&&this._btree){let e=this._images[this._images.length-1];this._completeNode(this.nodes,this._btree.insert(e))}else{let e=this._images.slice(0);e.sort((function(e,t){return(t.atlasWidth||t.width)-(e.atlasWidth||e.width)||(t.atlasHeight||t.height)-(e.atlasHeight||e.height)})),this._btree=new Vl(new Nl(0,0,this.canvas.getWidth(),this.canvas.getHeight())),this._btree.atlas=this,this.clearCanvas();let t=new Map;for(let i=0;i<e.length;i++)this._completeNode(t,this._btree.insert(e[i]));this.nodes=null,this.nodes=t}}get(e){return this.nodes.get(e)}set(e,t){this.nodes.set(e,t)}createTexture(e,t){this._handler&&(this._handler.gl.deleteTexture(this.texture),e&&(this.canvas.resize(e.width,e.height),this.canvas.drawImage(e,0,0,e.width,e.height)),this.texture=this._handler.createTexture_l(this.canvas.getCanvas(),t))}loadImage(e,t){this._imagesCacheManager.load(e,t)}getImageTexCoordinates(e){if(null!=e.__nodeIndex){let t=this.get(e.__nodeIndex);if(t)return t.texCoords}}}class Vl{constructor(e,t){this.childNodes=null,this.image=null,this.rect=e||new Nl,this.texCoords=t||[],this.atlas=null}insert(e){if(this.childNodes){let t=this.childNodes[0].insert(e);return t||this.childNodes[1].insert(e)}{if(null!=this.image)return;let t=this.rect;const i=(e.atlasWidth||e.width)+this.atlas.borderSize,s=(e.atlasHeight||e.height)+this.atlas.borderSize;if(i>t.getWidth()||s>t.getHeight())return;if(t.fit(i,s))return this.image=e,this;this.childNodes=new Array(2),this.childNodes[0]=new Vl,this.childNodes[0].atlas=this.atlas,this.childNodes[1]=new Vl,this.childNodes[1].atlas=this.atlas;return t.getWidth()-i>t.getHeight()-s?(this.childNodes[0].rect.set(t.left,t.top,t.left+i,t.bottom),this.childNodes[1].rect.set(t.left+i,t.top,t.right,t.bottom)):(this.childNodes[0].rect.set(t.left,t.top,t.right,t.top+s),this.childNodes[1].rect.set(t.left,t.top+s,t.right,t.bottom)),this.childNodes[0].insert(e)}}}class Ul extends Ol{constructor(e,t){super(e,t),this.width=0,this.height=0,this.gliphSize=0,this.distanceRange=0,this.nodes=new Map,this.kernings={}}get(e){return this.nodes.get(e)}}class Gl extends Vl{constructor(e,t){super(e,t),this.emptySize=1,this.metrics={id:0,char:"",width:0,height:0,x:0,y:0,chnl:0,index:0,page:0,xadvance:0,xoffset:0,yoffset:0,nChar:"",nCode:0,nWidth:0,nHeight:0,nAdvance:0,nXOffset:0,nYOffset:0}}}class Yl{constructor(e){this.atlasesArr=[],this.atlasIndexes={},this.atlasIndexesDeferred={},this.tokenImageSize=64,this.samplerArr=new Uint32Array(11),this.sdfParamsArr=new Float32Array(44),this._handler=null,this.catalogSrc=e||"./"}assignHandler(e){this._handler=e}getFontIndex(e){let t=this.getFullIndex(e);return this.atlasIndexes[t]||this.loadFont(e,this.catalogSrc,`${e}.json`),this.atlasIndexesDeferred[t]||(this.atlasIndexesDeferred[t]=new xr),this.atlasIndexesDeferred[t].promise}getFullIndex(e){return e.trim().toLowerCase()}_applyFontDataToAtlas(e,t,i=0){let s=t.chars;e.height=t.common.scaleH,e.width=t.common.scaleW,e.gliphSize=t.info.size,e.distanceRange=t.distanceField.distanceRange;let n=e.width,r=e.height,o=e.gliphSize;this.sdfParamsArr[4*i]=n,this.sdfParamsArr[4*i+1]=r,this.sdfParamsArr[4*i+2]=o,this.sdfParamsArr[4*i+3]=e.distanceRange;let a={};for(let t=0;t<s.length;t++){let i=s[t],l=i.char;a[i.id]=l;let h=new Nl(i.x,i.y,i.x+i.width,i.y+i.height),c=new Array(12);c[0]=h.left/n,c[1]=h.top/r,c[2]=h.left/n,c[3]=h.bottom/r,c[4]=h.right/n,c[5]=h.bottom/r,c[6]=h.right/n,c[7]=h.bottom/r,c[8]=h.right/n,c[9]=h.top/r,c[10]=h.left/n,c[11]=h.top/r;let d=new Gl(h,c),_=i.char.normalize("NFKC"),u=_.charCodeAt(0),g=d.metrics;g.id=i.id,g.char=i.char,g.width=i.width,g.height=i.height,g.x=i.x,g.y=i.y,g.chnl=i.chnl,g.index=i.index,g.page=i.page,g.xadvance=i.xadvance,g.xoffset=i.xoffset,g.yoffset=i.yoffset,g.nChar=_,g.nCode=u,g.nWidth=d.metrics.width/o,g.nHeight=d.metrics.height/o,g.nAdvance=d.metrics.xadvance/o,g.nXOffset=d.metrics.xoffset/o,g.nYOffset=1-d.metrics.yoffset/o,d.emptySize=1,e.nodes.set(_.charCodeAt(0),d)}e.kernings={};for(let i=0;i<t.kernings.length;i++){let s=t.kernings[i],n=s.first,r=s.second;e.kernings[n]||(e.kernings[n]={}),e.kernings[n][r]=s.amount/o}}initFont(e,t,i){let s=this.atlasesArr.length,n=this.getFullIndex(e);this.atlasIndexes[n]=s;let r=this.atlasIndexesDeferred[n];r||(r=this.atlasIndexesDeferred[n]=new xr),this.samplerArr[this.atlasesArr.length]=s;let o=new Ul;o.height=0,o.width=0,o.gliphSize=0,o.distanceRange=0,o.kernings={},o.assignHandler(this._handler),this.atlasesArr[s]=o,this._applyFontDataToAtlas(o,t,s);let a=new Image;a.onload=()=>{this._createTexture(o,a),r.resolve(s)},a.src=i}_createTexture(e,t){e.createTexture(t)}loadFont(e,t,i){let s=this.atlasesArr.length,n=this.getFullIndex(e);this.atlasIndexes[n]=s;let r=this.atlasIndexesDeferred[n];r||(r=this.atlasIndexesDeferred[n]=new xr),this.samplerArr[this.atlasesArr.length]=s;let o=new Ul;o.height=0,o.width=0,o.gliphSize=0,o.distanceRange=0,o.kernings={},o.assignHandler(this._handler),this.atlasesArr[s]=o,fetch(`${t}/${i}`).then((e=>{if(!e.ok)throw Error(`Unable to load "${t}/${i}"`);return e.json()})).then((e=>{this._applyFontDataToAtlas(o,e,s);let i=new Image;i.onload=()=>{this._createTexture(o,i),r.resolve(s)},i.src=`${t}/${e.pages[0]}`,i.crossOrigin="Anonymous"})).catch((e=>(r.reject(),{status:"error",msg:e.toString()})))}}let jl=0,Wl=0,ql=new Float32Array(2);class $l{constructor(e,t={}){if(this.div=null,this.handler=e instanceof Ll?e:new Ll(e,{pixelRatio:t.dpi||window.devicePixelRatio+.15,autoActivate:!0}),this.exposure=t.exposure||3.01,this.gamma=t.gamma||.47,this.whitepoint=1,this.brightThreshold=.9,this._renderNodesArr=[],this.renderNodes={},this.activeCamera=new Va(this,{eye:new oe(0,0,0),look:new oe(0,0,-1),up:new oe(0,1,0)}),this.events=new Dl(this),this.controls={},t.controls)for(let e in t.controls)this.controls[t.controls[e].name]=t.controls[e];this.controlsBag={},this.colorObjects=new Map,this._pickingCallbacks=[],this.pickingFramebuffer=null,this._depthCallbacks=[],this.depthFramebuffer=null;let i=new URLSearchParams(location.search),s=i.get("og_msaa");this._msaa=s?Number(i.get("og_msaa")):null!=t.msaa?t.msaa:0,this._internalFormat="RGBA16F",this._format="RGBA",this._type="FLOAT",this.sceneFramebuffer=null,this.blitFramebuffer=null,this.toneMappingFramebuffer=null,this._initialized=!1,this.billboardsTextureAtlas=new Ol,this.geoObjectsTextureAtlas=new Ol,this.fontAtlas=new Yl(t.fontsSrc),this._entityCollections=[[]],this._currentOutput="screen",this._fnScreenFrame=null,this.labelWorker=new si(4),this.screenDepthFramebuffer=null,this.screenFramePositionBuffer=null,this.screenTexture={},this.outputTexture=null,this._readPickingBuffer=this._readPickingBuffer_webgl2,(t.autoActivate||_e(t.autoActivate))&&this.start()}enableBlendOneSrcAlpha(){let e=this.handler.gl;e.enable(e.BLEND),e.blendEquation(e.FUNC_ADD),e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA)}enableBlendDefault(){let e=this.handler.gl;e.enable(e.BLEND),e.blendEquation(e.FUNC_ADD),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE)}setRelativeCenter(e){this.events.dispatch(this.events.changerelativecenter,e||this.activeCamera.eye)}setEventsActivity(e){this.events.active=e}addDepthCallback(e,t){let i=Wl++;return this._depthCallbacks.push({id:i,callback:t,sender:e}),i}removeDepthCallback(e){for(let t=0;t<this._depthCallbacks.length;t++)if(e===this._depthCallbacks[t].id){this._depthCallbacks.splice(t,1);break}}addPickingCallback(e,t){let i=jl++;return this._pickingCallbacks.push({id:i,callback:t,sender:e}),i}removePickingCallback(e){for(let t=0;t<this._pickingCallbacks.length;t++)if(e===this._pickingCallbacks[t].id){this._pickingCallbacks.splice(t,1);break}}getPickingObject(e,t,i){return this.colorObjects.get(`${e}_${t}_${i}`)}getPickingObjectArr(e){return this.colorObjects.get(`${e[0]}_${e[1]}_${e[2]}`)}getPickingObject3v(e){return this.colorObjects.get(`${e.x}_${e.y}_${e.z}`)}assignPickingColor(e){if(!e._pickingColor||e._pickingColor.isZero()){let t=0,i=0,s=0,n="0_0_0";for(;!(t||i||s)||this.colorObjects.has(n);)t=x(1,255),i=x(1,255),s=x(1,255),n=`${t}_${i}_${s}`;e._pickingColor?e._pickingColor.set(t,i,s):e._pickingColor=new oe(t,i,s),e._pickingColorU=new Float32Array([t/255,i/255,s/255]),this.colorObjects.set(n,e)}}clearPickingColor(e){if(e._pickingColor&&!e._pickingColor.isZero()){let t=e._pickingColor;t.isZero()||(this.colorObjects.delete(`${t.x}_${t.y}_${t.z}`),t.x=t.y=t.z=0)}}getWidth(){return this.handler.canvas.clientWidth}getHeight(){return this.handler.canvas.clientHeight}getCenter(){let e=this.handler.canvas;return new ae(Math.round(.5*e.width),Math.round(.5*e.height))}getClientCenter(){let e=this.handler.canvas;return new ae(Math.round(.5*e.clientWidth),Math.round(.5*e.clientHeight))}addControl(e){e.addTo(this)}addControls(e){for(let t=0;t<e.length;t++)e[t].addTo(this)}removeControl(e){e.remove()}isInitialized(){return this._initialized}initialize(){if(!this._initialized){if(this._initialized=!0,this.handler.initialize(),this.billboardsTextureAtlas.assignHandler(this.handler),this.geoObjectsTextureAtlas.assignHandler(this.handler),this.fontAtlas.assignHandler(this.handler),this.handler.setFrameCallback((()=>{this.draw()})),this.events.initialize(),this.events.on("charkeypress",Cn.KEY_APOSTROPHE,(function(){Bi.setVisibility(!Bi.getVisibility())})),this.handler.addProgram(new Ni("screenFrame",{uniforms:{texture:"sampler2d"},attributes:{corners:"vec3"},vertexShader:"attribute vec2 corners;\n \n varying vec2 tc;\n void main(void) {\n gl_Position = vec4(corners, 0.0, 1.0);\n tc = corners * 0.5 + 0.5;\n }",fragmentShader:"precision highp float;\n uniform sampler2D texture;\n \n varying vec2 tc;\n \n void main(void) {\n gl_FragColor = texture2D( texture, tc );\n }"})),this.pickingFramebuffer=new Yo(this.handler,{width:640,height:480,targets:[{readAsync:!0}]}),this.pickingFramebuffer.init(),this.depthFramebuffer=new Yo(this.handler,{width:640,height:480,targets:[{internalFormat:"RGBA",type:"UNSIGNED_BYTE",attachment:"COLOR_ATTACHMENT",readAsync:!0},{internalFormat:"RGBA16F",type:"FLOAT",attachment:"COLOR_ATTACHMENT",readAsync:!0}],useDepth:!0}),this.depthFramebuffer.init(),this.screenDepthFramebuffer=new Yo(this.handler,{useDepth:!1}),this.screenDepthFramebuffer.init(),"webgl"===this.handler.gl.type)this._readPickingBuffer=this._readPickingBuffer_webgl1,this.sceneFramebuffer=new Yo(this.handler),this.sceneFramebuffer.init(),this._fnScreenFrame=this._screenFrameNoMSAA,this.screenTexture={screen:this.sceneFramebuffer.textures[0],picking:this.pickingFramebuffer.textures[0],depth:this.screenDepthFramebuffer.textures[0]};else{let e=this.getMaxMSAA(this._internalFormat);this._msaa>e&&(this._msaa=e),this.handler.addPrograms([new Ni("toneMapping",{uniforms:{hdrBuffer:"sampler2d",exposure:"float",gamma:"float",whitepoint:"float"},attributes:{corners:"vec3"},vertexShader:"#version 300 es\n \n in vec2 corners;\n \n out vec2 tc;\n\n void main(void) {\n gl_Position = vec4(corners, 0.0, 1.0);\n tc = corners * 0.5 + 0.5;\n }",fragmentShader:"#version 300 es\n\n precision highp float;\n\n #ifndef saturate\n #define saturate(a) clamp(a, 0.0, 1.0)\n #endif\n\n uniform sampler2D hdrBuffer;\n\n uniform float whitepoint;\n uniform float exposure;\n uniform float gamma;\n\n vec3 LinearToneMapping(vec3 color) {\n return exposure * color;\n }\n\n vec3 ReinhardToneMapping2(vec3 color) {\n return vec3(1.0) - exp(-color * exposure);\n }\n\n vec3 ReinhardToneMapping(vec3 color) {\n color *= exposure;\n return saturate(color / (vec3(1.0) + color));\n }\n\n #define Uncharted2Helper(x) max(((x * (0.15 * x + 0.10 * 0.50) + 0.20 * 0.02) / (x * (0.15 * x + 0.50) + 0.20 * 0.30)) - 0.02 / 0.30, vec3(0.0))\n\n vec3 Uncharted2ToneMapping(vec3 color) {\n color *= exposure;\n return saturate(Uncharted2Helper(color) / Uncharted2Helper(vec3(whitepoint)));\n }\n\n vec3 OptimizedCineonToneMapping(vec3 color) {\n color *= exposure;\n color = max(vec3(0.0), color - 0.004);\n return pow((color * (6.2 * color + 0.5)) / (color * (6.2 * color + 1.7) + 0.06), vec3(2.2));\n }\n\n vec3 ACESFilmicToneMapping(vec3 color) {\n color *= exposure;\n return saturate((color * (2.51 * color + 0.03)) / (color * (2.43 * color + 0.59) + 0.14));\n }\n\n in vec2 tc;\n\n layout(location = 0) out vec4 fragColor;\n \n void main(void) {\n vec4 hdrColor = texture(hdrBuffer, tc).rgba;\n \n float oneByGamma = gamma / gamma;\n float oneByWhitePoint = whitepoint / whitepoint;\n vec3 mapped = ReinhardToneMapping2(hdrColor.rgb) * oneByGamma * oneByWhitePoint;\n //vec3 mapped = ACESFilmicToneMapping(hdrColor.rgb) * oneByGamma * oneByWhitePoint;\n\n mapped = pow(mapped, vec3(1.0 / gamma));\n \n fragColor = vec4(mapped, hdrColor.a);\n }"})]),this.handler.addPrograms([new Ni("depth",{uniforms:{depthTexture:"sampler2D"},attributes:{corners:"vec2"},vertexShader:"#version 300 es\n \n in vec2 corners;\n \n out vec2 tc;\n\n void main(void) {\n gl_Position = vec4(corners, 0.0, 1.0);\n tc = corners * 0.5 + 0.5;\n }",fragmentShader:"#version 300 es\n\n precision highp float;\n\n uniform sampler2D depthTexture;\n \n in vec2 tc;\n\n layout(location = 0) out vec4 fragColor;\n\n float LinearizeDepth(in vec2 uv)\n {\n return texture(depthTexture, tc).r;\n }\n \n void main(void) {\n float c = LinearizeDepth(tc);\n fragColor = vec4(c, c, c, 1.0);\n }"})]),this.sceneFramebuffer=new Al(this.handler,{size:1,msaa:this._msaa,internalFormat:this._internalFormat,filter:"LINEAR"}),this.sceneFramebuffer.init(),this.blitFramebuffer=new Yo(this.handler,{size:1,useDepth:!1,targets:[{internalFormat:this._internalFormat,format:this._format,type:this._type,filter:"NEAREST"}]}),this.blitFramebuffer.init(),this.toneMappingFramebuffer=new Yo(this.handler,{useDepth:!1}),this.toneMappingFramebuffer.init(),this._fnScreenFrame=this._screenFrameMSAA,this.screenTexture={screen:this.toneMappingFramebuffer.textures[0],picking:this.pickingFramebuffer.textures[0],depth:this.screenDepthFramebuffer.textures[0],frustum:this.depthFramebuffer.textures[0]}}this.handler.ONCANVASRESIZE=()=>{this._resizeStart(),this.events.dispatch(this.events.resize,this.handler.canvas),this._resizeEnd(),this.events.dispatch(this.events.resizeend,this.handler.canvas)},this.screenFramePositionBuffer=this.handler.createArrayBuffer(new Float32Array([1,1,-1,1,1,-1,-1,-1]),2,4),this.outputTexture=this.screenTexture.screen,this._initializeRenderNodes(),this._initializeControls()}}_initializeControls(){let e=this.controls;this.controls={};for(let t in e)this.addControl(e[t])}resize(){this._resizeEnd()}setCurrentScreen(e){this._currentOutput=e,this.screenTexture[e]&&(this.outputTexture=this.screenTexture[e])}_resizeStart(){let e=this.handler.canvas;this.activeCamera.setAspectRatio(e.width/e.height),this.sceneFramebuffer.setSize(.5*e.width,.5*e.height),this.blitFramebuffer&&this.blitFramebuffer.setSize(.5*e.width,.5*e.height,!0)}_resizeEnd(){let e=this.handler.canvas;this.activeCamera.setAspectRatio(e.width/e.height),this.sceneFramebuffer.setSize(e.width,e.height),this.blitFramebuffer&&this.blitFramebuffer.setSize(e.width,e.height,!0),this.toneMappingFramebuffer&&this.toneMappingFramebuffer.setSize(e.width,e.height,!0),this.screenDepthFramebuffer&&this.screenDepthFramebuffer.setSize(e.clientWidth,e.clientHeight,!0),"webgl"===this.handler.gl.type?(this.screenTexture.screen=this.sceneFramebuffer.textures[0],this.screenTexture.picking=this.pickingFramebuffer.textures[0],this.screenTexture.depth=this.screenDepthFramebuffer.textures[0],this.screenTexture.frustum=this.depthFramebuffer.textures[0]):(this.screenTexture.screen=this.toneMappingFramebuffer.textures[0],this.screenTexture.picking=this.pickingFramebuffer.textures[0],this.screenTexture.depth=this.screenDepthFramebuffer.textures[0],this.screenTexture.frustum=this.depthFramebuffer.textures[0]),this.setCurrentScreen(this._currentOutput)}removeNode(e){e.remove()}addNode(e){this.renderNodes[e.name]?Bi.logWrn(`Node name ${e.name} already exists.`):(e.assign(this),this._renderNodesArr.unshift(e),this.renderNodes[e.name]=e)}_initializeRenderNodes(){for(let e=0;e<this._renderNodesArr.length;e++)this._renderNodesArr[e].initialize()}addNodeBefore(e,t){if(this.renderNodes[e.name])Bi.logWrn(`Node name ${e.name} already exists.`);else{e.assign(this),this.renderNodes[e.name]=e;for(let i=0;i<this._renderNodesArr.length;i++)if(this._renderNodesArr[i].isEqual(t)){this._renderNodesArr.splice(i,0,e);break}this._renderNodesArr.unshift(e)}}addNodes(e){for(let t=0;t<e.length;t++)this.addNode(e[t])}getMaxMSAA(e){let t=this.handler.gl;return t.getInternalformatParameter(t.RENDERBUFFER,t[e],t.SAMPLES)[0]}getMSAA(){return this._msaa}enqueueEntityCollectionsToDraw(e,t=0){this._entityCollections[t]||(this._entityCollections[t]=[]),this._entityCollections[t].push(...e)}_drawEntityCollections(e){let t=this._entityCollections[e];if(t.length){let e=this.handler.gl;this.enableBlendDefault();let i=t.length;for(;i--;)t[i]._fadingOpacity&&t[i].pointCloudHandler.draw();for(i=t.length;i--;){let e=t[i];t[i]._fadingOpacity&&(e.events.dispatch(e.events.draw,e),t[i].geoObjectHandler.draw())}for(e.activeTexture(e.TEXTURE0),e.bindTexture(e.TEXTURE_2D,this.billboardsTextureAtlas.texture),i=t.length;i--;){let e=t[i];e._fadingOpacity&&e.billboardHandler.draw()}let s=this.fontAtlas.atlasesArr;for(i=0;i<s.length;i++)e.activeTexture(e.TEXTURE0+i),e.bindTexture(e.TEXTURE_2D,s[i].texture);for(i=t.length;i--;)t[i]._fadingOpacity&&t[i].labelHandler.draw();for(i=t.length;i--;)t[i]._fadingOpacity&&t[i].rayHandler.draw();for(i=t.length;i--;)t[i]._fadingOpacity&&t[i].polylineHandler.draw();for(i=t.length;i--;)t[i]._fadingOpacity&&t[i].stripHandler.draw()}}_drawPickingEntityCollections(e){let t=this._entityCollections[e];if(t.length){let e=t.length;for(;e--;)t[e]._fadingOpacity&&t[e].billboardHandler.drawPicking();for(e=t.length;e--;)t[e]._fadingOpacity&&t[e].geoObjectHandler.drawPicking();for(e=t.length;e--;)t[e]._fadingOpacity&&t[e].labelHandler.drawPicking();for(e=t.length;e--;)t[e]._fadingOpacity&&t[e].rayHandler.drawPicking();for(e=t.length;e--;)t[e]._visibility&&t[e].polylineHandler.drawPicking();for(e=t.length;e--;)t[e]._visibility&&t[e].stripHandler.drawPicking()}}_drawDepthEntityCollections(e){let t=this._entityCollections[e];if(t.length){let e=t.length;for(;e--;)t[e]._fadingOpacity&&t[e].geoObjectHandler.drawDepth()}}_clearEntityCollectionQueue(e){this._entityCollections[e].length=0,this._entityCollections[e]=[]}draw(){this.activeCamera.checkMoveEnd();let e=this.events;e.handleEvents();let t=this.sceneFramebuffer;t.activate();let i=this.handler.gl;i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT),this.enableBlendDefault(),e.dispatch(e.draw,this);let s=this.activeCamera.frustums,n=e.pointerEvent(),r=!e.mouseState.leftButtonDown&&!e.mouseState.rightButtonDown,o=this._renderNodesArr,a=s.length;for(;a--;){this.activeCamera.setCurrentFrustum(a),i.clear(i.DEPTH_BUFFER_BIT);let t=o.length;for(;t--;)o[t].preDrawNode();for(t=o.length;t--;)this.enableBlendDefault(),o[t].drawNode();this._drawEntityCollections(0),e.dispatch(e.drawtransparent,this),n&&r&&this._drawPickingBuffer(0),this._drawDepthBuffer(0),this._clearEntityCollectionQueue(0)}for(let e=1;e<this._entityCollections.length;e++){i.clear(i.DEPTH_BUFFER_BIT);let t=s.length;for(;t--;)this.activeCamera.setCurrentFrustum(t),this._drawEntityCollections(e),n&&r&&this._drawPickingBuffer(e),this._drawDepthBuffer(e);this._clearEntityCollectionQueue(e)}t.deactivate(),this.blitFramebuffer&&t.blitTo(this.blitFramebuffer,0),n&&r&&this._readPickingBuffer(),r&&this._readDepthBuffer(),this._fnScreenFrame(),e.dispatch(e.postdraw,this),e.mouseState.wheelDelta=0,e.mouseState.justStopped=!1,e.mouseState.moving=!1,e.touchState.moving=!1}getImageDataURL(e="image/png",t=1){return this.draw(),this.handler.canvas?this.handler.canvas.toDataURL(e,t):""}_screenFrameMSAA(){let e=this.handler,t=e.programs.toneMapping,i=t._program,s=e.gl;s.disable(s.DEPTH_TEST),s.bindBuffer(s.ARRAY_BUFFER,this.screenFramePositionBuffer),s.vertexAttribPointer(i.attributes.corners,2,s.FLOAT,!1,0,0),this.toneMappingFramebuffer.activate(),t.activate(),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,this.blitFramebuffer.textures[0]),s.uniform1i(i.uniforms.hdrBuffer,0),s.uniform1f(i.uniforms.gamma,this.gamma),s.uniform1f(i.uniforms.exposure,this.exposure),s.uniform1f(i.uniforms.whitepoint,this.whitepoint),s.drawArrays(s.TRIANGLE_STRIP,0,4),this.toneMappingFramebuffer.deactivate(),t=e.programs.screenFrame,i=t._program,t.activate(),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,this.outputTexture),s.uniform1i(i.uniforms.texture,0),s.drawArrays(s.TRIANGLE_STRIP,0,4),s.enable(s.DEPTH_TEST)}_screenFrameNoMSAA(){let e=this.handler,t=e.programs.screenFrame,i=t._program,s=e.gl;s.disable(s.DEPTH_TEST),t.activate(),s.activeTexture(s.TEXTURE0),s.bindTexture(s.TEXTURE_2D,this.outputTexture),s.uniform1i(i.uniforms.texture,0),s.bindBuffer(s.ARRAY_BUFFER,this.screenFramePositionBuffer),s.vertexAttribPointer(i.attributes.corners,2,s.FLOAT,!1,0,0),s.drawArrays(s.TRIANGLE_STRIP,0,4),s.enable(s.DEPTH_TEST)}_drawPickingBuffer(e){this.pickingFramebuffer.activate();let t=this.handler.gl;if(this.activeCamera.isFirstPass&&0===e?(t.clearColor(0,0,0,1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT)):t.clear(t.DEPTH_BUFFER_BIT),t.disable(t.BLEND),0===e){let e=this._pickingCallbacks;for(let t=0,i=e.length;t<i;t++)e[t].callback.call(e[t].sender)}this._drawPickingEntityCollections(e),t.enable(t.BLEND),this.pickingFramebuffer.deactivate()}_drawDepthBuffer(e){this.depthFramebuffer.activate();let t=this.handler,i=t.gl;if(i.disable(i.BLEND),this.activeCamera.isFirstPass&&0===e?(i.clearColor(0,0,0,1),i.clear(i.COLOR_BUFFER_BIT|i.DEPTH_BUFFER_BIT)):i.clear(i.DEPTH_BUFFER_BIT),0===e){let e=this._depthCallbacks,t=e.length;for(;t--;)e[t].callback.call(e[t].sender)}if(this._drawDepthEntityCollections(e),this.depthFramebuffer.deactivate(),"depth"===this._currentOutput||"frustum"===this._currentOutput){this.screenDepthFramebuffer.activate();let e=t.programs.depth,s=e._program;i.bindBuffer(i.ARRAY_BUFFER,this.screenFramePositionBuffer),i.vertexAttribPointer(s.attributes.corners,2,i.FLOAT,!1,0,0),e.activate(),i.activeTexture(i.TEXTURE0),i.bindTexture(i.TEXTURE_2D,this.depthFramebuffer.textures[1]),i.uniform1i(s.uniforms.depthTexture,0),i.drawArrays(i.TRIANGLE_STRIP,0,4),this.screenDepthFramebuffer.deactivate(),i.enable(i.BLEND)}}_readDepthBuffer(){this.depthFramebuffer.readPixelBuffersAsync()}_readPickingBuffer_webgl1(){this.pickingFramebuffer.readPixelBuffersAsync()}_readPickingBuffer_webgl2(){this.pickingFramebuffer.readPixelBuffersAsync()}readPickingColor(e,t,i){let s=this.pickingFramebuffer.width,n=this.pickingFramebuffer.height;e=Math.round(e*s);let r=4*((t=Math.round(t*n))*s+e),o=this.pickingFramebuffer?.pixelBuffers[0].data;o&&(i[0]=o[r],i[1]=o[r+1],i[2]=o[r+2])}readDepth(e,t,i){let s=this.depthFramebuffer.width,n=this.depthFramebuffer.height;e=Math.round(e*s);let r=4*((t=Math.round(t*n))*s+e),o=this.depthFramebuffer?.pixelBuffers[1].data,a=this.depthFramebuffer?.pixelBuffers[0].data;o&&(i[0]=o[r],i[1]=Math.round(a[r]/10)-1)}getDistanceFromPixel(e,t){t=t||this.activeCamera;let i=this,s=i.handler.canvas,n=e.x/s.width,r=(s.height-e.y)/s.height;ql[0]=ql[1]=0;let o=0;if(i.readDepth(n,r,ql),-1===ql[1])return;let a=ql[0],l=t.frustums[ql[1]];if(!l)return;let h=new se(2*n-1,2*r-1,2*a-1,1),c=l.inverseProjectionMatrix.mulVec4(h),d=e.direction||i.activeCamera.unproject(e.x,e.y);return o=-c.z/c.w/d.dot(i.activeCamera.getForward()),o}getCartesianFromPixel(e){let t=this.getDistanceFromPixel(e);if(t){return(e.direction||this.activeCamera.unproject(e.x,e.y)).scaleTo(t).addA(this.activeCamera.eye)}}start(){this._initialized||this.initialize(),this.handler.start()}destroy(){for(let e in this.controls)this.controls[e].remove();for(let e=0;e<this._renderNodesArr.length;e++)this._renderNodesArr[e].remove();this.div=null,this._renderNodesArr=[],this.renderNodes={},this.activeCamera=null,this.controls={},this.controlsBag={},this.colorObjects.clear(),this.colorObjects=null,this._pickingCallbacks=[],this.pickingFramebuffer=null,this._tempPickingPix_=null,this._depthCallbacks=[],this.depthFramebuffer=null,this.sceneFramebuffer=null,this.blitFramebuffer=null,this.toneMappingFramebuffer=null,this._entityCollections=[[]],this.handler.ONCANVASRESIZE=null,this.handler.destroy(),this.handler=null,this._initialized=!1}}const Xl="/res";class Zl{constructor(e){this.$target=null,this._instanceID=`__globus${Zl.__counter__++?Zl.__counter__:""}__`,window[this._instanceID]=this,this._canvas=document.createElement("canvas"),this._canvas.id=`canvas${this._instanceID}`,this._canvas.style.width="100%",this._canvas.style.height="100%",this._canvas.style.display="block",this._canvas.style.opacity="0.0",this._canvas.style.transition="opacity 150ms",this.$inner=document.createElement("div"),this.$inner.classList.add("og-inner"),this.$inner.appendChild(this._canvas),this.$inner.attributions=document.createElement("div"),e.attributionContainer?e.attributionContainer.appendChild(this.$inner.attributions):(this.$inner.attributions.classList.add("og-attribution"),this.$inner.appendChild(this.$inner.attributions)),e.target&&this.attachTo(e.target);const t=e=>{e.preventDefault()};this._canvas.onmouseenter=function(){document.addEventListener("mousewheel",t,{capture:!1,passive:!1})},this._canvas.onmouseleave=function(){document.removeEventListener("mousewheel",t)},this.renderer=new $l(new Ll(this._canvas,{autoActivate:!1,pixelRatio:e.dpi||window.devicePixelRatio+.15,context:{antialias:!1,premultipliedAlpha:!1,preserveDrawingBuffer:!1}}),{autoActivate:!1,msaa:e.msaa,fontsSrc:e.fontsSrc,gamma:e.gamma,exposure:e.exposure}),this.renderer.div=this.$inner,e.skybox&&this.renderer.addNode(e.skybox),this._planetName=e.name?e.name:"globus_planet_"+Zl.__counter__,this.planet=new qa({name:this._planetName,frustums:e.frustums,ellipsoid:e.ellipsoid,maxGridSize:e.maxGridSize,nightTextureSrc:null===e.nightTextureSrc?null:e.nightTextureSrc||`${e.resourcesSrc||Xl}/night.png`,specularTextureSrc:null===e.specularTextureSrc?null:e.specularTextureSrc||`${e.resourcesSrc||Xl}/spec.png`,minAltitude:e.minAltitude,maxAltitude:e.maxAltitude||15e6,maxEqualZoomAltitude:e.maxEqualZoomAltitude,minEqualZoomAltitude:e.minEqualZoomAltitude,minEqualZoomCameraSlope:e.minEqualZoomCameraSlope,quadTreeStrategyPrototype:e.quadTreeStrategyPrototype,maxLoadingRequests:e.maxLoadingRequests,atmosphereEnabled:e.atmosphereEnabled,transitionOpacityEnabled:e.transitionOpacityEnabled,atmosphereParameters:e.atmosphereParameters}),e.terrain?Array.isArray(e.terrain)?this.planet.setTerrain(e.terrain[0]):this.planet.setTerrain(e.terrain):this.planet.setTerrain(new Ka),this.renderer.addNode(this.planet),e.controls?this.planet.addControls(e.controls):this.planet.addControls([new nr,new zn,new sr,new xn,new Zn,new Ft]);const i=this.renderer.controls;let s;for(let e in i)if(i[e]instanceof tr){s=i[e];break}s?this.sun=s:(this.sun=new tr,this.planet.addControl(this.sun)),e.sun&&(void 0===e.sun.active||e.sun.active||this.sun.deactivate(),!0===e.sun.stopped&&this.sun.stop()),e.layers&&this.planet.addLayers(e.layers);let n=e.viewExtent;n&&(n instanceof Array?this.planet.viewExtentArr(n):this.planet.viewExtent(n)),(e.autoActivate||_e(e.autoActivate))&&this.start()}start(){this.renderer.start(),this.fadeIn()}fadeIn(){this._canvas.style.opacity="1.0"}fadeOut(){this._canvas.style.opacity="0"}attachTo(e,t){let i;this.detach(),i=e instanceof HTMLElement?e:document.getElementById(e)||document.querySelector(e),i?(this.$target=i,t&&this.$target.firstChild?this.$target.insertBefore(this.$inner,this.$target.firstChild):i.appendChild(this.$inner)):console.warn(`Target container not found. Provided target: ${e}`)}detach(){this.$target&&(this.$target.removeChild(this.$inner),this.$target=null)}destroy(){this.detach(),this.planet.layers.forEach((e=>e.remove())),this.planet.destroy(),this.renderer.destroy(),window[this._instanceID]=null}}Zl.__counter__=0;const Kl=new he(3396200,3389508),Ql=new he(1737400,1737400),Jl=`<div class="og-popup {className}">\n <div class="og-popup-content-wrapper">\n <div class="og-popup-content"></div>\n </div>\n <div class="og-popup-tip-container">\n <div class="og-popup-tip"></div>\n </div>\n <div class="og-popup-toolbar">\n <div class="og-popup-btn og-popup-close">${Nt}</div>\n </div>\n <div class="og-popup-title">{title}</div>\n </div>`,eh=["open","close"];const th=5/Math.pow(2,5);class ih extends Ea{constructor(e,t,i,s){super(e,t,i,s),this._projection=za,this.isPole=!1,this._tileGroup=0}_getMaxZoom(){let e=0;if(this._extent.northEast.lat>85){let t=Math.floor((90-this._extent.northEast.lat)/th);e=Math.floor(t/16)+5}else if(this._extent.southWest.lat<-85){let t=Math.floor((90+this._extent.southWest.lat)/th);e=Math.floor(t/16)+5}else e=50;return e}_assignTileYIndexes(e){const t=e.getCenter().lat;this.tileY=Qo(t,e.getHeight(),90),this.tileYN=this.tileY-1,this.tileYS=this.tileY+1}_assignTileXIndexes(e){let t=e.getCenter().lon;this.tileX=Qo(t,e.getWidth(),-180);let i=2*(1<<this.tileZoom);this.tileXE=(this.tileX+1)%i,this.tileXW=(i+this.tileX-1)%i}getDefaultTexture(){return this.planet.solidTextureOne}}class sh extends La{constructor(e,t,i,s,n,r){super(e,t,i,s,n,r),this.strategy=e}createChildNodes(){const e=this.strategy,t=this.extent,i=.5*t.getWidth(),s=.5*t.getHeight(),n=t.northEast,r=t.southWest,o=new I(r.lon+i,r.lat+s),a=this.childNodes,l=this.layer._planet,h=this.zoom+1;a[0]=new sh(e,0,this,new te(new I(r.lon,r.lat+s),new I(r.lon+i,n.lat)),l,h),a[1]=new sh(e,1,this,new te(o,new I(n.lon,n.lat)),l,h),a[2]=new sh(e,2,this,new te(new I(r.lon,r.lat),o),l,h),a[3]=new sh(e,3,this,new te(new I(r.lon+i,r.lat),new I(n.lon,r.lat+s)),l,h)}_setExtentBounds(){this.bsphere.setFromExtent(this.layer._planet.ellipsoid,this.extent)}__setLonLat__(e){return e._lonLat.isZero()&&(e._lonLat=this.layer._planet.ellipsoid.cartesianToLonLat(e._cartesian)),e._lonLat}isVisible(){return!!this.strategy._renderingNodesWest[this.nodeId]||!!this.strategy._renderingNodesEast[this.nodeId]}isInside(e){return this.extent.isInside(e._lonLat)}renderCollection(e,t,i){this.extent.southWest.lon<0?this.strategy._renderingNodesWest[this.nodeId]=!0:this.strategy._renderingNodesEast[this.nodeId]=!0,this.deferredEntities.length&&!this._inTheQueue&&(this.layer.async?this.strategy._queueDeferredNode(this):this.applyCollection());const s=this.entityCollection;s._fadingOpacity=this.layer._fadingOpacity,s.scaleByDistance=this.layer.scaleByDistance,s.pickingScale=this.layer.pickingScale,s.isEmpty()||e.push(s)}}class nh extends ba{constructor(e,t){super(e,t);let i=e._planet;this._entityCollectionsTreeWest=new sh(this,0,null,te.createFromArray([-180,-90,0,90]),i,0),this._entityCollectionsTreeEast=new sh(this,0,null,te.createFromArray([0,-90,180,90]),i,0),this._renderingNodesWest={},this._renderingNodesEast={}}insertEntity(e,t=!1){e._lonLat.lon<0?(this._entityCollectionsTreeWest.__setLonLat__(e),this._entityCollectionsTreeWest.insertEntity(e,t)):(this._entityCollectionsTreeEast.__setLonLat__(e),this._entityCollectionsTreeEast.insertEntity(e,t))}setPickingEnabled(e){this._entityCollectionsTreeWest.traverseTree((t=>{t.entityCollection.setPickingEnabled(e)})),this._entityCollectionsTreeEast.traverseTree((t=>{t.entityCollection.setPickingEnabled(e)}))}dispose(){this._entityCollectionsTreeWest=null,this._entityCollectionsTreeEast=null,this._renderingNodesWest={},this._renderingNodesEast={}}insertEntities(e){let t=[],i=[];for(let s=0,n=e.length;s<n;s++){let n=e[s];n._lonLat.lon<0?(t.push(n),this._entityCollectionsTreeWest.__setLonLat__(n)):(i.push(n),this._entityCollectionsTreeEast.__setLonLat__(n))}this._entityCollectionsTreeWest.buildTree(t),this._entityCollectionsTreeEast.buildTree(i)}collectVisibleEntityCollections(e){this._renderingNodesWest={},this._renderingNodesEast={};let t=this._layer._planet.quadTreeStrategy;this._secondPASS=[],this._entityCollectionsTreeWest.collectRenderCollectionsPASS1(t._visibleNodesWest,e);let i=this._secondPASS.length;for(;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodesWest,e,this._secondPASS[i].nodeId);for(this._secondPASS=[],this._entityCollectionsTreeEast.collectRenderCollectionsPASS1(t._visibleNodesEast,e),i=this._secondPASS.length;i--;)this._secondPASS[i].collectRenderCollectionsPASS2(t._visibleNodesEast,e,this._secondPASS[i].nodeId)}}class rh extends wa{constructor(e){super(e,"Mars",za),this._westExtent=te.createFromArray([-180,-90,0,90]),this._eastExtent=te.createFromArray([0,-90,180,90]),this._visibleNodesWest={},this._visibleNodesEast={}}init(){this._quadTreeList=[new ya(ih,this.planet,0,null,0,this._westExtent),new ya(ih,this.planet,0,null,0,this._eastExtent)]}getTileXY(e,t){let i=t,s=-1,n=-1,r=1<<i;return s=e.lon>0?Qo(e.lon,180/r,0)+r:Qo(e.lon,180/r,-180),n=Qo(e.lat,180/r,90),[s,n,i,0]}getLonLatTileOffset(e,t,i,s,n){let r=e,o=new te;o=e.lon>0?Jo(t-(1<<s),i,s,this._eastExtent):Jo(t,i,s,this._westExtent);let a=o.getWidth()/(n-1),l=o.getHeight()/(n-1);return[n-Math.ceil((r.lat-o.southWest.lat)/l)-1,Math.floor((r.lon-o.southWest.lon)/a)]}createEntitiCollectionsTreeStrategy(e,t){return new nh(e,t)}collectVisibleNode(e){e.segment.getExtent().southWest.lon<0?this._visibleNodesWest[e.nodeId]=e:this._visibleNodesEast[e.nodeId]=e}_clearVisibleNodes(){this._visibleNodesWest={},this._visibleNodesEast={}}}class oh extends wa{constructor(e){super(e,"wgs84",Ca)}init(){this._quadTreeList=[new ya(ih,this.planet,0,null,0,te.createFromArray([-180,-90,180,90]))]}}const ah={epsg4326:class extends wa{constructor(e){super(e,"EPSG4326",Ca)}init(){this._quadTreeList=[new ya(ih,this.planet,0,null,0,te.createFromArray([-180,-90,0,90])),new ya(ih,this.planet,0,null,0,te.createFromArray([0,-90,180,90]))]}},earth:Sa,equi:rh,wgs84:oh};e.ALIGN=xi,e.BilTerrain=sl,e.Billboard=oi,e.Bing=ml,e.Camera=Va,e.CanvasTiles=Kt,e.Clock=xl,e.Control=Dt,e.EarthQuadTreeStrategy=Sa,e.Ellipsoid=he,e.EmptyTerrain=Ka,e.Entity=Si,e.EntityCollection=fs,e.EquiQuadTreeStrategy=rh,e.Events=Rt,e.Extent=te,e.Framebuffer=Yo,e.GeoImage=dl,e.GeoObject=yi,e.GeoTexture2d=_l,e.GeoVideo=ul,e.Geoid=Ma,e.Geometry=hi,e.Globe=Zl,e.GlobusRgbTerrain=hl,e.GlobusTerrain=Qa,e.Handler=Ll,e.KML=gl,e.LAYER_EVENTS=Xt,e.LOCAL_FORWARD=vi,e.Label=wi,e.Layer=$t,e.LightSource=er,e.Line2=ci,e.Line3=di,e.LonLat=I,e.Mat3=ie,e.Mat4=ne,e.Material=qt,e.MoveAxisEntity=to,e.Multisample=Al,e.Object3d=mi,e.OpenStreetMap=fl,e.Plane=_i,e.Planet=qa,e.PlanetCamera=Ua,e.PointCloud=Ci,e.Polyline=Ti,e.Popup=class extends kt{constructor(e){super({template:we(Jl,{title:e.title||""}),classList:e.className?[e.className]:[],...e}),this.events=this.events.registerNames(eh),this._content=e.content||"",this.$content=null,this.$tip=null,this.$title=null,this._planet=e.planet,this._offset=e.offset||[0,0],this._lonLat=Re(e.lonLat),this._cartPos=new oe,this._visibility=e.visibility||!1,this.render()}_updatePosition(){this.setCartesian3v(this._cartPos)}setScreen(e){if(this._planet){let t=this._planet.renderer.handler.pixelRatio;this.el.style.transform=`translate(${e.x/t-.5*this.clientWidth}px, ${e.y/t-this._planet.renderer.handler.canvas.clientHeight-this.$tip.clientHeight}px)`}}get clientWidth(){return this.el?this.el.clientWidth:0}get clientHeight(){return this.el?this.el.clientHeight:0}setOffset(e=0,t=0){return this._offset[0]=e,this._offset[1]=t,this.el&&(this.el.style.left=`${e}px`,this.el.style.bottom=`${t}px`),this}render(e){return super.render(e),this.$content=this.select(".og-popup-content"),this.$title=this.select(".og-popup-title"),this.$tip=this.select(".og-popup-tip-container"),this.setOffset(this._offset[0],this._offset[1]),this.setContent(this._content),this.setLonLat(this._lonLat),this.setVisibility(this._visibility),this.select(".og-popup-close").addEventListener("click",(()=>{this.hide()})),this}setVisibility(e){return e?this.show():this.hide(),this}getContainer(){return this.$content}getToolbarContainer(){return this.select(".og-popup-toolbar")}show(){return this._visibility=!0,this._planet&&(this._planet.events.on("draw",this._updatePosition,this),this.appendTo(this._planet.renderer.div),this.events.dispatch(this.events.open,this)),this}hide(){return this._visibility=!1,this.el&&this.el.parentNode&&(this._planet.events.off("draw",this._updatePosition),this.el.parentNode.removeChild(this.el),this.events.dispatch(this.events.close,this)),this}setCartesian3v(e,t=0){if(this._cartPos=e,this._planet){let i=this._planet.camera,s=this._planet.ellipsoid.equatorialSize+t,n=i._lonLat.height,r=e.sub(i.eye);Math.sqrt((s+n)*(s+n)-s*s)>r.length()&&i.getForward().dot(r.normalize())>0?(this.el.style.display="block",this.setScreen(i.project3v(e))):this.el.style.display="none"}return this}setTitle(e){this.$title&&(this.$title.innerHTML=e)}setLonLat(e){this._lonLat=e,this._planet&&this.setCartesian3v(this._planet.ellipsoid.lonLatToCartesian(e),e.height)}setContent(e){e&&(this.clear(),this._content=e,this.$content&&("string"==typeof e?this.$content.innerHTML=e:this.$content.appendChild(e)))}clear(){this._content=null,this.$content&&(this.$content.innerHTML="")}},e.Program=Ni,e.QuadTreeStrategy=wa,e.Quat=re,e.Ray=ui,e.RenderNode=Ri,e.Renderer=$l,e.RgbTerrain=nl,e.Strip=Pi,e.Vec2=ae,e.Vec3=oe,e.Vec4=se,e.Vector=qs,e.WMS=il,e.Wgs84QuadTreeStrategy=oh,e.XYZ=el,e.bv=St,e.control=wo,e.input=Cn,e.jd=Lt,e.layer=vl,e.mars=Kl,e.math=P,e.mercator=ee,e.moon=Ql,e.quadTreeStrategyType=ah,e.scene=Za,e.terrain=cl,e.utils=et,e.webgl=Pl,e.wgs84=ce}));
|
|
2
2
|
//# sourceMappingURL=og.umd.js.map
|