Created
November 17, 2014 10:28
-
-
Save pgiraud/c40fc5172bfea8d3ac17 to your computer and use it in GitHub Desktop.
GeoJSON in OL3
This file contains hidden or 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 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> |
This file contains hidden or 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
| 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 | |
| }) | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment