|
3 | 3 | - SPDX-License-Identifier: AGPL-3.0-or-later |
4 | 4 | --> |
5 | 5 |
|
| 6 | +<script setup lang="ts"> |
| 7 | +import { t } from '@nextcloud/l10n' |
| 8 | +import { imagePath } from '@nextcloud/router' |
| 9 | +import { |
| 10 | + LControlAttribution, |
| 11 | + LIcon, |
| 12 | + LMap, |
| 13 | + LMarker, |
| 14 | + LTileLayer, |
| 15 | +} from '@vue-leaflet/vue-leaflet' |
| 16 | +import { computed } from 'vue' |
| 17 | +
|
| 18 | +// Leaflet icon patch | re-uses images from ~leaflet package |
| 19 | +import 'leaflet/dist/leaflet.css' |
| 20 | +import 'leaflet-defaulticon-compatibility/dist/leaflet-defaulticon-compatibility.webpack.css' |
| 21 | +import 'leaflet-defaulticon-compatibility' |
| 22 | +
|
| 23 | +const props = withDefaults(defineProps<{ |
| 24 | + /** The latitude of the location */ |
| 25 | + latitude: string |
| 26 | + /** The longitude of the location */ |
| 27 | + longitude: string |
| 28 | + /** The name of the location */ |
| 29 | + name?: string |
| 30 | + /** The component appearance (take full width) */ |
| 31 | + wide?: boolean |
| 32 | +}>(), { |
| 33 | + name: '', |
| 34 | +}) |
| 35 | +
|
| 36 | +// {s} subdomains are used by ~leaflet package instead of the policy-preferred 'tile.openstreetmap.org' host |
| 37 | +const url = 'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png' |
| 38 | +// The zoom level of the map in the Talk app (chat, shared items tab) |
| 39 | +const previewZoom = 13 |
| 40 | +// The zoom level of the map in the new OpenStreetMap tab upon opening the link |
| 41 | +const linkZoom = 18 |
| 42 | +
|
| 43 | +// Map preview is non-interactive |
| 44 | +// Attribution control from ~leaflet package is replaced with LControlAttribution |
| 45 | +const mapOptions = { |
| 46 | + scrollWheelZoom: false, |
| 47 | + zoomControl: false, |
| 48 | + dragging: false, |
| 49 | + attributionControl: false, |
| 50 | +} |
| 51 | +// Visible attribution is required by the OpenStreetMap tile usage policy (https://operations.osmfoundation.org/policies/tiles/) |
| 52 | +const attribution = '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors' |
| 53 | +
|
| 54 | +// HTTP Referer header is required by the OpenStreetMap tile usage policy (https://operations.osmfoundation.org/policies/tiles/) |
| 55 | +const tileLayerOptions = { |
| 56 | + referrerPolicy: 'strict-origin-when-cross-origin', |
| 57 | +} |
| 58 | +
|
| 59 | +const linkAriaLabel = t('spreed', 'Open this location in OpenStreetMap') |
| 60 | +const iconUrl = imagePath('spreed', 'icon-marker-openstreetmap.svg') |
| 61 | +
|
| 62 | +const center = computed(() => [Number(props.latitude), Number(props.longitude)]) |
| 63 | +const mapLink = computed(() => 'https://www.openstreetmap.org/' |
| 64 | + + `?mlat=${props.latitude}` |
| 65 | + + `&mlon=${props.longitude}` |
| 66 | + + `#map=${linkZoom}/${props.latitude}/${props.longitude}`) |
| 67 | +</script> |
| 68 | + |
6 | 69 | <template> |
7 | 70 | <a |
8 | 71 | :href="mapLink" |
|
14 | 77 | <LMap |
15 | 78 | :zoom="previewZoom" |
16 | 79 | :center="center" |
17 | | - :options="{ |
18 | | - scrollWheelZoom: false, |
19 | | - zoomControl: false, |
20 | | - dragging: false, |
21 | | - attributionControl: false, |
22 | | - }" |
| 80 | + :options="mapOptions" |
23 | 81 | @scroll.prevent=""> |
24 | 82 | <LTileLayer |
25 | 83 | :url="url" |
|
0 commit comments