如何消除 javascript 中的控制台错误
How can I get rid of a console error in javascript
正在尝试添加显示地址标记的地图。
所以我首先使用定位器获取地址的经度和纬度,然后创建以地址坐标为中心的地图和视图。然后我绘制确定区域的点和多边形以检查地址是否在区域内。
它工作正常,但它在控制台中显示此消息:
"Framebuffer is incomplete!"
这是代码:
<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 进行渲染。我无法重现该错误,所以我猜测它可能依赖于生命周期并且我的客户端执行 faster/slower。
如果您可以确定 webGL 何时在范围内并设置断点,您可以尝试在控制台中执行 glGetError()。
我还会尝试通过从 mapView.when 回调函数中执行其他代码来确保 mapView 已完全初始化。可能是 webGL 试图绑定到尚未实例化的东西。
可以调用 MapView 实例上的 .when() 方法来执行只能在地图加载后 运行 的进程。
https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html
正在尝试添加显示地址标记的地图。 所以我首先使用定位器获取地址的经度和纬度,然后创建以地址坐标为中心的地图和视图。然后我绘制确定区域的点和多边形以检查地址是否在区域内。 它工作正常,但它在控制台中显示此消息: "Framebuffer is incomplete!" 这是代码:
<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 进行渲染。我无法重现该错误,所以我猜测它可能依赖于生命周期并且我的客户端执行 faster/slower。
如果您可以确定 webGL 何时在范围内并设置断点,您可以尝试在控制台中执行 glGetError()。
我还会尝试通过从 mapView.when 回调函数中执行其他代码来确保 mapView 已完全初始化。可能是 webGL 试图绑定到尚未实例化的东西。
可以调用 MapView 实例上的.when() 方法来执行只能在地图加载后 运行 的进程。
https://developers.arcgis.com/javascript/latest/api-reference/esri-views-MapView.html