Skip to content

Commit

Permalink
update map when lat/lon change
Browse files Browse the repository at this point in the history
  • Loading branch information
BryonLewis committed Feb 6, 2024
1 parent d115904 commit f998cfd
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
31 changes: 30 additions & 1 deletion client/src/components/MapLocation.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,14 @@ export default defineComponent({
type: Object as PropType<{ x?: number; y?: number } | undefined>,
default: () => undefined,
},
updateMap: {

Check warning on line 24 in client/src/components/MapLocation.vue

View workflow job for this annotation

GitHub Actions / Lint [eslint]

Prop 'updateMap' requires default value to be set
type: Number,
defualt: 0,
},
},
emits: ['location'],
setup(props, { emit }) {
const usCenter = { x: -90.5855, y: 39.8333 };
const mapRef: Ref<HTMLDivElement | null> = ref(null);
const map: Ref<any> = ref();
const mapLayer: Ref<any> = ref();
Expand All @@ -32,7 +37,6 @@ export default defineComponent({
const markerLocation: Ref<{ x: number; y: number } | null> = ref(null);
watch(mapRef, () => {
if (mapRef.value) {
const usCenter = { x: -90.5855, y: 39.8333 };
const centerPoint = props.location && props.location.x && props.location.y ? props.location : usCenter;
const zoomLevel = props.location && props.location.x && props.location.y ? 6 : 3;
map.value = geo.map({ node: mapRef.value, center: centerPoint, zoom: zoomLevel });
Expand Down Expand Up @@ -79,6 +83,31 @@ export default defineComponent({
}
}
});
watch(() => props.updateMap, () => {
if (props.location?.x && props.location?.y && markerLocation.value) {
markerLocation.value = { x: props.location?.x, y: props.location.y };
markerFeature.value
.data([markerLocation.value])
.style({
symbol: geo.markerFeature.symbols.drop,
symbolValue: 1 / 3,
rotation: -Math.PI / 2,
radius: 30,
strokeWidth: 5,
strokeColor: "blue",
fillColor: "yellow",
rotateWithMap: false,
})
.draw();
const centerPoint = props.location && props.location.x && props.location.y ? props.location : usCenter;
const zoomLevel = props.location && props.location.x && props.location.y ? 6 : 3;
if (map.value) {
map.value.zoom(zoomLevel);
map.value.center(centerPoint);
}

}
});
return {
mapRef,
};
Expand Down
9 changes: 9 additions & 0 deletions client/src/components/UploadRecording.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ export default defineComponent({
longitude.value = lon;
};
const updateMap = ref(0); // updates the map when lat/lon change by editing directly;
const triggerUpdateMap = () => updateMap.value += 1;
return {
errorText,
fileModel,
Expand All @@ -134,11 +138,13 @@ export default defineComponent({
longitude,
gridCellId,
publicVal,
updateMap,
selectFile,
readFile,
handleSubmit,
updateTime,
setLocation,
triggerUpdateMap,
};
},
});
Expand Down Expand Up @@ -264,12 +270,14 @@ export default defineComponent({
type="number"
label="LAT:"
class="mx-4"
@change="triggerUpdateMap()"
/>
<v-text-field
v-model="longitude"
type="number"
label="LON:"
class="mx-4"
@change="triggerUpdateMap()"
/>
</v-row>
<v-row>
Expand All @@ -284,6 +292,7 @@ export default defineComponent({
<map-location
:size="{width: 600, height: 400}"
:location="{ x: latitude, y: longitude}"
:update-map="updateMap"
@location="setLocation($event)"
/>
<v-spacer />
Expand Down

0 comments on commit f998cfd

Please sign in to comment.