I know that is possible to make a heatmap using ol/layer/Heatmap, but this component accept as source only ol/source/Vector component.
Someone have build a heatmap using VectorTile as source? Can you suggest me a workaround?
heat mapopenlayersvector-tiles
I know that is possible to make a heatmap using ol/layer/Heatmap, but this component accept as source only ol/source/Vector component.
Someone have build a heatmap using VectorTile as source? Can you suggest me a workaround?
Best Answer
What @Mike proposed, to load vector tile features into normal vector heatmap layer is probably the only solution. Problem is that with vector tiles number of features can change greatly with zoom change, so with zoom change previous features in normal vector layer have to be cleared and new ones added.
One possible solution for this would be to use vector tile source method
getFeaturesInExtent
after all tiles are loaded, to get all features in visible extent and select the ones to be added to the heatmap vector layer. Vector tile features/geometries cannot be used directly, since they have different structure that normal vector features. Features for normal vector layer have to be created from coordinates of vector features.Code below is more a proof of concept than bulletproof solution. Whole idea is to wait for map
moveend
events and vector tile layerpostrender
events. Whenmoveend
is detected, set a flag, and when apostrender
event is detected andmoveend
flag is set, do inventory of vector tile layer features with thegetFeaturesInExtent
method, clear heatmap vector layer source and add desired features (points) from vector tile layer inventory.Code uses ArcGIS World_Basemap_v2 vector tile layer as a source. For heatmap points cities are filtered in. Since cities in the layer have no property to be used as weight, each city gets the same value
0.8
.Here is working JSFiddle: https://jsfiddle.net/TomazicM/y1xus3m0/ and two screenshots at different zooms: