2023-09-12 09:15:28 +00:00
|
|
|
|
<script setup lang="ts">
|
|
|
|
|
import { renderOsmTag } from "facilmap-utils";
|
2023-11-02 14:14:05 +00:00
|
|
|
|
import type { Point, SearchResult } from "facilmap-types";
|
2023-11-01 18:45:16 +00:00
|
|
|
|
import Icon from "./ui/icon.vue";
|
2023-11-02 14:14:05 +00:00
|
|
|
|
import type { FileResult } from "../utils/files";
|
2023-11-01 18:45:16 +00:00
|
|
|
|
import { isLineResult, isMarkerResult } from "../utils/search";
|
|
|
|
|
import { flyTo, getZoomDestinationForSearchResult } from "../utils/zoom";
|
|
|
|
|
import Coordinates from "./ui/coordinates.vue";
|
2023-10-25 02:09:33 +00:00
|
|
|
|
import vTooltip from "../utils/tooltip";
|
2023-11-01 18:45:16 +00:00
|
|
|
|
import { computed } from "vue";
|
|
|
|
|
import { injectContextRequired } from "../utils/context";
|
|
|
|
|
import { injectClientRequired } from "./client-context.vue";
|
|
|
|
|
import { injectMapContextRequired } from "./leaflet-map/leaflet-map.vue";
|
|
|
|
|
|
|
|
|
|
const context = injectContextRequired();
|
|
|
|
|
const client = injectClientRequired();
|
|
|
|
|
const mapContext = injectMapContextRequired();
|
|
|
|
|
|
|
|
|
|
const props = withDefaults(defineProps<{
|
|
|
|
|
result: SearchResult | FileResult;
|
|
|
|
|
showBackButton?: boolean;
|
|
|
|
|
isAdding?: boolean;
|
|
|
|
|
}>(), {
|
|
|
|
|
showBackButton: false,
|
|
|
|
|
isAdding: false
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const isMarker = computed(() => isMarkerResult(props.result));
|
|
|
|
|
|
|
|
|
|
const isLine = computed(() => isLineResult(props.result));
|
|
|
|
|
|
|
|
|
|
const types = computed(() => {
|
|
|
|
|
// Result can be both marker and line
|
|
|
|
|
return Object.values(client.types).filter((type) => (isMarker.value && type.type == "marker") || (isLine.value && type.type == "line"));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
function zoomToResult(): void {
|
|
|
|
|
const dest = getZoomDestinationForSearchResult(props.result);
|
|
|
|
|
if (dest)
|
|
|
|
|
flyTo(mapContext.components.map, dest);
|
2023-09-12 09:15:28 +00:00
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<template>
|
|
|
|
|
<div class="fm-search-result-info" v-if="result">
|
|
|
|
|
<h2>
|
|
|
|
|
<a v-if="showBackButton" href="javascript:" @click="$emit('back')"><Icon icon="arrow-left"></Icon></a>
|
|
|
|
|
{{result.short_name}}
|
|
|
|
|
</h2>
|
|
|
|
|
<dl class="fm-search-box-collapse-point">
|
2023-11-01 18:45:16 +00:00
|
|
|
|
<template v-if="result.type">
|
|
|
|
|
<dt>Type</dt>
|
|
|
|
|
<dd>{{result.type}}</dd>
|
|
|
|
|
</template>
|
2023-09-12 09:15:28 +00:00
|
|
|
|
|
2023-11-01 18:45:16 +00:00
|
|
|
|
<template v-if="result.address">
|
|
|
|
|
<dt>Address</dt>
|
|
|
|
|
<dd>{{result.address}}</dd>
|
|
|
|
|
</template>
|
2023-09-12 09:15:28 +00:00
|
|
|
|
|
2023-11-01 18:45:16 +00:00
|
|
|
|
<template v-if="result.type != 'coordinates' && result.lat != null && result.lon != null">
|
|
|
|
|
<dt>Coordinates</dt>
|
|
|
|
|
<dd><Coordinates :point="result as Point"></Coordinates></dd>
|
|
|
|
|
</template>
|
2023-09-12 09:15:28 +00:00
|
|
|
|
|
2023-11-01 18:45:16 +00:00
|
|
|
|
<template v-if="result.elevation != null">
|
|
|
|
|
<dt>Elevation</dt>
|
|
|
|
|
<dd>{{result.elevation}} m</dd>
|
|
|
|
|
</template>
|
2023-09-12 09:15:28 +00:00
|
|
|
|
|
2023-11-01 18:45:16 +00:00
|
|
|
|
<template v-for="(value, key) in result.extratags" :key="key">
|
2023-09-12 09:15:28 +00:00
|
|
|
|
<dt>{{key}}</dt>
|
|
|
|
|
<dd v-html="renderOsmTag(key, value)"></dd>
|
2021-04-04 21:07:12 +00:00
|
|
|
|
</template>
|
2023-09-12 09:15:28 +00:00
|
|
|
|
</dl>
|
|
|
|
|
|
2023-11-02 14:14:05 +00:00
|
|
|
|
<div>
|
|
|
|
|
<div class="btn-group" role="group">
|
|
|
|
|
<button
|
|
|
|
|
type="button"
|
2023-11-03 03:02:12 +00:00
|
|
|
|
class="btn btn-secondary btn-sm"
|
2023-11-02 14:14:05 +00:00
|
|
|
|
v-tooltip="'Zoom to search result'"
|
|
|
|
|
@click="zoomToResult()"
|
|
|
|
|
>
|
|
|
|
|
<Icon icon="zoom-in" alt="Zoom to search result"></Icon>
|
2023-10-24 00:08:47 +00:00
|
|
|
|
</button>
|
2023-11-02 14:14:05 +00:00
|
|
|
|
|
|
|
|
|
<div v-if="!client.readonly && types.length > 0" class="dropdown">
|
2023-11-03 03:02:12 +00:00
|
|
|
|
<button type="button" class="btn btn-secondary btn-sm dropdown-toggle" :disabled="isAdding" data-bs-toggle="dropdown">
|
2023-11-02 14:14:05 +00:00
|
|
|
|
<div v-if="isAdding" class="spinner-border spinner-border-sm"></div>
|
|
|
|
|
Add to map
|
|
|
|
|
</button>
|
|
|
|
|
<ul class="dropdown-menu">
|
|
|
|
|
<template v-for="type in types" :key="type.id">
|
|
|
|
|
<li>
|
|
|
|
|
<a
|
|
|
|
|
href="javascript:"
|
|
|
|
|
class="dropdown-item"
|
|
|
|
|
@click="$emit('add-to-map', type)"
|
|
|
|
|
>{{type.name}}</a>
|
|
|
|
|
</li>
|
|
|
|
|
</template>
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div v-if="isMarker && context.search" class="dropdown">
|
2023-11-03 03:02:12 +00:00
|
|
|
|
<button type="button" class="btn btn-secondary btn-sm dropdown-toggle" data-bs-toggle="dropdown">Use as</button>
|
2023-11-02 14:14:05 +00:00
|
|
|
|
<ul class="dropdown-menu">
|
2023-10-24 00:08:47 +00:00
|
|
|
|
<li>
|
|
|
|
|
<a
|
|
|
|
|
href="javascript:"
|
|
|
|
|
class="dropdown-item"
|
2023-11-02 14:14:05 +00:00
|
|
|
|
@click="$emit('use-as-from')"
|
|
|
|
|
>Route start</a>
|
2023-10-24 00:08:47 +00:00
|
|
|
|
</li>
|
|
|
|
|
|
2023-11-02 14:14:05 +00:00
|
|
|
|
<li>
|
|
|
|
|
<a
|
|
|
|
|
href="javascript:"
|
|
|
|
|
class="dropdown-item"
|
|
|
|
|
@click="$emit('use-as-via')"
|
|
|
|
|
>Route via</a>
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li>
|
|
|
|
|
<a
|
|
|
|
|
href="javascript:"
|
|
|
|
|
class="dropdown-item"
|
|
|
|
|
@click="$emit('use-as-to')"
|
|
|
|
|
>Route destination</a>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
2023-10-24 00:08:47 +00:00
|
|
|
|
</div>
|
2023-10-30 00:14:54 +00:00
|
|
|
|
</div>
|
2023-09-12 09:15:28 +00:00
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
|
.fm-search-result-info {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
min-height: 0;
|
|
|
|
|
|
|
|
|
|
.fm-search-box-collapse-point {
|
|
|
|
|
min-height: 1.5em;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|