const CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('') /** * 工具类 * 代码使用的leaflet开源工具 * https://github.com/Leaflet/Leaflet/tree/master/src/core * @ignore */ class Util { /** * generate uuid * @ignore * @param {*} prefix * */ static uuid(prefix = 'D') { let uuid = [] uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-' uuid[14] = '4' let r for (let i = 0; i < 36; i++) { if (!uuid[i]) { r = 0 | (Math.random() * 16) uuid[i] = CHARS[i == 19 ? (r & 0x3) | 0x8 : r] } } return prefix + '-' + uuid.join('') } /** * * Merges the properties of the `src` object (or multiple objects) into `dest` object and returns the latter. * @ignore * @param {*} dest * @param {*} sources * */ static merge(dest, ...sources) { let i, j, len, src for (j = 0, len = sources.length; j < len; j++) { src = sources[j] for (i in src) { dest[i] = src[i] } } return dest } /** * * Compatibility polyfill for [String.prototype.trim](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/Trim) * @ignore * @param {*} str * */ static trim(str) { return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g, '') } /** * Trims and splits the string on whitespace and returns the array of parts. * @ignore * @param {*} str * */ static splitWords(str) { return this.trim(str).split(/\s+/) } /** * * Merges the given properties to the `options` of the `obj` object, returning the resulting options. See `Class options`. * @ignore * @param {*} obj * @param {*} options * */ static setOptions(obj, options) { if (!obj.hasOwnProperty('options')) { obj.options = obj.options ? create(obj.options) : {} } for (var i in options) { obj.options[i] = options[i] } return obj.options } /** * Check position for validity * @ignore * @param {*} position */ static checkPosition(position) { return ( position && position.hasOwnProperty('_lng') && position.hasOwnProperty('_lat') && position.hasOwnProperty('_alt') ) } /** * Check positions for validity * @ignore * @param {*} position */ static checkPositions(positions) { return ( positions && (typeof positions === 'string' || Array.isArray(positions)) ) } /** * Check viewer for validity * @ignore * @param {*} position */ static checkViewer(viewer) { return viewer && viewer.delegate && viewer.canvas } } export default Util