WMSmap.html 3.29 KB
Newer Older
Boris Mericskay's avatar
Boris Mericskay committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<html>
<head>
  <meta charset="utf-8" />
    <title>MapLibreGL / WMS</title>
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
  <script src="https://cdn.maptiler.com/maplibre-gl-js/v1.13.0-rc.4/mapbox-gl.js"></script>
  <link href="https://cdn.maptiler.com/maplibre-gl-js/v1.13.0-rc.4/mapbox-gl.css" rel="stylesheet" />

  <style>
    #map {position: absolute; top: 0; right: 0; bottom: 0; left: 0;}
    
    .menu {
     position: absolute;
     top: 10px;
     left: 30px;
     width: 180px;
     background-color: #FFFFFF;
     opacity: 0.89;
     color: #000000;
     font: 13px/20px 'Helvetica Neue', Arial, Helvetica, sans-serif;
      padding:10;
        }

  </style>

  </head>

  <body> 
  <div id="map"></div>
   <div class='menu'>
    <hr>
<label class="categoryLabel"><B>Imagery</B></label>
          <br>
     <input type="checkbox" id="Ortho2020" value="Ortho2020" onchange="switchlayer('Ortho2020')" />
<label for="Ortho2020">Ortho2020</label>
          <hr>
<label class="categoryLabel"><B>Thematic data</B></label>
          <br>
<input type="checkbox" id="Cadastre" value="Cadastre" onchange="switchlayer('Cadastre')" checked/>
<label for="Cadastre">Cadastral plan</label>
          <br>
<input type="checkbox" id="Metro" value="Metro" onchange="switchlayer('Metro')" checked/>
<label for="Metro">Subway stations</label>
  <hr>
</div>
    <script>
   
      //Map Configuration
      
var map = new mapboxgl.Map({
      container: 'map',
      style: 'https://geoserveis.icgc.cat/contextmaps/positron.json',
      zoom: 16.5,
      center: [-1.674, 48.105],
  pitch: 20
    });
    
      // ADD WMS
      
map.on('load', function () {
  
 
  // Imagery
  map.addSource('Ortho2020', {
'type': 'raster',

'tiles': [
'https://public.sig.rennesmetropole.fr/geoserver/ows?bbox={bbox-epsg-3857}&format=image/png&service=WMS&version=1.3.0&request=GetMap&srs=EPSG:3857&transparent=true&width=256&height=256&raster-opacity=0.5&layers=raster:ortho2020'
],
'tileSize': 256
});
  
map.addLayer(
{'id': 'Ortho2020',
'type': 'raster',
'source': 'Ortho2020',
'layout': {'visibility': 'none'},
'paint': {'raster-opacity':0.6,}}
);
   
   
  // Subway stations
  
map.addSource('Metro', {
'type': 'raster',
'tiles': [
'https://public.sig.rennesmetropole.fr/geoserver/ows?bbox={bbox-epsg-3857}&format=image/png&service=WMS&version=1.3.0&request=GetMap&srs=EPSG:3857&transparent=true&width=256&height=256&layers=trp_coll:metro_station'
],
'tileSize': 256
});
      
 map.addLayer(
{
'id': 'Metro',
'type': 'raster',
'source': 'Metro',
'paint': {}
}
);
  
   
    // Cadastral plan
  
map.addSource('Cadastre', {
'type': 'raster',
'tiles': [
'https://public.sig.rennesmetropole.fr/geoserver/ows?bbox={bbox-epsg-3857}&format=image/png&service=WMS&version=1.3.0&request=GetMap&srs=EPSG:3857&transparent=true&width=256&height=256&layers=ref_cad:parcelle'
],
'tileSize': 256
});
      
 map.addLayer(
{
'id': 'Cadastre',
'type': 'raster',
'source': 'Cadastre',
'paint': {}
}
);
  
  
});
      

// Menu display configuration
 switchlayer = function (lname) {
            if (document.getElementById(lname ).checked) {
                map.setLayoutProperty(lname, 'visibility', 'visible');
            } else {
                map.setLayoutProperty(lname, 'visibility', 'none');
           }
        };
  
  
  </script>
</body>
</html>