ol-ext/examples/layer/map.wmscapabilities.html
2021-07-22 14:13:25 +02:00

222 lines
8.6 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<!--
Copyright (c) 2015-2020 Jean-Marc VIGLINO,
released under CeCILL-B (french BSD like) licence: http://www.cecill.info/
-->
<title>ol-ext: WMS Capabilities control</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="DBPedia layer for OL3" />
<meta name="keywords" content="openlayers, control, source, WMS, getCapabilities, capabilites" />
<!-- 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/latest/css/ol.css" />
<script type="text/javascript" src="https://openlayers.org/en/latest/build/ol.js"></script>
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=requestAnimationFrame,Element.prototype.classList,URL,Object.assign"></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>
<!-- Proj4 -->
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/proj4js/2.3.14/proj4.js"></script>
<!-- filesaver-js -->
<script type="text/javascript" src="https://cdn.rawgit.com/eligrey/FileSaver.js/aa9f4e0e/FileSaver.min.js"></script>
<link rel="stylesheet" href="../style.css" />
<style>
#map {
width: 100%;
height: 60vh;
}
.ol-wmscapabilities ul {
padding: 0;
}
</style>
</head>
<body >
<a href="https://github.com/Viglino/ol-ext" class="icss-github-corner"><i></i></a>
<a href="../../index.html">
<h1>ol-ext: WMS Capabilities control</h1>
</a>
<div class="info">
<b>ol/control/WMSCapabilities</b> is a control to load WMS layers on ol maps.
<br/>
It displays a dialog to select the service you want to add using getCapabilities of the service.
<br/>
Some services may not respond correctly because of
<a href="https://en.wikipedia.org/wiki/Cross-origin_resource_sharing">CORS policies</a>
and you may have to use a proxy to access the getCapabilities...
<br/>
Listen to the <i>load</i> event to get the selected layer or options to create it.
<br/>
Look at the console for the layer definition to insert into your code.
</div>
<!-- DIV pour la carte -->
<div id="map"></div>
<div class="options">
<ul>
<li>
url:
<input id="url" type="text" value="http://geoservices.brgm.fr/geologie" />
<button onclick="cap.showDialog($('#url').val())">search</button>
</li>
<li>
Services :
<button onclick="cap.showDialog('https://geoservices.brgm.fr/geologie'); ">BRGM</button>
<button onclick="cap.showDialog('https://services.sandre.eaufrance.fr/geo/sandre');">Sandre</button>
</li>
</ul>
<button onclick="exportCarte()" style="display: none;">exportCarte</button>
</div>
<script type="text/javascript">
// http services load on http
if (location.protocol === 'https:' && !/^localhost/.test(location.host)) {
location.href = window.location.href.replace(/^https:/,'http:');
}
// Define proj4 2154
proj4.defs("EPSG:2154","+proj=lcc +lat_1=49 +lat_2=44 +lat_0=46.5 +lon_0=3 +x_0=700000 +y_0=6600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs");
if (ol.proj.proj4 && ol.proj.proj4.register) ol.proj.proj4.register(proj4);
// The map
var map = new ol.Map({
target: 'map',
view: new ol.View ({
zoom: 15,
center: [261204.43490751847, 6250258.191535994]
}),
interactions: ol.interaction.defaults(),
layers: [ new ol.layer.Tile({ name:"OSM", source: new ol.source.OSM() })]
});
map.addControl(new ol.control.LayerSwitcher({
trash: true,
extent: true,
collapsed: false
}));
var plink = new ol.control.Permalink({ visible: false, localStorage: 'position' });
map.addControl(plink);
map.addControl(new ol.control.SearchNominatim({ zoomOnSelect: 13 }));
var cap = new ol.control.WMSCapabilities({
// target: $('.options').get(0),
target: document.body,
srs: ['EPSG:2154'],
cors: true,
services: {
'BRGM': 'https://geoservices.brgm.fr/geologie',
'OSM': 'https://wms.openstreetmap.fr/wms',
'Sandre': 'https://services.sandre.eaufrance.fr/geo/sandre', //'http://services.sandre.eaufrance.fr/geo/eth_FXX',
'Cartorisque': 'https://mapsref.brgm.fr/wxs/refcom-env/refign',
'Swiss Topo': 'https://wms.geo.admin.ch/',
'IFREMER*': 'http://tds0.ifremer.fr/thredds/wms/CORIOLIS-GLOBAL-NRTOA-OBS_TIME_SERIE?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&LAYERS=PSAL&CRS=EPSG%3A3857',
'Géorisque': 'https://mapsref.brgm.fr/wxs/georisques/risques',
'BDRisques': 'https://mapsref.brgm.fr/wxs/risques/bdrisques',
'Risques': 'https://geoservices.brgm.fr/risques',
'Natura 2000*': 'http://ws.carmencarto.fr/WMS/119/fxx_inpn?language=fre&SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&LAYERS=Zones_de_protection_speciale&CRS=EPSG%3A3857',
// https://www.cigalsace.org/portail/fr/page/723/flux-donnees -->
'Cigalsace': 'https://www.cigalsace.org/geoserver/cigal/ows',
'CG93-raster': 'https://geoportail93.fr/cgi-bin/mapserv?map=SIGD/raster.map',
'CG93-fond': 'https://geoportail93.fr/cgi-bin/mapserv?map=SIGD/fond_SIGD.map',
'CG94*': 'https://geo.valdemarne.fr/viewer/index.php?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&LAYERS=parcelles&CRS=EPSG%3A2154',
'GeoFoncier':'https://api.geofoncier.fr/referentielsoge/ogc/wxs',
// http://www.geolittoral.equipement.gouv.fr/rubrique.php3?id_rubrique=39 -->
// 'GeoLittoral*': 'http://geolittoral.application.equipement.gouv.fr/wms/metropole',
// http://www.sogefi-sig.com/sogefi-diffuse-des-donnees-en-wms/ -->
'SOGEFI': 'http://ws.sogefi-web.com/wms',
// http://inspire-geoportal.ec.europa.eu/discovery/ -->
'Photos anciennes litto': 'http://www.ifremer.fr/services/photos_anciennes',
'Geobretagne': 'https://geobretagne.fr/geoserver/dir_ouest/wms',
'Venise*': 'http://cigno.atlantedellalaguna.it/geoserver/ows?SERVICE=WMS&VERSION=1.3.0&FORMAT=image%2Fpng&LAYERS=carta_base',
'Geoportail': 'https://wxs.ign.fr/choisirgeoportail/geoportail/r/wms'
},
// Show trace in the console
trace: true
});
map.addControl(cap);
cap.on('load', function(e) {
map.addLayer(e.layer);
e.layer.set('legend', e.options.data.legend);
plink.setUrlParam('url', e.options.source.url);
plink.setUrlParam('layer', e.options.source.params.LAYERS);
});
var url = plink.getUrlParam('url');
var layerName = plink.getUrlParam('layer');
if (url) {
cap.loadLayer(url, layerName);
}
/* Export .carte file */
function exportCarte() {
var lonlat = ol.proj.toLonLat(map.getView().getCenter());
var carte = {
"param": {
"lon": lonlat[0],
"lat": lonlat[1],
"rot": 0,
"zoom": map.getView().getZoom(),
"titre": "WMS",
"description": ""
},
"layers": []
}
map.getLayers().getArray().forEach(function(l) {
if (l.get('WMS')) {
carte.layers.push({
"wms": true,
"type": "WMS",
"name": l.get('title'),
"titre": l.get('title'),
"visibility": l.getVisible(),
"opacity": l.getOpacity(),
"copyright": l.getSource().getAttributions()()[0] || '&copy;',
"wmsparam": {
"layer": {
"title": l.get('title'),
"extent": l.get('extent'),
"minResolution": l.getMinResolution(),
"maxResolution": l.getMaxResolution()
},
"source": {
"url": l.getSource().getUrls()[0],
"projection": "EPSG:3857",
"crossOrigin": "anonymous",
"params": {
"LAYERS": l.getSource().getParams().LAYERS,
"FORMAT": l.getSource().getParams().FORMAT,
"VERSION": l.getSource().getParams().VERSION,
"MAP": l.getSource().getParams().MAP || ''
}
},
"attribution": {
"html": l.getSource().getAttributions()()[0] || '&copy;'
},
"originator": [],
"legend": []
},
"maxZoomCluster": 20,
"radiusCluster": 40
})
}
});
var blob = new Blob([JSON.stringify(carte, null, ' ')], {type: 'text/plain;charset=utf-8'});
saveAs(blob, 'carte.carte');
}
</script>
</body>
</html>