-
Notifications
You must be signed in to change notification settings - Fork 0
13 minimap #42
Merged
+157
−1
Merged
13 minimap #42
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| /** | ||
| * Initializes the Potree minimap to work with offline map and EPSG:4978 coordinates. | ||
| * | ||
| * @param {Potree.Viewer} viewer - The Potree viewer instance | ||
| */ | ||
| export function initMiniMap(viewer) { | ||
| if (!viewer.mapView) return | ||
| const map = viewer.mapView.map | ||
| const layers = map.getLayers() | ||
|
|
||
| replaceMiniMapLayers(layers) | ||
|
|
||
| removeTileTools(map) | ||
|
|
||
| overrideMapViewUpdate(viewer) | ||
|
|
||
| // Transform minimap center [lon, lat] from EPSG:4326 to EPSG:3857 | ||
| const center = proj4('EPSG:4326', 'EPSG:3857', [2, 69]) | ||
| map.getView().setCenter(center) | ||
| } | ||
|
|
||
| /** | ||
| * Replaces default Open Street Map layer with custom GeoJSON in order for it to work offline. | ||
| * Also removes the extent layer. | ||
| * | ||
| * @param {ol.Collection} layers - Collection of OpenLayers layers | ||
| */ | ||
| function replaceMiniMapLayers(layers) { | ||
| // Remove the old Open Street Map layer | ||
| const oldOSMLayer = layers.item(0) | ||
| layers.remove(oldOSMLayer) | ||
|
|
||
| // Add new offline GeoJSON layer | ||
| const newGeojsonLayer = new ol.layer.Vector({ | ||
| source: new ol.source.Vector({ | ||
| url: '/data/geo/world_simplified.geojson', | ||
| format: new ol.format.GeoJSON() | ||
| }) | ||
| }) | ||
| layers.insertAt(0, newGeojsonLayer) | ||
|
|
||
| // Remove the extent layer | ||
| const extentLayer = layers.item(6) | ||
| layers.remove(extentLayer) | ||
| } | ||
|
|
||
| /** | ||
| * Removes the tools for downloading and showing/hiding tiles, denoted D and T in the minimap. | ||
| * | ||
| * @param {ol.Map} map - The OpenLayers map instance | ||
| */ | ||
| function removeTileTools(map) { | ||
| map.getControls().forEach((control) => { | ||
| if ( | ||
| control.constructor && | ||
| control.constructor.name === 'DownloadSelectionControl' | ||
| ) { | ||
| map.removeControl(control) | ||
| } | ||
| }) | ||
| } | ||
|
|
||
| /** | ||
| * Overrides the minimap pointer update logic to use 3D coordinates and correct direction. | ||
| * | ||
| * @param {Potree.Viewer} viewer - The Potree viewer instance | ||
| */ | ||
| function overrideMapViewUpdate(viewer) { | ||
| const Vector3 = THREE.Vector3 | ||
| const Vector2 = THREE.Vector2 | ||
| viewer.mapView.update = function (delta) { | ||
| if (!this.sceneProjection) { | ||
| return | ||
| } | ||
|
|
||
| let pm = $('#potree_map') | ||
|
|
||
| if (!this.enabled) { | ||
| return | ||
| } | ||
|
|
||
| let mapSize = this.map.getSize() | ||
| let resized = pm.width() !== mapSize[0] || pm.height() !== mapSize[1] | ||
| if (resized) { | ||
| this.map.updateSize() | ||
| } | ||
|
|
||
| let camera = this.viewer.scene.getActiveCamera() | ||
|
|
||
| let scale = this.map.getView().getResolution() | ||
| let campos = camera.position | ||
| let camdir = camera.getWorldDirection(new Vector3()) | ||
| let sceneLookAt = camdir | ||
| .clone() | ||
| .multiplyScalar(30 * scale) | ||
| .add(campos) | ||
| let geoPos = camera.position | ||
| let geoLookAt = sceneLookAt | ||
|
|
||
| // Include z-coordinate to handle EPSG:4978 properly | ||
| let mapPos = new Vector2().fromArray( | ||
| this.toMap.forward([geoPos.x, geoPos.y, geoPos.z]) | ||
| ) | ||
| let mapLookAt = new Vector2().fromArray( | ||
| this.toMap.forward([geoLookAt.x, geoLookAt.y, geoLookAt.z]) | ||
| ) | ||
|
|
||
| // Reverse direction so pointer faces correct way | ||
| let mapDir = new Vector2().subVectors(mapPos, mapLookAt).normalize() | ||
|
|
||
| mapLookAt = mapPos.clone().add(mapDir.clone().multiplyScalar(30 * scale)) | ||
| let mapLength = mapPos.distanceTo(mapLookAt) | ||
| let mapSide = new Vector2(-mapDir.y, mapDir.x) | ||
|
|
||
| let p1 = mapPos.toArray() | ||
| let p2 = mapLookAt | ||
| .clone() | ||
| .sub(mapSide.clone().multiplyScalar(0.3 * mapLength)) | ||
| .toArray() | ||
| let p3 = mapLookAt | ||
| .clone() | ||
| .add(mapSide.clone().multiplyScalar(0.3 * mapLength)) | ||
| .toArray() | ||
|
|
||
| this.gCamera.setCoordinates([p1, p2, p3, p1]) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.