ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

再谈arcgis portal的CORS

2022-02-17 11:01:38  阅读:199  来源: 互联网

标签:arcgis proxyUrl portal proxy https CORS com


CORS, Cross Origin Resource Sharing,跨域资源共享。

ArcGIS API for javascript一直支持CORS,如果你用的 Web服务器支持CORS的话,那就不需要代理来执行跨域请求。

官方:如果 Web 服务器上未启用 CORS,则需要代理来绕过这些资源的安全性。但显然IIS 也可以启用CORS 。

如果服务是使用ArcgGIS Server发布的,则api会自动发送请求以查看是否支持CORS。可以打开自己的server看一下:

http://10.45.204.xx8:6080/arcgis/admin/login,使用用户密码登录,可以看到

如果安装的托管ArcGIS Portal联合的 arcgis server:

 

 

 

设置为所有人(公开)就没有弹登录窗口。私有的话应该也可以通过token来解决: https://blog.csdn.net/qq_40376439/article/details/104260652

但是引用Portal 的webmap(portal的地理信息交互显示,可以包含底图,图层,范围,图例,导航工具缩放平移查地点书签)

 

但在web场景展示中,前端加载大量的数据,模型数据,超过浏览器限定级别了,要设置代理(请求超过2048字符,一般是用一个多边形作为输入参数的时候一般都容易超过)

在官网里搜proxy pages with the API ,这里https://developers.arcgis.com/javascript/latest/proxies/

据说可以通过配置代理,不使用openssl,不使用token来避免登录,但没有成功:

        // esriConfig.request.proxyUrl='/proxy/proxy.ashx'
        // esriConfig.proxyUrl='https://portal.valu.com/arcgis'
        // esriConfig.request.forceProxy = true;
        

        urlUtils.addProxyRule({
            urlPrefix: "https://portal.valu.com/arcgis/sharing/rest",
            proxyUrl: "/proxy/proxy.ashx"
        },
        {
            urlPrefix: "https://portal.valu.com/server/rest/services",
            proxyUrl: "/proxy/proxy.ashx"
        });

配置赛程

 ESRI在 github上有个项目代码,用于代理方式解决跨域问题

proxy目录解压到iis 下,配置映射

 

 如遇到 模块列表中必须要有IsapiModule或cgiModule 类似错误,则在控制面板 -> 程序和功能 -> 打开或关闭Windows功能(这几步可以简化为Win+R运行OptionalFeatures) -> Internet信息服务 -> 万维网服务 -> 应用程序开发功能,把cgi ,asp.net等勾选,安装即可解决。

 

 

 

 测试代码:

<html>
  <head>
    <meta charset="utf-8" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no" />
    <title>ArcGIS API</title>

    <style>
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }
    </style>

    <link rel="stylesheet" href="https://js.arcgis.com/4.18/esri/themes/light/main.css">
    <script src="https://js.arcgis.com/4.18/"></script>

    <script>
      require([
          "esri/config",
          "esri/views/SceneView",
          "esri/WebScene",
          "esri/webscene/Slide",
          "esri/layers/FeatureLayer",
          "esri/WebMap",
          "esri/views/MapView",
          "esri/core/urlUtils"
    ], function (esriConfig,SceneView, WebScene,Slide, FeatureLayer,WebMap,MapView,urlUtils) {

        // esriConfig.request.proxyUrl='/proxy/proxy.ashx'
        // esriConfig.proxyUrl='https://portal.valu.com/arcgis'
        // esriConfig.request.forceProxy = true;
        

        urlUtils.addProxyRule({
            urlPrefix: "https://portal.valu.com/arcgis/sharing/rest",
            proxyUrl: "/proxy/proxy.ashx"
        },
        {
            urlPrefix: "https://portal.valu.com/server/rest/services",
            proxyUrl: "/proxy/proxy.ashx"
        });
        //小区面
        const commLayer = new FeatureLayer("http://10.45.204.xx8:6080/arcgis/rest/services/base2/MapServer/53",{
            mode: FeatureLayer.MODE_SNAPSHOT, 
            outFields: ["*"]         
        });

        var webmap = new WebMap({
            portalItem:{
                id:'301f3e422db6465a974xx8a28d94',
                portal:"https://portal.valu.com/arcgis" 
            }
        });

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

        // 如果是场景
        // var scene=new WebScene({
        //     portalItem:{
        //         id:'301f3e422db646xx0ce8a28d94',
        //         portal:"https://portal.valu.com/arcgis" 
        //     }
        // });
        // const view = new SceneView({
        //     map: scene,
        //     container: "viewDiv",
        // });
      });
    </script>

  </head>
  <body>
    <div id="viewDiv"></div>
  </body>
</html>

 

总之,我的代理没有配置成功

标签:arcgis,proxyUrl,portal,proxy,https,CORS,com
来源: https://www.cnblogs.com/yansc/p/15903640.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有