forked from broady/osm-layer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathosm.js
64 lines (51 loc) · 1.92 KB
/
osm.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
/**
* A base layer using OSM tiles.
*
* Tiles graciously provided by OSM (tile.openstreetmap.org)
*
* To use this layer, you must provide attribution to OSM. See:
* http://wiki.openstreetmap.org/wiki/Tile_usage_policy
* http://wiki.openstreetmap.org/wiki/Legal_FAQ#I_would_like_to_use_OpenStreetMap_maps._How_should_I_credit_you.3F
*
* You can do this by creating a new OSMBase.Attribution like this:
* new OSMBase.Attribution(map)
* The attribution will be shown in the bottom right of the map when the OSM
* layer is activated.
*/
function OSMBase() {
var mapType = new google.maps.ImageMapType(this);
mapType.showOSMAttribution = true;
return mapType;
}
OSMBase.prototype.tileSize = new google.maps.Size(256, 256);
OSMBase.prototype.alt = 'Open Street Map';
OSMBase.prototype.name = 'OSM Base';
OSMBase.prototype.servers_ = ['a', 'b', 'c'];
OSMBase.prototype.getTileUrl = function(coord, zoom) {
var numTiles = 1 << zoom;
var x = coord.x % numTiles;
x = x >= 0 ? x : x + numTiles;
var y = coord.y;
if (y < 0 || y >= numTiles) {
return null;
}
var server = this.servers_[(49 * x + y) % this.servers_.length];
return 'http://' + server + '.tile.openstreetmap.org/' + zoom + '/' + x + '/' + y + '.png'
};
OSMBase.prototype.minZoom = 0;
OSMBase.prototype.maxZoom = 18;
OSMBase.Attribution = function(map) {
var el = document.createElement('div');
var style = el.style;
style.display = 'none';
style.fontFamily = 'sans-serif';
style.fontSize = '11px';
el.innerHTML = 'Map data © <a href="http://www.openstreetmap.org/">' +
'OpenStreetMap</a> contributors, <a href="http://creativecommons.org/' +
'licenses/by-sa/2.0/">CC-BY-SA</a>'
map.controls[google.maps.ControlPosition.RIGHT_BOTTOM].push(el);
google.maps.event.addListener(map, 'maptypeid_changed', function() {
var show = map.mapTypes.get(map.getMapTypeId()).showOSMAttribution;
style.display = show ? '' : 'none';
});
};