Skip to content

Commit

Permalink
Add an isoline feature.
Browse files Browse the repository at this point in the history
This adds a Math.log10 polyfill and removes the unused Math.sinh
polyfill.

Add simple isoline example.

Add an isoline tutorial.  This uses a data set of Oahu's elevation that
is lower resolution than the 'dense' set, primarily so that the tutorial
will run faster (and test faster).

This resolves #592.

The `used` function can be overridden for isoline and contour features.
This defaults to the `value` function returning a non-null, finite
number.

Pass the calculated position to the `value` function.  This allows the
value to be modified based on the position.

The isoline label feature is added to the list of dependent features so
that something like `myfeature.visible(false).draw()` does what is
expected.

Don't wrap across longitude if the data is more than 360 units wide,
since it probably isn't actually longitude in that case.

Reduce memory use for fully populated meshes.  For large meshes this can
reduce memory use and increase speed.  For small meshes, there is
practically no difference.

Label positions are calculated in map gcs, not interface gcs.  Lines are
not guaranteed to be linear in the interface gcs, so using it may put
labels off of the rendered line.

Modify layers for better nested support.

Layer's z-index should only be relative to their siblings, not all
layers.  Layers don't have to be children of the map; they can be
children of other layers.  Instead of enumerating the map layers for
determining siblings, enumerate the children of the layer's parent,
filtering to only those that are geo.layer instances.

This makes it easier to change the z index of a layer that has dependent
layers (such as the isoline feature's canvas layer for text).
  • Loading branch information
manthey committed Jul 9, 2018
1 parent 86dd841 commit a56a346
Show file tree
Hide file tree
Showing 22 changed files with 1,840 additions and 59 deletions.
7 changes: 7 additions & 0 deletions examples/isoline/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"title": "Isolines",
"exampleJs": ["main.js"],
"about": {
"text": "This example shows how to add isolines to a map."
}
}
63 changes: 63 additions & 0 deletions examples/isoline/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Run after the DOM loads
$(function () {
'use strict';

// Create a map object with the OpenStreetMaps base layer.
var map = geo.map({
node: '#map',
center: {
x: -157.965,
y: 21.482
},
zoom: 11
});

// Add a faint osm layer
map.createLayer('osm', {opacity: 0.5});

// Create a feature layer that supports contours
var isolineLayer = map.createLayer('feature', {
features: ['isoline']
});

// Load the data
$.get('../../data/oahu-dense.json').done(function (data) {
// Create an isoline feature
var iso = isolineLayer.createFeature('isoline', {
isoline: {
// Specify our grid data
gridWidth: data.gridWidth,
gridHeight: data.gridHeight,
x0: data.x0,
y0: data.y0,
dx: data.dx,
dy: data.dy,
// Don't plot any values less than zero
min: 0,
// Create a contour line every 50 meters
spacing: 50,
// Make every 4th line heavier and every 4*5 = 20th line heavier yet
levels: [4, 5]
},
style: {
// The data uses -9999 to represent no value; modify it to return null
// instead.
value: function (d) { return d > -9999 ? d : null; },
// level relates to the isoline importance, with 0 being the most
// common and, using the levels specified, a level of 1 being every
// fourth, and 2 every twentieth line. Color the lines differently
// depending on the level
strokeColor: function (v, vi, d) {
return ['grey', 'mediumblue', 'blue'][d.level];
}
}
}).data(data.values).draw();
// Make some values available in the global context so curious people can
// play with them.
window.example = {
map: map,
isolineLayer: isolineLayer,
iso: iso
};
});
});
Binary file added examples/isoline/thumb.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion karma-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ module.exports = function (config) {
}, FirefoxPrefs)
}
},
browserNoActivityTimeout: 30000,
browserNoActivityTimeout: 300000,
reporters: [
'spec', // we had used the 'progress' reporter in the past.
'kjhtml'
Expand Down
1 change: 1 addition & 0 deletions src/canvas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module.exports = {
canvasRenderer: require('./canvasRenderer'),
heatmapFeature: require('./heatmapFeature'),
isolineFeature: require('./isolineFeature'),
lineFeature: require('./lineFeature'),
pixelmapFeature: require('./pixelmapFeature'),
quadFeature: require('./quadFeature'),
Expand Down
34 changes: 34 additions & 0 deletions src/canvas/isolineFeature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
var inherit = require('../inherit');
var registerFeature = require('../registry').registerFeature;
var isolineFeature = require('../isolineFeature');

/**
* Create a new instance of class isolineFeature.
*
* @class
* @alias geo.canvas.isolineFeature
* @extends geo.isolineFeature
* @param {geo.isolineFeature.spec} arg
* @returns {geo.canvas.isolineFeature}
*/
var canvas_isolineFeature = function (arg) {
'use strict';
if (!(this instanceof canvas_isolineFeature)) {
return new canvas_isolineFeature(arg);
}

arg = arg || {};
isolineFeature.call(this, arg);

var object = require('./object');
object.call(this);

this._init(arg);
return this;
};

inherit(canvas_isolineFeature, isolineFeature);

// Now register it
registerFeature('canvas', 'isoline', canvas_isolineFeature);
module.exports = canvas_isolineFeature;
7 changes: 4 additions & 3 deletions src/contourFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,12 @@ var contourFeature = function (arg) {
this._createContours = function () {
var contour = m_this.contour,
valueFunc = m_this.style.get('value'),
usedFunc = m_this.style('used') !== undefined ?
m_this.style.get('used') :
function (d, i) { return util.isNonNullFinite(valueFunc(d, i)); },
minmax, val, range, i, k;
var result = this._createMesh({
used: function (d, i) {
return util.isNonNullFinite(valueFunc(d, i));
},
used: usedFunc,
opacity: m_this.style.get('opacity'),
value: valueFunc
});
Expand Down
1 change: 1 addition & 0 deletions src/gl/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
module.exports = {
choroplethFeature: require('./choroplethFeature'),
contourFeature: require('./contourFeature'),
isolineFeature: require('./isolineFeature'),
lineFeature: require('./lineFeature'),
pointFeature: require('./pointFeature'),
polygonFeature: require('./polygonFeature'),
Expand Down
33 changes: 33 additions & 0 deletions src/gl/isolineFeature.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
var inherit = require('../inherit');
var registerFeature = require('../registry').registerFeature;
var isolineFeature = require('../isolineFeature');

/**
* Create a new instance of isolineFeature.
*
* @class
* @alias geo.gl.isolineFeature
* @extends geo.isolineFeature
* @param {geo.isolineFeature.spec} arg
* @returns {geo.gl.isolineFeature}
*/
var gl_isolineFeature = function (arg) {
'use strict';
if (!(this instanceof gl_isolineFeature)) {
return new gl_isolineFeature(arg);
}
arg = arg || {};
isolineFeature.call(this, arg);

var object = require('./object');
object.call(this);

this._init(arg);
return this;
};

inherit(gl_isolineFeature, isolineFeature);

// Now register it
registerFeature('vgl', 'isoline', gl_isolineFeature);
module.exports = gl_isolineFeature;
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ module.exports = $.extend({
graphFeature: require('./graphFeature'),
heatmapFeature: require('./heatmapFeature'),
imageTile: require('./imageTile'),
isolineFeature: require('./isolineFeature'),
jsonReader: require('./jsonReader'),
layer: require('./layer'),
lineFeature: require('./lineFeature'),
Expand Down
Loading

0 comments on commit a56a346

Please sign in to comment.