deck.gl icon indicating copy to clipboard operation
deck.gl copied to clipboard

renderSubLayers one icon update

Open MacieJCzarkowskI opened this issue 6 years ago • 2 comments

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.

MacieJCzarkowskI avatar May 26 '20 11:05 MacieJCzarkowskI

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 avatar May 26 '20 20:05 Pessimistress

@Pessimistress Thx :)

One thing that did not work was refreshing renderSubLayers, but I needed only to add new props to TileLayer.

MacieJCzarkowskI avatar Jun 01 '20 11:06 MacieJCzarkowskI