Skip to content

Commit

Permalink
Merge pull request #237 from opendatasoft/feature/add-preserve-drawin…
Browse files Browse the repository at this point in the history
…g-buffer-option-for-maps

feat: add preserveDrawingBuffer option to Maplibre maps
  • Loading branch information
richterb authored May 20, 2024
2 parents e1bbccd + 0ff856b commit 3cfd073
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
// Data source link
let sourceLink: Source | undefined;
let cooperativeGestures: boolean | GestureOptions | undefined;
let preserveDrawingBuffer: boolean;
// Used to apply a chosen color for shapes without values (default: #cccccc)
let emptyValueColor: Color;
Expand All @@ -71,6 +72,7 @@
navigationMaps,
sourceLink,
cooperativeGestures,
preserveDrawingBuffer = false,
} = options);
// Choropleth is always display over a blank map, for readability purposes
Expand Down Expand Up @@ -137,6 +139,7 @@
{data}
{sourceLink}
{cooperativeGestures}
{preserveDrawingBuffer}
/>
</div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
// Data source link
let sourceLink: Source | undefined;
let cooperativeGestures: boolean | GestureOptions | undefined;
let preserveDrawingBuffer: boolean;
let fixedMaxBounds: LngLatBoundsLike | undefined;
// Used to apply a chosen color for shapes without values (default: #cccccc)
Expand Down Expand Up @@ -84,6 +85,7 @@
navigationMaps,
sourceLink,
cooperativeGestures,
preserveDrawingBuffer = false,
fixedMaxBounds,
} = options);
Expand Down Expand Up @@ -163,6 +165,7 @@
{data}
{sourceLink}
{cooperativeGestures}
{preserveDrawingBuffer}
{fixedMaxBounds}
/>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
// Data source link
export let sourceLink: Source | undefined;
export let cooperativeGestures: boolean | GestureOptions | undefined;
export let preserveDrawingBuffer: boolean;
// Fixed max bounds that will overide the automatic map.getBounds when setting the bbox
export let fixedMaxBounds: LngLatBoundsLike | undefined | null = null;
Expand Down Expand Up @@ -133,6 +134,7 @@
customAttribution: attribution,
renderWorldCopies: false,
cooperativeGestures,
preserveDrawingBuffer,
};
map = new maplibregl.Map({
Expand Down Expand Up @@ -435,7 +437,7 @@
figcaption h3 {
margin: 0;
}
/* To add classes programmatically in svelte we will use a global selector.
/* To add classes programmatically in svelte we will use a global selector.
We place it inside a local selector to obtain some encapsulation and avoid side effects */
.map-card :global(.tooltip-on-hover > .maplibregl-popup-content) {
border-radius: 6px;
Expand Down
2 changes: 2 additions & 0 deletions packages/visualizations/src/components/Map/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export interface ChoroplethOptions {
/** Link button to source */
sourceLink?: Source;
cooperativeGestures?: boolean | GestureOptions;
/** If true, the map's canvas can be exported to an image using toDataURL. This is false by default as a performance optimization. */
preserveDrawingBuffer?: boolean;
}

export interface MapFilter {
Expand Down
2 changes: 2 additions & 0 deletions packages/visualizations/src/components/MapPoi/Map.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
images,
transformRequest,
cooperativeGestures,
preserveDrawingBuffer,
} = getMapOptions(options));
const bbox = createDeepEqual(_bbox);
Expand Down Expand Up @@ -70,6 +71,7 @@
{images}
{transformRequest}
{cooperativeGestures}
{preserveDrawingBuffer}
/>
{/key}
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
export let legend: CategoryLegendType | undefined;
export let description: string | undefined;
export let cooperativeGestures: boolean | GestureOptions | undefined;
export let preserveDrawingBuffer: boolean;
// Data source link
export let sourceLink: Source | undefined;
Expand Down Expand Up @@ -73,6 +74,7 @@
minZoom,
maxZoom,
cooperativeGestures,
preserveDrawingBuffer,
};
map.initialize(style, container, options);
});
Expand Down Expand Up @@ -135,7 +137,7 @@
margin: 0;
}
/* To add classes programmatically in svelte we will use a global selector.
/* To add classes programmatically in svelte we will use a global selector.
We place it inside a local selector to obtain some encapsulation and avoid side effects */
/* --- POPUP --- */
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 @@ -58,6 +58,8 @@ export interface PoiMapOptions {
/** Link button to source */
sourceLink?: Source;
cooperativeGestures?: boolean | GestureOptions;
/** If true, the map's canvas can be exported to an image using toDataURL. This is false by default as a performance optimization. */
preserveDrawingBuffer?: boolean;
/** Images to load by the Map. keys are image ids */
images?: Images;
}
Expand Down
2 changes: 2 additions & 0 deletions packages/visualizations/src/components/MapPoi/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,7 @@ export const getMapOptions = (options: PoiMapOptions) => {
sourceLink,
transformRequest,
cooperativeGestures,
preserveDrawingBuffer = false,
images,
} = options;
return {
Expand All @@ -189,6 +190,7 @@ export const getMapOptions = (options: PoiMapOptions) => {
sourceLink,
transformRequest,
cooperativeGestures,
preserveDrawingBuffer,
images,
};
};
Expand Down

2 comments on commit 3cfd073

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage for this commit

94.64%

Coverage Report
FileBranchesFuncsLinesUncovered Lines
src
   index.ts100%100%100%
src/client
   error.ts100%100%100%
   index.ts74.03%100%95.31%102–103, 124, 13, 146, 148, 148–149, 15, 15, 151, 162, 169, 169, 17, 17, 171, 176, 179, 182, 184, 52, 82
   types.ts100%100%100%
src/odsql
   clauses.ts71.43%80%90.91%14, 32, 42
   index.ts83.72%95.74%94.19%111, 146, 25, 28, 56–57, 57, 57–58, 68, 78–79

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage for this commit

94.64%

Coverage Report
FileBranchesFuncsLinesUncovered Lines
src
   index.ts100%100%100%
src/client
   error.ts100%100%100%
   index.ts74.03%100%95.31%102–103, 124, 13, 146, 148, 148–149, 15, 15, 151, 162, 169, 169, 17, 17, 171, 176, 179, 182, 184, 52, 82
   types.ts100%100%100%
src/odsql
   clauses.ts71.43%80%90.91%14, 32, 42
   index.ts83.72%95.74%94.19%111, 146, 25, 28, 56–57, 57, 57–58, 68, 78–79

Please sign in to comment.