Skip to content

Instantly share code, notes, and snippets.

@danswick
danswick / README.md
Last active April 10, 2023 08:04
Restrict mapbox.js GeocoderControl to a single country

The Mapbox Geocoding API can handle lots of different query parameters, including country, which will only return results for a given country.

This example uses GeocoderControl's queryOptions option to restrict results to those from the United States. Try searching for "Dublin."

@danswick
danswick / README.md
Last active October 29, 2016 00:14
Mapbox GL toggle satellite without setting style

Mapbox GL JS's setStyle method completely removes the style object, taking any layers that were programmatically added to the map with it. Instead of using setStyle, this demo toggles the visibility of a satellite imagery layer (initially set to visibility: none). Try adding a route with the directions plugin, then toggling the satellite layer's visibility!

@danswick
danswick / index.html
Last active November 4, 2018 15:08
Mapbox.js fallback for Mapbox GL JS
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title></title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<style>
body { margin:0; padding:0; }
#map { position:absolute; top:0; bottom:0; width:100%; }
#status {
@danswick
danswick / README.md
Last active March 17, 2017 19:39
Mapbox GL Geocoder plugin using Mapzen Search!
@danswick
danswick / index.html
Last active March 17, 2017 19:40
OL3 with Mapbox classic raster tiles
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="http://openlayers.org/en/v3.16.0/css/ol.css" type="text/css">
<style>
.map {
height: 100%;
width: 100%;
}
</style>
@danswick
danswick / index.html
Last active March 17, 2017 19:40
OL3 with Mapbox styles API raster tiles
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="http://openlayers.org/en/v3.16.0/css/ol.css" type="text/css">
<style>
.map {
height: 100%;
width: 100%;
}
</style>
@danswick
danswick / index.html
Last active March 17, 2017 19:41
Programmatically offset lines
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title></title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.18.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.18.0/mapbox-gl.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
@danswick
danswick / index.html
Last active March 17, 2017 19:41
Replace marker popup event in Mapbox.js
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Markers as links</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.mapbox.com/mapbox.js/v2.4.0/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v2.4.0/mapbox.css' rel='stylesheet' />
<style>
body { margin:0; padding:0; }
@danswick
danswick / index.html
Last active March 17, 2017 19:42
Quickly test raster tiles from Studio styles
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Add styles made with Mapbox Studio to a Leaflet map</title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.mapbox.com/mapbox.js/v2.4.0/mapbox.js'></script>
<link href='https://api.mapbox.com/mapbox.js/v2.4.0/mapbox.css' rel='stylesheet' />
<style>
* { box-sizing: border-box; }
@danswick
danswick / index.html
Last active April 24, 2024 20:14
Fit map to polygon bounds with Turf and Mapbox GL JS
<!DOCTYPE html>
<html>
<head>
<meta charset='utf-8' />
<title></title>
<meta name='viewport' content='initial-scale=1,maximum-scale=1,user-scalable=no' />
<script src='https://api.tiles.mapbox.com/mapbox-gl-js/v0.18.0/mapbox-gl.js'></script>
<link href='https://api.tiles.mapbox.com/mapbox-gl-js/v0.18.0/mapbox-gl.css' rel='stylesheet' />
<script src='https://api.mapbox.com/mapbox.js/plugins/turf/v2.0.2/turf.min.js'></script>
<style>