@mapxus/mapxus-visual-jp 1.8.1 → 1.9.0

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.
Files changed (425) hide show
  1. package/bitbucket-pipelines.yml +50 -0
  2. package/config/rollup.js +33 -0
  3. package/config/rollup.serve.config.js +3 -0
  4. package/debug/circlemarker.html +444 -0
  5. package/debug/create_tags.html +474 -0
  6. package/debug/distance.html +220 -0
  7. package/debug/index.html +92 -0
  8. package/debug/integration.html +1084 -0
  9. package/debug/leaflet.html +54 -0
  10. package/debug/markers.html +115 -0
  11. package/debug/multi_monitor_sync.html +377 -0
  12. package/debug/outdoor.html +1026 -0
  13. package/debug/rect_tags.html +147 -0
  14. package/debug/rotate.html +236 -0
  15. package/debug/sample.html +324 -0
  16. package/debug/sequence.html +75 -0
  17. package/debug/tags.html +218 -0
  18. package/package.json +34 -10
  19. package/rollup.config.js +39 -0
  20. package/server.js +35 -0
  21. package/spec/api/APIv3.spec.ts +86 -0
  22. package/spec/component/Component.spec.ts +68 -0
  23. package/spec/component/StatsComponent.spec.ts +33 -0
  24. package/spec/component/direction/DirectionComponent.spec.ts +163 -0
  25. package/spec/component/direction/DirectionDOMRenderer.spec.ts +233 -0
  26. package/spec/component/keyboard/KeyZoomHandler.spec.ts +236 -0
  27. package/spec/component/marker/Marker.spec.ts +104 -0
  28. package/spec/component/marker/MarkerComponent.spec.ts +88 -0
  29. package/spec/component/marker/MarkerScene.spec.ts +223 -0
  30. package/spec/component/marker/MarkerSet.spec.ts +453 -0
  31. package/spec/component/mouse/DoubleClickZoomHandler.spec.ts +211 -0
  32. package/spec/component/popup/Popup.spec.ts +479 -0
  33. package/spec/component/popup/PopupComponent.spec.ts +414 -0
  34. package/spec/component/tag/CreateHandlerBase.spec.ts +83 -0
  35. package/spec/component/tag/CreatePointHandler.spec.ts +190 -0
  36. package/spec/component/tag/OutlineRenderTag.spec.ts +91 -0
  37. package/spec/component/tag/PointGeometry.spec.ts +131 -0
  38. package/spec/component/tag/PolygonGeometry.spec.ts +497 -0
  39. package/spec/component/tag/RectGeometry.spec.ts +1157 -0
  40. package/spec/component/tag/TagComponent.spec.ts +513 -0
  41. package/spec/component/tag/TagScene.spec.ts +346 -0
  42. package/spec/component/tag/TagSet.spec.ts +241 -0
  43. package/spec/component/utils/HandlerBase.spec.ts +203 -0
  44. package/spec/geo/Camera.spec.ts +250 -0
  45. package/spec/geo/GeoCoords.spec.ts +364 -0
  46. package/spec/geo/Spatial.spec.ts +711 -0
  47. package/spec/geo/Transform.spec.ts +850 -0
  48. package/spec/geo/ViewportCoords.spec.ts +534 -0
  49. package/spec/graph/FilterCreator.spec.ts +892 -0
  50. package/spec/graph/Graph.spec.ts +2078 -0
  51. package/spec/graph/GraphCalculator.spec.ts +263 -0
  52. package/spec/graph/GraphService.spec.ts +663 -0
  53. package/spec/graph/Node.spec.ts +373 -0
  54. package/spec/graph/NodeCache.spec.ts +206 -0
  55. package/spec/graph/Sequence.spec.ts +37 -0
  56. package/spec/graph/edge/EdgeCalculator.Pano.spec.ts +963 -0
  57. package/spec/graph/edge/EdgeCalculator.Sequence.spec.ts +108 -0
  58. package/spec/graph/edge/EdgeCalculator.Similar.spec.ts +272 -0
  59. package/spec/graph/edge/EdgeCalculator.Step.spec.ts +383 -0
  60. package/spec/graph/edge/EdgeCalculator.Turn.spec.ts +278 -0
  61. package/spec/graph/edge/EdgeCalculator.spec.ts +747 -0
  62. package/spec/helper/ContainerMockCreator.spec.ts +33 -0
  63. package/spec/helper/DOMRendererMockCreator.spec.ts +22 -0
  64. package/spec/helper/EdgeCalculatorHelper.spec.ts +96 -0
  65. package/spec/helper/EventHelper.spec.ts +92 -0
  66. package/spec/helper/GLRendererMockCreator.spec.ts +23 -0
  67. package/spec/helper/GeoHelper.spec.ts +16 -0
  68. package/spec/helper/ImageLoadingServiceMockCreator.spec.ts +24 -0
  69. package/spec/helper/KeyboardServiceMockCreator.spec.ts +21 -0
  70. package/spec/helper/LoadingServiceMockCreator.spec.ts +21 -0
  71. package/spec/helper/MockCreator.spec.ts +18 -0
  72. package/spec/helper/MockCreatorBase.spec.ts +17 -0
  73. package/spec/helper/MouseServiceMockCreator.spec.ts +38 -0
  74. package/spec/helper/NavigatorMockCreator.spec.ts +28 -0
  75. package/spec/helper/NodeHelper.spec.ts +77 -0
  76. package/spec/helper/NodeMockCreator.spec.ts +19 -0
  77. package/spec/helper/RenderServiceMockCreator.spec.ts +25 -0
  78. package/spec/helper/SpriteServiceMockCreator.spec.ts +22 -0
  79. package/spec/helper/StateServiceMockCreator.spec.ts +33 -0
  80. package/spec/helper/TouchServiceMockCreator.spec.ts +29 -0
  81. package/spec/helper/TransformHelper.spec.ts +17 -0
  82. package/spec/render/DOMRenderer.spec.ts +112 -0
  83. package/spec/render/GLRenderer.spec.ts +453 -0
  84. package/spec/render/RenderCamera.spec.ts +535 -0
  85. package/spec/render/RenderService.spec.ts +531 -0
  86. package/spec/state/StateBase.spec.ts +369 -0
  87. package/spec/state/StateService.spec.ts +9 -0
  88. package/spec/state/TraversingState.spec.ts +262 -0
  89. package/spec/state/WaitingState.spec.ts +319 -0
  90. package/spec/tiles/TextureProvider.spec.ts +653 -0
  91. package/spec/utils/EventEmitter.spec.ts +71 -0
  92. package/spec/utils/Support.spec.ts +54 -0
  93. package/spec/viewer/CacheService.spec.ts +160 -0
  94. package/spec/viewer/ComponentController.spec.ts +310 -0
  95. package/spec/viewer/LoadingService.spec.ts +19 -0
  96. package/spec/viewer/MouseService.spec.ts +1344 -0
  97. package/spec/viewer/Navigator.spec.ts +970 -0
  98. package/spec/viewer/Observer.spec.ts +96 -0
  99. package/spec/viewer/SpriteService.spec.ts +224 -0
  100. package/src/API.ts +3 -0
  101. package/src/Component.ts +77 -0
  102. package/src/Edge.ts +6 -0
  103. package/src/Error.ts +3 -0
  104. package/src/FilterRender.ts +27 -0
  105. package/src/Geo.ts +7 -0
  106. package/src/Graph.ts +19 -0
  107. package/src/MapxusVisual.ts +66 -0
  108. package/src/Render.ts +7 -0
  109. package/src/State.ts +8 -0
  110. package/src/Support.ts +35 -0
  111. package/src/Tiles.ts +5 -0
  112. package/src/Utils.ts +6 -0
  113. package/src/Viewer.ts +16 -0
  114. package/src/api/API.ts +396 -0
  115. package/src/api/Auth.ts +76 -0
  116. package/src/api/AuthStore.ts +11 -0
  117. package/src/api/GraphQLCreator.ts +100 -0
  118. package/src/api/interfaces/IAuth.ts +7 -0
  119. package/src/api/interfaces/IBuildingBase.ts +7 -0
  120. package/src/api/interfaces/IBuildingInfo.ts +19 -0
  121. package/src/api/interfaces/ICoreNode.ts +28 -0
  122. package/src/api/interfaces/IFillNode.ts +96 -0
  123. package/src/api/interfaces/IFloorInfo.ts +10 -0
  124. package/src/api/interfaces/IFullNode.ts +10 -0
  125. package/src/api/interfaces/IGPano.ts +38 -0
  126. package/src/api/interfaces/IImageTagInfo.ts +14 -0
  127. package/src/api/interfaces/IKey.ts +13 -0
  128. package/src/api/interfaces/ILatLon.ts +19 -0
  129. package/src/api/interfaces/IOutdoor.ts +14 -0
  130. package/src/api/interfaces/IPathNode.ts +37 -0
  131. package/src/api/interfaces/IProject.ts +8 -0
  132. package/src/api/interfaces/IQueryBuilding.ts +37 -0
  133. package/src/api/interfaces/IResponse.ts +7 -0
  134. package/src/api/interfaces/ISequence.ts +16 -0
  135. package/src/api/interfaces/IUser.ts +13 -0
  136. package/src/api/interfaces/interfaces.ts +17 -0
  137. package/src/component/AttributionComponent.ts +48 -0
  138. package/src/component/BackgroundComponent.ts +39 -0
  139. package/src/component/BearingComponent.ts +282 -0
  140. package/src/component/CacheComponent.ts +295 -0
  141. package/src/component/Component.ts +130 -0
  142. package/src/component/ComponentService.ts +150 -0
  143. package/src/component/CoverComponent.ts +132 -0
  144. package/src/component/DebugComponent.ts +157 -0
  145. package/src/component/ImageComponent.ts +96 -0
  146. package/src/component/LoadingComponent.ts +85 -0
  147. package/src/component/NavigationComponent.ts +233 -0
  148. package/src/component/RouteComponent.ts +354 -0
  149. package/src/component/StatsComponent.ts +100 -0
  150. package/src/component/direction/DirectionComponent.ts +254 -0
  151. package/src/component/direction/DirectionDOMCalculator.ts +243 -0
  152. package/src/component/direction/DirectionDOMRenderer.ts +631 -0
  153. package/src/component/imageplane/ImagePlaneComponent.ts +497 -0
  154. package/src/component/imageplane/ImagePlaneFactory.ts +314 -0
  155. package/src/component/imageplane/ImagePlaneGLRenderer.ts +247 -0
  156. package/src/component/imageplane/ImagePlaneScene.ts +87 -0
  157. package/src/component/imageplane/ImagePlaneShaders.ts +16 -0
  158. package/src/component/imageplane/SliderComponent.ts +697 -0
  159. package/src/component/imageplane/interfaces/IBBoxShaderMaterial.ts +10 -0
  160. package/src/component/imageplane/interfaces/IShaderMaterial.ts +9 -0
  161. package/src/component/imageplane/interfaces/interfaces.ts +2 -0
  162. package/src/component/imageplane/shaders/equirectangular.fragment.glsl.ts +26 -0
  163. package/src/component/imageplane/shaders/equirectangular.vertex.glsl.ts +15 -0
  164. package/src/component/imageplane/shaders/perspective.fragment.glsl.ts +27 -0
  165. package/src/component/imageplane/shaders/perspective.vertex.glsl.ts +15 -0
  166. package/src/component/interfaces/ICacheConfiguration.ts +72 -0
  167. package/src/component/interfaces/IComponentConfiguration.ts +5 -0
  168. package/src/component/interfaces/ICoverConfiguration.ts +15 -0
  169. package/src/component/interfaces/IDirectionConfiguration.ts +63 -0
  170. package/src/component/interfaces/IImagePlaneConfiguration.ts +17 -0
  171. package/src/component/interfaces/IKeyboardConfiguration.ts +44 -0
  172. package/src/component/interfaces/IMarkerConfiguration.ts +31 -0
  173. package/src/component/interfaces/IMouseConfiguration.ts +52 -0
  174. package/src/component/interfaces/INavigationConfiguration.ts +35 -0
  175. package/src/component/interfaces/IRouteConfiguration.ts +20 -0
  176. package/src/component/interfaces/ISequenceConfiguration.ts +72 -0
  177. package/src/component/interfaces/IShader.ts +6 -0
  178. package/src/component/interfaces/ISliderConfiguration.ts +61 -0
  179. package/src/component/interfaces/ITagConfiguration.ts +40 -0
  180. package/src/component/interfaces/interfaces.ts +17 -0
  181. package/src/component/keyboard/KeySequenceNavigationHandler.ts +86 -0
  182. package/src/component/keyboard/KeySpatialNavigationHandler.ts +216 -0
  183. package/src/component/keyboard/KeyZoomHandler.ts +106 -0
  184. package/src/component/keyboard/KeyboardComponent.ts +125 -0
  185. package/src/component/marker/Marker.ts +5 -0
  186. package/src/component/marker/MarkerComponent.ts +856 -0
  187. package/src/component/marker/MarkerScene.ts +145 -0
  188. package/src/component/marker/MarkerSet.ts +142 -0
  189. package/src/component/marker/interfaces/IArrowMarkerOptions.ts +41 -0
  190. package/src/component/marker/interfaces/ICircleMarkerOptions.ts +30 -0
  191. package/src/component/marker/interfaces/IDotMarkerOptions.ts +18 -0
  192. package/src/component/marker/interfaces/IMarkerEvent.ts +28 -0
  193. package/src/component/marker/interfaces/ISimpleMarkerOptions.ts +54 -0
  194. package/src/component/marker/interfaces/interfaces.ts +5 -0
  195. package/src/component/marker/marker/ArrowMarker.ts +84 -0
  196. package/src/component/marker/marker/CircleMarker.ts +82 -0
  197. package/src/component/marker/marker/DotMarker.ts +68 -0
  198. package/src/component/marker/marker/ImageMarker.ts +45 -0
  199. package/src/component/marker/marker/Marker.ts +99 -0
  200. package/src/component/marker/marker/SimpleMarker.ts +187 -0
  201. package/src/component/mouse/BounceHandler.ts +148 -0
  202. package/src/component/mouse/DoubleClickZoomHandler.ts +106 -0
  203. package/src/component/mouse/DragPanHandler.ts +489 -0
  204. package/src/component/mouse/HandlerTypes.ts +13 -0
  205. package/src/component/mouse/MouseComponent.ts +170 -0
  206. package/src/component/mouse/ScrollZoomHandler.ts +137 -0
  207. package/src/component/mouse/TouchZoomHandler.ts +136 -0
  208. package/src/component/path/PathComponent.ts +75 -0
  209. package/src/component/path/PathEvent.ts +245 -0
  210. package/src/component/path/PathMarker.ts +42 -0
  211. package/src/component/path/PathRender.ts +163 -0
  212. package/src/component/popup/Popup.ts +2 -0
  213. package/src/component/popup/PopupComponent.ts +244 -0
  214. package/src/component/popup/interfaces/IPopupOffset.ts +37 -0
  215. package/src/component/popup/interfaces/IPopupOptions.ts +81 -0
  216. package/src/component/popup/popup/Popup.ts +594 -0
  217. package/src/component/popup/popup/PopupAlignment.ts +3 -0
  218. package/src/component/sequence/SequenceComponent.ts +500 -0
  219. package/src/component/sequence/SequenceDOMInteraction.ts +23 -0
  220. package/src/component/sequence/SequenceDOMRenderer.ts +179 -0
  221. package/src/component/tag/Tag.ts +9 -0
  222. package/src/component/tag/TagComponent.ts +787 -0
  223. package/src/component/tag/TagCreator.ts +138 -0
  224. package/src/component/tag/TagDOMRenderer.ts +35 -0
  225. package/src/component/tag/TagMode.ts +37 -0
  226. package/src/component/tag/TagOperation.ts +7 -0
  227. package/src/component/tag/TagScene.ts +216 -0
  228. package/src/component/tag/TagSet.ts +186 -0
  229. package/src/component/tag/error/GeometryTagError.ts +11 -0
  230. package/src/component/tag/geometry/Geometry.ts +62 -0
  231. package/src/component/tag/geometry/PointGeometry.ts +89 -0
  232. package/src/component/tag/geometry/PolygonGeometry.ts +349 -0
  233. package/src/component/tag/geometry/RectGeometry.ts +759 -0
  234. package/src/component/tag/geometry/VertexGeometry.ts +185 -0
  235. package/src/component/tag/handlers/CreateHandlerBase.ts +81 -0
  236. package/src/component/tag/handlers/CreatePointHandler.ts +35 -0
  237. package/src/component/tag/handlers/CreatePolygonHandler.ts +33 -0
  238. package/src/component/tag/handlers/CreateRectDragHandler.ts +199 -0
  239. package/src/component/tag/handlers/CreateRectHandler.ts +57 -0
  240. package/src/component/tag/handlers/CreateVertexHandler.ts +165 -0
  241. package/src/component/tag/handlers/EditVertexHandler.ts +275 -0
  242. package/src/component/tag/handlers/TagHandlerBase.ts +57 -0
  243. package/src/component/tag/interfaces/IInteraction.ts +14 -0
  244. package/src/component/tag/interfaces/IOutlineCreateTagOptions.ts +15 -0
  245. package/src/component/tag/interfaces/IOutlineTagOptions.ts +89 -0
  246. package/src/component/tag/interfaces/ISpotTagOptions.ts +37 -0
  247. package/src/component/tag/interfaces/interfaces.ts +4 -0
  248. package/src/component/tag/tag/OutlineCreateTag.ts +330 -0
  249. package/src/component/tag/tag/OutlineRenderTag.ts +569 -0
  250. package/src/component/tag/tag/OutlineTag.ts +380 -0
  251. package/src/component/tag/tag/RenderTag.ts +50 -0
  252. package/src/component/tag/tag/SpotRenderTag.ts +160 -0
  253. package/src/component/tag/tag/SpotTag.ts +170 -0
  254. package/src/component/tag/tag/Tag.ts +103 -0
  255. package/src/component/utils/HandlerBase.ts +71 -0
  256. package/src/error/ArgumentBeeviewError.ts +11 -0
  257. package/src/error/BeeviewError.ts +9 -0
  258. package/src/error/GraphBeeviewError.ts +11 -0
  259. package/src/geo/Camera.ts +149 -0
  260. package/src/geo/GeoCoords.ts +280 -0
  261. package/src/geo/GeoRBush.ts +25 -0
  262. package/src/geo/Spatial.ts +259 -0
  263. package/src/geo/Transform.ts +543 -0
  264. package/src/geo/ViewportCoords.ts +518 -0
  265. package/src/geo/interfaces/ILatLonAlt.ts +7 -0
  266. package/src/geo/interfaces/interfaces.ts +1 -0
  267. package/src/graph/FilterCreator.ts +106 -0
  268. package/src/graph/FilterExpression.ts +16 -0
  269. package/src/graph/Graph.ts +1516 -0
  270. package/src/graph/GraphCalculator.ts +197 -0
  271. package/src/graph/GraphService.ts +516 -0
  272. package/src/graph/ImageLoadingService.ts +44 -0
  273. package/src/graph/MeshReader.ts +19 -0
  274. package/src/graph/Node.ts +622 -0
  275. package/src/graph/NodeCache.ts +548 -0
  276. package/src/graph/Sequence.ts +117 -0
  277. package/src/graph/edge/EdgeCalculator.ts +919 -0
  278. package/src/graph/edge/EdgeCalculatorCoefficients.ts +43 -0
  279. package/src/graph/edge/EdgeCalculatorDirections.ts +80 -0
  280. package/src/graph/edge/EdgeCalculatorSettings.ts +61 -0
  281. package/src/graph/edge/EdgeDirection.ts +63 -0
  282. package/src/graph/edge/interfaces/IEdge.ts +26 -0
  283. package/src/graph/edge/interfaces/IEdgeData.ts +22 -0
  284. package/src/graph/edge/interfaces/IPano.ts +8 -0
  285. package/src/graph/edge/interfaces/IPotentialEdge.ts +106 -0
  286. package/src/graph/edge/interfaces/IStep.ts +7 -0
  287. package/src/graph/edge/interfaces/ITurn.ts +7 -0
  288. package/src/graph/edge/interfaces/interfaces.ts +6 -0
  289. package/src/graph/interfaces/IEdgeStatus.ts +25 -0
  290. package/src/graph/interfaces/IGraphConfiguration.ts +26 -0
  291. package/src/graph/interfaces/ILoadStatus.ts +18 -0
  292. package/src/graph/interfaces/ILoadStatusObject.ts +8 -0
  293. package/src/graph/interfaces/IMesh.ts +20 -0
  294. package/src/graph/interfaces/interfaces.ts +5 -0
  295. package/src/render/DOMRenderer.ts +288 -0
  296. package/src/render/GLRenderStage.ts +6 -0
  297. package/src/render/GLRenderer.ts +436 -0
  298. package/src/render/RenderCamera.ts +212 -0
  299. package/src/render/RenderMode.ts +34 -0
  300. package/src/render/RenderService.ts +264 -0
  301. package/src/render/interfaces/IGLRender.ts +10 -0
  302. package/src/render/interfaces/IGLRenderFunction.ts +10 -0
  303. package/src/render/interfaces/IGLRenderHash.ts +8 -0
  304. package/src/render/interfaces/ISize.ts +6 -0
  305. package/src/render/interfaces/IVNodeHash.ts +8 -0
  306. package/src/render/interfaces/interfaces.ts +5 -0
  307. package/src/state/FrameGenerator.ts +36 -0
  308. package/src/state/State.ts +6 -0
  309. package/src/state/StateContext.ts +180 -0
  310. package/src/state/StateService.ts +600 -0
  311. package/src/state/StateTransitionMatrix.ts +58 -0
  312. package/src/state/interfaces/ICurrentState.ts +21 -0
  313. package/src/state/interfaces/IFrame.ts +9 -0
  314. package/src/state/interfaces/IRotation.ts +6 -0
  315. package/src/state/interfaces/IState.ts +11 -0
  316. package/src/state/interfaces/IStateContext.ts +31 -0
  317. package/src/state/interfaces/interfaces.ts +5 -0
  318. package/src/state/states/StateBase.ts +425 -0
  319. package/src/state/states/TraversingState.ts +861 -0
  320. package/src/state/states/WaitingState.ts +109 -0
  321. package/src/tiles/ImageTileLoader.ts +121 -0
  322. package/src/tiles/ImageTileStore.ts +70 -0
  323. package/src/tiles/RegionOfInterestCalculator.ts +158 -0
  324. package/src/tiles/TextureProvider.ts +609 -0
  325. package/src/tiles/interfaces/IBoundingBox.ts +28 -0
  326. package/src/tiles/interfaces/IRegionOfInterest.ts +25 -0
  327. package/src/tiles/interfaces/interfaces.ts +2 -0
  328. package/src/utils/DOM.ts +28 -0
  329. package/src/utils/EventEmitter.ts +61 -0
  330. package/src/utils/Func.ts +3 -0
  331. package/src/utils/Settings.ts +39 -0
  332. package/src/utils/Support.ts +70 -0
  333. package/src/utils/Urls.ts +43 -0
  334. package/src/viewer/Alignment.ts +53 -0
  335. package/src/viewer/CacheService.ts +75 -0
  336. package/src/viewer/ComponentController.ts +237 -0
  337. package/src/viewer/Container.ts +100 -0
  338. package/src/viewer/EventNames.ts +192 -0
  339. package/src/viewer/ImageSize.ts +28 -0
  340. package/src/viewer/KeyboardService.ts +15 -0
  341. package/src/viewer/LoadingService.ts +66 -0
  342. package/src/viewer/MouseService.ts +541 -0
  343. package/src/viewer/Navigator.ts +362 -0
  344. package/src/viewer/Observer.ts +441 -0
  345. package/src/viewer/Projection.ts +162 -0
  346. package/src/viewer/SpriteService.ts +281 -0
  347. package/src/viewer/TouchService.ts +336 -0
  348. package/src/viewer/Viewer.ts +1132 -0
  349. package/src/viewer/interfaces/IComponentOptions.ts +176 -0
  350. package/src/viewer/interfaces/IMouseClaim.ts +6 -0
  351. package/src/viewer/interfaces/IMouseDeferPixels.ts +6 -0
  352. package/src/viewer/interfaces/IPinch.ts +81 -0
  353. package/src/viewer/interfaces/ISpriteAtlas.ts +12 -0
  354. package/src/viewer/interfaces/IUnprojection.ts +9 -0
  355. package/src/viewer/interfaces/IViewerMouseEvent.ts +56 -0
  356. package/src/viewer/interfaces/IViewerOptions.ts +88 -0
  357. package/src/viewer/interfaces/PointOfView.ts +19 -0
  358. package/src/viewer/interfaces/interfaces.ts +9 -0
  359. package/styles/AttributionComponent.css +26 -0
  360. package/styles/BackgroundComponent.css +21 -0
  361. package/styles/BearingComponent.css +48 -0
  362. package/styles/CoverComponent.css +169 -0
  363. package/styles/DebugComponent.css +28 -0
  364. package/styles/DirectionComponent.css +154 -0
  365. package/styles/LoadingComponent.css +14 -0
  366. package/styles/NavigationComponent.css +64 -0
  367. package/styles/NorthBg.png +0 -0
  368. package/styles/PopupComponent.css +188 -0
  369. package/styles/RouteComponent.css +21 -0
  370. package/styles/SequenceComponent.css +120 -0
  371. package/styles/SliderComponent.css +82 -0
  372. package/styles/TagComponent.css +105 -0
  373. package/styles/cover-logo.png +0 -0
  374. package/styles/mapillary-js.css +29 -0
  375. package/styles/pano-indicator.svg +3 -0
  376. package/styles/pano.svg +20 -0
  377. package/styles/pointer-wheat.svg +3 -0
  378. package/styles/pointer-white.svg +3 -0
  379. package/styles/spinner.svg +1 -0
  380. package/styles/stepper-left.svg +1 -0
  381. package/styles/stepper-play.svg +1 -0
  382. package/styles/stepper-right.svg +1 -0
  383. package/styles/stepper-stop.svg +1 -0
  384. package/styles/turn-around.svg +3 -0
  385. package/styles/turn.svg +3 -0
  386. package/tsconfig.json +28 -0
  387. package/tslint.json +81 -0
  388. package/types/graphql/index.d.ts +28 -0
  389. package/types/graphql/language/ast/index.d.ts +7 -0
  390. package/types/images/index.d.ts +7 -0
  391. package/types/pbf/index.d.ts +16 -0
  392. package/types/rbush/index.d.ts +28 -0
  393. package/version/beeview-0.1.0.css +2 -0
  394. package/version/beeview-0.1.0.js +1 -0
  395. package/version/beeview-0.1.1.css +2 -0
  396. package/version/beeview-0.1.1.js +1 -0
  397. package/version/beeview-0.1.2.css +2 -0
  398. package/version/beeview-0.1.2.js +1 -0
  399. package/version/beeview-0.2.0.css +2 -0
  400. package/version/beeview-0.2.0.js +1 -0
  401. package/version/beeview-0.2.1.css +2 -0
  402. package/version/beeview-0.2.1.js +1 -0
  403. package/version/beeview-0.3.0.css +2 -0
  404. package/version/beeview-0.3.0.js +1 -0
  405. package/version/beeview-0.4.0.css +2 -0
  406. package/version/beeview-0.4.0.js +1 -0
  407. package/version/beeview-0.4.1.css +2 -0
  408. package/version/beeview-0.4.1.js +1 -0
  409. package/version/mapxus-visual-1.0.0.css +2 -0
  410. package/version/mapxus-visual-1.0.0.js +1 -0
  411. package/version/mapxus-visual-1.1.0.css +2 -0
  412. package/version/mapxus-visual-1.1.0.js +1 -0
  413. package/version/mapxus-visual-1.1.1.css +2 -0
  414. package/version/mapxus-visual-1.1.1.js +1 -0
  415. package/version/mapxus-visual-1.1.2.css +2 -0
  416. package/version/mapxus-visual-1.1.2.js +1 -0
  417. package/version/mapxus-visual-1.2.0.css +2 -0
  418. package/version/mapxus-visual-1.2.0.js +1 -0
  419. package/version/mapxus-visual-1.3.0.css +2 -0
  420. package/version/mapxus-visual-1.3.0.js +1 -0
  421. package/LICENSE +0 -11
  422. package/README.md +0 -28
  423. package/index.css +0 -2
  424. package/index.d.ts +0 -163
  425. package/index.js +0 -1
@@ -0,0 +1,1516 @@
1
+ import * as _ from "underscore";
2
+ import { Observable, Subject } from "rxjs";
3
+ import { tap, finalize, map, share, catchError } from "rxjs/operators";
4
+ import type {
5
+ ICoreNode,
6
+ IFillNode,
7
+ IFullNode,
8
+ ILatLon,
9
+ ISequence,
10
+ } from "../api/interfaces/interfaces";
11
+ import type {
12
+ IEdge,
13
+ IPotentialEdge,
14
+ } from "../graph/edge/interfaces/interfaces";
15
+ import { EdgeCalculator } from "../graph/edge/EdgeCalculator";
16
+ import { GraphBeeviewError } from "../error/GraphBeeviewError";
17
+ import type { IGraphConfiguration } from "./interfaces/interfaces";
18
+ import { FilterCreator, FilterFunction } from "./FilterCreator";
19
+ import { FilterExpression } from "./FilterExpression";
20
+ import { Node } from "./Node";
21
+ import { NodeCache } from "./NodeCache";
22
+ import { Sequence } from "./Sequence";
23
+ import { GraphCalculator } from "./GraphCalculator";
24
+ import { GeoRBush } from "../geo/GeoRBush";
25
+ import type { IPathNode } from "../api/interfaces/IPathNode";
26
+ import { API } from "../api/API";
27
+ import type { IQueryBuilding } from "../api/interfaces/IQueryBuilding";
28
+ import IOutdoor from "../api/interfaces/IOutdoor";
29
+
30
+ type NodeIndexItem = {
31
+ lat: number;
32
+ lon: number;
33
+ node: Node;
34
+ };
35
+
36
+ type NodeTiles = {
37
+ cache: string[];
38
+ caching: string[];
39
+ };
40
+
41
+ type SpatialArea = {
42
+ all: { [key: string]: Node };
43
+ cacheKeys: string[];
44
+ cacheNodes: { [key: string]: Node };
45
+ };
46
+
47
+ type NodeAccess = {
48
+ node: Node;
49
+ accessed: number;
50
+ };
51
+
52
+ type TileAccess = {
53
+ nodes: Node[];
54
+ accessed: number;
55
+ };
56
+
57
+ type SequenceAccess = {
58
+ sequence: Sequence;
59
+ accessed: number;
60
+ };
61
+
62
+ /**
63
+ * @class Graph
64
+ *
65
+ * @classdesc Represents a graph of nodes with edges.
66
+ */
67
+ export class Graph {
68
+ private _api: API;
69
+
70
+ private _cachedPaths: { [key: string]: IPathNode[] };
71
+ /**
72
+ * Nodes that have initialized cache with a timestamp of last access.
73
+ */
74
+ private _cachedNodes: { [key: string]: NodeAccess };
75
+
76
+ /**
77
+ * Nodes for which the required tiles are cached.
78
+ */
79
+ private _cachedNodeTiles: { [key: string]: boolean };
80
+
81
+ /**
82
+ * Nodes for which the spatial edges are cached.
83
+ */
84
+ private _cachedSpatialEdges: { [key: string]: Node };
85
+
86
+ /**
87
+ * Cached tiles with a timestamp of last access.
88
+ */
89
+ private _cachedTiles: { [h: string]: TileAccess };
90
+
91
+ /**
92
+ * Nodes for which fill properties are being retreived.
93
+ */
94
+ private _cachingFill$: { [key: string]: Observable<Graph> };
95
+
96
+ /**
97
+ * Nodes for which full properties are being retrieved.
98
+ */
99
+ private _cachingFull$: { [key: string]: Observable<Graph> };
100
+
101
+ /**
102
+ * Sequences that are being retrieved.
103
+ */
104
+ private _cachingSequences$: { [sequenceKey: string]: Observable<Graph> };
105
+
106
+ /**
107
+ * Nodes for which the spatial area fill properties are being retrieved.
108
+ */
109
+ private _cachingSpatialArea$: { [key: string]: Observable<Graph>[] };
110
+
111
+ /**
112
+ * Tiles that are being retrieved.
113
+ */
114
+ private _cachingTiles$: { [h: string]: Observable<Graph> };
115
+
116
+ private _changed$: Subject<Graph>;
117
+
118
+ private _defaultAlt: number;
119
+ private _edgeCalculator: EdgeCalculator;
120
+ private _filter: FilterFunction;
121
+ private _filterCreator: FilterCreator;
122
+ private _graphCalculator: GraphCalculator;
123
+ private _configuration: IGraphConfiguration;
124
+
125
+ /**
126
+ * All nodes in the graph.
127
+ */
128
+ private _nodes: { [key: string]: Node };
129
+
130
+ /**
131
+ * Contains all nodes in the graph. Used for fast spatial lookups.
132
+ */
133
+ private _nodeIndex: GeoRBush<NodeIndexItem>;
134
+
135
+ /**
136
+ * All node index items sorted in tiles for easy uncache.
137
+ */
138
+ private _nodeIndexTiles: { [h: string]: NodeIndexItem[] };
139
+
140
+ /**
141
+ * Node to tile dictionary for easy tile access updates.
142
+ */
143
+ private _nodeToTile: { [key: string]: string };
144
+
145
+ /**
146
+ * Nodes retrieved before tiles, stored on tile level.
147
+ */
148
+ private _preStored: { [h: string]: { [key: string]: Node } };
149
+
150
+ /**
151
+ * Tiles required for a node to retrive spatial area.
152
+ */
153
+ private _requiredNodeTiles: { [key: string]: NodeTiles };
154
+
155
+ /**
156
+ * Other nodes required for node to calculate spatial edges.
157
+ */
158
+ private _requiredSpatialArea: { [key: string]: SpatialArea };
159
+
160
+ /**
161
+ * All sequences in graph with a timestamp of last access.
162
+ */
163
+ private _sequences: { [skey: string]: SequenceAccess };
164
+
165
+ private _tilePrecision: number;
166
+ private _tileThreshold: number;
167
+
168
+ /**
169
+ * Create a new graph instance.
170
+ *
171
+ * @param {API} [api] - graphQL API instance for retrieving data.
172
+ * @param {GeoRBush<NodeIndexItem>} [nodeIndex] - Node index for fast spatial retreival.
173
+ * @param {GraphCalculator} [graphCalculator] - Instance for graph calculations.
174
+ * @param {EdgeCalculator} [edgeCalculator] - Instance for edge calculations.
175
+ * @param {FilterCreator} [filterCreator] - Instance for filter creation.
176
+ * @param {IGraphConfiguration} [configuration] - Configuration struct.
177
+ */
178
+ constructor(
179
+ api?: API,
180
+ nodeIndex?: GeoRBush<NodeIndexItem>,
181
+ graphCalculator?: GraphCalculator,
182
+ edgeCalculator?: EdgeCalculator,
183
+ filterCreator?: FilterCreator,
184
+ configuration?: IGraphConfiguration,
185
+ ) {
186
+ this._api = api;
187
+ this._cachedPaths = {};
188
+ this._cachedNodes = {};
189
+ this._cachedNodeTiles = {};
190
+ this._cachedSpatialEdges = {};
191
+ this._cachedTiles = {};
192
+ this._cachingFill$ = {};
193
+ this._cachingFull$ = {};
194
+ this._cachingSequences$ = {};
195
+ this._cachingSpatialArea$ = {};
196
+ this._cachingTiles$ = {};
197
+ this._changed$ = new Subject<Graph>();
198
+
199
+ this._defaultAlt = 2;
200
+ this._edgeCalculator =
201
+ edgeCalculator != null ? edgeCalculator : new EdgeCalculator();
202
+ this._filterCreator =
203
+ filterCreator != null ? filterCreator : new FilterCreator();
204
+ this._filter = this._filterCreator.createFilter(undefined);
205
+ this._graphCalculator =
206
+ graphCalculator != null ? graphCalculator : new GraphCalculator();
207
+ this._configuration =
208
+ configuration != null
209
+ ? configuration
210
+ : {
211
+ maxSequences: 50,
212
+ maxUnusedNodes: 100,
213
+ maxUnusedTiles: 20,
214
+ };
215
+
216
+ this._nodes = {};
217
+ this._nodeIndex =
218
+ nodeIndex != null ? nodeIndex : new GeoRBush<NodeIndexItem>(16);
219
+ this._nodeIndexTiles = {};
220
+ this._nodeToTile = {};
221
+
222
+ this._preStored = {};
223
+
224
+ this._requiredNodeTiles = {};
225
+ this._requiredSpatialArea = {};
226
+
227
+ this._sequences = {};
228
+
229
+ this._tilePrecision = 7;
230
+ this._tileThreshold = 20;
231
+ }
232
+
233
+ /**
234
+ * Get changed$.
235
+ *
236
+ * @returns {Observable<Graph>} Observable emitting
237
+ * the graph every time it has changed.
238
+ */
239
+ public get changed$(): Observable<Graph> {
240
+ return this._changed$;
241
+ }
242
+
243
+ /**
244
+ * Retrieve and cache path node (images) properties.
245
+ *
246
+ * @param {string} key - Key of building.
247
+ * @returns {Observable<IPathNode[]>} Observable emitting the imageload pathnode
248
+ * when the node has been updated.
249
+ * @throws {GraphBeeviewError} When the operation is not valid on the
250
+ * current graph.
251
+ */
252
+ public cachePath$(key: string, date?: number): Observable<IPathNode[]> {
253
+ let node: Node = this.getNode(key);
254
+
255
+ return this._api.buildingByKey$(node.building.id, date).pipe(
256
+ map((value: IQueryBuilding) => {
257
+ let cacheKey: string = node.building.id;
258
+ if (date) {
259
+ cacheKey += date;
260
+ }
261
+ this._cachedPaths[cacheKey] = _.values(value)
262
+ .map((val: IQueryBuilding) => val.images)
263
+ .reduce(
264
+ (pre: IPathNode[], cur: IPathNode[]) => pre.concat(cur),
265
+ [],
266
+ );
267
+ return this._cachedPaths[cacheKey];
268
+ }),
269
+ );
270
+ }
271
+
272
+ public cacheOutdoorPath$(
273
+ lon: number,
274
+ lat: number,
275
+ date?: number,
276
+ ): Observable<IPathNode[]> {
277
+ const latLon: ILatLon = { lon, lat };
278
+ return this._api.outdoorByLatLon$(latLon, 200, date).pipe(
279
+ // distance 200 match encodeH 7 bit
280
+ map((outdoors: IOutdoor[]) => {
281
+ let list: IPathNode[] = [];
282
+ outdoors.forEach(
283
+ (outdoor: IOutdoor) =>
284
+ (list = list.concat(outdoor.outdoorImages)),
285
+ );
286
+ const outdoorImageHash: string =
287
+ this._graphCalculator.encodeH(latLon);
288
+ let cacheKey: string = outdoorImageHash;
289
+ if (date) {
290
+ cacheKey += date;
291
+ }
292
+ this._cachedPaths[cacheKey] = list;
293
+ return this._cachedPaths[cacheKey];
294
+ }),
295
+ );
296
+ }
297
+
298
+ /**
299
+ * Retrieve and cache node fill properties.
300
+ *
301
+ * @param {string} key - Key of node to fill.
302
+ * @returns {Observable<Graph>} Observable emitting the graph
303
+ * when the node has been updated.
304
+ * @throws {GraphBeeviewError} When the operation is not valid on the
305
+ * current graph.
306
+ */
307
+ public cacheFill$(key: string): Observable<Graph> {
308
+ if (key in this._cachingFull$) {
309
+ throw new GraphBeeviewError(
310
+ `Cannot fill node while caching full (${key}).`,
311
+ );
312
+ }
313
+
314
+ if (!this.hasNode(key)) {
315
+ throw new GraphBeeviewError(
316
+ `Cannot fill node that does not exist in graph (${key}).`,
317
+ );
318
+ }
319
+
320
+ if (key in this._cachingFill$) {
321
+ return this._cachingFill$[key];
322
+ }
323
+
324
+ let node: Node = this.getNode(key);
325
+ if (node.full) {
326
+ throw new GraphBeeviewError(
327
+ `Cannot fill node that is already full (${key}).`,
328
+ );
329
+ }
330
+
331
+ this._cachingFill$[key] = this._api.imageByKeyFill$([key]).pipe(
332
+ tap((imageByKeyFill: { [key: string]: IFillNode }): void => {
333
+ if (!node.full) {
334
+ this._makeFull(node, imageByKeyFill[key]);
335
+ }
336
+
337
+ delete this._cachingFill$[key];
338
+ }),
339
+ map((imageByKeyFill: { [key: string]: IFillNode }): Graph => {
340
+ return this;
341
+ }),
342
+ finalize((): void => {
343
+ if (key in this._cachingFill$) {
344
+ delete this._cachingFill$[key];
345
+ }
346
+
347
+ this._changed$.next(this);
348
+ }),
349
+ share(),
350
+ );
351
+
352
+ return this._cachingFill$[key];
353
+ }
354
+
355
+ /**
356
+ * Retrieve and cache full node properties.
357
+ *
358
+ * @param {string} key - Key of node to fill.
359
+ * @returns {Observable<Graph>} Observable emitting the graph
360
+ * when the node has been updated.
361
+ * @throws {GraphBeeviewError} When the operation is not valid on the
362
+ * current graph.
363
+ */
364
+ public cacheFull$(key: string): Observable<Graph> {
365
+ if (key in this._cachingFull$) {
366
+ return this._cachingFull$[key];
367
+ }
368
+
369
+ if (this.hasNode(key)) {
370
+ throw new GraphBeeviewError(
371
+ `Cannot cache full node that already exist in graph (${key}).`,
372
+ );
373
+ }
374
+
375
+ const getImageByKey$: Observable<{ [key: string]: IFullNode }> =
376
+ this._api
377
+ .imageByKeyFull$([key])
378
+ .pipe(
379
+ catchError(() =>
380
+ this._api.imageByKeyFullForOutdoor$([key]),
381
+ ),
382
+ );
383
+
384
+ this._cachingFull$[key] = getImageByKey$.pipe(
385
+ tap((imageByKeyFull: { [key: string]: IFullNode }): void => {
386
+ let fn: IFullNode = imageByKeyFull[key];
387
+
388
+ if (this.hasNode(key)) {
389
+ let node: Node = this.getNode(key);
390
+
391
+ if (!node.full) {
392
+ this._makeFull(node, fn);
393
+ }
394
+ } else {
395
+ if (fn.sequence == null || fn.sequence.key == null) {
396
+ throw new GraphBeeviewError(
397
+ `Node has no sequence (${key}).`,
398
+ );
399
+ }
400
+ let node: Node = new Node(fn);
401
+ this._makeFull(node, fn);
402
+
403
+ let h: string = this._graphCalculator.encodeH(
404
+ node.originalLatLon,
405
+ this._tilePrecision,
406
+ );
407
+ this._preStore(h, node);
408
+ this._setNode(node);
409
+
410
+ delete this._cachingFull$[key];
411
+ }
412
+ }),
413
+ map((imageByKeyFull: { [key: string]: IFullNode }): Graph => {
414
+ return this;
415
+ }),
416
+ finalize((): void => {
417
+ if (key in this._cachingFull$) {
418
+ delete this._cachingFull$[key];
419
+ }
420
+
421
+ this._changed$.next(this);
422
+ }),
423
+ share(),
424
+ );
425
+
426
+ return this._cachingFull$[key];
427
+ }
428
+
429
+ /**
430
+ * Retrieve and cache a node sequence.
431
+ *
432
+ * @param {string} key - Key of node for which to retrieve sequence.
433
+ * @returns {Observable<Graph>} Observable emitting the graph
434
+ * when the sequence has been retrieved.
435
+ * @throws {GraphBeeviewError} When the operation is not valid on the
436
+ * current graph.
437
+ */
438
+ public cacheNodeSequence$(key: string): Observable<Graph> {
439
+ if (!this.hasNode(key)) {
440
+ throw new GraphBeeviewError(
441
+ `Cannot cache sequence edges of node that does not exist in graph (${key}).`,
442
+ );
443
+ }
444
+
445
+ let node: Node = this.getNode(key);
446
+ if (node.sequenceKey in this._sequences) {
447
+ throw new GraphBeeviewError(
448
+ `Sequence already cached (${key}), (${node.sequenceKey}).`,
449
+ );
450
+ }
451
+
452
+ return this._cacheSequence$(node.sequenceKey);
453
+ }
454
+
455
+ /**
456
+ * Retrieve and cache a sequence.
457
+ *
458
+ * @param {string} sequenceKey - Key of sequence to cache.
459
+ * @returns {Observable<Graph>} Observable emitting the graph
460
+ * when the sequence has been retrieved.
461
+ * @throws {GraphBeeviewError} When the operation is not valid on the
462
+ * current graph.
463
+ */
464
+ public cacheSequence$(sequenceKey: string): Observable<Graph> {
465
+ if (sequenceKey in this._sequences) {
466
+ throw new GraphBeeviewError(
467
+ `Sequence already cached (${sequenceKey})`,
468
+ );
469
+ }
470
+
471
+ return this._cacheSequence$(sequenceKey);
472
+ }
473
+
474
+ /**
475
+ * Cache sequence edges for a node.
476
+ *
477
+ * @param {string} key - Key of node.
478
+ * @throws {GraphBeeviewError} When the operation is not valid on the
479
+ * current graph.
480
+ */
481
+ public cacheSequenceEdges(key: string): void {
482
+ let node: Node = this.getNode(key);
483
+
484
+ if (!(node.sequenceKey in this._sequences)) {
485
+ throw new GraphBeeviewError(
486
+ `Sequence is not cached (${key}), (${node.sequenceKey})`,
487
+ );
488
+ }
489
+
490
+ let sequence: Sequence = this._sequences[node.sequenceKey].sequence;
491
+ let edges: IEdge[] = this._edgeCalculator.computeSequenceEdges(
492
+ node,
493
+ sequence,
494
+ );
495
+
496
+ node.cacheSequenceEdges(edges);
497
+ }
498
+
499
+ /**
500
+ * Retrieve and cache full nodes for a node spatial area.
501
+ *
502
+ * @param {string} key - Key of node for which to retrieve sequence.
503
+ * @returns {Observable<Graph>} Observable emitting the graph
504
+ * when the nodes in the spatial area has been made full.
505
+ * @throws {GraphBeeviewError} When the operation is not valid on the
506
+ * current graph.
507
+ */
508
+ public cacheSpatialArea$(key: string): Observable<Graph>[] {
509
+ if (!this.hasNode(key)) {
510
+ throw new GraphBeeviewError(
511
+ `Cannot cache spatial area of node that does not exist in graph (${key}).`,
512
+ );
513
+ }
514
+
515
+ if (key in this._cachedSpatialEdges) {
516
+ throw new GraphBeeviewError(
517
+ `Node already spatially cached (${key}).`,
518
+ );
519
+ }
520
+
521
+ if (!(key in this._requiredSpatialArea)) {
522
+ throw new GraphBeeviewError(
523
+ `Spatial area not determined (${key}).`,
524
+ );
525
+ }
526
+
527
+ let spatialArea: SpatialArea = this._requiredSpatialArea[key];
528
+ if (Object.keys(spatialArea.cacheNodes).length === 0) {
529
+ throw new GraphBeeviewError(
530
+ `Spatial nodes already cached (${key}).`,
531
+ );
532
+ }
533
+
534
+ if (key in this._cachingSpatialArea$) {
535
+ return this._cachingSpatialArea$[key];
536
+ }
537
+
538
+ let batches: string[][] = [];
539
+ while (spatialArea.cacheKeys.length > 0) {
540
+ batches.push(spatialArea.cacheKeys.splice(0, 200));
541
+ }
542
+
543
+ let batchesToCache: number = batches.length;
544
+ let spatialNodes$: Observable<Graph>[] = [];
545
+
546
+ for (let batch of batches) {
547
+ let spatialNodeBatch$: Observable<Graph> = this._api
548
+ .imageByKeyFill$(batch)
549
+ .pipe(
550
+ tap(
551
+ (imageByKeyFill: {
552
+ [key: string]: IFillNode;
553
+ }): void => {
554
+ for (let fillKey in imageByKeyFill) {
555
+ if (!imageByKeyFill.hasOwnProperty(fillKey)) {
556
+ continue;
557
+ }
558
+
559
+ let spatialNode: Node =
560
+ spatialArea.cacheNodes[fillKey];
561
+ if (spatialNode.full) {
562
+ delete spatialArea.cacheNodes[fillKey];
563
+ continue;
564
+ }
565
+
566
+ let fillNode: IFillNode =
567
+ imageByKeyFill[fillKey];
568
+ this._makeFull(spatialNode, fillNode);
569
+
570
+ delete spatialArea.cacheNodes[fillKey];
571
+ }
572
+
573
+ if (--batchesToCache === 0) {
574
+ delete this._cachingSpatialArea$[key];
575
+ }
576
+ },
577
+ ),
578
+ map(
579
+ (imageByKeyFill: {
580
+ [key: string]: IFillNode;
581
+ }): Graph => {
582
+ return this;
583
+ },
584
+ ),
585
+ catchError((error: Error): Observable<Graph> => {
586
+ for (let batchKey of batch) {
587
+ if (batchKey in spatialArea.all) {
588
+ delete spatialArea.all[batchKey];
589
+ }
590
+
591
+ if (batchKey in spatialArea.cacheNodes) {
592
+ delete spatialArea.cacheNodes[batchKey];
593
+ }
594
+ }
595
+
596
+ if (--batchesToCache === 0) {
597
+ delete this._cachingSpatialArea$[key];
598
+ }
599
+
600
+ throw error;
601
+ }),
602
+ finalize((): void => {
603
+ if (Object.keys(spatialArea.cacheNodes).length === 0) {
604
+ this._changed$.next(this);
605
+ }
606
+ }),
607
+ share(),
608
+ );
609
+
610
+ spatialNodes$.push(spatialNodeBatch$);
611
+ }
612
+
613
+ this._cachingSpatialArea$[key] = spatialNodes$;
614
+
615
+ return spatialNodes$;
616
+ }
617
+
618
+ /**
619
+ * Cache spatial edges for a node.
620
+ *
621
+ * @param {string} key - Key of node.
622
+ * @throws {GraphBeeviewError} When the operation is not valid on the
623
+ * current graph.
624
+ */
625
+ public cacheSpatialEdges(key: string): void {
626
+ if (key in this._cachedSpatialEdges) {
627
+ throw new GraphBeeviewError(
628
+ `Spatial edges already cached (${key}).`,
629
+ );
630
+ }
631
+
632
+ let node: Node = this.getNode(key);
633
+ let sequence: Sequence = this._sequences[node.sequenceKey].sequence;
634
+
635
+ let fallbackKeys: string[] = [];
636
+ let prevKey: string = sequence.findPrevKey(node.key);
637
+ if (prevKey != null) {
638
+ fallbackKeys.push(prevKey);
639
+ }
640
+
641
+ let nextKey: string = sequence.findNextKey(node.key);
642
+ if (nextKey != null) {
643
+ fallbackKeys.push(nextKey);
644
+ }
645
+
646
+ let allSpatialNodes: { [key: string]: Node } =
647
+ this._requiredSpatialArea[key].all;
648
+ let potentialNodes: Node[] = [];
649
+ let filter: FilterFunction = this._filter;
650
+ for (let spatialNodeKey in allSpatialNodes) {
651
+ if (!allSpatialNodes.hasOwnProperty(spatialNodeKey)) {
652
+ continue;
653
+ }
654
+
655
+ let spatialNode: Node = allSpatialNodes[spatialNodeKey];
656
+
657
+ if (filter(spatialNode)) {
658
+ potentialNodes.push(spatialNode);
659
+ }
660
+ }
661
+
662
+ let potentialEdges: IPotentialEdge[] =
663
+ this._edgeCalculator.getPotentialEdges(
664
+ node,
665
+ potentialNodes,
666
+ fallbackKeys,
667
+ );
668
+
669
+ let edges: IEdge[] = this._edgeCalculator.computeStepEdges(
670
+ node,
671
+ potentialEdges,
672
+ prevKey,
673
+ nextKey,
674
+ );
675
+
676
+ edges = edges.concat(
677
+ this._edgeCalculator.computeTurnEdges(node, potentialEdges),
678
+ );
679
+ edges = edges.concat(
680
+ this._edgeCalculator.computePanoEdges(node, potentialEdges),
681
+ );
682
+ edges = edges.concat(
683
+ this._edgeCalculator.computePerspectiveToPanoEdges(
684
+ node,
685
+ potentialEdges,
686
+ ),
687
+ );
688
+ edges = edges.concat(
689
+ this._edgeCalculator.computeSimilarEdges(node, potentialEdges),
690
+ );
691
+
692
+ node.cacheSpatialEdges(edges);
693
+
694
+ this._cachedSpatialEdges[key] = node;
695
+ delete this._requiredSpatialArea[key];
696
+ delete this._cachedNodeTiles[key];
697
+ }
698
+
699
+ /**
700
+ * Retrieve and cache geohash tiles for a node.
701
+ *
702
+ * @param {string} key - Key of node for which to retrieve tiles.
703
+ * @returns {Observable<Graph>} Observable emitting the graph
704
+ * when the tiles required for the node has been cached.
705
+ * @throws {GraphBeeviewError} When the operation is not valid on the
706
+ * current graph.
707
+ */
708
+ public cacheTiles$(key: string): Observable<Graph>[] {
709
+ if (key in this._cachedNodeTiles) {
710
+ throw new GraphBeeviewError(`Tiles already cached (${key}).`);
711
+ }
712
+
713
+ if (key in this._cachedSpatialEdges) {
714
+ throw new GraphBeeviewError(
715
+ `Spatial edges already cached so tiles considered cached (${key}).`,
716
+ );
717
+ }
718
+
719
+ if (!(key in this._requiredNodeTiles)) {
720
+ throw new GraphBeeviewError(
721
+ `Tiles have not been determined (${key}).`,
722
+ );
723
+ }
724
+
725
+ let nodeTiles: NodeTiles = this._requiredNodeTiles[key];
726
+ if (nodeTiles.cache.length === 0 && nodeTiles.caching.length === 0) {
727
+ throw new GraphBeeviewError(`Tiles already cached (${key}).`);
728
+ }
729
+
730
+ if (!this.hasNode(key)) {
731
+ throw new GraphBeeviewError(
732
+ `Cannot cache tiles of node that does not exist in graph (${key}).`,
733
+ );
734
+ }
735
+
736
+ let hs: string[] = nodeTiles.cache.slice();
737
+ nodeTiles.caching = this._requiredNodeTiles[key].caching.concat(hs);
738
+ nodeTiles.cache = [];
739
+ let cacheTiles$: Observable<Graph>[] = [];
740
+ for (let h of nodeTiles.caching) {
741
+ let cacheTile$: Observable<Graph> = null;
742
+ if (h in this._cachingTiles$) {
743
+ cacheTile$ = this._cachingTiles$[h];
744
+ } else {
745
+ cacheTile$ = this._api
746
+ .imagesByH$(h, this.getNode(key).latLon)
747
+ .pipe(
748
+ tap(
749
+ (imagesByH: {
750
+ [key: string]: { [index: string]: ICoreNode };
751
+ }): void => {
752
+ let coreNodes: { [index: string]: ICoreNode } =
753
+ imagesByH[h];
754
+ if (h in this._cachedTiles) {
755
+ return;
756
+ }
757
+ this._nodeIndexTiles[h] = [];
758
+ this._cachedTiles[h] = {
759
+ accessed: new Date().getTime(),
760
+ nodes: [],
761
+ };
762
+ let hCache: Node[] = this._cachedTiles[h].nodes;
763
+ let preStored: { [key: string]: Node } =
764
+ this._removeFromPreStore(h);
765
+ for (let index in coreNodes) {
766
+ if (!coreNodes.hasOwnProperty(index)) {
767
+ continue;
768
+ }
769
+ let coreNode: ICoreNode = coreNodes[index];
770
+ if (coreNode == null) {
771
+ break;
772
+ }
773
+ if (
774
+ coreNode.sequence == null ||
775
+ coreNode.sequence.key == null
776
+ ) {
777
+ console.warn(
778
+ `Sequence missing, discarding (${coreNode.key})`,
779
+ );
780
+ continue;
781
+ }
782
+ let node: Node;
783
+ let nodeIndexItem: NodeIndexItem;
784
+ if (
785
+ preStored != null &&
786
+ coreNode.key in preStored
787
+ ) {
788
+ node = preStored[coreNode.key];
789
+ delete preStored[coreNode.key];
790
+ hCache.push(node);
791
+ nodeIndexItem = {
792
+ lat: node.latLon.lat,
793
+ lon: node.latLon.lon,
794
+ node: node,
795
+ };
796
+ this._nodeIndex.insert(nodeIndexItem);
797
+ this._nodeIndexTiles[h].push(
798
+ nodeIndexItem,
799
+ );
800
+ this._nodeToTile[node.key] = h;
801
+ continue;
802
+ }
803
+ node = new Node(coreNode);
804
+ hCache.push(node);
805
+ nodeIndexItem = {
806
+ lat: node.latLon.lat,
807
+ lon: node.latLon.lon,
808
+ node: node,
809
+ };
810
+ this._nodeIndex.insert(nodeIndexItem);
811
+ this._nodeIndexTiles[h].push(nodeIndexItem);
812
+ this._nodeToTile[node.key] = h;
813
+ this._setNode(node);
814
+ }
815
+ delete this._cachingTiles$[h];
816
+ },
817
+ ),
818
+ map(
819
+ (imagesByH: {
820
+ [key: string]: { [index: string]: ICoreNode };
821
+ }): Graph => {
822
+ return this;
823
+ },
824
+ ),
825
+ catchError((error: Error): Observable<Graph> => {
826
+ delete this._cachingTiles$[h];
827
+ throw error;
828
+ }),
829
+ share<Graph>(),
830
+ );
831
+
832
+ this._cachingTiles$[h] = cacheTile$;
833
+ }
834
+
835
+ cacheTiles$.push(
836
+ cacheTile$.pipe(
837
+ tap((graph: Graph): void => {
838
+ let index: number = nodeTiles.caching.indexOf(h);
839
+ if (index > -1) {
840
+ nodeTiles.caching.splice(index, 1);
841
+ }
842
+ if (
843
+ nodeTiles.caching.length === 0 &&
844
+ nodeTiles.cache.length === 0
845
+ ) {
846
+ delete this._requiredNodeTiles[key];
847
+ this._cachedNodeTiles[key] = true;
848
+ }
849
+ }),
850
+ finalize((): void => {
851
+ this._changed$.next(this);
852
+ }),
853
+ share(),
854
+ ),
855
+ );
856
+ }
857
+
858
+ return cacheTiles$;
859
+ }
860
+
861
+ /**
862
+ * Initialize the cache for a node.
863
+ *
864
+ * @param {string} key - Key of node.
865
+ * @throws {GraphBeeviewError} When the operation is not valid on the
866
+ * current graph.
867
+ */
868
+ public initializeCache(key: string): void {
869
+ if (key in this._cachedNodes) {
870
+ throw new GraphBeeviewError(`Node already in cache (${key}).`);
871
+ }
872
+
873
+ let node: Node = this.getNode(key);
874
+ node.initializeCache(new NodeCache());
875
+
876
+ let accessed: number = new Date().getTime();
877
+ this._cachedNodes[key] = { accessed: accessed, node: node };
878
+
879
+ this._updateCachedTileAccess(key, accessed);
880
+ }
881
+
882
+ /**
883
+ * Get a value indicating if the graph is fill caching a node.
884
+ *
885
+ * @param {string} key - Key of node.
886
+ * @returns {boolean} Value indicating if the node is being fill cached.
887
+ */
888
+ public isCachingFill(key: string): boolean {
889
+ return key in this._cachingFill$;
890
+ }
891
+
892
+ /**
893
+ * Get a value indicating if the graph is fully caching a node.
894
+ *
895
+ * @param {string} key - Key of node.
896
+ * @returns {boolean} Value indicating if the node is being fully cached.
897
+ */
898
+ public isCachingFull(key: string): boolean {
899
+ return key in this._cachingFull$;
900
+ }
901
+
902
+ /**
903
+ * Get a value indicating if the graph is caching a sequence of a node.
904
+ *
905
+ * @param {string} key - Key of node.
906
+ * @returns {boolean} Value indicating if the sequence of a node is
907
+ * being cached.
908
+ */
909
+ public isCachingNodeSequence(key: string): boolean {
910
+ let node: Node = this.getNode(key);
911
+
912
+ return node.sequenceKey in this._cachingSequences$;
913
+ }
914
+
915
+ /**
916
+ * Get a value indicating if the graph is caching a sequence.
917
+ *
918
+ * @param {string} sequenceKey - Key of sequence.
919
+ * @returns {boolean} Value indicating if the sequence is
920
+ * being cached.
921
+ */
922
+ public isCachingSequence(sequenceKey: string): boolean {
923
+ return sequenceKey in this._cachingSequences$;
924
+ }
925
+
926
+ /**
927
+ * Get a value indicating if the graph is caching the tiles
928
+ * required for calculating spatial edges of a node.
929
+ *
930
+ * @param {string} key - Key of node.
931
+ * @returns {boolean} Value indicating if the tiles of
932
+ * a node are being cached.
933
+ */
934
+ public isCachingTiles(key: string): boolean {
935
+ return (
936
+ key in this._requiredNodeTiles &&
937
+ this._requiredNodeTiles[key].cache.length === 0 &&
938
+ this._requiredNodeTiles[key].caching.length > 0
939
+ );
940
+ }
941
+
942
+ /**
943
+ * Get a value indicating if the cache has been initialized
944
+ * for a node.
945
+ *
946
+ * @param {string} key - Key of node.
947
+ * @returns {boolean} Value indicating if the cache has been
948
+ * initialized for a node.
949
+ */
950
+ public hasInitializedCache(key: string): boolean {
951
+ return key in this._cachedNodes;
952
+ }
953
+
954
+ public hasCachedPaths(key: string, date?: number): boolean {
955
+ if (date) {
956
+ key += date;
957
+ }
958
+ return key in this._cachedPaths;
959
+ }
960
+
961
+ public getCachedPaths(key: string, date?: number): IPathNode[] {
962
+ if (date) {
963
+ key += date;
964
+ }
965
+ return this._cachedPaths[key];
966
+ }
967
+
968
+ /**
969
+ * Get a value indicating if a node exist in the graph.
970
+ *
971
+ * @param {string} key - Key of node.
972
+ * @returns {boolean} Value indicating if a node exist in the graph.
973
+ */
974
+ public hasNode(key: string): boolean {
975
+ let accessed: number = new Date().getTime();
976
+
977
+ this._updateCachedNodeAccess(key, accessed);
978
+ this._updateCachedTileAccess(key, accessed);
979
+
980
+ return key in this._nodes;
981
+ }
982
+
983
+ /**
984
+ * Get a value indicating if a node sequence exist in the graph.
985
+ *
986
+ * @param {string} key - Key of node.
987
+ * @returns {boolean} Value indicating if a node sequence exist
988
+ * in the graph.
989
+ */
990
+ public hasNodeSequence(key: string): boolean {
991
+ let node: Node = this.getNode(key);
992
+ let sequenceKey: string = node.sequenceKey;
993
+
994
+ let hasNodeSequence: boolean = sequenceKey in this._sequences;
995
+
996
+ if (hasNodeSequence) {
997
+ this._sequences[sequenceKey].accessed = new Date().getTime();
998
+ }
999
+
1000
+ return hasNodeSequence;
1001
+ }
1002
+
1003
+ /**
1004
+ * Get a value indicating if a sequence exist in the graph.
1005
+ *
1006
+ * @param {string} sequenceKey - Key of sequence.
1007
+ * @returns {boolean} Value indicating if a sequence exist
1008
+ * in the graph.
1009
+ */
1010
+ public hasSequence(sequenceKey: string): boolean {
1011
+ let hasSequence: boolean = sequenceKey in this._sequences;
1012
+
1013
+ if (hasSequence) {
1014
+ this._sequences[sequenceKey].accessed = new Date().getTime();
1015
+ }
1016
+
1017
+ return hasSequence;
1018
+ }
1019
+
1020
+ /**
1021
+ * Get a value indicating if the graph has fully cached
1022
+ * all nodes in the spatial area of a node.
1023
+ *
1024
+ * @param {string} key - Key of node.
1025
+ * @returns {boolean} Value indicating if the spatial area
1026
+ * of a node has been cached.
1027
+ */
1028
+ public hasSpatialArea(key: string): boolean {
1029
+ if (!this.hasNode(key)) {
1030
+ throw new GraphBeeviewError(
1031
+ `Spatial area nodes cannot be determined if node not in graph (${key}).`,
1032
+ );
1033
+ }
1034
+
1035
+ if (key in this._cachedSpatialEdges) {
1036
+ return true;
1037
+ }
1038
+
1039
+ if (key in this._requiredSpatialArea) {
1040
+ return (
1041
+ Object.keys(this._requiredSpatialArea[key].cacheNodes)
1042
+ .length === 0
1043
+ );
1044
+ }
1045
+
1046
+ let node: Node = this.getNode(key);
1047
+ let bbox: [ILatLon, ILatLon] = this._graphCalculator.boundingBoxCorners(
1048
+ node.latLon,
1049
+ this._tileThreshold,
1050
+ );
1051
+
1052
+ let spatialItems: NodeIndexItem[] = this._nodeIndex.search({
1053
+ maxX: bbox[1].lat,
1054
+ maxY: bbox[1].lon,
1055
+ minX: bbox[0].lat,
1056
+ minY: bbox[0].lon,
1057
+ });
1058
+
1059
+ let spatialNodes: SpatialArea = {
1060
+ all: {},
1061
+ cacheKeys: [],
1062
+ cacheNodes: {},
1063
+ };
1064
+
1065
+ for (let spatialItem of spatialItems) {
1066
+ spatialNodes.all[spatialItem.node.key] = spatialItem.node;
1067
+
1068
+ if (!spatialItem.node.full) {
1069
+ spatialNodes.cacheKeys.push(spatialItem.node.key);
1070
+ spatialNodes.cacheNodes[spatialItem.node.key] =
1071
+ spatialItem.node;
1072
+ }
1073
+ }
1074
+
1075
+ this._requiredSpatialArea[key] = spatialNodes;
1076
+
1077
+ return spatialNodes.cacheKeys.length === 0;
1078
+ }
1079
+
1080
+ /**
1081
+ * Get a value indicating if the graph has a tiles required
1082
+ * for a node.
1083
+ *
1084
+ * @param {string} key - Key of node.
1085
+ * @returns {boolean} Value indicating if the the tiles required
1086
+ * by a node has been cached.
1087
+ */
1088
+ public hasTiles(key: string): boolean {
1089
+ if (key in this._cachedNodeTiles) {
1090
+ return true;
1091
+ }
1092
+
1093
+ if (key in this._cachedSpatialEdges) {
1094
+ return true;
1095
+ }
1096
+
1097
+ if (!this.hasNode(key)) {
1098
+ throw new GraphBeeviewError(
1099
+ `Node does not exist in graph (${key}).`,
1100
+ );
1101
+ }
1102
+
1103
+ let nodeTiles: NodeTiles = { cache: [], caching: [] };
1104
+
1105
+ if (!(key in this._requiredNodeTiles)) {
1106
+ let node: Node = this.getNode(key);
1107
+ nodeTiles.cache = this._graphCalculator
1108
+ .encodeHs(node.latLon, this._tilePrecision, this._tileThreshold)
1109
+ .filter((h: string): boolean => {
1110
+ return !(h in this._cachedTiles);
1111
+ });
1112
+
1113
+ if (nodeTiles.cache.length > 0) {
1114
+ this._requiredNodeTiles[key] = nodeTiles;
1115
+ }
1116
+ } else {
1117
+ nodeTiles = this._requiredNodeTiles[key];
1118
+ }
1119
+
1120
+ return nodeTiles.cache.length === 0 && nodeTiles.caching.length === 0;
1121
+ }
1122
+
1123
+ /**
1124
+ * Get a node.
1125
+ *
1126
+ * @param {string} key - Key of node.
1127
+ * @returns {Node} Retrieved node.
1128
+ */
1129
+ public getNode(key: string): Node {
1130
+ let accessed: number = new Date().getTime();
1131
+
1132
+ this._updateCachedNodeAccess(key, accessed);
1133
+ this._updateCachedTileAccess(key, accessed);
1134
+
1135
+ return this._nodes[key];
1136
+ }
1137
+
1138
+ /**
1139
+ * Get a sequence.
1140
+ *
1141
+ * @param {string} sequenceKey - Key of sequence.
1142
+ * @returns {Node} Retrieved sequence.
1143
+ */
1144
+ public getSequence(sequenceKey: string): Sequence {
1145
+ let sequenceAccess: SequenceAccess = this._sequences[sequenceKey];
1146
+ sequenceAccess.accessed = new Date().getTime();
1147
+
1148
+ return sequenceAccess.sequence;
1149
+ }
1150
+
1151
+ /**
1152
+ * Reset all spatial edges of the graph nodes.
1153
+ */
1154
+ public resetSpatialEdges(): void {
1155
+ let cachedKeys: string[] = Object.keys(this._cachedSpatialEdges);
1156
+
1157
+ for (let cachedKey of cachedKeys) {
1158
+ let node: Node = this._cachedSpatialEdges[cachedKey];
1159
+ node.resetSpatialEdges();
1160
+
1161
+ delete this._cachedSpatialEdges[cachedKey];
1162
+ }
1163
+ }
1164
+
1165
+ /**
1166
+ * Reset the complete graph but keep the nodes corresponding
1167
+ * to the supplied keys. All other nodes will be disposed.
1168
+ *
1169
+ * @param {Array<string>} keepKeys - Keys for nodes to keep
1170
+ * in graph after reset.
1171
+ */
1172
+ public reset(keepKeys: string[]): void {
1173
+ const nodes: Node[] = [];
1174
+ for (const key of keepKeys) {
1175
+ if (!this.hasNode(key)) {
1176
+ throw new Error(`Node does not exist ${key}`);
1177
+ }
1178
+
1179
+ const node: Node = this.getNode(key);
1180
+ node.resetSequenceEdges();
1181
+ node.resetSpatialEdges();
1182
+ nodes.push(node);
1183
+ }
1184
+
1185
+ for (let cachedKey of Object.keys(this._cachedNodes)) {
1186
+ if (keepKeys.indexOf(cachedKey) !== -1) {
1187
+ continue;
1188
+ }
1189
+
1190
+ this._cachedNodes[cachedKey].node.dispose();
1191
+ delete this._cachedNodes[cachedKey];
1192
+ }
1193
+
1194
+ this._cachedNodeTiles = {};
1195
+ this._cachedSpatialEdges = {};
1196
+ this._cachedTiles = {};
1197
+
1198
+ this._cachingFill$ = {};
1199
+ this._cachingFull$ = {};
1200
+ this._cachingSequences$ = {};
1201
+ this._cachingSpatialArea$ = {};
1202
+ this._cachingTiles$ = {};
1203
+
1204
+ this._nodes = {};
1205
+ this._nodeToTile = {};
1206
+
1207
+ this._preStored = {};
1208
+
1209
+ for (const node of nodes) {
1210
+ this._nodes[node.key] = node;
1211
+
1212
+ const h: string = this._graphCalculator.encodeH(
1213
+ node.originalLatLon,
1214
+ this._tilePrecision,
1215
+ );
1216
+ this._preStore(h, node);
1217
+ }
1218
+
1219
+ this._requiredNodeTiles = {};
1220
+ this._requiredSpatialArea = {};
1221
+
1222
+ this._sequences = {};
1223
+
1224
+ this._nodeIndexTiles = {};
1225
+ this._nodeIndex.clear();
1226
+ }
1227
+
1228
+ /**
1229
+ * Set the spatial node filter.
1230
+ *
1231
+ * @param {FilterExpression} filter - Filter expression to be applied
1232
+ * when calculating spatial edges.
1233
+ */
1234
+ public setFilter(filter: FilterExpression): void {
1235
+ this._filter = this._filterCreator.createFilter(filter);
1236
+ }
1237
+
1238
+ /**
1239
+ * Uncache the graph according to the graph configuration.
1240
+ *
1241
+ * @description Uncaches unused tiles, unused nodes and
1242
+ * sequences according to the numbers specified in the
1243
+ * graph configuration. Sequences does not have a direct
1244
+ * reference to either tiles or nodes and may be uncached
1245
+ * even if they are related to the nodes that should be kept.
1246
+ *
1247
+ * @param {Array<string>} keepKeys - Keys of nodes to keep in
1248
+ * graph unrelated to last access. Tiles related to those keys
1249
+ * will also be kept in graph.
1250
+ */
1251
+ public uncache(keepKeys: string[]): void {
1252
+ let keysInUse: { [key: string]: boolean } = {};
1253
+
1254
+ this._addNewKeys(keysInUse, this._cachingFull$);
1255
+ this._addNewKeys(keysInUse, this._cachingFill$);
1256
+ this._addNewKeys(keysInUse, this._cachingTiles$);
1257
+ this._addNewKeys(keysInUse, this._cachingSpatialArea$);
1258
+ this._addNewKeys(keysInUse, this._requiredNodeTiles);
1259
+ this._addNewKeys(keysInUse, this._requiredSpatialArea);
1260
+
1261
+ for (let key of keepKeys) {
1262
+ if (key in keysInUse) {
1263
+ continue;
1264
+ }
1265
+
1266
+ keysInUse[key] = true;
1267
+ }
1268
+
1269
+ let keepHs: { [h: string]: boolean } = {};
1270
+ for (let key in keysInUse) {
1271
+ if (!keysInUse.hasOwnProperty(key)) {
1272
+ continue;
1273
+ }
1274
+
1275
+ let node: Node = this._nodes[key];
1276
+
1277
+ let nodeHs: string[] = this._graphCalculator.encodeHs(node.latLon);
1278
+ for (let nodeH of nodeHs) {
1279
+ if (!(nodeH in keepHs)) {
1280
+ keepHs[nodeH] = true;
1281
+ }
1282
+ }
1283
+ }
1284
+
1285
+ let potentialHs: [string, TileAccess][] = [];
1286
+ for (let h in this._cachedTiles) {
1287
+ if (!this._cachedTiles.hasOwnProperty(h) || h in keepHs) {
1288
+ continue;
1289
+ }
1290
+
1291
+ potentialHs.push([h, this._cachedTiles[h]]);
1292
+ }
1293
+
1294
+ let uncacheHs: string[] = potentialHs
1295
+ .sort(
1296
+ (
1297
+ h1: [string, TileAccess],
1298
+ h2: [string, TileAccess],
1299
+ ): number => {
1300
+ return h2[1].accessed - h1[1].accessed;
1301
+ },
1302
+ )
1303
+ .slice(this._configuration.maxUnusedTiles)
1304
+ .map((h: [string, TileAccess]): string => {
1305
+ return h[0];
1306
+ });
1307
+
1308
+ for (let uncacheH of uncacheHs) {
1309
+ this._uncacheTile(uncacheH);
1310
+ }
1311
+
1312
+ let potentialNodes: NodeAccess[] = [];
1313
+ for (let key in this._cachedNodes) {
1314
+ if (!this._cachedNodes.hasOwnProperty(key) || key in keysInUse) {
1315
+ continue;
1316
+ }
1317
+
1318
+ potentialNodes.push(this._cachedNodes[key]);
1319
+ }
1320
+
1321
+ let uncacheNodes: NodeAccess[] = potentialNodes
1322
+ .sort((n1: NodeAccess, n2: NodeAccess): number => {
1323
+ return n2.accessed - n1.accessed;
1324
+ })
1325
+ .slice(this._configuration.maxUnusedNodes);
1326
+
1327
+ for (let nodeAccess of uncacheNodes) {
1328
+ nodeAccess.node.uncache();
1329
+ let key: string = nodeAccess.node.key;
1330
+ delete this._cachedNodes[key];
1331
+
1332
+ if (key in this._cachedNodeTiles) {
1333
+ delete this._cachedNodeTiles[key];
1334
+ }
1335
+
1336
+ if (key in this._cachedSpatialEdges) {
1337
+ delete this._cachedSpatialEdges[key];
1338
+ }
1339
+ }
1340
+
1341
+ let potentialSequences: SequenceAccess[] = [];
1342
+ for (let sequenceKey in this._sequences) {
1343
+ if (
1344
+ !this._sequences.hasOwnProperty(sequenceKey) ||
1345
+ sequenceKey in this._cachingSequences$
1346
+ ) {
1347
+ continue;
1348
+ }
1349
+
1350
+ potentialSequences.push(this._sequences[sequenceKey]);
1351
+ }
1352
+
1353
+ let uncacheSequences: SequenceAccess[] = potentialSequences
1354
+ .sort((s1: SequenceAccess, s2: SequenceAccess): number => {
1355
+ return s2.accessed - s1.accessed;
1356
+ })
1357
+ .slice(this._configuration.maxSequences);
1358
+
1359
+ for (let sequenceAccess of uncacheSequences) {
1360
+ let sequenceKey: string = sequenceAccess.sequence.key;
1361
+
1362
+ delete this._sequences[sequenceKey];
1363
+
1364
+ sequenceAccess.sequence.dispose();
1365
+ }
1366
+ }
1367
+
1368
+ private _addNewKeys<T>(
1369
+ keys: { [key: string]: boolean },
1370
+ dict: { [key: string]: T },
1371
+ ): void {
1372
+ for (let key in dict) {
1373
+ if (!dict.hasOwnProperty(key) || !this.hasNode(key)) {
1374
+ continue;
1375
+ }
1376
+
1377
+ if (!(key in keys)) {
1378
+ keys[key] = true;
1379
+ }
1380
+ }
1381
+ }
1382
+
1383
+ private _cacheSequence$(sequenceKey: string): Observable<Graph> {
1384
+ if (sequenceKey in this._cachingSequences$) {
1385
+ return this._cachingSequences$[sequenceKey];
1386
+ }
1387
+
1388
+ const getSequenceByKey$: Observable<{
1389
+ [sequenceKey: string]: ISequence;
1390
+ }> = this._api
1391
+ .sequenceByKey$([sequenceKey])
1392
+ .pipe(
1393
+ catchError(() =>
1394
+ this._api.sequenceByKeyForOutdoor$([sequenceKey]),
1395
+ ),
1396
+ );
1397
+
1398
+ this._cachingSequences$[sequenceKey] = getSequenceByKey$.pipe(
1399
+ tap((sequenceByKey: { [sequenceKey: string]: ISequence }): void => {
1400
+ if (!(sequenceKey in this._sequences)) {
1401
+ this._sequences[sequenceKey] = {
1402
+ accessed: new Date().getTime(),
1403
+ sequence: new Sequence(sequenceByKey[sequenceKey]),
1404
+ };
1405
+ }
1406
+
1407
+ delete this._cachingSequences$[sequenceKey];
1408
+ }),
1409
+ map(
1410
+ (sequenceByKey: {
1411
+ [sequenceKey: string]: ISequence;
1412
+ }): Graph => {
1413
+ return this;
1414
+ },
1415
+ ),
1416
+ finalize((): void => {
1417
+ if (sequenceKey in this._cachingSequences$) {
1418
+ delete this._cachingSequences$[sequenceKey];
1419
+ }
1420
+
1421
+ this._changed$.next(this);
1422
+ }),
1423
+ share(),
1424
+ );
1425
+
1426
+ return this._cachingSequences$[sequenceKey];
1427
+ }
1428
+
1429
+ private _makeFull(node: Node, fillNode: IFillNode): void {
1430
+ if (fillNode.calt == null) {
1431
+ fillNode.calt = this._defaultAlt;
1432
+ }
1433
+
1434
+ if (fillNode.c_rotation == null) {
1435
+ fillNode.c_rotation = this._graphCalculator.rotationFromCompass(
1436
+ fillNode.ca,
1437
+ fillNode.orientation,
1438
+ );
1439
+ }
1440
+ node.makeFull(fillNode);
1441
+ }
1442
+
1443
+ private _preStore(h: string, node: Node): void {
1444
+ if (!(h in this._preStored)) {
1445
+ this._preStored[h] = {};
1446
+ }
1447
+
1448
+ this._preStored[h][node.key] = node;
1449
+ }
1450
+
1451
+ private _removeFromPreStore(h: string): { [key: string]: Node } {
1452
+ let preStored: { [key: string]: Node } = null;
1453
+
1454
+ if (h in this._preStored) {
1455
+ preStored = this._preStored[h];
1456
+ delete this._preStored[h];
1457
+ }
1458
+
1459
+ return preStored;
1460
+ }
1461
+
1462
+ private _setNode(node: Node): void {
1463
+ let key: string = node.key;
1464
+
1465
+ if (this.hasNode(key)) {
1466
+ return;
1467
+ // throw new GraphBeeviewError(`Node already exist (${key}).`);
1468
+ }
1469
+
1470
+ this._nodes[key] = node;
1471
+ }
1472
+
1473
+ private _uncacheTile(h: string): void {
1474
+ for (let node of this._cachedTiles[h].nodes) {
1475
+ let key: string = node.key;
1476
+
1477
+ delete this._nodes[key];
1478
+ delete this._nodeToTile[key];
1479
+
1480
+ if (key in this._cachedNodes) {
1481
+ delete this._cachedNodes[key];
1482
+ }
1483
+
1484
+ if (key in this._cachedNodeTiles) {
1485
+ delete this._cachedNodeTiles[key];
1486
+ }
1487
+
1488
+ if (key in this._cachedSpatialEdges) {
1489
+ delete this._cachedSpatialEdges[key];
1490
+ }
1491
+
1492
+ node.dispose();
1493
+ }
1494
+
1495
+ for (let nodeIndexItem of this._nodeIndexTiles[h]) {
1496
+ this._nodeIndex.remove(nodeIndexItem);
1497
+ }
1498
+
1499
+ delete this._nodeIndexTiles[h];
1500
+ delete this._cachedTiles[h];
1501
+ }
1502
+
1503
+ private _updateCachedTileAccess(key: string, accessed: number): void {
1504
+ if (key in this._nodeToTile) {
1505
+ this._cachedTiles[this._nodeToTile[key]].accessed = accessed;
1506
+ }
1507
+ }
1508
+
1509
+ private _updateCachedNodeAccess(key: string, accessed: number): void {
1510
+ if (key in this._cachedNodes) {
1511
+ this._cachedNodes[key].accessed = accessed;
1512
+ }
1513
+ }
1514
+ }
1515
+
1516
+ export default Graph;