Merge pull request #260 from twpayne/projections-in-feet
Projections in feet
This commit is contained in:
@@ -168,11 +168,13 @@ ol.control.ScaleLine.prototype.updateElement_ = function(frameState) {
|
|||||||
this.toEPSG4326_ = null;
|
this.toEPSG4326_ = null;
|
||||||
cosLatitude = Math.cos(goog.math.toRadians(center.y));
|
cosLatitude = Math.cos(goog.math.toRadians(center.y));
|
||||||
pointResolution *= Math.PI * cosLatitude * ol.sphere.NORMAL.radius / 180;
|
pointResolution *= Math.PI * cosLatitude * ol.sphere.NORMAL.radius / 180;
|
||||||
|
projectionUnits = ol.ProjectionUnits.METERS;
|
||||||
|
|
||||||
} else if (projectionUnits == ol.ProjectionUnits.METERS &&
|
} else if ((projectionUnits == ol.ProjectionUnits.FEET ||
|
||||||
|
projectionUnits == ol.ProjectionUnits.METERS) &&
|
||||||
this.units_ == ol.control.ScaleLineUnits.DEGREES) {
|
this.units_ == ol.control.ScaleLineUnits.DEGREES) {
|
||||||
|
|
||||||
// Convert pointResolution from meters to degrees
|
// Convert pointResolution from meters or feet to degrees
|
||||||
if (goog.isNull(this.toEPSG4326_)) {
|
if (goog.isNull(this.toEPSG4326_)) {
|
||||||
this.toEPSG4326_ = ol.projection.getTransform(
|
this.toEPSG4326_ = ol.projection.getTransform(
|
||||||
projection, ol.projection.getFromCode('EPSG:4326'));
|
projection, ol.projection.getFromCode('EPSG:4326'));
|
||||||
@@ -180,20 +182,26 @@ ol.control.ScaleLine.prototype.updateElement_ = function(frameState) {
|
|||||||
var vertex = [center.x, center.y];
|
var vertex = [center.x, center.y];
|
||||||
vertex = this.toEPSG4326_(vertex, vertex, 2);
|
vertex = this.toEPSG4326_(vertex, vertex, 2);
|
||||||
cosLatitude = Math.cos(goog.math.toRadians(vertex[1]));
|
cosLatitude = Math.cos(goog.math.toRadians(vertex[1]));
|
||||||
pointResolution *= 180 / (Math.PI * cosLatitude * ol.sphere.NORMAL.radius);
|
var radius = ol.sphere.NORMAL.radius;
|
||||||
|
if (projectionUnits == ol.ProjectionUnits.FEET) {
|
||||||
|
radius /= 0.3048;
|
||||||
|
}
|
||||||
|
pointResolution *= 180 / (Math.PI * cosLatitude * radius);
|
||||||
|
projectionUnits = ol.ProjectionUnits.DEGREES;
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
this.toEPSG4326_ = null;
|
this.toEPSG4326_ = null;
|
||||||
goog.asserts.assert(
|
|
||||||
((this.units_ == ol.control.ScaleLineUnits.METRIC ||
|
|
||||||
this.units_ == ol.control.ScaleLineUnits.IMPERIAL) &&
|
|
||||||
projectionUnits == ol.ProjectionUnits.METERS) ||
|
|
||||||
(this.units_ == ol.control.ScaleLineUnits.DEGREES &&
|
|
||||||
projectionUnits == ol.ProjectionUnits.DEGREES));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
goog.asserts.assert(
|
||||||
|
((this.units_ == ol.control.ScaleLineUnits.METRIC ||
|
||||||
|
this.units_ == ol.control.ScaleLineUnits.IMPERIAL) &&
|
||||||
|
projectionUnits == ol.ProjectionUnits.METERS) ||
|
||||||
|
(this.units_ == ol.control.ScaleLineUnits.DEGREES &&
|
||||||
|
projectionUnits == ol.ProjectionUnits.DEGREES));
|
||||||
|
|
||||||
var nominalCount = this.minWidth_ * pointResolution;
|
var nominalCount = this.minWidth_ * pointResolution;
|
||||||
var suffix = '';
|
var suffix = '';
|
||||||
if (this.units_ == ol.control.ScaleLineUnits.DEGREES) {
|
if (this.units_ == ol.control.ScaleLineUnits.DEGREES) {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ ol.HAVE_PROJ4JS = ol.ENABLE_PROJ4JS && typeof Proj4js == 'object';
|
|||||||
*/
|
*/
|
||||||
ol.ProjectionUnits = {
|
ol.ProjectionUnits = {
|
||||||
DEGREES: 'degrees',
|
DEGREES: 'degrees',
|
||||||
|
FEET: 'ft',
|
||||||
METERS: 'm'
|
METERS: 'm'
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -190,7 +191,13 @@ ol.Proj4jsProjection_.prototype.getPointResolution =
|
|||||||
var height = ol.sphere.NORMAL.haversineDistance(
|
var height = ol.sphere.NORMAL.haversineDistance(
|
||||||
new ol.Coordinate(vertices[4], vertices[5]),
|
new ol.Coordinate(vertices[4], vertices[5]),
|
||||||
new ol.Coordinate(vertices[6], vertices[7]));
|
new ol.Coordinate(vertices[6], vertices[7]));
|
||||||
return (width + height) / 2;
|
var pointResolution = (width + height) / 2;
|
||||||
|
if (this.getUnits() == ol.ProjectionUnits.FEET) {
|
||||||
|
// The radius of the normal sphere is defined in meters, so we must
|
||||||
|
// convert back to feet.
|
||||||
|
pointResolution /= 0.3048;
|
||||||
|
}
|
||||||
|
return pointResolution;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user