@wsdot/layer-metadata-soe-client
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

Layer Metadata Server Object Extension JavaScript client

This package provides functions for calling the Layer Metadata SOE.

npm version npm license npm donwloads Build Status

Usage

Install with the following command.

npm install @wsdot/layer-metadata-soe-client

See the API documentation for detailed information.

TypeScript Example

import { detectLayerMetadataSupport, getMetadataLinks, ArcGisError } from "@wsdot/layer-metadata-soe-client"

/**
 * Create HTML lists of metadata documents for map service layer data sources.
 * @returns a document fragment containing lists and headings.
 */
async function createMetadataList (url: string) {
    const isSupported = await detectLayerMetadataSupport(url);
    if (!isSupported) {
        const msg = `Service does not support LayerMetadata SOE: ${url}`;
        throw new Error(msg);
    }

    try {
        const metadataLinks = await getMetadataLinks(url);
        const frag = document.createDocumentFragment();
        for (const dataName in metadataLinks) {
            const heading = document.createElement("h2");
            heading.textContent = dataName;
            frag.appendChild(heading);
            if (metadataLinks.hasOwnProperty(dataName)) {
                const linkUrls = metadataLinks[dataName];
                const list = document.createElement("ul");
                for (const linkUrl of linkUrls) {
                    const li = document.createElement("li");
                    const a = document.createElement("a");
                    a.href = linkUrl;
                    a.textContent = linkUrl;
                    a.target = "_blank";
                    li.appendChild(a);
                    list.appendChild(li);
                }
                frag.appendChild(list);
            }
        }
        return frag;
    } catch (error) {
        if (error instanceof ArcGisError) {
            console.error(`The service returned an error message. ${error.code}: ${error.message}`);
        }
        throw error;
    }
}

// Specify the map service
const url = "https://example.com/ArcGIS/services/MyService/MapServer";
// Call the async function and handle success and error conditions.
createMetadataList(url).then(frag => {
    // Append the document fragment to the document body.
    document.body.appendChild(frag);
}, error => {
    // log the error to the console.
    console.error("list creation error", error);
})

Readme

Keywords

Package Sidebar

Install

npm i @wsdot/layer-metadata-soe-client

Weekly Downloads

0

Version

3.0.0

License

Unlicense

Unpacked Size

22 kB

Total Files

5

Last publish

Collaborators

  • jeff-jacobson