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