Skip to content

Commit

Permalink
feat: upgrade @Turf to v7 and remove geo utils (#478)
Browse files Browse the repository at this point in the history
* feat: remove getOrCalculateVisibleRegion
* refactor: replace geoUtils with direct usage
* feat: upgrade to @Turf v7
* refactor: use GeoJSON types
* docs: generate
* chore: update CHANGELOG
  • Loading branch information
KiwiKilian authored Oct 26, 2024
1 parent b381e66 commit a45fc55
Show file tree
Hide file tree
Showing 18 changed files with 214 additions and 341 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ PR Title ([#123](link to my pr))
```

feat: upgrade @turf to v7 and remove geo utils ([#478](https://github.com/maplibre/maplibre-react-native/pull/478))

## 10.0.0-alpha.22

chore: configure jest to use with ts
Expand Down
13 changes: 4 additions & 9 deletions __tests__/modules/snapshot/SnapshotOptions.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { featureCollection, point } from "@turf/helpers";
import { NativeModules } from "react-native";

import SnapshotOptions from "../../../javascript/modules/snapshot/SnapshotOptions";
import {
makePoint,
makeFeatureCollection,
} from "../../../javascript/utils/geoUtils";

describe("SnapshotOptions", () => {
it("should throw error if no centerCoordinate or bounds are provided", () => {
Expand All @@ -24,7 +21,7 @@ describe("SnapshotOptions", () => {
width: 50.0,
height: 50.0,
writeToDisk: false,
centerCoordinate: JSON.stringify(makePoint(centerCoordinate)),
centerCoordinate: JSON.stringify(point(centerCoordinate)),
withLogo: true,
});
});
Expand All @@ -45,9 +42,7 @@ describe("SnapshotOptions", () => {
const options = new SnapshotOptions(expectedOptions);
expect(options.toJSON()).toEqual({
...expectedOptions,
centerCoordinate: JSON.stringify(
makePoint(expectedOptions.centerCoordinate),
),
centerCoordinate: JSON.stringify(point(expectedOptions.centerCoordinate)),
});
});

Expand All @@ -65,7 +60,7 @@ describe("SnapshotOptions", () => {
};

const geoJSONBounds = JSON.stringify(
makeFeatureCollection(expectedOptions.bounds.map((c) => makePoint(c))),
featureCollection(expectedOptions.bounds.map((c) => point(c))),
);

const options = new SnapshotOptions(expectedOptions);
Expand Down
6 changes: 3 additions & 3 deletions docs/ShapeSource.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ Returns the zoom needed to expand the cluster.
##### arguments
| Name | Type | Required | Description |
| ---- | :--: | :------: | :----------: |
| `feature` | `Feature` | `Yes` | The feature cluster to expand. |
| `feature` | `GeoJSON.Feature` | `Yes` | The feature cluster to expand. |



Expand All @@ -66,7 +66,7 @@ Returns the FeatureCollection from the cluster.
##### arguments
| Name | Type | Required | Description |
| ---- | :--: | :------: | :----------: |
| `feature` | `Feature` | `Yes` | The feature cluster to expand. |
| `feature` | `GeoJSON.Feature` | `Yes` | The feature cluster to expand. |
| `limit` | `number` | `Yes` | The number of points to return. |
| `offset` | `number` | `Yes` | The amount of points to skip (for pagination). |

Expand All @@ -84,7 +84,7 @@ Returns the FeatureCollection from the cluster (on the next zoom level).
##### arguments
| Name | Type | Required | Description |
| ---- | :--: | :------: | :----------: |
| `feature` | `Feature` | `Yes` | The feature cluster to expand. |
| `feature` | `GeoJSON.Feature` | `Yes` | The feature cluster to expand. |



Expand Down
26 changes: 13 additions & 13 deletions docs/docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -3078,7 +3078,7 @@
"methods": [
{
"name": "features",
"docblock": "Returns all features from the source that match the query parameters regardless of whether or not the feature is\ncurrently rendered on the map.\n\n@example\nshapeSource.features()\n\n@param {Array=} filter - an optional filter statement to filter the returned Features.\n@return {FeatureCollection}",
"docblock": "Returns all features from the source that match the query parameters regardless of whether or not the feature is\ncurrently rendered on the map.\n\n@example\nshapeSource.features()\n\n@param {Array=} filter - an optional filter statement to filter the returned Features.\n@return {GeoJSON.FeatureCollection}",
"modifiers": [
"async"
],
Expand All @@ -3098,10 +3098,10 @@
"name": "Promise",
"elements": [
{
"name": "FeatureCollection"
"name": "GeoJSON.FeatureCollection"
}
],
"raw": "Promise<FeatureCollection>"
"raw": "Promise<GeoJSON.FeatureCollection>"
}
},
"description": "Returns all features from the source that match the query parameters regardless of whether or not the feature is\ncurrently rendered on the map.",
Expand All @@ -3111,7 +3111,7 @@
},
{
"name": "getClusterExpansionZoom",
"docblock": "Returns the zoom needed to expand the cluster.\n\n@example\nconst zoom = await shapeSource.getClusterExpansionZoom(clusterId);\n\n@param {Feature} feature - The feature cluster to expand.\n@return {number}",
"docblock": "Returns the zoom needed to expand the cluster.\n\n@example\nconst zoom = await shapeSource.getClusterExpansionZoom(clusterId);\n\n@param {GeoJSON.Feature} feature - The feature cluster to expand.\n@return {number}",
"modifiers": [
"async"
],
Expand All @@ -3120,7 +3120,7 @@
"name": "feature",
"description": "The feature cluster to expand.",
"type": {
"name": "Feature"
"name": "GeoJSON.Feature"
},
"optional": false
}
Expand All @@ -3144,7 +3144,7 @@
},
{
"name": "getClusterLeaves",
"docblock": "Returns the FeatureCollection from the cluster.\n\n@example\nconst collection = await shapeSource.getClusterLeaves(clusterId, limit, offset);\n\n@param {Feature} feature - The feature cluster to expand.\n@param {number} limit - The number of points to return.\n@param {number} offset - The amount of points to skip (for pagination).\n@return {FeatureCollection}",
"docblock": "Returns the FeatureCollection from the cluster.\n\n@example\nconst collection = await shapeSource.getClusterLeaves(clusterId, limit, offset);\n\n@param {GeoJSON.Feature} feature - The feature cluster to expand.\n@param {number} limit - The number of points to return.\n@param {number} offset - The amount of points to skip (for pagination).\n@return {GeoJSON.FeatureCollection}",
"modifiers": [
"async"
],
Expand All @@ -3153,7 +3153,7 @@
"name": "feature",
"description": "The feature cluster to expand.",
"type": {
"name": "Feature"
"name": "GeoJSON.Feature"
},
"optional": false
},
Expand All @@ -3180,10 +3180,10 @@
"name": "Promise",
"elements": [
{
"name": "FeatureCollection"
"name": "GeoJSON.FeatureCollection"
}
],
"raw": "Promise<FeatureCollection>"
"raw": "Promise<GeoJSON.FeatureCollection>"
}
},
"description": "Returns the FeatureCollection from the cluster.",
Expand All @@ -3193,7 +3193,7 @@
},
{
"name": "getClusterChildren",
"docblock": "Returns the FeatureCollection from the cluster (on the next zoom level).\n\n@example\nconst collection = await shapeSource.getClusterChildren(clusterId);\n\n@param {Feature} feature - The feature cluster to expand.\n@return {FeatureCollection}",
"docblock": "Returns the FeatureCollection from the cluster (on the next zoom level).\n\n@example\nconst collection = await shapeSource.getClusterChildren(clusterId);\n\n@param {GeoJSON.Feature} feature - The feature cluster to expand.\n@return {GeoJSON.FeatureCollection}",
"modifiers": [
"async"
],
Expand All @@ -3202,7 +3202,7 @@
"name": "feature",
"description": "The feature cluster to expand.",
"type": {
"name": "Feature"
"name": "GeoJSON.Feature"
},
"optional": false
}
Expand All @@ -3213,10 +3213,10 @@
"name": "Promise",
"elements": [
{
"name": "FeatureCollection"
"name": "GeoJSON.FeatureCollection"
}
],
"raw": "Promise<FeatureCollection>"
"raw": "Promise<GeoJSON.FeatureCollection>"
}
},
"description": "Returns the FeatureCollection from the cluster (on the next zoom level).",
Expand Down
14 changes: 7 additions & 7 deletions javascript/components/Camera.tsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
import { point } from "@turf/helpers";
import React, {
memo,
RefObject,
useCallback,
useEffect,
useImperativeHandle,
useMemo,
useRef,
useCallback,
} from "react";
import { NativeModules, requireNativeComponent, ViewProps } from "react-native";

import { useNativeRef } from "../hooks/useNativeRef";
import { MaplibreGLEvent } from "../types";
import { toJSONString } from "../utils";
import * as geoUtils from "../utils/geoUtils";
import { makeNativeBounds } from "../utils/makeNativeBounds";

const MapLibreGL = NativeModules.MLNModule;

Expand Down Expand Up @@ -334,14 +334,14 @@ const Camera = memo(
};

if (config.centerCoordinate) {
stopConfig.centerCoordinate = toJSONString(
geoUtils.makePoint(config.centerCoordinate),
stopConfig.centerCoordinate = JSON.stringify(
point(config.centerCoordinate),
);
}

if (config.bounds && config.bounds.ne && config.bounds.sw) {
const { ne, sw } = config.bounds;
stopConfig.bounds = toJSONString(geoUtils.makeLatLngBounds(ne, sw));
stopConfig.bounds = makeNativeBounds(ne, sw);
}

return stopConfig;
Expand Down Expand Up @@ -377,7 +377,7 @@ const Camera = memo(
if (!bounds || !bounds.ne || !bounds.sw) {
return null;
}
return toJSONString(geoUtils.makeLatLngBounds(bounds.ne, bounds.sw));
return makeNativeBounds(bounds.ne, bounds.sw);
}, [props.maxBounds]);

useEffect(() => {
Expand Down
4 changes: 2 additions & 2 deletions javascript/components/MarkerView.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { point } from "@turf/helpers";
import React, { ReactElement, useMemo } from "react";
import { Platform, requireNativeComponent, ViewProps } from "react-native";

import PointAnnotation from "./PointAnnotation";
import { toJSONString } from "../utils";
import { makePoint } from "../utils/geoUtils";

export const NATIVE_MODULE_NAME = "RCTMLNMarkerView";

Expand Down Expand Up @@ -61,7 +61,7 @@ const MarkerView = ({
}: MarkerViewProps): ReactElement => {
const props = { anchor, allowOverlap, isSelected, ...rest };
const coordinate = props.coordinate
? toJSONString(makePoint(props.coordinate))
? toJSONString(point(props.coordinate))
: undefined;

const idForPointAnnotation = useMemo(() => {
Expand Down
4 changes: 2 additions & 2 deletions javascript/components/PointAnnotation.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { point } from "@turf/helpers";
import React, {
Component,
SyntheticEvent,
Expand All @@ -15,7 +16,6 @@ import {

import useNativeBridge, { RNMLEvent } from "../hooks/useNativeBridge";
import { isFunction, toJSONString } from "../utils";
import { makePoint } from "../utils/geoUtils";

export const NATIVE_MODULE_NAME = "RCTMLNPointAnnotation";

Expand Down Expand Up @@ -200,7 +200,7 @@ const PointAnnotation = forwardRef<PointAnnotationRef, PointAnnotationProps>(
if (!props.coordinate) {
return undefined;
}
return toJSONString(makePoint(props.coordinate));
return toJSONString(point(props.coordinate));
}

const _setNativeRef = (nativeRef: Component<NativeProps> | null): void => {
Expand Down
Loading

0 comments on commit a45fc55

Please sign in to comment.