Skip to content

Commit

Permalink
OpenLayers 9 compatibility (#215)
Browse files Browse the repository at this point in the history
* OpenLayers 9 compatibility

* exchange the test order

* a test that does not depend on strictNullChecks

* fix more typescript types

* adapt the unit tests

* temporary restore the default version

* use the github version

* add ts-ignore

* detect if Options is a generic

* fix older versions

* use the published version
  • Loading branch information
mmomtchev authored Feb 26, 2024
1 parent e015d1a commit c753d26
Show file tree
Hide file tree
Showing 16 changed files with 134 additions and 102 deletions.
1 change: 1 addition & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ jobs:
- '8.0.0'
- '8.1.0'
- '8.2.0'
- '9.0.0'

steps:
- run: echo "::add-mask::${{ secrets.STADIA_MAPS_API_KEY }}"
Expand Down
22 changes: 11 additions & 11 deletions .github/workflows/test-npm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
run: |
cd rlayers-npm-tests/cra-js
npm install
npm i rlayers@${{ github.event.inputs.version }} ol
npm i rlayers@${{ github.event.inputs.version }} ol@9.0.0
npm run build
Expand All @@ -62,7 +62,7 @@ jobs:
run: |
cd rlayers-npm-tests/cra-ts
npm install
npm i rlayers@${{ github.event.inputs.version }} ol
npm i rlayers@${{ github.event.inputs.version }} ol@9.0.0
npm run build
Expand All @@ -76,7 +76,7 @@ jobs:
run: |
cd rlayers-npm-tests/cra-react18-js
npm install
npm i rlayers@${{ github.event.inputs.version }} ol
npm i rlayers@${{ github.event.inputs.version }} ol@9.0.0
npm run build
Expand All @@ -90,7 +90,7 @@ jobs:
run: |
cd rlayers-npm-tests/cra-react18-ts
npm install
npm i rlayers@${{ github.event.inputs.version }} ol
npm i rlayers@${{ github.event.inputs.version }} ol@9.0.0
npm run build
Expand All @@ -104,7 +104,7 @@ jobs:
run: |
cd rlayers-npm-tests/cra-react18-1-js
npm install
npm i rlayers@${{ github.event.inputs.version }} ol
npm i rlayers@${{ github.event.inputs.version }} ol@9.0.0
npm run build
Expand All @@ -118,7 +118,7 @@ jobs:
run: |
cd rlayers-npm-tests/cra-react18-1-ts
npm install
npm i rlayers@${{ github.event.inputs.version }} ol
npm i rlayers@${{ github.event.inputs.version }} ol@9.0.0
npm run build
Expand All @@ -132,7 +132,7 @@ jobs:
run: |
cd rlayers-npm-tests/cra-react18-2-js
npm install
npm i rlayers@${{ github.event.inputs.version }} ol
npm i rlayers@${{ github.event.inputs.version }} ol@9.0.0
npm run build
Expand All @@ -146,7 +146,7 @@ jobs:
run: |
cd rlayers-npm-tests/cra-react18-2-ts
npm install
npm i rlayers@${{ github.event.inputs.version }} ol
npm i rlayers@${{ github.event.inputs.version }} ol@9.0.0
npm run build
Expand All @@ -164,7 +164,7 @@ jobs:
run: |
cd rlayers-npm-tests/next12
npm install
npm i rlayers@${{ github.event.inputs.version }} ol
npm i rlayers@${{ github.event.inputs.version }} ol@9.0.0
npm run build
Expand All @@ -178,7 +178,7 @@ jobs:
run: |
cd rlayers-npm-tests/next13
npm install
npm i rlayers@${{ github.event.inputs.version }} ol
npm i rlayers@${{ github.event.inputs.version }} ol@9.0.0
npm run build
Expand All @@ -192,5 +192,5 @@ jobs:
run: |
cd rlayers-npm-tests/next13-esm
npm install
npm i rlayers@${{ github.event.inputs.version }} ol
npm i rlayers@${{ github.event.inputs.version }} ol@9.0.0
npm run build
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.2.0] 2024-02-26

- Support OpenLayers 9.0.0

## [2.2.0] 2023-11-20

- Support OpenLayers 8.2.0
Expand Down
22 changes: 11 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,17 @@ _React_ is supported from version 16.8.0.

---

| rlayers | Unit-tested _OpenLayers_ versions | Unit-tested _React_ versions |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------- |
| 1.0 (_obsolete_) | 6.0 | 16.8, 16.14, 17.0.2 |
| 1.1 (_obsolete_) | 6.6, 6.7, 6.8, 6.9 | 16.8, 16.14, 17.0.2 |
| 1.2 (_obsolete_) | 6.6, 6.7, 6.8, 6.9 | 16.8, 16.14, 17.0.2 |
| 1.3 (_obsolete_) | 6.10, 6.11, 6.12, 6.13, 6.14, 6.14.1 | 16.8, 16.14, 17.0.2, 18.0.0 |
| 1.4 (_obsolete_) | 6.10, 6.11, 6.12, 6.13, 6.14, 6.14.1, 6.15, 6.15.1, 7.0.0, 7.1.0, 7.2.0, 7.2.2, 7.3.0 | 16.8, 16.14, 17.0.2, 18.0.0, 18.1.0, 18.2.0 |
| 1.5 (_obsolete_) | 6.10, 6.11, 6.12, 6.13, 6.14, 6.14.1, 6.15, 6.15.1, 7.0.0, 7.1.0, 7.2.0, 7.2.2, 7.3.0, 7.4.0 | 16.8, 16.14, 17.0.2, 18.0.0, 18.1.0, 18.2.0 |
| 2.0 | 6.10, 6.11, 6.12, 6.13, 6.14, 6.14.1, 6.15, 6.15.1, 7.0.0, 7.1.0, 7.2.0, 7.2.2, 7.3.0, 7.4.0, 7.5.1 | 16.8, 16.14, 17.0.2, 18.0.0, 18.1.0, 18.2.0 |
| 2.1 `(@latest)` | 6.10, 6.11, 6.12, 6.13, 6.14, 6.14.1, 6.15, 6.15.1, 7.0.0, 7.1.0, 7.2.0, 7.2.2, 7.3.0, 7.4.0, 7.5.1, 8.0.0, 8.1.0 | 16.8, 16.14, 17.0.2, 18.0.0, 18.1.0, 18.2.0 |
| 2.2 `(@next)` | 6.10, 6.11, 6.12, 6.13, 6.14, 6.14.1, 6.15, 6.15.1, 7.0.0, 7.1.0, 7.2.0, 7.2.2, 7.3.0, 7.4.0, 7.5.1, 8.0.0, 8.1.0, 8.2.0 | 16.8, 16.14, 17.0.2, 18.0.0, 18.1.0, 18.2.0 |
| rlayers | Unit-tested _OpenLayers_ versions | Unit-tested _React_ versions |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------- |
| 1.0 (_obsolete_) | 6.0 | 16.8, 16.14, 17.0.2 |
| 1.1 (_obsolete_) | 6.6, 6.7, 6.8, 6.9 | 16.8, 16.14, 17.0.2 |
| 1.2 (_obsolete_) | 6.6, 6.7, 6.8, 6.9 | 16.8, 16.14, 17.0.2 |
| 1.3 (_obsolete_) | 6.10, 6.11, 6.12, 6.13, 6.14, 6.14.1 | 16.8, 16.14, 17.0.2, 18.0.0 |
| 1.4 (_obsolete_) | 6.10, 6.11, 6.12, 6.13, 6.14, 6.14.1, 6.15, 6.15.1, 7.0.0, 7.1.0, 7.2.0, 7.2.2, 7.3.0 | 16.8, 16.14, 17.0.2, 18.0.0, 18.1.0, 18.2.0 |
| 1.5 (_obsolete_) | 6.10, 6.11, 6.12, 6.13, 6.14, 6.14.1, 6.15, 6.15.1, 7.0.0, 7.1.0, 7.2.0, 7.2.2, 7.3.0, 7.4.0 | 16.8, 16.14, 17.0.2, 18.0.0, 18.1.0, 18.2.0 |
| 2.0 | 6.10, 6.11, 6.12, 6.13, 6.14, 6.14.1, 6.15, 6.15.1, 7.0.0, 7.1.0, 7.2.0, 7.2.2, 7.3.0, 7.4.0, 7.5.1 | 16.8, 16.14, 17.0.2, 18.0.0, 18.1.0, 18.2.0 |
| 2.1 `(@latest)` | 6.10, 6.11, 6.12, 6.13, 6.14, 6.14.1, 6.15, 6.15.1, 7.0.0, 7.1.0, 7.2.0, 7.2.2, 7.3.0, 7.4.0, 7.5.1, 8.0.0, 8.1.0 | 16.8, 16.14, 17.0.2, 18.0.0, 18.1.0, 18.2.0 |
| 2.2 `(@next)` | 6.10, 6.11, 6.12, 6.13, 6.14, 6.14.1, 6.15, 6.15.1, 7.0.0, 7.1.0, 7.2.0, 7.2.2, 7.3.0, 7.4.0, 7.5.1, 8.0.0, 8.1.0, 8.2.0, 9.0.0 | 16.8, 16.14, 17.0.2, 18.0.0, 18.1.0, 18.2.0 |

---

Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
"lru-cache": "^7.10.0"
},
"peerDependencies": {
"ol": ">=6.10.0 <=8.2.0",
"ol": ">=6.10.0 <9.1.0",
"react": ">=16.8",
"react-dom": ">=16.8"
},
Expand Down Expand Up @@ -134,8 +134,8 @@
"jest-environment-jsdom": "^29.4.3",
"markdown-loader": "^8.0.0",
"null-loader": "^4.0.1",
"ol": "^8.2.0",
"ol-mbtiles": "^2.0.2",
"ol": "^9.0.0",
"ol-mbtiles": "^2.2.0",
"prettier": "2.8.8",
"prism-themes": "^1.6.0",
"prismjs": "^1.28.0",
Expand Down
1 change: 0 additions & 1 deletion src/RFeature.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import SourceVector from 'ol/source/Vector';
import Geometry from 'ol/geom/Geometry';
import BaseEvent from 'ol/events/Event';
import {getCenter} from 'ol/extent';
import {Layer} from 'ol/layer';

import {OLFeatureClass, RContext, RContextType} from './context';
import {OLEvent, RlayersBase, handlersSymbol} from './REvent';
Expand Down
23 changes: 17 additions & 6 deletions src/context.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import {Map as Map} from 'ol';
import {Map} from 'ol';
import Layer from 'ol/layer/Layer';
import Source from 'ol/source/Source';
import BaseVector from 'ol/layer/BaseVector';
Expand All @@ -15,20 +15,31 @@ import Style from 'ol/style/Style';
import Geometry from 'ol/geom/Geometry';
import LayerRenderer from 'ol/renderer/Layer';
import JSONFeature from 'ol/format/JSONFeature';
import RenderFeature from 'ol/render/Feature';
import {Options as OLVectorTileOptions} from 'ol/source/VectorTile.js';
import {FeatureLike} from 'ol/Feature';

import RMap from './RMap';
import RLayer, {RLayerProps} from './layer/RLayer';
import RLayerBaseVector, {RLayerBaseVectorProps} from './layer/RLayerBaseVector';
import RFeature from './RFeature';
import RLayerVectorTile from './layer/RLayerVectorTile';
import RenderFeature from 'ol/render/Feature';

export const RContext = React.createContext({} as RContextType);

// Detect the new OpenLayers 8.2.0 FeatureClass
export type OLFeatureClass = RenderFeature extends ReturnType<JSONFeature['readFeatures']>[0]
? Feature<Geometry>
: Geometry;
// Check if the type is any
// https://stackoverflow.com/questions/55541275/typescript-check-for-the-any-type
type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;

export type OLFeatureClass =
// Detect the new OpenLayers 8.2.0 FeatureClass
RenderFeature extends ReturnType<JSONFeature['readFeatures']>[0]
? Feature<Geometry>
: // Detect if VectorTileOptions is a generic type
// (works because with @ts-ignore invalid types resolve to any)
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
IfAny<OLVectorTileOptions<FeatureLike>, Geometry, Feature<Geometry>>;

/**
* Context type
Expand Down
12 changes: 8 additions & 4 deletions src/layer/RLayerBaseVector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import FeatureFormat from 'ol/format/Feature';
import {FeatureLoader, FeatureUrlFunction} from 'ol/featureloader';
import Geometry from 'ol/geom/Geometry';
import BaseObject from 'ol/Object';
import {Options as OLVectorTileOptions} from 'ol/source/VectorTile.js';
import {FeatureLike} from 'ol/Feature';

import {OLFeatureClass, RContext, RContextType} from '../context';
import {default as RLayer, RLayerProps} from './RLayer';
Expand All @@ -35,7 +37,7 @@ type OLFeatureType<F extends OLFeatureClass> = RenderFeature extends ReturnType<
F
: // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Feature<F>;
F<Geometry>;

/**
* @propsfor RLayerBaseVector
Expand All @@ -52,7 +54,8 @@ export interface RLayerBaseVectorProps<F extends OLFeatureClass = OLFeatureClass
* this property currently does not support dynamic updates
*/
renderBuffer?: number;
/** OpenLayers features that will be loaded
/**
* OpenLayers features that will be loaded
*
* this property currently does not support dynamic updates
*/
Expand All @@ -66,7 +69,7 @@ export interface RLayerBaseVectorProps<F extends OLFeatureClass = OLFeatureClass
loader?: FeatureLoader;
/** OpenLayers default style for features without `style` */
style?: RStyleLike;
/** OpenLayers option to specify LoadingStrategy default is `all` strategy */
/** OpenLayers option to specify LoadingStrategy default is `all` strategy */
strategy?: LoadingStrategy;
/**
* Wrap features around the antimeridian. Cannot be dynamically updated once the layer is created.
Expand All @@ -78,7 +81,8 @@ export interface RLayerBaseVectorProps<F extends OLFeatureClass = OLFeatureClass
this: RLayerBaseVector<F, RLayerBaseVectorProps<F>>,
e: RFeatureUIEvent
) => boolean | void;
/** Called when a feature is added, not called for features
/**
* Called when a feature is added, not called for features
* already present at creation, ie loaded via `features` or `url`
*
* use onFeaturesLoadEnd for features loaded via `url`
Expand Down
4 changes: 1 addition & 3 deletions src/layer/RLayerCluster.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import React from 'react';
import {Map, Feature} from 'ol';
import {Vector as LayerVector} from 'ol/layer';
import {Vector as SourceVector, Cluster as SourceCluster} from 'ol/source';
import Geometry from 'ol/geom/Geometry';
import BaseObject from 'ol/Object';

import {OLFeatureClass, RContext, RContextType} from '../context';
Expand Down Expand Up @@ -35,7 +33,7 @@ export default class RLayerCluster<
cluster: SourceVector<OLFeatureClass>;

protected createSource(props: Readonly<RLayerClusterProps>): BaseObject[] {
this.cluster = new SourceVector({
this.cluster = new SourceVector<OLFeatureClass>({
features: this.props.features,
url: this.props.url,
format: this.props.format,
Expand Down
7 changes: 6 additions & 1 deletion src/layer/RLayerHeatmap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,20 @@ import {Heatmap as LayerHeatmap} from 'ol/layer';
import {Vector as SourceVector} from 'ol/source';
import BaseObject from 'ol/Object';
import {Point} from 'ol/geom';
import {Options as OLVectorTileOptions} from 'ol/source/VectorTile.js';
import {FeatureLike} from 'ol/Feature';

import {default as RLayerBaseVector, RLayerBaseVectorProps} from './RLayerBaseVector';
import RenderFeature from 'ol/render/Feature';
import JSONFeature from 'ol/format/JSONFeature';

type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
// Detect the new OpenLayers 8.2.0 FeatureClass
type OLFeaturePoint = RenderFeature extends ReturnType<JSONFeature['readFeatures']>[0]
? Feature<Point>
: Point;
: // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
IfAny<OLVectorTileOptions<FeatureLike>, Point, Feature<Point>>;

/**
* @propsfor RLayerHeatmap
Expand Down
2 changes: 1 addition & 1 deletion src/layer/RLayerVector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default class RLayerVector<
source: SourceVector<F>;

protected createSource(props: Readonly<RLayerBaseVectorProps<F>>): BaseObject[] {
this.source = new SourceVector({
this.source = new SourceVector<F>({
features: this.props.features,
url: this.props.url,
format: this.props.format,
Expand Down
11 changes: 8 additions & 3 deletions src/layer/RLayerVectorTile.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
import React from 'react';
import {VectorTile as LayerVectorTile} from 'ol/layer';
import {VectorTile as SourceVectorTile} from 'ol/source';
import type {Options} from 'ol/source/VectorTile';
import type {Options as OLOptions} from 'ol/source/VectorTile';
import FeatureFormat from 'ol/format/Feature';

import {RContext, RContextType} from '../context';
import {OLFeatureClass, RContext, RContextType} from '../context';
import {default as RLayer, RLayerProps} from './RLayer';
import {default as RFeature, RFeatureUIEvent} from '../RFeature';
import {OLEvent, RlayersBase} from '../REvent';
import {FeatureHandlers, featureHandlersSymbol} from './RLayerBaseVector';
import RStyle, {RStyleLike} from '../style/RStyle';
import debug from '../debug';

type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
type Options = IfAny<OLOptions<OLFeatureClass>, OLOptions, OLOptions<OLFeatureClass>>;

/**
* @propsfor RLayerVectorTile
*/
Expand All @@ -34,7 +39,7 @@ export interface RLayerVectorTileProps extends RLayerProps {
* this property currently does not support dynamic updates
*/
renderBuffer?: number;
/* vector tile specific source options */
/* vector tile specific source Options */
extent?: Options['extent'];
overlaps?: Options['overlaps'];
state?: Options['state'];
Expand Down
2 changes: 1 addition & 1 deletion src/style/RRegularShape.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import debug from '../debug';
*/
export interface RRegularShapeProps extends RRegularBaseProps {
/** Outer radius */
radius1?: number;
radius: number;
/** Inner radius */
radius2?: number;
/** Number of points/edges */
Expand Down
1 change: 0 additions & 1 deletion src/style/RStyle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import Style, {StyleLike} from 'ol/style/Style';
import Geometry from 'ol/geom/Geometry';

import {RContext, RContextType} from '../context';
import {RlayersBase} from '../REvent';
import debug from '../debug';

/**
Expand Down
Loading

0 comments on commit c753d26

Please sign in to comment.