Skip to content

Commit

Permalink
Use any to keep the support for OL < 10.
Browse files Browse the repository at this point in the history
  • Loading branch information
ismailsunni committed Aug 12, 2024
1 parent f14bbc7 commit e4d2885
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
53 changes: 37 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"eslint-config-prettier": "9.1.0",
"eslint-plugin-prettier": "5.2.1",
"gh-pages": "6.1.1",
"ol": "^10.0.0",
"ol": "^9.0.0",
"prettier": "^3.3.3",
"typedoc": "0.26.5",
"typescript": "5.5.4"
Expand Down
9 changes: 4 additions & 5 deletions src/MFPEncoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ import VectorEncoder from './VectorEncoder';
import {toContext} from 'ol/render.js';
import LayerGroup from 'ol/layer/Group';
import VectorContext from 'ol/render/VectorContext';
import type {Feature} from 'ol';
import VectorSource from 'ol/source/Vector';
import { VectorTile } from 'ol/source';

export interface EncodeMapOptions {
map: Map;
Expand Down Expand Up @@ -309,7 +306,8 @@ export default class MFPBaseEncoder {
printResolution: number,
customizer: BaseCustomizer,
): Promise<MFPLayer[] | MFPLayer | null> {
const layer = layerState.layer as VectorTileLayer<VectorTile<Feature>>;
// VectorTile<Feature> for OL 10.0.0, any to support OL < 10
const layer = layerState.layer as VectorTileLayer<any>;
const {MVTEncoder} = await import('@geoblocks/print');
const encoder = new MVTEncoder();
const printExtent = customizer.getPrintExtent();
Expand Down Expand Up @@ -353,7 +351,8 @@ export default class MFPBaseEncoder {
customizer: BaseCustomizer,
additionalDraw: (cir: VectorContext, geometry: Geometry) => void,
): Promise<MFPImageLayer> {
const layer = layerState.layer as VectorLayer<VectorSource<Feature>>;
// VectorSource<Feature> for OL 10.0.0, any to support OL < 10
const layer = layerState.layer as VectorLayer<any>;
const printExtent = customizer.getPrintExtent();
const width = getExtentWidth(printExtent) / resolution;
const height = getExtentHeight(printExtent) / resolution;
Expand Down
9 changes: 6 additions & 3 deletions src/VectorEncoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import {Constants} from './constants';

import {getFontParameters} from 'ol/css.js';
import {type ColorLike} from 'ol/colorlike';
import { Geometry } from 'ol/geom';

/** Represents the different types of printing styles. */
export const PrintStyleType = {
Expand Down Expand Up @@ -85,15 +86,17 @@ const styleKey = (styles: string | string[]): string => {
*/
export default class VectorEncoder {
private layerState_: State;
private layer_: VectorLayer<VectorSource<Feature>>;
// VectorSource<Feature> for OL 10.0.0, any to support OL < 10
private layer_: VectorLayer<any>;
private customizer_: BaseCustomizer;
private geojsonFormat = new olFormatGeoJSON();
private deepIds_: Map<string, number> = new Map();
private lastDeepId_ = 0;

constructor(layerState: State, customizer: BaseCustomizer) {
this.layerState_ = layerState;
this.layer_ = this.layerState_.layer as VectorLayer<VectorSource<Feature>>;
// VectorSource<Feature> for OL 10.0.0, any to support OL < 10
this.layer_ = this.layerState_.layer as VectorLayer<any>;
this.customizer_ = customizer;
}

Expand All @@ -115,7 +118,7 @@ export default class VectorEncoder {
version: 2,
};

features.forEach((feature) =>
features.forEach((feature: Feature<Geometry>) =>
this.encodeFeature(feature, resolution, geojsonFeatures, mapfishStyleObject),
);

Expand Down

0 comments on commit e4d2885

Please sign in to comment.