@dative-gpi/foundation-shared-components 1.0.166 → 1.0.167-map-edit
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<FSCol>
|
|
3
|
+
<FSMap
|
|
4
|
+
:lockZoomOnFlyTo="true"
|
|
5
|
+
v-model:center="center"
|
|
6
|
+
:enableScrollWheelZoom="true"
|
|
7
|
+
:showMyLocation="true"
|
|
8
|
+
:zoom="5"
|
|
9
|
+
v-model:currentLayer="mapLayer"
|
|
10
|
+
@click:latlng="(latlng: any) => onNewLatLng(latlng.lat, latlng.lng, false)"
|
|
11
|
+
v-bind="$attrs"
|
|
12
|
+
>
|
|
13
|
+
<FSMapMarker
|
|
14
|
+
v-if="actualLatitude && actualLongitude"
|
|
15
|
+
:label="$props.label"
|
|
16
|
+
:icon="$props.icon"
|
|
17
|
+
:latlng="{ lat: actualLatitude, lng: actualLongitude }"
|
|
18
|
+
:selected="true"
|
|
19
|
+
/>
|
|
20
|
+
</FSMap>
|
|
21
|
+
<FSCol>
|
|
22
|
+
<FSAutoCompleteAddress
|
|
23
|
+
:maxWidth="null"
|
|
24
|
+
:modelValue="$props.modelValue"
|
|
25
|
+
@update:modelValue="$emit('update:modelValue', $event)"
|
|
26
|
+
/>
|
|
27
|
+
<FSRow>
|
|
28
|
+
<FSNumberField
|
|
29
|
+
:label="$tr('ui.location.latitude', 'Latitude')"
|
|
30
|
+
:modelValue="actualLatitude"
|
|
31
|
+
:clearable="false"
|
|
32
|
+
:rules="[NumberRules.max(90), NumberRules.min(-90), NumberRules.required()]"
|
|
33
|
+
@update:modelValue="onNewLatLng($event, actualLongitude ?? 0, true)"
|
|
34
|
+
/>
|
|
35
|
+
<FSNumberField
|
|
36
|
+
:label="$tr('ui.location.longitude', 'Longitude')"
|
|
37
|
+
:modelValue="actualLongitude"
|
|
38
|
+
:clearable="false"
|
|
39
|
+
:rules="[NumberRules.max(180), NumberRules.min(-180), NumberRules.required()]"
|
|
40
|
+
@update:modelValue="onNewLatLng(actualLatitude ?? 0, $event, true)"
|
|
41
|
+
/>
|
|
42
|
+
</FSRow>
|
|
43
|
+
</FSCol>
|
|
44
|
+
</FSCol>
|
|
45
|
+
</template>
|
|
46
|
+
|
|
47
|
+
<script lang="ts">
|
|
48
|
+
import { computed, defineComponent, ref, watch, type PropType } from "vue";
|
|
49
|
+
|
|
50
|
+
import type { Address } from "@dative-gpi/foundation-shared-domain";
|
|
51
|
+
import { useAddress } from "@dative-gpi/foundation-shared-components/composables";
|
|
52
|
+
import { MapLayers, NumberRules } from '@dative-gpi/foundation-shared-components/models';
|
|
53
|
+
|
|
54
|
+
import FSAutoCompleteAddress from '@dative-gpi/foundation-shared-components/components/autocompletes/FSAutoCompleteAddress.vue';
|
|
55
|
+
import FSNumberField from "@dative-gpi/foundation-shared-components/components/fields/FSNumberField.vue"
|
|
56
|
+
import FSMapMarker from '@dative-gpi/foundation-shared-components/components/map/FSMapMarker.vue';
|
|
57
|
+
import FSMap from "@dative-gpi/foundation-shared-components/components/map/FSMap.vue";
|
|
58
|
+
import FSRow from '@dative-gpi/foundation-shared-components/components/FSRow.vue';
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
export function debounceAsync<T, U extends any[]>(
|
|
62
|
+
callback: (...args: U) => Promise<T>,
|
|
63
|
+
wait: number,
|
|
64
|
+
): (...args: U) => Promise<T> {
|
|
65
|
+
let timeoutId: number | null = null;
|
|
66
|
+
let rejectPromise: (((reason?: any) => void) | null) = null;
|
|
67
|
+
|
|
68
|
+
return (...args: U) => {
|
|
69
|
+
if (timeoutId) {
|
|
70
|
+
clearTimeout(timeoutId);
|
|
71
|
+
timeoutId = null;
|
|
72
|
+
}
|
|
73
|
+
if (rejectPromise) {
|
|
74
|
+
rejectPromise("debounced");
|
|
75
|
+
rejectPromise = null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
return new Promise<T>((resolve) => {
|
|
79
|
+
const timeoutPromise = new Promise<void>((resolve, reject) => {
|
|
80
|
+
timeoutId = setTimeout(resolve, wait);
|
|
81
|
+
rejectPromise = reject;
|
|
82
|
+
});
|
|
83
|
+
timeoutPromise.then(async () => {
|
|
84
|
+
resolve(await callback(...args));
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export default defineComponent({
|
|
91
|
+
name: "FSMapEditLocationAddress",
|
|
92
|
+
components: {
|
|
93
|
+
FSAutoCompleteAddress,
|
|
94
|
+
FSNumberField,
|
|
95
|
+
FSMapMarker,
|
|
96
|
+
FSMap,
|
|
97
|
+
FSRow,
|
|
98
|
+
},
|
|
99
|
+
emits: ["update:modelValue"],
|
|
100
|
+
props: {
|
|
101
|
+
label: {
|
|
102
|
+
type: String,
|
|
103
|
+
required: true,
|
|
104
|
+
},
|
|
105
|
+
icon: {
|
|
106
|
+
type: String,
|
|
107
|
+
required: true,
|
|
108
|
+
},
|
|
109
|
+
modelValue: {
|
|
110
|
+
type: Object as PropType<Address | null>,
|
|
111
|
+
required: false,
|
|
112
|
+
},
|
|
113
|
+
color: {
|
|
114
|
+
type: String,
|
|
115
|
+
required: true,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
setup(props, { emit }) {
|
|
119
|
+
const { reverseSearch } = useAddress();
|
|
120
|
+
|
|
121
|
+
const loading = ref(false);
|
|
122
|
+
const actualLatitude = ref<number | null>(null);
|
|
123
|
+
const actualLongitude = ref<number | null>(null);
|
|
124
|
+
const mapLayer = ref(MapLayers.Map);
|
|
125
|
+
|
|
126
|
+
const center = computed(() => {
|
|
127
|
+
return props.modelValue ? [props.modelValue.latitude, props.modelValue.longitude] : null;
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const reverseSearchDebounced = debounceAsync(reverseSearch, 500);
|
|
131
|
+
|
|
132
|
+
const onNewLatLng = async (lat: number|string, lng: number|string, debounced: boolean) => {
|
|
133
|
+
if(typeof lat === 'string') {
|
|
134
|
+
lat = parseFloat(lat);
|
|
135
|
+
if(isNaN(lat)) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if(typeof lng === 'string') {
|
|
141
|
+
lng = parseFloat(lng);
|
|
142
|
+
if(isNaN(lng)) {
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
actualLatitude.value = lat;
|
|
148
|
+
actualLongitude.value = lng;
|
|
149
|
+
|
|
150
|
+
let fullAddress;
|
|
151
|
+
loading.value = true;
|
|
152
|
+
if(debounced) {
|
|
153
|
+
try {
|
|
154
|
+
fullAddress = await reverseSearchDebounced(lat, lng);
|
|
155
|
+
} catch {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
} else {
|
|
159
|
+
fullAddress = await reverseSearch(lat, lng);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
emit("update:modelValue", {
|
|
163
|
+
...fullAddress,
|
|
164
|
+
latitude: actualLatitude.value,
|
|
165
|
+
longitude: actualLongitude.value,
|
|
166
|
+
});
|
|
167
|
+
loading.value = false;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
watch(() => props.modelValue, (newValue) => {
|
|
171
|
+
if(newValue) {
|
|
172
|
+
actualLatitude.value = newValue.latitude;
|
|
173
|
+
actualLongitude.value = newValue.longitude;
|
|
174
|
+
}
|
|
175
|
+
}, { immediate: true });
|
|
176
|
+
|
|
177
|
+
return {
|
|
178
|
+
center,
|
|
179
|
+
mapLayer,
|
|
180
|
+
NumberRules,
|
|
181
|
+
actualLatitude,
|
|
182
|
+
actualLongitude,
|
|
183
|
+
onNewLatLng
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
</script>
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dative-gpi/foundation-shared-components",
|
|
3
3
|
"sideEffects": false,
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.167-map-edit",
|
|
5
5
|
"description": "",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
"author": "",
|
|
11
11
|
"license": "ISC",
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@dative-gpi/foundation-shared-domain": "1.0.
|
|
14
|
-
"@dative-gpi/foundation-shared-services": "1.0.
|
|
13
|
+
"@dative-gpi/foundation-shared-domain": "1.0.167-map-edit",
|
|
14
|
+
"@dative-gpi/foundation-shared-services": "1.0.167-map-edit"
|
|
15
15
|
},
|
|
16
16
|
"peerDependencies": {
|
|
17
17
|
"@dative-gpi/bones-ui": "^1.0.0",
|
|
@@ -35,5 +35,5 @@
|
|
|
35
35
|
"sass": "1.71.1",
|
|
36
36
|
"sass-loader": "13.3.2"
|
|
37
37
|
},
|
|
38
|
-
"gitHead": "
|
|
38
|
+
"gitHead": "725635256ebf2bb6450c38e5a3077fb907ea550c"
|
|
39
39
|
}
|