Skip to content

Instantly share code, notes, and snippets.

@eeeschwartz
Last active January 8, 2016 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eeeschwartz/ed3080018d779ad1bb6c to your computer and use it in GitHub Desktop.
Save eeeschwartz/ed3080018d779ad1bb6c to your computer and use it in GitHub Desktop.
Use esri-leaflet to geocode against Lexington's ArcGISOnline API
<!DOCTYPE html>
<html>
<head>
<title>Esri Leaflet Geocoder</title>
<!-- Load Leaflet from CDN-->
<link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-1.0.0-b1/leaflet.css" />
<script src="http://cdn.leafletjs.com/leaflet-1.0.0-b1/leaflet.js"></script>
<!-- Esri Leaflet -->
<script src="//cdn.jsdelivr.net/leaflet.esri/2.0.0-beta.6/esri-leaflet.js"></script>
<!-- Esri Leaflet Geocoder -->
<link rel="stylesheet" href="//cdn.jsdelivr.net/leaflet.esri.geocoder/2.0.0/esri-leaflet-geocoder.css">
<script src="//cdn.jsdelivr.net/leaflet.esri.geocoder/2.0.0/esri-leaflet-geocoder.js"></script>
<!-- Make the map fill the entire page -->
<style>
#map {
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
}
</style>
</head>
<body>
<div id="map"></div>
<script>
var map = L.map('map').setView([45.5165, -122.6764], 12);
var tiles = L.tileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png").addTo(map);
var arcgisOnline = L.esri.Geocoding.arcgisOnlineProvider();
var lex = new L.esri.Geocoding.geocodeServiceProvider({
// url: 'http://gis.lexingtonky.gov/lfucggis/rest/services/Locator_AddressPoint/GeocodeServer'
url: 'http://gis.lexingtonky.gov/lfucggis/rest/services/addresses/MapServer/'
});
// create the geocoding control and add it to the map
var searchControl = L.esri.Geocoding.geosearch({
providers: [arcgisOnline]
}).addTo(map);
// create an empty layer group to store the results and add it to the map
var results = L.layerGroup().addTo(map);
// listen for the results event and add every result to the map
searchControl.on("results", function(data) {
results.clearLayers();
for (var i = data.results.length - 1; i >= 0; i--) {
results.addLayer(L.marker(data.results[i].latlng));
};
});
</script>
</body>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment