@twinmatrix/spatialverse-sdk-web 0.0.3 → 0.0.4
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/cjs/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/CustomThreeJsWrapper.js +2 -2
- package/lib/cjs/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/CustomThreeJsWrapper.js.map +1 -1
- package/lib/cjs/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/utility/utils.js +4 -3
- package/lib/cjs/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/utility/utils.js.map +1 -1
- package/lib/cjs/meta-atlas-sdk/3DMap/MainMap.js +202 -198
- package/lib/cjs/meta-atlas-sdk/3DMap/MainMap.js.map +1 -1
- package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/fetch-published-json.js +3 -3
- package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/fetch-published-json.js.map +1 -1
- package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/meta-atlas-sdk-core.js +32 -29
- package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/meta-atlas-sdk-core.js.map +1 -1
- package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/routing-core/index.js +10 -13
- package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/routing-core/index.js.map +1 -1
- package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/routing-core/routing-helpers.js +55 -68
- package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/routing-core/routing-helpers.js.map +1 -1
- package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/routing-core/utils.js +12 -12
- package/lib/cjs/meta-atlas-sdk/MetaAtlasCore/routing-core/utils.js.map +1 -1
- package/lib/cjs/meta-atlas-sdk/meta-atlas-sdk.js +73 -69
- package/lib/cjs/meta-atlas-sdk/meta-atlas-sdk.js.map +1 -1
- package/lib/cjs/meta-atlas-sdk/utils/helpers.js +1 -1
- package/lib/cjs/meta-atlas-sdk/utils/helpers.js.map +1 -1
- package/lib/cjs/meta-atlas-sdk/utils/local-storage.js +6 -1
- package/lib/cjs/meta-atlas-sdk/utils/local-storage.js.map +1 -1
- package/lib/cjs/meta-atlas-sdk/utils/routing-visualizer/index.js +103 -103
- package/lib/cjs/meta-atlas-sdk/utils/routing-visualizer/index.js.map +1 -1
- package/lib/cjs/react/MetaAtlasMap.js +4 -4
- package/lib/cjs/react/MetaAtlasMap.js.map +1 -1
- package/lib/cjs/react/hooks/useMapEvents/index.js +6 -3
- package/lib/cjs/react/hooks/useMapEvents/index.js.map +1 -1
- package/lib/cjs/react/hooks/useStampRally/index.js +7 -5
- package/lib/cjs/react/hooks/useStampRally/index.js.map +1 -1
- package/lib/cjs/react/hooks/useStampRally/utils.js +1 -1
- package/lib/cjs/react/hooks/useStampRally/utils.js.map +1 -1
- package/lib/cjs/react/stores/useMapDataStore.js +17 -21
- package/lib/cjs/react/stores/useMapDataStore.js.map +1 -1
- package/lib/esm/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/CustomThreeJsWrapper.js +2 -2
- package/lib/esm/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/CustomThreeJsWrapper.js.map +1 -1
- package/lib/esm/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/utility/utils.js +4 -3
- package/lib/esm/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/utility/utils.js.map +1 -1
- package/lib/esm/meta-atlas-sdk/3DMap/MainMap.js +202 -198
- package/lib/esm/meta-atlas-sdk/3DMap/MainMap.js.map +1 -1
- package/lib/esm/meta-atlas-sdk/MetaAtlasCore/fetch-published-json.js +3 -3
- package/lib/esm/meta-atlas-sdk/MetaAtlasCore/fetch-published-json.js.map +1 -1
- package/lib/esm/meta-atlas-sdk/MetaAtlasCore/meta-atlas-sdk-core.js +34 -31
- package/lib/esm/meta-atlas-sdk/MetaAtlasCore/meta-atlas-sdk-core.js.map +1 -1
- package/lib/esm/meta-atlas-sdk/MetaAtlasCore/routing-core/index.js +10 -8
- package/lib/esm/meta-atlas-sdk/MetaAtlasCore/routing-core/index.js.map +1 -1
- package/lib/esm/meta-atlas-sdk/MetaAtlasCore/routing-core/routing-helpers.js +55 -68
- package/lib/esm/meta-atlas-sdk/MetaAtlasCore/routing-core/routing-helpers.js.map +1 -1
- package/lib/esm/meta-atlas-sdk/MetaAtlasCore/routing-core/utils.js +12 -12
- package/lib/esm/meta-atlas-sdk/MetaAtlasCore/routing-core/utils.js.map +1 -1
- package/lib/esm/meta-atlas-sdk/meta-atlas-sdk.js +73 -68
- package/lib/esm/meta-atlas-sdk/meta-atlas-sdk.js.map +1 -1
- package/lib/esm/meta-atlas-sdk/utils/helpers.js +1 -1
- package/lib/esm/meta-atlas-sdk/utils/helpers.js.map +1 -1
- package/lib/esm/meta-atlas-sdk/utils/local-storage.js +6 -1
- package/lib/esm/meta-atlas-sdk/utils/local-storage.js.map +1 -1
- package/lib/esm/meta-atlas-sdk/utils/routing-visualizer/index.js +103 -101
- package/lib/esm/meta-atlas-sdk/utils/routing-visualizer/index.js.map +1 -1
- package/lib/esm/react/MetaAtlasMap.js +4 -4
- package/lib/esm/react/MetaAtlasMap.js.map +1 -1
- package/lib/esm/react/hooks/useMapEvents/index.js +6 -3
- package/lib/esm/react/hooks/useMapEvents/index.js.map +1 -1
- package/lib/esm/react/hooks/useStampRally/index.js +7 -5
- package/lib/esm/react/hooks/useStampRally/index.js.map +1 -1
- package/lib/esm/react/hooks/useStampRally/utils.js +1 -1
- package/lib/esm/react/hooks/useStampRally/utils.js.map +1 -1
- package/lib/esm/react/stores/useMapDataStore.js +17 -21
- package/lib/esm/react/stores/useMapDataStore.js.map +1 -1
- package/lib/types/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/utility/CameraSync.d.ts +30 -0
- package/lib/types/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/utility/CameraSync.d.ts.map +1 -0
- package/lib/types/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/utility/CameraUtils.d.ts +5 -0
- package/lib/types/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/utility/CameraUtils.d.ts.map +1 -0
- package/lib/types/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/utility/constants.d.ts +21 -0
- package/lib/types/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/utility/constants.d.ts.map +1 -0
- package/lib/types/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/utility/suncalc.d.ts +27 -0
- package/lib/types/meta-atlas-sdk/3DMap/CustomThreeJsWrapper/utility/suncalc.d.ts.map +1 -0
- package/lib/types/meta-atlas-sdk/mapbox_draw_custom_modes/draw_marker.d.ts +18 -0
- package/lib/types/meta-atlas-sdk/mapbox_draw_custom_modes/draw_marker.d.ts.map +1 -0
- package/lib/types/meta-atlas-sdk/mapbox_draw_custom_modes/marker_select.d.ts +37 -0
- package/lib/types/meta-atlas-sdk/mapbox_draw_custom_modes/marker_select.d.ts.map +1 -0
- package/package.json +4 -4
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MainMap.js","names":["_troikaThreeText","require","turf","_interopRequireWildcard","THREE","_utils","_threeSpritetext","_interopRequireDefault","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","MainMap","mainInstance","constructor","metaAtlasCore","init","map2D","map","initThreebox","wrapper","CustomThreeJSWrapper","setEnvironment","addLayer","id","type","renderingMode","onAdd","console","log","render","update","threebox","getThreebox","getAllPolygonCoordinates","polygonFeatures","source","getSource","features","querySourceFeatures","sourceLayer","filter","length","forEach","feature","geometry","properties","dimension_what","push","mapObjectId","name","title","coordinates","hasImage","Math","round","random","addNewLine","input","replace","updatePolygons","polygon","centroid","dimension_where","myText","SpriteText","color","text","textHeight","textPosition","projectToWorld","rotation","x","PI","y","scale","position","add","addLogo","logo","textureLoader","TextureLoader","texture","load","width","height","depth","BoxGeometry","sideMaterial","MeshBasicMaterial","Color","topMaterial","MeshStandardMaterial","side","DoubleSide","transparent","materials","logoMesh","Mesh","z","addTitle","textMesh","Text","fontSize","anchorX","anchorY","fontWeight","textAlign","sync","exports"],"sources":["../../../../src/meta-atlas-sdk/3DMap/MainMap.ts"],"sourcesContent":["import { Map as MaplibreMap } from 'maplibre-gl';\n\nimport CustomThreeJSWrapper from './CustomThreeJsWrapper/CustomThreeJsWrapper';\nimport { Text } from 'troika-three-text';\n\nimport { EquirectangularReflectionMapping } from 'three';\nimport { MetaAtlasCore } from '../MetaAtlasCore/meta-atlas-sdk-core';\nimport * as turf from '@turf/turf';\nimport * as THREE from 'three';\nimport { projectToWorld } from './CustomThreeJsWrapper/utility/utils';\nimport SpriteText from 'three-spritetext';\nimport { HDRLoader } from 'three/examples/jsm/loaders/HDRLoader';\n\nexport default class MainMap {\n public static mainInstance: MainMap | null = null;\n public map!: MaplibreMap;\n public threebox!: CustomThreeJSWrapper;\n public metaAtlasCore!: MetaAtlasCore;\n\n constructor(metaAtlasCore: MetaAtlasCore) {\n if (MainMap.mainInstance) {\n return MainMap.mainInstance;\n }\n\n MainMap.mainInstance = this;\n\n this.metaAtlasCore = metaAtlasCore;\n }\n\n public init(map2D: MaplibreMap) {\n this.map = map2D;\n this.initThreebox();\n }\n\n /**\n * Creates a Threebox instance of the class.\n * @param map Maplibre instance to initialize threebox\n * @returns Threebox class instance created\n */\n private initThreebox() {\n const map = this.map;\n const wrapper = new CustomThreeJSWrapper(map);\n wrapper.setEnvironment();\n // const hdrLoader = new HDRLoader();\n // hdrLoader.load('./golden_gate_hills_1k.hdr', texture => {\n // texture.mapping = EquirectangularReflectionMapping;\n // wrapper.scene.environment = texture;\n // });\n\n map.addLayer({\n id: '3d-model-layer',\n type: 'custom',\n renderingMode: '3d',\n onAdd: () => {\n console.log('onAdd _initThreebox');\n },\n render: () => {\n wrapper.update();\n }\n });\n\n this.threebox = wrapper;\n return wrapper;\n }\n\n /**\n * Get the threebox instance for 3D model operations\n */\n getThreebox() {\n return this.threebox;\n }\n\n getAllPolygonCoordinates = () => {\n const map = this.map;\n\n if (!map) return [];\n\n const polygonFeatures: any[] = [];\n const source = map.getSource('custom');\n if (source) {\n const features = map.querySourceFeatures('custom', {\n sourceLayer: 'geojson',\n filter: ['==', ['geometry-type'], 'Polygon']\n });\n\n if (features && features.length > 0) {\n features.forEach(feature => {\n if (\n (feature.geometry.type === 'Polygon' || feature.geometry.type === 'MultiPolygon') &&\n feature.properties.dimension_what === 'what.booth'\n ) {\n polygonFeatures.push({\n id: feature.properties.mapObjectId,\n name: feature.properties?.title || 'Unnamed Polygon',\n coordinates: feature.geometry.coordinates,\n properties: {\n ...feature.properties,\n hasImage: !!Math.round(Math.random())\n }\n });\n }\n });\n }\n }\n\n return polygonFeatures;\n };\n\n addNewLine(input: string): string {\n return input.replace(/ /g, '\\r\\n');\n }\n\n updatePolygons = (features: any[]) => {\n features.map(async (feature: any) => {\n const coordinates = feature.geometry.coordinates;\n // const centroid = feature.properties.center;\n const polygon = turf.polygon(coordinates);\n const centroid = turf.centroid(polygon).geometry.coordinates;\n // const modelPosition = projectToWorld(centroid);\n\n // const vertex1 = projectToWorld(coordinates[0][0]);\n // const vertex2 = projectToWorld(coordinates[0][1]);\n // const angle = vertex1.angleTo(vertex2);\n // console.log(angle);\n\n // await modelLoader.loadModel({\n // modelPath: feature.properties.modelPath,\n // feature,\n // wrapper: wrapper.current!,\n // onProgress: (progress) => {\n // setLoadingProgress((prev) => ({\n // ...prev,\n // [feature.properties.id]: progress,\n // }));\n // },\n // onError: (error) => {\n // console.error(\n // `Failed to load model ${feature.properties.id}:`,\n // error\n // );\n // },\n // });\n\n if (\n !feature.properties.hasImage &&\n feature.properties.dimension_where &&\n feature.properties.dimension_where === 'where.lima.mahsuri_center.exhibition_floor'\n ) {\n const myText = new SpriteText();\n myText.color = 'black';\n let text = feature.properties.title;\n text = this.addNewLine(text);\n\n // Set properties to configure:\n myText.text = text;\n myText.textHeight = 100;\n // myText.textHeight = 1;\n // myText.backgroundColor = '';\n const textPosition = projectToWorld(centroid);\n myText.rotation.x = Math.PI;\n myText.rotation.y = Math.PI;\n myText.scale.set(0.1, 0.1, 0.01);\n\n myText.position.set(\n textPosition.x,\n textPosition.y,\n // feature.properties.height > 0 ? 0.4 : 0.25\n 0.1\n );\n this.threebox.add(myText);\n } else {\n // Load Texture\n // const textureLoader = new THREE.TextureLoader();\n // textureLoader.load('/sk.png', (texture: THREE.Texture) => {\n // // Create a plane geometry and material with the loaded texture\n // const geometry = new THREE.PlaneGeometry(\n // texture.image.width,\n // texture.image.height\n // );\n // geometry.computeBoundingBox();\n // const material = new THREE.MeshStandardMaterial({\n // map: texture,\n // transparent: true, // Enable transparency\n // opacity: 1,\n // });\n // const plane = new THREE.Mesh(geometry, material);\n // const group = new THREE.Group();\n // const childContainer = new THREE.Group();\n // childContainer.add(plane);\n // childContainer.rotateZ(Math.PI / 2);\n // childContainer.rotateZ(1);\n // childContainer.updateMatrixWorld();\n // group.add(childContainer);\n // const geojsonbbox = turf.bbox(polygon);\n // const bbox1 = new THREE.Box3(\n // projectToWorld([geojsonbbox[2], geojsonbbox[3]]),\n // projectToWorld([geojsonbbox[0], geojsonbbox[1]])\n // );\n // const bbox2 = new THREE.Box3().setFromObject(plane);\n // const size1 = new THREE.Vector3();\n // bbox1.getSize(size1);\n // size1.setZ(1);\n // const size2 = new THREE.Vector3();\n // bbox2.getSize(size2);\n // size2.setZ(1);\n // const ratio = size1.divide(size2);\n // const ratioCopy = ratio.clone().multiplyScalar(0.85);\n // plane.scale.set(\n // plane.scale.x * ratioCopy.x,\n // plane.scale.y * ratioCopy.y,\n // plane.scale.z * ratioCopy.z\n // );\n // // // Set the position of the plane to the centroid\n // group.position.set(modelPosition.x, modelPosition.y, 0.11);\n // this.threebox.add(group);\n // });\n }\n });\n };\n\n addLogo = (logo: string, position: THREE.Vector3) => {\n const textureLoader = new THREE.TextureLoader();\n const texture = textureLoader.load(logo);\n\n // Define rectangle dimensions\n const width = 4;\n const height = 0;\n const depth = 2;\n\n // Create a box geometry instead of cylinder\n const geometry = new THREE.BoxGeometry(width, height, depth);\n\n // Create materials: [right, left, top, bottom, front, back]\n const sideMaterial = new THREE.MeshBasicMaterial({ color: new THREE.Color(0xffffff) });\n const topMaterial = new THREE.MeshStandardMaterial({\n map: texture,\n side: THREE.DoubleSide,\n transparent: true\n });\n\n // Create an array of materials for each face of the box\n const materials = [\n sideMaterial, // right\n sideMaterial, // left\n topMaterial, // top (with logo texture)\n sideMaterial, // bottom\n sideMaterial, // front\n sideMaterial // back\n ];\n\n // Create the mesh with geometry and materials\n const logoMesh = new THREE.Mesh(geometry, materials);\n\n // Adjust rotation to match your previous orientation\n logoMesh.rotation.x = Math.PI / 2;\n logoMesh.rotation.y = -Math.PI / 1.45;\n logoMesh.position.set(position.x + 0.5, position.y - 0.3, position.z);\n\n this.threebox.add(logoMesh);\n\n return logoMesh;\n };\n\n // Function to add text using Troika Text library at a specified position\n addTitle = (title: string, position: THREE.Vector3) => {\n // Create a new Text instance\n const textMesh = new Text();\n\n // Configure text properties\n textMesh.text = title;\n textMesh.fontSize = 0.2;\n textMesh.color = 0x000000;\n textMesh.anchorX = '50%';\n textMesh.anchorY = 'bottom-baseline';\n textMesh.fontWeight = 'bold';\n textMesh.textAlign = 'center';\n\n textMesh.position.set(position.x, position.y, position.z);\n textMesh.rotation.z = -Math.PI / 1.45;\n\n // Add text to the scene\n this.threebox.add(textMesh);\n\n // Update the text rendering\n textMesh.sync();\n\n return textMesh;\n };\n}\n"],"mappings":";;;;;;;AAGA,IAAAA,gBAAA,GAAAC,OAAA;AAIA,IAAAC,IAAA,GAAAC,uBAAA,CAAAF,OAAA;AACA,IAAAG,KAAA,GAAAD,uBAAA,CAAAF,OAAA;AAA+B,IAAAI,MAAA,GAAAJ,OAAA;AAE/B,IAAAK,gBAAA,GAAAC,sBAAA,CAAAN,OAAA;AAA0C,SAAAE,wBAAAK,CAAA,EAAAC,CAAA,6BAAAC,OAAA,MAAAC,CAAA,OAAAD,OAAA,IAAAE,C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,OAAOA,QAAQ;EACjB,CAAC;;EAED;EACAG,QAAQ,GAAGA,CAACjD,KAAa,EAAEyB,QAAuB,KAAK;IACrD;IACA,MAAMyB,QAAQ,GAAG,IAAIC,qBAAI,CAAC,CAAC;;IAE3B;IACAD,QAAQ,CAAClC,IAAI,GAAGhB,KAAK;IACrBkD,QAAQ,CAACE,QAAQ,GAAG,GAAG;IACvBF,QAAQ,CAACnC,KAAK,GAAG,QAAQ;IACzBmC,QAAQ,CAACG,OAAO,GAAG,KAAK;IACxBH,QAAQ,CAACI,OAAO,GAAG,iBAAiB;IACpCJ,QAAQ,CAACK,UAAU,GAAG,MAAM;IAC5BL,QAAQ,CAACM,SAAS,GAAG,QAAQ;IAE7BN,QAAQ,CAACzB,QAAQ,CAACtE,GAAG,CAACsE,QAAQ,CAACJ,CAAC,EAAEI,QAAQ,CAACF,CAAC,EAAEE,QAAQ,CAACuB,CAAC,CAAC;IACzDE,QAAQ,CAAC9B,QAAQ,CAAC4B,CAAC,GAAG,CAAC7C,IAAI,CAACmB,EAAE,GAAG,IAAI;;IAErC;IACA,IAAI,CAACzC,QAAQ,CAAC6C,GAAG,CAACwB,QAAQ,CAAC;;IAE3B;IACAA,QAAQ,CAACO,IAAI,CAAC,CAAC;IAEf,OAAOP,QAAQ;EACjB,CAAC;AACH;AAACQ,OAAA,CAAA1G,OAAA,GAAAS,OAAA","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"MainMap.js","names":["_troikaThreeText","require","turf","_interopRequireWildcard","THREE","_utils","_threeSpritetext","_interopRequireDefault","e","t","WeakMap","r","n","__esModule","o","i","f","__proto__","default","has","get","set","hasOwnProperty","call","Object","defineProperty","getOwnPropertyDescriptor","ownKeys","keys","getOwnPropertySymbols","filter","enumerable","push","apply","_objectSpread","arguments","length","forEach","_defineProperty","getOwnPropertyDescriptors","defineProperties","_toPropertyKey","value","configurable","writable","_toPrimitive","Symbol","toPrimitive","TypeError","String","Number","MainMap","constructor","metaAtlasCore","map","polygonFeatures","source","getSource","features","querySourceFeatures","sourceLayer","feature","geometry","type","properties","dimension_what","_feature$properties","id","mapObjectId","name","title","coordinates","hasImage","Math","round","random","polygon","centroid","dimension_where","myText","SpriteText","color","text","addNewLine","textHeight","textPosition","projectToWorld","rotation","x","PI","y","scale","position","threebox","add","logo","textureLoader","TextureLoader","texture","load","width","height","depth","BoxGeometry","sideMaterial","MeshBasicMaterial","Color","topMaterial","MeshStandardMaterial","side","DoubleSide","transparent","materials","logoMesh","Mesh","z","textMesh","Text","fontSize","anchorX","anchorY","fontWeight","textAlign","sync","mainInstance","init","map2D","initThreebox","wrapper","CustomThreeJSWrapper","setEnvironment","addLayer","renderingMode","onAdd","console","log","render","update","getThreebox","input","replace","exports"],"sources":["../../../../src/meta-atlas-sdk/3DMap/MainMap.ts"],"sourcesContent":["import { Map as MaplibreMap } from 'maplibre-gl';\n\nimport CustomThreeJSWrapper from './CustomThreeJsWrapper/CustomThreeJsWrapper';\nimport { Text } from 'troika-three-text';\n\nimport { EquirectangularReflectionMapping } from 'three';\nimport { MetaAtlasCore } from '../MetaAtlasCore/meta-atlas-sdk-core';\nimport * as turf from '@turf/turf';\nimport * as THREE from 'three';\nimport { projectToWorld } from './CustomThreeJsWrapper/utility/utils';\nimport SpriteText from 'three-spritetext';\nimport { HDRLoader } from 'three/examples/jsm/loaders/HDRLoader';\n\nexport default class MainMap {\n public static mainInstance: MainMap | null = null;\n public map!: MaplibreMap;\n public threebox!: CustomThreeJSWrapper;\n public metaAtlasCore!: MetaAtlasCore;\n\n constructor(metaAtlasCore: MetaAtlasCore) {\n if (MainMap.mainInstance) {\n return MainMap.mainInstance;\n }\n\n MainMap.mainInstance = this;\n\n this.metaAtlasCore = metaAtlasCore;\n }\n\n public init(map2D: MaplibreMap) {\n this.map = map2D;\n this.initThreebox();\n }\n\n /**\n * Creates a Threebox instance of the class.\n * @param map Maplibre instance to initialize threebox\n * @returns Threebox class instance created\n */\n private initThreebox() {\n const map = this.map;\n const wrapper = new CustomThreeJSWrapper(map);\n wrapper.setEnvironment();\n // const hdrLoader = new HDRLoader();\n // hdrLoader.load('./golden_gate_hills_1k.hdr', texture => {\n // texture.mapping = EquirectangularReflectionMapping;\n // wrapper.scene.environment = texture;\n // });\n\n map.addLayer({\n id: '3d-model-layer',\n type: 'custom',\n renderingMode: '3d',\n onAdd: () => {\n console.log('onAdd _initThreebox');\n },\n render: () => {\n wrapper.update();\n }\n });\n\n this.threebox = wrapper;\n return wrapper;\n }\n\n /**\n * Get the threebox instance for 3D model operations\n */\n getThreebox() {\n return this.threebox;\n }\n\n getAllPolygonCoordinates = () => {\n const map = this.map;\n\n if (!map) return [];\n\n const polygonFeatures: any[] = [];\n const source = map.getSource('custom');\n if (source) {\n const features = map.querySourceFeatures('custom', {\n sourceLayer: 'geojson',\n filter: ['==', ['geometry-type'], 'Polygon']\n });\n\n if (features && features.length > 0) {\n features.forEach(feature => {\n if (\n (feature.geometry.type === 'Polygon' || feature.geometry.type === 'MultiPolygon') &&\n feature.properties.dimension_what === 'what.booth'\n ) {\n polygonFeatures.push({\n id: feature.properties.mapObjectId,\n name: feature.properties?.title || 'Unnamed Polygon',\n coordinates: feature.geometry.coordinates,\n properties: {\n ...feature.properties,\n hasImage: !!Math.round(Math.random())\n }\n });\n }\n });\n }\n }\n\n return polygonFeatures;\n };\n\n addNewLine(input: string): string {\n return input.replace(/ /g, '\\r\\n');\n }\n\n updatePolygons = (features: any[]) => {\n features.map(async (feature: any) => {\n const coordinates = feature.geometry.coordinates;\n // const centroid = feature.properties.center;\n const polygon = turf.polygon(coordinates);\n const centroid = turf.centroid(polygon).geometry.coordinates;\n // const modelPosition = projectToWorld(centroid);\n\n // const vertex1 = projectToWorld(coordinates[0][0]);\n // const vertex2 = projectToWorld(coordinates[0][1]);\n // const angle = vertex1.angleTo(vertex2);\n // console.log(angle);\n\n // await modelLoader.loadModel({\n // modelPath: feature.properties.modelPath,\n // feature,\n // wrapper: wrapper.current!,\n // onProgress: (progress) => {\n // setLoadingProgress((prev) => ({\n // ...prev,\n // [feature.properties.id]: progress,\n // }));\n // },\n // onError: (error) => {\n // console.error(\n // `Failed to load model ${feature.properties.id}:`,\n // error\n // );\n // },\n // });\n\n if (\n !feature.properties.hasImage &&\n feature.properties.dimension_where &&\n feature.properties.dimension_where === 'where.lima.mahsuri_center.exhibition_floor'\n ) {\n const myText = new SpriteText();\n myText.color = 'black';\n let text = feature.properties.title;\n text = this.addNewLine(text);\n\n // Set properties to configure:\n myText.text = text;\n myText.textHeight = 100;\n // myText.textHeight = 1;\n // myText.backgroundColor = '';\n const textPosition = projectToWorld(centroid);\n myText.rotation.x = Math.PI;\n myText.rotation.y = Math.PI;\n myText.scale.set(0.1, 0.1, 0.01);\n\n myText.position.set(\n textPosition.x,\n textPosition.y,\n // feature.properties.height > 0 ? 0.4 : 0.25\n 0.1\n );\n this.threebox.add(myText);\n } else {\n // Load Texture\n // const textureLoader = new THREE.TextureLoader();\n // textureLoader.load('/sk.png', (texture: THREE.Texture) => {\n // // Create a plane geometry and material with the loaded texture\n // const geometry = new THREE.PlaneGeometry(\n // texture.image.width,\n // texture.image.height\n // );\n // geometry.computeBoundingBox();\n // const material = new THREE.MeshStandardMaterial({\n // map: texture,\n // transparent: true, // Enable transparency\n // opacity: 1,\n // });\n // const plane = new THREE.Mesh(geometry, material);\n // const group = new THREE.Group();\n // const childContainer = new THREE.Group();\n // childContainer.add(plane);\n // childContainer.rotateZ(Math.PI / 2);\n // childContainer.rotateZ(1);\n // childContainer.updateMatrixWorld();\n // group.add(childContainer);\n // const geojsonbbox = turf.bbox(polygon);\n // const bbox1 = new THREE.Box3(\n // projectToWorld([geojsonbbox[2], geojsonbbox[3]]),\n // projectToWorld([geojsonbbox[0], geojsonbbox[1]])\n // );\n // const bbox2 = new THREE.Box3().setFromObject(plane);\n // const size1 = new THREE.Vector3();\n // bbox1.getSize(size1);\n // size1.setZ(1);\n // const size2 = new THREE.Vector3();\n // bbox2.getSize(size2);\n // size2.setZ(1);\n // const ratio = size1.divide(size2);\n // const ratioCopy = ratio.clone().multiplyScalar(0.85);\n // plane.scale.set(\n // plane.scale.x * ratioCopy.x,\n // plane.scale.y * ratioCopy.y,\n // plane.scale.z * ratioCopy.z\n // );\n // // // Set the position of the plane to the centroid\n // group.position.set(modelPosition.x, modelPosition.y, 0.11);\n // this.threebox.add(group);\n // });\n }\n });\n };\n\n addLogo = (logo: string, position: THREE.Vector3) => {\n const textureLoader = new THREE.TextureLoader();\n const texture = textureLoader.load(logo);\n\n // Define rectangle dimensions\n const width = 4;\n const height = 0;\n const depth = 2;\n\n // Create a box geometry instead of cylinder\n const geometry = new THREE.BoxGeometry(width, height, depth);\n\n // Create materials: [right, left, top, bottom, front, back]\n const sideMaterial = new THREE.MeshBasicMaterial({ color: new THREE.Color(0xffffff) });\n const topMaterial = new THREE.MeshStandardMaterial({\n map: texture,\n side: THREE.DoubleSide,\n transparent: true\n });\n\n // Create an array of materials for each face of the box\n const materials = [\n sideMaterial, // right\n sideMaterial, // left\n topMaterial, // top (with logo texture)\n sideMaterial, // bottom\n sideMaterial, // front\n sideMaterial // back\n ];\n\n // Create the mesh with geometry and materials\n const logoMesh = new THREE.Mesh(geometry, materials);\n\n // Adjust rotation to match your previous orientation\n logoMesh.rotation.x = Math.PI / 2;\n logoMesh.rotation.y = -Math.PI / 1.45;\n logoMesh.position.set(position.x + 0.5, position.y - 0.3, position.z);\n\n this.threebox.add(logoMesh);\n\n return logoMesh;\n };\n\n // Function to add text using Troika Text library at a specified position\n addTitle = (title: string, position: THREE.Vector3) => {\n // Create a new Text instance\n const textMesh = new Text();\n\n // Configure text properties\n textMesh.text = title;\n textMesh.fontSize = 0.2;\n textMesh.color = 0x000000;\n textMesh.anchorX = '50%';\n textMesh.anchorY = 'bottom-baseline';\n textMesh.fontWeight = 'bold';\n textMesh.textAlign = 'center';\n\n textMesh.position.set(position.x, position.y, position.z);\n textMesh.rotation.z = -Math.PI / 1.45;\n\n // Add text to the scene\n this.threebox.add(textMesh);\n\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AC6E,QAAQ,CAAC;MACXhE,EAAE,EAAE,gBAAgB;MACpBJ,IAAI,EAAE,QAAQ;MACdqE,aAAa,EAAE,IAAI;MACnBC,KAAK,EAAEA,CAAA,KAAM;QACXC,OAAO,CAACC,GAAG,CAAC,qBAAqB,CAAC;MACpC,CAAC;MACDC,MAAM,EAAEA,CAAA,KAAM;QACZR,OAAO,CAACS,MAAM,CAAC,CAAC;MAClB;IACF,CAAC,CAAC;IAEF,IAAI,CAAC5C,QAAQ,GAAGmC,OAAO;IACvB,OAAOA,OAAO;EAChB;;EAEA;AACF;AACA;EACEU,WAAWA,CAAA,EAAG;IACZ,OAAO,IAAI,CAAC7C,QAAQ;EACtB;EAsCAV,UAAUA,CAACwD,KAAa,EAAU;IAChC,OAAOA,KAAK,CAACC,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC;EACpC;AAkLF;AAACC,OAAA,CAAA3H,OAAA,GAAAiC,OAAA;AAAAb,eAAA,CAnRoBa,OAAO,kBACmB,IAAI","ignoreList":[]}
|
|
@@ -52,9 +52,9 @@ async function getPublishedData(serverAPIInfo, localStorage) {
|
|
|
52
52
|
const currentVersion = localStorage.contains(localStorageVersionKey) ? localStorage.getString(localStorageVersionKey) : '0.0.0';
|
|
53
53
|
return new Promise((resolve, reject) => {
|
|
54
54
|
(0, _axios.default)({
|
|
55
|
-
url:
|
|
55
|
+
url: "".concat(serverAPIInfo.URL, "/check-published-versions"),
|
|
56
56
|
headers: {
|
|
57
|
-
Authorization:
|
|
57
|
+
Authorization: "Bearer ".concat(serverAPIInfo.accessToken),
|
|
58
58
|
'Content-Type': 'application/json'
|
|
59
59
|
},
|
|
60
60
|
method: 'POST',
|
|
@@ -168,7 +168,7 @@ async function getPublishedData(serverAPIInfo, localStorage) {
|
|
|
168
168
|
// This is the API call for getting map-objects.json
|
|
169
169
|
const response = await fetch(info.URL);
|
|
170
170
|
if (!response.ok) {
|
|
171
|
-
throw new Error(
|
|
171
|
+
throw new Error("HTTP error! Status: ".concat(response.status));
|
|
172
172
|
}
|
|
173
173
|
const responseData = await response.json();
|
|
174
174
|
// const responseData = JSON.parse(fileContent);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fetch-published-json.js","names":["_axios","_interopRequireDefault","require","_helpers","_routingStore","_mapobjectsStore","e","__esModule","default","PublishedDataType","exports","Status","getDataType","publishedDataType","Routing","MapObjects","getLocalStorageKey","param","valueOf","setRouteData","useRouteDataStore","setState","setMapObjectsData","useMapObjectsDataStore","getRunTimeStore","getPublishedData","serverAPIInfo","localStorage","localStorageVersionKey","status","Awaiting","setRunTimeStoreData","fetchInfo","currentVersion","contains","getString","Promise","resolve","reject","axios","url","URL","headers","Authorization","accessToken","method","data","JSON","stringify","version","dataType","then","response","remoteData","publishedDataInfo","undefined","remoteVersion","localVersion","hasOwnProperty","currentData","tag","downloadUrl","DownloadingResources","console","log","catch","error","request","message","config","storeFileToLocalStorage","set","loadFileFromStore","decryptedJson","decryptFile","secretKey","Ready","onError","loaded","Unavailable","clearAll","info","fetch","ok","Error","responseData","json","storedSuccessfully"],"sources":["../../../../src/meta-atlas-sdk/MetaAtlasCore/fetch-published-json.ts"],"sourcesContent":["import axios from 'axios';\n\nimport { LocalStorage } from '../utils/local-storage';\nimport { decryptFile } from '../utils/helpers';\nimport useRouteDataStore from '../utils/routing-store';\nimport useMapObjectsDataStore from '../utils/mapobjects-store';\n\nexport enum PublishedDataType {\n Routing = 'routing',\n MapObjects = 'mapObjects',\n}\n\nexport enum Status {\n Ready = 'Ready',\n Awaiting = 'Awaiting',\n DownloadingResources = 'DownloadingResources',\n Unavailable = 'Unavailable',\n}\n\nexport type StatusUpdateCallbackType = (loaded: boolean) => void;\n\nexport interface ServerAPIInfo {\n URL: string;\n accessToken: string;\n secretKey: string;\n publishedDataType: PublishedDataType;\n}\n\nexport interface PublishedDataInfo {\n currentVersion: string | undefined;\n remoteVersion: string | undefined;\n URL: string | undefined;\n data: string | undefined;\n}\n\nfunction getDataType(publishedDataType: PublishedDataType) {\n if (publishedDataType === PublishedDataType.Routing) {\n return 'generate-route-json-per-role';\n }\n if (publishedDataType === PublishedDataType.MapObjects) {\n return 'generate-map-objects-per-role';\n }\n}\n\nfunction getLocalStorageKey(\n param: string,\n publishedDataType: PublishedDataType,\n): string {\n return publishedDataType.valueOf() + param;\n}\n\nconst setRouteData = useRouteDataStore.setState;\nconst setMapObjectsData = useMapObjectsDataStore.setState;\n\nfunction getRunTimeStore(publishedDataType: PublishedDataType) {\n if (publishedDataType === PublishedDataType.Routing) {\n return setRouteData;\n }\n if (publishedDataType === PublishedDataType.MapObjects) {\n return setMapObjectsData;\n }\n}\n\nexport async function getPublishedData(\n serverAPIInfo: ServerAPIInfo,\n localStorage: LocalStorage,\n) {\n const publishedDataType = serverAPIInfo.publishedDataType;\n const localStorageVersionKey = getLocalStorageKey(\n 'version',\n publishedDataType,\n );\n let status: Status = Status.Awaiting;\n let setRunTimeStoreData = getRunTimeStore(publishedDataType);\n\n const fetchInfo = async () => {\n const currentVersion = localStorage.contains(localStorageVersionKey)\n ? localStorage.getString(localStorageVersionKey)\n : '0.0.0';\n return new Promise(\n (resolve: (routingInfo: PublishedDataInfo) => void, reject) => {\n axios({\n url: `${serverAPIInfo.URL}/check-published-versions`,\n headers: {\n Authorization: `Bearer ${serverAPIInfo.accessToken}`,\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n data: JSON.stringify({\n version: currentVersion,\n dataType: getDataType(serverAPIInfo.publishedDataType),\n }),\n })\n .then(response => {\n const remoteData = response.data;\n\n const publishedDataInfo = {\n currentVersion: undefined,\n remoteVersion: undefined,\n URL: undefined,\n data: undefined,\n } as PublishedDataInfo;\n const localVersion = localStorage.getString(localStorageVersionKey);\n let remoteVersion = localVersion;\n if (remoteData.hasOwnProperty('version')) {\n remoteVersion = remoteData.version;\n }\n\n publishedDataInfo.currentVersion = localVersion;\n publishedDataInfo.remoteVersion = remoteVersion;\n if (localVersion) {\n const currentData = localStorage.getString(\n getLocalStorageKey('data', publishedDataType),\n );\n const tag = localStorage.getString(\n getLocalStorageKey('encryptionTag', publishedDataType),\n );\n\n // Check both because data is useless without tag\n if (tag && currentData) {\n publishedDataInfo.data = currentData;\n }\n }\n if (remoteVersion) {\n if (remoteData.hasOwnProperty('downloadUrl')) {\n publishedDataInfo.URL = remoteData.downloadUrl;\n }\n if (\n (localVersion && remoteVersion > localVersion) ||\n !localVersion ||\n !publishedDataInfo.data\n ) {\n status = publishedDataInfo.URL\n ? Status.DownloadingResources\n : status;\n }\n }\n\n console.log(\n 'final: ',\n publishedDataInfo.URL,\n publishedDataInfo.currentVersion,\n publishedDataInfo.remoteVersion,\n );\n resolve(publishedDataInfo);\n })\n .catch(function (error) {\n console.log('error while fetching published version: ');\n if (error.response) {\n // The request was made and the server responded with a status code\n // that falls out of the range of 2xx\n console.log(error.response.data);\n console.log(error.response.status);\n console.log(error.response.headers);\n } else if (error.request) {\n // The request was made but no response was received\n // `error.request` is an instance of XMLHttpRequest in the browser and an instance of\n // http.ClientRequest in node.js\n console.log(error.request);\n } else {\n // Something happened in setting up the request that triggered an Error\n console.log('Error', error.message);\n }\n console.log(error.config);\n reject(error);\n });\n },\n );\n };\n\n const storeFileToLocalStorage = (data: any, version: any, tag: any) => {\n try {\n localStorage.set(getLocalStorageKey('data', publishedDataType), data);\n localStorage.set(localStorageVersionKey, version);\n localStorage.set(\n getLocalStorageKey('encryptionTag', publishedDataType),\n tag,\n );\n return true;\n } catch (e) {\n console.log('error storing routing file from local storage', e);\n return false;\n }\n };\n\n const loadFileFromStore = () => {\n const currentData = localStorage.getString(\n getLocalStorageKey('data', publishedDataType),\n );\n const tag = localStorage.getString(\n getLocalStorageKey('encryptionTag', publishedDataType),\n );\n if (currentData && tag) {\n const decryptedJson = decryptFile(currentData, tag, serverAPIInfo.secretKey);\n // JSON.parse(storage.getString('routeData')\n setRunTimeStoreData({data: decryptedJson});\n status = Status.Ready;\n return true;\n } else {\n return false;\n }\n };\n\n const onError = () => {\n try {\n const loaded = loadFileFromStore();\n if (!loaded) {\n console.log('failed to load data');\n status = Status.Unavailable;\n }\n } catch (error) {\n console.log('erro while loading data');\n status = Status.Unavailable;\n localStorage.clearAll();\n }\n };\n\n try {\n const info = await fetchInfo();\n // @ts-ignore\n if (status === Status.DownloadingResources && info.URL) {\n // download\n console.log('downloading from server');\n try {\n // Fetch encrypted data from the server\n // This is the API call for getting map-objects.json\n const response = await fetch(info.URL);\n if (!response.ok) {\n throw new Error(`HTTP error! Status: ${response.status}`);\n }\n const responseData = await response.json();\n // const responseData = JSON.parse(fileContent);\n const {data, tag} = responseData;\n\n const decryptedJson = await decryptFile(data, tag, serverAPIInfo.secretKey);\n const storedSuccessfully = storeFileToLocalStorage(\n data,\n info.remoteVersion,\n tag,\n );\n if (storedSuccessfully) {\n console.log('loaded file');\n setRunTimeStoreData({data: decryptedJson});\n status = Status.Ready;\n }\n } catch (error) {\n console.error('Error fetching and decrypting data:', error);\n onError();\n }\n } else {\n const tag = localStorage.getString('encryptionTag');\n // set to store\n if (info.data && tag) {\n console.log('loaded local file');\n const decryptedJson = decryptFile(info.data, tag, serverAPIInfo.secretKey);\n setRunTimeStoreData({data: decryptedJson});\n status = Status.Ready;\n } else {\n onError();\n }\n }\n } catch (error) {\n onError();\n }\n\n return status;\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA0B,IAAAC,QAAA,GAAAD,OAAA;AAAA,IAAAE,aAAA,GAAAH,sBAAA,CAAAC,OAAA;AAAA,IAAAG,gBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAAA,SAAAD,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,IAOdG,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,0BAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAA,OAAjBA,iBAAiB;AAAA;AA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AACG,KAAK,CAAC,qCAAqC,EAAEA,KAAK,CAAC;QAC3DW,OAAO,CAAC,CAAC;MACX;IACF,CAAC,MAAM;MACL,MAAMjB,GAAG,GAAGjC,YAAY,CAACQ,SAAS,CAAC,eAAe,CAAC;MACnD;MACA,IAAI8C,IAAI,CAACnC,IAAI,IAAIc,GAAG,EAAE;QACpBG,OAAO,CAACC,GAAG,CAAC,mBAAmB,CAAC;QAChC,MAAMS,aAAa,GAAG,IAAAC,oBAAW,EAACO,IAAI,CAACnC,IAAI,EAAEc,GAAG,EAAElC,aAAa,CAACiD,SAAS,CAAC;QAC1E5C,mBAAmB,CAAC;UAACe,IAAI,EAAE2B;QAAa,CAAC,CAAC;QAC1C5C,MAAM,GAAGlB,MAAM,CAACiE,KAAK;MACvB,CAAC,MAAM;QACLC,OAAO,CAAC,CAAC;MACX;IACF;EACF,CAAC,CAAC,OAAOX,KAAK,EAAE;IACdW,OAAO,CAAC,CAAC;EACX;EAEA,OAAOhD,MAAM;AACf","ignoreList":[]}
|
|
1
|
+
{"version":3,"file":"fetch-published-json.js","names":["_axios","_interopRequireDefault","require","_helpers","_routingStore","_mapobjectsStore","e","__esModule","default","PublishedDataType","exports","Status","getDataType","publishedDataType","Routing","MapObjects","getLocalStorageKey","param","valueOf","setRouteData","useRouteDataStore","setState","setMapObjectsData","useMapObjectsDataStore","getRunTimeStore","getPublishedData","serverAPIInfo","localStorage","localStorageVersionKey","status","Awaiting","setRunTimeStoreData","fetchInfo","currentVersion","contains","getString","Promise","resolve","reject","axios","url","concat","URL","headers","Authorization","accessToken","method","data","JSON","stringify","version","dataType","then","response","remoteData","publishedDataInfo","undefined","remoteVersion","localVersion","hasOwnProperty","currentData","tag","downloadUrl","DownloadingResources","console","log","catch","error","request","message","config","storeFileToLocalStorage","set","loadFileFromStore","decryptedJson","decryptFile","secretKey","Ready","onError","loaded","Unavailable","clearAll","info","fetch","ok","Error","responseData","json","storedSuccessfully"],"sources":["../../../../src/meta-atlas-sdk/MetaAtlasCore/fetch-published-json.ts"],"sourcesContent":["import axios from 'axios';\n\nimport { LocalStorage } from '../utils/local-storage';\nimport { decryptFile } from '../utils/helpers';\nimport useRouteDataStore from '../utils/routing-store';\nimport useMapObjectsDataStore from '../utils/mapobjects-store';\n\nexport enum PublishedDataType {\n Routing = 'routing',\n MapObjects = 'mapObjects',\n}\n\nexport enum Status {\n Ready = 'Ready',\n Awaiting = 'Awaiting',\n DownloadingResources = 'DownloadingResources',\n Unavailable = 'Unavailable',\n}\n\nexport type StatusUpdateCallbackType = (loaded: boolean) => void;\n\nexport interface ServerAPIInfo {\n URL: string;\n accessToken: string;\n secretKey: string;\n publishedDataType: PublishedDataType;\n}\n\nexport interface PublishedDataInfo {\n currentVersion: string | undefined;\n remoteVersion: string | undefined;\n URL: string | undefined;\n data: string | undefined;\n}\n\nfunction getDataType(publishedDataType: PublishedDataType) {\n if (publishedDataType === PublishedDataType.Routing) {\n return 'generate-route-json-per-role';\n }\n if (publishedDataType === PublishedDataType.MapObjects) {\n return 'generate-map-objects-per-role';\n }\n}\n\nfunction getLocalStorageKey(\n param: string,\n publishedDataType: PublishedDataType,\n): string {\n return publishedDataType.valueOf() + param;\n}\n\nconst setRouteData = useRouteDataStore.setState;\nconst setMapObjectsData = useMapObjectsDataStore.setState;\n\nfunction getRunTimeStore(publishedDataType: PublishedDataType) {\n if (publishedDataType === PublishedDataType.Routing) {\n return setRouteData;\n }\n if (publishedDataType === PublishedDataType.MapObjects) {\n return setMapObjectsData;\n }\n}\n\nexport async function getPublishedData(\n serverAPIInfo: ServerAPIInfo,\n localStorage: LocalStorage,\n) {\n const publishedDataType = serverAPIInfo.publishedDataType;\n const localStorageVersionKey = getLocalStorageKey(\n 'version',\n publishedDataType,\n );\n let status: Status = Status.Awaiting;\n let setRunTimeStoreData = getRunTimeStore(publishedDataType);\n\n const fetchInfo = async () => {\n const currentVersion = localStorage.contains(localStorageVersionKey)\n ? localStorage.getString(localStorageVersionKey)\n : '0.0.0';\n return new Promise(\n (resolve: (routingInfo: PublishedDataInfo) => void, reject) => {\n axios({\n url: `${serverAPIInfo.URL}/check-published-versions`,\n headers: {\n Authorization: `Bearer ${serverAPIInfo.accessToken}`,\n 'Content-Type': 'application/json',\n },\n method: 'POST',\n data: JSON.stringify({\n version: currentVersion,\n dataType: getDataType(serverAPIInfo.publishedDataType),\n }),\n })\n .then(response => {\n const remoteData = response.data;\n\n const publishedDataInfo = {\n currentVersion: undefined,\n remoteVersion: undefined,\n URL: undefined,\n data: undefined,\n } as PublishedDataInfo;\n const localVersion = localStorage.getString(localStorageVersionKey);\n let remoteVersion = localVersion;\n if (remoteData.hasOwnProperty('version')) {\n remoteVersion = remoteData.version;\n }\n\n publishedDataInfo.currentVersion = localVersion;\n publishedDataInfo.remoteVersion = remoteVersion;\n if (localVersion) {\n const currentData = localStorage.getString(\n getLocalStorageKey('data', publishedDataType),\n );\n const tag = localStorage.getString(\n getLocalStorageKey('encryptionTag', publishedDataType),\n );\n\n // Check both because data is useless without tag\n if (tag && currentData) {\n publishedDataInfo.data = currentData;\n }\n }\n if (remoteVersion) {\n if (remoteData.hasOwnProperty('downloadUrl')) {\n publishedDataInfo.URL = remoteData.downloadUrl;\n }\n if (\n (localVersion && remoteVersion > localVersion) ||\n !localVersion ||\n !publishedDataInfo.data\n ) {\n status = publishedDataInfo.URL\n ? Status.DownloadingResources\n : status;\n }\n }\n\n console.log(\n 'final: ',\n publishedDataInfo.URL,\n publishedDataInfo.currentVersion,\n publishedDataInfo.remoteVersion,\n );\n resolve(publishedDataInfo);\n })\n .catch(function (error) {\n console.log('error while fetching published version: ');\n if (error.response) {\n // The request was made and the server responded with a status code\n // that falls out of the range of 2xx\n console.log(error.response.data);\n console.log(error.response.status);\n console.log(error.response.headers);\n } else if (error.request) {\n // The request was made but no response was received\n // `error.request` is an instance of XMLHttpRequest in the browser and an instance of\n // http.ClientRequest in node.js\n console.log(error.request);\n } else {\n // Something happened in setting up the request that triggered an Error\n console.log('Error', error.message);\n }\n console.log(error.config);\n reject(error);\n });\n },\n );\n };\n\n const storeFileToLocalStorage = (data: any, version: any, tag: any) => {\n try {\n localStorage.set(getLocalStorageKey('data', publishedDataType), data);\n localStorage.set(localStorageVersionKey, version);\n localStorage.set(\n getLocalStorageKey('encryptionTag', publishedDataType),\n tag,\n );\n return true;\n } catch (e) {\n console.log('error storing routing file from local storage', e);\n return false;\n }\n };\n\n const loadFileFromStore = () => {\n const currentData = localStorage.getString(\n getLocalStorageKey('data', publishedDataType),\n );\n const tag = localStorage.getString(\n getLocalStorageKey('encryptionTag', publishedDataType),\n );\n if (currentData && tag) {\n const decryptedJson = decryptFile(currentData, tag, serverAPIInfo.secretKey);\n // JSON.parse(storage.getString('routeData')\n setRunTimeStoreData({data: decryptedJson});\n status = Status.Ready;\n return true;\n } else {\n return false;\n }\n };\n\n const onError = () => {\n try {\n const loaded = loadFileFromStore();\n if (!loaded) {\n console.log('failed to load data');\n status = Status.Unavailable;\n }\n } catch (error) {\n console.log('erro while loading data');\n status = Status.Unavailable;\n localStorage.clearAll();\n }\n };\n\n try {\n const info = await fetchInfo();\n // @ts-ignore\n if (status === Status.DownloadingResources && info.URL) {\n // download\n console.log('downloading from server');\n try {\n // Fetch encrypted data from the server\n // This is the API call for getting map-objects.json\n const response = await fetch(info.URL);\n if (!response.ok) {\n throw new Error(`HTTP error! Status: ${response.status}`);\n }\n const responseData = await response.json();\n // const responseData = JSON.parse(fileContent);\n const {data, tag} = responseData;\n\n const decryptedJson = await decryptFile(data, tag, serverAPIInfo.secretKey);\n const storedSuccessfully = storeFileToLocalStorage(\n data,\n info.remoteVersion,\n tag,\n );\n if (storedSuccessfully) {\n console.log('loaded file');\n setRunTimeStoreData({data: decryptedJson});\n status = Status.Ready;\n }\n } catch (error) {\n console.error('Error fetching and decrypting data:', error);\n onError();\n }\n } else {\n const tag = localStorage.getString('encryptionTag');\n // set to store\n if (info.data && tag) {\n console.log('loaded local file');\n const decryptedJson = decryptFile(info.data, tag, serverAPIInfo.secretKey);\n setRunTimeStoreData({data: decryptedJson});\n status = Status.Ready;\n } else {\n onError();\n }\n }\n } catch (error) {\n onError();\n }\n\n return status;\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA0B,IAAAC,QAAA,GAAAD,OAAA;AAAA,IAAAE,aAAA,GAAAH,sBAAA,CAAAC,OAAA;AAAA,IAAAG,gBAAA,GAAAJ,sBAAA,CAAAC,OAAA;AAAA,SAAAD,uBAAAK,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAAA,IAOdG,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,0BAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAjBA,iBAAiB;EAAA,OAAjBA,iBAAiB;AAAA;AAAA,IAKjBE,MAAM,GAAAD,OAAA,CAAAC,MAAA,0BAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAANA,MAAM;EAAA,OAANA,MAAM;AAAA;AAuBlB,SAASC,WAAWA,CAACC,iBAAoC,EAAE;EACzD,IAAIA,iBAAiB,KAAKJ,iBAAiB,CAACK,OAAO,EAAE;IACnD,OAAO,8BAA8B;EACvC;EACA,IAAID,iBAAiB,KAAKJ,iBAAiB,CAACM,UAAU,EAAE;IACtD,OAAO,+BAA+B;EACxC;AACF;AAEA,SAASC,kBAAkBA,CACzBC,KAAa,EACbJ,iBAAoC,EAC5B;EACR,OAAOA,iBAAiB,CAACK,OAAO,CAAC,CAAC,GAAGD,KAAK;AAC5C;AAEA,MAAME,YAAY,GAAGC,qBAAiB,CAACC,QAAQ;AAC/C,MAAMC,iBAAiB,GAAGC,wBAAsB,CAACF,QAAQ;AAEzD,SAASG,eAAeA,CAACX,iBAAoC,EAAE;EAC7D,IAAIA,iBAAiB,KAAKJ,iBAAiB,CAACK,OAAO,EAAE;IACnD,OAAOK,YAAY;EACrB;EACA,IAAIN,iBA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-storage.js");
|
|
|
16
16
|
var _fetchPublishedJson = require("./fetch-published-json.js");
|
|
17
17
|
var _mapobjectsStore = _interopRequireDefault(require("../utils/mapobjects-store.js"));
|
|
18
18
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
19
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
20
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
21
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
22
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
23
|
+
function _toPrimitive(t, r) { if ("object" != typeof t || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
19
24
|
// Type for clicked features that includes both metaFeature data and raw click event
|
|
20
25
|
var SortType = /*#__PURE__*/function (SortType) {
|
|
21
26
|
SortType["Name"] = "Name";
|
|
@@ -31,21 +36,22 @@ let FilterType = exports.FilterType = /*#__PURE__*/function (FilterType) {
|
|
|
31
36
|
return FilterType;
|
|
32
37
|
}({});
|
|
33
38
|
class MetaAtlasCore {
|
|
34
|
-
defaultFocusedTaxonomy = 'where.changi';
|
|
35
|
-
searchableGeoJsonFeatures = [];
|
|
36
|
-
currentFocus = this.defaultFocusedTaxonomy;
|
|
37
|
-
// For ATOMS API
|
|
38
|
-
token = '';
|
|
39
|
-
empApi = '';
|
|
40
|
-
atomsAPIAccessToken = '';
|
|
41
|
-
apiRequestLimit = 5000;
|
|
42
|
-
|
|
43
|
-
// For Routing & Search
|
|
44
|
-
secretKeyForDecryption = '';
|
|
45
|
-
routingStatus = (() => _fetchPublishedJson.Status.Awaiting)();
|
|
46
|
-
searchStatus = (() => _fetchPublishedJson.Status.Awaiting)();
|
|
47
|
-
storage = (() => new _localStorage.LocalStorage())();
|
|
48
39
|
constructor() {
|
|
40
|
+
_defineProperty(this, "defaultFocusedTaxonomy", 'where.changi');
|
|
41
|
+
_defineProperty(this, "searchableGeoJsonFeatures", []);
|
|
42
|
+
_defineProperty(this, "currentFocus", this.defaultFocusedTaxonomy);
|
|
43
|
+
// For ATOMS API
|
|
44
|
+
_defineProperty(this, "token", '');
|
|
45
|
+
_defineProperty(this, "empApi", '');
|
|
46
|
+
_defineProperty(this, "atomsAPIAccessToken", '');
|
|
47
|
+
_defineProperty(this, "apiRequestLimit", 5000);
|
|
48
|
+
// For Routing & Search
|
|
49
|
+
_defineProperty(this, "secretKeyForDecryption", '');
|
|
50
|
+
_defineProperty(this, "routingStatus", _fetchPublishedJson.Status.Awaiting);
|
|
51
|
+
_defineProperty(this, "searchStatus", _fetchPublishedJson.Status.Awaiting);
|
|
52
|
+
_defineProperty(this, "storage", new _localStorage.LocalStorage());
|
|
53
|
+
_defineProperty(this, "ignoredLayers", ['Aerodrome', 'Aerodrome names', 'Aerobridge', 'Aerobridge gates', 'Airplanes', 'Airplanes outline', 'Building Extrusion', 'Building icon', 'Building overlay', 'Building overlay outline', 'Building underlay', 'Building underlay icon', 'Building underlay selected outline', 'building_outline', 'Changi Airport Connector', 'Changi Airport Connector Text', 'Changi Walkway Text', 'T2 overlay outline copy', 'Building overlay base', 'Skytrain track outdoor']);
|
|
54
|
+
_defineProperty(this, "nonFloorLayers", ['where.changi', 'where.changi.tarmac', 'where.changi.tarmac.public', 'where.changi.tarmac.private', 'where.changi.terminals', 'where.changi.terminals.jewel', 'where.changi.terminals.t1', 'where.changi.terminals.t2', 'where.changi.terminals.t3', 'where.changi.terminals.t4', 'where.hkcec.main_bldg', 'where.gbtb.flower_dome', 'where.lima', 'where.lima.mahsuri_center', 'where.lima.maritime', 'where.malaysia', 'where.malaysia.bcck', 'where.malaysia.rmh', 'where.malaysia.pm', 'where.indonesia.fairmont_jakarta']);
|
|
49
55
|
this.lastClicked = {
|
|
50
56
|
mapObjectId: null,
|
|
51
57
|
coordinates: null,
|
|
@@ -72,14 +78,15 @@ class MetaAtlasCore {
|
|
|
72
78
|
});
|
|
73
79
|
const config = {
|
|
74
80
|
method: 'post',
|
|
75
|
-
url:
|
|
81
|
+
url: "".concat(this.empApi, "/authentication"),
|
|
76
82
|
headers: {
|
|
77
83
|
'Content-Type': 'application/json'
|
|
78
84
|
},
|
|
79
85
|
data: data
|
|
80
86
|
};
|
|
81
87
|
(0, _axios.default)(config).then(async response => {
|
|
82
|
-
|
|
88
|
+
var _response$data;
|
|
89
|
+
if (response !== null && response !== void 0 && (_response$data = response.data) !== null && _response$data !== void 0 && _response$data.accessToken) {
|
|
83
90
|
this.atomsAPIAccessToken = response.data.accessToken;
|
|
84
91
|
onAuthenticationResponse({
|
|
85
92
|
authenticated: true
|
|
@@ -113,15 +120,13 @@ class MetaAtlasCore {
|
|
|
113
120
|
setLastClickedFeature(featureData) {
|
|
114
121
|
if (featureData.mapObjectId) {
|
|
115
122
|
this.getMapObjectById(featureData.mapObjectId, res => {
|
|
116
|
-
const mo = res
|
|
123
|
+
const mo = res === null || res === void 0 ? void 0 : res[0];
|
|
117
124
|
if (mo) {
|
|
118
|
-
this.lastClicked = {
|
|
119
|
-
|
|
120
|
-
properties: {
|
|
121
|
-
...featureData.properties,
|
|
125
|
+
this.lastClicked = _objectSpread(_objectSpread({}, featureData), {}, {
|
|
126
|
+
properties: _objectSpread(_objectSpread({}, featureData.properties), {}, {
|
|
122
127
|
booth_info: mo.properties.booth_info
|
|
123
|
-
}
|
|
124
|
-
};
|
|
128
|
+
})
|
|
129
|
+
});
|
|
125
130
|
}
|
|
126
131
|
});
|
|
127
132
|
} else {
|
|
@@ -246,8 +251,6 @@ class MetaAtlasCore {
|
|
|
246
251
|
let isViewingFloor = (0, _booleanPointInPolygon.default)(centerPoint, fBounds);
|
|
247
252
|
return isViewingBuilding || isViewingFloor;
|
|
248
253
|
}
|
|
249
|
-
ignoredLayers = ['Aerodrome', 'Aerodrome names', 'Aerobridge', 'Aerobridge gates', 'Airplanes', 'Airplanes outline', 'Building Extrusion', 'Building icon', 'Building overlay', 'Building overlay outline', 'Building underlay', 'Building underlay icon', 'Building underlay selected outline', 'building_outline', 'Changi Airport Connector', 'Changi Airport Connector Text', 'Changi Walkway Text', 'T2 overlay outline copy', 'Building overlay base', 'Skytrain track outdoor'];
|
|
250
|
-
nonFloorLayers = ['where.changi', 'where.changi.tarmac', 'where.changi.tarmac.public', 'where.changi.tarmac.private', 'where.changi.terminals', 'where.changi.terminals.jewel', 'where.changi.terminals.t1', 'where.changi.terminals.t2', 'where.changi.terminals.t3', 'where.changi.terminals.t4', 'where.hkcec.main_bldg', 'where.gbtb.flower_dome', 'where.lima', 'where.lima.mahsuri_center', 'where.lima.maritime', 'where.malaysia', 'where.malaysia.bcck', 'where.malaysia.rmh', 'where.malaysia.pm', 'where.indonesia.fairmont_jakarta'];
|
|
251
254
|
filterBaseMapWhereDimension(layersData, whereTaxonomyPath) {
|
|
252
255
|
let dimensionWhere = whereTaxonomyPath;
|
|
253
256
|
if (!dimensionWhere) {
|
|
@@ -1017,9 +1020,9 @@ class MetaAtlasCore {
|
|
|
1017
1020
|
let query = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
|
|
1018
1021
|
return new Promise((resolve, reject) => {
|
|
1019
1022
|
(0, _axios.default)({
|
|
1020
|
-
url:
|
|
1023
|
+
url: "".concat(this.empApi, "/map-objects").concat(query),
|
|
1021
1024
|
headers: {
|
|
1022
|
-
Authorization:
|
|
1025
|
+
Authorization: "Bearer ".concat(this.atomsAPIAccessToken)
|
|
1023
1026
|
},
|
|
1024
1027
|
method: 'get'
|
|
1025
1028
|
}).then(response => {
|
|
@@ -1032,8 +1035,8 @@ class MetaAtlasCore {
|
|
|
1032
1035
|
});
|
|
1033
1036
|
}
|
|
1034
1037
|
getMapObjectsByWhatTaxonomyAPI(whatTaxonomyPath, onResponseCallback) {
|
|
1035
|
-
let query =
|
|
1036
|
-
if (whatTaxonomyPath) query +=
|
|
1038
|
+
let query = "?$limit=".concat(this.apiRequestLimit);
|
|
1039
|
+
if (whatTaxonomyPath) query += "&taxonomy2Path=".concat(whatTaxonomyPath);
|
|
1037
1040
|
this.getMapObjectsApi(query).then(onResponseCallback).catch(onResponseCallback);
|
|
1038
1041
|
}
|
|
1039
1042
|
}
|