Skip to content

Commit

Permalink
fix add layer
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Kuznecov committed Aug 31, 2023
1 parent 889f1e2 commit 3feb347
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 deletions.
22 changes: 17 additions & 5 deletions demo/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ const map = new mapgl.Map('container', {
webglVersion: 2,
});

const deck = new Deck(initDeck2gisProps(map, { antialiasing: 'msaa' }));
map.once('ready', () => {
initDeckGL();
const deck = new Deck(initDeck2gisProps(map, { antialiasing: 'none' }));
map.once('styleload', () => {
setTimeout(() => initDeckGL(), 3000);
});

function initDeckGL() {
Expand All @@ -40,21 +40,33 @@ const COLOR_RANGE: Color[] = [
[209, 55, 78],
];

function getCharacters() {
const charSet = 'МмЛлРрДдНнKkMmКкМм1234567890'.split('');

for (let i = 32; i < 128; i++) {
// eslint-disable-next-line functional/immutable-data
charSet.push(String.fromCharCode(i));
}

return charSet;
}

export const characterSet = getCharacters();

function createTextlayer(data) {
const layer = new Deck2gisLayer<TextLayer>({
id: 'text-layer',
data,
deck,
type: TextLayer,
characterSet: 'auto',
characterSet,
fontFamily: 'SBSansText, Helvetica, Arial, sans-serif',
getBackgroundColor: [66, 0, 255, 66],
getColor: [255, 128, 0],
getPosition: (d) => [d.point.lon, d.point.lat],
getText: (d) => '' + d.values.capacity,
getSize: 14,
background: true,
parameters: { depthTest: true },
});

return layer;
Expand Down
47 changes: 27 additions & 20 deletions src/deckgl2gisLayer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,30 +105,37 @@ export class Deck2gisLayer<LayerT extends Layer> implements DeckCustomLayer {
* MapGL calls this method after adding a layer to a map.
*/
public onAdd = () => {
if (!this.map && this.props?.deck && !this.isDestroyed) {
const deck = this.props?.deck;
const map = (this.props.deck.props as CustomRenderInternalProps)._2gisData._2gisMap;
this.map = map;
const gl = (this.gl = map.getWebGLContext());
if ((map as any).__deck) {
this.deck = (map as any).__deck;
this.renderTarget = (this.deck as any).props._2glRenderTarget;
this.msaaFrameBuffer = (this.deck as any).props._2glMsaaFrameBuffer;
const map: Map = (this.props?.deck.props as CustomRenderInternalProps)._2gisData._2gisMap;

// fix wrong initRender use when add layer in map on move
const initBeforeAdd = () => {
if (!this.map && this.props?.deck && !this.isDestroyed) {
const deck = this.props?.deck;
this.map = map;
const gl = (this.gl = map.getWebGLContext());
if ((map as any).__deck) {
this.deck = (map as any).__deck;
this.renderTarget = (this.deck as any).props._2glRenderTarget;
this.msaaFrameBuffer = (this.deck as any).props._2glMsaaFrameBuffer;
}
if (!this.renderTarget || !this.deck) {
this.initRenderTarget(gl, map, deck);
}
if (this.deck) {
this.program = (this.deck as any).props._2glProgram;
this.vao = (this.deck as any).props._2glVao;
}
}
if (!this.renderTarget || !this.deck) {
this.initRenderTarget(gl, map, deck);
}
if (this.deck) {
this.program = (this.deck as any).props._2glProgram;
this.vao = (this.deck as any).props._2glVao;

if (this.deck && !this.isDestroyed) {
addLayer(this.deck, this);
}
}
};

if (this.deck && !this.isDestroyed) {
addLayer(this.deck, this);
}
if ((map as any).__deck) {
initBeforeAdd();
} else [map.once('idle', () => initBeforeAdd())];
};

/**
* @hidden
* @internal
Expand Down

0 comments on commit 3feb347

Please sign in to comment.