Recreating the result of Mike Bostock's awesome tutorial with OpenLayers
Last active
December 21, 2015 12:28
-
-
Save pbogden/6305720 to your computer and use it in GitHub Desktop.
OpenLayers & GeoJSON
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> | |
<meta charset="utf-8"> | |
<title>openlayers</title> | |
<style> | |
body { | |
margin: 0em 0em; | |
} | |
#map { | |
width: 960px; | |
height: 500px; | |
border: 1px solid #ccc; | |
} | |
path { | |
fill: #000; | |
fill-opacity: .2; | |
stroke: #fff; | |
stroke-width: 1.5px; | |
} | |
path:hover { | |
fill: brown; | |
fill-opacity: .7; | |
} | |
</style> | |
<script src="http://openlayers.org/api/OpenLayers.js"></script> | |
<body> | |
<div id="map"></div> | |
<script> | |
var map = new OpenLayers.Map('map'); | |
var layer = new OpenLayers.Layer.WMS( "OpenLayers WMS", | |
"http://vmap0.tiles.osgeo.org/wms/vmap0", {layers: 'basic'} ); | |
map.addLayer(layer); | |
map.zoomToExtent([ -125, 20, -65, 50]); // draw the map centered on the US | |
var states = new OpenLayers.Layer.Vector("GeoJSON", { | |
protocol: new OpenLayers.Protocol.HTTP({ | |
url: "us-states.json", | |
format: new OpenLayers.Format.GeoJSON() | |
}), | |
strategies: [new OpenLayers.Strategy.Fixed()] | |
}); | |
map.addLayer( states ); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment