187 lines
5.4 KiB
HTML
187 lines
5.4 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html xmlns="https://www.w3.org/1999/xhtml">
|
|
<head>
|
|
<title>Leaflet Panel Layers</title>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
|
|
|
<link rel="stylesheet" href="https://unpkg.com/ion-rangeslider@2.2.0/css/ion.rangeSlider.css" />
|
|
<link rel="stylesheet" href="https://unpkg.com/ion-rangeslider@2.2.0/css/ion.rangeSlider.skinNice.css" />
|
|
|
|
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css" integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ==" crossorigin=""/>
|
|
<link rel="stylesheet" href="../src/leaflet-panel-layers.css" />
|
|
|
|
<link rel="stylesheet" href="icons.css" />
|
|
<link rel="stylesheet" href="style.css" />
|
|
</head>
|
|
|
|
<body>
|
|
<h3><a href="../"><big>◄</big> Leaflet Panel Layers</a></h3>
|
|
<h4> Custom List Layer Example: multiple base layers and overlays with Custom icon and opacity slider</h4>
|
|
<br />
|
|
<div id="map"></div>
|
|
|
|
<div id="copy"><a href="https://opengeo.tech/">Labs</a> • <a rel="author" href="https://opengeo.tech/stefano-cudini/">Stefano Cudini</a></div>
|
|
|
|
<a href="https://github.com/stefanocudini/leaflet-panel-layers"><img id="ribbon" src="https://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a>
|
|
|
|
<script src="https://unpkg.com/jquery@2.1.1/dist/jquery.min.js"></script>
|
|
<script src="https://unpkg.com/ion-rangeslider@2.2.0/js/ion.rangeSlider.js"></script>
|
|
|
|
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js" integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew==" crossorigin=""></script>
|
|
<script src="../src/leaflet-panel-layers.js"></script>
|
|
<!-- GEOJSON DATA -->
|
|
<script src="data/bar.js"></script>
|
|
<script src="data/fuel.js"></script>
|
|
<script src="data/parking.js"></script>
|
|
<script src="data/drinking_water.js"></script>
|
|
<script>
|
|
|
|
var osmLayer = new L.TileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'),
|
|
map = L.map('map', {
|
|
zoom: 11,
|
|
attributionControl: false,
|
|
center: L.latLng([42.4918,12.4992]),
|
|
maxBounds: L.latLngBounds([[42.41281,12.28821],[42.5589,12.63805]]).pad(0.5),
|
|
layers: osmLayer
|
|
});
|
|
|
|
function iconByName(name) {
|
|
return '<i class="icon icon-'+name+'"></i>';
|
|
}
|
|
|
|
function featureToMarker(feature, latlng) {
|
|
return L.marker(latlng, {
|
|
icon: L.divIcon({
|
|
className: 'marker-'+feature.properties.amenity,
|
|
html: iconByName(feature.properties.amenity),
|
|
iconUrl: 'images/markers/'+feature.properties.amenity+'.png',
|
|
iconSize: [25, 41], iconAnchor: [12, 41],
|
|
popupAnchor: [1, -34], shadowSize: [41, 41]
|
|
})
|
|
});
|
|
}
|
|
|
|
map.addControl( new L.Control.PanelLayers(
|
|
//baselayers
|
|
[
|
|
{
|
|
name: "OpenStreetMap",
|
|
layer: osmLayer
|
|
},
|
|
{
|
|
name: "OpenCycleMap",
|
|
layer: L.tileLayer('https://{s}.tile.opencyclemap.org/cycle/{z}/{x}/{y}.png')
|
|
}
|
|
],
|
|
//overlays
|
|
[
|
|
{
|
|
name: "Bar",
|
|
background: 'images/icons/bar.png',
|
|
layer: L.geoJson(Bar, {pointToLayer: featureToMarker })
|
|
},
|
|
{
|
|
name: "Drinking Water",
|
|
background: 'images/icons/drinking_water.png',
|
|
layer: L.geoJson(Drinking_water, {pointToLayer: featureToMarker })
|
|
},
|
|
{
|
|
name: "Fuel",
|
|
background: 'images/icons/fuel.png',
|
|
layer: L.geoJson(Fuel, {pointToLayer: featureToMarker })
|
|
},
|
|
{
|
|
name: "Parking",
|
|
background: 'images/icons/parking.png',
|
|
layer: L.geoJson(Parking, {pointToLayer: featureToMarker })
|
|
}
|
|
],
|
|
//options
|
|
{
|
|
buildItem: function(item) {
|
|
|
|
var points = item.layer.getLayers ? item.layer.getLayers().length : 0,
|
|
label = points ? ' #'+points : '',
|
|
size = Math.min(18,Math.max(9,points))+'px',
|
|
node = L.DomUtil.create('span','');
|
|
|
|
node.innerHTML = label;
|
|
|
|
if(points)
|
|
node.style.fontSize = size;
|
|
|
|
if(item.background) {
|
|
node.style.background = "url('"+item.background+"') center left no-repeat";
|
|
node.style.paddingLeft = '24px';
|
|
}
|
|
|
|
return node;
|
|
}
|
|
}
|
|
) );
|
|
|
|
L.control.panelLayers(null, [{
|
|
group: "WMS Natural Layers",
|
|
layers: [
|
|
{
|
|
active: true,
|
|
name: "Isolines",
|
|
layer: {
|
|
type: "tileLayer.wms",
|
|
args: ["https://siat.regione.umbria.it/arcgis/services/public/DBT_05_Orografia/MapServer/WMSServer", {
|
|
layers: '13',
|
|
format: 'image/png',
|
|
transparent: true,
|
|
opacity: 0.5
|
|
}
|
|
]
|
|
}
|
|
},
|
|
{
|
|
active: true,
|
|
name: "Streams",
|
|
layer: {
|
|
type: "tileLayer.wms",
|
|
args: ["https://siat.regione.umbria.it/arcgis/services/public/DBT_04_Idrografia/MapServer/WMSServer", {
|
|
layers: '6',
|
|
format: 'image/png',
|
|
transparent: true
|
|
}
|
|
]
|
|
}
|
|
}
|
|
]
|
|
}], {
|
|
position: 'bottomright',
|
|
buildItem: function(item) {
|
|
|
|
var $slider = $('<div class="layer-slider">');
|
|
|
|
var $input = $('<input type="text" value="' + item.layer.options.opacity + '" />');
|
|
|
|
$slider.append($input);
|
|
|
|
$input.ionRangeSlider({
|
|
min: 0.1,
|
|
max: 1,
|
|
step: 0.01,
|
|
hide_min_max: true,
|
|
hide_from_to: true,
|
|
from: item.layer.options.opacity,
|
|
onChange: function(o) {
|
|
item.layer.setOpacity(o.from);
|
|
}
|
|
});
|
|
|
|
return $slider[0];
|
|
}
|
|
}).addTo(map);
|
|
|
|
|
|
</script>
|
|
|
|
<script type="text/javascript" src="/labs-common.js"></script>
|
|
|
|
</body>
|
|
</html>
|