Skip to content

Commit

Permalink
Test layer.js.
Browse files Browse the repository at this point in the history
Move the layer specification to a typedef for better documentation.
Make sure all layer types use typedefs.

Fix issues with the layer id function.

Ensures that canvas and renderer can actually be specified when creating
a layer.  This allows layers to share a renderer or a canvas.  For the
webgl renderer, sharing a canvas results in flashing, as each layer
completely redraws the canvas.  When sharing a renderer, there is no
proper support for opacity (probably not for visibility) or z-order, but
this is a first step to implementing #942.

Removed some unused code.
  • Loading branch information
manthey committed Nov 2, 2018
1 parent 7c100bb commit 3b3eb7b
Show file tree
Hide file tree
Showing 11 changed files with 461 additions and 180 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
- Removed the dependency on the vgl module for the `object` and `timestamp` classes (#918)
- CSS color names are obtained from an npm package rather than being defined in the util module (#936)

### Bug Fixes
- Fixed some minor issues with layers (#949)

## Version 0.18.1

### Bug Fixes
Expand Down
60 changes: 33 additions & 27 deletions src/annotationLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,34 @@ var $ = require('jquery');
var Mousetrap = require('mousetrap');
var textFeature = require('./textFeature');

/**
* Object specification for an annotation layer.
*
* @typedef {geo.layer.spec} geo.annotationLayer.spec
* @extends {geo.layer.spec}
* @property {number} [dblClickTime=300] The delay in milliseconds that is
* treated as a double-click when working with annotations.
* @property {number} [adjacentPointProximity=5] The minimum distance in
* display coordinates (pixels) between two adjacent points when creating a
* polygon or line. A value of 0 requires an exact match.
* @property {number} [continuousPointProximity=5] The minimum distance in
* display coordinates (pixels) between two adjacent points when dragging
* to create an annotation. `false` disables continuous drawing mode.
* @property {number} [continuousPointColinearity=1.0deg] The minimum angle
* between a series of three points when dragging to not interpret them as
* colinear. Only applies if `continuousPointProximity` is not `false`.
* @property {number} [finalPointProximity=10] The maximum distance in display
* coordinates (pixels) between the starting point and the mouse coordinates
* to signal closing a polygon. A value of 0 requires an exact match. A
* negative value disables closing a polygon by clicking on the start point.
* @property {boolean} [showLabels=true] Truthy to show feature labels that are
* allowed by the associated feature to be shown.
* @property {boolean} [clickToEdit=false] Truthy to allow clicking an
* annotation to place it in edit mode.
* @property {geo.textFeature.styleSpec} [defaultLabelStyle] Default styles for
* labels.
*/

/**
* @typedef {object} geo.annotationLayer.labelRecord
* @property {string} text The text of the label
Expand All @@ -26,41 +54,19 @@ var textFeature = require('./textFeature');
* @class
* @alias geo.annotationLayer
* @extends geo.featureLayer
* @param {object} [args] Layer options.
* @param {number} [args.dblClickTime=300] The delay in milliseconds that is
* treated as a double-click when working with annotations.
* @param {number} [args.adjacentPointProximity=5] The minimum distance in
* display coordinates (pixels) between two adjacent points when creating a
* polygon or line. A value of 0 requires an exact match.
* @param {number} [args.continuousPointProximity=5] The minimum distance in
* display coordinates (pixels) between two adjacent points when dragging
* to create an annotation. `false` disables continuous drawing mode.
* @param {number} [args.continuousPointColinearity=1.0deg] The minimum
* angle between a series of three points when dragging to not interpret
* them as colinear. Only applies if `continuousPointProximity` is not
* `false`.
* @param {number} [args.finalPointProximity=10] The maximum distance in
* display coordinates (pixels) between the starting point and the mouse
* coordinates to signal closing a polygon. A value of 0 requires an exact
* match. A negative value disables closing a polygon by clicking on the
* start point.
* @param {boolean} [args.showLabels=true] Truthy to show feature labels that
* are allowed by the associated feature to be shown.
* @param {boolean} [args.clickToEdit=false] Truthy to allow clicking an
* annotation to place it in edit mode.
* @param {object} [args.defaultLabelStyle] Default styles for labels.
* @param {geo.annotationLayer.spec} [arg] Specification for the new layer.
* @returns {geo.annotationLayer}
* @fires geo.event.annotation.state
* @fires geo.event.annotation.coordinates
* @fires geo.event.annotation.edit_action
* @fires geo.event.annotation.select_edit_handle
*/
var annotationLayer = function (args) {
var annotationLayer = function (arg) {
'use strict';
if (!(this instanceof annotationLayer)) {
return new annotationLayer(args);
return new annotationLayer(arg);
}
featureLayer.call(this, args);
featureLayer.call(this, arg);

var mapInteractor = require('./mapInteractor');
var timestamp = require('./timestamp');
Expand Down Expand Up @@ -130,7 +136,7 @@ var annotationLayer = function (args) {
finalPointProximity: 10, // in pixels, 0 is exact
showLabels: true,
clickToEdit: false
}, args);
}, arg);

/**
* Process an action event. If we are in rectangle-creation mode, this
Expand Down
4 changes: 2 additions & 2 deletions src/canvas/canvasRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ var canvasRenderer = function (arg) {

s_init.call(m_this);

var canvas = $(document.createElement('canvas'));
var canvas = arg.canvas || $(document.createElement('canvas'));
m_this.context2d = canvas[0].getContext('2d');

canvas.addClass('canvas-canvas');
Expand Down Expand Up @@ -113,7 +113,7 @@ var canvasRenderer = function (arg) {
var layer = m_this.layer(),
map = layer.map(),
mapSize = map.size(),
features = layer.features(),
features = layer.features ? layer.features() : [],
i;

for (i = 0; i < features.length; i += 1) {
Expand Down
2 changes: 1 addition & 1 deletion src/d3/d3Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ var d3Renderer = function (arg) {
.attr('mode', 'normal');

if (!arg.widget) {
canvas = m_svg.append('g');
canvas = arg.canvas || m_svg.append('g');
}

shadow = m_defs.append('filter')
Expand Down
2 changes: 1 addition & 1 deletion src/featureLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ var registry = require('./registry');
* @class
* @alias geo.featureLayer
* @extends geo.layer
* @param {object} arg Options for the new layer.
* @param {geo.layer.spec} [arg] Specification for the new layer.
* @returns {geo.featureLayer}
*/
var featureLayer = function (arg) {
Expand Down
2 changes: 1 addition & 1 deletion src/gl/vglRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ var vglRenderer = function (arg) {

s_init.call(m_this);

var canvas = $(document.createElement('canvas'));
var canvas = arg.canvas || $(document.createElement('canvas'));
canvas.addClass('webgl-canvas');
$(m_this.layer().node().get(0)).append(canvas);

Expand Down
Loading

0 comments on commit 3b3eb7b

Please sign in to comment.