-
Notifications
You must be signed in to change notification settings - Fork 1
/
basemap-tiles.js
131 lines (114 loc) · 4.56 KB
/
basemap-tiles.js
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
(function() {
var types = {
geolandbasemap: { format: 'png' },
bmapgrau: { format: 'png' },
bmaphidpi: { format: 'jpg' },
bmapgelaende: { format: 'jpg', style: 'grau' },
bmaporthofoto30cm: { format: 'jpg' },
bmapoverlay: { format: 'png' }
};
/*
* BasemapType for Google Maps API V3
* <https://developers.google.com/maps/documentation/javascript/>
*/
if (typeof google === "object" && typeof google.maps === "object") {
// Extending Google class based on a post by Bogart Salzberg of Portland Webworks,
// http://www.portlandwebworks.com/blog/extending-googlemapsmap-object
google.maps.ImageMapType = (function(_constructor) {
var f = function() {
if (!arguments.length) {
return;
}
_constructor.apply(this, arguments);
}
f.prototype = _constructor.prototype;
return f;
})(google.maps.ImageMapType);
google.maps.BasemapMapType = function(name) {
if (!(name in types)) throw new Error('Map type not found');
let { format, style = 'normal' } = types[name];
return google.maps.ImageMapType.call(this, {
"getTileUrl": function(coord, zoom) {
var numTiles = 1 << zoom,
wx = coord.x % numTiles,
x = (wx < 0) ? wx + numTiles : wx,
y = coord.y,
project = function(latLng) {
var siny = Math.sin(latLng.lat * Math.PI / 180);
return {
x: Math.floor((0.5 + latLng.lng / 360) * numTiles),
y: Math.floor((0.5 - Math.log((1 + siny) / (1 - siny)) / (4 * Math.PI)) * numTiles)
};
},
// EPSG:31297 Austria Lambert
allowedBounds = [{
lat: 46.41,
lng: 9.53
}, {
lat: 49.02,
lng: 17.17
}],
sw = project(allowedBounds[0]),
ne = project(allowedBounds[1]);
if (x > ne.x || y < ne.y || x < sw.x || y > sw.y) return null;
return "//mapsneu.wien.gv.at/basemap/{N}/{S}/google3857/{Z}/{Y}/{X}.{F}"
.replace("{N}", name)
.replace("{S}", style)
.replace("{Z}", zoom)
.replace("{X}", x)
.replace("{Y}", y)
.replace("{F}", format);
},
"tileSize": new google.maps.Size(256, 256),
"name": name,
"alt": 'Tiles © basemap.at',
"minZoom": 3,
"maxZoom": 19
});
};
google.maps.BasemapMapType.prototype = new google.maps.ImageMapType;
Basemap = function(map) {
var baseType = new google.maps.BasemapMapType(window.devicePixelRatio == 1 ? 'geolandbasemap' : 'bmaphidpi'),
terrainType = new google.maps.BasemapMapType('bmapgelaende'),
satelliteType = new google.maps.BasemapMapType('bmaporthofoto30cm'),
overlayType = new google.maps.BasemapMapType('bmapoverlay'),
allowedBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(46.41, 9.53),
new google.maps.LatLng(49.02, 17.17)
),
typeChangeListener = map.addListener('maptypeid_changed', function() {
// Terrain tiles
if (map.getMapTypeId() == 'terrain') {
map.overlayMapTypes.clear()
map.overlayMapTypes.insertAt(0, terrainType);
}
// Sattelite tiles displayed for both 'hybrid' and 'satellite'
if (map.getMapTypeId() == 'hybrid' || map.getMapTypeId() == 'satellite') {
map.overlayMapTypes.clear()
map.overlayMapTypes.insertAt(0, satelliteType);
}
// For 'hybrid' and 'terrain' also caption layer is added
if (map.getMapTypeId() == 'hybrid' || map.getMapTypeId() == 'terrain') {
map.overlayMapTypes.insertAt(1, overlayType);
}
// Default type is usually 'roadmap'
if (map.getMapTypeId() == 'roadmap') {
map.overlayMapTypes.clear()
map.overlayMapTypes.push(baseType);
}
}),
attribution = document.createElement('div');
attribution.innerHTML = 'Datenquelle: <a href="http://www.basemap.at/" target="_blank">basemap.at</a>';
attribution.style.cssText = 'white-space: nowrap;background-color: #fff;opacity: .7;padding: 1px 5px 2px;font-size: 10px';
map.controls[google.maps.ControlPosition.BOTTOM_RIGHT].push(attribution);
map.overlayMapTypes.clear();
map.overlayMapTypes.push(baseType);
map.setOptions({
restriction: {
latLngBounds: allowedBounds,
strictBounds: false,
},
});
}
}
})();