mirror of
https://github.com/FoggedLens/iD.git
synced 2026-05-18 14:45:12 +02:00
Extract iD.geo.RawMercator
This commit is contained in:
@@ -48,6 +48,7 @@
|
||||
<script src="js/id/geo.js"></script>
|
||||
<script src="js/id/geo/extent.js"></script>
|
||||
<script src="js/id/geo/multipolygon.js"></script>
|
||||
<script src="js/id/geo/raw_mercator.js"></script>
|
||||
<script src="js/id/geo/turn.js"></script>
|
||||
|
||||
<script src='js/id/renderer/background.js'></script>
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
Bypasses features of D3's default projection stream pipeline that are unnecessary:
|
||||
* Antimeridian clipping
|
||||
* Spherical rotation
|
||||
* Resampling
|
||||
*/
|
||||
iD.geo.RawMercator = function () {
|
||||
var project = d3.geo.mercator.raw,
|
||||
k = 512 / Math.PI, // scale
|
||||
x = 0, y = 0, // translate
|
||||
clipExtent = [[0, 0], [0, 0]];
|
||||
|
||||
function projection(point) {
|
||||
point = project(point[0] * Math.PI / 180, point[1] * Math.PI / 180);
|
||||
return [point[0] * k + x, y - point[1] * k];
|
||||
}
|
||||
|
||||
projection.invert = function(point) {
|
||||
point = project.invert((point[0] - x) / k, (y - point[1]) / k);
|
||||
return point && [point[0] * 180 / Math.PI, point[1] * 180 / Math.PI];
|
||||
};
|
||||
|
||||
projection.scale = function(_) {
|
||||
if (!arguments.length) return k;
|
||||
k = +_;
|
||||
return projection;
|
||||
};
|
||||
|
||||
projection.translate = function(_) {
|
||||
if (!arguments.length) return [x, y];
|
||||
x = +_[0];
|
||||
y = +_[1];
|
||||
return projection;
|
||||
};
|
||||
|
||||
projection.clipExtent = function(_) {
|
||||
if (!arguments.length) return clipExtent;
|
||||
clipExtent = _;
|
||||
return projection;
|
||||
};
|
||||
|
||||
projection.stream = d3.geo.transform({
|
||||
point: function(x, y) {
|
||||
x = projection([x, y]);
|
||||
this.stream.point(x[0], x[1]);
|
||||
}
|
||||
}).stream;
|
||||
|
||||
return projection;
|
||||
};
|
||||
+1
-46
@@ -197,52 +197,7 @@ window.iD = function () {
|
||||
};
|
||||
|
||||
/* Projection */
|
||||
function rawMercator() {
|
||||
var project = d3.geo.mercator.raw,
|
||||
k = 512 / Math.PI, // scale
|
||||
x = 0, y = 0, // translate
|
||||
clipExtent = [[0, 0], [0, 0]];
|
||||
|
||||
function projection(point) {
|
||||
point = project(point[0] * Math.PI / 180, point[1] * Math.PI / 180);
|
||||
return [point[0] * k + x, y - point[1] * k];
|
||||
}
|
||||
|
||||
projection.invert = function(point) {
|
||||
point = project.invert((point[0] - x) / k, (y - point[1]) / k);
|
||||
return point && [point[0] * 180 / Math.PI, point[1] * 180 / Math.PI];
|
||||
};
|
||||
|
||||
projection.scale = function(_) {
|
||||
if (!arguments.length) return k;
|
||||
k = +_;
|
||||
return projection;
|
||||
};
|
||||
|
||||
projection.translate = function(_) {
|
||||
if (!arguments.length) return [x, y];
|
||||
x = +_[0];
|
||||
y = +_[1];
|
||||
return projection;
|
||||
};
|
||||
|
||||
projection.clipExtent = function(_) {
|
||||
if (!arguments.length) return clipExtent;
|
||||
clipExtent = _;
|
||||
return projection;
|
||||
};
|
||||
|
||||
projection.stream = d3.geo.transform({
|
||||
point: function(x, y) {
|
||||
x = projection([x, y]);
|
||||
this.stream.point(x[0], x[1]);
|
||||
}
|
||||
}).stream;
|
||||
|
||||
return projection;
|
||||
}
|
||||
|
||||
context.projection = rawMercator();
|
||||
context.projection = iD.geo.RawMercator();
|
||||
|
||||
/* Background */
|
||||
var background = iD.Background(context);
|
||||
|
||||
@@ -46,6 +46,7 @@
|
||||
<script src="../js/id/geo.js"></script>
|
||||
<script src="../js/id/geo/extent.js"></script>
|
||||
<script src="../js/id/geo/multipolygon.js"></script>
|
||||
<script src="../js/id/geo/raw_mercator.js"></script>
|
||||
<script src="../js/id/geo/turn.js"></script>
|
||||
|
||||
<script src='../js/id/renderer/background.js'></script>
|
||||
|
||||
Reference in New Issue
Block a user