-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTileLayerWithColorPicker.html
More file actions
46 lines (43 loc) · 1.66 KB
/
TileLayerWithColorPicker.html
File metadata and controls
46 lines (43 loc) · 1.66 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>TileLayerWithColorPicker for leaflet 2.0.0-alpha.1</title>
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0" />
<link href="https://unpkg.com/leaflet@2.0.0-alpha.1/dist/leaflet.css" rel="stylesheet" />
<script type="importmap">
{
"imports": {
"leaflet": "https://unpkg.com/leaflet@2.0.0-alpha.1/dist/leaflet.js",
"colorpicker": "./TileLayerWithColorPicker.js"
}
}
</script>
</head>
<body>
<div id="map" style="position: absolute; top: 0; left: 0; right: 0; bottom: 0"></div>
<script type="module">
import { Map } from "leaflet";
import TileLayerWithColorPicker from "colorpicker";
const map = new Map("map").setView([35.6323, 139.768815], 15);
const colorpicker = new TileLayerWithColorPicker(
"https://cyberjapandata.gsi.go.jp/xyz/pale/{z}/{x}/{y}.png",
{
maxZoom: 18,
attribution: '<a href="https://maps.gsi.go.jp/development/ichiran.html">GSI pale</a>',
}
).addTo(map);
map.on("pointermove", function (event) {
const a = colorpicker.getColor(event.latlng);
if (a !== null) {
const hex = "#" + (0x1000000 + (a[0] << 16) + (a[1] << 8) + a[2]).toString(16).substr(1);
var tmpl = "<b style='background:@;color:black;'>@</b>";
if (Math.min(a[0], a[1], a[2]) < 0x40) tmpl = tmpl.replace("black", "white");
map.attributionControl.setPrefix(tmpl.replace(/@/g, hex));
} else {
map.attributionControl.setPrefix("unavailable");
}
});
</script>
</body>
</html>