Skip to content

Instantly share code, notes, and snippets.

@odoe
Created February 1, 2016 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odoe/436849dfb8765284d3a7 to your computer and use it in GitHub Desktop.
Save odoe/436849dfb8765284d3a7 to your computer and use it in GitHub Desktop.
on(btns, ".btn-condition:click", function(e) {
// do a multiselect
var graphics = featureLayer.graphics;
// find the graphics that match my query
var matches = graphics.filter(function(x) {
return x.attributes.Condition === e.target.innerText;
});
// make sure you have results
if (!matches[0]) {
return;
}
var gnode = matches[0].getNode();
if (!gnode) {
return;
}
// keep a document fragment on hand
var fragment = document.createDocumentFragment();
// save the parentNode, same for all graphics
var parent = gnode.parentNode;
matches
.map(function(x) {
var node = x.getNode();
if (node) {
// removing and adding the node, brings it to the top
node.parentNode.removeChild(node);
node.setAttribute("class", "selected");
fragment.appendChild(node);
}
});
parent.appendChild(fragment);
function update() {
glayerNode = featureLayer.getNode();
glayerNode.setAttribute("class", "unselected");
// small timeout then reset the css of everything
setTimeout(function() {
matches.map(function(x) {
var node = x.getNode();
if (node) {
node.setAttribute("class", "");
}
});
glayerNode.setAttribute("class", "");
}, 1000);
};
// on the next frame let's update the css
requestAnimationFrame(update);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment