svelte-leafletjs icon indicating copy to clipboard operation
svelte-leafletjs copied to clipboard

LeafletMap load event never fires when options center is passed.

Open kauaicreative opened this issue 1 year ago • 0 comments

Note that the 'load' event will never fire with this code. But if you remove center' from mapOptions then it will fire. Note that to get center and load to work manually center the map leafletMap.getMap().setView(center)`

<script>
	import {LeafletMap, TileLayer} from 'svelte-leafletjs';
	import 'leaflet/dist/leaflet.css';

	const center           = [1.250111, 103.830933]
	const zoom             = 15
	const mapOptions       = {
		center,
		zoom
	};
	const tileUrl          = "https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png";
	const tileLayerOptions = {}

	let leafletMap;
	$: if (leafletMap) {
		leafletMap.getMap().setView(center)
	}

</script>

<div class="example" style="width: 100%; height: 100vh;">
	<LeafletMap
			bind:this={leafletMap}
			options={mapOptions}
			events={['load', 'click']}
			on:load={e => {
				console.log('load');
			}}
			on:click={e => {
				console.log('click');
			}}>
		<TileLayer url={tileUrl} options={tileLayerOptions}/>
	</LeafletMap>
</div>

https://github.com/ngyewch/svelte-leaflet/issues/9#issuecomment-1649787205

kauaicreative avatar Oct 16 '23 23:10 kauaicreative