0

I've got a Flex application that shows pipeline data on a touchscreen map (for an exhibit). The spec mandates that tapping an element on the map (such as a power plant or substation) will trigger a popup with related data (age of the facility, name of the facility, owner of the facility, etc.)

I'm not sure how to go about this. I've tried multiple approaches including using a MapMouseEvent on my map and trying to catch MouseEvents on the individual layers. I only ever get either the whole map returned or the top layer (not even the layer I'm trying to touch). It's like layers are large fields that act as one single entity and I can't access individual elements of them or other layers that lie beneath them.

Here's the MXML code I use to access the layers from the server:

<esri:Map level="3" wrapAround180="true" id="myMap">
    <esri:center>
        <esri:WebMercatorMapPoint lon="-98.35" lat="39.5" />
    </esri:center>
    <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer" id="baseStreet" />
    <esri:ArcGISTiledMapServiceLayer url="http://server.arcgisonline.com/ArcGIS/rest/services/World_Imagery/MapServer" id="baseImagery" />
    <esri:ArcGISDynamicMapServiceLayer url="http://localhost:6080/arcgis/rest/services/Pennwell_Substations/MapServer" id="Substations" />
    <esri:ArcGISDynamicMapServiceLayer url="http://localhost:6080/arcgis/rest/services/Pennwell_Facilities/MapServer" id="Facilities" />
    <esri:ArcGISDynamicMapServiceLayer url="http://localhost:6080/arcgis/rest/services/Pennwell_Interconnects/MapServer" id="Interconnects" />
    <esri:ArcGISDynamicMapServiceLayer url="http://localhost:6080/arcgis/rest/services/Pennwell_Pipelines/MapServer" id="Pipelines" />
    <esri:ArcGISDynamicMapServiceLayer url="http://localhost:6080/arcgis/rest/services/Pennwell_PowerLines/MapServer" id="PowerLines" />
    <esri:ArcGISDynamicMapServiceLayer url="http://localhost:6080/arcgis/rest/services/Pennwell_PowerPlants/MapServer" id="PowerPlants" />
    <esri:ArcGISDynamicMapServiceLayer url="http://localhost:6080/arcgis/rest/services/Pennwell_HydroelectricPlants/MapServer" id="HydroelectricPlants" />
    <esri:ArcGISDynamicMapServiceLayer url="http://localhost:6080/arcgis/rest/services/USGS_WindTurbines/MapServer" id="WindTurbines" />
</esri:Map>

Here's the Actionscript 3.0 code I'm using to try and access the elements, where log(str:String):void is my equivalent of trace() but prints arguments to a text field in the application.

myMap.addEventListener(MapMouseEvent.MAP_CLICK, function(meEvent:MapMouseEvent):void {
    log(meEvent.toString());
});

I don't want to display the data to an InfoPanel, I just want to be able to access it (for now). I'll be implementing a custom UI for this.

Screenshot of application

0

Finally got it to work. I ended up using identifyParams().

myMap.addEventListener(MapMouseEvent.MAP_CLICK, function(meEvent:MapMouseEvent):void {
    hidePopup();                                              // I have a popup method later on that hides or shows a popup containing a string

    var identifyParams:IdentifyParameters = new IdentifyParameters();
    identifyParams.layerOption = IdentifyParameters.LAYER_OPTION_VISIBLE;
    identifyParams.returnGeometry = true;                     // Not sure what this does, just know that it's needed
    identifyParams.tolerance = 20;                            // How close the point can be to the event
    identifyParams.width = myMap.width;                       // Check the whole map (width)
    identifyParams.height = myMap.height;                     // Check the whole map (height)
    identifyParams.geometry = meEvent.mapPoint;               // Just do this
    identifyParams.mapExtent = myMap.extent;                  // And this
    identifyParams.spatialReference = myMap.spatialReference; // And also this

    clickLocation = meEvent.mapPoint;                         // Identify the click location

    //================================================
    // The following could definitely be done more elegantly,
    // like putting all the layers in an array and then looping through
    // but meh...
    //================================================

    identifySubstations.execute(identifyParams, new AsyncResponder(onResult, myFaultFunction));
    identifyFacilities.execute(identifyParams, new AsyncResponder(onResult, myFaultFunction));
    identifyInterconnects.execute(identifyParams, new AsyncResponder(onResult, myFaultFunction));
    identifyPipelines.execute(identifyParams, new AsyncResponder(onResult, myFaultFunction));
    identifyPowerLines.execute(identifyParams, new AsyncResponder(onResult, myFaultFunction));
    identifyPowerPlants.execute(identifyParams, new AsyncResponder(onResult, myFaultFunction));
    identifyHydroelectricPlants.execute(identifyParams, new AsyncResponder(onResult, myFaultFunction));
    identifyWindTurbines.execute(identifyParams, new AsyncResponder(onResult, myFaultFunction));
});

function onResult(results:Array, token:Object = null):void {
    if (results && results.length > 0) {
        var result:IdentifyResult = results[i];
        var allOfIt:String = "";
        for (var str:String in result.feature.attributes) {
            allOfIt += str + ": " + result.feature.attributes[str] + "\n";
        }
        trace(allOfIt);
    }
}

function myFaultFunction(error:Object, token:Object = null):void {
    trace(String(error));
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.