cellsysBase/cellsysLayer.js

167 lines
4.8 KiB
JavaScript
Raw Normal View History

2024-08-14 16:20:56 +08:00
import { Query, CellsysType, QueryType, QueryTask, Operator } from './cellsysUtil.js';
import CellsysMark from './cellsysMark';
import CellsysLine from './cellsysLine';
import CellsysPolygon from './cellsysPolygon';
import { hexColorToRgba } from './utils/utils';
class CellsysLayer {
constructor(params) {
this.cellsysType = CellsysType.Layer;
if (!params) {
params = {};
}
this.orgId = params.org_id;
this.id = params.id;
this.layerId = params.layer_id;
this.layerType = params.layer_type;
this.layerName = params.name || params.layer_name;
this.description = params.description;
this.geometryType = params.geometry_type; //点线面类型
this.style = params.style;
this.type = params.type ? params.type : 1; //geoJson类型
this.dataApi = params.data_api;
this.dataParam = params.data_param;
this.legendOrder = params.legend_order;
this.layerResId = params.layer_res_id;
this.createBy = params.create_by;
}
setId(value) {
this.id = value;
}
setName(value) {
this.layerName = value;
}
setDescription(value) {
this.description = value;
}
setGeometryType(value) {
this.geometryType = value;
}
setDataApi(value) {
this.dataApi = value;
}
setType(value) {
this.type = value;
}
setStyle(value) {
this.style = value;
}
setDataParam(value) {
this.dataParam = value;
}
setDataUrl(value) {
this.dataUrl = value;
}
setLegendOrder(value) {
this.legendOrder = value;
}
setLayerResId(value) {
this.layerResId = value;
}
getIcon() {
return this.style ? this.style.icon : null;
}
getColor() {
return this.style ? this.style.color : null;
}
getFillColor() {
return this.style ? this.style.fillColor : null;
}
getCssStyle() {
let style = this.style;
if (this.geometryType === 1) {
if (style) {
return {
'border-color': style.strokeColor || null,
opacity: style.strokeOpacity || null,
'border-top-width': (style.weight || 0) + 'px',
'border-top-style': style.dashArray == '10,10' ? 'dashed' : 'solid',
cursor: 'text',
};
}
return null;
} else if (this.geometryType === 2) {
if (style) {
let strokeOpacity = style.strokeOpacity;
strokeOpacity =
strokeOpacity === null || strokeOpacity === undefined ? 0 : strokeOpacity;
let colors = hexColorToRgba(style.strokeColor || '#000000');
colors.push(strokeOpacity);
let border = style.weight + 'px ' + 'solid rgba(' + colors.join(',') + ')';
let fillOpacity = style.fillOpacity;
fillOpacity = fillOpacity === null || fillOpacity === undefined ? 0 : fillOpacity;
let colors2 = hexColorToRgba(style.fillColor || '#000000');
colors2.push(fillOpacity);
let backgroundColor = 'rgba(' + colors2.join(',') + ')';
return {
border: border,
'background-color': backgroundColor,
cursor: 'text',
};
}
return null;
}
return null;
}
//查询图层关联的要素
queryElements() {
let query = new Query();
let queryType = QueryType.Marker;
switch (this.geometryType) {
case 0:
queryType = QueryType.Marker;
break;
case 1:
queryType = QueryType.Line;
break;
case 2:
queryType = QueryType.Polygon;
break;
}
let queryTask = new QueryTask(queryType);
let typeId = this.dataParam.type;
query.addFilter('type', Operator.Equals, typeId);
return new Promise((resolve, reject) => {
queryTask
.execute(query)
.then((res) => {
let resArr = res.map((item) => {
switch (this.geometryType) {
case 0:
return new CellsysMark(item);
case 1:
return new CellsysLine(item);
case 2:
return new CellsysPolygon(item);
}
});
resolve(resArr);
})
.catch((err) => {
reject(err);
});
});
}
}
export default CellsysLayer;