-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
61 lines (55 loc) · 1.63 KB
/
index.html
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Leaflet drawnLayer</title>
<link rel="stylesheet" href="//unpkg.com/leaflet@1.0.1/dist/leaflet.css" />
<style>
html, body, #map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="//unpkg.com/leaflet@1.0.1/dist/leaflet.js"></script>
<script src="./L.drawnLayer.js"></script>
<script>
// Generic Leaflet setup
var map = L.map('map').setView([51.505, -0.09], 13);
L.tileLayer('http://{s}.tile.osm.org/{z}/{x}/{y}.png', {
attribution: '© <a href="http://osm.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
// pass these values
L.drawnLayer('5Vy5RHT', 'landuse', function(geojson, canvasctx) {
geojson.features.map(function(feature) {
if (feature.properties.kind === 'residential') {
CustomDrawFunction(feature.geometry, canvasctx);
}
});
}).addTo(map);
// your custom renderer
function CustomDrawFunction(geometry, canvasctx) {
// only draw outer ring of polygons
var coords = (geometry.type === 'Polygon') ? geometry.coordinates[0] : geometry.coordinates;
// draw shape
canvasctx.beginPath();
canvasctx.moveTo(coords[0].x, coords[0].y);
for (var pt = 1; pt < coords.length; pt++) {
canvasctx.lineTo(coords[pt].x, coords[pt].y);
}
canvasctx.closePath();
// fill in the shape
canvasctx.fillStyle = 'darkgreen';
canvasctx.fill();
// if you just wanted to draw an outline
canvasctx.strokeStyle = 'darkgreen';
canvasctx.stroke();
}
</script>
</body>
</html>