根据唯一值查询到要定位查看的图斑,goTo实现定位。注意点和线面的区别
esriLoader.loadModules(["esri/tasks/support/Query","esri/Graphic"])
.then(([Query,Graphic])=>{
const query=new Query();
query.where= "GUID = '"+id +"'";
_this.map.layers.items[layerIndex].queryFeatures(query).then(function(results){
if(layerindex!==0){
_this.view.goTo(results.features[0].geometry.extent.expand(1)).then(function () {
_this.view.graphics.removeAll();
let addGraphic = new Graphic({
geometry:results.features[0].geometry,
symbol: {
type: "simple-fill",
color: [226, 119, 40,0.1],
style: "solid",
outline: {
color: "red",
width: 1
}
},
// attributes: _this.formdata
});
_this.view.graphics.add(addGraphic);
});
}else{
_this.view.goTo({target:results.features[0].geometry,zoom:5},{duration: 1000}).then(function () {//放点坐标不行放geometry
_this.view.graphics.removeAll();console.log(layerIndex);
let addGraphic = new Graphic({
geometry:results.features[0].geometry,//放new点不行放geometry
symbol: {
type: "simple-marker",
color: [226, 119, 40]
}
});
_this.view.graphics.add(addGraphic);
});
}
})
})
2.goTo简介
3.goTo
goTo方法的参数可以是两个或一个。当只有一个参数时,是一个数组;当是两个参数时,第一个参数是数组(一维或二维)或对象或某个图层的graphics,第二个参数是duration。
示例:
view.goTo([112.6, 22.542])
------------------------------------------
mapView.goTo([113.6042903, 22.5501197], {
duration: 2000 //视角跳转时长为2秒
})
---------------------------------------------
mapView.goTo([
[113.59764, 22.49856],
[113.59513, 22.50922],
[113.60482, 22.51036],
[113.60669, 22.49959],
[113.59764, 22.49856]
], {
duration: 2000
});
---------------------------------------------
mapView.goTo({
target: [113.60389, 22.54591],
zoom: 13,
heading: 48,
tilt: 40
}, {
duration: 2000, //视角跳转时长为2秒,
}).then(function () {
// console.log("跳转完成");
})
-------------------------------------------------
mapView.goTo(videoPointLayer.graphics, {
duration: 2000 //视角跳转时长为2秒
})
//可以使用定时器创建连续的动画: goTo返回一个承诺,该承诺在动画完成时解决。这个承诺可能会被链接以创建一系列动画。
view.goTo([112.6, 22.542])
.then(function() {
return view.goTo([113.6, 25.542]);
})
.then(function() {
return view.goTo([113.6, 22.542]);
});
点击,回到初始化位置以及视角:
backToOldVisualAngle() {
var mapView = global.mapView;
mapView.goTo({
target: [113.60389, 22.54591],
zoom: 13,
heading: 48,
tilt: 40
}, {
duration: 2000, //视角跳转时长为2秒,
}).then(function () {
// console.log("跳转完成");
})
},
//扶正视角,但是不回到初始位置:
backToOldVisualAngle() {
var mapView = global.mapView;
mapView.goTo({
zoom: 13,
heading: 48,
tilt: 40
}, {
duration: 2000, //视角跳转时长为2秒,
}).then(function () {
// console.log("跳转完成");
})
},
target: [113.6, 22.542], 可以换为
center: {
x: 113.6,
y: 22.542,
spatialReference: {wkid: 4490}
},
//并添加参考系属性
view.when(function () {
view.goTo({
// target: [113.6, 22.542],
center: {
x: 113.6,
y: 22.542,
spatialReference: {wkid: 4490}
},
zoom: 13,
heading: 80, // 旋转角
tilt: 30 // 倾斜角
}, {
duration: 2000 // 视角跳转时长为2秒,
})
})