@antv/l7-layers 2.8.27 → 2.8.28
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/Geometry/index.d.ts +1 -1
- package/es/Geometry/index.js +14 -2
- package/es/Geometry/index.js.map +1 -1
- package/es/Geometry/models/index.d.ts +1 -1
- package/es/Geometry/models/index.js +3 -1
- package/es/Geometry/models/index.js.map +1 -1
- package/es/Geometry/models/sprite.d.ts +47 -0
- package/es/Geometry/models/sprite.js +305 -0
- package/es/Geometry/models/sprite.js.map +1 -0
- package/es/core/BaseLayer.d.ts +1 -0
- package/es/core/BaseLayer.js +10 -0
- package/es/core/BaseLayer.js.map +1 -1
- package/es/core/interface.d.ts +9 -1
- package/es/core/interface.js.map +1 -1
- package/lib/Geometry/index.js +14 -2
- package/lib/Geometry/index.js.map +1 -1
- package/lib/Geometry/models/index.js +4 -1
- package/lib/Geometry/models/index.js.map +1 -1
- package/lib/Geometry/models/sprite.js +312 -0
- package/lib/Geometry/models/sprite.js.map +1 -0
- package/lib/core/BaseLayer.js +10 -0
- package/lib/core/BaseLayer.js.map +1 -1
- package/lib/core/interface.js.map +1 -1
- package/package.json +5 -5
package/es/Geometry/index.d.ts
CHANGED
package/es/Geometry/index.js
CHANGED
|
@@ -64,14 +64,26 @@ var GeometryLayer = function (_BaseLayer) {
|
|
|
64
64
|
value: function getDefaultConfig() {
|
|
65
65
|
var type = this.getModelType();
|
|
66
66
|
var defaultConfig = {
|
|
67
|
-
plane: {}
|
|
67
|
+
plane: {},
|
|
68
|
+
sprite: {}
|
|
68
69
|
};
|
|
69
70
|
return defaultConfig[type];
|
|
70
71
|
}
|
|
71
72
|
}, {
|
|
72
73
|
key: "getModelType",
|
|
73
74
|
value: function getModelType() {
|
|
74
|
-
|
|
75
|
+
var _shapeAttribute$scale;
|
|
76
|
+
|
|
77
|
+
var shapeAttribute = this.styleAttributeService.getLayerStyleAttribute('shape');
|
|
78
|
+
var shape = shapeAttribute === null || shapeAttribute === void 0 ? void 0 : (_shapeAttribute$scale = shapeAttribute.scale) === null || _shapeAttribute$scale === void 0 ? void 0 : _shapeAttribute$scale.field;
|
|
79
|
+
|
|
80
|
+
if (shape === 'plane') {
|
|
81
|
+
return 'plane';
|
|
82
|
+
} else if (shape === 'sprite') {
|
|
83
|
+
return 'sprite';
|
|
84
|
+
} else {
|
|
85
|
+
return 'plane';
|
|
86
|
+
}
|
|
75
87
|
}
|
|
76
88
|
}]);
|
|
77
89
|
|
package/es/Geometry/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/Geometry/index.ts"],"names":["BaseLayer","GeometryModels","GeometryLayer","modelType","getModelType","layerModel","models","initModels","buildModels","properties","opacity","type","minimum","maximum","defaultConfig","plane"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,SAAP,MAAsB,mBAAtB;AAEA,OAAOC,cAAP,MAAkD,UAAlD;;IAEqBC,a;;;;;;;;;;;;;;;;2DAGG,e;;;;;;;WACtB,uBAAqB;AACnB,UAAMC,SAAS,GAAG,KAAKC,YAAL,EAAlB;AACA,WAAKC,UAAL,GAAkB,IAAIJ,cAAc,CAACE,SAAD,CAAlB,CAA8B,IAA9B,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,KAAK,EAAE;
|
|
1
|
+
{"version":3,"sources":["../../src/Geometry/index.ts"],"names":["BaseLayer","GeometryModels","GeometryLayer","modelType","getModelType","layerModel","models","initModels","buildModels","properties","opacity","type","minimum","maximum","defaultConfig","plane","sprite","shapeAttribute","styleAttributeService","getLayerStyleAttribute","shape","scale","field"],"mappings":";;;;;;;;;;;;AAAA,OAAOA,SAAP,MAAsB,mBAAtB;AAEA,OAAOC,cAAP,MAAkD,UAAlD;;IAEqBC,a;;;;;;;;;;;;;;;;2DAGG,e;;;;;;;WACtB,uBAAqB;AACnB,UAAMC,SAAS,GAAG,KAAKC,YAAL,EAAlB;AACA,WAAKC,UAAL,GAAkB,IAAIJ,cAAc,CAACE,SAAD,CAAlB,CAA8B,IAA9B,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,KAAK,EAAE,EADa;AAEpBC,QAAAA,MAAM,EAAE;AAFY,OAAtB;AAIA,aAAOF,aAAa,CAACH,IAAD,CAApB;AACD;;;WAED,wBAA4C;AAAA;;AAC1C,UAAMM,cAAc,GAAG,KAAKC,qBAAL,CAA2BC,sBAA3B,CACrB,OADqB,CAAvB;AAGA,UAAMC,KAAK,GAAGH,cAAH,aAAGA,cAAH,gDAAGA,cAAc,CAAEI,KAAnB,0DAAG,sBAAuBC,KAArC;;AACA,UAAIF,KAAK,KAAK,OAAd,EAAuB;AACrB,eAAO,OAAP;AACD,OAFD,MAEO,IAAIA,KAAK,KAAK,QAAd,EAAwB;AAC7B,eAAO,QAAP;AACD,OAFM,MAEA;AACL,eAAO,OAAP;AACD;AACF;;;;EA7CwCpB,S;;SAAtBE,a","sourcesContent":["import BaseLayer from '../core/BaseLayer';\nimport { IGeometryLayerStyleOptions } from '../core/interface';\nimport GeometryModels, { GeometryModelType } from './models';\n\nexport default class GeometryLayer extends BaseLayer<\n IGeometryLayerStyleOptions\n> {\n public type: string = 'GeometryLayer';\n public buildModels() {\n const modelType = this.getModelType();\n this.layerModel = new GeometryModels[modelType](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 plane: {},\n sprite: {},\n };\n return defaultConfig[type];\n }\n\n protected getModelType(): GeometryModelType {\n const shapeAttribute = this.styleAttributeService.getLayerStyleAttribute(\n 'shape',\n );\n const shape = shapeAttribute?.scale?.field as GeometryModelType;\n if (shape === 'plane') {\n return 'plane';\n } else if (shape === 'sprite') {\n return 'sprite';\n } else {\n return 'plane';\n }\n }\n}\n"],"file":"index.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Geometry/models/index.ts"],"names":["PlaneModel","GeometryModels","plane"],"mappings":"AAAA,OAAOA,UAAP,MAAuB,SAAvB;AAGA,IAAMC,cAAmD,GAAG;AAC1DC,EAAAA,KAAK,
|
|
1
|
+
{"version":3,"sources":["../../../src/Geometry/models/index.ts"],"names":["PlaneModel","SpriteModel","GeometryModels","plane","sprite"],"mappings":"AAAA,OAAOA,UAAP,MAAuB,SAAvB;AACA,OAAOC,WAAP,MAAwB,UAAxB;AAGA,IAAMC,cAAmD,GAAG;AAC1DC,EAAAA,KAAK,EAAEH,UADmD;AAE1DI,EAAAA,MAAM,EAAEH;AAFkD,CAA5D;AAIA,eAAeC,cAAf","sourcesContent":["import PlaneModel from './plane';\nimport SpriteModel from './sprite';\nexport type GeometryModelType = 'plane' | 'sprite';\n\nconst GeometryModels: { [key in GeometryModelType]: any } = {\n plane: PlaneModel,\n sprite: SpriteModel,\n};\nexport default GeometryModels;\n"],"file":"index.js"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { IModelUniform, ITexture2D } from '@antv/l7-core';
|
|
2
|
+
import BaseModel from '../../core/BaseModel';
|
|
3
|
+
declare enum SPRITE_ANIMATE_DIR {
|
|
4
|
+
'UP' = "up",
|
|
5
|
+
'DOWN' = "down"
|
|
6
|
+
}
|
|
7
|
+
export default class SpriteModel extends BaseModel {
|
|
8
|
+
protected texture: ITexture2D;
|
|
9
|
+
protected mapTexture: string | undefined;
|
|
10
|
+
protected positions: number[];
|
|
11
|
+
protected indices: number[];
|
|
12
|
+
protected timer: number;
|
|
13
|
+
protected spriteTop: number;
|
|
14
|
+
protected spriteUpdate: number;
|
|
15
|
+
protected spriteAnimate: SPRITE_ANIMATE_DIR;
|
|
16
|
+
initSprite(radius?: number, spriteCount?: number, lng?: number, lat?: number): {
|
|
17
|
+
indices: number[];
|
|
18
|
+
positions: number[];
|
|
19
|
+
};
|
|
20
|
+
planeGeometryUpdateTriangulation: () => {
|
|
21
|
+
vertices: number[];
|
|
22
|
+
indices: number[];
|
|
23
|
+
size: number;
|
|
24
|
+
};
|
|
25
|
+
updateModel: () => void;
|
|
26
|
+
planeGeometryTriangulation: () => {
|
|
27
|
+
vertices: number[];
|
|
28
|
+
indices: number[];
|
|
29
|
+
size: number;
|
|
30
|
+
};
|
|
31
|
+
getUninforms(): IModelUniform;
|
|
32
|
+
clearModels(): void;
|
|
33
|
+
initModels(): import("@antv/l7-core").IModel[];
|
|
34
|
+
buildModels(): import("@antv/l7-core").IModel[];
|
|
35
|
+
updateTexture(mapTexture: string | undefined): void;
|
|
36
|
+
protected getConfigSchema(): {
|
|
37
|
+
properties: {
|
|
38
|
+
opacity: {
|
|
39
|
+
type: string;
|
|
40
|
+
minimum: number;
|
|
41
|
+
maximum: number;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
protected registerBuiltinAttributes(): string;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,305 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
|
+
import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
|
|
4
|
+
import _createClass from "@babel/runtime/helpers/createClass";
|
|
5
|
+
import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
|
|
6
|
+
import _inherits from "@babel/runtime/helpers/inherits";
|
|
7
|
+
import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
|
|
8
|
+
import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
|
|
9
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
10
|
+
|
|
11
|
+
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); }; }
|
|
12
|
+
|
|
13
|
+
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; } }
|
|
14
|
+
|
|
15
|
+
import { gl } from '@antv/l7-core';
|
|
16
|
+
import { Version } from '@antv/l7-maps';
|
|
17
|
+
import BaseModel from '../../core/BaseModel';
|
|
18
|
+
var spriteFrag = "\nuniform sampler2D u_texture;\nuniform float u_mapFlag;\nuniform float u_opacity;\n\nvarying vec3 v_Color;\nvarying float v_d;\n\n#pragma include \"picking\"\nvoid main() {\n\n if(v_d < 0.0) {\n discard;\n }\n\n if(u_mapFlag > 0.0) {\n gl_FragColor = texture2D(u_texture, gl_PointCoord);\n gl_FragColor.a *= u_opacity;\n } else {\n gl_FragColor = vec4(v_Color, u_opacity);\n }\n\n gl_FragColor = filterColor(gl_FragColor);\n}\n";
|
|
19
|
+
var spriteVert = "precision highp float;\n\nattribute vec3 a_Position;\nattribute vec3 a_Color;\n\nuniform mat4 u_ModelMatrix;\nuniform mat4 u_Mvp;\nuniform float u_opacity;\nuniform float u_Scale;\nvarying vec3 v_Color;\nvarying float v_d;\n\n#pragma include \"projection\"\n#pragma include \"picking\"\nvoid main() {\n v_Color = a_Color;\n \n vec4 project_pos = project_position(vec4(a_Position, 1.0));\n\n v_d = a_Position.z;\n\n if(u_CoordinateSystem == COORDINATE_SYSTEM_P20_2) { // gaode2.x\n gl_Position = u_Mvp * (vec4(project_pos.xy, a_Position.z, 1.0));\n } else {\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy, a_Position.z, 1.0));\n }\n\n gl_PointSize = pow((u_Zoom - 1.0), 2.0) * u_Scale;\n\n setPickingColor(a_PickingColor);\n}\n";
|
|
20
|
+
var SPRITE_ANIMATE_DIR;
|
|
21
|
+
|
|
22
|
+
(function (SPRITE_ANIMATE_DIR) {
|
|
23
|
+
SPRITE_ANIMATE_DIR["UP"] = "up";
|
|
24
|
+
SPRITE_ANIMATE_DIR["DOWN"] = "down";
|
|
25
|
+
})(SPRITE_ANIMATE_DIR || (SPRITE_ANIMATE_DIR = {}));
|
|
26
|
+
|
|
27
|
+
var SpriteModel = function (_BaseModel) {
|
|
28
|
+
_inherits(SpriteModel, _BaseModel);
|
|
29
|
+
|
|
30
|
+
var _super = _createSuper(SpriteModel);
|
|
31
|
+
|
|
32
|
+
function SpriteModel() {
|
|
33
|
+
var _this;
|
|
34
|
+
|
|
35
|
+
_classCallCheck(this, SpriteModel);
|
|
36
|
+
|
|
37
|
+
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
|
38
|
+
args[_key] = arguments[_key];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
_this = _super.call.apply(_super, [this].concat(args));
|
|
42
|
+
|
|
43
|
+
_defineProperty(_assertThisInitialized(_this), "texture", void 0);
|
|
44
|
+
|
|
45
|
+
_defineProperty(_assertThisInitialized(_this), "mapTexture", void 0);
|
|
46
|
+
|
|
47
|
+
_defineProperty(_assertThisInitialized(_this), "positions", void 0);
|
|
48
|
+
|
|
49
|
+
_defineProperty(_assertThisInitialized(_this), "indices", void 0);
|
|
50
|
+
|
|
51
|
+
_defineProperty(_assertThisInitialized(_this), "timer", void 0);
|
|
52
|
+
|
|
53
|
+
_defineProperty(_assertThisInitialized(_this), "spriteTop", void 0);
|
|
54
|
+
|
|
55
|
+
_defineProperty(_assertThisInitialized(_this), "spriteUpdate", void 0);
|
|
56
|
+
|
|
57
|
+
_defineProperty(_assertThisInitialized(_this), "spriteAnimate", void 0);
|
|
58
|
+
|
|
59
|
+
_defineProperty(_assertThisInitialized(_this), "planeGeometryUpdateTriangulation", function () {
|
|
60
|
+
var updateZ = _this.spriteUpdate;
|
|
61
|
+
var bottomZ = -100000;
|
|
62
|
+
var topZ = _this.spriteTop;
|
|
63
|
+
|
|
64
|
+
for (var i = 0; i < _this.positions.length; i += 5) {
|
|
65
|
+
if (_this.spriteAnimate === SPRITE_ANIMATE_DIR.UP) {
|
|
66
|
+
_this.positions[i + 2] += updateZ;
|
|
67
|
+
|
|
68
|
+
if (_this.positions[i + 2] > topZ) {
|
|
69
|
+
_this.positions[i + 2] = bottomZ;
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
_this.positions[i + 2] -= updateZ;
|
|
73
|
+
|
|
74
|
+
if (_this.positions[i + 2] < bottomZ) {
|
|
75
|
+
_this.positions[i + 2] = topZ;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return {
|
|
81
|
+
vertices: _this.positions,
|
|
82
|
+
indices: _this.indices,
|
|
83
|
+
size: 5
|
|
84
|
+
};
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
_defineProperty(_assertThisInitialized(_this), "updateModel", function () {
|
|
88
|
+
var attributes = _this.layer.createAttrubutes({
|
|
89
|
+
triangulation: _this.planeGeometryUpdateTriangulation
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
_this.layer.models.map(function (m) {
|
|
93
|
+
m.updateAttributes(attributes);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
_this.layer.renderLayers();
|
|
97
|
+
|
|
98
|
+
_this.timer = requestAnimationFrame(_this.updateModel);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
_defineProperty(_assertThisInitialized(_this), "planeGeometryTriangulation", function () {
|
|
102
|
+
var _this2;
|
|
103
|
+
|
|
104
|
+
var _ref = _this.layer.getLayerConfig(),
|
|
105
|
+
_ref$center = _ref.center,
|
|
106
|
+
center = _ref$center === void 0 ? [120, 30] : _ref$center,
|
|
107
|
+
_ref$spriteCount = _ref.spriteCount,
|
|
108
|
+
spriteCount = _ref$spriteCount === void 0 ? 100 : _ref$spriteCount,
|
|
109
|
+
_ref$spriteRadius = _ref.spriteRadius,
|
|
110
|
+
spriteRadius = _ref$spriteRadius === void 0 ? 10 : _ref$spriteRadius;
|
|
111
|
+
|
|
112
|
+
var _this$initSprite = (_this2 = _this).initSprite.apply(_this2, [spriteRadius, spriteCount].concat(_toConsumableArray(center))),
|
|
113
|
+
indices = _this$initSprite.indices,
|
|
114
|
+
positions = _this$initSprite.positions;
|
|
115
|
+
|
|
116
|
+
_this.positions = positions;
|
|
117
|
+
_this.indices = indices;
|
|
118
|
+
return {
|
|
119
|
+
vertices: positions,
|
|
120
|
+
indices: indices,
|
|
121
|
+
size: 5
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
return _this;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
_createClass(SpriteModel, [{
|
|
129
|
+
key: "initSprite",
|
|
130
|
+
value: function initSprite() {
|
|
131
|
+
var radius = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 10;
|
|
132
|
+
var spriteCount = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 100;
|
|
133
|
+
var lng = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 120;
|
|
134
|
+
var lat = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 30;
|
|
135
|
+
var indices = [];
|
|
136
|
+
var positions = [];
|
|
137
|
+
var mapService = this.mapService;
|
|
138
|
+
var heightLimit = this.spriteAnimate === SPRITE_ANIMATE_DIR.UP ? -this.spriteTop : this.spriteTop;
|
|
139
|
+
|
|
140
|
+
for (var i = 0; i < spriteCount; i++) {
|
|
141
|
+
var height = Math.random() * heightLimit;
|
|
142
|
+
positions.push.apply(positions, _toConsumableArray(getPos(height)));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
for (var _i = 0; _i < spriteCount; _i++) {
|
|
146
|
+
indices.push(_i);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function getPos(z) {
|
|
150
|
+
var randomX = radius * Math.random();
|
|
151
|
+
var randomY = radius * Math.random();
|
|
152
|
+
var x = -radius / 2 + randomX;
|
|
153
|
+
var y = -radius / 2 + randomY;
|
|
154
|
+
|
|
155
|
+
if (mapService.version === Version['GAODE2.x']) {
|
|
156
|
+
var _ref2 = mapService.lngLatToCoord([x + lng, -y + lat]),
|
|
157
|
+
_ref3 = _slicedToArray(_ref2, 2),
|
|
158
|
+
a = _ref3[0],
|
|
159
|
+
b = _ref3[1];
|
|
160
|
+
|
|
161
|
+
return [a, b, z, 0, 0];
|
|
162
|
+
} else {
|
|
163
|
+
return [x + lng, -y + lat, z, 0, 0];
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
return {
|
|
168
|
+
indices: indices,
|
|
169
|
+
positions: positions
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
}, {
|
|
173
|
+
key: "getUninforms",
|
|
174
|
+
value: function getUninforms() {
|
|
175
|
+
var _ref4 = this.layer.getLayerConfig(),
|
|
176
|
+
opacity = _ref4.opacity,
|
|
177
|
+
mapTexture = _ref4.mapTexture,
|
|
178
|
+
_ref4$spriteScale = _ref4.spriteScale,
|
|
179
|
+
spriteScale = _ref4$spriteScale === void 0 ? 1 : _ref4$spriteScale;
|
|
180
|
+
|
|
181
|
+
if (this.mapTexture !== mapTexture) {
|
|
182
|
+
var _this$texture;
|
|
183
|
+
|
|
184
|
+
this.mapTexture = mapTexture;
|
|
185
|
+
(_this$texture = this.texture) === null || _this$texture === void 0 ? void 0 : _this$texture.destroy();
|
|
186
|
+
this.updateTexture(mapTexture);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
u_opacity: opacity || 1,
|
|
191
|
+
u_mapFlag: mapTexture ? 1 : 0,
|
|
192
|
+
u_texture: this.texture,
|
|
193
|
+
u_Scale: spriteScale
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
}, {
|
|
197
|
+
key: "clearModels",
|
|
198
|
+
value: function clearModels() {
|
|
199
|
+
var _this$texture2;
|
|
200
|
+
|
|
201
|
+
cancelAnimationFrame(this.timer);
|
|
202
|
+
(_this$texture2 = this.texture) === null || _this$texture2 === void 0 ? void 0 : _this$texture2.destroy();
|
|
203
|
+
}
|
|
204
|
+
}, {
|
|
205
|
+
key: "initModels",
|
|
206
|
+
value: function initModels() {
|
|
207
|
+
var _this3 = this;
|
|
208
|
+
|
|
209
|
+
var _ref5 = this.layer.getLayerConfig(),
|
|
210
|
+
mapTexture = _ref5.mapTexture,
|
|
211
|
+
_ref5$spriteTop = _ref5.spriteTop,
|
|
212
|
+
spriteTop = _ref5$spriteTop === void 0 ? 5000000 : _ref5$spriteTop,
|
|
213
|
+
_ref5$spriteUpdate = _ref5.spriteUpdate,
|
|
214
|
+
spriteUpdate = _ref5$spriteUpdate === void 0 ? 10000 : _ref5$spriteUpdate,
|
|
215
|
+
_ref5$spriteAnimate = _ref5.spriteAnimate,
|
|
216
|
+
spriteAnimate = _ref5$spriteAnimate === void 0 ? SPRITE_ANIMATE_DIR.DOWN : _ref5$spriteAnimate;
|
|
217
|
+
|
|
218
|
+
this.mapTexture = mapTexture;
|
|
219
|
+
this.spriteTop = spriteTop;
|
|
220
|
+
this.spriteUpdate = spriteUpdate;
|
|
221
|
+
spriteAnimate === 'up' ? this.spriteAnimate = SPRITE_ANIMATE_DIR.UP : this.spriteAnimate = SPRITE_ANIMATE_DIR.DOWN;
|
|
222
|
+
var createTexture2D = this.rendererService.createTexture2D;
|
|
223
|
+
this.texture = createTexture2D({
|
|
224
|
+
height: 0,
|
|
225
|
+
width: 0
|
|
226
|
+
});
|
|
227
|
+
this.updateTexture(mapTexture);
|
|
228
|
+
setTimeout(function () {
|
|
229
|
+
_this3.updateModel();
|
|
230
|
+
}, 100);
|
|
231
|
+
return [this.layer.buildLayerModel({
|
|
232
|
+
moduleName: 'geometry_sprite',
|
|
233
|
+
vertexShader: spriteVert,
|
|
234
|
+
fragmentShader: spriteFrag,
|
|
235
|
+
triangulation: this.planeGeometryTriangulation,
|
|
236
|
+
primitive: gl.POINTS,
|
|
237
|
+
depth: {
|
|
238
|
+
enable: false
|
|
239
|
+
},
|
|
240
|
+
blend: this.getBlend()
|
|
241
|
+
})];
|
|
242
|
+
}
|
|
243
|
+
}, {
|
|
244
|
+
key: "buildModels",
|
|
245
|
+
value: function buildModels() {
|
|
246
|
+
return this.initModels();
|
|
247
|
+
}
|
|
248
|
+
}, {
|
|
249
|
+
key: "updateTexture",
|
|
250
|
+
value: function updateTexture(mapTexture) {
|
|
251
|
+
var _this4 = this;
|
|
252
|
+
|
|
253
|
+
var createTexture2D = this.rendererService.createTexture2D;
|
|
254
|
+
|
|
255
|
+
if (mapTexture) {
|
|
256
|
+
var img = new Image();
|
|
257
|
+
img.crossOrigin = 'anonymous';
|
|
258
|
+
|
|
259
|
+
img.onload = function () {
|
|
260
|
+
_this4.texture = createTexture2D({
|
|
261
|
+
data: img,
|
|
262
|
+
width: img.width,
|
|
263
|
+
height: img.height,
|
|
264
|
+
wrapS: gl.CLAMP_TO_EDGE,
|
|
265
|
+
wrapT: gl.CLAMP_TO_EDGE
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
_this4.layerService.updateLayerRenderList();
|
|
269
|
+
|
|
270
|
+
_this4.layerService.renderLayers();
|
|
271
|
+
};
|
|
272
|
+
|
|
273
|
+
img.src = mapTexture;
|
|
274
|
+
} else {
|
|
275
|
+
this.texture = createTexture2D({
|
|
276
|
+
width: 0,
|
|
277
|
+
height: 0
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}, {
|
|
282
|
+
key: "getConfigSchema",
|
|
283
|
+
value: function getConfigSchema() {
|
|
284
|
+
return {
|
|
285
|
+
properties: {
|
|
286
|
+
opacity: {
|
|
287
|
+
type: 'number',
|
|
288
|
+
minimum: 0,
|
|
289
|
+
maximum: 1
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
}
|
|
294
|
+
}, {
|
|
295
|
+
key: "registerBuiltinAttributes",
|
|
296
|
+
value: function registerBuiltinAttributes() {
|
|
297
|
+
return '';
|
|
298
|
+
}
|
|
299
|
+
}]);
|
|
300
|
+
|
|
301
|
+
return SpriteModel;
|
|
302
|
+
}(BaseModel);
|
|
303
|
+
|
|
304
|
+
export { SpriteModel as default };
|
|
305
|
+
//# sourceMappingURL=sprite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/Geometry/models/sprite.ts"],"names":["gl","Version","BaseModel","SPRITE_ANIMATE_DIR","SpriteModel","updateZ","spriteUpdate","bottomZ","topZ","spriteTop","i","positions","length","spriteAnimate","UP","vertices","indices","size","attributes","layer","createAttrubutes","triangulation","planeGeometryUpdateTriangulation","models","map","m","updateAttributes","renderLayers","timer","requestAnimationFrame","updateModel","getLayerConfig","center","spriteCount","spriteRadius","initSprite","radius","lng","lat","mapService","heightLimit","height","Math","random","push","getPos","z","randomX","randomY","x","y","version","lngLatToCoord","a","b","opacity","mapTexture","spriteScale","texture","destroy","updateTexture","u_opacity","u_mapFlag","u_texture","u_Scale","cancelAnimationFrame","DOWN","createTexture2D","rendererService","width","setTimeout","buildLayerModel","moduleName","vertexShader","spriteVert","fragmentShader","spriteFrag","planeGeometryTriangulation","primitive","POINTS","depth","enable","blend","getBlend","initModels","img","Image","crossOrigin","onload","data","wrapS","CLAMP_TO_EDGE","wrapT","layerService","updateLayerRenderList","src","properties","type","minimum","maximum"],"mappings":";;;;;;;;;;;;;;AAAA,SAEEA,EAFF,QAQO,eARP;AASA,SAASC,OAAT,QAAwB,eAAxB;AAEA,OAAOC,SAAP,MAAsB,sBAAtB;;;IAKKC,kB;;WAAAA,kB;AAAAA,EAAAA,kB;AAAAA,EAAAA,kB;GAAAA,kB,KAAAA,kB;;IAKgBC,W;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uFA8CuB,YAAM;AAC9C,UAAMC,OAAO,GAAG,MAAKC,YAArB;AACA,UAAMC,OAAO,GAAG,CAAC,MAAjB;AACA,UAAMC,IAAI,GAAG,MAAKC,SAAlB;;AAEA,WAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAG,MAAKC,SAAL,CAAeC,MAAnC,EAA2CF,CAAC,IAAI,CAAhD,EAAmD;AACjD,YAAI,MAAKG,aAAL,KAAuBV,kBAAkB,CAACW,EAA9C,EAAkD;AAChD,gBAAKH,SAAL,CAAeD,CAAC,GAAG,CAAnB,KAAyBL,OAAzB;;AACA,cAAI,MAAKM,SAAL,CAAeD,CAAC,GAAG,CAAnB,IAAwBF,IAA5B,EAAkC;AAChC,kBAAKG,SAA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,\n} from '@antv/l7-core';\nimport { Version } from '@antv/l7-maps';\n\nimport BaseModel from '../../core/BaseModel';\nimport { IGeometryLayerStyleOptions } from '../../core/interface';\nimport spriteFrag from '../shaders/sprite_frag.glsl';\nimport spriteVert from '../shaders/sprite_vert.glsl';\n\nenum SPRITE_ANIMATE_DIR {\n 'UP' = 'up',\n 'DOWN' = 'down',\n}\n\nexport default class SpriteModel extends BaseModel {\n protected texture: ITexture2D;\n protected mapTexture: string | undefined;\n protected positions: number[];\n protected indices: number[];\n protected timer: number;\n protected spriteTop: number;\n protected spriteUpdate: number;\n protected spriteAnimate: SPRITE_ANIMATE_DIR;\n\n public initSprite(radius = 10, spriteCount = 100, lng = 120, lat = 30) {\n const indices = [];\n const positions = [];\n const mapService = this.mapService;\n const heightLimit =\n this.spriteAnimate === SPRITE_ANIMATE_DIR.UP\n ? -this.spriteTop\n : this.spriteTop;\n for (let i = 0; i < spriteCount; i++) {\n const height = Math.random() * heightLimit;\n positions.push(...getPos(height));\n }\n for (let i = 0; i < spriteCount; i++) {\n indices.push(i);\n }\n\n function getPos(z: number) {\n const randomX = radius * Math.random();\n const randomY = radius * Math.random();\n const x = -radius / 2 + randomX;\n const y = -radius / 2 + randomY;\n if (mapService.version === Version['GAODE2.x']) {\n // @ts-ignore\n const [a, b] = mapService.lngLatToCoord([x + lng, -y + lat]) as [\n number,\n number,\n ];\n return [a, b, z, 0, 0];\n } else {\n return [x + lng, -y + lat, z, 0, 0];\n }\n }\n\n return { indices, positions };\n }\n\n public planeGeometryUpdateTriangulation = () => {\n const updateZ = this.spriteUpdate;\n const bottomZ = -100000;\n const topZ = this.spriteTop;\n\n for (let i = 0; i < this.positions.length; i += 5) {\n if (this.spriteAnimate === SPRITE_ANIMATE_DIR.UP) {\n this.positions[i + 2] += updateZ;\n if (this.positions[i + 2] > topZ) {\n this.positions[i + 2] = bottomZ;\n }\n } else {\n this.positions[i + 2] -= updateZ;\n if (this.positions[i + 2] < bottomZ) {\n this.positions[i + 2] = topZ;\n }\n }\n }\n\n return {\n vertices: this.positions,\n indices: this.indices,\n size: 5,\n };\n };\n\n public updateModel = () => {\n // @ts-ignore\n const attributes = this.layer.createAttrubutes({\n triangulation: this.planeGeometryUpdateTriangulation,\n });\n this.layer.models.map((m) => {\n m.updateAttributes(attributes);\n });\n this.layer.renderLayers();\n\n this.timer = requestAnimationFrame(this.updateModel);\n };\n\n public planeGeometryTriangulation = () => {\n const {\n center = [120, 30],\n spriteCount = 100,\n spriteRadius = 10,\n } = this.layer.getLayerConfig() as IGeometryLayerStyleOptions;\n\n const { indices, positions } = this.initSprite(\n spriteRadius,\n spriteCount,\n ...center,\n );\n this.positions = positions;\n this.indices = indices;\n return {\n vertices: positions,\n indices,\n size: 5,\n };\n };\n\n public getUninforms(): IModelUniform {\n const {\n opacity,\n mapTexture,\n spriteScale = 1,\n } = this.layer.getLayerConfig() as IGeometryLayerStyleOptions;\n if (this.mapTexture !== mapTexture) {\n this.mapTexture = mapTexture;\n this.texture?.destroy();\n this.updateTexture(mapTexture);\n }\n return {\n u_opacity: opacity || 1,\n u_mapFlag: mapTexture ? 1 : 0,\n u_texture: this.texture,\n u_Scale: spriteScale,\n };\n }\n\n public clearModels(): void {\n cancelAnimationFrame(this.timer);\n this.texture?.destroy();\n }\n\n public initModels() {\n const {\n mapTexture,\n spriteTop = 5000000,\n spriteUpdate = 10000,\n spriteAnimate = SPRITE_ANIMATE_DIR.DOWN,\n } = this.layer.getLayerConfig() as IGeometryLayerStyleOptions;\n this.mapTexture = mapTexture;\n this.spriteTop = spriteTop;\n this.spriteUpdate = spriteUpdate;\n spriteAnimate === 'up'\n ? (this.spriteAnimate = SPRITE_ANIMATE_DIR.UP)\n : (this.spriteAnimate = SPRITE_ANIMATE_DIR.DOWN);\n\n const { createTexture2D } = this.rendererService;\n this.texture = createTexture2D({\n height: 0,\n width: 0,\n });\n\n this.updateTexture(mapTexture);\n\n setTimeout(() => {\n this.updateModel();\n }, 100);\n\n return [\n this.layer.buildLayerModel({\n moduleName: 'geometry_sprite',\n vertexShader: spriteVert,\n fragmentShader: spriteFrag,\n triangulation: this.planeGeometryTriangulation,\n primitive: gl.POINTS,\n depth: { enable: false },\n blend: this.getBlend(),\n }),\n ];\n }\n\n public buildModels() {\n return this.initModels();\n }\n\n public updateTexture(mapTexture: string | undefined): void {\n const { createTexture2D } = this.rendererService;\n\n if (mapTexture) {\n const img = new Image();\n img.crossOrigin = 'anonymous';\n img.onload = () => {\n this.texture = createTexture2D({\n data: img,\n width: img.width,\n height: img.height,\n wrapS: gl.CLAMP_TO_EDGE,\n wrapT: gl.CLAMP_TO_EDGE,\n });\n this.layerService.updateLayerRenderList();\n this.layerService.renderLayers();\n };\n img.src = mapTexture;\n } else {\n this.texture = createTexture2D({\n width: 0,\n height: 0,\n });\n }\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\n protected registerBuiltinAttributes() {\n return '';\n }\n}\n"],"file":"sprite.js"}
|
package/es/core/BaseLayer.d.ts
CHANGED
|
@@ -176,6 +176,7 @@ export default class BaseLayer<ChildLayerStyleOptions = {}> extends EventEmitter
|
|
|
176
176
|
}): void;
|
|
177
177
|
boxSelect(box: [number, number, number, number], cb: (...args: any[]) => void): void;
|
|
178
178
|
buildLayerModel(options: ILayerModelInitializationOptions & Partial<IModelInitializationOptions>): IModel;
|
|
179
|
+
createAttrubutes(options: ILayerModelInitializationOptions & Partial<IModelInitializationOptions>): any;
|
|
179
180
|
getTime(): number;
|
|
180
181
|
setAnimateStartTime(): void;
|
|
181
182
|
stopAnimate(): void;
|
package/es/core/BaseLayer.js
CHANGED
|
@@ -1047,6 +1047,16 @@ var BaseLayer = (_dec = lazyInject(TYPES.IGlobalConfigService), (_class = functi
|
|
|
1047
1047
|
blend: BlendTypes[BlendType.normal]
|
|
1048
1048
|
}, rest));
|
|
1049
1049
|
}
|
|
1050
|
+
}, {
|
|
1051
|
+
key: "createAttrubutes",
|
|
1052
|
+
value: function createAttrubutes(options) {
|
|
1053
|
+
var triangulation = options.triangulation;
|
|
1054
|
+
|
|
1055
|
+
var _this$styleAttributeS5 = this.styleAttributeService.createAttributes(this.encodedData, triangulation),
|
|
1056
|
+
attributes = _this$styleAttributeS5.attributes;
|
|
1057
|
+
|
|
1058
|
+
return attributes;
|
|
1059
|
+
}
|
|
1050
1060
|
}, {
|
|
1051
1061
|
key: "getTime",
|
|
1052
1062
|
value: function getTime() {
|