Aller au contenu principal

Get layer name from layer action in a workflow

Répondu

Commentaires

11 commentaires

  • Victor Catalán

    Marc Rempel

    When you access the context, you have access to the VertiGIS Studio Object Classes. If you navigate to "Layers"  you will find the properties like "url" and "title" (I think this is what you are looking for).

    I would do something like this:

    $getWorkflowInputs.inputs.context.layers.title

    You can also access the ArcGIS Maps Object using the "_layer" property:

    $getWorkflowInputs.inputs.context.layers._layer

    Note that if you are accessing the layer action from the menu and not directly from the layer, the context will have an array of all layers instead of an object. And you will have to iterate through it.

    $getWorkflowInputs.inputs.context.layers[0].title

    Here the link to the documentation about the use of the context in the different menus https://docs.vertigisstudio.com/webviewer/latest/admin-help/use-the-menu-context-as-a-work.html

     

    0
  • Marc Rempel

    Victor,

    Thanks for the response. That helped me get on the right track! It is a bit of a mystery in exploring the context object for how to grab content from what is returned.

    For anyone else that might go down this path, I found that I can find the sourceJSON of the layer and url which can be handy for other uses.

    =$getWorkflowInputs1.inputs.context.layers.sublayer.url

    =$getWorkflowInputs1.inputs.context.layers.sublayer.sourceJSON

     

    0
  • Ali VanSickle

    To add to this….I believe context object is also different for Map Image Layers vs Feature Layers.

    We have Map Image Layers configured in our WebMap and you cannot get the .layer information for it.
    =$getWorkflowInputs1.inputs.context.layers will not return anything and you have to explicitly use context[0] to find any information.

    Does anyone have a better way to get layer info from the context of Map Image Layers?

    0
  • Gareth Evans

    Hey Ali VanSickle 

    TLDR: To access the layer-specific information, the key is to use the operationalLayers property nested within inputs.context.maps.map.

    I went down a rabbit hole when investigating this context (pun unintended), and wanted to share my findings and suggestions. You're absolutely correct that the context object behaves differently for Map Image Layers compared to other layer types due to the underlying differences in how these layers are structured and interacted within the ArcGIS Maps SDK for JavaScript that we depend on. 

    Key Differences

    • Map Image Layers:
      • Represented as a single object in operationalLayers with potential sublayers nested in the layers property.
      • Metadata like id, title, and visibility is accessible, but feature-level interactivity is limited.
      • Use this for server-rendered visualization of large datasets.
    • Feature Layers:
      • Provide direct access to individual features, attributes, and geometries.
      • Contain additional properties such as fields, features, and geometryType.
      • Ideal for applications needing interactivity or editing at the feature level.

     

    Example Expressions For Map Image Layers

    1. To access all operational layers:

      =$getWorkflowInputs1.inputs.context.maps.map.operationalLayers

    2. To access a specific layer's details (e.g., the first layer in the array):

      =$getWorkflowInputs1.inputs.context.maps.map.operationalLayers[0].id

       

    This expression retrieves the id of the first operational layer. You can also access other properties such as title, layerType, and visibility.

    This approach works for retrieving all the layer-specific information from a Map Image Layer, including:

    • ID
    • Title
    • Visibility
    • Sublayers (if present, accessible under the layers property)

    For instance, to get the title of the 0th layer:

    =$getWorkflowInputs1.inputs.context.maps.map.operationalLayers[0].title

    Example JSON

    Below is the (abridged) JSON structure returned by =$getWorkflowInputs1 in my workflow. This helped me identify the correct path to access operationalLayers:

    {
        "inputs": {
            "context": {
                "maps": {
                    "failureMode": "warn",
                    "id": "default",
                    "layerExtensions": [
                        "item://layer-extension/b6607ded-338e-4109-9ccd-3c09223a9521"
                    ],
                    "map": {
                        "operationalLayers": [
                            {
                                "id": "1937a18c79c-layer-2",
                                "title": "NHDES - Public Potential Contaminants",
                                "layerType": "ArcGISMapServiceLayer",
                                "visibility": true,
                                "layers": [
                                    { "id": 0 },
                                    { "id": 1 },
                                    { "id": 2 }
                                ]
                            }
                        ]
                    }
                }
            }
        }
    }

    From this JSON, I identified that:

    1. The operationalLayers array resides under inputs.context.maps.map.
    2. Each layer's metadata (e.g., id, title, visibility) is directly accessible in the array elements.
    3. For Map Image Layers, sublayers are nested under the layers property of the parent layer.

    By using the path inputs.context.maps.map.operationalLayers, I was able to dynamically retrieve and work with the layer data.

    If you encounter undefined errors, optional chaining can help prevent crashes. For example:

    =$getWorkflowInputs1?.inputs?.context?.maps?.map?.operationalLayers[0]?.id

    Hopefully this helps!

     

    0
  • Ali VanSickle

    Thanks for this Gareth! Very helpful.

    However, our GetWorkFlowInputs, does not return the Map object:
     

     

    We are running this workflow from a Feature Action in the result details. Do it matter how/where you are triggering the workflow from as well?

    0
  • Gareth Evans

    Doh, I had written a response to this and it seems to have not sent. Here you go, Ali VanSickle:

    Yes, it does matter: that context only includes the full map when you are running from the right-click Context menu. Feature Actions do not get that same context, they only get an array of the feature(s). This is covered in docs here: Use the Menu Context as a Workflow Input

    All that to say, I would suggest using a Get Map if you need to work with more than just the features you have selected.

    I have, just yesterday, put together a KBA on  How to extend VertiGIS Studio Web with Workflow: Query a Layer and Display Results using viewer commands. In the provided workflow (download here), I use a Get Map and work through a query and results display. You could probably extend that with some further logic to get what you are after. 

    0
  • Ali VanSickle

    Thanks Gareth, 

    This is very helpful! So just so I am understanding it correctly, if you are using Map Image Layers and need to access the Layer Name from the Feature Actions menu, the only way to do this would be to add a GetMap activity. We still will not be able to know what layer the user is interacting with in the workflow though. 

    Our situation:

    - Map Image Layers
    -From the feature actions menu, fire off a workflow that will submit data issues about that feature to a new feature class. We need to provide the layer name as an attribute in the feature class that we are adding to. But I don't think this is possible to do pragmatically. 

    My workaround at the moment is to just used a bunch of IF activities and search based on the ID of the layer and assign the Layer Name one by one, because that is the only think I can find that is returned from the GetWorkflowInputs activity.

    0
  • Ryanne Pattenden

    Ali VanSickle  I am working on workflow that is fired off from result actions but the workflow only applies to one feature class. I would have another workflow path for other features using a switch activity. How are you using if activities going from the getworkflowinput activity to identify the feature layer id.

    0
  • Ali VanSickle

    Ryanne Pattenden 

    First use the convert to JSON tool with the outputs from the getworkflowinput activity =$getWorkflowInputs1.inputs.context[0])

    Then parse the JSON from the result of the convert to json
    =$json1.json

    Use the parse result in the if statements:

    ex:
    =$parseJson1.result.source == "item://layer-extension/49d8e5aa-4f7d-4545-a4fa-b65b1b3369e6"

    It is defiantly a pain to do it this way but it works for me.

    0
  • Ryanne Pattenden

    Great! Thank you! I was trying to get the id/Source from the $getWorkflowInputs1.

    Not sure if this is helpful but instead of if activities, I am using a switch. You still need to identify each of the feature sources, but it might clean up the if activities.

    0
  • Andreas Grimm

    Hey everyone,

    instead of getting a layer's name, is there a way to get a layer's associated feature classes' name in this way? 

    Background: I'd like to offer a dynamic URL for each layer, linking to the associated layer's metadata on an external website. 

    The URL would look something like this: “metadata.com/<name of feature class>” - does anyone know if this is doable?

    0

Vous devez vous connecter pour laisser un commentaire.