Skip to content

Commit

Permalink
Merge pull request #590 from OpenGeoscience/select-renderer-by-feature
Browse files Browse the repository at this point in the history
Create layers based on a list of features.
  • Loading branch information
jbeezley authored Jun 24, 2016
2 parents c0429f3 + 5f41066 commit 5f16176
Show file tree
Hide file tree
Showing 26 changed files with 212 additions and 52 deletions.
10 changes: 6 additions & 4 deletions examples/choropleth/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ $(function () {
'osm'
);

// Create a gl feature layer
var vglLayer = map.createLayer(
// Create a feature layer. We could either ask for a layer via a specific
// render {renderer: 'vgl'} or for a layer that supports our feature
// {features: ['choropleth']}.
var choroplethLayer = map.createLayer(
'feature',
{
renderer: 'vgl'
features: ['choropleth']
}
);

Expand All @@ -57,7 +59,7 @@ $(function () {
});

var choropleth =
makeChoropleth(geoData.features, mockScalarData, vglLayer);
makeChoropleth(geoData.features, mockScalarData, choroplethLayer);

setTimeout(function () {
var mockScalarData2 = geoData
Expand Down
12 changes: 6 additions & 6 deletions examples/contour/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,27 +66,27 @@ $(function () {
'osm'
);

// Create a gl feature layer
var vglLayer = map.createLayer(
// Create a feature layer that supports contours
var contourLayer = map.createLayer(
'feature',
{
renderer: 'vgl'
features: ['contour']
}
);

// Load the data
$.ajax({
url: '../../data/oahu.json',
success: function (data) {
var contour = makeContour(data, vglLayer);
var contour = makeContour(data, contourLayer);
contour.draw();
/* After 10 second, load a denser data set */
window.setTimeout(function () {
$.ajax({
url: '../../data/oahu-dense.json',
success: function (data) {
vglLayer.deleteFeature(contour);
contour = makeContour(data, vglLayer, contour);
contourLayer.deleteFeature(contour);
contour = makeContour(data, contourLayer, contour);
contour.draw();
}
});
Expand Down
3 changes: 1 addition & 2 deletions examples/deepzoom/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ $(function () {

// Add the osm layer with a custom tile url
map.createLayer(
'tiledFish',
{renderer: 'vgl'}
'tiledFish'
);
});
4 changes: 3 additions & 1 deletion examples/dynamicData/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ $(function () {
baseUrl: 'http://otile1.mqcdn.com/tiles/1.0.0/sat'
});

// Add a feature layer with a D3 renderer
// Add a feature layer with a D3 renderer. We could, instead, ask for any
// renderer that supports point features, like so:
// var features = map.createLayer('feature', {features: ['point']});
var features = map.createLayer('feature', {renderer: 'd3'});

var numberOfFeatures = 200;
Expand Down
5 changes: 3 additions & 2 deletions examples/geoJSON/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ $(function () {
}
);

// Create a gl layer to put the features in
var layer = map.createLayer('feature');
// Create a layer to put the features in. We could need point, line, and
// polygon features, so ask for a layer that supports all of them.
var layer = map.createLayer('feature', {features: ['point', 'line', 'polygon']});
map.draw();

// Initialize the json reader.
Expand Down
2 changes: 1 addition & 1 deletion examples/heatmap/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ $(function () {
var layer, heatmap, points, datapoints;

var layerOptions = {
renderer: 'canvas',
features: ['heatmap'],
opacity: 0.75
};
var heatmapOptions = {
Expand Down
4 changes: 2 additions & 2 deletions examples/hurricanes/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,8 +369,8 @@ $(function () {
}
);

// Create a feature layer to draw on
layer = map.createLayer('feature');
// Create a feature layer to draw on.
layer = map.createLayer('feature', {features: [geo.lineFeature.capabilities.multicolor]});

// Create a line feature
feature = layer.createFeature('line', {selectionAPI: true});
Expand Down
3 changes: 2 additions & 1 deletion examples/quads/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ $(function () {
zoom: 4
});
var layer = map.createLayer('feature', {
renderer: query.renderer ? (query.renderer === 'html' ? null : query.renderer) : 'vgl'
renderer: query.renderer ? (query.renderer === 'html' ? null : query.renderer) : undefined,
features: query.renderer ? undefined : ['quad']
});
var quads = layer.createFeature('quad', {selectionAPI: true});
var previewImage = new Image();
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 = {
renderer: 'vgl',
features: [geo.quadFeature.capabilities.imageFull],
zIndex: 0,
gcs: 'EPSG:3857',
attribution: $('#url-list [value="' + $('#layer-url').val() + '"]').attr(
Expand Down
3 changes: 2 additions & 1 deletion examples/tiles/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ block append mainContent
div#controls
.form-group(title="Tiles can be drawn using WebGL, Canvas, HTML, or SVG. WebGL is generally the fastest and HTML the most compatible.")
label(for="map-renderer") Renderer
select#map-renderer.mapparam(param-name="renderer", placeholder="vgl")
select#map-renderer.mapparam(param-name="renderer", placeholder="default")
option(value="default") Default
option(value="vgl") VGL (WebGL)
option(value="canvas") Canvas
option(value="d3") SVG (d3)
Expand Down
6 changes: 5 additions & 1 deletion examples/tiles/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
* projection: 'parallel' or 'projection' for the camera projection.
* renderer: 'vgl' (default), 'canvas', 'd3', 'null', or 'html'. This picks
* the renderer for map tiles. null or html uses the html renderer.
* 'default' uses the default renderer for the user's platform.
* round: 'round' (default), 'floor', 'ceil'.
* subdomains: a comma-separated string of subdomains to use in the {s} part
* of the url parameter. If there are no commas in the string, each letter
Expand Down Expand Up @@ -104,7 +105,7 @@ $(function () {
};
// Set the tile layer defaults to use the specified renderer and opacity
var layerParams = {
renderer: query.renderer || 'vgl',
renderer: query.renderer && query.renderer !== 'default' ? query.renderer : undefined,
opacity: query.opacity || '1',
/* Always use a larger cache so if keepLower is changed, we still have a
* big enough cache. */
Expand Down Expand Up @@ -340,6 +341,9 @@ $(function () {
if (layerParams.renderer === 'html') {
layerParams.renderer = null;
}
if (layerParams.renderer === 'default') {
layerParams.renderer = undefined;
}
map.deleteLayer(osmLayer);
osmLayer = map.createLayer('osm', layerParams);
tileDebug.osmLayer = osmLayer;
Expand Down
2 changes: 1 addition & 1 deletion examples/transitions/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ $(function () {
// Add an OSM layer
map.createLayer('osm', {
baseUrl: 'http://otile1.mqcdn.com/tiles/1.0.0/map',
renderer: query.renderer ? (query.renderer === 'html' ? null : query.renderer) : 'vgl'
renderer: query.renderer ? (query.renderer === 'html' ? null : query.renderer) : undefined
});

// Bind button clicks to map transitions
Expand Down
2 changes: 1 addition & 1 deletion examples/vectors/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ $(function () {

// Create a gl feature layer
var layer = map.createLayer(
'feature', { renderer: 'd3' }
'feature', {features: ['vector']}
);

var routes = [
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);
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);
// 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);
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);
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);
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: 4 additions & 3 deletions src/layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ var inherit = require('./inherit');
var sceneObject = require('./sceneObject');
var feature = require('./feature');
var checkRenderer = require('./registry').checkRenderer;
var rendererForFeatures = require('./registry').rendererForFeatures;

//////////////////////////////////////////////////////////////////////////////
/**
Expand Down Expand Up @@ -30,11 +31,11 @@ var layer = function (arg) {
var geo_event = require('./event');
var camera = require('./camera');

//////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
/**
* @private
*/
//////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////
var m_this = this,
s_exit = this._exit,
m_id = arg.id === undefined ? layer.newLayerId() : arg.id,
Expand All @@ -44,7 +45,7 @@ var layer = function (arg) {
m_canvas = null,
m_renderer = null,
m_initialized = false,
m_rendererName = arg.renderer === undefined ? 'vgl' : arg.renderer,
m_rendererName = arg.renderer === undefined ? rendererForFeatures(arg.features) : arg.renderer,
m_dataTime = timestamp(),
m_updateTime = timestamp(),
m_sticky = arg.sticky === undefined ? true : arg.sticky,
Expand Down
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: 3 additions & 3 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 @@ -685,9 +686,8 @@ var mapInteractor = function (args) {
m_this.map().deleteLayer(m_selectionLayer);
m_selectionLayer = null;
}
// Create a feature layer and plane feature to show the selection bounds
m_selectionLayer = m_this.map().createLayer('feature', {renderer: 'd3'});

m_selectionLayer = m_this.map().createLayer(
'feature', {features: [quadFeature.capabilities.color]});
m_selectionQuad = m_selectionLayer.createFeature(
'quad', {gcs: m_this.map().gcs()});
m_selectionQuad.style({
Expand Down
6 changes: 5 additions & 1 deletion 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 @@ -80,6 +81,9 @@ module.exports = (function () {
});

inherit(osmLayer, tileLayer);
registry.registerLayer('osm', osmLayer);
/* By default, ask to support image quads. If the user needs full
* 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;
Loading

0 comments on commit 5f16176

Please sign in to comment.