-
Notifications
You must be signed in to change notification settings - Fork 1
/
gmaps.html
64 lines (58 loc) · 1.58 KB
/
gmaps.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
62
63
64
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title>Google Maps API and drawnLayer</title>
<style>
html, body, #map {
width: 100%;
height: 100%;
margin: 0;
padding: 0;
overflow: hidden;
}
</style>
</head>
<body>
<div id="map"></div>
<script src="./gmaps.drawnLayer.js"></script>
<script>
// Generic Google Maps setup
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: {lat: 41.850, lng: -87.650}
});
// pass these values
var dl = new DrawnLayer('5Vy5RHT', 'landuse', function(geojson, canvasctx) {
geojson.features.map(function(feature) {
if (feature.properties.kind === 'residential') {
CustomDrawFunction(feature.geometry, canvasctx);
}
});
});
map.overlayMapTypes.insertAt(1, dl);
}
// 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>
<script async defer src="//maps.googleapis.com/maps/api/js?callback=initMap">
</script>
</body>
</html>