Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Stashing work on geoprojection, refs d3/d3-plugins#37

  • Loading branch information...
commit 7cda89b75753b9ad4d300e267bae5b0f5f86995c 1 parent 29577f7
@tmcw tmcw authored
Showing with 16 additions and 37 deletions.
  1. +5 −4 js/id/renderer/background.js
  2. +11 −33 js/id/renderer/map.js
View
9 js/id/renderer/background.js
@@ -47,17 +47,18 @@ iD.Background = function() {
// derive the tiles onscreen, remove those offscreen and position tiles
// correctly for the currentstate of `projection`
function background() {
- var tiles = tile
+ var trans = projection([0, 0]),
+ tiles = tile
.scale(projection.scale())
.scaleExtent(source.scaleExtent || [1, 17])
- .translate(projection.translate())(),
+ .translate(trans)(),
scaleExtent = tile.scaleExtent(),
z = Math.max(Math.log(projection.scale()) / Math.log(2) - 8, 0),
rz = Math.max(scaleExtent[0], Math.min(scaleExtent[1], Math.floor(z))),
ts = 256 * Math.pow(2, z - rz),
tile_origin = [
- projection.scale() / 2 - projection.translate()[0],
- projection.scale() / 2 - projection.translate()[1]],
+ projection.scale() / 2 - trans[0],
+ projection.scale() / 2 - trans[1]],
ups = {};
tiles.forEach(function(d) {
View
44 js/id/renderer/map.js
@@ -5,7 +5,7 @@ iD.Map = function() {
projection = d3.geo.mercator().scale(1024),
roundedProjection = iD.svg.RoundProjection(projection),
zoom = d3.behavior.zoom()
- .translate(projection.translate())
+ .translate([0, 0])
.scale(projection.scale())
.scaleExtent([1024, 256 * Math.pow(2, 24)])
.on('zoom', zoomPan),
@@ -133,7 +133,10 @@ iD.Map = function() {
}
projection
- .translate(d3.event.translate)
+ .center(projection.invert([
+ d3.event.translate[0],
+ d3.event.translate[1]
+ ]))
.scale(d3.event.scale);
var ascale = d3.event.scale;
@@ -149,6 +152,7 @@ iD.Map = function() {
tilegroup.style(transformProp, transform);
surface.style(transformProp, transform);
+
queueRedraw();
}
@@ -177,18 +181,6 @@ iD.Map = function() {
var queueRedraw = _.debounce(redraw, 200);
- function pointLocation(p) {
- var translate = projection.translate(),
- scale = projection.scale();
- return [(p[0] - translate[0]) / scale, (p[1] - translate[1]) / scale];
- }
-
- function locationPoint(l) {
- var translate = projection.translate(),
- scale = projection.scale();
- return [l[0] * scale + translate[0], l[1] * scale + translate[1]];
- }
-
map.mouseCoordinates = function() {
try {
return projection.invert(d3.mouse(surface.node()));
@@ -211,33 +203,19 @@ iD.Map = function() {
};
function setZoom(z) {
- var scale = 256 * Math.pow(2, z),
- center = pxCenter(),
- l = pointLocation(center);
- scale = Math.max(1024, Math.min(256 * Math.pow(2, 24), scale));
- projection.scale(scale);
+ projection.scale(256 << z);
zoom.scale(projection.scale());
- var t = projection.translate();
- l = locationPoint(l);
- t[0] += center[0] - l[0];
- t[1] += center[1] - l[1];
- projection.translate(t);
- zoom.translate(projection.translate());
}
function setCenter(loc) {
- var t = projection.translate(),
- c = pxCenter(),
- ll = projection(loc);
- projection.translate([
- t[0] - ll[0] + c[0],
- t[1] - ll[1] + c[1]]);
- zoom.translate(projection.translate());
+ projection.center(loc);
+ zoom.translate(projection([0, 0]));
}
map.size = function(_) {
if (!arguments.length) return dimensions;
dimensions = _;
+ projection.translate(pxCenter());
surface.size(dimensions);
background.size(dimensions);
return redraw();
@@ -248,7 +226,7 @@ iD.Map = function() {
map.center = function(loc) {
if (!arguments.length) {
- return projection.invert(pxCenter());
+ return projection.center();
} else {
setCenter(loc);
return redraw();
Please sign in to comment.
Something went wrong with that request. Please try again.