@antv/l7-layers 2.9.12 → 2.9.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/line/index.d.ts +1 -1
- package/es/line/index.js +2 -1
- package/es/line/index.js.map +1 -1
- package/es/line/models/half.d.ts +18 -0
- package/es/line/models/half.js +244 -0
- package/es/line/models/half.js.map +1 -0
- package/es/line/models/index.d.ts +1 -1
- package/es/line/models/index.js +2 -0
- package/es/line/models/index.js.map +1 -1
- package/es/plugins/DataMappingPlugin.js +1 -1
- package/es/plugins/DataMappingPlugin.js.map +1 -1
- package/es/plugins/DataSourcePlugin.js +7 -6
- package/es/plugins/DataSourcePlugin.js.map +1 -1
- package/lib/line/index.js +2 -1
- package/lib/line/index.js.map +1 -1
- package/lib/line/models/half.js +260 -0
- package/lib/line/models/half.js.map +1 -0
- package/lib/line/models/index.js +3 -0
- package/lib/line/models/index.js.map +1 -1
- package/lib/plugins/DataMappingPlugin.js +1 -1
- package/lib/plugins/DataMappingPlugin.js.map +1 -1
- package/lib/plugins/DataSourcePlugin.js +7 -6
- package/lib/plugins/DataSourcePlugin.js.map +1 -1
- package/package.json +5 -5
package/es/line/index.d.ts
CHANGED
package/es/line/index.js
CHANGED
package/es/line/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/line/index.ts"],"names":["BaseLayer","LineModels","LineLayer","shape","getModelType","layerModel","models","initModels","buildModels","properties","opacity","type","minimum","maximum","defaultConfig","line","linearline","simple","wall","arc3d","blend","arc","arcmini","greatcircle","vectorline","tileLine","layerSource","parser","shapeAttribute","styleAttributeService","getLayerStyleAttribute","scale","field"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,SAAP,MAAsB,mBAAtB;AAEA,OAAOC,UAAP,MAA0C,UAA1C;;IAEqBC,S;;;;;;;;;;;;;;;;2DACG,W;;;;;;;WAEtB,uBAAqB;AACnB,UAAMC,KAAK,GAAG,KAAKC,YAAL,EAAd;AACA,WAAKC,UAAL,GAAkB,IAAIJ,UAAU,CAACE,KAAD,CAAd,CAAsB,IAAtB,CAAlB;AACA,WAAKG,MAAL,GAAc,KAAKD,UAAL,CAAgBE,UAAhB,EAAd;AACD;;;WACD,yBAAuB;AACrB,WAAKD,MAAL,GAAc,KAAKD,UAAL,CAAgBG,WAAhB,EAAd;AACD;;;WAED,2BAA4B;AAC1B,aAAO;AACLC,QAAAA,UAAU,EAAE;AACVC,UAAAA,OAAO,EAAE;AACPC,YAAAA,IAAI,EAAE,QADC;AAEPC,YAAAA,OAAO,EAAE,CAFF;AAGPC,YAAAA,OAAO,EAAE;AAHF;AADC;AADP,OAAP;AASD;;;WACD,4BAA6B;AAC3B,UAAMF,IAAI,GAAG,KAAKP,YAAL,EAAb;AACA,UAAMU,aAAa,GAAG;AACpBC,QAAAA,IAAI,EAAE,EADc;AAEpBC,QAAAA,UAAU,EAAE,EAFQ;AAGpBC,QAAAA,MAAM,EAAE,EAHY;AAIpBC,QAAAA,IAAI,EAAE,EAJc;AAKpBC,QAAAA,KAAK,EAAE;AAAEC,UAAAA,KAAK,EAAE;AAAT,SALa;AAMpBC,QAAAA,GAAG,EAAE;AAAED,UAAAA,KAAK,EAAE;AAAT,SANe;AAOpBE,QAAAA,OAAO,EAAE;AAAEF,UAAAA,KAAK,EAAE;AAAT,SAPW;AAQpBG,QAAAA,WAAW,EAAE;AAAEH,UAAAA,KAAK,EAAE;AAAT,SARO;AASpBI,QAAAA,UAAU,EAAE,EATQ;AAUpBC,QAAAA,QAAQ,EAAE;
|
|
1
|
+
{"version":3,"sources":["../../src/line/index.ts"],"names":["BaseLayer","LineModels","LineLayer","shape","getModelType","layerModel","models","initModels","buildModels","properties","opacity","type","minimum","maximum","defaultConfig","line","linearline","simple","wall","arc3d","blend","arc","arcmini","greatcircle","vectorline","tileLine","halfLine","layerSource","parser","shapeAttribute","styleAttributeService","getLayerStyleAttribute","scale","field"],"mappings":";;;;;;;;;;;;AAAA,OA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AAAA;;AACtC,UAAI,KAAKgB,WAAL,CAAiBC,MAAjB,CAAwBjB,IAAxB,KAAiC,KAArC,EAA4C;AAC1C,eAAO,YAAP;AACD;;AACD,UAAMkB,cAAc,GAAG,KAAKC,qBAAL,CAA2BC,sBAA3B,CACrB,OADqB,CAAvB;AAGA,UAAM5B,KAAK,GAAG0B,cAAH,aAAGA,cAAH,gDAAGA,cAAc,CAAEG,KAAnB,0DAAG,sBAAuBC,KAArC;AACA,aAAO9B,KAAK,IAAI,MAAhB;AACD;;;;EAjDoCH,S;;SAAlBE,S","sourcesContent":["import BaseLayer from '../core/BaseLayer';\nimport { ILineLayerStyleOptions } from '../core/interface';\nimport LineModels, { LineModelType } from './models';\n\nexport default class LineLayer extends BaseLayer<ILineLayerStyleOptions> {\n public type: string = 'LineLayer';\n\n public buildModels() {\n const shape = this.getModelType();\n this.layerModel = new LineModels[shape](this);\n this.models = this.layerModel.initModels();\n }\n public rebuildModels() {\n this.models = this.layerModel.buildModels();\n }\n\n protected getConfigSchema() {\n return {\n properties: {\n opacity: {\n type: 'number',\n minimum: 0,\n maximum: 1,\n },\n },\n };\n }\n protected getDefaultConfig() {\n const type = this.getModelType();\n const defaultConfig = {\n line: {},\n linearline: {},\n simple: {},\n wall: {},\n arc3d: { blend: 'additive' },\n arc: { blend: 'additive' },\n arcmini: { blend: 'additive' },\n greatcircle: { blend: 'additive' },\n vectorline: {},\n tileLine: {},\n halfLine: {},\n };\n return defaultConfig[type];\n }\n protected getModelType(): LineModelType {\n if (this.layerSource.parser.type === 'mvt') {\n return 'vectorline';\n }\n const shapeAttribute = this.styleAttributeService.getLayerStyleAttribute(\n 'shape',\n );\n const shape = shapeAttribute?.scale?.field as LineModelType;\n return shape || 'line';\n }\n}\n"],"file":"index.js"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { IModel, IModelUniform } from '@antv/l7-core';
|
|
2
|
+
import BaseModel from '../../core/BaseModel';
|
|
3
|
+
export default class LineModel extends BaseModel {
|
|
4
|
+
getUninforms(): IModelUniform;
|
|
5
|
+
initModels(): IModel[];
|
|
6
|
+
clearModels(): void;
|
|
7
|
+
buildModels(): IModel[];
|
|
8
|
+
/**
|
|
9
|
+
* 根据参数获取不同的 shader 代码
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
getShaders(): {
|
|
13
|
+
frag: string;
|
|
14
|
+
vert: string;
|
|
15
|
+
type: string;
|
|
16
|
+
};
|
|
17
|
+
protected registerBuiltinAttributes(): void;
|
|
18
|
+
}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
2
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
3
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
4
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
5
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
6
|
+
import _isNumber from "lodash/isNumber";
|
|
7
|
+
|
|
8
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
9
|
+
|
|
10
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
11
|
+
|
|
12
|
+
import { AttributeType, gl } from '@antv/l7-core';
|
|
13
|
+
import { getMask, rgb2arr } from '@antv/l7-utils';
|
|
14
|
+
import BaseModel from '../../core/BaseModel';
|
|
15
|
+
import { LineTriangulation } from '../../core/triangulation';
|
|
16
|
+
var line_half_frag = "#define COORDINATE_SYSTEM_LNGLAT 1.0 // mapbox\n#define COORDINATE_SYSTEM_LNGLAT_OFFSET 2.0 // mapbox offset\n#define COORDINATE_SYSTEM_VECTOR_TILE 3.0\n#define COORDINATE_SYSTEM_IDENTITY 4.0\n#define COORDINATE_SYSTEM_P20 5.0 // amap\n#define COORDINATE_SYSTEM_P20_OFFSET 6.0 // amap offset\n#define COORDINATE_SYSTEM_METER_OFFSET 7.0\n\n#define COORDINATE_SYSTEM_P20_2 8.0 // amap2.0\nuniform float u_CoordinateSystem;\nvarying vec4 v_color;\nuniform float u_arrow: 0.0;\nuniform float u_linearColor: 0;\nuniform vec4 u_sourceColor;\nuniform vec4 u_targetColor;\n\n#pragma include \"picking\"\n\nvarying mat4 styleMappingMat;\nvoid main() {\n float distanceAndIndex = styleMappingMat[0][3];\n float miter = styleMappingMat[0][2];\n\n float opacity = styleMappingMat[0][0];\n float d_distance_ratio = styleMappingMat[3].r; // \u5F53\u524D\u70B9\u4F4D\u8DDD\u79BB\u5360\u7EBF\u603B\u957F\u7684\u6BD4\u4F8B\n\n\n if(u_arrow > 0.0 && distanceAndIndex < 2.0) { // arrow\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20 || u_CoordinateSystem == COORDINATE_SYSTEM_P20_OFFSET) { \n if(cross(vec3(styleMappingMat[1].rg, 0.0), vec3(styleMappingMat[1].ba, 0.0)).z < 0.0) { // amap\n discard;\n }\n } else { // amap2 mapbox map\n if(cross(vec3(styleMappingMat[1].rg, 0.0), vec3(styleMappingMat[1].ba, 0.0)).z > 0.0) { \n discard;\n }\n }\n } else { // line body\n if(miter < 0.0) {\n discard;\n }\n }\n\n\n if(u_linearColor == 1.0) { // \u4F7F\u7528\u6E10\u53D8\u989C\u8272\n gl_FragColor = mix(u_sourceColor, u_targetColor, d_distance_ratio);\n } else { // \u4F7F\u7528 color \u65B9\u6CD5\u4F20\u5165\u7684\u989C\u8272\n gl_FragColor = v_color;\n }\n\n gl_FragColor.a *= opacity; // \u5168\u5C40\u900F\u660E\u5EA6\n gl_FragColor = filterColor(gl_FragColor);\n}\n";
|
|
17
|
+
var line_half_vert = "attribute float a_Miter;\nattribute vec4 a_Color;\nattribute vec2 a_Size;\nattribute vec3 a_Normal;\nattribute vec3 a_Position;\n\n// dash line\nattribute vec4 a_dirPoints;\nattribute vec3 a_DistanceAndIndex;\n\nuniform vec4 u_lineDir;\n\nuniform mat4 u_ModelMatrix;\nuniform mat4 u_Mvp;\n\n#pragma include \"projection\"\n#pragma include \"picking\"\n\nvarying vec4 v_color;\n\nuniform float u_linearColor: 0;\nuniform float u_arrow: 0.0;\nuniform float u_arrowHeight: 3.0;\nuniform float u_arrowWidth: 2.0;\nuniform float u_tailWidth: 1.0;\n\nuniform float u_opacity: 1.0;\nvarying mat4 styleMappingMat; // \u7528\u4E8E\u5C06\u5728\u9876\u70B9\u7740\u8272\u5668\u4E2D\u8BA1\u7B97\u597D\u7684\u6837\u5F0F\u503C\u4F20\u9012\u7ED9\u7247\u5143\n\n#pragma include \"styleMapping\"\n#pragma include \"styleMappingCalOpacity\"\n\nvec2 calculateArrow(vec2 offset) {\n /*\n * \u5728\u652F\u6301\u7BAD\u5934\u7684\u65F6\u5019\uFF0C\u7B2C\u4E8C\u3001\u7B2C\u4E09\u7EC4\u9876\u70B9\u662F\u989D\u5916\u63D2\u5165\u7528\u4E8E\u6784\u5EFA\u9876\u70B9\u7684\n */\n float arrowFlag = -1.0;\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) {\n // \u9AD8\u5FB7 2.0 \u7684\u65CB\u8F6C\u89D2\u5EA6\u4E0D\u540C\n arrowFlag = 1.0;\n }\n float pi = arrowFlag * 3.1415926/2.;\n if(a_Miter < 0.) {\n // \u6839\u636E\u7EBF\u7684\u4E24\u4FA7\u504F\u79FB\u4E0D\u540C\u3001\u65CB\u8F6C\u7684\u65B9\u5411\u76F8\u53CD\n pi = -pi;\n }\n highp float angle_sin = sin(pi);\n highp float angle_cos = cos(pi);\n // \u8BA1\u7B97\u5782\u76F4\u4E0E\u7EBF\u65B9\u5411\u7684\u65CB\u8F6C\u77E9\u9635\n mat2 rotation_matrix = mat2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos);\n float arrowWidth = u_arrowWidth;\n float arrowHeight = u_arrowHeight;\n\n vec2 arrowOffset = vec2(0.0);\n /*\n * a_DistanceAndIndex.y \u7528\u4E8E\u6807\u8BB0\u5F53\u524D\u9876\u70B9\u5C5E\u4E8E\u54EA\u4E00\u7EC4\uFF08\u4E24\u4E2A\u9876\u70B9\u4E00\u7EC4\uFF0C\u6784\u6210\u7EBF\u7684\u5176\u5B9E\u662F\u77E9\u5F62\uFF0C\u6700\u7B80\u9700\u8981\u56DB\u4E2A\u9876\u70B9\u3001\u4E24\u7EC4\u9876\u70B9\u6784\u6210\uFF09\n */\n if(a_DistanceAndIndex.y == 0.0) {\n // \u7BAD\u5934\u5C16\u90E8\n offset = vec2(0.0);\n } else if(a_DistanceAndIndex.y == 1.0) {\n // \u7BAD\u5934\u4E24\u4FA7\n arrowOffset = rotation_matrix*(offset * arrowHeight);\n offset += arrowOffset; // \u6CBF\u7EBF\u504F\u79FB\n offset = offset * arrowWidth; // \u5782\u76F4\u7EBF\u5411\u5916\u504F\u79FB\uFF08\u662F\u6784\u5EFA\u7BAD\u5934\u4E24\u4FA7\u7684\u9876\u70B9\uFF09\n } else if(a_DistanceAndIndex.y == 2.0 || a_DistanceAndIndex.y == 3.0 || a_DistanceAndIndex.y == 4.0) {\n // \u504F\u79FB\u5176\u4F59\u7684\u70B9\u4F4D\uFF08\u5C06\u957F\u5EA6\u8BA9\u4F4D\u7ED9\u7BAD\u5934\uFF09\n arrowOffset = rotation_matrix*(offset * arrowHeight) * arrowWidth;\n offset += arrowOffset;// \u6CBF\u7EBF\u504F\u79FB\n }\n\n return offset;\n}\n\nvoid main() {\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n styleMappingMat = mat4(\n 0.0, 0.0, 0.0, 0.0, // opacity - strokeOpacity - a_Miter - a_DistanceAndIndex\n 0.0, 0.0, 0.0, 0.0, // originX - originY - vectorX - vectorY\n 0.0, 0.0, 0.0, 0.0, // offsets[0] - offsets[1]\n 0.0, 0.0, 0.0, 0.0 // distance_ratio/distance/pixelLen/texV\n );\n styleMappingMat[0][3] = a_DistanceAndIndex.y;\n styleMappingMat[0][2] = a_Miter;\n\n float rowCount = u_cellTypeLayout[0][0]; // \u5F53\u524D\u7684\u6570\u636E\u7EB9\u7406\u6709\u51E0\u884C\n float columnCount = u_cellTypeLayout[0][1]; // \u5F53\u770B\u5230\u6570\u636E\u7EB9\u7406\u6709\u51E0\u5217\n float columnWidth = 1.0/columnCount; // \u5217\u5BBD\n float rowHeight = 1.0/rowCount; // \u884C\u9AD8\n float cellCount = calCellCount(); // opacity - strokeOpacity - strokeWidth - stroke - offsets\n float id = a_vertexId; // \u7B2Cn\u4E2A\u9876\u70B9\n float cellCurrentRow = floor(id * cellCount / columnCount) + 1.0; // \u8D77\u59CB\u70B9\u5728\u7B2C\u51E0\u884C\n float cellCurrentColumn = mod(id * cellCount, columnCount) + 1.0; // \u8D77\u59CB\u70B9\u5728\u7B2C\u51E0\u5217\n \n // cell \u56FA\u5B9A\u987A\u5E8F opacity -> strokeOpacity -> strokeWidth -> stroke ... \n // \u6309\u987A\u5E8F\u4ECE cell \u4E2D\u53D6\u503C\u3001\u82E5\u6CA1\u6709\u5219\u81EA\u52A8\u5F80\u4E0B\u53D6\u503C\n float textureOffset = 0.0; // \u5728 cell \u4E2D\u53D6\u503C\u7684\u504F\u79FB\u91CF\n\n vec2 opacityAndOffset = calOpacityAndOffset(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset, columnWidth, rowHeight);\n styleMappingMat[0][0] = opacityAndOffset.r;\n textureOffset = opacityAndOffset.g;\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n\n\n v_color = a_Color;\n\n vec3 size = a_Miter * setPickingSize(a_Size.x) * reverse_offset_normal(a_Normal);\n \n vec2 offset = project_pixel(size.xy);\n\n // styleMappingMat[1].rg = a_Position.xy + offset;\n\n vec2 copyOffset = vec2(offset.x, offset.y);\n\n float lineDistance = a_DistanceAndIndex.x;\n float total_Distance = a_DistanceAndIndex.z;\n float currentLinePointRatio = lineDistance / total_Distance;\n \n if(u_arrow > 0.0) {\n // \u8BA1\u7B97\u7BAD\u5934\n offset = calculateArrow(offset);\n\n if(a_DistanceAndIndex.y > 4.0) {\n offset *= mix(1.0, u_tailWidth, currentLinePointRatio);\n }\n }\n\n float lineOffsetWidth = length(offset + offset * sign(a_Miter)); // \u7EBF\u6A2A\u5411\u504F\u79FB\u7684\u8DDD\u79BB\uFF08\u5411\u4E24\u4FA7\u504F\u79FB\u7684\u548C\uFF09\n float linePixelSize = project_pixel(a_Size.x) * 2.0; // \u5B9A\u70B9\u4F4D\u7F6E\u504F\u79FB\uFF0C\u6309\u5730\u56FE\u7B49\u7EA7\u7F29\u653E\u540E\u7684\u8DDD\u79BB \u5355\u4FA7 * 2\n\n // \u8BBE\u7F6E\u6570\u636E\u96C6\u7684\u53C2\u6570\n styleMappingMat[3][0] = currentLinePointRatio; // \u5F53\u524D\u70B9\u4F4D\u8DDD\u79BB\u5360\u7EBF\u603B\u957F\u7684\u6BD4\u4F8B\n styleMappingMat[3][1] = lineDistance; // \u5F53\u524D\u9876\u70B9\u7684\u8DDD\u79BB\n\n vec4 project_pos = project_position(vec4(a_Position.xy, 0, 1.0));\n\n // gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy + offset, a_Size.y, 1.0));\n\n float h = float(a_Position.z); // \u7EBF\u9876\u70B9\u7684\u9AD8\u5EA6 - \u517C\u5BB9\u4E0D\u5B58\u5728\u7B2C\u4E09\u4E2A\u6570\u503C\u7684\u60C5\u51B5 vertex height\n float lineHeight = a_Size.y; // size \u7B2C\u4E8C\u4E2A\u53C2\u6570\u4EE3\u8868\u7684\u9AD8\u5EA6 [linewidth, lineheight]\n\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) { // gaode2.x\n lineHeight *= 0.2; // \u4FDD\u6301\u548C amap/mapbox \u4E00\u81F4\u7684\u6548\u679C\n gl_Position = u_Mvp * (vec4(project_pos.xy + offset, lineHeight, 1.0));\n } else {\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy + offset, lineHeight, 1.0));\n }\n \n if(u_arrow > 0.0 && a_DistanceAndIndex.y < 2.0) {\n vec2 startPoint = a_dirPoints.rg;\n vec2 endPoint = a_dirPoints.ba;\n vec4 t1 = project_position(vec4(startPoint, 0, 1.0));\n vec4 t2 = project_position(vec4(endPoint, 0, 1.0));\n // TODO\uFF1A \u540E\u7EED\u4F18\u5316\u53EF\u4EE5\u628A\u4F4D\u7F6E\u8BA1\u7B97\u653E\u5728 cpu \u4E2D\u5B8C\u6210\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) { // gaode2.x\n vec2 p1 = (u_Mvp * vec4(t1.xy, 0.0, 1.0)).xy;\n vec2 p2 = (u_Mvp * vec4(t2.xy, 0.0, 1.0)).xy;\n styleMappingMat[1].rg = normalize(p1 - p2);\n styleMappingMat[1].ba = normalize(gl_Position.xy - p2);\n } else {\n vec2 p1 = project_common_position_to_clipspace(vec4(t1.xy, 0.0, 1.0)).xy;\n vec2 p2 = project_common_position_to_clipspace(vec4(t2.xy, 0.0, 1.0)).xy;\n styleMappingMat[1].rg = normalize(p1 - p2);\n styleMappingMat[1].ba = normalize(gl_Position.xy - p2);\n }\n }\n\n setPickingColor(a_PickingColor);\n}\n";
|
|
18
|
+
|
|
19
|
+
var LineModel = function (_BaseModel) {
|
|
20
|
+
_inherits(LineModel, _BaseModel);
|
|
21
|
+
|
|
22
|
+
var _super = _createSuper(LineModel);
|
|
23
|
+
|
|
24
|
+
function LineModel() {
|
|
25
|
+
_classCallCheck(this, LineModel);
|
|
26
|
+
|
|
27
|
+
return _super.apply(this, arguments);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
_createClass(LineModel, [{
|
|
31
|
+
key: "getUninforms",
|
|
32
|
+
value: function getUninforms() {
|
|
33
|
+
var _ref = this.layer.getLayerConfig(),
|
|
34
|
+
_ref$opacity = _ref.opacity,
|
|
35
|
+
opacity = _ref$opacity === void 0 ? 1 : _ref$opacity,
|
|
36
|
+
sourceColor = _ref.sourceColor,
|
|
37
|
+
targetColor = _ref.targetColor,
|
|
38
|
+
_ref$arrow = _ref.arrow,
|
|
39
|
+
arrow = _ref$arrow === void 0 ? {
|
|
40
|
+
enable: false,
|
|
41
|
+
arrowWidth: 2,
|
|
42
|
+
arrowHeight: 3,
|
|
43
|
+
tailWidth: 1
|
|
44
|
+
} : _ref$arrow;
|
|
45
|
+
|
|
46
|
+
var useLinearColor = 0;
|
|
47
|
+
var sourceColorArr = [0, 0, 0, 0];
|
|
48
|
+
var targetColorArr = [0, 0, 0, 0];
|
|
49
|
+
|
|
50
|
+
if (sourceColor && targetColor) {
|
|
51
|
+
sourceColorArr = rgb2arr(sourceColor);
|
|
52
|
+
targetColorArr = rgb2arr(targetColor);
|
|
53
|
+
useLinearColor = 1;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (this.dataTextureTest && this.dataTextureNeedUpdate({
|
|
57
|
+
opacity: opacity
|
|
58
|
+
})) {
|
|
59
|
+
this.judgeStyleAttributes({
|
|
60
|
+
opacity: opacity
|
|
61
|
+
});
|
|
62
|
+
var encodeData = this.layer.getEncodedData();
|
|
63
|
+
|
|
64
|
+
var _this$calDataFrame = this.calDataFrame(this.cellLength, encodeData, this.cellProperties),
|
|
65
|
+
data = _this$calDataFrame.data,
|
|
66
|
+
width = _this$calDataFrame.width,
|
|
67
|
+
height = _this$calDataFrame.height;
|
|
68
|
+
|
|
69
|
+
this.rowCount = height;
|
|
70
|
+
this.dataTexture = this.cellLength > 0 && data.length > 0 ? this.createTexture2D({
|
|
71
|
+
flipY: true,
|
|
72
|
+
data: data,
|
|
73
|
+
format: gl.LUMINANCE,
|
|
74
|
+
type: gl.FLOAT,
|
|
75
|
+
width: width,
|
|
76
|
+
height: height
|
|
77
|
+
}) : this.createTexture2D({
|
|
78
|
+
flipY: true,
|
|
79
|
+
data: [1],
|
|
80
|
+
format: gl.LUMINANCE,
|
|
81
|
+
type: gl.FLOAT,
|
|
82
|
+
width: 1,
|
|
83
|
+
height: 1
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
u_dataTexture: this.dataTexture,
|
|
89
|
+
u_cellTypeLayout: this.getCellTypeLayout(),
|
|
90
|
+
u_opacity: _isNumber(opacity) ? opacity : 1.0,
|
|
91
|
+
u_linearColor: useLinearColor,
|
|
92
|
+
u_sourceColor: sourceColorArr,
|
|
93
|
+
u_targetColor: targetColorArr,
|
|
94
|
+
u_arrow: Number(arrow.enable),
|
|
95
|
+
u_arrowHeight: arrow.arrowHeight || 3,
|
|
96
|
+
u_arrowWidth: arrow.arrowWidth || 2,
|
|
97
|
+
u_tailWidth: arrow.tailWidth === undefined ? 1 : arrow.tailWidth
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
}, {
|
|
101
|
+
key: "initModels",
|
|
102
|
+
value: function initModels() {
|
|
103
|
+
return this.buildModels();
|
|
104
|
+
}
|
|
105
|
+
}, {
|
|
106
|
+
key: "clearModels",
|
|
107
|
+
value: function clearModels() {
|
|
108
|
+
var _this$dataTexture;
|
|
109
|
+
|
|
110
|
+
(_this$dataTexture = this.dataTexture) === null || _this$dataTexture === void 0 ? void 0 : _this$dataTexture.destroy();
|
|
111
|
+
}
|
|
112
|
+
}, {
|
|
113
|
+
key: "buildModels",
|
|
114
|
+
value: function buildModels() {
|
|
115
|
+
var _ref2 = this.layer.getLayerConfig(),
|
|
116
|
+
_ref2$mask = _ref2.mask,
|
|
117
|
+
mask = _ref2$mask === void 0 ? false : _ref2$mask,
|
|
118
|
+
_ref2$maskInside = _ref2.maskInside,
|
|
119
|
+
maskInside = _ref2$maskInside === void 0 ? true : _ref2$maskInside,
|
|
120
|
+
_ref2$depth = _ref2.depth,
|
|
121
|
+
depth = _ref2$depth === void 0 ? false : _ref2$depth;
|
|
122
|
+
|
|
123
|
+
var _this$getShaders = this.getShaders(),
|
|
124
|
+
frag = _this$getShaders.frag,
|
|
125
|
+
vert = _this$getShaders.vert;
|
|
126
|
+
|
|
127
|
+
this.layer.triangulation = LineTriangulation;
|
|
128
|
+
return [this.layer.buildLayerModel({
|
|
129
|
+
moduleName: 'line_half',
|
|
130
|
+
vertexShader: vert,
|
|
131
|
+
fragmentShader: frag,
|
|
132
|
+
triangulation: LineTriangulation,
|
|
133
|
+
primitive: gl.TRIANGLES,
|
|
134
|
+
blend: this.getBlend(),
|
|
135
|
+
depth: {
|
|
136
|
+
enable: depth
|
|
137
|
+
},
|
|
138
|
+
stencil: getMask(mask, maskInside)
|
|
139
|
+
})];
|
|
140
|
+
}
|
|
141
|
+
}, {
|
|
142
|
+
key: "getShaders",
|
|
143
|
+
value: function getShaders() {
|
|
144
|
+
return {
|
|
145
|
+
frag: line_half_frag,
|
|
146
|
+
vert: line_half_vert,
|
|
147
|
+
type: 'normal'
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}, {
|
|
151
|
+
key: "registerBuiltinAttributes",
|
|
152
|
+
value: function registerBuiltinAttributes() {
|
|
153
|
+
this.styleAttributeService.registerStyleAttribute({
|
|
154
|
+
name: 'distanceAndIndex',
|
|
155
|
+
type: AttributeType.Attribute,
|
|
156
|
+
descriptor: {
|
|
157
|
+
name: 'a_DistanceAndIndex',
|
|
158
|
+
buffer: {
|
|
159
|
+
usage: gl.STATIC_DRAW,
|
|
160
|
+
data: [],
|
|
161
|
+
type: gl.FLOAT
|
|
162
|
+
},
|
|
163
|
+
size: 3,
|
|
164
|
+
update: function update(feature, featureIdx, vertex, attributeIdx, normal, vertexIndex) {
|
|
165
|
+
return vertexIndex === undefined ? [vertex[3], 10, vertex[5]] : [vertex[3], vertexIndex, vertex[5]];
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
this.styleAttributeService.registerStyleAttribute({
|
|
170
|
+
name: 'dirPoints',
|
|
171
|
+
type: AttributeType.Attribute,
|
|
172
|
+
descriptor: {
|
|
173
|
+
name: 'a_dirPoints',
|
|
174
|
+
buffer: {
|
|
175
|
+
usage: gl.STATIC_DRAW,
|
|
176
|
+
data: [],
|
|
177
|
+
type: gl.FLOAT
|
|
178
|
+
},
|
|
179
|
+
size: 4,
|
|
180
|
+
update: function update(feature, featureIdx, vertex, attributeIdx) {
|
|
181
|
+
var startPoint = feature.coordinates[0] || [0, 0];
|
|
182
|
+
var endPoint = feature.coordinates[3] || [0, 0];
|
|
183
|
+
return [startPoint[0], startPoint[1], endPoint[0], endPoint[1]];
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
this.styleAttributeService.registerStyleAttribute({
|
|
188
|
+
name: 'size',
|
|
189
|
+
type: AttributeType.Attribute,
|
|
190
|
+
descriptor: {
|
|
191
|
+
name: 'a_Size',
|
|
192
|
+
buffer: {
|
|
193
|
+
usage: gl.DYNAMIC_DRAW,
|
|
194
|
+
data: [],
|
|
195
|
+
type: gl.FLOAT
|
|
196
|
+
},
|
|
197
|
+
size: 2,
|
|
198
|
+
update: function update(feature, featureIdx, vertex, attributeIdx) {
|
|
199
|
+
var _feature$size = feature.size,
|
|
200
|
+
size = _feature$size === void 0 ? 1 : _feature$size;
|
|
201
|
+
return Array.isArray(size) ? [size[0], size[1]] : [size, 0];
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
this.styleAttributeService.registerStyleAttribute({
|
|
206
|
+
name: 'normal',
|
|
207
|
+
type: AttributeType.Attribute,
|
|
208
|
+
descriptor: {
|
|
209
|
+
name: 'a_Normal',
|
|
210
|
+
buffer: {
|
|
211
|
+
usage: gl.STATIC_DRAW,
|
|
212
|
+
data: [],
|
|
213
|
+
type: gl.FLOAT
|
|
214
|
+
},
|
|
215
|
+
size: 3,
|
|
216
|
+
update: function update(feature, featureIdx, vertex, attributeIdx, normal) {
|
|
217
|
+
return normal;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
});
|
|
221
|
+
this.styleAttributeService.registerStyleAttribute({
|
|
222
|
+
name: 'miter',
|
|
223
|
+
type: AttributeType.Attribute,
|
|
224
|
+
descriptor: {
|
|
225
|
+
name: 'a_Miter',
|
|
226
|
+
buffer: {
|
|
227
|
+
usage: gl.STATIC_DRAW,
|
|
228
|
+
data: [],
|
|
229
|
+
type: gl.FLOAT
|
|
230
|
+
},
|
|
231
|
+
size: 1,
|
|
232
|
+
update: function update(feature, featureIdx, vertex, attributeIdx) {
|
|
233
|
+
return [vertex[4]];
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
}]);
|
|
239
|
+
|
|
240
|
+
return LineModel;
|
|
241
|
+
}(BaseModel);
|
|
242
|
+
|
|
243
|
+
export { LineModel as default };
|
|
244
|
+
//# sourceMappingURL=half.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/line/models/half.ts"],"names":["AttributeType","gl","getMask","rgb2arr","BaseModel","LineTriangulation","LineModel","layer","getLayerConfig","opacity","sourceColor","targetColor","arrow","enable","arrowWidth","arrowHeight","tailWidth","useLinearColor","sourceColorArr","targetColorArr","dataTextureTest","dataTextureNeedUpdate","judgeStyleAttributes","encodeData","getEncodedData","calDataFrame","cellLength","cellProperties","data","width","height","rowCount","dataTexture","length","createTexture2D","flipY","format","LUMINANCE","type","FLOAT","u_dataTexture","u_cellTypeLayout","getCellTypeLayout","u_opacity","u_linearColor","u_sourceColor","u_targetColor","u_arrow","Number","u_arrowHeight","u_arrowWidth","u_tailWidth","undefined","buildModels","destroy","mask","maskInside","depth","getShaders","frag","vert","triangulation","buildLayerModel","moduleName","vertexShader","fragmentShader","primitive","TRIANGLES","blend","getBlend","stencil","line_half_frag","line_half_vert","styleAttributeService","registerStyleAttribute","name","Attribute","descriptor","buffer","usage","STATIC_DRAW","size","update","feature","featureIdx","vertex","attributeIdx","normal","vertexIndex","startPoint","coordinates","endPoint","DYNAMIC_DRAW","Array","isArray"],"mappings":";;;;;;;;;;;AAAA,SACEA,aADF,EAEEC,EAFF,QAMO,eANP;AAOA,SAASC,OAAT,EAAkBC,OAAlB,QAAiC,gBAAjC;AAEA,OAAOC,SAAP,MAAsB,sBAAtB;AAEA,SAASC,iBAAT,QAAkC,0BAAlC;;;;IAIqBC,S;;;;;;;;;;;;;WACnB,wBAAqC;AACnC,iBAUI,KAAKC,KAAL,CAAWC,cAAX,EAVJ;AAAA,8BACEC,OADF;AAAA,UACEA,OADF,6BACY,CADZ;AAAA,UAEEC,WAFF,QAEEA,WAFF;AAAA,UAGEC,WAHF,QAGEA,WAHF;AAAA,4BAIEC,KAJF;AAAA,UAIEA,KAJF,2BAIU;AACNC,QAAAA,MAAM,EAAE,KADF;AAENC,QAAAA,UAAU,EAAE,CAFN;AAGNC,QAAAA,WAAW,EAAE,CAHP;AAINC,QAAAA,SAAS,EAAE;AAJL,OAJV;;AAaA,UAAIC,cAAc,GAAG,CAArB;AACA,UAAIC,cAAc,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,CAArB;AACA,UAAIC,cAAc,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,CAArB;;AACA,UAAIT,WAAW,IAAIC,WAAnB,EAAgC;AAC9BO,QAAAA,cAAc,GAAGf,OAAO,CAACO,WAAD,CAAxB;AACAS,QAAAA,cAAc,GAAGhB,OAAO,CAACQ,WAAD,CAAxB;AACAM,QAAAA,cAAc,GAAG,CAAjB;AACD;;AAED,UAAI,KAAKG,eAAL,IAAwB,KAAKC,qBAAL,CAA2B;AAAEZ,QAAAA,OAAO,EAAPA;AAAF,OAA3B,CA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7-core';\nimport { getMask, rgb2arr } from '@antv/l7-utils';\nimport { isNumber } from 'lodash';\nimport BaseModel from '../../core/BaseModel';\nimport { ILineLayerStyleOptions } from '../../core/interface';\nimport { LineTriangulation } from '../../core/triangulation';\nimport line_half_frag from '../shaders/half/line_half_frag.glsl';\nimport line_half_vert from '../shaders/half/line_half_vert.glsl';\n\nexport default class LineModel extends BaseModel {\n public getUninforms(): IModelUniform {\n const {\n opacity = 1,\n sourceColor,\n targetColor,\n arrow = {\n enable: false,\n arrowWidth: 2,\n arrowHeight: 3,\n tailWidth: 1,\n },\n } = this.layer.getLayerConfig() as ILineLayerStyleOptions;\n\n // 转化渐变色\n let useLinearColor = 0; // 默认不生效\n let sourceColorArr = [0, 0, 0, 0];\n let targetColorArr = [0, 0, 0, 0];\n if (sourceColor && targetColor) {\n sourceColorArr = rgb2arr(sourceColor);\n targetColorArr = rgb2arr(targetColor);\n useLinearColor = 1;\n }\n\n if (this.dataTextureTest && this.dataTextureNeedUpdate({ opacity })) {\n this.judgeStyleAttributes({ opacity });\n const encodeData = this.layer.getEncodedData();\n const { data, width, height } = this.calDataFrame(\n this.cellLength,\n encodeData,\n this.cellProperties,\n );\n this.rowCount = height; // 当前数据纹理有多少行\n\n this.dataTexture =\n this.cellLength > 0 && data.length > 0\n ? this.createTexture2D({\n flipY: true,\n data,\n format: gl.LUMINANCE,\n type: gl.FLOAT,\n width,\n height,\n })\n : this.createTexture2D({\n flipY: true,\n data: [1],\n format: gl.LUMINANCE,\n type: gl.FLOAT,\n width: 1,\n height: 1,\n });\n }\n return {\n u_dataTexture: this.dataTexture, // 数据纹理 - 有数据映射的时候纹理中带数据,若没有任何数据映射时纹理是 [1]\n u_cellTypeLayout: this.getCellTypeLayout(),\n u_opacity: isNumber(opacity) ? opacity : 1.0,\n\n // 渐变色支持参数\n u_linearColor: useLinearColor,\n u_sourceColor: sourceColorArr,\n u_targetColor: targetColorArr,\n\n // arrow\n u_arrow: Number(arrow.enable),\n u_arrowHeight: arrow.arrowHeight || 3,\n u_arrowWidth: arrow.arrowWidth || 2,\n u_tailWidth: arrow.tailWidth === undefined ? 1 : arrow.tailWidth,\n };\n }\n\n public initModels(): IModel[] {\n return this.buildModels();\n }\n\n public clearModels() {\n this.dataTexture?.destroy();\n }\n\n public buildModels(): IModel[] {\n const {\n mask = false,\n maskInside = true,\n depth = false,\n } = this.layer.getLayerConfig() as ILineLayerStyleOptions;\n const { frag, vert } = this.getShaders();\n this.layer.triangulation = LineTriangulation;\n return [\n this.layer.buildLayerModel({\n moduleName: 'line_half',\n vertexShader: vert,\n fragmentShader: frag,\n triangulation: LineTriangulation,\n primitive: gl.TRIANGLES,\n blend: this.getBlend(),\n depth: { enable: depth },\n stencil: getMask(mask, maskInside),\n }),\n ];\n }\n\n /**\n * 根据参数获取不同的 shader 代码\n * @returns\n */\n public getShaders(): { frag: string; vert: string; type: string } {\n return {\n frag: line_half_frag,\n vert: line_half_vert,\n type: 'normal',\n };\n }\n\n protected registerBuiltinAttributes() {\n this.styleAttributeService.registerStyleAttribute({\n name: 'distanceAndIndex',\n type: AttributeType.Attribute,\n descriptor: {\n name: 'a_DistanceAndIndex',\n buffer: {\n // give the WebGL driver a hint that this buffer may change\n usage: gl.STATIC_DRAW,\n data: [],\n type: gl.FLOAT,\n },\n size: 3,\n update: (\n feature: IEncodeFeature,\n featureIdx: number,\n vertex: number[],\n attributeIdx: number,\n normal: number[],\n vertexIndex?: number,\n ) => {\n return vertexIndex === undefined\n ? [vertex[3], 10, vertex[5]]\n : [vertex[3], vertexIndex, vertex[5]];\n },\n },\n });\n this.styleAttributeService.registerStyleAttribute({\n name: 'dirPoints',\n type: AttributeType.Attribute,\n descriptor: {\n name: 'a_dirPoints',\n buffer: {\n // give the WebGL driver a hint that this buffer may change\n usage: gl.STATIC_DRAW,\n data: [],\n type: gl.FLOAT,\n },\n size: 4,\n update: (\n feature: IEncodeFeature,\n featureIdx: number,\n vertex: number[],\n attributeIdx: number,\n ) => {\n // console.log(feature)\n const startPoint = (feature.coordinates[0] || [0, 0]) as number[];\n const endPoint = (feature.coordinates[3] || [0, 0]) as number[];\n\n return [startPoint[0], startPoint[1], endPoint[0], endPoint[1]];\n },\n },\n });\n\n this.styleAttributeService.registerStyleAttribute({\n name: 'size',\n type: AttributeType.Attribute,\n descriptor: {\n name: 'a_Size',\n buffer: {\n // give the WebGL driver a hint that this buffer may change\n usage: gl.DYNAMIC_DRAW,\n data: [],\n type: gl.FLOAT,\n },\n size: 2,\n update: (\n feature: IEncodeFeature,\n featureIdx: number,\n vertex: number[],\n attributeIdx: number,\n ) => {\n const { size = 1 } = feature;\n return Array.isArray(size) ? [size[0], size[1]] : [size as number, 0];\n },\n },\n });\n\n // point layer size;\n this.styleAttributeService.registerStyleAttribute({\n name: 'normal',\n type: AttributeType.Attribute,\n descriptor: {\n name: 'a_Normal',\n buffer: {\n // give the WebGL driver a hint that this buffer may change\n usage: gl.STATIC_DRAW,\n data: [],\n type: gl.FLOAT,\n },\n size: 3,\n update: (\n feature: IEncodeFeature,\n featureIdx: number,\n vertex: number[],\n attributeIdx: number,\n normal: number[],\n ) => {\n return normal;\n },\n },\n });\n\n this.styleAttributeService.registerStyleAttribute({\n name: 'miter',\n type: AttributeType.Attribute,\n descriptor: {\n name: 'a_Miter',\n buffer: {\n // give the WebGL driver a hint that this buffer may change\n usage: gl.STATIC_DRAW,\n data: [],\n type: gl.FLOAT,\n },\n size: 1,\n update: (\n feature: IEncodeFeature,\n featureIdx: number,\n vertex: number[],\n attributeIdx: number,\n ) => {\n return [vertex[4]];\n },\n },\n });\n }\n}\n"],"file":"half.js"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare type LineModelType = 'arc' | 'arcmini' | 'arc3d' | 'greatcircle' | 'wall' | 'simple' | 'line' | 'linearline' | 'vectorline' | 'tileLine';
|
|
1
|
+
export declare type LineModelType = 'arc' | 'arcmini' | 'arc3d' | 'greatcircle' | 'wall' | 'simple' | 'line' | 'halfLine' | 'linearline' | 'vectorline' | 'tileLine';
|
|
2
2
|
declare const LineModels: {
|
|
3
3
|
[key in LineModelType]: any;
|
|
4
4
|
};
|
package/es/line/models/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import ArcModel from './arc';
|
|
|
3
3
|
import Arc3DModel from './arc_3d';
|
|
4
4
|
import ArcMiniModel from './arcmini';
|
|
5
5
|
import GreatCircleModel from './great_circle';
|
|
6
|
+
import LineHalfModel from './half';
|
|
6
7
|
import LineModel from './line';
|
|
7
8
|
import LinearLine from './linearline';
|
|
8
9
|
import SimpleLineModel from './simpleLine';
|
|
@@ -15,6 +16,7 @@ var LineModels = {
|
|
|
15
16
|
greatcircle: GreatCircleModel,
|
|
16
17
|
wall: LineWallModel,
|
|
17
18
|
line: LineModel,
|
|
19
|
+
halfLine: LineHalfModel,
|
|
18
20
|
simple: SimpleLineModel,
|
|
19
21
|
linearline: LinearLine,
|
|
20
22
|
vectorline: LineTileModel,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/line/models/index.ts"],"names":["LineTileModel","ArcModel","Arc3DModel","ArcMiniModel","GreatCircleModel","LineModel","LinearLine","SimpleLineModel","TileLineModel","LineWallModel","LineModels","arc","arcmini","arc3d","greatcircle","wall","line","simple","linearline","vectorline","tileLine"],"mappings":"AAAA,OAAOA,aAAP,MAA0B,6BAA1B;AACA,OAAOC,QAAP,MAAqB,OAArB;AACA,OAAOC,UAAP,MAAuB,UAAvB;AACA,OAAOC,YAAP,MAAyB,WAAzB;AACA,OAAOC,gBAAP,MAA6B,gBAA7B;AACA,OAAOC,SAAP,MAAsB,QAAtB;AACA,OAAOC,UAAP,MAAuB,cAAvB;AACA,OAAOC,eAAP,MAA4B,cAA5B;AACA,OAAOC,aAAP,MAA0B,QAA1B;AACA,OAAOC,aAAP,MAA0B,QAA1B;
|
|
1
|
+
{"version":3,"sources":["../../../src/line/models/index.ts"],"names":["LineTileModel","ArcModel","Arc3DModel","ArcMiniModel","GreatCircleModel","LineHalfModel","LineModel","LinearLine","SimpleLineModel","TileLineModel","LineWallModel","LineModels","arc","arcmini","arc3d","greatcircle","wall","line","halfLine","simple","linearline","vectorline","tileLine"],"mappings":"AAAA,OAAOA,aAAP,MAA0B,6BAA1B;AACA,OAAOC,QAAP,MAAqB,OAArB;AACA,OAAOC,UAAP,MAAuB,UAAvB;AACA,OAAOC,YAAP,MAAyB,WAAzB;AACA,OAAOC,gBAAP,MAA6B,gBAA7B;AACA,OAAOC,aAAP,MAA0B,QAA1B;AACA,OAAOC,SAAP,MAAsB,QAAtB;AACA,OAAOC,UAAP,MAAuB,cAAvB;AACA,OAAOC,eAAP,MAA4B,cAA5B;AACA,OAAOC,aAAP,MAA0B,QAA1B;AACA,OAAOC,aAAP,MAA0B,QAA1B;AAeA,IAAMC,UAA2C,GAAG;AAClDC,EAAAA,GAAG,EAAEX,QAD6C;AAElDY,EAAAA,OAAO,EAAEV,YAFyC;AAGlDW,EAAAA,KAAK,EAAEZ,UAH2C;AAIlDa,EAAAA,WAAW,EAAEX,gBAJqC;AAKlDY,EAAAA,IAAI,EAAEN,aAL4C;AAMlDO,EAAAA,IAAI,EAAEX,SAN4C;AAOlDY,EAAAA,QAAQ,EAAEb,aAPwC;AAQlDc,EAAAA,MAAM,EAAEX,eAR0C;AASlDY,EAAAA,UAAU,EAAEb,UATsC;AAUlDc,EAAAA,UAAU,EAAErB,aAVsC;AAWlDsB,EAAAA,QAAQ,EAAEb;AAXwC,CAApD;AAcA,eAAeE,UAAf","sourcesContent":["import LineTileModel from '../../tile/models/tileModel';\nimport ArcModel from './arc';\nimport Arc3DModel from './arc_3d';\nimport ArcMiniModel from './arcmini';\nimport GreatCircleModel from './great_circle';\nimport LineHalfModel from './half';\nimport LineModel from './line';\nimport LinearLine from './linearline';\nimport SimpleLineModel from './simpleLine';\nimport TileLineModel from './tile';\nimport LineWallModel from './wall';\n\nexport type LineModelType =\n | 'arc'\n | 'arcmini'\n | 'arc3d'\n | 'greatcircle'\n | 'wall'\n | 'simple'\n | 'line'\n | 'halfLine'\n | 'linearline'\n | 'vectorline'\n | 'tileLine';\n\nconst LineModels: { [key in LineModelType]: any } = {\n arc: ArcModel,\n arcmini: ArcMiniModel,\n arc3d: Arc3DModel,\n greatcircle: GreatCircleModel,\n wall: LineWallModel,\n line: LineModel,\n halfLine: LineHalfModel,\n simple: SimpleLineModel,\n linearline: LinearLine,\n vectorline: LineTileModel,\n tileLine: TileLineModel,\n};\n\nexport default LineModels;\n"],"file":"index.js"}
|
|
@@ -148,7 +148,7 @@ var DataMappingPlugin = (_dec = injectable(), _dec2 = inject(TYPES.IGlobalConfig
|
|
|
148
148
|
}
|
|
149
149
|
});
|
|
150
150
|
|
|
151
|
-
if (encodeRecord.shape === 'line'
|
|
151
|
+
if (arrow.enable && (encodeRecord.shape === 'line' || encodeRecord.shape === 'halfLine')) {
|
|
152
152
|
var coords = encodeRecord.coordinates;
|
|
153
153
|
|
|
154
154
|
var arrowPoint = _this3.getArrowPoints(coords[0], coords[1]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/DataMappingPlugin.ts"],"names":["TYPES","Version","isColor","normalize","rgb2arr","inject","injectable","DataMappingPlugin","IGlobalConfigService","IMapService","IFontService","layer","styleAttributeService","hooks","init","tap","generateMaping","beforeRenderData","dataState","dataMappingNeedUpdate","beforeRender","layerModelNeedUpdate","bottomColor","getBottomColor","attributes","getLayerStyleAttributes","filter","getLayerStyleAttribute","dataArray","getSource","data","attributesToRemapping","attribute","needRemapping","filterData","scale","record","applyAttributeMapping","length","setEncodedData","mapping","undefined","getEncodedData","emit","p1","p2","dir","normalizeDir","arrowPoint","predata","minimumColor","getLayerConfig","arrow","enable","mappedData","map","i","preRecord","encodeRecord","id","_id","coordinates","forEach","values","name","c","Array","isArray","shape","fontService","getIconFontKey","coords","getArrowPoints","splice","adjustData2Amap2Coordinates","adjustData2SimpleCoordinates","mapService","version","layerCenter","getLayerCenter","d","originCoordinates","lngLatToCoordByLayer","lngLatToCoordsByLayer","source","center","SIMPLE","simpleCoordinate","unProjectCoordinates","simpleMapCoord","unproject","coord","c1","co","push","scalers","params","field","hasOwnProperty","type","mappingResult"],"mappings":";;;;;;;;;;;;;;AAAA,SAYEA,KAZF,QAaO,eAbP;AAcA,SAASC,OAAT,QAAwB,eAAxB;AACA,SAASC,OAAT,EAAkBC,SAAlB,EAA6BC,OAA7B,QAA2D,gBAA3D;AACA,SAASC,MAAT,EAAiBC,UAAjB,QAAmC,WAAnC;AAEA,OAAO,kBAAP;IAIqBC,iB,WADpBD,UAAU,E,UAERD,MAAM,CAACL,KAAK,CAACQ,oBAAP,C,UAGNH,MAAM,CAACL,KAAK,CAACS,WAAP,C,UAGNJ,MAAM,CAACL,KAAK,CAACU,YAAP,C;;;;;;;;;;;;;WAGP,eACEC,KADF,QAKE;AAAA;;AAAA,UAFEC,qBAEF,QAFEA,qBAEF;AACAD,MAAAA,KAAK,CAACE,KAAN,CAAYC,IAAZ,CAAiBC,GAAjB,CAAqB,mBAArB,EAA0C,YAAM;AAE9C,QAAA,KAAI,CAACC,cAAL,CAAoBL,KAApB,EAA2B;AAAEC,UAAAA,qBAAqB,EAArBA;AAAF,SAA3B;AACD,OAHD;AAKAD,MAAAA,KAAK,CAACE,KAAN,CAAYI,gBAAZ,CAA6BF,GAA7B,CAAiC,mBAAjC,EAAsD,YAAM;AAC1DJ,QAAAA,KAAK,CAACO,SAAN,CAAgBC,qBAAhB,GAAwC,KAAxC;;AACA,QAAA,KAAI,CAACH,cAAL,CAAoBL,KAApB,EAA2B;AAAEC,UAAAA,qBAAqB,EAArBA;AAAF,SAA3B;;AACA,eAAO,IAAP;AACD,OAJD;AAOAD,MAAAA,KAAK,CAACE,KAAN,CAAYO,YAAZ,CAAyBL,GAAzB,CAA6B,mBAA7B,EAAkD,YAAM;AACtD,YAAIJ,KAAK,CAACU,oBAAV,EAAgC;AAC9B;AACD;;AACD,YAAMC,WAAW,GAAGX,KAAK,CAACY,cAAN,EAApB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,OAAlB,KAA6B,EAA7C;AACA,UAAMC,MAAiB,GAAG,EAA1B;AAEAD,MAAAA,OAAO,CAACjC,OAAR,CAAgB,iBAAe;AAAA;;AAAA,YAAZmC,KAAY,SAAZA,KAAY;;AAC7B,YACE7D,MAAM,CAAC8D,cAAP,CAAsBD,KAAtB,KACA,sBAAAjE,SAAS,CAACG,KAAV,wEAAiBgE,IAAjB,MAA0B,UAF5B,EAGE;AAEAH,UAAAA,MAAM,CAACF,IAAP,CAAY1D,MAAM,CAAC6D,KAAD,CAAlB;AACD;AACF,OARD;AAYA,UAAMG,aAAa,GAAGpE,SAAS,CAACQ,OAAV,GAAoBR,SAAS,CAACQ,OAAV,CAAkBwD,MAAlB,CAApB,GAAgD,EAAtE;;AACA,UAAIhE,SAAS,CAACgC,IAAV,KAAmB,OAAnB,IAA8B,CAAC9D,OAAO,CAACkG,aAAa,CAAC,CAAD,CAAd,CAA1C,EAA8D;AAC5D,eAAO,CAAClD,YAAD,CAAP;AACD;;AACD,aAAOkD,aAAP;AAED;;;;;;;;;;;;;;;;;;;;SAjTkB7F,iB","sourcesContent":["import {\n IEncodeFeature,\n IFontService,\n IGlobalConfigService,\n ILayer,\n ILayerPlugin,\n ILngLat,\n IMapService,\n IParseDataItem,\n IStyleAttribute,\n IStyleAttributeService,\n Position,\n TYPES,\n} from '@antv/l7-core';\nimport { Version } from '@antv/l7-maps';\nimport { isColor, normalize, rgb2arr, unProjectFlat } from '@antv/l7-utils';\nimport { inject, injectable } from 'inversify';\nimport { cloneDeep } from 'lodash';\nimport 'reflect-metadata';\nimport { ILineLayerStyleOptions } from '../core/interface';\n\n@injectable()\nexport default class DataMappingPlugin implements ILayerPlugin {\n @inject(TYPES.IGlobalConfigService)\n private readonly configService: IGlobalConfigService;\n\n @inject(TYPES.IMapService)\n private readonly mapService: IMapService;\n\n @inject(TYPES.IFontService)\n private readonly fontService: IFontService;\n\n public apply(\n layer: ILayer,\n {\n styleAttributeService,\n }: { styleAttributeService: IStyleAttributeService },\n ) {\n layer.hooks.init.tap('DataMappingPlugin', () => {\n // 初始化重新生成 map\n this.generateMaping(layer, { styleAttributeService });\n });\n\n layer.hooks.beforeRenderData.tap('DataMappingPlugin', () => {\n layer.dataState.dataMappingNeedUpdate = false;\n this.generateMaping(layer, { styleAttributeService });\n return true;\n });\n\n // remapping before render\n layer.hooks.beforeRender.tap('DataMappingPlugin', () => {\n if (layer.layerModelNeedUpdate) {\n return;\n }\n const bottomColor = layer.getBottomColor();\n const attributes = styleAttributeService.getLayerStyleAttributes() || [];\n const filter = styleAttributeService.getLayerStyleAttribute('filter');\n const { dataArray } = layer.getSource().data;\n\n const attributesToRemapping = attributes.filter(\n (attribute) => attribute.needRemapping, // 如果filter变化\n );\n let filterData = dataArray;\n\n // 数据过滤完 再执行数据映射\n if (filter?.needRemapping && filter?.scale) {\n filterData = dataArray.filter((record: IParseDataItem) => {\n return this.applyAttributeMapping(filter, record, bottomColor)[0];\n });\n }\n\n if (attributesToRemapping.length) {\n // 过滤数据\n if (filter?.needRemapping) {\n layer.setEncodedData(\n this.mapping(layer, attributes, filterData, undefined, bottomColor),\n );\n filter.needRemapping = false;\n } else {\n layer.setEncodedData(\n this.mapping(\n layer,\n attributesToRemapping,\n filterData,\n layer.getEncodedData(),\n bottomColor,\n ),\n );\n }\n // 处理文本更新\n layer.emit('remapping', null);\n }\n });\n }\n private generateMaping(\n layer: ILayer,\n {\n styleAttributeService,\n }: { styleAttributeService: IStyleAttributeService },\n ) {\n const bottomColor = layer.getBottomColor();\n const attributes = styleAttributeService.getLayerStyleAttributes() || [];\n const filter = styleAttributeService.getLayerStyleAttribute('filter');\n const { dataArray } = layer.getSource().data;\n let filterData = dataArray;\n // 数据过滤完 再执行数据映射\n if (filter?.scale) {\n filterData = dataArray.filter((record: IParseDataItem) => {\n return this.applyAttributeMapping(filter, record, bottomColor)[0];\n });\n }\n layer.setEncodedData(\n this.mapping(layer, attributes, filterData, undefined, bottomColor),\n );\n // 对外暴露事件\n layer.emit('dataUpdate', null);\n }\n\n private getArrowPoints(p1: Position, p2: Position) {\n const dir = [p2[0] - p1[0], p2[1] - p1[1]];\n const normalizeDir = normalize(dir);\n const arrowPoint = [\n p1[0] + normalizeDir[0] * 0.0001,\n p1[1] + normalizeDir[1] * 0.0001,\n ];\n return arrowPoint;\n }\n\n private mapping(\n layer: ILayer,\n attributes: IStyleAttribute[],\n data: IParseDataItem[],\n predata?: IEncodeFeature[],\n minimumColor?: string,\n ): IEncodeFeature[] {\n const {\n arrow = {\n enable: false,\n },\n } = layer.getLayerConfig() as ILineLayerStyleOptions;\n const mappedData = data.map((record: IParseDataItem, i) => {\n const preRecord = predata ? predata[i] : {};\n const encodeRecord: IEncodeFeature = {\n id: record._id,\n coordinates: record.coordinates,\n ...preRecord,\n };\n attributes\n .filter((attribute) => attribute.scale !== undefined)\n .forEach((attribute: IStyleAttribute) => {\n // console.log('record', record)\n let values = this.applyAttributeMapping(\n attribute,\n record,\n minimumColor,\n );\n // console.log('values', values)\n attribute.needRemapping = false;\n\n // TODO: 支持每个属性配置 postprocess\n if (attribute.name === 'color') {\n // console.log('attribute', attribute)\n values = values.map((c: unknown) => {\n return rgb2arr(c as string);\n });\n }\n // @ts-ignore\n encodeRecord[attribute.name] =\n Array.isArray(values) && values.length === 1 ? values[0] : values;\n\n // 增加对 layer/text/iconfont unicode 映射的解析\n if (attribute.name === 'shape') {\n encodeRecord.shape = this.fontService.getIconFontKey(\n encodeRecord[attribute.name] as string,\n );\n }\n });\n\n if (encodeRecord.shape === 'line' && arrow.enable) {\n // 只有在线图层且支持配置箭头的时候进行插入顶点的处理\n const coords = encodeRecord.coordinates as Position[];\n const arrowPoint = this.getArrowPoints(coords[0], coords[1]);\n encodeRecord.coordinates.splice(1, 0, arrowPoint, arrowPoint);\n }\n return encodeRecord;\n }) as IEncodeFeature[];\n // console.log('mappedData', mappedData)\n\n // 调整数据兼容 Amap2.0\n this.adjustData2Amap2Coordinates(mappedData, layer);\n\n // 调整数据兼容 SimpleCoordinates\n this.adjustData2SimpleCoordinates(mappedData);\n\n return mappedData;\n }\n\n private adjustData2Amap2Coordinates(\n mappedData: IEncodeFeature[],\n layer: ILayer,\n ) {\n // 根据地图的类型判断是否需要对点位数据进行处理, 若是高德2.0则需要对坐标进行相对偏移\n if (\n mappedData.length > 0 &&\n this.mapService.version === Version['GAODE2.x']\n ) {\n const layerCenter = this.getLayerCenter(layer);\n if (typeof mappedData[0].coordinates[0] === 'number') {\n // 单个的点数据\n // @ts-ignore\n mappedData\n // TODO: 避免经纬度被重复计算导致坐标位置偏移\n .filter((d) => !d.originCoordinates)\n .map((d) => {\n d.version = Version['GAODE2.x'];\n // @ts-ignore\n d.originCoordinates = cloneDeep(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)\n // @ts-ignore\n // d.coordinates = this.mapService.lngLatToCoord(d.coordinates);\n d.coordinates = this.mapService.lngLatToCoordByLayer(\n d.coordinates,\n layerCenter,\n );\n });\n } else {\n // 连续的线、面数据\n // @ts-ignore\n mappedData\n // TODO: 避免经纬度被重复计算导致坐标位置偏移\n .filter((d) => !d.originCoordinates)\n .map((d) => {\n d.version = Version['GAODE2.x'];\n // @ts-ignore\n d.originCoordinates = cloneDeep(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)\n // @ts-ignore\n // d.coordinates = this.mapService.lngLatToCoords(d.coordinates);\n d.coordinates = this.mapService.lngLatToCoordsByLayer(\n d.coordinates,\n layerCenter,\n );\n });\n }\n }\n }\n\n private getLayerCenter(layer: ILayer) {\n const source = layer.getSource();\n return source.center;\n }\n\n private adjustData2SimpleCoordinates(mappedData: IEncodeFeature[]) {\n if (mappedData.length > 0 && this.mapService.version === Version.SIMPLE) {\n mappedData.map((d) => {\n if (!d.simpleCoordinate) {\n d.coordinates = this.unProjectCoordinates(d.coordinates);\n d.simpleCoordinate = true;\n }\n });\n }\n }\n\n private unProjectCoordinates(coordinates: any) {\n if (typeof coordinates[0] === 'number') {\n return this.mapService.simpleMapCoord.unproject(\n coordinates as [number, number],\n );\n }\n\n if (coordinates[0] && coordinates[0][0] instanceof Array) {\n // @ts-ignore\n const coords = [];\n coordinates.map((coord: any) => {\n // @ts-ignore\n const c1 = [];\n coord.map((co: any) => {\n c1.push(\n this.mapService.simpleMapCoord.unproject(co as [number, number]),\n );\n });\n // @ts-ignore\n coords.push(c1);\n });\n // @ts-ignore\n return coords;\n } else {\n // @ts-ignore\n const coords = [];\n // @ts-ignore\n coordinates.map((coord) => {\n coords.push(\n this.mapService.simpleMapCoord.unproject(coord as [number, number]),\n );\n });\n // @ts-ignore\n return coords;\n }\n }\n\n private applyAttributeMapping(\n attribute: IStyleAttribute,\n record: { [key: string]: unknown },\n minimumColor?: string,\n ) {\n if (!attribute.scale) {\n return [];\n }\n const scalers = attribute?.scale?.scalers || [];\n const params: unknown[] = [];\n\n scalers.forEach(({ field }) => {\n if (\n record.hasOwnProperty(field) ||\n attribute.scale?.type === 'variable'\n ) {\n // TODO:多字段,常量\n params.push(record[field]);\n }\n });\n // console.log('params', params)\n // console.log('attribute', attribute)\n\n const mappingResult = attribute.mapping ? attribute.mapping(params) : [];\n if (attribute.name === 'color' && !isColor(mappingResult[0])) {\n return [minimumColor];\n }\n return mappingResult;\n // return attribute.mapping ? attribute.mapping(params) : [];\n }\n}\n"],"file":"DataMappingPlugin.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/DataMappingPlugin.ts"],"names":["TYPES","Version","isColor","normalize","rgb2arr","inject","injectable","DataMappingPlugin","IGlobalConfigService","IMapService","IFontService","layer","styleAttributeService","hooks","init","tap","generateMaping","beforeRenderData","dataState","dataMappingNeedUpdate","beforeRender","layerModelNeedUpdate","bottomColor","getBottomColor","attributes","getLayerStyleAttributes","filter","getLayerStyleAttribute","dataArray","getSource","data","attributesToRemapping","attribute","needRemapping","filterData","scale","record","applyAttributeMapping","length","setEncodedData","mapping","undefined","getEncodedData","emit","p1","p2","dir","normalizeDir","arrowPoint","predata","minimumColor","getLayerConfig","arrow","enable","mappedData","map","i","preRecord","encodeRecord","id","_id","coordinates","forEach","values","name","c","Array","isArray","shape","fontService","getIconFontKey","coords","getArrowPoints","splice","adjustData2Amap2Coordinates","adjustData2SimpleCoordinates","mapService","version","layerCenter","getLayerCenter","d","originCoordinates","lngLatToCoordByLayer","lngLatToCoordsByLayer","source","center","SIMPLE","simpleCoordinate","unProjectCoordinates","simpleMapCoord","unproject","coord","c1","co","push","scalers","params","field","hasOwnProperty","type","mappingResult"],"mappings":";;;;;;;;;;;;;;AAAA,SAYEA,KAZF,QAaO,eAbP;AAcA,SAASC,OAAT,QAAwB,eAAxB;AACA,SAASC,OAAT,EAAkBC,SAAlB,EAA6BC,OAA7B,QAA2D,gBAA3D;AACA,SAASC,MAAT,EAAiBC,UAAjB,QAAmC,WAAnC;AAEA,OAAO,kBAAP;IAIqBC,iB,WADpBD,UAAU,E,UAERD,MAAM,CAACL,KAAK,CAACQ,oBAAP,C,UAGNH,MAAM,CAACL,KAAK,CAACS,WAAP,C,UAGNJ,MAAM,CAACL,KAAK,CAACU,YAAP,C;;;;;;;;;;;;;WAGP,eACEC,KADF,QAKE;AAAA;;AAAA,UAFEC,qBAEF,QAFEA,qBAEF;AACAD,MAAAA,KAAK,CAACE,KAAN,CAAYC,IAAZ,CAAiBC,GAAjB,CAAqB,mBAArB,EAA0C,YAAM;AAE9C,QAAA,KAAI,CAACC,cAAL,CAAoBL,KAApB,EAA2B;AAAEC,UAAAA,qBAAqB,EAArBA;AAAF,SAA3B;AACD,OAHD;AAKAD,MAAAA,KAAK,CAACE,KAAN,CAAYI,gBAAZ,CAA6BF,GAA7B,CAAiC,mBAAjC,EAAsD,YAAM;AAC1DJ,QAAAA,KAAK,CAACO,SAAN,CAAgBC,qBAAhB,GAAwC,KAAxC;;AACA,QAAA,KAAI,CAACH,cAAL,CAAoBL,KAApB,EAA2B;AAAEC,UAAAA,qBAAqB,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zC,CADF;AAGD,SAJD;AAMA,eAAOpB,OAAP;AACD;AACF;;;WAED,+BACEvC,SADF,EAEEI,MAFF,EAGEc,YAHF,EAIE;AAAA;;AACA,UAAI,CAAClB,SAAS,CAACG,KAAf,EAAsB;AACpB,eAAO,EAAP;AACD;;AACD,UAAM4D,OAAO,GAAG,CAAA/D,SAAS,SAAT,IAAAA,SAAS,WAAT,gCAAAA,SAAS,CAAEG,KAAX,sEAAkB4D,OAAlB,KAA6B,EAA7C;AACA,UAAMC,MAAiB,GAAG,EAA1B;AAEAD,MAAAA,OAAO,CAACjC,OAAR,CAAgB,iBAAe;AAAA;;AAAA,YAAZmC,KAAY,SAAZA,KAAY;;AAC7B,YACE7D,MAAM,CAAC8D,cAAP,CAAsBD,KAAtB,KACA,sBAAAjE,SAAS,CAACG,KAAV,wEAAiBgE,IAAjB,MAA0B,UAF5B,EAGE;AAEAH,UAAAA,MAAM,CAACF,IAAP,CAAY1D,MAAM,CAAC6D,KAAD,CAAlB;AACD;AACF,OARD;AAYA,UAAMG,aAAa,GAAGpE,SAAS,CAACQ,OAAV,GAAoBR,SAAS,CAACQ,OAAV,CAAkBwD,MAAlB,CAApB,GAAgD,EAAtE;;AACA,UAAIhE,SAAS,CAACgC,IAAV,KAAmB,OAAnB,IAA8B,CAAC9D,OAAO,CAACkG,aAAa,CAAC,CAAD,CAAd,CAA1C,EAA8D;AAC5D,eAAO,CAAClD,YAAD,CAAP;AACD;;AACD,aAAOkD,aAAP;AAED;;;;;;;;;;;;;;;;;;;;SApTkB7F,iB","sourcesContent":["import {\n IEncodeFeature,\n IFontService,\n IGlobalConfigService,\n ILayer,\n ILayerPlugin,\n ILngLat,\n IMapService,\n IParseDataItem,\n IStyleAttribute,\n IStyleAttributeService,\n Position,\n TYPES,\n} from '@antv/l7-core';\nimport { Version } from '@antv/l7-maps';\nimport { isColor, normalize, rgb2arr, unProjectFlat } from '@antv/l7-utils';\nimport { inject, injectable } from 'inversify';\nimport { cloneDeep } from 'lodash';\nimport 'reflect-metadata';\nimport { ILineLayerStyleOptions } from '../core/interface';\n\n@injectable()\nexport default class DataMappingPlugin implements ILayerPlugin {\n @inject(TYPES.IGlobalConfigService)\n private readonly configService: IGlobalConfigService;\n\n @inject(TYPES.IMapService)\n private readonly mapService: IMapService;\n\n @inject(TYPES.IFontService)\n private readonly fontService: IFontService;\n\n public apply(\n layer: ILayer,\n {\n styleAttributeService,\n }: { styleAttributeService: IStyleAttributeService },\n ) {\n layer.hooks.init.tap('DataMappingPlugin', () => {\n // 初始化重新生成 map\n this.generateMaping(layer, { styleAttributeService });\n });\n\n layer.hooks.beforeRenderData.tap('DataMappingPlugin', () => {\n layer.dataState.dataMappingNeedUpdate = false;\n this.generateMaping(layer, { styleAttributeService });\n return true;\n });\n\n // remapping before render\n layer.hooks.beforeRender.tap('DataMappingPlugin', () => {\n if (layer.layerModelNeedUpdate) {\n return;\n }\n const bottomColor = layer.getBottomColor();\n const attributes = styleAttributeService.getLayerStyleAttributes() || [];\n const filter = styleAttributeService.getLayerStyleAttribute('filter');\n const { dataArray } = layer.getSource().data;\n\n const attributesToRemapping = attributes.filter(\n (attribute) => attribute.needRemapping, // 如果filter变化\n );\n let filterData = dataArray;\n\n // 数据过滤完 再执行数据映射\n if (filter?.needRemapping && filter?.scale) {\n filterData = dataArray.filter((record: IParseDataItem) => {\n return this.applyAttributeMapping(filter, record, bottomColor)[0];\n });\n }\n\n if (attributesToRemapping.length) {\n // 过滤数据\n if (filter?.needRemapping) {\n layer.setEncodedData(\n this.mapping(layer, attributes, filterData, undefined, bottomColor),\n );\n filter.needRemapping = false;\n } else {\n layer.setEncodedData(\n this.mapping(\n layer,\n attributesToRemapping,\n filterData,\n layer.getEncodedData(),\n bottomColor,\n ),\n );\n }\n // 处理文本更新\n layer.emit('remapping', null);\n }\n });\n }\n private generateMaping(\n layer: ILayer,\n {\n styleAttributeService,\n }: { styleAttributeService: IStyleAttributeService },\n ) {\n const bottomColor = layer.getBottomColor();\n const attributes = styleAttributeService.getLayerStyleAttributes() || [];\n const filter = styleAttributeService.getLayerStyleAttribute('filter');\n const { dataArray } = layer.getSource().data;\n let filterData = dataArray;\n // 数据过滤完 再执行数据映射\n if (filter?.scale) {\n filterData = dataArray.filter((record: IParseDataItem) => {\n return this.applyAttributeMapping(filter, record, bottomColor)[0];\n });\n }\n layer.setEncodedData(\n this.mapping(layer, attributes, filterData, undefined, bottomColor),\n );\n // 对外暴露事件\n layer.emit('dataUpdate', null);\n }\n\n private getArrowPoints(p1: Position, p2: Position) {\n const dir = [p2[0] - p1[0], p2[1] - p1[1]];\n const normalizeDir = normalize(dir);\n const arrowPoint = [\n p1[0] + normalizeDir[0] * 0.0001,\n p1[1] + normalizeDir[1] * 0.0001,\n ];\n return arrowPoint;\n }\n\n private mapping(\n layer: ILayer,\n attributes: IStyleAttribute[],\n data: IParseDataItem[],\n predata?: IEncodeFeature[],\n minimumColor?: string,\n ): IEncodeFeature[] {\n const {\n arrow = {\n enable: false,\n },\n } = layer.getLayerConfig() as ILineLayerStyleOptions;\n const mappedData = data.map((record: IParseDataItem, i) => {\n const preRecord = predata ? predata[i] : {};\n const encodeRecord: IEncodeFeature = {\n id: record._id,\n coordinates: record.coordinates,\n ...preRecord,\n };\n attributes\n .filter((attribute) => attribute.scale !== undefined)\n .forEach((attribute: IStyleAttribute) => {\n // console.log('record', record)\n let values = this.applyAttributeMapping(\n attribute,\n record,\n minimumColor,\n );\n // console.log('values', values)\n attribute.needRemapping = false;\n\n // TODO: 支持每个属性配置 postprocess\n if (attribute.name === 'color') {\n // console.log('attribute', attribute)\n values = values.map((c: unknown) => {\n return rgb2arr(c as string);\n });\n }\n // @ts-ignore\n encodeRecord[attribute.name] =\n Array.isArray(values) && values.length === 1 ? values[0] : values;\n\n // 增加对 layer/text/iconfont unicode 映射的解析\n if (attribute.name === 'shape') {\n encodeRecord.shape = this.fontService.getIconFontKey(\n encodeRecord[attribute.name] as string,\n );\n }\n });\n\n if (\n arrow.enable &&\n (encodeRecord.shape === 'line' || encodeRecord.shape === 'halfLine')\n ) {\n // 只有在线图层且支持配置箭头的时候进行插入顶点的处理\n const coords = encodeRecord.coordinates as Position[];\n const arrowPoint = this.getArrowPoints(coords[0], coords[1]);\n encodeRecord.coordinates.splice(1, 0, arrowPoint, arrowPoint);\n }\n return encodeRecord;\n }) as IEncodeFeature[];\n // console.log('mappedData', mappedData)\n\n // 调整数据兼容 Amap2.0\n this.adjustData2Amap2Coordinates(mappedData, layer);\n\n // 调整数据兼容 SimpleCoordinates\n this.adjustData2SimpleCoordinates(mappedData);\n\n return mappedData;\n }\n\n private adjustData2Amap2Coordinates(\n mappedData: IEncodeFeature[],\n layer: ILayer,\n ) {\n // 根据地图的类型判断是否需要对点位数据进行处理, 若是高德2.0则需要对坐标进行相对偏移\n if (\n mappedData.length > 0 &&\n this.mapService.version === Version['GAODE2.x']\n ) {\n const layerCenter = this.getLayerCenter(layer);\n if (typeof mappedData[0].coordinates[0] === 'number') {\n // 单个的点数据\n // @ts-ignore\n mappedData\n // TODO: 避免经纬度被重复计算导致坐标位置偏移\n .filter((d) => !d.originCoordinates)\n .map((d) => {\n d.version = Version['GAODE2.x'];\n // @ts-ignore\n d.originCoordinates = cloneDeep(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)\n // @ts-ignore\n // d.coordinates = this.mapService.lngLatToCoord(d.coordinates);\n d.coordinates = this.mapService.lngLatToCoordByLayer(\n d.coordinates,\n layerCenter,\n );\n });\n } else {\n // 连续的线、面数据\n // @ts-ignore\n mappedData\n // TODO: 避免经纬度被重复计算导致坐标位置偏移\n .filter((d) => !d.originCoordinates)\n .map((d) => {\n d.version = Version['GAODE2.x'];\n // @ts-ignore\n d.originCoordinates = cloneDeep(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)\n // @ts-ignore\n // d.coordinates = this.mapService.lngLatToCoords(d.coordinates);\n d.coordinates = this.mapService.lngLatToCoordsByLayer(\n d.coordinates,\n layerCenter,\n );\n });\n }\n }\n }\n\n private getLayerCenter(layer: ILayer) {\n const source = layer.getSource();\n return source.center;\n }\n\n private adjustData2SimpleCoordinates(mappedData: IEncodeFeature[]) {\n if (mappedData.length > 0 && this.mapService.version === Version.SIMPLE) {\n mappedData.map((d) => {\n if (!d.simpleCoordinate) {\n d.coordinates = this.unProjectCoordinates(d.coordinates);\n d.simpleCoordinate = true;\n }\n });\n }\n }\n\n private unProjectCoordinates(coordinates: any) {\n if (typeof coordinates[0] === 'number') {\n return this.mapService.simpleMapCoord.unproject(\n coordinates as [number, number],\n );\n }\n\n if (coordinates[0] && coordinates[0][0] instanceof Array) {\n // @ts-ignore\n const coords = [];\n coordinates.map((coord: any) => {\n // @ts-ignore\n const c1 = [];\n coord.map((co: any) => {\n c1.push(\n this.mapService.simpleMapCoord.unproject(co as [number, number]),\n );\n });\n // @ts-ignore\n coords.push(c1);\n });\n // @ts-ignore\n return coords;\n } else {\n // @ts-ignore\n const coords = [];\n // @ts-ignore\n coordinates.map((coord) => {\n coords.push(\n this.mapService.simpleMapCoord.unproject(coord as [number, number]),\n );\n });\n // @ts-ignore\n return coords;\n }\n }\n\n private applyAttributeMapping(\n attribute: IStyleAttribute,\n record: { [key: string]: unknown },\n minimumColor?: string,\n ) {\n if (!attribute.scale) {\n return [];\n }\n const scalers = attribute?.scale?.scalers || [];\n const params: unknown[] = [];\n\n scalers.forEach(({ field }) => {\n if (\n record.hasOwnProperty(field) ||\n attribute.scale?.type === 'variable'\n ) {\n // TODO:多字段,常量\n params.push(record[field]);\n }\n });\n // console.log('params', params)\n // console.log('attribute', attribute)\n\n const mappingResult = attribute.mapping ? attribute.mapping(params) : [];\n if (attribute.name === 'color' && !isColor(mappingResult[0])) {\n return [minimumColor];\n }\n return mappingResult;\n // return attribute.mapping ? attribute.mapping(params) : [];\n }\n}\n"],"file":"DataMappingPlugin.js"}
|
|
@@ -50,15 +50,16 @@ var DataSourcePlugin = (_dec = injectable(), _dec(_class = function () {
|
|
|
50
50
|
value: function updateClusterData(layer) {
|
|
51
51
|
var source = layer.getSource();
|
|
52
52
|
var cluster = source.cluster;
|
|
53
|
-
var _source$clusterOption = source.clusterOptions,
|
|
54
|
-
_source$
|
|
55
|
-
zoom = _source$clusterOption2 === void 0 ? 0 : _source$clusterOption2,
|
|
56
|
-
_source$clusterOption3 = _source$clusterOption.maxZoom,
|
|
57
|
-
maxZoom = _source$clusterOption3 === void 0 ? 16 : _source$clusterOption3;
|
|
53
|
+
var _source$clusterOption = source.clusterOptions.zoom,
|
|
54
|
+
zoom = _source$clusterOption === void 0 ? 0 : _source$clusterOption;
|
|
58
55
|
var newZoom = this.mapService.getZoom() - 1;
|
|
59
56
|
var dataSourceNeedUpdate = layer.dataState.dataSourceNeedUpdate;
|
|
60
57
|
|
|
61
|
-
if (cluster &&
|
|
58
|
+
if (cluster && dataSourceNeedUpdate) {
|
|
59
|
+
source.updateClusterData(Math.floor(newZoom));
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (cluster && Math.abs(layer.clusterZoom - newZoom) >= 1) {
|
|
62
63
|
if (zoom !== Math.floor(newZoom)) {
|
|
63
64
|
source.updateClusterData(Math.floor(newZoom));
|
|
64
65
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/DataSourcePlugin.ts"],"names":["TYPES","Source","DEFAULT_DATA","DEFAULT_PARSER","injectable","DataSourcePlugin","layer","mapService","getContainer","get","IMapService","hooks","init","tap","source","getSource","sourceOption","data","options","setSource","updateClusterData","beforeRenderData","neeUpdateCluster","dataSourceNeedUpdate","dataState","cluster","clusterOptions","zoom","
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/DataSourcePlugin.ts"],"names":["TYPES","Source","DEFAULT_DATA","DEFAULT_PARSER","injectable","DataSourcePlugin","layer","mapService","getContainer","get","IMapService","hooks","init","tap","source","getSource","sourceOption","data","options","setSource","updateClusterData","beforeRenderData","neeUpdateCluster","dataSourceNeedUpdate","dataState","cluster","clusterOptions","zoom","newZoom","getZoom","Math","floor","abs","clusterZoom"],"mappings":";;;;;;AAAA,SAKEA,KALF,QAMO,eANP;AAOA,OAAOC,MAAP,IAAiBC,YAAjB,EAA+BC,cAA/B,QAAqD,iBAArD;AACA,SAASC,UAAT,QAA2B,WAA3B;AACA,OAAO,kBAAP;IAGqBC,gB,WADpBD,UAAU,E;;;;;;;;;WAGT,eAAaE,KAAb,EAA4B;AAAA;;AAC1B,WAAKC,UAAL,GAAkBD,KAAK,CAACE,YAAN,GAAqBC,GAArB,CAAsCT,KAAK,CAACU,WAA5C,CAAlB;AACAJ,MAAAA,KAAK,CAACK,KAAN,CAAYC,IAAZ,CAAiBC,GAAjB,CAAqB,kBAArB,EAAyC,YAAM;AAC7C,YAAMC,MAAM,GAAGR,KAAK,CAACS,SAAN,EAAf;;AACA,YAAI,CAACD,MAAL,EAAa;AAEX,qBAA0BR,KAAK,CAACU,YAAN,IAAsB;AAC9CC,YAAAA,IAAI,EAAEf,YADwC;AAE9CgB,YAAAA,OAAO,EAAEf;AAFqC,WAAhD;AAAA,cAAQc,IAAR,QAAQA,IAAR;AAAA,cAAcC,OAAd,QAAcA,OAAd;;AAIAZ,UAAAA,KAAK,CAACa,SAAN,CAAgB,IAAIlB,MAAJ,CAAWgB,IAAX,EAAiBC,OAAjB,CAAhB;AACD;;AAED,QAAA,KAAI,CAACE,iBAAL,CAAuBd,KAAvB;AACD,OAZD;AAeAA,MAAAA,KAAK,CAACK,KAAN,CAAYU,gBAAZ,CAA6BR,GAA7B,CAAiC,kBAAjC,EAAqD,YAAM;AACzD,YAAMS,gBAAgB,GAAG,KAAI,CAACF,iBAAL,CAAuBd,KAAvB,CAAzB;;AACA,YAAMiB,oBAAoB,GAAGjB,KAAK,CAACkB,SAAN,CAAgBD,oBAA7C;AACAjB,QAAAA,KAAK,CAACkB,SAAN,CAAgBD,oBAAhB,GAAuC,KAAvC;AACA,eAAOD,gBAAgB,IAAIC,oBAA3B;AACD,OALD;AAMD;;;WAED,2BAA0BjB,KAA1B,EAAkD;AAChD,UAAMQ,MAAM,GAAGR,KAAK,CAACS,SAAN,EAAf;AACA,UAAMU,OAAO,GAAGX,MAAM,CAACW,OAAvB;AACA,kCAAqBX,MAAM,CAACY,cAA5B,CAAQC,IAAR;AAAA,UAAQA,IAAR,sCAAe,CAAf;AACA,UAAMC,OAAO,GAAG,KAAKrB,UAAL,CAAgBsB,OAAhB,KAA4B,CAA5C;AACA,UAAMN,oBAAoB,GAAGjB,KAAK,CAACkB,SAAN,CAAgBD,oBAA7C;;AACA,UAAIE,OAAO,IAAIF,oBAAf,EAAqC;AAEnCT,QAAAA,MAAM,CAACM,iBAAP,CAAyBU,IAAI,CAACC,KAAL,CAAWH,OAAX,CAAzB;AACD;;AAED,UAAIH,OAAO,IAAIK,IAAI,CAACE,GAAL,CAAS1B,KAAK,CAAC2B,WAAN,GAAoBL,OAA7B,KAAyC,CAAxD,EAA2D;AACzD,YAAID,IAAI,KAAKG,IAAI,CAACC,KAAL,CAAWH,OAAX,CAAb,EAAkC;AAChCd,UAAAA,MAAM,CAACM,iBAAP,CAAyBU,IAAI,CAACC,KAAL,CAAWH,OAAX,CAAzB;AACD;;AACDtB,QAAAA,KAAK,CAAC2B,WAAN,GAAoBL,OAApB;AACA,eAAO,IAAP;AACD;;AACD,aAAO,KAAP;AACD;;;;;SA9CkBvB,gB","sourcesContent":["import {\n ILayer,\n ILayerPlugin,\n ILngLat,\n IMapService,\n TYPES,\n} from '@antv/l7-core';\nimport Source, { DEFAULT_DATA, DEFAULT_PARSER } from '@antv/l7-source';\nimport { injectable } from 'inversify';\nimport 'reflect-metadata';\n\n@injectable()\nexport default class DataSourcePlugin implements ILayerPlugin {\n protected mapService: IMapService;\n public apply(layer: ILayer) {\n this.mapService = layer.getContainer().get<IMapService>(TYPES.IMapService);\n layer.hooks.init.tap('DataSourcePlugin', () => {\n const source = layer.getSource();\n if (!source) {\n // TODO: 允许用户不使用 layer 的 source 方法,在这里传入一个默认的替换的默认数据\n const { data, options } = layer.sourceOption || {\n data: DEFAULT_DATA,\n options: DEFAULT_PARSER,\n };\n layer.setSource(new Source(data, options));\n }\n\n this.updateClusterData(layer);\n });\n\n // 检测数据是否需要更新\n layer.hooks.beforeRenderData.tap('DataSourcePlugin', () => {\n const neeUpdateCluster = this.updateClusterData(layer);\n const dataSourceNeedUpdate = layer.dataState.dataSourceNeedUpdate;\n layer.dataState.dataSourceNeedUpdate = false;\n return neeUpdateCluster || dataSourceNeedUpdate;\n });\n }\n\n private updateClusterData(layer: ILayer): boolean {\n const source = layer.getSource();\n const cluster = source.cluster;\n const { zoom = 0 } = source.clusterOptions;\n const newZoom = this.mapService.getZoom() - 1;\n const dataSourceNeedUpdate = layer.dataState.dataSourceNeedUpdate;\n if (cluster && dataSourceNeedUpdate) {\n // 数据发生更新\n source.updateClusterData(Math.floor(newZoom));\n }\n // 如果 dataSource 有更新,跳过 zoom 的判断,直接更新一次\n if (cluster && Math.abs(layer.clusterZoom - newZoom) >= 1) {\n if (zoom !== Math.floor(newZoom)) {\n source.updateClusterData(Math.floor(newZoom));\n }\n layer.clusterZoom = newZoom;\n return true;\n }\n return false;\n }\n}\n"],"file":"DataSourcePlugin.js"}
|
package/lib/line/index.js
CHANGED
package/lib/line/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/line/index.ts"],"names":["LineLayer","shape","getModelType","layerModel","LineModels","models","initModels","buildModels","properties","opacity","type","minimum","maximum","defaultConfig","line","linearline","simple","wall","arc3d","blend","arc","arcmini","greatcircle","vectorline","tileLine","layerSource","parser","shapeAttribute","styleAttributeService","getLayerStyleAttribute","scale","field","BaseLayer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAEA;;;;;;IAEqBA,S;;;;;;;;;;;;;;;uFACG,W;;;;;;WAEtB,uBAAqB;AACnB,UAAMC,KAAK,GAAG,KAAKC,YAAL,EAAd;AACA,WAAKC,UAAL,GAAkB,IAAIC,gBAAWH,KAAX,CAAJ,CAAsB,IAAtB,CAAlB;AACA,WAAKI,MAAL,GAAc,KAAKF,UAAL,CAAgBG,UAAhB,EAAd;AACD;;;WACD,yBAAuB;AACrB,WAAKD,MAAL,GAAc,KAAKF,UAAL,CAAgBI,WAAhB,EAAd;AACD;;;WAED,2BAA4B;AAC1B,aAAO;AACLC,QAAAA,UAAU,EAAE;AACVC,UAAAA,OAAO,EAAE;AACPC,YAAAA,IAAI,EAAE,QADC;AAEPC,YAAAA,OAAO,EAAE,CAFF;AAGPC,YAAAA,OAAO,EAAE;AAHF;AADC;AADP,OAAP;AASD;;;WACD,4BAA6B;AAC3B,UAAMF,IAAI,GAAG,KAAKR,YAAL,EAAb;AACA,UAAMW,aAAa,GAAG;AACpBC,QAAAA,IAAI,EAAE,EADc;AAEpBC,QAAAA,UAAU,EAAE,EAFQ;AAGpBC,QAAAA,MAAM,EAAE,EAHY;AAIpBC,QAAAA,IAAI,EAAE,EAJc;AAKpBC,QAAAA,KAAK,EAAE;AAAEC,UAAAA,KAAK,EAAE;AAAT,SALa;AAMpBC,QAAAA,GAAG,EAAE;AAAED,UAAAA,KAAK,EAAE;AAAT,SANe;AAOpBE,QAAAA,OAAO,EAAE;AAAEF,UAAAA,KAAK,EAAE;AAAT,SAPW;AAQpBG,QAAAA,WAAW,EAAE;AAAEH,UAAAA,KAAK,EAAE;AAAT,SARO;AASpBI,QAAAA,UAAU,EAAE,EATQ;AAUpBC,QAAAA,QAAQ,EAAE;
|
|
1
|
+
{"version":3,"sources":["../../src/line/index.ts"],"names":["LineLayer","shape","getModelType","layerModel","LineModels","models","initModels","buildModels","properties","opacity","type","minimum","maximum","defaultConfig","line","linearline","simple","wall","arc3d","blend","arc","arcmini","greatcircle","vectorline","tileLine","halfLine","layerSource","parser","shapeAttribute","styleAttributeService","getLayerStyleAttribute","scale","field","BaseLayer"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;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BjB,IAAxB,KAAiC,KAArC,EAA4C;AAC1C,eAAO,YAAP;AACD;;AACD,UAAMkB,cAAc,GAAG,KAAKC,qBAAL,CAA2BC,sBAA3B,CACrB,OADqB,CAAvB;AAGA,UAAM7B,KAAK,GAAG2B,cAAH,aAAGA,cAAH,gDAAGA,cAAc,CAAEG,KAAnB,0DAAG,sBAAuBC,KAArC;AACA,aAAO/B,KAAK,IAAI,MAAhB;AACD;;;EAjDoCgC,mB","sourcesContent":["import BaseLayer from '../core/BaseLayer';\nimport { ILineLayerStyleOptions } from '../core/interface';\nimport LineModels, { LineModelType } from './models';\n\nexport default class LineLayer extends BaseLayer<ILineLayerStyleOptions> {\n public type: string = 'LineLayer';\n\n public buildModels() {\n const shape = this.getModelType();\n this.layerModel = new LineModels[shape](this);\n this.models = this.layerModel.initModels();\n }\n public rebuildModels() {\n this.models = this.layerModel.buildModels();\n }\n\n protected getConfigSchema() {\n return {\n properties: {\n opacity: {\n type: 'number',\n minimum: 0,\n maximum: 1,\n },\n },\n };\n }\n protected getDefaultConfig() {\n const type = this.getModelType();\n const defaultConfig = {\n line: {},\n linearline: {},\n simple: {},\n wall: {},\n arc3d: { blend: 'additive' },\n arc: { blend: 'additive' },\n arcmini: { blend: 'additive' },\n greatcircle: { blend: 'additive' },\n vectorline: {},\n tileLine: {},\n halfLine: {},\n };\n return defaultConfig[type];\n }\n protected getModelType(): LineModelType {\n if (this.layerSource.parser.type === 'mvt') {\n return 'vectorline';\n }\n const shapeAttribute = this.styleAttributeService.getLayerStyleAttribute(\n 'shape',\n );\n const shape = shapeAttribute?.scale?.field as LineModelType;\n return shape || 'line';\n }\n}\n"],"file":"index.js"}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = void 0;
|
|
9
|
+
|
|
10
|
+
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
|
+
|
|
12
|
+
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
13
|
+
|
|
14
|
+
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
15
|
+
|
|
16
|
+
var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
|
|
17
|
+
|
|
18
|
+
var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
|
|
19
|
+
|
|
20
|
+
var _isNumber2 = _interopRequireDefault(require("lodash/isNumber"));
|
|
21
|
+
|
|
22
|
+
var _l7Core = require("@antv/l7-core");
|
|
23
|
+
|
|
24
|
+
var _l7Utils = require("@antv/l7-utils");
|
|
25
|
+
|
|
26
|
+
var _BaseModel2 = _interopRequireDefault(require("../../core/BaseModel"));
|
|
27
|
+
|
|
28
|
+
var _triangulation = require("../../core/triangulation");
|
|
29
|
+
|
|
30
|
+
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
|
|
31
|
+
|
|
32
|
+
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
33
|
+
|
|
34
|
+
var line_half_frag = "#define COORDINATE_SYSTEM_LNGLAT 1.0 // mapbox\n#define COORDINATE_SYSTEM_LNGLAT_OFFSET 2.0 // mapbox offset\n#define COORDINATE_SYSTEM_VECTOR_TILE 3.0\n#define COORDINATE_SYSTEM_IDENTITY 4.0\n#define COORDINATE_SYSTEM_P20 5.0 // amap\n#define COORDINATE_SYSTEM_P20_OFFSET 6.0 // amap offset\n#define COORDINATE_SYSTEM_METER_OFFSET 7.0\n\n#define COORDINATE_SYSTEM_P20_2 8.0 // amap2.0\nuniform float u_CoordinateSystem;\nvarying vec4 v_color;\nuniform float u_arrow: 0.0;\nuniform float u_linearColor: 0;\nuniform vec4 u_sourceColor;\nuniform vec4 u_targetColor;\n\n#pragma include \"picking\"\n\nvarying mat4 styleMappingMat;\nvoid main() {\n float distanceAndIndex = styleMappingMat[0][3];\n float miter = styleMappingMat[0][2];\n\n float opacity = styleMappingMat[0][0];\n float d_distance_ratio = styleMappingMat[3].r; // \u5F53\u524D\u70B9\u4F4D\u8DDD\u79BB\u5360\u7EBF\u603B\u957F\u7684\u6BD4\u4F8B\n\n\n if(u_arrow > 0.0 && distanceAndIndex < 2.0) { // arrow\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20 || u_CoordinateSystem == COORDINATE_SYSTEM_P20_OFFSET) { \n if(cross(vec3(styleMappingMat[1].rg, 0.0), vec3(styleMappingMat[1].ba, 0.0)).z < 0.0) { // amap\n discard;\n }\n } else { // amap2 mapbox map\n if(cross(vec3(styleMappingMat[1].rg, 0.0), vec3(styleMappingMat[1].ba, 0.0)).z > 0.0) { \n discard;\n }\n }\n } else { // line body\n if(miter < 0.0) {\n discard;\n }\n }\n\n\n if(u_linearColor == 1.0) { // \u4F7F\u7528\u6E10\u53D8\u989C\u8272\n gl_FragColor = mix(u_sourceColor, u_targetColor, d_distance_ratio);\n } else { // \u4F7F\u7528 color \u65B9\u6CD5\u4F20\u5165\u7684\u989C\u8272\n gl_FragColor = v_color;\n }\n\n gl_FragColor.a *= opacity; // \u5168\u5C40\u900F\u660E\u5EA6\n gl_FragColor = filterColor(gl_FragColor);\n}\n";
|
|
35
|
+
var line_half_vert = "attribute float a_Miter;\nattribute vec4 a_Color;\nattribute vec2 a_Size;\nattribute vec3 a_Normal;\nattribute vec3 a_Position;\n\n// dash line\nattribute vec4 a_dirPoints;\nattribute vec3 a_DistanceAndIndex;\n\nuniform vec4 u_lineDir;\n\nuniform mat4 u_ModelMatrix;\nuniform mat4 u_Mvp;\n\n#pragma include \"projection\"\n#pragma include \"picking\"\n\nvarying vec4 v_color;\n\nuniform float u_linearColor: 0;\nuniform float u_arrow: 0.0;\nuniform float u_arrowHeight: 3.0;\nuniform float u_arrowWidth: 2.0;\nuniform float u_tailWidth: 1.0;\n\nuniform float u_opacity: 1.0;\nvarying mat4 styleMappingMat; // \u7528\u4E8E\u5C06\u5728\u9876\u70B9\u7740\u8272\u5668\u4E2D\u8BA1\u7B97\u597D\u7684\u6837\u5F0F\u503C\u4F20\u9012\u7ED9\u7247\u5143\n\n#pragma include \"styleMapping\"\n#pragma include \"styleMappingCalOpacity\"\n\nvec2 calculateArrow(vec2 offset) {\n /*\n * \u5728\u652F\u6301\u7BAD\u5934\u7684\u65F6\u5019\uFF0C\u7B2C\u4E8C\u3001\u7B2C\u4E09\u7EC4\u9876\u70B9\u662F\u989D\u5916\u63D2\u5165\u7528\u4E8E\u6784\u5EFA\u9876\u70B9\u7684\n */\n float arrowFlag = -1.0;\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) {\n // \u9AD8\u5FB7 2.0 \u7684\u65CB\u8F6C\u89D2\u5EA6\u4E0D\u540C\n arrowFlag = 1.0;\n }\n float pi = arrowFlag * 3.1415926/2.;\n if(a_Miter < 0.) {\n // \u6839\u636E\u7EBF\u7684\u4E24\u4FA7\u504F\u79FB\u4E0D\u540C\u3001\u65CB\u8F6C\u7684\u65B9\u5411\u76F8\u53CD\n pi = -pi;\n }\n highp float angle_sin = sin(pi);\n highp float angle_cos = cos(pi);\n // \u8BA1\u7B97\u5782\u76F4\u4E0E\u7EBF\u65B9\u5411\u7684\u65CB\u8F6C\u77E9\u9635\n mat2 rotation_matrix = mat2(angle_cos, -1.0 * angle_sin, angle_sin, angle_cos);\n float arrowWidth = u_arrowWidth;\n float arrowHeight = u_arrowHeight;\n\n vec2 arrowOffset = vec2(0.0);\n /*\n * a_DistanceAndIndex.y \u7528\u4E8E\u6807\u8BB0\u5F53\u524D\u9876\u70B9\u5C5E\u4E8E\u54EA\u4E00\u7EC4\uFF08\u4E24\u4E2A\u9876\u70B9\u4E00\u7EC4\uFF0C\u6784\u6210\u7EBF\u7684\u5176\u5B9E\u662F\u77E9\u5F62\uFF0C\u6700\u7B80\u9700\u8981\u56DB\u4E2A\u9876\u70B9\u3001\u4E24\u7EC4\u9876\u70B9\u6784\u6210\uFF09\n */\n if(a_DistanceAndIndex.y == 0.0) {\n // \u7BAD\u5934\u5C16\u90E8\n offset = vec2(0.0);\n } else if(a_DistanceAndIndex.y == 1.0) {\n // \u7BAD\u5934\u4E24\u4FA7\n arrowOffset = rotation_matrix*(offset * arrowHeight);\n offset += arrowOffset; // \u6CBF\u7EBF\u504F\u79FB\n offset = offset * arrowWidth; // \u5782\u76F4\u7EBF\u5411\u5916\u504F\u79FB\uFF08\u662F\u6784\u5EFA\u7BAD\u5934\u4E24\u4FA7\u7684\u9876\u70B9\uFF09\n } else if(a_DistanceAndIndex.y == 2.0 || a_DistanceAndIndex.y == 3.0 || a_DistanceAndIndex.y == 4.0) {\n // \u504F\u79FB\u5176\u4F59\u7684\u70B9\u4F4D\uFF08\u5C06\u957F\u5EA6\u8BA9\u4F4D\u7ED9\u7BAD\u5934\uFF09\n arrowOffset = rotation_matrix*(offset * arrowHeight) * arrowWidth;\n offset += arrowOffset;// \u6CBF\u7EBF\u504F\u79FB\n }\n\n return offset;\n}\n\nvoid main() {\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n styleMappingMat = mat4(\n 0.0, 0.0, 0.0, 0.0, // opacity - strokeOpacity - a_Miter - a_DistanceAndIndex\n 0.0, 0.0, 0.0, 0.0, // originX - originY - vectorX - vectorY\n 0.0, 0.0, 0.0, 0.0, // offsets[0] - offsets[1]\n 0.0, 0.0, 0.0, 0.0 // distance_ratio/distance/pixelLen/texV\n );\n styleMappingMat[0][3] = a_DistanceAndIndex.y;\n styleMappingMat[0][2] = a_Miter;\n\n float rowCount = u_cellTypeLayout[0][0]; // \u5F53\u524D\u7684\u6570\u636E\u7EB9\u7406\u6709\u51E0\u884C\n float columnCount = u_cellTypeLayout[0][1]; // \u5F53\u770B\u5230\u6570\u636E\u7EB9\u7406\u6709\u51E0\u5217\n float columnWidth = 1.0/columnCount; // \u5217\u5BBD\n float rowHeight = 1.0/rowCount; // \u884C\u9AD8\n float cellCount = calCellCount(); // opacity - strokeOpacity - strokeWidth - stroke - offsets\n float id = a_vertexId; // \u7B2Cn\u4E2A\u9876\u70B9\n float cellCurrentRow = floor(id * cellCount / columnCount) + 1.0; // \u8D77\u59CB\u70B9\u5728\u7B2C\u51E0\u884C\n float cellCurrentColumn = mod(id * cellCount, columnCount) + 1.0; // \u8D77\u59CB\u70B9\u5728\u7B2C\u51E0\u5217\n \n // cell \u56FA\u5B9A\u987A\u5E8F opacity -> strokeOpacity -> strokeWidth -> stroke ... \n // \u6309\u987A\u5E8F\u4ECE cell \u4E2D\u53D6\u503C\u3001\u82E5\u6CA1\u6709\u5219\u81EA\u52A8\u5F80\u4E0B\u53D6\u503C\n float textureOffset = 0.0; // \u5728 cell \u4E2D\u53D6\u503C\u7684\u504F\u79FB\u91CF\n\n vec2 opacityAndOffset = calOpacityAndOffset(cellCurrentRow, cellCurrentColumn, columnCount, textureOffset, columnWidth, rowHeight);\n styleMappingMat[0][0] = opacityAndOffset.r;\n textureOffset = opacityAndOffset.g;\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n\n\n v_color = a_Color;\n\n vec3 size = a_Miter * setPickingSize(a_Size.x) * reverse_offset_normal(a_Normal);\n \n vec2 offset = project_pixel(size.xy);\n\n // styleMappingMat[1].rg = a_Position.xy + offset;\n\n vec2 copyOffset = vec2(offset.x, offset.y);\n\n float lineDistance = a_DistanceAndIndex.x;\n float total_Distance = a_DistanceAndIndex.z;\n float currentLinePointRatio = lineDistance / total_Distance;\n \n if(u_arrow > 0.0) {\n // \u8BA1\u7B97\u7BAD\u5934\n offset = calculateArrow(offset);\n\n if(a_DistanceAndIndex.y > 4.0) {\n offset *= mix(1.0, u_tailWidth, currentLinePointRatio);\n }\n }\n\n float lineOffsetWidth = length(offset + offset * sign(a_Miter)); // \u7EBF\u6A2A\u5411\u504F\u79FB\u7684\u8DDD\u79BB\uFF08\u5411\u4E24\u4FA7\u504F\u79FB\u7684\u548C\uFF09\n float linePixelSize = project_pixel(a_Size.x) * 2.0; // \u5B9A\u70B9\u4F4D\u7F6E\u504F\u79FB\uFF0C\u6309\u5730\u56FE\u7B49\u7EA7\u7F29\u653E\u540E\u7684\u8DDD\u79BB \u5355\u4FA7 * 2\n\n // \u8BBE\u7F6E\u6570\u636E\u96C6\u7684\u53C2\u6570\n styleMappingMat[3][0] = currentLinePointRatio; // \u5F53\u524D\u70B9\u4F4D\u8DDD\u79BB\u5360\u7EBF\u603B\u957F\u7684\u6BD4\u4F8B\n styleMappingMat[3][1] = lineDistance; // \u5F53\u524D\u9876\u70B9\u7684\u8DDD\u79BB\n\n vec4 project_pos = project_position(vec4(a_Position.xy, 0, 1.0));\n\n // gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy + offset, a_Size.y, 1.0));\n\n float h = float(a_Position.z); // \u7EBF\u9876\u70B9\u7684\u9AD8\u5EA6 - \u517C\u5BB9\u4E0D\u5B58\u5728\u7B2C\u4E09\u4E2A\u6570\u503C\u7684\u60C5\u51B5 vertex height\n float lineHeight = a_Size.y; // size \u7B2C\u4E8C\u4E2A\u53C2\u6570\u4EE3\u8868\u7684\u9AD8\u5EA6 [linewidth, lineheight]\n\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) { // gaode2.x\n lineHeight *= 0.2; // \u4FDD\u6301\u548C amap/mapbox \u4E00\u81F4\u7684\u6548\u679C\n gl_Position = u_Mvp * (vec4(project_pos.xy + offset, lineHeight, 1.0));\n } else {\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy + offset, lineHeight, 1.0));\n }\n \n if(u_arrow > 0.0 && a_DistanceAndIndex.y < 2.0) {\n vec2 startPoint = a_dirPoints.rg;\n vec2 endPoint = a_dirPoints.ba;\n vec4 t1 = project_position(vec4(startPoint, 0, 1.0));\n vec4 t2 = project_position(vec4(endPoint, 0, 1.0));\n // TODO\uFF1A \u540E\u7EED\u4F18\u5316\u53EF\u4EE5\u628A\u4F4D\u7F6E\u8BA1\u7B97\u653E\u5728 cpu \u4E2D\u5B8C\u6210\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) { // gaode2.x\n vec2 p1 = (u_Mvp * vec4(t1.xy, 0.0, 1.0)).xy;\n vec2 p2 = (u_Mvp * vec4(t2.xy, 0.0, 1.0)).xy;\n styleMappingMat[1].rg = normalize(p1 - p2);\n styleMappingMat[1].ba = normalize(gl_Position.xy - p2);\n } else {\n vec2 p1 = project_common_position_to_clipspace(vec4(t1.xy, 0.0, 1.0)).xy;\n vec2 p2 = project_common_position_to_clipspace(vec4(t2.xy, 0.0, 1.0)).xy;\n styleMappingMat[1].rg = normalize(p1 - p2);\n styleMappingMat[1].ba = normalize(gl_Position.xy - p2);\n }\n }\n\n setPickingColor(a_PickingColor);\n}\n";
|
|
36
|
+
|
|
37
|
+
var LineModel = function (_BaseModel) {
|
|
38
|
+
(0, _inherits2.default)(LineModel, _BaseModel);
|
|
39
|
+
|
|
40
|
+
var _super = _createSuper(LineModel);
|
|
41
|
+
|
|
42
|
+
function LineModel() {
|
|
43
|
+
(0, _classCallCheck2.default)(this, LineModel);
|
|
44
|
+
return _super.apply(this, arguments);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
(0, _createClass2.default)(LineModel, [{
|
|
48
|
+
key: "getUninforms",
|
|
49
|
+
value: function getUninforms() {
|
|
50
|
+
var _ref = this.layer.getLayerConfig(),
|
|
51
|
+
_ref$opacity = _ref.opacity,
|
|
52
|
+
opacity = _ref$opacity === void 0 ? 1 : _ref$opacity,
|
|
53
|
+
sourceColor = _ref.sourceColor,
|
|
54
|
+
targetColor = _ref.targetColor,
|
|
55
|
+
_ref$arrow = _ref.arrow,
|
|
56
|
+
arrow = _ref$arrow === void 0 ? {
|
|
57
|
+
enable: false,
|
|
58
|
+
arrowWidth: 2,
|
|
59
|
+
arrowHeight: 3,
|
|
60
|
+
tailWidth: 1
|
|
61
|
+
} : _ref$arrow;
|
|
62
|
+
|
|
63
|
+
var useLinearColor = 0;
|
|
64
|
+
var sourceColorArr = [0, 0, 0, 0];
|
|
65
|
+
var targetColorArr = [0, 0, 0, 0];
|
|
66
|
+
|
|
67
|
+
if (sourceColor && targetColor) {
|
|
68
|
+
sourceColorArr = (0, _l7Utils.rgb2arr)(sourceColor);
|
|
69
|
+
targetColorArr = (0, _l7Utils.rgb2arr)(targetColor);
|
|
70
|
+
useLinearColor = 1;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (this.dataTextureTest && this.dataTextureNeedUpdate({
|
|
74
|
+
opacity: opacity
|
|
75
|
+
})) {
|
|
76
|
+
this.judgeStyleAttributes({
|
|
77
|
+
opacity: opacity
|
|
78
|
+
});
|
|
79
|
+
var encodeData = this.layer.getEncodedData();
|
|
80
|
+
|
|
81
|
+
var _this$calDataFrame = this.calDataFrame(this.cellLength, encodeData, this.cellProperties),
|
|
82
|
+
data = _this$calDataFrame.data,
|
|
83
|
+
width = _this$calDataFrame.width,
|
|
84
|
+
height = _this$calDataFrame.height;
|
|
85
|
+
|
|
86
|
+
this.rowCount = height;
|
|
87
|
+
this.dataTexture = this.cellLength > 0 && data.length > 0 ? this.createTexture2D({
|
|
88
|
+
flipY: true,
|
|
89
|
+
data: data,
|
|
90
|
+
format: _l7Core.gl.LUMINANCE,
|
|
91
|
+
type: _l7Core.gl.FLOAT,
|
|
92
|
+
width: width,
|
|
93
|
+
height: height
|
|
94
|
+
}) : this.createTexture2D({
|
|
95
|
+
flipY: true,
|
|
96
|
+
data: [1],
|
|
97
|
+
format: _l7Core.gl.LUMINANCE,
|
|
98
|
+
type: _l7Core.gl.FLOAT,
|
|
99
|
+
width: 1,
|
|
100
|
+
height: 1
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
u_dataTexture: this.dataTexture,
|
|
106
|
+
u_cellTypeLayout: this.getCellTypeLayout(),
|
|
107
|
+
u_opacity: (0, _isNumber2.default)(opacity) ? opacity : 1.0,
|
|
108
|
+
u_linearColor: useLinearColor,
|
|
109
|
+
u_sourceColor: sourceColorArr,
|
|
110
|
+
u_targetColor: targetColorArr,
|
|
111
|
+
u_arrow: Number(arrow.enable),
|
|
112
|
+
u_arrowHeight: arrow.arrowHeight || 3,
|
|
113
|
+
u_arrowWidth: arrow.arrowWidth || 2,
|
|
114
|
+
u_tailWidth: arrow.tailWidth === undefined ? 1 : arrow.tailWidth
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}, {
|
|
118
|
+
key: "initModels",
|
|
119
|
+
value: function initModels() {
|
|
120
|
+
return this.buildModels();
|
|
121
|
+
}
|
|
122
|
+
}, {
|
|
123
|
+
key: "clearModels",
|
|
124
|
+
value: function clearModels() {
|
|
125
|
+
var _this$dataTexture;
|
|
126
|
+
|
|
127
|
+
(_this$dataTexture = this.dataTexture) === null || _this$dataTexture === void 0 ? void 0 : _this$dataTexture.destroy();
|
|
128
|
+
}
|
|
129
|
+
}, {
|
|
130
|
+
key: "buildModels",
|
|
131
|
+
value: function buildModels() {
|
|
132
|
+
var _ref2 = this.layer.getLayerConfig(),
|
|
133
|
+
_ref2$mask = _ref2.mask,
|
|
134
|
+
mask = _ref2$mask === void 0 ? false : _ref2$mask,
|
|
135
|
+
_ref2$maskInside = _ref2.maskInside,
|
|
136
|
+
maskInside = _ref2$maskInside === void 0 ? true : _ref2$maskInside,
|
|
137
|
+
_ref2$depth = _ref2.depth,
|
|
138
|
+
depth = _ref2$depth === void 0 ? false : _ref2$depth;
|
|
139
|
+
|
|
140
|
+
var _this$getShaders = this.getShaders(),
|
|
141
|
+
frag = _this$getShaders.frag,
|
|
142
|
+
vert = _this$getShaders.vert;
|
|
143
|
+
|
|
144
|
+
this.layer.triangulation = _triangulation.LineTriangulation;
|
|
145
|
+
return [this.layer.buildLayerModel({
|
|
146
|
+
moduleName: 'line_half',
|
|
147
|
+
vertexShader: vert,
|
|
148
|
+
fragmentShader: frag,
|
|
149
|
+
triangulation: _triangulation.LineTriangulation,
|
|
150
|
+
primitive: _l7Core.gl.TRIANGLES,
|
|
151
|
+
blend: this.getBlend(),
|
|
152
|
+
depth: {
|
|
153
|
+
enable: depth
|
|
154
|
+
},
|
|
155
|
+
stencil: (0, _l7Utils.getMask)(mask, maskInside)
|
|
156
|
+
})];
|
|
157
|
+
}
|
|
158
|
+
}, {
|
|
159
|
+
key: "getShaders",
|
|
160
|
+
value: function getShaders() {
|
|
161
|
+
return {
|
|
162
|
+
frag: line_half_frag,
|
|
163
|
+
vert: line_half_vert,
|
|
164
|
+
type: 'normal'
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}, {
|
|
168
|
+
key: "registerBuiltinAttributes",
|
|
169
|
+
value: function registerBuiltinAttributes() {
|
|
170
|
+
this.styleAttributeService.registerStyleAttribute({
|
|
171
|
+
name: 'distanceAndIndex',
|
|
172
|
+
type: _l7Core.AttributeType.Attribute,
|
|
173
|
+
descriptor: {
|
|
174
|
+
name: 'a_DistanceAndIndex',
|
|
175
|
+
buffer: {
|
|
176
|
+
usage: _l7Core.gl.STATIC_DRAW,
|
|
177
|
+
data: [],
|
|
178
|
+
type: _l7Core.gl.FLOAT
|
|
179
|
+
},
|
|
180
|
+
size: 3,
|
|
181
|
+
update: function update(feature, featureIdx, vertex, attributeIdx, normal, vertexIndex) {
|
|
182
|
+
return vertexIndex === undefined ? [vertex[3], 10, vertex[5]] : [vertex[3], vertexIndex, vertex[5]];
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
this.styleAttributeService.registerStyleAttribute({
|
|
187
|
+
name: 'dirPoints',
|
|
188
|
+
type: _l7Core.AttributeType.Attribute,
|
|
189
|
+
descriptor: {
|
|
190
|
+
name: 'a_dirPoints',
|
|
191
|
+
buffer: {
|
|
192
|
+
usage: _l7Core.gl.STATIC_DRAW,
|
|
193
|
+
data: [],
|
|
194
|
+
type: _l7Core.gl.FLOAT
|
|
195
|
+
},
|
|
196
|
+
size: 4,
|
|
197
|
+
update: function update(feature, featureIdx, vertex, attributeIdx) {
|
|
198
|
+
var startPoint = feature.coordinates[0] || [0, 0];
|
|
199
|
+
var endPoint = feature.coordinates[3] || [0, 0];
|
|
200
|
+
return [startPoint[0], startPoint[1], endPoint[0], endPoint[1]];
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
});
|
|
204
|
+
this.styleAttributeService.registerStyleAttribute({
|
|
205
|
+
name: 'size',
|
|
206
|
+
type: _l7Core.AttributeType.Attribute,
|
|
207
|
+
descriptor: {
|
|
208
|
+
name: 'a_Size',
|
|
209
|
+
buffer: {
|
|
210
|
+
usage: _l7Core.gl.DYNAMIC_DRAW,
|
|
211
|
+
data: [],
|
|
212
|
+
type: _l7Core.gl.FLOAT
|
|
213
|
+
},
|
|
214
|
+
size: 2,
|
|
215
|
+
update: function update(feature, featureIdx, vertex, attributeIdx) {
|
|
216
|
+
var _feature$size = feature.size,
|
|
217
|
+
size = _feature$size === void 0 ? 1 : _feature$size;
|
|
218
|
+
return Array.isArray(size) ? [size[0], size[1]] : [size, 0];
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
});
|
|
222
|
+
this.styleAttributeService.registerStyleAttribute({
|
|
223
|
+
name: 'normal',
|
|
224
|
+
type: _l7Core.AttributeType.Attribute,
|
|
225
|
+
descriptor: {
|
|
226
|
+
name: 'a_Normal',
|
|
227
|
+
buffer: {
|
|
228
|
+
usage: _l7Core.gl.STATIC_DRAW,
|
|
229
|
+
data: [],
|
|
230
|
+
type: _l7Core.gl.FLOAT
|
|
231
|
+
},
|
|
232
|
+
size: 3,
|
|
233
|
+
update: function update(feature, featureIdx, vertex, attributeIdx, normal) {
|
|
234
|
+
return normal;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
this.styleAttributeService.registerStyleAttribute({
|
|
239
|
+
name: 'miter',
|
|
240
|
+
type: _l7Core.AttributeType.Attribute,
|
|
241
|
+
descriptor: {
|
|
242
|
+
name: 'a_Miter',
|
|
243
|
+
buffer: {
|
|
244
|
+
usage: _l7Core.gl.STATIC_DRAW,
|
|
245
|
+
data: [],
|
|
246
|
+
type: _l7Core.gl.FLOAT
|
|
247
|
+
},
|
|
248
|
+
size: 1,
|
|
249
|
+
update: function update(feature, featureIdx, vertex, attributeIdx) {
|
|
250
|
+
return [vertex[4]];
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
}
|
|
255
|
+
}]);
|
|
256
|
+
return LineModel;
|
|
257
|
+
}(_BaseModel2.default);
|
|
258
|
+
|
|
259
|
+
exports.default = LineModel;
|
|
260
|
+
//# sourceMappingURL=half.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/line/models/half.ts"],"names":["LineModel","layer","getLayerConfig","opacity","sourceColor","targetColor","arrow","enable","arrowWidth","arrowHeight","tailWidth","useLinearColor","sourceColorArr","targetColorArr","dataTextureTest","dataTextureNeedUpdate","judgeStyleAttributes","encodeData","getEncodedData","calDataFrame","cellLength","cellProperties","data","width","height","rowCount","dataTexture","length","createTexture2D","flipY","format","gl","LUMINANCE","type","FLOAT","u_dataTexture","u_cellTypeLayout","getCellTypeLayout","u_opacity","u_linearColor","u_sourceColor","u_targetColor","u_arrow","Number","u_arrowHeight","u_arrowWidth","u_tailWidth","undefined","buildModels","destroy","mask","maskInside","depth","getShaders","frag","vert","triangulation","LineTriangulation","buildLayerModel","moduleName","vertexShader","fragmentShader","primitive","TRIANGLES","blend","getBlend","stencil","line_half_frag","line_half_vert","styleAttributeService","registerStyleAttribute","name","AttributeType","Attribute","descriptor","buffer","usage","STATIC_DRAW","size","update","feature","featureIdx","vertex","attributeIdx","normal","vertexIndex","startPoint","coordinates","endPoint","DYNAMIC_DRAW","Array","isArray","BaseModel"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;;AAOA;;AAEA;;AAEA;;;;;;;;;IAIqBA,S;;;;;;;;;;;;WACnB,wBAAqC;AACnC,iBAUI,KAAKC,KAAL,CAAWC,cAAX,EAVJ;AAAA,8BACEC,OADF;AAAA,UACEA,OADF,6BACY,CADZ;AAAA,UAEEC,WAFF,QAEEA,WAFF;AAAA,UAGEC,WAHF,QAGEA,WAHF;AAAA,4BAIEC,KAJF;AAAA,UAIEA,KAJF,2BAIU;AACNC,QAAAA,MAAM,EAAE,KADF;AAENC,QAAAA,UAAU,EAAE,CAFN;AAGNC,QAAAA,WAAW,EAAE,CAHP;AAINC,QAAAA,SAAS,EAAE;AAJL,OAJV;;AAaA,UAAIC,cAAc,GAAG,CAArB;AACA,UAAIC,cAAc,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,CAArB;AACA,UAAIC,cAAc,GAAG,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,CAArB;;AACA,UAAIT,WAAW,IAAIC,WAAnB,EAAgC;AAC9BO,QAAAA,cAAc,GAAG,sBAAQR,WAAR,CAAjB;AACAS,QAAAA,cAAc,GAAG,sBAAQR,WAAR,CAAjB;AACAM,QAAAA,cAAc,GAAG,CAAjB;AACD;;AAED,UAAI,KAAKG,eAAL,IAAwB,KAAKC,qBAAL,CAA2B;AAAEZ,QAAAA,OAAO,EAAPA;AAAF,OAA3B,CAA5B,EAAqE;AACn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;AAChDC,QAAAA,IAAI,EAAE,QAD0C;AAEhDtC,QAAAA,IAAI,EAAEuC,sBAAcC,SAF4B;AAGhDC,QAAAA,UAAU,EAAE;AACVH,UAAAA,IAAI,EAAE,UADI;AAEVI,UAAAA,MAAM,EAAE;AAENC,YAAAA,KAAK,EAAE7C,WAAG8C,WAFJ;AAGNvD,YAAAA,IAAI,EAAE,EAHA;AAINW,YAAAA,IAAI,EAAEF,WAAGG;AAJH,WAFE;AAQV4C,UAAAA,IAAI,EAAE,CARI;AASVC,UAAAA,MAAM,EAAE,gBACNC,OADM,EAENC,UAFM,EAGNC,MAHM,EAINC,YAJM,EAKNC,MALM,EAMH;AACH,mBAAOA,MAAP;AACD;AAjBS;AAHoC,OAAlD;AAwBA,WAAKf,qBAAL,CAA2BC,sBAA3B,CAAkD;AAChDC,QAAAA,IAAI,EAAE,OAD0C;AAEhDtC,QAAAA,IAAI,EAAEuC,sBAAcC,SAF4B;AAGhDC,QAAAA,UAAU,EAAE;AACVH,UAAAA,IAAI,EAAE,SADI;AAEVI,UAAAA,MAAM,EAAE;AAENC,YAAAA,KAAK,EAAE7C,WAAG8C,WAFJ;AAGNvD,YAAAA,IAAI,EAAE,EAHA;AAINW,YAAAA,IAAI,EAAEF,WAAGG;AAJH,WAFE;AAQV4C,UAAAA,IAAI,EAAE,CARI;AASVC,UAAAA,MAAM,EAAE,gBACNC,OADM,EAENC,UAFM,EAGNC,MAHM,EAINC,YAJM,EAKH;AACH,mBAAO,CAACD,MAAM,CAAC,CAAD,CAAP,CAAP;AACD;AAhBS;AAHoC,OAAlD;AAsBD;;;EA9OoCU,mB","sourcesContent":["import {\n AttributeType,\n gl,\n IEncodeFeature,\n IModel,\n IModelUniform,\n} from '@antv/l7-core';\nimport { getMask, rgb2arr } from '@antv/l7-utils';\nimport { isNumber } from 'lodash';\nimport BaseModel from '../../core/BaseModel';\nimport { ILineLayerStyleOptions } from '../../core/interface';\nimport { LineTriangulation } from '../../core/triangulation';\nimport line_half_frag from '../shaders/half/line_half_frag.glsl';\nimport line_half_vert from '../shaders/half/line_half_vert.glsl';\n\nexport default class LineModel extends BaseModel {\n public getUninforms(): IModelUniform {\n const {\n opacity = 1,\n sourceColor,\n targetColor,\n arrow = {\n enable: false,\n arrowWidth: 2,\n arrowHeight: 3,\n tailWidth: 1,\n },\n } = this.layer.getLayerConfig() as ILineLayerStyleOptions;\n\n // 转化渐变色\n let useLinearColor = 0; // 默认不生效\n let sourceColorArr = [0, 0, 0, 0];\n let targetColorArr = [0, 0, 0, 0];\n if (sourceColor && targetColor) {\n sourceColorArr = rgb2arr(sourceColor);\n targetColorArr = rgb2arr(targetColor);\n useLinearColor = 1;\n }\n\n if (this.dataTextureTest && this.dataTextureNeedUpdate({ opacity })) {\n this.judgeStyleAttributes({ opacity });\n const encodeData = this.layer.getEncodedData();\n const { data, width, height } = this.calDataFrame(\n this.cellLength,\n encodeData,\n this.cellProperties,\n );\n this.rowCount = height; // 当前数据纹理有多少行\n\n this.dataTexture =\n this.cellLength > 0 && data.length > 0\n ? this.createTexture2D({\n flipY: true,\n data,\n format: gl.LUMINANCE,\n type: gl.FLOAT,\n width,\n height,\n })\n : this.createTexture2D({\n flipY: true,\n data: [1],\n format: gl.LUMINANCE,\n type: gl.FLOAT,\n width: 1,\n height: 1,\n });\n }\n return {\n u_dataTexture: this.dataTexture, // 数据纹理 - 有数据映射的时候纹理中带数据,若没有任何数据映射时纹理是 [1]\n u_cellTypeLayout: this.getCellTypeLayout(),\n u_opacity: isNumber(opacity) ? opacity : 1.0,\n\n // 渐变色支持参数\n u_linearColor: useLinearColor,\n u_sourceColor: sourceColorArr,\n u_targetColor: targetColorArr,\n\n // arrow\n u_arrow: Number(arrow.enable),\n u_arrowHeight: arrow.arrowHeight || 3,\n u_arrowWidth: arrow.arrowWidth || 2,\n u_tailWidth: arrow.tailWidth === undefined ? 1 : arrow.tailWidth,\n };\n }\n\n public initModels(): IModel[] {\n return this.buildModels();\n }\n\n public clearModels() {\n this.dataTexture?.destroy();\n }\n\n public buildModels(): IModel[] {\n const {\n mask = false,\n maskInside = true,\n depth = false,\n } = this.layer.getLayerConfig() as ILineLayerStyleOptions;\n const { frag, vert } = this.getShaders();\n this.layer.triangulation = LineTriangulation;\n return [\n this.layer.buildLayerModel({\n moduleName: 'line_half',\n vertexShader: vert,\n fragmentShader: frag,\n triangulation: LineTriangulation,\n primitive: gl.TRIANGLES,\n blend: this.getBlend(),\n depth: { enable: depth },\n stencil: getMask(mask, maskInside),\n }),\n ];\n }\n\n /**\n * 根据参数获取不同的 shader 代码\n * @returns\n */\n public getShaders(): { frag: string; vert: string; type: string } {\n return {\n frag: line_half_frag,\n vert: line_half_vert,\n type: 'normal',\n };\n }\n\n protected registerBuiltinAttributes() {\n this.styleAttributeService.registerStyleAttribute({\n name: 'distanceAndIndex',\n type: AttributeType.Attribute,\n descriptor: {\n name: 'a_DistanceAndIndex',\n buffer: {\n // give the WebGL driver a hint that this buffer may change\n usage: gl.STATIC_DRAW,\n data: [],\n type: gl.FLOAT,\n },\n size: 3,\n update: (\n feature: IEncodeFeature,\n featureIdx: number,\n vertex: number[],\n attributeIdx: number,\n normal: number[],\n vertexIndex?: number,\n ) => {\n return vertexIndex === undefined\n ? [vertex[3], 10, vertex[5]]\n : [vertex[3], vertexIndex, vertex[5]];\n },\n },\n });\n this.styleAttributeService.registerStyleAttribute({\n name: 'dirPoints',\n type: AttributeType.Attribute,\n descriptor: {\n name: 'a_dirPoints',\n buffer: {\n // give the WebGL driver a hint that this buffer may change\n usage: gl.STATIC_DRAW,\n data: [],\n type: gl.FLOAT,\n },\n size: 4,\n update: (\n feature: IEncodeFeature,\n featureIdx: number,\n vertex: number[],\n attributeIdx: number,\n ) => {\n // console.log(feature)\n const startPoint = (feature.coordinates[0] || [0, 0]) as number[];\n const endPoint = (feature.coordinates[3] || [0, 0]) as number[];\n\n return [startPoint[0], startPoint[1], endPoint[0], endPoint[1]];\n },\n },\n });\n\n this.styleAttributeService.registerStyleAttribute({\n name: 'size',\n type: AttributeType.Attribute,\n descriptor: {\n name: 'a_Size',\n buffer: {\n // give the WebGL driver a hint that this buffer may change\n usage: gl.DYNAMIC_DRAW,\n data: [],\n type: gl.FLOAT,\n },\n size: 2,\n update: (\n feature: IEncodeFeature,\n featureIdx: number,\n vertex: number[],\n attributeIdx: number,\n ) => {\n const { size = 1 } = feature;\n return Array.isArray(size) ? [size[0], size[1]] : [size as number, 0];\n },\n },\n });\n\n // point layer size;\n this.styleAttributeService.registerStyleAttribute({\n name: 'normal',\n type: AttributeType.Attribute,\n descriptor: {\n name: 'a_Normal',\n buffer: {\n // give the WebGL driver a hint that this buffer may change\n usage: gl.STATIC_DRAW,\n data: [],\n type: gl.FLOAT,\n },\n size: 3,\n update: (\n feature: IEncodeFeature,\n featureIdx: number,\n vertex: number[],\n attributeIdx: number,\n normal: number[],\n ) => {\n return normal;\n },\n },\n });\n\n this.styleAttributeService.registerStyleAttribute({\n name: 'miter',\n type: AttributeType.Attribute,\n descriptor: {\n name: 'a_Miter',\n buffer: {\n // give the WebGL driver a hint that this buffer may change\n usage: gl.STATIC_DRAW,\n data: [],\n type: gl.FLOAT,\n },\n size: 1,\n update: (\n feature: IEncodeFeature,\n featureIdx: number,\n vertex: number[],\n attributeIdx: number,\n ) => {\n return [vertex[4]];\n },\n },\n });\n }\n}\n"],"file":"half.js"}
|
package/lib/line/models/index.js
CHANGED
|
@@ -17,6 +17,8 @@ var _arcmini = _interopRequireDefault(require("./arcmini"));
|
|
|
17
17
|
|
|
18
18
|
var _great_circle = _interopRequireDefault(require("./great_circle"));
|
|
19
19
|
|
|
20
|
+
var _half = _interopRequireDefault(require("./half"));
|
|
21
|
+
|
|
20
22
|
var _line = _interopRequireDefault(require("./line"));
|
|
21
23
|
|
|
22
24
|
var _linearline = _interopRequireDefault(require("./linearline"));
|
|
@@ -34,6 +36,7 @@ var LineModels = {
|
|
|
34
36
|
greatcircle: _great_circle.default,
|
|
35
37
|
wall: _wall.default,
|
|
36
38
|
line: _line.default,
|
|
39
|
+
halfLine: _half.default,
|
|
37
40
|
simple: _simpleLine.default,
|
|
38
41
|
linearline: _linearline.default,
|
|
39
42
|
vectorline: _tileModel.default,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/line/models/index.ts"],"names":["LineModels","arc","ArcModel","arcmini","ArcMiniModel","arc3d","Arc3DModel","greatcircle","GreatCircleModel","wall","LineWallModel","line","LineModel","simple","SimpleLineModel","linearline","LinearLine","vectorline","LineTileModel","tileLine","TileLineModel"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;
|
|
1
|
+
{"version":3,"sources":["../../../src/line/models/index.ts"],"names":["LineModels","arc","ArcModel","arcmini","ArcMiniModel","arc3d","Arc3DModel","greatcircle","GreatCircleModel","wall","LineWallModel","line","LineModel","halfLine","LineHalfModel","simple","SimpleLineModel","linearline","LinearLine","vectorline","LineTileModel","tileLine","TileLineModel"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAeA,IAAMA,UAA2C,GAAG;AAClDC,EAAAA,GAAG,EAAEC,YAD6C;AAElDC,EAAAA,OAAO,EAAEC,gBAFyC;AAGlDC,EAAAA,KAAK,EAAEC,eAH2C;AAIlDC,EAAAA,WAAW,EAAEC,qBAJqC;AAKlDC,EAAAA,IAAI,EAAEC,aAL4C;AAMlDC,EAAAA,IAAI,EAAEC,aAN4C;AAOlDC,EAAAA,QAAQ,EAAEC,aAPwC;AAQlDC,EAAAA,MAAM,EAAEC,mBAR0C;AASlDC,EAAAA,UAAU,EAAEC,mBATsC;AAUlDC,EAAAA,UAAU,EAAEC,kBAVsC;AAWlDC,EAAAA,QAAQ,EAAEC;AAXwC,CAApD;eAcetB,U","sourcesContent":["import LineTileModel from '../../tile/models/tileModel';\nimport ArcModel from './arc';\nimport Arc3DModel from './arc_3d';\nimport ArcMiniModel from './arcmini';\nimport GreatCircleModel from './great_circle';\nimport LineHalfModel from './half';\nimport LineModel from './line';\nimport LinearLine from './linearline';\nimport SimpleLineModel from './simpleLine';\nimport TileLineModel from './tile';\nimport LineWallModel from './wall';\n\nexport type LineModelType =\n | 'arc'\n | 'arcmini'\n | 'arc3d'\n | 'greatcircle'\n | 'wall'\n | 'simple'\n | 'line'\n | 'halfLine'\n | 'linearline'\n | 'vectorline'\n | 'tileLine';\n\nconst LineModels: { [key in LineModelType]: any } = {\n arc: ArcModel,\n arcmini: ArcMiniModel,\n arc3d: Arc3DModel,\n greatcircle: GreatCircleModel,\n wall: LineWallModel,\n line: LineModel,\n halfLine: LineHalfModel,\n simple: SimpleLineModel,\n linearline: LinearLine,\n vectorline: LineTileModel,\n tileLine: TileLineModel,\n};\n\nexport default LineModels;\n"],"file":"index.js"}
|
|
@@ -165,7 +165,7 @@ var DataMappingPlugin = (_dec = (0, _inversify.injectable)(), _dec2 = (0, _inver
|
|
|
165
165
|
}
|
|
166
166
|
});
|
|
167
167
|
|
|
168
|
-
if (encodeRecord.shape === 'line'
|
|
168
|
+
if (arrow.enable && (encodeRecord.shape === 'line' || encodeRecord.shape === 'halfLine')) {
|
|
169
169
|
var coords = encodeRecord.coordinates;
|
|
170
170
|
|
|
171
171
|
var arrowPoint = _this3.getArrowPoints(coords[0], coords[1]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/DataMappingPlugin.ts"],"names":["DataMappingPlugin","TYPES","IGlobalConfigService","IMapService","IFontService","layer","styleAttributeService","hooks","init","tap","generateMaping","beforeRenderData","dataState","dataMappingNeedUpdate","beforeRender","layerModelNeedUpdate","bottomColor","getBottomColor","attributes","getLayerStyleAttributes","filter","getLayerStyleAttribute","dataArray","getSource","data","attributesToRemapping","attribute","needRemapping","filterData","scale","record","applyAttributeMapping","length","setEncodedData","mapping","undefined","getEncodedData","emit","p1","p2","dir","normalizeDir","arrowPoint","predata","minimumColor","getLayerConfig","arrow","enable","mappedData","map","i","preRecord","encodeRecord","id","_id","coordinates","forEach","values","name","c","Array","isArray","shape","fontService","getIconFontKey","coords","getArrowPoints","splice","adjustData2Amap2Coordinates","adjustData2SimpleCoordinates","mapService","version","Version","layerCenter","getLayerCenter","d","originCoordinates","lngLatToCoordByLayer","lngLatToCoordsByLayer","source","center","SIMPLE","simpleCoordinate","unProjectCoordinates","simpleMapCoord","unproject","coord","c1","co","push","scalers","params","field","hasOwnProperty","type","mappingResult"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAcA;;AACA;;AACA;;AAEA;;;;;;;;IAIqBA,iB,WADpB,4B,UAEE,uBAAOC,cAAMC,oBAAb,C,UAGA,uBAAOD,cAAME,WAAb,C,UAGA,uBAAOF,cAAMG,YAAb,C;;;;;;;;;;WAGD,eACEC,KADF,QAKE;AAAA;;AAAA,UAFEC,qBAEF,QAFEA,qBAEF;AACAD,MAAAA,KAAK,CAACE,KAAN,CAAYC,IAAZ,CAAiBC,GAAjB,CAAqB,mBAArB,EAA0C,YAAM;AAE9C,QAAA,KAAI,CAACC,cAAL,CAAoBL,KAApB,EAA2B;AAAEC,UAAAA,qBAAqB,EAArBA;AAAF,SAA3B;AACD,OAHD;AAKAD,MAAAA,KAAK,CAACE,KAAN,CAAYI,gBAAZ,CAA6BF,GAA7B,CAAiC,mBAAjC,EAAsD,YAAM;AAC1DJ,QAAAA,KAAK,CAACO,SAAN,CAAgBC,qBAAhB,GAAwC,KAAxC;;AACA,QAAA,KAAI,CAACH,cAAL,CAAoBL,KAApB,EAA2B;AAAEC,UAAAA,qBAAqB,EAArBA;AAAF,SAA3B;;AACA,eAAO,IAAP;AACD,OAJD;AAOAD,MAAAA,KAAK,CAACE,KAAN,CAAYO,YAAZ,CAAyBL,GAAzB,CAA6B,mBAA7B,EAAkD,YAAM;AACtD,YAAIJ,KAAK,CAACU,oBAAV,EAAgC;AAC9B;AACD;;AACD,YAAMC,WAAW,GAAGX,KAAK,CAACY,cA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A,UAAMC,MAAiB,GAAG,EAA1B;AAEAD,MAAAA,OAAO,CAAClC,OAAR,CAAgB,iBAAe;AAAA;;AAAA,YAAZoC,KAAY,SAAZA,KAAY;;AAC7B,YACE9D,MAAM,CAAC+D,cAAP,CAAsBD,KAAtB,KACA,sBAAAlE,SAAS,CAACG,KAAV,wEAAiBiE,IAAjB,MAA0B,UAF5B,EAGE;AAEAH,UAAAA,MAAM,CAACF,IAAP,CAAY3D,MAAM,CAAC8D,KAAD,CAAlB;AACD;AACF,OARD;AAYA,UAAMG,aAAa,GAAGrE,SAAS,CAACQ,OAAV,GAAoBR,SAAS,CAACQ,OAAV,CAAkByD,MAAlB,CAApB,GAAgD,EAAtE;;AACA,UAAIjE,SAAS,CAACgC,IAAV,KAAmB,OAAnB,IAA8B,CAAC,sBAAQqC,aAAa,CAAC,CAAD,CAArB,CAAnC,EAA8D;AAC5D,eAAO,CAACnD,YAAD,CAAP;AACD;;AACD,aAAOmD,aAAP;AAED","sourcesContent":["import {\n IEncodeFeature,\n IFontService,\n IGlobalConfigService,\n ILayer,\n ILayerPlugin,\n ILngLat,\n IMapService,\n IParseDataItem,\n IStyleAttribute,\n IStyleAttributeService,\n Position,\n TYPES,\n} from '@antv/l7-core';\nimport { Version } from '@antv/l7-maps';\nimport { isColor, normalize, rgb2arr, unProjectFlat } from '@antv/l7-utils';\nimport { inject, injectable } from 'inversify';\nimport { cloneDeep } from 'lodash';\nimport 'reflect-metadata';\nimport { ILineLayerStyleOptions } from '../core/interface';\n\n@injectable()\nexport default class DataMappingPlugin implements ILayerPlugin {\n @inject(TYPES.IGlobalConfigService)\n private readonly configService: IGlobalConfigService;\n\n @inject(TYPES.IMapService)\n private readonly mapService: IMapService;\n\n @inject(TYPES.IFontService)\n private readonly fontService: IFontService;\n\n public apply(\n layer: ILayer,\n {\n styleAttributeService,\n }: { styleAttributeService: IStyleAttributeService },\n ) {\n layer.hooks.init.tap('DataMappingPlugin', () => {\n // 初始化重新生成 map\n this.generateMaping(layer, { styleAttributeService });\n });\n\n layer.hooks.beforeRenderData.tap('DataMappingPlugin', () => {\n layer.dataState.dataMappingNeedUpdate = false;\n this.generateMaping(layer, { styleAttributeService });\n return true;\n });\n\n // remapping before render\n layer.hooks.beforeRender.tap('DataMappingPlugin', () => {\n if (layer.layerModelNeedUpdate) {\n return;\n }\n const bottomColor = layer.getBottomColor();\n const attributes = styleAttributeService.getLayerStyleAttributes() || [];\n const filter = styleAttributeService.getLayerStyleAttribute('filter');\n const { dataArray } = layer.getSource().data;\n\n const attributesToRemapping = attributes.filter(\n (attribute) => attribute.needRemapping, // 如果filter变化\n );\n let filterData = dataArray;\n\n // 数据过滤完 再执行数据映射\n if (filter?.needRemapping && filter?.scale) {\n filterData = dataArray.filter((record: IParseDataItem) => {\n return this.applyAttributeMapping(filter, record, bottomColor)[0];\n });\n }\n\n if (attributesToRemapping.length) {\n // 过滤数据\n if (filter?.needRemapping) {\n layer.setEncodedData(\n this.mapping(layer, attributes, filterData, undefined, bottomColor),\n );\n filter.needRemapping = false;\n } else {\n layer.setEncodedData(\n this.mapping(\n layer,\n attributesToRemapping,\n filterData,\n layer.getEncodedData(),\n bottomColor,\n ),\n );\n }\n // 处理文本更新\n layer.emit('remapping', null);\n }\n });\n }\n private generateMaping(\n layer: ILayer,\n {\n styleAttributeService,\n }: { styleAttributeService: IStyleAttributeService },\n ) {\n const bottomColor = layer.getBottomColor();\n const attributes = styleAttributeService.getLayerStyleAttributes() || [];\n const filter = styleAttributeService.getLayerStyleAttribute('filter');\n const { dataArray } = layer.getSource().data;\n let filterData = dataArray;\n // 数据过滤完 再执行数据映射\n if (filter?.scale) {\n filterData = dataArray.filter((record: IParseDataItem) => {\n return this.applyAttributeMapping(filter, record, bottomColor)[0];\n });\n }\n layer.setEncodedData(\n this.mapping(layer, attributes, filterData, undefined, bottomColor),\n );\n // 对外暴露事件\n layer.emit('dataUpdate', null);\n }\n\n private getArrowPoints(p1: Position, p2: Position) {\n const dir = [p2[0] - p1[0], p2[1] - p1[1]];\n const normalizeDir = normalize(dir);\n const arrowPoint = [\n p1[0] + normalizeDir[0] * 0.0001,\n p1[1] + normalizeDir[1] * 0.0001,\n ];\n return arrowPoint;\n }\n\n private mapping(\n layer: ILayer,\n attributes: IStyleAttribute[],\n data: IParseDataItem[],\n predata?: IEncodeFeature[],\n minimumColor?: string,\n ): IEncodeFeature[] {\n const {\n arrow = {\n enable: false,\n },\n } = layer.getLayerConfig() as ILineLayerStyleOptions;\n const mappedData = data.map((record: IParseDataItem, i) => {\n const preRecord = predata ? predata[i] : {};\n const encodeRecord: IEncodeFeature = {\n id: record._id,\n coordinates: record.coordinates,\n ...preRecord,\n };\n attributes\n .filter((attribute) => attribute.scale !== undefined)\n .forEach((attribute: IStyleAttribute) => {\n // console.log('record', record)\n let values = this.applyAttributeMapping(\n attribute,\n record,\n minimumColor,\n );\n // console.log('values', values)\n attribute.needRemapping = false;\n\n // TODO: 支持每个属性配置 postprocess\n if (attribute.name === 'color') {\n // console.log('attribute', attribute)\n values = values.map((c: unknown) => {\n return rgb2arr(c as string);\n });\n }\n // @ts-ignore\n encodeRecord[attribute.name] =\n Array.isArray(values) && values.length === 1 ? values[0] : values;\n\n // 增加对 layer/text/iconfont unicode 映射的解析\n if (attribute.name === 'shape') {\n encodeRecord.shape = this.fontService.getIconFontKey(\n encodeRecord[attribute.name] as string,\n );\n }\n });\n\n if (encodeRecord.shape === 'line' && arrow.enable) {\n // 只有在线图层且支持配置箭头的时候进行插入顶点的处理\n const coords = encodeRecord.coordinates as Position[];\n const arrowPoint = this.getArrowPoints(coords[0], coords[1]);\n encodeRecord.coordinates.splice(1, 0, arrowPoint, arrowPoint);\n }\n return encodeRecord;\n }) as IEncodeFeature[];\n // console.log('mappedData', mappedData)\n\n // 调整数据兼容 Amap2.0\n this.adjustData2Amap2Coordinates(mappedData, layer);\n\n // 调整数据兼容 SimpleCoordinates\n this.adjustData2SimpleCoordinates(mappedData);\n\n return mappedData;\n }\n\n private adjustData2Amap2Coordinates(\n mappedData: IEncodeFeature[],\n layer: ILayer,\n ) {\n // 根据地图的类型判断是否需要对点位数据进行处理, 若是高德2.0则需要对坐标进行相对偏移\n if (\n mappedData.length > 0 &&\n this.mapService.version === Version['GAODE2.x']\n ) {\n const layerCenter = this.getLayerCenter(layer);\n if (typeof mappedData[0].coordinates[0] === 'number') {\n // 单个的点数据\n // @ts-ignore\n mappedData\n // TODO: 避免经纬度被重复计算导致坐标位置偏移\n .filter((d) => !d.originCoordinates)\n .map((d) => {\n d.version = Version['GAODE2.x'];\n // @ts-ignore\n d.originCoordinates = cloneDeep(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)\n // @ts-ignore\n // d.coordinates = this.mapService.lngLatToCoord(d.coordinates);\n d.coordinates = this.mapService.lngLatToCoordByLayer(\n d.coordinates,\n layerCenter,\n );\n });\n } else {\n // 连续的线、面数据\n // @ts-ignore\n mappedData\n // TODO: 避免经纬度被重复计算导致坐标位置偏移\n .filter((d) => !d.originCoordinates)\n .map((d) => {\n d.version = Version['GAODE2.x'];\n // @ts-ignore\n d.originCoordinates = cloneDeep(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)\n // @ts-ignore\n // d.coordinates = this.mapService.lngLatToCoords(d.coordinates);\n d.coordinates = this.mapService.lngLatToCoordsByLayer(\n d.coordinates,\n layerCenter,\n );\n });\n }\n }\n }\n\n private getLayerCenter(layer: ILayer) {\n const source = layer.getSource();\n return source.center;\n }\n\n private adjustData2SimpleCoordinates(mappedData: IEncodeFeature[]) {\n if (mappedData.length > 0 && this.mapService.version === Version.SIMPLE) {\n mappedData.map((d) => {\n if (!d.simpleCoordinate) {\n d.coordinates = this.unProjectCoordinates(d.coordinates);\n d.simpleCoordinate = true;\n }\n });\n }\n }\n\n private unProjectCoordinates(coordinates: any) {\n if (typeof coordinates[0] === 'number') {\n return this.mapService.simpleMapCoord.unproject(\n coordinates as [number, number],\n );\n }\n\n if (coordinates[0] && coordinates[0][0] instanceof Array) {\n // @ts-ignore\n const coords = [];\n coordinates.map((coord: any) => {\n // @ts-ignore\n const c1 = [];\n coord.map((co: any) => {\n c1.push(\n this.mapService.simpleMapCoord.unproject(co as [number, number]),\n );\n });\n // @ts-ignore\n coords.push(c1);\n });\n // @ts-ignore\n return coords;\n } else {\n // @ts-ignore\n const coords = [];\n // @ts-ignore\n coordinates.map((coord) => {\n coords.push(\n this.mapService.simpleMapCoord.unproject(coord as [number, number]),\n );\n });\n // @ts-ignore\n return coords;\n }\n }\n\n private applyAttributeMapping(\n attribute: IStyleAttribute,\n record: { [key: string]: unknown },\n minimumColor?: string,\n ) {\n if (!attribute.scale) {\n return [];\n }\n const scalers = attribute?.scale?.scalers || [];\n const params: unknown[] = [];\n\n scalers.forEach(({ field }) => {\n if (\n record.hasOwnProperty(field) ||\n attribute.scale?.type === 'variable'\n ) {\n // TODO:多字段,常量\n params.push(record[field]);\n }\n });\n // console.log('params', params)\n // console.log('attribute', attribute)\n\n const mappingResult = attribute.mapping ? attribute.mapping(params) : [];\n if (attribute.name === 'color' && !isColor(mappingResult[0])) {\n return [minimumColor];\n }\n return mappingResult;\n // return attribute.mapping ? attribute.mapping(params) : [];\n }\n}\n"],"file":"DataMappingPlugin.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/DataMappingPlugin.ts"],"names":["DataMappingPlugin","TYPES","IGlobalConfigService","IMapService","IFontService","layer","styleAttributeService","hooks","init","tap","generateMaping","beforeRenderData","dataState","dataMappingNeedUpdate","beforeRender","layerModelNeedUpdate","bottomColor","getBottomColor","attributes","getLayerStyleAttributes","filter","getLayerStyleAttribute","dataArray","getSource","data","attributesToRemapping","attribute","needRemapping","filterData","scale","record","applyAttributeMapping","length","setEncodedData","mapping","undefined","getEncodedData","emit","p1","p2","dir","normalizeDir","arrowPoint","predata","minimumColor","getLayerConfig","arrow","enable","mappedData","map","i","preRecord","encodeRecord","id","_id","coordinates","forEach","values","name","c","Array","isArray","shape","fontService","getIconFontKey","coords","getArrowPoints","splice","adjustData2Amap2Coordinates","adjustData2SimpleCoordinates","mapService","version","Version","layerCenter","getLayerCenter","d","originCoordinates","lngLatToCoordByLayer","lngLatToCoordsByLayer","source","center","SIMPLE","simpleCoordinate","unProjectCoordinates","simpleMapCoord","unproject","coord","c1","co","push","scalers","params","field","hasOwnProperty","type","mappingResult"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAcA;;AACA;;AACA;;AAEA;;;;;;;;IAIqBA,iB,WADpB,4B,UAEE,uBAAOC,cAAMC,oBAAb,C,UAGA,uBAAOD,cAAME,WAAb,C,UAGA,uBAAOF,cAAMG,YAAb,C;;;;;;;;;;WAGD,eACEC,KADF,QAKE;AAAA;;AAAA,UAFEC,qBAEF,QAFEA,qBAEF;AACAD,MAAAA,KAAK,CAACE,KAAN,CAAYC,IAAZ,CAAiBC,GAAjB,CAAqB,mBAArB,EAA0C,YAAM;AAE9C,QAAA,KAAI,CAACC,cAAL,CAAoBL,KAApB,EAA2B;AAAEC,UAAAA,qBAAqB,EAArBA;AAAF,SAA3B;AACD,OAHD;AAKAD,MAAAA,KAAK,CAACE,KAAN,CAAYI,gBAAZ,CAA6BF,GAA7B,CAAiC,mBAAjC,EAAsD,YAAM;AAC1DJ,QAAAA,KAAK,CAACO,SAAN,CAAgBC,qBAAhB,GAAwC,KAAxC;;AACA,QAAA,KAAI,CAACH,cAAL,CAAoBL,KAApB,EAA2B;AAAEC,UAAAA,qBAAqB,EAArBA;AAAF,SAA3B;;AACA,eAAO,IAAP;AACD,OAJD;AAOAD,MAAAA,KAAK,CAACE,KAAN,CAAYO,YAAZ,CAAyBL,GAAzB,CAA6B,mBAA7B,EAAkD,YAAM;AACtD,YAAIJ,KAAK,CAACU,oBAAV,EAAgC;AAC9B;AACD;;AACD,YAAMC,WAAW,GAAGX,KAAK,CAACY,cAAN,EAApB;AACA,YAAMC,UAAU,GAAGZ,qBAAqB,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C,MAAiB,GAAG,EAA1B;AAEAD,MAAAA,OAAO,CAAClC,OAAR,CAAgB,iBAAe;AAAA;;AAAA,YAAZoC,KAAY,SAAZA,KAAY;;AAC7B,YACE9D,MAAM,CAAC+D,cAAP,CAAsBD,KAAtB,KACA,sBAAAlE,SAAS,CAACG,KAAV,wEAAiBiE,IAAjB,MAA0B,UAF5B,EAGE;AAEAH,UAAAA,MAAM,CAACF,IAAP,CAAY3D,MAAM,CAAC8D,KAAD,CAAlB;AACD;AACF,OARD;AAYA,UAAMG,aAAa,GAAGrE,SAAS,CAACQ,OAAV,GAAoBR,SAAS,CAACQ,OAAV,CAAkByD,MAAlB,CAApB,GAAgD,EAAtE;;AACA,UAAIjE,SAAS,CAACgC,IAAV,KAAmB,OAAnB,IAA8B,CAAC,sBAAQqC,aAAa,CAAC,CAAD,CAArB,CAAnC,EAA8D;AAC5D,eAAO,CAACnD,YAAD,CAAP;AACD;;AACD,aAAOmD,aAAP;AAED","sourcesContent":["import {\n IEncodeFeature,\n IFontService,\n IGlobalConfigService,\n ILayer,\n ILayerPlugin,\n ILngLat,\n IMapService,\n IParseDataItem,\n IStyleAttribute,\n IStyleAttributeService,\n Position,\n TYPES,\n} from '@antv/l7-core';\nimport { Version } from '@antv/l7-maps';\nimport { isColor, normalize, rgb2arr, unProjectFlat } from '@antv/l7-utils';\nimport { inject, injectable } from 'inversify';\nimport { cloneDeep } from 'lodash';\nimport 'reflect-metadata';\nimport { ILineLayerStyleOptions } from '../core/interface';\n\n@injectable()\nexport default class DataMappingPlugin implements ILayerPlugin {\n @inject(TYPES.IGlobalConfigService)\n private readonly configService: IGlobalConfigService;\n\n @inject(TYPES.IMapService)\n private readonly mapService: IMapService;\n\n @inject(TYPES.IFontService)\n private readonly fontService: IFontService;\n\n public apply(\n layer: ILayer,\n {\n styleAttributeService,\n }: { styleAttributeService: IStyleAttributeService },\n ) {\n layer.hooks.init.tap('DataMappingPlugin', () => {\n // 初始化重新生成 map\n this.generateMaping(layer, { styleAttributeService });\n });\n\n layer.hooks.beforeRenderData.tap('DataMappingPlugin', () => {\n layer.dataState.dataMappingNeedUpdate = false;\n this.generateMaping(layer, { styleAttributeService });\n return true;\n });\n\n // remapping before render\n layer.hooks.beforeRender.tap('DataMappingPlugin', () => {\n if (layer.layerModelNeedUpdate) {\n return;\n }\n const bottomColor = layer.getBottomColor();\n const attributes = styleAttributeService.getLayerStyleAttributes() || [];\n const filter = styleAttributeService.getLayerStyleAttribute('filter');\n const { dataArray } = layer.getSource().data;\n\n const attributesToRemapping = attributes.filter(\n (attribute) => attribute.needRemapping, // 如果filter变化\n );\n let filterData = dataArray;\n\n // 数据过滤完 再执行数据映射\n if (filter?.needRemapping && filter?.scale) {\n filterData = dataArray.filter((record: IParseDataItem) => {\n return this.applyAttributeMapping(filter, record, bottomColor)[0];\n });\n }\n\n if (attributesToRemapping.length) {\n // 过滤数据\n if (filter?.needRemapping) {\n layer.setEncodedData(\n this.mapping(layer, attributes, filterData, undefined, bottomColor),\n );\n filter.needRemapping = false;\n } else {\n layer.setEncodedData(\n this.mapping(\n layer,\n attributesToRemapping,\n filterData,\n layer.getEncodedData(),\n bottomColor,\n ),\n );\n }\n // 处理文本更新\n layer.emit('remapping', null);\n }\n });\n }\n private generateMaping(\n layer: ILayer,\n {\n styleAttributeService,\n }: { styleAttributeService: IStyleAttributeService },\n ) {\n const bottomColor = layer.getBottomColor();\n const attributes = styleAttributeService.getLayerStyleAttributes() || [];\n const filter = styleAttributeService.getLayerStyleAttribute('filter');\n const { dataArray } = layer.getSource().data;\n let filterData = dataArray;\n // 数据过滤完 再执行数据映射\n if (filter?.scale) {\n filterData = dataArray.filter((record: IParseDataItem) => {\n return this.applyAttributeMapping(filter, record, bottomColor)[0];\n });\n }\n layer.setEncodedData(\n this.mapping(layer, attributes, filterData, undefined, bottomColor),\n );\n // 对外暴露事件\n layer.emit('dataUpdate', null);\n }\n\n private getArrowPoints(p1: Position, p2: Position) {\n const dir = [p2[0] - p1[0], p2[1] - p1[1]];\n const normalizeDir = normalize(dir);\n const arrowPoint = [\n p1[0] + normalizeDir[0] * 0.0001,\n p1[1] + normalizeDir[1] * 0.0001,\n ];\n return arrowPoint;\n }\n\n private mapping(\n layer: ILayer,\n attributes: IStyleAttribute[],\n data: IParseDataItem[],\n predata?: IEncodeFeature[],\n minimumColor?: string,\n ): IEncodeFeature[] {\n const {\n arrow = {\n enable: false,\n },\n } = layer.getLayerConfig() as ILineLayerStyleOptions;\n const mappedData = data.map((record: IParseDataItem, i) => {\n const preRecord = predata ? predata[i] : {};\n const encodeRecord: IEncodeFeature = {\n id: record._id,\n coordinates: record.coordinates,\n ...preRecord,\n };\n attributes\n .filter((attribute) => attribute.scale !== undefined)\n .forEach((attribute: IStyleAttribute) => {\n // console.log('record', record)\n let values = this.applyAttributeMapping(\n attribute,\n record,\n minimumColor,\n );\n // console.log('values', values)\n attribute.needRemapping = false;\n\n // TODO: 支持每个属性配置 postprocess\n if (attribute.name === 'color') {\n // console.log('attribute', attribute)\n values = values.map((c: unknown) => {\n return rgb2arr(c as string);\n });\n }\n // @ts-ignore\n encodeRecord[attribute.name] =\n Array.isArray(values) && values.length === 1 ? values[0] : values;\n\n // 增加对 layer/text/iconfont unicode 映射的解析\n if (attribute.name === 'shape') {\n encodeRecord.shape = this.fontService.getIconFontKey(\n encodeRecord[attribute.name] as string,\n );\n }\n });\n\n if (\n arrow.enable &&\n (encodeRecord.shape === 'line' || encodeRecord.shape === 'halfLine')\n ) {\n // 只有在线图层且支持配置箭头的时候进行插入顶点的处理\n const coords = encodeRecord.coordinates as Position[];\n const arrowPoint = this.getArrowPoints(coords[0], coords[1]);\n encodeRecord.coordinates.splice(1, 0, arrowPoint, arrowPoint);\n }\n return encodeRecord;\n }) as IEncodeFeature[];\n // console.log('mappedData', mappedData)\n\n // 调整数据兼容 Amap2.0\n this.adjustData2Amap2Coordinates(mappedData, layer);\n\n // 调整数据兼容 SimpleCoordinates\n this.adjustData2SimpleCoordinates(mappedData);\n\n return mappedData;\n }\n\n private adjustData2Amap2Coordinates(\n mappedData: IEncodeFeature[],\n layer: ILayer,\n ) {\n // 根据地图的类型判断是否需要对点位数据进行处理, 若是高德2.0则需要对坐标进行相对偏移\n if (\n mappedData.length > 0 &&\n this.mapService.version === Version['GAODE2.x']\n ) {\n const layerCenter = this.getLayerCenter(layer);\n if (typeof mappedData[0].coordinates[0] === 'number') {\n // 单个的点数据\n // @ts-ignore\n mappedData\n // TODO: 避免经纬度被重复计算导致坐标位置偏移\n .filter((d) => !d.originCoordinates)\n .map((d) => {\n d.version = Version['GAODE2.x'];\n // @ts-ignore\n d.originCoordinates = cloneDeep(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)\n // @ts-ignore\n // d.coordinates = this.mapService.lngLatToCoord(d.coordinates);\n d.coordinates = this.mapService.lngLatToCoordByLayer(\n d.coordinates,\n layerCenter,\n );\n });\n } else {\n // 连续的线、面数据\n // @ts-ignore\n mappedData\n // TODO: 避免经纬度被重复计算导致坐标位置偏移\n .filter((d) => !d.originCoordinates)\n .map((d) => {\n d.version = Version['GAODE2.x'];\n // @ts-ignore\n d.originCoordinates = cloneDeep(d.coordinates); // 为了兼容高德1.x 需要保存一份原始的经纬度坐标数据(许多上层逻辑依赖经纬度数据)\n // @ts-ignore\n // d.coordinates = this.mapService.lngLatToCoords(d.coordinates);\n d.coordinates = this.mapService.lngLatToCoordsByLayer(\n d.coordinates,\n layerCenter,\n );\n });\n }\n }\n }\n\n private getLayerCenter(layer: ILayer) {\n const source = layer.getSource();\n return source.center;\n }\n\n private adjustData2SimpleCoordinates(mappedData: IEncodeFeature[]) {\n if (mappedData.length > 0 && this.mapService.version === Version.SIMPLE) {\n mappedData.map((d) => {\n if (!d.simpleCoordinate) {\n d.coordinates = this.unProjectCoordinates(d.coordinates);\n d.simpleCoordinate = true;\n }\n });\n }\n }\n\n private unProjectCoordinates(coordinates: any) {\n if (typeof coordinates[0] === 'number') {\n return this.mapService.simpleMapCoord.unproject(\n coordinates as [number, number],\n );\n }\n\n if (coordinates[0] && coordinates[0][0] instanceof Array) {\n // @ts-ignore\n const coords = [];\n coordinates.map((coord: any) => {\n // @ts-ignore\n const c1 = [];\n coord.map((co: any) => {\n c1.push(\n this.mapService.simpleMapCoord.unproject(co as [number, number]),\n );\n });\n // @ts-ignore\n coords.push(c1);\n });\n // @ts-ignore\n return coords;\n } else {\n // @ts-ignore\n const coords = [];\n // @ts-ignore\n coordinates.map((coord) => {\n coords.push(\n this.mapService.simpleMapCoord.unproject(coord as [number, number]),\n );\n });\n // @ts-ignore\n return coords;\n }\n }\n\n private applyAttributeMapping(\n attribute: IStyleAttribute,\n record: { [key: string]: unknown },\n minimumColor?: string,\n ) {\n if (!attribute.scale) {\n return [];\n }\n const scalers = attribute?.scale?.scalers || [];\n const params: unknown[] = [];\n\n scalers.forEach(({ field }) => {\n if (\n record.hasOwnProperty(field) ||\n attribute.scale?.type === 'variable'\n ) {\n // TODO:多字段,常量\n params.push(record[field]);\n }\n });\n // console.log('params', params)\n // console.log('attribute', attribute)\n\n const mappingResult = attribute.mapping ? attribute.mapping(params) : [];\n if (attribute.name === 'color' && !isColor(mappingResult[0])) {\n return [minimumColor];\n }\n return mappingResult;\n // return attribute.mapping ? attribute.mapping(params) : [];\n }\n}\n"],"file":"DataMappingPlugin.js"}
|
|
@@ -70,15 +70,16 @@ var DataSourcePlugin = (_dec = (0, _inversify.injectable)(), _dec(_class = funct
|
|
|
70
70
|
value: function updateClusterData(layer) {
|
|
71
71
|
var source = layer.getSource();
|
|
72
72
|
var cluster = source.cluster;
|
|
73
|
-
var _source$clusterOption = source.clusterOptions,
|
|
74
|
-
_source$
|
|
75
|
-
zoom = _source$clusterOption2 === void 0 ? 0 : _source$clusterOption2,
|
|
76
|
-
_source$clusterOption3 = _source$clusterOption.maxZoom,
|
|
77
|
-
maxZoom = _source$clusterOption3 === void 0 ? 16 : _source$clusterOption3;
|
|
73
|
+
var _source$clusterOption = source.clusterOptions.zoom,
|
|
74
|
+
zoom = _source$clusterOption === void 0 ? 0 : _source$clusterOption;
|
|
78
75
|
var newZoom = this.mapService.getZoom() - 1;
|
|
79
76
|
var dataSourceNeedUpdate = layer.dataState.dataSourceNeedUpdate;
|
|
80
77
|
|
|
81
|
-
if (cluster &&
|
|
78
|
+
if (cluster && dataSourceNeedUpdate) {
|
|
79
|
+
source.updateClusterData(Math.floor(newZoom));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (cluster && Math.abs(layer.clusterZoom - newZoom) >= 1) {
|
|
82
83
|
if (zoom !== Math.floor(newZoom)) {
|
|
83
84
|
source.updateClusterData(Math.floor(newZoom));
|
|
84
85
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/DataSourcePlugin.ts"],"names":["DataSourcePlugin","layer","mapService","getContainer","get","TYPES","IMapService","hooks","init","tap","source","getSource","sourceOption","data","DEFAULT_DATA","options","DEFAULT_PARSER","setSource","Source","updateClusterData","beforeRenderData","neeUpdateCluster","dataSourceNeedUpdate","dataState","cluster","clusterOptions","zoom","
|
|
1
|
+
{"version":3,"sources":["../../src/plugins/DataSourcePlugin.ts"],"names":["DataSourcePlugin","layer","mapService","getContainer","get","TYPES","IMapService","hooks","init","tap","source","getSource","sourceOption","data","DEFAULT_DATA","options","DEFAULT_PARSER","setSource","Source","updateClusterData","beforeRenderData","neeUpdateCluster","dataSourceNeedUpdate","dataState","cluster","clusterOptions","zoom","newZoom","getZoom","Math","floor","abs","clusterZoom"],"mappings":";;;;;;;;;;;;;;;;;AAAA;;AAOA;;AACA;;AACA;;;;;;;;IAGqBA,gB,WADpB,4B;;;;;;;;WAGC,eAAaC,KAAb,EAA4B;AAAA;;AAC1B,WAAKC,UAAL,GAAkBD,KAAK,CAACE,YAAN,GAAqBC,GAArB,CAAsCC,cAAMC,WAA5C,CAAlB;AACAL,MAAAA,KAAK,CAACM,KAAN,CAAYC,IAAZ,CAAiBC,GAAj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I,CAACC,KAAL,CAAWH,OAAX,CAAzB;AACD;;AAED,UAAIH,OAAO,IAAIK,IAAI,CAACE,GAAL,CAAS9B,KAAK,CAAC+B,WAAN,GAAoBL,OAA7B,KAAyC,CAAxD,EAA2D;AACzD,YAAID,IAAI,KAAKG,IAAI,CAACC,KAAL,CAAWH,OAAX,CAAb,EAAkC;AAChCjB,UAAAA,MAAM,CAACS,iBAAP,CAAyBU,IAAI,CAACC,KAAL,CAAWH,OAAX,CAAzB;AACD;;AACD1B,QAAAA,KAAK,CAAC+B,WAAN,GAAoBL,OAApB;AACA,eAAO,IAAP;AACD;;AACD,aAAO,KAAP;AACD","sourcesContent":["import {\n ILayer,\n ILayerPlugin,\n ILngLat,\n IMapService,\n TYPES,\n} from '@antv/l7-core';\nimport Source, { DEFAULT_DATA, DEFAULT_PARSER } from '@antv/l7-source';\nimport { injectable } from 'inversify';\nimport 'reflect-metadata';\n\n@injectable()\nexport default class DataSourcePlugin implements ILayerPlugin {\n protected mapService: IMapService;\n public apply(layer: ILayer) {\n this.mapService = layer.getContainer().get<IMapService>(TYPES.IMapService);\n layer.hooks.init.tap('DataSourcePlugin', () => {\n const source = layer.getSource();\n if (!source) {\n // TODO: 允许用户不使用 layer 的 source 方法,在这里传入一个默认的替换的默认数据\n const { data, options } = layer.sourceOption || {\n data: DEFAULT_DATA,\n options: DEFAULT_PARSER,\n };\n layer.setSource(new Source(data, options));\n }\n\n this.updateClusterData(layer);\n });\n\n // 检测数据是否需要更新\n layer.hooks.beforeRenderData.tap('DataSourcePlugin', () => {\n const neeUpdateCluster = this.updateClusterData(layer);\n const dataSourceNeedUpdate = layer.dataState.dataSourceNeedUpdate;\n layer.dataState.dataSourceNeedUpdate = false;\n return neeUpdateCluster || dataSourceNeedUpdate;\n });\n }\n\n private updateClusterData(layer: ILayer): boolean {\n const source = layer.getSource();\n const cluster = source.cluster;\n const { zoom = 0 } = source.clusterOptions;\n const newZoom = this.mapService.getZoom() - 1;\n const dataSourceNeedUpdate = layer.dataState.dataSourceNeedUpdate;\n if (cluster && dataSourceNeedUpdate) {\n // 数据发生更新\n source.updateClusterData(Math.floor(newZoom));\n }\n // 如果 dataSource 有更新,跳过 zoom 的判断,直接更新一次\n if (cluster && Math.abs(layer.clusterZoom - newZoom) >= 1) {\n if (zoom !== Math.floor(newZoom)) {\n source.updateClusterData(Math.floor(newZoom));\n }\n layer.clusterZoom = newZoom;\n return true;\n }\n return false;\n }\n}\n"],"file":"DataSourcePlugin.js"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antv/l7-layers",
|
|
3
|
-
"version": "2.9.
|
|
3
|
+
"version": "2.9.13",
|
|
4
4
|
"description": "L7's collection of built-in layers",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -25,9 +25,9 @@
|
|
|
25
25
|
"author": "xiaoiver",
|
|
26
26
|
"license": "ISC",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@antv/l7-core": "2.9.
|
|
29
|
-
"@antv/l7-source": "2.9.
|
|
30
|
-
"@antv/l7-utils": "2.9.
|
|
28
|
+
"@antv/l7-core": "2.9.13",
|
|
29
|
+
"@antv/l7-source": "2.9.13",
|
|
30
|
+
"@antv/l7-utils": "2.9.13",
|
|
31
31
|
"@babel/runtime": "^7.7.7",
|
|
32
32
|
"@mapbox/martini": "^0.2.0",
|
|
33
33
|
"@turf/helpers": "^6.1.4",
|
|
@@ -57,7 +57,7 @@
|
|
|
57
57
|
"@types/gl-matrix": "^2.4.5",
|
|
58
58
|
"@types/lodash": "^4.14.138"
|
|
59
59
|
},
|
|
60
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "7507d6b2cdbeec29e4a904cefeed4e11ebc41e3a",
|
|
61
61
|
"publishConfig": {
|
|
62
62
|
"access": "public"
|
|
63
63
|
}
|