mirror of
https://github.com/Viglino/ol-ext.git
synced 2026-01-18 17:11:52 +00:00
160 lines
5.0 KiB
HTML
160 lines
5.0 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<!----------------------------------------------------------
|
|
|
|
Copyright (c) 2015 Jean-Marc VIGLINO,
|
|
released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
|
|
|
|
------------------------------------------------------------>
|
|
<title>ol-ext: layer preview</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
<!-- 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/master/css/ol.css" />
|
|
<script type="text/javascript" src="https://openlayers.org/en/master/build/ol.js"></script>
|
|
|
|
<!-- ol-ext -->
|
|
<link rel="stylesheet" href="../../dist/ol-ext.css" />
|
|
<script type="text/javascript" src="../../dist/ol-ext.js"></script>
|
|
|
|
<link rel="stylesheet" href="../style.css" />
|
|
<style>
|
|
#preview .img
|
|
{ display:block;
|
|
width:128px;
|
|
height:92px;
|
|
position:relative;
|
|
overflow:hidden;
|
|
margin-top:1em;
|
|
box-shadow: 2px 2px 2px 2px rgba(0, 0, 0, 0.5)
|
|
}
|
|
#preview img
|
|
{ position:absolute;
|
|
bottom:0;
|
|
max-width:128px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body >
|
|
<a href="https://github.com/Viglino/ol3-ext"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://camo.githubusercontent.com/38ef81f8aca64bb9a64448d0d70f1308ef5341ab/68747470733a2f2f73332e616d617a6f6e6177732e636f6d2f6769746875622f726962626f6e732f666f726b6d655f72696768745f6461726b626c75655f3132313632312e706e67" alt="Fork me on GitHub" data-canonical-src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png"></a>
|
|
|
|
<a href="../../index.html">
|
|
<h1>ol-ext: layer preview</h1>
|
|
</a>
|
|
<div class="info">
|
|
Get a preview image for a layer.
|
|
<br />
|
|
It will add a <i>getPreview(lonlat, res)</i> function to layers to get an image preview of it.
|
|
<ul>
|
|
<li>
|
|
The function return an array of previews (group layers will return a preview for each layers in it).</li>
|
|
<li>
|
|
You can add a preview image on layer that has no preview (vector layers for examples).
|
|
</li>
|
|
<li>
|
|
See how it runs on <a href="map.switcher.image.html">Layer switcher image example</a>.
|
|
</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<!-- map div -->
|
|
<div id="map" style="width:600px; height:400px;"></div>
|
|
|
|
<div id="preview" class="options" style="padding:1em;">
|
|
Preview: <select></select>
|
|
<div class="img"></div>
|
|
</div>
|
|
|
|
<script type="text/javascript">
|
|
|
|
// Two base layers
|
|
var stamen = new ol.layer.Tile(
|
|
{ title: "Watercolor",
|
|
baseLayer: true,
|
|
source: new ol.source.Stamen({
|
|
layer: 'watercolor'
|
|
})
|
|
});
|
|
var osm = new ol.layer.Tile(
|
|
{ title: "OSM",
|
|
baseLayer: true,
|
|
source: new ol.source.OSM(),
|
|
visible: false
|
|
});
|
|
|
|
// WMS Layer BRGM
|
|
var brgm = new ol.layer.Tile
|
|
({ name: "Geologie (WMS)",
|
|
visible: false,
|
|
minResolution: 200000 /(72/2.54*100),
|
|
maxResolution: 10000000 /(72/2.54*100),
|
|
source: new ol.source.TileWMS(
|
|
{ url: 'https://geoservices.brgm.fr/geologie',
|
|
attributions:
|
|
[ new ol.Attribution({
|
|
html: '© BRGM (French USGS equivalent)'
|
|
})
|
|
],
|
|
projection:"EPSG:3857",
|
|
params:
|
|
{ 'LAYERS': 'SCAN_F_GEOL1M', //'SCAN_D_GEOL50',
|
|
'FORMAT': 'image/png',
|
|
'VERSION': '1.1.1'
|
|
}
|
|
//crossOrigin: 'anonymous',
|
|
})
|
|
});
|
|
// GeoJSON layer
|
|
var vectorSource = new ol.source.Vector(
|
|
{ url: '../data/fond_guerre.geojson',
|
|
projection: 'EPSG:3857',
|
|
format: new ol.format.GeoJSON(),
|
|
attributions: [new ol.Attribution({ html: "© <a href='https://www.data.gouv.fr/fr/datasets/fonds-de-la-guerre-14-18-extrait-de-la-base-memoire/'>data.gouv.fr</a>" })],
|
|
logo:"https://www.data.gouv.fr/s/avatars/37/e56718abd4465985ddde68b33be1ef.jpg"
|
|
});
|
|
var vector = new ol.layer.Vector(
|
|
{ name: '1914-18 (vector)',
|
|
// Set the preview for vector layer
|
|
preview: "http://www.culture.gouv.fr/Wave/image/memoire/2484/sap40_z0002136_v.jpg",
|
|
source: vectorSource
|
|
});
|
|
|
|
// The map
|
|
var map = new ol.Map
|
|
({ target: 'map',
|
|
//renderer: ["canvas", "webgl", "dom"], /* ["webgl", "canvas", "dom"] */
|
|
view: new ol.View
|
|
({ zoom: 6,
|
|
center: [270148, 6247782]
|
|
}),
|
|
controls: ol.control.defaults().extend
|
|
([ // Add a new Layerswitcher to the map
|
|
new ol.control.LayerSwitcher()
|
|
]),
|
|
layers: [osm,stamen,brgm, vector]
|
|
});
|
|
|
|
// Fill select with maps layer
|
|
var select = $("#preview select").on("change", function () { showPreview(layers[this.value]);} );
|
|
var layers = map.getLayers().getArray();
|
|
for (var i = 0; i<layers.length; i++)
|
|
{ $("<option>").val(i)
|
|
.text(layers[i].get('title') || layers[i].get('name'))
|
|
.appendTo(select);
|
|
}
|
|
// Display preview in the img div
|
|
function showPreview (l)
|
|
{ $("#preview .img").html("");
|
|
var pv = l.getPreview(map.getView().getCenter());
|
|
for (var i=0; i<pv.length; i++) $("<img>").attr('src',pv[i]).appendTo("#preview .img");
|
|
}
|
|
showPreview(layers[0]);
|
|
|
|
</script>
|
|
|
|
</body>
|
|
</html> |