Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Loading External GeoJSON (Promises): .when() & .done()
<!DOCTYPE html>
<meta charset="utf-8" />
<title>Starter map</title>
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
<link rel="stylesheet" href="" />
body {
margin: 0;
padding: 0;
#map {
position: absolute;
top: 0;
bottom: 0;
width: 100%;
<div id="map"></div>
<script src=""></script>
<script src=""></script>
<!-- MAP SCRIPT -->
var counties = $.ajax({
dataType: "json",
success: console.log("County data successfully loaded."),
error: function (xhr) {
// Specify that this code should run once the county data request is complete
$.when(counties).done(function() {
var map ='map')
.setView([37.857507, -85.632935], 7);
var basemap = L.tileLayer('http://{s}{z}/{x}/{y}.png', {
attribution: '&copy; <a href="">OpenStreetMap</a> &copy; <a href="">CartoDB</a>',
subdomains: 'abcd',
maxZoom: 19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment