Skip to content

Commit bd999a4

Browse files
authored
Merge pull request #477 from performant-software/feature/cdp139_map_clustering
CDP #139 - Map clustering
2 parents 41468b5 + 232e0a4 commit bd999a4

File tree

5 files changed

+36
-27
lines changed

5 files changed

+36
-27
lines changed

packages/core-data/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@
4747
"peerDependencies": {
4848
"@performant-software/geospatial": "^2.3.8",
4949
"@performant-software/shared-components": "^2.3.8",
50-
"@peripleo/maplibre": "^0.5.2",
51-
"@peripleo/peripleo": "^0.5.2",
50+
"@peripleo/maplibre": "^0.8.7",
51+
"@peripleo/peripleo": "^0.8.7",
5252
"react": ">= 16.13.1 < 19.0.0",
5353
"react-dom": ">= 16.13.1 < 19.0.0"
5454
},

packages/core-data/src/components/SearchResultsLayer.js

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@
22

33
import { LocationMarkers, Map as MapUtils } from '@performant-software/geospatial';
44
import { useMap } from '@peripleo/maplibre';
5-
import React, { useEffect, useMemo, useState } from 'react';
6-
import _ from 'underscore';
7-
import TypesenseUtils from '../utils/Typesense';
8-
import { useCachedHits, useSearching } from '../hooks/Typesense';
5+
import React, { useEffect, useState } from 'react';
96

107
type Props = {
118
/**
@@ -23,6 +20,11 @@ type Props = {
2320
*/
2421
buffer?: number,
2522

23+
/**
24+
* The GeoJSON data representing the location.
25+
*/
26+
data: { [key: string]: any },
27+
2628
/**
2729
* If `true`, the map will fit the bounding box around the passed data.
2830
*/
@@ -32,6 +34,11 @@ type Props = {
3234
* Path to the geometry attribute for each result.
3335
*/
3436
geometry: string,
37+
38+
/**
39+
* If `true`, the bounding box will not be fit.
40+
*/
41+
searching?: boolean
3542
};
3643

3744
/**
@@ -40,37 +47,26 @@ type Props = {
4047
const SearchResultsLayer = (props: Props) => {
4148
const [mapLoaded, setMapLoaded] = useState(false);
4249

43-
const hits = useCachedHits();
4450
const map = useMap();
45-
const isSearching = useSearching();
46-
47-
/**
48-
* Memo-ize the Typesense hits as a feature collection.
49-
*
50-
* @type {unknown}
51-
*/
52-
const data = useMemo(() => (
53-
!_.isEmpty(hits) && TypesenseUtils.toFeatureCollection(hits, props.geometry)
54-
), [hits, props.geometry]);
5551

5652
/**
5753
* Here we'll implement our own fitting of the bounding box once the search has completed and the map has loaded,
5854
* rather than using the default implementation in LocationMarker that will change when the "data" prop changes.
5955
*/
6056
const boundingBoxDependencies = [
61-
data,
6257
mapLoaded,
63-
isSearching,
6458
props.boundingBoxData,
6559
props.boundingBoxOptions,
6660
props.buffer,
67-
props.fitBoundingBox
61+
props.data,
62+
props.fitBoundingBox,
63+
props.searching
6864
];
6965

7066
useEffect(() => {
71-
if (props.fitBoundingBox && data && mapLoaded && !isSearching) {
67+
if (props.fitBoundingBox && props.data && mapLoaded && !props.searching) {
7268
// Set the bounding box on the map
73-
const bbox = MapUtils.getBoundingBox(data, props.buffer);
69+
const bbox = MapUtils.getBoundingBox(props.data, props.buffer);
7470

7571
if (bbox) {
7672
map.fitBounds(bbox, props.boundingBoxOptions, props.boundingBoxData);
@@ -94,14 +90,14 @@ const SearchResultsLayer = (props: Props) => {
9490
};
9591
}, [map]);
9692

97-
if (!data) {
93+
if (!props.data) {
9894
return null;
9995
}
10096

10197
return (
10298
<LocationMarkers
10399
{...props}
104-
data={data}
100+
data={props.data}
105101
fitBoundingBox={false}
106102
/>
107103
);

packages/core-data/src/utils/Typesense.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import TypesenseInstantsearchAdapter from 'typesense-instantsearch-adapter';
77
import _ from 'underscore';
88
import type { TypesenseSearchResult } from '../types/typesense/SearchResult';
99

10+
type Options = {
11+
type?: string
12+
};
13+
1014
type TypesenseConfig = {
1115
api_key: string,
1216
host: string,
@@ -174,10 +178,11 @@ const toFeature = (record: any, item: any, geometry: any) => {
174178
*
175179
* @param results
176180
* @param path
181+
* @param options
177182
*
178183
* @returns {FeatureCollection<Geometry, Properties>}
179184
*/
180-
const toFeatureCollection = (results: Array<any>, path: string) => {
185+
const toFeatureCollection = (results: Array<any>, path: string, options: Options = {}) => {
181186
const features = [];
182187

183188
const objectPath = path.substring(0, path.lastIndexOf(ATTRIBUTE_DELIMITER));
@@ -193,7 +198,9 @@ const toFeatureCollection = (results: Array<any>, path: string) => {
193198
_.each(geometryObjects, (geometryObject) => {
194199
const geometry = _.get(geometryObject, geometryPath);
195200

196-
if (geometry) {
201+
const include = geometry && (!options.type || geometry.type === options.type);
202+
203+
if (include) {
197204
const record = _.find(features, (f) => f.properties?.uuid === geometryObject.uuid);
198205

199206
if (record) {

packages/geospatial/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"underscore": "^1.13.6"
3030
},
3131
"peerDependencies": {
32-
"@peripleo/maplibre": "^0.5.1",
32+
"@peripleo/maplibre": "^0.8.7",
3333
"react": ">= 16.13.1 < 19.0.0",
3434
"react-dom": ">= 16.13.1 < 19.0.0"
3535
},

packages/geospatial/src/components/LocationMarkers.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ type Props = {
6868
*/
6969
fitBoundingBox?: boolean,
7070

71+
/**
72+
* If `true`, the selection and hover state will apply to the layer.
73+
*/
74+
interactive?: boolean,
75+
7176
/**
7277
* An ID value to apply to the layer.
7378
*/
@@ -133,6 +138,7 @@ const LocationMarkers = (props: Props) => {
133138
data={props.data}
134139
fillStyle={props.fillStyle}
135140
id={props.layerId}
141+
interactive={props.interactive}
136142
strokeStyle={props.strokeStyle}
137143
pointStyle={props.pointStyle}
138144
/>

0 commit comments

Comments
 (0)