From 5f41066f95d17b5f06c187972eea07dc0a9f3c10 Mon Sep 17 00:00:00 2001 From: David Manthey Date: Fri, 17 Jun 2016 11:49:31 -0400 Subject: [PATCH] Use defined values for the capabilities of features so that they are more clearly documented. --- examples/hurricanes/main.js | 2 +- examples/reprojection/main.js | 2 +- src/canvas/quadFeature.js | 7 ++++++- src/d3/lineFeature.js | 7 ++++++- src/d3/quadFeature.js | 7 ++++++- src/gl/lineFeature.js | 7 ++++++- src/gl/quadFeature.js | 7 ++++++- src/lineFeature.js | 7 +++++++ src/mapInteractor.js | 6 ++++-- src/osmLayer.js | 6 ++++-- src/quadFeature.js | 9 +++++++++ src/registry.js | 16 +++++++++------- tests/cases/registry.js | 4 ++-- 13 files changed, 67 insertions(+), 20 deletions(-) diff --git a/examples/hurricanes/main.js b/examples/hurricanes/main.js index 252e1c589d..1cbb7acf09 100644 --- a/examples/hurricanes/main.js +++ b/examples/hurricanes/main.js @@ -370,7 +370,7 @@ $(function () { ); // Create a feature layer to draw on. - layer = map.createLayer('feature', {features: ['line.multicolor']}); + layer = map.createLayer('feature', {features: [geo.lineFeature.capabilities.multicolor]}); // Create a line feature feature = layer.createFeature('line', {selectionAPI: true}); diff --git a/examples/reprojection/main.js b/examples/reprojection/main.js index e18dc4ea6a..da5c18ec91 100644 --- a/examples/reprojection/main.js +++ b/examples/reprojection/main.js @@ -126,7 +126,7 @@ $(function () { } // Set the tile layer defaults to use the specified renderer and opacity var layerParams = { - features: ['quad.img-full'], + features: [geo.quadFeature.capabilities.imageFull], zIndex: 0, gcs: 'EPSG:3857', attribution: $('#url-list [value="' + $('#layer-url').val() + '"]').attr( diff --git a/src/canvas/quadFeature.js b/src/canvas/quadFeature.js index 3b312b55e4..2fd6cae8eb 100644 --- a/src/canvas/quadFeature.js +++ b/src/canvas/quadFeature.js @@ -143,5 +143,10 @@ var canvas_quadFeature = function (arg) { inherit(canvas_quadFeature, quadFeature); // Now register it -registerFeature('canvas', 'quad', canvas_quadFeature, {clr: false, img: true, 'img-full': false}); +var capabilities = {}; +capabilities[quadFeature.capabilities.color] = false; +capabilities[quadFeature.capabilities.image] = true; +capabilities[quadFeature.capabilities.imageFull] = false; + +registerFeature('canvas', 'quad', canvas_quadFeature, capabilities); module.exports = canvas_quadFeature; diff --git a/src/d3/lineFeature.js b/src/d3/lineFeature.js index bd1aa4e030..8eb5dd9dc1 100644 --- a/src/d3/lineFeature.js +++ b/src/d3/lineFeature.js @@ -130,6 +130,11 @@ var d3_lineFeature = function (arg) { inherit(d3_lineFeature, lineFeature); -registerFeature('d3', 'line', d3_lineFeature, {basic: true, multicolor: false}); +// Now register it +var capabilities = {}; +capabilities[lineFeature.capabilities.basic] = true; +capabilities[lineFeature.capabilities.multicolor] = false; + +registerFeature('d3', 'line', d3_lineFeature, capabilities); module.exports = d3_lineFeature; diff --git a/src/d3/quadFeature.js b/src/d3/quadFeature.js index 1c6713bcd0..a82181bec3 100644 --- a/src/d3/quadFeature.js +++ b/src/d3/quadFeature.js @@ -228,5 +228,10 @@ var d3_quadFeature = function (arg) { inherit(d3_quadFeature, quadFeature); // Now register it -registerFeature('d3', 'quad', d3_quadFeature, {clr: true, img: true, 'img-full': false}); +var capabilities = {}; +capabilities[quadFeature.capabilities.color] = true; +capabilities[quadFeature.capabilities.image] = true; +capabilities[quadFeature.capabilities.imageFull] = false; + +registerFeature('d3', 'quad', d3_quadFeature, capabilities); module.exports = d3_quadFeature; diff --git a/src/gl/lineFeature.js b/src/gl/lineFeature.js index 6746e7784a..b9d1872f7f 100644 --- a/src/gl/lineFeature.js +++ b/src/gl/lineFeature.js @@ -398,6 +398,11 @@ var gl_lineFeature = function (arg) { inherit(gl_lineFeature, lineFeature); // Now register it -registerFeature('vgl', 'line', gl_lineFeature, {basic: true, multicolor: true}); +var capabilities = {}; +capabilities[lineFeature.capabilities.basic] = true; +capabilities[lineFeature.capabilities.multicolor] = true; + +// Now register it +registerFeature('vgl', 'line', gl_lineFeature, capabilities); module.exports = gl_lineFeature; diff --git a/src/gl/quadFeature.js b/src/gl/quadFeature.js index 6fdf5ab54f..1d61bf655f 100644 --- a/src/gl/quadFeature.js +++ b/src/gl/quadFeature.js @@ -392,5 +392,10 @@ var gl_quadFeature = function (arg) { inherit(gl_quadFeature, quadFeature); // Now register it -registerFeature('vgl', 'quad', gl_quadFeature, {clr: true, img: true, 'img-full': true}); +var capabilities = {}; +capabilities[quadFeature.capabilities.color] = true; +capabilities[quadFeature.capabilities.image] = true; +capabilities[quadFeature.capabilities.imageFull] = true; + +registerFeature('vgl', 'quad', gl_quadFeature, capabilities); module.exports = gl_quadFeature; diff --git a/src/lineFeature.js b/src/lineFeature.js index ece37e003e..1ca4df8ceb 100644 --- a/src/lineFeature.js +++ b/src/lineFeature.js @@ -244,5 +244,12 @@ lineFeature.create = function (layer, spec) { return feature.create(layer, spec); }; +lineFeature.capabilities = { + /* support for solid-colored, constant-width lines */ + basic: 'line.basic', + /* support for lines that very in width and color */ + multicolor: 'line.multicolor' +}; + inherit(lineFeature, feature); module.exports = lineFeature; diff --git a/src/mapInteractor.js b/src/mapInteractor.js index b53eb2fc4c..ff602466de 100644 --- a/src/mapInteractor.js +++ b/src/mapInteractor.js @@ -24,6 +24,7 @@ var mapInteractor = function (args) { var geo_event = require('./event'); var throttle = require('./util').throttle; var debounce = require('./util').debounce; + var quadFeature = require('./quadFeature'); var m_options = args || {}, m_this = this, @@ -686,8 +687,9 @@ var mapInteractor = function (args) { m_selectionLayer = null; } m_selectionLayer = m_this.map().createLayer( - 'feature', {features: ['quad.clr']}); - m_selectionQuad = m_selectionLayer.createFeature('quad'); + 'feature', {features: [quadFeature.capabilities.color]}); + m_selectionQuad = m_selectionLayer.createFeature( + 'quad', {gcs: m_this.map().gcs()}); m_selectionQuad.style({ opacity: 0.25, color: {r: 0.3, g: 0.3, b: 0.3} diff --git a/src/osmLayer.js b/src/osmLayer.js index b94d35084f..d146986cfa 100644 --- a/src/osmLayer.js +++ b/src/osmLayer.js @@ -5,6 +5,7 @@ module.exports = (function () { var inherit = require('./inherit'); var tileLayer = require('./tileLayer'); var registry = require('./registry'); + var quadFeature = require('./quadFeature'); ////////////////////////////////////////////////////////////////////////////// /** @@ -81,7 +82,8 @@ module.exports = (function () { inherit(osmLayer, tileLayer); /* By default, ask to support image quads. If the user needs full - * reprojection, they will need to require the quad.img-full feature */ - registry.registerLayer('osm', osmLayer, ['quad.img']); + * reprojection, they will need to require the + * quadFeature.capabilities.imageFull feature */ + registry.registerLayer('osm', osmLayer, [quadFeature.capabilities.image]); return osmLayer; })(); diff --git a/src/quadFeature.js b/src/quadFeature.js index fddb10d4d2..05519c8258 100644 --- a/src/quadFeature.js +++ b/src/quadFeature.js @@ -465,5 +465,14 @@ quadFeature.create = function (layer, spec) { return feature.create(layer, spec); }; +quadFeature.capabilities = { + /* support for solid-colored quads */ + color: 'quad.color', + /* support for parallelogram images */ + image: 'quad.image', + /* support for arbitrary quad images */ + imageFull: 'quad.imageFull' +}; + inherit(quadFeature, feature); module.exports = quadFeature; diff --git a/src/registry.js b/src/registry.js index 4e15158f09..0310552f10 100644 --- a/src/registry.js +++ b/src/registry.js @@ -101,11 +101,12 @@ util.checkRenderer = function (name, noFallback) { * @param {array|undefined} featureList A list of features that will be used * with this renderer. Features are the basic feature names (e.g., * 'quad'), or the feature name followed by a required capability (e.g., - * 'quad.img'). If more than one feature or more than one capability of a - * feature is required, include each feature and capability combination in - * the list (e.g., ['quad.img', 'plane']). If no capability is specified - * for a feature (or that feature was registered without a capability - * object), then the feature will match regardless of capabilities. + * 'quad.image'). If more than one feature or more than one capability of + * a feature is required, include each feature and capability combination + * in the list (e.g., ['quad.image', 'plane']). If no capability is + * specified for a feature (or that feature was registered without a + * capability object), then the feature will match regardless of + * capabilities. * @return {string|null|false} the name of the renderer that should be used * or false if no valid renderer can be determined. */ @@ -130,7 +131,7 @@ util.rendererForFeatures = function (featureList) { feature = featureList[fidx]; capability = null; if (feature.indexOf('.') >= 0) { - capability = feature.substr(feature.indexOf('.') + 1); + capability = feature; feature = feature.substr(0, feature.indexOf('.')); } if (features[renderer][feature] === undefined) { @@ -165,7 +166,8 @@ util.rendererForFeatures = function (featureList) { * should expose a simple dictionary of supported and unsupported * features. For instance, the quad feature has color quads, image quads, * and image quads that support full transformations. The capabailities - * might be {clr: true, img: true: 'img-full': false}. + * should be defined in the base feature in a capabilities object so that + * they can be referenced by that rather than an explicit string. */ ////////////////////////////////////////////////////////////////////////////// util.registerFeature = function (category, name, func, capabilities) { diff --git a/tests/cases/registry.js b/tests/cases/registry.js index 7a149e91d7..0f14ab54da 100644 --- a/tests/cases/registry.js +++ b/tests/cases/registry.js @@ -15,8 +15,8 @@ describe('geo.registry', function () { expect(geo.rendererForFeatures(['contour'])).toBe('vgl'); expect(geo.rendererForFeatures(['contour', 'graph'])).toBe(false); expect(geo.rendererForFeatures(['quad', 'graph'])).toBe('d3'); - expect(geo.rendererForFeatures(['quad.img-full', 'graph'])).toBe(false); - expect(geo.rendererForFeatures(['quad.img', 'graph'])).toBe('d3'); + expect(geo.rendererForFeatures([geo.quadFeature.capabilities.imageFull, 'graph'])).toBe(false); + expect(geo.rendererForFeatures([geo.quadFeature.capabilities.image, 'graph'])).toBe('d3'); restoreVGLRenderer(); }); it('unsupported vgl renderer', function () {