Nachrichten Popup und Positionsmarker im mobilen View
This commit is contained in:
1 parent
6e24c79008
commit
18278fdf43
4 files changed
+197
-35
No files matched your search
@@ -454,6 +454,8 @@ html[data-theme="dark"] .mobile-chat-card.own {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.mobile-user-dot {
|
.mobile-user-dot {
|
||||||
|
position: relative;
|
||||||
|
z-index: 2;
|
||||||
width: 16px;
|
width: 16px;
|
||||||
height: 16px;
|
height: 16px;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
@@ -462,32 +464,39 @@ html[data-theme="dark"] .mobile-chat-card.own {
|
|||||||
box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.4);
|
box-shadow: 0 0 0 2px rgba(37, 99, 235, 0.4);
|
||||||
}
|
}
|
||||||
|
|
||||||
.mobile-user-arrow {
|
.mobile-user-heading {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
left: 50%;
|
left: 50%;
|
||||||
top: 50%;
|
top: 50%;
|
||||||
width: 0;
|
z-index: 1;
|
||||||
height: 0;
|
width: 2px;
|
||||||
border-left: 6px solid transparent;
|
height: 20px;
|
||||||
border-right: 6px solid transparent;
|
border-radius: 999px;
|
||||||
border-bottom: 14px solid #2563eb;
|
background: #2563eb;
|
||||||
|
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.85);
|
||||||
transform-origin: 50% 100%;
|
transform-origin: 50% 100%;
|
||||||
transform: translate(-50%, -100%) rotate(0deg);
|
transform: translate(-50%, -100%) rotate(0deg);
|
||||||
|
pointer-events: none;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mobile-group-marker {
|
.mobile-group-marker {
|
||||||
position: relative;
|
position: relative;
|
||||||
width: 14px;
|
width: 32px;
|
||||||
height: 14px;
|
height: 32px;
|
||||||
|
cursor: pointer;
|
||||||
}
|
}
|
||||||
|
|
||||||
.mobile-group-dot {
|
.mobile-group-dot {
|
||||||
|
position: absolute;
|
||||||
|
left: 50%;
|
||||||
|
top: 50%;
|
||||||
width: 14px;
|
width: 14px;
|
||||||
height: 14px;
|
height: 14px;
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
background: var(--marker-color);
|
background: var(--marker-color);
|
||||||
border: 2px solid #fff;
|
border: 2px solid #fff;
|
||||||
box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.4);
|
box-shadow: 0 0 0 1px rgba(15, 23, 42, 0.4);
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
}
|
}
|
||||||
|
|
||||||
@media (max-width: 420px) {
|
@media (max-width: 420px) {
|
||||||
|
|||||||
@@ -5,7 +5,7 @@
|
|||||||
* damit er sowohl die mobilen Views als auch die statischen Assets
|
* damit er sowohl die mobilen Views als auch die statischen Assets
|
||||||
* kontrolliert. Der Cache-Name wird pro App-Wurzel gebildet.
|
* kontrolliert. Der Cache-Name wird pro App-Wurzel gebildet.
|
||||||
*/
|
*/
|
||||||
const VERSION = 'cmbnet-pwa-v17';
|
const VERSION = 'cmbnet-pwa-v18';
|
||||||
const BASE = new URL('./', self.location).href;
|
const BASE = new URL('./', self.location).href;
|
||||||
const SHELL_CACHE = `${VERSION}-shell`;
|
const SHELL_CACHE = `${VERSION}-shell`;
|
||||||
const TILE_CACHE = `${VERSION}-tiles`;
|
const TILE_CACHE = `${VERSION}-tiles`;
|
||||||
|
|||||||
@@ -2539,11 +2539,13 @@ function openChat(groupId) {
|
|||||||
dispatcherState.chatGroupId = Number(groupId);
|
dispatcherState.chatGroupId = Number(groupId);
|
||||||
renderChat();
|
renderChat();
|
||||||
const dialog = document.getElementById('chatModal');
|
const dialog = document.getElementById('chatModal');
|
||||||
if (dialog && typeof dialog.showModal === 'function') {
|
if (dialog && !dialog.open) {
|
||||||
|
if (typeof dialog.showModal === 'function') {
|
||||||
dialog.showModal();
|
dialog.showModal();
|
||||||
} else if (dialog) {
|
} else {
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
const container = document.getElementById('chatMessages');
|
const container = document.getElementById('chatMessages');
|
||||||
if (container) {
|
if (container) {
|
||||||
container.scrollTop = container.scrollHeight;
|
container.scrollTop = container.scrollHeight;
|
||||||
@@ -2850,11 +2852,13 @@ function showInfoMessage(message) {
|
|||||||
|
|
||||||
renderInfoMessages();
|
renderInfoMessages();
|
||||||
|
|
||||||
|
if (!dialog.open) {
|
||||||
if (typeof dialog.showModal === 'function') {
|
if (typeof dialog.showModal === 'function') {
|
||||||
dialog.showModal();
|
dialog.showModal();
|
||||||
} else {
|
} else {
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
const container = document.getElementById('infoMessages');
|
const container = document.getElementById('infoMessages');
|
||||||
if (container) {
|
if (container) {
|
||||||
container.scrollTop = container.scrollHeight;
|
container.scrollTop = container.scrollHeight;
|
||||||
@@ -2948,7 +2952,12 @@ function handleGroupChatMessage(message) {
|
|||||||
const payload = parsePayload(message.msg) || {};
|
const payload = parsePayload(message.msg) || {};
|
||||||
const groupId = Number(payload.group_id ?? message.receiver_id);
|
const groupId = Number(payload.group_id ?? message.receiver_id);
|
||||||
const group = dispatcherState.groupById.get(groupId);
|
const group = dispatcherState.groupById.get(groupId);
|
||||||
if (!group) return;
|
if (!group) {
|
||||||
|
if (Number(message.sender_id) !== currentAccountId) {
|
||||||
|
showInfoMessage(message);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const text = extractMessageText(payload.text ?? payload.msg ?? '');
|
const text = extractMessageText(payload.text ?? payload.msg ?? '');
|
||||||
|
|
||||||
@@ -2963,6 +2972,11 @@ function handleGroupChatMessage(message) {
|
|||||||
ts: normalizeTimestamp(message.ts) || Date.now(),
|
ts: normalizeTimestamp(message.ts) || Date.now(),
|
||||||
text
|
text
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if (Number(message.sender_id) !== currentAccountId) {
|
||||||
|
playNotificationSound();
|
||||||
|
openChat(group.id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ------------------------------------------------------------------ */
|
/* ------------------------------------------------------------------ */
|
||||||
@@ -3160,8 +3174,9 @@ function handleWsMessage(event) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 1100: {
|
case 1100: {
|
||||||
const groupId = Number(message.receiver_id) || Number((message.msg && typeof message.msg === 'object' && message.msg.group_id));
|
const payload = parsePayload(message.msg) || {};
|
||||||
const text = extractMessageText(message.msg);
|
const groupId = Number(message.receiver_id) || Number(payload.group_id);
|
||||||
|
const text = extractMessageText(payload.text ?? message.msg);
|
||||||
if (window.CMBNET_VIEW_MODE !== 'observer') {
|
if (window.CMBNET_VIEW_MODE !== 'observer') {
|
||||||
if (groupId) {
|
if (groupId) {
|
||||||
addChatMessage(groupId, {
|
addChatMessage(groupId, {
|
||||||
@@ -3181,14 +3196,19 @@ function handleWsMessage(event) {
|
|||||||
ts: message.ts
|
ts: message.ts
|
||||||
});
|
});
|
||||||
} else if (Number(message.sender_id) !== currentAccountId) {
|
} else if (Number(message.sender_id) !== currentAccountId) {
|
||||||
|
playNotificationSound();
|
||||||
|
if (groupId) {
|
||||||
|
openChat(groupId);
|
||||||
|
} else {
|
||||||
showInfoMessage({
|
showInfoMessage({
|
||||||
code: message.code,
|
code: message.code,
|
||||||
sender_id: message.sender_id,
|
sender_id: message.sender_id,
|
||||||
receiver_id: groupId || message.receiver_id,
|
receiver_id: message.receiver_id,
|
||||||
msg: text,
|
msg: text,
|
||||||
ts: message.ts
|
ts: message.ts
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2000:
|
case 2000:
|
||||||
|
|||||||
@@ -52,7 +52,15 @@ const state = {
|
|||||||
chatMessages: [],
|
chatMessages: [],
|
||||||
chatKeys: new Set(),
|
chatKeys: new Set(),
|
||||||
userMarker: null,
|
userMarker: null,
|
||||||
userArrow: null,
|
userHeadingLine: null,
|
||||||
|
userHeading: null,
|
||||||
|
lastCompassHeading: null,
|
||||||
|
lastCompassAt: 0,
|
||||||
|
absoluteCompassAvailable: false,
|
||||||
|
lastGpsHeading: null,
|
||||||
|
lastGpsAt: 0,
|
||||||
|
orientationListenersBound: false,
|
||||||
|
orientationPermissionRequested: false,
|
||||||
watchId: null,
|
watchId: null,
|
||||||
positionSendTimerId: null,
|
positionSendTimerId: null,
|
||||||
navigationTimerId: null,
|
navigationTimerId: null,
|
||||||
@@ -426,11 +434,13 @@ function sendPositionNow() {
|
|||||||
navigator.geolocation.getCurrentPosition((position) => {
|
navigator.geolocation.getCurrentPosition((position) => {
|
||||||
const lat = Number(position.coords.latitude);
|
const lat = Number(position.coords.latitude);
|
||||||
const lon = Number(position.coords.longitude);
|
const lon = Number(position.coords.longitude);
|
||||||
|
const previous = state.lastKnownPosition;
|
||||||
state.lastKnownPosition = {
|
state.lastKnownPosition = {
|
||||||
lat,
|
lat,
|
||||||
lon,
|
lon,
|
||||||
accuracy: position.coords.accuracy
|
accuracy: position.coords.accuracy
|
||||||
};
|
};
|
||||||
|
updateHeadingFromGps(position, previous);
|
||||||
updateOwnPositionMarker(lat, lon);
|
updateOwnPositionMarker(lat, lon);
|
||||||
|
|
||||||
const sent = sendOwnPosition(lat, lon, false);
|
const sent = sendOwnPosition(lat, lon, false);
|
||||||
@@ -1031,27 +1041,31 @@ function startGeolocation() {
|
|||||||
map.removeLayer(state.userMarker);
|
map.removeLayer(state.userMarker);
|
||||||
state.userMarker = null;
|
state.userMarker = null;
|
||||||
}
|
}
|
||||||
if (state.userArrow) {
|
state.userHeadingLine = null;
|
||||||
map.removeLayer(state.userArrow);
|
|
||||||
state.userArrow = null;
|
|
||||||
}
|
|
||||||
const icon = L.divIcon({
|
const icon = L.divIcon({
|
||||||
className: 'mobile-user-marker',
|
className: 'mobile-user-marker',
|
||||||
html: '<div class="mobile-user-dot"></div><div class="mobile-user-arrow" id="mobileUserArrow"></div>',
|
html: '<div class="mobile-user-heading" id="mobileUserHeading" hidden></div><div class="mobile-user-dot"></div>',
|
||||||
iconSize: [16, 16],
|
iconSize: [16, 16],
|
||||||
iconAnchor: [8, 8]
|
iconAnchor: [8, 8]
|
||||||
});
|
});
|
||||||
state.userMarker = L.marker(map.getCenter(), {icon, interactive: false}).addTo(map);
|
state.userMarker = L.marker(map.getCenter(), {icon, interactive: false}).addTo(map);
|
||||||
state.userArrow = document.getElementById('mobileUserArrow');
|
state.userHeadingLine = document.getElementById('mobileUserHeading');
|
||||||
|
applyUserHeading(state.userHeading);
|
||||||
|
|
||||||
state.watchId = navigator.geolocation.watchPosition((pos) => {
|
state.watchId = navigator.geolocation.watchPosition((pos) => {
|
||||||
const lat = Number(pos.coords.latitude);
|
const lat = Number(pos.coords.latitude);
|
||||||
const lon = Number(pos.coords.longitude);
|
const lon = Number(pos.coords.longitude);
|
||||||
|
if (!Number.isFinite(lat) || !Number.isFinite(lon)) return;
|
||||||
|
|
||||||
|
const previous = state.lastKnownPosition;
|
||||||
state.lastKnownPosition = {
|
state.lastKnownPosition = {
|
||||||
lat,
|
lat,
|
||||||
lon,
|
lon,
|
||||||
accuracy: pos.coords.accuracy
|
accuracy: pos.coords.accuracy
|
||||||
};
|
};
|
||||||
|
|
||||||
|
updateHeadingFromGps(pos, previous);
|
||||||
updateOwnPositionMarker(lat, lon);
|
updateOwnPositionMarker(lat, lon);
|
||||||
|
|
||||||
if (viewMode === 'mobile_group') {
|
if (viewMode === 'mobile_group') {
|
||||||
@@ -1070,20 +1084,122 @@ function startGeolocation() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (window.DeviceOrientationEvent) {
|
setupDeviceOrientation();
|
||||||
window.addEventListener('deviceorientationabsolute', handleOrientation, true);
|
}
|
||||||
window.addEventListener('deviceorientation', handleOrientation, true);
|
|
||||||
|
function normalizeHeading(value) {
|
||||||
|
if (value === null || value === undefined || value === '') return null;
|
||||||
|
const heading = Number(value);
|
||||||
|
if (!Number.isFinite(heading)) return null;
|
||||||
|
return ((heading % 360) + 360) % 360;
|
||||||
|
}
|
||||||
|
|
||||||
|
function applyUserHeading(heading) {
|
||||||
|
const normalized = normalizeHeading(heading);
|
||||||
|
if (normalized === null) return;
|
||||||
|
|
||||||
|
state.userHeading = normalized;
|
||||||
|
const line = state.userHeadingLine;
|
||||||
|
if (!line) return;
|
||||||
|
|
||||||
|
line.hidden = false;
|
||||||
|
line.style.transform = `translate(-50%, -100%) rotate(${normalized}deg)`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function bearingBetween(from, to) {
|
||||||
|
if (!from || !to) return null;
|
||||||
|
const lat1 = Number(from.lat);
|
||||||
|
const lon1 = Number(from.lon);
|
||||||
|
const lat2 = Number(to.lat);
|
||||||
|
const lon2 = Number(to.lon);
|
||||||
|
if (![lat1, lon1, lat2, lon2].every(Number.isFinite)) return null;
|
||||||
|
|
||||||
|
const toRad = (value) => value * Math.PI / 180;
|
||||||
|
const y = Math.sin(toRad(lon2 - lon1)) * Math.cos(toRad(lat2));
|
||||||
|
const x = Math.cos(toRad(lat1)) * Math.sin(toRad(lat2))
|
||||||
|
- Math.sin(toRad(lat1)) * Math.cos(toRad(lat2)) * Math.cos(toRad(lon2 - lon1));
|
||||||
|
return normalizeHeading(Math.atan2(y, x) * 180 / Math.PI);
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateHeadingFromGps(position, previous) {
|
||||||
|
const coords = position && position.coords;
|
||||||
|
if (!coords) return;
|
||||||
|
|
||||||
|
let heading = normalizeHeading(coords.heading);
|
||||||
|
if (heading === null && previous && state.lastKnownPosition) {
|
||||||
|
const moved = L.latLng(previous.lat, previous.lon)
|
||||||
|
.distanceTo(L.latLng(state.lastKnownPosition.lat, state.lastKnownPosition.lon));
|
||||||
|
if (moved >= 3) {
|
||||||
|
heading = bearingBetween(previous, state.lastKnownPosition);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (heading === null) return;
|
||||||
|
|
||||||
|
state.lastGpsHeading = heading;
|
||||||
|
state.lastGpsAt = Date.now();
|
||||||
|
|
||||||
|
// Der Kompass hat Vorrang. GPS dient als Rückfallebene, solange keine
|
||||||
|
// aktuelle Kompassrichtung vorliegt (z. B. ohne Sensorfreigabe).
|
||||||
|
if (Date.now() - state.lastCompassAt > 10000) {
|
||||||
|
applyUserHeading(heading);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function handleOrientation(e) {
|
function handleOrientation(event) {
|
||||||
let heading = e.alpha;
|
const hasCompassHeading = typeof event.webkitCompassHeading === 'number'
|
||||||
if (typeof e.webkitCompassHeading === 'number') {
|
&& Number.isFinite(event.webkitCompassHeading);
|
||||||
heading = e.webkitCompassHeading;
|
const isAbsolute = hasCompassHeading
|
||||||
|
|| event.type === 'deviceorientationabsolute'
|
||||||
|
|| event.absolute === true;
|
||||||
|
|
||||||
|
let heading = null;
|
||||||
|
if (hasCompassHeading) {
|
||||||
|
heading = event.webkitCompassHeading;
|
||||||
|
} else if (typeof event.alpha === 'number'
|
||||||
|
&& Number.isFinite(event.alpha)
|
||||||
|
&& (isAbsolute || !state.absoluteCompassAvailable)) {
|
||||||
|
// DeviceOrientationEvent.alpha dreht gegen den Uhrzeigersinn.
|
||||||
|
// Relative Werte dienen nur als Rückfall, solange keine absolute
|
||||||
|
// Kompassrichtung verfügbar ist.
|
||||||
|
heading = 360 - event.alpha;
|
||||||
}
|
}
|
||||||
if (typeof heading !== 'number' || isNaN(heading)) return;
|
|
||||||
if (state.userArrow) {
|
const normalized = normalizeHeading(heading);
|
||||||
state.userArrow.style.transform = `translate(-50%, -100%) rotate(${heading}deg)`;
|
if (normalized === null) return;
|
||||||
|
|
||||||
|
if (isAbsolute) state.absoluteCompassAvailable = true;
|
||||||
|
state.lastCompassHeading = normalized;
|
||||||
|
state.lastCompassAt = Date.now();
|
||||||
|
applyUserHeading(normalized);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupDeviceOrientation() {
|
||||||
|
if (!window.DeviceOrientationEvent || state.orientationListenersBound) return;
|
||||||
|
|
||||||
|
const addListeners = () => {
|
||||||
|
if (state.orientationListenersBound) return;
|
||||||
|
window.addEventListener('deviceorientationabsolute', handleOrientation, true);
|
||||||
|
window.addEventListener('deviceorientation', handleOrientation, true);
|
||||||
|
state.orientationListenersBound = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (typeof DeviceOrientationEvent.requestPermission === 'function') {
|
||||||
|
// iOS verlangt die Freigabe aus einer Nutzergeste. Die erste Berührung
|
||||||
|
// der Karte bzw. Seite wird dafür verwendet.
|
||||||
|
const requestPermission = () => {
|
||||||
|
if (state.orientationPermissionRequested) return;
|
||||||
|
state.orientationPermissionRequested = true;
|
||||||
|
DeviceOrientationEvent.requestPermission()
|
||||||
|
.then((result) => {
|
||||||
|
if (result === 'granted') addListeners();
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
console.warn('Kompassfreigabe nicht erteilt.', error);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
document.addEventListener('pointerdown', requestPermission, {once: true, passive: true});
|
||||||
|
} else {
|
||||||
|
addListeners();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1100,11 +1216,13 @@ function showAllGroupPositions() {
|
|||||||
const icon = L.divIcon({
|
const icon = L.divIcon({
|
||||||
className: 'mobile-group-marker',
|
className: 'mobile-group-marker',
|
||||||
html: `<div class="mobile-group-dot" style="--marker-color:${color}"></div>`,
|
html: `<div class="mobile-group-dot" style="--marker-color:${color}"></div>`,
|
||||||
iconSize: [14, 14],
|
iconSize: [32, 32],
|
||||||
iconAnchor: [7, 7]
|
iconAnchor: [16, 16]
|
||||||
});
|
});
|
||||||
const marker = L.marker([lat, lon], {icon}).addTo(map);
|
const marker = L.marker([lat, lon], {icon}).addTo(map);
|
||||||
marker.bindTooltip(group.aliasname || String(group.id));
|
if (viewMode === 'mobile_dispatcher') {
|
||||||
|
marker.on('click', () => focusGroupFromMarker(group.id));
|
||||||
|
}
|
||||||
state.groupMarkers.set(group.id, marker);
|
state.groupMarkers.set(group.id, marker);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1112,6 +1230,21 @@ function showAllGroupPositions() {
|
|||||||
updateNavigationButton();
|
updateNavigationButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function focusGroupFromMarker(groupId) {
|
||||||
|
if (viewMode !== 'mobile_dispatcher') return;
|
||||||
|
|
||||||
|
const group = state.groupById.get(Number(groupId));
|
||||||
|
if (!group) return;
|
||||||
|
|
||||||
|
if (Number(state.currentGroupId) !== Number(group.id)) {
|
||||||
|
await loadGroupData(group.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
const coordinates = getGroupCoordinates(group);
|
||||||
|
if (!coordinates) return;
|
||||||
|
map.setView([coordinates.lat, coordinates.lon], Math.max(map.getZoom(), 15));
|
||||||
|
}
|
||||||
|
|
||||||
function getGroupColor(id) {
|
function getGroupColor(id) {
|
||||||
const hue = Math.round((Number(id) * 137.508) % 360);
|
const hue = Math.round((Number(id) * 137.508) % 360);
|
||||||
return `hsl(${hue}, 72%, 45%)`;
|
return `hsl(${hue}, 72%, 45%)`;
|
||||||
|
|||||||
Reference in new issue
Block a user