Skip to content

Commit

Permalink
Add button to move marker to current location
Browse files Browse the repository at this point in the history
  • Loading branch information
cdauth committed Apr 11, 2024
1 parent 43de05b commit 1075b07
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
3 changes: 2 additions & 1 deletion frontend/src/i18n/de.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,13 @@
"add-marker-error": "Fehler beim Erstellen des Markers",
"add-marker-title": "{{typeName}} erstellen",
"add-marker-message": "Klicken Sie auf die Karte, um den Marker dort zu erstellen.",
"add-marker-current": "Am aktuellen Standort erstellen",
"add-marker-current": "Am Standort erstellen",
"add-marker-cancel": "Abbrechen",
"move-marker-error": "Fehler beim Bewegen des Markers",
"move-marker-title": "Marker bewegen",
"move-marker-message": "Ziehen Sie den Marker herum, um seine Position zu ändern.",
"move-marker-save": "Speichern",
"move-marker-current": "Zum Standort bewegen",
"move-marker-cancel": "Abbrechen",
"add-line-title": "{{typeName}} erstellen",
"add-line-message": "Klicken Sie mehrfach auf die Karte, um eine Linie zu malen. Klicken Sie dann auf „Speichern“, um die Linie zu erstellen.",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
"move-marker-title": "Drag marker",
"move-marker-message": "Drag the marker to reposition it.",
"move-marker-save": "Save",
"move-marker-current": "Move to current location",
"move-marker-cancel": "Cancel",
"add-line-title": "Add {{typeName}}",
"add-line-message": "Click on the map multiple times to draw a line. Then click “Finish” to save it.",
Expand Down
10 changes: 5 additions & 5 deletions frontend/src/lib/components/marker-info/marker-info.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
back: [];
}>();
const isDeleting = ref(false);
const isBusy = ref(false);
const showEditDialog = ref(false);
const marker = computed(() => client.value.markers[props.markerId]);
Expand All @@ -56,14 +56,14 @@
}))
return;
isDeleting.value = true;
isBusy.value = true;
try {
await client.value.deleteMarker({ id: props.markerId });
} catch (err) {
toasts.showErrorToast(`fm${context.id}-marker-info-delete`, () => i18n.t("marker-info.delete-marker-error"), err);
} finally {
isDeleting.value = false;
isBusy.value = false;
}
}
Expand Down Expand Up @@ -118,14 +118,14 @@
type="button"
class="btn btn-secondary btn-sm"
@click="showEditDialog = true"
:disabled="isDeleting || mapContext.interaction"
:disabled="isBusy || mapContext.interaction"
>{{i18n.t("marker-info.edit-data")}}</button>

<DropdownMenu
v-if="!client.readonly"
size="sm"
:label="i18n.t('marker-info.actions')"
:isBusy="isDeleting"
:isBusy="isBusy"
:isDisabled="mapContext.interaction"
>
<li>
Expand Down
19 changes: 13 additions & 6 deletions frontend/src/lib/utils/draw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,13 @@ export function moveMarker(markerId: ID, context: FacilMapContext, toasts: Toast

const isSaving = ref(false);

const finish = async (save: boolean) => {
const finish = async (pos: Point | undefined) => {
markerLayer.dragging!.disable();

try {
if(save) {
if(pos) {
isSaving.value = true;
const pos = markerLayer.getLatLng();
await client.value.editMarker({ id: markerId, lat: pos.lat, lon: pos.lng });
await client.value.editMarker({ id: markerId, lat: pos.lat, lon: pos.lon });
}

toasts.hideToast("fm-draw-drag-marker");
Expand All @@ -97,15 +96,23 @@ export function moveMarker(markerId: ID, context: FacilMapContext, toasts: Toast
label: getI18n().t("draw.move-marker-save"),
variant: "primary" as const,
onClick: () => {
void finish(true);
const pos = markerLayer.getLatLng()
void finish({ lat: pos.lat, lon: pos.lng });
},
isPending: isSaving.value,
isDisabled: isSaving.value
},
...mapContext.value.location ? [{
label: getI18n().t("draw.move-marker-current"),
onClick: () => {
void finish(mapContext.value.location);
},
isDisabled: isSaving.value
}] : [],
{
label: getI18n().t("draw.move-marker-cancel"),
onClick: () => {
void finish(false);
void finish(undefined);
},
isDisabled: isSaving.value
}
Expand Down

0 comments on commit 1075b07

Please sign in to comment.