Skip to content

Instantly share code, notes, and snippets.

@pgiraud
Created November 17, 2014 10:28
Show Gist options
  • Select an option

  • Save pgiraud/c40fc5172bfea8d3ac17 to your computer and use it in GitHub Desktop.

Select an option

Save pgiraud/c40fc5172bfea8d3ac17 to your computer and use it in GitHub Desktop.
GeoJSON in OL3
<!doctype html>
<html lang="en">
<head>
<link rel="stylesheet" href="http://openlayers.org/en/v3.0.0/css/ol.css" type="text/css">
<style>
.map {
height: 400px;
width: 100%;
}
</style>
<script src="http://openlayers.org/en/v3.0.0/build/ol.js" type="text/javascript"></script>
<title>OpenLayers 3 example</title>
</head>
<body>
<h2>My Map</h2>
<div id="map" class="map"></div>
<script src="index.js"></script>
</body>
</html>
var raster = new ol.layer.Tile({
source: new ol.source.TileJSON({
url: 'http://api.tiles.mapbox.com/v3/mapbox.world-dark.jsonp'
})
});
var styleArray = [new ol.style.Style({
fill: new ol.style.Fill({
color: 'rgba(255, 255, 255, 0.6)'
}),
stroke: new ol.style.Stroke({
color: '#319FD3',
width: 1
})
})];
//var vector = new ol.layer.Vector({
//source: new ol.source.TopoJSON({
//projection: 'EPSG:3857',
//url: 'data/topojson/world-110m.json'
//}),
//style: function(feature, resolution) {
//// don't want to render the full world polygon, which repeats all countries
//return feature.getId() !== undefined ? styleArray : null;
//}
//});
var vector = new ol.layer.Vector({
source: new ol.source.GeoJSON({
projection: 'EPSG:3857',
url: 'data/geojson/States_sample.json'
}),
style: function(feature, resolution) {
// don't want to render the full world polygon, which repeats all countries
return feature.getId() !== undefined ? styleArray : null;
}
});
var map = new ol.Map({
layers: [raster, vector],
target: 'map',
view: new ol.View({
center: [0, 0],
zoom: 1
})
});
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment