MXML checkbox toggle mappoints on/off

664
4
01-28-2014 04:30 PM
TomRauch
New Contributor
Hi, I am stumped about how to turn on and off a set of mappoints that meet a certain criteria indicated in MXML checkbox choices.  In my application, I want to be able to show facilities of a particular size (Large, Medium, Small).  When a user clicks "Large" on the checkbox, only facilities identified as Large appear as mapoints; the same would be true for Medium and Small.  When the user unclicks "Large" those facilities (and their associated mappoints) are cleared.

So far, in the code below, I can get a large red square to appear when the user clicks the "Large" checkbox; however, when the user unclicks "Large" that red square persists.  I know the code is running to the "else" condition because I have a trace set up that appears when I debug.  I suspect it has something to do with "wmp2_Q1" which is a WebMercatorMapPoint, but I can't figure out how to remove it.

Thanks for any help/guidance!

protected function checkbox1_clickHandler(event:MouseEvent):void
   {
    
    
if (Q1_cb.selected) {
    
var employees_from_facility_Q1: Array = from_query.filter(set_population);
    

    
 for (var i:uint = 0; i < employees_from_facility_Q1.length; ++i){
     
       
  var myGraphicMarker_Q1: Graphic = new Graphic(new WebMercatorMapPoint(employees_from_facility_Q1.facility_lon, employees_from_facility_Q1.facility_lat), new SimpleMarkerSymbol(SimpleMarkerSymbol.STYLE_SQUARE, 30, 0xFF3333, 0.5));
  var wmp2_Q1: WebMercatorMapPoint = new WebMercatorMapPoint(employees_from_facility_Q1.facility_lon, employees_from_facility_Q1.facility_lat);
     
     
  myGraphicsLayer.add(myGraphicMarker_Q1);
     
  myMap.centerAt(wmp2_Q1);  
      
     
  myGraphicsLayer.refresh(); }}
     
   
else {
 myGraphicsLayer.remove(myGraphicMarker_Q1);

 trace ("selected false");
      
 myGraphicsLayer.refresh();}}
    
    

private function set_population(element:*, index:int, arr:Array): Boolean{
 return (element.employees_per_facility > markerQ2);}
   
Tags (2)
0 Kudos
4 Replies
AnthonyGiles
Frequent Contributor
Tom,

What I would do is on load of the widget create 3 graphics layers one for each size, large, medium and small. Add the graphics you want on each layer and add the layers to the map but set the visible attribute of the layer to false.

Then all you need to do when the checkbox is selected/deselected is make the corresponding graphics layer visibility equal to the checkbox selected value.

Regards

Anthony
0 Kudos
TomRauch
New Contributor
Anthony, thanks - I had considered doing that (using layers); the ESRI/Flex demo code showed how to do on/off toggling using layers.  I have seen layers used for shapes, but not so much for mappoints, but I guess that's possible?

I will give using layers a shot!  Thanks, Tom
0 Kudos
TomRauch
New Contributor
Anthony, thanks - that approached worked!

Tom
0 Kudos
AnthonyGiles
Frequent Contributor
Tom,

No probs glad you got your solution. Please don't forget to mark the post as answered.

Regards

Anthony
0 Kudos