mirror of
https://github.com/Viglino/ol-ext.git
synced 2025-12-08 19:26:29 +00:00
136 lines
3.8 KiB
HTML
136 lines
3.8 KiB
HTML
<DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<!--
|
|
Copyright (c) 2015-2019 Jean-Marc VIGLINO,
|
|
released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
|
|
-->
|
|
<title>Layer 3D</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
<meta name="description" content="2.5D/3D buildings on an OL3 map" />
|
|
<meta name="keywords" content="ol3, layer, vector, 3D, buildings, animation" />
|
|
|
|
<!-- jQuery -->
|
|
<script type="text/javascript" src="https://code.jquery.com/jquery-1.11.0.min.js"></script>
|
|
|
|
<!-- Openlayers -->
|
|
<link rel="stylesheet" href="https://openlayers.org/en/v6.15.1/css/ol.css" />
|
|
<script type="text/javascript" src="https://openlayers.org/en/v6.15.1/build/ol.js"></script>
|
|
|
|
|
|
<!-- ol-ext -->
|
|
<link rel="stylesheet" href="../../dist/ol-ext.css" />
|
|
<script type="text/javascript" src="../../dist/ol-ext.js"></script>
|
|
<!-- Pointer events polyfill for old browsers, see https://caniuse.com/#feat=pointer -->
|
|
<script src="https://unpkg.com/elm-pep"></script>
|
|
|
|
<link rel="stylesheet" href="../style.css" />
|
|
<style>
|
|
#map {
|
|
position:fixed;
|
|
top: 4em;
|
|
left: 0;
|
|
right:0;
|
|
bottom:0;
|
|
margin:0;
|
|
}
|
|
.info {
|
|
position: fixed;
|
|
right: 0.5em;
|
|
top: 4em;
|
|
width: 300px;
|
|
z-index: 1;
|
|
}
|
|
.loading {
|
|
background: #fff;
|
|
border: 2px solid #369;
|
|
left: 50%;
|
|
margin: -2em -100px;
|
|
padding: 0.5em;
|
|
position: fixed;
|
|
text-align: center;
|
|
top: 50%;
|
|
width: 200px;
|
|
z-index: 1;
|
|
box-sizing: border-box;
|
|
box-shadow: 2px 2px 4px rgba(0,0,0,0.5);
|
|
}
|
|
</style>
|
|
</head>
|
|
<body >
|
|
<a href="https://github.com/Viglino/ol-ext" class="icss-github-corner"><i></i></a>
|
|
<a href="../../index.html">
|
|
<h1>Layer 3D</h1>
|
|
</a>
|
|
<div class="info">
|
|
This example add a setRenderer3D function to vector layers that do the job in a postcompose loop.
|
|
<br />
|
|
Buildings from <a href="http://professionnels.ign.fr/bdtopo">BDTopo © IGN-France</a>.
|
|
<br />
|
|
POI informations from <a href="https://www.wikipedia.org/">WikiPedia</a>
|
|
<br/>
|
|
<button onclick="doAnime();">Animate!</button>
|
|
</div>
|
|
|
|
<!-- DIV pour la carte -->
|
|
<div id="map"></div>
|
|
<div class="loading">Please wait while loading data...</div>
|
|
|
|
<script type="text/javascript">
|
|
// The map
|
|
var map = new ol.Map ({
|
|
target: 'map',
|
|
view: new ol.View ({
|
|
zoom: 13,
|
|
center: [260841, 6250141]
|
|
}),
|
|
interactions: ol.interaction.defaults(),
|
|
layers: [ new ol.layer.Tile({ name:"OSM", source: new ol.source.OSM() })]
|
|
});
|
|
|
|
// Create layer
|
|
var vectorSource = new ol.source.Vector({
|
|
url: '../data/dvf-75-2017-100m.geojson',
|
|
// projection: 'EPSG:3857',
|
|
format: new ol.format.GeoJSON(),
|
|
attributions: [ "© <a href='https://cadastre.data.gouv.fr/dvf'>DGFiP</a>" ]
|
|
});
|
|
var vector = new ol.layer.Vector({
|
|
source: vectorSource,
|
|
maxResolution: 40
|
|
});
|
|
map.addLayer(vector);
|
|
|
|
// Set 3D renderer
|
|
var r3D = new ol.render3D({
|
|
layer: vector,
|
|
style: new ol.style.Style({
|
|
stroke: new ol.style.Stroke({ width: 3, color: [255,0,0] }),
|
|
geometry: function (f) { return f.get('geom'); }
|
|
}),
|
|
height: function(f) { return f.get('nb')*20; },
|
|
maxResolution: 40,
|
|
defaultHeight: 0
|
|
});
|
|
var listenerKey = vectorSource.on('change', function(e) {
|
|
if (vectorSource.getState() == 'ready') {
|
|
ol.Observable.unByKey(listenerKey)
|
|
$(".loading").hide();
|
|
vectorSource.getFeatures().forEach(function(f) {
|
|
f.set('geom', f.getGeometry().getInteriorPoint());
|
|
})
|
|
}
|
|
});
|
|
|
|
var height = 1;
|
|
function doAnime() {
|
|
if (r3D.animating()) return;
|
|
height = height ? 0 : function(f) { return f.get('nb')*20; };
|
|
r3D.animate({ height:height });
|
|
}
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html> |