Leaflet Géoportail Ext : couches WMS
Utilisation de L.GeoportalLayer.WMS
by Géoportail IGNF
HTML
<script src="https://unpkg.com/leaflet@1.3.1/dist/leaflet.js"></script>
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.3.1/dist/leaflet.css">
<script src="https://ignf.github.io/geoportal-extensions/leaflet-latest/dist/GpPluginLeaflet.js"></script>
<link rel="stylesheet" href="https://ignf.github.io/geoportal-extensions/leaflet-latest/dist/GpPluginLeaflet.css">
<div id="map"></div>
<div id="info"></div>
CSS
#map {
padding: 5px;
width: 100%;
height: 300px;
box-shadow: 0 0 10px #999;
}
#info {
padding: 5px;
width: 100%;
height: 20px;
font-family: monospace;
}
JavaScript
function go() {
map = L.map("map",{crs : L.CRS.EPSG4326}).setView([16.239, -61.545], 12);
L.geoportalLayer.WMS({
layer: "OI.OrthoimageCoverage",
}, { // leafletParams
opacity: 0.7,
}).addTo(map);
L.geoportalLayer.WMS({
layer: "BU.Building"
},{
// on surcharche le style car les styles par defaut pour le WMS INSPIRE vecteur
// ne sont pas bien renseignes dans l'autoconf (en cours de correction)
styles : "inspire_common:DEFAULT",
transparent : true,
}).addTo(map);
L.geoportalLayer.WMS({
layer: "TN.RoadTransportNetwork",
},{
styles : "inspire_common:DEFAULT",
transparent : true,
}).addTo(map);
L.geoportalLayer.WMS({
layer: "HY.PhysicalWaters",
},{
styles : "inspire_common:DEFAULT",
transparent : true,
}).addTo(map);
L.geoportalLayer.WMS({
layer: "GN.GeographicalNames",
},{
styles : "inspire_common:DEFAULT",
transparent : true,
}).addTo(map);
}
Gp.Services.getConfig({
apiKey: "jhyvi0fgmnuxvfv0zjzorvdn",
onSuccess: go
});
var infoDiv = document.getElementById("info");
infoDiv.innerHTML = "<p> Extension Leaflet version " + Gp.leafletExtVersion + " (" + Gp.leafletExtDate + ")</p>";