Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a flyTo option to make the map automatically fly to the built route when it's updated #109

Open
smellyshovel opened this issue Jun 26, 2022 · 1 comment
Labels
enhancement New feature or request good first issue Good for newcomers
Milestone

Comments

@smellyshovel
Copy link
Collaborator

No description provided.

@smellyshovel smellyshovel added enhancement New feature or request good first issue Good for newcomers labels Jun 26, 2022
@smellyshovel smellyshovel added this to the v1.x milestone Jun 26, 2022
@joleeee
Copy link

joleeee commented Jul 30, 2024

onMount(() => {
	map.on('load', () => {
		directions = new MapLibreGlDirections(map, {
			...
		});

		directions.on('setwaypoints', zoomToWaypoints);
	});
});

function zoomToWaypoints() {
	const wps = directions?.waypoints;
	if (wps.length >= 1) {
		let lats = wps.map((x) => x[0]);
		let lons = wps.map((x) => x[1]);

		let bb: [number, number, number, number] = [
			Math.min(...lats),
			Math.min(...lons),
			Math.max(...lats),
			Math.max(...lons)
		];

		if (!bb.includes(NaN)) {
			map.fitBounds(bb, { padding: 50 });
		}
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants