feat: add defaultOpen prop to LeafletMap
This commit is contained in:
@@ -17,7 +17,7 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, watch, onUnmounted, nextTick } from 'vue'
|
import { ref, watch, onMounted, onUnmounted, nextTick } from 'vue'
|
||||||
import L from 'leaflet'
|
import L from 'leaflet'
|
||||||
import 'leaflet/dist/leaflet.css'
|
import 'leaflet/dist/leaflet.css'
|
||||||
|
|
||||||
@@ -31,6 +31,7 @@ L.Icon.Default.mergeOptions({
|
|||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
stations: { type: Array, required: true },
|
stations: { type: Array, required: true },
|
||||||
|
defaultOpen: { type: Boolean, default: false },
|
||||||
})
|
})
|
||||||
|
|
||||||
const mapContainer = ref(null)
|
const mapContainer = ref(null)
|
||||||
@@ -82,6 +83,16 @@ async function toggleMap() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
if (props.defaultOpen) {
|
||||||
|
isOpen.value = true
|
||||||
|
await nextTick()
|
||||||
|
initMap()
|
||||||
|
mapInstance.invalidateSize()
|
||||||
|
renderMarkers()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
watch(() => props.stations, () => {
|
watch(() => props.stations, () => {
|
||||||
if (isOpen.value) {
|
if (isOpen.value) {
|
||||||
renderMarkers()
|
renderMarkers()
|
||||||
|
|||||||
Reference in New Issue
Block a user