mcpField
A
arcgis-portal-content

arcgis-portal-content

github.com/saschabrunnerch開発2363 回インストール29 週間前に更新
リポジトリ

arcgis-portal-content について

ArcGIS Maps SDK for JavaScriptでマップ、シーン、ArcGIS ポータルのコンテンツを管理する開発者向けのスキルです。WebMap と WebScene の保存、ブックマークやスライドの管理、ポータル項目とグループの検索・更新を扱います。

主な機能

  1. 01WebMap と WebScene の読み込みと設定
  2. 02マップとシーンのポータル項目への保存
  3. 03ブックマークとシーンスライドの作成・管理
  4. 04ポータル項目とグループの検索・更新
  5. 05ポータルのユーザー情報とフォルダーの取得

活用シーン

  1. 01マップビューをポータル項目として保存
  2. 02スライドでシーンのプレゼンテーションを構成
  3. 03ポータル内の項目の検索と更新

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/saschabrunnerch/arcgis-maps-sdk-js-ai-context --skill arcgis-portal-content

インストール後、Claude Code で/arcgis-portal-contentを入力して読み込まれたか確認します。

詳細

ArcGIS ポータルコンテンツ

マップの保存、ブックマークの管理、スライドの操作、ポータルアイテムの操作、WebMap/WebScene の構造設定には、このスキルを使用します。

インポートパターン

ESM の直接インポート
import WebMap from "@arcgis/core/WebMap.js";
import WebScene from "@arcgis/core/WebScene.js";
import Portal from "@arcgis/core/portal/Portal.js";
import PortalItem from "@arcgis/core/portal/PortalItem.js";
import PortalQueryParams from "@arcgis/core/portal/PortalQueryParams.js";
動的インポート(CDN)
const WebMap = await $arcgis.import("@arcgis/core/WebMap.js");
const Portal = await $arcgis.import("@arcgis/core/portal/Portal.js");
const [PortalItem, PortalQueryParams] = await $arcgis.import([
  "@arcgis/core/portal/PortalItem.js",
  "@arcgis/core/portal/PortalQueryParams.js",
]);

WebMap の構造

WebMap のプロパティ
import WebMap from "@arcgis/core/WebMap.js";

const webMap = new WebMap({
  // From portal item
  portalItem: {
    id: "WEBMAP_ID",
    portal: { url: "https://www.arcgis.com" },
  },
});

// Or create from scratch
const webMap = new WebMap({
  basemap: "topo-vector",
  ground: "world-elevation",
  layers: [featureLayer, graphicsLayer],
  tables: [tableLayer],
  initialViewProperties: {
    center: [-118.805, 34.027],
    zoom: 13,
  },
  bookmarks: [bookmark1, bookmark2],
});
JSON からの WebMap
const webMap = WebMap.fromJSON({
  operationalLayers: [
    {
      id: "layer1",
      layerType: "ArcGISFeatureLayer",
      url: "https://services.arcgis.com/.../FeatureServer/0",
      title: "My Layer",
      visibility: true,
      opacity: 1,
    },
  ],
  baseMap: {
    baseMapLayers: [
      {
        id: "basemap",
        layerType: "VectorTileLayer",
        styleUrl:
          "https://basemaps-api.arcgis.com/arcgis/rest/services/styles/v2/styles/arcgis/topographic",
      },
    ],
    title: "Topographic",
  },
  initialState: {
    viewpoint: {
      targetGeometry: {
        xmin: -118.9,
        ymin: 33.8,
        xmax: -118.1,
        ymax: 34.3,
        spatialReference: { wkid: 4326 },
      },
    },
  },
});

WebScene の構造

import WebScene from "@arcgis/core/WebScene.js";

const webScene = new WebScene({
  portalItem: { id: "WEBSCENE_ID" },
});

// Or create from scratch
const webScene = new WebScene({
  basemap: "satellite",
  ground: "world-elevation",
  layers: [sceneLayer, featureLayer],
  initialViewProperties: {
    viewpoint: {
      camera: {
        position: {
          x: -118.805,
          y: 34.027,
          z: 1500,
          spatialReference: { wkid: 4326 },
        },
        heading: 45,
        tilt: 65,
      },
    },
  },
  presentation: {
    slides: [slide1, slide2],
  },
});
ローカルシーンとグローバルシーン
// Global scene (default)
const globalScene = new WebScene({
  basemap: "satellite",
  ground: "world-elevation",
  viewingMode: "global",
});

// Local scene (with clipping)
const localScene = new WebScene({
  basemap: "satellite",
  ground: "world-elevation",
  viewingMode: "local",
  clippingArea: {
    type: "extent",
    xmin: -118.9,
    ymin: 33.8,
    xmax: -118.1,
    ymax: 34.3,
    spatialReference: { wkid: 4326 },
  },
  clippingEnabled: true,
});

WebMap の保存

新しいアイテムとして保存
const map = new WebMap({
  portalItem: { id: "EXISTING_WEBMAP_ID" },
});

// Update map properties from view before saving
await map.updateFrom(view);

const savedItem = await map.saveAs({
  title: "My New WebMap",
  snippet: "Description of the map",
  tags: ["tag1", "tag2"],
});

console.log(
  "Saved to:",
  savedItem.portal.url + "/home/item.html?id=" + savedItem.id,
);
既存の WebMap を保存
await map.updateFrom(view);
await map.save();
マップコンポーネントの保存例
<arcgis-map item-id="YOUR_WEBMAP_ID">
  <arcgis-zoom slot="top-left"></arcgis-zoom>
</arcgis-map>

<script type="module">
  const viewElement = document.querySelector("arcgis-map");
  await viewElement.viewOnReady();

  document.getElementById("saveBtn").onclick = async () => {
    await viewElement.map.updateFrom(viewElement.view);
    await viewElement.map.save();
  };
</script>

WebScene の保存

const scene = new WebScene({
  portalItem: { id: "EXISTING_WEBSCENE_ID" },
});

await scene.updateFrom(sceneView);
await scene.saveAs({
  title: "My New WebScene",
  snippet: "3D scene description",
});

ブックマーク

ブックマークコンポーネント
<arcgis-map item-id="YOUR_WEBMAP_ID">
  <arcgis-expand slot="top-right" expanded>
    <arcgis-bookmarks
      drag-enabled
      show-add-bookmark-button
      show-edit-bookmark-button
      hide-time
    >
    </arcgis-bookmarks>
  </arcgis-expand>
</arcgis-map>

<script type="module">
  const bookmarks = document.querySelector("arcgis-bookmarks");

  bookmarks.addEventListener("arcgisSelect", (event) => {
    console.log("Selected:", event.detail.bookmark.name);
  });
</script>
プログラムによるブックマークの作成
import Bookmark from "@arcgis/core/webmap/Bookmark.js";

const bookmark = new Bookmark({
  name: "My Location",
  viewpoint: view.viewpoint.clone(),
});

map.bookmarks.add(bookmark);

// Go to bookmark
view.goTo(bookmark.viewpoint);

WebScene のスライド

現在のビューからスライドを作成
import Slide from "@arcgis/core/webscene/Slide.js";

const slide = await Slide.createFrom(sceneView);
slide.title = { text: "Downtown View" };

// Add to presentation
scene.presentation.slides.add(slide);
スライドをビューに適用
const slide = scene.presentation.slides.getItemAt(0);

slide.applyTo(sceneView, {
  maxDuration: 3000,
  easing: "in-out-coast-cubic",
});
スライドを削除
scene.presentation.slides.remove(slide);

ポータルアイテム

ポータルアイテムを読み込む
import PortalItem from "@arcgis/core/portal/PortalItem.js";

const item = new PortalItem({ id: "ITEM_ID" });
await item.load();

console.log("Title:", item.title);
console.log("Type:", item.type);
console.log("Owner:", item.owner);
console.log("Created:", item.created);
ポータルアイテムを検索
import Portal from "@arcgis/core/portal/Portal.js";
import PortalQueryParams from "@arcgis/core/portal/PortalQueryParams.js";

const portal = new Portal({ authMode: "immediate" });
await portal.load();

const queryParams = new PortalQueryParams({
  query: `owner:${portal.user.username} type:"Web Map"`,
  sortField: "modified",
  sortOrder: "desc",
  num: 20,
});

const result = await portal.queryItems(queryParams);
result.results.forEach((item) => {
  console.log(item.title, item.id);
});
ポータルアイテムを更新
const item = new PortalItem({ id: "ITEM_ID" });
await item.load();

item.title = "Updated Title";
item.snippet = "Updated description";
item.tags = ["new", "tags"];

await item.update();

ポータルグループ

グループを検索
const portal = new Portal();
await portal.load();

const groups = await portal.queryGroups({ query: "title:GIS" });
groups.results.forEach((group) => {
  console.log(group.title, group.id);
});
グループのコンテンツを検索
const group = (await portal.queryGroups({ query: `id:GROUP_ID` })).results[0];
const content = await group.queryItems();
content.results.forEach((item) => {
  console.log(item.title);
});

ポータルユーザー情報

const portal = new Portal({ authMode: "immediate" });
await portal.load();

console.log("Username:", portal.user.username);
console.log("Full name:", portal.user.fullName);
console.log("Email:", portal.user.email);
console.log("Role:", portal.user.role);
console.log("Org name:", portal.name);

ポータルフォルダー

import PortalFolder from "@arcgis/core/portal/PortalFolder.js";

// Get user folders
const folders = await portal.user.fetchFolders();
folders.forEach((folder) => {
  console.log(folder.title, folder.id);
});

// Query items in a specific folder
const queryParams = new PortalQueryParams({
  query: `owner:${portal.user.username}`,
  sortField: "modified",
  num: 20,
});
queryParams.folder = folder;

const result = await portal.queryItems(queryParams);

よくある問題

  1. 保存には認証が必要:保存にはユーザー認証が必要です。save() または saveAs() を呼び出す前に、OAuth が設定されていることを確認してください。

  2. 保存前の updateFrom の呼び出し忘れ:現在のビュー状態を取得するため、保存前に必ず updateFrom(view) を呼び出してください。

    // Anti-pattern: saving without updating
    await map.save(); // May save stale viewpoint
    
    // Correct: update from view first
    await map.updateFrom(view);
    await map.save();
    
  3. エンタープライズポータルの URL:エンタープライズポータルでは、ポータル URL を明示する必要があります。

    const portal = new Portal({
      url: "https://your-portal.com/portal",
    });
    
  4. 所有権の制限:更新できるのは、自分が所有するポータルアイテムのみです。自分が所有するコピーを作成するには、saveAs() を使用してください。

  5. スライドのサムネイル:Slide.createFrom() によって自動生成されますが、レンダリングに時間がかかる場合があります。

保存の完全な例

<!DOCTYPE html>
<html>
  <head>
    <script src="https://js.arcgis.com/5.0/"></script>
    <script
      type="module"
      src="https://js.arcgis.com/5.0/map-components/"
    ></script>
    <style>
      html,
      body {
        height: 100%;
        margin: 0;
      }
    </style>
  </head>
  <body>
    <arcgis-map item-id="YOUR_WEBMAP_ID">
      <arcgis-zoom slot="top-left"></arcgis-zoom>
      <arcgis-expand slot="top-right" expanded>
        <arcgis-bookmarks
          drag-enabled
          show-add-bookmark-button
          show-edit-bookmark-button
        >
        </arcgis-bookmarks>
      </arcgis-expand>
    </arcgis-map>

    <script type="module">
      const viewElement = document.querySelector("arcgis-map");
      await viewElement.viewOnReady();

      // Save map on button click
      document.getElementById("saveBtn").onclick = async () => {
        await viewElement.map.updateFrom(viewElement.view);
        await viewElement.map.save();
      };
    </script>
  </body>
</html>

参考サンプル

  • webmap-save - WebMap をポータルに保存
  • webmap-basic - ポータルから WebMap を読み込む
  • webmap-swap - WebMap を切り替える
  • webscene-save - WebScene をポータルに保存
  • webscene-basic - ポータルから WebScene を読み込む
  • webscene-slides - WebScene のスライドを管理
  • webscene-slide-tour - WebScene 内をスライドで巡る
  • bookmarks - マップのブックマークを操作
  • widgets-bookmarks - ブックマークウィジェットの使用
  • basemaps-portal - ポータルからベースマップを読み込む
  • layers-portal - ポータルアイテムからレイヤーを読み込む
  • portalitem-dragndrop - ポータルアイテムをドラッグ&ドロップ

関連スキル

  • OAuth と API キーの設定については、arcgis-authentication を参照してください。
  • マップとビューの作成については、arcgis-core-maps を参照してください。
  • レイヤーの設定については、arcgis-layers を参照してください。

コメント