GraduatedCirclesColor.html 3.19 KB
Newer Older
Boris Mericskay's avatar
Boris Mericskay committed
1
2
3
4
<html>
  
<head>
  <meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no" />
5
6
7
8
9
10
11
12
      <meta charset='utf-8' />
    <title>MapLibreGL / Graduated Circles Map</title>
	
	
	
<script src='https://unpkg.com/maplibre-gl@2.1.1/dist/maplibre-gl.js'></script>
<link href='https://unpkg.com/maplibre-gl@2.1.1/dist/maplibre-gl.css' rel='stylesheet' />

Boris Mericskay's avatar
Boris Mericskay committed
13
14
15

  <style>
#map {position: absolute; top: 0; right: 0; bottom: 0; left: 0;}  
16
17
18
19
20
21
22
23
24
25
26
    
.Mypopup .maplibregl-popup-content {
      background-color: black;
      color : white;
      opacity : 0.9;
	  height : 200px;
 	  width : 170px;

	  }
    
    
Boris Mericskay's avatar
Boris Mericskay committed
27
28
29
30
31
32
33
34
35
36
37
  </style>

  </head>

  <body> 
    
  <div id="map"></div>
   
   
<script>
   
38
      //Appel et configuration de la carte
Boris Mericskay's avatar
Boris Mericskay committed
39
    
40
var map = new maplibregl.Map({
Boris Mericskay's avatar
Boris Mericskay committed
41
42
43
44
45
46
47
48
49
  container: 'map',
  style: 'https://geoserveis.icgc.cat/contextmaps/positron.json', //Fond de carte 
  zoom: 11.7, // Zoom
  center: [2.335, 48.854],  // Centrage carte
  pitch: 10, // Inclinaison carte
  bearing: 0,  // Rotation carte
  minZoom:11.7
    });
    
50
  // Ajout des données
Boris Mericskay's avatar
Boris Mericskay committed
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
      
map.on('load', function () {   

// Add arrondissements

       map.addSource('lignes', {
            type: 'geojson',
            data: 'https://raw.githubusercontent.com/mastersigat/data/main/arrondissements.geojson' 
        });

     map.addLayer({
            'id': 'Lignes',
            'type': 'line',
            'source': 'lignes',
            'paint': {'line-width': 1,
                     'line-color': '#111111'}
     });   



// Add bike stations
  
  map.addSource('Stations', {
            type: 'geojson',
            data: 'https://raw.githubusercontent.com/mastersigat/data/main/velib-emplacement-des-stations.geojson' 
        });

     map.addLayer({
            'id': 'Stations',
            'type': 'circle',
            'source': 'Stations',
82
83
84
85
86
87
88
89
90
91
92
93
94
95
            'paint': {'circle-stroke-color': 'white', 
                      'circle-stroke-width': 1, 
                      'circle-radius': {
        property: 'capacity',
        type: 'exponential',
        stops: [
          [0, 0],
          [95, 20]
        ]
      },
                      'circle-color': '#0074D9'}}
                 );  

		 
Boris Mericskay's avatar
Boris Mericskay committed
96
97
98
99
		 
         });
  
  
100
  //Interactivité HOVER
Boris Mericskay's avatar
Boris Mericskay committed
101

102
var popup = new maplibregl.Popup({
Boris Mericskay's avatar
Boris Mericskay committed
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
    className: "Mypopup",
  closeButton: false,
    closeOnClick: false });

map.on('mousemove', function(e) {
    var features = map.queryRenderedFeatures(e.point, { layers: ['Stations'] });
    // Change the cursor style as a UI indicator.
    map.getCanvas().style.cursor = (features.length) ? 'pointer' : '';

    if (!features.length) {
        popup.remove();
        return; }
 
    var feature = features[0];
        popup.setLngLat(feature.geometry.coordinates)
118
119
	  .setHTML('<h2>'+ feature.properties.name + '</h2><hr> <img src="https://img.20mn.fr/E_l1DZgVR-K26DkVcvjpYQ/640x410_velib-paris-illustration.jpg" style="width:70%"><h3>' + 'Bike Capacity: ' + feature.properties.capacity + '</h3>')
      .addTo(map);
Boris Mericskay's avatar
Boris Mericskay committed
120
121
122

}); 

123

124
    // Add navigation control and scale
Boris Mericskay's avatar
Boris Mericskay committed
125
  
126
127
128
129
130
131
132
133
134
var nav = new maplibregl.NavigationControl();
map.addControl(nav, 'top-left');

var scale = new maplibregl.ScaleControl({
maxWidth: 80,
unit: 'metric'
});
map.addControl(scale);

Boris Mericskay's avatar
Boris Mericskay committed
135
136
137
138
  
</script>
    
</body>
139
</html>