Popups on multiple copies of same service layer

2328
11
Jump to solution
08-16-2012 11:02 AM
RhettZufelt
MVP Frequent Contributor
I have a service with three feature classes in it.  I load them with the follwing code: (As you can see, they are all from the same mapservice, just with different definitionexpression)

   <layer label="Post-closure" type="dynamic" visible="true" alpha="1"       url="http://gis01.wch-rcc.com/ArcGIS/rest/services/SDCV_custom/WCH_WIDS_Status/MapServer">       <sublayer id="3" popupconfig="popups/PopUp_wastepolys.xml" definitionexpression="LVL1Stage = 'Post-closure'"/>       <sublayer id="1" popupconfig="popups/PopUp_wastepoints.xml" definitionexpression="LVL1Stage = 'Post-closure'"/>       <sublayer id="2" popupconfig="popups/PopUp_wastelines.xml" definitionexpression="LVL1Stage = 'Post-closure'"/>     </layer>    <layer label="Closure" type="dynamic" visible="true" alpha="1"       url="http://gis01.wch-rcc.com/ArcGIS/rest/services/SDCV_custom/WCH_WIDS_Status/MapServer">       <sublayer id="3" popupconfig="popups/PopUp_wastepolys.xml" definitionexpression="LVL1Stage = 'Closure'"/>       <sublayer id="1" popupconfig="popups/PopUp_wastepoints.xml" definitionexpression="LVL1Stage = 'Closure'"/>       <sublayer id="2" popupconfig="popups/PopUp_wastelines.xml" definitionexpression="LVL1Stage = 'Closure'"/>       </layer>    <layer label="RTD" type="dynamic" visible="true" alpha="1"       url="http://gis01.wch-rcc.com/ArcGIS/rest/services/SDCV_custom/WCH_WIDS_Status/MapServer">       <sublayer id="3" popupconfig="popups/PopUp_wastepolys.xml" definitionexpression="LVL1Stage = 'RTD'"/>       <sublayer id="1" popupconfig="popups/PopUp_wastepoints.xml" definitionexpression="LVL1Stage = 'RTD'"/>       <sublayer id="2" popupconfig="popups/PopUp_wastelines.xml" definitionexpression="LVL1Stage = 'RTD'"/>     </layer>    <layer label="Confirmatory" type="dynamic" visible="true" alpha="1"       url="http://gis01.wch-rcc.com/ArcGIS/rest/services/SDCV_custom/WCH_WIDS_Status/MapServer">       <sublayer id="3" popupconfig="popups/PopUp_wastepolys.xml" definitionexpression="LVL1Stage = 'Confirmatory'"/>       <sublayer id="1" popupconfig="popups/PopUp_wastepoints.xml" definitionexpression="LVL1Stage = 'Confirmatory'"/>       <sublayer id="2" popupconfig="popups/PopUp_wastelines.xml" definitionexpression="LVL1Stage = 'Confirmatory'"/>     </layer>
This way, I can have it draw only a subset of each based on my definition and it loads a point, line, and polygon layer and displays features in all three that match the query that loads as a "single" layer.
The problem seems to be the popups only work on the last load instance of this layer.  I.e., with the above config, it will only popup on the "Post-closure" layer, and just ignores the "Closure" and other layers.  If I turn off the "Post-closure", then it will popup on the "Closure" layer.  I actually have to turn off "Post-closure" and "Closure" to get it to popup on "RTD" (see the pattern).  Since I have 4 different layers loaded from this same service, it will only popup one at a time and all the other layers "above" it need to be turned off.

Is it possible to make the popups work on "any" of the layers that are visible, regardless of which was turned on last or that they are from the same service?

R_
Tags (2)
0 Kudos
11 Replies
AndrewEdmonds
New Contributor III
Wow, thanks for all the help you are offering, Rhett.  This is great.  It may be a couple days before I can test this; getting pulled in different directions right now.

Quick note about the photos -- we are storing them online so they are accessible to other clients.  Each layer's pop-up references the photos in the <medias> tag with this code:

    <medias>
        <media type="image" caption="{Site_Name}"     
    imagesource="http://www.hpo.ncdcr.gov/photos/{Site_ID}.JPG"
    imagelink="http://www.hpo.ncdcr.gov/photos/{Site_ID}.JPG" />
    </medias>


So you see that EVERY feature's pop-up attempts to go find a photo (every feature has a Site_ID), although only a very small number currently have one.
0 Kudos
RhettZufelt
MVP Frequent Contributor
Add this to the default.css:
esri|PopUpRenderer
{
 skin-class: ClassReference("com.esri.ags.skins.PopUpRendererSkin");
}



and this modification to the PopUpRendererSkin.mxml:
   for each (var fieldInfo:PopUpFieldInfo in popUpInfo.popUpFieldInfos)
{
 var fldName:String = formattedAttributes[fieldInfo.fieldName];
        if (fieldInfo.visible && hostComponent.featureLayer.url == "http://gis.ncdcr.gov/ArcGIS/rest/services/NC_Surveyed_Only/MapServer/0"
 && fieldInfo.fieldName == "County" && fldName!= "Bertie" && fldName!= "Brunswick")
{
  validMediaInfos = null;
}  
 if (fieldInfo.visible && formattedAttributes[fieldInfo.fieldName] && formattedAttributes[fieldInfo.fieldName] != " ")
 {
 var fieldLabel:Label = new Label();


does it. The idea being to make it fail this test just below the above code



                    if (validMediaInfos && validMediaInfos.length > 0)
                    {
                        vGroup.addElement(mediaBrowser);
                        mediaBrowser.attributes = graphic.attributes;
                        mediaBrowser.formattedAttributes = formattedAttributes;
                        mediaBrowser.popUpFieldInfos = popUpInfo.popUpFieldInfos;
                        mediaBrowser.popUpMediaInfos = validMediaInfos;
                    }
so that the medias don't get added to the vGroup.

(again, the red code removes items with null or empty values from the popup, so remove that if you want to see no values.)

R_

Of course this will still give you the broken link/preview for the sites in the two counties that do NOT have a photo (noticed there are a few).

Thought one could get fancy and test to see if the jpeg file exists, if so, then add it. However, there is no http://www.hpo.ncdcr.gov/crossdomain.xml file, so it doesn't allow access to the images from index.swf so throws a debugger error every time. However, if it does exist, it will still preview it and give you the link? Not sure why, almost as if the crossdomain.xml doesn't apply from within the popup? Once clicked, it opens in a separate browser, not within flex, so that makes sense. Don't really understand why I get the sandbox violation and still load the preview/link.
0 Kudos