Built with blockbuilder.org
Created
December 2, 2016 05:16
-
-
Save maptastik/585192657d3cf7999f4d4a64d9f9446f to your computer and use it in GitHub Desktop.
Simple Map w/ external GeoJSON, Promises, and jQuery Geo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
license: mit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<title>jQuery Geo-KY Map</title> | |
<link rel="stylesheet" href="style.css"> | |
</head> | |
<body> | |
<div id="map"></div> | |
<script src="http://code.jquery.com/jquery-2.2.4.min.js"></script> | |
<script src="http://code.jquerygeo.com/jquery.geo-1.0.0-rc1.min.js"></script> | |
<script src="map.js"></script> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// request GeoJSON feature data | |
var counties = $.ajax({ | |
url: "kyCounties.geojson", | |
dataType: "json", | |
success: function (result){ | |
return result; | |
}, | |
error: function (xhr) { | |
alert(xhr.statusText) | |
} | |
}); | |
// once the county data is retrieved, we can start making a map! | |
$.when(counties).done(function(){ | |
// set up the map | |
var map = $("#map").geomap({ | |
center: [-85.632935, 37.857507], | |
zoom: 7, | |
services: [{ | |
id: "toner", | |
type: "tiled", | |
src:"http://a.basemaps.cartocdn.com/light_all/{{:zoom}}/{{:tile.column}}/{{:tile.row}}.png" | |
}] | |
}); | |
// parse the responseText property from the feature data request as JSON | |
counties = JSON.parse(counties.responseText); | |
// add and style the feature data | |
map.geomap("append", counties, { | |
fill: "#2196F3", | |
fillOpacity: 0.75, | |
stroke: "#212121", | |
strokeOpacity: 1, | |
strokeWidth: 1 | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
body { | |
margin: 0; | |
padding: 0; | |
} | |
#map { | |
position: absolute; | |
top: 0; | |
bottom: 0; | |
width: 100%; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment