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;
|
||||
|
||||
|
||||
/**
|
||||
* @type {number}
|
||||
*/
|
||||
Proj4js.Proj.prototype.to_meter;
|
||||
|
||||
|
||||
/**
|
||||
* @nosideeffects
|
||||
* @param {Proj4js.Proj} source
|
||||
|
||||
@@ -143,7 +143,15 @@ ol.Projection.prototype.getUnits = function() {
|
||||
* @return {number} Meters.
|
||||
*/
|
||||
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
|
||||
* @type {ol.TileRange}
|
||||
*/
|
||||
this.tileRange_ = null;
|
||||
this.tileRange_ = new ol.TileRange(NaN, NaN, NaN, NaN);
|
||||
|
||||
/**
|
||||
* @private
|
||||
@@ -332,9 +332,12 @@ ol.renderer.canvas.VectorLayer.prototype.renderFrame =
|
||||
// lazy tile grid creation
|
||||
if (idle) {
|
||||
// avoid rendering issues for very high zoom levels
|
||||
var gridResolution = Math.max(resolution,
|
||||
ol.renderer.canvas.MIN_RESOLUTION /
|
||||
ol.METERS_PER_UNIT[projection.getUnits()]);
|
||||
var minResolution = ol.renderer.canvas.MIN_RESOLUTION;
|
||||
var metersPerUnit = projection.getMetersPerUnit();
|
||||
if (metersPerUnit) {
|
||||
minResolution = minResolution / metersPerUnit;
|
||||
}
|
||||
var gridResolution = Math.max(resolution, minResolution);
|
||||
if (gridResolution !== this.renderedResolution_) {
|
||||
tileGrid = new ol.tilegrid.TileGrid({
|
||||
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
|
||||
var tileResolution = tileGrid.getResolution(0);
|
||||
if (idle) {
|
||||
this.tileRange_ = tileGrid.getTileRangeForExtentAndResolution(
|
||||
extent, tileResolution);
|
||||
tileGrid.getTileRangeForExtentAndResolution(
|
||||
extent, tileResolution, this.tileRange_);
|
||||
}
|
||||
var transform = this.transform_,
|
||||
tileRange = this.tileRange_,
|
||||
|
||||
@@ -313,11 +313,31 @@ describe('ol.proj', 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() {
|
||||
var epsg4326 = ol.proj.get('EPSG:4326');
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user