-
Notifications
You must be signed in to change notification settings - Fork 2
/
GoogleMap_with_OneMap.html
92 lines (84 loc) · 2.83 KB
/
GoogleMap_with_OneMap.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>Example of OneMap with Google Map</title>
<style>
html, body, #map {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
div#footer {
position: fixed;
left: 0;
right: 0;
bottom: 0;
width: 100%;
height: 18px;
margin: 0;
padding: 6px;
z-index: 2;
background: WHITE;
}
</style>
</head>
<body>
<div id="map"></div>
<div id="footer"><img src="https://docs.onemap.sg/maps/images/oneMap64-01.png" style="height:16px;width:16px;"/>© Map data © contributors, <a href="http://SLA.gov.sg">Singapore Land Authority</a></div>
<script>
var map;
function initMap() {
var map = new google.maps.Map(document.getElementById('map'), {
center: {
lat: 1.3,
lng: 103.8
},
zoom: 11,
mapTypeId: google.maps.MapTypeId.ROADMAP,
disableDefaultUI: true
});
var OneMap = new google.maps.ImageMapType({
getTileUrl: function(coord, zoom) {
var normalizedCoord = getNormalizedCoord(coord, zoom);
if (!normalizedCoord) {
return null;
}
var bound = Math.pow(2, zoom);
return "https://maps-a.onemap.sg/v3/Default/" +
zoom + "/" + normalizedCoord.x + "/" + normalizedCoord.y + ".png";
},
tileSize: new google.maps.Size(256, 256),
maxZoom: 18,
minZoom: 11,
opacity: 0.5,
name: 'onemap'
});
// Normalizes the coords that tiles repeat across the x axis (horizontally)
// like the standard Google map tiles.
function getNormalizedCoord(coord, zoom) {
var y = coord.y;
var x = coord.x;
// tile range in one direction range is dependent on zoom level
// 0 = 1 tile, 1 = 2 tiles, 2 = 4 tiles, 3 = 8 tiles, etc
var tileRange = 1 << zoom;
// don't repeat across y-axis (vertically)
if (y < 0 || y >= tileRange) {
return null;
}
// repeat across x-axis
if (x < 0 || x >= tileRange) {
x = (x % tileRange + tileRange) % tileRange;
}
return {
x: x,
y: y
};
}
map.overlayMapTypes.insertAt(0, OneMap);
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?callback=initMap" async defer></script>
</body>
</html>