promise.then()问题
本帖最后由 冷回清风暖 于 2021-1-2 09:07 编辑有个错误搞不懂{:5_102:}
55-63行
view_2d = new MapView({
map: webmap,
container: "viewDiv_2d"
}).then(function(){
view_2d.watch("extent",function(response){
if(response){
view_3d.center =response.center;
}
});
});
提示:(index):19 Uncaught TypeError: (intermediate value).then is not a function
代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="initial-scale=1,maximum-scale=1,user-scalable=no">
<title>Integrate 2D and 3D Views</title>
<link rel="stylesheet" href="https://js.arcgis.com/4.7/esri/css/main.css">
<script src="https://js.arcgis.com/4.7/"></script>
<style>
html,
body {
padding: 0;
margin: 0;
height: 100%;
width: 100%;
}
#viewDiv_2d {
float: left;
height: 100%;
width: 49.9%;
}
#viewDiv_3d {
float: right;
height: 100%;
width: 49.9%;
}
</style>
<script>
require([
"esri/views/MapView",
"esri/views/SceneView",
"esri/WebMap",
"esri/WebScene",
"dojo/domReady!"
],
function(
MapView, SceneView, WebMap, WebScene
) {
var view_2d,view_3d;
create_2dView();
create_3dView();
function create_2dView() {
var webmap = new WebMap({
portalItem: {
id: "08656515afaf4d0587d4f99b9909ddfc"
}
});
view_2d = new MapView({
map: webmap,
container: "viewDiv_2d"
}).then(function(){
view_2d.watch("extent",function(response){
if(response){
view_3d.center =response.center;
}
});
});
}
function create_3dView() {
var scene = new WebScene({
portalItem: {
id: "ae2631226f9b4883942a1d2423e29772"
}
});
view_3d = new SceneView({
map: scene,
container: "viewDiv_3d"
})
}
});
</script>
</head>
<body>
<div id="viewDiv_2d"></div>
<div id="viewDiv_3d"></div>
</body>
</html> 帮顶一下,来个大佬解答一下啊{:10_254:} 报错不是说了吗,.then()不是个函数,说明你前面的函数原型上没有.then方法 你把这个类实例出来的对象打印出来看看,看值是不是 Promise
new MapView({
map: webmap,
container: "viewDiv_2d"
}) 蹭热度 帮顶下{:10_257:} {:10_254:} 帮忙顶一下{:10_266:} 萌新躲在角落瑟瑟发抖! {:10_266:} 也不懂,蹭学 顶 顶 {:10_257:} {:7_141:} 不懂帮顶 顶
页:
[1]