Skip to content

Commit

Permalink
feat: add fixed max bounds props
Browse files Browse the repository at this point in the history
  • Loading branch information
RafaelSzmarowski committed Dec 19, 2023
1 parent f356fa5 commit bc4b5e1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<script lang="ts">
import type { SourceSpecification, GestureOptions, ExpressionSpecification } from 'maplibre-gl';
import type {
SourceSpecification,
GestureOptions,
ExpressionSpecification,
LngLatBoundsLike,
} from 'maplibre-gl';
import type { BBox } from 'geojson';
import { debounce } from 'lodash';
import type { ColorScale, DataBounds, Color, Source } from '../../types';
Expand Down Expand Up @@ -48,6 +53,7 @@
// Data source link
let sourceLink: Source | undefined;
let cooperativeGestures: boolean | GestureOptions | undefined;
let fixedMaxBounds: LngLatBoundsLike | undefined;
// Used to apply a chosen color for shapes without values (default: #cccccc)
let emptyValueColor: Color;
Expand Down Expand Up @@ -75,6 +81,7 @@
navigationMaps,
sourceLink,
cooperativeGestures,
fixedMaxBounds,
} = options);
// Choropleth is always display over a blank map, for readability purposes
Expand Down Expand Up @@ -153,6 +160,7 @@
{data}
{sourceLink}
{cooperativeGestures}
{fixedMaxBounds}
/>

<style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@
// Data source link
export let sourceLink: Source | undefined;
export let cooperativeGestures: boolean | GestureOptions | undefined;
// Fixed max bounds that will overide the automatic map.getBounds when setting the bbox
export let fixedMaxBounds: LngLatBoundsLike | undefined | null = null;
let clientWidth: number;
let legendVariant: LegendVariant;
Expand Down Expand Up @@ -115,7 +117,7 @@
padding: 40,
});
// Set new map max bounds after bbox changes
map.setMaxBounds(map.getBounds());
map.setMaxBounds(fixedMaxBounds || map.getBounds());
};
function initializeMap() {
Expand Down
4 changes: 3 additions & 1 deletion packages/visualizations/src/components/Map/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Feature, FeatureCollection, Position, BBox } from 'geojson';
import type { FillLayerSpecification, Popup, GestureOptions } from 'maplibre-gl';
import type { FillLayerSpecification, Popup, GestureOptions, LngLatBoundsLike } from 'maplibre-gl';
import type { DebouncedFunc } from 'lodash';
import type { LegendPositions } from '../Legend/types';
import type { ColorScale, Color, Source } from '../types';
Expand Down Expand Up @@ -64,6 +64,8 @@ export interface ChoroplethVectorTilesOptions extends ChoroplethOptions {
shapesTiles: ChoroplethShapeVectorTilesValue;
/** Only draw shapes that match the given filter */
filter?: MapFilter;
/** Override the default automatic adjustment of bounds from map instance, it is useful in cases where it doesn't work and, in particular, to display the world map without the extreme poles */
fixedMaxBounds?: LngLatBoundsLike;
}

export type NavigationMap = {
Expand Down

0 comments on commit bc4b5e1

Please sign in to comment.