mizmay / WebMapStarterKit

Demo project for creating web maps
14 stars 4 forks source link

Create hover effect from PMTiles source #1

Open mizmay opened 1 month ago

mizmay commented 1 month ago

Putting this aside until I can debug what's going on.

  1. Need a way to set promoteId to something unique, e.g. "name"

  2. Set hoverstate:

                map.on('mousemove', 'states', (e) => {
                    if (e.features.length > 0) {
    
                        if (hoveredStateId) {
                            map.setFeatureState(
                                {source: 'states', id: hoveredStateId},
                                {hover: false}
                            );
                        }
                        hoveredStateId = e.features[0].properties.name;
                        map.setFeatureState(
                            {source: 'states', id: hoveredStateId},
                            {hover: true}
                        );
                    }
                });
    
                map.on('mouseleave', 'states', () => {
                    if (hoveredStateId) {
                        map.setFeatureState(
                            {source: 'states', id: hoveredStateId},
                            {hover: false}
                        );
                    }
                hoveredStateId = null;
                });
mizmay commented 1 month ago

Debugging using geojson source:

                            'states': {
                                type: "geojson",
                                data: "https://mizmay.github.io/WebMapStarterKit/states_swing_2020_coterminoususa.geojson",
                                promoteId: "name"
                            }