Identify Deprecated Items with ArcGIS JSAPI

Identify Deprecated Items with ArcGIS JSAPI

Rene Rubalcava | December 30, 2020

What are deprecated items

When you build an app on the ArcGIS Online Platform, you not only get to use data that you publish, but also data others publish. There's a wealth of awesome curated data in the Living Atlas, and it's exciting to have access to everything at your fingertips. However, sometimes, data becomes deprecated for various reasons, either new data is published as a new item, or some other reason unbeknownst to me. Whatever the reason, when the item is marked as deprecated, and you are using it in an application, it would be cool to figure that out. If you're lucky, they added deprecated to the title. Sometimes, they don't.

Do what you need to do

First thing you need to know is that when an item has been deprecated, it's added as a tag to the item. That means you can check the tags property of the portal item. Any webmap or layer that was created from a portal item will have a .portalItem property. That means you can check the tags to see if it's been deprecated.

if (layer.portalItem && layer.portalItem.tags.includes("deprecated")) {
    // do something
    // let the user know
    // set off an alarm
}

You can decide how you want to let your users know if an item is deprecated, but if I may. The LayerList widget offers a unique and user-friendly way to do something like this. You can customize the ListItem via the ListItemPanel to add some custom UI elements. This is done by add a listItemCreated. You can look at this sample to how it's used to add custom actions.

You can modify this sample to add a deprecation notice too!

const layerList = new LayerList({
    view: view,
    listItemCreatedFunction: defineActions
});

// Creates actions in the LayerList
function defineActions(event) {
    const item = event.item;

    ...

    if (event.item.layer.portalItem) {
        if (event.item.layer.portalItem.tags.includes("deprecated")) {
            const elem = document.createElement("div");
            elem.classList.add("error");
            elem.classList.add("message");
            elem.innerText = "Item Deprecated";
            item.panel = {
                content: elem,
                className: "esri-icon-notice-triangle error"
            };
        }
    }
}

This will add a warning icon to the LayerList and a message about the deprecated item. That's pretty cool right!

I think this is a pretty straightforward way to let users know about deprecated items that might show up in your apps. Of course, they can now contact you and you can update the data in your app! It's a win-win for everyone!

Try it yourself

You can view a demo of how this works below.

And what do you know, I made a video about this too!

Enjoy!