I am looking for some script that will count the number of features on the map and display it.
I am thinking something like this: Crime Mapper
I need this to change every time the filter changes.
Solved! Go to Solution.
I tried that (that is what Robert has above)
My error is:
TypeError: Cannot read property 'on' of undefined
I removed yourFeatureLayer and that error goes away.
and i get this error:
Cannot read property 'graphics' of undefined
I did pull it from Robert's example - it should work. Did you replace "yourFeatureLayer" with the one you're using, and it's defined/in scope? You should pull it right from "evt", the graphics, that is - I see you're defining graphics to itself above, however - I would need to see more code to see what you're doing here.
The reason I am defining it to itself is because I was testing out options to define graphics.
My code:
lLayer.on("update-end", function (evt) { console.info(evt); dom.byId("featcount").innerHTML = " " + evt.target.graphics.length; });
I get this error
lLayer is the same as layer def as I use here:
lLayer.setDefinitionExpression(defArr.join(" AND "));
Ok, cool - so it looks like ILayer is good from what I can see... it just doesn't know what "on" is referring to. Can you share how you're constructing your main map page? Are you doing it in the main require, or in a module? I'm sorry - I haven't used the webapp builder... I'm not sure how it constructs this for you.
Okay I got it!
I moved:
var target = e.target || e.srcElement; lLayer.on("update-end", function (evt) { console.info(evt); dom.byId("featcount").innerHTML = " " + evt.target.graphics.length;
inside :
on(node, "click", function (e) {
Thank you Robert and Chris for your help!