Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable linting #1136

Merged
merged 3 commits into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.d.ts
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,9 @@ jobs:
- uses: actions/setup-node@v3
with:
node-version: 18
- name: CI
run: npm ci
- name: Lint
run: npm run lint
- name: Pseudo release
run: buildtools/release.sh
4 changes: 2 additions & 2 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
"build-umd": "cross-env NODE_ENV=production TARGET=umd webpack --progress --bail",
"start": "cross-env DEV_SERVER=1 NODE_ENV=development TARGET=examples webpack serve --port 3000 --progress --bail --static-directory .",
"typecheck": "tsc --pretty",
"lint": "eslint src",
"doc": "typedoc --name ol-cesium --excludeExternals --out dist/apidoc --entryPoints src/index.library.js --tsconfig ./tsconfig.json"
},
"main": "./dist/olcesium.js",
Expand Down
2 changes: 1 addition & 1 deletion src/olcs/AbstractSynchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ abstract class AbstractSynchronizer<T extends ImageryLayer | VectorLayerCounterp
/**
* Map of listen keys for OpenLayers layer layers ids (from getUid).
*/
protected olLayerListenKeys: Record<string, Array<EventsKey>> = {};
protected olLayerListenKeys: Record<string, Array<EventsKey>> = {};
/**
* Map of listen keys for OpenLayers layer groups ids (from getUid).
*/
Expand Down
20 changes: 10 additions & 10 deletions src/olcs/OLCesium.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const BoundingSphereState: Record<string, number> = {
* The BoundingSphere does not exist.
*/
FAILED: 2,
}
};

type SceneOptions = {
canvas: HTMLCanvasElement;
Expand Down Expand Up @@ -130,7 +130,7 @@ class OLCesium {
constructor(options: OLCesiumOptions) {
this.map_ = options.map;

this.time_ = options.time || function () {
this.time_ = options.time || function() {
return Cesium.JulianDate.now();
};

Expand Down Expand Up @@ -176,10 +176,10 @@ class OLCesium {
this.canvas_.style['imageRendering'] = imageRenderingValue();
}

this.canvas_.oncontextmenu = function () {
this.canvas_.oncontextmenu = function() {
return false;
};
this.canvas_.onselectstart = function () {
this.canvas_.onselectstart = function() {
return false;
};

Expand Down Expand Up @@ -382,7 +382,7 @@ class OLCesium {

this.canvas_.width = width;
this.canvas_.height = height;
(<PerspectiveFrustum>this.scene_.camera.frustum).aspectRatio = width / height;
(<PerspectiveFrustum> this.scene_.camera.frustum).aspectRatio = width / height;
}

getCamera(): olcsCamera {
Expand Down Expand Up @@ -440,14 +440,14 @@ class OLCesium {

this.map_.addInteraction = interaction => this.pausedInteractions_.push(interaction);
this.map_.removeInteraction = (interaction) => {
let interactionRemoved = false
let interactionRemoved = false;
this.pausedInteractions_ = this.pausedInteractions_.filter((i) => {
const removed = i !== interaction;
if(!interactionRemoved) interactionRemoved = removed
return removed
})
if (!interactionRemoved) {interactionRemoved = removed;}
return removed;
});
return interactionRemoved ? interaction : undefined;
}
};

const rootGroup = this.map_.getLayerGroup();
if (rootGroup.getVisible()) {
Expand Down
8 changes: 4 additions & 4 deletions src/olcs/RasterSynchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,10 @@ class RasterSynchronizer extends olcsAbstractSynchronizer<ImageryLayer> {

const ip = csObj.imageryProvider;
if (ip) {
// @ts-ignore TS2341
ip.tileCache?.clear();
// @ts-ignore TS2341
ip.styleFunction_ = currentStyleFunction;
// @ts-ignore TS2341
ip.tileCache?.clear();
// @ts-ignore TS2341
ip.styleFunction_ = currentStyleFunction;
}
}
this.scene.requestRender();
Expand Down
4 changes: 2 additions & 2 deletions src/olcs/VectorSynchronizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {Primitive, PrimitiveCollection, Scene} from 'cesium';

class VectorSynchronizer extends olcsAbstractSynchronizer<VectorLayerCounterpart> {
protected converter: olcsFeatureConverter;
private csAllPrimitives_: PrimitiveCollection
private csAllPrimitives_: PrimitiveCollection;
/**
* Unidirectionally synchronize OpenLayers vector layers to Cesium.
*/
Expand All @@ -36,7 +36,7 @@ class VectorSynchronizer extends olcsAbstractSynchronizer<VectorLayerCounterpart

addCesiumObject(counterpart: VectorLayerCounterpart) {
console.assert(counterpart);
const collection = <PrimitiveCollectionCounterpart>counterpart.getRootPrimitive()
const collection = <PrimitiveCollectionCounterpart>counterpart.getRootPrimitive();
collection.counterpart = counterpart;
this.csAllPrimitives_.add(counterpart.getRootPrimitive());
}
Expand Down
6 changes: 3 additions & 3 deletions src/olcs/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ export function sourceToImageryProvider(
source.getImageExtent()[2],
source.getImageExtent()[3],
new Cesium.Rectangle()
)
);
provider = new Cesium.SingleTileImageryProvider({
url: source.getUrl(),
rectangle
Expand Down Expand Up @@ -456,7 +456,7 @@ export function sourceToImageryProvider(
* Creates Cesium.ImageryLayer best corresponding to the given ol.layer.Layer.
* Only supports raster layers and export function images
*/
export function tileLayerToImageryLayer(olMap: Map, olLayer: BaseLayer, viewProj: Projection): ImageryLayer | null {
export function tileLayerToImageryLayer(olMap: Map, olLayer: BaseLayer, viewProj: Projection): ImageryLayer | null {

if (!(olLayer instanceof olLayerTile) && !(olLayer instanceof olLayerImage) &&
!(olLayer instanceof VectorTileLayer)) {
Expand Down Expand Up @@ -784,7 +784,7 @@ export function calcResolutionForDistance(distance: number, latitude: number, sc
*/
export function limitCameraToBoundingSphere(camera: Camera, boundingSphere: BoundingSphere, ratio: (height: number) => number): () => void {
let blockLimiter = false;
return function () {
return function() {
if (!blockLimiter) {
const position = camera.position;
const carto = Cesium.Cartographic.fromCartesian(position);
Expand Down
5 changes: 2 additions & 3 deletions src/olcs/core/VectorLayerCounterpart.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,9 @@ export type OlFeatureToCesiumContext = {
primitives: PrimitiveCollection
};

export type PrimitiveCollectionCounterpart = PrimitiveCollection & {counterpart: VectorLayerCounterpart};


class VectorLayerCounterpart {
olListenKeys: EventsKey[] = []
olListenKeys: EventsKey[] = [];
context: OlFeatureToCesiumContext;
private rootCollection_: PrimitiveCollection;
/**
Expand Down Expand Up @@ -57,3 +55,4 @@ class VectorLayerCounterpart {


export default VectorLayerCounterpart;
export type PrimitiveCollectionCounterpart = PrimitiveCollection & {counterpart: VectorLayerCounterpart};
108 changes: 54 additions & 54 deletions src/olcs/print/drawCesiumMask.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,29 +12,6 @@ interface ProgramInfo {
}
}

/**
*
*/
export function autoDrawMask(scene: Scene, getScalings: () => number[]) {
const canvas = scene.canvas;
const ctx = canvas.getContext("webgl2") || canvas.getContext("webgl");

if (getScalings) {
if (!postUnlistener) {
const drawer = new MaskDrawer(ctx);
postUnlistener = scene.postRender.addEventListener(() => {
drawer.drawMask(getScalings());
});
}
}
else if (postUnlistener) {
postUnlistener();
// FIXME: destroy program
postUnlistener = null;
}
scene.requestRender();
}


// CC0 from https://github.com/mdn/dom-examples/tree/main/webgl-examples/tutorial/sample2

Expand All @@ -49,12 +26,12 @@ export class MaskDrawer {
this.programInfo = {
program: shaderProgram,
attribLocations: {
vertexPosition: gl.getAttribLocation(shaderProgram, "aVertexPosition")
vertexPosition: gl.getAttribLocation(shaderProgram, 'aVertexPosition')
},
uniformLocations: {
uScaling: gl.getUniformLocation(
shaderProgram,
"uScaling"
shaderProgram,
'uScaling'
)
}
};
Expand Down Expand Up @@ -93,8 +70,8 @@ export class MaskDrawer {
const vsSource = this.getVertexShaderSource();
const fsSource = this.getFragmentShaderSource();
const vertexShader = MaskDrawer.loadShader(gl, gl.VERTEX_SHADER, vsSource),
fragmentShader = MaskDrawer.loadShader(gl, gl.FRAGMENT_SHADER, fsSource),
shaderProgram = gl.createProgram();
fragmentShader = MaskDrawer.loadShader(gl, gl.FRAGMENT_SHADER, fsSource),
shaderProgram = gl.createProgram();

gl.attachShader(shaderProgram, vertexShader);
gl.attachShader(shaderProgram, fragmentShader);
Expand All @@ -104,9 +81,9 @@ export class MaskDrawer {

if (!gl.getProgramParameter(shaderProgram, gl.LINK_STATUS)) {
throw new Error(
`Unable to initialize the shader program: ${gl.getProgramInfoLog(
shaderProgram
)}`
`Unable to initialize the shader program: ${gl.getProgramInfoLog(
shaderProgram
)}`
);
}

Expand All @@ -126,12 +103,12 @@ export class MaskDrawer {

gl.bindBuffer(gl.ARRAY_BUFFER, this.positionBuffer);
gl.vertexAttribPointer(
programInfo.attribLocations.vertexPosition,
2,
gl.FLOAT,
false,
0,
0
programInfo.attribLocations.vertexPosition,
2,
gl.FLOAT,
false,
0,
0
);
gl.enableVertexAttribArray(programInfo.attribLocations.vertexPosition);
gl.useProgram(programInfo.program);
Expand All @@ -140,37 +117,37 @@ export class MaskDrawer {
// Draw a first time to fill the stencil area while keeping the destination color
gl.enable(gl.STENCIL_TEST);
gl.stencilFunc(
gl.ALWAYS,
1,
0xFF
gl.ALWAYS,
1,
0xFF
);
gl.stencilOp(
gl.KEEP,
gl.KEEP,
gl.REPLACE
gl.KEEP,
gl.KEEP,
gl.REPLACE
);
gl.uniform2fv(
programInfo.uniformLocations.uScaling,
scaling
programInfo.uniformLocations.uScaling,
scaling
);
gl.blendFunc(gl.ZERO, gl.ONE);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);


// Now draw again the whole viewport and darken the pixels that are not on the stencil
gl.stencilFunc(
gl.EQUAL,
0,
0xFF
gl.EQUAL,
0,
0xFF
);
gl.stencilOp(
gl.KEEP,
gl.KEEP,
gl.KEEP
gl.KEEP,
gl.KEEP,
gl.KEEP
);
gl.uniform2fv(
programInfo.uniformLocations.uScaling,
[1, 1]
programInfo.uniformLocations.uScaling,
[1, 1]
);
gl.blendFunc(gl.ZERO, gl.SRC_ALPHA);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
Expand All @@ -188,11 +165,34 @@ export class MaskDrawer {

if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {
throw new Error(
`An error occurred compiling the shaders: ${gl.getShaderInfoLog(shader)}`
`An error occurred compiling the shaders: ${gl.getShaderInfoLog(shader)}`
);
// gl.deleteShader(shader);
}

return shader;
}
}

/**
*
*/
export function autoDrawMask(scene: Scene, getScalings: () => number[]) {
const canvas = scene.canvas;
const ctx = canvas.getContext('webgl2') || canvas.getContext('webgl');

if (getScalings) {
if (!postUnlistener) {
const drawer = new MaskDrawer(ctx);
postUnlistener = scene.postRender.addEventListener(() => {
drawer.drawMask(getScalings());
});
}
}
else if (postUnlistener) {
postUnlistener();
// FIXME: destroy program
postUnlistener = null;
}
scene.requestRender();
}
Loading