一、引用
使用Vue+arcgis4.18
怎么使用map我就不多说了,自己去官网看
import Point from "@arcgis/core/geometry/Point";
import GraphicsLayer from "@arcgis/core/layers/GraphicsLayer";
二、Graphics
为什么先写Graphics,因为Graphics可以挂(个人的理解)在GraphicsLayer上
1,属性
其实不搞那些花里胡哨的只需要
var polylineGraphic = new Graphic({
geometry: polyline,
symbol: polylineSymbol,
attributes: polylineAtt
});
- geometry
type:不需要太在意
说明它是条线
var polyline = {
type: "polyline", // autocasts as new Polyline()
paths: [
[-111.30, 52.68],
[-98, 49.5],
[-93.94, 29.89]
]
};
- symbol
type:也是个对象
主要是设置这条线的样式
var polylineSymbol = {
type: "simple-line", // autocasts as SimpleLineSymbol()
color: [226, 119, 40],
width: 4
};
- attributes
属性,不做介绍,暂时没用到过
var polylineAtt = {
Name: "Keystone Pipeline",
Owner: "TransCanada"
};
- popupTemplate,点击或者其他触发方式显示信息框
- 其他自测
2,方法
暂不介绍
有可能之后都不会介绍
三、GraphicsLayer
百度翻译:图形杀手,我呸
// Create graphics
var graphicA = new Graphic({ // graphic with line geometry
geometry: new Polyline({...}), // set geometry here
symbol: new SimpleLineSymbol({...}) // set symbol here
});
var graphicB = new Graphic({ // graphic with point geometry
geometry: new Point({...}), // set geometry here
symbol: new SimpleMarkerSymbol({...}) // set symbol here
});
var graphicC = new Graphic({ // graphic with polygon geometry
geometry: new Polygon({...}), // set geometry here
symbol: new SimpleFillSymbol({...}) // set symbol here
});
var graphicD = new Graphic();
var graphicE = new Graphic();
// Add graphic when GraphicsLayer is constructed
var layer = new GraphicsLayer({
graphics: [graphicA]
});
// Add graphic to graphics collection
layer.graphics.add(graphicB);
// Add graphic using add()
layer.add(graphicC);
layer.addMany([graphicD, graphicE]);
// Add graphics using push method graphics collection
layer.graphics.push(graphic1, graphic2);
// Add GraphicsLayer to map
map.add(layer);
});
1,属性
有点多,我就不截屏了
2,方法
有点多,我就不截屏了
主要就是add【添加】、addMany【添加多个】、remove、removeAll、removeMany
3,注意事项
官网有这么一句话:在处理客户端图形时,通常首选使用其source属性构造一个featurellayer,因为featurellayer比GraphicsLayer有更多的功能,包括渲染、查询和标记。
也就是说你自己想创建一个图层,如果后续需要渲染、查询和标记,那么GraphicsLayer不支持这些功能,建议使用featurellayer,因为是客户端处理,所以featurellayer也支持客户端创建。