Skip to content

Commit

Permalink
Added sample config
Browse files Browse the repository at this point in the history
  • Loading branch information
ckwongesri committed Apr 18, 2023
1 parent 60048e4 commit 3052c28
Show file tree
Hide file tree
Showing 2 changed files with 33,857 additions and 17 deletions.
37 changes: 20 additions & 17 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import esriRequest from "@arcgis/core/request";
import MapView from "@arcgis/core/views/MapView";
import LayerList from "@arcgis/core/widgets/LayerList";
import "./style.css";
import config from "./sample/config.json";

const mapImageLayerUrl =
"https://geriapp.esrisa.com/swa/rest/services/NEWater_Network/MapServer";

const mapImageLayer = new MapImageLayer({
url: mapImageLayerUrl,
sublayers: config.subLayers,
});

const map = new Map({
Expand All @@ -22,9 +24,6 @@ const view = new MapView({
map: map,
center: [103.78, 1.34],
zoom: 12,
popup: {
defaultPopupTemplateEnabled: true,
},
});

const layerList = new LayerList({
Expand All @@ -34,6 +33,7 @@ const layerList = new LayerList({
view.ui.add(layerList, "top-right");

view.whenLayerView(mapImageLayer).then(async () => {
console.log("loading...");
const popupTemplate = await generatePopupTemplate(mapImageLayerUrl);
console.log(popupTemplate);
});
Expand All @@ -46,27 +46,30 @@ const generatePopupTemplate = async (url: string, id?: number) => {
return {
title: layer.name,
id: layer.id,
visibility: layer.defaultVisibility,
content: [
{
type: "fields",
fieldInfos:
layer.fields?.map((field: any) => {
return {
fieldName: field.name,
label: field.alias,
};
}) || [],
},
],
visible: layer.defaultVisibility,
popupTemplate: {
title: `{${layer.displayField}}`,
content: [
{
type: "fields",
fieldInfos:
layer.fields?.map((field: any) => {
return {
fieldName: field.name,
label: field.alias,
};
}) || [],
},
],
},
};
}
return Promise.all(
sublayers.map((sublayer: any) => generatePopupTemplate(url, sublayer.id))
).then((popupTemplates) => {
return {
title: layer.name || layer.mapName,
visibility: layer.defaultVisibility,
visible: layer.defaultVisibility,
id: layer.id,
subLayers: popupTemplates,
};
Expand Down
Loading

0 comments on commit 3052c28

Please sign in to comment.