mirror of https://gitee.com/antv-l7/antv-l7
fix(lib) delete lib
This commit is contained in:
parent
d06de6fcd2
commit
f6c8f053f4
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
257
lib/attr/base.js
257
lib/attr/base.js
|
@ -1,257 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _colorUtil = _interopRequireDefault(require("./color-util"));
|
||||
|
||||
var _util = _interopRequireDefault(require("../util"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function toScaleString(scale, value) {
|
||||
if (_util["default"].isString(value)) {
|
||||
return value;
|
||||
}
|
||||
|
||||
return scale.invert(scale.scale(value));
|
||||
}
|
||||
/**
|
||||
* 所有视觉通道属性的基类
|
||||
* @class Attr
|
||||
*/
|
||||
|
||||
|
||||
var AttributeBase =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function AttributeBase(cfg) {
|
||||
_classCallCheck(this, AttributeBase);
|
||||
|
||||
/**
|
||||
* 属性的类型
|
||||
* @type {String}
|
||||
*/
|
||||
this.type = 'base';
|
||||
/**
|
||||
* 属性的名称
|
||||
* @type {String}
|
||||
*/
|
||||
|
||||
this.name = null;
|
||||
/**
|
||||
* 回调函数
|
||||
* @type {Function}
|
||||
*/
|
||||
|
||||
this.method = null;
|
||||
/**
|
||||
* 备选的值数组
|
||||
* @type {Array}
|
||||
*/
|
||||
|
||||
this.values = [];
|
||||
/**
|
||||
* 属性内部的度量
|
||||
* @type {Array}
|
||||
*/
|
||||
|
||||
this.scales = [];
|
||||
/**
|
||||
* 是否通过线性取值, 如果未指定,则根据数值的类型判定
|
||||
* @type {Boolean}
|
||||
*/
|
||||
|
||||
this.linear = null;
|
||||
|
||||
_util["default"].mix(this, cfg);
|
||||
}
|
||||
|
||||
_createClass(AttributeBase, [{
|
||||
key: "get",
|
||||
value: function get(name) {
|
||||
return this[name];
|
||||
}
|
||||
}, {
|
||||
key: "set",
|
||||
value: function set(name, value) {
|
||||
this[name] = value;
|
||||
} // 获取属性值,将值映射到视觉通道
|
||||
|
||||
}, {
|
||||
key: "_getAttrValue",
|
||||
value: function _getAttrValue(scale, value) {
|
||||
var values = this.values;
|
||||
|
||||
if (scale.isCategory && !this.linear) {
|
||||
var index = scale.translate(value);
|
||||
return values[index % values.length];
|
||||
}
|
||||
|
||||
var percent = scale.scale(value);
|
||||
return this.getLinearValue(percent);
|
||||
}
|
||||
/**
|
||||
* 如果进行线性映射,返回对应的映射值
|
||||
* @protected
|
||||
* @param {Number} percent 百分比
|
||||
* @return {*} 颜色值、形状、大小等
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: "getLinearValue",
|
||||
value: function getLinearValue(percent) {
|
||||
var values = this.values;
|
||||
var steps = values.length - 1;
|
||||
var step = Math.floor(steps * percent);
|
||||
var leftPercent = steps * percent - step;
|
||||
var start = values[step];
|
||||
var end = step === steps ? start : values[step + 1];
|
||||
var rstValue = start + (end - start) * leftPercent;
|
||||
return rstValue;
|
||||
}
|
||||
/**
|
||||
* 默认的回调函数
|
||||
* @param {*} value 回调函数的值
|
||||
* @type {Function}
|
||||
* @return {Array} 返回映射后的值
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: "callback",
|
||||
value: function callback(value) {
|
||||
var self = this;
|
||||
var scale = self.scales[0];
|
||||
var rstValue = null;
|
||||
|
||||
if (scale.type === 'identity') {
|
||||
rstValue = scale.value;
|
||||
} else {
|
||||
rstValue = self._getAttrValue(scale, value);
|
||||
}
|
||||
|
||||
return rstValue;
|
||||
}
|
||||
/**
|
||||
* 根据度量获取属性名
|
||||
* @return {Array} dims of this Attribute
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: "getNames",
|
||||
value: function getNames() {
|
||||
var scales = this.scales;
|
||||
var names = this.names;
|
||||
var length = Math.min(scales.length, names.length);
|
||||
var rst = [];
|
||||
|
||||
for (var i = 0; i < length; i++) {
|
||||
rst.push(names[i]);
|
||||
}
|
||||
|
||||
return rst;
|
||||
}
|
||||
/**
|
||||
* 根据度量获取维度名
|
||||
* @return {Array} dims of this Attribute
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: "getFields",
|
||||
value: function getFields() {
|
||||
var scales = this.scales;
|
||||
var rst = [];
|
||||
|
||||
_util["default"].each(scales, function (scale) {
|
||||
rst.push(scale.field);
|
||||
});
|
||||
|
||||
return rst;
|
||||
}
|
||||
/**
|
||||
* 根据名称获取度量
|
||||
* @param {String} name the name of scale
|
||||
* @return {Scale} scale
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: "getScale",
|
||||
value: function getScale(name) {
|
||||
var scales = this.scales;
|
||||
var names = this.names;
|
||||
var index = names.indexOf(name);
|
||||
return scales[index];
|
||||
}
|
||||
/**
|
||||
* 映射数据
|
||||
* @param {*} param1...paramn 多个数值
|
||||
* @return {Array} 映射的值组成的数组
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: "mapping",
|
||||
value: function mapping() {
|
||||
var scales = this.scales;
|
||||
var callback = this.callback;
|
||||
|
||||
for (var _len = arguments.length, params = new Array(_len), _key = 0; _key < _len; _key++) {
|
||||
params[_key] = arguments[_key];
|
||||
}
|
||||
|
||||
var values = params;
|
||||
|
||||
if (callback) {
|
||||
for (var i = 0; i < params.length; i++) {
|
||||
params[i] = this._toOriginParam(params[i], scales[i]);
|
||||
}
|
||||
|
||||
values = callback.apply(this, params);
|
||||
}
|
||||
|
||||
if (this.type === 'color' && !_util["default"].isArray(values)) {
|
||||
values = _colorUtil["default"].toRGB(values).map(function (e) {
|
||||
return e / 255;
|
||||
}); // values[3] = values[3] * 255;
|
||||
}
|
||||
|
||||
if (!_util["default"].isArray(values)) {
|
||||
values = [values];
|
||||
}
|
||||
|
||||
return values;
|
||||
} // 原始的参数
|
||||
|
||||
}, {
|
||||
key: "_toOriginParam",
|
||||
value: function _toOriginParam(param, scale) {
|
||||
var rst = param;
|
||||
|
||||
if (!scale.isLinear) {
|
||||
if (_util["default"].isArray(param)) {
|
||||
rst = [];
|
||||
|
||||
for (var i = 0; i < param.length; i++) {
|
||||
rst.push(toScaleString(scale, param[i]));
|
||||
}
|
||||
} else {
|
||||
rst = toScaleString(scale, param);
|
||||
}
|
||||
}
|
||||
|
||||
return rst;
|
||||
}
|
||||
}]);
|
||||
|
||||
return AttributeBase;
|
||||
}();
|
||||
|
||||
var _default = AttributeBase;
|
||||
exports["default"] = _default;
|
|
@ -1,282 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _util = _interopRequireDefault(require("../util"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
/**
|
||||
* @fileOverview 颜色计算的辅助方法
|
||||
* @author dxq613@gmail.com
|
||||
*/
|
||||
var RGB_REG = /rgba?\(([\s.,0-9]+)\)/;
|
||||
var ColorKeywords = {
|
||||
aliceblue: '#F0F8FF',
|
||||
antiquewhite: '#FAEBD7',
|
||||
aqua: '#00FFFF',
|
||||
aquamarine: '#7FFFD4',
|
||||
azure: '#F0FFFF',
|
||||
beige: '#F5F5DC',
|
||||
bisque: '#FFE4C4',
|
||||
black: '#000000',
|
||||
blanchedalmond: '#FFEBCD',
|
||||
blue: '#0000FF',
|
||||
blueviolet: '#8A2BE2',
|
||||
brown: '#A52A2A',
|
||||
burlywood: '#DEB887',
|
||||
cadetblue: '#5F9EA0',
|
||||
chartreuse: '#7FFF00',
|
||||
chocolate: '#D2691E',
|
||||
coral: '#FF7F50',
|
||||
cornflowerblue: '#6495ED',
|
||||
cornsilk: '#FFF8DC',
|
||||
crimson: '#DC143C',
|
||||
cyan: '#00FFFF',
|
||||
darkblue: '#00008B',
|
||||
darkcyan: '#008B8B',
|
||||
darkgoldenrod: '#B8860B',
|
||||
darkgray: '#A9A9A9',
|
||||
darkgreen: '#006400',
|
||||
darkgrey: '#A9A9A9',
|
||||
darkkhaki: '#BDB76B',
|
||||
darkmagenta: '#8B008B',
|
||||
darkolivegreen: '#556B2F',
|
||||
darkorange: '#FF8C00',
|
||||
darkorchid: '#9932CC',
|
||||
darkred: '#8B0000',
|
||||
darksalmon: '#E9967A',
|
||||
darkseagreen: '#8FBC8F',
|
||||
darkslateblue: '#483D8B',
|
||||
darkslategray: '#2F4F4F',
|
||||
darkslategrey: '#2F4F4F',
|
||||
darkturquoise: '#00CED1',
|
||||
darkviolet: '#9400D3',
|
||||
deeppink: '#FF1493',
|
||||
deepskyblue: '#00BFFF',
|
||||
dimgray: '#696969',
|
||||
dimgrey: '#696969',
|
||||
dodgerblue: '#1E90FF',
|
||||
firebrick: '#B22222',
|
||||
floralwhite: '#FFFAF0',
|
||||
forestgreen: '#228B22',
|
||||
fuchsia: '#FF00FF',
|
||||
gainsboro: '#DCDCDC',
|
||||
ghostwhite: '#F8F8FF',
|
||||
gold: '#FFD700',
|
||||
goldenrod: '#DAA520',
|
||||
gray: '#808080',
|
||||
green: '#008000',
|
||||
greenyellow: '#ADFF2F',
|
||||
grey: '#808080',
|
||||
honeydew: '#F0FFF0',
|
||||
hotpink: '#FF69B4',
|
||||
indianred: '#CD5C5C',
|
||||
indigo: '#4B0082',
|
||||
ivory: '#FFFFF0',
|
||||
khaki: '#F0E68C',
|
||||
lavender: '#E6E6FA',
|
||||
lavenderblush: '#FFF0F5',
|
||||
lawngreen: '#7CFC00',
|
||||
lemonchiffon: '#FFFACD',
|
||||
lightblue: '#ADD8E6',
|
||||
lightcoral: '#F08080',
|
||||
lightcyan: '#E0FFFF',
|
||||
lightgoldenrodyellow: '#FAFAD2',
|
||||
lightgray: '#D3D3D3',
|
||||
lightgreen: '#90EE90',
|
||||
lightgrey: '#D3D3D3',
|
||||
lightpink: '#FFB6C1',
|
||||
lightsalmon: '#FFA07A',
|
||||
lightseagreen: '#20B2AA',
|
||||
lightskyblue: '#87CEFA',
|
||||
lightslategray: '#778899',
|
||||
lightslategrey: '#778899',
|
||||
lightsteelblue: '#B0C4DE',
|
||||
lightyellow: '#FFFFE0',
|
||||
lime: '#00FF00',
|
||||
limegreen: '#32CD32',
|
||||
linen: '#FAF0E6',
|
||||
magenta: '#FF00FF',
|
||||
maroon: '#800000',
|
||||
mediumaquamarine: '#66CDAA',
|
||||
mediumblue: '#0000CD',
|
||||
mediumorchid: '#BA55D3',
|
||||
mediumpurple: '#9370DB',
|
||||
mediumseagreen: '#3CB371',
|
||||
mediumslateblue: '#7B68EE',
|
||||
mediumspringgreen: '#00FA9A',
|
||||
mediumturquoise: '#48D1CC',
|
||||
mediumvioletred: '#C71585',
|
||||
midnightblue: '#191970',
|
||||
mintcream: '#F5FFFA',
|
||||
mistyrose: '#FFE4E1',
|
||||
moccasin: '#FFE4B5',
|
||||
navajowhite: '#FFDEAD',
|
||||
navy: '#000080',
|
||||
oldlace: '#FDF5E6',
|
||||
olive: '#808000',
|
||||
olivedrab: '#6B8E23',
|
||||
orange: '#FFA500',
|
||||
orangered: '#FF4500',
|
||||
orchid: '#DA70D6',
|
||||
palegoldenrod: '#EEE8AA',
|
||||
palegreen: '#98FB98',
|
||||
paleturquoise: '#AFEEEE',
|
||||
palevioletred: '#DB7093',
|
||||
papayawhip: '#FFEFD5',
|
||||
peachpuff: '#FFDAB9',
|
||||
peru: '#CD853F',
|
||||
pink: '#FFC0CB',
|
||||
plum: '#DDA0DD',
|
||||
powderblue: '#B0E0E6',
|
||||
purple: '#800080',
|
||||
rebeccapurple: '#663399',
|
||||
red: '#FF0000',
|
||||
rosybrown: '#BC8F8F',
|
||||
royalblue: '#4169E1',
|
||||
saddlebrown: '#8B4513',
|
||||
salmon: '#FA8072',
|
||||
sandybrown: '#F4A460',
|
||||
seagreen: '#2E8B57',
|
||||
seashell: '#FFF5EE',
|
||||
sienna: '#A0522D',
|
||||
silver: '#C0C0C0',
|
||||
skyblue: '#87CEEB',
|
||||
slateblue: '#6A5ACD',
|
||||
slategray: '#708090',
|
||||
slategrey: '#708090',
|
||||
snow: '#FFFAFA',
|
||||
springgreen: '#00FF7F',
|
||||
steelblue: '#4682B4',
|
||||
tan: '#D2B48C',
|
||||
teal: '#008080',
|
||||
thistle: '#D8BFD8',
|
||||
tomato: '#FF6347',
|
||||
turquoise: '#40E0D0',
|
||||
violet: '#EE82EE',
|
||||
wheat: '#F5DEB3',
|
||||
white: '#FFFFFF',
|
||||
whitesmoke: '#F5F5F5',
|
||||
yellow: '#FFFF00',
|
||||
yellowgreen: '#9ACD32'
|
||||
}; // 获取颜色之间的插值
|
||||
|
||||
function getValue(start, end, percent, index) {
|
||||
var value = start[index] + (end[index] - start[index]) * percent;
|
||||
return value;
|
||||
}
|
||||
|
||||
function calColor(colors, percent) {
|
||||
if (_util["default"].isNaN(percent) || !_util["default"].isNumber(percent)) {
|
||||
percent = 0;
|
||||
}
|
||||
|
||||
var steps = colors.length - 1;
|
||||
var step = Math.floor(steps * percent);
|
||||
var left = steps * percent - step;
|
||||
var start = colors[step];
|
||||
var end = step === steps ? start : colors[step + 1];
|
||||
return [getValue(start, end, left, 0), getValue(start, end, left, 1), getValue(start, end, left, 2), getValue(start, end, left, 3)];
|
||||
} // rgb 颜色转换成数组
|
||||
|
||||
|
||||
function rgb2arr(str) {
|
||||
var arr = [];
|
||||
|
||||
if (str.length === 4) {
|
||||
str = "#".concat(str[1]).concat(str[1]).concat(str[2]).concat(str[2]).concat(str[3]).concat(str[3]);
|
||||
}
|
||||
|
||||
arr.push(parseInt(str.substr(1, 2), 16));
|
||||
arr.push(parseInt(str.substr(3, 2), 16));
|
||||
arr.push(parseInt(str.substr(5, 2), 16));
|
||||
return arr;
|
||||
}
|
||||
|
||||
var colorCache = {};
|
||||
var ColorUtil = {
|
||||
/**
|
||||
* 将颜色转换到 rgb 的格式
|
||||
* @param {String} color 颜色
|
||||
* @return {String} 将颜色转换到 '#ffffff' 的格式
|
||||
*/
|
||||
toRGB: function toRGB(color) {
|
||||
// 如果已经是 rgb的格式
|
||||
var colorArray = [255, 255, 255, 255];
|
||||
|
||||
if (ColorKeywords[color]) {
|
||||
// color name 2 hex
|
||||
var hexColor = ColorKeywords[color];
|
||||
colorArray = rgb2arr(hexColor);
|
||||
colorArray.push(255.0);
|
||||
}
|
||||
|
||||
if (color[0] === '#' && (color.length === 7 || color.length === 4)) {
|
||||
// hex2array
|
||||
colorArray = rgb2arr(color);
|
||||
colorArray.push(255.0);
|
||||
return colorArray;
|
||||
}
|
||||
|
||||
if (RGB_REG.test(color)) {
|
||||
var matchs = RGB_REG.exec(color);
|
||||
colorArray = matchs[1].split(/\s*,\s*/);
|
||||
|
||||
if (colorArray.length === 4) {
|
||||
colorArray[3] *= 255;
|
||||
}
|
||||
|
||||
if (colorArray.length === 3) {
|
||||
colorArray.push(255.0);
|
||||
}
|
||||
}
|
||||
|
||||
colorCache[color] = colorArray;
|
||||
return colorArray;
|
||||
},
|
||||
// 转成 WebGl color buffer
|
||||
color2Arr: function color2Arr(str) {
|
||||
var rgba = this.toRGB(str);
|
||||
return rgba.map(function (v) {
|
||||
return v / 255;
|
||||
});
|
||||
},
|
||||
colorArray2RGBA: function colorArray2RGBA(arr) {
|
||||
return "rgba(".concat(arr[0] * 255, ",").concat(arr[1] * 255, ",").concat(arr[2] * 255, ",").concat(arr[3], ")");
|
||||
},
|
||||
color2RGBA: function color2RGBA(str) {
|
||||
return this.color2Arr(str);
|
||||
},
|
||||
rgb2arr: rgb2arr,
|
||||
|
||||
/**
|
||||
* 获取渐变函数
|
||||
* @param {Array} colors 多个颜色
|
||||
* @return {String} 颜色值
|
||||
*/
|
||||
gradient: function gradient(colors) {
|
||||
var points = [];
|
||||
|
||||
if (_util["default"].isString(colors)) {
|
||||
colors = colors.split('-');
|
||||
}
|
||||
|
||||
_util["default"].each(colors, function (color) {
|
||||
var colorArray = ColorUtil.toRGB(color).map(function (e) {
|
||||
return e / 255;
|
||||
}); // colorArray[3] = colorArray[3] * 255;
|
||||
|
||||
points.push(colorArray);
|
||||
});
|
||||
|
||||
return function (percent) {
|
||||
return calColor(points, percent);
|
||||
};
|
||||
}
|
||||
};
|
||||
var _default = ColorUtil;
|
||||
exports["default"] = _default;
|
|
@ -1,84 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _colorUtil = _interopRequireDefault(require("./color-util"));
|
||||
|
||||
var _base = _interopRequireDefault(require("./base"));
|
||||
|
||||
var _util = _interopRequireDefault(require("../util"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
/**
|
||||
* 视觉通道 color
|
||||
* @class Attr.Color
|
||||
*/
|
||||
var Color =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Color, _Base);
|
||||
|
||||
function Color(cfg) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, Color);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Color).call(this, cfg));
|
||||
_this.names = ['color'];
|
||||
_this.type = 'color';
|
||||
_this.gradient = null;
|
||||
|
||||
if (_util["default"].isString(_this.values)) {
|
||||
_this.linear = true;
|
||||
}
|
||||
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
|
||||
|
||||
_createClass(Color, [{
|
||||
key: "getLinearValue",
|
||||
value: function getLinearValue(percent) {
|
||||
var gradient = this.gradient;
|
||||
|
||||
if (!gradient) {
|
||||
var values = this.values;
|
||||
gradient = _colorUtil["default"].gradient(values);
|
||||
this.gradient = gradient;
|
||||
}
|
||||
|
||||
var color = gradient(percent);
|
||||
return color;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Color;
|
||||
}(_base["default"]);
|
||||
|
||||
var _default = Color;
|
||||
exports["default"] = _default;
|
|
@ -1,107 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.colorScales = void 0;
|
||||
// code from https://github.com/santilland/plotty/blob/master/src/colorscales.js
|
||||
var colorScales = {
|
||||
viridis: new Uint8Array([68, 1, 84, 255, 68, 2, 86, 255, 69, 4, 87, 255, 69, 5, 89, 255, 70, 7, 90, 255, 70, 8, 92, 255, 70, 10, 93, 255, 70, 11, 94, 255, 71, 13, 96, 255, 71, 14, 97, 255, 71, 16, 99, 255, 71, 17, 100, 255, 71, 19, 101, 255, 72, 20, 103, 255, 72, 22, 104, 255, 72, 23, 105, 255, 72, 24, 106, 255, 72, 26, 108, 255, 72, 27, 109, 255, 72, 28, 110, 255, 72, 29, 111, 255, 72, 31, 112, 255, 72, 32, 113, 255, 72, 33, 115, 255, 72, 35, 116, 255, 72, 36, 117, 255, 72, 37, 118, 255, 72, 38, 119, 255, 72, 40, 120, 255, 72, 41, 121, 255, 71, 42, 122, 255, 71, 44, 122, 255, 71, 45, 123, 255, 71, 46, 124, 255, 71, 47, 125, 255, 70, 48, 126, 255, 70, 50, 126, 255, 70, 51, 127, 255, 70, 52, 128, 255, 69, 53, 129, 255, 69, 55, 129, 255, 69, 56, 130, 255, 68, 57, 131, 255, 68, 58, 131, 255, 68, 59, 132, 255, 67, 61, 132, 255, 67, 62, 133, 255, 66, 63, 133, 255, 66, 64, 134, 255, 66, 65, 134, 255, 65, 66, 135, 255, 65, 68, 135, 255, 64, 69, 136, 255, 64, 70, 136, 255, 63, 71, 136, 255, 63, 72, 137, 255, 62, 73, 137, 255, 62, 74, 137, 255, 62, 76, 138, 255, 61, 77, 138, 255, 61, 78, 138, 255, 60, 79, 138, 255, 60, 80, 139, 255, 59, 81, 139, 255, 59, 82, 139, 255, 58, 83, 139, 255, 58, 84, 140, 255, 57, 85, 140, 255, 57, 86, 140, 255, 56, 88, 140, 255, 56, 89, 140, 255, 55, 90, 140, 255, 55, 91, 141, 255, 54, 92, 141, 255, 54, 93, 141, 255, 53, 94, 141, 255, 53, 95, 141, 255, 52, 96, 141, 255, 52, 97, 141, 255, 51, 98, 141, 255, 51, 99, 141, 255, 50, 100, 142, 255, 50, 101, 142, 255, 49, 102, 142, 255, 49, 103, 142, 255, 49, 104, 142, 255, 48, 105, 142, 255, 48, 106, 142, 255, 47, 107, 142, 255, 47, 108, 142, 255, 46, 109, 142, 255, 46, 110, 142, 255, 46, 111, 142, 255, 45, 112, 142, 255, 45, 113, 142, 255, 44, 113, 142, 255, 44, 114, 142, 255, 44, 115, 142, 255, 43, 116, 142, 255, 43, 117, 142, 255, 42, 118, 142, 255, 42, 119, 142, 255, 42, 120, 142, 255, 41, 121, 142, 255, 41, 122, 142, 255, 41, 123, 142, 255, 40, 124, 142, 255, 40, 125, 142, 255, 39, 126, 142, 255, 39, 127, 142, 255, 39, 128, 142, 255, 38, 129, 142, 255, 38, 130, 142, 255, 38, 130, 142, 255, 37, 131, 142, 255, 37, 132, 142, 255, 37, 133, 142, 255, 36, 134, 142, 255, 36, 135, 142, 255, 35, 136, 142, 255, 35, 137, 142, 255, 35, 138, 141, 255, 34, 139, 141, 255, 34, 140, 141, 255, 34, 141, 141, 255, 33, 142, 141, 255, 33, 143, 141, 255, 33, 144, 141, 255, 33, 145, 140, 255, 32, 146, 140, 255, 32, 146, 140, 255, 32, 147, 140, 255, 31, 148, 140, 255, 31, 149, 139, 255, 31, 150, 139, 255, 31, 151, 139, 255, 31, 152, 139, 255, 31, 153, 138, 255, 31, 154, 138, 255, 30, 155, 138, 255, 30, 156, 137, 255, 30, 157, 137, 255, 31, 158, 137, 255, 31, 159, 136, 255, 31, 160, 136, 255, 31, 161, 136, 255, 31, 161, 135, 255, 31, 162, 135, 255, 32, 163, 134, 255, 32, 164, 134, 255, 33, 165, 133, 255, 33, 166, 133, 255, 34, 167, 133, 255, 34, 168, 132, 255, 35, 169, 131, 255, 36, 170, 131, 255, 37, 171, 130, 255, 37, 172, 130, 255, 38, 173, 129, 255, 39, 173, 129, 255, 40, 174, 128, 255, 41, 175, 127, 255, 42, 176, 127, 255, 44, 177, 126, 255, 45, 178, 125, 255, 46, 179, 124, 255, 47, 180, 124, 255, 49, 181, 123, 255, 50, 182, 122, 255, 52, 182, 121, 255, 53, 183, 121, 255, 55, 184, 120, 255, 56, 185, 119, 255, 58, 186, 118, 255, 59, 187, 117, 255, 61, 188, 116, 255, 63, 188, 115, 255, 64, 189, 114, 255, 66, 190, 113, 255, 68, 191, 112, 255, 70, 192, 111, 255, 72, 193, 110, 255, 74, 193, 109, 255, 76, 194, 108, 255, 78, 195, 107, 255, 80, 196, 106, 255, 82, 197, 105, 255, 84, 197, 104, 255, 86, 198, 103, 255, 88, 199, 101, 255, 90, 200, 100, 255, 92, 200, 99, 255, 94, 201, 98, 255, 96, 202, 96, 255, 99, 203, 95, 255, 101, 203, 94, 255, 103, 204, 92, 255, 105, 205, 91, 255, 108, 205, 90, 255, 110, 206, 88, 255, 112, 207, 87, 255, 115, 208, 86, 255, 117, 208, 84, 255, 119, 209, 83, 255, 122, 209, 81, 255, 124, 210, 80, 255, 127, 211, 78, 255, 129, 211, 77, 255, 132, 212, 75, 255, 134, 213, 73, 255, 137, 213, 72, 255, 139, 214, 70, 255, 142, 214, 69, 255, 144, 215, 67, 255, 147, 215, 65, 255, 149, 216, 64, 255, 152, 216, 62, 255, 155, 217, 60, 255, 157, 217, 59, 255, 160, 218, 57, 255, 162, 218, 55, 255, 165, 219, 54, 255, 168, 219, 52, 255, 170, 220, 50, 255, 173, 220, 48, 255, 176, 221, 47, 255, 178, 221, 45, 255, 181, 222, 43, 255, 184, 222, 41, 255, 186, 222, 40, 255, 189, 223, 38, 255, 192, 223, 37, 255, 194, 223, 35, 255, 197, 224, 33, 255, 200, 224, 32, 255, 202, 225, 31, 255, 205, 225, 29, 255, 208, 225, 28, 255, 210, 226, 27, 255, 213, 226, 26, 255, 216, 226, 25, 255, 218, 227, 25, 255, 221, 227, 24, 255, 223, 227, 24, 255, 226, 228, 24, 255, 229, 228, 25, 255, 231, 228, 25, 255, 234, 229, 26, 255, 236, 229, 27, 255, 239, 229, 28, 255, 241, 229, 29, 255, 244, 230, 30, 255, 246, 230, 32, 255, 248, 230, 33, 255, 251, 231, 35, 255, 253, 231, 37, 255]),
|
||||
inferno: new Uint8Array([0, 0, 4, 255, 1, 0, 5, 255, 1, 1, 6, 255, 1, 1, 8, 255, 2, 1, 10, 255, 2, 2, 12, 255, 2, 2, 14, 255, 3, 2, 16, 255, 4, 3, 18, 255, 4, 3, 20, 255, 5, 4, 23, 255, 6, 4, 25, 255, 7, 5, 27, 255, 8, 5, 29, 255, 9, 6, 31, 255, 10, 7, 34, 255, 11, 7, 36, 255, 12, 8, 38, 255, 13, 8, 41, 255, 14, 9, 43, 255, 16, 9, 45, 255, 17, 10, 48, 255, 18, 10, 50, 255, 20, 11, 52, 255, 21, 11, 55, 255, 22, 11, 57, 255, 24, 12, 60, 255, 25, 12, 62, 255, 27, 12, 65, 255, 28, 12, 67, 255, 30, 12, 69, 255, 31, 12, 72, 255, 33, 12, 74, 255, 35, 12, 76, 255, 36, 12, 79, 255, 38, 12, 81, 255, 40, 11, 83, 255, 41, 11, 85, 255, 43, 11, 87, 255, 45, 11, 89, 255, 47, 10, 91, 255, 49, 10, 92, 255, 50, 10, 94, 255, 52, 10, 95, 255, 54, 9, 97, 255, 56, 9, 98, 255, 57, 9, 99, 255, 59, 9, 100, 255, 61, 9, 101, 255, 62, 9, 102, 255, 64, 10, 103, 255, 66, 10, 104, 255, 68, 10, 104, 255, 69, 10, 105, 255, 71, 11, 106, 255, 73, 11, 106, 255, 74, 12, 107, 255, 76, 12, 107, 255, 77, 13, 108, 255, 79, 13, 108, 255, 81, 14, 108, 255, 82, 14, 109, 255, 84, 15, 109, 255, 85, 15, 109, 255, 87, 16, 110, 255, 89, 16, 110, 255, 90, 17, 110, 255, 92, 18, 110, 255, 93, 18, 110, 255, 95, 19, 110, 255, 97, 19, 110, 255, 98, 20, 110, 255, 100, 21, 110, 255, 101, 21, 110, 255, 103, 22, 110, 255, 105, 22, 110, 255, 106, 23, 110, 255, 108, 24, 110, 255, 109, 24, 110, 255, 111, 25, 110, 255, 113, 25, 110, 255, 114, 26, 110, 255, 116, 26, 110, 255, 117, 27, 110, 255, 119, 28, 109, 255, 120, 28, 109, 255, 122, 29, 109, 255, 124, 29, 109, 255, 125, 30, 109, 255, 127, 30, 108, 255, 128, 31, 108, 255, 130, 32, 108, 255, 132, 32, 107, 255, 133, 33, 107, 255, 135, 33, 107, 255, 136, 34, 106, 255, 138, 34, 106, 255, 140, 35, 105, 255, 141, 35, 105, 255, 143, 36, 105, 255, 144, 37, 104, 255, 146, 37, 104, 255, 147, 38, 103, 255, 149, 38, 103, 255, 151, 39, 102, 255, 152, 39, 102, 255, 154, 40, 101, 255, 155, 41, 100, 255, 157, 41, 100, 255, 159, 42, 99, 255, 160, 42, 99, 255, 162, 43, 98, 255, 163, 44, 97, 255, 165, 44, 96, 255, 166, 45, 96, 255, 168, 46, 95, 255, 169, 46, 94, 255, 171, 47, 94, 255, 173, 48, 93, 255, 174, 48, 92, 255, 176, 49, 91, 255, 177, 50, 90, 255, 179, 50, 90, 255, 180, 51, 89, 255, 182, 52, 88, 255, 183, 53, 87, 255, 185, 53, 86, 255, 186, 54, 85, 255, 188, 55, 84, 255, 189, 56, 83, 255, 191, 57, 82, 255, 192, 58, 81, 255, 193, 58, 80, 255, 195, 59, 79, 255, 196, 60, 78, 255, 198, 61, 77, 255, 199, 62, 76, 255, 200, 63, 75, 255, 202, 64, 74, 255, 203, 65, 73, 255, 204, 66, 72, 255, 206, 67, 71, 255, 207, 68, 70, 255, 208, 69, 69, 255, 210, 70, 68, 255, 211, 71, 67, 255, 212, 72, 66, 255, 213, 74, 65, 255, 215, 75, 63, 255, 216, 76, 62, 255, 217, 77, 61, 255, 218, 78, 60, 255, 219, 80, 59, 255, 221, 81, 58, 255, 222, 82, 56, 255, 223, 83, 55, 255, 224, 85, 54, 255, 225, 86, 53, 255, 226, 87, 52, 255, 227, 89, 51, 255, 228, 90, 49, 255, 229, 92, 48, 255, 230, 93, 47, 255, 231, 94, 46, 255, 232, 96, 45, 255, 233, 97, 43, 255, 234, 99, 42, 255, 235, 100, 41, 255, 235, 102, 40, 255, 236, 103, 38, 255, 237, 105, 37, 255, 238, 106, 36, 255, 239, 108, 35, 255, 239, 110, 33, 255, 240, 111, 32, 255, 241, 113, 31, 255, 241, 115, 29, 255, 242, 116, 28, 255, 243, 118, 27, 255, 243, 120, 25, 255, 244, 121, 24, 255, 245, 123, 23, 255, 245, 125, 21, 255, 246, 126, 20, 255, 246, 128, 19, 255, 247, 130, 18, 255, 247, 132, 16, 255, 248, 133, 15, 255, 248, 135, 14, 255, 248, 137, 12, 255, 249, 139, 11, 255, 249, 140, 10, 255, 249, 142, 9, 255, 250, 144, 8, 255, 250, 146, 7, 255, 250, 148, 7, 255, 251, 150, 6, 255, 251, 151, 6, 255, 251, 153, 6, 255, 251, 155, 6, 255, 251, 157, 7, 255, 252, 159, 7, 255, 252, 161, 8, 255, 252, 163, 9, 255, 252, 165, 10, 255, 252, 166, 12, 255, 252, 168, 13, 255, 252, 170, 15, 255, 252, 172, 17, 255, 252, 174, 18, 255, 252, 176, 20, 255, 252, 178, 22, 255, 252, 180, 24, 255, 251, 182, 26, 255, 251, 184, 29, 255, 251, 186, 31, 255, 251, 188, 33, 255, 251, 190, 35, 255, 250, 192, 38, 255, 250, 194, 40, 255, 250, 196, 42, 255, 250, 198, 45, 255, 249, 199, 47, 255, 249, 201, 50, 255, 249, 203, 53, 255, 248, 205, 55, 255, 248, 207, 58, 255, 247, 209, 61, 255, 247, 211, 64, 255, 246, 213, 67, 255, 246, 215, 70, 255, 245, 217, 73, 255, 245, 219, 76, 255, 244, 221, 79, 255, 244, 223, 83, 255, 244, 225, 86, 255, 243, 227, 90, 255, 243, 229, 93, 255, 242, 230, 97, 255, 242, 232, 101, 255, 242, 234, 105, 255, 241, 236, 109, 255, 241, 237, 113, 255, 241, 239, 117, 255, 241, 241, 121, 255, 242, 242, 125, 255, 242, 244, 130, 255, 243, 245, 134, 255, 243, 246, 138, 255, 244, 248, 142, 255, 245, 249, 146, 255, 246, 250, 150, 255, 248, 251, 154, 255, 249, 252, 157, 255, 250, 253, 161, 255, 252, 255, 164, 255]),
|
||||
rainbow: {
|
||||
colors: ['#96005A', '#0000C8', '#0019FF', '#0098FF', '#2CFF96', '#97FF00', '#FFEA00', '#FF6F00', '#FF0000'],
|
||||
positions: [0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1]
|
||||
},
|
||||
jet: {
|
||||
colors: ['#000083', '#003CAA', '#05FFFF', '#FFFF00', '#FA0000', '#800000'],
|
||||
positions: [0, 0.125, 0.375, 0.625, 0.875, 1]
|
||||
},
|
||||
hsv: {
|
||||
colors: ['#ff0000', '#fdff02', '#f7ff02', '#00fc04', '#00fc0a', '#01f9ff', '#0200fd', '#0800fd', '#ff00fb', '#ff00f5', '#ff0006'],
|
||||
positions: [0, 0.169, 0.173, 0.337, 0.341, 0.506, 0.671, 0.675, 0.839, 0.843, 1]
|
||||
},
|
||||
hot: {
|
||||
colors: ['#000000', '#e60000', '#ffd200', '#ffffff'],
|
||||
positions: [0, 0.3, 0.6, 1]
|
||||
},
|
||||
cool: {
|
||||
colors: ['#00ffff', '#ff00ff'],
|
||||
positions: [0, 1]
|
||||
},
|
||||
spring: {
|
||||
colors: ['#ff00ff', '#ffff00'],
|
||||
positions: [0, 1]
|
||||
},
|
||||
summer: {
|
||||
colors: ['#008066', '#ffff66'],
|
||||
positions: [0, 1]
|
||||
},
|
||||
autumn: {
|
||||
colors: ['#ff0000', '#ffff00'],
|
||||
positions: [0, 1]
|
||||
},
|
||||
winter: {
|
||||
colors: ['#0000ff', '#00ff80'],
|
||||
positions: [0, 1]
|
||||
},
|
||||
bone: {
|
||||
colors: ['#000000', '#545474', '#a9c8c8', '#ffffff'],
|
||||
positions: [0, 0.376, 0.753, 1]
|
||||
},
|
||||
copper: {
|
||||
colors: ['#000000', '#ffa066', '#ffc77f'],
|
||||
positions: [0, 0.804, 1]
|
||||
},
|
||||
greys: {
|
||||
colors: ['#000000', '#ffffff'],
|
||||
positions: [0, 1]
|
||||
},
|
||||
yignbu: {
|
||||
colors: ['#081d58', '#253494', '#225ea8', '#1d91c0', '#41b6c4', '#7fcdbb', '#c7e9b4', '#edf8d9', '#ffffd9'],
|
||||
positions: [0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1]
|
||||
},
|
||||
greens: {
|
||||
colors: ['#00441b', '#006d2c', '#238b45', '#41ab5d', '#74c476', '#a1d99b', '#c7e9c0', '#e5f5e0', '#f7fcf5'],
|
||||
positions: [0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1]
|
||||
},
|
||||
wind: {
|
||||
colors: ['#3288bd', '#66c2a5', '#abdda4', '#e6f598', '#fee08b', '#fdae61', '#f46d43', '#d53e4f'],
|
||||
positions: [0, 0.1, 0.2, 0.6, 0.7, 0.8, 0.9, 1]
|
||||
},
|
||||
yiorrd: {
|
||||
colors: ['#800026', '#bd0026', '#e31a1c', '#fc4e2a', '#fd8d3c', '#feb24c', '#fed976', '#ffeda0', '#ffffcc'],
|
||||
positions: [0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1]
|
||||
},
|
||||
bluered: {
|
||||
colors: ['#0000ff', '#ff0000'],
|
||||
positions: [0, 1]
|
||||
},
|
||||
rdbu: {
|
||||
colors: ['#050aac', '#6a89f7', '#bebebe', '#dcaa84', '#e6915a', '#b20a1c'],
|
||||
positions: [0, 0.35, 0.5, 0.6, 0.7, 1]
|
||||
},
|
||||
picnic: {
|
||||
colors: ['#0000ff', '#3399ff', '#66ccff', '#99ccff', '#ccccff', '#ffffff', '#ffccff', '#ff99ff', '#ff66cc', '#ff6666', '#ff0000'],
|
||||
positions: [0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]
|
||||
},
|
||||
portland: {
|
||||
colors: ['#0c3383', '#0a88ba', '#f2d338', '#f28f38', '#d91e1e'],
|
||||
positions: [0, 0.25, 0.5, 0.75, 1]
|
||||
},
|
||||
blackbody: {
|
||||
colors: ['#000000', '#e60000', '#e6d200', '#ffffff', '#a0c8ff'],
|
||||
positions: [0, 0.2, 0.4, 0.7, 1]
|
||||
},
|
||||
earth: {
|
||||
colors: ['#000082', '#00b4b4', '#28d228', '#e6e632', '#784614', '#ffffff'],
|
||||
positions: [0, 0.1, 0.2, 0.4, 0.6, 1]
|
||||
},
|
||||
electric: {
|
||||
colors: ['#000000', '#1e0064', '#780064', '#a05a00', '#e6c800', '#fffadc'],
|
||||
positions: [0, 0.15, 0.4, 0.6, 0.8, 1]
|
||||
},
|
||||
magma: new Uint8Array([0, 0, 4, 255, 1, 0, 5, 255, 1, 1, 6, 255, 1, 1, 8, 255, 2, 1, 9, 255, 2, 2, 11, 255, 2, 2, 13, 255, 3, 3, 15, 255, 3, 3, 18, 255, 4, 4, 20, 255, 5, 4, 22, 255, 6, 5, 24, 255, 6, 5, 26, 255, 7, 6, 28, 255, 8, 7, 30, 255, 9, 7, 32, 255, 10, 8, 34, 255, 11, 9, 36, 255, 12, 9, 38, 255, 13, 10, 41, 255, 14, 11, 43, 255, 16, 11, 45, 255, 17, 12, 47, 255, 18, 13, 49, 255, 19, 13, 52, 255, 20, 14, 54, 255, 21, 14, 56, 255, 22, 15, 59, 255, 24, 15, 61, 255, 25, 16, 63, 255, 26, 16, 66, 255, 28, 16, 68, 255, 29, 17, 71, 255, 30, 17, 73, 255, 32, 17, 75, 255, 33, 17, 78, 255, 34, 17, 80, 255, 36, 18, 83, 255, 37, 18, 85, 255, 39, 18, 88, 255, 41, 17, 90, 255, 42, 17, 92, 255, 44, 17, 95, 255, 45, 17, 97, 255, 47, 17, 99, 255, 49, 17, 101, 255, 51, 16, 103, 255, 52, 16, 105, 255, 54, 16, 107, 255, 56, 16, 108, 255, 57, 15, 110, 255, 59, 15, 112, 255, 61, 15, 113, 255, 63, 15, 114, 255, 64, 15, 116, 255, 66, 15, 117, 255, 68, 15, 118, 255, 69, 16, 119, 255, 71, 16, 120, 255, 73, 16, 120, 255, 74, 16, 121, 255, 76, 17, 122, 255, 78, 17, 123, 255, 79, 18, 123, 255, 81, 18, 124, 255, 82, 19, 124, 255, 84, 19, 125, 255, 86, 20, 125, 255, 87, 21, 126, 255, 89, 21, 126, 255, 90, 22, 126, 255, 92, 22, 127, 255, 93, 23, 127, 255, 95, 24, 127, 255, 96, 24, 128, 255, 98, 25, 128, 255, 100, 26, 128, 255, 101, 26, 128, 255, 103, 27, 128, 255, 104, 28, 129, 255, 106, 28, 129, 255, 107, 29, 129, 255, 109, 29, 129, 255, 110, 30, 129, 255, 112, 31, 129, 255, 114, 31, 129, 255, 115, 32, 129, 255, 117, 33, 129, 255, 118, 33, 129, 255, 120, 34, 129, 255, 121, 34, 130, 255, 123, 35, 130, 255, 124, 35, 130, 255, 126, 36, 130, 255, 128, 37, 130, 255, 129, 37, 129, 255, 131, 38, 129, 255, 132, 38, 129, 255, 134, 39, 129, 255, 136, 39, 129, 255, 137, 40, 129, 255, 139, 41, 129, 255, 140, 41, 129, 255, 142, 42, 129, 255, 144, 42, 129, 255, 145, 43, 129, 255, 147, 43, 128, 255, 148, 44, 128, 255, 150, 44, 128, 255, 152, 45, 128, 255, 153, 45, 128, 255, 155, 46, 127, 255, 156, 46, 127, 255, 158, 47, 127, 255, 160, 47, 127, 255, 161, 48, 126, 255, 163, 48, 126, 255, 165, 49, 126, 255, 166, 49, 125, 255, 168, 50, 125, 255, 170, 51, 125, 255, 171, 51, 124, 255, 173, 52, 124, 255, 174, 52, 123, 255, 176, 53, 123, 255, 178, 53, 123, 255, 179, 54, 122, 255, 181, 54, 122, 255, 183, 55, 121, 255, 184, 55, 121, 255, 186, 56, 120, 255, 188, 57, 120, 255, 189, 57, 119, 255, 191, 58, 119, 255, 192, 58, 118, 255, 194, 59, 117, 255, 196, 60, 117, 255, 197, 60, 116, 255, 199, 61, 115, 255, 200, 62, 115, 255, 202, 62, 114, 255, 204, 63, 113, 255, 205, 64, 113, 255, 207, 64, 112, 255, 208, 65, 111, 255, 210, 66, 111, 255, 211, 67, 110, 255, 213, 68, 109, 255, 214, 69, 108, 255, 216, 69, 108, 255, 217, 70, 107, 255, 219, 71, 106, 255, 220, 72, 105, 255, 222, 73, 104, 255, 223, 74, 104, 255, 224, 76, 103, 255, 226, 77, 102, 255, 227, 78, 101, 255, 228, 79, 100, 255, 229, 80, 100, 255, 231, 82, 99, 255, 232, 83, 98, 255, 233, 84, 98, 255, 234, 86, 97, 255, 235, 87, 96, 255, 236, 88, 96, 255, 237, 90, 95, 255, 238, 91, 94, 255, 239, 93, 94, 255, 240, 95, 94, 255, 241, 96, 93, 255, 242, 98, 93, 255, 242, 100, 92, 255, 243, 101, 92, 255, 244, 103, 92, 255, 244, 105, 92, 255, 245, 107, 92, 255, 246, 108, 92, 255, 246, 110, 92, 255, 247, 112, 92, 255, 247, 114, 92, 255, 248, 116, 92, 255, 248, 118, 92, 255, 249, 120, 93, 255, 249, 121, 93, 255, 249, 123, 93, 255, 250, 125, 94, 255, 250, 127, 94, 255, 250, 129, 95, 255, 251, 131, 95, 255, 251, 133, 96, 255, 251, 135, 97, 255, 252, 137, 97, 255, 252, 138, 98, 255, 252, 140, 99, 255, 252, 142, 100, 255, 252, 144, 101, 255, 253, 146, 102, 255, 253, 148, 103, 255, 253, 150, 104, 255, 253, 152, 105, 255, 253, 154, 106, 255, 253, 155, 107, 255, 254, 157, 108, 255, 254, 159, 109, 255, 254, 161, 110, 255, 254, 163, 111, 255, 254, 165, 113, 255, 254, 167, 114, 255, 254, 169, 115, 255, 254, 170, 116, 255, 254, 172, 118, 255, 254, 174, 119, 255, 254, 176, 120, 255, 254, 178, 122, 255, 254, 180, 123, 255, 254, 182, 124, 255, 254, 183, 126, 255, 254, 185, 127, 255, 254, 187, 129, 255, 254, 189, 130, 255, 254, 191, 132, 255, 254, 193, 133, 255, 254, 194, 135, 255, 254, 196, 136, 255, 254, 198, 138, 255, 254, 200, 140, 255, 254, 202, 141, 255, 254, 204, 143, 255, 254, 205, 144, 255, 254, 207, 146, 255, 254, 209, 148, 255, 254, 211, 149, 255, 254, 213, 151, 255, 254, 215, 153, 255, 254, 216, 154, 255, 253, 218, 156, 255, 253, 220, 158, 255, 253, 222, 160, 255, 253, 224, 161, 255, 253, 226, 163, 255, 253, 227, 165, 255, 253, 229, 167, 255, 253, 231, 169, 255, 253, 233, 170, 255, 253, 235, 172, 255, 252, 236, 174, 255, 252, 238, 176, 255, 252, 240, 178, 255, 252, 242, 180, 255, 252, 244, 182, 255, 252, 246, 184, 255, 252, 247, 185, 255, 252, 249, 187, 255, 252, 251, 189, 255, 252, 253, 191, 255]),
|
||||
plasma: new Uint8Array([13, 8, 135, 255, 16, 7, 136, 255, 19, 7, 137, 255, 22, 7, 138, 255, 25, 6, 140, 255, 27, 6, 141, 255, 29, 6, 142, 255, 32, 6, 143, 255, 34, 6, 144, 255, 36, 6, 145, 255, 38, 5, 145, 255, 40, 5, 146, 255, 42, 5, 147, 255, 44, 5, 148, 255, 46, 5, 149, 255, 47, 5, 150, 255, 49, 5, 151, 255, 51, 5, 151, 255, 53, 4, 152, 255, 55, 4, 153, 255, 56, 4, 154, 255, 58, 4, 154, 255, 60, 4, 155, 255, 62, 4, 156, 255, 63, 4, 156, 255, 65, 4, 157, 255, 67, 3, 158, 255, 68, 3, 158, 255, 70, 3, 159, 255, 72, 3, 159, 255, 73, 3, 160, 255, 75, 3, 161, 255, 76, 2, 161, 255, 78, 2, 162, 255, 80, 2, 162, 255, 81, 2, 163, 255, 83, 2, 163, 255, 85, 2, 164, 255, 86, 1, 164, 255, 88, 1, 164, 255, 89, 1, 165, 255, 91, 1, 165, 255, 92, 1, 166, 255, 94, 1, 166, 255, 96, 1, 166, 255, 97, 0, 167, 255, 99, 0, 167, 255, 100, 0, 167, 255, 102, 0, 167, 255, 103, 0, 168, 255, 105, 0, 168, 255, 106, 0, 168, 255, 108, 0, 168, 255, 110, 0, 168, 255, 111, 0, 168, 255, 113, 0, 168, 255, 114, 1, 168, 255, 116, 1, 168, 255, 117, 1, 168, 255, 119, 1, 168, 255, 120, 1, 168, 255, 122, 2, 168, 255, 123, 2, 168, 255, 125, 3, 168, 255, 126, 3, 168, 255, 128, 4, 168, 255, 129, 4, 167, 255, 131, 5, 167, 255, 132, 5, 167, 255, 134, 6, 166, 255, 135, 7, 166, 255, 136, 8, 166, 255, 138, 9, 165, 255, 139, 10, 165, 255, 141, 11, 165, 255, 142, 12, 164, 255, 143, 13, 164, 255, 145, 14, 163, 255, 146, 15, 163, 255, 148, 16, 162, 255, 149, 17, 161, 255, 150, 19, 161, 255, 152, 20, 160, 255, 153, 21, 159, 255, 154, 22, 159, 255, 156, 23, 158, 255, 157, 24, 157, 255, 158, 25, 157, 255, 160, 26, 156, 255, 161, 27, 155, 255, 162, 29, 154, 255, 163, 30, 154, 255, 165, 31, 153, 255, 166, 32, 152, 255, 167, 33, 151, 255, 168, 34, 150, 255, 170, 35, 149, 255, 171, 36, 148, 255, 172, 38, 148, 255, 173, 39, 147, 255, 174, 40, 146, 255, 176, 41, 145, 255, 177, 42, 144, 255, 178, 43, 143, 255, 179, 44, 142, 255, 180, 46, 141, 255, 181, 47, 140, 255, 182, 48, 139, 255, 183, 49, 138, 255, 184, 50, 137, 255, 186, 51, 136, 255, 187, 52, 136, 255, 188, 53, 135, 255, 189, 55, 134, 255, 190, 56, 133, 255, 191, 57, 132, 255, 192, 58, 131, 255, 193, 59, 130, 255, 194, 60, 129, 255, 195, 61, 128, 255, 196, 62, 127, 255, 197, 64, 126, 255, 198, 65, 125, 255, 199, 66, 124, 255, 200, 67, 123, 255, 201, 68, 122, 255, 202, 69, 122, 255, 203, 70, 121, 255, 204, 71, 120, 255, 204, 73, 119, 255, 205, 74, 118, 255, 206, 75, 117, 255, 207, 76, 116, 255, 208, 77, 115, 255, 209, 78, 114, 255, 210, 79, 113, 255, 211, 81, 113, 255, 212, 82, 112, 255, 213, 83, 111, 255, 213, 84, 110, 255, 214, 85, 109, 255, 215, 86, 108, 255, 216, 87, 107, 255, 217, 88, 106, 255, 218, 90, 106, 255, 218, 91, 105, 255, 219, 92, 104, 255, 220, 93, 103, 255, 221, 94, 102, 255, 222, 95, 101, 255, 222, 97, 100, 255, 223, 98, 99, 255, 224, 99, 99, 255, 225, 100, 98, 255, 226, 101, 97, 255, 226, 102, 96, 255, 227, 104, 95, 255, 228, 105, 94, 255, 229, 106, 93, 255, 229, 107, 93, 255, 230, 108, 92, 255, 231, 110, 91, 255, 231, 111, 90, 255, 232, 112, 89, 255, 233, 113, 88, 255, 233, 114, 87, 255, 234, 116, 87, 255, 235, 117, 86, 255, 235, 118, 85, 255, 236, 119, 84, 255, 237, 121, 83, 255, 237, 122, 82, 255, 238, 123, 81, 255, 239, 124, 81, 255, 239, 126, 80, 255, 240, 127, 79, 255, 240, 128, 78, 255, 241, 129, 77, 255, 241, 131, 76, 255, 242, 132, 75, 255, 243, 133, 75, 255, 243, 135, 74, 255, 244, 136, 73, 255, 244, 137, 72, 255, 245, 139, 71, 255, 245, 140, 70, 255, 246, 141, 69, 255, 246, 143, 68, 255, 247, 144, 68, 255, 247, 145, 67, 255, 247, 147, 66, 255, 248, 148, 65, 255, 248, 149, 64, 255, 249, 151, 63, 255, 249, 152, 62, 255, 249, 154, 62, 255, 250, 155, 61, 255, 250, 156, 60, 255, 250, 158, 59, 255, 251, 159, 58, 255, 251, 161, 57, 255, 251, 162, 56, 255, 252, 163, 56, 255, 252, 165, 55, 255, 252, 166, 54, 255, 252, 168, 53, 255, 252, 169, 52, 255, 253, 171, 51, 255, 253, 172, 51, 255, 253, 174, 50, 255, 253, 175, 49, 255, 253, 177, 48, 255, 253, 178, 47, 255, 253, 180, 47, 255, 253, 181, 46, 255, 254, 183, 45, 255, 254, 184, 44, 255, 254, 186, 44, 255, 254, 187, 43, 255, 254, 189, 42, 255, 254, 190, 42, 255, 254, 192, 41, 255, 253, 194, 41, 255, 253, 195, 40, 255, 253, 197, 39, 255, 253, 198, 39, 255, 253, 200, 39, 255, 253, 202, 38, 255, 253, 203, 38, 255, 252, 205, 37, 255, 252, 206, 37, 255, 252, 208, 37, 255, 252, 210, 37, 255, 251, 211, 36, 255, 251, 213, 36, 255, 251, 215, 36, 255, 250, 216, 36, 255, 250, 218, 36, 255, 249, 220, 36, 255, 249, 221, 37, 255, 248, 223, 37, 255, 248, 225, 37, 255, 247, 226, 37, 255, 247, 228, 37, 255, 246, 230, 38, 255, 246, 232, 38, 255, 245, 233, 38, 255, 245, 235, 39, 255, 244, 237, 39, 255, 243, 238, 39, 255, 243, 240, 39, 255, 242, 242, 39, 255, 241, 244, 38, 255, 241, 245, 37, 255, 240, 247, 36, 255, 240, 249, 33, 255])
|
||||
}; // export default colorScales;
|
||||
|
||||
exports.colorScales = colorScales;
|
|
@ -1,51 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _base = _interopRequireDefault(require("./base"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
/**
|
||||
* 视觉通道 filter
|
||||
* @class Attr.filter
|
||||
*/
|
||||
var Filter =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Filter, _Base);
|
||||
|
||||
function Filter(cfg) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, Filter);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Filter).call(this, cfg));
|
||||
_this.names = ['filter'];
|
||||
_this.type = 'filter';
|
||||
_this.gradient = null;
|
||||
return _this;
|
||||
}
|
||||
|
||||
return Filter;
|
||||
}(_base["default"]);
|
||||
|
||||
var _default = Filter;
|
||||
exports["default"] = _default;
|
|
@ -1,37 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _base = _interopRequireDefault(require("./base"));
|
||||
|
||||
var _color = _interopRequireDefault(require("./color"));
|
||||
|
||||
var _size = _interopRequireDefault(require("./size"));
|
||||
|
||||
var _opacity = _interopRequireDefault(require("./opacity"));
|
||||
|
||||
var _shape = _interopRequireDefault(require("./shape"));
|
||||
|
||||
var _position = _interopRequireDefault(require("./position"));
|
||||
|
||||
var _symbol = _interopRequireDefault(require("./symbol"));
|
||||
|
||||
var _filter = _interopRequireDefault(require("./filter"));
|
||||
|
||||
var _pattern = _interopRequireDefault(require("./pattern"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
_base["default"].Color = _color["default"];
|
||||
_base["default"].Size = _size["default"];
|
||||
_base["default"].Opacity = _opacity["default"];
|
||||
_base["default"].Shape = _shape["default"];
|
||||
_base["default"].Position = _position["default"];
|
||||
_base["default"].Symbol = _symbol["default"];
|
||||
_base["default"].Filter = _filter["default"];
|
||||
_base["default"].Pattern = _pattern["default"];
|
||||
var _default = _base["default"];
|
||||
exports["default"] = _default;
|
|
@ -1,51 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _base = _interopRequireDefault(require("./base"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
/**
|
||||
* 视觉通道 Opacity
|
||||
* @class Attr.Opacity
|
||||
*/
|
||||
var Opacity =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Opacity, _Base);
|
||||
|
||||
function Opacity(cfg) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, Opacity);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Opacity).call(this, cfg));
|
||||
_this.names = ['opacity'];
|
||||
_this.type = 'opacity';
|
||||
_this.gradient = null;
|
||||
return _this;
|
||||
}
|
||||
|
||||
return Opacity;
|
||||
}(_base["default"]);
|
||||
|
||||
var _default = Opacity;
|
||||
exports["default"] = _default;
|
|
@ -1,51 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _base = _interopRequireDefault(require("./base"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
/**
|
||||
* 视觉通道 pattern
|
||||
* @class Attr.pattern
|
||||
*/
|
||||
var Pattern =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Pattern, _Base);
|
||||
|
||||
function Pattern(cfg) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, Pattern);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Pattern).call(this, cfg));
|
||||
_this.names = ['pattern'];
|
||||
_this.type = 'pattern';
|
||||
_this.gradient = null;
|
||||
return _this;
|
||||
}
|
||||
|
||||
return Pattern;
|
||||
}(_base["default"]);
|
||||
|
||||
var _default = Pattern;
|
||||
exports["default"] = _default;
|
|
@ -1,140 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _base = _interopRequireDefault(require("./base"));
|
||||
|
||||
var _util = _interopRequireDefault(require("../util"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var Position =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Position, _Base);
|
||||
|
||||
function Position(cfg) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, Position);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Position).call(this, cfg));
|
||||
_this.names = ['x', 'y'];
|
||||
_this.type = 'position';
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(Position, [{
|
||||
key: "mapping",
|
||||
value: function mapping(x, y) {
|
||||
var scales = this.scales;
|
||||
var coord = this.coord;
|
||||
var scaleX = scales[0];
|
||||
var scaleY = scales[1];
|
||||
var rstX;
|
||||
var rstY;
|
||||
var obj;
|
||||
|
||||
if (_util["default"].isNil(x) || _util["default"].isNil(y)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (_util["default"].isArray(y) && _util["default"].isArray(x)) {
|
||||
rstX = [];
|
||||
rstY = [];
|
||||
|
||||
for (var i = 0, j = 0; i < x.length && j < y.length; i++, j++) {
|
||||
obj = coord.convertPoint({
|
||||
x: scaleX.scale(x[i]),
|
||||
y: scaleY.scale(y[j])
|
||||
});
|
||||
rstX.push(obj.x);
|
||||
rstY.push(obj.y);
|
||||
}
|
||||
} else if (_util["default"].isArray(y)) {
|
||||
x = scaleX.scale(x);
|
||||
rstY = [];
|
||||
|
||||
_util["default"].each(y, function (yVal) {
|
||||
yVal = scaleY.scale(yVal);
|
||||
obj = coord.convertPoint({
|
||||
x: x,
|
||||
y: yVal
|
||||
});
|
||||
|
||||
if (rstX && rstX !== obj.x) {
|
||||
if (!_util["default"].isArray(rstX)) {
|
||||
rstX = [rstX];
|
||||
}
|
||||
|
||||
rstX.push(obj.x);
|
||||
} else {
|
||||
rstX = obj.x;
|
||||
}
|
||||
|
||||
rstY.push(obj.y);
|
||||
});
|
||||
} else if (_util["default"].isArray(x)) {
|
||||
y = scaleY.scale(y);
|
||||
rstX = [];
|
||||
|
||||
_util["default"].each(x, function (xVal) {
|
||||
xVal = scaleX.scale(xVal);
|
||||
obj = coord.convertPoint({
|
||||
x: xVal,
|
||||
y: y
|
||||
});
|
||||
|
||||
if (rstY && rstY !== obj.y) {
|
||||
if (!_util["default"].isArray(rstY)) {
|
||||
rstY = [rstY];
|
||||
}
|
||||
|
||||
rstY.push(obj.y);
|
||||
} else {
|
||||
rstY = obj.y;
|
||||
}
|
||||
|
||||
rstX.push(obj.x);
|
||||
});
|
||||
} else {
|
||||
x = scaleX.scale(x);
|
||||
y = scaleY.scale(y);
|
||||
var point = coord.convertPoint({
|
||||
x: x,
|
||||
y: y
|
||||
});
|
||||
rstX = point.x;
|
||||
rstY = point.y;
|
||||
}
|
||||
|
||||
return [rstX, rstY];
|
||||
}
|
||||
}]);
|
||||
|
||||
return Position;
|
||||
}(_base["default"]);
|
||||
|
||||
var _default = Position;
|
||||
exports["default"] = _default;
|
|
@ -1,89 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _base = _interopRequireDefault(require("./base"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
/**
|
||||
* 视觉通道 Shape
|
||||
* @class Attr.Shape
|
||||
*/
|
||||
var Shape =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Shape, _Base);
|
||||
|
||||
function Shape(cfg) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, Shape);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Shape).call(this, cfg));
|
||||
_this.names = ['shape'];
|
||||
_this.type = 'shape';
|
||||
_this.gradient = null;
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
|
||||
|
||||
_createClass(Shape, [{
|
||||
key: "getLinearValue",
|
||||
value: function getLinearValue(percent) {
|
||||
var values = this.values;
|
||||
var index = Math.round((values.length - 1) * percent);
|
||||
return values[index];
|
||||
}
|
||||
/**
|
||||
* @override
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: "_getAttrValue",
|
||||
value: function _getAttrValue(scale, value) {
|
||||
if (this.values === 'text') {
|
||||
return value;
|
||||
}
|
||||
|
||||
var values = this.values;
|
||||
|
||||
if (scale.isCategory && !this.linear) {
|
||||
var index = scale.translate(value);
|
||||
return values[index % values.length];
|
||||
}
|
||||
|
||||
var percent = scale.scale(value);
|
||||
return this.getLinearValue(percent);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Shape;
|
||||
}(_base["default"]);
|
||||
|
||||
var _default = Shape;
|
||||
exports["default"] = _default;
|
107
lib/attr/size.js
107
lib/attr/size.js
|
@ -1,107 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _base = _interopRequireDefault(require("./base"));
|
||||
|
||||
var _util = _interopRequireDefault(require("../util"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
/**
|
||||
* 视觉通道 size
|
||||
* @class Attr.Size
|
||||
*/
|
||||
var Size =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Size, _Base);
|
||||
|
||||
function Size(cfg) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, Size);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Size).call(this, cfg));
|
||||
_this.names = ['size'];
|
||||
_this.type = 'size';
|
||||
_this.gradient = null;
|
||||
_this.domainIndex = 0;
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(Size, [{
|
||||
key: "mapping",
|
||||
value: function mapping() {
|
||||
// 重构
|
||||
var self = this;
|
||||
var outputs = [];
|
||||
var scales = self.scales;
|
||||
|
||||
if (self.values.length === 0) {
|
||||
var callback = this.callback.bind(this);
|
||||
outputs.push(callback.apply(void 0, arguments));
|
||||
} else {
|
||||
if (!_util["default"].isArray(self.values[0])) {
|
||||
self.values = [self.values];
|
||||
}
|
||||
|
||||
for (var i = 0; i < scales.length; i++) {
|
||||
outputs.push(self._scaling(scales[i], arguments[i]));
|
||||
}
|
||||
}
|
||||
|
||||
this.domainIndex = 0;
|
||||
return outputs;
|
||||
}
|
||||
}, {
|
||||
key: "_scaling",
|
||||
value: function _scaling(scale, v) {
|
||||
if (scale.type === 'identity') {
|
||||
return v;
|
||||
}
|
||||
|
||||
var percent = scale.scale(v);
|
||||
return this.getLinearValue(percent); // else if (scale.type === 'linear') {
|
||||
}
|
||||
}, {
|
||||
key: "getLinearValue",
|
||||
value: function getLinearValue(percent) {
|
||||
var values = this.values[this.domainIndex];
|
||||
var steps = values.length - 1;
|
||||
var step = Math.floor(steps * percent);
|
||||
var leftPercent = steps * percent - step;
|
||||
var start = values[step];
|
||||
var end = step === steps ? start : values[step + 1];
|
||||
var rstValue = start + (end - start) * leftPercent;
|
||||
this.domainIndex += 1;
|
||||
return rstValue;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Size;
|
||||
}(_base["default"]);
|
||||
|
||||
var _default = Size;
|
||||
exports["default"] = _default;
|
|
@ -1,51 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _base = _interopRequireDefault(require("./base"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
/**
|
||||
* 视觉通道 symbol
|
||||
* @class Attr.symbol
|
||||
*/
|
||||
var _Symbol =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(_Symbol, _Base);
|
||||
|
||||
function _Symbol(cfg) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, _Symbol);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(_Symbol).call(this, cfg));
|
||||
_this.names = ['symbol'];
|
||||
_this.type = 'symbol';
|
||||
_this.gradient = null;
|
||||
return _this;
|
||||
}
|
||||
|
||||
return _Symbol;
|
||||
}(_base["default"]);
|
||||
|
||||
var _default = _Symbol;
|
||||
exports["default"] = _default;
|
|
@ -1 +0,0 @@
|
|||
"use strict";
|
|
@ -1 +0,0 @@
|
|||
"use strict";
|
|
@ -1 +0,0 @@
|
|||
"use strict";
|
|
@ -1,14 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
/**
|
||||
* @fileOverview chart component module
|
||||
* @author sima.zhang1990@gmail.com
|
||||
*/
|
||||
module.exports = {
|
||||
Axis: require('./axis/index'),
|
||||
Guide: require('./guide/index'),
|
||||
Label: require('./label/index'),
|
||||
Legend: require('./legend/index'),
|
||||
Plot: require('./plot'),
|
||||
Tooltip: require('./tooltip/index')
|
||||
};
|
|
@ -1,693 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
/**
|
||||
* @fileOverview The class of tooltip
|
||||
* @author sima.zhang
|
||||
*/
|
||||
var Util = require('../../util');
|
||||
|
||||
var Base = require('../../base');
|
||||
|
||||
var Global = require('../../global');
|
||||
|
||||
var _require = require('@antv/g'),
|
||||
DomUtil = _require.DomUtil;
|
||||
|
||||
var CONTAINER_CLASS = 'g2-tooltip';
|
||||
var TITLE_CLASS = 'g2-tooltip-title';
|
||||
var LIST_CLASS = 'g2-tooltip-list';
|
||||
var MARKER_CLASS = 'g2-tooltip-marker';
|
||||
var LIST_ITEM_CLASS = 'g2-tooltip-list-item';
|
||||
|
||||
function find(dom, cls) {
|
||||
return dom.getElementsByClassName(cls)[0];
|
||||
}
|
||||
|
||||
function refixTooltipPosition(x, y, el, viewWidth, viewHeight) {
|
||||
var width = el.clientWidth;
|
||||
var height = el.clientHeight;
|
||||
var gap = 20;
|
||||
|
||||
if (x + width + gap > viewWidth) {
|
||||
x -= width + gap;
|
||||
x = x < 0 ? 0 : x;
|
||||
} else {
|
||||
x += gap;
|
||||
}
|
||||
|
||||
if (y + height + gap > viewHeight) {
|
||||
y -= height + gap;
|
||||
y = x < 0 ? 0 : y;
|
||||
} else {
|
||||
y += gap;
|
||||
}
|
||||
|
||||
return [x, y];
|
||||
}
|
||||
|
||||
function calcTooltipPosition(x, y, position, dom, target) {
|
||||
var domWidth = dom.clientWidth;
|
||||
var domHeight = dom.clientHeight;
|
||||
var rectWidth = 0;
|
||||
var rectHeight = 0;
|
||||
var gap = 20;
|
||||
|
||||
if (target) {
|
||||
var rect = target.getBBox();
|
||||
rectWidth = rect.width;
|
||||
rectHeight = rect.height;
|
||||
x = rect.x;
|
||||
y = rect.y;
|
||||
gap = 5;
|
||||
}
|
||||
|
||||
switch (position) {
|
||||
case 'inside':
|
||||
x = x + rectWidth / 2 - domWidth / 2;
|
||||
y = y + rectHeight / 2 - domHeight / 2;
|
||||
break;
|
||||
|
||||
case 'top':
|
||||
x = x + rectWidth / 2 - domWidth / 2;
|
||||
y = y - domHeight - gap;
|
||||
break;
|
||||
|
||||
case 'left':
|
||||
x = x - domWidth - gap;
|
||||
y = y + rectHeight / 2 - domHeight / 2;
|
||||
break;
|
||||
|
||||
case 'right':
|
||||
x = x + rectWidth + gap;
|
||||
y = y + rectHeight / 2 - domHeight / 2;
|
||||
break;
|
||||
|
||||
case 'bottom':
|
||||
default:
|
||||
x = x + rectWidth / 2 - domWidth / 2;
|
||||
y = y + rectHeight + gap;
|
||||
break;
|
||||
}
|
||||
|
||||
return [x, y];
|
||||
}
|
||||
|
||||
function confineTooltipPosition(x, y, el, plotRange) {
|
||||
var gap = 20;
|
||||
var width = el.clientWidth;
|
||||
var height = el.clientHeight;
|
||||
|
||||
if (x + width > plotRange.tr.x) {
|
||||
x -= width + 2 * gap;
|
||||
}
|
||||
|
||||
if (x < plotRange.tl.x) {
|
||||
x = plotRange.tl.x;
|
||||
}
|
||||
|
||||
if (y + height > plotRange.bl.y) {
|
||||
y -= height + 2 * gap;
|
||||
}
|
||||
|
||||
if (y < plotRange.tl.y) {
|
||||
y = plotRange.tl.y;
|
||||
}
|
||||
|
||||
return [x, y];
|
||||
}
|
||||
|
||||
var Tooltip =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Tooltip, _Base);
|
||||
|
||||
_createClass(Tooltip, [{
|
||||
key: "getDefaultCfg",
|
||||
value: function getDefaultCfg() {
|
||||
return {
|
||||
/**
|
||||
* 右下角坐标
|
||||
* @type {Number}
|
||||
*/
|
||||
x: 0,
|
||||
|
||||
/**
|
||||
* y 右下角坐标
|
||||
* @type {Number}
|
||||
*/
|
||||
y: 0,
|
||||
|
||||
/**
|
||||
* tooltip 记录项
|
||||
* @type {Array}
|
||||
*/
|
||||
items: null,
|
||||
|
||||
/**
|
||||
* 是否展示 title
|
||||
* @type {Boolean}
|
||||
*/
|
||||
showTitle: true,
|
||||
|
||||
/**
|
||||
* tooltip 辅助线配置
|
||||
* @type {Object}
|
||||
*/
|
||||
crosshairs: null,
|
||||
|
||||
/**
|
||||
* 视图范围
|
||||
* @type {Object}
|
||||
*/
|
||||
plotRange: null,
|
||||
|
||||
/**
|
||||
* x轴上,移动到位置的偏移量
|
||||
* @type {Number}
|
||||
*/
|
||||
offset: 10,
|
||||
|
||||
/**
|
||||
* 时间戳
|
||||
* @type {Number}
|
||||
*/
|
||||
timeStamp: 0,
|
||||
|
||||
/**
|
||||
* tooltip 容器模板
|
||||
* @type {String}
|
||||
*/
|
||||
containerTpl: '<div class="' + CONTAINER_CLASS + '">' + '<div class="' + TITLE_CLASS + '"></div>' + '<ul class="' + LIST_CLASS + '"></ul>' + '</div>',
|
||||
|
||||
/**
|
||||
* tooltip 列表项模板
|
||||
* @type {String}
|
||||
*/
|
||||
itemTpl: '<li data-index={index}>' + '<span style="background-color:{color};" class=' + MARKER_CLASS + '></span>' + '{name}: {value}</li>',
|
||||
|
||||
/**
|
||||
* 将 tooltip 展示在指定区域内
|
||||
* @type {Boolean}
|
||||
*/
|
||||
inPlot: true,
|
||||
|
||||
/**
|
||||
* tooltip 内容跟随鼠标移动
|
||||
* @type {Boolean}
|
||||
*/
|
||||
follow: true,
|
||||
|
||||
/**
|
||||
* 是否允许鼠标停留在 tooltip 上,默认不允许
|
||||
* @type {Boolean}
|
||||
*/
|
||||
enterable: false
|
||||
};
|
||||
}
|
||||
}, {
|
||||
key: "_initTooltipWrapper",
|
||||
value: function _initTooltipWrapper() {
|
||||
var self = this;
|
||||
var containerTpl = self.get('containerTpl');
|
||||
var outterNode = self.get('canvas').get('el').parentNode;
|
||||
var container;
|
||||
|
||||
if (/^\#/.test(containerTpl)) {
|
||||
// 如果传入 dom 节点的 id
|
||||
var id = containerTpl.replace('#', '');
|
||||
container = document.getElementById(id);
|
||||
} else {
|
||||
container = DomUtil.createDom(containerTpl);
|
||||
DomUtil.modifyCSS(container, self.get(CONTAINER_CLASS));
|
||||
outterNode.appendChild(container);
|
||||
outterNode.style.position = 'relative';
|
||||
}
|
||||
|
||||
self.set('container', container);
|
||||
}
|
||||
}, {
|
||||
key: "_init",
|
||||
value: function _init() {
|
||||
var crosshairs = this.get('crosshairs');
|
||||
var frontPlot = this.get('frontPlot');
|
||||
var backPlot = this.get('backPlot');
|
||||
var crosshairsGroup;
|
||||
|
||||
if (crosshairs) {
|
||||
if (crosshairs.type === 'rect') {
|
||||
this.set('crosshairs', Util.deepMix({}, Global.tooltipCrosshairsRect, crosshairs));
|
||||
crosshairsGroup = backPlot.addGroup({
|
||||
zIndex: 0
|
||||
});
|
||||
} else {
|
||||
this.set('crosshairs', Util.deepMix({}, Global.tooltipCrosshairsLine, crosshairs));
|
||||
crosshairsGroup = frontPlot.addGroup();
|
||||
}
|
||||
}
|
||||
|
||||
this.set('crosshairsGroup', crosshairsGroup);
|
||||
|
||||
this._initTooltipWrapper();
|
||||
}
|
||||
}]);
|
||||
|
||||
function Tooltip(cfg) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, Tooltip);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Tooltip).call(this, cfg));
|
||||
|
||||
_this._init(); // 初始化属性
|
||||
|
||||
|
||||
if (_this.get('items')) {
|
||||
_this._renderTooltip();
|
||||
}
|
||||
|
||||
_this._renderCrosshairs();
|
||||
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(Tooltip, [{
|
||||
key: "_clearDom",
|
||||
value: function _clearDom() {
|
||||
var container = this.get('container');
|
||||
var titleDom = find(container, TITLE_CLASS);
|
||||
var listDom = find(container, LIST_CLASS);
|
||||
|
||||
if (titleDom) {
|
||||
titleDom.innerHTML = '';
|
||||
}
|
||||
|
||||
if (listDom) {
|
||||
listDom.innerHTML = '';
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "_addItem",
|
||||
value: function _addItem(item, index) {
|
||||
var itemTpl = this.get('itemTpl'); // TODO: 有可能是个回调函数
|
||||
|
||||
var itemDiv = Util.substitute(itemTpl, Util.mix({
|
||||
index: index
|
||||
}, item));
|
||||
var itemDOM = DomUtil.createDom(itemDiv);
|
||||
DomUtil.modifyCSS(itemDOM, this.get(LIST_ITEM_CLASS));
|
||||
var markerDom = find(itemDOM, MARKER_CLASS);
|
||||
|
||||
if (markerDom) {
|
||||
DomUtil.modifyCSS(markerDom, this.get(MARKER_CLASS));
|
||||
}
|
||||
|
||||
return itemDOM;
|
||||
}
|
||||
}, {
|
||||
key: "_renderTooltip",
|
||||
value: function _renderTooltip() {
|
||||
var self = this;
|
||||
var showTitle = self.get('showTitle');
|
||||
var titleContent = self.get('titleContent');
|
||||
var container = self.get('container');
|
||||
var titleDom = find(container, TITLE_CLASS);
|
||||
var listDom = find(container, LIST_CLASS);
|
||||
var items = self.get('items');
|
||||
|
||||
self._clearDom();
|
||||
|
||||
if (titleDom && showTitle) {
|
||||
DomUtil.modifyCSS(titleDom, self.get(TITLE_CLASS));
|
||||
titleDom.innerHTML = titleContent;
|
||||
}
|
||||
|
||||
if (listDom) {
|
||||
DomUtil.modifyCSS(listDom, self.get(LIST_CLASS));
|
||||
Util.each(items, function (item, index) {
|
||||
listDom.appendChild(self._addItem(item, index));
|
||||
});
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "_clearCrosshairsGroup",
|
||||
value: function _clearCrosshairsGroup() {
|
||||
var crosshairsGroup = this.get('crosshairsGroup');
|
||||
this.set('crossLineShapeX', null);
|
||||
this.set('crossLineShapeY', null);
|
||||
this.set('crosshairsRectShape', null);
|
||||
crosshairsGroup.clear();
|
||||
}
|
||||
}, {
|
||||
key: "_renderCrosshairs",
|
||||
value: function _renderCrosshairs() {
|
||||
var crosshairs = this.get('crosshairs');
|
||||
var canvas = this.get('canvas');
|
||||
var plotRange = this.get('plotRange');
|
||||
var isTransposed = this.get('isTransposed');
|
||||
|
||||
if (crosshairs) {
|
||||
this._clearCrosshairsGroup();
|
||||
|
||||
switch (crosshairs.type) {
|
||||
case 'x':
|
||||
this._renderHorizontalLine(canvas, plotRange);
|
||||
|
||||
break;
|
||||
|
||||
case 'y':
|
||||
this._renderVerticalLine(canvas, plotRange);
|
||||
|
||||
break;
|
||||
|
||||
case 'cross':
|
||||
this._renderHorizontalLine(canvas, plotRange);
|
||||
|
||||
this._renderVerticalLine(canvas, plotRange);
|
||||
|
||||
break;
|
||||
|
||||
case 'rect':
|
||||
this._renderBackground(canvas, plotRange);
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
isTransposed ? this._renderHorizontalLine(canvas, plotRange) : this._renderVerticalLine(canvas, plotRange);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "_addCrossLineShape",
|
||||
value: function _addCrossLineShape(attrs, type) {
|
||||
var crosshairsGroup = this.get('crosshairsGroup');
|
||||
var shape = crosshairsGroup.addShape('line', {
|
||||
attrs: attrs
|
||||
});
|
||||
shape.hide();
|
||||
this.set('crossLineShape' + type, shape);
|
||||
return shape;
|
||||
}
|
||||
}, {
|
||||
key: "_renderVerticalLine",
|
||||
value: function _renderVerticalLine(canvas, plotRange) {
|
||||
var _this$get = this.get('crosshairs'),
|
||||
style = _this$get.style;
|
||||
|
||||
var attrs = Util.mix({
|
||||
x1: 0,
|
||||
y1: plotRange ? plotRange.bl.y : canvas.get('height'),
|
||||
x2: 0,
|
||||
y2: plotRange ? plotRange.tl.y : 0
|
||||
}, style);
|
||||
|
||||
this._addCrossLineShape(attrs, 'Y');
|
||||
}
|
||||
}, {
|
||||
key: "_renderHorizontalLine",
|
||||
value: function _renderHorizontalLine(canvas, plotRange) {
|
||||
var _this$get2 = this.get('crosshairs'),
|
||||
style = _this$get2.style;
|
||||
|
||||
var attrs = Util.mix({
|
||||
x1: plotRange ? plotRange.bl.x : canvas.get('width'),
|
||||
y1: 0,
|
||||
x2: plotRange ? plotRange.br.x : 0,
|
||||
y2: 0
|
||||
}, style);
|
||||
|
||||
this._addCrossLineShape(attrs, 'X');
|
||||
}
|
||||
}, {
|
||||
key: "_renderBackground",
|
||||
value: function _renderBackground(canvas, plotRange) {
|
||||
var _this$get3 = this.get('crosshairs'),
|
||||
style = _this$get3.style;
|
||||
|
||||
var crosshairsGroup = this.get('crosshairsGroup');
|
||||
var attrs = Util.mix({
|
||||
x: plotRange ? plotRange.tl.x : 0,
|
||||
y: plotRange ? plotRange.tl.y : canvas.get('height'),
|
||||
width: plotRange ? plotRange.br.x - plotRange.bl.x : canvas.get('width'),
|
||||
height: plotRange ? Math.abs(plotRange.tl.y - plotRange.bl.y) : canvas.get('height')
|
||||
}, style);
|
||||
var shape = crosshairsGroup.addShape('rect', {
|
||||
attrs: attrs
|
||||
});
|
||||
shape.hide();
|
||||
this.set('crosshairsRectShape', shape);
|
||||
return shape;
|
||||
}
|
||||
}, {
|
||||
key: "isContentChange",
|
||||
value: function isContentChange(title, items) {
|
||||
var titleContent = this.get('titleContent');
|
||||
var lastItems = this.get('items');
|
||||
var isChanged = !(title === titleContent && lastItems.length === items.length);
|
||||
|
||||
if (!isChanged) {
|
||||
Util.each(items, function (item, index) {
|
||||
var preItem = lastItems[index];
|
||||
isChanged = item.value !== preItem.value || item.color !== preItem.color || item.name !== preItem.name || item.title !== preItem.title;
|
||||
|
||||
if (isChanged) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return isChanged;
|
||||
}
|
||||
}, {
|
||||
key: "setContent",
|
||||
value: function setContent(title, items) {
|
||||
// const isChange = this.isContentChange(title, items);
|
||||
// if (isChange) {
|
||||
// 在外面进行判断是否内容发生改变
|
||||
var timeStamp = +new Date();
|
||||
this.set('items', items);
|
||||
this.set('titleContent', title);
|
||||
this.set('timeStamp', timeStamp);
|
||||
|
||||
this._renderTooltip(); // }
|
||||
|
||||
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "setMarkers",
|
||||
value: function setMarkers(markerItems, markerCfg) {
|
||||
var self = this;
|
||||
var markerGroup = self.get('markerGroup');
|
||||
var frontPlot = self.get('frontPlot');
|
||||
|
||||
if (!markerGroup) {
|
||||
markerGroup = frontPlot.addGroup({
|
||||
zIndex: 1,
|
||||
capture: false // 不进行拾取
|
||||
|
||||
});
|
||||
self.set('markerGroup', markerGroup);
|
||||
} else {
|
||||
markerGroup.clear();
|
||||
}
|
||||
|
||||
Util.each(markerItems, function (item) {
|
||||
markerGroup.addShape('marker', {
|
||||
color: item.color,
|
||||
attrs: Util.mix({}, markerCfg, {
|
||||
x: item.x,
|
||||
y: item.y
|
||||
})
|
||||
});
|
||||
});
|
||||
this.set('markerItems', markerItems);
|
||||
}
|
||||
}, {
|
||||
key: "clearMarkers",
|
||||
value: function clearMarkers() {
|
||||
var markerGroup = this.get('markerGroup');
|
||||
markerGroup && markerGroup.clear();
|
||||
}
|
||||
}, {
|
||||
key: "setPosition",
|
||||
value: function setPosition(x, y, target) {
|
||||
var container = this.get('container');
|
||||
var crossLineShapeX = this.get('crossLineShapeX');
|
||||
var crossLineShapeY = this.get('crossLineShapeY');
|
||||
var crosshairsRectShape = this.get('crosshairsRectShape');
|
||||
var endx = x;
|
||||
var endy = y; // const outterNode = this.get('canvas').get('el').parentNode;
|
||||
|
||||
var outterNode = this.get('canvas').get('el');
|
||||
var viewWidth = DomUtil.getWidth(outterNode);
|
||||
var viewHeight = DomUtil.getHeight(outterNode);
|
||||
var offset = this.get('offset');
|
||||
var position;
|
||||
|
||||
if (this.get('position')) {
|
||||
position = calcTooltipPosition(x, y, this.get('position'), container, target);
|
||||
x = position[0];
|
||||
y = position[1];
|
||||
} else if (!this.get('position')) {
|
||||
position = refixTooltipPosition(x, y, container, viewWidth, viewHeight);
|
||||
x = position[0];
|
||||
y = position[1];
|
||||
}
|
||||
|
||||
if (this.get('inPlot')) {
|
||||
// tooltip 必须限制在绘图区域内
|
||||
var plotRange = this.get('plotRange');
|
||||
position = confineTooltipPosition(x, y, container, plotRange);
|
||||
x = position[0];
|
||||
y = position[1];
|
||||
}
|
||||
|
||||
if (this.get('x') !== x || this.get('y') !== y) {
|
||||
var markerItems = this.get('markerItems');
|
||||
|
||||
if (!Util.isEmpty(markerItems)) {
|
||||
endx = markerItems[0].x;
|
||||
endy = markerItems[0].y;
|
||||
}
|
||||
|
||||
if (crossLineShapeY) {
|
||||
// 第一次进入时,画布需要单独绘制,所以需要先设定corss的位置
|
||||
crossLineShapeY.move(endx, 0);
|
||||
}
|
||||
|
||||
if (crossLineShapeX) {
|
||||
crossLineShapeX.move(0, endy);
|
||||
}
|
||||
|
||||
if (crosshairsRectShape) {
|
||||
// 绘制矩形辅助框,只在直角坐标系下生效
|
||||
var isTransposed = this.get('isTransposed');
|
||||
var items = this.get('items');
|
||||
var firstItem = items[0];
|
||||
var lastItem = items[items.length - 1];
|
||||
var dim = isTransposed ? 'y' : 'x';
|
||||
var attr = isTransposed ? 'height' : 'width';
|
||||
var startDim = firstItem[dim];
|
||||
|
||||
if (items.length > 1 && firstItem[dim] > lastItem[dim]) {
|
||||
startDim = lastItem[dim];
|
||||
}
|
||||
|
||||
if (this.get('crosshairs').width) {
|
||||
// 用户定义了 width
|
||||
crosshairsRectShape.attr(dim, startDim - this.get('crosshairs').width / 2);
|
||||
crosshairsRectShape.attr(attr, this.get('crosshairs').width);
|
||||
} else {
|
||||
if (Util.isArray(firstItem.point[dim]) && !firstItem.size) {
|
||||
// 直方图
|
||||
var width = firstItem.point[dim][1] - firstItem.point[dim][0];
|
||||
crosshairsRectShape.attr(dim, firstItem.point[dim][0]);
|
||||
crosshairsRectShape.attr(attr, width);
|
||||
} else {
|
||||
offset = 3 * firstItem.size / 4;
|
||||
crosshairsRectShape.attr(dim, startDim - offset);
|
||||
|
||||
if (items.length === 1) {
|
||||
crosshairsRectShape.attr(attr, 3 * firstItem.size / 2);
|
||||
} else {
|
||||
crosshairsRectShape.attr(attr, Math.abs(lastItem[dim] - firstItem[dim]) + 2 * offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var follow = this.get('follow');
|
||||
container.style.left = follow ? x + 'px' : 0;
|
||||
container.style.top = follow ? y + 'px' : 0;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "show",
|
||||
value: function show() {
|
||||
var crossLineShapeX = this.get('crossLineShapeX');
|
||||
var crossLineShapeY = this.get('crossLineShapeY');
|
||||
var crosshairsRectShape = this.get('crosshairsRectShape');
|
||||
var markerGroup = this.get('markerGroup');
|
||||
var container = this.get('container');
|
||||
var canvas = this.get('canvas');
|
||||
crossLineShapeX && crossLineShapeX.show();
|
||||
crossLineShapeY && crossLineShapeY.show();
|
||||
crosshairsRectShape && crosshairsRectShape.show();
|
||||
markerGroup && markerGroup.show();
|
||||
|
||||
_get(_getPrototypeOf(Tooltip.prototype), "show", this).call(this);
|
||||
|
||||
container.style.visibility = 'visible'; // canvas.sort();
|
||||
|
||||
canvas.draw();
|
||||
}
|
||||
}, {
|
||||
key: "hide",
|
||||
value: function hide() {
|
||||
var self = this;
|
||||
var container = self.get('container');
|
||||
var crossLineShapeX = self.get('crossLineShapeX');
|
||||
var crossLineShapeY = self.get('crossLineShapeY');
|
||||
var crosshairsRectShape = this.get('crosshairsRectShape');
|
||||
var markerGroup = self.get('markerGroup');
|
||||
var canvas = self.get('canvas');
|
||||
container.style.visibility = 'hidden';
|
||||
crossLineShapeX && crossLineShapeX.hide();
|
||||
crossLineShapeY && crossLineShapeY.hide();
|
||||
crosshairsRectShape && crosshairsRectShape.hide();
|
||||
markerGroup && markerGroup.hide();
|
||||
|
||||
_get(_getPrototypeOf(Tooltip.prototype), "hide", this).call(this);
|
||||
|
||||
canvas.draw();
|
||||
}
|
||||
}, {
|
||||
key: "destroy",
|
||||
value: function destroy() {
|
||||
var self = this;
|
||||
var crossLineShapeX = self.get('crossLineShapeX');
|
||||
var crossLineShapeY = self.get('crossLineShapeY');
|
||||
var markerGroup = self.get('markerGroup');
|
||||
var crosshairsRectShape = self.get('crosshairsRectShape');
|
||||
var container = self.get('container');
|
||||
var containerTpl = self.get('containerTpl');
|
||||
|
||||
if (container && !/^\#/.test(containerTpl)) {
|
||||
container.parentNode.removeChild(container);
|
||||
}
|
||||
|
||||
crossLineShapeX && crossLineShapeX.remove();
|
||||
crossLineShapeY && crossLineShapeY.remove();
|
||||
markerGroup && markerGroup.remove();
|
||||
crosshairsRectShape && crosshairsRectShape.remove(); // super.remove();
|
||||
|
||||
_get(_getPrototypeOf(Tooltip.prototype), "destroy", this).call(this);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Tooltip;
|
||||
}(Base);
|
||||
|
||||
module.exports = Tooltip;
|
|
@ -1,326 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = exports.DEFAULT_RADIUS = exports.DEFAULT_CUTOFF = exports.DEFAULT_BUFFER = exports.DEFAULT_FONT_SIZE = exports.DEFAULT_FONT_WEIGHT = exports.DEFAULT_FONT_FAMILY = exports.DEFAULT_CHAR_SET = void 0;
|
||||
|
||||
var _tinySdf = _interopRequireDefault(require("@mapbox/tiny-sdf"));
|
||||
|
||||
var _fontUtil = require("../../util/font-util");
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../../core/three"));
|
||||
|
||||
var _lruCache = _interopRequireDefault(require("../../util/lru-cache"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
var DEFAULT_CHAR_SET = getDefaultCharacterSet();
|
||||
exports.DEFAULT_CHAR_SET = DEFAULT_CHAR_SET;
|
||||
var DEFAULT_FONT_FAMILY = 'sans-serif';
|
||||
exports.DEFAULT_FONT_FAMILY = DEFAULT_FONT_FAMILY;
|
||||
var DEFAULT_FONT_WEIGHT = 'normal';
|
||||
exports.DEFAULT_FONT_WEIGHT = DEFAULT_FONT_WEIGHT;
|
||||
var DEFAULT_FONT_SIZE = 24;
|
||||
exports.DEFAULT_FONT_SIZE = DEFAULT_FONT_SIZE;
|
||||
var DEFAULT_BUFFER = 3;
|
||||
exports.DEFAULT_BUFFER = DEFAULT_BUFFER;
|
||||
var DEFAULT_CUTOFF = 0.25;
|
||||
exports.DEFAULT_CUTOFF = DEFAULT_CUTOFF;
|
||||
var DEFAULT_RADIUS = 8;
|
||||
exports.DEFAULT_RADIUS = DEFAULT_RADIUS;
|
||||
var MAX_CANVAS_WIDTH = 1024;
|
||||
var BASELINE_SCALE = 0.9;
|
||||
var HEIGHT_SCALE = 1.2;
|
||||
var CACHE_LIMIT = 3;
|
||||
var cache = new _lruCache["default"](CACHE_LIMIT);
|
||||
var VALID_PROPS = ['fontFamily', 'fontWeight', 'characterSet', 'fontSize', 'sdf', 'buffer', 'cutoff', 'radius'];
|
||||
|
||||
function getDefaultCharacterSet() {
|
||||
var charSet = [];
|
||||
|
||||
for (var i = 32; i < 128; i++) {
|
||||
charSet.push(String.fromCharCode(i));
|
||||
}
|
||||
|
||||
return charSet;
|
||||
}
|
||||
|
||||
function setTextStyle(ctx, fontFamily, fontSize, fontWeight) {
|
||||
ctx.font = "".concat(fontWeight, " ").concat(fontSize, "px ").concat(fontFamily);
|
||||
ctx.fillStyle = '#000';
|
||||
ctx.textBaseline = 'baseline';
|
||||
ctx.textAlign = 'left';
|
||||
}
|
||||
|
||||
function getNewChars(key, characterSet) {
|
||||
var cachedFontAtlas = cache.get(key);
|
||||
|
||||
if (!cachedFontAtlas) {
|
||||
return characterSet;
|
||||
}
|
||||
|
||||
var newChars = [];
|
||||
var cachedMapping = cachedFontAtlas.mapping;
|
||||
var cachedCharSet = Object.keys(cachedMapping);
|
||||
cachedCharSet = new Set(cachedCharSet);
|
||||
var charSet = characterSet;
|
||||
|
||||
if (charSet instanceof Array) {
|
||||
charSet = new Set(charSet);
|
||||
}
|
||||
|
||||
charSet.forEach(function (_char) {
|
||||
if (!cachedCharSet.has(_char)) {
|
||||
newChars.push(_char);
|
||||
}
|
||||
});
|
||||
return newChars;
|
||||
}
|
||||
|
||||
function populateAlphaChannel(alphaChannel, imageData) {
|
||||
// populate distance value from tinySDF to image alpha channel
|
||||
for (var i = 0; i < alphaChannel.length; i++) {
|
||||
imageData.data[4 * i + 3] = alphaChannel[i];
|
||||
}
|
||||
}
|
||||
|
||||
var FontAtlasManager =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function FontAtlasManager() {
|
||||
_classCallCheck(this, FontAtlasManager);
|
||||
|
||||
// font settings
|
||||
this.props = {
|
||||
fontFamily: DEFAULT_FONT_FAMILY,
|
||||
fontWeight: DEFAULT_FONT_WEIGHT,
|
||||
characterSet: DEFAULT_CHAR_SET,
|
||||
fontSize: DEFAULT_FONT_SIZE,
|
||||
buffer: DEFAULT_BUFFER,
|
||||
// sdf only props
|
||||
// https://github.com/mapbox/tiny-sdf
|
||||
sdf: true,
|
||||
cutoff: DEFAULT_CUTOFF,
|
||||
radius: DEFAULT_RADIUS
|
||||
}; // key is used for caching generated fontAtlas
|
||||
|
||||
this._key = null;
|
||||
this._texture = new THREE.Texture();
|
||||
}
|
||||
|
||||
_createClass(FontAtlasManager, [{
|
||||
key: "setProps",
|
||||
value: function setProps() {
|
||||
var _this = this;
|
||||
|
||||
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||||
VALID_PROPS.forEach(function (prop) {
|
||||
if (prop in props) {
|
||||
_this.props[prop] = props[prop];
|
||||
}
|
||||
}); // update cache key
|
||||
|
||||
var oldKey = this._key;
|
||||
this._key = this._getKey();
|
||||
var charSet = getNewChars(this._key, this.props.characterSet);
|
||||
var cachedFontAtlas = cache.get(this._key); // if a fontAtlas associated with the new settings is cached and
|
||||
// there are no new chars
|
||||
|
||||
if (cachedFontAtlas && charSet.length === 0) {
|
||||
// update texture with cached fontAtlas
|
||||
if (this._key !== oldKey) {
|
||||
this._updateTexture(cachedFontAtlas);
|
||||
}
|
||||
|
||||
return;
|
||||
} // update fontAtlas with new settings
|
||||
|
||||
|
||||
var fontAtlas = this._generateFontAtlas(this._key, charSet, cachedFontAtlas);
|
||||
|
||||
this._fontAtlas = fontAtlas;
|
||||
|
||||
this._updateTexture(fontAtlas); // update cache
|
||||
|
||||
|
||||
cache.set(this._key, fontAtlas);
|
||||
}
|
||||
}, {
|
||||
key: "_updateTexture",
|
||||
value: function _updateTexture(_ref) {
|
||||
var canvas = _ref.data;
|
||||
this._texture = new THREE.CanvasTexture(canvas);
|
||||
this._texture.wrapS = THREE.ClampToEdgeWrapping;
|
||||
this._texture.wrapT = THREE.ClampToEdgeWrapping;
|
||||
this._texture.minFilter = THREE.LinearFilter;
|
||||
this._texture.flipY = false;
|
||||
this._texture.needUpdate = true;
|
||||
}
|
||||
}, {
|
||||
key: "_generateFontAtlas",
|
||||
value: function _generateFontAtlas(key, characterSet, cachedFontAtlas) {
|
||||
var _this$props = this.props,
|
||||
fontFamily = _this$props.fontFamily,
|
||||
fontWeight = _this$props.fontWeight,
|
||||
fontSize = _this$props.fontSize,
|
||||
buffer = _this$props.buffer,
|
||||
sdf = _this$props.sdf,
|
||||
radius = _this$props.radius,
|
||||
cutoff = _this$props.cutoff;
|
||||
var canvas = cachedFontAtlas && cachedFontAtlas.data;
|
||||
|
||||
if (!canvas) {
|
||||
canvas = document.createElement('canvas');
|
||||
canvas.width = MAX_CANVAS_WIDTH;
|
||||
}
|
||||
|
||||
var ctx = canvas.getContext('2d');
|
||||
setTextStyle(ctx, fontFamily, fontSize, fontWeight); // 1. build mapping
|
||||
|
||||
var _buildMapping = (0, _fontUtil.buildMapping)(Object.assign({
|
||||
getFontWidth: function getFontWidth(_char2) {
|
||||
return ctx.measureText(_char2).width;
|
||||
},
|
||||
fontHeight: fontSize * HEIGHT_SCALE,
|
||||
buffer: buffer,
|
||||
characterSet: characterSet,
|
||||
maxCanvasWidth: MAX_CANVAS_WIDTH
|
||||
}, cachedFontAtlas && {
|
||||
mapping: cachedFontAtlas.mapping,
|
||||
xOffset: cachedFontAtlas.xOffset,
|
||||
yOffset: cachedFontAtlas.yOffset
|
||||
})),
|
||||
mapping = _buildMapping.mapping,
|
||||
canvasHeight = _buildMapping.canvasHeight,
|
||||
xOffset = _buildMapping.xOffset,
|
||||
yOffset = _buildMapping.yOffset; // 2. update canvas
|
||||
// copy old canvas data to new canvas only when height changed
|
||||
|
||||
|
||||
if (canvas.height !== canvasHeight) {
|
||||
var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||
canvas.height = canvasHeight;
|
||||
ctx.putImageData(imageData, 0, 0);
|
||||
}
|
||||
|
||||
setTextStyle(ctx, fontFamily, fontSize, fontWeight); // 3. layout characters
|
||||
|
||||
if (sdf) {
|
||||
var tinySDF = new _tinySdf["default"](fontSize, buffer, radius, cutoff, fontFamily, fontWeight); // used to store distance values from tinySDF
|
||||
// tinySDF.size equals `fontSize + buffer * 2`
|
||||
|
||||
var _imageData = ctx.getImageData(0, 0, tinySDF.size, tinySDF.size);
|
||||
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = characterSet[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var _char3 = _step.value;
|
||||
populateAlphaChannel(tinySDF.draw(_char3), _imageData);
|
||||
ctx.putImageData(_imageData, mapping[_char3].x - buffer, mapping[_char3].y - buffer);
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
||||
_iterator["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var _iteratorNormalCompletion2 = true;
|
||||
var _didIteratorError2 = false;
|
||||
var _iteratorError2 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator2 = characterSet[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
||||
var _char4 = _step2.value;
|
||||
ctx.fillText(_char4, mapping[_char4].x, mapping[_char4].y + fontSize * BASELINE_SCALE);
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError2 = true;
|
||||
_iteratorError2 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
|
||||
_iterator2["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError2) {
|
||||
throw _iteratorError2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
xOffset: xOffset,
|
||||
yOffset: yOffset,
|
||||
mapping: mapping,
|
||||
data: canvas,
|
||||
width: canvas.width,
|
||||
height: canvas.height
|
||||
};
|
||||
}
|
||||
}, {
|
||||
key: "_getKey",
|
||||
value: function _getKey() {
|
||||
var _this$props2 = this.props,
|
||||
fontFamily = _this$props2.fontFamily,
|
||||
fontWeight = _this$props2.fontWeight,
|
||||
fontSize = _this$props2.fontSize,
|
||||
buffer = _this$props2.buffer,
|
||||
sdf = _this$props2.sdf,
|
||||
radius = _this$props2.radius,
|
||||
cutoff = _this$props2.cutoff;
|
||||
|
||||
if (sdf) {
|
||||
return "".concat(fontFamily, " ").concat(fontWeight, " ").concat(fontSize, " ").concat(buffer, " ").concat(radius, " ").concat(cutoff);
|
||||
}
|
||||
|
||||
return "".concat(fontFamily, " ").concat(fontWeight, " ").concat(fontSize, " ").concat(buffer);
|
||||
}
|
||||
}, {
|
||||
key: "texture",
|
||||
get: function get() {
|
||||
return this._texture;
|
||||
}
|
||||
}, {
|
||||
key: "mapping",
|
||||
get: function get() {
|
||||
var data = cache.get(this._key);
|
||||
return data && data.mapping;
|
||||
}
|
||||
}, {
|
||||
key: "scale",
|
||||
get: function get() {
|
||||
return HEIGHT_SCALE;
|
||||
}
|
||||
}, {
|
||||
key: "fontAtlas",
|
||||
get: function get() {
|
||||
return this._fontAtlas;
|
||||
}
|
||||
}]);
|
||||
|
||||
return FontAtlasManager;
|
||||
}();
|
||||
|
||||
exports["default"] = FontAtlasManager;
|
|
@ -1,102 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _fontUtil = require("../../util/font-util");
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../../../../core/three"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
var BUFFER = 3;
|
||||
var MAX_CANVAS_WIDTH = 1024;
|
||||
|
||||
var IconManager =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function IconManager() {
|
||||
_classCallCheck(this, IconManager);
|
||||
|
||||
this._getIcon = null;
|
||||
this._mapping = {};
|
||||
this._autoPacking = false;
|
||||
this.iconData = {};
|
||||
this._canvas = document.createElement('canvas');
|
||||
this._texture = new THREE.Texture(this._canvas);
|
||||
this.ctx = this._canvas.getContext('2d');
|
||||
}
|
||||
|
||||
_createClass(IconManager, [{
|
||||
key: "getTexture",
|
||||
value: function getTexture() {
|
||||
return this._texture;
|
||||
}
|
||||
}, {
|
||||
key: "_updateIconAtlas",
|
||||
value: function _updateIconAtlas() {
|
||||
this._canvas.width = MAX_CANVAS_WIDTH;
|
||||
this._canvas.height = this._canvasHeigth;
|
||||
|
||||
for (var key in this.mapping) {
|
||||
var icon = this.mapping[key];
|
||||
var x = icon.x,
|
||||
y = icon.y,
|
||||
image = icon.image;
|
||||
this.ctx.drawImage(image, x, y, this.imageWidth, this.imageWidth);
|
||||
}
|
||||
|
||||
this.texture.magFilter = THREE.LinearFilter;
|
||||
this.texture.minFilter = THREE.LinearFilter;
|
||||
this.texture.needsUpdate = true;
|
||||
}
|
||||
}, {
|
||||
key: "addImage",
|
||||
value: function addImage(id, opt) {
|
||||
var _this = this;
|
||||
|
||||
this._loadImage(opt).then(function (image) {
|
||||
_this.iconData.push({
|
||||
id: id,
|
||||
image: image
|
||||
});
|
||||
|
||||
var _buildIconMaping = (0, _fontUtil.buildIconMaping)(_this.iconData, BUFFER, MAX_CANVAS_WIDTH),
|
||||
mapping = _buildIconMaping.mapping,
|
||||
canvasHeight = _buildIconMaping.canvasHeight;
|
||||
|
||||
_this._mapping = mapping;
|
||||
_this._canvasHeigth = canvasHeight;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_loadImage",
|
||||
value: function _loadImage(url) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
var image = new Image();
|
||||
|
||||
image.onload = function () {
|
||||
resolve(image);
|
||||
};
|
||||
|
||||
image.onerror = function () {
|
||||
reject(new Error('Could not load image at ' + url));
|
||||
};
|
||||
|
||||
image.src = url;
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return IconManager;
|
||||
}();
|
||||
|
||||
exports["default"] = IconManager;
|
|
@ -1,86 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _wolfy87Eventemitter = _interopRequireDefault(require("wolfy87-eventemitter"));
|
||||
|
||||
var _util = _interopRequireDefault(require("../util"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var Base =
|
||||
/*#__PURE__*/
|
||||
function (_EventEmitter) {
|
||||
_inherits(Base, _EventEmitter);
|
||||
|
||||
_createClass(Base, [{
|
||||
key: "getDefaultCfg",
|
||||
value: function getDefaultCfg() {
|
||||
return {};
|
||||
}
|
||||
}]);
|
||||
|
||||
function Base(cfg) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, Base);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Base).call(this));
|
||||
var attrs = {
|
||||
visible: true
|
||||
};
|
||||
|
||||
var defaultCfg = _this.getDefaultCfg();
|
||||
|
||||
_this._attrs = attrs;
|
||||
|
||||
_util["default"].assign(attrs, defaultCfg, cfg);
|
||||
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(Base, [{
|
||||
key: "get",
|
||||
value: function get(name) {
|
||||
return this._attrs[name];
|
||||
}
|
||||
}, {
|
||||
key: "set",
|
||||
value: function set(name, value) {
|
||||
this._attrs[name] = value;
|
||||
}
|
||||
}, {
|
||||
key: "destroy",
|
||||
value: function destroy() {
|
||||
this._attrs = {};
|
||||
this.removeAllListeners();
|
||||
this.destroyed = true;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Base;
|
||||
}(_wolfy87Eventemitter["default"]);
|
||||
|
||||
var _default = Base;
|
||||
exports["default"] = _default;
|
|
@ -1,97 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _util = _interopRequireDefault(require("../../util"));
|
||||
|
||||
var _object3dUtil = require("../../util/object3d-util");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
var BufferController =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function BufferController(cfg) {
|
||||
_classCallCheck(this, BufferController);
|
||||
|
||||
// defs 列定义
|
||||
_util["default"].assign(this, cfg);
|
||||
|
||||
if (!this.mesh) this.mesh = this.layer;
|
||||
}
|
||||
|
||||
_createClass(BufferController, [{
|
||||
key: "_updateColorAttributes",
|
||||
value: function _updateColorAttributes() {
|
||||
var _this = this;
|
||||
|
||||
var filterData = this.mesh.layerData;
|
||||
var colorKey = {};
|
||||
|
||||
for (var e = 0; e < filterData.length; e++) {
|
||||
var item = filterData[e];
|
||||
colorKey[item.id] = item.color;
|
||||
}
|
||||
|
||||
this.layer._activeIds = null; // 清空选中元素xwxw
|
||||
|
||||
var colorAttr = this.mesh.mesh.geometry.attributes.a_color;
|
||||
var pickAttr = this.mesh.mesh.geometry.attributes.pickingId;
|
||||
pickAttr.array.forEach(function (id, index) {
|
||||
var newId = Math.abs(id);
|
||||
var item = null;
|
||||
var color = null;
|
||||
|
||||
if (_this.mesh.layerSource.data.featureKeys) {
|
||||
// hash数据映射
|
||||
newId = _this.mesh.layerSource.data.featureKeys[newId].index;
|
||||
item = filterData[newId];
|
||||
color = colorKey[item.id];
|
||||
} else {
|
||||
item = filterData[newId - 1];
|
||||
color = colorKey[newId];
|
||||
}
|
||||
|
||||
if (item.hasOwnProperty('filter') && item.filter === false) {
|
||||
colorAttr.array[index * 4 + 0] = 0;
|
||||
colorAttr.array[index * 4 + 1] = 0;
|
||||
colorAttr.array[index * 4 + 2] = 0;
|
||||
colorAttr.array[index * 4 + 3] = 0;
|
||||
pickAttr.array[index] = -id; // 通过Id数据过滤 id<0 不显示
|
||||
} else {
|
||||
colorAttr.array[index * 4 + 0] = color[0];
|
||||
colorAttr.array[index * 4 + 1] = color[1];
|
||||
colorAttr.array[index * 4 + 2] = color[2];
|
||||
colorAttr.array[index * 4 + 3] = color[3];
|
||||
pickAttr.array[index] = id;
|
||||
}
|
||||
});
|
||||
colorAttr.needsUpdate = true;
|
||||
pickAttr.needsUpdate = true;
|
||||
}
|
||||
}, {
|
||||
key: "_updateStyle",
|
||||
value: function _updateStyle(option) {
|
||||
var newOption = {};
|
||||
|
||||
for (var key in option) {
|
||||
newOption['u_' + key] = option[key];
|
||||
}
|
||||
|
||||
(0, _object3dUtil.updateObjecteUniform)(this.mesh._object3D, newOption);
|
||||
}
|
||||
}]);
|
||||
|
||||
return BufferController;
|
||||
}();
|
||||
|
||||
exports["default"] = BufferController;
|
|
@ -1,76 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _util = _interopRequireDefault(require("../../util"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
var EventContoller =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function EventContoller(cfg) {
|
||||
_classCallCheck(this, EventContoller);
|
||||
|
||||
_util["default"].assign(this, cfg);
|
||||
}
|
||||
|
||||
_createClass(EventContoller, [{
|
||||
key: "_init",
|
||||
value: function _init() {
|
||||
var _this = this;
|
||||
|
||||
this.layer.scene.on('pick-' + this.layer.layerId, function (e) {
|
||||
var featureId = e.featureId,
|
||||
point2d = e.point2d,
|
||||
type = e.type;
|
||||
|
||||
if (featureId < 0 && _this._activeIds !== null) {
|
||||
type = 'mouseleave';
|
||||
}
|
||||
|
||||
_this._activeIds = featureId; // TODO 瓦片图层获取选中数据信息
|
||||
|
||||
var lnglat = _this.layer.scene.containerToLngLat(point2d);
|
||||
|
||||
var _this$layer$getSelect = _this.layer.getSelectFeature(featureId, lnglat),
|
||||
feature = _this$layer$getSelect.feature,
|
||||
style = _this$layer$getSelect.style; // const style = this.layerData[featureId - 1];
|
||||
|
||||
|
||||
var target = {
|
||||
featureId: featureId,
|
||||
feature: feature,
|
||||
style: style,
|
||||
pixel: point2d,
|
||||
type: type,
|
||||
lnglat: {
|
||||
lng: lnglat.lng,
|
||||
lat: lnglat.lat
|
||||
}
|
||||
};
|
||||
|
||||
if (featureId >= 0 || _this._activeIds >= 0) {
|
||||
// 拾取到元素,或者离开元素
|
||||
_this.layer.emit(type, target);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_initMapEvent",
|
||||
value: function _initMapEvent() {}
|
||||
}]);
|
||||
|
||||
return EventContoller;
|
||||
}();
|
||||
|
||||
exports["default"] = EventContoller;
|
|
@ -1,56 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = polygonGeom;
|
||||
exports.pointGeom = pointGeom;
|
||||
|
||||
var _geom = _interopRequireDefault(require("../../geom/geom"));
|
||||
|
||||
var _index = require("../../geom/index");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
// geom shape buffer geometry material
|
||||
// shape name type()
|
||||
// buffer 1:n geometry
|
||||
// geometry
|
||||
//
|
||||
function polygonGeom(shape, coordinates, properties, layerid) {
|
||||
var polygongeom = _geom.default.polygon;
|
||||
var _polygongeom$shape = polygongeom[shape],
|
||||
buffer = _polygongeom$shape.buffer,
|
||||
geometry = _polygongeom$shape.geometry,
|
||||
material = _polygongeom$shape.material; // polygon 映射表
|
||||
|
||||
var bufferData = new _index.GeoBuffer[buffer]({
|
||||
coordinates: coordinates,
|
||||
properties: properties,
|
||||
shape: shape
|
||||
});
|
||||
bufferData.bufferStruct.name = layerid;
|
||||
var bg = new _index.bufferGeometry[geometry](bufferData.bufferStruct);
|
||||
|
||||
var mtl = _index.Material[material]();
|
||||
|
||||
return {
|
||||
geometry: bg,
|
||||
mtl: mtl
|
||||
};
|
||||
}
|
||||
|
||||
function pointGeom(shape, bufferData) {
|
||||
var pointgeom = _geom.default.point;
|
||||
var _pointgeom$shape = pointgeom[shape],
|
||||
geometry = _pointgeom$shape.geometry,
|
||||
material = _pointgeom$shape.material;
|
||||
var bg = new _index.bufferGeometry[geometry](bufferData.bufferStruct);
|
||||
|
||||
var mtl = _index.Material[material]();
|
||||
|
||||
return {
|
||||
geometry: bg,
|
||||
mtl: mtl
|
||||
};
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _scale = _interopRequireDefault(require("./scale"));
|
||||
|
||||
var _mapping = _interopRequireDefault(require("./mapping"));
|
||||
|
||||
var _pick = _interopRequireDefault(require("./pick"));
|
||||
|
||||
var _interaction = _interopRequireDefault(require("./interaction"));
|
||||
|
||||
var _event = _interopRequireDefault(require("./event"));
|
||||
|
||||
var _buffer = _interopRequireDefault(require("./buffer"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
var _default = {
|
||||
Scale: _scale["default"],
|
||||
Mapping: _mapping["default"],
|
||||
Picking: _pick["default"],
|
||||
Interaction: _interaction["default"],
|
||||
Event: _event["default"],
|
||||
Buffer: _buffer["default"]
|
||||
};
|
||||
exports["default"] = _default;
|
|
@ -1,83 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _util = _interopRequireDefault(require("../../util"));
|
||||
|
||||
var _index = require("../../interaction/index");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
var InteractionController =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function InteractionController(cfg) {
|
||||
_classCallCheck(this, InteractionController);
|
||||
|
||||
// defs 列定义
|
||||
_util["default"].assign(this, cfg);
|
||||
} // interaction 方法
|
||||
|
||||
|
||||
_createClass(InteractionController, [{
|
||||
key: "clearAllInteractions",
|
||||
value: function clearAllInteractions() {
|
||||
var interactions = this.layer.get('interactions');
|
||||
|
||||
_util["default"].each(interactions, function (interaction, key) {
|
||||
interaction.destory();
|
||||
delete interactions[key];
|
||||
});
|
||||
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "clearInteraction",
|
||||
value: function clearInteraction(type) {
|
||||
var interactions = this.layer.get('interactions');
|
||||
|
||||
if (interactions[type]) {
|
||||
interactions[type].destory();
|
||||
delete interactions[type];
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "addInteraction",
|
||||
value: function addInteraction(type) {
|
||||
var cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
cfg.layer = this.layer;
|
||||
var Ctor = (0, _index.getInteraction)(type);
|
||||
var interaction = new Ctor(cfg);
|
||||
|
||||
this._setInteraction(type, interaction);
|
||||
|
||||
return this;
|
||||
}
|
||||
}, {
|
||||
key: "_setInteraction",
|
||||
value: function _setInteraction(type, interaction) {
|
||||
var interactions = this.layer.get('interactions');
|
||||
|
||||
if (interactions[type]) {
|
||||
interactions[type].destory();
|
||||
}
|
||||
|
||||
interactions[type] = interaction;
|
||||
}
|
||||
}]);
|
||||
|
||||
return InteractionController;
|
||||
}();
|
||||
|
||||
exports["default"] = InteractionController;
|
|
@ -1,14 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.layerControl = void 0;
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
var layerControl = function layerControl() {
|
||||
_classCallCheck(this, layerControl);
|
||||
};
|
||||
|
||||
exports.layerControl = layerControl;
|
|
@ -1,70 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _map = require("../../map");
|
||||
|
||||
var _base = _interopRequireDefault(require("../base"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var MapContorller =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(MapContorller, _Base);
|
||||
|
||||
function MapContorller(cfg, engine, scene) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, MapContorller);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(MapContorller).call(this, cfg));
|
||||
_this._engine = engine;
|
||||
_this.scene = scene;
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(MapContorller, [{
|
||||
key: "_init",
|
||||
value: function _init() {
|
||||
var mapType = this.get('mapType');
|
||||
var mapCfg = this.get('mapCfg');
|
||||
this.map = new _map.getMap(mapType)(mapCfg);
|
||||
this.map('mapLoad', this._mapload.bind(this));
|
||||
}
|
||||
}, {
|
||||
key: "_mapload",
|
||||
value: function _mapload() {
|
||||
this.map.asyncCamera(this._engine);
|
||||
this.emit('loaded');
|
||||
}
|
||||
}, {
|
||||
key: "_bindMapMethod",
|
||||
value: function _bindMapMethod() {}
|
||||
}]);
|
||||
|
||||
return MapContorller;
|
||||
}(_base.default);
|
||||
|
||||
exports.default = MapContorller;
|
|
@ -1,279 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _util = _interopRequireDefault(require("../../util"));
|
||||
|
||||
var _global = _interopRequireDefault(require("../../global"));
|
||||
|
||||
var _scale = _interopRequireDefault(require("./scale"));
|
||||
|
||||
var _index = _interopRequireDefault(require("../../attr/index"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
||||
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
var Mapping =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
/** 初始化mapping
|
||||
* 初始化mapping
|
||||
* @param {*} cfg 配置
|
||||
* @param {*} cfg.layer layer对象
|
||||
* @param {*} cfg.mesh mesh对象
|
||||
*/
|
||||
function Mapping(cfg) {
|
||||
_classCallCheck(this, Mapping);
|
||||
|
||||
_util["default"].assign(this, cfg);
|
||||
|
||||
if (!this.mesh) this.mesh = this.layer;
|
||||
|
||||
this._init();
|
||||
}
|
||||
|
||||
_createClass(Mapping, [{
|
||||
key: "_init",
|
||||
value: function _init() {
|
||||
this._initControllers();
|
||||
|
||||
this._initTileAttrs();
|
||||
|
||||
this._mapping();
|
||||
}
|
||||
}, {
|
||||
key: "update",
|
||||
value: function update() {
|
||||
this.mesh.set('scales', {});
|
||||
|
||||
this._initTileAttrs();
|
||||
|
||||
this._updateMaping();
|
||||
}
|
||||
}, {
|
||||
key: "_initControllers",
|
||||
value: function _initControllers() {
|
||||
var scalesOption = this.layer.get('scaleOptions');
|
||||
var scaleController = new _scale["default"]({
|
||||
defs: _objectSpread({}, scalesOption)
|
||||
});
|
||||
this.mesh.set('scaleController', scaleController);
|
||||
}
|
||||
}, {
|
||||
key: "_createScale",
|
||||
value: function _createScale(field) {
|
||||
var scales = this.mesh.get('scales');
|
||||
|
||||
this._initControllers(); // scale更新
|
||||
|
||||
|
||||
var scale = scales[field];
|
||||
|
||||
if (!scale) {
|
||||
scale = this.createScale(field);
|
||||
scales[field] = scale;
|
||||
}
|
||||
|
||||
return scale;
|
||||
}
|
||||
}, {
|
||||
key: "createScale",
|
||||
value: function createScale(field) {
|
||||
var data = this.mesh.layerSource.data.dataArray;
|
||||
var scales = this.mesh.get('scales');
|
||||
var scale = scales[field];
|
||||
var scaleController = this.mesh.get('scaleController');
|
||||
|
||||
if (!scale) {
|
||||
scale = scaleController.createScale(field, data);
|
||||
scales[field] = scale;
|
||||
}
|
||||
|
||||
return scale;
|
||||
} // 获取属性映射的值
|
||||
|
||||
}, {
|
||||
key: "_getAttrValues",
|
||||
value: function _getAttrValues(attr, record) {
|
||||
var scales = attr.scales;
|
||||
var params = [];
|
||||
|
||||
for (var i = 0; i < scales.length; i++) {
|
||||
var scale = scales[i];
|
||||
var field = scale.field;
|
||||
|
||||
if (scale.type === 'identity') {
|
||||
params.push(scale.value);
|
||||
} else {
|
||||
params.push(record[field]);
|
||||
}
|
||||
}
|
||||
|
||||
var indexZoom = params.indexOf('zoom');
|
||||
indexZoom !== -1 ? params[indexZoom] = attr.zoom : null;
|
||||
var values = attr.mapping.apply(attr, params);
|
||||
return values;
|
||||
}
|
||||
}, {
|
||||
key: "_mapping",
|
||||
value: function _mapping() {
|
||||
var attrs = this.mesh.get('attrs');
|
||||
var mappedData = [];
|
||||
var data = this.mesh.layerSource.data.dataArray;
|
||||
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var record = data[i];
|
||||
var newRecord = {};
|
||||
newRecord.id = data[i]._id;
|
||||
|
||||
for (var k in attrs) {
|
||||
if (attrs.hasOwnProperty(k)) {
|
||||
var attr = attrs[k];
|
||||
var names = attr.names;
|
||||
|
||||
var values = this._getAttrValues(attr, record);
|
||||
|
||||
if (names.length > 1) {
|
||||
// position 之类的生成多个字段的属性
|
||||
for (var j = 0; j < values.length; j++) {
|
||||
var val = values[j];
|
||||
var name = names[j];
|
||||
newRecord[name] = _util["default"].isArray(val) && val.length === 1 ? val[0] : val; // 只有一个值时返回第一个属性值
|
||||
}
|
||||
} else {
|
||||
newRecord[names[0]] = values.length === 1 ? values[0] : values;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newRecord.coordinates = record.coordinates;
|
||||
mappedData.push(newRecord);
|
||||
} // 通过透明度过滤数据
|
||||
|
||||
|
||||
if (attrs.hasOwnProperty('filter')) {
|
||||
mappedData.forEach(function (item) {
|
||||
if (item.filter === false) {
|
||||
item.color[3] = 0;
|
||||
item.id = -item.id;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.mesh.layerData = mappedData;
|
||||
}
|
||||
/**
|
||||
* 更新数据maping
|
||||
* @param {*} layerSource 数据源
|
||||
* @param {*} layer map
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: "_updateMaping",
|
||||
value: function _updateMaping() {
|
||||
var attrs = this.mesh.get('attrs');
|
||||
var data = this.mesh.layerSource.data.dataArray;
|
||||
var layerData = this.mesh.layerData;
|
||||
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var record = data[i];
|
||||
|
||||
for (var attrName in attrs) {
|
||||
if (attrs.hasOwnProperty(attrName) && attrs[attrName].neadUpdate) {
|
||||
var attr = attrs[attrName];
|
||||
var names = attr.names;
|
||||
|
||||
var values = this._getAttrValues(attr, record);
|
||||
|
||||
if (names.length > 1) {
|
||||
// position 之类的生成多个字段的属性
|
||||
for (var j = 0; j < values.length; j++) {
|
||||
var val = values[j];
|
||||
var name = names[j];
|
||||
layerData[i][name] = _util["default"].isArray(val) && val.length === 1 ? val[0] : val; // 只有一个值时返回第一个属性值
|
||||
}
|
||||
} else {
|
||||
layerData[i][names[0]] = values.length === 1 ? values[0] : values;
|
||||
}
|
||||
|
||||
attr.neadUpdate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "_initTileAttrs",
|
||||
value: function _initTileAttrs() {
|
||||
var attrOptions = this.layer.get('attrOptions');
|
||||
|
||||
for (var type in attrOptions) {
|
||||
if (attrOptions.hasOwnProperty(type)) {
|
||||
this._updateTileAttr(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "_updateTileAttr",
|
||||
value: function _updateTileAttr(type) {
|
||||
var self = this;
|
||||
var attrs = this.mesh.get('attrs');
|
||||
var attrOptions = this.layer.get('attrOptions');
|
||||
var option = attrOptions[type];
|
||||
option.neadUpdate = true;
|
||||
|
||||
var className = _util["default"].upperFirst(type);
|
||||
|
||||
var fields = this._parseFields(option.field);
|
||||
|
||||
var scales = [];
|
||||
|
||||
for (var i = 0; i < fields.length; i++) {
|
||||
var field = fields[i];
|
||||
|
||||
var scale = self._createScale(field);
|
||||
|
||||
if (type === 'color' && _util["default"].isNil(option.values)) {
|
||||
// 设置 color 的默认色值
|
||||
option.values = _global["default"].colors;
|
||||
}
|
||||
|
||||
scales.push(scale);
|
||||
}
|
||||
|
||||
option.scales = scales;
|
||||
var attr = new _index["default"][className](option);
|
||||
attrs[type] = attr;
|
||||
}
|
||||
}, {
|
||||
key: "_parseFields",
|
||||
value: function _parseFields(field) {
|
||||
if (_util["default"].isArray(field)) {
|
||||
return field;
|
||||
}
|
||||
|
||||
if (_util["default"].isString(field)) {
|
||||
return field.split('*');
|
||||
}
|
||||
|
||||
return [field];
|
||||
}
|
||||
}]);
|
||||
|
||||
return Mapping;
|
||||
}();
|
||||
|
||||
exports["default"] = Mapping;
|
|
@ -1,105 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _util = _interopRequireDefault(require("../../util"));
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../three"));
|
||||
|
||||
var _object3dUtil = require("../../util/object3d-util");
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
var PickContoller =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function PickContoller(cfg) {
|
||||
_classCallCheck(this, PickContoller);
|
||||
|
||||
_util["default"].assign(this, cfg);
|
||||
|
||||
this.pickObject3D = new THREE.Object3D();
|
||||
this.addToPicking(this.pickObject3D);
|
||||
}
|
||||
|
||||
_createClass(PickContoller, [{
|
||||
key: "getPickingId",
|
||||
value: function getPickingId() {
|
||||
return this.layer.scene._engine._picking.getNextId();
|
||||
}
|
||||
}, {
|
||||
key: "addToPicking",
|
||||
value: function addToPicking(object) {
|
||||
object.name = this.layer.layerId;
|
||||
|
||||
this.layer.scene._engine._picking.add(object);
|
||||
}
|
||||
}, {
|
||||
key: "removePickingObject",
|
||||
value: function removePickingObject(object) {
|
||||
this.layer.scene._engine._picking.remove(object);
|
||||
}
|
||||
}, {
|
||||
key: "removePickingMesh",
|
||||
value: function removePickingMesh(mesh) {
|
||||
this.pickObject3D.remove(mesh);
|
||||
(0, _object3dUtil.destoryObject)(mesh);
|
||||
}
|
||||
}, {
|
||||
key: "removePickMeshByName",
|
||||
value: function removePickMeshByName(name) {
|
||||
for (var i = 0; i < this.pickObject3D.children.length; i++) {
|
||||
if (this.pickObject3D.children[i].name === name) {
|
||||
this.removePickingMesh(this.pickObject3D.children[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "removeAllMesh",
|
||||
value: function removeAllMesh() {
|
||||
var _this = this;
|
||||
|
||||
this.pickObject3D.children.forEach(function (element) {
|
||||
_this.pickObject3D.remove(element);
|
||||
|
||||
(0, _object3dUtil.destoryObject)(element);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "addPickMesh",
|
||||
value: function addPickMesh(mesh) {
|
||||
var _this2 = this;
|
||||
|
||||
var pickmaterial = mesh.material.clone();
|
||||
pickmaterial.defines.PICK = true; // pickmaterial.fragmentShader = pickingFragmentShader;
|
||||
|
||||
var pickingMesh = new THREE[mesh.type](mesh.geometry, pickmaterial);
|
||||
pickingMesh.name = mesh.name;
|
||||
|
||||
pickingMesh.onBeforeRender = function () {
|
||||
var zoom = _this2.layer.scene.getZoom();
|
||||
|
||||
(0, _object3dUtil.updateObjecteUniform)(pickingMesh, {
|
||||
u_zoom: zoom
|
||||
});
|
||||
};
|
||||
|
||||
this.pickObject3D.add(pickingMesh);
|
||||
}
|
||||
}]);
|
||||
|
||||
return PickContoller;
|
||||
}();
|
||||
|
||||
exports["default"] = PickContoller;
|
|
@ -1,163 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _util = _interopRequireDefault(require("../../util"));
|
||||
|
||||
var _global = _interopRequireDefault(require("../../global"));
|
||||
|
||||
var _scale = _interopRequireDefault(require("../../scale/"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
var dateRegex = /^(?:(?!0000)[0-9]{4}([-/.]+)(?:(?:0?[1-9]|1[0-2])\1(?:0?[1-9]|1[0-9]|2[0-8])|(?:0?[13-9]|1[0-2])\1(?:29|30)|(?:0?[13578]|1[02])\1(?:31))|(?:[0-9]{2}(?:0[48]|[2468][048]|[13579][26])|(?:0[48]|[2468][048]|[13579][26])00)([-/.]?)0?2\2(?:29))(\s+([01]|([01][0-9]|2[0-3])):([0-9]|[0-5][0-9]):([0-9]|[0-5][0-9]))?$/;
|
||||
var TYPES = {
|
||||
LINEAR: 'linear',
|
||||
CAT: 'cat',
|
||||
TIME: 'time'
|
||||
};
|
||||
|
||||
var ScaleController =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function ScaleController(cfg) {
|
||||
_classCallCheck(this, ScaleController);
|
||||
|
||||
// defs 列定义
|
||||
this.defs = {};
|
||||
|
||||
_util["default"].assign(this, cfg);
|
||||
}
|
||||
|
||||
_createClass(ScaleController, [{
|
||||
key: "_getDef",
|
||||
value: function _getDef(field) {
|
||||
var defs = this.defs;
|
||||
var def = null;
|
||||
|
||||
if (_global["default"].scales[field] || defs[field]) {
|
||||
def = _util["default"].mix({}, _global["default"].scales[field]); // 处理覆盖属性的问题
|
||||
|
||||
_util["default"].each(defs[field], function (v, k) {
|
||||
if (_util["default"].isNil(v)) {
|
||||
delete def[k];
|
||||
} else {
|
||||
def[k] = v;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return def;
|
||||
}
|
||||
}, {
|
||||
key: "_getDefaultType",
|
||||
value: function _getDefaultType(field, data) {
|
||||
var type = TYPES.LINEAR;
|
||||
|
||||
var value = _util["default"].Array.firstValue(data, field);
|
||||
|
||||
if (_util["default"].isArray(value)) {
|
||||
value = value[0];
|
||||
}
|
||||
|
||||
if (dateRegex.test(value)) {
|
||||
type = TYPES.TIME;
|
||||
} else if (_util["default"].isString(value)) {
|
||||
type = TYPES.CAT;
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
}, {
|
||||
key: "_getScaleCfg",
|
||||
value: function _getScaleCfg(type, field, data) {
|
||||
var cfg = {
|
||||
field: field
|
||||
};
|
||||
|
||||
var values = _util["default"].Array.values(data, field);
|
||||
|
||||
cfg.values = values;
|
||||
|
||||
if (!_scale["default"].isCategory(type) && type !== 'time') {
|
||||
var range = _util["default"].Array.getRange(values);
|
||||
|
||||
cfg.min = range.min;
|
||||
cfg.max = range.max;
|
||||
cfg.nice = true;
|
||||
}
|
||||
|
||||
if (type === 'time') {
|
||||
cfg.nice = false;
|
||||
}
|
||||
|
||||
return cfg;
|
||||
}
|
||||
}, {
|
||||
key: "createScale",
|
||||
value: function createScale(field, data) {
|
||||
var self = this;
|
||||
|
||||
var def = self._getDef(field);
|
||||
|
||||
var scale; // 如果数据为空直接返回常量度量
|
||||
|
||||
if (!data || !data.length) {
|
||||
if (def && def.type) {
|
||||
scale = _scale["default"][def.type](def);
|
||||
} else {
|
||||
scale = _scale["default"].identity({
|
||||
value: field,
|
||||
field: field.toString(),
|
||||
values: [field]
|
||||
});
|
||||
}
|
||||
|
||||
return scale;
|
||||
}
|
||||
|
||||
var firstValue = _util["default"].Array.firstValue(data, field);
|
||||
|
||||
if (_util["default"].isNumber(field) || _util["default"].isNil(firstValue) && !def) {
|
||||
scale = _scale["default"].identity({
|
||||
value: field,
|
||||
field: field.toString(),
|
||||
values: [field]
|
||||
});
|
||||
} else {
|
||||
// 如果已经定义过这个度量
|
||||
var type;
|
||||
|
||||
if (def) {
|
||||
type = def.type;
|
||||
}
|
||||
|
||||
type = type || self._getDefaultType(field, data);
|
||||
|
||||
var cfg = self._getScaleCfg(type, field, data);
|
||||
|
||||
if (def) {
|
||||
_util["default"].mix(cfg, def);
|
||||
}
|
||||
|
||||
scale = _scale["default"][type](cfg);
|
||||
}
|
||||
|
||||
return scale;
|
||||
}
|
||||
}]);
|
||||
|
||||
return ScaleController;
|
||||
}();
|
||||
|
||||
var _default = ScaleController;
|
||||
exports["default"] = _default;
|
|
@ -1,292 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _util = _interopRequireDefault(require("../../util"));
|
||||
|
||||
var _global = _interopRequireDefault(require("../../global"));
|
||||
|
||||
var _scale = _interopRequireDefault(require("./scale"));
|
||||
|
||||
var _base = _interopRequireDefault(require("../base"));
|
||||
|
||||
var _index = _interopRequireDefault(require("../../attr/index"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
||||
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(source, true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(source).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var TileMapping =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(TileMapping, _Base);
|
||||
|
||||
function TileMapping(source, cfg) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, TileMapping);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(TileMapping).call(this, cfg));
|
||||
_this.source = source;
|
||||
|
||||
_this._init();
|
||||
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(TileMapping, [{
|
||||
key: "_init",
|
||||
value: function _init() {
|
||||
this._initControllers();
|
||||
|
||||
this._initTileAttrs();
|
||||
|
||||
this._mapping();
|
||||
}
|
||||
}, {
|
||||
key: "update",
|
||||
value: function update() {
|
||||
this.set('scales', {});
|
||||
|
||||
this._initTileAttrs();
|
||||
|
||||
this._updateMaping();
|
||||
}
|
||||
}, {
|
||||
key: "_initControllers",
|
||||
value: function _initControllers() {
|
||||
var scalesOption = this.get('scaleOptions');
|
||||
var scaleController = new _scale["default"]({
|
||||
defs: _objectSpread({}, scalesOption)
|
||||
});
|
||||
this.set('scaleController', scaleController);
|
||||
}
|
||||
}, {
|
||||
key: "_createScale",
|
||||
value: function _createScale(field) {
|
||||
var scales = this.get('scales');
|
||||
|
||||
this._initControllers(); // scale更新
|
||||
|
||||
|
||||
var scale = scales[field];
|
||||
|
||||
if (!scale) {
|
||||
scale = this.createScale(field);
|
||||
scales[field] = scale;
|
||||
}
|
||||
|
||||
return scale;
|
||||
}
|
||||
}, {
|
||||
key: "createScale",
|
||||
value: function createScale(field) {
|
||||
var data = this.source.data.dataArray;
|
||||
var scales = this.get('scales');
|
||||
var scale = scales[field];
|
||||
var scaleController = this.get('scaleController');
|
||||
|
||||
if (!scale) {
|
||||
scale = scaleController.createScale(field, data);
|
||||
scales[field] = scale;
|
||||
}
|
||||
|
||||
return scale;
|
||||
} // 获取属性映射的值
|
||||
|
||||
}, {
|
||||
key: "_getAttrValues",
|
||||
value: function _getAttrValues(attr, record) {
|
||||
var scales = attr.scales;
|
||||
var params = [];
|
||||
|
||||
for (var i = 0; i < scales.length; i++) {
|
||||
var scale = scales[i];
|
||||
var field = scale.field;
|
||||
|
||||
if (scale.type === 'identity') {
|
||||
params.push(scale.value);
|
||||
} else {
|
||||
params.push(record[field]);
|
||||
}
|
||||
}
|
||||
|
||||
var indexZoom = params.indexOf('zoom');
|
||||
indexZoom !== -1 ? params[indexZoom] = attr.zoom : null;
|
||||
var values = attr.mapping.apply(attr, params);
|
||||
return values;
|
||||
}
|
||||
}, {
|
||||
key: "_mapping",
|
||||
value: function _mapping() {
|
||||
var attrs = this.get('attrs');
|
||||
var mappedData = [];
|
||||
var data = this.source.data.dataArray;
|
||||
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var record = data[i];
|
||||
var newRecord = {};
|
||||
newRecord.id = data[i]._id;
|
||||
|
||||
for (var k in attrs) {
|
||||
if (attrs.hasOwnProperty(k)) {
|
||||
var attr = attrs[k];
|
||||
var names = attr.names;
|
||||
|
||||
var values = this._getAttrValues(attr, record);
|
||||
|
||||
if (names.length > 1) {
|
||||
// position 之类的生成多个字段的属性
|
||||
for (var j = 0; j < values.length; j++) {
|
||||
var val = values[j];
|
||||
var name = names[j];
|
||||
newRecord[name] = _util["default"].isArray(val) && val.length === 1 ? val[0] : val; // 只有一个值时返回第一个属性值
|
||||
}
|
||||
} else {
|
||||
newRecord[names[0]] = values.length === 1 ? values[0] : values;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newRecord.coordinates = record.coordinates;
|
||||
mappedData.push(newRecord);
|
||||
} // 通过透明度过滤数据
|
||||
|
||||
|
||||
if (attrs.hasOwnProperty('filter')) {
|
||||
mappedData.forEach(function (item) {
|
||||
if (item.filter === false) {
|
||||
item.color[3] = 0;
|
||||
item.id = -item.id;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.layerData = mappedData;
|
||||
}
|
||||
/**
|
||||
* 更新数据maping
|
||||
* @param {*} layerSource 数据源
|
||||
* @param {*} layer map
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: "_updateMaping",
|
||||
value: function _updateMaping() {
|
||||
var attrs = this.get('attrs');
|
||||
var data = this.source.data.dataArray;
|
||||
var layerData = this.layerData;
|
||||
|
||||
for (var i = 0; i < data.length; i++) {
|
||||
var record = data[i];
|
||||
|
||||
for (var attrName in attrs) {
|
||||
if (attrs.hasOwnProperty(attrName) && attrs[attrName].neadUpdate) {
|
||||
var attr = attrs[attrName];
|
||||
var names = attr.names;
|
||||
|
||||
var values = this._getAttrValues(attr, record);
|
||||
|
||||
if (names.length > 1) {
|
||||
// position 之类的生成多个字段的属性
|
||||
for (var j = 0; j < values.length; j++) {
|
||||
var val = values[j];
|
||||
var name = names[j];
|
||||
layerData[i][name] = _util["default"].isArray(val) && val.length === 1 ? val[0] : val; // 只有一个值时返回第一个属性值
|
||||
}
|
||||
} else {
|
||||
layerData[i][names[0]] = values.length === 1 ? values[0] : values;
|
||||
}
|
||||
|
||||
attr.neadUpdate = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "_initTileAttrs",
|
||||
value: function _initTileAttrs() {
|
||||
var attrOptions = this.get('attrOptions');
|
||||
|
||||
for (var type in attrOptions) {
|
||||
if (attrOptions.hasOwnProperty(type)) {
|
||||
this._updateTileAttr(type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "_updateTileAttr",
|
||||
value: function _updateTileAttr(type) {
|
||||
var self = this;
|
||||
var attrs = this.get('attrs');
|
||||
var attrOptions = this.get('attrOptions');
|
||||
var option = attrOptions[type];
|
||||
option.neadUpdate = true;
|
||||
|
||||
var className = _util["default"].upperFirst(type);
|
||||
|
||||
var fields = this._parseFields(option.field);
|
||||
|
||||
var scales = [];
|
||||
|
||||
for (var i = 0; i < fields.length; i++) {
|
||||
var field = fields[i];
|
||||
|
||||
var scale = self._createScale(field);
|
||||
|
||||
if (type === 'color' && _util["default"].isNil(option.values)) {
|
||||
// 设置 color 的默认色值
|
||||
option.values = _global["default"].colors;
|
||||
}
|
||||
|
||||
scales.push(scale);
|
||||
}
|
||||
|
||||
option.scales = scales;
|
||||
var attr = new _index["default"][className](option);
|
||||
attrs[type] = attr;
|
||||
}
|
||||
}, {
|
||||
key: "_parseFields",
|
||||
value: function _parseFields(field) {
|
||||
if (_util["default"].isArray(field)) {
|
||||
return field;
|
||||
}
|
||||
|
||||
if (_util["default"].isString(field)) {
|
||||
return field.split('*');
|
||||
}
|
||||
|
||||
return [field];
|
||||
}
|
||||
}]);
|
||||
|
||||
return TileMapping;
|
||||
}(_base["default"]);
|
||||
|
||||
exports["default"] = TileMapping;
|
|
@ -1,43 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../three"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
var Camera =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function Camera(container) {
|
||||
_classCallCheck(this, Camera);
|
||||
|
||||
this.container = container;
|
||||
var camera = new THREE.PerspectiveCamera(45, 1, 1, 2000000);
|
||||
this.camera = camera;
|
||||
this.updateSize();
|
||||
window.addEventListener('resize', this.updateSize.bind(this));
|
||||
}
|
||||
|
||||
_createClass(Camera, [{
|
||||
key: "updateSize",
|
||||
value: function updateSize() {
|
||||
var container = this.container;
|
||||
this.camera.aspect = container.clientWidth / container.clientHeight;
|
||||
this.camera.updateProjectionMatrix();
|
||||
}
|
||||
}]);
|
||||
|
||||
return Camera;
|
||||
}();
|
||||
|
||||
exports["default"] = Camera;
|
|
@ -1,117 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../three"));
|
||||
|
||||
var _copyShader = _interopRequireDefault(require("./copy-shader"));
|
||||
|
||||
var _shaderPass = _interopRequireDefault(require("./shader-pass"));
|
||||
|
||||
var _maskPass = _interopRequireWildcard(require("./mask-pass"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
// jscs:disable
|
||||
|
||||
/* eslint-disable */
|
||||
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
*/
|
||||
var EffectComposer = function EffectComposer(renderer, renderTarget) {
|
||||
this.renderer = renderer;
|
||||
|
||||
if (renderTarget === undefined) {
|
||||
var pixelRatio = renderer.getPixelRatio();
|
||||
var width = Math.floor(renderer.context.canvas.width / pixelRatio) || 1;
|
||||
var height = Math.floor(renderer.context.canvas.height / pixelRatio) || 1;
|
||||
var parameters = {
|
||||
minFilter: THREE.LinearFilter,
|
||||
magFilter: THREE.LinearFilter,
|
||||
format: THREE.RGBAFormat,
|
||||
stencilBuffer: false
|
||||
};
|
||||
renderTarget = new THREE.WebGLRenderTarget(width, height, parameters);
|
||||
}
|
||||
|
||||
this.renderTarget1 = renderTarget;
|
||||
this.renderTarget2 = renderTarget.clone();
|
||||
this.writeBuffer = this.renderTarget1;
|
||||
this.readBuffer = this.renderTarget2;
|
||||
this.passes = [];
|
||||
if (_copyShader["default"] === undefined) console.error("EffectComposer relies on THREE.CopyShader");
|
||||
this.copyPass = new _shaderPass["default"](_copyShader["default"]);
|
||||
};
|
||||
|
||||
EffectComposer.prototype = {
|
||||
swapBuffers: function swapBuffers() {
|
||||
var tmp = this.readBuffer;
|
||||
this.readBuffer = this.writeBuffer;
|
||||
this.writeBuffer = tmp;
|
||||
},
|
||||
visible: true,
|
||||
type: 'composer',
|
||||
addPass: function addPass(pass) {
|
||||
this.passes.push(pass);
|
||||
},
|
||||
insertPass: function insertPass(pass, index) {
|
||||
this.passes.splice(index, 0, pass);
|
||||
},
|
||||
render: function render(delta) {
|
||||
this.writeBuffer = this.renderTarget1;
|
||||
this.readBuffer = this.renderTarget2;
|
||||
var maskActive = false;
|
||||
var pass,
|
||||
i,
|
||||
il = this.passes.length;
|
||||
|
||||
for (i = 0; i < il; i++) {
|
||||
pass = this.passes[i];
|
||||
if (!pass.enabled) continue;
|
||||
pass.render(this.renderer, this.writeBuffer, this.readBuffer, delta, maskActive);
|
||||
|
||||
if (pass.needsSwap) {
|
||||
if (maskActive) {
|
||||
var context = this.renderer.context;
|
||||
context.stencilFunc(context.NOTEQUAL, 1, 0xffffffff);
|
||||
this.copyPass.render(this.renderer, this.writeBuffer, this.readBuffer, delta);
|
||||
context.stencilFunc(context.EQUAL, 1, 0xffffffff);
|
||||
}
|
||||
|
||||
this.swapBuffers();
|
||||
}
|
||||
|
||||
if (pass instanceof _maskPass["default"]) {
|
||||
maskActive = true;
|
||||
} else if (pass instanceof _maskPass.ClearMaskPass) {
|
||||
maskActive = false;
|
||||
}
|
||||
}
|
||||
},
|
||||
reset: function reset(renderTarget) {
|
||||
if (renderTarget === undefined) {
|
||||
renderTarget = this.renderTarget1.clone();
|
||||
var pixelRatio = this.renderer.getPixelRatio();
|
||||
renderTarget.setSize(Math.floor(this.renderer.context.canvas.width / pixelRatio), Math.floor(this.renderer.context.canvas.height / pixelRatio));
|
||||
}
|
||||
|
||||
this.renderTarget1.dispose();
|
||||
this.renderTarget1 = renderTarget;
|
||||
this.renderTarget2.dispose();
|
||||
this.renderTarget2 = renderTarget.clone();
|
||||
this.writeBuffer = this.renderTarget1;
|
||||
this.readBuffer = this.renderTarget2;
|
||||
},
|
||||
setSize: function setSize(width, height) {
|
||||
this.renderTarget1.setSize(width, height);
|
||||
this.renderTarget2.setSize(width, height);
|
||||
}
|
||||
};
|
||||
var _default = EffectComposer;
|
||||
exports["default"] = _default;
|
|
@ -1,36 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../three"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
// jscs:disable
|
||||
|
||||
/* eslint-disable */
|
||||
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
*
|
||||
* Full-screen textured quad shader
|
||||
*/
|
||||
var CopyShader = {
|
||||
uniforms: {
|
||||
"tDiffuse": {
|
||||
type: "t",
|
||||
value: null
|
||||
},
|
||||
"opacity": {
|
||||
type: "f",
|
||||
value: 1.0
|
||||
}
|
||||
},
|
||||
vertexShader: ["varying vec2 vUv;", "void main() {", "vUv = uv;", "gl_Position = projectionMatrix * modelViewMatrix * vec4( position, 1.0 );", "}"].join("\n"),
|
||||
fragmentShader: ["uniform float opacity;", "uniform sampler2D tDiffuse;", "varying vec2 vUv;", "void main() {", "vec4 texel = texture2D( tDiffuse, vUv );", "gl_FragColor = opacity * texel;", "}"].join("\n")
|
||||
};
|
||||
var _default = CopyShader;
|
||||
exports["default"] = _default;
|
|
@ -1,27 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = _default;
|
||||
|
||||
var _composer = _interopRequireDefault(require("./composer"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _default(renderer, container) {
|
||||
var composer = new _composer["default"](renderer);
|
||||
|
||||
var updateSize = function updateSize() {
|
||||
// TODO: Re-enable this when perf issues can be solved
|
||||
//
|
||||
// Rendering double the resolution of the screen can be really slow
|
||||
// var pixelRatio = window.devicePixelRatio;
|
||||
var pixelRatio = 1;
|
||||
composer.setSize(container.clientWidth * pixelRatio, container.clientHeight * pixelRatio);
|
||||
};
|
||||
|
||||
window.addEventListener('resize', updateSize, false);
|
||||
updateSize();
|
||||
return composer;
|
||||
}
|
|
@ -1,110 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _wolfy87Eventemitter = _interopRequireDefault(require("wolfy87-eventemitter"));
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../three"));
|
||||
|
||||
var _scene = _interopRequireDefault(require("./scene"));
|
||||
|
||||
var _camera = _interopRequireDefault(require("./camera"));
|
||||
|
||||
var _renderer = _interopRequireDefault(require("./renderer"));
|
||||
|
||||
var _picking = _interopRequireDefault(require("./picking/picking"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var Engine =
|
||||
/*#__PURE__*/
|
||||
function (_EventEmitter) {
|
||||
_inherits(Engine, _EventEmitter);
|
||||
|
||||
function Engine(container, world) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, Engine);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Engine).call(this));
|
||||
_this._scene = _scene["default"];
|
||||
_this._camera = new _camera["default"](container).camera;
|
||||
_this._renderer = new _renderer["default"](container).renderer;
|
||||
_this._world = world; // 地图场景实例
|
||||
// for MapBox
|
||||
|
||||
_this.world = new THREE.Group();
|
||||
|
||||
_this._scene.add(_this.world);
|
||||
|
||||
_this._picking = (0, _picking["default"])(_this._world, _this._renderer, _this._camera);
|
||||
_this.clock = new THREE.Clock();
|
||||
_this.composerLayers = [];
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(Engine, [{
|
||||
key: "_initPostProcessing",
|
||||
value: function _initPostProcessing() {
|
||||
this.composerLayers.forEach(function (layer) {
|
||||
layer.visible && layer.render();
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "update",
|
||||
value: function update() {
|
||||
this._renderer.clear();
|
||||
|
||||
this._renderer.render(this._scene, this._camera);
|
||||
|
||||
this._initPostProcessing();
|
||||
}
|
||||
}, {
|
||||
key: "destroy",
|
||||
value: function destroy() {} // 渲染第三方Scene对象
|
||||
|
||||
}, {
|
||||
key: "renderScene",
|
||||
value: function renderScene(scene) {
|
||||
this._renderer.render(scene, this._camera);
|
||||
}
|
||||
}, {
|
||||
key: "run",
|
||||
value: function run() {
|
||||
this.update();
|
||||
this.engineID = requestAnimationFrame(this.run.bind(this));
|
||||
}
|
||||
}, {
|
||||
key: "stop",
|
||||
value: function stop() {
|
||||
cancelAnimationFrame(this.engineID);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Engine;
|
||||
}(_wolfy87Eventemitter["default"]);
|
||||
|
||||
exports["default"] = Engine;
|
|
@ -1,74 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.ClearMaskPass = exports["default"] = void 0;
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../three"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
// jscs:disable
|
||||
|
||||
/* eslint-disable */
|
||||
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
*/
|
||||
var MaskPass = function MaskPass(scene, camera) {
|
||||
this.scene = scene;
|
||||
this.camera = camera;
|
||||
this.enabled = true;
|
||||
this.clear = true;
|
||||
this.needsSwap = false;
|
||||
this.inverse = false;
|
||||
};
|
||||
|
||||
MaskPass.prototype = {
|
||||
render: function render(renderer, writeBuffer, readBuffer, delta) {
|
||||
var context = renderer.context; // don't update color or depth
|
||||
|
||||
context.colorMask(false, false, false, false);
|
||||
context.depthMask(false); // set up stencil
|
||||
|
||||
var writeValue, clearValue;
|
||||
|
||||
if (this.inverse) {
|
||||
writeValue = 0;
|
||||
clearValue = 1;
|
||||
} else {
|
||||
writeValue = 1;
|
||||
clearValue = 0;
|
||||
}
|
||||
|
||||
context.enable(context.STENCIL_TEST);
|
||||
context.stencilOp(context.REPLACE, context.REPLACE, context.REPLACE);
|
||||
context.stencilFunc(context.ALWAYS, writeValue, 0xffffffff);
|
||||
context.clearStencil(clearValue); // draw into the stencil buffer
|
||||
|
||||
renderer.render(this.scene, this.camera, readBuffer, this.clear);
|
||||
renderer.render(this.scene, this.camera, writeBuffer, this.clear); // re-enable update of color and depth
|
||||
|
||||
context.colorMask(true, true, true, true);
|
||||
context.depthMask(true); // only render where stencil is set to 1
|
||||
|
||||
context.stencilFunc(context.EQUAL, 1, 0xffffffff); // draw if == 1
|
||||
|
||||
context.stencilOp(context.KEEP, context.KEEP, context.KEEP);
|
||||
}
|
||||
};
|
||||
|
||||
var ClearMaskPass = function ClearMaskPass() {
|
||||
this.enabled = true;
|
||||
};
|
||||
|
||||
exports.ClearMaskPass = ClearMaskPass;
|
||||
ClearMaskPass.prototype = {
|
||||
render: function render(renderer, writeBuffer, readBuffer, delta) {
|
||||
var context = renderer.context;
|
||||
context.disable(context.STENCIL_TEST);
|
||||
}
|
||||
};
|
||||
var _default = MaskPass;
|
||||
exports["default"] = _default;
|
|
@ -1,250 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = _default;
|
||||
|
||||
var _pickingScene = _interopRequireDefault(require("./pickingScene"));
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../../three"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
var nextId = 1;
|
||||
|
||||
var Picking =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function Picking(world, renderer, camera) {
|
||||
_classCallCheck(this, Picking);
|
||||
|
||||
this._world = world;
|
||||
this._renderer = renderer;
|
||||
this._camera = camera;
|
||||
this._pickingScene = _pickingScene["default"];
|
||||
this.world = new THREE.Group();
|
||||
|
||||
this._pickingScene.add(this.world);
|
||||
|
||||
var size = this._renderer.getSize();
|
||||
|
||||
this._width = size.width;
|
||||
this._height = size.height;
|
||||
var parameters = {
|
||||
minFilter: THREE.LinearFilter,
|
||||
magFilter: THREE.LinearFilter,
|
||||
format: THREE.RGBAFormat,
|
||||
stencilBuffer: false,
|
||||
depthBuffer: true
|
||||
};
|
||||
this._pickingTexture = new THREE.WebGLRenderTarget(this._width, this._height, parameters);
|
||||
this._nextId = 1;
|
||||
|
||||
this._resizeTexture();
|
||||
|
||||
this._initEvents();
|
||||
}
|
||||
|
||||
_createClass(Picking, [{
|
||||
key: "_initEvents",
|
||||
value: function _initEvents() {
|
||||
this._resizeHandler = this._resizeTexture.bind(this);
|
||||
window.addEventListener('resize', this._resizeHandler, false);
|
||||
}
|
||||
}, {
|
||||
key: "pickdata",
|
||||
value: function pickdata(event) {
|
||||
var point = {
|
||||
x: event.offsetX,
|
||||
y: event.offsetY,
|
||||
type: event.type
|
||||
};
|
||||
var normalisedPoint = {
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
normalisedPoint.x = point.x / this._width * 2 - 1;
|
||||
normalisedPoint.y = -(point.y / this._height) * 2 + 1;
|
||||
|
||||
this._pickAllObject(point, normalisedPoint);
|
||||
}
|
||||
}, {
|
||||
key: "_resizeTexture",
|
||||
value: function _resizeTexture() {
|
||||
var size = this._renderer.getSize();
|
||||
|
||||
this._width = size.width;
|
||||
this._height = size.height;
|
||||
|
||||
this._pickingTexture.setSize(this._width, this._height);
|
||||
|
||||
this._pixelBuffer = new Uint8Array(4 * this._width * this._height);
|
||||
this._needUpdate = true;
|
||||
}
|
||||
}, {
|
||||
key: "_update",
|
||||
value: function _update(point) {
|
||||
var texture = this._pickingTexture;
|
||||
|
||||
this._renderer.render(this._pickingScene, this._camera, texture);
|
||||
|
||||
this.pixelBuffer = new Uint8Array(4);
|
||||
|
||||
this._renderer.readRenderTargetPixels(texture, point.x, this._height - point.y, 1, 1, this.pixelBuffer);
|
||||
}
|
||||
}, {
|
||||
key: "_filterObject",
|
||||
value: function _filterObject(id) {
|
||||
this.world.children.forEach(function (object, index) {
|
||||
index === id ? object.visible = true : object.visible = false;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_layerIsVisable",
|
||||
value: function _layerIsVisable(object) {
|
||||
var layers = this._world.getLayers();
|
||||
|
||||
var isVisable = false;
|
||||
|
||||
for (var i = 0; i < layers.length; i++) {
|
||||
var layer = layers[i];
|
||||
|
||||
if (object.name === layer.layerId) {
|
||||
isVisable = layer.get('visible');
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return isVisable;
|
||||
}
|
||||
}, {
|
||||
key: "_pickAllObject",
|
||||
value: function _pickAllObject(point, normalisedPoint) {
|
||||
var _this = this;
|
||||
|
||||
this.world.children.forEach(function (object, index) {
|
||||
if (!_this._layerIsVisable(object)) {
|
||||
return;
|
||||
}
|
||||
|
||||
_this._filterObject(index);
|
||||
|
||||
var item = _this._pick(point, normalisedPoint, object.name);
|
||||
|
||||
item.type = point.type;
|
||||
|
||||
_this._world.emit('pick', item);
|
||||
|
||||
_this._world.emit('pick-' + object.name, item);
|
||||
});
|
||||
} // _updateRender() {
|
||||
// this._renderer.render(this._pickingScene, this._camera, this._pickingTexture);
|
||||
// }
|
||||
|
||||
}, {
|
||||
key: "_pick",
|
||||
value: function _pick(point, normalisedPoint, layerId) {
|
||||
this._update(point);
|
||||
|
||||
var id = this.pixelBuffer[2] * 255 * 255 + this.pixelBuffer[1] * 255 + this.pixelBuffer[0];
|
||||
|
||||
if (id === 16646655 || this.pixelBuffer[3] === 0) {
|
||||
id = -999; // return;
|
||||
}
|
||||
|
||||
var _point2d = {
|
||||
x: point.x,
|
||||
y: point.y
|
||||
};
|
||||
var item = {
|
||||
layerId: layerId,
|
||||
featureId: id,
|
||||
point2d: _point2d
|
||||
};
|
||||
return item;
|
||||
} // Add mesh to picking scene
|
||||
//
|
||||
// Picking ID should already be added as an attribute
|
||||
|
||||
}, {
|
||||
key: "add",
|
||||
value: function add(mesh) {
|
||||
this.world.add(mesh);
|
||||
this._needUpdate = true;
|
||||
} // Remove mesh from picking scene
|
||||
|
||||
}, {
|
||||
key: "remove",
|
||||
value: function remove(mesh) {
|
||||
this.world.remove(mesh);
|
||||
this._needUpdate = true;
|
||||
} // Returns next ID to use for picking
|
||||
|
||||
}, {
|
||||
key: "getNextId",
|
||||
value: function getNextId() {
|
||||
return nextId++;
|
||||
}
|
||||
}, {
|
||||
key: "destroy",
|
||||
value: function destroy() {
|
||||
var _this2 = this;
|
||||
|
||||
// TODO: Find a way to properly remove these listeners as they stay
|
||||
// active at the moment
|
||||
window.removeEventListener('resize', this._resizeHandler, false);
|
||||
|
||||
this._envents.forEach(function (event) {
|
||||
_this2._world._container.removeEventListener(event[0], event[1], false);
|
||||
});
|
||||
|
||||
if (this._pickingScene.children) {
|
||||
// Remove everything else in the layer
|
||||
var child;
|
||||
|
||||
for (var i = this._pickingScene.children.length - 1; i >= 0; i--) {
|
||||
child = this._pickingScene.children[i];
|
||||
|
||||
if (!child) {
|
||||
continue;
|
||||
}
|
||||
|
||||
this._pickingScene.remove(child);
|
||||
|
||||
if (child.material) {
|
||||
if (child.material.map) {
|
||||
child.material.map.dispose();
|
||||
child.material.map = null;
|
||||
}
|
||||
|
||||
child.material.dispose();
|
||||
child.material = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this._pickingScene = null;
|
||||
this._pickingTexture = null;
|
||||
this._pixelBuffer = null;
|
||||
this._world = null;
|
||||
this._renderer = null;
|
||||
this._camera = null;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Picking;
|
||||
}(); // Initialise without requiring new keyword
|
||||
|
||||
|
||||
function _default(world, renderer, camera, scene) {
|
||||
return new Picking(world, renderer, camera, scene);
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = PickingMaterial;
|
||||
|
||||
var _material = _interopRequireDefault(require("../../../geom/material/material"));
|
||||
|
||||
var _picking_frag = _interopRequireDefault(require("./picking_frag.glsl"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
// import picking_vert from './picking_vert.glsl';
|
||||
function PickingMaterial(options) {
|
||||
var material = new _material["default"]({
|
||||
uniforms: {
|
||||
u_zoom: {
|
||||
value: options.u_zoom || 1
|
||||
}
|
||||
},
|
||||
defines: {
|
||||
PICK: true
|
||||
},
|
||||
vertexShader: options.vs,
|
||||
fragmentShader: _picking_frag["default"],
|
||||
transparent: false
|
||||
});
|
||||
return material;
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../../three"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
// This can be imported from anywhere and will still reference the same scene,
|
||||
// though there is a helper reference in Engine.pickingScene
|
||||
var _default = function () {
|
||||
var scene = new THREE.Scene();
|
||||
return scene;
|
||||
}();
|
||||
|
||||
exports["default"] = _default;
|
|
@ -1,52 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../three"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
// jscs:disable
|
||||
|
||||
/* eslint-disable */
|
||||
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
*/
|
||||
var RenderPass = function RenderPass(scene, camera, overrideMaterial, clearColor, clearAlpha) {
|
||||
this.scene = scene;
|
||||
this.camera = camera;
|
||||
this.overrideMaterial = overrideMaterial;
|
||||
this.clearColor = clearColor;
|
||||
this.clearAlpha = clearAlpha !== undefined ? clearAlpha : 1;
|
||||
this.oldClearColor = new THREE.Color();
|
||||
this.oldClearAlpha = 1;
|
||||
this.enabled = true;
|
||||
this.clear = false;
|
||||
this.needsSwap = false;
|
||||
};
|
||||
|
||||
RenderPass.prototype = {
|
||||
render: function render(renderer, writeBuffer, readBuffer, delta) {
|
||||
this.scene.overrideMaterial = this.overrideMaterial;
|
||||
|
||||
if (this.clearColor) {
|
||||
this.oldClearColor.copy(renderer.getClearColor());
|
||||
this.oldClearAlpha = renderer.getClearAlpha();
|
||||
renderer.setClearColor(this.clearColor, this.clearAlpha);
|
||||
}
|
||||
|
||||
renderer.render(this.scene, this.camera, readBuffer, this.clear);
|
||||
|
||||
if (this.clearColor) {
|
||||
renderer.setClearColor(this.oldClearColor, this.oldClearAlpha);
|
||||
}
|
||||
|
||||
this.scene.overrideMaterial = null;
|
||||
}
|
||||
};
|
||||
var _default = RenderPass;
|
||||
exports["default"] = _default;
|
|
@ -1,56 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../three"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
var Renderer =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function Renderer(container) {
|
||||
_classCallCheck(this, Renderer);
|
||||
|
||||
this.container = container;
|
||||
this.initRender();
|
||||
this.updateSize();
|
||||
window.addEventListener('resize', this.updateSize.bind(this), false);
|
||||
}
|
||||
|
||||
_createClass(Renderer, [{
|
||||
key: "initRender",
|
||||
value: function initRender() {
|
||||
this.renderer = new THREE.WebGLRenderer({
|
||||
antialias: true,
|
||||
alpha: true,
|
||||
autoClear: false
|
||||
});
|
||||
this.renderer.setClearColor(0xff0000, 0.0);
|
||||
this.pixelRatio = window.devicePixelRatio;
|
||||
this.renderer.setPixelRatio(this.pixelRatio);
|
||||
this.renderer.gammaInput = true;
|
||||
this.renderer.gammaOutput = true;
|
||||
this.renderer.shadowMap.enabled = false;
|
||||
this.container.appendChild(this.renderer.domElement);
|
||||
}
|
||||
}, {
|
||||
key: "updateSize",
|
||||
value: function updateSize() {
|
||||
this.renderer.setSize(this.container.clientWidth, this.container.clientHeight);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Renderer;
|
||||
}();
|
||||
|
||||
exports["default"] = Renderer;
|
|
@ -1,107 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../three"));
|
||||
|
||||
var _util = _interopRequireDefault(require("../../util"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
var RenderPass =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function RenderPass(cfg) {
|
||||
_classCallCheck(this, RenderPass);
|
||||
|
||||
var defaultCfg = this._getDefaultCfg();
|
||||
|
||||
_util.default.assign(this, defaultCfg, cfg);
|
||||
|
||||
this._init();
|
||||
}
|
||||
|
||||
_createClass(RenderPass, [{
|
||||
key: "_getDefaultCfg",
|
||||
value: function _getDefaultCfg() {
|
||||
var defaultRenderCfg = {
|
||||
minFilter: THREE.NearestFilter,
|
||||
magFilter: THREE.NearestFilter,
|
||||
format: THREE.RGBAFormat,
|
||||
stencilBuffer: false,
|
||||
depthBuffer: false
|
||||
};
|
||||
return {
|
||||
size: null,
|
||||
renderCfg: defaultRenderCfg,
|
||||
clearColor: 0x000000,
|
||||
clearAlpha: 0.0,
|
||||
renderToScreen: false,
|
||||
renderTarget: true
|
||||
};
|
||||
}
|
||||
}, {
|
||||
key: "_init",
|
||||
value: function _init() {
|
||||
this.scene = new THREE.Scene();
|
||||
|
||||
if (this.renderTarget) {
|
||||
var size = this.size ? this.size : this.renderer.getSize();
|
||||
this.renderTarget = new THREE.WebGLRenderTarget(size.width, size.height, this.renderCfg);
|
||||
this.texture = this.renderTarget.texture;
|
||||
}
|
||||
|
||||
this.originClearColor = this.renderer.getClearColor();
|
||||
this.originClearAlpha = this.renderer.getClearAlpha();
|
||||
}
|
||||
}, {
|
||||
key: "setSize",
|
||||
value: function setSize(width, height) {
|
||||
this.size = {
|
||||
width: width,
|
||||
height: height
|
||||
};
|
||||
this.renderTarget && this.renderTarget.setSize(width, height);
|
||||
}
|
||||
}, {
|
||||
key: "add",
|
||||
value: function add(mesh) {
|
||||
this.scene.add(mesh);
|
||||
}
|
||||
}, {
|
||||
key: "remove",
|
||||
value: function remove(mesh) {
|
||||
this.scene.remove(mesh);
|
||||
}
|
||||
}, {
|
||||
key: "render",
|
||||
value: function render() {
|
||||
this.renderer.setClearColor(this.clearColor, this.clearAlpha);
|
||||
|
||||
if (this.renderToScreen) {
|
||||
this.renderer.setRenderTarget(null);
|
||||
this.renderer.render(this.scene, this.camera);
|
||||
} else {
|
||||
this.renderTarget && this.renderer.render(this.scene, this.camera, this.renderTarget, true);
|
||||
this.renderer.setRenderTarget(null);
|
||||
}
|
||||
|
||||
this.renderer.setClearColor(this.originClearColor, this.originClearAlpha);
|
||||
}
|
||||
}]);
|
||||
|
||||
return RenderPass;
|
||||
}();
|
||||
|
||||
exports.default = RenderPass;
|
|
@ -1,17 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../three"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
var _default = function () {
|
||||
var scene = new THREE.Scene();
|
||||
return scene;
|
||||
}();
|
||||
|
||||
exports["default"] = _default;
|
|
@ -1,64 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../three"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
// jscs:disable
|
||||
|
||||
/* eslint-disable */
|
||||
|
||||
/**
|
||||
* @author alteredq / http://alteredqualia.com/
|
||||
*/
|
||||
var ShaderPass = function ShaderPass(shader, textureID) {
|
||||
this.textureID = textureID !== undefined ? textureID : "tDiffuse";
|
||||
|
||||
if (shader instanceof THREE.ShaderMaterial) {
|
||||
this.uniforms = shader.uniforms;
|
||||
this.material = shader;
|
||||
} else if (shader) {
|
||||
this.uniforms = THREE.UniformsUtils.clone(shader.uniforms);
|
||||
this.material = new THREE.ShaderMaterial({
|
||||
defines: shader.defines || {},
|
||||
uniforms: this.uniforms,
|
||||
vertexShader: shader.vertexShader,
|
||||
fragmentShader: shader.fragmentShader
|
||||
});
|
||||
}
|
||||
|
||||
this.renderToScreen = false;
|
||||
this.enabled = true;
|
||||
this.needsSwap = true;
|
||||
this.clear = true;
|
||||
this.camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
||||
this.scene = new THREE.Scene();
|
||||
this.quad = new THREE.Mesh(new THREE.PlaneBufferGeometry(2, 2), null);
|
||||
this.scene.add(this.quad);
|
||||
};
|
||||
|
||||
ShaderPass.prototype = {
|
||||
render: function render(renderer, writeBuffer, readBuffer, delta) {
|
||||
if (this.uniforms[this.textureID]) {
|
||||
this.uniforms[this.textureID].value = readBuffer.texture;
|
||||
}
|
||||
|
||||
renderer.autoClear = false;
|
||||
this.quad.material = this.material;
|
||||
|
||||
if (this.renderToScreen) {
|
||||
renderer.render(this.scene, this.camera);
|
||||
} else {
|
||||
renderer.render(this.scene, this.camera, writeBuffer, this.clear);
|
||||
}
|
||||
|
||||
renderer.autoClear = true;
|
||||
}
|
||||
};
|
||||
var _default = ShaderPass;
|
||||
exports["default"] = _default;
|
|
@ -1,79 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../three"));
|
||||
|
||||
var _renderpass = _interopRequireDefault(require("./renderpass"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
|
||||
|
||||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var ShaderPass =
|
||||
/*#__PURE__*/
|
||||
function (_RenderPass) {
|
||||
_inherits(ShaderPass, _RenderPass);
|
||||
|
||||
function ShaderPass(cfg) {
|
||||
_classCallCheck(this, ShaderPass);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(ShaderPass).call(this, _objectSpread({
|
||||
size: {
|
||||
width: 2,
|
||||
height: 2
|
||||
}
|
||||
}, cfg)));
|
||||
}
|
||||
|
||||
_createClass(ShaderPass, [{
|
||||
key: "_init",
|
||||
value: function _init(cfg) {
|
||||
_get(_getPrototypeOf(ShaderPass.prototype), "_init", this).call(this, cfg);
|
||||
|
||||
this.camera = new THREE.OrthographicCamera(-this.size.width / 2, this.size.width / 2, this.size.height / 2, -this.size.height / 2, 0, 100);
|
||||
this.material = new THREE.ShaderMaterial(_objectSpread({
|
||||
vertexShader: this.vertexShader,
|
||||
fragmentShader: this.fragmentShader,
|
||||
uniforms: this.uniforms
|
||||
}, this.matCfg));
|
||||
this.quad = new THREE.Mesh(new THREE.PlaneBufferGeometry(this.size.width, this.size.height), this.material);
|
||||
this.quad.frustumCulled = false; // Avoid getting clipped
|
||||
|
||||
this.scene.add(this.quad);
|
||||
}
|
||||
}]);
|
||||
|
||||
return ShaderPass;
|
||||
}(_renderpass.default);
|
||||
|
||||
exports.default = ShaderPass;
|
|
@ -1,50 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = DrawMaterial;
|
||||
|
||||
var _material = _interopRequireDefault(require("../../../geom/material/material"));
|
||||
|
||||
var _draw_vert = _interopRequireDefault(require("./draw_vert.glsl"));
|
||||
|
||||
var _draw_frag = _interopRequireDefault(require("./draw_frag.glsl"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function DrawMaterial(options) {
|
||||
var material = new _material.default({
|
||||
uniforms: {
|
||||
u_color_ramp: {
|
||||
value: options.u_color_ramp
|
||||
},
|
||||
u_wind_max: {
|
||||
value: options.u_wind_max
|
||||
},
|
||||
u_particles_res: {
|
||||
value: options.u_particles_res
|
||||
},
|
||||
u_wind_min: {
|
||||
value: options.u_wind_min
|
||||
},
|
||||
u_opacity: {
|
||||
value: options.u_opacity
|
||||
},
|
||||
u_wind: {
|
||||
value: options.u_wind
|
||||
},
|
||||
u_particles: {
|
||||
value: options.u_particles
|
||||
},
|
||||
u_bbox: {
|
||||
value: options.u_bbox
|
||||
}
|
||||
},
|
||||
vertexShader: _draw_vert.default,
|
||||
fragmentShader: _draw_frag.default,
|
||||
transparent: true
|
||||
}); // material.blending = THREE.AdditiveBlending
|
||||
|
||||
return material;
|
||||
}
|
|
@ -1,85 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _r3Base = require("@ali/r3-base");
|
||||
|
||||
var _r3Geometry = require("@ali/r3-geometry");
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
/**
|
||||
* 创建点图层几何体
|
||||
*/
|
||||
var DrawGeometry =
|
||||
/*#__PURE__*/
|
||||
function (_BufferGeometry) {
|
||||
_inherits(DrawGeometry, _BufferGeometry);
|
||||
|
||||
function DrawGeometry(opts) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, DrawGeometry);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(DrawGeometry).call(this, opts.name));
|
||||
_this._index = opts.index;
|
||||
_this.mode = _r3Base.DrawMode.POINTS;
|
||||
_this.primitive.indexType = _r3Base.DataType.UNSIGNED_INT;
|
||||
|
||||
_this.initialize();
|
||||
|
||||
return _this;
|
||||
}
|
||||
/**
|
||||
* 构造多边形数据
|
||||
* @private
|
||||
*/
|
||||
|
||||
|
||||
_createClass(DrawGeometry, [{
|
||||
key: "initialize",
|
||||
value: function initialize() {
|
||||
var _this2 = this;
|
||||
|
||||
_get(_getPrototypeOf(DrawGeometry.prototype), "initialize", this).call(this, [{
|
||||
semantic: 'INDEX',
|
||||
size: 1,
|
||||
type: _r3Base.DataType.FLOAT,
|
||||
normalized: false
|
||||
}], this._index.length);
|
||||
|
||||
this._index.forEach(function (vert, j) {
|
||||
_this2.setVertexValues(j, {
|
||||
INDEX: [vert]
|
||||
});
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return DrawGeometry;
|
||||
}(_r3Geometry.BufferGeometry);
|
||||
|
||||
exports.default = DrawGeometry;
|
|
@ -1,137 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var THREE = _interopRequireWildcard(require("./three"));
|
||||
|
||||
var _wolfy87Eventemitter = _interopRequireDefault(require("wolfy87-eventemitter"));
|
||||
|
||||
var _ajax = require("../util/ajax");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
// 将图片标注绘制在512*512的画布上,每个大小 64*64 支持 64种图片
|
||||
var LoadImage =
|
||||
/*#__PURE__*/
|
||||
function (_EventEmitter) {
|
||||
_inherits(LoadImage, _EventEmitter);
|
||||
|
||||
function LoadImage() {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, LoadImage);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(LoadImage).call(this));
|
||||
var pixelRatio = window.devicePixelRatio || 1;
|
||||
_this.imageWidth = 64 * pixelRatio;
|
||||
_this.canvas = document.createElement('canvas');
|
||||
_this.canvas.style.cssText += 'height: 512px;width: 512px;';
|
||||
_this.canvas.width = _this.imageWidth * 8;
|
||||
_this.canvas.height = _this.imageWidth * 8;
|
||||
_this.ctx = _this.canvas.getContext('2d');
|
||||
_this.images = [];
|
||||
_this.imagesCount = 0;
|
||||
_this.imagePos = {};
|
||||
_this.imagesIds = [];
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(LoadImage, [{
|
||||
key: "addImage",
|
||||
value: function addImage(id, opt) {
|
||||
var _this2 = this;
|
||||
|
||||
this.imagesCount++;
|
||||
this.imagesIds.push(id);
|
||||
var imageCount = this.imagesCount;
|
||||
var x = imageCount % 8 * this.imageWidth;
|
||||
var y = parseInt(imageCount / 8) * this.imageWidth;
|
||||
this.imagePos[id] = {
|
||||
x: x / this.canvas.width,
|
||||
y: y / this.canvas.height
|
||||
};
|
||||
this.texture = new THREE.Texture(this.canvas);
|
||||
|
||||
if (typeof opt === 'string') {
|
||||
(0, _ajax.getImage)({
|
||||
url: opt
|
||||
}, function (err, img) {
|
||||
img.id = id;
|
||||
|
||||
_this2.images.push(img);
|
||||
|
||||
_this2.ctx.drawImage(img, x, y, _this2.imageWidth, _this2.imageWidth);
|
||||
|
||||
_this2.texture.magFilter = THREE.LinearFilter;
|
||||
_this2.texture.minFilter = THREE.LinearFilter;
|
||||
_this2.texture.needsUpdate = true;
|
||||
|
||||
if (_this2.images.length === _this2.imagesCount) {
|
||||
_this2.emit('imageLoaded');
|
||||
}
|
||||
});
|
||||
} else {
|
||||
var width = opt.width,
|
||||
height = opt.height,
|
||||
channels = opt.channels;
|
||||
var data = new Uint8Array(width * height * channels);
|
||||
var image = new Image();
|
||||
image.width = width;
|
||||
image.height = height;
|
||||
image.data = data;
|
||||
image.id = id;
|
||||
this.images.push(image);
|
||||
this.ctx.drawImage(image, x, y, this.imageWidth, this.imageWidth);
|
||||
this.texture = new THREE.CanvasTexture(this.canvas);
|
||||
this.imagePos[id] = {
|
||||
x: x >> 9,
|
||||
y: y >> 9
|
||||
};
|
||||
|
||||
if (this.images.length === this.imagesCount) {
|
||||
this.emit('imageLoaded');
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "removeImage",
|
||||
value: function removeImage() {} // todo
|
||||
// drawAllImages() {
|
||||
// this.images.forEach((item, index) => {
|
||||
// const x = parseInt(index / 8) * 64;
|
||||
// const y = index % 8 * 64;
|
||||
// this.ctx.drawImage(item, x, y, 64, 64);
|
||||
// });
|
||||
// this.texture = new CanvasTexture(this.canvas);
|
||||
// this.texture.needsUpdate=true;
|
||||
// }
|
||||
|
||||
}]);
|
||||
|
||||
return LoadImage;
|
||||
}(_wolfy87Eventemitter["default"]);
|
||||
|
||||
exports["default"] = LoadImage;
|
1010
lib/core/layer.js
1010
lib/core/layer.js
File diff suppressed because it is too large
Load Diff
|
@ -1,279 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _engine = _interopRequireDefault(require("./engine"));
|
||||
|
||||
var _layer = require("../layer");
|
||||
|
||||
var _base = _interopRequireDefault(require("./base"));
|
||||
|
||||
var _image = _interopRequireDefault(require("./image"));
|
||||
|
||||
var _fontManager = _interopRequireDefault(require("../geom/buffer/point/text/font-manager"));
|
||||
|
||||
var _index = require("../map/index");
|
||||
|
||||
var _global = _interopRequireDefault(require("../global"));
|
||||
|
||||
var _index2 = require("../interaction/index");
|
||||
|
||||
var _shader = require("../geom/shader");
|
||||
|
||||
var _style = _interopRequireDefault(require("./style"));
|
||||
|
||||
var _crsEpsg = require("@antv/geo-coord/lib/geo/crs/crs-epsg3857");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var Scene =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Scene, _Base);
|
||||
|
||||
_createClass(Scene, [{
|
||||
key: "getDefaultCfg",
|
||||
value: function getDefaultCfg() {
|
||||
return _global["default"].scene;
|
||||
}
|
||||
}]);
|
||||
|
||||
function Scene(cfg) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, Scene);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Scene).call(this, cfg));
|
||||
|
||||
_this._initMap();
|
||||
|
||||
_this.crs = _crsEpsg.epsg3857; // this._initAttribution(); // 暂时取消,后面作为组件去加载
|
||||
|
||||
_this.addImage();
|
||||
|
||||
_this.fontAtlasManager = new _fontManager["default"]();
|
||||
_this._layers = [];
|
||||
_this.animateCount = 0;
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(Scene, [{
|
||||
key: "_initEngine",
|
||||
value: function _initEngine(mapContainer) {
|
||||
this._engine = new _engine["default"](mapContainer, this);
|
||||
this.registerMapEvent(); // this._engine.run();
|
||||
|
||||
(0, _shader.compileBuiltinModules)();
|
||||
} // 为pickup场景添加 object 对象
|
||||
|
||||
}, {
|
||||
key: "addPickMesh",
|
||||
value: function addPickMesh(object) {
|
||||
this._engine._picking.add(object);
|
||||
}
|
||||
}, {
|
||||
key: "_initMap",
|
||||
value: function _initMap() {
|
||||
var _this2 = this;
|
||||
|
||||
this.mapContainer = this.get('id');
|
||||
this.mapType = this.get('mapType') || 'amap';
|
||||
var MapProvider = (0, _index.getMap)(this.mapType);
|
||||
var Map = new MapProvider(this._attrs);
|
||||
Map.mixMap(this);
|
||||
this._container = Map.container;
|
||||
Map.on('mapLoad', function () {
|
||||
_this2.map = Map.map;
|
||||
|
||||
_this2._initEngine(Map.renderDom);
|
||||
|
||||
Map.asyncCamera(_this2._engine);
|
||||
|
||||
_this2.initLayer();
|
||||
|
||||
_this2._registEvents();
|
||||
|
||||
var hash = _this2.get('hash');
|
||||
|
||||
if (hash) {
|
||||
var Ctor = (0, _index2.getInteraction)('hash');
|
||||
var interaction = new Ctor({
|
||||
layer: _this2
|
||||
});
|
||||
|
||||
interaction._onHashChange();
|
||||
}
|
||||
|
||||
_this2.style = new _style["default"](_this2, {});
|
||||
|
||||
_this2.emit('loaded');
|
||||
|
||||
_this2._engine.update();
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "initLayer",
|
||||
value: function initLayer() {
|
||||
var _this3 = this;
|
||||
|
||||
var _loop = function _loop(key) {
|
||||
Scene.prototype[key] = function (cfg) {
|
||||
var layer = new _layer.LAYER_MAP[key](_this3, cfg);
|
||||
|
||||
_this3._layers.push(layer);
|
||||
|
||||
return layer;
|
||||
};
|
||||
};
|
||||
|
||||
for (var key in _layer.LAYER_MAP) {
|
||||
_loop(key);
|
||||
}
|
||||
} // 添加 Tile Source
|
||||
|
||||
}, {
|
||||
key: "addTileSource",
|
||||
value: function addTileSource(id, Sourcecfg) {
|
||||
this.style.addSource(id, Sourcecfg);
|
||||
}
|
||||
}, {
|
||||
key: "getTileSource",
|
||||
value: function getTileSource(id) {
|
||||
return this.style.getSource(id);
|
||||
}
|
||||
}, {
|
||||
key: "on",
|
||||
value: function on(type, hander) {
|
||||
if (this.map) {
|
||||
this.map.on(type, hander);
|
||||
}
|
||||
|
||||
_get(_getPrototypeOf(Scene.prototype), "on", this).call(this, type, hander);
|
||||
}
|
||||
}, {
|
||||
key: "off",
|
||||
value: function off(type, hander) {
|
||||
if (this.map) {
|
||||
this.map.off(type, hander);
|
||||
}
|
||||
|
||||
_get(_getPrototypeOf(Scene.prototype), "off", this).call(this, type, hander);
|
||||
}
|
||||
}, {
|
||||
key: "addImage",
|
||||
value: function addImage() {
|
||||
this.image = new _image["default"]();
|
||||
}
|
||||
}, {
|
||||
key: "_initEvent",
|
||||
value: function _initEvent() {}
|
||||
}, {
|
||||
key: "getLayers",
|
||||
value: function getLayers() {
|
||||
return this._layers;
|
||||
}
|
||||
}, {
|
||||
key: "_addLayer",
|
||||
value: function _addLayer() {}
|
||||
}, {
|
||||
key: "_registEvents",
|
||||
value: function _registEvents() {
|
||||
var _this4 = this;
|
||||
|
||||
var events = ['mouseout', 'mouseover', 'mousemove', 'mousedown', 'mouseleave', 'mouseup', 'rightclick', 'click', 'dblclick'];
|
||||
events.forEach(function (event) {
|
||||
_this4._container.addEventListener(event, function (e) {
|
||||
// 要素拾取
|
||||
e.pixel || (e.pixel = e.point);
|
||||
requestAnimationFrame(function () {
|
||||
_this4._engine._picking.pickdata(e);
|
||||
});
|
||||
}, false);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "removeLayer",
|
||||
value: function removeLayer(layer) {
|
||||
var layerIndex = this._layers.indexOf(layer);
|
||||
|
||||
if (layerIndex > -1) {
|
||||
this._layers.splice(layerIndex, 1);
|
||||
}
|
||||
|
||||
layer.destroy();
|
||||
layer = null;
|
||||
}
|
||||
}, {
|
||||
key: "startAnimate",
|
||||
value: function startAnimate() {
|
||||
if (this.animateCount === 0) {
|
||||
this.unRegsterMapEvent();
|
||||
|
||||
this._engine.run();
|
||||
}
|
||||
|
||||
this.animateCount++;
|
||||
}
|
||||
}, {
|
||||
key: "stopAnimate",
|
||||
value: function stopAnimate() {
|
||||
if (this.animateCount === 1) {
|
||||
this._engine.stop();
|
||||
|
||||
this.registerMapEvent();
|
||||
}
|
||||
|
||||
this.animateCount++;
|
||||
} // 地图状态变化时更新可视化渲染
|
||||
|
||||
}, {
|
||||
key: "registerMapEvent",
|
||||
value: function registerMapEvent() {
|
||||
var _this5 = this;
|
||||
|
||||
this._updateRender = function () {
|
||||
return _this5._engine.update();
|
||||
};
|
||||
|
||||
this.map.on('mousemove', this._updateRender);
|
||||
this.map.on('mapmove', this._updateRender);
|
||||
this.map.on('camerachange', this._updateRender);
|
||||
}
|
||||
}, {
|
||||
key: "unRegsterMapEvent",
|
||||
value: function unRegsterMapEvent() {
|
||||
this.map.off('mousemove', this._updateRender);
|
||||
this.map.off('mapmove', this._updateRender);
|
||||
this.map.off('camerachange', this._updateRender);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Scene;
|
||||
}(_base["default"]);
|
||||
|
||||
exports["default"] = Scene;
|
|
@ -1,274 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _base = _interopRequireDefault(require("./base"));
|
||||
|
||||
var _source = require("../source");
|
||||
|
||||
var _cluster = require("../source/transform/cluster");
|
||||
|
||||
var _geo = require("../util/geo");
|
||||
|
||||
var _util = require("@antv/util");
|
||||
|
||||
var _index = require("../map/index");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var Source =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Source, _Base);
|
||||
|
||||
_createClass(Source, [{
|
||||
key: "getDefaultCfg",
|
||||
value: function getDefaultCfg() {
|
||||
return {
|
||||
data: null,
|
||||
defs: {},
|
||||
parser: {},
|
||||
transforms: [],
|
||||
scaledefs: {},
|
||||
scales: {},
|
||||
options: {}
|
||||
};
|
||||
}
|
||||
}]);
|
||||
|
||||
function Source(cfg) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, Source);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Source).call(this, cfg));
|
||||
|
||||
var transform = _this.get('transforms');
|
||||
|
||||
_this._transforms = transform || [];
|
||||
var mapType = _this.get('mapType') || 'AMap';
|
||||
_this.projectFlat = (0, _index.getMap)(mapType).project; // 数据解析
|
||||
|
||||
_this._init();
|
||||
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(Source, [{
|
||||
key: "_init",
|
||||
value: function _init() {
|
||||
this._excuteParser();
|
||||
|
||||
var isCluster = this.get('isCluster') || false;
|
||||
isCluster && this._executeCluster(); // 数据转换 统计,聚合,分类
|
||||
|
||||
this._executeTrans(); // 坐标转换
|
||||
|
||||
|
||||
if (!this.get('projected')) {
|
||||
this._projectCoords();
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "setData",
|
||||
value: function setData(data) {
|
||||
var cfg = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
||||
Object.assign(this._attrs, cfg);
|
||||
var transform = this.get('transforms');
|
||||
this._transforms = transform || [];
|
||||
this.set('data', data);
|
||||
|
||||
this._init();
|
||||
} // 数据更新
|
||||
|
||||
}, {
|
||||
key: "updateTransfrom",
|
||||
value: function updateTransfrom(cfg) {
|
||||
var transforms = cfg.transforms;
|
||||
this._transforms = transforms;
|
||||
this.data = (0, _util.clone)(this.originData);
|
||||
|
||||
this._executeTrans();
|
||||
|
||||
this._projectCoords();
|
||||
}
|
||||
}, {
|
||||
key: "_excuteParser",
|
||||
value: function _excuteParser() {
|
||||
var parser = this.get('parser');
|
||||
var _parser$type = parser.type,
|
||||
type = _parser$type === void 0 ? 'geojson' : _parser$type;
|
||||
var data = this.get('data');
|
||||
this.originData = (0, _source.getParser)(type)(data, parser); // this.data = {
|
||||
// dataArray: clone(this.originData.dataArray)
|
||||
// }; // TODO 关闭数据备份
|
||||
|
||||
this.data = this.originData;
|
||||
|
||||
if (this.data !== null && !this.get('projected')) {
|
||||
this.data.extent = (0, _geo.extent)(this.data.dataArray);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 数据统计
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: "_executeTrans",
|
||||
value: function _executeTrans() {
|
||||
var _this2 = this;
|
||||
|
||||
var trans = this._transforms;
|
||||
trans.forEach(function (tran) {
|
||||
var type = tran.type;
|
||||
var data = (0, _source.getTransform)(type)(_this2.data, tran);
|
||||
Object.assign(_this2.data, data);
|
||||
});
|
||||
this._transforms = trans;
|
||||
}
|
||||
}, {
|
||||
key: "transform",
|
||||
value: function transform(option) {
|
||||
var data = (0, _source.getTransform)(option.type)(this.data, option);
|
||||
Object.assign(this.data, data);
|
||||
}
|
||||
}, {
|
||||
key: "_executeCluster",
|
||||
value: function _executeCluster() {
|
||||
var clusterCfg = this.get('Cluster') || {};
|
||||
var zoom = this.get('zoom');
|
||||
clusterCfg.zoom = Math.floor(zoom);
|
||||
this.set('cluster', clusterCfg);
|
||||
var clusterData = (0, _cluster.cluster)(this.data, clusterCfg);
|
||||
this.data = clusterData.data;
|
||||
this.pointIndex = clusterData.pointIndex;
|
||||
}
|
||||
}, {
|
||||
key: "updateCusterData",
|
||||
value: function updateCusterData(zoom, bbox) {
|
||||
var clusterPoint = this.pointIndex.getClusters(bbox, zoom);
|
||||
this.data.dataArray = (0, _cluster.formatData)(clusterPoint);
|
||||
var clusterCfg = this.get('Cluster') || {};
|
||||
clusterCfg.zoom = Math.floor(zoom);
|
||||
clusterCfg.bbox = bbox;
|
||||
this.set('cluster', clusterCfg);
|
||||
|
||||
this._projectCoords();
|
||||
}
|
||||
}, {
|
||||
key: "_projectCoords",
|
||||
value: function _projectCoords() {
|
||||
var _this3 = this;
|
||||
|
||||
if (this.data === null) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.data.dataArray.forEach(function (data) {
|
||||
// data.coordinates = this._coordProject(data.coordinates);
|
||||
data.coordinates = (0, _geo.tranfrormCoord)(data.coordinates, _this3._coorConvert.bind(_this3));
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_getCoord",
|
||||
value: function _getCoord(geo) {
|
||||
if (geo.geometry) {
|
||||
// GeoJSON feature
|
||||
geo = geo.geometry.coordinates;
|
||||
} else if (geo.coordinates) {
|
||||
// GeoJSON geometry
|
||||
geo = geo.coordinates;
|
||||
}
|
||||
|
||||
return geo;
|
||||
}
|
||||
}, {
|
||||
key: "_coordProject",
|
||||
value: function _coordProject(geo) {
|
||||
var _this4 = this;
|
||||
|
||||
if (Array.isArray(geo[0][0])) {
|
||||
return geo.map(function (coor) {
|
||||
return _this4._coordProject(coor);
|
||||
});
|
||||
}
|
||||
|
||||
if (!Array.isArray(geo[0])) {
|
||||
return this._coorConvert(geo);
|
||||
}
|
||||
|
||||
return geo.map(function (coor) {
|
||||
return _this4._coorConvert(coor);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_coorConvert",
|
||||
value: function _coorConvert(geo) {
|
||||
var ll = this.projectFlat(geo);
|
||||
return [ll.x, ll.y, geo[2] || 0];
|
||||
}
|
||||
}, {
|
||||
key: "getSelectFeature",
|
||||
value: function getSelectFeature(featureId) {
|
||||
var data = this.get('data'); // 如果是GeoJSON 数据返回原数
|
||||
// 颜色编码从1开始,要素索引从0开始,所以颜色转变要素需要减1
|
||||
|
||||
var isCluster = this.get('isCluster') || false;
|
||||
return data.features && !isCluster ? data.features[featureId - 1] : this.data.dataArray[featureId - 1];
|
||||
}
|
||||
}, {
|
||||
key: "getSeletFeatureIndex",
|
||||
value: function getSeletFeatureIndex(featureId) {
|
||||
var data = this.get('data');
|
||||
|
||||
if (!data.features) {
|
||||
return featureId - 1;
|
||||
}
|
||||
|
||||
var featureIndex = 0;
|
||||
|
||||
for (var i = 0; i < this.data.dataArray.length; i++) {
|
||||
var item = this.data.dataArray[i];
|
||||
|
||||
if (item._id === featureId) {
|
||||
break;
|
||||
}
|
||||
|
||||
featureIndex++;
|
||||
}
|
||||
|
||||
return featureIndex;
|
||||
}
|
||||
}, {
|
||||
key: "destroy",
|
||||
value: function destroy() {
|
||||
this.data = null;
|
||||
this.originData = null;
|
||||
}
|
||||
}]);
|
||||
|
||||
return Source;
|
||||
}(_base["default"]);
|
||||
|
||||
exports["default"] = Source;
|
|
@ -1,154 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _base = _interopRequireDefault(require("../core/base"));
|
||||
|
||||
var _worker_pool = _interopRequireDefault(require("../worker/worker_pool"));
|
||||
|
||||
var _throttle = _interopRequireDefault(require("../util/throttle"));
|
||||
|
||||
var _source_cache = _interopRequireDefault(require("../source/source_cache"));
|
||||
|
||||
var _worker_controller = _interopRequireDefault(require("../worker/worker_controller"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
// 统一管理所有的Source
|
||||
// 统一管理地图样式
|
||||
var Style =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(Style, _Base);
|
||||
|
||||
function Style(scene, cfg) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, Style);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(Style).call(this, cfg));
|
||||
_this.scene = scene;
|
||||
_this._sourceCaches = {};
|
||||
_this.WorkerPool = new _worker_pool["default"]();
|
||||
_this._tileMap = {};
|
||||
_this.WorkerController = new _worker_controller["default"](_this.WorkerPool, _assertThisInitialized(_this));
|
||||
_this.layerStyles = {};
|
||||
_this.layers = [];
|
||||
|
||||
_this.addMapEvent();
|
||||
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(Style, [{
|
||||
key: "addSource",
|
||||
value: function addSource(id, sourceCfg) {
|
||||
if (this._sourceCaches[id] !== undefined) {
|
||||
throw new Error('SourceID 已存在');
|
||||
}
|
||||
|
||||
sourceCfg.sourceID = id;
|
||||
this._sourceCaches[id] = new _source_cache["default"](this.scene, sourceCfg);
|
||||
}
|
||||
}, {
|
||||
key: "getSource",
|
||||
value: function getSource(id) {
|
||||
return this._sourceCaches[id];
|
||||
}
|
||||
}, {
|
||||
key: "addLayer",
|
||||
value: function addLayer(layer) {
|
||||
var id = layer.layerId;
|
||||
this.layers[id] = layer;
|
||||
} // 设置
|
||||
|
||||
}, {
|
||||
key: "_addTileStyle",
|
||||
value: function _addTileStyle(layerCfg) {
|
||||
var layerid = layerCfg.layerId;
|
||||
this.layerStyles[layerid] = layerCfg;
|
||||
|
||||
this._layerStyleGroupBySourceID();
|
||||
|
||||
this.WorkerController.broadcast('setLayers', this.layerStyles); // TODO 更新 style
|
||||
}
|
||||
}, {
|
||||
key: "removeTileStyle",
|
||||
value: function removeTileStyle(id) {
|
||||
delete this.layerStyles[id];
|
||||
|
||||
this._layerStyleGroupBySourceID();
|
||||
}
|
||||
}, {
|
||||
key: "_layerStyleGroupBySourceID",
|
||||
value: function _layerStyleGroupBySourceID() {
|
||||
var sourceStyles = []; // 支持VectorLayer
|
||||
|
||||
for (var layerId in this.layerStyles) {
|
||||
var sourceID = this.layerStyles[layerId].sourceOption.id;
|
||||
var sourcelayer = this.layerStyles[layerId].sourceOption.parser.sourceLayer;
|
||||
if (!sourceStyles[sourceID]) sourceStyles[sourceID] = {};
|
||||
if (!sourceStyles[sourceID][sourcelayer]) sourceStyles[sourceID][sourcelayer] = [];
|
||||
sourceStyles[sourceID][sourcelayer].push(this.layerStyles[layerId]);
|
||||
}
|
||||
|
||||
this.sourceStyles = sourceStyles;
|
||||
}
|
||||
}, {
|
||||
key: "update",
|
||||
value: function update(parameters) {
|
||||
this._addTileStyle(parameters);
|
||||
|
||||
for (var key in this._sourceCaches) {
|
||||
this._sourceCaches[key].update(this.layers, this.sourceStyles[key]);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "addMapEvent",
|
||||
value: function addMapEvent() {
|
||||
var _this2 = this;
|
||||
|
||||
this.mapEventHander = (0, _throttle["default"])(function () {
|
||||
requestAnimationFrame(function () {
|
||||
for (var key in _this2._sourceCaches) {
|
||||
_this2._sourceCaches[key].update(_this2.layers, _this2.sourceStyles[key]);
|
||||
}
|
||||
});
|
||||
}, 200);
|
||||
this.scene.map.on('zoomchange', this.mapEventHander);
|
||||
this.scene.map.on('dragend', this.mapEventHander);
|
||||
}
|
||||
}, {
|
||||
key: "clearMapEvent",
|
||||
value: function clearMapEvent() {
|
||||
this.scene.map.off('zoomchange', this.mapEventHander);
|
||||
this.scene.map.off('dragend', this.mapEventHander);
|
||||
} // 计算视野内的瓦片坐标
|
||||
|
||||
}]);
|
||||
|
||||
return Style;
|
||||
}(_base["default"]);
|
||||
|
||||
exports["default"] = Style;
|
|
@ -1,362 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
var _exportNames = {
|
||||
Float32BufferAttribute: true,
|
||||
Float64BufferAttribute: true,
|
||||
Uint32BufferAttribute: true,
|
||||
Int32BufferAttribute: true,
|
||||
Uint16BufferAttribute: true,
|
||||
Int16BufferAttribute: true,
|
||||
Uint8ClampedBufferAttribute: true,
|
||||
Uint8BufferAttribute: true,
|
||||
Int8BufferAttribute: true,
|
||||
BufferAttribute: true,
|
||||
Scene: true,
|
||||
WebGLRenderer: true,
|
||||
CanvasTexture: true,
|
||||
Object3D: true,
|
||||
Group: true,
|
||||
Clock: true,
|
||||
Points: true,
|
||||
LineSegments: true,
|
||||
Mesh: true,
|
||||
Texture: true,
|
||||
WebGLRenderTarget: true,
|
||||
PerspectiveCamera: true,
|
||||
OrthographicCamera: true,
|
||||
BufferGeometry: true,
|
||||
InstancedBufferGeometry: true,
|
||||
PlaneBufferGeometry: true,
|
||||
BoxBufferGeometry: true,
|
||||
Raycaster: true,
|
||||
UniformsUtils: true,
|
||||
Matrix4: true,
|
||||
Matrix3: true,
|
||||
Line: true,
|
||||
Vector4: true,
|
||||
Vector3: true,
|
||||
Vector2: true,
|
||||
ShaderMaterial: true,
|
||||
DataTexture: true,
|
||||
Color: true,
|
||||
InstancedBufferAttribute: true
|
||||
};
|
||||
exports.Float32BufferAttribute = Float32BufferAttribute;
|
||||
Object.defineProperty(exports, "Float64BufferAttribute", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _BufferAttribute.Float64BufferAttribute;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Uint32BufferAttribute", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _BufferAttribute.Uint32BufferAttribute;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Int32BufferAttribute", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _BufferAttribute.Int32BufferAttribute;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Uint16BufferAttribute", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _BufferAttribute.Uint16BufferAttribute;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Int16BufferAttribute", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _BufferAttribute.Int16BufferAttribute;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Uint8ClampedBufferAttribute", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _BufferAttribute.Uint8ClampedBufferAttribute;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Uint8BufferAttribute", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _BufferAttribute.Uint8BufferAttribute;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Int8BufferAttribute", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _BufferAttribute.Int8BufferAttribute;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "BufferAttribute", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _BufferAttribute.BufferAttribute;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Scene", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _Scene.Scene;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "WebGLRenderer", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _WebGLRenderer.WebGLRenderer;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "CanvasTexture", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _CanvasTexture.CanvasTexture;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Object3D", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _Object3D.Object3D;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Group", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _Group.Group;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Clock", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _Clock.Clock;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Points", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _Points.Points;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "LineSegments", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _LineSegments.LineSegments;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Mesh", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _Mesh.Mesh;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Texture", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _Texture.Texture;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "WebGLRenderTarget", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _WebGLRenderTarget.WebGLRenderTarget;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "PerspectiveCamera", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _PerspectiveCamera.PerspectiveCamera;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "OrthographicCamera", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _OrthographicCamera.OrthographicCamera;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "BufferGeometry", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _BufferGeometry.BufferGeometry;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "InstancedBufferGeometry", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _InstancedBufferGeometry.InstancedBufferGeometry;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "PlaneBufferGeometry", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _PlaneGeometry.PlaneBufferGeometry;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "BoxBufferGeometry", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _BoxGeometry.BoxBufferGeometry;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Raycaster", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _Raycaster.Raycaster;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "UniformsUtils", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _UniformsUtils.UniformsUtils;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Matrix4", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _Matrix.Matrix4;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Matrix3", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _Matrix2.Matrix3;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Line", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _Line.Line;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Vector4", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _Vector.Vector4;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Vector3", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _Vector2.Vector3;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Vector2", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _Vector3.Vector2;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "ShaderMaterial", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _ShaderMaterial.ShaderMaterial;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "DataTexture", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _DataTexture.DataTexture;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "Color", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _Color.Color;
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "InstancedBufferAttribute", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _InstancedBufferAttribute.InstancedBufferAttribute;
|
||||
}
|
||||
});
|
||||
|
||||
require("three/src/polyfills.js");
|
||||
|
||||
var _BufferAttribute = require("three/src/core/BufferAttribute.js");
|
||||
|
||||
var _constants = require("three/src/constants.js");
|
||||
|
||||
Object.keys(_constants).forEach(function (key) {
|
||||
if (key === "default" || key === "__esModule") return;
|
||||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
||||
Object.defineProperty(exports, key, {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _constants[key];
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var _Scene = require("three/src/scenes/Scene.js");
|
||||
|
||||
var _WebGLRenderer = require("three/src/renderers/WebGLRenderer.js");
|
||||
|
||||
var _CanvasTexture = require("three/src/textures/CanvasTexture.js");
|
||||
|
||||
var _Object3D = require("three/src/core/Object3D.js");
|
||||
|
||||
var _Group = require("three/src/objects/Group");
|
||||
|
||||
var _Clock = require("three/src/core/Clock");
|
||||
|
||||
var _Points = require("three/src/objects/Points.js");
|
||||
|
||||
var _LineSegments = require("three/src/objects/LineSegments.js");
|
||||
|
||||
var _Mesh = require("three/src/objects/Mesh.js");
|
||||
|
||||
var _Texture = require("three/src/textures/Texture.js");
|
||||
|
||||
var _WebGLRenderTarget = require("three/src/renderers/WebGLRenderTarget.js");
|
||||
|
||||
var _PerspectiveCamera = require("three/src/cameras/PerspectiveCamera.js");
|
||||
|
||||
var _OrthographicCamera = require("three/src/cameras/OrthographicCamera.js");
|
||||
|
||||
var _BufferGeometry = require("three/src/core/BufferGeometry.js");
|
||||
|
||||
var _InstancedBufferGeometry = require("three/src/core/InstancedBufferGeometry");
|
||||
|
||||
var _PlaneGeometry = require("three/src/geometries/PlaneGeometry.js");
|
||||
|
||||
var _BoxGeometry = require("three/src/geometries/BoxGeometry.js");
|
||||
|
||||
var _Raycaster = require("three/src/core/Raycaster.js");
|
||||
|
||||
var _UniformsUtils = require("three/src/renderers/shaders/UniformsUtils.js");
|
||||
|
||||
var _Matrix = require("three/src/math/Matrix4.js");
|
||||
|
||||
var _Matrix2 = require("three/src/math/Matrix3.js");
|
||||
|
||||
var _Line = require("three/src/objects/Line.js");
|
||||
|
||||
var _Vector = require("three/src/math/Vector4.js");
|
||||
|
||||
var _Vector2 = require("three/src/math/Vector3.js");
|
||||
|
||||
var _Vector3 = require("three/src/math/Vector2.js");
|
||||
|
||||
var _ShaderMaterial = require("three/src/materials/ShaderMaterial.js");
|
||||
|
||||
var _DataTexture = require("three/src/textures/DataTexture.js");
|
||||
|
||||
var _Color = require("three/src/math/Color.js");
|
||||
|
||||
var _InstancedBufferAttribute = require("three/src/core/InstancedBufferAttribute");
|
||||
|
||||
// export * from '../../build/three.js';
|
||||
function Float32BufferAttribute(array, itemSize, normalized) {
|
||||
if (Array.isArray(array)) {
|
||||
array = new Float32Array(array);
|
||||
}
|
||||
|
||||
_BufferAttribute.BufferAttribute.call(this, array, itemSize, normalized);
|
||||
}
|
||||
|
||||
Float32BufferAttribute.prototype = Object.create(_BufferAttribute.BufferAttribute.prototype);
|
||||
Float32BufferAttribute.prototype.constructor = Float32BufferAttribute;
|
|
@ -1,94 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
var WorkerPool =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function WorkerPool(workerCount) {
|
||||
_classCallCheck(this, WorkerPool);
|
||||
|
||||
this.workerCount = workerCount || Math.max(Math.floor(window.navigator.hardwareConcurrency / 2), 1);
|
||||
this.workers = []; // worker线程池
|
||||
|
||||
this.workerQueue = []; // 任务队列
|
||||
|
||||
this._initWorker(); // 初始化线程池
|
||||
|
||||
}
|
||||
|
||||
_createClass(WorkerPool, [{
|
||||
key: "_initWorker",
|
||||
value: function _initWorker() {
|
||||
while (this.workers.length < this.workerCount) {
|
||||
this.workers.push(new Worker());
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "runTask",
|
||||
value: function runTask(payload) {
|
||||
var _this = this;
|
||||
|
||||
return new Promise(function (resolve, reject) {
|
||||
if (_this.workers.length > 0) {
|
||||
var worker = _this.workers.shift(); // 从线程池取出一个worker
|
||||
|
||||
|
||||
worker.postMessage(payload); // 向线程发送数据
|
||||
|
||||
var workerCallback = function workerCallback(e) {
|
||||
resolve(e.data); // 成功则返回数据
|
||||
// 移除事件监听
|
||||
|
||||
worker.removeEventListener('message', workerCallback); // 重新放回线程池
|
||||
|
||||
_this.workers.push(worker); // 如果任务队列的数据还有则从任务队列继续取数据执行任务
|
||||
|
||||
|
||||
if (_this.workerQueue.length > 0) {
|
||||
var queueData = _this.workerQueue.shift();
|
||||
|
||||
_this.runTask(queueData.payload).then(function (data) {
|
||||
queueData.resolve(data);
|
||||
});
|
||||
}
|
||||
}; // 监听worker事件
|
||||
|
||||
|
||||
worker.addEventListener('message', workerCallback);
|
||||
worker.addEventListener('error', function (e) {
|
||||
reject('filename:' + e.filename + '\nmessage:' + e.message + '\nlineno:' + e.lineno);
|
||||
});
|
||||
} else {
|
||||
// 如果线程池都被占用,则将数据丢入任务队列,并保存对应的resolve和reject
|
||||
_this.workerQueue.push({
|
||||
payload: payload,
|
||||
resolve: resolve,
|
||||
reject: reject
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "release",
|
||||
value: function release() {
|
||||
this.workers.forEach(function (worker) {
|
||||
worker.terminate();
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return WorkerPool;
|
||||
}();
|
||||
|
||||
var _default = WorkerPool;
|
||||
exports["default"] = _default;
|
|
@ -1 +0,0 @@
|
|||
"use strict";
|
|
@ -1 +0,0 @@
|
|||
"use strict";
|
|
@ -1,92 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _rbush = _interopRequireDefault(require("rbush"));
|
||||
|
||||
var _bbox = _interopRequireDefault(require("@turf/bbox"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
||||
|
||||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
||||
|
||||
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
||||
|
||||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
var FeatureIndex =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function FeatureIndex(data) {
|
||||
var _this = this;
|
||||
|
||||
_classCallCheck(this, FeatureIndex);
|
||||
|
||||
this.tree = (0, _rbush["default"])();
|
||||
this.rawData = data;
|
||||
data.features.forEach(function (feature) {
|
||||
_this.insert(feature);
|
||||
});
|
||||
}
|
||||
|
||||
_createClass(FeatureIndex, [{
|
||||
key: "insert",
|
||||
value: function insert(feature) {
|
||||
var bbox = this.toBBox(feature);
|
||||
bbox.feature = feature;
|
||||
this.tree.insert(bbox);
|
||||
}
|
||||
}, {
|
||||
key: "search",
|
||||
value: function search(feature) {
|
||||
return this.tree.search(this.toBBox(feature));
|
||||
}
|
||||
}, {
|
||||
key: "clear",
|
||||
value: function clear() {
|
||||
this.tree.clear();
|
||||
}
|
||||
}, {
|
||||
key: "all",
|
||||
value: function all() {
|
||||
return this.tree.all();
|
||||
}
|
||||
}, {
|
||||
key: "toBBox",
|
||||
value: function toBBox(feature) {
|
||||
var bbox = feature.type === 'Point' ? this.pointBBox(feature) : (0, _bbox["default"])(feature);
|
||||
return {
|
||||
minX: bbox[0],
|
||||
minY: bbox[1],
|
||||
maxX: bbox[2],
|
||||
maxY: bbox[3]
|
||||
};
|
||||
}
|
||||
}, {
|
||||
key: "pointBBox",
|
||||
value: function pointBBox(feature) {
|
||||
var size = 1 / 1000 / 1000; // 1m
|
||||
|
||||
var _feature$geometry$coo = _slicedToArray(feature.geometry.coordinates, 2),
|
||||
x = _feature$geometry$coo[0],
|
||||
y = _feature$geometry$coo[1];
|
||||
|
||||
return [x - size, y - size, x + size, y + size];
|
||||
}
|
||||
}]);
|
||||
|
||||
return FeatureIndex;
|
||||
}();
|
||||
|
||||
exports["default"] = FeatureIndex;
|
|
@ -1 +0,0 @@
|
|||
"use strict";
|
|
@ -1 +0,0 @@
|
|||
"use strict";
|
|
@ -1,55 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.aProjectFlat = aProjectFlat;
|
||||
exports.unProjectFlat = unProjectFlat;
|
||||
|
||||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
||||
|
||||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
||||
|
||||
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
||||
|
||||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
||||
|
||||
function aProjectFlat(lnglat) {
|
||||
var maxs = 85.0511287798;
|
||||
var lat = Math.max(Math.min(maxs, lnglat[1]), -maxs);
|
||||
var scale = 256 << 20;
|
||||
var d = Math.PI / 180;
|
||||
var x = lnglat[0] * d;
|
||||
var y = lat * d;
|
||||
y = Math.log(Math.tan(Math.PI / 4 + y / 2));
|
||||
var a = 0.5 / Math.PI,
|
||||
b = 0.5,
|
||||
c = -0.5 / Math.PI;
|
||||
d = 0.5;
|
||||
x = scale * (a * x + b) - 215440491;
|
||||
y = scale * (c * y + d) - 106744817;
|
||||
return {
|
||||
x: parseInt(x),
|
||||
y: parseInt(y)
|
||||
};
|
||||
}
|
||||
|
||||
function unProjectFlat(px) {
|
||||
var a = 0.5 / Math.PI,
|
||||
b = 0.5,
|
||||
c = -0.5 / Math.PI;
|
||||
var d = 0.5;
|
||||
var scale = 256 << 20;
|
||||
|
||||
var _px = _slicedToArray(px, 2),
|
||||
x = _px[0],
|
||||
y = _px[1];
|
||||
|
||||
x = ((x + 215440491) / scale - b) / a;
|
||||
y = ((y + 106744817) / scale - d) / c;
|
||||
y = (Math.atan(Math.pow(Math.E, y)) - Math.PI / 4) * 2;
|
||||
d = Math.PI / 180;
|
||||
var lat = y / d;
|
||||
var lng = x / d;
|
||||
return [lng, lat];
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.shapeBae = exports.GeomBase = void 0;
|
||||
var GeomBase = {
|
||||
color: 'updateDraw',
|
||||
size: 'repaint',
|
||||
filter: 'updateDraw',
|
||||
layer: '',
|
||||
pickable: true,
|
||||
setLayer: function setLayer(layer) {
|
||||
this.layer = layer;
|
||||
this.style = layer.get('styleOption');
|
||||
},
|
||||
getShape: function getShape(type) {
|
||||
return type;
|
||||
},
|
||||
draw: function draw() {
|
||||
var shape = this.getShape();
|
||||
this.Mesh = shape.Mesh();
|
||||
},
|
||||
// 更新geometry buffer;
|
||||
updateDraw: function updateDraw() {},
|
||||
repaint: function repaint() {}
|
||||
};
|
||||
exports.GeomBase = GeomBase;
|
||||
var shapeBae = {
|
||||
geometryBuffer: function geometryBuffer() {},
|
||||
geometry: function geometry() {},
|
||||
material: function material() {},
|
||||
mesh: function mesh() {}
|
||||
};
|
||||
exports.shapeBae = shapeBae;
|
|
@ -1,241 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _base = _interopRequireDefault(require("../../core/base"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var BufferBase =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(BufferBase, _Base);
|
||||
|
||||
function BufferBase(cfg) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, BufferBase);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(BufferBase).call(this, cfg));
|
||||
_this.attributes = {};
|
||||
_this.verticesCount = 0;
|
||||
_this.indexCount = 0;
|
||||
_this.indexArray = new Int32Array(0);
|
||||
|
||||
_this._init();
|
||||
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(BufferBase, [{
|
||||
key: "_init",
|
||||
value: function _init() {
|
||||
this._calculateFeatures();
|
||||
|
||||
this._initAttributes();
|
||||
|
||||
this._buildFeatures();
|
||||
}
|
||||
}, {
|
||||
key: "_initAttributes",
|
||||
value: function _initAttributes() {
|
||||
this.attributes.positions = new Float32Array(this.verticesCount * 3);
|
||||
this.attributes.colors = new Float32Array(this.verticesCount * 4);
|
||||
this.attributes.pickingIds = new Float32Array(this.verticesCount);
|
||||
this.attributes.sizes = new Float32Array(this.verticesCount);
|
||||
this.attributes.pickingIds = new Float32Array(this.verticesCount);
|
||||
|
||||
if (this.get('uv')) {
|
||||
this.attributes.uv = new Float32Array(this.verticesCount * 2);
|
||||
}
|
||||
|
||||
this.indexArray = new Int32Array(this.indexCount);
|
||||
}
|
||||
}, {
|
||||
key: "addFeature",
|
||||
value: function addFeature() {} // 更新渲染
|
||||
|
||||
}, {
|
||||
key: "upload",
|
||||
value: function upload() {}
|
||||
}, {
|
||||
key: "destroy",
|
||||
value: function destroy() {}
|
||||
}, {
|
||||
key: "resize",
|
||||
value: function resize() {}
|
||||
}, {
|
||||
key: "checkIsClosed",
|
||||
value: function checkIsClosed(points) {
|
||||
var p1 = points[0][0];
|
||||
var p2 = points[0][points[0].length - 1];
|
||||
return p1[0] === p2[0] && p1[1] === p2[1];
|
||||
}
|
||||
}, {
|
||||
key: "concat",
|
||||
value: function concat(arrayType, arrays) {
|
||||
var totalLength = 0;
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = arrays[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var arr = _step.value;
|
||||
totalLength += arr.length;
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
||||
_iterator["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var arrayBuffer = new ArrayBuffer(totalLength * arrayType.BYTES_PER_ELEMENT);
|
||||
var offset = 0;
|
||||
var result = new arrayType(arrayBuffer);
|
||||
var _iteratorNormalCompletion2 = true;
|
||||
var _didIteratorError2 = false;
|
||||
var _iteratorError2 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator2 = arrays[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
||||
var _arr = _step2.value;
|
||||
result.set(_arr, offset);
|
||||
offset += _arr.length;
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError2 = true;
|
||||
_iteratorError2 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
|
||||
_iterator2["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError2) {
|
||||
throw _iteratorError2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}, {
|
||||
key: "_encodeArray",
|
||||
value: function _encodeArray(feature, num) {
|
||||
var color = feature.color,
|
||||
id = feature.id,
|
||||
pattern = feature.pattern,
|
||||
size = feature.size;
|
||||
var verticesOffset = feature.bufferInfo.verticesOffset;
|
||||
var imagePos = this.get('imagePos');
|
||||
var start1 = verticesOffset;
|
||||
|
||||
for (var i = 0; i < num; i++) {
|
||||
if (feature.hasOwnProperty('color')) {
|
||||
this.attributes.colors[start1 * 4 + i * 4] = color[0];
|
||||
this.attributes.colors[start1 * 4 + i * 4 + 1] = color[1];
|
||||
this.attributes.colors[start1 * 4 + i * 4 + 2] = color[2];
|
||||
this.attributes.colors[start1 * 4 + i * 4 + 3] = color[3];
|
||||
}
|
||||
|
||||
if (feature.hasOwnProperty('id')) {
|
||||
this.attributes.pickingIds[start1 + i] = id;
|
||||
}
|
||||
|
||||
if (feature.hasOwnProperty('size')) {
|
||||
var size2 = size;
|
||||
|
||||
if (Array.isArray(size) && size.length === 2) {
|
||||
size2 = [size[0]];
|
||||
}
|
||||
|
||||
if (!Array.isArray(size)) {
|
||||
size2 = [size];
|
||||
}
|
||||
|
||||
this.attributes.sizes.set(size2, (start1 + i) * size2.length);
|
||||
}
|
||||
|
||||
if (feature.hasOwnProperty('pattern')) {
|
||||
var patternPos = imagePos[pattern] || {
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
this.attributes.patterns[start1 * 2 + i * 2] = patternPos.x;
|
||||
this.attributes.patterns[start1 * 2 + i * 2 + 1] = patternPos.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "_calculateWall",
|
||||
value: function _calculateWall(feature) {
|
||||
var size = feature.size;
|
||||
var _feature$bufferInfo = feature.bufferInfo,
|
||||
vertices = _feature$bufferInfo.vertices,
|
||||
indexOffset = _feature$bufferInfo.indexOffset,
|
||||
verticesOffset = _feature$bufferInfo.verticesOffset,
|
||||
faceNum = _feature$bufferInfo.faceNum;
|
||||
|
||||
this._encodeArray(feature, faceNum * 4);
|
||||
|
||||
for (var i = 0; i < faceNum; i++) {
|
||||
var prePoint = vertices.slice(i * 3, i * 3 + 3);
|
||||
var nextPoint = vertices.slice(i * 3 + 3, i * 3 + 6);
|
||||
|
||||
this._calculateExtrudeFace(prePoint, nextPoint, verticesOffset + i * 4, indexOffset + i * 6, size);
|
||||
|
||||
feature.bufferInfo.verticesOffset += 4;
|
||||
feature.bufferInfo.indexOffset += 6;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "_calculateExtrudeFace",
|
||||
value: function _calculateExtrudeFace(prePoint, nextPoint, positionOffset, indexOffset, size) {
|
||||
this.attributes.positions.set([prePoint[0], prePoint[1], size, nextPoint[0], nextPoint[1], size, prePoint[0], prePoint[1], 0, nextPoint[0], nextPoint[1], 0], positionOffset * 3);
|
||||
var indexArray = [1, 2, 0, 3, 2, 1].map(function (v) {
|
||||
return v + positionOffset;
|
||||
});
|
||||
|
||||
if (this.get('uv')) {
|
||||
this.attributes.uv.set([0.1, 0, 0, 0, 0.1, size / 2000, 0, size / 2000], positionOffset * 2);
|
||||
}
|
||||
|
||||
this.indexArray.set(indexArray, indexOffset);
|
||||
}
|
||||
}]);
|
||||
|
||||
return BufferBase;
|
||||
}(_base["default"]);
|
||||
|
||||
exports["default"] = BufferBase;
|
|
@ -1,431 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _base = _interopRequireDefault(require("../../core/base"));
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../../core/three"));
|
||||
|
||||
var _normals2 = require("../normals");
|
||||
|
||||
var _extrude2 = _interopRequireDefault(require("../extrude"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var BufferBase =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(BufferBase, _Base);
|
||||
|
||||
function BufferBase(cfg) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, BufferBase);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(BufferBase).call(this, cfg));
|
||||
_this.bufferStruct = {};
|
||||
|
||||
_this.geometryBuffer();
|
||||
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(BufferBase, [{
|
||||
key: "geometryBuffer",
|
||||
value: function geometryBuffer() {}
|
||||
}, {
|
||||
key: "_normals",
|
||||
value: function _normals() {
|
||||
var _this$bufferStruct = this.bufferStruct,
|
||||
position = _this$bufferStruct.position,
|
||||
indices = _this$bufferStruct.indices,
|
||||
_this$bufferStruct$no = _this$bufferStruct.normals,
|
||||
normals = _this$bufferStruct$no === void 0 ? [] : _this$bufferStruct$no;
|
||||
indices.forEach(function (index, i) {
|
||||
normals.push((0, _normals2.faceNormals)(index, position[i]));
|
||||
});
|
||||
this.bufferStruct.normals = normals;
|
||||
}
|
||||
}, {
|
||||
key: "_extrude",
|
||||
value: function _extrude(coordinate, heightValue) {
|
||||
var extrudeData = (0, _extrude2["default"])(coordinate, heightValue);
|
||||
return extrudeData;
|
||||
}
|
||||
}, {
|
||||
key: "_mergeAttributes",
|
||||
value: function _mergeAttributes(attributes) {
|
||||
var lengths = {}; // Find array lengths
|
||||
|
||||
attributes.forEach(function (_attributes) {
|
||||
for (var k in _attributes) {
|
||||
if (!lengths[k]) {
|
||||
lengths[k] = 0;
|
||||
}
|
||||
|
||||
lengths[k] += _attributes[k].length;
|
||||
}
|
||||
});
|
||||
var mergedAttributes = {}; // Set up arrays to merge into
|
||||
|
||||
for (var k in lengths) {
|
||||
mergedAttributes[k] = new Float32Array(lengths[k]);
|
||||
}
|
||||
|
||||
var lastLengths = {};
|
||||
attributes.forEach(function (_attributes) {
|
||||
for (var _k in _attributes) {
|
||||
if (!lastLengths[_k]) {
|
||||
lastLengths[_k] = 0;
|
||||
}
|
||||
|
||||
mergedAttributes[_k].set(_attributes[_k], lastLengths[_k]);
|
||||
|
||||
lastLengths[_k] += _attributes[_k].length;
|
||||
}
|
||||
});
|
||||
return mergedAttributes;
|
||||
}
|
||||
}, {
|
||||
key: "_toPolygonAttributes",
|
||||
value: function _toPolygonAttributes(polygon) {
|
||||
// Three components per vertex per face (3 x 3 = 9)
|
||||
var style = polygon.style,
|
||||
indices = polygon.indices,
|
||||
position = polygon.position,
|
||||
indexCount = polygon.indexCount;
|
||||
var vertices = new Float32Array(indexCount * 3);
|
||||
var normals = new Float32Array(indexCount * 3);
|
||||
var colors = new Float32Array(indexCount * 4);
|
||||
var pickingIds = new Float32Array(indexCount);
|
||||
var pA = new THREE.Vector3();
|
||||
var pB = new THREE.Vector3();
|
||||
var pC = new THREE.Vector3();
|
||||
var cb = new THREE.Vector3();
|
||||
var ab = new THREE.Vector3();
|
||||
var lastIndex = 0;
|
||||
indices.forEach(function (indice, pIndex) {
|
||||
for (var i = 0; i < indice.length / 3; i++) {
|
||||
var index = indice[i * 3];
|
||||
var color = style[pIndex].color;
|
||||
var _pickingId = style[pIndex].id;
|
||||
var ax = position[pIndex][index][0];
|
||||
var ay = position[pIndex][index][1];
|
||||
var az = position[pIndex][index][2];
|
||||
index = indice[i * 3 + 1];
|
||||
var bx = position[pIndex][index][0];
|
||||
var by = position[pIndex][index][1];
|
||||
var bz = position[pIndex][index][2];
|
||||
index = indice[i * 3 + 2];
|
||||
var cx = position[pIndex][index][0];
|
||||
var cy = position[pIndex][index][1];
|
||||
var cz = position[pIndex][index][2];
|
||||
pA.set(ax, ay, az);
|
||||
pB.set(bx, by, bz);
|
||||
pC.set(cx, cy, cz);
|
||||
cb.subVectors(pC, pB);
|
||||
ab.subVectors(pA, pB);
|
||||
cb.cross(ab);
|
||||
cb.normalize();
|
||||
var nx = cb.x;
|
||||
var ny = cb.y;
|
||||
var nz = cb.z;
|
||||
vertices[lastIndex * 9 + 0] = ax;
|
||||
vertices[lastIndex * 9 + 1] = ay;
|
||||
vertices[lastIndex * 9 + 2] = az;
|
||||
normals[lastIndex * 9 + 0] = nx;
|
||||
normals[lastIndex * 9 + 1] = ny;
|
||||
normals[lastIndex * 9 + 2] = nz;
|
||||
colors[lastIndex * 12 + 0] = color[0];
|
||||
colors[lastIndex * 12 + 1] = color[1];
|
||||
colors[lastIndex * 12 + 2] = color[2];
|
||||
colors[lastIndex * 12 + 3] = color[3];
|
||||
vertices[lastIndex * 9 + 3] = bx;
|
||||
vertices[lastIndex * 9 + 4] = by;
|
||||
vertices[lastIndex * 9 + 5] = bz;
|
||||
normals[lastIndex * 9 + 3] = nx;
|
||||
normals[lastIndex * 9 + 4] = ny;
|
||||
normals[lastIndex * 9 + 5] = nz;
|
||||
colors[lastIndex * 12 + 4] = color[0];
|
||||
colors[lastIndex * 12 + 5] = color[1];
|
||||
colors[lastIndex * 12 + 6] = color[2];
|
||||
colors[lastIndex * 12 + 7] = color[3];
|
||||
vertices[lastIndex * 9 + 6] = cx;
|
||||
vertices[lastIndex * 9 + 7] = cy;
|
||||
vertices[lastIndex * 9 + 8] = cz;
|
||||
normals[lastIndex * 9 + 6] = nx;
|
||||
normals[lastIndex * 9 + 7] = ny;
|
||||
normals[lastIndex * 9 + 8] = nz;
|
||||
colors[lastIndex * 12 + 8] = color[0];
|
||||
colors[lastIndex * 12 + 9] = color[1];
|
||||
colors[lastIndex * 12 + 10] = color[2];
|
||||
colors[lastIndex * 12 + 11] = color[3];
|
||||
pickingIds[lastIndex * 3 + 0] = _pickingId;
|
||||
pickingIds[lastIndex * 3 + 1] = _pickingId;
|
||||
pickingIds[lastIndex * 3 + 2] = _pickingId;
|
||||
lastIndex++;
|
||||
}
|
||||
});
|
||||
var attributes = {
|
||||
vertices: vertices,
|
||||
normals: normals,
|
||||
colors: colors,
|
||||
pickingIds: pickingIds,
|
||||
faceUv: new Float32Array(polygon.faceUv),
|
||||
sizes: new Float32Array(polygon.sizes)
|
||||
};
|
||||
return attributes;
|
||||
}
|
||||
}, {
|
||||
key: "_toPointShapeAttributes",
|
||||
value: function _toPointShapeAttributes(polygon) {
|
||||
// Three components per vertex per face (3 x 3 = 9)
|
||||
var style = polygon.style,
|
||||
indices = polygon.indices,
|
||||
position = polygon.position,
|
||||
indexCount = polygon.indexCount,
|
||||
shapes = polygon.shapes,
|
||||
sizes = polygon.sizes;
|
||||
var vertices = new Float32Array(indexCount * 3);
|
||||
var shapePositions = new Float32Array(indexCount * 3);
|
||||
var a_size = new Float32Array(indexCount * 3);
|
||||
var normals = new Float32Array(indexCount * 3);
|
||||
var colors = new Float32Array(indexCount * 4);
|
||||
var pickingIds = new Float32Array(indexCount);
|
||||
var pA = new THREE.Vector3();
|
||||
var pB = new THREE.Vector3();
|
||||
var pC = new THREE.Vector3();
|
||||
var cb = new THREE.Vector3();
|
||||
var ab = new THREE.Vector3();
|
||||
var lastIndex = 0;
|
||||
indices.forEach(function (indice, pIndex) {
|
||||
for (var i = 0; i < indice.length / 3; i++) {
|
||||
var index = indice[i * 3];
|
||||
var color = style[pIndex].color;
|
||||
var coor1 = position[pIndex];
|
||||
var size = sizes[pIndex];
|
||||
var _pickingId = style[pIndex].id;
|
||||
var ax = shapes[pIndex][index][0];
|
||||
var ay = shapes[pIndex][index][1];
|
||||
var az = shapes[pIndex][index][2];
|
||||
index = indice[i * 3 + 1];
|
||||
var bx = shapes[pIndex][index][0];
|
||||
var by = shapes[pIndex][index][1];
|
||||
var bz = shapes[pIndex][index][2];
|
||||
index = indice[i * 3 + 2];
|
||||
var cx = shapes[pIndex][index][0];
|
||||
var cy = shapes[pIndex][index][1];
|
||||
var cz = shapes[pIndex][index][2];
|
||||
pA.set(ax, ay, az);
|
||||
pB.set(bx, by, bz);
|
||||
pC.set(cx, cy, cz);
|
||||
cb.subVectors(pC, pB);
|
||||
ab.subVectors(pA, pB);
|
||||
cb.cross(ab);
|
||||
cb.normalize();
|
||||
var nx = cb.x;
|
||||
var ny = cb.y;
|
||||
var nz = cb.z;
|
||||
vertices[lastIndex * 9 + 0] = coor1[0];
|
||||
vertices[lastIndex * 9 + 1] = coor1[1];
|
||||
vertices[lastIndex * 9 + 2] = coor1[2];
|
||||
shapePositions[lastIndex * 9 + 0] = ax;
|
||||
shapePositions[lastIndex * 9 + 1] = ay;
|
||||
shapePositions[lastIndex * 9 + 2] = az;
|
||||
a_size[lastIndex * 9 + 0] = size[0];
|
||||
a_size[lastIndex * 9 + 1] = size[1];
|
||||
a_size[lastIndex * 9 + 2] = size[2];
|
||||
normals[lastIndex * 9 + 0] = nx;
|
||||
normals[lastIndex * 9 + 1] = ny;
|
||||
normals[lastIndex * 9 + 2] = nz;
|
||||
colors[lastIndex * 12 + 0] = color[0];
|
||||
colors[lastIndex * 12 + 1] = color[1];
|
||||
colors[lastIndex * 12 + 2] = color[2];
|
||||
colors[lastIndex * 12 + 3] = color[3];
|
||||
vertices[lastIndex * 9 + 3] = coor1[0];
|
||||
vertices[lastIndex * 9 + 4] = coor1[1];
|
||||
vertices[lastIndex * 9 + 5] = coor1[2];
|
||||
shapePositions[lastIndex * 9 + 3] = bx;
|
||||
shapePositions[lastIndex * 9 + 4] = by;
|
||||
shapePositions[lastIndex * 9 + 5] = bz;
|
||||
a_size[lastIndex * 9 + 3] = size[0];
|
||||
a_size[lastIndex * 9 + 4] = size[1];
|
||||
a_size[lastIndex * 9 + 5] = size[2];
|
||||
normals[lastIndex * 9 + 3] = nx;
|
||||
normals[lastIndex * 9 + 4] = ny;
|
||||
normals[lastIndex * 9 + 5] = nz;
|
||||
colors[lastIndex * 12 + 4] = color[0];
|
||||
colors[lastIndex * 12 + 5] = color[1];
|
||||
colors[lastIndex * 12 + 6] = color[2];
|
||||
colors[lastIndex * 12 + 7] = color[3];
|
||||
vertices[lastIndex * 9 + 6] = coor1[0];
|
||||
vertices[lastIndex * 9 + 7] = coor1[1];
|
||||
vertices[lastIndex * 9 + 8] = coor1[2];
|
||||
a_size[lastIndex * 9 + 6] = size[0];
|
||||
a_size[lastIndex * 9 + 7] = size[1];
|
||||
a_size[lastIndex * 9 + 8] = size[2];
|
||||
shapePositions[lastIndex * 9 + 6] = cx;
|
||||
shapePositions[lastIndex * 9 + 7] = cy;
|
||||
shapePositions[lastIndex * 9 + 8] = cz;
|
||||
normals[lastIndex * 9 + 6] = nx;
|
||||
normals[lastIndex * 9 + 7] = ny;
|
||||
normals[lastIndex * 9 + 8] = nz;
|
||||
colors[lastIndex * 12 + 8] = color[0];
|
||||
colors[lastIndex * 12 + 9] = color[1];
|
||||
colors[lastIndex * 12 + 10] = color[2];
|
||||
colors[lastIndex * 12 + 11] = color[3];
|
||||
pickingIds[lastIndex * 3 + 0] = _pickingId;
|
||||
pickingIds[lastIndex * 3 + 1] = _pickingId;
|
||||
pickingIds[lastIndex * 3 + 2] = _pickingId;
|
||||
lastIndex++;
|
||||
}
|
||||
});
|
||||
var attributes = {
|
||||
vertices: vertices,
|
||||
normals: normals,
|
||||
colors: colors,
|
||||
pickingIds: pickingIds,
|
||||
shapePositions: shapePositions,
|
||||
a_size: a_size,
|
||||
faceUv: new Float32Array(polygon.faceUv)
|
||||
};
|
||||
return attributes;
|
||||
}
|
||||
}, {
|
||||
key: "_toPolygonLineAttributes",
|
||||
value: function _toPolygonLineAttributes(polygonline) {
|
||||
var style = polygonline.style,
|
||||
indices = polygonline.indices,
|
||||
position = polygonline.position,
|
||||
indexCount = polygonline.indexCount;
|
||||
var vertices = new Float32Array(indexCount * 3);
|
||||
var colors = new Float32Array(indexCount * 4);
|
||||
var pickingIds = new Float32Array(indexCount);
|
||||
var lastIndex = 0;
|
||||
indices.forEach(function (indice, pIndex) {
|
||||
for (var i = 0; i < indice.length; i++) {
|
||||
var index = indice[i];
|
||||
var color = style[pIndex].color;
|
||||
var _pickingId = style[pIndex].id;
|
||||
vertices[lastIndex * 3] = position[pIndex][index][0];
|
||||
vertices[lastIndex * 3 + 1] = position[pIndex][index][1];
|
||||
vertices[lastIndex * 3 + 2] = position[pIndex][index][2];
|
||||
colors[lastIndex * 4] = color[0];
|
||||
colors[lastIndex * 4 + 1] = color[1];
|
||||
colors[lastIndex * 4 + 2] = color[2];
|
||||
colors[lastIndex * 4 + 3] = color[3];
|
||||
pickingIds[lastIndex] = _pickingId;
|
||||
lastIndex++;
|
||||
}
|
||||
});
|
||||
var attributes = {
|
||||
vertices: vertices,
|
||||
colors: colors,
|
||||
pickingIds: pickingIds
|
||||
};
|
||||
return attributes;
|
||||
}
|
||||
}, {
|
||||
key: "_toPointsAttributes",
|
||||
value: function _toPointsAttributes(point) {
|
||||
var style = point.style,
|
||||
position = point.position;
|
||||
var count = position.length;
|
||||
var vertices = new Float32Array(count * 3);
|
||||
var colors = new Float32Array(count * 4);
|
||||
var sizes = new Float32Array(count);
|
||||
var shapes = new Float32Array(count);
|
||||
var pickingIds = new Float32Array(count);
|
||||
position.forEach(function (pos, index) {
|
||||
vertices[index * 3] = pos[0];
|
||||
vertices[index * 3 + 1] = pos[1];
|
||||
vertices[index * 3 + 2] = pos[2];
|
||||
colors[index * 4] = style[index].color[0];
|
||||
colors[index * 4 + 1] = style[index].color[1];
|
||||
colors[index * 4 + 2] = style[index].color[2];
|
||||
colors[index * 4 + 3] = style[index].color[3];
|
||||
pickingIds[index] = style[index].id;
|
||||
sizes[index] = style[index].size * window.devicePixelRatio;
|
||||
|
||||
if (style[index].shape) {
|
||||
shapes[index] = style[index].shape;
|
||||
}
|
||||
});
|
||||
var attributes = {
|
||||
vertices: vertices,
|
||||
colors: colors,
|
||||
sizes: sizes,
|
||||
shapes: shapes,
|
||||
pickingIds: pickingIds
|
||||
};
|
||||
return attributes;
|
||||
}
|
||||
}, {
|
||||
key: "_generateTexture",
|
||||
value: function _generateTexture() {
|
||||
// build a small canvas 32x64 and paint it in white
|
||||
var canvas = document.createElement('canvas');
|
||||
canvas.width = 32;
|
||||
canvas.height = 64;
|
||||
var context = canvas.getContext('2d'); // plain it in white
|
||||
|
||||
context.fillStyle = '#ffffff';
|
||||
context.fillRect(0, 0, 32, 64); // draw the window rows - with a small noise to simulate light variations in each room
|
||||
|
||||
for (var y = 8; y < 64; y += 8) {
|
||||
for (var x = 0; x < 32; x += 2) {
|
||||
var value = Math.floor(Math.random() * 64);
|
||||
context.fillStyle = 'rgb(' + [value, value, value].join(',') + ')';
|
||||
context.fillRect(x, y, 2, 4);
|
||||
}
|
||||
}
|
||||
|
||||
context.fillStyle = '#105CB3';
|
||||
context.fillRect(0, 60, 32, 64); // build a bigger canvas and copy the small one in it
|
||||
// This is a trick to upscale the texture without filtering
|
||||
|
||||
var canvas2 = document.createElement('canvas');
|
||||
canvas2.width = 512;
|
||||
canvas2.height = 1024;
|
||||
var context2 = canvas2.getContext('2d'); // disable smoothing
|
||||
|
||||
context2.imageSmoothingEnabled = false;
|
||||
context2.webkitImageSmoothingEnabled = false;
|
||||
context2.mozImageSmoothingEnabled = false; // then draw the image
|
||||
|
||||
context2.drawImage(canvas, 0, 0, canvas2.width, canvas2.height); // return the just built canvas2
|
||||
|
||||
var texture = new THREE.Texture(canvas2); // texture.anisotropy = renderer.getMaxAnisotropy();
|
||||
|
||||
texture.needsUpdate = true;
|
||||
return texture;
|
||||
}
|
||||
}]);
|
||||
|
||||
return BufferBase;
|
||||
}(_base["default"]);
|
||||
|
||||
exports["default"] = BufferBase;
|
|
@ -1,26 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.registerBuffer = exports.getBuffer = exports.Buffer_MAP = void 0;
|
||||
var Buffer_MAP = {};
|
||||
exports.Buffer_MAP = Buffer_MAP;
|
||||
|
||||
var getBuffer = function getBuffer(bufferType, shapeType) {
|
||||
return Buffer_MAP[bufferType.toLowerCase()] && Buffer_MAP[bufferType.toLowerCase()][shapeType.toLowerCase()];
|
||||
};
|
||||
|
||||
exports.getBuffer = getBuffer;
|
||||
|
||||
var registerBuffer = function registerBuffer(bufferType, shapeType, render) {
|
||||
if (getBuffer(bufferType, shapeType)) {
|
||||
throw new Error("Render shapeType '".concat(shapeType, "' existed."));
|
||||
} // 存储到 map 中
|
||||
|
||||
|
||||
if (!Buffer_MAP[bufferType.toLowerCase()]) Buffer_MAP[bufferType.toLowerCase()] = {};
|
||||
Buffer_MAP[bufferType.toLowerCase()][shapeType.toLowerCase()] = render;
|
||||
};
|
||||
|
||||
exports.registerBuffer = registerBuffer;
|
|
@ -1,70 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = gridBuffer;
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
||||
|
||||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
||||
|
||||
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
||||
|
||||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
||||
|
||||
function gridBuffer(layerData) {
|
||||
var attribute = {
|
||||
vertices: [],
|
||||
miter: [],
|
||||
colors: [],
|
||||
pickingIds: []
|
||||
};
|
||||
layerData.forEach(function (element) {
|
||||
var _attribute$colors, _attribute$colors2, _attribute$colors3, _attribute$colors4, _attribute$colors5, _attribute$colors6;
|
||||
|
||||
var color = element.color,
|
||||
id = element.id;
|
||||
|
||||
var _element$coordinates = _slicedToArray(element.coordinates, 3),
|
||||
x = _element$coordinates[0],
|
||||
y = _element$coordinates[1],
|
||||
z = _element$coordinates[2];
|
||||
|
||||
attribute.vertices.push(x, y, z);
|
||||
attribute.miter.push(-1, -1);
|
||||
attribute.vertices.push(x, y, z);
|
||||
attribute.miter.push(1, 1);
|
||||
attribute.vertices.push(x, y, z);
|
||||
attribute.miter.push(-1, 1);
|
||||
attribute.vertices.push(x, y, z);
|
||||
attribute.miter.push(-1, -1);
|
||||
attribute.vertices.push(x, y, z);
|
||||
attribute.miter.push(1, -1);
|
||||
attribute.vertices.push(x, y, z);
|
||||
attribute.miter.push(1, 1);
|
||||
|
||||
(_attribute$colors = attribute.colors).push.apply(_attribute$colors, _toConsumableArray(color));
|
||||
|
||||
(_attribute$colors2 = attribute.colors).push.apply(_attribute$colors2, _toConsumableArray(color));
|
||||
|
||||
(_attribute$colors3 = attribute.colors).push.apply(_attribute$colors3, _toConsumableArray(color));
|
||||
|
||||
(_attribute$colors4 = attribute.colors).push.apply(_attribute$colors4, _toConsumableArray(color));
|
||||
|
||||
(_attribute$colors5 = attribute.colors).push.apply(_attribute$colors5, _toConsumableArray(color));
|
||||
|
||||
(_attribute$colors6 = attribute.colors).push.apply(_attribute$colors6, _toConsumableArray(color));
|
||||
|
||||
attribute.pickingIds.push(id, id, id, id, id, id);
|
||||
});
|
||||
return attribute;
|
||||
}
|
|
@ -1,177 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _buffer = _interopRequireDefault(require("../buffer"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
||||
|
||||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
||||
|
||||
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
||||
|
||||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var Grid3D =
|
||||
/*#__PURE__*/
|
||||
function (_BufferBase) {
|
||||
_inherits(Grid3D, _BufferBase);
|
||||
|
||||
function Grid3D() {
|
||||
_classCallCheck(this, Grid3D);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(Grid3D).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(Grid3D, [{
|
||||
key: "_buildFeatures",
|
||||
value: function _buildFeatures() {
|
||||
var _this = this;
|
||||
|
||||
var layerData = this.get('layerData');
|
||||
this._offset = 0;
|
||||
var shapeType = this.get('shapeType');
|
||||
layerData.forEach(function (feature) {
|
||||
_this._calculateTop(feature);
|
||||
|
||||
if (shapeType === 'squareColumn') {
|
||||
_this._calculateWall(feature);
|
||||
}
|
||||
|
||||
delete feature.bufferInfo;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_initAttributes",
|
||||
value: function _initAttributes() {
|
||||
_get(_getPrototypeOf(Grid3D.prototype), "_initAttributes", this).call(this);
|
||||
|
||||
this.attributes.miters = new Float32Array(this.verticesCount * 3);
|
||||
this.attributes.normals = new Float32Array(this.verticesCount * 3);
|
||||
}
|
||||
}, {
|
||||
key: "_calculateFeatures",
|
||||
value: function _calculateFeatures() {
|
||||
var layerData = this.get('layerData');
|
||||
var shapeType = this.get('shapeType');
|
||||
|
||||
if (shapeType === 'squareColumn') {
|
||||
this.verticesCount = layerData.length * 20;
|
||||
} else {
|
||||
this.verticesCount = layerData.length * 4;
|
||||
}
|
||||
|
||||
this.indexCount = this.verticesCount * 1.5;
|
||||
}
|
||||
}, {
|
||||
key: "_calculateTop",
|
||||
value: function _calculateTop(feature) {
|
||||
var _this2 = this;
|
||||
|
||||
var _feature$coordinates = _slicedToArray(feature.coordinates, 2),
|
||||
x = _feature$coordinates[0],
|
||||
y = _feature$coordinates[1];
|
||||
|
||||
var size = feature.size;
|
||||
feature.bufferInfo = {
|
||||
verticesOffset: this._offset
|
||||
};
|
||||
var shapeType = this.get('shapeType');
|
||||
|
||||
if (shapeType !== 'squareColumn') {
|
||||
size = 0;
|
||||
}
|
||||
|
||||
this._encodeArray(feature, 4);
|
||||
|
||||
this.attributes.positions.set([x, y, size, x, y, size, x, y, size, x, y, size], this._offset * 3);
|
||||
this.attributes.miters.set([-1, 1, 1, 1, 1, 1, -1, -1, 1, 1, -1, 1], this._offset * 3);
|
||||
this.attributes.normals.set([0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1], this._offset * 3); // top normal
|
||||
|
||||
var indexArray = [0, 2, 1, 2, 3, 1].map(function (v) {
|
||||
return v + _this2._offset;
|
||||
});
|
||||
this.indexArray.set(indexArray, this._offset * 1.5);
|
||||
this._offset += 4;
|
||||
}
|
||||
}, {
|
||||
key: "_calculateWall",
|
||||
value: function _calculateWall(feature) {
|
||||
var size = feature.size;
|
||||
|
||||
var _feature$coordinates2 = _slicedToArray(feature.coordinates, 2),
|
||||
x = _feature$coordinates2[0],
|
||||
y = _feature$coordinates2[1];
|
||||
|
||||
var vertices = [1, -1, 1, -1, -1, 1, -1, 1, 1, 1, 1, 1, 1, -1, 1];
|
||||
feature.bufferInfo = {
|
||||
verticesOffset: this._offset
|
||||
};
|
||||
|
||||
this._encodeArray(feature, 20); // front left, back right
|
||||
|
||||
|
||||
this.attributes.normals.set([0, -1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, // bottom
|
||||
-1, 0, 0, -1, 0, 0, -1, 0, 0, -1, 0, 0, // left
|
||||
0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, // top
|
||||
1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0 // right
|
||||
], this._offset * 3); // top normal
|
||||
|
||||
for (var i = 0; i < 4; i++) {
|
||||
this.attributes.positions.set([x, y, 1, x, y, 1, x, y, 1, x, y, 1], this._offset * 3);
|
||||
var prePoint = vertices.slice(i * 3, i * 3 + 3);
|
||||
var nextPoint = vertices.slice(i * 3 + 3, i * 3 + 6);
|
||||
|
||||
this._calculateExtrudeFace(prePoint, nextPoint, this._offset, this._offset * 1.5, size);
|
||||
|
||||
this._offset += 4;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "_calculateExtrudeFace",
|
||||
value: function _calculateExtrudeFace(prePoint, nextPoint, positionOffset, indexOffset, size) {
|
||||
this.attributes.miters.set([prePoint[0], prePoint[1], size, nextPoint[0], nextPoint[1], size, prePoint[0], prePoint[1], 0, nextPoint[0], nextPoint[1], 0], positionOffset * 3);
|
||||
var indexArray = [0, 1, 2, 1, 3, 2].map(function (v) {
|
||||
return v + positionOffset;
|
||||
});
|
||||
|
||||
if (this.get('uv')) {
|
||||
// temp 点亮城市demo
|
||||
this.attributes.uv.set([0.1, 0, 0, 0, 0.1, size / 2000, 0, size / 2000], positionOffset * 2);
|
||||
}
|
||||
|
||||
this.indexArray.set(indexArray, indexOffset);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Grid3D;
|
||||
}(_buffer["default"]);
|
||||
|
||||
exports["default"] = Grid3D;
|
|
@ -1,169 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.createColorRamp = createColorRamp;
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _colorscales = require("../../../attr/colorscales");
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../../../core/three"));
|
||||
|
||||
var _base = _interopRequireDefault(require("../../../core/base"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var HeatmapBuffer =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(HeatmapBuffer, _Base);
|
||||
|
||||
function HeatmapBuffer(cfg) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, HeatmapBuffer);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(HeatmapBuffer).call(this, cfg));
|
||||
|
||||
_this.init();
|
||||
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(HeatmapBuffer, [{
|
||||
key: "init",
|
||||
value: function init() {
|
||||
var _this2 = this;
|
||||
|
||||
var data = this.get('data');
|
||||
var positions = [];
|
||||
var dirs = [];
|
||||
var weights = []; // const indices = [];
|
||||
// 组织顶点数据
|
||||
|
||||
data.forEach(function (d) {
|
||||
// const totalIndex = index * 4;
|
||||
var coord = d.coordinates;
|
||||
var weight = d.size;
|
||||
|
||||
var dir = _this2._addDir(-1, 1);
|
||||
|
||||
var dir1 = _this2._addDir(1, 1);
|
||||
|
||||
var dir2 = _this2._addDir(-1, -1);
|
||||
|
||||
var dir3 = _this2._addDir(1, -1);
|
||||
|
||||
positions.push.apply(positions, _toConsumableArray(coord).concat(_toConsumableArray(coord), _toConsumableArray(coord), _toConsumableArray(coord), _toConsumableArray(coord), _toConsumableArray(coord)));
|
||||
dirs.push.apply(dirs, _toConsumableArray(dir).concat(_toConsumableArray(dir2), _toConsumableArray(dir3), _toConsumableArray(dir1), _toConsumableArray(dir), _toConsumableArray(dir3)));
|
||||
weights.push(weight, weight, weight, weight, weight, weight); // indices.push(totalIndex, totalIndex + 2, totalIndex + 3, totalIndex, totalIndex + 3, totalIndex + 1);
|
||||
});
|
||||
this.attributes = {
|
||||
vertices: positions,
|
||||
// indices,
|
||||
dirs: dirs,
|
||||
weights: weights
|
||||
};
|
||||
}
|
||||
}, {
|
||||
key: "_addVertex",
|
||||
value: function _addVertex(position, dirX, dirY) {
|
||||
var x = position[0] * 2 + (dirX + 1) / 2;
|
||||
var y = position[1] * 2 + (dirY + 1) / 2;
|
||||
var z = position[2];
|
||||
return [x, y, z];
|
||||
}
|
||||
}, {
|
||||
key: "_addDir",
|
||||
value: function _addDir(dirX, dirY) {
|
||||
var x = (dirX + 1) / 2;
|
||||
var y = (dirY + 1) / 2;
|
||||
return [x, y];
|
||||
}
|
||||
}]);
|
||||
|
||||
return HeatmapBuffer;
|
||||
}(_base["default"]);
|
||||
|
||||
exports["default"] = HeatmapBuffer;
|
||||
|
||||
function createColorRamp(colors) {
|
||||
var colorImageData = getColorRamp(colors);
|
||||
var colorTexture = getTexture(colorImageData);
|
||||
return colorTexture;
|
||||
}
|
||||
|
||||
function getColorRamp(name) {
|
||||
var colorscale = name;
|
||||
var canvas = document.createElement('canvas');
|
||||
var ctx = canvas.getContext('2d');
|
||||
canvas.width = 1;
|
||||
canvas.height = 256;
|
||||
var gradient = ctx.createLinearGradient(0, 0, 0, 256);
|
||||
var data = null;
|
||||
|
||||
if (typeof colorscale === 'string') {
|
||||
colorscale = _colorscales.colorScales[name];
|
||||
}
|
||||
|
||||
if (Object.prototype.toString.call(colorscale) === '[object Object]') {
|
||||
var min = colorscale.positions[0];
|
||||
var max = colorscale.positions[colorscale.positions.length - 1];
|
||||
|
||||
for (var i = 0; i < colorscale.colors.length; ++i) {
|
||||
var value = (colorscale.positions[i] - min) / (max - min);
|
||||
gradient.addColorStop(value, colorscale.colors[i]);
|
||||
}
|
||||
|
||||
ctx.fillStyle = gradient;
|
||||
ctx.fillRect(0, 0, 1, 256);
|
||||
data = new Uint8ClampedArray(ctx.getImageData(0, 0, 1, 256).data);
|
||||
}
|
||||
|
||||
if (Object.prototype.toString.call(colorscale) === '[object Uint8Array]') {
|
||||
data = ctx.createImageData(1, 256);
|
||||
}
|
||||
|
||||
return new ImageData(data, 1, 256);
|
||||
}
|
||||
|
||||
function getTexture(image) {
|
||||
var texture = new THREE.Texture(image);
|
||||
texture.wrapS = THREE.ClampToEdgeWrapping;
|
||||
texture.wrapT = THREE.ClampToEdgeWrapping;
|
||||
texture.magFilter = THREE.NearestFilter;
|
||||
texture.minFilter = THREE.NearestFilter;
|
||||
texture.format = THREE.RGBAFormat;
|
||||
texture.type = THREE.UnsignedByteType;
|
||||
texture.needsUpdate = true;
|
||||
return texture;
|
||||
}
|
|
@ -1,44 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = hexagonBuffer;
|
||||
|
||||
var _polygon = require("../../shape/polygon");
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
function hexagonBuffer(layerData) {
|
||||
var attribute = {
|
||||
vertices: [],
|
||||
miter: [],
|
||||
colors: [],
|
||||
pickingIds: []
|
||||
};
|
||||
var a = Math.cos(Math.PI / 6);
|
||||
var points = [[0, -1, 0], [-a, -0.5, 0], [-a, 0.5, 0], [0, 1, 0], [a, 0.5, 0], [a, -0.5, 0], [0, -1, 0]]; // const hexgonPoints = polygonPath(6);
|
||||
|
||||
var hexgonFill = (0, _polygon.fill)([points]);
|
||||
var positionsIndex = hexgonFill.positionsIndex,
|
||||
positions = hexgonFill.positions;
|
||||
layerData.forEach(function (element) {
|
||||
positionsIndex.forEach(function (pointIndex) {
|
||||
var _attribute$vertices, _attribute$colors;
|
||||
|
||||
(_attribute$vertices = attribute.vertices).push.apply(_attribute$vertices, _toConsumableArray(element.coordinates));
|
||||
|
||||
attribute.miter.push(positions[pointIndex][0], positions[pointIndex][1]);
|
||||
attribute.pickingIds.push(element.id);
|
||||
|
||||
(_attribute$colors = attribute.colors).push.apply(_attribute$colors, _toConsumableArray(element.color));
|
||||
});
|
||||
});
|
||||
return attribute;
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _buffer = _interopRequireDefault(require("../buffer"));
|
||||
|
||||
var _extrude = require("../../extrude");
|
||||
|
||||
var _global = _interopRequireDefault(require("../../../global"));
|
||||
|
||||
var shapePath = _interopRequireWildcard(require("../../shape/path"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var Hexagon3D =
|
||||
/*#__PURE__*/
|
||||
function (_BufferBase) {
|
||||
_inherits(Hexagon3D, _BufferBase);
|
||||
|
||||
function Hexagon3D() {
|
||||
_classCallCheck(this, Hexagon3D);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(Hexagon3D).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(Hexagon3D, [{
|
||||
key: "_buildFeatures",
|
||||
value: function _buildFeatures() {
|
||||
var _this = this;
|
||||
|
||||
var layerData = this.get('layerData');
|
||||
this._offset = 0;
|
||||
layerData.forEach(function (feature) {
|
||||
_this._calculateFill(feature);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_calculateFeatures",
|
||||
value: function _calculateFeatures() {
|
||||
var shape = this.get('shapeType');
|
||||
var hexgonFill = this.getShape(shape);
|
||||
var layerData = this.get('layerData');
|
||||
this.verticesCount = layerData.length;
|
||||
this.indexCount = 0;
|
||||
this.instanceGeometry = hexgonFill;
|
||||
}
|
||||
}, {
|
||||
key: "_calculateFill",
|
||||
value: function _calculateFill(feature) {
|
||||
feature.bufferInfo = {
|
||||
verticesOffset: this._offset
|
||||
};
|
||||
var coordinates = feature.coordinates;
|
||||
|
||||
this._encodeArray(feature, 1);
|
||||
|
||||
this.attributes.positions.set(coordinates, this._offset * 3);
|
||||
this._offset++;
|
||||
}
|
||||
}, {
|
||||
key: "getShape",
|
||||
value: function getShape(shape) {
|
||||
var pointShape = _global["default"].pointShape;
|
||||
if (pointShape['3d'].indexOf(shape) !== -1) return (0, _extrude.extrude_Polygon)([shapePath[shape]()]);
|
||||
if (pointShape['2d'].indexOf(shape) !== -1) return (0, _extrude.fillPolygon)([shapePath[shape]()]);
|
||||
return (0, _extrude.fillPolygon)([shapePath[shape]()]);
|
||||
}
|
||||
}]);
|
||||
|
||||
return Hexagon3D;
|
||||
}(_buffer["default"]);
|
||||
|
||||
exports["default"] = Hexagon3D;
|
|
@ -1,104 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _util = _interopRequireDefault(require("../../util"));
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../../core/three"));
|
||||
|
||||
var _base = _interopRequireDefault(require("../../core/base"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var ImageBuffer =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(ImageBuffer, _Base);
|
||||
|
||||
function ImageBuffer(cfg) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, ImageBuffer);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(ImageBuffer).call(this, cfg));
|
||||
|
||||
_this.init();
|
||||
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(ImageBuffer, [{
|
||||
key: "init",
|
||||
value: function init() {
|
||||
var _this2 = this;
|
||||
|
||||
var layerData = this.get('layerData');
|
||||
var coordinates = layerData[0].coordinates;
|
||||
var images = layerData[0].images;
|
||||
var positions = [].concat(_toConsumableArray(coordinates[0]), [coordinates[1][0], coordinates[0][1], 0], _toConsumableArray(coordinates[1]), _toConsumableArray(coordinates[0]), _toConsumableArray(coordinates[1]), [coordinates[0][0], coordinates[1][1], 0]);
|
||||
var image = images;
|
||||
|
||||
if (_util["default"].isArray(images)) {
|
||||
image = images[0];
|
||||
var textures = images.map(function (img) {
|
||||
return _this2._getTexture(img);
|
||||
});
|
||||
this.u_rasters = textures;
|
||||
}
|
||||
|
||||
var uv = [0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0];
|
||||
var texture = new THREE.Texture(image);
|
||||
texture.magFilter = THREE.LinearFilter;
|
||||
texture.minFilter = THREE.LinearMipMapLinearFilter;
|
||||
texture.needsUpdate = true;
|
||||
var attributes = {
|
||||
vertices: new Float32Array(positions),
|
||||
uvs: new Float32Array(uv)
|
||||
};
|
||||
this.attributes = attributes;
|
||||
this.texture = texture;
|
||||
}
|
||||
}, {
|
||||
key: "_getTexture",
|
||||
value: function _getTexture(image) {
|
||||
var texture = new THREE.Texture(image);
|
||||
texture.magFilter = THREE.LinearFilter;
|
||||
texture.minFilter = THREE.LinearFilter;
|
||||
}
|
||||
}]);
|
||||
|
||||
return ImageBuffer;
|
||||
}(_base["default"]);
|
||||
|
||||
exports["default"] = ImageBuffer;
|
|
@ -1,54 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "getBuffer", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _factory.getBuffer;
|
||||
}
|
||||
});
|
||||
|
||||
var _fill_buffer = _interopRequireDefault(require("./polygon/fill_buffer"));
|
||||
|
||||
var _line_buffer = _interopRequireDefault(require("./polygon/line_buffer"));
|
||||
|
||||
var _extrude_buffer = _interopRequireDefault(require("./polygon/extrude_buffer"));
|
||||
|
||||
var _fill_buffer2 = _interopRequireDefault(require("./point/fill_buffer2"));
|
||||
|
||||
var _meshline = _interopRequireDefault(require("./line/meshline"));
|
||||
|
||||
var _arcline = _interopRequireDefault(require("./line/arcline"));
|
||||
|
||||
var _hexagon_3d = _interopRequireDefault(require("./heatmap/hexagon_3d"));
|
||||
|
||||
var _extrude_buffer2 = _interopRequireDefault(require("./point/extrude_buffer"));
|
||||
|
||||
var _factory = require("./factory");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
// Polygon
|
||||
// Point
|
||||
// Line
|
||||
// heatmap
|
||||
// 3D Shape
|
||||
// Point
|
||||
(0, _factory.registerBuffer)('point', 'fill', _fill_buffer2["default"]); // polygon
|
||||
|
||||
(0, _factory.registerBuffer)('polygon', 'fill', _fill_buffer["default"]);
|
||||
(0, _factory.registerBuffer)('polygon', 'extrude', _extrude_buffer["default"]);
|
||||
(0, _factory.registerBuffer)('polygon', 'line', _line_buffer["default"]); // line
|
||||
|
||||
(0, _factory.registerBuffer)('line', 'line', _meshline["default"]);
|
||||
(0, _factory.registerBuffer)('line', 'arc', _arcline["default"]);
|
||||
(0, _factory.registerBuffer)('line', 'greatCircle', _arcline["default"]); // heatmap
|
||||
// registerBuffer('heatmap', 'square', Grid3D);
|
||||
// registerBuffer('heatmap', 'squareColumn', Grid3D);
|
||||
|
||||
(0, _factory.registerBuffer)('heatmap', 'shape', _hexagon_3d["default"]);
|
||||
(0, _factory.registerBuffer)('point', 'shape', _hexagon_3d["default"]); // 3D Shape
|
||||
|
||||
(0, _factory.registerBuffer)('shape', 'extrude', _extrude_buffer2["default"]);
|
|
@ -1,182 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _bufferBase = _interopRequireDefault(require("./bufferBase"));
|
||||
|
||||
var _shape = require("../shape");
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var LineBuffer =
|
||||
/*#__PURE__*/
|
||||
function (_BufferBase) {
|
||||
_inherits(LineBuffer, _BufferBase);
|
||||
|
||||
function LineBuffer() {
|
||||
_classCallCheck(this, LineBuffer);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(LineBuffer).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(LineBuffer, [{
|
||||
key: "geometryBuffer",
|
||||
value: function geometryBuffer() {
|
||||
var shapeType = this.shapeType = this.get('shapeType');
|
||||
|
||||
if (shapeType === 'line') {
|
||||
this.attributes = this._getMeshLineAttributes();
|
||||
return;
|
||||
} else if (shapeType === 'arc') {
|
||||
this.attributes = this._getArcLineAttributes();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "_getShape",
|
||||
value: function _getShape(geo, props, index) {
|
||||
if (!this.shapeType) {
|
||||
return _shape.lineShape.defaultLine(geo, index);
|
||||
}
|
||||
|
||||
var shape = this.shapeType;
|
||||
|
||||
if (shape === 'meshLine') {
|
||||
return _shape.lineShape[shape](geo, props, index);
|
||||
} else if (shape === 'tubeLine') {
|
||||
return _shape.lineShape[shape](geo, props, index);
|
||||
} else if (shape === 'arc') {
|
||||
return _shape.lineShape[shape](geo, props, index);
|
||||
}
|
||||
|
||||
return _shape.lineShape.Line(geo, props, index);
|
||||
}
|
||||
}, {
|
||||
key: "_getArcLineAttributes",
|
||||
value: function _getArcLineAttributes() {
|
||||
var _this = this;
|
||||
|
||||
var layerData = this.get('layerData');
|
||||
var positions = [];
|
||||
var colors = [];
|
||||
var indexArray = [];
|
||||
var sizes = [];
|
||||
var instances = [];
|
||||
var pickingIds = [];
|
||||
layerData.forEach(function (item) {
|
||||
var props = item;
|
||||
var positionCount = positions.length / 3;
|
||||
|
||||
var attrData = _this._getShape(item.coordinates, props, positionCount);
|
||||
|
||||
positions.push.apply(positions, _toConsumableArray(attrData.positions));
|
||||
colors.push.apply(colors, _toConsumableArray(attrData.colors));
|
||||
indexArray.push.apply(indexArray, _toConsumableArray(attrData.indexArray));
|
||||
instances.push.apply(instances, _toConsumableArray(attrData.instances));
|
||||
sizes.push.apply(sizes, _toConsumableArray(attrData.sizes));
|
||||
pickingIds.push.apply(pickingIds, _toConsumableArray(attrData.pickingIds));
|
||||
});
|
||||
return {
|
||||
pickingIds: pickingIds,
|
||||
positions: positions,
|
||||
colors: colors,
|
||||
indexArray: indexArray,
|
||||
sizes: sizes,
|
||||
instances: instances
|
||||
};
|
||||
}
|
||||
}, {
|
||||
key: "_getMeshLineAttributes",
|
||||
value: function _getMeshLineAttributes() {
|
||||
var layerData = this.get('layerData');
|
||||
|
||||
var _this$get = this.get('style'),
|
||||
dashArray = _this$get.dashArray;
|
||||
|
||||
var imagePos = this.get('imagePos');
|
||||
var positions = [];
|
||||
var pickingIds = [];
|
||||
var normal = [];
|
||||
var miter = [];
|
||||
var colors = [];
|
||||
var indexArray = [];
|
||||
var sizes = [];
|
||||
var attrDistance = [];
|
||||
var attrDashArray = [];
|
||||
var textureCoord = [];
|
||||
var totalDistance = [];
|
||||
layerData.forEach(function (item) {
|
||||
var props = item;
|
||||
var positionCount = positions.length / 3;
|
||||
var patternPos = {
|
||||
x: 0,
|
||||
y: 0
|
||||
};
|
||||
|
||||
if (item.pattern && imagePos[item.pattern]) {
|
||||
patternPos = imagePos[item.pattern];
|
||||
}
|
||||
|
||||
var attr = _shape.lineShape.Line(item.coordinates, props, positionCount, dashArray, patternPos);
|
||||
|
||||
positions.push.apply(positions, _toConsumableArray(attr.positions));
|
||||
normal.push.apply(normal, _toConsumableArray(attr.normal));
|
||||
miter.push.apply(miter, _toConsumableArray(attr.miter));
|
||||
colors.push.apply(colors, _toConsumableArray(attr.colors));
|
||||
indexArray.push.apply(indexArray, _toConsumableArray(attr.indexArray));
|
||||
sizes.push.apply(sizes, _toConsumableArray(attr.sizes));
|
||||
attrDistance.push.apply(attrDistance, _toConsumableArray(attr.attrDistance));
|
||||
pickingIds.push.apply(pickingIds, _toConsumableArray(attr.pickingIds));
|
||||
attrDashArray.push.apply(attrDashArray, _toConsumableArray(attr.dashArray));
|
||||
textureCoord.push.apply(textureCoord, _toConsumableArray(attr.textureCoordArray));
|
||||
totalDistance.push.apply(totalDistance, _toConsumableArray(attr.totalDistances));
|
||||
});
|
||||
return {
|
||||
positions: positions,
|
||||
normal: normal,
|
||||
miter: miter,
|
||||
colors: colors,
|
||||
indexArray: indexArray,
|
||||
pickingIds: pickingIds,
|
||||
sizes: sizes,
|
||||
attrDistance: attrDistance,
|
||||
attrDashArray: attrDashArray,
|
||||
textureCoord: textureCoord,
|
||||
totalDistance: totalDistance
|
||||
};
|
||||
}
|
||||
}]);
|
||||
|
||||
return LineBuffer;
|
||||
}(_bufferBase["default"]);
|
||||
|
||||
exports["default"] = LineBuffer;
|
|
@ -1,110 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _buffer = _interopRequireDefault(require("../buffer"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var ArcLineBuffer =
|
||||
/*#__PURE__*/
|
||||
function (_BufferBase) {
|
||||
_inherits(ArcLineBuffer, _BufferBase);
|
||||
|
||||
function ArcLineBuffer() {
|
||||
_classCallCheck(this, ArcLineBuffer);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(ArcLineBuffer).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(ArcLineBuffer, [{
|
||||
key: "_buildFeatures",
|
||||
value: function _buildFeatures() {
|
||||
var _this = this;
|
||||
|
||||
var layerData = this.get('layerData');
|
||||
layerData.forEach(function (feature, index) {
|
||||
_this._calculateArc(feature, index);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_initAttributes",
|
||||
value: function _initAttributes() {
|
||||
_get(_getPrototypeOf(ArcLineBuffer.prototype), "_initAttributes", this).call(this);
|
||||
|
||||
this.attributes.instanceArray = new Float32Array(this.verticesCount * 4);
|
||||
}
|
||||
}, {
|
||||
key: "_calculateArc",
|
||||
value: function _calculateArc(feature, offset) {
|
||||
var _this2 = this;
|
||||
|
||||
var _this$get = this.get('style'),
|
||||
_this$get$segNum = _this$get.segNum,
|
||||
segNum = _this$get$segNum === void 0 ? 30 : _this$get$segNum;
|
||||
|
||||
var coordinates = feature.coordinates;
|
||||
|
||||
var _loop = function _loop(i) {
|
||||
_this2.attributes.positions.set([i, 1, i, i, -1, i], offset * segNum * 6 + i * 6);
|
||||
|
||||
_this2.attributes.instanceArray.set([coordinates[0][0], coordinates[0][1], coordinates[1][0], coordinates[1][1], coordinates[0][0], coordinates[0][1], coordinates[1][0], coordinates[1][1]], offset * segNum * 8 + i * 8);
|
||||
|
||||
if (i !== segNum - 1) {
|
||||
var indexArray = [0, 1, 2, 1, 3, 2].map(function (v) {
|
||||
return offset * segNum * 2 + i * 2 + v;
|
||||
});
|
||||
|
||||
_this2.indexArray.set(indexArray, offset * segNum * 6 + i * 6 - offset * 6);
|
||||
}
|
||||
};
|
||||
|
||||
for (var i = 0; i < segNum; i++) {
|
||||
_loop(i);
|
||||
}
|
||||
|
||||
feature.bufferInfo = {
|
||||
verticesOffset: offset * segNum * 2
|
||||
};
|
||||
|
||||
this._encodeArray(feature, segNum * 2);
|
||||
}
|
||||
}, {
|
||||
key: "_calculateFeatures",
|
||||
value: function _calculateFeatures() {
|
||||
var layerData = this.get('layerData');
|
||||
var segNum = this.get('segNum') || 30;
|
||||
this.verticesCount = layerData.length * segNum * 2;
|
||||
this.indexCount = this.verticesCount * 3 - layerData.length * 6;
|
||||
}
|
||||
}]);
|
||||
|
||||
return ArcLineBuffer;
|
||||
}(_buffer["default"]);
|
||||
|
||||
exports["default"] = ArcLineBuffer;
|
|
@ -1,142 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _buffer = _interopRequireDefault(require("../buffer"));
|
||||
|
||||
var _polylineNormals = _interopRequireDefault(require("../../../util/polyline-normals"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var MeshLineBuffer =
|
||||
/*#__PURE__*/
|
||||
function (_BufferBase) {
|
||||
_inherits(MeshLineBuffer, _BufferBase);
|
||||
|
||||
function MeshLineBuffer() {
|
||||
_classCallCheck(this, MeshLineBuffer);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(MeshLineBuffer).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(MeshLineBuffer, [{
|
||||
key: "_buildFeatures",
|
||||
value: function _buildFeatures() {
|
||||
var _this = this;
|
||||
|
||||
var layerData = this.get('layerData');
|
||||
layerData.forEach(function (feature) {
|
||||
_this._calculateLine(feature);
|
||||
|
||||
delete feature.bufferInfo;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_initAttributes",
|
||||
value: function _initAttributes() {
|
||||
_get(_getPrototypeOf(MeshLineBuffer.prototype), "_initAttributes", this).call(this);
|
||||
|
||||
this.attributes.dashArray = new Float32Array(this.verticesCount);
|
||||
this.attributes.attrDistance = new Float32Array(this.verticesCount);
|
||||
this.attributes.totalDistances = new Float32Array(this.verticesCount);
|
||||
this.attributes.patterns = new Float32Array(this.verticesCount * 2);
|
||||
this.attributes.miters = new Float32Array(this.verticesCount);
|
||||
this.attributes.normals = new Float32Array(this.verticesCount * 3);
|
||||
}
|
||||
}, {
|
||||
key: "_calculateFeatures",
|
||||
value: function _calculateFeatures() {
|
||||
var _this2 = this;
|
||||
|
||||
var layerData = this.get('layerData'); // 计算长
|
||||
|
||||
layerData.forEach(function (feature) {
|
||||
var bufferInfo = {};
|
||||
var coordinates = feature.coordinates;
|
||||
|
||||
if (Array.isArray(coordinates[0][0])) {
|
||||
coordinates = coordinates[0];
|
||||
}
|
||||
|
||||
var _getNormals = (0, _polylineNormals["default"])(coordinates, false, _this2.verticesCount),
|
||||
normals = _getNormals.normals,
|
||||
attrIndex = _getNormals.attrIndex,
|
||||
attrPos = _getNormals.attrPos,
|
||||
attrDistance = _getNormals.attrDistance,
|
||||
miters = _getNormals.miters;
|
||||
|
||||
bufferInfo.normals = normals;
|
||||
bufferInfo.arrayIndex = attrIndex;
|
||||
bufferInfo.positions = attrPos;
|
||||
bufferInfo.attrDistance = attrDistance;
|
||||
bufferInfo.miters = miters;
|
||||
bufferInfo.verticesOffset = _this2.verticesCount;
|
||||
bufferInfo.indexOffset = _this2.indexCount;
|
||||
_this2.verticesCount += attrPos.length / 3;
|
||||
_this2.indexCount += attrIndex.length;
|
||||
feature.bufferInfo = bufferInfo;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_calculateLine",
|
||||
value: function _calculateLine(feature) {
|
||||
var _feature$bufferInfo = feature.bufferInfo,
|
||||
normals = _feature$bufferInfo.normals,
|
||||
arrayIndex = _feature$bufferInfo.arrayIndex,
|
||||
positions = _feature$bufferInfo.positions,
|
||||
attrDistance = _feature$bufferInfo.attrDistance,
|
||||
miters = _feature$bufferInfo.miters,
|
||||
verticesOffset = _feature$bufferInfo.verticesOffset,
|
||||
indexOffset = _feature$bufferInfo.indexOffset;
|
||||
|
||||
var _this$get = this.get('style'),
|
||||
_this$get$dashArray = _this$get.dashArray,
|
||||
dashArray = _this$get$dashArray === void 0 ? 200 : _this$get$dashArray;
|
||||
|
||||
this._encodeArray(feature, positions.length / 3);
|
||||
|
||||
var totalLength = attrDistance[attrDistance.length - 1]; // 增加长度
|
||||
|
||||
var totalDistances = Array(positions.length / 3).fill(totalLength); // 虚线比例
|
||||
|
||||
var ratio = dashArray / totalLength;
|
||||
var dashArrays = Array(positions.length / 3).fill(ratio);
|
||||
this.attributes.positions.set(positions, verticesOffset * 3);
|
||||
this.indexArray.set(arrayIndex, indexOffset);
|
||||
this.attributes.miters.set(miters, verticesOffset);
|
||||
this.attributes.normals.set(normals, verticesOffset * 3);
|
||||
this.attributes.attrDistance.set(attrDistance, verticesOffset);
|
||||
this.attributes.totalDistances.set(totalDistances, verticesOffset);
|
||||
this.attributes.dashArray.set(dashArrays, verticesOffset);
|
||||
}
|
||||
}]);
|
||||
|
||||
return MeshLineBuffer;
|
||||
}(_buffer["default"]);
|
||||
|
||||
exports["default"] = MeshLineBuffer;
|
|
@ -1,243 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _bufferBase = _interopRequireDefault(require("./bufferBase"));
|
||||
|
||||
var _index = require("../shape/index");
|
||||
|
||||
var polygonPath = _interopRequireWildcard(require("../shape/path"));
|
||||
|
||||
var polygonShape = _interopRequireWildcard(require("../shape/polygon"));
|
||||
|
||||
var lineShape = _interopRequireWildcard(require("../shape/line"));
|
||||
|
||||
var _global = _interopRequireDefault(require("../../global"));
|
||||
|
||||
var _util = _interopRequireDefault(require("../../util"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
|
||||
|
||||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
|
||||
|
||||
function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
|
||||
|
||||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var pointShape = _global["default"].pointShape;
|
||||
|
||||
var PointBuffer =
|
||||
/*#__PURE__*/
|
||||
function (_BufferBase) {
|
||||
_inherits(PointBuffer, _BufferBase);
|
||||
|
||||
function PointBuffer() {
|
||||
_classCallCheck(this, PointBuffer);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(PointBuffer).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(PointBuffer, [{
|
||||
key: "geometryBuffer",
|
||||
value: function geometryBuffer() {
|
||||
var type = this.get('type');
|
||||
|
||||
switch (type) {
|
||||
case 'image':
|
||||
this._imageBuffer();
|
||||
|
||||
break;
|
||||
|
||||
case '2d':
|
||||
this._3dRegularBuffer();
|
||||
|
||||
break;
|
||||
|
||||
case '3d':
|
||||
this._3dRegularBuffer();
|
||||
|
||||
break;
|
||||
|
||||
case 'Model':
|
||||
this._ModelBuffer();
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
this._sdfRegularBuffer();
|
||||
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "_imageBuffer",
|
||||
value: function _imageBuffer() {
|
||||
var coordinates = this.get('coordinates');
|
||||
var properties = this.get('properties');
|
||||
var imagePos = this.get('imagePos');
|
||||
var uv = new Float32Array(properties.length * 2);
|
||||
|
||||
for (var i = 0; i < properties.length; i++) {
|
||||
var _imagePos$properties$ = imagePos[properties[i].shape],
|
||||
x = _imagePos$properties$.x,
|
||||
y = _imagePos$properties$.y;
|
||||
uv[i * 2] = x;
|
||||
uv[i * 2 + 1] = y;
|
||||
}
|
||||
|
||||
this.bufferStruct.position = coordinates;
|
||||
this.bufferStruct.uv = uv;
|
||||
this.bufferStruct.style = properties;
|
||||
this.attributes = this._toPointsAttributes(this.bufferStruct);
|
||||
this.attributes.uvs = uv;
|
||||
}
|
||||
}, {
|
||||
key: "_sdfRegularBuffer",
|
||||
value: function _sdfRegularBuffer() {
|
||||
var coordinates = this.get('coordinates');
|
||||
var properties = this.get('properties');
|
||||
this.bufferStruct.position = coordinates;
|
||||
this.bufferStruct.style = properties;
|
||||
this.attributes = this._toPointsAttributes(this.bufferStruct);
|
||||
}
|
||||
}, {
|
||||
key: "_3dRegularBuffer",
|
||||
value: function _3dRegularBuffer() {
|
||||
var _this = this;
|
||||
|
||||
var lineAttribute = {
|
||||
shapes: [],
|
||||
normal: [],
|
||||
miter: [],
|
||||
indexArray: [],
|
||||
sizes: [],
|
||||
positions: []
|
||||
};
|
||||
var coordinates = this.get('coordinates');
|
||||
var properties = this.get('properties');
|
||||
var style = this.get('style');
|
||||
var type = this.get('type');
|
||||
var positions = [];
|
||||
var shapes = [];
|
||||
var sizes = [];
|
||||
var uvs = [];
|
||||
var positionsIndex = [];
|
||||
var indexCount = 0;
|
||||
this.bufferStruct.style = properties;
|
||||
coordinates.forEach(function (geo, index) {
|
||||
var _lineAttribute$shapes, _lineAttribute$normal, _lineAttribute$miter, _lineAttribute$indexA;
|
||||
|
||||
var _properties$index = properties[index],
|
||||
size = _properties$index.size,
|
||||
shape = _properties$index.shape; // let shapeType = '';
|
||||
|
||||
if (type === '2d' || type === '3d' && size[2] === 0) {
|
||||
// let shapeType = 'fill';
|
||||
_util["default"].isArray(size) || (size = [size, size, 0]);
|
||||
} else {
|
||||
_util["default"].isArray(size) || (size = [size, size, size]);
|
||||
}
|
||||
|
||||
if (_index.regularShape[shape] == null) {
|
||||
uvs.push(0, 0, 1, 0, 1, 1, 1, 1, 0, 1, 0, 0);
|
||||
shape = 'square';
|
||||
}
|
||||
|
||||
properties[index].size = size;
|
||||
|
||||
var _this$_getShape = _this._getShape(properties[index], style, lineAttribute.miter.length),
|
||||
_this$_getShape2 = _slicedToArray(_this$_getShape, 2),
|
||||
vert = _this$_getShape2[0],
|
||||
polygonLine = _this$_getShape2[1];
|
||||
|
||||
polygonLine.miter.forEach(function () {
|
||||
var _lineAttribute$positi, _lineAttribute$sizes;
|
||||
|
||||
(_lineAttribute$positi = lineAttribute.positions).push.apply(_lineAttribute$positi, _toConsumableArray(geo));
|
||||
|
||||
(_lineAttribute$sizes = lineAttribute.sizes).push.apply(_lineAttribute$sizes, _toConsumableArray(size));
|
||||
});
|
||||
|
||||
(_lineAttribute$shapes = lineAttribute.shapes).push.apply(_lineAttribute$shapes, _toConsumableArray(polygonLine.positions));
|
||||
|
||||
(_lineAttribute$normal = lineAttribute.normal).push.apply(_lineAttribute$normal, _toConsumableArray(polygonLine.normal));
|
||||
|
||||
(_lineAttribute$miter = lineAttribute.miter).push.apply(_lineAttribute$miter, _toConsumableArray(polygonLine.miter));
|
||||
|
||||
(_lineAttribute$indexA = lineAttribute.indexArray).push.apply(_lineAttribute$indexA, _toConsumableArray(polygonLine.indexArray));
|
||||
|
||||
shapes.push(vert.positions);
|
||||
positions.push(geo);
|
||||
sizes.push(size);
|
||||
positionsIndex.push(vert.positionsIndex);
|
||||
indexCount += vert.positionsIndex.length;
|
||||
});
|
||||
this.bufferStruct.indices = positionsIndex;
|
||||
this.bufferStruct.position = positions;
|
||||
this.bufferStruct.indexCount = indexCount;
|
||||
this.bufferStruct.shapes = shapes;
|
||||
this.bufferStruct.sizes = sizes;
|
||||
this.bufferStruct.faceUv = uvs;
|
||||
this.attributes = this._toPointShapeAttributes(this.bufferStruct);
|
||||
this.lineAttribute = lineAttribute;
|
||||
}
|
||||
}, {
|
||||
key: "_getShape",
|
||||
value: function _getShape(props, style, positionsIndex) {
|
||||
var shape = props.shape;
|
||||
var stroke = style.stroke,
|
||||
strokeWidth = style.strokeWidth;
|
||||
var path = polygonPath[shape]();
|
||||
var polygon = null;
|
||||
var polygonLine = null;
|
||||
|
||||
if (pointShape['3d'].indexOf(shape) === -1) {
|
||||
polygon = polygonShape.fill([path]);
|
||||
polygonLine = lineShape.Line(path, {
|
||||
size: [strokeWidth, 0],
|
||||
color: stroke
|
||||
}, positionsIndex);
|
||||
} else {
|
||||
polygon = polygonShape.extrude([path]);
|
||||
}
|
||||
|
||||
return [polygon, polygonLine];
|
||||
}
|
||||
}]);
|
||||
|
||||
return PointBuffer;
|
||||
}(_bufferBase["default"]);
|
||||
|
||||
exports["default"] = PointBuffer;
|
|
@ -1,66 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = circleBuffer;
|
||||
|
||||
var _vertexCompress = require("../../../util/vertex-compress");
|
||||
|
||||
var _global = _interopRequireDefault(require("../../../global"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
var pointShape = _global["default"].pointShape;
|
||||
var LEFT_SHIFT17 = 131072.0; // const LEFT_SHIFT18 = 262144.0;
|
||||
// const LEFT_SHIFT19 = 524288.0;
|
||||
// const LEFT_SHIFT20 = 1048576.0;
|
||||
|
||||
var LEFT_SHIFT21 = 2097152.0; // const LEFT_SHIFT22 = 4194304.0;
|
||||
|
||||
var LEFT_SHIFT23 = 8388608.0; // const LEFT_SHIFT24 = 16777216.0;
|
||||
|
||||
function circleBuffer(layerData) {
|
||||
var index = [];
|
||||
var aPosition = [];
|
||||
var aPackedData = [];
|
||||
layerData.forEach(function (_ref, i) {
|
||||
var _ref$size = _ref.size,
|
||||
size = _ref$size === void 0 ? 0 : _ref$size,
|
||||
color = _ref.color,
|
||||
id = _ref.id,
|
||||
coordinates = _ref.coordinates,
|
||||
shape = _ref.shape;
|
||||
var shapeIndex = pointShape['2d'].indexOf(shape) || 0;
|
||||
|
||||
if (isNaN(size)) {
|
||||
size = 0;
|
||||
} // pack color(vec4) into vec2
|
||||
|
||||
|
||||
var packedColor = [(0, _vertexCompress.packUint8ToFloat)(color[0] * 255, color[1] * 255), (0, _vertexCompress.packUint8ToFloat)(color[2] * 255, color[3] * 255)]; // construct point coords
|
||||
|
||||
[[-1, -1], [1, -1], [1, 1], [-1, 1]].forEach(function (extrude) {
|
||||
// vec4(color, color, (4-bit extrude, 4-bit shape, 16-bit size), id)
|
||||
aPackedData.push.apply(aPackedData, packedColor.concat([(extrude[0] + 1) * LEFT_SHIFT23 + (extrude[1] + 1) * LEFT_SHIFT21 + shapeIndex * LEFT_SHIFT17 + size, id]));
|
||||
}); // TODO:如果使用相对瓦片坐标,还可以进一步压缩
|
||||
|
||||
aPosition.push.apply(aPosition, _toConsumableArray(coordinates).concat(_toConsumableArray(coordinates), _toConsumableArray(coordinates), _toConsumableArray(coordinates)));
|
||||
index.push.apply(index, _toConsumableArray([0, 1, 2, 0, 2, 3].map(function (n) {
|
||||
return n + i * 4;
|
||||
})));
|
||||
});
|
||||
return {
|
||||
aPosition: aPosition,
|
||||
index: index,
|
||||
aPackedData: aPackedData
|
||||
};
|
||||
}
|
|
@ -1,174 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _buffer = _interopRequireDefault(require("../buffer"));
|
||||
|
||||
var _global = _interopRequireDefault(require("../../../global"));
|
||||
|
||||
var _extrude = require("../../extrude");
|
||||
|
||||
var shapePath = _interopRequireWildcard(require("../../shape/path"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var ExtrudeBuffer =
|
||||
/*#__PURE__*/
|
||||
function (_BufferBase) {
|
||||
_inherits(ExtrudeBuffer, _BufferBase);
|
||||
|
||||
function ExtrudeBuffer() {
|
||||
_classCallCheck(this, ExtrudeBuffer);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(ExtrudeBuffer).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(ExtrudeBuffer, [{
|
||||
key: "_buildFeatures",
|
||||
value: function _buildFeatures() {
|
||||
var _this = this;
|
||||
|
||||
var layerData = this.get('layerData');
|
||||
this._offset = 0;
|
||||
this._indexOffset = 0;
|
||||
layerData.forEach(function (feature) {
|
||||
_this._calculateFill(feature);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_initAttributes",
|
||||
value: function _initAttributes() {
|
||||
_get(_getPrototypeOf(ExtrudeBuffer.prototype), "_initAttributes", this).call(this);
|
||||
|
||||
this.attributes.miters = new Float32Array(this.verticesCount * 3);
|
||||
this.attributes.normals = new Float32Array(this.verticesCount * 3);
|
||||
this.attributes.sizes = new Float32Array(this.verticesCount * 3);
|
||||
}
|
||||
}, {
|
||||
key: "_calculateFeatures",
|
||||
value: function _calculateFeatures() {
|
||||
var _this2 = this;
|
||||
|
||||
var layerData = this.get('layerData');
|
||||
this.geometryMap = {};
|
||||
layerData.forEach(function (feature) {
|
||||
var shape = feature.shape;
|
||||
|
||||
var _this2$getShape = _this2.getShape(shape),
|
||||
positions = _this2$getShape.positions,
|
||||
indexArray = _this2$getShape.indexArray;
|
||||
|
||||
_this2.verticesCount += positions.length / 3;
|
||||
_this2.indexCount += indexArray.length;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_calcultateGeometry",
|
||||
value: function _calcultateGeometry() {
|
||||
var shape = this.get('shapeType');
|
||||
var hexgonFill = this.getShapeFunction(shape)([this._getPoints(6)]);
|
||||
this.instanceGeometry = hexgonFill;
|
||||
}
|
||||
}, {
|
||||
key: "_calculateFill",
|
||||
value: function _calculateFill(feature) {
|
||||
var _this3 = this;
|
||||
|
||||
feature.bufferInfo = {
|
||||
verticesOffset: this._offset
|
||||
};
|
||||
var coordinates = feature.coordinates,
|
||||
shape = feature.shape;
|
||||
var instanceGeometry = this.getShape(shape);
|
||||
var numPoint = instanceGeometry.positions.length / 3;
|
||||
|
||||
this._encodeArray(feature, numPoint);
|
||||
|
||||
this.attributes.miters.set(instanceGeometry.positions, this._offset * 3);
|
||||
var indexArray = instanceGeometry.indexArray.map(function (v) {
|
||||
return v + _this3._offset;
|
||||
});
|
||||
this.indexArray.set(indexArray, this._indexOffset);
|
||||
|
||||
if (instanceGeometry.normals) {
|
||||
this.attributes.normals.set(instanceGeometry.normals, this._offset * 3);
|
||||
}
|
||||
|
||||
var position = [];
|
||||
|
||||
for (var i = 0; i < numPoint; i++) {
|
||||
position.push.apply(position, _toConsumableArray(coordinates));
|
||||
}
|
||||
|
||||
this.attributes.positions.set(position, this._offset * 3);
|
||||
this._offset += numPoint;
|
||||
this._indexOffset += indexArray.length;
|
||||
}
|
||||
}, {
|
||||
key: "_getPoints",
|
||||
value: function _getPoints(num) {
|
||||
return (0, shapePath.polygonPath)(num, 1);
|
||||
}
|
||||
}, {
|
||||
key: "getShape",
|
||||
value: function getShape(shape) {
|
||||
var pointShape = _global["default"].pointShape;
|
||||
|
||||
if (this.geometryMap[shape]) {
|
||||
return this.geometryMap[shape];
|
||||
}
|
||||
|
||||
var geometry = null;
|
||||
|
||||
if (pointShape['3d'].indexOf(shape) !== -1) {
|
||||
geometry = (0, _extrude.extrude_Polygon)([shapePath[shape]()]);
|
||||
} else if (pointShape['2d'].indexOf(shape) !== -1) {
|
||||
geometry = (0, _extrude.fillPolygon)([shapePath[shape]()]);
|
||||
} else {
|
||||
geometry = (0, _extrude.fillPolygon)([shapePath[shape]()]);
|
||||
}
|
||||
|
||||
this.geometryMap[shape] = geometry;
|
||||
return geometry;
|
||||
}
|
||||
}]);
|
||||
|
||||
return ExtrudeBuffer;
|
||||
}(_buffer["default"]);
|
||||
|
||||
exports["default"] = ExtrudeBuffer;
|
|
@ -1,127 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = fillBuffer;
|
||||
|
||||
var _global = _interopRequireDefault(require("../../../global"));
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../../../core/three"));
|
||||
|
||||
var polygonShape = _interopRequireWildcard(require("../../shape/polygon"));
|
||||
|
||||
var polygonPath = _interopRequireWildcard(require("../../shape/path"));
|
||||
|
||||
var _util = _interopRequireDefault(require("../../../util"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
var pointShape = _global["default"].pointShape;
|
||||
|
||||
function fillBuffer(layerData) {
|
||||
var attribute = {
|
||||
vertices: [],
|
||||
normals: [],
|
||||
colors: [],
|
||||
pickingIds: [],
|
||||
shapePositions: [],
|
||||
a_size: [],
|
||||
faceUv: []
|
||||
};
|
||||
layerData.forEach(function (item) {
|
||||
var size = item.size,
|
||||
shape = item.shape,
|
||||
color = item.color,
|
||||
id = item.id,
|
||||
coordinates = item.coordinates;
|
||||
var polygon = null;
|
||||
var path = polygonPath[shape]();
|
||||
|
||||
if (pointShape['2d'].indexOf(shape) !== -1) {
|
||||
_util["default"].isArray(size) || (size = [size, size, 0]);
|
||||
polygon = polygonShape.fill([path]);
|
||||
} else if (pointShape['3d'].indexOf(shape) !== -1) {
|
||||
_util["default"].isArray(size) || (size = [size, size, size]);
|
||||
polygon = polygonShape.extrude([path]);
|
||||
} else {
|
||||
throw new Error('Invalid shape type: ' + shape);
|
||||
}
|
||||
|
||||
toPointShapeAttributes(polygon, coordinates, {
|
||||
size: size,
|
||||
shape: shape,
|
||||
color: color,
|
||||
id: id
|
||||
}, attribute); // toPointShapeAttributes(polygon, null, {}, attribute);
|
||||
// instanced attributes
|
||||
// attribute.vertices.push(...coordinates);
|
||||
// attribute.a_size.push(...size);
|
||||
// attribute.colors.push(...color);
|
||||
// attribute.pickingIds.push(id);
|
||||
});
|
||||
return attribute;
|
||||
}
|
||||
|
||||
function toPointShapeAttributes(polygon, geo, style, attribute) {
|
||||
var positionsIndex = polygon.positionsIndex,
|
||||
positions = polygon.positions;
|
||||
var pA = new THREE.Vector3();
|
||||
var pB = new THREE.Vector3();
|
||||
var pC = new THREE.Vector3();
|
||||
var cb = new THREE.Vector3();
|
||||
var ab = new THREE.Vector3();
|
||||
|
||||
for (var i = 0; i < positionsIndex.length / 3; i++) {
|
||||
var _attribute$vertices, _attribute$a_size, _attribute$colors;
|
||||
|
||||
var index = positionsIndex[i * 3];
|
||||
var color = style.color,
|
||||
size = style.size,
|
||||
id = style.id;
|
||||
var ax = positions[index][0];
|
||||
var ay = positions[index][1];
|
||||
var az = positions[index][2];
|
||||
index = positionsIndex[i * 3 + 1];
|
||||
var bx = positions[index][0];
|
||||
var by = positions[index][1];
|
||||
var bz = positions[index][2];
|
||||
index = positionsIndex[i * 3 + 2];
|
||||
var cx = positions[index][0];
|
||||
var cy = positions[index][1];
|
||||
var cz = positions[index][2];
|
||||
pA.set(ax, ay, az);
|
||||
pB.set(bx, by, bz);
|
||||
pC.set(cx, cy, cz);
|
||||
cb.subVectors(pC, pB);
|
||||
ab.subVectors(pA, pB);
|
||||
cb.cross(ab);
|
||||
cb.normalize();
|
||||
var nx = cb.x;
|
||||
var ny = cb.y;
|
||||
var nz = cb.z;
|
||||
|
||||
(_attribute$vertices = attribute.vertices).push.apply(_attribute$vertices, _toConsumableArray(geo).concat(_toConsumableArray(geo), _toConsumableArray(geo)));
|
||||
|
||||
attribute.shapePositions.push(ax, ay, az, bx, by, bz, cx, cy, cz);
|
||||
|
||||
(_attribute$a_size = attribute.a_size).push.apply(_attribute$a_size, _toConsumableArray(size).concat(_toConsumableArray(size), _toConsumableArray(size)));
|
||||
|
||||
attribute.normals.push(nx, ny, nz, nx, ny, nz, nx, ny, nz);
|
||||
|
||||
(_attribute$colors = attribute.colors).push.apply(_attribute$colors, _toConsumableArray(color).concat(_toConsumableArray(color), _toConsumableArray(color)));
|
||||
|
||||
attribute.pickingIds.push(id, id, id); // attribute.shapePositions.push(ax, ay, az, bx, by, bz, cx, cy, cz);
|
||||
// attribute.normals.push(nx, ny, nz, nx, ny, nz, nx, ny, nz);
|
||||
}
|
||||
}
|
|
@ -1,74 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = FillBuffer;
|
||||
|
||||
var _vertexCompress = require("../../../util/vertex-compress");
|
||||
|
||||
var _global = _interopRequireDefault(require("../../../global"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
var pointShape = _global["default"].pointShape;
|
||||
var LEFT_SHIFT17 = 131072.0; // const LEFT_SHIFT18 = 262144.0;
|
||||
// const LEFT_SHIFT19 = 524288.0;
|
||||
// const LEFT_SHIFT20 = 1048576.0;
|
||||
|
||||
var LEFT_SHIFT21 = 2097152.0; // const LEFT_SHIFT22 = 4194304.0;
|
||||
|
||||
var LEFT_SHIFT23 = 8388608.0; // const LEFT_SHIFT24 = 16777216.0;
|
||||
|
||||
function FillBuffer(data) {
|
||||
var index = [];
|
||||
var aPosition = [];
|
||||
var aPackedData = [];
|
||||
var layerData = data.layerData;
|
||||
layerData.forEach(function (_ref, i) {
|
||||
var _ref$size = _ref.size,
|
||||
size = _ref$size === void 0 ? 0 : _ref$size,
|
||||
color = _ref.color,
|
||||
id = _ref.id,
|
||||
coordinates = _ref.coordinates,
|
||||
shape = _ref.shape;
|
||||
var shapeIndex = pointShape['2d'].indexOf(shape) || 0;
|
||||
var newCoord = coordinates;
|
||||
|
||||
if (coordinates.length === 1) {
|
||||
newCoord = coordinates[0][0];
|
||||
}
|
||||
|
||||
if (isNaN(size)) {
|
||||
size = 0;
|
||||
} // pack color(vec4) into vec2
|
||||
|
||||
|
||||
var packedColor = [(0, _vertexCompress.packUint8ToFloat)(color[0] * 255, color[1] * 255), (0, _vertexCompress.packUint8ToFloat)(color[2] * 255, color[3] * 255)]; // construct point coords
|
||||
|
||||
[[-1, -1], [1, -1], [1, 1], [-1, 1]].forEach(function (extrude) {
|
||||
// vec4(color, color, (4-bit extrude, 4-bit shape, 16-bit size), id)
|
||||
aPackedData.push.apply(aPackedData, packedColor.concat([(extrude[0] + 1) * LEFT_SHIFT23 + (extrude[1] + 1) * LEFT_SHIFT21 + shapeIndex * LEFT_SHIFT17 + size, id]));
|
||||
}); // TODO:如果使用相对瓦片坐标,还可以进一步压缩
|
||||
|
||||
aPosition.push.apply(aPosition, _toConsumableArray(newCoord).concat(_toConsumableArray(newCoord), _toConsumableArray(newCoord), _toConsumableArray(newCoord)));
|
||||
index.push.apply(index, _toConsumableArray([0, 1, 2, 0, 2, 3].map(function (n) {
|
||||
return n + i * 4;
|
||||
})));
|
||||
});
|
||||
return {
|
||||
attributes: {
|
||||
aPosition: new Float32Array(aPosition),
|
||||
aPackedData: new Float32Array(aPackedData)
|
||||
},
|
||||
indexArray: new Int32Array(index)
|
||||
};
|
||||
}
|
|
@ -1,168 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _buffer = _interopRequireDefault(require("../buffer"));
|
||||
|
||||
var _global = _interopRequireDefault(require("../../../global"));
|
||||
|
||||
var _extrude = require("../../extrude");
|
||||
|
||||
var shapePath = _interopRequireWildcard(require("../../shape/path"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _get(target, property, receiver) { if (typeof Reflect !== "undefined" && Reflect.get) { _get = Reflect.get; } else { _get = function _get(target, property, receiver) { var base = _superPropBase(target, property); if (!base) return; var desc = Object.getOwnPropertyDescriptor(base, property); if (desc.get) { return desc.get.call(receiver); } return desc.value; }; } return _get(target, property, receiver || target); }
|
||||
|
||||
function _superPropBase(object, property) { while (!Object.prototype.hasOwnProperty.call(object, property)) { object = _getPrototypeOf(object); if (object === null) break; } return object; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var pointShape = _global["default"].pointShape;
|
||||
|
||||
var PointFillBuffer =
|
||||
/*#__PURE__*/
|
||||
function (_BufferBase) {
|
||||
_inherits(PointFillBuffer, _BufferBase);
|
||||
|
||||
function PointFillBuffer() {
|
||||
_classCallCheck(this, PointFillBuffer);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(PointFillBuffer).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(PointFillBuffer, [{
|
||||
key: "_buildFeatures",
|
||||
value: function _buildFeatures() {
|
||||
var _this = this;
|
||||
|
||||
var layerData = this.get('layerData');
|
||||
this._offset = 0;
|
||||
this._indexOffset = 0;
|
||||
layerData.forEach(function (feature) {
|
||||
_this._calculateFill(feature);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_initAttributes",
|
||||
value: function _initAttributes() {
|
||||
_get(_getPrototypeOf(PointFillBuffer.prototype), "_initAttributes", this).call(this);
|
||||
|
||||
this.attributes.miters = new Float32Array(this.verticesCount * 2);
|
||||
this.attributes.sizes = new Float32Array(this.verticesCount);
|
||||
this.attributes.shapes = new Float32Array(this.verticesCount);
|
||||
}
|
||||
}, {
|
||||
key: "_calculateFeatures",
|
||||
value: function _calculateFeatures() {
|
||||
var layerData = this.get('layerData');
|
||||
this.verticesCount = layerData.length * 4;
|
||||
this.indexCount = layerData.length * 6;
|
||||
}
|
||||
}, {
|
||||
key: "_calcultateGeometry",
|
||||
value: function _calcultateGeometry() {
|
||||
var shape = this.get('shapeType');
|
||||
var hexgonFill = this.getShapeFunction(shape)([this._getPoints(6)]);
|
||||
this.instanceGeometry = hexgonFill;
|
||||
}
|
||||
}, {
|
||||
key: "_calculateFill",
|
||||
value: function _calculateFill(feature) {
|
||||
var _this2 = this;
|
||||
|
||||
feature.bufferInfo = {
|
||||
verticesOffset: this._offset
|
||||
};
|
||||
var coordinates = feature.coordinates,
|
||||
shape = feature.shape;
|
||||
var shapeIndex = pointShape['2d'].indexOf(shape) || 0;
|
||||
var newCoord = coordinates;
|
||||
|
||||
if (coordinates.length === 1) {
|
||||
newCoord = coordinates[0][0];
|
||||
}
|
||||
|
||||
feature.bufferInfo = {
|
||||
verticesOffset: this._offset
|
||||
};
|
||||
|
||||
this._encodeArray(feature, 4);
|
||||
|
||||
this.attributes.shapes.set([shapeIndex, shapeIndex, shapeIndex, shapeIndex], this._offset);
|
||||
this.attributes.miters.set([-1, -1, 1, -1, 1, 1, -1, 1], this._offset * 2);
|
||||
var indexArray = [0, 1, 2, 0, 2, 3].map(function (n) {
|
||||
return n + _this2._offset;
|
||||
});
|
||||
this.indexArray.set(indexArray, this._offset * 1.5);
|
||||
var position = [];
|
||||
|
||||
for (var i = 0; i < 4; i++) {
|
||||
position.push.apply(position, _toConsumableArray(newCoord));
|
||||
}
|
||||
|
||||
this.attributes.positions.set(position, this._offset * 3);
|
||||
this._offset += 4;
|
||||
}
|
||||
}, {
|
||||
key: "_getPoints",
|
||||
value: function _getPoints(num) {
|
||||
return (0, shapePath.polygonPath)(num, 1);
|
||||
}
|
||||
}, {
|
||||
key: "getShape",
|
||||
value: function getShape(shape) {
|
||||
var pointShape = _global["default"].pointShape;
|
||||
|
||||
if (this.geometryMap[shape]) {
|
||||
return this.geometryMap[shape];
|
||||
}
|
||||
|
||||
var geometry = null;
|
||||
|
||||
if (pointShape['3d'].indexOf(shape) !== -1) {
|
||||
geometry = (0, _extrude.extrude_Polygon)([shapePath[shape]()]);
|
||||
} else if (pointShape['2d'].indexOf(shape) !== -1) {
|
||||
geometry = (0, _extrude.fillPolygon)([shapePath[shape]()]);
|
||||
} else {
|
||||
geometry = (0, _extrude.fillPolygon)([shapePath[shape]()]);
|
||||
}
|
||||
|
||||
this.geometryMap[shape] = geometry;
|
||||
return geometry;
|
||||
}
|
||||
}]);
|
||||
|
||||
return PointFillBuffer;
|
||||
}(_buffer["default"]);
|
||||
|
||||
exports["default"] = PointFillBuffer;
|
|
@ -1,48 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = ImageBuffer;
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
function ImageBuffer(layerData, opt) {
|
||||
var attributes = {
|
||||
vertices: [],
|
||||
colors: [],
|
||||
sizes: [],
|
||||
shapes: [],
|
||||
pickingIds: [],
|
||||
uv: []
|
||||
};
|
||||
layerData.forEach(function (item) {
|
||||
var _attributes$vertices, _attributes$colors;
|
||||
|
||||
var color = item.color,
|
||||
size = item.size,
|
||||
id = item.id,
|
||||
shape = item.shape,
|
||||
coordinates = item.coordinates;
|
||||
var _opt$imagePos$shape = opt.imagePos[shape],
|
||||
x = _opt$imagePos$shape.x,
|
||||
y = _opt$imagePos$shape.y;
|
||||
|
||||
(_attributes$vertices = attributes.vertices).push.apply(_attributes$vertices, _toConsumableArray(coordinates));
|
||||
|
||||
(_attributes$colors = attributes.colors).push.apply(_attributes$colors, _toConsumableArray(color));
|
||||
|
||||
attributes.pickingIds.push(id);
|
||||
attributes.sizes.push(size * window.devicePixelRatio); //
|
||||
|
||||
attributes.uv.push(x, y);
|
||||
attributes.shapes.push(shape);
|
||||
});
|
||||
return attributes;
|
||||
}
|
|
@ -1,48 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = ImageBuffer;
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
function ImageBuffer(layerData, opt) {
|
||||
var attributes = {
|
||||
vertices: [],
|
||||
colors: [],
|
||||
sizes: [],
|
||||
shapes: [],
|
||||
pickingIds: [],
|
||||
uv: []
|
||||
};
|
||||
layerData.forEach(function (item) {
|
||||
var _attributes$vertices, _attributes$colors;
|
||||
|
||||
var color = item.color,
|
||||
size = item.size,
|
||||
id = item.id,
|
||||
shape = item.shape,
|
||||
coordinates = item.coordinates;
|
||||
var _opt$imagePos$shape = opt.imagePos[shape],
|
||||
x = _opt$imagePos$shape.x,
|
||||
y = _opt$imagePos$shape.y;
|
||||
|
||||
(_attributes$vertices = attributes.vertices).push.apply(_attributes$vertices, _toConsumableArray(coordinates));
|
||||
|
||||
(_attributes$colors = attributes.colors).push.apply(_attributes$colors, _toConsumableArray(color));
|
||||
|
||||
attributes.pickingIds.push(id);
|
||||
attributes.sizes.push(size * window.devicePixelRatio); //
|
||||
|
||||
attributes.uv.push(x, y);
|
||||
attributes.shapes.push(shape);
|
||||
});
|
||||
return attributes;
|
||||
}
|
|
@ -1,47 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
Object.defineProperty(exports, "FillBuffer", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _fillBuffer["default"];
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "StrokeBuffer", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _strokeBuffer["default"];
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "ImageBuffer", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _image_buffer["default"];
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "NormalBuffer", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _normalBuffer["default"];
|
||||
}
|
||||
});
|
||||
Object.defineProperty(exports, "CircleBuffer", {
|
||||
enumerable: true,
|
||||
get: function get() {
|
||||
return _fill_buffer["default"];
|
||||
}
|
||||
});
|
||||
|
||||
var _fillBuffer = _interopRequireDefault(require("./fillBuffer"));
|
||||
|
||||
var _strokeBuffer = _interopRequireDefault(require("./strokeBuffer"));
|
||||
|
||||
var _image_buffer = _interopRequireDefault(require("./image_buffer"));
|
||||
|
||||
var _normalBuffer = _interopRequireDefault(require("./normalBuffer"));
|
||||
|
||||
var _fill_buffer = _interopRequireDefault(require("./fill_buffer"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
|
@ -1,39 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = NormalBuffer;
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
function NormalBuffer(layerData) {
|
||||
var attributes = {
|
||||
vertices: [],
|
||||
colors: [],
|
||||
sizes: [],
|
||||
pickingIds: []
|
||||
};
|
||||
layerData.forEach(function (item) {
|
||||
var _attributes$vertices, _attributes$colors;
|
||||
|
||||
var color = item.color,
|
||||
size = item.size,
|
||||
id = item.id,
|
||||
coordinates = item.coordinates;
|
||||
|
||||
(_attributes$vertices = attributes.vertices).push.apply(_attributes$vertices, _toConsumableArray(coordinates));
|
||||
|
||||
(_attributes$colors = attributes.colors).push.apply(_attributes$colors, _toConsumableArray(color));
|
||||
|
||||
attributes.pickingIds.push(id);
|
||||
attributes.sizes.push(size);
|
||||
});
|
||||
return attributes;
|
||||
}
|
|
@ -1,178 +0,0 @@
|
|||
// const SDFCommonWordsKey = '_AMap_sdf_com_words';
|
||||
// /**
|
||||
// * SDF 常用字获取/存储/check
|
||||
// *
|
||||
// */
|
||||
// const SDFCommonWords = {
|
||||
// store() {
|
||||
// },
|
||||
// /**
|
||||
// * 检查一个字符是否在常用字中
|
||||
// * @param {*} charcode 汉字
|
||||
// */
|
||||
// check(charcode) {
|
||||
// const range = this.range || [];
|
||||
// const info = this.info || {};
|
||||
// if (typeof charcode !== 'number') {
|
||||
// charcode = charcode.substr(0).charCodeAt(0);
|
||||
// }
|
||||
// for (let i = 0; i < range.length; i++) {
|
||||
// const curRange = range[i];
|
||||
// const [ rangeStart, rangeEnd ] = curRange.split('-');
|
||||
// if (charcode >= rangeStart && charcode <= rangeEnd) {
|
||||
// const curInfo = info[curRange] && info[curRange].info || {};
|
||||
// if (curInfo[charcode]) {
|
||||
// return true;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return false;
|
||||
// },
|
||||
// /**
|
||||
// * 获取纹理和位置信息
|
||||
// * @param list
|
||||
// * @param cb
|
||||
// */
|
||||
// getImagesAndInfo(list, cb) {
|
||||
// const range = this.range;
|
||||
// },
|
||||
// loadCanvas(url, range, done) {
|
||||
// try {
|
||||
// const xhr = new XMLHttpRequest();
|
||||
// xhr.open('GET', url);
|
||||
// // 直接用 blob 格式 load 图片文件,方便直接转换成 base64
|
||||
// // 转成 base64 便于存储
|
||||
// // 使用 canvas 转换 base64 容易有损
|
||||
// xhr.responseType = 'blob';
|
||||
// xhr.onerror = function() {
|
||||
// done({ code: 0 });
|
||||
// };
|
||||
// xhr.onload = function() {
|
||||
// if (xhr.status === 200) {
|
||||
// const reader = new FileReader();
|
||||
// reader.onload = () => {
|
||||
// done(reader.result, range);
|
||||
// };
|
||||
// reader.readAsDataURL(xhr.response);
|
||||
// } else {
|
||||
// done({ code: 0 });
|
||||
// }
|
||||
// };
|
||||
// xhr.send();
|
||||
// } catch (err) {
|
||||
// done({ code: 0 });
|
||||
// }
|
||||
// },
|
||||
// loadImages(urls = []) {
|
||||
// const deferred = $.Deferred();
|
||||
// const totalNumbers = urls.length;
|
||||
// const localInfo = this.info;
|
||||
// let loadPicNum = 0;
|
||||
// for (let i = 0; i < urls.length; i++) {
|
||||
// const { url, range } = urls[i];
|
||||
// this.loadCanvas(url, range, (base64, range) => {
|
||||
// // image to base64
|
||||
// loadPicNum++;
|
||||
// !localInfo[range] && (localInfo[range] = {});
|
||||
// localInfo[range].pic = base64;
|
||||
// this.info = localInfo;
|
||||
// // todo: temp 暂时用 localstorage 存储,因为数据比较大,最好使用 indexDB
|
||||
// localStorage.setItem(SDFCommonWordsKey, JSON.stringify(localInfo));
|
||||
// if (loadPicNum === totalNumbers) {
|
||||
// deferred.resolve();
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// return deferred;
|
||||
// },
|
||||
// loadInfo(urls) {
|
||||
// const deferred = $.Deferred();
|
||||
// const totalNumbers = urls.length;
|
||||
// const localInfo = this.info;
|
||||
// let loadInfoNum = 0;
|
||||
// for (let i = 0; i < urls.length; i++) {
|
||||
// const { url, range } = urls[i];
|
||||
// $.ajax({
|
||||
// url,
|
||||
// dataType: 'json',
|
||||
// success: data => {
|
||||
// loadInfoNum++;
|
||||
// !localInfo[range] && (localInfo[range] = {});
|
||||
// localInfo[range].info = data;
|
||||
// this.info = localInfo;
|
||||
// localStorage.setItem(SDFCommonWordsKey, JSON.stringify(localInfo));
|
||||
// if (loadInfoNum === totalNumbers) {
|
||||
// deferred.resolve();
|
||||
// }
|
||||
// },
|
||||
// error: () => {
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// return deferred;
|
||||
// },
|
||||
// getTotalAssets(info, cb) {
|
||||
// const { range = [], urlPrefix } = info;
|
||||
// const picUrls = [];
|
||||
// const infoUrls = [];
|
||||
// this.range = range;
|
||||
// for (let i = 0; i < range.length; i++) {
|
||||
// const curRange = range[i];
|
||||
// const baseUrl = urlPrefix + curRange;
|
||||
// const picUrl = baseUrl + '.png';
|
||||
// const infoUrl = baseUrl + '.json';
|
||||
// picUrls.push({ range: curRange, url: picUrl });
|
||||
// infoUrls.push({ range: curRange, url: infoUrl });
|
||||
// }
|
||||
// const imageDeferred = this.loadImages(picUrls);
|
||||
// const infoDeferred = this.loadInfo(infoUrls);
|
||||
// $.when(imageDeferred, infoDeferred)
|
||||
// .then(() => {
|
||||
// // all info load complete
|
||||
// // console.log("all info load complete", " -- ", 1);
|
||||
// cb && cb(this.info);
|
||||
// }, () => {
|
||||
// // fail
|
||||
// });
|
||||
// },
|
||||
// // 获取数据
|
||||
// getData(cb) {
|
||||
// if (!_.isEmpty(this.info)) {
|
||||
// cb && cb(this.info);
|
||||
// } else {
|
||||
// this.getRemoteData(cb);
|
||||
// }
|
||||
// },
|
||||
// /**
|
||||
// * 从服务获取数据,什么时候强制去取一回数据?过期?
|
||||
// * @param cb
|
||||
// */
|
||||
// getRemoteData(cb) {
|
||||
// const self = this;
|
||||
// $.ajax({
|
||||
// url: '/getcommonwords',
|
||||
// dataType: 'json',
|
||||
// success: data => {
|
||||
// if (data.code == 1) {
|
||||
// const info = data.data;
|
||||
// self.getTotalAssets(info, cb);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
// },
|
||||
// destroy() {
|
||||
// },
|
||||
// init() {
|
||||
// let info = localStorage.getItem(SDFCommonWordsKey);
|
||||
// this.range = [];
|
||||
// this.info = {};
|
||||
// if (info) {
|
||||
// info = JSON.parse(info);
|
||||
// this.range = Object.keys(info);
|
||||
// this.info = info;
|
||||
// }
|
||||
// this.info = info || {};
|
||||
// }
|
||||
// };
|
||||
// export default SDFCommonWords;
|
||||
"use strict";
|
|
@ -1,103 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = StrokeBuffer;
|
||||
|
||||
var polygonPath = _interopRequireWildcard(require("../../shape/path"));
|
||||
|
||||
var polygonShape = _interopRequireWildcard(require("../../shape/polygon"));
|
||||
|
||||
var lineShape = _interopRequireWildcard(require("../../shape/line"));
|
||||
|
||||
var _global = _interopRequireDefault(require("../../../global"));
|
||||
|
||||
var _util = _interopRequireDefault(require("../../../util"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
var pointShape = _global["default"].pointShape;
|
||||
|
||||
function StrokeBuffer(layerData, style) {
|
||||
var attribute = {
|
||||
shapes: [],
|
||||
normal: [],
|
||||
miter: [],
|
||||
indexArray: [],
|
||||
sizes: [],
|
||||
positions: [],
|
||||
pickingIds: [],
|
||||
colors: []
|
||||
};
|
||||
var stroke = style.stroke,
|
||||
strokeWidth = style.strokeWidth;
|
||||
layerData.forEach(function (item) {
|
||||
var size = item.size,
|
||||
shape = item.shape,
|
||||
id = item.id,
|
||||
coordinates = item.coordinates;
|
||||
var path = polygonPath[shape]();
|
||||
var positionsIndex = attribute.miter.length;
|
||||
var polygon = null;
|
||||
|
||||
if (pointShape['2d'].indexOf(shape) !== -1) {
|
||||
_util["default"].isArray(size) || (size = [size, size, 0]);
|
||||
polygon = lineShape.Line([path], {
|
||||
size: [strokeWidth, 0],
|
||||
color: stroke,
|
||||
id: id
|
||||
}, positionsIndex);
|
||||
} else if (pointShape['3d'].indexOf(shape) !== -1) {
|
||||
_util["default"].isArray(size) || (size = [size, size, size]);
|
||||
var polygonExtrudePath = polygonShape.extrudeline([path]); // TODO 3d line
|
||||
|
||||
polygon = lineShape.Line([polygonExtrudePath], {
|
||||
size: [strokeWidth, 0],
|
||||
color: stroke,
|
||||
id: id
|
||||
}, positionsIndex);
|
||||
} else {
|
||||
throw new Error('Invalid shape type: ' + shape);
|
||||
}
|
||||
|
||||
polygonLineBuffer(polygon, coordinates, size, attribute);
|
||||
});
|
||||
return attribute;
|
||||
}
|
||||
|
||||
function polygonLineBuffer(polygon, geo, size, attribute) {
|
||||
var _attribute$shapes, _attribute$normal, _attribute$miter, _attribute$pickingIds, _attribute$indexArray, _attribute$colors;
|
||||
|
||||
(_attribute$shapes = attribute.shapes).push.apply(_attribute$shapes, _toConsumableArray(polygon.positions));
|
||||
|
||||
(_attribute$normal = attribute.normal).push.apply(_attribute$normal, _toConsumableArray(polygon.normal));
|
||||
|
||||
(_attribute$miter = attribute.miter).push.apply(_attribute$miter, _toConsumableArray(polygon.miter));
|
||||
|
||||
(_attribute$pickingIds = attribute.pickingIds).push.apply(_attribute$pickingIds, _toConsumableArray(polygon.pickingIds));
|
||||
|
||||
(_attribute$indexArray = attribute.indexArray).push.apply(_attribute$indexArray, _toConsumableArray(polygon.indexArray));
|
||||
|
||||
(_attribute$colors = attribute.colors).push.apply(_attribute$colors, _toConsumableArray(polygon.colors));
|
||||
|
||||
polygon.miter.forEach(function () {
|
||||
var _attribute$positions, _attribute$sizes;
|
||||
|
||||
(_attribute$positions = attribute.positions).push.apply(_attribute$positions, _toConsumableArray(geo)); // 多边形位置
|
||||
|
||||
|
||||
(_attribute$sizes = attribute.sizes).push.apply(_attribute$sizes, _toConsumableArray(size)); // 多边形大小
|
||||
|
||||
});
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = TextBuffer;
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
function TextBuffer(layerData, fontAtlasManager) {
|
||||
var characterSet = [];
|
||||
layerData.forEach(function (element) {
|
||||
var text = element.shape || '';
|
||||
text = text.toString();
|
||||
|
||||
for (var j = 0; j < text.length; j++) {
|
||||
if (characterSet.indexOf(text[j]) === -1) {
|
||||
characterSet.push(text[j]);
|
||||
}
|
||||
}
|
||||
});
|
||||
fontAtlasManager.setProps({
|
||||
characterSet: characterSet
|
||||
});
|
||||
var attr = drawGlyph(layerData, fontAtlasManager);
|
||||
return attr;
|
||||
}
|
||||
|
||||
function drawGlyph(layerData, fontAtlasManager) {
|
||||
var attributes = {
|
||||
originPoints: [],
|
||||
textSizes: [],
|
||||
textOffsets: [],
|
||||
colors: [],
|
||||
textureElements: [],
|
||||
pickingIds: []
|
||||
};
|
||||
var texture = fontAtlasManager.texture,
|
||||
fontAtlas = fontAtlasManager.fontAtlas,
|
||||
mapping = fontAtlasManager.mapping,
|
||||
scale = fontAtlasManager.scale;
|
||||
layerData.forEach(function (element) {
|
||||
var size = element.size;
|
||||
var pos = element.coordinates;
|
||||
var text = element.shape || '';
|
||||
text = text.toString();
|
||||
var pen = {
|
||||
x: -text.length * size / 2,
|
||||
y: 0
|
||||
};
|
||||
|
||||
for (var i = 0; i < text.length; i++) {
|
||||
var _attributes$colors;
|
||||
|
||||
var metric = mapping[text[i]];
|
||||
var x = metric.x,
|
||||
y = metric.y,
|
||||
width = metric.width,
|
||||
height = metric.height;
|
||||
var color = element.color;
|
||||
var offsetX = pen.x;
|
||||
var offsetY = pen.y;
|
||||
attributes.pickingIds.push(element.id, element.id, element.id, element.id, element.id, element.id);
|
||||
attributes.textOffsets.push( // 文字在词语的偏移量
|
||||
offsetX, offsetY, offsetX, offsetY, offsetX, offsetY, offsetX, offsetY, offsetX, offsetY, offsetX, offsetY);
|
||||
attributes.originPoints.push( // 词语的经纬度坐标
|
||||
pos[0], pos[1], 0, pos[0], pos[1], 0, pos[0], pos[1], 0, pos[0], pos[1], 0, pos[0], pos[1], 0, pos[0], pos[1], 0);
|
||||
attributes.textSizes.push(size, size * scale, 0, size * scale, 0, 0, size, size * scale, 0, 0, size, 0);
|
||||
|
||||
(_attributes$colors = attributes.colors).push.apply(_attributes$colors, _toConsumableArray(color).concat(_toConsumableArray(color), _toConsumableArray(color), _toConsumableArray(color), _toConsumableArray(color), _toConsumableArray(color)));
|
||||
|
||||
attributes.textureElements.push( // 文字纹理坐标
|
||||
x + width, y, x, y, x, y + height, x + width, y, x, y + height, x + width, y + height);
|
||||
pen.x = pen.x + size;
|
||||
}
|
||||
});
|
||||
attributes.texture = texture;
|
||||
attributes.fontAtlas = fontAtlas;
|
||||
return attributes;
|
||||
}
|
|
@ -1,326 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = exports.DEFAULT_RADIUS = exports.DEFAULT_CUTOFF = exports.DEFAULT_BUFFER = exports.DEFAULT_FONT_SIZE = exports.DEFAULT_FONT_WEIGHT = exports.DEFAULT_FONT_FAMILY = exports.DEFAULT_CHAR_SET = void 0;
|
||||
|
||||
var _tinySdf = _interopRequireDefault(require("@mapbox/tiny-sdf"));
|
||||
|
||||
var _fontUtil = require("../../../../util/font-util");
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../../../../core/three"));
|
||||
|
||||
var _lruCache = _interopRequireDefault(require("./lru-cache"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
var DEFAULT_CHAR_SET = getDefaultCharacterSet();
|
||||
exports.DEFAULT_CHAR_SET = DEFAULT_CHAR_SET;
|
||||
var DEFAULT_FONT_FAMILY = 'sans-serif';
|
||||
exports.DEFAULT_FONT_FAMILY = DEFAULT_FONT_FAMILY;
|
||||
var DEFAULT_FONT_WEIGHT = 'normal';
|
||||
exports.DEFAULT_FONT_WEIGHT = DEFAULT_FONT_WEIGHT;
|
||||
var DEFAULT_FONT_SIZE = 24;
|
||||
exports.DEFAULT_FONT_SIZE = DEFAULT_FONT_SIZE;
|
||||
var DEFAULT_BUFFER = 3;
|
||||
exports.DEFAULT_BUFFER = DEFAULT_BUFFER;
|
||||
var DEFAULT_CUTOFF = 0.25;
|
||||
exports.DEFAULT_CUTOFF = DEFAULT_CUTOFF;
|
||||
var DEFAULT_RADIUS = 8;
|
||||
exports.DEFAULT_RADIUS = DEFAULT_RADIUS;
|
||||
var MAX_CANVAS_WIDTH = 1024;
|
||||
var BASELINE_SCALE = 0.9;
|
||||
var HEIGHT_SCALE = 1.2;
|
||||
var CACHE_LIMIT = 3;
|
||||
var cache = new _lruCache["default"](CACHE_LIMIT);
|
||||
var VALID_PROPS = ['fontFamily', 'fontWeight', 'characterSet', 'fontSize', 'sdf', 'buffer', 'cutoff', 'radius'];
|
||||
|
||||
function getDefaultCharacterSet() {
|
||||
var charSet = [];
|
||||
|
||||
for (var i = 32; i < 128; i++) {
|
||||
charSet.push(String.fromCharCode(i));
|
||||
}
|
||||
|
||||
return charSet;
|
||||
}
|
||||
|
||||
function setTextStyle(ctx, fontFamily, fontSize, fontWeight) {
|
||||
ctx.font = "".concat(fontWeight, " ").concat(fontSize, "px ").concat(fontFamily);
|
||||
ctx.fillStyle = '#000';
|
||||
ctx.textBaseline = 'baseline';
|
||||
ctx.textAlign = 'left';
|
||||
}
|
||||
|
||||
function getNewChars(key, characterSet) {
|
||||
var cachedFontAtlas = cache.get(key);
|
||||
|
||||
if (!cachedFontAtlas) {
|
||||
return characterSet;
|
||||
}
|
||||
|
||||
var newChars = [];
|
||||
var cachedMapping = cachedFontAtlas.mapping;
|
||||
var cachedCharSet = Object.keys(cachedMapping);
|
||||
cachedCharSet = new Set(cachedCharSet);
|
||||
var charSet = characterSet;
|
||||
|
||||
if (charSet instanceof Array) {
|
||||
charSet = new Set(charSet);
|
||||
}
|
||||
|
||||
charSet.forEach(function (_char) {
|
||||
if (!cachedCharSet.has(_char)) {
|
||||
newChars.push(_char);
|
||||
}
|
||||
});
|
||||
return newChars;
|
||||
}
|
||||
|
||||
function populateAlphaChannel(alphaChannel, imageData) {
|
||||
// populate distance value from tinySDF to image alpha channel
|
||||
for (var i = 0; i < alphaChannel.length; i++) {
|
||||
imageData.data[4 * i + 3] = alphaChannel[i];
|
||||
}
|
||||
}
|
||||
|
||||
var FontAtlasManager =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function FontAtlasManager() {
|
||||
_classCallCheck(this, FontAtlasManager);
|
||||
|
||||
// font settings
|
||||
this.props = {
|
||||
fontFamily: DEFAULT_FONT_FAMILY,
|
||||
fontWeight: DEFAULT_FONT_WEIGHT,
|
||||
characterSet: DEFAULT_CHAR_SET,
|
||||
fontSize: DEFAULT_FONT_SIZE,
|
||||
buffer: DEFAULT_BUFFER,
|
||||
// sdf only props
|
||||
// https://github.com/mapbox/tiny-sdf
|
||||
sdf: true,
|
||||
cutoff: DEFAULT_CUTOFF,
|
||||
radius: DEFAULT_RADIUS
|
||||
}; // key is used for caching generated fontAtlas
|
||||
|
||||
this._key = null;
|
||||
this._texture = new THREE.Texture();
|
||||
}
|
||||
|
||||
_createClass(FontAtlasManager, [{
|
||||
key: "setProps",
|
||||
value: function setProps() {
|
||||
var _this = this;
|
||||
|
||||
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
||||
VALID_PROPS.forEach(function (prop) {
|
||||
if (prop in props) {
|
||||
_this.props[prop] = props[prop];
|
||||
}
|
||||
}); // update cache key
|
||||
|
||||
var oldKey = this._key;
|
||||
this._key = this._getKey();
|
||||
var charSet = getNewChars(this._key, this.props.characterSet);
|
||||
var cachedFontAtlas = cache.get(this._key); // if a fontAtlas associated with the new settings is cached and
|
||||
// there are no new chars
|
||||
|
||||
if (cachedFontAtlas && charSet.length === 0) {
|
||||
// update texture with cached fontAtlas
|
||||
if (this._key !== oldKey) {
|
||||
this._updateTexture(cachedFontAtlas);
|
||||
}
|
||||
|
||||
return;
|
||||
} // update fontAtlas with new settings
|
||||
|
||||
|
||||
var fontAtlas = this._generateFontAtlas(this._key, charSet, cachedFontAtlas);
|
||||
|
||||
this._fontAtlas = fontAtlas;
|
||||
|
||||
this._updateTexture(fontAtlas); // update cache
|
||||
|
||||
|
||||
cache.set(this._key, fontAtlas);
|
||||
}
|
||||
}, {
|
||||
key: "_updateTexture",
|
||||
value: function _updateTexture(_ref) {
|
||||
var canvas = _ref.data;
|
||||
this._texture = new THREE.CanvasTexture(canvas);
|
||||
this._texture.wrapS = THREE.ClampToEdgeWrapping;
|
||||
this._texture.wrapT = THREE.ClampToEdgeWrapping;
|
||||
this._texture.minFilter = THREE.LinearFilter;
|
||||
this._texture.flipY = false;
|
||||
this._texture.needUpdate = true;
|
||||
}
|
||||
}, {
|
||||
key: "_generateFontAtlas",
|
||||
value: function _generateFontAtlas(key, characterSet, cachedFontAtlas) {
|
||||
var _this$props = this.props,
|
||||
fontFamily = _this$props.fontFamily,
|
||||
fontWeight = _this$props.fontWeight,
|
||||
fontSize = _this$props.fontSize,
|
||||
buffer = _this$props.buffer,
|
||||
sdf = _this$props.sdf,
|
||||
radius = _this$props.radius,
|
||||
cutoff = _this$props.cutoff;
|
||||
var canvas = cachedFontAtlas && cachedFontAtlas.data;
|
||||
|
||||
if (!canvas) {
|
||||
canvas = document.createElement('canvas');
|
||||
canvas.width = MAX_CANVAS_WIDTH;
|
||||
}
|
||||
|
||||
var ctx = canvas.getContext('2d');
|
||||
setTextStyle(ctx, fontFamily, fontSize, fontWeight); // 1. build mapping
|
||||
|
||||
var _buildMapping = (0, _fontUtil.buildMapping)(Object.assign({
|
||||
getFontWidth: function getFontWidth(_char2) {
|
||||
return ctx.measureText(_char2).width;
|
||||
},
|
||||
fontHeight: fontSize * HEIGHT_SCALE,
|
||||
buffer: buffer,
|
||||
characterSet: characterSet,
|
||||
maxCanvasWidth: MAX_CANVAS_WIDTH
|
||||
}, cachedFontAtlas && {
|
||||
mapping: cachedFontAtlas.mapping,
|
||||
xOffset: cachedFontAtlas.xOffset,
|
||||
yOffset: cachedFontAtlas.yOffset
|
||||
})),
|
||||
mapping = _buildMapping.mapping,
|
||||
canvasHeight = _buildMapping.canvasHeight,
|
||||
xOffset = _buildMapping.xOffset,
|
||||
yOffset = _buildMapping.yOffset; // 2. update canvas
|
||||
// copy old canvas data to new canvas only when height changed
|
||||
|
||||
|
||||
if (canvas.height !== canvasHeight) {
|
||||
var imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
||||
canvas.height = canvasHeight;
|
||||
ctx.putImageData(imageData, 0, 0);
|
||||
}
|
||||
|
||||
setTextStyle(ctx, fontFamily, fontSize, fontWeight); // 3. layout characters
|
||||
|
||||
if (sdf) {
|
||||
var tinySDF = new _tinySdf["default"](fontSize, buffer, radius, cutoff, fontFamily, fontWeight); // used to store distance values from tinySDF
|
||||
// tinySDF.size equals `fontSize + buffer * 2`
|
||||
|
||||
var _imageData = ctx.getImageData(0, 0, tinySDF.size, tinySDF.size);
|
||||
|
||||
var _iteratorNormalCompletion = true;
|
||||
var _didIteratorError = false;
|
||||
var _iteratorError = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator = characterSet[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
|
||||
var _char3 = _step.value;
|
||||
populateAlphaChannel(tinySDF.draw(_char3), _imageData);
|
||||
ctx.putImageData(_imageData, mapping[_char3].x - buffer, mapping[_char3].y - buffer);
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError = true;
|
||||
_iteratorError = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion && _iterator["return"] != null) {
|
||||
_iterator["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError) {
|
||||
throw _iteratorError;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
var _iteratorNormalCompletion2 = true;
|
||||
var _didIteratorError2 = false;
|
||||
var _iteratorError2 = undefined;
|
||||
|
||||
try {
|
||||
for (var _iterator2 = characterSet[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
|
||||
var _char4 = _step2.value;
|
||||
ctx.fillText(_char4, mapping[_char4].x, mapping[_char4].y + fontSize * BASELINE_SCALE);
|
||||
}
|
||||
} catch (err) {
|
||||
_didIteratorError2 = true;
|
||||
_iteratorError2 = err;
|
||||
} finally {
|
||||
try {
|
||||
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) {
|
||||
_iterator2["return"]();
|
||||
}
|
||||
} finally {
|
||||
if (_didIteratorError2) {
|
||||
throw _iteratorError2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
xOffset: xOffset,
|
||||
yOffset: yOffset,
|
||||
mapping: mapping,
|
||||
data: canvas,
|
||||
width: canvas.width,
|
||||
height: canvas.height
|
||||
};
|
||||
}
|
||||
}, {
|
||||
key: "_getKey",
|
||||
value: function _getKey() {
|
||||
var _this$props2 = this.props,
|
||||
fontFamily = _this$props2.fontFamily,
|
||||
fontWeight = _this$props2.fontWeight,
|
||||
fontSize = _this$props2.fontSize,
|
||||
buffer = _this$props2.buffer,
|
||||
sdf = _this$props2.sdf,
|
||||
radius = _this$props2.radius,
|
||||
cutoff = _this$props2.cutoff;
|
||||
|
||||
if (sdf) {
|
||||
return "".concat(fontFamily, " ").concat(fontWeight, " ").concat(fontSize, " ").concat(buffer, " ").concat(radius, " ").concat(cutoff);
|
||||
}
|
||||
|
||||
return "".concat(fontFamily, " ").concat(fontWeight, " ").concat(fontSize, " ").concat(buffer);
|
||||
}
|
||||
}, {
|
||||
key: "texture",
|
||||
get: function get() {
|
||||
return this._texture;
|
||||
}
|
||||
}, {
|
||||
key: "mapping",
|
||||
get: function get() {
|
||||
var data = cache.get(this._key);
|
||||
return data && data.mapping;
|
||||
}
|
||||
}, {
|
||||
key: "scale",
|
||||
get: function get() {
|
||||
return HEIGHT_SCALE;
|
||||
}
|
||||
}, {
|
||||
key: "fontAtlas",
|
||||
get: function get() {
|
||||
return this._fontAtlas;
|
||||
}
|
||||
}]);
|
||||
|
||||
return FontAtlasManager;
|
||||
}();
|
||||
|
||||
exports["default"] = FontAtlasManager;
|
|
@ -1,110 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
/**
|
||||
* LRU Cache class with limit
|
||||
*
|
||||
* Update order for each get/set operation
|
||||
* Delete oldest when reach given limit
|
||||
*/
|
||||
var LRUCache =
|
||||
/*#__PURE__*/
|
||||
function () {
|
||||
function LRUCache() {
|
||||
var limit = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 5;
|
||||
|
||||
_classCallCheck(this, LRUCache);
|
||||
|
||||
this.limit = limit;
|
||||
this.clear();
|
||||
}
|
||||
|
||||
_createClass(LRUCache, [{
|
||||
key: "clear",
|
||||
value: function clear() {
|
||||
this._cache = {}; // access/update order, first item is oldest, last item is newest
|
||||
|
||||
this._order = [];
|
||||
}
|
||||
}, {
|
||||
key: "get",
|
||||
value: function get(key) {
|
||||
var value = this._cache[key];
|
||||
|
||||
if (value) {
|
||||
// update order
|
||||
this._deleteOrder(key);
|
||||
|
||||
this._appendOrder(key);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}, {
|
||||
key: "set",
|
||||
value: function set(key, value) {
|
||||
if (!this._cache[key]) {
|
||||
// if reach limit, delete the oldest
|
||||
if (Object.keys(this._cache).length === this.limit) {
|
||||
this["delete"](this._order[0]);
|
||||
}
|
||||
|
||||
this._cache[key] = value;
|
||||
|
||||
this._appendOrder(key);
|
||||
} else {
|
||||
// if found in cache, delete the old one, insert new one to the first of list
|
||||
this["delete"](key);
|
||||
this._cache[key] = value;
|
||||
|
||||
this._appendOrder(key);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "delete",
|
||||
value: function _delete(key) {
|
||||
var value = this._cache[key];
|
||||
|
||||
if (value) {
|
||||
this._deleteCache(key);
|
||||
|
||||
this._deleteOrder(key);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "_deleteCache",
|
||||
value: function _deleteCache(key) {
|
||||
delete this._cache[key];
|
||||
}
|
||||
}, {
|
||||
key: "_deleteOrder",
|
||||
value: function _deleteOrder(key) {
|
||||
var index = this._order.findIndex(function (o) {
|
||||
return o === key;
|
||||
});
|
||||
|
||||
if (index >= 0) {
|
||||
this._order.splice(index, 1);
|
||||
}
|
||||
}
|
||||
}, {
|
||||
key: "_appendOrder",
|
||||
value: function _appendOrder(key) {
|
||||
this._order.push(key);
|
||||
}
|
||||
}]);
|
||||
|
||||
return LRUCache;
|
||||
}();
|
||||
|
||||
exports["default"] = LRUCache;
|
|
@ -1,172 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = TextBuffer;
|
||||
|
||||
var _ajax = require("../../../util/ajax");
|
||||
|
||||
var _wolfy87Eventemitter = _interopRequireDefault(require("wolfy87-eventemitter"));
|
||||
|
||||
var _global = _interopRequireDefault(require("../../../global"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
// const Space = 1;
|
||||
var metrics = {
|
||||
buffer: 3,
|
||||
family: 'ios9',
|
||||
size: 24
|
||||
};
|
||||
|
||||
function TextBuffer(layerData, style) {
|
||||
var _this = this;
|
||||
|
||||
_wolfy87Eventemitter.default.call(this);
|
||||
|
||||
var attributes = {
|
||||
originPoints: [],
|
||||
textSizes: [],
|
||||
textOffsets: [],
|
||||
colors: [],
|
||||
textureElements: []
|
||||
};
|
||||
var _style$textOffset = style.textOffset,
|
||||
textOffset = _style$textOffset === void 0 ? [0, 0] : _style$textOffset;
|
||||
var chars = [];
|
||||
var textChars = {};
|
||||
layerData.forEach(function (element) {
|
||||
var text = element.shape || '';
|
||||
text = text.toString();
|
||||
|
||||
for (var j = 0; j < text.length; j++) {
|
||||
var code = text.charCodeAt(j);
|
||||
textChars[text] = 0;
|
||||
|
||||
if (chars.indexOf(code) === -1) {
|
||||
chars.push(text.charCodeAt(j));
|
||||
}
|
||||
}
|
||||
});
|
||||
loadTextInfo(chars, function (chars, texture) {
|
||||
layerData.forEach(function (element) {
|
||||
var size = element.size;
|
||||
var pos = layerData.coordinates;
|
||||
var pen = {
|
||||
x: textOffset[0],
|
||||
y: textOffset[1]
|
||||
};
|
||||
var text = element.shape || '';
|
||||
text = text.toString();
|
||||
|
||||
for (var i = 0; i < text.length; i++) {
|
||||
var color = element.color;
|
||||
drawGlyph(chars, pos, text[i], pen, size, attributes.colors, attributes.textureElements, attributes.originPoints, attributes.textSizes, attributes.textOffsets, color);
|
||||
}
|
||||
|
||||
_this.emit('completed', {
|
||||
attributes: attributes,
|
||||
texture: texture
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function loadTextInfo(chars, done) {
|
||||
(0, _ajax.getJSON)({
|
||||
url: "".concat(_global.default.sdfHomeUrl, "/getsdfdata?chars=").concat(chars.join('|'))
|
||||
}, function (e, info) {
|
||||
loadTextTexture(info.url, function (texture) {
|
||||
done(info.info, texture);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function loadTextTexture(url, cb) {
|
||||
var _this2 = this;
|
||||
|
||||
var img = new Image();
|
||||
img.crossOrigin = 'anonymous';
|
||||
|
||||
img.onload = function () {
|
||||
var textTexture = _this2._creatTexture(img);
|
||||
|
||||
cb(textTexture);
|
||||
};
|
||||
|
||||
img.src = url;
|
||||
}
|
||||
/**
|
||||
* 计算每个标注词语的位置
|
||||
* @param {*} chars 文本信息
|
||||
* @param {*} pos 文字三维空间坐标
|
||||
* @param {*} text 字符
|
||||
* @param {*} pen 字符在词语的偏移量
|
||||
* @param {*} size 字体大小
|
||||
* @param {*} colors 颜色
|
||||
* @param {*} textureElements 纹理坐标
|
||||
* @param {*} originPoints 初始位置数据
|
||||
* @param {*} textSizes 文字大小数组
|
||||
* @param {*} textOffsets 字体偏移量数据
|
||||
* @param {*} color 文字颜色
|
||||
*/
|
||||
|
||||
|
||||
function drawGlyph(chars, pos, text, pen, size, colors, textureElements, originPoints, textSizes, textOffsets, color) {
|
||||
var chr = text.charCodeAt(0);
|
||||
var metric = chars[chr];
|
||||
if (!metric) return;
|
||||
var scale = size / metrics.size;
|
||||
var width = metric[0];
|
||||
var height = metric[1];
|
||||
var posX = metric[5];
|
||||
var posY = metric[6];
|
||||
var buffer = metrics.buffer;
|
||||
|
||||
if (width > 0 && height > 0) {
|
||||
width += buffer * 2;
|
||||
height += buffer * 2;
|
||||
var originX = 0;
|
||||
var originY = 0;
|
||||
var offsetX = pen.x;
|
||||
var offsetY = pen.y;
|
||||
originPoints.push(pos[0] + originX, pos[1] + originY, 0, pos[0] + originX, pos[1] + originY, 0, pos[0] + originX, pos[1] + originY, 0, pos[0] + originX, pos[1] + originY, 0, pos[0] + originX, pos[1] + originY, 0, pos[0] + originX, pos[1] + originY, 0);
|
||||
var bx = 0;
|
||||
var by = metrics.size / 2 + buffer;
|
||||
textSizes.push((bx - buffer + width) * scale, (height - by) * scale, (bx - buffer) * scale, (height - by) * scale, (bx - buffer) * scale, -by * scale, (bx - buffer + width) * scale, (height - by) * scale, (bx - buffer) * scale, -by * scale, (bx - buffer + width) * scale, -by * scale);
|
||||
textOffsets.push(offsetX, offsetY, offsetX, offsetY, offsetX, offsetY, offsetX, offsetY, offsetX, offsetY, offsetX, offsetY);
|
||||
colors.push.apply(colors, _toConsumableArray(color).concat(_toConsumableArray(color), _toConsumableArray(color), _toConsumableArray(color), _toConsumableArray(color), _toConsumableArray(color)));
|
||||
textureElements.push(posX + width, posY, posX, posY, posX, posY + height, posX + width, posY, posX, posY + height, posX + width, posY + height);
|
||||
}
|
||||
|
||||
pen.x = pen.x + size * 1.8;
|
||||
} // function measureText(text, size) {
|
||||
// const dimensions = {
|
||||
// advance: 0
|
||||
// };
|
||||
// const metrics = this.metrics;
|
||||
// const scale = size / metrics.size;
|
||||
// for (let i = 0; i < text.length; i++) {
|
||||
// const code = text.charCodeAt(i);
|
||||
// const horiAdvance = metrics.chars[code][4];
|
||||
// dimensions.advance += (horiAdvance + Space) * scale;
|
||||
// }
|
||||
// return dimensions;
|
||||
// }
|
||||
// function creatTexture(image) {
|
||||
// this.bufferStruct.textSize = [ image.width, image.height ];
|
||||
// const texture = new THREE.Texture(image);
|
||||
// texture.minFilter = THREE.LinearFilter;
|
||||
// texture.magFilter = THREE.ClampToEdgeWrapping;
|
||||
// texture.needsUpdate = true;
|
||||
// return texture;
|
||||
// }
|
|
@ -1,91 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _index = require("../shape/index");
|
||||
|
||||
var _bufferBase = _interopRequireDefault(require("./bufferBase"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var polygonLineBuffer =
|
||||
/*#__PURE__*/
|
||||
function (_BufferBase) {
|
||||
_inherits(polygonLineBuffer, _BufferBase);
|
||||
|
||||
function polygonLineBuffer() {
|
||||
_classCallCheck(this, polygonLineBuffer);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(polygonLineBuffer).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(polygonLineBuffer, [{
|
||||
key: "geometryBuffer",
|
||||
value: function geometryBuffer() {
|
||||
var coordinates = this.get('coordinates');
|
||||
var properties = this.get('properties');
|
||||
var shape = this.get('shape');
|
||||
var positions = [];
|
||||
var positionsIndex = [];
|
||||
var vertsCount = 0;
|
||||
this.bufferStruct.style = properties;
|
||||
var isExtrude = properties[0].hasOwnProperty('size');
|
||||
coordinates.forEach(function (geo, index) {
|
||||
var heightValue = properties[index].size;
|
||||
var extrudeData = [];
|
||||
|
||||
if (isExtrude && shape === 'extrudeline') {
|
||||
extrudeData = _index.polygonShape.extrudeline(geo);
|
||||
extrudeData.positions = extrudeData.positions.map(function (pos) {
|
||||
pos[2] *= heightValue;
|
||||
return pos;
|
||||
});
|
||||
} else {
|
||||
extrudeData = _index.polygonShape.line(geo);
|
||||
}
|
||||
|
||||
positions.push(extrudeData.positions);
|
||||
positionsIndex.push.apply(positionsIndex, _toConsumableArray(extrudeData.positionsIndex.map(function (index) {
|
||||
return index + vertsCount;
|
||||
})));
|
||||
vertsCount += extrudeData.positions.length;
|
||||
});
|
||||
this.bufferStruct.indexs = positionsIndex;
|
||||
this.bufferStruct.verts = positions;
|
||||
this.bufferStruct.vertsCount = vertsCount;
|
||||
}
|
||||
}]);
|
||||
|
||||
return polygonLineBuffer;
|
||||
}(_bufferBase["default"]);
|
||||
|
||||
exports["default"] = polygonLineBuffer;
|
|
@ -1,112 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _shape = require("../shape");
|
||||
|
||||
var _bufferBase = _interopRequireDefault(require("./bufferBase"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var PolygonBuffer =
|
||||
/*#__PURE__*/
|
||||
function (_BufferBase) {
|
||||
_inherits(PolygonBuffer, _BufferBase);
|
||||
|
||||
function PolygonBuffer() {
|
||||
_classCallCheck(this, PolygonBuffer);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(PolygonBuffer).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(PolygonBuffer, [{
|
||||
key: "geometryBuffer",
|
||||
value: function geometryBuffer() {
|
||||
var layerData = this.get('layerData');
|
||||
var shape = this.get('shape');
|
||||
var positions = [];
|
||||
var faceUv = [];
|
||||
var sizes = [];
|
||||
var positionsIndex = [];
|
||||
var indexCount = 0;
|
||||
this.bufferStruct.style = layerData;
|
||||
var isExtrude = layerData[0].hasOwnProperty('size'); // indices, normals, colors, UVs
|
||||
|
||||
layerData.forEach(function (item) {
|
||||
var heightValue = item.size;
|
||||
|
||||
var extrudeData = _shape.polygonShape[shape](item.coordinates);
|
||||
|
||||
if (isExtrude && shape === 'extrude') {
|
||||
extrudeData = _shape.polygonShape.extrude(item.coordinates);
|
||||
extrudeData.positions = extrudeData.positions.map(function (pos) {
|
||||
pos[2] *= heightValue;
|
||||
return pos;
|
||||
});
|
||||
}
|
||||
|
||||
positions.push(extrudeData.positions);
|
||||
|
||||
if (shape !== 'line') {
|
||||
// faceUv.push(...extrudeData.faceUv);
|
||||
var count = extrudeData.faceUv.length / 2;
|
||||
|
||||
for (var i = 0; i < count; i++) {
|
||||
// uv 系数生成等大小的窗户
|
||||
var x = extrudeData.faceUv[i * 2];
|
||||
var y = extrudeData.faceUv[i * 2 + 1];
|
||||
|
||||
if (x !== -1) {
|
||||
x = x * 0.1;
|
||||
y = y * heightValue / 2000;
|
||||
}
|
||||
|
||||
faceUv.push(x, y);
|
||||
sizes.push((1.0 - extrudeData.faceUv[i * 2 + 1]) * heightValue);
|
||||
}
|
||||
}
|
||||
|
||||
indexCount += extrudeData.positionsIndex.length;
|
||||
positionsIndex.push(extrudeData.positionsIndex);
|
||||
});
|
||||
this.bufferStruct.indices = positionsIndex;
|
||||
this.bufferStruct.position = positions;
|
||||
this.bufferStruct.indexCount = indexCount;
|
||||
this.bufferStruct.style = layerData;
|
||||
this.bufferStruct.faceUv = faceUv;
|
||||
this.bufferStruct.sizes = sizes;
|
||||
|
||||
if (shape !== 'line') {
|
||||
this.attributes = this._toPolygonAttributes(this.bufferStruct);
|
||||
this.faceTexture = this._generateTexture();
|
||||
} else {
|
||||
this.attributes = this._toPolygonLineAttributes(this.bufferStruct);
|
||||
}
|
||||
}
|
||||
}]);
|
||||
|
||||
return PolygonBuffer;
|
||||
}(_bufferBase["default"]);
|
||||
|
||||
exports["default"] = PolygonBuffer;
|
|
@ -1,121 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _buffer = _interopRequireDefault(require("../buffer"));
|
||||
|
||||
var _earcut = _interopRequireDefault(require("earcut"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var ExtrudeButffer =
|
||||
/*#__PURE__*/
|
||||
function (_BufferBase) {
|
||||
_inherits(ExtrudeButffer, _BufferBase);
|
||||
|
||||
function ExtrudeButffer() {
|
||||
_classCallCheck(this, ExtrudeButffer);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(ExtrudeButffer).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(ExtrudeButffer, [{
|
||||
key: "_buildFeatures",
|
||||
value: function _buildFeatures() {
|
||||
var _this = this;
|
||||
|
||||
var layerData = this.get('layerData');
|
||||
layerData.forEach(function (feature) {
|
||||
_this._calculateTop(feature);
|
||||
|
||||
_this._calculateWall(feature);
|
||||
|
||||
delete feature.bufferInfo;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_calculateFeatures",
|
||||
value: function _calculateFeatures() {
|
||||
var _this2 = this;
|
||||
|
||||
var layerData = this.get('layerData'); // 计算长
|
||||
|
||||
layerData.forEach(function (feature) {
|
||||
var coordinates = feature.coordinates;
|
||||
var bufferInfo = {};
|
||||
|
||||
var flattengeo = _earcut["default"].flatten(coordinates);
|
||||
|
||||
var n = _this2.checkIsClosed(coordinates[0]) ? coordinates[0].length - 1 : coordinates[0].length;
|
||||
var vertices = flattengeo.vertices,
|
||||
dimensions = flattengeo.dimensions,
|
||||
holes = flattengeo.holes;
|
||||
var indexArray = (0, _earcut["default"])(vertices, holes, dimensions).map(function (v) {
|
||||
return _this2.verticesCount + v;
|
||||
});
|
||||
bufferInfo.vertices = vertices;
|
||||
bufferInfo.indexArray = indexArray;
|
||||
bufferInfo.verticesOffset = _this2.verticesCount + 0;
|
||||
bufferInfo.indexOffset = _this2.indexCount + 0;
|
||||
bufferInfo.faceNum = n;
|
||||
_this2.indexCount += indexArray.length + n * 6;
|
||||
_this2.verticesCount += vertices.length / 3 + n * 4;
|
||||
feature.bufferInfo = bufferInfo;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_calculateTop",
|
||||
value: function _calculateTop(feature) {
|
||||
var size = feature.size;
|
||||
var _feature$bufferInfo = feature.bufferInfo,
|
||||
indexArray = _feature$bufferInfo.indexArray,
|
||||
vertices = _feature$bufferInfo.vertices,
|
||||
indexOffset = _feature$bufferInfo.indexOffset,
|
||||
verticesOffset = _feature$bufferInfo.verticesOffset;
|
||||
var pointCount = vertices.length / 3;
|
||||
|
||||
this._encodeArray(feature, vertices.length / 3); // 添加顶点
|
||||
|
||||
|
||||
for (var i = 0; i < pointCount; i++) {
|
||||
this.attributes.positions.set([vertices[i * 3], vertices[i * 3 + 1], size], (verticesOffset + i) * 3); // 顶部文理坐标计算
|
||||
|
||||
if (this.get('uv')) {
|
||||
// TODO 用过BBox计算纹理坐标
|
||||
this.attributes.uv.set([-1, -1], (verticesOffset + i) * 2);
|
||||
}
|
||||
}
|
||||
|
||||
feature.bufferInfo.verticesOffset += pointCount; // 添加顶点索引
|
||||
|
||||
this.indexArray.set(indexArray, indexOffset); // 顶部坐标
|
||||
|
||||
feature.bufferInfo.indexOffset += indexArray.length;
|
||||
}
|
||||
}]);
|
||||
|
||||
return ExtrudeButffer;
|
||||
}(_buffer["default"]);
|
||||
|
||||
exports["default"] = ExtrudeButffer;
|
|
@ -1,116 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _buffer = _interopRequireDefault(require("../buffer"));
|
||||
|
||||
var _earcut = _interopRequireDefault(require("earcut"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var FillBuffer =
|
||||
/*#__PURE__*/
|
||||
function (_BufferBase) {
|
||||
_inherits(FillBuffer, _BufferBase);
|
||||
|
||||
function FillBuffer() {
|
||||
_classCallCheck(this, FillBuffer);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(FillBuffer).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(FillBuffer, [{
|
||||
key: "_buildFeatures",
|
||||
value: function _buildFeatures() {
|
||||
var _this = this;
|
||||
|
||||
var layerData = this.get('layerData');
|
||||
layerData.forEach(function (feature) {
|
||||
_this._calculateFill(feature);
|
||||
|
||||
delete feature.bufferInfo;
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_calculateFill",
|
||||
value: function _calculateFill(feature) {
|
||||
var _feature$bufferInfo = feature.bufferInfo,
|
||||
indexArray = _feature$bufferInfo.indexArray,
|
||||
vertices = _feature$bufferInfo.vertices,
|
||||
indexOffset = _feature$bufferInfo.indexOffset,
|
||||
verticesOffset = _feature$bufferInfo.verticesOffset;
|
||||
var pointCount = vertices.length / 3;
|
||||
|
||||
this._encodeArray(feature, vertices.length / 3); // 添加顶点
|
||||
|
||||
|
||||
for (var i = 0; i < pointCount; i++) {
|
||||
this.attributes.positions.set([vertices[i * 3], vertices[i * 3 + 1], 0], (verticesOffset + i) * 3);
|
||||
|
||||
if (this.get('uv')) {
|
||||
// TODO 用过BBox计算纹理坐标
|
||||
this.attributes.uv.set([0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0], (verticesOffset + i) * 3);
|
||||
}
|
||||
}
|
||||
|
||||
feature.bufferInfo.verticesOffset += pointCount; // 添加顶点索引
|
||||
|
||||
this.indexArray.set(indexArray, indexOffset); // 顶部坐标
|
||||
|
||||
feature.bufferInfo.indexOffset += indexArray.length;
|
||||
}
|
||||
}, {
|
||||
key: "_calculateFeatures",
|
||||
value: function _calculateFeatures() {
|
||||
var _this2 = this;
|
||||
|
||||
var layerData = this.get('layerData'); // 计算长
|
||||
|
||||
layerData.forEach(function (feature) {
|
||||
var coordinates = feature.coordinates;
|
||||
var bufferInfo = {};
|
||||
|
||||
var flattengeo = _earcut["default"].flatten(coordinates);
|
||||
|
||||
var vertices = flattengeo.vertices,
|
||||
dimensions = flattengeo.dimensions,
|
||||
holes = flattengeo.holes;
|
||||
var indexArray = (0, _earcut["default"])(vertices, holes, dimensions).map(function (v) {
|
||||
return _this2.verticesCount + v;
|
||||
});
|
||||
bufferInfo.vertices = vertices;
|
||||
bufferInfo.indexArray = indexArray;
|
||||
bufferInfo.verticesOffset = _this2.verticesCount + 0;
|
||||
bufferInfo.indexOffset = _this2.indexCount + 0;
|
||||
_this2.indexCount += indexArray.length;
|
||||
_this2.verticesCount += vertices.length / 3;
|
||||
feature.bufferInfo = bufferInfo;
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return FillBuffer;
|
||||
}(_buffer["default"]);
|
||||
|
||||
exports["default"] = FillBuffer;
|
|
@ -1,141 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports["default"] = void 0;
|
||||
|
||||
var _buffer = _interopRequireDefault(require("../buffer"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var LineBuffer =
|
||||
/*#__PURE__*/
|
||||
function (_BufferBase) {
|
||||
_inherits(LineBuffer, _BufferBase);
|
||||
|
||||
function LineBuffer() {
|
||||
_classCallCheck(this, LineBuffer);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(LineBuffer).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(LineBuffer, [{
|
||||
key: "_buildFeatures",
|
||||
value: function _buildFeatures() {
|
||||
var _this = this;
|
||||
|
||||
var layerData = this.get('layerData');
|
||||
var offsetVertices = 0;
|
||||
var offsetIndex = 0;
|
||||
var offset = 0;
|
||||
layerData.forEach(function (feature) {
|
||||
var coordinates = feature.coordinates;
|
||||
coordinates.forEach(function (coord) {
|
||||
var n = coord.length;
|
||||
feature.bufferInfo = {
|
||||
verticesOffset: offsetVertices
|
||||
};
|
||||
|
||||
_this._encodeArray(feature, n);
|
||||
|
||||
for (var i = 0; i < n; i++) {
|
||||
_this.attributes.positions[offsetVertices * 3] = coord[i][0];
|
||||
_this.attributes.positions[offsetVertices * 3 + 1] = coord[i][1];
|
||||
_this.attributes.positions[offsetVertices * 3 + 2] = coord[i][2];
|
||||
_this.indexArray[offsetIndex * 2] = i + offset;
|
||||
_this.indexArray[offsetIndex * 2 + 1] = i + offset + 1;
|
||||
|
||||
if (i === n - 1) {
|
||||
_this.indexArray[offsetIndex * 2 + 1] = offsetVertices - n + 1;
|
||||
}
|
||||
|
||||
offsetVertices++;
|
||||
offsetIndex++;
|
||||
}
|
||||
|
||||
offset += n;
|
||||
});
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_calculateBufferLength",
|
||||
value: function _calculateBufferLength() {
|
||||
var _this2 = this;
|
||||
|
||||
var layerData = this.get('layerData');
|
||||
layerData.forEach(function (feature) {
|
||||
var coordinates = feature.coordinates;
|
||||
coordinates.forEach(function (coord) {
|
||||
_this2.verticesCount += coord.length;
|
||||
_this2.indexCount += coord.length * 2 - 2;
|
||||
});
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_calculateFeatures",
|
||||
value: function _calculateFeatures() {
|
||||
var _this3 = this;
|
||||
|
||||
var layerData = this.get('layerData');
|
||||
layerData.forEach(function (feature) {
|
||||
var coordinates = feature.coordinates;
|
||||
coordinates.forEach(function (coord) {
|
||||
_this3.verticesCount += coord.length;
|
||||
_this3.indexCount += coord.length * 2;
|
||||
});
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_calculateLine",
|
||||
value: function _calculateLine(feature) {
|
||||
var _this4 = this;
|
||||
|
||||
var _feature$bufferInfo = feature.bufferInfo,
|
||||
indexOffset = _feature$bufferInfo.indexOffset,
|
||||
verticesOffset = _feature$bufferInfo.verticesOffset;
|
||||
feature.coordinates.forEach(function (coord) {
|
||||
var n = coord.length;
|
||||
|
||||
_this4._encodeArray(feature, n);
|
||||
|
||||
for (var i = 0; i < n; i++) {
|
||||
_this4.attributes.positions[(verticesOffset + i) * 3] = coord[i][0];
|
||||
_this4.attributes.positions[(verticesOffset + i) * 3 + 1] = coord[i][1];
|
||||
_this4.attributes.positions[(verticesOffset + i) * 3 + 2] = coord[i][2];
|
||||
_this4.indexArray[(indexOffset + i) * 2] = i + verticesOffset * 2;
|
||||
_this4.indexArray[(indexOffset + i) * 2 + 1] = i + verticesOffset * 2 + 1;
|
||||
|
||||
if (i === n - 1) {
|
||||
_this4.indexArray[(indexOffset + i) * 2 + 1] = verticesOffset + 1;
|
||||
}
|
||||
}
|
||||
|
||||
verticesOffset += n;
|
||||
indexOffset += n;
|
||||
});
|
||||
}
|
||||
}]);
|
||||
|
||||
return LineBuffer;
|
||||
}(_buffer["default"]);
|
||||
|
||||
exports["default"] = LineBuffer;
|
|
@ -1,201 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.RasterBuffer = void 0;
|
||||
|
||||
var _colorscales = require("../../attr/colorscales");
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../../core/three"));
|
||||
|
||||
var _base = _interopRequireDefault(require("../../core/base"));
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj["default"] = obj; return newObj; } }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var RasterBuffer =
|
||||
/*#__PURE__*/
|
||||
function (_Base) {
|
||||
_inherits(RasterBuffer, _Base);
|
||||
|
||||
function RasterBuffer(cfg) {
|
||||
var _this;
|
||||
|
||||
_classCallCheck(this, RasterBuffer);
|
||||
|
||||
_this = _possibleConstructorReturn(this, _getPrototypeOf(RasterBuffer).call(this, cfg));
|
||||
|
||||
_this.init();
|
||||
|
||||
return _this;
|
||||
}
|
||||
|
||||
_createClass(RasterBuffer, [{
|
||||
key: "init",
|
||||
value: function init() {
|
||||
var layerData = this.get('layerData');
|
||||
var _layerData$dataArray$ = layerData.dataArray[0],
|
||||
coordinates = _layerData$dataArray$.coordinates,
|
||||
width = _layerData$dataArray$.width,
|
||||
data = _layerData$dataArray$.data,
|
||||
height = _layerData$dataArray$.height;
|
||||
var positions = [].concat(_toConsumableArray(coordinates[0]), [coordinates[1][0], coordinates[0][1], 0], _toConsumableArray(coordinates[1]), _toConsumableArray(coordinates[0]), _toConsumableArray(coordinates[1]), [coordinates[0][0], coordinates[1][1], 0]);
|
||||
var imgPosUv = [0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0];
|
||||
var size = this.get('size');
|
||||
var texture = new THREE.DataTexture(new Float32Array(data), width, height, THREE.LuminanceFormat, THREE.FloatType);
|
||||
texture.needsUpdate = true;
|
||||
var colors = this.get('rampColors');
|
||||
var colorImageData = this.getColorRamp(colors);
|
||||
|
||||
var colorTexture = this._getTexture(colorImageData); // 颜色纹理
|
||||
|
||||
|
||||
this.position = positions;
|
||||
this.uv = imgPosUv;
|
||||
this.u_raster = texture; //
|
||||
|
||||
this.u_extent = [coordinates[0][0], coordinates[0][1], coordinates[1][0], coordinates[1][1]];
|
||||
this.u_colorTexture = colorTexture; // 颜色表‘=
|
||||
|
||||
var triangles = this._buildTriangles(width, height, size, this.u_extent);
|
||||
|
||||
var attributes = {
|
||||
vertices: new Float32Array(triangles.vertices),
|
||||
uvs: new Float32Array(triangles.uvs),
|
||||
indices: triangles.indices,
|
||||
dimension: triangles.dimension
|
||||
};
|
||||
this.attributes = attributes;
|
||||
}
|
||||
}, {
|
||||
key: "getColorRamp",
|
||||
value: function getColorRamp(name) {
|
||||
var colorscale = name;
|
||||
var canvas = document.createElement('canvas');
|
||||
var ctx = canvas.getContext('2d');
|
||||
canvas.width = 256;
|
||||
canvas.height = 1;
|
||||
var gradient = ctx.createLinearGradient(0, 0, 256, 0);
|
||||
var data = null;
|
||||
|
||||
if (typeof colorscale === 'string') {
|
||||
colorscale = _colorscales.colorScales[name];
|
||||
}
|
||||
|
||||
if (Object.prototype.toString.call(colorscale) === '[object Object]') {
|
||||
var min = colorscale.positions[0];
|
||||
var max = colorscale.positions[colorscale.positions.length - 1];
|
||||
|
||||
for (var i = 0; i < colorscale.colors.length; ++i) {
|
||||
var value = (colorscale.positions[i] - min) / (max - min);
|
||||
gradient.addColorStop(value, colorscale.colors[i]);
|
||||
}
|
||||
|
||||
ctx.fillStyle = gradient;
|
||||
ctx.fillRect(0, 0, 256, 1);
|
||||
data = new Uint8ClampedArray(ctx.getImageData(0, 0, 256, 1).data);
|
||||
}
|
||||
|
||||
if (Object.prototype.toString.call(colorscale) === '[object Uint8Array]') {
|
||||
data = ctx.createImageData(256, 1);
|
||||
}
|
||||
|
||||
return new ImageData(data, 16, 16);
|
||||
}
|
||||
/**
|
||||
* 颜色纹理
|
||||
* @param {*} image 颜色图片
|
||||
* @return {texture} texture
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: "_getTexture",
|
||||
value: function _getTexture(image) {
|
||||
var texture1 = new THREE.Texture(image);
|
||||
texture1.magFilter = THREE.LinearFilter;
|
||||
texture1.minFilter = THREE.LinearFilter;
|
||||
texture1.format = THREE.RGBAFormat;
|
||||
texture1.type = THREE.UnsignedByteType;
|
||||
texture1.generateMipmaps = true;
|
||||
texture1.needsUpdate = true;
|
||||
return texture1;
|
||||
}
|
||||
}, {
|
||||
key: "_buildTriangles",
|
||||
value: function _buildTriangles(width, height) {
|
||||
var size = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;
|
||||
var extent = arguments.length > 3 ? arguments[3] : undefined;
|
||||
// const extent = [ 73.482190241, 3.82501784112, 135.106618732, 57.6300459963 ]
|
||||
var indices = [];
|
||||
var vertices = [];
|
||||
var uvs = [];
|
||||
var gridX = Math.floor(width / size);
|
||||
var gridY = Math.floor(height / size);
|
||||
var gridX1 = gridX + 1;
|
||||
var gridY1 = gridY + 1;
|
||||
var stepX = (extent[2] - extent[0]) / gridX1;
|
||||
var stepY = (extent[3] - extent[1]) / gridY1;
|
||||
|
||||
for (var i = 0; i < gridY1; i++) {
|
||||
var y = i * size;
|
||||
|
||||
for (var j = 0; j < gridX1; j++) {
|
||||
var x = j * size;
|
||||
vertices.push(extent[0] + x * stepX, (height - y) * stepY + extent[1], 0);
|
||||
uvs.push(j / gridX);
|
||||
uvs.push(i / gridY);
|
||||
}
|
||||
}
|
||||
|
||||
for (var iy = 0; iy < gridY; iy++) {
|
||||
for (var ix = 0; ix < gridX; ix++) {
|
||||
var a = ix + gridX1 * iy;
|
||||
var b = ix + gridX1 * (iy + 1);
|
||||
var c = ix + 1 + gridX1 * (iy + 1);
|
||||
var d = ix + 1 + gridX1 * iy;
|
||||
indices.push(a, b, d);
|
||||
indices.push(b, c, d);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
uvs: uvs,
|
||||
indices: indices,
|
||||
vertices: vertices,
|
||||
dimension: [gridX, gridY]
|
||||
};
|
||||
}
|
||||
}]);
|
||||
|
||||
return RasterBuffer;
|
||||
}(_base["default"]);
|
||||
|
||||
exports.RasterBuffer = RasterBuffer;
|
|
@ -1,316 +0,0 @@
|
|||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", {
|
||||
value: true
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
var _bufferBase = _interopRequireDefault(require("./bufferBase"));
|
||||
|
||||
var _ajax = require("../../util/ajax");
|
||||
|
||||
var THREE = _interopRequireWildcard(require("../../core/three"));
|
||||
|
||||
var _tinySdf = _interopRequireDefault(require("@mapbox/tiny-sdf"));
|
||||
|
||||
var _global = _interopRequireDefault(require("../../global"));
|
||||
|
||||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
|
||||
|
||||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
||||
|
||||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
||||
|
||||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
|
||||
|
||||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
|
||||
|
||||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
|
||||
|
||||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
|
||||
|
||||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
||||
|
||||
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
||||
|
||||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
||||
|
||||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
||||
|
||||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
||||
|
||||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
||||
|
||||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
||||
|
||||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
||||
|
||||
var Space = 1;
|
||||
|
||||
var TextBuffer =
|
||||
/*#__PURE__*/
|
||||
function (_BufferBase) {
|
||||
_inherits(TextBuffer, _BufferBase);
|
||||
|
||||
function TextBuffer() {
|
||||
_classCallCheck(this, TextBuffer);
|
||||
|
||||
return _possibleConstructorReturn(this, _getPrototypeOf(TextBuffer).apply(this, arguments));
|
||||
}
|
||||
|
||||
_createClass(TextBuffer, [{
|
||||
key: "geometryBuffer",
|
||||
value: function geometryBuffer() {
|
||||
var _this = this;
|
||||
|
||||
this.metrics = {
|
||||
buffer: 3,
|
||||
family: 'ios9',
|
||||
size: 24
|
||||
};
|
||||
var layerData = this.get('layerData');
|
||||
|
||||
var _this$get = this.get('style'),
|
||||
_this$get$textOffset = _this$get.textOffset,
|
||||
textOffset = _this$get$textOffset === void 0 ? [0, 0] : _this$get$textOffset;
|
||||
|
||||
var chars = [];
|
||||
var textChars = {};
|
||||
layerData.forEach(function (element) {
|
||||
var text = element.shape || '';
|
||||
text = text.toString();
|
||||
|
||||
for (var j = 0; j < text.length; j++) {
|
||||
var code = text.charCodeAt(j);
|
||||
textChars[text] = 0;
|
||||
|
||||
if (chars.indexOf(code) === -1) {
|
||||
chars.push(text.charCodeAt(j));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var sdfTexture = this._updateSdf(Object.keys(textChars).join(''));
|
||||
|
||||
this.sdfTexture = sdfTexture;
|
||||
|
||||
this._loadTextInfo(chars);
|
||||
|
||||
this.on('SourceLoaded', function () {
|
||||
var textureElements = [];
|
||||
var colors = [];
|
||||
var originPoints = [];
|
||||
var textSizes = [];
|
||||
var textOffsets = [];
|
||||
layerData.forEach(function (element) {
|
||||
var size = element.size;
|
||||
var pos = element.coordinates; // const pen = { x: pos[0] - dimensions.advance / 2, y: pos[1] };
|
||||
|
||||
var pen = {
|
||||
x: textOffset[0],
|
||||
y: textOffset[1]
|
||||
};
|
||||
var text = element.shape || '';
|
||||
text = text.toString();
|
||||
|
||||
for (var i = 0; i < text.length; i++) {
|
||||
var color = element.color;
|
||||
|
||||
_this._drawGlyph(pos, text[i], pen, size, colors, textureElements, originPoints, textSizes, textOffsets, color);
|
||||
}
|
||||
});
|
||||
_this.bufferStruct.style = layerData;
|
||||
_this.attributes = {
|
||||
originPoints: originPoints,
|
||||
textSizes: textSizes,
|
||||
textOffsets: textOffsets,
|
||||
colors: colors,
|
||||
textureElements: textureElements
|
||||
};
|
||||
|
||||
_this.emit('completed');
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_loadTextInfo",
|
||||
value: function _loadTextInfo(chars) {
|
||||
var _this2 = this;
|
||||
|
||||
(0, _ajax.getJSON)({
|
||||
url: "".concat(_global.default.sdfHomeUrl, "/getsdfdata?chars=").concat(chars.join('|'))
|
||||
}, function (e, info) {
|
||||
_this2.metrics.chars = info.info;
|
||||
|
||||
_this2._loadTextTexture(info.url);
|
||||
});
|
||||
}
|
||||
}, {
|
||||
key: "_loadTextTexture",
|
||||
value: function _loadTextTexture(url) {
|
||||
var _this3 = this;
|
||||
|
||||
var img = new Image();
|
||||
img.crossOrigin = 'anonymous';
|
||||
|
||||
img.onload = function () {
|
||||
_this3.bufferStruct.textTexture = _this3._creatTexture(_this3.sdfTexture.texure);
|
||||
|
||||
_this3.emit('SourceLoaded');
|
||||
};
|
||||
|
||||
img.src = url;
|
||||
}
|
||||
/**
|
||||
* 计算每个标注词语的位置
|
||||
* @param {*} pos 文字三维空间坐标
|
||||
* @param {*} text 字符
|
||||
* @param {*} pen 字符在词语的偏移量
|
||||
* @param {*} size 字体大小
|
||||
* @param {*} colors 颜色
|
||||
* @param {*} textureElements 纹理坐标
|
||||
* @param {*} originPoints 初始位置数据
|
||||
* @param {*} textSizes 文字大小数组
|
||||
* @param {*} textOffsets 字体偏移量数据
|
||||
* @param {*} color 文字颜色
|
||||
*/
|
||||
|
||||
}, {
|
||||
key: "_drawGlyph",
|
||||
value: function _drawGlyph(pos, text, pen, size, colors, textureElements, originPoints, textSizes, textOffsets, color) {
|
||||
var metrics = this.metrics;
|
||||
var chr = text.charCodeAt(0);
|
||||
var metric = metrics.chars[chr];
|
||||
if (!metric) return;
|
||||
var info = this.sdfTexture.info;
|
||||
var _info$text = info[text],
|
||||
x = _info$text.x,
|
||||
y = _info$text.y;
|
||||
var scale = size / metrics.size;
|
||||
var width = 24; // metric[0];
|
||||
|
||||
var height = 24; // metric[1];
|
||||
// const horiBearingX = metric[2];
|
||||
// const horiBearingY = metric[3];
|
||||
// const horiAdvance = metric[4];
|
||||
// const posX = metric[5];
|
||||
// const posY = metric[6];
|
||||
|
||||
var posX = x;
|
||||
var posY = y;
|
||||
var buffer = metrics.buffer;
|
||||
|
||||
if (width > 0 && height > 0) {
|
||||
width += buffer * 2;
|
||||
height += buffer * 2; // Add a quad (= two triangles) per glyph.
|
||||
// const originX = (horiBearingX - buffer + width / 2) * scale;
|
||||
// const originY = -(height - horiBearingY) * scale;
|
||||
|
||||
var originX = 0;
|
||||
var originY = 0; // const offsetWidth = width / 2 * scale / (1.0 - horiBearingX * 1.5 / horiAdvance);
|
||||
// const offsetHeight = (horiAdvance / 2) * scale;
|
||||
// const offsetWidth = width/2 * scale;
|
||||
// const offsetHeight = height / 2 * scale;
|
||||
// const offsetHeight = height * scale;
|
||||
|
||||
var offsetX = pen.x;
|
||||
var offsetY = pen.y;
|
||||
originPoints.push(pos[0] + originX, pos[1] + originY, 0, pos[0] + originX, pos[1] + originY, 0, pos[0] + originX, pos[1] + originY, 0, pos[0] + originX, pos[1] + originY, 0, pos[0] + originX, pos[1] + originY, 0, pos[0] + originX, pos[1] + originY, 0); // textSizes.push(
|
||||
// offsetWidth, offsetHeight,
|
||||
// -offsetWidth, offsetHeight,
|
||||
// -offsetWidth, -offsetHeight,
|
||||
// offsetWidth, offsetHeight,
|
||||
// -offsetWidth, -offsetHeight,
|
||||
// offsetWidth, -offsetHeight,
|
||||
// );
|
||||
|
||||
var bx = 0;
|
||||
var by = metrics.size / 2 + buffer;
|
||||
textSizes.push((bx - buffer + width) * scale, (height - by) * scale, (bx - buffer) * scale, (height - by) * scale, (bx - buffer) * scale, -by * scale, (bx - buffer + width) * scale, (height - by) * scale, (bx - buffer) * scale, -by * scale, (bx - buffer + width) * scale, -by * scale);
|
||||
textOffsets.push(offsetX, offsetY, offsetX, offsetY, offsetX, offsetY, offsetX, offsetY, offsetX, offsetY, offsetX, offsetY);
|
||||
colors.push.apply(colors, _toConsumableArray(color).concat(_toConsumableArray(color), _toConsumableArray(color), _toConsumableArray(color), _toConsumableArray(color), _toConsumableArray(color)));
|
||||
textureElements.push(posX + width, posY, posX, posY, posX, posY + height, posX + width, posY, posX, posY + height, posX + width, posY + height);
|
||||
} // pen.x = pen.x + (horiAdvance + Space) * scale;
|
||||
|
||||
|
||||
pen.x = pen.x + size * 1.8;
|
||||
}
|
||||
}, {
|
||||
key: "_measureText",
|
||||
value: function _measureText(text, size) {
|
||||
var dimensions = {
|
||||
advance: 0
|
||||
};
|
||||
var metrics = this.metrics;
|
||||
var scale = size / metrics.size;
|
||||
|
||||
for (var i = 0; i < text.length; i++) {
|
||||
var code = text.charCodeAt(i);
|
||||
var horiAdvance = metrics.chars[code][4];
|
||||
dimensions.advance += (horiAdvance + Space) * scale;
|
||||
}
|
||||
|
||||
return dimensions;
|
||||
}
|
||||
}, {
|
||||
key: "_creatTexture",
|
||||
value: function _creatTexture(image) {
|
||||
this.bufferStruct.textSize = [image.width, image.height];
|
||||
var texture = new THREE.Texture(image);
|
||||
texture.minFilter = THREE.LinearFilter;
|
||||
texture.magFilter = THREE.ClampToEdgeWrapping;
|
||||
texture.needsUpdate = true;
|
||||
return texture;
|
||||
}
|
||||
}, {
|
||||
key: "_updateSdf",
|
||||
value: function _updateSdf(chars) {
|
||||
var canvas = document.createElement('canvas');
|
||||
var ctx = canvas.getContext('2d');
|
||||
var sdfs = {};
|
||||
var fontSize = 24;
|
||||
var fontWeight = 100;
|
||||
var buffer = fontSize / 8;
|
||||
var radius = fontSize / 3;
|
||||
var canvasSize = Math.floor(Math.pow(chars.length, 0.5)) * (fontSize + buffer + radius);
|
||||
canvas.width = canvasSize;
|
||||
canvas.height = canvasSize;
|
||||
ctx.clearRect(0, 0, canvas.width, canvas.height);
|
||||
var sdf = new _tinySdf.default(fontSize, buffer, radius, null, null, fontWeight);
|
||||
|
||||
for (var y = 0, i = 0; y + sdf.size <= canvas.height && i < chars.length; y += sdf.size) {
|
||||
for (var x = 0; x + sdf.size <= canvas.width && i < chars.length; x += sdf.size) {
|
||||
ctx.putImageData(this._makeRGBAImageData(ctx, sdf.draw(chars[i]), sdf.size), x, y);
|
||||
sdfs[chars[i]] = {
|
||||
x: x,
|
||||
y: y
|
||||
};
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
info: sdfs,
|
||||
texure: canvas
|
||||
};
|
||||
}
|
||||
}, {
|
||||
key: "_makeRGBAImageData",
|
||||
value: function _makeRGBAImageData(ctx, alphaChannel, size) {
|
||||
var imageData = ctx.createImageData(size, size);
|
||||
var data = imageData.data;
|
||||
|
||||
for (var i = 0; i < alphaChannel.length; i++) {
|
||||
data[4 * i + 0] = alphaChannel[i];
|
||||
data[4 * i + 1] = alphaChannel[i];
|
||||
data[4 * i + 2] = alphaChannel[i];
|
||||
data[4 * i + 3] = 255;
|
||||
}
|
||||
|
||||
return imageData;
|
||||
}
|
||||
}]);
|
||||
|
||||
return TextBuffer;
|
||||
}(_bufferBase.default);
|
||||
|
||||
exports.default = TextBuffer;
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue