mapboxgl.accessToken = 'pk.eyJ1Ijoia2Vud29vZG1hcHMiLCJhIjoiY2o2czZxMjg2MDEyNTJ3cGRqM2FvdHc4diJ9.TP8cfPrAE_oKWDPIY_Mvaw';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9',
center: [-100.04, 38.907],
zoom: 3
});
map.on('load', function () {
map.addLayer({
'id': 'testlayer',
'type': 'fill',
"source": {
"type": "geojson",
"data": {
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [[[-100, 40],
[-120, 40],
[-120, 30],
[-100, 30]]]
},
"properties": {
"name": "TEST 1"
}
}, {
"type": "Feature",
"geometry": {
"type": "Polygon",
"coordinates": [[[-95, 35],
[-115, 35],
[-115, 25],
[-95, 25]]]
},
"properties": {
"name": "TEST 2"
}
}]
}
},
'layout': {},
'paint': {
'fill-color': '#088',
'fill-opacity': 0.5
}
});
// When a click event occurs on a feature in the states layer, open a popup at the
// location of the click, with description HTML from its properties.
map.on('click', 'testlayer', function (e) {
new mapboxgl.Popup()
.setLngLat(e.lngLat)
.setHTML(e.features[0].properties.name)
.addTo(map);
});
// Change the cursor to a pointer when the mouse is over the states layer.
map.on('mouseenter', 'states-layer',...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.