deck.gl
deck.gl copied to clipboard
renderSubLayers one icon update
Hey! My code:
return new TileLayer({
id: 'tile_layer_data_assets',
getTileData: ({ x, y, z }: any) => {
return getTileData(mapSource, x, y, z, refreshGeoserver);
},
getRadius: 100,
visible: true,
onHover: ({ x, y, object }: any) => {
if (object && object.properties) {
onHover({ ...object.properties, x, y });
}
},
onClick: ({ object }: any) => {
if (object && object.properties) {
onClick({ ...object.properties, coordinates: object.geometry.coordinates });
}
},
renderSubLayers: (props: any) => {
return new IconLayer({
id: `${props.id}-icon`,
data: props.data,
iconAtlas: pin,
iconMapping: ICON_MAPPING,
pickable: true,
autoHighlight: true,
highlightColor: [193, 59, 255],
getIcon: () => 'marker',
sizeScale: 10,
getPosition: (d: any) => d.geometry.coordinates,
getSize: (d: { properties: any }) => (condition 9 : 6),
getColor: (d: { properties: any }) => {
return condition ? [48, 213, 200] : [255, 179, 71]
},
})
}
});
I would like to have effect like this: When i click on hovered icon, color and size of this element changes. I know if I push new prop in TileLayer then renderSubLayers will rerender, but not iconLayers.
You need to pass an updateTriggers prop for the IconLayer to re-evaluate certain accessors:
renderSubLayers: (props: any) => new IconLayer({
...
getSize: (d: { properties: any }) => (condition ? 9 : 6),
getColor: (d: { properties: any }) => {
return condition ? [48, 213, 200] : [255, 179, 71]
},
updateTriggers: {
getSize: [condition],
getColor: [condition]
}
})
@Pessimistress Thx :)
One thing that did not work was refreshing renderSubLayers, but I needed only to add new props to TileLayer.