Skip to content

Commit

Permalink
fix more typescript types
Browse files Browse the repository at this point in the history
  • Loading branch information
mmomtchev committed Feb 26, 2024
1 parent 4def633 commit d2fbf26
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 22 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
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.1.0",
"prettier": "2.8.8",
"prism-themes": "^1.6.0",
"prismjs": "^1.28.0",
Expand Down
13 changes: 9 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 @@ -26,6 +28,7 @@ import JSONFeature from 'ol/format/JSONFeature';
export const featureHandlersSymbol = '_rlayers_feature_handlers';
export type FeatureHandlers = Record<OLEvent, number>;

type IfAny<T, Y, N> = 0 extends 1 & T ? Y : N;
// This is very hackish, maybe it is time to drop older OpenLayers versions
type OLFeatureType<F extends OLFeatureClass> = RenderFeature extends ReturnType<
JSONFeature['readFeatures']
Expand All @@ -35,7 +38,7 @@ type OLFeatureType<F extends OLFeatureClass> = RenderFeature extends ReturnType<
F
: // eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
Feature<F>;
IfAny<OLVectorTileOptions<FeatureLike>, Geometry, F<Geometry>>;

/**
* @propsfor RLayerBaseVector
Expand All @@ -52,7 +55,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 +70,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 +82,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
2 changes: 1 addition & 1 deletion src/layer/RLayerCluster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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
5 changes: 4 additions & 1 deletion src/layer/RLayerHeatmap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ 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;
: 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
24 changes: 12 additions & 12 deletions src/layer/RLayerVectorTile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {VectorTile as SourceVectorTile} from 'ol/source';
import type {Options} 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';
Expand Down Expand Up @@ -34,17 +34,17 @@ export interface RLayerVectorTileProps extends RLayerProps {
* this property currently does not support dynamic updates
*/
renderBuffer?: number;
/* vector tile specific source options */
extent?: Options['extent'];
overlaps?: Options['overlaps'];
state?: Options['state'];
tileClass?: Options['tileClass'];
tileSize?: Options['tileSize'];
tileGrid?: Options['tileGrid'];
tileLoadFunction?: Options['tileLoadFunction'];
tileUrlFunction?: Options['tileUrlFunction'];
transition?: Options['transition'];
zDirection?: Options['zDirection'];
/* vector tile specific source Options<OLFeatureClass> */
extent?: Options<OLFeatureClass>['extent'];
overlaps?: Options<OLFeatureClass>['overlaps'];
state?: Options<OLFeatureClass>['state'];
tileClass?: Options<OLFeatureClass>['tileClass'];
tileSize?: Options<OLFeatureClass>['tileSize'];
tileGrid?: Options<OLFeatureClass>['tileGrid'];
tileLoadFunction?: Options<OLFeatureClass>['tileLoadFunction'];
tileUrlFunction?: Options<OLFeatureClass>['tileUrlFunction'];
transition?: Options<OLFeatureClass>['transition'];
zDirection?: Options<OLFeatureClass>['zDirection'];
/** onClick handler for loaded features */
onClick?: (this: RLayerVectorTile, e: RFeatureUIEvent) => boolean | void;
/** onPointerMove handler for loaded features */
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

0 comments on commit d2fbf26

Please sign in to comment.