From 2382faad41a9a9bd2b3817be8b9532017b693da4 Mon Sep 17 00:00:00 2001 From: Tom Chapman Date: Tue, 18 Jun 2024 15:06:40 -0700 Subject: [PATCH] add geojson layer to map export --- .../src/components/publicDashboard/util.ts | 35 +++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/met-web/src/components/publicDashboard/util.ts b/met-web/src/components/publicDashboard/util.ts index 98df5aed3..049e4fbe2 100644 --- a/met-web/src/components/publicDashboard/util.ts +++ b/met-web/src/components/publicDashboard/util.ts @@ -4,6 +4,7 @@ import { Map } from 'maplibre-gl'; import { MAP_STYLE } from 'components/map'; import { Map as IMap } from 'models/analytics/map'; import { geoJSONDecode, calculateZoomLevel } from 'components/engagement/form/EngagementWidgets/Map/utils'; +import { Palette } from 'styles/Theme'; const toPng = async (element: HTMLElement): Promise => { try { @@ -25,14 +26,14 @@ const addImageToPdf = (doc: jsPDF, imageData: string, x: number, y: number, widt export const getMapImageDataUrl = async (projectMapData: IMap | null): Promise => { const mapContainer = document.getElementById('printableMapContainer'); if (!mapContainer || !projectMapData) return ''; - // Create a maplibre-gl.Map instance const map = new Map({ container: mapContainer, style: MAP_STYLE, center: [projectMapData.longitude, projectMapData.latitude], - zoom: calculateZoomLevel(500, 500, geoJSONDecode(projectMapData.geojson)), + zoom: calculateZoomLevel(300, 300, geoJSONDecode(projectMapData.geojson)), }); + const geojson = projectMapData.geojson ? JSON.parse(projectMapData.geojson.replace(/\\/g, '')) : null; // Add marker map.on('load', function () { map.addLayer({ @@ -63,6 +64,36 @@ export const getMapImageDataUrl = async (projectMapData: IMap | null): Promise