arcgis javascript api4.x加载非公开或者私有的arcgis地图服务

需求:

加载arcgis没有公开或者私有的地图服务,同时还想实现加载时不弹出登录窗口

提示:​

下述是针对独立的arcgis server,没有portal的应用场景;

如果有portal可以参考链接:https://mp.weixin.qq.com/s/WB09URxnPkaW9RvjHqAoSg

补充:

如果按照下述代码还弹窗,请确保通信协议保持统一,例如都使用https后者http

代码:

html 复制代码
<html>
  <head>
    <meta charset="utf-8" />
    <meta
      name="viewport"
      content="initial-scale=1, maximum-scale=1, user-scalable=no"
    />
    <title>hello</title>
    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>
    <link
      rel="stylesheet"
      href="https://js.arcgis.com/4.27/esri/themes/light/main.css"
    />
    <script src="https://js.arcgis.com/4.27/"></script>
    <script>
      require([
        "esri/config",
        "esri/WebMap",
        "esri/views/MapView",
        "esri/layers/FeatureLayer",
        "esri/identity/IdentityManager",
        "esri/identity/ServerInfo",
      ], function (
        esriConfig,
        Map,
        MapView,
        FeatureLayer,
        IdentityManager,
        ServerInfo
      ) {
        let serverInfo = new ServerInfo({
          hasServer: true,
          server: "https://192.168.17.138:6443/arcgis/rest/services",
          tokenServiceUrl:
            "https://192.168.17.138:6443/arcgis/tokens/generateToken",
        
        });
        let userInfo = {
          username: "siteadmin",
          password: "arcgis123",
        };
        IdentityManager.generateToken(serverInfo, userInfo).then(
          (res) => {
            console.log(res);
            IdentityManager.registerToken({
              server: "https://192.168.17.138:6443/arcgis/rest/services",
              token: res.token,
            });

            let layer = new FeatureLayer({
              url: "https://192.168.17.138:6443/arcgis/rest/services/china/MapServer/0",
            });

            const map = new Map({
              layers: [layer],
            });

            const view = new MapView({
              map: map,
              container: "viewDiv",
            });

            view.when(function () {
              view.extent = layer.fullExtent;
            });
          },
          (error) => {
            console.error(error);
          }
        );
      });
    </script>
  </head>
  <body>
    <div id="viewDiv"></div>
  </body>
</html>

参考资料:

arcgis中基于token访问私有服务

相关推荐
他们都不看好你,偏偏你最不争气8 分钟前
【iOS】UIViewController
开发语言·macos·ios·objective-c·cocoa
Pocker_Spades_A18 分钟前
Python快速入门专业版(二十二):if语句进阶:嵌套if与条件表达式(简洁写法技巧)
开发语言·python
ホロHoro19 分钟前
学习笔记:JavaScript(4)——DOM节点
javascript·笔记·学习
看海的四叔31 分钟前
【Python】Python解决阿里云DataWorks导出数据1万条限制的问题
开发语言·python·阿里云·dataworks·maxcomputer
吾日三省吾码31 分钟前
用 Python UTCP 直调 HTTP、CLI、MCP……
开发语言·python·http
zcz16071278211 小时前
LVS + Keepalived 高可用负载均衡集群
java·开发语言·算法
一只小风华~1 小时前
Vue: ref、reactive、shallowRef、shallowReactive
前端·javascript·vue.js
Bellafu6661 小时前
项目中遇到pom文件里使用systemPath的例子记录
开发语言
爱喝水的鱼丶2 小时前
SAP-MM:SAP采购组织全面学习指南:从概念到实战配置图解
运维·开发语言·数据库·学习·sap·mm模块·采购组织
楼田莉子2 小时前
Python学习——字典和文件
开发语言·python·学习·pycharm