-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a pixelmap feature #637
Merged
Changes from 14 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
bbf7669
Add a pixelmap feature.
manthey ea56189
Fix issues with setting feature visibility.
manthey 9f5008e
Add and remove features on a feature layer.
manthey 8886861
Add pixelmap example.
manthey c9a83d0
Added a maxIndex function.
manthey ef1f546
Improve the speed of pixelmap's update.
manthey 7eda653
More speed improvements for updates.
manthey 3d0d00a
Add a event.pixelmap.prepared event.
manthey 8060563
When constructing a mapInteractor with options, make sure the whole s…
manthey 88db688
Merge branch 'master' into pixelmap
manthey d98ca30
Several adjustments to align with other PRs.
manthey 75cdc50
Allow colors to include an alpha value.
manthey b536513
Add tests.
manthey 4b5d219
Merge branch 'master' into pixelmap
manthey 6e73a80
Add isReadyImage function.
manthey 8f65be1
Rename mapColor to color.
manthey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"path": "pixelmap", | ||
"title": "Pixelmap feature", | ||
"exampleCss": ["main.css"], | ||
"exampleJs": ["main.js"], | ||
"about": { | ||
"text": "This example shows how to use a pixelmap feature. The pixelmap colors areas based on an index derived from an image and some data per index." | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
extends ../common/templates/index.jade |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* globals utils */ | ||
|
||
var debug = {}; | ||
|
||
// Run after the DOM loads | ||
$(function () { | ||
'use strict'; | ||
|
||
// Get the query parameters and set controls appropriately. The query takes: | ||
// map: the png file used for the pixel map. | ||
// json: the json file for the starting state. | ||
var query = utils.getQuery(); | ||
var pixelmapUrl = query.map || 'pixelmap.png'; | ||
var pixelmapJSON = query.json === undefined ? 'pixelmap.json' : query.json; | ||
var map, mapParams, osm, osmParams, layer, pixelmap, pixelmapParams; | ||
// Center the map on the United States | ||
mapParams = { | ||
node: '#map', | ||
center: {x: -98.58333, y: 39.83333}, | ||
zoom: 4, | ||
discreteZoom: false | ||
}; | ||
map = geo.map(mapParams); | ||
// Add a tile layer to the map | ||
osm = map.createLayer('osm', osmParams); | ||
// Create a feature layer that supports the pixelmap feature. This can be | ||
// overridden to use a specific renderer | ||
layer = map.createLayer('feature', { | ||
renderer: query.renderer ? (query.renderer === 'html' ? null : query.renderer) : undefined, | ||
features: query.renderer ? undefined : ['pixelmap'], | ||
opacity: 0.65 | ||
}); | ||
// Our default pixelmap covers a known geographic region | ||
pixelmapParams = { | ||
selectionAPI: true, | ||
url: pixelmapUrl, | ||
position: {ul: {x: -180, y: 71.471178}, lr: {x: -60, y: 13.759032}}, | ||
mapColor: function (d, idx) { | ||
// Always set index 0 to transparent. Other indicies are set based on | ||
// the data value | ||
var color = {r: 0, g: 0, b: 0, a: 0}; | ||
if (idx && d && d.value) { | ||
color = d.value === 'R' ? 'red' : 'blue'; | ||
} | ||
return color; | ||
} | ||
}; | ||
pixelmap = layer.createFeature('pixelmap', pixelmapParams); | ||
layer.draw(); | ||
// When the user left clicks, cycle through three states. A right click | ||
// clears the state. | ||
pixelmap.geoOn(geo.event.feature.mouseclick, function (evt) { | ||
var data = pixelmap.data(); | ||
if (!data) { | ||
return; | ||
} | ||
if (data[evt.index] === undefined) { | ||
data[evt.index] = {}; | ||
} | ||
var val = data[evt.index].value; | ||
if (evt.mouse.buttonsDown.left) { | ||
var cycle = {'D': 'R', 'R': '', '': 'D'}; | ||
val = cycle[cycle[val] !== undefined ? val : '']; | ||
} else if (evt.mouse.buttonsDown.right) { | ||
val = ''; | ||
} | ||
if (val !== data[evt.index].value) { | ||
data[evt.index].value = val; | ||
pixelmap.data(data).draw(); | ||
} | ||
}); | ||
// Load the JSON file | ||
if (pixelmapJSON) { | ||
$.ajax({url: pixelmapJSON}).done(function (resp) { | ||
pixelmap.data(resp); | ||
pixelmap.draw(); | ||
}); | ||
} | ||
|
||
// Expose some internal to make it easier to play with the example from the | ||
// browser console. | ||
debug.map = map; | ||
debug.mapParams = mapParams; | ||
debug.osm = osm; | ||
debug.osmParams = osmParams; | ||
debug.layer = layer; | ||
debug.pixelmap = pixelmap; | ||
debug.pixelmapParams = pixelmapParams; | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[{"name": "background"}, {"name": "Arizona", "value": "D"}, {"name": "Arkansas", "value": "R"}, {"name": "California", "value": "D"}, {"name": "Colorado", "value": "D"}, {"name": "Connecticut", "value": "D"}, {"name": "District of Columbia", "value": "D"}, {"name": "Georgia", "value": "R"}, {"name": "Hawaii", "value": "D"}, {"name": "Illinois", "value": "D"}, {"name": "Indiana", "value": "R"}, {"name": "Louisiana", "value": "R"}, {"name": "Minnesota", "value": "D"}, {"name": "Mississippi", "value": "R"}, {"name": "Montana", "value": "R"}, {"name": "New Mexico", "value": "D"}, {"name": "North Dakota", "value": "R"}, {"name": "Oklahoma", "value": "R"}, {"name": "Pennsylvania", "value": "D"}, {"name": "Tennessee", "value": "R"}, {"name": "Virginia", "value": "D"}, {"name": "Puerto Rico", "value": null}, {"name": "Delaware", "value": "D"}, {"name": "West Virginia", "value": "R"}, {"name": "Wisconsin", "value": "D"}, {"name": "Wyoming", "value": "R"}, {"name": "Alabama", "value": "R"}, {"name": "Alaska", "value": "R"}, {"name": "Florida", "value": "D"}, {"name": "Idaho", "value": "R"}, {"name": "Kansas", "value": "R"}, {"name": "Maryland", "value": "D"}, {"name": "New Jersey", "value": "D"}, {"name": "North Carolina", "value": "D"}, {"name": "South Carolina", "value": "R"}, {"name": "Washington", "value": "D"}, {"name": "Vermont", "value": "D"}, {"name": "Utah", "value": "R"}, {"name": "Iowa", "value": "D"}, {"name": "Kentucky", "value": "R"}, {"name": "Maine", "value": "D"}, {"name": "Massachusetts", "value": "D"}, {"name": "Michigan", "value": "D"}, {"name": "Missouri", "value": "R"}, {"name": "Nebraska", "value": "R"}, {"name": "Nevada", "value": "D"}, {"name": "New Hampshire", "value": "D"}, {"name": "New York", "value": "D"}, {"name": "Ohio", "value": "D"}, {"name": "Oregon", "value": "D"}, {"name": "Rhode Island", "value": "D"}, {"name": "South Dakota", "value": "R"}, {"name": "Texas", "value": "R"}] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
var inherit = require('../inherit'); | ||
var registerFeature = require('../registry').registerFeature; | ||
var pixelmapFeature = require('../pixelmapFeature'); | ||
|
||
////////////////////////////////////////////////////////////////////////////// | ||
/** | ||
* Create a new instance of class pixelmapFeature | ||
* | ||
* @class geo.canvas.pixelmapFeature | ||
* @param {Object} arg Options object | ||
* @extends geo.pixelmapFeature | ||
* @returns {canvas_pixelmapFeature} | ||
*/ | ||
////////////////////////////////////////////////////////////////////////////// | ||
var canvas_pixelmapFeature = function (arg) { | ||
'use strict'; | ||
|
||
if (!(this instanceof canvas_pixelmapFeature)) { | ||
return new canvas_pixelmapFeature(arg); | ||
} | ||
pixelmapFeature.call(this, arg); | ||
|
||
var object = require('./object'); | ||
object.call(this); | ||
|
||
this._init(arg); | ||
return this; | ||
}; | ||
|
||
inherit(canvas_pixelmapFeature, pixelmapFeature); | ||
|
||
// Now register it | ||
registerFeature('canvas', 'pixelmap', canvas_pixelmapFeature); | ||
module.exports = canvas_pixelmapFeature; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
curious: why you had to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In our various renderers, we have renderer-specific changes to objects, mostly to make a renderer-specific draw method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay, thanks.