Bonjour,

J'aimerai connaître le niveau de zoom des cartes affichées avec l'API Leaflet, j'ai trouvé un développement avec affichage d'une fenêtre.
Code HTML : Sélectionner tout - Visualiser dans une fenêtre à part
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
<!DOCTYPE html>
<html>
<head>
 
	<title>Zoom Levels Tutorial - Leaflet</title>
 
	<meta charset="utf-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0">
 
	<link rel="shortcut icon" type="image/x-icon" href="docs/images/favicon.ico" />
 
    <link rel="stylesheet" href="https://unpkg.com/leaflet@1.7.1/dist/leaflet.css" integrity="sha512-xodZBNTC5n17Xt2atTPuE1HxjVMSvLVW9ocqUKLsCC5CXdbqCmblAshOMAS6/keqq/sMZMZ19scR4PsZChSR7A==" crossorigin=""/>
    <script src="https://unpkg.com/leaflet@1.7.1/dist/leaflet.js" integrity="sha512-XQoYMqMTK8LvdxXYG3nZ448hOEQiglfqkJs1NOQV44cWnUrBc8PkAOcXy20w0vlaXaVUearIOBhiXZ5V3ynxwA==" crossorigin=""></script>
 
 
	<style>
                html, body {
                        height: 100%;
                        margin: 0;
                }
                #map {
                        width: 800px;
                        height: 600px;
                }
        </style>
 
 
</head>
<body>
 
<div id='map'></div>
 
<script>
 
        var map = L.map('map', {
                zoom: 6,
                attributionControl: false,
                center: L.latLng([28,-8]),
                
        }),
 
        osmLayer = new L.TileLayer('http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png');
 
map.addLayer(osmLayer);
 
        var ZoomViewer = L.Control.extend({
                onAdd: function(){
                        var gauge = L.DomUtil.create('div');
                        gauge.style.width = '200px';
                        gauge.style.margin = '10px 100px 0px 0px';
                        gauge.style.background = 'rgba(255,255,255,0.5)';
                        gauge.style.textAlign = 'left';
                        map.on('zoomstart zoom zoomend', function(ev){
                                gauge.innerHTML = 'Zoom level: ' + map.getZoom();
                        })
                        return gauge;
                }
        });
 
        (new ZoomViewer).addTo(map);
        
</script>
 
</body>
</html>
Pour éviter d'avoir cette fenêtre, serait-il possible de mettre cette valeur de zoom dans le bouton de Zoom "+" ?

Dans le fichier leaflet.js, il y a cette syntaxe
Code : Sélectionner tout - Visualiser dans une fenêtre à part
{position:"topleft",zoomInText:"+",zoomInTitle:"Zoom in",zoomOutText:"&#x2212;",zoomOutTitle:"Zoom out"}
J'ai essayé de remplacer "zoomInText:"+"" par zoomInText:"+" + map.getZoom() , ce n'est pas reconnu. Quelle serait la syntaxe à insérer ?

Avec mes remerciements

Bernard