Skip to content

Instantly share code, notes, and snippets.

@stevage stevage/index.html
Created Jun 26, 2018

What would you like to do?
mapbox on.load vs queryRenderedFeatures
<!DOCTYPE html>
<meta charset='utf-8' />
<title>Display a map</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src=''></script>
<link href='' rel='stylesheet' />
body { margin:0; padding:0; }
.rounded-label {
background: white;
padding: 0.25em 0.5em;
font-size: 16pt;
border-radius: 1em;
border:1px solid lightgrey;
#map { position:absolute; top:0; bottom:0; width:100%; }
<div id='map'></div>
function countCities(event) {
var labelLayers = ['place-city-lg-n', 'place-city-lg-s', 'place-city-md-n', 'place-city-md-s', 'place-city-sm'];
var places = map.queryRenderedFeatures({ layers: labelLayers});
console.log('[' + event + '] ', places.length, ' city labels found');
mapboxgl.accessToken = 'pk.eyJ1Ijoic3RldmFnZSIsImEiOiJGcW03aExzIn0.QUkUmTGIO3gGt83HiRIjQw';
var map = new mapboxgl.Map({
container: 'map',
style: 'mapbox://styles/mapbox/streets-v9',
center: [-74.50, 40],
zoom: 9
map.on('load', () => countCities('load'));
map.on('render', () => countCities('render'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.