arcgis api中save map

保存地图

需要引入的模块:

import WebMap from "@arcgis/core/WebMap";

首先声明一个webmap,引入底图

const webmap = new WebMap({
  portalItem: { // autocasts as new PortalItem()
    id: "e691172598f04ea8881cd2a4adaa45ba"
  }
});

官方使用文档:

webmap.updateFrom(view)
  .then(function() {
    return webmap.save();
  })
  // thumbnail will be updated based on current extent of webmap
  .then(function(portalItem) {
    console.log("Saved to portal", portalItem.id);
  })
  .catch(function(error) {
    console.error("Error saving to portal", error);
  });

实际使用过程中,保存之后提示保存结果

map.updateFrom(view).then(function(){
              map.saveAs(item)
              // Saved successfully
              .then(function(item) {
                // 设置存储位置
                var itemPageUrl = item.portal.url + "/home/item.html?id=" + item.id;
                var link = '<a target="_blank" href="' + itemPageUrl + '">' + title.value + </a>";
//弹窗提示成功信息,并给出存储链接
                statusMessage("Save WebMap", "<br>Successfully saved as <i>"+link + </i>"
                );
              })
              // Save didn't work correctly
              .catch(function(error) {
//弹窗提示错误信息
                statusMessage("Save WebMap", "<br> Error " + error);
              });
            });

保存三维地图:

// Update properties of the WebScene related to the view.
            // This should be called just before saving a webscene.
            scene.updateFrom(view).then(() => {
              scene
                .saveAs(item)
                // Saved successfully
                .then((item) => {
                  // link to the newly-created web scene item
                  const itemPageUrl = item.portal.url + "/home/item.html?id=" + item.id;
                  const link = '<a target="_blank" href="' + itemPageUrl + '">' + title.value + "</a>";

                  statusMessage("Save WebScene", "<br> Successfully saved as <i>" + link + "</i>");
                })
                // Save didn't work correctly
                .catch((error) => {
                  statusMessage("Save WebScene", "<br> Error " + error);
                });
            });

webmap.updateFrom(view)

  .then(function() {

    return webmap.save();

  })

  // thumbnail will be updated based on current extent of webmap

  .then(function(portalItem) {

    console.log("Saved to portal", portalItem.id);

  })

  .catch(function(error) {

    console.error("Error saving to portal", error);

  });

原文地址:https://www.cnblogs.com/1gaoyu/p/15167606.html