Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Alfakhori
Gengenbach
Commits
34cd7047
Commit
34cd7047
authored
Sep 21, 2026
by
Alfakhori
Browse files
center to prposed location
parent
136a3d4e
Changes
1
Hide whitespace changes
Inline
Side-by-side
public/ar_overviewmap.js
View file @
34cd7047
...
@@ -7,15 +7,34 @@ let modeMarkers = [];
...
@@ -7,15 +7,34 @@ let modeMarkers = [];
// ============================================================
// ============================================================
// Proposed plan overlay
// Proposed plan overlay
// ============================================================
// ============================================================
let
planOverlay
=
null
;
let
planOverlay
=
null
;
let
planVisible
=
false
;
let
planVisible
=
false
;
// Proposed plan geographic bounds
// DHDN / Gauss-Krüger Zone 3
// Converted to WGS84
//
// Southwest:
// Latitude = 48.405858385
// Longitude = 7.997080070
//
// Northeast:
// Latitude = 48.414966828
// Longitude = 8.010410216
const
planBounds
=
[
[
48.405858385
,
7.997080070
],
// Southwest / bottom-left
[
48.414966828
,
8.010410216
]
// Northeast / top-right
];
const
earthRadius
=
6378137
;
// Erdradius in Metern (WGS84)
const
earthRadius
=
6378137
;
// Erdradius in Metern (WGS84)
// ============================================================
// ============================================================
// Initialize map
// Initialize map
// ============================================================
// ============================================================
function
init_map
()
{
function
init_map
()
{
const
mapContainer
=
document
.
getElementById
(
"
map-container
"
);
const
mapContainer
=
document
.
getElementById
(
"
map-container
"
);
...
@@ -24,24 +43,29 @@ function init_map() {
...
@@ -24,24 +43,29 @@ function init_map() {
if
(
!
init
)
{
if
(
!
init
)
{
// ====================================================
// Create Leaflet map
// ====================================================
mymap
=
L
.
map
(
mapContainer
);
mymap
=
L
.
map
(
mapContainer
);
// ====================================================
// OpenStreetMap Germany basemap
// ====================================================
var
OpenStreetMap_DE
=
L
.
tileLayer
(
var
OpenStreetMap_DE
=
L
.
tileLayer
(
'
https://
{s}.
tile.openstreetmap.de/
tiles/osmde/
{z}/{x}/{y}.png
'
,
'
https://tile.openstreetmap.de/{z}/{x}/{y}.png
'
,
{
{
//
maxZoom:
3
0,
maxZoom
:
2
0
,
//minZoom: 15,
attribution
:
attribution
:
'
© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors
'
'
© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors
'
}
}
);
);
// Select one basemap from:
// https://leaflet-extras.github.io/leaflet-providers/preview/
OpenStreetMap_DE
.
addTo
(
mymap
);
OpenStreetMap_DE
.
addTo
(
mymap
);
// ====================================================
// ====================================================
// User icon
// User icon
// ====================================================
// ====================================================
...
@@ -57,18 +81,17 @@ function init_map() {
...
@@ -57,18 +81,17 @@ function init_map() {
// ====================================================
// ====================================================
// Initial map position
// Initial map position
// ====================================================
// ====================================================
//
// The map is centered on the proposed plan instead
// of the user's current GPS position.
//
// We use fitBounds() so the whole plan is visible.
//
mymap
.
fitBounds
(
planBounds
,
{
padding
:
[
20
,
20
]
});
//mymap.setView(
// [geoLocation.latitude, geoLocation.longitude],
// 20
//);
const
planBounds
=
[
[
48.405858385
,
7.997080070
],
// Southwest
[
48.414966828
,
8.010410216
]
// Northeast
];
mymap
.
fitBounds
(
planBounds
);
// ====================================================
// ====================================================
// User position marker
// User position marker
...
@@ -97,6 +120,10 @@ function init_map() {
...
@@ -97,6 +120,10 @@ function init_map() {
});
});
// Clear marker array
modeMarkers
=
[];
// ========================================================
// ========================================================
// Add currently placed models to map
// Add currently placed models to map
// ========================================================
// ========================================================
...
@@ -110,6 +137,7 @@ function init_map() {
...
@@ -110,6 +137,7 @@ function init_map() {
model
.
position
.
z
model
.
position
.
z
);
);
const
modelMarker
=
L
.
marker
(
const
modelMarker
=
L
.
marker
(
[
lat
,
lng
],
[
lat
,
lng
],
{
{
...
@@ -126,6 +154,7 @@ function init_map() {
...
@@ -126,6 +154,7 @@ function init_map() {
model
.
modelConfig
?.
name
||
"
Unbenannt
"
model
.
modelConfig
?.
name
||
"
Unbenannt
"
);
);
modeMarkers
.
push
(
modelMarker
);
modeMarkers
.
push
(
modelMarker
);
});
});
...
@@ -137,6 +166,17 @@ function init_map() {
...
@@ -137,6 +166,17 @@ function init_map() {
addPlanOverlay
();
addPlanOverlay
();
// ========================================================
// Make sure Leaflet knows the map container dimensions
// ========================================================
setTimeout
(()
=>
{
centerOnPlan
();
},
100
);
// ========================================================
// ========================================================
// Update map position continuously
// Update map position continuously
// ========================================================
// ========================================================
...
@@ -146,6 +186,40 @@ function init_map() {
...
@@ -146,6 +186,40 @@ function init_map() {
}
}
// ============================================================
// Center map on proposed plan
// ============================================================
function
centerOnPlan
()
{
if
(
!
mymap
)
{
console
.
error
(
"
Map ist noch nicht initialisiert.
"
);
return
;
}
// Tell Leaflet to recalculate the map container size.
// This is important because map-window may initially
// be hidden when the map is initialized.
mymap
.
invalidateSize
();
// Center and zoom the map on the proposed plan.
mymap
.
fitBounds
(
planBounds
,
{
padding
:
[
20
,
20
]
}
);
}
// ============================================================
// ============================================================
// Add georeferenced proposed plan
// Add georeferenced proposed plan
// ============================================================
// ============================================================
...
@@ -173,39 +247,36 @@ function init_map() {
...
@@ -173,39 +247,36 @@ function init_map() {
// Northeast:
// Northeast:
// Latitude = 48.414966828
// Latitude = 48.414966828
// Longitude = 8.010410216
// Longitude = 8.010410216
//
// Image:
//
// assets/plans/proposed-plan.png
// ============================================================
// ============================================================
function
addPlanOverlay
()
{
function
addPlanOverlay
()
{
if
(
!
mymap
)
{
if
(
!
mymap
)
{
console
.
error
(
"
Map ist noch nicht initialisiert.
"
);
return
;
}
// If the overlay already exists,
console
.
error
(
// simply make sure that it is visible.
"
Map ist noch nicht initialisiert.
"
if
(
planOverlay
)
{
);
planOverlay
.
addTo
(
mymap
);
planVisible
=
true
;
return
;
return
;
}
}
// ========================================================
// ========================================================
//
Geographic bounds of the plan
//
If overlay already exists, show it
// ========================================================
// ========================================================
const
planBounds
=
[
if
(
planOverlay
)
{
// Southwest / bottom-left
planOverlay
.
addTo
(
mymap
);
[
48.405858385
,
7.997080070
],
// Northeast / top-right
planVisible
=
true
;
[
48.414966828
,
8.010410216
]
];
return
;
}
// ========================================================
// ========================================================
...
@@ -214,14 +285,12 @@ function addPlanOverlay() {
...
@@ -214,14 +285,12 @@ function addPlanOverlay() {
planOverlay
=
L
.
imageOverlay
(
planOverlay
=
L
.
imageOverlay
(
'
assets/plans/proposed-plan.png
'
,
'
assets/plans/proposed-plan.png
'
,
planBounds
,
planBounds
,
{
{
// Transparency
of the plan
// Transparency
opacity
:
0.7
,
opacity
:
0.7
,
//
P
lan does not capture mouse/touch events
//
The p
lan does not capture mouse/touch events
interactive
:
false
interactive
:
false
}
}
);
);
...
@@ -249,6 +318,7 @@ function updateMap() {
...
@@ -249,6 +318,7 @@ function updateMap() {
)
{
)
{
clearInterval
(
intervalId
);
clearInterval
(
intervalId
);
intervalId
=
null
;
intervalId
=
null
;
return
;
return
;
...
@@ -259,6 +329,7 @@ function updateMap() {
...
@@ -259,6 +329,7 @@ function updateMap() {
const
userPosition
=
camera
.
getWorldPosition
(
vec
);
const
userPosition
=
camera
.
getWorldPosition
(
vec
);
const
{
lat
,
lng
}
=
threeToLeaflet
(
const
{
lat
,
lng
}
=
threeToLeaflet
(
userPosition
.
x
,
userPosition
.
x
,
userPosition
.
z
userPosition
.
z
...
@@ -305,7 +376,9 @@ function threeToLeaflet(threeX, threeZ) {
...
@@ -305,7 +376,9 @@ function threeToLeaflet(threeX, threeZ) {
threeX
/
threeX
/
(
(
earthRadius
*
earthRadius
*
Math
.
cos
(
Math
.
PI
*
originLat
/
180
)
Math
.
cos
(
Math
.
PI
*
originLat
/
180
)
)
)
)
*
)
*
(
180
/
Math
.
PI
);
(
180
/
Math
.
PI
);
...
@@ -364,7 +437,9 @@ function leafletToThree(lat, lng) {
...
@@ -364,7 +437,9 @@ function leafletToThree(lat, lng) {
deltaLng
*
deltaLng
*
(
Math
.
PI
/
180
)
*
(
Math
.
PI
/
180
)
*
earthRadius
*
earthRadius
*
Math
.
cos
(
Math
.
PI
*
originLat
/
180
);
Math
.
cos
(
Math
.
PI
*
originLat
/
180
);
return
{
return
{
...
@@ -384,6 +459,7 @@ function roundTo(n, digits) {
...
@@ -384,6 +459,7 @@ function roundTo(n, digits) {
if
(
digits
===
undefined
)
{
if
(
digits
===
undefined
)
{
digits
=
0
;
digits
=
0
;
}
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment