Allow opening a map view in OpenStreetMap (#7428)
This commit is contained in:
parent
38634f86d1
commit
a239c456e3
7 changed files with 143 additions and 2 deletions
|
@ -18,6 +18,7 @@ import React from 'react';
|
|||
import maplibregl from 'maplibre-gl';
|
||||
import { logger } from "matrix-js-sdk/src/logger";
|
||||
import { LOCATION_EVENT_TYPE } from 'matrix-js-sdk/src/@types/location';
|
||||
import { MatrixEvent } from 'matrix-js-sdk/src/models/event';
|
||||
|
||||
import SdkConfig from '../../../SdkConfig';
|
||||
import { replaceableComponent } from "../../../utils/replaceableComponent";
|
||||
|
@ -147,3 +148,29 @@ export function parseGeoUri(uri: string): GeolocationCoordinates {
|
|||
speed: undefined,
|
||||
};
|
||||
}
|
||||
|
||||
function makeLink(coords: GeolocationCoordinates): string {
|
||||
return (
|
||||
"https://www.openstreetmap.org/" +
|
||||
`?mlat=${coords.latitude}` +
|
||||
`&mlon=${coords.longitude}` +
|
||||
`#map=16/${coords.latitude}/${coords.longitude}`
|
||||
);
|
||||
}
|
||||
|
||||
export function createMapSiteLink(event: MatrixEvent): string {
|
||||
const content: Object = event.getContent();
|
||||
const mLocation = content[LOCATION_EVENT_TYPE.name];
|
||||
if (mLocation !== undefined) {
|
||||
const uri = mLocation["uri"];
|
||||
if (uri !== undefined) {
|
||||
return makeLink(parseGeoUri(uri));
|
||||
}
|
||||
} else {
|
||||
const geoUri = content["geo_uri"];
|
||||
if (geoUri) {
|
||||
return makeLink(parseGeoUri(geoUri));
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue