Skip to content

Commit

Permalink
Use defined values for the capabilities of features so that they are …
Browse files Browse the repository at this point in the history
…more clearly documented.
  • Loading branch information
manthey committed Jun 17, 2016
1 parent 84777ad commit 5f41066
Show file tree
Hide file tree
Showing 13 changed files with 67 additions and 20 deletions.
2 changes: 1 addition & 1 deletion examples/hurricanes/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down
2 changes: 1 addition & 1 deletion examples/reprojection/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 6 additions & 1 deletion src/canvas/quadFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
7 changes: 6 additions & 1 deletion src/d3/lineFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
7 changes: 6 additions & 1 deletion src/d3/quadFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
7 changes: 6 additions & 1 deletion src/gl/lineFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
7 changes: 6 additions & 1 deletion src/gl/quadFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
7 changes: 7 additions & 0 deletions src/lineFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
6 changes: 4 additions & 2 deletions src/mapInteractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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}
Expand Down
6 changes: 4 additions & 2 deletions src/osmLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = (function () {
var inherit = require('./inherit');
var tileLayer = require('./tileLayer');
var registry = require('./registry');
var quadFeature = require('./quadFeature');

//////////////////////////////////////////////////////////////////////////////
/**
Expand Down Expand Up @@ -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;
})();
9 changes: 9 additions & 0 deletions src/quadFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
16 changes: 9 additions & 7 deletions src/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions tests/cases/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down

0 comments on commit 5f41066

Please sign in to comment.