Various type fix

pull/13/head
Anthony Catel 2022-03-30 09:33:56 +02:00
rodzic 912620e44d
commit 633033b4d1
1 zmienionych plików z 18 dodań i 11 usunięć

Wyświetl plik

@ -1,7 +1,7 @@
<template> <template>
<div class="w-full h-full"> <div class="w-full h-full">
<input ref="pacinput" class="controls" :class="[mapLoaded ? '' : 'hidden']" type="text" placeholder="Search Box"> <input ref="pacinput" class="controls" :class="[mapLoaded ? '' : 'hidden']" type="text" placeholder="Search Box">
<div class="w-full h-full" id="map"></div> <div class="w-full h-full" ref="mapel"></div>
</div> </div>
</template> </template>
@ -11,7 +11,6 @@
import { onMounted, ref, watch, computed } from 'vue'; import { onMounted, ref, watch, computed } from 'vue';
import { watchDebounced } from '@vueuse/core' import { watchDebounced } from '@vueuse/core'
const DEFAULT_MAP_POSITION = [48.862895, 2.286978, 18] const DEFAULT_MAP_POSITION = [48.862895, 2.286978, 18]
const loader = new MapLoader({ const loader = new MapLoader({
@ -35,9 +34,10 @@
const arrPoly = ref<google.maps.LatLng[]>([]) const arrPoly = ref<google.maps.LatLng[]>([])
const mapLoaded = ref(false); const mapLoaded = ref(false);
const pacinput = ref() const pacinput = ref()
const mapel = ref()
let currentMap : google.maps.Map | undefined; let currentMap : google.maps.Map;
let currentPolygon : google.maps.Polygon | undefined; let currentPolygon : google.maps.Polygon;
onMounted(() => { onMounted(() => {
loader.loadCallback(e => { loader.loadCallback(e => {
@ -46,7 +46,7 @@
return; return;
} }
currentMap = new google.maps.Map(document.getElementById("map"), { currentMap = new google.maps.Map(mapel.value, {
zoom: mapPosition.value[2], zoom: mapPosition.value[2],
center: { center: {
lat: mapPosition.value[0], lat: mapPosition.value[0],
@ -62,20 +62,23 @@
searchBox.addListener('places_changed', () => { searchBox.addListener('places_changed', () => {
const places = searchBox.getPlaces(); const places = searchBox.getPlaces();
if (places.length == 0) { if (!places || places.length == 0) {
return; return;
} }
const place = places[0]; const place = places[0];
currentMap.setCenter(place.geometry.location); if (place.geometry?.location) {
currentMap.setCenter(place.geometry.location);
}
currentMap.setZoom(17); currentMap.setZoom(17);
reset(); reset();
}); });
currentMap.addListener('bounds_changed', function() { currentMap.addListener('bounds_changed', function() {
searchBox.setBounds(currentMap.getBounds()); searchBox.setBounds(currentMap.getBounds()!);
}); });
currentMap.addListener('center_changed', mapUpdated); currentMap.addListener('center_changed', mapUpdated);
currentMap.addListener('zoom_changed', mapUpdated); currentMap.addListener('zoom_changed', mapUpdated);
@ -138,6 +141,10 @@
const pos = currentMap.getCenter(); const pos = currentMap.getCenter();
const zoom = currentMap.getZoom(); const zoom = currentMap.getZoom();
if (!pos || !zoom) {
return;
}
mapPosition.value = [pos.lat(), pos.lng(), zoom]; mapPosition.value = [pos.lat(), pos.lng(), zoom];
} }
@ -175,7 +182,7 @@
currentMap.setCenter({lat: meta[1], lng: meta[2]}); currentMap.setCenter({lat: meta[1], lng: meta[2]});
currentMap.setZoom(meta[3]); currentMap.setZoom(meta[3]);
const path = []; const path : google.maps.LatLngLiteral[] = [];
for (let i = 0; i < data.length; i += 2) { for (let i = 0; i < data.length; i += 2) {
path.push({ path.push({
lat: data[i], lat: data[i],
@ -201,8 +208,8 @@
currentMap.setZoom(parseInt(cursetting[2])); currentMap.setZoom(parseInt(cursetting[2]));
} }
const density = parseFloat(opt.pop()) || 1; const density = parseFloat(opt.pop() ?? '') || 1;
const path = []; const path : google.maps.LatLngLiteral[] = [];
for (let i = 0; i < opt.length; i++) { for (let i = 0; i < opt.length; i++) {
const coord = opt[i].split(','); const coord = opt[i].split(',');