Skip to content

Commit

Permalink
Merge pull request #15036 from tschaub/geotiff-projection
Browse files Browse the repository at this point in the history
Allow to set GeoTiff projection
  • Loading branch information
tschaub committed Aug 21, 2023
2 parents e47c3b5 + bc88d98 commit b88cf6c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/ol/source/GeoTIFF.js
Expand Up @@ -359,6 +359,8 @@ function getMaxForDataType(array) {
* If instead you want to work with the raw values in a style expression, set this to `false`. Setting this option
* to `false` will make it so any `min` and `max` properties on sources are ignored.
* @property {boolean} [opaque=false] Whether the layer is opaque.
* @property {import("../proj.js").ProjectionLike} [projection] Source projection. If not provided, the GeoTIFF metadata
* will be read for projection information.
* @property {number} [transition=250] Duration of the opacity transition for rendering.
* To disable the opacity transition, pass `transition: 0`.
* @property {boolean} [wrapX=false] Render tiles beyond the tile grid extent.
Expand All @@ -382,7 +384,7 @@ class GeoTIFFSource extends DataTile {
super({
state: 'loading',
tileGrid: null,
projection: null,
projection: options.projection || null,
opaque: options.opaque,
transition: options.transition,
interpolate: options.interpolate !== false,
Expand Down
26 changes: 26 additions & 0 deletions test/browser/spec/ol/source/GeoTIFF.test.js
@@ -1,5 +1,6 @@
import GeoTIFFSource from '../../../../../src/ol/source/GeoTIFF.js';
import TileState from '../../../../../src/ol/TileState.js';
import {get} from '../../../../../src/ol/proj.js';

describe('ol/source/GeoTIFF', function () {
describe('constructor', function () {
Expand Down Expand Up @@ -61,6 +62,31 @@ describe('ol/source/GeoTIFF', function () {
expect(source.getWrapX()).to.be(true);
});

it('defaults to projection: null', function () {
const source = new GeoTIFFSource({
sources: [
{
url: 'spec/ol/source/images/0-0-0.tif',
},
],
});
expect(source.getProjection()).to.be(null);
});

it('allows projection to be set', function () {
const projection = 'EPSG:4326';
const expected = get(projection);
const source = new GeoTIFFSource({
projection,
sources: [
{
url: 'spec/ol/source/images/0-0-0.tif',
},
],
});
expect(source.getProjection()).to.be(expected);
});

it('generates Float32Array data if normalize is set to false', (done) => {
const source = new GeoTIFFSource({
normalize: false,
Expand Down

0 comments on commit b88cf6c

Please sign in to comment.