Support other tilesets, xyz tiles, etc. Fixes #130

This commit is contained in:
Tom MacWright
2012-11-30 17:25:48 -05:00
parent 4abc8b394b
commit fa2d04dfe7
4 changed files with 21 additions and 3 deletions

View File

@@ -50,6 +50,8 @@
</head>
<body>
<div id="iD"></div>
<script>iD(document.getElementById('iD'));</script>
<script>
iD(document.getElementById('iD'));
</script>
</body>
</html>

View File

@@ -149,6 +149,8 @@ var iD = function(container) {
d3.select('.user').call(iD.userpanel(connection)
.on('logout', connection.logout)
.on('login', connection.authenticate));
return map;
};
iD.supported = function() {

View File

@@ -510,6 +510,7 @@ iD.Map = function(elem, connection) {
map.selectEntity = selectEntity;
map.tileclient = tileclient;
map.center = center;
map.centre = center;
map.getZoom = getZoom;

View File

@@ -1,5 +1,6 @@
iD.Tiles = function(selection, projection) {
var t = {},
template = 'http://ecn.t{t}.tiles.virtualearth.net/tiles/a{u}.jpeg?g=587&mkt=en-gb&n=z',
tile = d3.geo.tile();
// derive the url of a 'quadkey' style tile from a coordinate object
@@ -14,7 +15,12 @@ iD.Tiles = function(selection, projection) {
}
// distribute requests against multiple domains
var t = coord[2] % 5;
return 'http://ecn.t' + t + '.tiles.virtualearth.net/tiles/a' + u + '.jpeg?g=587&mkt=en-gb&n=z';
return template
.replace('{t}', t)
.replace('{u}', u)
.replace('{x}', coord[0])
.replace('{y}', coord[1])
.replace('{z}', coord[2]);
}
// derive the tiles onscreen, remove those offscreen and position tiles
@@ -29,7 +35,7 @@ iD.Tiles = function(selection, projection) {
return "scale(" + tiles.scale + ")translate(" + tiles.translate + ")";
})
.selectAll("image")
.data(tiles, function(d) { return d; });
.data(tiles, function(d) { return [d.join(), template].join(); });
image.exit()
.remove();
@@ -48,6 +54,13 @@ iD.Tiles = function(selection, projection) {
return t;
}
t.template = function(x) {
if (!arguments.length) return template;
template = x;
redraw();
return t;
};
t.setSize = setSize;
t.redraw = redraw;