Skip to content

Commit

Permalink
Revert "feat: add onFeatureClick callback to map"
Browse files Browse the repository at this point in the history
This reverts commit 1e38008.
  • Loading branch information
etienneburdet committed Dec 26, 2024
1 parent 1e38008 commit b88936c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
$: sources = getMapSources(data.sources);
$: layers = getMapLayers(data.layers);
$: popupConfigurationByLayers = getPopupConfigurationByLayers(data.layers);
let container: HTMLElement;
const map = new Map();
Expand All @@ -54,7 +55,6 @@
$: map.setPopupConfigurationByLayers(popupConfigurationByLayers);
$: map.jumpTo(getCenterZoomOptions({ zoom, center: $center }));
$: map.loadImages(images);
$: map.updateClickHandler(options?.onFeatureClick);
// Lifecycle
onMount(() => {
Expand Down
30 changes: 2 additions & 28 deletions packages/visualizations/src/components/Map/WebGl/WebGl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ import type {
CenterZoomOptions,
PopupDisplayTypes,
Images,
OnFeatureClick,
} from './types';

const CURSOR = {
Expand Down Expand Up @@ -107,9 +106,6 @@ export default class MapPOI {
/** An array of functions to be executed when the map is ready. */
private queuedFunctions: Array<MapFunction> = [];

/** Additional custom click handler */
private onFeatureClick: OnFeatureClick | null = null;

/** To queue functions that depend on map readiness. Will be executed when the card is ready. */
private queue(fn: MapFunction) {
if (this.isReady && this.map) return fn(this.map);
Expand Down Expand Up @@ -244,9 +240,6 @@ export default class MapPOI {
private onMapClick({ point }: MapLayerMouseEvent) {
this.queue((map) => {
this.handlePopupAfterMapClick(map, point);
if (this?.onFeatureClick) {
this.handleCustomFeatureClick(map, point, this.onFeatureClick);
}
});
}

Expand Down Expand Up @@ -399,20 +392,6 @@ export default class MapPOI {
});
}

private handleCustomFeatureClick(
map: Map,
point: MapMouseEvent['point'],
onFeatureClick: OnFeatureClick
) {
/*
* Get features close to the click area.
* We ask for features that are not in base style layers and for which a popup config is defined.
*/
const { callback, layers } = onFeatureClick;
const features = map.queryRenderedFeatures(point, { layers });
return callback(features);
}

/**
* Is triggered when a click has been made on the map.
* Is responsible for opening and closing the popup.
Expand All @@ -430,7 +409,7 @@ export default class MapPOI {
*/
private handlePopupAfterMapClick(map: Map, point: MapMouseEvent['point']) {
/*
* Get features close to the click area.
* Get features closed to the click area.
* We ask for features that are not in base style layers and for which a popup config is defined.
*/
const features = map.queryRenderedFeatures(point, {
Expand Down Expand Up @@ -511,6 +490,7 @@ export default class MapPOI {
options: Omit<MapOptions, 'style' | 'container'>
) {
this.map = new MaplibreGl.Map({ style, container, ...options });

this.queue((map) => this.initializeMapResizer(map, container));
this.queue((map) => this.initializeCursorBehavior(map));

Expand Down Expand Up @@ -593,12 +573,6 @@ export default class MapPOI {
});
}

updateClickHandler(handler?: OnFeatureClick) {
if (handler) {
this.onFeatureClick = handler;
}
}

/**
* Changes any combination of center and zoom without an animated transition.
* The map will retain its current values for any details not specified in options
Expand Down
8 changes: 0 additions & 8 deletions packages/visualizations/src/components/Map/WebGl/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import type {
GeoJSONFeature,
GestureOptions,
LngLatLike,
MapGeoJSONFeature,
RequestTransformFunction,
StyleImageMetadata,
StyleSpecification,
Expand All @@ -20,11 +19,6 @@ export type WebGlMapData = Partial<{
layers: Layer[];
}>;

export type FeatureClickHandler = (f: MapGeoJSONFeature[]) => void;
export type OnFeatureClick = {
callback: FeatureClickHandler;
layers: string[];
};
export interface WebGlMapOptions {
/*
* To render a basemap. Could be:
Expand Down Expand Up @@ -58,8 +52,6 @@ export interface WebGlMapOptions {
preserveDrawingBuffer?: boolean;
/** Images to load by the Map. keys are image ids */
images?: Images;
/** An addiational callback to be triggered when clicking a feature */
onFeatureClick?: OnFeatureClick;
}

export type WebGlMapStyleOption = Partial<Pick<StyleSpecification, 'sources' | 'layers'>>;
Expand Down

1 comment on commit b88936c

@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.71%

Coverage Report
FileStmtsBranchesFuncsLinesUncovered Lines
src
   index.ts100%100%100%100%
src/client
   constants.ts100%100%100%100%
   error.ts100%100%100%100%
   index.ts84.14%74.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%100%
src/odsql
   clauses.ts82.61%71.43%80%90.91%14, 32, 42
   index.ts92.05%83.72%95.74%94.19%111, 146, 25, 28, 56–57, 57, 57–58, 68, 78–79

Please sign in to comment.