Skip to content

Commit

Permalink
Merge pull request #56 from scaife-viewer/fix-map-mode
Browse files Browse the repository at this point in the history
Fix map mode
  • Loading branch information
jacobwegner authored Jul 31, 2020
2 parents 76e22f3 + d11eefa commit 0d6c925
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 35 deletions.
14 changes: 12 additions & 2 deletions src/components/EntityMap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
@load="onMapLoaded"
>
<EntityMapMarker
v-for="(coordinates, index) in coordinatesList"
:key="`${coordinates[2]}-${coordinates[3]}-${index}`"
v-for="(coordinates, idx) in coordinatesList"
:key="getMarkerKey(coordinates[2], idx)"
:lat="coordinates[0]"
:lng="coordinates[1]"
:placeId="coordinates[2]"
Expand Down Expand Up @@ -44,6 +44,13 @@
this.map.fitBounds(bbox);
}
},
getMarkerKey(entityId, idx) {
// constructs a key that will be recomputed
// when the value of `selectedNamedEntities` changes in the store
const isSelected =
this.selectedEntities.filter(id => entityId === id).length > 0;
return `${entityId}::${idx}::${isSelected}`;
},
},
watch: {
coordinatesList: {
Expand Down Expand Up @@ -74,6 +81,9 @@
mapStyle() {
return this.config.mapStyle;
},
selectedEntities() {
return this.$store.state.selectedNamedEntities;
},
},
};
</script>
36 changes: 6 additions & 30 deletions src/components/EntityMapMarker.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
<template>
<MglMarker ref="marker" :coordinates="[lat, lng]" @click="onMarkerClick">
<MglPopup ref="popup" :closeButton="false" :closeOnClick="false">
<MglPopup
ref="popup"
:showed="selected"
:closeButton="false"
:closeOnClick="false"
>
<div class="label">{{ placeLabel }}</div>
</MglPopup>
</MglMarker>
Expand All @@ -27,35 +32,6 @@
}
},
},
watch: {
selected: {
immediate: true,
handler() {
// eslint-disable-next-line no-console
console.log('selected', this.selected, this.placeLabel);
if (this.selected) {
this.$nextTick(() => {
// eslint-disable-next-line no-console
console.log('open', this.$refs.popup.open, this.placeLabel);
if (this.$refs.popup.open) {
this.$refs.popup.remove();
}
// eslint-disable-next-line no-console
console.log('toggle', this.placeLabel);
this.$refs.marker.togglePopup();
// eslint-disable-next-line no-console
console.log('now open?', this.$refs.popup.open, this.placeLabel);
});
} else {
this.$nextTick(() => {
// eslint-disable-next-line no-console
console.log('remove it', this.placeLabel);
this.$refs.popup.remove();
});
}
},
},
},
computed: {
selected() {
return (
Expand Down
4 changes: 1 addition & 3 deletions src/reader/components/NamedEntitiesModeReader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</ErrorMessage>
<template v-else>
<EntityMapToolbar
v-if="enabled && data.coordinatesList.length > 0"
v-if="data.coordinatesList.length > 0"
:mapState="mapState"
@show="onShowMap"
/>
Expand Down Expand Up @@ -56,8 +56,6 @@
},
data() {
return {
// @@@ remove `enabled` when we're ready to expose map mode again
enabled: false,
mapState: MAP_STATE_NONE,
};
},
Expand Down

0 comments on commit 0d6c925

Please sign in to comment.