-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathleaflet_gradient.html
More file actions
65 lines (61 loc) · 2.01 KB
/
Copy pathleaflet_gradient.html
File metadata and controls
65 lines (61 loc) · 2.01 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.6.0/leaflet.css">
<style>
html, body {
margin: 0;
padding: 0;
width: 100vw;
height: 100vh;
}
#map {
width: 100vw;
height: 100vh;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/leaflet/1.6.0/leaflet.js"></script>
<script>
const map = L.map("map").setView([14.0100298, 120.9965796], 16);
const osmTl = L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
// create a SVG radial gradient
// create a temporary marker to get the default marker layer
let circleMarker = L.circle([14.0100298, 120.9965796], {
radius: 1
}).addTo(map);
// get a reference to the SVG element
const svg = circleMarker.getElement().farthestViewportElement
const defs = svg.querySelector('defs') || svg.insertBefore( document.createElementNS(svg.namespaceURI,'defs'), svg.firstChild);
circleMarker.remove()
function createGradient(svgElem, id, stops) {
const radGrad = document.createElementNS(svg.namespaceURI, "radialGradient");
radGrad.setAttribute("id", id);
for (let s of stops) {
const stop = document.createElementNS(svg.namespaceURI, "stop");
for (let k in s) {
stop.setAttribute(k, s[k]);
}
radGrad.appendChild(stop);
}
defs.appendChild(radGrad);
}
createGradient(svg, "radgrad", [
{offset: "0%", "stop-color": "#f00"},
{offset: "80%", "stop-color": "orange"},
{offset: "100%", "stop-color": "#ff0"},
]);
// end radial gradient creation
L.circle([14.0100298, 120.9965796], {
fillColor: "url(#radgrad)", // id of the radial gradient
fillOpacity: 0.7,
stroke: false,
radius: 1000
}).addTo(map);
</script>
</body>
</html>