From 0c38d55066b40fe1efc9655ee904f653718a3634 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Fri, 6 Aug 2021 12:32:44 -0400 Subject: [PATCH] feat: Add a baseQuad option to tileLayers. --- src/canvas/tileLayer.js | 13 +++++++++++++ src/svg/tileLayer.js | 14 ++++++++++++++ src/tileLayer.js | 40 ++++++++++++++++++++++++++++++++++++++++ src/webgl/tileLayer.js | 4 +--- tests/cases/osmLayer.js | 8 ++++++++ tests/cases/tileLayer.js | 8 ++++++++ 6 files changed, 84 insertions(+), 3 deletions(-) diff --git a/src/canvas/tileLayer.js b/src/canvas/tileLayer.js index 3cc1a6b7aa..92af1b027c 100644 --- a/src/canvas/tileLayer.js +++ b/src/canvas/tileLayer.js @@ -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 = []; @@ -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. */ diff --git a/src/svg/tileLayer.js b/src/svg/tileLayer.js index 2584e97c28..5cd58fcad9 100644 --- a/src/svg/tileLayer.js +++ b/src/svg/tileLayer.js @@ -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 = []; @@ -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. */ diff --git a/src/tileLayer.js b/src/tileLayer.js index ac7b6def0e..7d52bcca94 100644 --- a/src/tileLayer.js +++ b/src/tileLayer.js @@ -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. */ /** @@ -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 @@ -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. * diff --git a/src/webgl/tileLayer.js b/src/webgl/tileLayer.js index 793a60ced8..c5c31f1e34 100644 --- a/src/webgl/tileLayer.js +++ b/src/webgl/tileLayer.js @@ -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; }; diff --git a/tests/cases/osmLayer.js b/tests/cases/osmLayer.js index 3237b0814b..ceaf04e9e2 100644 --- a/tests/cases/osmLayer.js +++ b/tests/cases/osmLayer.js @@ -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); }); diff --git a/tests/cases/tileLayer.js b/tests/cases/tileLayer.js index d364f6143f..1e0f82c47f 100644 --- a/tests/cases/tileLayer.js +++ b/tests/cases/tileLayer.js @@ -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 () {