Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a baseQuad option to tileLayers. #1105

Merged
merged 1 commit into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/canvas/tileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var canvas_tileLayer = function () {
var m_this = this,
s_init = this._init,
s_exit = this._exit,
s_update = this._update,
m_quadFeature,
m_nextTileId = 0,
m_tiles = [];
Expand Down Expand Up @@ -60,6 +61,18 @@ var canvas_tileLayer = function () {
}
};

/**
* Update layer.
*
* @param {object} request A value to pass to the parent class.
* @returns {this}
*/
this._update = function (request) {
s_update.call(m_this, request);
m_this._addBaseQuadToTiles(m_quadFeature, m_tiles);
return m_this;
};

/**
* Clean up the layer.
*/
Expand Down
14 changes: 14 additions & 0 deletions src/svg/tileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ var registerLayerAdjustment = require('../registry').registerLayerAdjustment;

var svg_tileLayer = function () {
'use strict';

var m_this = this,
s_init = this._init,
s_exit = this._exit,
s_update = this._update,
m_quadFeature,
m_nextTileId = 0,
m_tiles = [];
Expand Down Expand Up @@ -60,6 +62,18 @@ var svg_tileLayer = function () {
}
};

/**
* Update layer.
*
* @param {object} request A value to pass to the parent class.
* @returns {this}
*/
this._update = function (request) {
s_update.call(m_this, request);
m_this._addBaseQuadToTiles(m_quadFeature, m_tiles);
return m_this;
};

/**
* Clean up the layer.
*/
Expand Down
40 changes: 40 additions & 0 deletions src/tileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ var featureLayer = require('./featureLayer');
* loaded. 'all' is when tiles in view and tiles that were once requested
* have been loaded (this corresponds to having all network activity
* finished).
* @property {object} [baseQuad] A quad feature element to draw before below
* any tile layers. If specified, this uses the quad defaults, so this is a
* ``geo.quadFeature.position`` object with, typically, an ``image`` property
* added to it. The quad positions are in the map gcs coordinates.
*/

/**
Expand Down Expand Up @@ -219,6 +223,7 @@ var tileLayer = function (arg) {
m_maxBounds = [],
m_reference,
m_exited,
m_lastBaseQuad,
m_this = this;

// copy the options into a private variable
Expand Down Expand Up @@ -1658,6 +1663,41 @@ var tileLayer = function (arg) {
return m_this;
};

/**
* Get/set the baseQuad.
*
* @property {object} [baseQuad] A quad feature element to draw before below
* any tile layers. If specified, this uses the quad defaults, so this is
* a ``geo.quadFeature.position`` object with, typically, an ``image``
* property added to it. The quad positions are in the map gcs
* coordinates.
* @name geo.tileLayer.baseQuad
*/
Object.defineProperty(this, 'baseQuad', {
get: function () { return m_this._options.baseQuad; },
set: function (baseQuad) {
m_this._options.baseQuad = baseQuad;
m_this._update();
}
});

this._addBaseQuadToTiles = function (quadFeature, tiles) {
if (quadFeature) {
if (this.baseQuad !== m_lastBaseQuad) {
if (m_lastBaseQuad) {
tiles.splice(0, 1);
}
m_lastBaseQuad = this.baseQuad;
if (m_lastBaseQuad) {
tiles.splice(0, 0, this.baseQuad);
quadFeature.cacheUpdate(0);
}
quadFeature.data(tiles);
}
quadFeature._update();
}
};

/**
* Initialize after the layer is added to the map.
*
Expand Down
4 changes: 1 addition & 3 deletions src/webgl/tileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ var webgl_tileLayer = function () {
*/
this._update = function (request) {
s_update.call(m_this, request);
if (m_quadFeature) {
m_quadFeature._update();
}
m_this._addBaseQuadToTiles(m_quadFeature, m_tiles);
return m_this;
};

Expand Down
8 changes: 8 additions & 0 deletions tests/cases/osmLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,14 @@ describe('geo.core.osmLayer', function () {
// function is called with eight parameters in some instances
return Object.keys(layer.activeTiles).length === 21;
});
it('baseQuad', function () {
expect(layer.baseQuad).toBe(undefined);
var quad = {ul: {x: 0, y: 0}, lr: {x: 10, y: 10}, image: '/testdata/white.jpg'};
layer.baseQuad = quad;
expect(layer.baseQuad).toBe(quad);
layer.baseQuad = undefined;
expect(layer.baseQuad).toBe(undefined);
});
it('destroy', destroy_map);
});

Expand Down
8 changes: 8 additions & 0 deletions tests/cases/tileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,14 @@ describe('geo.tileLayer', function () {
layer.reference = 'A';
expect(layer.reference).toBe(layer.id() + '_A');
});
it('baseQuad', function () {
var m = map(), layer;
opts.map = m;
layer = geo.tileLayer(opts);
expect(layer.baseQuad).toBe(undefined);
// we don't test setting it here, as we have too much mocked to carry
// through. The setting test is done in the osmLayer tests.
});
});
describe('Public utility methods', function () {
describe('isValid', function () {
Expand Down