feat: add defaultOpen prop to LeafletMap

This commit is contained in:
Ovidiu U
2026-04-11 18:45:26 +01:00
parent d11d500a35
commit 6f52f3f0d7

View File

@@ -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()