You can interact with geojson.io programmatically in two ways:
You can do a few interesting things with just URLs and geojson.io. Here are the current URL formats.
Open the map at a specific location. The argument is numbers separated by /
in the form zoom/latitude/longitude
.
http://geojson.io/#map=2/20.0/0.0
Open the map and load a chunk of GeoJSON data from a
URL segment directly onto the map. The GeoJSON data should be encoded
as per encodeURIComponent(JSON.stringify(geojson_data))
.
Load GeoJSON data from a URL on the internet onto the map. The URL must refer directly to a resource that is:
- Freely accessible (not behind a password)
- Supports CORS
- Is valid GeoJSON
The URL should be encoded as per encodeURIComponent(url)
.
Load GeoJSON data from a GitHub Gist, given an argument
in the form of login/gistid
. The Gist can be public or private, and must
contain a file with a .geojson
extension that is valid GeoJSON.
http://geojson.io/#id=gist:tmcw/e9a29ad54dbaa83dee08&map=8/39.198/-76.981
Load a file from a GitHub repository. You must have access to the file, and it must be valid GeoJSON.
The url is in the form:
login/repository/blob/branch/filepath
Pop open your browser console and see the beautiful examples: geojson.io has started to expose a subset of its inner workings for you to mess around with:
The Mapbox GL JS map that you see and use on the site. See the Mapbox GL JS API Reference for all the things you can do with it.
For instance, you could add another map source and layer:
window.api.map.addSource('raster-tiles', {
'type': 'raster',
'tiles': [
'https://stamen-tiles.a.ssl.fastly.net/watercolor/{z}/{x}/{y}.jpg'
],
'tileSize': 256,
'attribution':
'Map tiles by <a target="_top" rel="noopener" href="https://stamen.com">Stamen Design</a>, under <a target="_top" rel="noopener" href="https://creativecommons.org/licenses/by/3.0">CC BY 3.0</a>. Data by <a target="_top" rel="noopener" href="https://openstreetmap.org">OpenStreetMap</a>, under <a target="_top" rel="noopener" href="https://creativecommons.org/licenses/by-sa/3.0">CC BY SA</a>'
})
window.api.map.addLayer({
'id': 'simple-tiles',
'type': 'raster',
'source': 'raster-tiles',
'minzoom': 0,
'maxzoom': 22
})
The data model. See the code to get an idea of how it works -
you'll want to use stuff like data.set({ map: { .. your geojson map information .. })
and data.get('map')
and data.mergeFeatures([arrayoffeatures])
to do your
dirty business.
Exposes the mapbox-gl-draw instance in the console.
Exposes d3 events, including change
.