Skip to content

Commit

Permalink
wip: zoom restriction for non-members
Browse files Browse the repository at this point in the history
  • Loading branch information
th0rgall committed Jul 31, 2023
1 parent 16b9009 commit 7fcca2f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
12 changes: 11 additions & 1 deletion src/lib/components/Map/GardenLayer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import { getContext, createEventDispatcher } from 'svelte';
import key from './mapbox-context.js';
import { tentIcon } from '$lib/images/markers';
import { user } from '$lib/stores/auth';
import { memberMaxZoom, nonMemberMaxZoom } from '$lib/constants';
type GardenFeatureCollection = {
type: 'FeatureCollection';
Expand Down Expand Up @@ -209,10 +211,18 @@
type: 'geojson',
data: fcAllGardens,
cluster: true,
clusterMaxZoom: 14,
/** Max zoom on which to cluster points if clustering is enabled.
* Defaults to one zoom less than maxzoom (so that last zoom features are not clustered).
* https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#geojson-clusterMaxZoom
*
* Note: the non-member max zoom should be more zoomed out than the member max zoom.
*/
clusterMaxZoom: nonMemberMaxZoom - 1,
clusterRadius: 50
});
map.on('zoomend', () => console.log('zoom level: ', map.getZoom()));
map.addSource(savedGardenSourceId, {
type: 'geojson',
data: fcSavedGardens
Expand Down
5 changes: 4 additions & 1 deletion src/lib/components/Map/Map.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import key from './mapbox-context.js';
import 'maplibre-gl/dist/maplibre-gl.css';
import { DEFAULT_MAP_STYLE } from '$lib/constants.js';
import { DEFAULT_MAP_STYLE, memberMaxZoom, nonMemberMaxZoom } from '$lib/constants.js';
import FullscreenControl from './FullscreenControl.js';
import { isFullscreen } from '$lib/stores/fullscreen.js';
import { user } from '$lib/stores/auth.js';
export let lat: number;
export let lon: number;
Expand Down Expand Up @@ -75,6 +76,8 @@
style: DEFAULT_MAP_STYLE,
center: [lon, lat],
zoom,
/** https://docs.mapbox.com/mapbox-gl-js/api/map/#map-parameters */
maxZoom: $user?.superfan ? memberMaxZoom : nonMemberMaxZoom,
attributionControl: false,
hash: false // TODO: discuss if we want this or not
});
Expand Down
7 changes: 7 additions & 0 deletions src/lib/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,10 @@ export const ICON_SIZE = [
];

export const IMAGES_PATH = '/images';

/**
* MapBox max zoom level for non-members, in order to preserve privacy
*/
export const nonMemberMaxZoom = 12;
// This is the MapBox default https://docs.mapbox.com/mapbox-gl-js/api/map/#map-parameters
export const memberMaxZoom = 22;

0 comments on commit 7fcca2f

Please sign in to comment.