尝试添加在地址上显示标记的地图。因此,我首先使用“定位器”来获取地址的经度和纬度,然后创建地图和以地址坐标为中心的视图。然后,我绘制一个点和一个确定区域的多边形,以检查地址是否在该区域内。它工作正常,但在控制台中显示以下消息:“帧缓冲区不完整!”这是代码:
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">
<title>ArcGIS JavaScript show address in map</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.13/esri/css/main.css">
<script src="https://js.arcgis.com/4.13/"></script>
<script>
require([
"esri/Map",
"esri/views/MapView",
"esri/tasks/Locator",
"esri/Graphic",
"dojo/domReady!"
], function(Map, MapView, Locator, Graphic) {
var locatorTask = new Locator({
url: "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"
});
let addressParams1 = {
Address: "carrer Girona 9",
City: "Tarragona",
Postcode: "43003",
State: "Tarragona",
Country: "Spain"
}
locatorTask.addressToLocations({address:addressParams1})
.then(function(response){
let x = response[0].location.x;
let y = response[0].location.y;
var addr = response[0].address;
document.getElementById("response").innerHTML = addr;
var map = new Map({
basemap: "streets"
});
var view = new MapView({
container: "viewDiv",
map: map,
center: [x, y], // longitude, latitude
zoom: 17
});
drawPoint(x, y, view);
let rings = [
[1.2479, 41.1179],
[1.257, 41.1135],
[1.2576, 41.11367],
[1.258, 41.11386],
[1.25812, 41.114],
[1.25812, 41.1141],
[1.258, 41.11418],
[1.2577, 41.1144],
[1.25762, 41.1148],
[1.25759, 41.1152],
[1.2575, 41.11535],
[1.257, 41.1155],
[1.25645, 41.11576],
[1.25675, 41.11615],
[1.2569, 41.1163],
[1.25758, 41.11659],
[1.2546, 41.11806],
[1.255, 41.11843],
[1.25367, 41.11944],
[1.25115, 41.1179],
[1.24857, 41.11854],
[1.2479, 41.1179]
];
drawPolygon(rings, view);
})
.catch(function(error) {console.error(error)});
function drawPolygon(rings, view){
let pl = {
type: "polygon",
rings: rings
};
let sl = {
type: "simple-fill",
// style: "none",
color: [0, 0, 255, 0.1],
outline: {
width: 5,
join: "round",
style: "short-dot", //solid
color: "darkblue"
}
};
let graphpl = new Graphic({geometry: pl, symbol: sl});
view.graphics.add(graphpl);
}
function drawPoint(x, y, view){
//Draw point
let p = {
type: "point",
longitude: x,
latitude: y
};
let s = {
type: "simple-marker",
color: [255, 0, 5, 0.6],
size: 9
};
let graphic = new Graphic({geometry: p, symbol: s});
view.graphics.add(graphic);
}
});
</script>
</head>
<body>
<div id="viewDiv" style="width:500px; height:400px">
</div>
<div id="response">
</div>
</body>
</html>
此消息的来源是什么?我必须使用图层吗?预先感谢。
这是一个webGL错误。 ESRI使用webGL在4.x上进行渲染。我无法重现该错误,因此我猜测它可能与生命周期有关,并且我的客户端执行得更快/更慢。
如果您可以确定webGL在范围内并设置断点,则可以尝试在控制台中执行glGetError()。
我还将尝试通过从mapView .when回调函数中执行其他代码来确保完全初始化mapView。 webGL可能试图绑定到尚未实例化的内容。
可以调用MapView实例上的.when()方法来执行仅在加载地图后才能运行的过程。
https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html