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 min max zoom options #197

Merged
merged 6 commits into from
Oct 12, 2023
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"bootstrap": "lerna bootstrap",
"watch": "lerna run watch --parallel --stream",
"lint": "lerna run lint --parallel --no-bail",
"build-package-lock": "lerna run build-package-lock"
"build-package-lock": "lerna run build-package-lock",
"storybook": "lerna run --scope=@opendatasoft/visualizations-react storybook"
},
"devDependencies": {
"lerna": "^5.5.0",
Expand Down
17 changes: 16 additions & 1 deletion packages/visualizations-react/stories/Poi/PoiMap.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const meta: ComponentMeta<typeof PoiMap> = {

export default meta;

const Template: ComponentStory<typeof PoiMap> = (args) => (
const Template: ComponentStory<typeof PoiMap> = args => (
<div
style={{
width: '50%',
Expand Down Expand Up @@ -170,3 +170,18 @@ const PoiMapLegendCenterArgs = {
options: { ...options, legend: { ...legend, align: 'center' as const } },
};
PoiMapLegendCenter.args = PoiMapLegendCenterArgs;

/**
* STORY: with min and max zoom
*/
export const PoiMapMinMaxZooms: ComponentStory<typeof PoiMap> = Template.bind({});
const PoiMapMinMaxZoomsArgs = {
data: { value: { layers: [{ ...layer1, colorMatch: citiesColorMatch }, layer2], sources } },
options: {
...options,
legend,
minZoom: 3,
maxZoom: 5,
},
};
PoiMapMinMaxZooms.args = PoiMapMinMaxZoomsArgs;
6 changes: 5 additions & 1 deletion packages/visualizations/src/components/MapPoi/Map.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@
$: ({
bbox: _bbox,
zoom,
center: _center,
zoom,
minZoom,
maxZoom,
title,
subtitle,
description,
Expand All @@ -52,6 +54,8 @@
bbox={$bbox}
center={$center}
{zoom}
{minZoom}
{maxZoom}
{title}
{subtitle}
{description}
Expand Down
12 changes: 12 additions & 0 deletions packages/visualizations/src/components/MapPoi/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,18 @@ export default class MapPOI {
});
}

setMinZoom(minZoom?: number) {
this.queue((map) => {
map.setMinZoom(minZoom);
});
}

setMaxZoom(maxZoom?: number) {
this.queue((map) => {
map.setMaxZoom(maxZoom);
});
}

setBbox(bbox?: BBox) {
this.queue((map) => {
if (!bbox) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
// Options
export let bbox: BBox | undefined;
export let zoom: number | undefined;
export let minZoom: number | undefined;
export let maxZoom: number | undefined;
export let center: LngLatLike | undefined;
export let aspectRatio: number;
export let interactive: boolean;
Expand All @@ -42,6 +44,8 @@

$: map.toggleInteractivity(interactive ? 'enable' : 'disable');
$: map.setBbox(bbox);
$: map.setMinZoom(minZoom);
$: map.setMaxZoom(maxZoom);
$: map.setSourcesAndLayers(sources, layers);
$: map.setPopupsConfiguration(popupsConfiguration);
$: map.jumpTo(getCenterZoomOptions({ zoom, center }));
Expand All @@ -53,6 +57,8 @@
bounds: bbox as LngLatBoundsLike,
...getCenterZoomOptions({ zoom, center }),
transformRequest,
minZoom,
maxZoom,
KevinFabre-ods marked this conversation as resolved.
Show resolved Hide resolved
};
map.initialize(style, container, options);
});
Expand Down
2 changes: 2 additions & 0 deletions packages/visualizations/src/components/MapPoi/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export interface PoiMapOptions {
bbox?: BBox;
center?: LngLatLike;
zoom?: number;
minZoom?: number;
maxZoom?: number;
// Aspect ratio used to draw the map. The map will take he width available to it, and decide its height based on that ratio.
aspectRatio?: number;
// Is the map interactive for the user (zoom, move, tooltips...)
Expand Down
4 changes: 4 additions & 0 deletions packages/visualizations/src/components/MapPoi/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export const getMapOptions = (options: PoiMapOptions) => {
aspectRatio = DEFAULT_ASPECT_RATIO,
bbox,
zoom,
maxZoom,
minZoom,
center,
interactive = true,
title,
Expand All @@ -114,6 +116,8 @@ export const getMapOptions = (options: PoiMapOptions) => {
aspectRatio,
bbox,
zoom,
minZoom,
maxZoom,
center,
interactive,
title,
Expand Down
Loading