require([
"esri/map",
"esri/layers/FeatureLayer",
"dojo/on",
"dojo/domReady!"
],
function(
Map,
FeatureLayer,
on
) {
var map = new Map("map", {
basemap: "hybrid",
center: [-82.44109, 35.6122],
zoom: 17
});
var featureLayer = new FeatureLayer("https://services.arcgis.com/V6ZHFr6zdgNZuVG0/arcgis/rest/services/Landscape_Trees/FeatureServer/0", {
outFields: ["*"]
});
var timer;
var g;
var glayerNode;
var oldRVal;
map.addLayer(featureLayer);
on.once(featureLayer, "update-end", function() {
var docFrag = document.createDocumentFragment();
var names = featureLayer.graphics.map(function(x) {
return x.attributes.Condition;
}).reduce(function(a, b) {
if (a.indexOf(b) < 0) a.push(b);
return a;
}, []).filter(function(x) {
return x.length > 3;
}).map(function(name) {
var btn = document.createElement('button');
btn.className = "btn-condition";
btn.innerText = name;
docFrag.appendChild(btn);
return name;
});
document.getElementById("btns").appendChild(docFrag);
var btns = document.getElementById('btns');
on(btns, ".btn-condition:click", function(e) {
// do a multiselect
var graphics = featureLayer.graphics;
var matches = graphics.filter(function(x) {
return x.attributes.Condition === e.target.innerText;
});
var fragment = document.createDocumentFragment();
if (!matches[0]) {
return;
}
var gnode = matches[0].getNode();
if (!gnode) {
return;
}
var parent = gnode.parentNode;
matches
.map(function(x) {
var node = x.getNode();
if (node) {
node.parentNode.removeChild(node);
node.setAttribute("class", "selected");
fragment.appendChild(node);
}
});
parent.appendChild(fragment);
function update() {
glayerNode = featureLayer.getNode();
glayerNode.setAttribute("class", "unselected");
setTimeout(function() {
matches.map(function(x) {
var node = x.getNode();
if (node) {
node.setAttribute("class", "");
}
});
glayerNode.setAttribute("class", "");
}, 1000);
};
requestAnimationFrame(update);
});
featureLayer.on("click", function(e) {
if (g) {
var n = g.getNode();
if (n) {
n.r.baseVal.value = oldRVal;
n.setAttribute("class", "");
}
featureLayer.getNode().setAttribute("class", "");
}
g = e.graphic;
var node = g.getNode();
var parent = node.parentNode;
parent.removeChild(node);
parent.appendChild(node);
oldRVal = node.r.baseVal.value;
function update() {
node.r.baseVal.value = node.r.baseVal.value * 1.3;
node.setAttribute("class", "selected");
glayerNode = featureLayer.getNode();
console.log(glayerNode);
glayerNode.setAttribute("class", "unselected");
if (timer) {
clearTimeout(timer);
}
setTimeout(function() {
node.r.baseVal.value = oldRVal;
}, 200);
timer = setTimeout(function() {
node.setAttribute("class", "");
glayerNode.setAttribute("class", "");
node.r.baseVal.value = oldRVal;
clearTimeout(timer);
}, 1000);
};
requestAnimationFrame(update);
});
});
});
<body>
<div id="btns"></div>
<!--<button id="btnSelect">Push Me</button>-->
<div id="map"></div>
</body>
html,
body,
#map {
height: 100%;
width: 100%;
margin: 0;
padding: 0;
}
.esriMapLayers > svg circle {
transition: all .3s ease-in;
}
.selected {
opacity: 1 !important;
fill-opacity: 1 !important;
}
.unselected > circle {
opacity: 0.30;
}
External resources loaded into this fiddle: