首页 > 解决方案 > 未经授权的 API Arcgis 到 laravel 中的谷歌地图

问题描述

我是 ArcGIS 的新手,但我想了解它。所以我有这个问题。我想将来自 API 的 ArcGIS 数据放入 Google Map。我已经在 Laravel 5.7 和 javascript 中做到了。但我得到一个错误未经授权,如下图所示

在此处输入图像描述

这是我在视图刀片 laravel 中的 javascript:

 <div id="map">

  </div>
    <script>
      var map;
      const TILE_ORIGIN = [-20037508.34789244, 20037508.34789244];
      const ORIG_X = 1;
      const ORIG_Y = 0;
      const MAP_SIZE = 20037508.34789244 * 2;
      const MINX = 0;
      const MAXX = 1;
      const MINY = 2;
      const MAXY = 3;

      function getBoundingBox(x, y, zoom){
         tileSize = MAP_SIZE / Math.pow(2, zoom);
         minx = TILE_ORIGIN[ORIG_X] + x * tileSize;
         maxx = TILE_ORIGIN[ORIG_X] + (x+1) * tileSize;
         miny = TILE_ORIGIN[ORIG_Y] - (y+1) * tileSize;
         maxy = TILE_ORIGIN[ORIG_Y] - y * tileSize;

         bbox = [minx, miny, maxx, maxy];


        return bbox;
      }
      function initMap() {
        map = new google.maps.Map(document.getElementById('map'), {
          center: {lat: -6.160323, lng: 106.905114},
          zoom: 18
        });

        var imageMapType = new google.maps.ImageMapType({
        getTileUrl: function(coord, zoom) {
          resultBBox = getBoundingBox(coord.x, coord.y,  zoom);
          url = "http://xx.xx.x.xx/arcgis/services/Asset/AssetMAP_Mobile/MapServer/WmsServer?LAYERS=1,2,3,4,5&TILED=true&TRANSPARENT=TRUE&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&FORMAT=image/png&SRS=EPSG:3857&BBOX="+resultBBox[MINX]+","+resultBBox[MINY]+","+resultBBox[MAXX]+","+resultBBox[MAXY]+"&WIDTH=256&HEIGHT=256" ; //API
          console.log(url);

              return url;

            },

                tileSize: new google.maps.Size(256, 256)
        });
        map.overlayMapTypes.push(imageMapType);
      }
    </script>
    <script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBu5nZKbeK-WHQ70oqOWo-_4VmwOwKP9YQ&callback=initMap"
    async defer></script>

错误是用于身份验证,我必须输入用户名和密码吗?但我不知道如何将用户名和密码的身份验证放在代码中。任何人都可以帮助我吗?

标签: javascriptgoogle-mapslaravel-5arcgisarcgis-server

解决方案


您可以使用代理页面通过 ESRI 的 API 访问安全的休息服务:

信息: https ://developers.arcgis.com/javascript/3/jshelp/ags_proxy.html

Github 仓库: https ://github.com/Esri/resource-proxy


推荐阅读