拿到矢量坐标数组,可以通过geoserver发布的图层数据,比如geojson
// 这里的result就是矢量数组
goto(result, name) {
// console.log(result, name);
result.forEach((item) => {
if (item.properties.Name === name) {
// 要定位的位置的坐标集合
const coordinates = item.geometry.coordinates[0];
// console.log("coordinates", coordinates);
// 通过geometry.coordinates绘制,在地图上高亮显示
let options = {
url: "https://js.arcgis.com/4.26/",
css: "https://js.arcgis.com/4.26/esri/themes/light/main.css",
};
loadModules(
["esri/Graphic", "esri/layers/GraphicsLayer"],
options
).then(([Graphic, GraphicsLayer]) => {
this.clearLayerTemporarily();
const graphicsLayer = new GraphicsLayer();
this.map.add(graphicsLayer);
const polyline = {
type: "polyline",
paths: [coordinates],
};
const simpleFillSymbol = {
type: "simple-fill",
color: [255, 255, 255, 0],
outline: {
color: [0, 255, 255],
width: 2,
},
};
const polylineGraphic = new Graphic({
geometry: polyline,
symbol: simpleFillSymbol,
});
graphicsLayer.add(polylineGraphic);
// 临时图层
this.layer_temporarily = graphicsLayer;
this.layer_temporarily_list.push(graphicsLayer);
});
// 计算中心点
var x = 0,
y = 0;
coordinates.forEach((item) => {
x += item[0];
y += item[1];
});
// 跳转
this.view.goTo({
target: [
parseFloat(x / coordinates.length),
parseFloat(y / coordinates.length),
],
heading: 180,
duration: 2000,
});
}
});
},