Skip to content
 
 

Latest commit

 

History

175 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Mapbox GL Generic Geocoder

Bring your own geocoding srevice to mapbox-gl-js. Based on Mapbox GL Geocoder

Example

var geocodeNominatimRequest = function(query, mapBounds, options) {
	var params = { format: "json", q: query, limit: options.limit };
	var urlParams = new URLSearchParams(Object.entries(params));

	return fetch("http://nominatim.openstreetmap.org/search?" + urlParams).then(function(response) {
		if(response.ok) {
			return response.json();
		} else {
			return [];
		}
	}).then(function(json) {
		return json.map(function(result) {
			return {
				name: result.display_name,
				lat: result.lat,
				lon: result.lon,
				bbox: [result.boundingbox[2], result.boundingbox[0], result.boundingbox[3], result.boundingbox[1]]
			};
		});
	});
};

mapboxglmap.addControl(new MapboxGenericGeocoder({}, geocodeNominatimRequest));

Usage with a module bundler

This module exports a single class called MapboxGenericGeocoder as its default export, so in browserify or webpack, you can require it like:

var MapboxGenericGeocoder = require('mapbox-gl-generic-geocoder');

About

Geocoder control for mapbox-gl-js using your own Geocoding API

Resources

Stars

5 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages