@wsdot/layer-metadata-soe-client
v3.0.0
Published
Client for accessing layer metadata from an ArcGIS Server map service which has the Layer Metadata SOE installed.
Downloads
5
Readme
Layer Metadata Server Object Extension JavaScript client
This package provides functions for calling the Layer Metadata SOE.
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);
})