Skip to content

Commit

Permalink
Merge pull request #10 from 2gis/TILES-4788
Browse files Browse the repository at this point in the history
TILES-4788 add plugin registry
  • Loading branch information
Kuznecoff authored Jan 15, 2023
2 parents c453a2a + a03174e commit 08b02f2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 5 deletions.
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.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@2gis/deck2gis-layer",
"version": "1.1.0",
"version": "1.1.1",
"description": "",
"main": "dist/deck2gislayer.js",
"typings": "dist/types/index.d.ts",
Expand Down
9 changes: 9 additions & 0 deletions project.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
import * as _mapgl from '@2gis/mapgl/types';

declare global {
const mapgl: typeof _mapgl;
}

export as namespace mapgl;
export = _mapgl;

declare module '*.fsh' {
const _: string;
export default _;
Expand Down
12 changes: 11 additions & 1 deletion src/deckgl2gisLayer.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
// Use fork mapbox layer in deck.gl
// https://github.com/visgl/deck.gl/tree/master/modules/mapbox

import { prepareDeckInstance, addLayer, removeLayer, updateLayer, drawLayer } from './utils';
import {
prepareDeckInstance,
addLayer,
removeLayer,
updateLayer,
drawLayer,
initDeck2gisProps,
} from './utils';
import type { Deck, Layer } from '@deck.gl/core/typed';
import { CustomRenderProps, DeckCustomLayer } from './types';
import type { Map } from '@2gis/mapgl/types';
Expand Down Expand Up @@ -29,6 +36,9 @@ export class Deck2gisLayer<LayerT extends Layer> implements DeckCustomLayer {
gl?: WebGLRenderingContext | WebGL2RenderingContext;
antialiasing: boolean;

static initDeck2gisProps = (map: Map, deckProps?: CustomRenderProps) =>
initDeck2gisProps(map, deckProps);

private frameBuffer?: RenderTarget;
private program?: ShaderProgram;
private vao?: Vao;
Expand Down
14 changes: 14 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
import { Deck2gisLayer } from './deckgl2gisLayer';
import { initDeck2gisProps } from './utils';

if (typeof window !== 'undefined') {
if ('mapgl' in window) {
(mapgl as any).Deck2gisLayer = Deck2gisLayer;
} else {
// Если так вышло, что плагин инициализирован раньше mapgl, поместим его во временную переменную
// Из нее уже сам mapgl все положит в себя.
if (!(window as any).__mapglPlugins) {
(window as any).__mapglPlugins = {};
}

(window as any).__mapglPlugins.Deck2gisLayer = Deck2gisLayer;
}
}

export { Deck2gisLayer, initDeck2gisProps };
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export function initDeck2gisProps(map: Map, deckProps?: CustomRenderProps): Deck
// Fix heatmap layer render: need reset gl state after each draw layers
function stateBinder(map: Map, layer: Deck2gisLayer<any>) {
const gl = map.getWebGLContext();
if (!layer.props.parameters.cullFaceEnabled) {
if (!layer.props?.parameters?.cullFaceEnabled) {
gl.disable(gl.CULL_FACE);
}
gl.clearDepth(1);
Expand Down

0 comments on commit 08b02f2

Please sign in to comment.