Add countries example

This commit is contained in:
Tom Payne
2013-11-09 01:49:33 +01:00
parent e4623af4df
commit a89c9b17ef
2 changed files with 104 additions and 0 deletions

50
examples/countries.html Normal file
View File

@@ -0,0 +1,50 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="chrome=1">
<meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
<link rel="stylesheet" href="../css/ol.css" type="text/css">
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap.min.css" type="text/css">
<link rel="stylesheet" href="../resources/layout.css" type="text/css">
<link rel="stylesheet" href="../resources/bootstrap/css/bootstrap-responsive.min.css" type="text/css">
<title>Countries example</title>
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container">
<a class="brand" href="./"><img src="../resources/logo.png"> OpenLayers 3 Examples</a>
</div>
</div>
</div>
<div class="container-fluid">
<div class="row-fluid">
<div class="span12">
<div id="map" class="map"></div>
</div>
</div>
<div class="row-fluid">
<div class="span12">
<h4 id="title">Countries example</h4>
<p id="shortdesc">Example of a loading GeoJSON map.</p>
<div id="docs">
<p>See the <a href="countries.js" target="_blank">countries.js source</a> to see how this is done.</p>
</div>
<div id="tags">geojson</div>
</div>
</div>
</div>
<script src="loader.js?id=countries" type="text/javascript"></script>
<script src="../resources/example-behaviour.js" type="text/javascript"></script>
</body>
</html>

54
examples/countries.js Normal file
View File

@@ -0,0 +1,54 @@
goog.require('goog.asserts');
goog.require('goog.functions');
goog.require('goog.net.XhrIo');
goog.require('ol.Map');
goog.require('ol.RendererHint');
goog.require('ol.View2D');
goog.require('ol.format.GeoJSON');
goog.require('ol.layer.Tile');
goog.require('ol.layer.Vector');
goog.require('ol.proj');
goog.require('ol.source.MapQuestOpenAerial');
goog.require('ol.source.Vector');
var map = new ol.Map({
layers: [
new ol.layer.Tile({
source: new ol.source.MapQuestOpenAerial()
})
],
renderer: ol.RendererHint.CANVAS,
target: 'map',
view: new ol.View2D({
center: [0, 0],
zoom: 2
})
});
goog.net.XhrIo.send('data/countries.geojson', function(event) {
var xhrIo = /** @type {goog.net.XhrIo} */ (event.target);
if (xhrIo.isSuccess()) {
var format = new ol.format.GeoJSON();
var object = xhrIo.getResponseJson();
var vectorSource = new ol.source.Vector();
goog.asserts.assert(goog.isDefAndNotNull(object));
var transformFn = ol.proj.getTransform('EPSG:4326', 'EPSG:3857');
format.readObject(object, function(feature) {
var geometry = feature.getGeometry();
geometry.transform(transformFn);
feature.setGeometry(geometry);
vectorSource.addFeature(feature);
});
map.getLayers().push(new ol.layer.Vector({
source: vectorSource,
styleFunction: goog.functions.constant({
fill: {
color: 'rgba(255, 255, 255, 0.6)'
},
stroke: {
color: '#319FD3'
}
})
}));
}
});