javascript - 未经授权的 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>
错误是用于身份验证,我必须输入用户名和密码吗?但我不知道如何将用户名和密码的身份验证放在代码中。任何人都可以帮助我吗?
解决方案
您可以使用代理页面通过 ESRI 的 API 访问安全的休息服务:
信息: https ://developers.arcgis.com/javascript/3/jshelp/ags_proxy.html
Github 仓库: https ://github.com/Esri/resource-proxy
推荐阅读
- javascript - 在使用 ReactJS 发送到 API 之前翻转 Base64 图像
- python - 嗨,我可以向 Visual Studio 寻求帮助,因为它没有显示结果
- database - 有没有办法从>给定日期备份数据库,然后继续使用从给定日期到现在存在的数据库?谢谢
- oracle - ORACLE Forms (WHEN-BUTTON-PRESSED) 事件问题
- r - 如何在一列中设置一行中某个值以下几列的数据个数?
- java - 向 Mongo db 集合插入多个用户输入值时出现异常
- python - 无法在 PyCharm 中运行子进程
- scala - 是否可以在 OIDC 或 OpenAuth2.0 的身份验证提供程序前面添加代理?
- javascript - 在 JavaScript 中添加命名空间会导致意外的令牌“。” 错误
- html - Django使用对象ID重定向?