JavaScript
mapboxgl.accessToken = 'pk.eyJ1IjoiYWxhbnRnZW8tcHJlc2FsZXMiLCJhIjoiY2pxcmZ1cW1mMG1tcDN4bDVvYzA4MWg5MyJ9.7QtVj_0ythHwEg1n_zaRTQ';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v11',
center: [-75.5802,39.8389],
zoom: 6
});
var hoveredStateId = null;
map.on('load', function () {
map.addSource('states', {
'type': 'geojson',
"promoteId": "id",
'data': {"type":"FeatureCollection", "features": [
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-75.7886,39.7222],[-75.5802,39.8389],[-75.4151,39.8019],[-75.5584,39.6303],[-75.5128,39.5783],[-75.5605,39.4556],[-75.321,39.2514],[-75.1685,39.0562],[-75.0151,38.7887],[-74.9863,38.4516],[-75.6937,38.4601],[-75.743,39.084],[-75.7886,39.7222]]]},"properties":{"STATE_ID":"10","STATE_NAME":"Delaware", "id":"a"}},
{"type":"Feature","geometry":{"type":"Polygon","coordinates":[[[-75.7886,39.7222],[-75.5802,39.8389],[-75.4151,39.8019],[-75.5584,39.6303],[-75.5128,39.5783],[-75.5605,39.4556],[-75.321,39.2514],[-75.1685,39.0562],[-75.0151,38.7887],[-74.9863,38.4516],[-75.6937,38.4601],[-75.743,39.084],[-75.7886,39.7222]]]},"properties":{"STATE_ID":"10","STATE_NAME":"Delaware", "id":"b"}}
]}
});
// The feature-state dependent fill-opacity expression will render the hover effect
// when a feature's hover state is set to true.
map.addLayer({
'id': 'state-fills',
'type': 'fill',
'source': 'states',
'layout': {},
'paint': {
'fill-color': '#627BC1',
'fill-opacity': [
'case',
['boolean', ['feature-state', 'hover'], false],
1,
0.5
]
}
});
map.addLayer({
'id': 'state-borders',
'type': 'line',
'source': 'states',
...