Polyline - Sveaflet

Vector Layers - Polyline

A component for drawing polyline overlays on a map. Extends Path.

Setup #

  • Svelte
<script>
	import { Polyline } from 'sveaflet';
</script>

Default Polyline #

  • Svelte
<script>
	import { Map, TileLayer, Polyline } from 'sveaflet';
</script>

<div style="width: 100%;height: 500px;">
	<Map options={{ center: [37.77, -122.43], zoom: 4 }}>
		<TileLayer url={'https://tile.openstreetmap.org/{z}/{x}/{y}.png'} />
		<Polyline
			latLngs={[
				[45.51, -122.68],
				[37.77, -122.43],
				[34.04, -118.2]
			]}
		/>
	</Map>
</div>

Polyline with Options #

  • Svelte
<script>
	import { Map, TileLayer, Polyline } from 'sveaflet';
	import { Radio } from 'flowbite-svelte';

	let color = 'red';
</script>

<div class="flex items-center gap-4 mb-4">
	<Radio bind:group={color} value="red">Red</Radio>
	<Radio bind:group={color} value="green">Green</Radio>
	<Radio bind:group={color} value="blue">Blue</Radio>
</div>

<div style="width: 100%;height: 500px;">
	<Map options={{ center: [37.77, -122.43], zoom: 4 }}>
		<TileLayer url={'https://tile.openstreetmap.org/{z}/{x}/{y}.png'} />
		<Polyline
			latLngs={[
				[45.51, -122.68],
				[37.77, -122.43],
				[34.04, -118.2]
			]}
			options={{ color }}
		/>
	</Map>
</div>

Polyline with Popup #

  • Svelte
<script>
	import { Map, TileLayer, Polyline, Popup } from 'sveaflet';
</script>

<div style="width: 100%;height: 500px;">
	<Map options={{ center: [37.77, -122.43], zoom: 4 }}>
		<TileLayer url={'https://tile.openstreetmap.org/{z}/{x}/{y}.png'} />
		<Polyline
			latLngs={[
				[45.51, -122.68],
				[37.77, -122.43],
				[34.04, -118.2]
			]}
			options={{ color: 'yellow' }}
		>
			<Popup options={{ content: 'Popup in Polyline.' }} />
		</Polyline>
	</Map>
</div>

Props #

Prop name Description Type Default
latLngs Required LatLng[]
options Optional PolylineOptions {}