jansule commented on code in PR #39760:
URL: https://github.com/apache/superset/pull/39760#discussion_r4422811095
##########
superset-frontend/plugins/plugin-chart-cartodiagram/src/components/OlChartMap.tsx:
##########
@@ -20,21 +20,67 @@ import { useEffect, useState } from 'react';
import { useSelector } from 'react-redux';
import Point from 'ol/geom/Point';
-import { View } from 'ol';
+import { Map, View } from 'ol';
import BaseEvent from 'ol/events/Event';
+import GeoJSON from 'ol/format/GeoJSON';
import { unByKey } from 'ol/Observable';
-import { toLonLat } from 'ol/proj';
+import { toLonLat, transformExtent } from 'ol/proj';
import { debounce } from 'lodash-es';
-import { fitMapToCharts } from '../util/mapUtil';
+import { fitMapToData } from '../util/mapUtil';
import { ChartLayer } from './ChartLayer';
import { createLayer } from '../util/layerUtil';
import {
ChartConfig,
LayerConf,
+ MapMaxExtentConfigs,
MapViewConfigs,
OlChartMapProps,
} from '../types';
import { isChartConfigEqual } from '../util/chartUtil';
+import {
+ getExtentFromFeatures,
+ getMapExtentPadding,
+} from '../util/geometryUtil';
+
+/**
+ * Computes a transformed extent from a MapMaxExtentConfigs (if CUSTOM mode)
+ * and applies it by setting a new view on the map.
+ */
+const applyMapExtentView = (
+ olMap: Map,
+ mapMaxExtentConf: MapMaxExtentConfigs,
+) => {
+ const { extentMode, fixedMaxX, fixedMaxY, fixedMinX, fixedMinY } =
+ mapMaxExtentConf;
+ const view = olMap.getView();
+ const center = view.getCenter();
+ const zoom = view.getZoom();
+ let extent;
+
+ if (
+ extentMode === 'CUSTOM' &&
+ fixedMaxX !== undefined &&
+ fixedMaxY !== undefined &&
+ fixedMinX !== undefined &&
+ fixedMinY !== undefined
+ ) {
+ extent = transformExtent(
+ [fixedMinX, fixedMinY, fixedMaxX, fixedMaxY],
+ 'EPSG:4326',
+ 'EPSG:3857',
+ );
+ }
+
+ olMap.setView(
Review Comment:
Yes, that will likely lead to inconsistencies. I adjusted so the we now use
the eventlisteners of the map instance, which will not be recreated. So
recreating the view does not affect the listeners any more.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]