1

I am a newbie in ArcGIS, but I want to learn about it. So I have a problem with this. I want to put ArcGIS data from an API into Google Map. I have made it in Laravel 5.7 and javascript. But I got an error Unauthorized like the image below

enter image description here

This is my javascript in view blade laravel :

 <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>

The error is for authentication, I must put username and password right? but I don't know how to put the authentication for username and password in the code. Anyone can help me?

1 Answer 1

0

You can use a proxy page to access secured rest services with ESRI's API:

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

Github repo: https://github.com/Esri/resource-proxy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.