Skip to content

Commit 839591e

Browse files
authored
Merge pull request #12 from 2gis/TILES-4788-reference-docs
Add docs reference comments
2 parents 46d68be + da25722 commit 839591e

File tree

6 files changed

+59
-5
lines changed

6 files changed

+59
-5
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@2gis/deck2gis-layer",
3-
"version": "1.1.2",
3+
"version": "1.1.3",
44
"description": "",
55
"main": "dist/deck2gislayer.js",
66
"typings": "dist/types/index.d.ts",

src/deckgl2gisLayer.ts

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,19 @@ import Texture from '2gl/Texture';
1818
import type Vao from '2gl/Vao';
1919
import type ShaderProgram from '2gl/ShaderProgram';
2020

21-
export type LayerProps<LayerT extends Layer> = Partial<LayerT['props']> & {
21+
export type DeckInternalLayerProps = {
2222
id: string;
2323
renderingMode?: '2d' | '3d';
2424
deck: Deck;
2525
type: any;
2626
antialiasing?: boolean;
2727
};
2828

29+
export type LayerProps<LayerT extends Layer> = Partial<LayerT['props']> & DeckInternalLayerProps;
30+
31+
/**
32+
* A class that provides rendering any deck.gl layer inside the MapGl canvas / WebGL context.
33+
*/
2934
export class Deck2gisLayer<LayerT extends Layer> implements DeckCustomLayer {
3035
id: string;
3136
type: 'custom';
@@ -44,6 +49,22 @@ export class Deck2gisLayer<LayerT extends Layer> implements DeckCustomLayer {
4449
private vao?: Vao;
4550

4651
/* eslint-disable no-this-before-super */
52+
/**
53+
* Example:
54+
* ```js
55+
* const deckLayer = new mapgl.Deck2gisLayer(map, {
56+
* id: 'deckLayer',
57+
* deck,
58+
* type: HexagonLayer,
59+
* data,
60+
* getPosition: (d) => [d.point.lon, d.point.lat]
61+
* });
62+
*
63+
* map.addLayer(deckLayer);
64+
* ```
65+
* @param map The map instance.
66+
* @param options Deck2gisLayer initialization options.
67+
*/
4768
constructor(props: LayerProps<LayerT>) {
4869
if (!props.id) {
4970
throw new Error('Layer must have a unique id');
@@ -58,6 +79,11 @@ export class Deck2gisLayer<LayerT extends Layer> implements DeckCustomLayer {
5879
this.antialiasing = Boolean(props.antialiasing);
5980
}
6081

82+
/**
83+
* @hidden
84+
* @internal
85+
* MapGL calls this method after adding a layer to a map.
86+
*/
6187
public onAdd = () => {
6288
if (!this.map && this.props.deck) {
6389
const map = (this.props.deck.props as CustomRenderProps)._2gisData._2gisMap;
@@ -94,12 +120,20 @@ export class Deck2gisLayer<LayerT extends Layer> implements DeckCustomLayer {
94120
}
95121
};
96122

123+
/**
124+
* @hidden
125+
* @internal
126+
* MapGL calls this method after removing a layer from a map.
127+
*/
97128
public onRemove = () => {
98129
if (this.deck) {
99130
removeLayer(this.deck, this);
100131
}
101132
};
102133

134+
/**
135+
* Sets layer properties and updates the layer.
136+
*/
103137
public setProps(props: Partial<LayerProps<LayerT>>) {
104138
// id cannot be changed
105139
Object.assign(this.props, props, { id: this.id });
@@ -110,6 +144,11 @@ export class Deck2gisLayer<LayerT extends Layer> implements DeckCustomLayer {
110144
}
111145
}
112146

147+
/**
148+
* @hidden
149+
* @internal
150+
* MapGL calls this method on each map frame rendering.
151+
*/
113152
public render = () => {
114153
if (
115154
!this.deck ||

src/types.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,17 @@ export interface MapViewState {
3030
fovy: number;
3131
}
3232

33-
export type CustomRenderProps = Partial<DeckProps> & {
33+
/**
34+
* @hidden
35+
* @internal
36+
*/
37+
export type CustomRenderInternalProps = {
3438
_2glRenderTarget: RenderTarget;
3539
_2glProgram: ShaderProgram;
3640
_2glVao: Vao;
3741
_2gisFramestart: boolean;
3842
_customRender: (reason: string) => void;
3943
_2gisData?: any;
4044
};
45+
46+
export type CustomRenderProps = Partial<DeckProps> & CustomRenderInternalProps;

src/utils.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,11 @@ function updateLayers(deck: Deck): void {
197197
deck.setProps({ layers });
198198
}
199199

200+
/**
201+
* Initializes deck.gl properties for working with the MapGL map.
202+
* @param map The map instance.
203+
* @param deckProps CustomRenderProps initialization options.
204+
*/
200205
export function initDeck2gisProps(map: Map, deckProps?: CustomRenderProps): DeckProps {
201206
const gl = map.getWebGLContext();
202207
const deck2gisProps: any = {

src/viewport.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export class MapglMercatorViewport extends WebMercatorViewport {
3232
}
3333
}
3434

35+
/**
36+
* @hidden
37+
* @internal
38+
*/
3539
export function getViewState(map: Map): WebMercatorViewportOptions & {
3640
padding: {
3741
left: number;

0 commit comments

Comments
 (0)