Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/blocks/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@viamrobotics/prime-blocks",
"version": "0.1.9",
"version": "0.1.10",
"repository": {
"type": "git",
"url": "https://github.com/viamrobotics/prime.git",
Expand Down
5 changes: 3 additions & 2 deletions packages/blocks/src/lib/maplibre/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { Map, type MapOptions } from 'maplibre-gl';
import { getStyleSpecification } from './style';
import { LngLat } from '$lib';
import { MapProviders, type MapProvider } from './types';
import { DEFAULT_MAX_ZOOM } from './zoom';

/** The minimum camera pitch. */
export let minPitch = 0;
Expand All @@ -41,7 +42,7 @@ export let zoom = 9;
export let minZoom = 0;

/** The maximum zoom level of the map (0-24). */
export let maxZoom = 22;
export let maxZoom = DEFAULT_MAX_ZOOM;

/**
* The map center.
Expand Down Expand Up @@ -130,7 +131,7 @@ onMount(() => {
map = new Map({
antialias: true,
container,
style: getStyleSpecification(mapProvider, mapProviderKey),
style: getStyleSpecification(mapProvider, mapProviderKey, maxZoom),
center,
zoom,
minPitch,
Expand Down
19 changes: 12 additions & 7 deletions packages/blocks/src/lib/maplibre/style.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
import type { StyleSpecification } from 'maplibre-gl';
import { MapProviders, type MapProvider } from './types';
import { DEFAULT_MAX_ZOOM } from './zoom';

const tileSize = 256;
const maxzoom = 20;

const getGoogleMapsStyle = (apiKey: string): StyleSpecification => ({
const getGoogleMapsStyle = (
apiKey: string,
maxzoom: number
): StyleSpecification => ({
version: 8,
sources: {
[MapProviders.googleMaps]: {
Expand Down Expand Up @@ -43,7 +46,7 @@ const getGoogleMapsStyle = (apiKey: string): StyleSpecification => ({
],
});

const getOpenStreetMapStyle = (): StyleSpecification => ({
const getOpenStreetMapStyle = (maxzoom: number): StyleSpecification => ({
version: 8,
sources: {
osm: {
Expand Down Expand Up @@ -82,19 +85,21 @@ const getOpenStreetMapStyle = (): StyleSpecification => ({

export const getStyleSpecification = (
provider: MapProvider,
apiKey?: string
apiKey?: string,
maxZoom?: number
): StyleSpecification => {
const maxzoom = maxZoom ?? DEFAULT_MAX_ZOOM;
switch (provider) {
case MapProviders.googleMaps: {
if (!apiKey) {
// eslint-disable-next-line no-console
console.warn('Google Maps API key is required');
return getOpenStreetMapStyle();
return getOpenStreetMapStyle(maxzoom);
}
return getGoogleMapsStyle(apiKey);
return getGoogleMapsStyle(apiKey, maxzoom);
}
case MapProviders.openStreet: {
return getOpenStreetMapStyle();
return getOpenStreetMapStyle(maxzoom);
}
}
};
1 change: 1 addition & 0 deletions packages/blocks/src/lib/maplibre/zoom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const DEFAULT_MAX_ZOOM = 21;