1,使用new对象的默认的方法
点
const pointGeometry = new Point({
longitude:-118.29026,
latitude:34.1816
});
const pointSymbol = new SimpleMarkerSymbol({
color: [226, 119, 40],
outline: {
color: [255, 255, 255],
width: 1
}
})
线
const lineGeometry = new Polyline({
paths: [
[-118.29026, 34.1816],
[-118.26451, 34.09664]
]
});
const lineSymbol = new SimpleLineSymbol({
color: [226, 119, 40],
width: 2
});
面
var polygonGeometry = new Polygon({
rings: [
[-118.27653, 34.15121],
[-118.2446, 34.15462],
[-118.22915, 34.14439],
[-118.23327, 34.12279],
[-118.25318, 34.10972],
[-118.26486, 34.11625],
[-118.27653, 34.15121]
]
});
var fillSymbol = new SimpleFillSymbol({
color: [227, 139, 79, 0.8],
outline: {
color: [255, 255, 255],
width: 1
}
});
2,使用其它的方式
export default {
methods: {
createPointGeometry(longitude, latitude) {
// 创建点 Geometry new Point()
return {
type: 'point',
longitude,
latitude
}
},
createPointSymbol(color, style = 'circle', size, outlineColor, outlineWidth) {
// 绘制点 Symbol
return {
type: "simple-marker",
style, // "circle"|"square"|"cross"|"x"|"diamond"|"triangle"|"path"
color,
size,
outline: {
color: outlineColor,
width: outlineWidth
}
};
},
createPictureMarkerSymbol(url, width, height) {
// 绘制点图标 Symbol
return {
type: "picture-marker",
url, width, height
};
},
createPolylineGeometry(paths) {
// 创建线 Geometry new Polyline()
return {
type: 'polyline',
paths
}
},
createSimpleLineSymbol(color, width = 2, style = 'solid') {
// 创建线 simpleLineSymbol
return {
type: 'simple-line',
color, width,
style // "dash"|"dash-dot"|"dot"|"long-dash"|"long-dash-dot"|
// "long-dash-dot-dot"|"none"|"short-dash"|"short-dash-dot"
// |"short-dash-dot-dot"|"short-dot"|"solid"
}
},
createFillGeometry(rings = []) {
// 创建图形 polygon new Polygon()
return {
type: 'polygon',
rings
}
},
createFillSymbol(color, style = 'solid', width, outlineColor) {
// 绘制图形Symbol
return {
type: "simple-fill",
style, // "backward-diagonal"|"cross"|"diagonal-cross"
//|"forward-diagonal"|"horizontal"|"none"|"solid"|"vertical"
color,
outline: {
color: outlineColor,
width
}
};
},
createToScreenGeometry(x, y) {
// 创建 mapView.toScreen(geometry) 中的点geometry,用于屏幕定位
return {
x, y,
spatialReference: {
wkid: 4326
}
}
}
}
}