GraduatedCircles.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" />
Boris Mericskay's avatar
Boris Mericskay committed
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;}  
Boris Mericskay's avatar
Boris Mericskay committed
16
17
    
.Mypopup .maplibregl-popup-content {
Boris Mericskay's avatar
Boris Mericskay committed
18
19
      background-color: black;
      color : white;
Boris Mericskay's avatar
Boris Mericskay committed
20
21
22
23
24
25
26
      opacity : 0.9;
	  height : 200px;
 	  width : 170px;

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

  </head>

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


Boris Mericskay's avatar
Boris Mericskay committed
70

Boris Mericskay's avatar
Boris Mericskay committed
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
// 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',
            'paint': {'circle-stroke-color': 'white', 
                      'circle-stroke-width': 1, 
                      'circle-radius': {
        property: 'capacity',
        type: 'exponential',
Boris Mericskay's avatar
Boris Mericskay committed
87
88
89
90
91
        stops: [
          [0, 0],
          [95, 20]
        ]
      },
Boris Mericskay's avatar
Boris Mericskay committed
92
93
94
                      'circle-color': '#0074D9'}}
                 );  

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

Boris Mericskay's avatar
Boris Mericskay committed
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)
Boris Mericskay's avatar
Boris Mericskay committed
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

}); 


Boris Mericskay's avatar
Boris Mericskay committed
124
    // Add navigation control and scale
Boris Mericskay's avatar
Boris Mericskay committed
125
  
Boris Mericskay's avatar
Boris Mericskay committed
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>
Boris Mericskay's avatar
Boris Mericskay committed
139
</html>