Merge pull request #814 from tschaub/814-min-resolution
Fix vector rendering for projections that do not specify units
This commit is contained in:
@@ -76,6 +76,12 @@ Proj4js.Proj.prototype.units;
|
|||||||
Proj4js.Proj.prototype.srsCode;
|
Proj4js.Proj.prototype.srsCode;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @type {number}
|
||||||
|
*/
|
||||||
|
Proj4js.Proj.prototype.to_meter;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @nosideeffects
|
* @nosideeffects
|
||||||
* @param {Proj4js.Proj} source
|
* @param {Proj4js.Proj} source
|
||||||
|
|||||||
+9
-1
@@ -143,7 +143,15 @@ ol.Projection.prototype.getUnits = function() {
|
|||||||
* @return {number} Meters.
|
* @return {number} Meters.
|
||||||
*/
|
*/
|
||||||
ol.Projection.prototype.getMetersPerUnit = function() {
|
ol.Projection.prototype.getMetersPerUnit = function() {
|
||||||
return ol.METERS_PER_UNIT[this.units_];
|
var metersPerUnit;
|
||||||
|
if (!goog.isNull(this.units_)) {
|
||||||
|
metersPerUnit = ol.METERS_PER_UNIT[this.units_];
|
||||||
|
} else {
|
||||||
|
if (this instanceof ol.Proj4jsProjection_) {
|
||||||
|
metersPerUnit = this.getProj4jsProj().to_meter;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return metersPerUnit;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -159,7 +159,7 @@ ol.renderer.canvas.VectorLayer = function(mapRenderer, layer) {
|
|||||||
* @private
|
* @private
|
||||||
* @type {ol.TileRange}
|
* @type {ol.TileRange}
|
||||||
*/
|
*/
|
||||||
this.tileRange_ = null;
|
this.tileRange_ = new ol.TileRange(NaN, NaN, NaN, NaN);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @private
|
* @private
|
||||||
@@ -332,9 +332,12 @@ ol.renderer.canvas.VectorLayer.prototype.renderFrame =
|
|||||||
// lazy tile grid creation
|
// lazy tile grid creation
|
||||||
if (idle) {
|
if (idle) {
|
||||||
// avoid rendering issues for very high zoom levels
|
// avoid rendering issues for very high zoom levels
|
||||||
var gridResolution = Math.max(resolution,
|
var minResolution = ol.renderer.canvas.MIN_RESOLUTION;
|
||||||
ol.renderer.canvas.MIN_RESOLUTION /
|
var metersPerUnit = projection.getMetersPerUnit();
|
||||||
ol.METERS_PER_UNIT[projection.getUnits()]);
|
if (metersPerUnit) {
|
||||||
|
minResolution = minResolution / metersPerUnit;
|
||||||
|
}
|
||||||
|
var gridResolution = Math.max(resolution, minResolution);
|
||||||
if (gridResolution !== this.renderedResolution_) {
|
if (gridResolution !== this.renderedResolution_) {
|
||||||
tileGrid = new ol.tilegrid.TileGrid({
|
tileGrid = new ol.tilegrid.TileGrid({
|
||||||
origin: [0, 0],
|
origin: [0, 0],
|
||||||
@@ -357,8 +360,8 @@ ol.renderer.canvas.VectorLayer.prototype.renderFrame =
|
|||||||
// set up transform for the layer canvas to be drawn to the map canvas
|
// set up transform for the layer canvas to be drawn to the map canvas
|
||||||
var tileResolution = tileGrid.getResolution(0);
|
var tileResolution = tileGrid.getResolution(0);
|
||||||
if (idle) {
|
if (idle) {
|
||||||
this.tileRange_ = tileGrid.getTileRangeForExtentAndResolution(
|
tileGrid.getTileRangeForExtentAndResolution(
|
||||||
extent, tileResolution);
|
extent, tileResolution, this.tileRange_);
|
||||||
}
|
}
|
||||||
var transform = this.transform_,
|
var transform = this.transform_,
|
||||||
tileRange = this.tileRange_,
|
tileRange = this.tileRange_,
|
||||||
|
|||||||
@@ -313,11 +313,31 @@ describe('ol.proj', function() {
|
|||||||
|
|
||||||
describe('ol.Projection.prototype.getMetersPerUnit()', function() {
|
describe('ol.Projection.prototype.getMetersPerUnit()', function() {
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
Proj4js.defs['EPSG:26782'] =
|
||||||
|
'+proj=lcc +lat_1=29.3 +lat_2=30.7 +lat_0=28.66666666666667 ' +
|
||||||
|
'+lon_0=-91.33333333333333 +x_0=609601.2192024384 +y_0=0 ' +
|
||||||
|
'+ellps=clrk66 +datum=NAD27 +to_meter=0.3048006096012192 +no_defs';
|
||||||
|
ol.proj.configureProj4jsProjection({
|
||||||
|
code: 'EPSG:26782'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function() {
|
||||||
|
ol.proj.proj4jsProjections_ = {};
|
||||||
|
delete Proj4js.defs['EPSG:26782'];
|
||||||
|
});
|
||||||
|
|
||||||
it('returns value in meters', function() {
|
it('returns value in meters', function() {
|
||||||
var epsg4326 = ol.proj.get('EPSG:4326');
|
var epsg4326 = ol.proj.get('EPSG:4326');
|
||||||
expect(epsg4326.getMetersPerUnit()).to.eql(111194.87428468118);
|
expect(epsg4326.getMetersPerUnit()).to.eql(111194.87428468118);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('works for proj4js projections without units', function() {
|
||||||
|
var epsg26782 = ol.proj.get('EPSG:26782');
|
||||||
|
expect(epsg26782.getMetersPerUnit()).to.eql(0.3048006096012192);
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('ol.proj.configureProj4jsProjection()', function() {
|
describe('ol.proj.configureProj4jsProjection()', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user