* @param {object} opts (see Plotly.toImage in ../plot_api/to_image)
* @return {promise}
*/
function downloadImage(gd, opts) {
var _gd;
if (!Lib.isPlainObject(gd)) _gd = Lib.getGraphDiv(gd);
opts = opts || {};
opts.format = opts.format || 'png';
opts.width = opts.width || null;
opts.height = opts.height || null;
opts.imageDataOnly = true;
return new Promise(function (resolve, reject) {
if (_gd && _gd._snapshotInProgress) {
reject(new Error('Snapshotting already in progress.'));
}
// see comments within svgtoimg for additional
// discussion of problems with IE
// can now draw to canvas, but CORS tainted canvas
// does not allow toDataURL
// svg format will work though
if (Lib.isIE() && opts.format !== 'svg') {
reject(new Error(helpers.MSG_IE_BAD_FORMAT));
}
if (_gd) _gd._snapshotInProgress = true;
var promise = toImage(gd, opts);
var filename = opts.filename || gd.fn || 'newplot';
filename += '.' + opts.format.replace('-', '.');
promise.then(function (result) {
if (_gd) _gd._snapshotInProgress = false;
return fileSaver(result, filename, opts.format);
}).then(function (name) {
resolve(name);
}).catch(function (err) {
if (_gd) _gd._snapshotInProgress = false;
reject(err);
});
});
}
module.exports = downloadImage;
/***/ }),
/***/ 8616:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Lib = __webpack_require__(3400);
var helpers = __webpack_require__(7030);
/*
* substantial portions of this code from FileSaver.js
* https://github.com/eligrey/FileSaver.js
* License: https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
* FileSaver.js
* A saveAs() FileSaver implementation.
* 1.1.20160328
*
* By Eli Grey, http://eligrey.com
* License: MIT
* See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
*/
function fileSaver(url, name, format) {
var saveLink = document.createElement('a');
var canUseSaveLink = ('download' in saveLink);
var promise = new Promise(function (resolve, reject) {
var blob;
var objectUrl;
// IE 10+ (native saveAs)
if (Lib.isIE()) {
// At this point we are only dealing with a decoded SVG as
// a data URL (since IE only supports SVG)
blob = helpers.createBlob(url, 'svg');
window.navigator.msSaveBlob(blob, name);
blob = null;
return resolve(name);
}
if (canUseSaveLink) {
blob = helpers.createBlob(url, format);
objectUrl = helpers.createObjectURL(blob);
saveLink.href = objectUrl;
saveLink.download = name;
document.body.appendChild(saveLink);
saveLink.click();
document.body.removeChild(saveLink);
helpers.revokeObjectURL(objectUrl);
blob = null;
return resolve(name);
}
// Older versions of Safari did not allow downloading of blob urls
if (Lib.isSafari()) {
var prefix = format === 'svg' ? ',' : ';base64,';
helpers.octetStream(prefix + encodeURIComponent(url));
return resolve(name);
}
reject(new Error('download error'));
});
return promise;
}
module.exports = fileSaver;
/***/ }),
/***/ 7030:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
var Registry = __webpack_require__(4040);
exports.getDelay = function (fullLayout) {
if (!fullLayout._has) return 0;
return fullLayout._has('gl3d') || fullLayout._has('gl2d') || fullLayout._has('mapbox') ? 500 : 0;
};
exports.getRedrawFunc = function (gd) {
return function () {
Registry.getComponentMethod('colorbar', 'draw')(gd);
};
};
exports.encodeSVG = function (svg) {
return 'data:image/svg+xml,' + encodeURIComponent(svg);
};
exports.encodeJSON = function (json) {
return 'data:application/json,' + encodeURIComponent(json);
};
var DOM_URL = window.URL || window.webkitURL;
exports.createObjectURL = function (blob) {
return DOM_URL.createObjectURL(blob);
};
exports.revokeObjectURL = function (url) {
return DOM_URL.revokeObjectURL(url);
};
exports.createBlob = function (url, format) {
if (format === 'svg') {
return new window.Blob([url], {
type: 'image/svg+xml;charset=utf-8'
});
} else if (format === 'full-json') {
return new window.Blob([url], {
type: 'application/json;charset=utf-8'
});
} else {
var binary = fixBinary(window.atob(url));
return new window.Blob([binary], {
type: 'image/' + format
});
}
};
exports.octetStream = function (s) {
document.location.href = 'data:application/octet-stream' + s;
};
// Taken from https://bl.ocks.org/nolanlawson/0eac306e4dac2114c752
function fixBinary(b) {
var len = b.length;
var buf = new ArrayBuffer(len);
var arr = new Uint8Array(buf);
for (var i = 0; i < len; i++) {
arr[i] = b.charCodeAt(i);
}
return buf;
}
exports.IMAGE_URL_PREFIX = /^data:image\/\w+;base64,/;
exports.MSG_IE_BAD_FORMAT = 'Sorry IE does not support downloading from canvas. Try {format:\'svg\'} instead.';
/***/ }),
/***/ 8904:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var helpers = __webpack_require__(7030);
var Snapshot = {
getDelay: helpers.getDelay,
getRedrawFunc: helpers.getRedrawFunc,
clone: __webpack_require__(1536),
toSVG: __webpack_require__(7164),
svgToImg: __webpack_require__(3268),
toImage: __webpack_require__(1808),
downloadImage: __webpack_require__(7412)
};
module.exports = Snapshot;
/***/ }),
/***/ 3268:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Lib = __webpack_require__(3400);
var EventEmitter = (__webpack_require__(1252).EventEmitter);
var helpers = __webpack_require__(7030);
function svgToImg(opts) {
var ev = opts.emitter || new EventEmitter();
var promise = new Promise(function (resolve, reject) {
var Image = window.Image;
var svg = opts.svg;
var format = opts.format || 'png';
// IE only support svg
if (Lib.isIE() && format !== 'svg') {
var ieSvgError = new Error(helpers.MSG_IE_BAD_FORMAT);
reject(ieSvgError);
// eventually remove the ev
// in favor of promises
if (!opts.promise) {
return ev.emit('error', ieSvgError);
} else {
return promise;
}
}
var canvas = opts.canvas;
var scale = opts.scale || 1;
var w0 = opts.width || 300;
var h0 = opts.height || 150;
var w1 = scale * w0;
var h1 = scale * h0;
var ctx = canvas.getContext('2d', {
willReadFrequently: true
});
var img = new Image();
var svgBlob, url;
if (format === 'svg' || Lib.isSafari()) {
url = helpers.encodeSVG(svg);
} else {
svgBlob = helpers.createBlob(svg, 'svg');
url = helpers.createObjectURL(svgBlob);
}
canvas.width = w1;
canvas.height = h1;
img.onload = function () {
var imgData;
svgBlob = null;
helpers.revokeObjectURL(url);
// don't need to draw to canvas if svg
// save some time and also avoid failure on IE
if (format !== 'svg') {
ctx.drawImage(img, 0, 0, w1, h1);
}
switch (format) {
case 'jpeg':
imgData = canvas.toDataURL('image/jpeg');
break;
case 'png':
imgData = canvas.toDataURL('image/png');
break;
case 'webp':
imgData = canvas.toDataURL('image/webp');
break;
case 'svg':
imgData = url;
break;
default:
var errorMsg = 'Image format is not jpeg, png, svg or webp.';
reject(new Error(errorMsg));
// eventually remove the ev
// in favor of promises
if (!opts.promise) {
return ev.emit('error', errorMsg);
}
}
resolve(imgData);
// eventually remove the ev
// in favor of promises
if (!opts.promise) {
ev.emit('success', imgData);
}
};
img.onerror = function (err) {
svgBlob = null;
helpers.revokeObjectURL(url);
reject(err);
// eventually remove the ev
// in favor of promises
if (!opts.promise) {
return ev.emit('error', err);
}
};
img.src = url;
});
// temporary for backward compatibility
// move to only Promise in 2.0.0
// and eliminate the EventEmitter
if (opts.promise) {
return promise;
}
return ev;
}
module.exports = svgToImg;
/***/ }),
/***/ 1808:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var EventEmitter = (__webpack_require__(1252).EventEmitter);
var Registry = __webpack_require__(4040);
var Lib = __webpack_require__(3400);
var helpers = __webpack_require__(7030);
var clonePlot = __webpack_require__(1536);
var toSVG = __webpack_require__(7164);
var svgToImg = __webpack_require__(3268);
/**
* @param {object} gd figure Object
* @param {object} opts option object
* @param opts.format 'jpeg' | 'png' | 'webp' | 'svg'
*/
function toImage(gd, opts) {
// first clone the GD so we can operate in a clean environment
var ev = new EventEmitter();
var clone = clonePlot(gd, {
format: 'png'
});
var clonedGd = clone.gd;
// put the cloned div somewhere off screen before attaching to DOM
clonedGd.style.position = 'absolute';
clonedGd.style.left = '-5000px';
document.body.appendChild(clonedGd);
function wait() {
var delay = helpers.getDelay(clonedGd._fullLayout);
setTimeout(function () {
var svg = toSVG(clonedGd);
var canvas = document.createElement('canvas');
canvas.id = Lib.randstr();
ev = svgToImg({
format: opts.format,
width: clonedGd._fullLayout.width,
height: clonedGd._fullLayout.height,
canvas: canvas,
emitter: ev,
svg: svg
});
ev.clean = function () {
if (clonedGd) document.body.removeChild(clonedGd);
};
}, delay);
}
var redrawFunc = helpers.getRedrawFunc(clonedGd);
Registry.call('_doPlot', clonedGd, clone.data, clone.layout, clone.config).then(redrawFunc).then(wait).catch(function (err) {
ev.emit('error', err);
});
return ev;
}
module.exports = toImage;
/***/ }),
/***/ 7164:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var d3 = __webpack_require__(3428);
var Lib = __webpack_require__(3400);
var Drawing = __webpack_require__(3616);
var Color = __webpack_require__(6308);
var xmlnsNamespaces = __webpack_require__(9616);
var DOUBLEQUOTE_REGEX = /"/g;
var DUMMY_SUB = 'TOBESTRIPPED';
var DUMMY_REGEX = new RegExp('("' + DUMMY_SUB + ')|(' + DUMMY_SUB + '")', 'g');
function htmlEntityDecode(s) {
var hiddenDiv = d3.select('body').append('div').style({
display: 'none'
}).html('');
var replaced = s.replace(/(&[^;]*;)/gi, function (d) {
if (d === '<') {
return '<';
} // special handling for brackets
if (d === '&rt;') {
return '>';
}
if (d.indexOf('<') !== -1 || d.indexOf('>') !== -1) {
return '';
}
return hiddenDiv.html(d).text(); // everything else, let the browser decode it to unicode
});
hiddenDiv.remove();
return replaced;
}
function xmlEntityEncode(str) {
return str.replace(/&(?!\w+;|\#[0-9]+;| \#x[0-9A-F]+;)/g, '&');
}
module.exports = function toSVG(gd, format, scale) {
var fullLayout = gd._fullLayout;
var svg = fullLayout._paper;
var toppaper = fullLayout._toppaper;
var width = fullLayout.width;
var height = fullLayout.height;
var i;
// make background color a rect in the svg, then revert after scraping
// all other alterations have been dealt with by properly preparing the svg
// in the first place... like setting cursors with css classes so we don't
// have to remove them, and providing the right namespaces in the svg to
// begin with
svg.insert('rect', ':first-child').call(Drawing.setRect, 0, 0, width, height).call(Color.fill, fullLayout.paper_bgcolor);
// subplot-specific to-SVG methods
// which notably add the contents of the gl-container
// into the main svg node
var basePlotModules = fullLayout._basePlotModules || [];
for (i = 0; i < basePlotModules.length; i++) {
var _module = basePlotModules[i];
if (_module.toSVG) _module.toSVG(gd);
}
// add top items above them assumes everything in toppaper is either
// a group or a defs, and if it's empty (like hoverlayer) we can ignore it.
if (toppaper) {
var nodes = toppaper.node().childNodes;
// make copy of nodes as childNodes prop gets mutated in loop below
var topGroups = Array.prototype.slice.call(nodes);
for (i = 0; i < topGroups.length; i++) {
var topGroup = topGroups[i];
if (topGroup.childNodes.length) svg.node().appendChild(topGroup);
}
}
// remove draglayer for Adobe Illustrator compatibility
if (fullLayout._draggers) {
fullLayout._draggers.remove();
}
// in case the svg element had an explicit background color, remove this
// we want the rect to get the color so it's the right size; svg bg will
// fill whatever container it's displayed in regardless of plot size.
svg.node().style.background = '';
svg.selectAll('text').attr({
'data-unformatted': null,
'data-math': null
}).each(function () {
var txt = d3.select(this);
// hidden text is pre-formatting mathjax, the browser ignores it
// but in a static plot it's useless and it can confuse batik
// we've tried to standardize on display:none but make sure we still
// catch visibility:hidden if it ever arises
if (this.style.visibility === 'hidden' || this.style.display === 'none') {
txt.remove();
return;
} else {
// clear other visibility/display values to default
// to not potentially confuse non-browser SVG implementations
txt.style({
visibility: null,
display: null
});
}
// Font family styles break things because of quotation marks,
// so we must remove them *after* the SVG DOM has been serialized
// to a string (browsers convert singles back)
var ff = this.style.fontFamily;
if (ff && ff.indexOf('"') !== -1) {
txt.style('font-family', ff.replace(DOUBLEQUOTE_REGEX, DUMMY_SUB));
}
});
svg.selectAll('.gradient_filled,.pattern_filled').each(function () {
var pt = d3.select(this);
// similar to font family styles above,
// we must remove " after the SVG DOM has been serialized
var fill = this.style.fill;
if (fill && fill.indexOf('url(') !== -1) {
pt.style('fill', fill.replace(DOUBLEQUOTE_REGEX, DUMMY_SUB));
}
var stroke = this.style.stroke;
if (stroke && stroke.indexOf('url(') !== -1) {
pt.style('stroke', stroke.replace(DOUBLEQUOTE_REGEX, DUMMY_SUB));
}
});
if (format === 'pdf' || format === 'eps') {
// these formats make the extra line MathJax adds around symbols look super thick in some cases
// it looks better if this is removed entirely.
svg.selectAll('#MathJax_SVG_glyphs path').attr('stroke-width', 0);
}
// fix for IE namespacing quirk?
// http://stackoverflow.com/questions/19610089/unwanted-namespaces-on-svg-markup-when-using-xmlserializer-in-javascript-with-ie
svg.node().setAttributeNS(xmlnsNamespaces.xmlns, 'xmlns', xmlnsNamespaces.svg);
svg.node().setAttributeNS(xmlnsNamespaces.xmlns, 'xmlns:xlink', xmlnsNamespaces.xlink);
if (format === 'svg' && scale) {
svg.attr('width', scale * width);
svg.attr('height', scale * height);
svg.attr('viewBox', '0 0 ' + width + ' ' + height);
}
var s = new window.XMLSerializer().serializeToString(svg.node());
s = htmlEntityDecode(s);
s = xmlEntityEncode(s);
// Fix quotations around font strings and gradient URLs
s = s.replace(DUMMY_REGEX, '\'');
// Do we need this process now that IE9 and IE10 are not supported?
// IE is very strict, so we will need to clean
// svg with the following regex
// yes this is messy, but do not know a better way
// Even with this IE will not work due to tainted canvas
// see https://github.com/kangax/fabric.js/issues/1957
// http://stackoverflow.com/questions/18112047/canvas-todataurl-working-in-all-browsers-except-ie10
// Leave here just in case the CORS/tainted IE issue gets resolved
if (Lib.isIE()) {
// replace double quote with single quote
s = s.replace(/"/gi, '\'');
// url in svg are single quoted
// since we changed double to single
// we'll need to change these to double-quoted
s = s.replace(/(\('#)([^']*)('\))/gi, '(\"#$2\")');
// font names with spaces will be escaped single-quoted
// we'll need to change these to double-quoted
s = s.replace(/(\\')/gi, '\"');
}
return s;
};
/***/ }),
/***/ 6376:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var isNumeric = __webpack_require__(8248);
var isArrayOrTypedArray = (__webpack_require__(3400).isArrayOrTypedArray);
var BADNUM = (__webpack_require__(9032).BADNUM);
var Registry = __webpack_require__(4040);
var Axes = __webpack_require__(4460);
var getAxisGroup = (__webpack_require__(1888).getAxisGroup);
var Sieve = __webpack_require__(2592);
/*
* Bar chart stacking/grouping positioning and autoscaling calculations
* for each direction separately calculate the ranges and positions
* note that this handles histograms too
* now doing this one subplot at a time
*/
function crossTraceCalc(gd, plotinfo) {
var xa = plotinfo.xaxis;
var ya = plotinfo.yaxis;
var fullLayout = gd._fullLayout;
var fullTraces = gd._fullData;
var calcTraces = gd.calcdata;
var calcTracesHorz = [];
var calcTracesVert = [];
for (var i = 0; i < fullTraces.length; i++) {
var fullTrace = fullTraces[i];
if (fullTrace.visible === true && Registry.traceIs(fullTrace, 'bar') && fullTrace.xaxis === xa._id && fullTrace.yaxis === ya._id) {
if (fullTrace.orientation === 'h') {
calcTracesHorz.push(calcTraces[i]);
} else {
calcTracesVert.push(calcTraces[i]);
}
if (fullTrace._computePh) {
var cd = gd.calcdata[i];
for (var j = 0; j < cd.length; j++) {
if (typeof cd[j].ph0 === 'function') cd[j].ph0 = cd[j].ph0();
if (typeof cd[j].ph1 === 'function') cd[j].ph1 = cd[j].ph1();
}
}
}
}
var opts = {
xCat: xa.type === 'category' || xa.type === 'multicategory',
yCat: ya.type === 'category' || ya.type === 'multicategory',
mode: fullLayout.barmode,
norm: fullLayout.barnorm,
gap: fullLayout.bargap,
groupgap: fullLayout.bargroupgap
};
setGroupPositions(gd, xa, ya, calcTracesVert, opts);
setGroupPositions(gd, ya, xa, calcTracesHorz, opts);
}
function setGroupPositions(gd, pa, sa, calcTraces, opts) {
if (!calcTraces.length) return;
var excluded;
var included;
var i, calcTrace, fullTrace;
initBase(sa, calcTraces);
switch (opts.mode) {
case 'overlay':
setGroupPositionsInOverlayMode(pa, sa, calcTraces, opts);
break;
case 'group':
// exclude from the group those traces for which the user set an offset
excluded = [];
included = [];
for (i = 0; i < calcTraces.length; i++) {
calcTrace = calcTraces[i];
fullTrace = calcTrace[0].trace;
if (fullTrace.offset === undefined) included.push(calcTrace);else excluded.push(calcTrace);
}
if (included.length) {
setGroupPositionsInGroupMode(gd, pa, sa, included, opts);
}
if (excluded.length) {
setGroupPositionsInOverlayMode(pa, sa, excluded, opts);
}
break;
case 'stack':
case 'relative':
// exclude from the stack those traces for which the user set a base
excluded = [];
included = [];
for (i = 0; i < calcTraces.length; i++) {
calcTrace = calcTraces[i];
fullTrace = calcTrace[0].trace;
if (fullTrace.base === undefined) included.push(calcTrace);else excluded.push(calcTrace);
}
// If any trace in `included` has a cornerradius, set cornerradius of all bars
// in `included` to match the first trace which has a cornerradius
standardizeCornerradius(included);
if (included.length) {
setGroupPositionsInStackOrRelativeMode(gd, pa, sa, included, opts);
}
if (excluded.length) {
setGroupPositionsInOverlayMode(pa, sa, excluded, opts);
}
break;
}
setCornerradius(calcTraces);
collectExtents(calcTraces, pa);
}
// Set cornerradiusvalue and cornerradiusform in calcTraces[0].t
function setCornerradius(calcTraces) {
var i, calcTrace, fullTrace, t, cr, crValue, crForm;
for (i = 0; i < calcTraces.length; i++) {
calcTrace = calcTraces[i];
fullTrace = calcTrace[0].trace;
t = calcTrace[0].t;
if (t.cornerradiusvalue === undefined) {
cr = fullTrace.marker ? fullTrace.marker.cornerradius : undefined;
if (cr !== undefined) {
crValue = isNumeric(cr) ? +cr : +cr.slice(0, -1);
crForm = isNumeric(cr) ? 'px' : '%';
t.cornerradiusvalue = crValue;
t.cornerradiusform = crForm;
}
}
}
}
// Make sure all traces in a stack use the same cornerradius
function standardizeCornerradius(calcTraces) {
if (calcTraces.length < 2) return;
var i, calcTrace, fullTrace, t;
var cr, crValue, crForm;
for (i = 0; i < calcTraces.length; i++) {
calcTrace = calcTraces[i];
fullTrace = calcTrace[0].trace;
cr = fullTrace.marker ? fullTrace.marker.cornerradius : undefined;
if (cr !== undefined) break;
}
// If any trace has cornerradius, store first cornerradius
// in calcTrace[0].t so that all traces in stack use same cornerradius
if (cr !== undefined) {
crValue = isNumeric(cr) ? +cr : +cr.slice(0, -1);
crForm = isNumeric(cr) ? 'px' : '%';
for (i = 0; i < calcTraces.length; i++) {
calcTrace = calcTraces[i];
t = calcTrace[0].t;
t.cornerradiusvalue = crValue;
t.cornerradiusform = crForm;
}
}
}
function initBase(sa, calcTraces) {
var i, j;
for (i = 0; i < calcTraces.length; i++) {
var cd = calcTraces[i];
var trace = cd[0].trace;
var base = trace.type === 'funnel' ? trace._base : trace.base;
var b;
// not sure if it really makes sense to have dates for bar size data...
// ideally if we want to make gantt charts or something we'd treat
// the actual size (trace.x or y) as time delta but base as absolute
// time. But included here for completeness.
var scalendar = trace.orientation === 'h' ? trace.xcalendar : trace.ycalendar;
// 'base' on categorical axes makes no sense
var d2c = sa.type === 'category' || sa.type === 'multicategory' ? function () {
return null;
} : sa.d2c;
if (isArrayOrTypedArray(base)) {
for (j = 0; j < Math.min(base.length, cd.length); j++) {
b = d2c(base[j], 0, scalendar);
if (isNumeric(b)) {
cd[j].b = +b;
cd[j].hasB = 1;
} else cd[j].b = 0;
}
for (; j < cd.length; j++) {
cd[j].b = 0;
}
} else {
b = d2c(base, 0, scalendar);
var hasBase = isNumeric(b);
b = hasBase ? b : 0;
for (j = 0; j < cd.length; j++) {
cd[j].b = b;
if (hasBase) cd[j].hasB = 1;
}
}
}
}
function setGroupPositionsInOverlayMode(pa, sa, calcTraces, opts) {
// update position axis and set bar offsets and widths
for (var i = 0; i < calcTraces.length; i++) {
var calcTrace = calcTraces[i];
var sieve = new Sieve([calcTrace], {
posAxis: pa,
sepNegVal: false,
overlapNoMerge: !opts.norm
});
// set bar offsets and widths, and update position axis
setOffsetAndWidth(pa, sieve, opts);
// set bar bases and sizes, and update size axis
//
// (note that `setGroupPositionsInOverlayMode` handles the case barnorm
// is defined, because this function is also invoked for traces that
// can't be grouped or stacked)
if (opts.norm) {
sieveBars(sieve);
normalizeBars(sa, sieve, opts);
} else {
setBaseAndTop(sa, sieve);
}
}
}
function setGroupPositionsInGroupMode(gd, pa, sa, calcTraces, opts) {
var sieve = new Sieve(calcTraces, {
posAxis: pa,
sepNegVal: false,
overlapNoMerge: !opts.norm
});
// set bar offsets and widths, and update position axis
setOffsetAndWidthInGroupMode(gd, pa, sieve, opts);
// relative-stack bars within the same trace that would otherwise
// be hidden
unhideBarsWithinTrace(sieve, pa);
// set bar bases and sizes, and update size axis
if (opts.norm) {
sieveBars(sieve);
normalizeBars(sa, sieve, opts);
} else {
setBaseAndTop(sa, sieve);
}
}
function setGroupPositionsInStackOrRelativeMode(gd, pa, sa, calcTraces, opts) {
var sieve = new Sieve(calcTraces, {
posAxis: pa,
sepNegVal: opts.mode === 'relative',
overlapNoMerge: !(opts.norm || opts.mode === 'stack' || opts.mode === 'relative')
});
// set bar offsets and widths, and update position axis
setOffsetAndWidth(pa, sieve, opts);
// set bar bases and sizes, and update size axis
stackBars(sa, sieve, opts);
// flag the outmost bar (for text display purposes)
for (var i = 0; i < calcTraces.length; i++) {
var calcTrace = calcTraces[i];
for (var j = 0; j < calcTrace.length; j++) {
var bar = calcTrace[j];
if (bar.s !== BADNUM) {
var isOutmostBar = bar.b + bar.s === sieve.get(bar.p, bar.s);
if (isOutmostBar) bar._outmost = true;
}
}
}
// Note that marking the outmost bars has to be done
// before `normalizeBars` changes `bar.b` and `bar.s`.
if (opts.norm) normalizeBars(sa, sieve, opts);
}
function setOffsetAndWidth(pa, sieve, opts) {
var minDiff = sieve.minDiff;
var calcTraces = sieve.traces;
// set bar offsets and widths
var barGroupWidth = minDiff * (1 - opts.gap);
var barWidthPlusGap = barGroupWidth;
var barWidth = barWidthPlusGap * (1 - (opts.groupgap || 0));
// computer bar group center and bar offset
var offsetFromCenter = -barWidth / 2;
for (var i = 0; i < calcTraces.length; i++) {
var calcTrace = calcTraces[i];
var t = calcTrace[0].t;
// store bar width and offset for this trace
t.barwidth = barWidth;
t.poffset = offsetFromCenter;
t.bargroupwidth = barGroupWidth;
t.bardelta = minDiff;
}
// stack bars that only differ by rounding
sieve.binWidth = calcTraces[0][0].t.barwidth / 100;
// if defined, apply trace offset and width
applyAttributes(sieve);
// store the bar center in each calcdata item
setBarCenterAndWidth(pa, sieve);
// update position axes
updatePositionAxis(pa, sieve);
}
function setOffsetAndWidthInGroupMode(gd, pa, sieve, opts) {
var fullLayout = gd._fullLayout;
var positions = sieve.positions;
var distinctPositions = sieve.distinctPositions;
var minDiff = sieve.minDiff;
var calcTraces = sieve.traces;
var nTraces = calcTraces.length;
// if there aren't any overlapping positions,
// let them have full width even if mode is group
var overlap = positions.length !== distinctPositions.length;
var barGroupWidth = minDiff * (1 - opts.gap);
var groupId = getAxisGroup(fullLayout, pa._id) + calcTraces[0][0].trace.orientation;
var alignmentGroups = fullLayout._alignmentOpts[groupId] || {};
for (var i = 0; i < nTraces; i++) {
var calcTrace = calcTraces[i];
var trace = calcTrace[0].trace;
var alignmentGroupOpts = alignmentGroups[trace.alignmentgroup] || {};
var nOffsetGroups = Object.keys(alignmentGroupOpts.offsetGroups || {}).length;
var barWidthPlusGap;
if (nOffsetGroups) {
barWidthPlusGap = barGroupWidth / nOffsetGroups;
} else {
barWidthPlusGap = overlap ? barGroupWidth / nTraces : barGroupWidth;
}
var barWidth = barWidthPlusGap * (1 - (opts.groupgap || 0));
var offsetFromCenter;
if (nOffsetGroups) {
offsetFromCenter = ((2 * trace._offsetIndex + 1 - nOffsetGroups) * barWidthPlusGap - barWidth) / 2;
} else {
offsetFromCenter = overlap ? ((2 * i + 1 - nTraces) * barWidthPlusGap - barWidth) / 2 : -barWidth / 2;
}
var t = calcTrace[0].t;
t.barwidth = barWidth;
t.poffset = offsetFromCenter;
t.bargroupwidth = barGroupWidth;
t.bardelta = minDiff;
}
// stack bars that only differ by rounding
sieve.binWidth = calcTraces[0][0].t.barwidth / 100;
// if defined, apply trace width
applyAttributes(sieve);
// store the bar center in each calcdata item
setBarCenterAndWidth(pa, sieve);
// update position axes
updatePositionAxis(pa, sieve, overlap);
}
function applyAttributes(sieve) {
var calcTraces = sieve.traces;
var i, j;
for (i = 0; i < calcTraces.length; i++) {
var calcTrace = calcTraces[i];
var calcTrace0 = calcTrace[0];
var fullTrace = calcTrace0.trace;
var t = calcTrace0.t;
var offset = fullTrace._offset || fullTrace.offset;
var initialPoffset = t.poffset;
var newPoffset;
if (isArrayOrTypedArray(offset)) {
// if offset is an array, then clone it into t.poffset.
newPoffset = Array.prototype.slice.call(offset, 0, calcTrace.length);
// guard against non-numeric items
for (j = 0; j < newPoffset.length; j++) {
if (!isNumeric(newPoffset[j])) {
newPoffset[j] = initialPoffset;
}
}
// if the length of the array is too short,
// then extend it with the initial value of t.poffset
for (j = newPoffset.length; j < calcTrace.length; j++) {
newPoffset.push(initialPoffset);
}
t.poffset = newPoffset;
} else if (offset !== undefined) {
t.poffset = offset;
}
var width = fullTrace._width || fullTrace.width;
var initialBarwidth = t.barwidth;
if (isArrayOrTypedArray(width)) {
// if width is an array, then clone it into t.barwidth.
var newBarwidth = Array.prototype.slice.call(width, 0, calcTrace.length);
// guard against non-numeric items
for (j = 0; j < newBarwidth.length; j++) {
if (!isNumeric(newBarwidth[j])) newBarwidth[j] = initialBarwidth;
}
// if the length of the array is too short,
// then extend it with the initial value of t.barwidth
for (j = newBarwidth.length; j < calcTrace.length; j++) {
newBarwidth.push(initialBarwidth);
}
t.barwidth = newBarwidth;
// if user didn't set offset,
// then correct t.poffset to ensure bars remain centered
if (offset === undefined) {
newPoffset = [];
for (j = 0; j < calcTrace.length; j++) {
newPoffset.push(initialPoffset + (initialBarwidth - newBarwidth[j]) / 2);
}
t.poffset = newPoffset;
}
} else if (width !== undefined) {
t.barwidth = width;
// if user didn't set offset,
// then correct t.poffset to ensure bars remain centered
if (offset === undefined) {
t.poffset = initialPoffset + (initialBarwidth - width) / 2;
}
}
}
}
function setBarCenterAndWidth(pa, sieve) {
var calcTraces = sieve.traces;
var pLetter = getAxisLetter(pa);
for (var i = 0; i < calcTraces.length; i++) {
var calcTrace = calcTraces[i];
var t = calcTrace[0].t;
var poffset = t.poffset;
var poffsetIsArray = isArrayOrTypedArray(poffset);
var barwidth = t.barwidth;
var barwidthIsArray = isArrayOrTypedArray(barwidth);
for (var j = 0; j < calcTrace.length; j++) {
var calcBar = calcTrace[j];
// store the actual bar width and position, for use by hover
var width = calcBar.w = barwidthIsArray ? barwidth[j] : barwidth;
if (calcBar.p === undefined) {
calcBar.p = calcBar[pLetter];
calcBar['orig_' + pLetter] = calcBar[pLetter];
}
var delta = (poffsetIsArray ? poffset[j] : poffset) + width / 2;
calcBar[pLetter] = calcBar.p + delta;
}
}
}
function updatePositionAxis(pa, sieve, allowMinDtick) {
var calcTraces = sieve.traces;
var minDiff = sieve.minDiff;
var vpad = minDiff / 2;
Axes.minDtick(pa, sieve.minDiff, sieve.distinctPositions[0], allowMinDtick);
for (var i = 0; i < calcTraces.length; i++) {
var calcTrace = calcTraces[i];
var calcTrace0 = calcTrace[0];
var fullTrace = calcTrace0.trace;
var pts = [];
var bar, l, r, j;
for (j = 0; j < calcTrace.length; j++) {
bar = calcTrace[j];
l = bar.p - vpad;
r = bar.p + vpad;
pts.push(l, r);
}
if (fullTrace.width || fullTrace.offset) {
var t = calcTrace0.t;
var poffset = t.poffset;
var barwidth = t.barwidth;
var poffsetIsArray = isArrayOrTypedArray(poffset);
var barwidthIsArray = isArrayOrTypedArray(barwidth);
for (j = 0; j < calcTrace.length; j++) {
bar = calcTrace[j];
var calcBarOffset = poffsetIsArray ? poffset[j] : poffset;
var calcBarWidth = barwidthIsArray ? barwidth[j] : barwidth;
l = bar.p + calcBarOffset;
r = l + calcBarWidth;
pts.push(l, r);
}
}
fullTrace._extremes[pa._id] = Axes.findExtremes(pa, pts, {
padded: false
});
}
}
// store these bar bases and tops in calcdata
// and make sure the size axis includes zero,
// along with the bases and tops of each bar.
function setBaseAndTop(sa, sieve) {
var calcTraces = sieve.traces;
var sLetter = getAxisLetter(sa);
for (var i = 0; i < calcTraces.length; i++) {
var calcTrace = calcTraces[i];
var fullTrace = calcTrace[0].trace;
var isScatter = fullTrace.type === 'scatter';
var isVertical = fullTrace.orientation === 'v';
var pts = [];
var tozero = false;
for (var j = 0; j < calcTrace.length; j++) {
var bar = calcTrace[j];
var base = isScatter ? 0 : bar.b;
var top = isScatter ? isVertical ? bar.y : bar.x : base + bar.s;
bar[sLetter] = top;
pts.push(top);
if (bar.hasB) pts.push(base);
if (!bar.hasB || !bar.b) {
tozero = true;
}
}
fullTrace._extremes[sa._id] = Axes.findExtremes(sa, pts, {
tozero: tozero,
padded: true
});
}
}
function stackBars(sa, sieve, opts) {
var sLetter = getAxisLetter(sa);
var calcTraces = sieve.traces;
var calcTrace;
var fullTrace;
var isFunnel;
var i, j;
var bar;
for (i = 0; i < calcTraces.length; i++) {
calcTrace = calcTraces[i];
fullTrace = calcTrace[0].trace;
if (fullTrace.type === 'funnel') {
for (j = 0; j < calcTrace.length; j++) {
bar = calcTrace[j];
if (bar.s !== BADNUM) {
// create base of funnels
sieve.put(bar.p, -0.5 * bar.s);
}
}
}
}
for (i = 0; i < calcTraces.length; i++) {
calcTrace = calcTraces[i];
fullTrace = calcTrace[0].trace;
isFunnel = fullTrace.type === 'funnel';
var pts = [];
for (j = 0; j < calcTrace.length; j++) {
bar = calcTrace[j];
if (bar.s !== BADNUM) {
// stack current bar and get previous sum
var value;
if (isFunnel) {
value = bar.s;
} else {
value = bar.s + bar.b;
}
var base = sieve.put(bar.p, value);
var top = base + value;
// store the bar base and top in each calcdata item
bar.b = base;
bar[sLetter] = top;
if (!opts.norm) {
pts.push(top);
if (bar.hasB) {
pts.push(base);
}
}
}
}
// if barnorm is set, let normalizeBars update the axis range
if (!opts.norm) {
fullTrace._extremes[sa._id] = Axes.findExtremes(sa, pts, {
// N.B. we don't stack base with 'base',
// so set tozero:true always!
tozero: true,
padded: true
});
}
}
}
function sieveBars(sieve) {
var calcTraces = sieve.traces;
for (var i = 0; i < calcTraces.length; i++) {
var calcTrace = calcTraces[i];
for (var j = 0; j < calcTrace.length; j++) {
var bar = calcTrace[j];
if (bar.s !== BADNUM) {
sieve.put(bar.p, bar.b + bar.s);
}
}
}
}
function unhideBarsWithinTrace(sieve, pa) {
var calcTraces = sieve.traces;
for (var i = 0; i < calcTraces.length; i++) {
var calcTrace = calcTraces[i];
var fullTrace = calcTrace[0].trace;
if (fullTrace.base === undefined) {
var inTraceSieve = new Sieve([calcTrace], {
posAxis: pa,
sepNegVal: true,
overlapNoMerge: true
});
for (var j = 0; j < calcTrace.length; j++) {
var bar = calcTrace[j];
if (bar.p !== BADNUM) {
// stack current bar and get previous sum
var base = inTraceSieve.put(bar.p, bar.b + bar.s);
// if previous sum if non-zero, this means:
// multiple bars have same starting point are potentially hidden,
// shift them vertically so that all bars are visible by default
if (base) bar.b = base;
}
}
}
}
}
// Note:
//
// normalizeBars requires that either sieveBars or stackBars has been
// previously invoked.
function normalizeBars(sa, sieve, opts) {
var calcTraces = sieve.traces;
var sLetter = getAxisLetter(sa);
var sTop = opts.norm === 'fraction' ? 1 : 100;
var sTiny = sTop / 1e9; // in case of rounding error in sum
var sMin = sa.l2c(sa.c2l(0));
var sMax = opts.mode === 'stack' ? sTop : sMin;
function needsPadding(v) {
return isNumeric(sa.c2l(v)) && (v < sMin - sTiny || v > sMax + sTiny || !isNumeric(sMin));
}
for (var i = 0; i < calcTraces.length; i++) {
var calcTrace = calcTraces[i];
var fullTrace = calcTrace[0].trace;
var pts = [];
var tozero = false;
var padded = false;
for (var j = 0; j < calcTrace.length; j++) {
var bar = calcTrace[j];
if (bar.s !== BADNUM) {
var scale = Math.abs(sTop / sieve.get(bar.p, bar.s));
bar.b *= scale;
bar.s *= scale;
var base = bar.b;
var top = base + bar.s;
bar[sLetter] = top;
pts.push(top);
padded = padded || needsPadding(top);
if (bar.hasB) {
pts.push(base);
padded = padded || needsPadding(base);
}
if (!bar.hasB || !bar.b) {
tozero = true;
}
}
}
fullTrace._extremes[sa._id] = Axes.findExtremes(sa, pts, {
tozero: tozero,
padded: padded
});
}
}
// Add an `_sMin` and `_sMax` value for each bar representing the min and max size value
// across all bars sharing the same position as that bar. These values are used for rounded
// bar corners, to carry rounding down to lower bars in the stack as needed.
function setHelperValuesForRoundedCorners(calcTraces, sMinByPos, sMaxByPos, pa) {
var pLetter = getAxisLetter(pa);
// Set `_sMin` and `_sMax` value for each bar
for (var i = 0; i < calcTraces.length; i++) {
var calcTrace = calcTraces[i];
for (var j = 0; j < calcTrace.length; j++) {
var bar = calcTrace[j];
var pos = bar[pLetter];
bar._sMin = sMinByPos[pos];
bar._sMax = sMaxByPos[pos];
}
}
}
// find the full position span of bars at each position
// for use by hover, to ensure labels move in if bars are
// narrower than the space they're in.
// run once per trace group (subplot & direction) and
// the same mapping is attached to all calcdata traces
function collectExtents(calcTraces, pa) {
var pLetter = getAxisLetter(pa);
var extents = {};
var i, j, cd;
var pMin = Infinity;
var pMax = -Infinity;
for (i = 0; i < calcTraces.length; i++) {
cd = calcTraces[i];
for (j = 0; j < cd.length; j++) {
var p = cd[j].p;
if (isNumeric(p)) {
pMin = Math.min(pMin, p);
pMax = Math.max(pMax, p);
}
}
}
// this is just for positioning of hover labels, and nobody will care if
// the label is 1px too far out; so round positions to 1/10K in case
// position values don't exactly match from trace to trace
var roundFactor = 10000 / (pMax - pMin);
var round = extents.round = function (p) {
return String(Math.round(roundFactor * (p - pMin)));
};
// Find min and max size axis extent for each position
// This is used for rounded bar corners, to carry rounding
// down to lower bars in the case of stacked bars
var sMinByPos = {};
var sMaxByPos = {};
// Check whether any trace has rounded corners
var anyTraceHasCornerradius = calcTraces.some(function (x) {
var trace = x[0].trace;
return 'marker' in trace && trace.marker.cornerradius;
});
for (i = 0; i < calcTraces.length; i++) {
cd = calcTraces[i];
cd[0].t.extents = extents;
var poffset = cd[0].t.poffset;
var poffsetIsArray = isArrayOrTypedArray(poffset);
for (j = 0; j < cd.length; j++) {
var di = cd[j];
var p0 = di[pLetter] - di.w / 2;
if (isNumeric(p0)) {
var p1 = di[pLetter] + di.w / 2;
var pVal = round(di.p);
if (extents[pVal]) {
extents[pVal] = [Math.min(p0, extents[pVal][0]), Math.max(p1, extents[pVal][1])];
} else {
extents[pVal] = [p0, p1];
}
}
di.p0 = di.p + (poffsetIsArray ? poffset[j] : poffset);
di.p1 = di.p0 + di.w;
di.s0 = di.b;
di.s1 = di.s0 + di.s;
if (anyTraceHasCornerradius) {
var sMin = Math.min(di.s0, di.s1) || 0;
var sMax = Math.max(di.s0, di.s1) || 0;
var pos = di[pLetter];
sMinByPos[pos] = pos in sMinByPos ? Math.min(sMinByPos[pos], sMin) : sMin;
sMaxByPos[pos] = pos in sMaxByPos ? Math.max(sMaxByPos[pos], sMax) : sMax;
}
}
}
if (anyTraceHasCornerradius) {
setHelperValuesForRoundedCorners(calcTraces, sMinByPos, sMaxByPos, pa);
}
}
function getAxisLetter(ax) {
return ax._id.charAt(0);
}
module.exports = {
crossTraceCalc: crossTraceCalc,
setGroupPositions: setGroupPositions
};
/***/ }),
/***/ 2592:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
module.exports = Sieve;
var distinctVals = (__webpack_require__(3400).distinctVals);
/**
* Helper class to sieve data from traces into bins
*
* @class
*
* @param {Array} traces
* Array of calculated traces
* @param {object} opts
* - @param {boolean} [sepNegVal]
* If true, then split data at the same position into a bar
* for positive values and another for negative values
* - @param {boolean} [overlapNoMerge]
* If true, then don't merge overlapping bars into a single bar
*/
function Sieve(traces, opts) {
this.traces = traces;
this.sepNegVal = opts.sepNegVal;
this.overlapNoMerge = opts.overlapNoMerge;
// for single-bin histograms - see histogram/calc
var width1 = Infinity;
var axLetter = opts.posAxis._id.charAt(0);
var positions = [];
for (var i = 0; i < traces.length; i++) {
var trace = traces[i];
for (var j = 0; j < trace.length; j++) {
var bar = trace[j];
var pos = bar.p;
if (pos === undefined) {
pos = bar[axLetter];
}
if (pos !== undefined) positions.push(pos);
}
if (trace[0] && trace[0].width1) {
width1 = Math.min(trace[0].width1, width1);
}
}
this.positions = positions;
var dv = distinctVals(positions);
this.distinctPositions = dv.vals;
if (dv.vals.length === 1 && width1 !== Infinity) this.minDiff = width1;else this.minDiff = Math.min(dv.minDiff, width1);
var type = (opts.posAxis || {}).type;
if (type === 'category' || type === 'multicategory') {
this.minDiff = 1;
}
this.binWidth = this.minDiff;
this.bins = {};
}
/**
* Sieve datum
*
* @method
* @param {number} position
* @param {number} value
* @returns {number} Previous bin value
*/
Sieve.prototype.put = function put(position, value) {
var label = this.getLabel(position, value);
var oldValue = this.bins[label] || 0;
this.bins[label] = oldValue + value;
return oldValue;
};
/**
* Get current bin value for a given datum
*
* @method
* @param {number} position Position of datum
* @param {number} [value] Value of datum
* (required if this.sepNegVal is true)
* @returns {number} Current bin value
*/
Sieve.prototype.get = function get(position, value) {
var label = this.getLabel(position, value);
return this.bins[label] || 0;
};
/**
* Get bin label for a given datum
*
* @method
* @param {number} position Position of datum
* @param {number} [value] Value of datum
* (required if this.sepNegVal is true)
* @returns {string} Bin label
* (prefixed with a 'v' if value is negative and this.sepNegVal is
* true; otherwise prefixed with '^')
*/
Sieve.prototype.getLabel = function getLabel(position, value) {
var prefix = value < 0 && this.sepNegVal ? 'v' : '^';
var label = this.overlapNoMerge ? position : Math.round(position / this.binWidth);
return prefix + label;
};
/***/ }),
/***/ 3372:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var hovertemplateAttrs = (__webpack_require__(1776)/* .hovertemplateAttrs */ .Ks);
var scatterGeoAttrs = __webpack_require__(6096);
var colorScaleAttrs = __webpack_require__(9084);
var baseAttrs = __webpack_require__(5464);
var defaultLine = (__webpack_require__(2548).defaultLine);
var extendFlat = (__webpack_require__(2880).extendFlat);
var scatterGeoMarkerLineAttrs = scatterGeoAttrs.marker.line;
module.exports = extendFlat({
locations: {
valType: 'data_array',
editType: 'calc'
},
locationmode: scatterGeoAttrs.locationmode,
z: {
valType: 'data_array',
editType: 'calc'
},
geojson: extendFlat({}, scatterGeoAttrs.geojson, {}),
featureidkey: scatterGeoAttrs.featureidkey,
text: extendFlat({}, scatterGeoAttrs.text, {}),
hovertext: extendFlat({}, scatterGeoAttrs.hovertext, {}),
marker: {
line: {
color: extendFlat({}, scatterGeoMarkerLineAttrs.color, {
dflt: defaultLine
}),
width: extendFlat({}, scatterGeoMarkerLineAttrs.width, {
dflt: 1
}),
editType: 'calc'
},
opacity: {
valType: 'number',
arrayOk: true,
min: 0,
max: 1,
dflt: 1,
editType: 'style'
},
editType: 'calc'
},
selected: {
marker: {
opacity: scatterGeoAttrs.selected.marker.opacity,
editType: 'plot'
},
editType: 'plot'
},
unselected: {
marker: {
opacity: scatterGeoAttrs.unselected.marker.opacity,
editType: 'plot'
},
editType: 'plot'
},
hoverinfo: extendFlat({}, baseAttrs.hoverinfo, {
editType: 'calc',
flags: ['location', 'z', 'text', 'name']
}),
hovertemplate: hovertemplateAttrs(),
showlegend: extendFlat({}, baseAttrs.showlegend, {
dflt: false
})
}, colorScaleAttrs('', {
cLetter: 'z',
editTypeOverride: 'calc'
}));
/***/ }),
/***/ 7924:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var isNumeric = __webpack_require__(8248);
var BADNUM = (__webpack_require__(9032).BADNUM);
var colorscaleCalc = __webpack_require__(7128);
var arraysToCalcdata = __webpack_require__(148);
var calcSelection = __webpack_require__(4500);
function isNonBlankString(v) {
return v && typeof v === 'string';
}
module.exports = function calc(gd, trace) {
var len = trace._length;
var calcTrace = new Array(len);
var isValidLoc;
if (trace.geojson) {
isValidLoc = function (v) {
return isNonBlankString(v) || isNumeric(v);
};
} else {
isValidLoc = isNonBlankString;
}
for (var i = 0; i < len; i++) {
var calcPt = calcTrace[i] = {};
var loc = trace.locations[i];
var z = trace.z[i];
if (isValidLoc(loc) && isNumeric(z)) {
calcPt.loc = loc;
calcPt.z = z;
} else {
calcPt.loc = null;
calcPt.z = BADNUM;
}
calcPt.index = i;
}
arraysToCalcdata(calcTrace, trace);
colorscaleCalc(gd, trace, {
vals: trace.z,
containerStr: '',
cLetter: 'z'
});
calcSelection(calcTrace, trace);
return calcTrace;
};
/***/ }),
/***/ 7664:
/***/ (function(module) {
"use strict";
module.exports = function eventData(out, pt, trace, cd, pointNumber) {
out.location = pt.location;
out.z = pt.z;
// include feature properties from input geojson
var cdi = cd[pointNumber];
if (cdi.fIn && cdi.fIn.properties) {
out.properties = cdi.fIn.properties;
}
out.ct = cdi.ct;
return out;
};
/***/ }),
/***/ 4464:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Axes = __webpack_require__(4460);
var attributes = __webpack_require__(3372);
var fillText = (__webpack_require__(3400).fillText);
module.exports = function hoverPoints(pointData, xval, yval) {
var cd = pointData.cd;
var trace = cd[0].trace;
var geo = pointData.subplot;
var pt, i, j, isInside;
var xy = [xval, yval];
var altXy = [xval + 360, yval];
for (i = 0; i < cd.length; i++) {
pt = cd[i];
isInside = false;
if (pt._polygons) {
for (j = 0; j < pt._polygons.length; j++) {
if (pt._polygons[j].contains(xy)) {
isInside = !isInside;
}
// for polygons that cross antimeridian as xval is in [-180, 180]
if (pt._polygons[j].contains(altXy)) {
isInside = !isInside;
}
}
if (isInside) break;
}
}
if (!isInside || !pt) return;
pointData.x0 = pointData.x1 = pointData.xa.c2p(pt.ct);
pointData.y0 = pointData.y1 = pointData.ya.c2p(pt.ct);
pointData.index = pt.index;
pointData.location = pt.loc;
pointData.z = pt.z;
pointData.zLabel = Axes.tickText(geo.mockAxis, geo.mockAxis.c2l(pt.z), 'hover').text;
pointData.hovertemplate = pt.hovertemplate;
makeHoverInfo(pointData, trace, pt);
return [pointData];
};
function makeHoverInfo(pointData, trace, pt) {
if (trace.hovertemplate) return;
var hoverinfo = pt.hi || trace.hoverinfo;
var loc = String(pt.loc);
var parts = hoverinfo === 'all' ? attributes.hoverinfo.flags : hoverinfo.split('+');
var hasName = parts.indexOf('name') !== -1;
var hasLocation = parts.indexOf('location') !== -1;
var hasZ = parts.indexOf('z') !== -1;
var hasText = parts.indexOf('text') !== -1;
var hasIdAsNameLabel = !hasName && hasLocation;
var text = [];
if (hasIdAsNameLabel) {
pointData.nameOverride = loc;
} else {
if (hasName) pointData.nameOverride = trace.name;
if (hasLocation) text.push(loc);
}
if (hasZ) {
text.push(pointData.zLabel);
}
if (hasText) {
fillText(pt, trace, text);
}
pointData.extraText = text.join('
');
}
/***/ }),
/***/ 7328:
/***/ (function(module) {
"use strict";
module.exports = function selectPoints(searchInfo, selectionTester) {
var cd = searchInfo.cd;
var xa = searchInfo.xaxis;
var ya = searchInfo.yaxis;
var selection = [];
var i, di, ct, x, y;
if (selectionTester === false) {
for (i = 0; i < cd.length; i++) {
cd[i].selected = 0;
}
} else {
for (i = 0; i < cd.length; i++) {
di = cd[i];
ct = di.ct;
if (!ct) continue;
x = xa.c2p(ct);
y = ya.c2p(ct);
if (selectionTester.contains([x, y], null, i, searchInfo)) {
selection.push({
pointNumber: i,
lon: ct[0],
lat: ct[1]
});
di.selected = 1;
} else {
di.selected = 0;
}
}
}
return selection;
};
/***/ }),
/***/ 5608:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var choroplethAttrs = __webpack_require__(3372);
var colorScaleAttrs = __webpack_require__(9084);
var hovertemplateAttrs = (__webpack_require__(1776)/* .hovertemplateAttrs */ .Ks);
var baseAttrs = __webpack_require__(5464);
var extendFlat = (__webpack_require__(2880).extendFlat);
module.exports = extendFlat({
locations: {
valType: 'data_array',
editType: 'calc'
},
// TODO
// Maybe start with only one value (that we could name e.g. 'geojson-id'),
// but eventually:
// - we could also support for our own dist/topojson/*
// .. and locationmode: choroplethAttrs.locationmode,
z: {
valType: 'data_array',
editType: 'calc'
},
// TODO maybe we could also set a "key" to dig out values out of the
// GeoJSON feature `properties` fields?
geojson: {
valType: 'any',
editType: 'calc'
},
featureidkey: extendFlat({}, choroplethAttrs.featureidkey, {}),
// TODO agree on name / behaviour
//
// 'below' is used currently for layout.mapbox.layers,
// even though it's not very plotly-esque.
//
// Note also, that the mapbox-gl style don't all have the same layers,
// see https://codepen.io/etpinard/pen/ydVMwM for full list
below: {
valType: 'string',
editType: 'plot'
},
text: choroplethAttrs.text,
hovertext: choroplethAttrs.hovertext,
marker: {
line: {
color: extendFlat({}, choroplethAttrs.marker.line.color, {
editType: 'plot'
}),
width: extendFlat({}, choroplethAttrs.marker.line.width, {
editType: 'plot'
}),
editType: 'calc'
},
// TODO maybe having a dflt less than 1, together with `below:''` would be better?
opacity: extendFlat({}, choroplethAttrs.marker.opacity, {
editType: 'plot'
}),
editType: 'calc'
},
selected: {
marker: {
opacity: extendFlat({}, choroplethAttrs.selected.marker.opacity, {
editType: 'plot'
}),
editType: 'plot'
},
editType: 'plot'
},
unselected: {
marker: {
opacity: extendFlat({}, choroplethAttrs.unselected.marker.opacity, {
editType: 'plot'
}),
editType: 'plot'
},
editType: 'plot'
},
hoverinfo: choroplethAttrs.hoverinfo,
hovertemplate: hovertemplateAttrs({}, {
keys: ['properties']
}),
showlegend: extendFlat({}, baseAttrs.showlegend, {
dflt: false
})
}, colorScaleAttrs('', {
cLetter: 'z',
editTypeOverride: 'calc'
}));
/***/ }),
/***/ 3504:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var isNumeric = __webpack_require__(8248);
var Lib = __webpack_require__(3400);
var Colorscale = __webpack_require__(8932);
var Drawing = __webpack_require__(3616);
var makeBlank = (__webpack_require__(4808).makeBlank);
var geoUtils = __webpack_require__(7144);
/* N.B.
*
* We fetch the GeoJSON files "ourselves" (during
* mapbox.prototype.fetchMapData) where they are stored in a global object
* named `PlotlyGeoAssets` (same as for topojson files in `geo` subplots).
*
* Mapbox does allow using URLs as geojson sources, but does NOT allow filtering
* features by feature `id` that are not numbers (more info in:
* https://github.com/mapbox/mapbox-gl-js/issues/8088).
*/
function convert(calcTrace) {
var trace = calcTrace[0].trace;
var isVisible = trace.visible === true && trace._length !== 0;
var fill = {
layout: {
visibility: 'none'
},
paint: {}
};
var line = {
layout: {
visibility: 'none'
},
paint: {}
};
var opts = trace._opts = {
fill: fill,
line: line,
geojson: makeBlank()
};
if (!isVisible) return opts;
var features = geoUtils.extractTraceFeature(calcTrace);
if (!features) return opts;
var sclFunc = Colorscale.makeColorScaleFuncFromTrace(trace);
var marker = trace.marker;
var markerLine = marker.line || {};
var opacityFn;
if (Lib.isArrayOrTypedArray(marker.opacity)) {
opacityFn = function (d) {
var mo = d.mo;
return isNumeric(mo) ? +Lib.constrain(mo, 0, 1) : 0;
};
}
var lineColorFn;
if (Lib.isArrayOrTypedArray(markerLine.color)) {
lineColorFn = function (d) {
return d.mlc;
};
}
var lineWidthFn;
if (Lib.isArrayOrTypedArray(markerLine.width)) {
lineWidthFn = function (d) {
return d.mlw;
};
}
for (var i = 0; i < calcTrace.length; i++) {
var cdi = calcTrace[i];
var fOut = cdi.fOut;
if (fOut) {
var props = fOut.properties;
props.fc = sclFunc(cdi.z);
if (opacityFn) props.mo = opacityFn(cdi);
if (lineColorFn) props.mlc = lineColorFn(cdi);
if (lineWidthFn) props.mlw = lineWidthFn(cdi);
cdi.ct = props.ct;
cdi._polygons = geoUtils.feature2polygons(fOut);
}
}
var opacitySetting = opacityFn ? {
type: 'identity',
property: 'mo'
} : marker.opacity;
Lib.extendFlat(fill.paint, {
'fill-color': {
type: 'identity',
property: 'fc'
},
'fill-opacity': opacitySetting
});
Lib.extendFlat(line.paint, {
'line-color': lineColorFn ? {
type: 'identity',
property: 'mlc'
} : markerLine.color,
'line-width': lineWidthFn ? {
type: 'identity',
property: 'mlw'
} : markerLine.width,
'line-opacity': opacitySetting
});
fill.layout.visibility = 'visible';
line.layout.visibility = 'visible';
opts.geojson = {
type: 'FeatureCollection',
features: features
};
convertOnSelect(calcTrace);
return opts;
}
function convertOnSelect(calcTrace) {
var trace = calcTrace[0].trace;
var opts = trace._opts;
var opacitySetting;
if (trace.selectedpoints) {
var fns = Drawing.makeSelectedPointStyleFns(trace);
for (var i = 0; i < calcTrace.length; i++) {
var cdi = calcTrace[i];
if (cdi.fOut) {
cdi.fOut.properties.mo2 = fns.selectedOpacityFn(cdi);
}
}
opacitySetting = {
type: 'identity',
property: 'mo2'
};
} else {
opacitySetting = Lib.isArrayOrTypedArray(trace.marker.opacity) ? {
type: 'identity',
property: 'mo'
} : trace.marker.opacity;
}
Lib.extendFlat(opts.fill.paint, {
'fill-opacity': opacitySetting
});
Lib.extendFlat(opts.line.paint, {
'line-opacity': opacitySetting
});
return opts;
}
module.exports = {
convert: convert,
convertOnSelect: convertOnSelect
};
/***/ }),
/***/ 9352:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Lib = __webpack_require__(3400);
var colorscaleDefaults = __webpack_require__(7260);
var attributes = __webpack_require__(5608);
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
function coerce(attr, dflt) {
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}
var locations = coerce('locations');
var z = coerce('z');
var geojson = coerce('geojson');
if (!Lib.isArrayOrTypedArray(locations) || !locations.length || !Lib.isArrayOrTypedArray(z) || !z.length || !(typeof geojson === 'string' && geojson !== '' || Lib.isPlainObject(geojson))) {
traceOut.visible = false;
return;
}
coerce('featureidkey');
traceOut._length = Math.min(locations.length, z.length);
coerce('below');
coerce('text');
coerce('hovertext');
coerce('hovertemplate');
var mlw = coerce('marker.line.width');
if (mlw) coerce('marker.line.color');
coerce('marker.opacity');
colorscaleDefaults(traceIn, traceOut, layout, coerce, {
prefix: '',
cLetter: 'z'
});
Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
};
/***/ }),
/***/ 3023:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
module.exports = {
attributes: __webpack_require__(5608),
supplyDefaults: __webpack_require__(9352),
colorbar: __webpack_require__(6288),
calc: __webpack_require__(7924),
plot: __webpack_require__(1288),
hoverPoints: __webpack_require__(4464),
eventData: __webpack_require__(7664),
selectPoints: __webpack_require__(7328),
styleOnSelect: function (_, cd) {
if (cd) {
var trace = cd[0].trace;
trace._glTrace.updateOnSelect(cd);
}
},
getBelow: function (trace, subplot) {
var mapLayers = subplot.getMapLayers();
// find layer just above top-most "water" layer
// that is not a plotly layer
for (var i = mapLayers.length - 2; i >= 0; i--) {
var layerId = mapLayers[i].id;
if (typeof layerId === 'string' && layerId.indexOf('water') === 0) {
for (var j = i + 1; j < mapLayers.length; j++) {
layerId = mapLayers[j].id;
if (typeof layerId === 'string' && layerId.indexOf('plotly-') === -1) {
return layerId;
}
}
}
}
},
moduleType: 'trace',
name: 'choroplethmapbox',
basePlotModule: __webpack_require__(1308),
categories: ['mapbox', 'gl', 'noOpacity', 'showLegend'],
meta: {
hr_name: 'choropleth_mapbox'
}
};
/***/ }),
/***/ 1288:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var convert = (__webpack_require__(3504).convert);
var convertOnSelect = (__webpack_require__(3504).convertOnSelect);
var LAYER_PREFIX = (__webpack_require__(7552).traceLayerPrefix);
function ChoroplethMapbox(subplot, uid) {
this.type = 'choroplethmapbox';
this.subplot = subplot;
this.uid = uid;
// N.B. fill and line layers share same source
this.sourceId = 'source-' + uid;
this.layerList = [['fill', LAYER_PREFIX + uid + '-fill'], ['line', LAYER_PREFIX + uid + '-line']];
// previous 'below' value,
// need this to update it properly
this.below = null;
}
var proto = ChoroplethMapbox.prototype;
proto.update = function (calcTrace) {
this._update(convert(calcTrace));
// link ref for quick update during selections
calcTrace[0].trace._glTrace = this;
};
proto.updateOnSelect = function (calcTrace) {
this._update(convertOnSelect(calcTrace));
};
proto._update = function (optsAll) {
var subplot = this.subplot;
var layerList = this.layerList;
var below = subplot.belowLookup['trace-' + this.uid];
subplot.map.getSource(this.sourceId).setData(optsAll.geojson);
if (below !== this.below) {
this._removeLayers();
this._addLayers(optsAll, below);
this.below = below;
}
for (var i = 0; i < layerList.length; i++) {
var item = layerList[i];
var k = item[0];
var id = item[1];
var opts = optsAll[k];
subplot.setOptions(id, 'setLayoutProperty', opts.layout);
if (opts.layout.visibility === 'visible') {
subplot.setOptions(id, 'setPaintProperty', opts.paint);
}
}
};
proto._addLayers = function (optsAll, below) {
var subplot = this.subplot;
var layerList = this.layerList;
var sourceId = this.sourceId;
for (var i = 0; i < layerList.length; i++) {
var item = layerList[i];
var k = item[0];
var opts = optsAll[k];
subplot.addLayer({
type: k,
id: item[1],
source: sourceId,
layout: opts.layout,
paint: opts.paint
}, below);
}
};
proto._removeLayers = function () {
var map = this.subplot.map;
var layerList = this.layerList;
for (var i = layerList.length - 1; i >= 0; i--) {
map.removeLayer(layerList[i][1]);
}
};
proto.dispose = function () {
var map = this.subplot.map;
this._removeLayers();
map.removeSource(this.sourceId);
};
module.exports = function createChoroplethMapbox(subplot, calcTrace) {
var trace = calcTrace[0].trace;
var choroplethMapbox = new ChoroplethMapbox(subplot, trace.uid);
var sourceId = choroplethMapbox.sourceId;
var optsAll = convert(calcTrace);
var below = choroplethMapbox.below = subplot.belowLookup['trace-' + trace.uid];
subplot.map.addSource(sourceId, {
type: 'geojson',
data: optsAll.geojson
});
choroplethMapbox._addLayers(optsAll, below);
// link ref for quick update during selections
calcTrace[0].trace._glTrace = choroplethMapbox;
return choroplethMapbox;
};
/***/ }),
/***/ 3928:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var colorScaleAttrs = __webpack_require__(9084);
var hovertemplateAttrs = (__webpack_require__(1776)/* .hovertemplateAttrs */ .Ks);
var baseAttrs = __webpack_require__(5464);
var scatterMapboxAttrs = __webpack_require__(1512);
var extendFlat = (__webpack_require__(2880).extendFlat);
/*
* - https://docs.mapbox.com/help/tutorials/make-a-heatmap-with-mapbox-gl-js/
* - https://docs.mapbox.com/mapbox-gl-js/example/heatmap-layer/
* - https://docs.mapbox.com/mapbox-gl-js/style-spec/#layers-heatmap
* - https://blog.mapbox.com/introducing-heatmaps-in-mapbox-gl-js-71355ada9e6c
*
* Gotchas:
* - https://github.com/mapbox/mapbox-gl-js/issues/6463
* - https://github.com/mapbox/mapbox-gl-js/issues/6112
*/
/*
*
* In mathematical terms, Mapbox GL heatmaps are a bivariate (2D) kernel density
* estimation with a Gaussian kernel. It means that each data point has an area
* of “influence” around it (called a kernel) where the numerical value of
* influence (which we call density) decreases as you go further from the point.
* If we sum density values of all points in every pixel of the screen, we get a
* combined density value which we then map to a heatmap color.
*
*/
module.exports = extendFlat({
lon: scatterMapboxAttrs.lon,
lat: scatterMapboxAttrs.lat,
z: {
valType: 'data_array',
editType: 'calc'
},
radius: {
valType: 'number',
editType: 'plot',
arrayOk: true,
min: 1,
dflt: 30
},
below: {
valType: 'string',
editType: 'plot'
},
text: scatterMapboxAttrs.text,
hovertext: scatterMapboxAttrs.hovertext,
hoverinfo: extendFlat({}, baseAttrs.hoverinfo, {
flags: ['lon', 'lat', 'z', 'text', 'name']
}),
hovertemplate: hovertemplateAttrs(),
showlegend: extendFlat({}, baseAttrs.showlegend, {
dflt: false
})
}, colorScaleAttrs('', {
cLetter: 'z',
editTypeOverride: 'calc'
}));
/***/ }),
/***/ 8496:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var isNumeric = __webpack_require__(8248);
var isArrayOrTypedArray = (__webpack_require__(3400).isArrayOrTypedArray);
var BADNUM = (__webpack_require__(9032).BADNUM);
var colorscaleCalc = __webpack_require__(7128);
var _ = (__webpack_require__(3400)._);
module.exports = function calc(gd, trace) {
var len = trace._length;
var calcTrace = new Array(len);
var z = trace.z;
var hasZ = isArrayOrTypedArray(z) && z.length;
for (var i = 0; i < len; i++) {
var cdi = calcTrace[i] = {};
var lon = trace.lon[i];
var lat = trace.lat[i];
cdi.lonlat = isNumeric(lon) && isNumeric(lat) ? [+lon, +lat] : [BADNUM, BADNUM];
if (hasZ) {
var zi = z[i];
cdi.z = isNumeric(zi) ? zi : BADNUM;
}
}
colorscaleCalc(gd, trace, {
vals: hasZ ? z : [0, 1],
containerStr: '',
cLetter: 'z'
});
if (len) {
calcTrace[0].t = {
labels: {
lat: _(gd, 'lat:') + ' ',
lon: _(gd, 'lon:') + ' '
}
};
}
return calcTrace;
};
/***/ }),
/***/ 4629:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var isNumeric = __webpack_require__(8248);
var Lib = __webpack_require__(3400);
var Color = __webpack_require__(6308);
var Colorscale = __webpack_require__(8932);
var BADNUM = (__webpack_require__(9032).BADNUM);
var makeBlank = (__webpack_require__(4808).makeBlank);
module.exports = function convert(calcTrace) {
var trace = calcTrace[0].trace;
var isVisible = trace.visible === true && trace._length !== 0;
var heatmap = {
layout: {
visibility: 'none'
},
paint: {}
};
var opts = trace._opts = {
heatmap: heatmap,
geojson: makeBlank()
};
// early return if not visible or placeholder
if (!isVisible) return opts;
var features = [];
var i;
var z = trace.z;
var radius = trace.radius;
var hasZ = Lib.isArrayOrTypedArray(z) && z.length;
var hasArrayRadius = Lib.isArrayOrTypedArray(radius);
for (i = 0; i < calcTrace.length; i++) {
var cdi = calcTrace[i];
var lonlat = cdi.lonlat;
if (lonlat[0] !== BADNUM) {
var props = {};
if (hasZ) {
var zi = cdi.z;
props.z = zi !== BADNUM ? zi : 0;
}
if (hasArrayRadius) {
props.r = isNumeric(radius[i]) && radius[i] > 0 ? +radius[i] : 0;
}
features.push({
type: 'Feature',
geometry: {
type: 'Point',
coordinates: lonlat
},
properties: props
});
}
}
var cOpts = Colorscale.extractOpts(trace);
var scl = cOpts.reversescale ? Colorscale.flipScale(cOpts.colorscale) : cOpts.colorscale;
// Add alpha channel to first colorscale step.
// If not, we would essentially color the entire map.
// See https://docs.mapbox.com/mapbox-gl-js/example/heatmap-layer/
var scl01 = scl[0][1];
var color0 = Color.opacity(scl01) < 1 ? scl01 : Color.addOpacity(scl01, 0);
var heatmapColor = ['interpolate', ['linear'], ['heatmap-density'], 0, color0];
for (i = 1; i < scl.length; i++) {
heatmapColor.push(scl[i][0], scl[i][1]);
}
// Those "weights" have to be in [0, 1], we can do this either:
// - as here using a mapbox-gl expression
// - or, scale the 'z' property in the feature loop
var zExp = ['interpolate', ['linear'], ['get', 'z'], cOpts.min, 0, cOpts.max, 1];
Lib.extendFlat(opts.heatmap.paint, {
'heatmap-weight': hasZ ? zExp : 1 / (cOpts.max - cOpts.min),
'heatmap-color': heatmapColor,
'heatmap-radius': hasArrayRadius ? {
type: 'identity',
property: 'r'
} : trace.radius,
'heatmap-opacity': trace.opacity
});
opts.geojson = {
type: 'FeatureCollection',
features: features
};
opts.heatmap.layout.visibility = 'visible';
return opts;
};
/***/ }),
/***/ 5284:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Lib = __webpack_require__(3400);
var colorscaleDefaults = __webpack_require__(7260);
var attributes = __webpack_require__(3928);
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
function coerce(attr, dflt) {
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}
var lon = coerce('lon') || [];
var lat = coerce('lat') || [];
var len = Math.min(lon.length, lat.length);
if (!len) {
traceOut.visible = false;
return;
}
traceOut._length = len;
coerce('z');
coerce('radius');
coerce('below');
coerce('text');
coerce('hovertext');
coerce('hovertemplate');
colorscaleDefaults(traceIn, traceOut, layout, coerce, {
prefix: '',
cLetter: 'z'
});
};
/***/ }),
/***/ 6176:
/***/ (function(module) {
"use strict";
module.exports = function eventData(out, pt) {
out.lon = pt.lon;
out.lat = pt.lat;
out.z = pt.z;
return out;
};
/***/ }),
/***/ 5336:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Axes = __webpack_require__(4460);
var scatterMapboxHoverPoints = (__webpack_require__(3312).hoverPoints);
var getExtraText = (__webpack_require__(3312).getExtraText);
module.exports = function hoverPoints(pointData, xval, yval) {
var pts = scatterMapboxHoverPoints(pointData, xval, yval);
if (!pts) return;
var newPointData = pts[0];
var cd = newPointData.cd;
var trace = cd[0].trace;
var di = cd[newPointData.index];
// let Fx.hover pick the color
delete newPointData.color;
if ('z' in di) {
var ax = newPointData.subplot.mockAxis;
newPointData.z = di.z;
newPointData.zLabel = Axes.tickText(ax, ax.c2l(di.z), 'hover').text;
}
newPointData.extraText = getExtraText(trace, di, cd[0].t.labels);
return [newPointData];
};
/***/ }),
/***/ 5088:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
module.exports = {
attributes: __webpack_require__(3928),
supplyDefaults: __webpack_require__(5284),
colorbar: __webpack_require__(6288),
formatLabels: __webpack_require__(1960),
calc: __webpack_require__(8496),
plot: __webpack_require__(5256),
hoverPoints: __webpack_require__(5336),
eventData: __webpack_require__(6176),
getBelow: function (trace, subplot) {
var mapLayers = subplot.getMapLayers();
// find first layer with `type: 'symbol'`,
// that is not a plotly layer
for (var i = 0; i < mapLayers.length; i++) {
var layer = mapLayers[i];
var layerId = layer.id;
if (layer.type === 'symbol' && typeof layerId === 'string' && layerId.indexOf('plotly-') === -1) {
return layerId;
}
}
},
moduleType: 'trace',
name: 'densitymapbox',
basePlotModule: __webpack_require__(1308),
categories: ['mapbox', 'gl', 'showLegend'],
meta: {
hr_name: 'density_mapbox'
}
};
/***/ }),
/***/ 5256:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var convert = __webpack_require__(4629);
var LAYER_PREFIX = (__webpack_require__(7552).traceLayerPrefix);
function DensityMapbox(subplot, uid) {
this.type = 'densitymapbox';
this.subplot = subplot;
this.uid = uid;
this.sourceId = 'source-' + uid;
this.layerList = [['heatmap', LAYER_PREFIX + uid + '-heatmap']];
// previous 'below' value,
// need this to update it properly
this.below = null;
}
var proto = DensityMapbox.prototype;
proto.update = function (calcTrace) {
var subplot = this.subplot;
var layerList = this.layerList;
var optsAll = convert(calcTrace);
var below = subplot.belowLookup['trace-' + this.uid];
subplot.map.getSource(this.sourceId).setData(optsAll.geojson);
if (below !== this.below) {
this._removeLayers();
this._addLayers(optsAll, below);
this.below = below;
}
for (var i = 0; i < layerList.length; i++) {
var item = layerList[i];
var k = item[0];
var id = item[1];
var opts = optsAll[k];
subplot.setOptions(id, 'setLayoutProperty', opts.layout);
if (opts.layout.visibility === 'visible') {
subplot.setOptions(id, 'setPaintProperty', opts.paint);
}
}
};
proto._addLayers = function (optsAll, below) {
var subplot = this.subplot;
var layerList = this.layerList;
var sourceId = this.sourceId;
for (var i = 0; i < layerList.length; i++) {
var item = layerList[i];
var k = item[0];
var opts = optsAll[k];
subplot.addLayer({
type: k,
id: item[1],
source: sourceId,
layout: opts.layout,
paint: opts.paint
}, below);
}
};
proto._removeLayers = function () {
var map = this.subplot.map;
var layerList = this.layerList;
for (var i = layerList.length - 1; i >= 0; i--) {
map.removeLayer(layerList[i][1]);
}
};
proto.dispose = function () {
var map = this.subplot.map;
this._removeLayers();
map.removeSource(this.sourceId);
};
module.exports = function createDensityMapbox(subplot, calcTrace) {
var trace = calcTrace[0].trace;
var densityMapbox = new DensityMapbox(subplot, trace.uid);
var sourceId = densityMapbox.sourceId;
var optsAll = convert(calcTrace);
var below = densityMapbox.below = subplot.belowLookup['trace-' + trace.uid];
subplot.map.addSource(sourceId, {
type: 'geojson',
data: optsAll.geojson
});
densityMapbox._addLayers(optsAll, below);
return densityMapbox;
};
/***/ }),
/***/ 6288:
/***/ (function(module) {
"use strict";
module.exports = {
min: 'zmin',
max: 'zmax'
};
/***/ }),
/***/ 1552:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Drawing = __webpack_require__(3616);
var Color = __webpack_require__(6308);
module.exports = function fillOne(s, pt, trace, gd) {
var pattern = trace.marker.pattern;
if (pattern && pattern.shape) {
Drawing.pointStyle(s, trace, gd, pt);
} else {
Color.fill(s, pt.color);
}
};
/***/ }),
/***/ 9656:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
var Lib = __webpack_require__(3400);
function format(vRounded) {
return vRounded.indexOf('e') !== -1 ? vRounded.replace(/[.]?0+e/, 'e') : vRounded.indexOf('.') !== -1 ? vRounded.replace(/[.]?0+$/, '') : vRounded;
}
exports.formatPiePercent = function formatPiePercent(v, separators) {
var vRounded = format((v * 100).toPrecision(3));
return Lib.numSeparate(vRounded, separators) + '%';
};
exports.formatPieValue = function formatPieValue(v, separators) {
var vRounded = format(v.toPrecision(10));
return Lib.numSeparate(vRounded, separators);
};
exports.getFirstFilled = function getFirstFilled(array, indices) {
if (!Lib.isArrayOrTypedArray(array)) return;
for (var i = 0; i < indices.length; i++) {
var v = array[indices[i]];
if (v || v === 0 || v === '') return v;
}
};
exports.castOption = function castOption(item, indices) {
if (Lib.isArrayOrTypedArray(item)) return exports.getFirstFilled(item, indices);else if (item) return item;
};
exports.getRotationAngle = function (rotation) {
return (rotation === 'auto' ? 0 : rotation) * Math.PI / 180;
};
/***/ }),
/***/ 528:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Color = __webpack_require__(6308);
var castOption = (__webpack_require__(9656).castOption);
var fillOne = __webpack_require__(1552);
module.exports = function styleOne(s, pt, trace, gd) {
var line = trace.marker.line;
var lineColor = castOption(line.color, pt.pts) || Color.defaultLine;
var lineWidth = castOption(line.width, pt.pts) || 0;
s.call(fillOne, pt, trace, gd).style('stroke-width', lineWidth).call(Color.stroke, lineColor);
};
/***/ }),
/***/ 148:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Lib = __webpack_require__(3400);
// arrayOk attributes, merge them into calcdata array
module.exports = function arraysToCalcdata(cd, trace) {
// so each point knows which index it originally came from
for (var i = 0; i < cd.length; i++) cd[i].i = i;
Lib.mergeArray(trace.text, cd, 'tx');
Lib.mergeArray(trace.texttemplate, cd, 'txt');
Lib.mergeArray(trace.hovertext, cd, 'htx');
Lib.mergeArray(trace.customdata, cd, 'data');
Lib.mergeArray(trace.textposition, cd, 'tp');
if (trace.textfont) {
Lib.mergeArrayCastPositive(trace.textfont.size, cd, 'ts');
Lib.mergeArray(trace.textfont.color, cd, 'tc');
Lib.mergeArray(trace.textfont.family, cd, 'tf');
}
var marker = trace.marker;
if (marker) {
Lib.mergeArrayCastPositive(marker.size, cd, 'ms');
Lib.mergeArrayCastPositive(marker.opacity, cd, 'mo');
Lib.mergeArray(marker.symbol, cd, 'mx');
Lib.mergeArray(marker.angle, cd, 'ma');
Lib.mergeArray(marker.standoff, cd, 'mf');
Lib.mergeArray(marker.color, cd, 'mc');
var markerLine = marker.line;
if (marker.line) {
Lib.mergeArray(markerLine.color, cd, 'mlc');
Lib.mergeArrayCastPositive(markerLine.width, cd, 'mlw');
}
var markerGradient = marker.gradient;
if (markerGradient && markerGradient.type !== 'none') {
Lib.mergeArray(markerGradient.type, cd, 'mgt');
Lib.mergeArray(markerGradient.color, cd, 'mgc');
}
}
};
/***/ }),
/***/ 2904:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var axisHoverFormat = (__webpack_require__(9736).axisHoverFormat);
var texttemplateAttrs = (__webpack_require__(1776)/* .texttemplateAttrs */ .Gw);
var hovertemplateAttrs = (__webpack_require__(1776)/* .hovertemplateAttrs */ .Ks);
var colorScaleAttrs = __webpack_require__(9084);
var fontAttrs = __webpack_require__(5376);
var dash = (__webpack_require__(8192)/* .dash */ .u);
var pattern = (__webpack_require__(8192)/* .pattern */ .c);
var Drawing = __webpack_require__(3616);
var constants = __webpack_require__(8200);
var extendFlat = (__webpack_require__(2880).extendFlat);
var makeFillcolorAttr = __webpack_require__(3544);
function axisPeriod(axis) {
return {
valType: 'any',
dflt: 0,
editType: 'calc'
};
}
function axisPeriod0(axis) {
return {
valType: 'any',
editType: 'calc'
};
}
function axisPeriodAlignment(axis) {
return {
valType: 'enumerated',
values: ['start', 'middle', 'end'],
dflt: 'middle',
editType: 'calc'
};
}
module.exports = {
x: {
valType: 'data_array',
editType: 'calc+clearAxisTypes',
anim: true
},
x0: {
valType: 'any',
dflt: 0,
editType: 'calc+clearAxisTypes',
anim: true
},
dx: {
valType: 'number',
dflt: 1,
editType: 'calc',
anim: true
},
y: {
valType: 'data_array',
editType: 'calc+clearAxisTypes',
anim: true
},
y0: {
valType: 'any',
dflt: 0,
editType: 'calc+clearAxisTypes',
anim: true
},
dy: {
valType: 'number',
dflt: 1,
editType: 'calc',
anim: true
},
xperiod: axisPeriod('x'),
yperiod: axisPeriod('y'),
xperiod0: axisPeriod0('x0'),
yperiod0: axisPeriod0('y0'),
xperiodalignment: axisPeriodAlignment('x'),
yperiodalignment: axisPeriodAlignment('y'),
xhoverformat: axisHoverFormat('x'),
yhoverformat: axisHoverFormat('y'),
offsetgroup: {
valType: 'string',
dflt: '',
editType: 'calc'
},
alignmentgroup: {
valType: 'string',
dflt: '',
editType: 'calc'
},
stackgroup: {
valType: 'string',
dflt: '',
editType: 'calc'
},
orientation: {
valType: 'enumerated',
values: ['v', 'h'],
editType: 'calc'
},
groupnorm: {
valType: 'enumerated',
values: ['', 'fraction', 'percent'],
dflt: '',
editType: 'calc'
},
stackgaps: {
valType: 'enumerated',
values: ['infer zero', 'interpolate'],
dflt: 'infer zero',
editType: 'calc'
},
text: {
valType: 'string',
dflt: '',
arrayOk: true,
editType: 'calc'
},
texttemplate: texttemplateAttrs({}, {}),
hovertext: {
valType: 'string',
dflt: '',
arrayOk: true,
editType: 'style'
},
mode: {
valType: 'flaglist',
flags: ['lines', 'markers', 'text'],
extras: ['none'],
editType: 'calc'
},
hoveron: {
valType: 'flaglist',
flags: ['points', 'fills'],
editType: 'style'
},
hovertemplate: hovertemplateAttrs({}, {
keys: constants.eventDataKeys
}),
line: {
color: {
valType: 'color',
editType: 'style',
anim: true
},
width: {
valType: 'number',
min: 0,
dflt: 2,
editType: 'style',
anim: true
},
shape: {
valType: 'enumerated',
values: ['linear', 'spline', 'hv', 'vh', 'hvh', 'vhv'],
dflt: 'linear',
editType: 'plot'
},
smoothing: {
valType: 'number',
min: 0,
max: 1.3,
dflt: 1,
editType: 'plot'
},
dash: extendFlat({}, dash, {
editType: 'style'
}),
backoff: {
// we want to have a similar option for the start of the line
valType: 'number',
min: 0,
dflt: 'auto',
arrayOk: true,
editType: 'plot'
},
simplify: {
valType: 'boolean',
dflt: true,
editType: 'plot'
},
editType: 'plot'
},
connectgaps: {
valType: 'boolean',
dflt: false,
editType: 'calc'
},
cliponaxis: {
valType: 'boolean',
dflt: true,
editType: 'plot'
},
fill: {
valType: 'enumerated',
values: ['none', 'tozeroy', 'tozerox', 'tonexty', 'tonextx', 'toself', 'tonext'],
editType: 'calc'
},
fillcolor: makeFillcolorAttr(true),
fillgradient: extendFlat({
type: {
valType: 'enumerated',
values: ['radial', 'horizontal', 'vertical', 'none'],
dflt: 'none',
editType: 'calc'
},
start: {
valType: 'number',
editType: 'calc'
},
stop: {
valType: 'number',
editType: 'calc'
},
colorscale: {
valType: 'colorscale',
editType: 'style'
},
editType: 'calc'
}),
fillpattern: pattern,
marker: extendFlat({
symbol: {
valType: 'enumerated',
values: Drawing.symbolList,
dflt: 'circle',
arrayOk: true,
editType: 'style'
},
opacity: {
valType: 'number',
min: 0,
max: 1,
arrayOk: true,
editType: 'style',
anim: true
},
angle: {
valType: 'angle',
dflt: 0,
arrayOk: true,
editType: 'plot',
anim: false // TODO: possibly set to true in future
},
angleref: {
valType: 'enumerated',
values: ['previous', 'up'],
dflt: 'up',
editType: 'plot',
anim: false
},
standoff: {
valType: 'number',
min: 0,
dflt: 0,
arrayOk: true,
editType: 'plot',
anim: true
},
size: {
valType: 'number',
min: 0,
dflt: 6,
arrayOk: true,
editType: 'calc',
anim: true
},
maxdisplayed: {
valType: 'number',
min: 0,
dflt: 0,
editType: 'plot'
},
sizeref: {
valType: 'number',
dflt: 1,
editType: 'calc'
},
sizemin: {
valType: 'number',
min: 0,
dflt: 0,
editType: 'calc'
},
sizemode: {
valType: 'enumerated',
values: ['diameter', 'area'],
dflt: 'diameter',
editType: 'calc'
},
line: extendFlat({
width: {
valType: 'number',
min: 0,
arrayOk: true,
editType: 'style',
anim: true
},
editType: 'calc'
}, colorScaleAttrs('marker.line', {
anim: true
})),
gradient: {
type: {
valType: 'enumerated',
values: ['radial', 'horizontal', 'vertical', 'none'],
arrayOk: true,
dflt: 'none',
editType: 'calc'
},
color: {
valType: 'color',
arrayOk: true,
editType: 'calc'
},
editType: 'calc'
},
editType: 'calc'
}, colorScaleAttrs('marker', {
anim: true
})),
selected: {
marker: {
opacity: {
valType: 'number',
min: 0,
max: 1,
editType: 'style'
},
color: {
valType: 'color',
editType: 'style'
},
size: {
valType: 'number',
min: 0,
editType: 'style'
},
editType: 'style'
},
textfont: {
color: {
valType: 'color',
editType: 'style'
},
editType: 'style'
},
editType: 'style'
},
unselected: {
marker: {
opacity: {
valType: 'number',
min: 0,
max: 1,
editType: 'style'
},
color: {
valType: 'color',
editType: 'style'
},
size: {
valType: 'number',
min: 0,
editType: 'style'
},
editType: 'style'
},
textfont: {
color: {
valType: 'color',
editType: 'style'
},
editType: 'style'
},
editType: 'style'
},
textposition: {
valType: 'enumerated',
values: ['top left', 'top center', 'top right', 'middle left', 'middle center', 'middle right', 'bottom left', 'bottom center', 'bottom right'],
dflt: 'middle center',
arrayOk: true,
editType: 'calc'
},
textfont: fontAttrs({
editType: 'calc',
colorEditType: 'style',
arrayOk: true
}),
zorder: {
valType: 'integer',
dflt: 0,
editType: 'plot'
}
};
/***/ }),
/***/ 6356:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var isNumeric = __webpack_require__(8248);
var Lib = __webpack_require__(3400);
var Axes = __webpack_require__(4460);
var alignPeriod = __webpack_require__(1220);
var BADNUM = (__webpack_require__(9032).BADNUM);
var subTypes = __webpack_require__(3028);
var calcColorscale = __webpack_require__(136);
var arraysToCalcdata = __webpack_require__(148);
var calcSelection = __webpack_require__(4500);
function calc(gd, trace) {
var fullLayout = gd._fullLayout;
var xa = trace._xA = Axes.getFromId(gd, trace.xaxis || 'x', 'x');
var ya = trace._yA = Axes.getFromId(gd, trace.yaxis || 'y', 'y');
var origX = xa.makeCalcdata(trace, 'x');
var origY = ya.makeCalcdata(trace, 'y');
var xObj = alignPeriod(trace, xa, 'x', origX);
var yObj = alignPeriod(trace, ya, 'y', origY);
var x = xObj.vals;
var y = yObj.vals;
var serieslen = trace._length;
var cd = new Array(serieslen);
var ids = trace.ids;
var stackGroupOpts = getStackOpts(trace, fullLayout, xa, ya);
var interpolateGaps = false;
var isV, i, j, k, interpolate, vali;
setFirstScatter(fullLayout, trace);
var xAttr = 'x';
var yAttr = 'y';
var posAttr;
if (stackGroupOpts) {
Lib.pushUnique(stackGroupOpts.traceIndices, trace._expandedIndex);
isV = stackGroupOpts.orientation === 'v';
// size, like we use for bar
if (isV) {
yAttr = 's';
posAttr = 'x';
} else {
xAttr = 's';
posAttr = 'y';
}
interpolate = stackGroupOpts.stackgaps === 'interpolate';
} else {
var ppad = calcMarkerSize(trace, serieslen);
calcAxisExpansion(gd, trace, xa, ya, x, y, ppad);
}
var hasPeriodX = !!trace.xperiodalignment;
var hasPeriodY = !!trace.yperiodalignment;
for (i = 0; i < serieslen; i++) {
var cdi = cd[i] = {};
var xValid = isNumeric(x[i]);
var yValid = isNumeric(y[i]);
if (xValid && yValid) {
cdi[xAttr] = x[i];
cdi[yAttr] = y[i];
if (hasPeriodX) {
cdi.orig_x = origX[i]; // used by hover
cdi.xEnd = xObj.ends[i];
cdi.xStart = xObj.starts[i];
}
if (hasPeriodY) {
cdi.orig_y = origY[i]; // used by hover
cdi.yEnd = yObj.ends[i];
cdi.yStart = yObj.starts[i];
}
} else if (stackGroupOpts && (isV ? xValid : yValid)) {
// if we're stacking we need to hold on to all valid positions
// even with invalid sizes
cdi[posAttr] = isV ? x[i] : y[i];
cdi.gap = true;
if (interpolate) {
cdi.s = BADNUM;
interpolateGaps = true;
} else {
cdi.s = 0;
}
} else {
cdi[xAttr] = cdi[yAttr] = BADNUM;
}
if (ids) {
cdi.id = String(ids[i]);
}
}
arraysToCalcdata(cd, trace);
calcColorscale(gd, trace);
calcSelection(cd, trace);
if (stackGroupOpts) {
// remove bad positions and sort
// note that original indices get added to cd in arraysToCalcdata
i = 0;
while (i < cd.length) {
if (cd[i][posAttr] === BADNUM) {
cd.splice(i, 1);
} else i++;
}
Lib.sort(cd, function (a, b) {
return a[posAttr] - b[posAttr] || a.i - b.i;
});
if (interpolateGaps) {
// first fill the beginning with constant from the first point
i = 0;
while (i < cd.length - 1 && cd[i].gap) {
i++;
}
vali = cd[i].s;
if (!vali) vali = cd[i].s = 0; // in case of no data AT ALL in this trace - use 0
for (j = 0; j < i; j++) {
cd[j].s = vali;
}
// then fill the end with constant from the last point
k = cd.length - 1;
while (k > i && cd[k].gap) {
k--;
}
vali = cd[k].s;
for (j = cd.length - 1; j > k; j--) {
cd[j].s = vali;
}
// now interpolate internal gaps linearly
while (i < k) {
i++;
if (cd[i].gap) {
j = i + 1;
while (cd[j].gap) {
j++;
}
var pos0 = cd[i - 1][posAttr];
var size0 = cd[i - 1].s;
var m = (cd[j].s - size0) / (cd[j][posAttr] - pos0);
while (i < j) {
cd[i].s = size0 + (cd[i][posAttr] - pos0) * m;
i++;
}
}
}
}
}
return cd;
}
function calcAxisExpansion(gd, trace, xa, ya, x, y, ppad) {
var serieslen = trace._length;
var fullLayout = gd._fullLayout;
var xId = xa._id;
var yId = ya._id;
var firstScatter = fullLayout._firstScatter[firstScatterGroup(trace)] === trace.uid;
var stackOrientation = (getStackOpts(trace, fullLayout, xa, ya) || {}).orientation;
var fill = trace.fill;
// cancel minimum tick spacings (only applies to bars and boxes)
xa._minDtick = 0;
ya._minDtick = 0;
// check whether bounds should be tight, padded, extended to zero...
// most cases both should be padded on both ends, so start with that.
var xOptions = {
padded: true
};
var yOptions = {
padded: true
};
if (ppad) {
xOptions.ppad = yOptions.ppad = ppad;
}
// TODO: text size
var openEnded = serieslen < 2 || x[0] !== x[serieslen - 1] || y[0] !== y[serieslen - 1];
if (openEnded && (fill === 'tozerox' || fill === 'tonextx' && (firstScatter || stackOrientation === 'h'))) {
// include zero (tight) and extremes (padded) if fill to zero
// (unless the shape is closed, then it's just filling the shape regardless)
xOptions.tozero = true;
} else if (!(trace.error_y || {}).visible && (
// if no error bars, markers or text, or fill to y=0 remove x padding
fill === 'tonexty' || fill === 'tozeroy' || !subTypes.hasMarkers(trace) && !subTypes.hasText(trace))) {
xOptions.padded = false;
xOptions.ppad = 0;
}
if (openEnded && (fill === 'tozeroy' || fill === 'tonexty' && (firstScatter || stackOrientation === 'v'))) {
// now check for y - rather different logic, though still mostly padded both ends
// include zero (tight) and extremes (padded) if fill to zero
// (unless the shape is closed, then it's just filling the shape regardless)
yOptions.tozero = true;
} else if (fill === 'tonextx' || fill === 'tozerox') {
// tight y: any x fill
yOptions.padded = false;
}
// N.B. asymmetric splom traces call this with blank {} xa or ya
if (xId) trace._extremes[xId] = Axes.findExtremes(xa, x, xOptions);
if (yId) trace._extremes[yId] = Axes.findExtremes(ya, y, yOptions);
}
function calcMarkerSize(trace, serieslen) {
if (!subTypes.hasMarkers(trace)) return;
// Treat size like x or y arrays --- Run d2c
// this needs to go before ppad computation
var marker = trace.marker;
var sizeref = 1.6 * (trace.marker.sizeref || 1);
var markerTrans;
if (trace.marker.sizemode === 'area') {
markerTrans = function (v) {
return Math.max(Math.sqrt((v || 0) / sizeref), 3);
};
} else {
markerTrans = function (v) {
return Math.max((v || 0) / sizeref, 3);
};
}
if (Lib.isArrayOrTypedArray(marker.size)) {
// I tried auto-type but category and dates dont make much sense.
var ax = {
type: 'linear'
};
Axes.setConvert(ax);
var s = ax.makeCalcdata(trace.marker, 'size');
var sizeOut = new Array(serieslen);
for (var i = 0; i < serieslen; i++) {
sizeOut[i] = markerTrans(s[i]);
}
return sizeOut;
} else {
return markerTrans(marker.size);
}
}
/**
* mark the first scatter trace for each subplot
* note that scatter and scattergl each get their own first trace
* note also that I'm doing this during calc rather than supplyDefaults
* so I don't need to worry about transforms, but if we ever do
* per-trace calc this will get confused.
*/
function setFirstScatter(fullLayout, trace) {
var group = firstScatterGroup(trace);
var firstScatter = fullLayout._firstScatter;
if (!firstScatter[group]) firstScatter[group] = trace.uid;
}
function firstScatterGroup(trace) {
var stackGroup = trace.stackgroup;
return trace.xaxis + trace.yaxis + trace.type + (stackGroup ? '-' + stackGroup : '');
}
function getStackOpts(trace, fullLayout, xa, ya) {
var stackGroup = trace.stackgroup;
if (!stackGroup) return;
var stackOpts = fullLayout._scatterStackOpts[xa._id + ya._id][stackGroup];
var stackAx = stackOpts.orientation === 'v' ? ya : xa;
// Allow stacking only on numeric axes
// calc is a little late to be figuring this out, but during supplyDefaults
// we don't know the axis type yet
if (stackAx.type === 'linear' || stackAx.type === 'log') return stackOpts;
}
module.exports = {
calc: calc,
calcMarkerSize: calcMarkerSize,
calcAxisExpansion: calcAxisExpansion,
setFirstScatter: setFirstScatter,
getStackOpts: getStackOpts
};
/***/ }),
/***/ 4500:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Lib = __webpack_require__(3400);
module.exports = function calcSelection(cd, trace) {
if (Lib.isArrayOrTypedArray(trace.selectedpoints)) {
Lib.tagSelected(cd, trace);
}
};
/***/ }),
/***/ 136:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var hasColorscale = (__webpack_require__(4288).hasColorscale);
var calcColorscale = __webpack_require__(7128);
var subTypes = __webpack_require__(3028);
module.exports = function calcMarkerColorscale(gd, trace) {
if (subTypes.hasLines(trace) && hasColorscale(trace, 'line')) {
calcColorscale(gd, trace, {
vals: trace.line.color,
containerStr: 'line',
cLetter: 'c'
});
}
if (subTypes.hasMarkers(trace)) {
if (hasColorscale(trace, 'marker')) {
calcColorscale(gd, trace, {
vals: trace.marker.color,
containerStr: 'marker',
cLetter: 'c'
});
}
if (hasColorscale(trace, 'marker.line')) {
calcColorscale(gd, trace, {
vals: trace.marker.line.color,
containerStr: 'marker.line',
cLetter: 'c'
});
}
}
};
/***/ }),
/***/ 8200:
/***/ (function(module) {
"use strict";
module.exports = {
PTS_LINESONLY: 20,
// fixed parameters of clustering and clipping algorithms
// fraction of clustering tolerance "so close we don't even consider it a new point"
minTolerance: 0.2,
// how fast does clustering tolerance increase as you get away from the visible region
toleranceGrowth: 10,
// number of viewport sizes away from the visible region
// at which we clip all lines to the perimeter
maxScreensAway: 20,
eventDataKeys: []
};
/***/ }),
/***/ 6664:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var calc = __webpack_require__(6356);
var setGroupPositions = (__webpack_require__(6376).setGroupPositions);
function groupCrossTraceCalc(gd, plotinfo) {
var xa = plotinfo.xaxis;
var ya = plotinfo.yaxis;
var fullLayout = gd._fullLayout;
var fullTraces = gd._fullData;
var calcTraces = gd.calcdata;
var calcTracesHorz = [];
var calcTracesVert = [];
for (var i = 0; i < fullTraces.length; i++) {
var fullTrace = fullTraces[i];
if (fullTrace.visible === true && fullTrace.type === 'scatter' && fullTrace.xaxis === xa._id && fullTrace.yaxis === ya._id) {
if (fullTrace.orientation === 'h') {
calcTracesHorz.push(calcTraces[i]);
} else if (fullTrace.orientation === 'v') {
// check for v since certain scatter traces may not have an orientation
calcTracesVert.push(calcTraces[i]);
}
}
}
var opts = {
mode: fullLayout.scattermode,
gap: fullLayout.scattergap
};
setGroupPositions(gd, xa, ya, calcTracesVert, opts);
setGroupPositions(gd, ya, xa, calcTracesHorz, opts);
}
/*
* Scatter stacking & normalization calculations
* runs per subplot, and can handle multiple stacking groups
*/
module.exports = function crossTraceCalc(gd, plotinfo) {
if (gd._fullLayout.scattermode === 'group') {
groupCrossTraceCalc(gd, plotinfo);
}
var xa = plotinfo.xaxis;
var ya = plotinfo.yaxis;
var subplot = xa._id + ya._id;
var subplotStackOpts = gd._fullLayout._scatterStackOpts[subplot];
if (!subplotStackOpts) return;
var calcTraces = gd.calcdata;
var i, j, k, i2, cd, cd0, posj, sumj, norm;
var groupOpts, interpolate, groupnorm, posAttr, valAttr;
var hasAnyBlanks;
for (var stackGroup in subplotStackOpts) {
groupOpts = subplotStackOpts[stackGroup];
var indices = groupOpts.traceIndices;
// can get here with no indices if the stack axis is non-numeric
if (!indices.length) continue;
interpolate = groupOpts.stackgaps === 'interpolate';
groupnorm = groupOpts.groupnorm;
if (groupOpts.orientation === 'v') {
posAttr = 'x';
valAttr = 'y';
} else {
posAttr = 'y';
valAttr = 'x';
}
hasAnyBlanks = new Array(indices.length);
for (i = 0; i < hasAnyBlanks.length; i++) {
hasAnyBlanks[i] = false;
}
// Collect the complete set of all positions across ALL traces.
// Start with the first trace, then interleave items from later traces
// as needed.
// Fill in mising items as we go.
cd0 = calcTraces[indices[0]];
var allPositions = new Array(cd0.length);
for (i = 0; i < cd0.length; i++) {
allPositions[i] = cd0[i][posAttr];
}
for (i = 1; i < indices.length; i++) {
cd = calcTraces[indices[i]];
for (j = k = 0; j < cd.length; j++) {
posj = cd[j][posAttr];
for (; posj > allPositions[k] && k < allPositions.length; k++) {
// the current trace is missing a position from some previous trace(s)
insertBlank(cd, j, allPositions[k], i, hasAnyBlanks, interpolate, posAttr);
j++;
}
if (posj !== allPositions[k]) {
// previous trace(s) are missing a position from the current trace
for (i2 = 0; i2 < i; i2++) {
insertBlank(calcTraces[indices[i2]], k, posj, i2, hasAnyBlanks, interpolate, posAttr);
}
allPositions.splice(k, 0, posj);
}
k++;
}
for (; k < allPositions.length; k++) {
insertBlank(cd, j, allPositions[k], i, hasAnyBlanks, interpolate, posAttr);
j++;
}
}
var serieslen = allPositions.length;
// stack (and normalize)!
for (j = 0; j < cd0.length; j++) {
sumj = cd0[j][valAttr] = cd0[j].s;
for (i = 1; i < indices.length; i++) {
cd = calcTraces[indices[i]];
cd[0].trace._rawLength = cd[0].trace._length;
cd[0].trace._length = serieslen;
sumj += cd[j].s;
cd[j][valAttr] = sumj;
}
if (groupnorm) {
norm = (groupnorm === 'fraction' ? sumj : sumj / 100) || 1;
for (i = 0; i < indices.length; i++) {
var cdj = calcTraces[indices[i]][j];
cdj[valAttr] /= norm;
cdj.sNorm = cdj.s / norm;
}
}
}
// autorange
for (i = 0; i < indices.length; i++) {
cd = calcTraces[indices[i]];
var trace = cd[0].trace;
var ppad = calc.calcMarkerSize(trace, trace._rawLength);
var arrayPad = Array.isArray(ppad);
if (ppad && hasAnyBlanks[i] || arrayPad) {
var ppadRaw = ppad;
ppad = new Array(serieslen);
for (j = 0; j < serieslen; j++) {
ppad[j] = cd[j].gap ? 0 : arrayPad ? ppadRaw[cd[j].i] : ppadRaw;
}
}
var x = new Array(serieslen);
var y = new Array(serieslen);
for (j = 0; j < serieslen; j++) {
x[j] = cd[j].x;
y[j] = cd[j].y;
}
calc.calcAxisExpansion(gd, trace, xa, ya, x, y, ppad);
// while we're here (in a loop over all traces in the stack)
// record the orientation, so hover can find it easily
cd[0].t.orientation = groupOpts.orientation;
}
}
};
function insertBlank(calcTrace, index, position, traceIndex, hasAnyBlanks, interpolate, posAttr) {
hasAnyBlanks[traceIndex] = true;
var newEntry = {
i: null,
gap: true,
s: 0
};
newEntry[posAttr] = position;
calcTrace.splice(index, 0, newEntry);
// Even if we're not interpolating, if one trace has multiple
// values at the same position and this trace only has one value there,
// we just duplicate that one value rather than insert a zero.
// We also make it look like a real point - because it's ambiguous which
// one really is the real one!
if (index && position === calcTrace[index - 1][posAttr]) {
var prevEntry = calcTrace[index - 1];
newEntry.s = prevEntry.s;
// TODO is it going to cause any problems to have multiple
// calcdata points with the same index?
newEntry.i = prevEntry.i;
newEntry.gap = prevEntry.gap;
} else if (interpolate) {
newEntry.s = getInterp(calcTrace, index, position, posAttr);
}
if (!index) {
// t and trace need to stay on the first cd entry
calcTrace[0].t = calcTrace[1].t;
calcTrace[0].trace = calcTrace[1].trace;
delete calcTrace[1].t;
delete calcTrace[1].trace;
}
}
function getInterp(calcTrace, index, position, posAttr) {
var pt0 = calcTrace[index - 1];
var pt1 = calcTrace[index + 1];
if (!pt1) return pt0.s;
if (!pt0) return pt1.s;
return pt0.s + (pt1.s - pt0.s) * (position - pt0[posAttr]) / (pt1[posAttr] - pt0[posAttr]);
}
/***/ }),
/***/ 5036:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Lib = __webpack_require__(3400);
var handleGroupingDefaults = __webpack_require__(11);
var attributes = __webpack_require__(2904);
// remove opacity for any trace that has a fill or is filled to
module.exports = function crossTraceDefaults(fullData, fullLayout) {
var traceIn, traceOut, i;
function coerce(attr) {
return Lib.coerce(traceOut._input, traceOut, attributes, attr);
}
if (fullLayout.scattermode === 'group') {
for (i = 0; i < fullData.length; i++) {
traceOut = fullData[i];
if (traceOut.type === 'scatter') {
traceIn = traceOut._input;
handleGroupingDefaults(traceIn, traceOut, fullLayout, coerce);
}
}
}
for (i = 0; i < fullData.length; i++) {
var tracei = fullData[i];
if (tracei.type !== 'scatter') continue;
var filli = tracei.fill;
if (filli === 'none' || filli === 'toself') continue;
tracei.opacity = undefined;
if (filli === 'tonexty' || filli === 'tonextx') {
for (var j = i - 1; j >= 0; j--) {
var tracej = fullData[j];
if (tracej.type === 'scatter' && tracej.xaxis === tracei.xaxis && tracej.yaxis === tracei.yaxis) {
tracej.opacity = undefined;
break;
}
}
}
}
};
/***/ }),
/***/ 8800:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Lib = __webpack_require__(3400);
var Registry = __webpack_require__(4040);
var attributes = __webpack_require__(2904);
var constants = __webpack_require__(8200);
var subTypes = __webpack_require__(3028);
var handleXYDefaults = __webpack_require__(3980);
var handlePeriodDefaults = __webpack_require__(1147);
var handleStackDefaults = __webpack_require__(3912);
var handleMarkerDefaults = __webpack_require__(4428);
var handleLineDefaults = __webpack_require__(6828);
var handleLineShapeDefaults = __webpack_require__(1731);
var handleTextDefaults = __webpack_require__(124);
var handleFillColorDefaults = __webpack_require__(840);
var coercePattern = (__webpack_require__(3400).coercePattern);
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
function coerce(attr, dflt) {
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}
var len = handleXYDefaults(traceIn, traceOut, layout, coerce);
if (!len) traceOut.visible = false;
if (!traceOut.visible) return;
handlePeriodDefaults(traceIn, traceOut, layout, coerce);
coerce('xhoverformat');
coerce('yhoverformat');
coerce('zorder');
var stackGroupOpts = handleStackDefaults(traceIn, traceOut, layout, coerce);
if (layout.scattermode === 'group' && traceOut.orientation === undefined) {
coerce('orientation', 'v');
}
var defaultMode = !stackGroupOpts && len < constants.PTS_LINESONLY ? 'lines+markers' : 'lines';
coerce('text');
coerce('hovertext');
coerce('mode', defaultMode);
if (subTypes.hasMarkers(traceOut)) {
handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {
gradient: true
});
}
if (subTypes.hasLines(traceOut)) {
handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce, {
backoff: true
});
handleLineShapeDefaults(traceIn, traceOut, coerce);
coerce('connectgaps');
coerce('line.simplify');
}
if (subTypes.hasText(traceOut)) {
coerce('texttemplate');
handleTextDefaults(traceIn, traceOut, layout, coerce);
}
var dfltHoverOn = [];
if (subTypes.hasMarkers(traceOut) || subTypes.hasText(traceOut)) {
coerce('cliponaxis');
coerce('marker.maxdisplayed');
dfltHoverOn.push('points');
}
// It's possible for this default to be changed by a later trace.
// We handle that case in some hacky code inside handleStackDefaults.
coerce('fill', stackGroupOpts ? stackGroupOpts.fillDflt : 'none');
if (traceOut.fill !== 'none') {
handleFillColorDefaults(traceIn, traceOut, defaultColor, coerce, {
moduleHasFillgradient: true
});
if (!subTypes.hasLines(traceOut)) handleLineShapeDefaults(traceIn, traceOut, coerce);
coercePattern(coerce, 'fillpattern', traceOut.fillcolor, false);
}
var lineColor = (traceOut.line || {}).color;
var markerColor = (traceOut.marker || {}).color;
if (traceOut.fill === 'tonext' || traceOut.fill === 'toself') {
dfltHoverOn.push('fills');
}
coerce('hoveron', dfltHoverOn.join('+') || 'points');
if (traceOut.hoveron !== 'fills') coerce('hovertemplate');
var errorBarsSupplyDefaults = Registry.getComponentMethod('errorbars', 'supplyDefaults');
errorBarsSupplyDefaults(traceIn, traceOut, lineColor || markerColor || defaultColor, {
axis: 'y'
});
errorBarsSupplyDefaults(traceIn, traceOut, lineColor || markerColor || defaultColor, {
axis: 'x',
inherit: 'y'
});
Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
};
/***/ }),
/***/ 3544:
/***/ (function(module) {
"use strict";
module.exports = function makeFillcolorAttr(hasFillgradient) {
return {
valType: 'color',
editType: 'style',
anim: true
};
};
/***/ }),
/***/ 840:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Color = __webpack_require__(6308);
var isArrayOrTypedArray = (__webpack_require__(3400).isArrayOrTypedArray);
function averageColors(colorscale) {
var color = Color.interpolate(colorscale[0][1], colorscale[1][1], 0.5);
for (var i = 2; i < colorscale.length; i++) {
var averageColorI = Color.interpolate(colorscale[i - 1][1], colorscale[i][1], 0.5);
color = Color.interpolate(color, averageColorI, colorscale[i - 1][0] / colorscale[i][0]);
}
return color;
}
module.exports = function fillColorDefaults(traceIn, traceOut, defaultColor, coerce, opts) {
if (!opts) opts = {};
var inheritColorFromMarker = false;
if (traceOut.marker) {
// don't try to inherit a color array
var markerColor = traceOut.marker.color;
var markerLineColor = (traceOut.marker.line || {}).color;
if (markerColor && !isArrayOrTypedArray(markerColor)) {
inheritColorFromMarker = markerColor;
} else if (markerLineColor && !isArrayOrTypedArray(markerLineColor)) {
inheritColorFromMarker = markerLineColor;
}
}
var averageGradientColor;
if (opts.moduleHasFillgradient) {
var gradientOrientation = coerce('fillgradient.type');
if (gradientOrientation !== 'none') {
coerce('fillgradient.start');
coerce('fillgradient.stop');
var gradientColorscale = coerce('fillgradient.colorscale');
// if a fillgradient is specified, we use the average gradient color
// to specify fillcolor after all other more specific candidates
// are considered, but before the global default color.
// fillcolor affects the background color of the hoverlabel in this case.
if (gradientColorscale) {
averageGradientColor = averageColors(gradientColorscale);
}
}
}
coerce('fillcolor', Color.addOpacity((traceOut.line || {}).color || inheritColorFromMarker || averageGradientColor || defaultColor, 0.5));
};
/***/ }),
/***/ 6688:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Axes = __webpack_require__(4460);
module.exports = function formatLabels(cdi, trace, fullLayout) {
var labels = {};
var mockGd = {
_fullLayout: fullLayout
};
var xa = Axes.getFromTrace(mockGd, trace, 'x');
var ya = Axes.getFromTrace(mockGd, trace, 'y');
var x = cdi.orig_x;
if (x === undefined) x = cdi.x;
var y = cdi.orig_y;
if (y === undefined) y = cdi.y;
labels.xLabel = Axes.tickText(xa, xa.c2l(x), true).text;
labels.yLabel = Axes.tickText(ya, ya.c2l(y), true).text;
return labels;
};
/***/ }),
/***/ 4928:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Color = __webpack_require__(6308);
var subtypes = __webpack_require__(3028);
module.exports = function getTraceColor(trace, di) {
var lc, tc;
// TODO: text modes
if (trace.mode === 'lines') {
lc = trace.line.color;
return lc && Color.opacity(lc) ? lc : trace.fillcolor;
} else if (trace.mode === 'none') {
return trace.fill ? trace.fillcolor : '';
} else {
var mc = di.mcc || (trace.marker || {}).color;
var mlc = di.mlcc || ((trace.marker || {}).line || {}).color;
tc = mc && Color.opacity(mc) ? mc : mlc && Color.opacity(mlc) && (di.mlw || ((trace.marker || {}).line || {}).width) ? mlc : '';
if (tc) {
// make sure the points aren't TOO transparent
if (Color.opacity(tc) < 0.3) {
return Color.addOpacity(tc, 0.3);
} else return tc;
} else {
lc = (trace.line || {}).color;
return lc && Color.opacity(lc) && subtypes.hasLines(trace) && trace.line.width ? lc : trace.fillcolor;
}
}
};
/***/ }),
/***/ 11:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var getAxisGroup = (__webpack_require__(1888).getAxisGroup);
module.exports = function handleGroupingDefaults(traceIn, traceOut, fullLayout, coerce) {
var orientation = traceOut.orientation;
// N.B. grouping is done across all trace types that support it
var posAxId = traceOut[{
v: 'x',
h: 'y'
}[orientation] + 'axis'];
var groupId = getAxisGroup(fullLayout, posAxId) + orientation;
var alignmentOpts = fullLayout._alignmentOpts || {};
var alignmentgroup = coerce('alignmentgroup');
var alignmentGroups = alignmentOpts[groupId];
if (!alignmentGroups) alignmentGroups = alignmentOpts[groupId] = {};
var alignmentGroupOpts = alignmentGroups[alignmentgroup];
if (alignmentGroupOpts) {
alignmentGroupOpts.traces.push(traceOut);
} else {
alignmentGroupOpts = alignmentGroups[alignmentgroup] = {
traces: [traceOut],
alignmentIndex: Object.keys(alignmentGroups).length,
offsetGroups: {}
};
}
var offsetgroup = coerce('offsetgroup');
var offsetGroups = alignmentGroupOpts.offsetGroups;
var offsetGroupOpts = offsetGroups[offsetgroup];
if (offsetgroup) {
if (!offsetGroupOpts) {
offsetGroupOpts = offsetGroups[offsetgroup] = {
offsetIndex: Object.keys(offsetGroups).length
};
}
traceOut._offsetIndex = offsetGroupOpts.offsetIndex;
}
};
/***/ }),
/***/ 8723:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Lib = __webpack_require__(3400);
var Fx = __webpack_require__(3024);
var Registry = __webpack_require__(4040);
var getTraceColor = __webpack_require__(4928);
var Color = __webpack_require__(6308);
var fillText = Lib.fillText;
module.exports = function hoverPoints(pointData, xval, yval, hovermode) {
var cd = pointData.cd;
var trace = cd[0].trace;
var xa = pointData.xa;
var ya = pointData.ya;
var xpx = xa.c2p(xval);
var ypx = ya.c2p(yval);
var pt = [xpx, ypx];
var hoveron = trace.hoveron || '';
var minRad = trace.mode.indexOf('markers') !== -1 ? 3 : 0.5;
var xPeriod = !!trace.xperiodalignment;
var yPeriod = !!trace.yperiodalignment;
// look for points to hover on first, then take fills only if we
// didn't find a point
if (hoveron.indexOf('points') !== -1) {
// dx and dy are used in compare modes - here we want to always
// prioritize the closest data point, at least as long as markers are
// the same size or nonexistent, but still try to prioritize small markers too.
var dx = function (di) {
if (xPeriod) {
var x0 = xa.c2p(di.xStart);
var x1 = xa.c2p(di.xEnd);
return xpx >= Math.min(x0, x1) && xpx <= Math.max(x0, x1) ? 0 : Infinity;
}
var rad = Math.max(3, di.mrc || 0);
var kink = 1 - 1 / rad;
var dxRaw = Math.abs(xa.c2p(di.x) - xpx);
return dxRaw < rad ? kink * dxRaw / rad : dxRaw - rad + kink;
};
var dy = function (di) {
if (yPeriod) {
var y0 = ya.c2p(di.yStart);
var y1 = ya.c2p(di.yEnd);
return ypx >= Math.min(y0, y1) && ypx <= Math.max(y0, y1) ? 0 : Infinity;
}
var rad = Math.max(3, di.mrc || 0);
var kink = 1 - 1 / rad;
var dyRaw = Math.abs(ya.c2p(di.y) - ypx);
return dyRaw < rad ? kink * dyRaw / rad : dyRaw - rad + kink;
};
// scatter points: d.mrc is the calculated marker radius
// adjust the distance so if you're inside the marker it
// always will show up regardless of point size, but
// prioritize smaller points
var dxy = function (di) {
var rad = Math.max(minRad, di.mrc || 0);
var dx = xa.c2p(di.x) - xpx;
var dy = ya.c2p(di.y) - ypx;
return Math.max(Math.sqrt(dx * dx + dy * dy) - rad, 1 - minRad / rad);
};
var distfn = Fx.getDistanceFunction(hovermode, dx, dy, dxy);
Fx.getClosest(cd, distfn, pointData);
// skip the rest (for this trace) if we didn't find a close point
if (pointData.index !== false) {
// the closest data point
var di = cd[pointData.index];
var xc = xa.c2p(di.x, true);
var yc = ya.c2p(di.y, true);
var rad = di.mrc || 1;
// now we're done using the whole `calcdata` array, replace the
// index with the original index (in case of inserted point from
// stacked area)
pointData.index = di.i;
var orientation = cd[0].t.orientation;
// TODO: for scatter and bar, option to show (sub)totals and
// raw data? Currently stacked and/or normalized bars just show
// the normalized individual sizes, so that's what I'm doing here
// for now.
var sizeVal = orientation && (di.sNorm || di.s);
var xLabelVal = orientation === 'h' ? sizeVal : di.orig_x !== undefined ? di.orig_x : di.x;
var yLabelVal = orientation === 'v' ? sizeVal : di.orig_y !== undefined ? di.orig_y : di.y;
Lib.extendFlat(pointData, {
color: getTraceColor(trace, di),
x0: xc - rad,
x1: xc + rad,
xLabelVal: xLabelVal,
y0: yc - rad,
y1: yc + rad,
yLabelVal: yLabelVal,
spikeDistance: dxy(di),
hovertemplate: trace.hovertemplate
});
fillText(di, trace, pointData);
Registry.getComponentMethod('errorbars', 'hoverInfo')(di, trace, pointData);
return [pointData];
}
}
function isHoverPointInFillElement(el) {
// Uses SVGElement.isPointInFill to accurately determine wether
// the hover point / cursor is contained in the fill, taking
// curved or jagged edges into account, which the Polygon-based
// approach does not.
if (!el) {
return false;
}
var svgElement = el.node();
try {
var domPoint = new DOMPoint(pt[0], pt[1]);
return svgElement.isPointInFill(domPoint);
} catch (TypeError) {
var svgPoint = svgElement.ownerSVGElement.createSVGPoint();
svgPoint.x = pt[0];
svgPoint.y = pt[1];
return svgElement.isPointInFill(svgPoint);
}
}
function getHoverLabelPosition(polygons) {
// Uses Polygon s to determine the left- and right-most x-coordinates
// of the subshape of the fill that contains the hover point / cursor.
// Doing this with the SVGElement directly is quite tricky, so this falls
// back to the existing relatively simple code, accepting some small inaccuracies
// of label positioning for curved/jagged edges.
var i;
var polygonsIn = [];
var xmin = Infinity;
var xmax = -Infinity;
var ymin = Infinity;
var ymax = -Infinity;
var yPos;
for (i = 0; i < polygons.length; i++) {
var polygon = polygons[i];
// This is not going to work right for curved or jagged edges, it will
// act as though they're straight.
if (polygon.contains(pt)) {
polygonsIn.push(polygon);
ymin = Math.min(ymin, polygon.ymin);
ymax = Math.max(ymax, polygon.ymax);
}
}
// The above found no polygon that contains the cursor, but we know that
// the cursor must be inside the fill as determined by the SVGElement
// (so we are probably close to a curved/jagged edge...).
if (polygonsIn.length === 0) {
return null;
}
// constrain ymin/max to the visible plot, so the label goes
// at the middle of the piece you can see
ymin = Math.max(ymin, 0);
ymax = Math.min(ymax, ya._length);
yPos = (ymin + ymax) / 2;
// find the overall left-most and right-most points of the
// polygon(s) we're inside at their combined vertical midpoint.
// This is where we will draw the hover label.
// Note that this might not be the vertical midpoint of the
// whole trace, if it's disjoint.
var j, pts, xAtYPos, x0, x1, y0, y1;
for (i = 0; i < polygonsIn.length; i++) {
pts = polygonsIn[i].pts;
for (j = 1; j < pts.length; j++) {
y0 = pts[j - 1][1];
y1 = pts[j][1];
if (y0 > yPos !== y1 >= yPos) {
x0 = pts[j - 1][0];
x1 = pts[j][0];
if (y1 - y0) {
xAtYPos = x0 + (x1 - x0) * (yPos - y0) / (y1 - y0);
xmin = Math.min(xmin, xAtYPos);
xmax = Math.max(xmax, xAtYPos);
}
}
}
}
// constrain xmin/max to the visible plot now too
xmin = Math.max(xmin, 0);
xmax = Math.min(xmax, xa._length);
return {
x0: xmin,
x1: xmax,
y0: yPos,
y1: yPos
};
}
// even if hoveron is 'fills', only use it if we have a fill element too
if (hoveron.indexOf('fills') !== -1 && trace._fillElement) {
var inside = isHoverPointInFillElement(trace._fillElement) && !isHoverPointInFillElement(trace._fillExclusionElement);
if (inside) {
var hoverLabelCoords = getHoverLabelPosition(trace._polygons);
// getHoverLabelPosition may return null if the cursor / hover point is not contained
// in any of the trace's polygons, which can happen close to curved edges. in that
// case we fall back to displaying the hover label at the cursor position.
if (hoverLabelCoords === null) {
hoverLabelCoords = {
x0: pt[0],
x1: pt[0],
y0: pt[1],
y1: pt[1]
};
}
// get only fill or line color for the hover color
var color = Color.defaultLine;
if (Color.opacity(trace.fillcolor)) color = trace.fillcolor;else if (Color.opacity((trace.line || {}).color)) {
color = trace.line.color;
}
Lib.extendFlat(pointData, {
// never let a 2D override 1D type as closest point
// also: no spikeDistance, it's not allowed for fills
distance: pointData.maxHoverDistance,
x0: hoverLabelCoords.x0,
x1: hoverLabelCoords.x1,
y0: hoverLabelCoords.y0,
y1: hoverLabelCoords.y1,
color: color,
hovertemplate: false
});
delete pointData.index;
if (trace.text && !Lib.isArrayOrTypedArray(trace.text)) {
pointData.text = String(trace.text);
} else pointData.text = trace.name;
return [pointData];
}
}
};
/***/ }),
/***/ 5875:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var subtypes = __webpack_require__(3028);
module.exports = {
hasLines: subtypes.hasLines,
hasMarkers: subtypes.hasMarkers,
hasText: subtypes.hasText,
isBubble: subtypes.isBubble,
attributes: __webpack_require__(2904),
layoutAttributes: __webpack_require__(5308),
supplyDefaults: __webpack_require__(8800),
crossTraceDefaults: __webpack_require__(5036),
supplyLayoutDefaults: __webpack_require__(9748),
calc: (__webpack_require__(6356).calc),
crossTraceCalc: __webpack_require__(6664),
arraysToCalcdata: __webpack_require__(148),
plot: __webpack_require__(6504),
colorbar: __webpack_require__(5528),
formatLabels: __webpack_require__(6688),
style: (__webpack_require__(6844).style),
styleOnSelect: (__webpack_require__(6844).styleOnSelect),
hoverPoints: __webpack_require__(8723),
selectPoints: __webpack_require__(1560),
animatable: true,
moduleType: 'trace',
name: 'scatter',
basePlotModule: __webpack_require__(7952),
categories: ['cartesian', 'svg', 'symbols', 'errorBarsOK', 'showLegend', 'scatter-like', 'zoomScale'],
meta: {}
};
/***/ }),
/***/ 5308:
/***/ (function(module) {
"use strict";
module.exports = {
scattermode: {
valType: 'enumerated',
values: ['group', 'overlay'],
dflt: 'overlay',
editType: 'calc'
},
scattergap: {
valType: 'number',
min: 0,
max: 1,
editType: 'calc'
}
};
/***/ }),
/***/ 9748:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Lib = __webpack_require__(3400);
var layoutAttributes = __webpack_require__(5308);
module.exports = function (layoutIn, layoutOut) {
function coerce(attr, dflt) {
return Lib.coerce(layoutIn, layoutOut, layoutAttributes, attr, dflt);
}
var groupBarmode = layoutOut.barmode === 'group';
if (layoutOut.scattermode === 'group') {
coerce('scattergap', groupBarmode ? layoutOut.bargap : 0.2);
}
};
/***/ }),
/***/ 6828:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var isArrayOrTypedArray = (__webpack_require__(3400).isArrayOrTypedArray);
var hasColorscale = (__webpack_require__(4288).hasColorscale);
var colorscaleDefaults = __webpack_require__(7260);
module.exports = function lineDefaults(traceIn, traceOut, defaultColor, layout, coerce, opts) {
if (!opts) opts = {};
var markerColor = (traceIn.marker || {}).color;
if (markerColor && markerColor._inputArray) markerColor = markerColor._inputArray;
coerce('line.color', defaultColor);
if (hasColorscale(traceIn, 'line')) {
colorscaleDefaults(traceIn, traceOut, layout, coerce, {
prefix: 'line.',
cLetter: 'c'
});
} else {
var lineColorDflt = (isArrayOrTypedArray(markerColor) ? false : markerColor) || defaultColor;
coerce('line.color', lineColorDflt);
}
coerce('line.width');
if (!opts.noDash) coerce('line.dash');
if (opts.backoff) coerce('line.backoff');
};
/***/ }),
/***/ 2340:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Drawing = __webpack_require__(3616);
var numConstants = __webpack_require__(9032);
var BADNUM = numConstants.BADNUM;
var LOG_CLIP = numConstants.LOG_CLIP;
var LOG_CLIP_PLUS = LOG_CLIP + 0.5;
var LOG_CLIP_MINUS = LOG_CLIP - 0.5;
var Lib = __webpack_require__(3400);
var segmentsIntersect = Lib.segmentsIntersect;
var constrain = Lib.constrain;
var constants = __webpack_require__(8200);
module.exports = function linePoints(d, opts) {
var trace = opts.trace || {};
var xa = opts.xaxis;
var ya = opts.yaxis;
var xLog = xa.type === 'log';
var yLog = ya.type === 'log';
var xLen = xa._length;
var yLen = ya._length;
var backoff = opts.backoff;
var marker = trace.marker;
var connectGaps = opts.connectGaps;
var baseTolerance = opts.baseTolerance;
var shape = opts.shape;
var linear = shape === 'linear';
var fill = trace.fill && trace.fill !== 'none';
var segments = [];
var minTolerance = constants.minTolerance;
var len = d.length;
var pts = new Array(len);
var pti = 0;
var i;
// pt variables are pixel coordinates [x,y] of one point
// these four are the outputs of clustering on a line
var clusterStartPt, clusterEndPt, clusterHighPt, clusterLowPt;
// "this" is the next point we're considering adding to the cluster
var thisPt;
// did we encounter the high point first, then a low point, or vice versa?
var clusterHighFirst;
// the first two points in the cluster determine its unit vector
// so the second is always in the "High" direction
var clusterUnitVector;
// the pixel delta from clusterStartPt
var thisVector;
// val variables are (signed) pixel distances along the cluster vector
var clusterRefDist, clusterHighVal, clusterLowVal, thisVal;
// deviation variables are (signed) pixel distances normal to the cluster vector
var clusterMinDeviation, clusterMaxDeviation, thisDeviation;
// turn one calcdata point into pixel coordinates
function getPt(index) {
var di = d[index];
if (!di) return false;
var x = opts.linearized ? xa.l2p(di.x) : xa.c2p(di.x);
var y = opts.linearized ? ya.l2p(di.y) : ya.c2p(di.y);
// if non-positive log values, set them VERY far off-screen
// so the line looks essentially straight from the previous point.
if (x === BADNUM) {
if (xLog) x = xa.c2p(di.x, true);
if (x === BADNUM) return false;
// If BOTH were bad log values, make the line follow a constant
// exponent rather than a constant slope
if (yLog && y === BADNUM) {
x *= Math.abs(xa._m * yLen * (xa._m > 0 ? LOG_CLIP_PLUS : LOG_CLIP_MINUS) / (ya._m * xLen * (ya._m > 0 ? LOG_CLIP_PLUS : LOG_CLIP_MINUS)));
}
x *= 1000;
}
if (y === BADNUM) {
if (yLog) y = ya.c2p(di.y, true);
if (y === BADNUM) return false;
y *= 1000;
}
return [x, y];
}
function crossesViewport(xFrac0, yFrac0, xFrac1, yFrac1) {
var dx = xFrac1 - xFrac0;
var dy = yFrac1 - yFrac0;
var dx0 = 0.5 - xFrac0;
var dy0 = 0.5 - yFrac0;
var norm2 = dx * dx + dy * dy;
var dot = dx * dx0 + dy * dy0;
if (dot > 0 && dot < norm2) {
var cross = dx0 * dy - dy0 * dx;
if (cross * cross < norm2) return true;
}
}
var latestXFrac, latestYFrac;
// if we're off-screen, increase tolerance over baseTolerance
function getTolerance(pt, nextPt) {
var xFrac = pt[0] / xLen;
var yFrac = pt[1] / yLen;
var offScreenFraction = Math.max(0, -xFrac, xFrac - 1, -yFrac, yFrac - 1);
if (offScreenFraction && latestXFrac !== undefined && crossesViewport(xFrac, yFrac, latestXFrac, latestYFrac)) {
offScreenFraction = 0;
}
if (offScreenFraction && nextPt && crossesViewport(xFrac, yFrac, nextPt[0] / xLen, nextPt[1] / yLen)) {
offScreenFraction = 0;
}
return (1 + constants.toleranceGrowth * offScreenFraction) * baseTolerance;
}
function ptDist(pt1, pt2) {
var dx = pt1[0] - pt2[0];
var dy = pt1[1] - pt2[1];
return Math.sqrt(dx * dx + dy * dy);
}
// last bit of filtering: clip paths that are VERY far off-screen
// so we don't get near the browser's hard limit (+/- 2^29 px in Chrome and FF)
var maxScreensAway = constants.maxScreensAway;
// find the intersections between the segment from pt1 to pt2
// and the large rectangle maxScreensAway around the viewport
// if one of pt1 and pt2 is inside and the other outside, there
// will be only one intersection.
// if both are outside there will be 0 or 2 intersections
// (or 1 if it's right at a corner - we'll treat that like 0)
// returns an array of intersection pts
var xEdge0 = -xLen * maxScreensAway;
var xEdge1 = xLen * (1 + maxScreensAway);
var yEdge0 = -yLen * maxScreensAway;
var yEdge1 = yLen * (1 + maxScreensAway);
var edges = [[xEdge0, yEdge0, xEdge1, yEdge0], [xEdge1, yEdge0, xEdge1, yEdge1], [xEdge1, yEdge1, xEdge0, yEdge1], [xEdge0, yEdge1, xEdge0, yEdge0]];
var xEdge, yEdge, lastXEdge, lastYEdge, lastFarPt, edgePt;
// for linear line shape, edge intersections should be linearly interpolated
// spline uses this too, which isn't precisely correct but is actually pretty
// good, because Catmull-Rom weights far-away points less in creating the curvature
function getLinearEdgeIntersections(pt1, pt2) {
var out = [];
var ptCount = 0;
for (var i = 0; i < 4; i++) {
var edge = edges[i];
var ptInt = segmentsIntersect(pt1[0], pt1[1], pt2[0], pt2[1], edge[0], edge[1], edge[2], edge[3]);
if (ptInt && (!ptCount || Math.abs(ptInt.x - out[0][0]) > 1 || Math.abs(ptInt.y - out[0][1]) > 1)) {
ptInt = [ptInt.x, ptInt.y];
// if we have 2 intersections, make sure the closest one to pt1 comes first
if (ptCount && ptDist(ptInt, pt1) < ptDist(out[0], pt1)) out.unshift(ptInt);else out.push(ptInt);
ptCount++;
}
}
return out;
}
function onlyConstrainedPoint(pt) {
if (pt[0] < xEdge0 || pt[0] > xEdge1 || pt[1] < yEdge0 || pt[1] > yEdge1) {
return [constrain(pt[0], xEdge0, xEdge1), constrain(pt[1], yEdge0, yEdge1)];
}
}
function sameEdge(pt1, pt2) {
if (pt1[0] === pt2[0] && (pt1[0] === xEdge0 || pt1[0] === xEdge1)) return true;
if (pt1[1] === pt2[1] && (pt1[1] === yEdge0 || pt1[1] === yEdge1)) return true;
}
// for line shapes hv and vh, movement in the two dimensions is decoupled,
// so all we need to do is constrain each dimension independently
function getHVEdgeIntersections(pt1, pt2) {
var out = [];
var ptInt1 = onlyConstrainedPoint(pt1);
var ptInt2 = onlyConstrainedPoint(pt2);
if (ptInt1 && ptInt2 && sameEdge(ptInt1, ptInt2)) return out;
if (ptInt1) out.push(ptInt1);
if (ptInt2) out.push(ptInt2);
return out;
}
// hvh and vhv we sometimes have to move one of the intersection points
// out BEYOND the clipping rect, by a maximum of a factor of 2, so that
// the midpoint line is drawn in the right place
function getABAEdgeIntersections(dim, limit0, limit1) {
return function (pt1, pt2) {
var ptInt1 = onlyConstrainedPoint(pt1);
var ptInt2 = onlyConstrainedPoint(pt2);
var out = [];
if (ptInt1 && ptInt2 && sameEdge(ptInt1, ptInt2)) return out;
if (ptInt1) out.push(ptInt1);
if (ptInt2) out.push(ptInt2);
var midShift = 2 * Lib.constrain((pt1[dim] + pt2[dim]) / 2, limit0, limit1) - ((ptInt1 || pt1)[dim] + (ptInt2 || pt2)[dim]);
if (midShift) {
var ptToAlter;
if (ptInt1 && ptInt2) {
ptToAlter = midShift > 0 === ptInt1[dim] > ptInt2[dim] ? ptInt1 : ptInt2;
} else ptToAlter = ptInt1 || ptInt2;
ptToAlter[dim] += midShift;
}
return out;
};
}
var getEdgeIntersections;
if (shape === 'linear' || shape === 'spline') {
getEdgeIntersections = getLinearEdgeIntersections;
} else if (shape === 'hv' || shape === 'vh') {
getEdgeIntersections = getHVEdgeIntersections;
} else if (shape === 'hvh') getEdgeIntersections = getABAEdgeIntersections(0, xEdge0, xEdge1);else if (shape === 'vhv') getEdgeIntersections = getABAEdgeIntersections(1, yEdge0, yEdge1);
// a segment pt1->pt2 entirely outside the nearby region:
// find the corner it gets closest to touching
function getClosestCorner(pt1, pt2) {
var dx = pt2[0] - pt1[0];
var m = (pt2[1] - pt1[1]) / dx;
var b = (pt1[1] * pt2[0] - pt2[1] * pt1[0]) / dx;
if (b > 0) return [m > 0 ? xEdge0 : xEdge1, yEdge1];else return [m > 0 ? xEdge1 : xEdge0, yEdge0];
}
function updateEdge(pt) {
var x = pt[0];
var y = pt[1];
var xSame = x === pts[pti - 1][0];
var ySame = y === pts[pti - 1][1];
// duplicate point?
if (xSame && ySame) return;
if (pti > 1) {
// backtracking along an edge?
var xSame2 = x === pts[pti - 2][0];
var ySame2 = y === pts[pti - 2][1];
if (xSame && (x === xEdge0 || x === xEdge1) && xSame2) {
if (ySame2) pti--; // backtracking exactly - drop prev pt and don't add
else pts[pti - 1] = pt; // not exact: replace the prev pt
} else if (ySame && (y === yEdge0 || y === yEdge1) && ySame2) {
if (xSame2) pti--;else pts[pti - 1] = pt;
} else pts[pti++] = pt;
} else pts[pti++] = pt;
}
function updateEdgesForReentry(pt) {
// if we're outside the nearby region and going back in,
// we may need to loop around a corner point
if (pts[pti - 1][0] !== pt[0] && pts[pti - 1][1] !== pt[1]) {
updateEdge([lastXEdge, lastYEdge]);
}
updateEdge(pt);
lastFarPt = null;
lastXEdge = lastYEdge = 0;
}
var arrayMarker = Lib.isArrayOrTypedArray(marker);
function addPt(pt) {
if (pt && backoff) {
pt.i = i;
pt.d = d;
pt.trace = trace;
pt.marker = arrayMarker ? marker[pt.i] : marker;
pt.backoff = backoff;
}
latestXFrac = pt[0] / xLen;
latestYFrac = pt[1] / yLen;
// Are we more than maxScreensAway off-screen any direction?
// if so, clip to this box, but in such a way that on-screen
// drawing is unchanged
xEdge = pt[0] < xEdge0 ? xEdge0 : pt[0] > xEdge1 ? xEdge1 : 0;
yEdge = pt[1] < yEdge0 ? yEdge0 : pt[1] > yEdge1 ? yEdge1 : 0;
if (xEdge || yEdge) {
if (!pti) {
// to get fills right - if first point is far, push it toward the
// screen in whichever direction(s) are far
pts[pti++] = [xEdge || pt[0], yEdge || pt[1]];
} else if (lastFarPt) {
// both this point and the last are outside the nearby region
// check if we're crossing the nearby region
var intersections = getEdgeIntersections(lastFarPt, pt);
if (intersections.length > 1) {
updateEdgesForReentry(intersections[0]);
pts[pti++] = intersections[1];
}
} else {
// we're leaving the nearby region - add the point where we left it
edgePt = getEdgeIntersections(pts[pti - 1], pt)[0];
pts[pti++] = edgePt;
}
var lastPt = pts[pti - 1];
if (xEdge && yEdge && (lastPt[0] !== xEdge || lastPt[1] !== yEdge)) {
// we've gone out beyond a new corner: add the corner too
// so that the next point will take the right winding
if (lastFarPt) {
if (lastXEdge !== xEdge && lastYEdge !== yEdge) {
if (lastXEdge && lastYEdge) {
// we've gone around to an opposite corner - we
// need to add the correct extra corner
// in order to get the right winding
updateEdge(getClosestCorner(lastFarPt, pt));
} else {
// we're coming from a far edge - the extra corner
// we need is determined uniquely by the sectors
updateEdge([lastXEdge || xEdge, lastYEdge || yEdge]);
}
} else if (lastXEdge && lastYEdge) {
updateEdge([lastXEdge, lastYEdge]);
}
}
updateEdge([xEdge, yEdge]);
} else if (lastXEdge - xEdge && lastYEdge - yEdge) {
// we're coming from an edge or far corner to an edge - again the
// extra corner we need is uniquely determined by the sectors
updateEdge([xEdge || lastXEdge, yEdge || lastYEdge]);
}
lastFarPt = pt;
lastXEdge = xEdge;
lastYEdge = yEdge;
} else {
if (lastFarPt) {
// this point is in range but the previous wasn't: add its entry pt first
updateEdgesForReentry(getEdgeIntersections(lastFarPt, pt)[0]);
}
pts[pti++] = pt;
}
}
// loop over ALL points in this trace
for (i = 0; i < len; i++) {
clusterStartPt = getPt(i);
if (!clusterStartPt) continue;
pti = 0;
lastFarPt = null;
addPt(clusterStartPt);
// loop over one segment of the trace
for (i++; i < len; i++) {
clusterHighPt = getPt(i);
if (!clusterHighPt) {
if (connectGaps) continue;else break;
}
// can't decimate if nonlinear line shape
// TODO: we *could* decimate [hv]{2,3} shapes if we restricted clusters to horz or vert again
// but spline would be verrry awkward to decimate
if (!linear || !opts.simplify) {
addPt(clusterHighPt);
continue;
}
var nextPt = getPt(i + 1);
clusterRefDist = ptDist(clusterHighPt, clusterStartPt);
// #3147 - always include the very first and last points for fills
if (!(fill && (pti === 0 || pti === len - 1)) && clusterRefDist < getTolerance(clusterHighPt, nextPt) * minTolerance) continue;
clusterUnitVector = [(clusterHighPt[0] - clusterStartPt[0]) / clusterRefDist, (clusterHighPt[1] - clusterStartPt[1]) / clusterRefDist];
clusterLowPt = clusterStartPt;
clusterHighVal = clusterRefDist;
clusterLowVal = clusterMinDeviation = clusterMaxDeviation = 0;
clusterHighFirst = false;
clusterEndPt = clusterHighPt;
// loop over one cluster of points that collapse onto one line
for (i++; i < d.length; i++) {
thisPt = nextPt;
nextPt = getPt(i + 1);
if (!thisPt) {
if (connectGaps) continue;else break;
}
thisVector = [thisPt[0] - clusterStartPt[0], thisPt[1] - clusterStartPt[1]];
// cross product (or dot with normal to the cluster vector)
thisDeviation = thisVector[0] * clusterUnitVector[1] - thisVector[1] * clusterUnitVector[0];
clusterMinDeviation = Math.min(clusterMinDeviation, thisDeviation);
clusterMaxDeviation = Math.max(clusterMaxDeviation, thisDeviation);
if (clusterMaxDeviation - clusterMinDeviation > getTolerance(thisPt, nextPt)) break;
clusterEndPt = thisPt;
thisVal = thisVector[0] * clusterUnitVector[0] + thisVector[1] * clusterUnitVector[1];
if (thisVal > clusterHighVal) {
clusterHighVal = thisVal;
clusterHighPt = thisPt;
clusterHighFirst = false;
} else if (thisVal < clusterLowVal) {
clusterLowVal = thisVal;
clusterLowPt = thisPt;
clusterHighFirst = true;
}
}
// insert this cluster into pts
// we've already inserted the start pt, now check if we have high and low pts
if (clusterHighFirst) {
addPt(clusterHighPt);
if (clusterEndPt !== clusterLowPt) addPt(clusterLowPt);
} else {
if (clusterLowPt !== clusterStartPt) addPt(clusterLowPt);
if (clusterEndPt !== clusterHighPt) addPt(clusterHighPt);
}
// and finally insert the end pt
addPt(clusterEndPt);
// have we reached the end of this segment?
if (i >= d.length || !thisPt) break;
// otherwise we have an out-of-cluster point to insert as next clusterStartPt
addPt(thisPt);
clusterStartPt = thisPt;
}
// to get fills right - repeat what we did at the start
if (lastFarPt) updateEdge([lastXEdge || lastFarPt[0], lastYEdge || lastFarPt[1]]);
segments.push(pts.slice(0, pti));
}
var lastShapeChar = shape.slice(shape.length - 1);
if (backoff && lastShapeChar !== 'h' && lastShapeChar !== 'v') {
var trimmed = false;
var n = -1;
var newSegments = [];
for (var j = 0; j < segments.length; j++) {
for (var k = 0; k < segments[j].length - 1; k++) {
var start = segments[j][k];
var end = segments[j][k + 1];
var xy = Drawing.applyBackoff(end, start);
if (xy[0] !== end[0] || xy[1] !== end[1]) {
trimmed = true;
}
if (!newSegments[n + 1]) {
n++;
newSegments[n] = [start, [xy[0], xy[1]]];
}
}
}
return trimmed ? newSegments : segments;
}
return segments;
};
/***/ }),
/***/ 1731:
/***/ (function(module) {
"use strict";
// common to 'scatter' and 'scatterternary'
module.exports = function handleLineShapeDefaults(traceIn, traceOut, coerce) {
var shape = coerce('line.shape');
if (shape === 'spline') coerce('line.smoothing');
};
/***/ }),
/***/ 4328:
/***/ (function(module) {
"use strict";
var LINKEDFILLS = {
tonextx: 1,
tonexty: 1,
tonext: 1
};
module.exports = function linkTraces(gd, plotinfo, cdscatter) {
var trace, i, group, prevtrace, groupIndex;
// first sort traces to keep stacks & filled-together groups together
var groupIndices = {};
var needsSort = false;
var prevGroupIndex = -1;
var nextGroupIndex = 0;
var prevUnstackedGroupIndex = -1;
for (i = 0; i < cdscatter.length; i++) {
trace = cdscatter[i][0].trace;
group = trace.stackgroup || '';
if (group) {
if (group in groupIndices) {
groupIndex = groupIndices[group];
} else {
groupIndex = groupIndices[group] = nextGroupIndex;
nextGroupIndex++;
}
} else if (trace.fill in LINKEDFILLS && prevUnstackedGroupIndex >= 0) {
groupIndex = prevUnstackedGroupIndex;
} else {
groupIndex = prevUnstackedGroupIndex = nextGroupIndex;
nextGroupIndex++;
}
if (groupIndex < prevGroupIndex) needsSort = true;
trace._groupIndex = prevGroupIndex = groupIndex;
}
var cdscatterSorted = cdscatter.slice();
if (needsSort) {
cdscatterSorted.sort(function (a, b) {
var traceA = a[0].trace;
var traceB = b[0].trace;
return traceA._groupIndex - traceB._groupIndex || traceA.index - traceB.index;
});
}
// now link traces to each other
var prevtraces = {};
for (i = 0; i < cdscatterSorted.length; i++) {
trace = cdscatterSorted[i][0].trace;
group = trace.stackgroup || '';
// Note: The check which ensures all cdscatter here are for the same axis and
// are either cartesian or scatterternary has been removed. This code assumes
// the passed scattertraces have been filtered to the proper plot types and
// the proper subplots.
if (trace.visible === true) {
trace._nexttrace = null;
if (trace.fill in LINKEDFILLS) {
prevtrace = prevtraces[group];
trace._prevtrace = prevtrace || null;
if (prevtrace) {
prevtrace._nexttrace = trace;
}
}
trace._ownfill = trace.fill && (trace.fill.substr(0, 6) === 'tozero' || trace.fill === 'toself' || trace.fill.substr(0, 2) === 'to' && !trace._prevtrace);
prevtraces[group] = trace;
} else {
trace._prevtrace = trace._nexttrace = trace._ownfill = null;
}
}
return cdscatterSorted;
};
/***/ }),
/***/ 7152:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var isNumeric = __webpack_require__(8248);
// used in the drawing step for 'scatter' and 'scattegeo' and
// in the convert step for 'scatter3d'
module.exports = function makeBubbleSizeFn(trace, factor) {
if (!factor) {
factor = 2;
}
var marker = trace.marker;
var sizeRef = marker.sizeref || 1;
var sizeMin = marker.sizemin || 0;
// for bubble charts, allow scaling the provided value linearly
// and by area or diameter.
// Note this only applies to the array-value sizes
var baseFn = marker.sizemode === 'area' ? function (v) {
return Math.sqrt(v / sizeRef);
} : function (v) {
return v / sizeRef;
};
// TODO add support for position/negative bubbles?
// TODO add 'sizeoffset' attribute?
return function (v) {
var baseSize = baseFn(v / factor);
// don't show non-numeric and negative sizes
return isNumeric(baseSize) && baseSize > 0 ? Math.max(baseSize, sizeMin) : 0;
};
};
/***/ }),
/***/ 5528:
/***/ (function(module) {
"use strict";
module.exports = {
container: 'marker',
min: 'cmin',
max: 'cmax'
};
/***/ }),
/***/ 4428:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Color = __webpack_require__(6308);
var hasColorscale = (__webpack_require__(4288).hasColorscale);
var colorscaleDefaults = __webpack_require__(7260);
var subTypes = __webpack_require__(3028);
/*
* opts: object of flags to control features not all marker users support
* noLine: caller does not support marker lines
* gradient: caller supports gradients
* noSelect: caller does not support selected/unselected attribute containers
*/
module.exports = function markerDefaults(traceIn, traceOut, defaultColor, layout, coerce, opts) {
var isBubble = subTypes.isBubble(traceIn);
var lineColor = (traceIn.line || {}).color;
var defaultMLC;
opts = opts || {};
// marker.color inherit from line.color (even if line.color is an array)
if (lineColor) defaultColor = lineColor;
coerce('marker.symbol');
coerce('marker.opacity', isBubble ? 0.7 : 1);
coerce('marker.size');
if (!opts.noAngle) {
coerce('marker.angle');
if (!opts.noAngleRef) {
coerce('marker.angleref');
}
if (!opts.noStandOff) {
coerce('marker.standoff');
}
}
coerce('marker.color', defaultColor);
if (hasColorscale(traceIn, 'marker')) {
colorscaleDefaults(traceIn, traceOut, layout, coerce, {
prefix: 'marker.',
cLetter: 'c'
});
}
if (!opts.noSelect) {
coerce('selected.marker.color');
coerce('unselected.marker.color');
coerce('selected.marker.size');
coerce('unselected.marker.size');
}
if (!opts.noLine) {
// if there's a line with a different color than the marker, use
// that line color as the default marker line color
// (except when it's an array)
// mostly this is for transparent markers to behave nicely
if (lineColor && !Array.isArray(lineColor) && traceOut.marker.color !== lineColor) {
defaultMLC = lineColor;
} else if (isBubble) defaultMLC = Color.background;else defaultMLC = Color.defaultLine;
coerce('marker.line.color', defaultMLC);
if (hasColorscale(traceIn, 'marker.line')) {
colorscaleDefaults(traceIn, traceOut, layout, coerce, {
prefix: 'marker.line.',
cLetter: 'c'
});
}
coerce('marker.line.width', isBubble ? 1 : 0);
}
if (isBubble) {
coerce('marker.sizeref');
coerce('marker.sizemin');
coerce('marker.sizemode');
}
if (opts.gradient) {
var gradientType = coerce('marker.gradient.type');
if (gradientType !== 'none') {
coerce('marker.gradient.color');
}
}
};
/***/ }),
/***/ 1147:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var dateTick0 = (__webpack_require__(3400).dateTick0);
var numConstants = __webpack_require__(9032);
var ONEWEEK = numConstants.ONEWEEK;
function getPeriod0Dflt(period, calendar) {
if (period % ONEWEEK === 0) {
return dateTick0(calendar, 1); // Sunday
}
return dateTick0(calendar, 0);
}
module.exports = function handlePeriodDefaults(traceIn, traceOut, layout, coerce, opts) {
if (!opts) {
opts = {
x: true,
y: true
};
}
if (opts.x) {
var xperiod = coerce('xperiod');
if (xperiod) {
coerce('xperiod0', getPeriod0Dflt(xperiod, traceOut.xcalendar));
coerce('xperiodalignment');
}
}
if (opts.y) {
var yperiod = coerce('yperiod');
if (yperiod) {
coerce('yperiod0', getPeriod0Dflt(yperiod, traceOut.ycalendar));
coerce('yperiodalignment');
}
}
};
/***/ }),
/***/ 6504:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var d3 = __webpack_require__(3428);
var Registry = __webpack_require__(4040);
var Lib = __webpack_require__(3400);
var ensureSingle = Lib.ensureSingle;
var identity = Lib.identity;
var Drawing = __webpack_require__(3616);
var subTypes = __webpack_require__(3028);
var linePoints = __webpack_require__(2340);
var linkTraces = __webpack_require__(4328);
var polygonTester = (__webpack_require__(2065).tester);
module.exports = function plot(gd, plotinfo, cdscatter, scatterLayer, transitionOpts, makeOnCompleteCallback) {
var join, onComplete;
// If transition config is provided, then it is only a partial replot and traces not
// updated are removed.
var isFullReplot = !transitionOpts;
var hasTransition = !!transitionOpts && transitionOpts.duration > 0;
// Link traces so the z-order of fill layers is correct
var cdscatterSorted = linkTraces(gd, plotinfo, cdscatter);
join = scatterLayer.selectAll('g.trace').data(cdscatterSorted, function (d) {
return d[0].trace.uid;
});
// Append new traces:
join.enter().append('g').attr('class', function (d) {
return 'trace scatter trace' + d[0].trace.uid;
}).style('stroke-miterlimit', 2);
join.order();
createFills(gd, join, plotinfo);
if (hasTransition) {
if (makeOnCompleteCallback) {
// If it was passed a callback to register completion, make a callback. If
// this is created, then it must be executed on completion, otherwise the
// pos-transition redraw will not execute:
onComplete = makeOnCompleteCallback();
}
var transition = d3.transition().duration(transitionOpts.duration).ease(transitionOpts.easing).each('end', function () {
onComplete && onComplete();
}).each('interrupt', function () {
onComplete && onComplete();
});
transition.each(function () {
// Must run the selection again since otherwise enters/updates get grouped together
// and these get executed out of order. Except we need them in order!
scatterLayer.selectAll('g.trace').each(function (d, i) {
plotOne(gd, i, plotinfo, d, cdscatterSorted, this, transitionOpts);
});
});
} else {
join.each(function (d, i) {
plotOne(gd, i, plotinfo, d, cdscatterSorted, this, transitionOpts);
});
}
if (isFullReplot) {
join.exit().remove();
}
// remove paths that didn't get used
scatterLayer.selectAll('path:not([d])').remove();
};
function createFills(gd, traceJoin, plotinfo) {
traceJoin.each(function (d) {
var fills = ensureSingle(d3.select(this), 'g', 'fills');
Drawing.setClipUrl(fills, plotinfo.layerClipId, gd);
var trace = d[0].trace;
var fillData = [];
if (trace._ownfill) fillData.push('_ownFill');
if (trace._nexttrace) fillData.push('_nextFill');
var fillJoin = fills.selectAll('g').data(fillData, identity);
fillJoin.enter().append('g');
fillJoin.exit().each(function (d) {
trace[d] = null;
}).remove();
fillJoin.order().each(function (d) {
// make a path element inside the fill group, just so
// we can give it its own data later on and the group can
// keep its simple '_*Fill' data
trace[d] = ensureSingle(d3.select(this), 'path', 'js-fill');
});
});
}
function plotOne(gd, idx, plotinfo, cdscatter, cdscatterAll, element, transitionOpts) {
var isStatic = gd._context.staticPlot;
var i;
// Since this has been reorganized and we're executing this on individual traces,
// we need to pass it the full list of cdscatter as well as this trace's index (idx)
// since it does an internal n^2 loop over comparisons with other traces:
selectMarkers(gd, idx, plotinfo, cdscatter, cdscatterAll);
var hasTransition = !!transitionOpts && transitionOpts.duration > 0;
function transition(selection) {
return hasTransition ? selection.transition() : selection;
}
var xa = plotinfo.xaxis;
var ya = plotinfo.yaxis;
var trace = cdscatter[0].trace;
var line = trace.line;
var tr = d3.select(element);
var errorBarGroup = ensureSingle(tr, 'g', 'errorbars');
var lines = ensureSingle(tr, 'g', 'lines');
var points = ensureSingle(tr, 'g', 'points');
var text = ensureSingle(tr, 'g', 'text');
// error bars are at the bottom
Registry.getComponentMethod('errorbars', 'plot')(gd, errorBarGroup, plotinfo, transitionOpts);
if (trace.visible !== true) return;
transition(tr).style('opacity', trace.opacity);
// BUILD LINES AND FILLS
var ownFillEl3, tonext;
var ownFillDir = trace.fill.charAt(trace.fill.length - 1);
if (ownFillDir !== 'x' && ownFillDir !== 'y') ownFillDir = '';
var fillAxisIndex, fillAxisZero;
if (ownFillDir === 'y') {
fillAxisIndex = 1;
fillAxisZero = ya.c2p(0, true);
} else if (ownFillDir === 'x') {
fillAxisIndex = 0;
fillAxisZero = xa.c2p(0, true);
}
// store node for tweaking by selectPoints
cdscatter[0][plotinfo.isRangePlot ? 'nodeRangePlot3' : 'node3'] = tr;
var prevRevpath = '';
var prevPolygons = [];
var prevtrace = trace._prevtrace;
var prevFillsegments = null;
var prevFillElement = null;
if (prevtrace) {
prevRevpath = prevtrace._prevRevpath || '';
tonext = prevtrace._nextFill;
prevPolygons = prevtrace._ownPolygons;
prevFillsegments = prevtrace._fillsegments;
prevFillElement = prevtrace._fillElement;
}
var thispath;
var thisrevpath;
// fullpath is all paths for this curve, joined together straight
// across gaps, for filling
var fullpath = '';
// revpath is fullpath reversed, for fill-to-next
var revpath = '';
// functions for converting a point array to a path
var pathfn, revpathbase, revpathfn;
// variables used before and after the data join
var pt0, lastSegment, pt1;
// thisPolygons always contains only the polygons of this trace only
// whereas trace._polygons may be extended to include those of the previous
// trace as well for exclusion during hover detection
var thisPolygons = [];
trace._polygons = [];
var fillsegments = [];
// initialize line join data / method
var segments = [];
var makeUpdate = Lib.noop;
ownFillEl3 = trace._ownFill;
if (subTypes.hasLines(trace) || trace.fill !== 'none') {
if (tonext) {
// This tells .style which trace to use for fill information:
tonext.datum(cdscatter);
}
if (['hv', 'vh', 'hvh', 'vhv'].indexOf(line.shape) !== -1) {
pathfn = Drawing.steps(line.shape);
revpathbase = Drawing.steps(line.shape.split('').reverse().join(''));
} else if (line.shape === 'spline') {
pathfn = revpathbase = function (pts) {
var pLast = pts[pts.length - 1];
if (pts.length > 1 && pts[0][0] === pLast[0] && pts[0][1] === pLast[1]) {
// identical start and end points: treat it as a
// closed curve so we don't get a kink
return Drawing.smoothclosed(pts.slice(1), line.smoothing);
} else {
return Drawing.smoothopen(pts, line.smoothing);
}
};
} else {
pathfn = revpathbase = function (pts) {
return 'M' + pts.join('L');
};
}
revpathfn = function (pts) {
// note: this is destructive (reverses pts in place) so can't use pts after this
return revpathbase(pts.reverse());
};
segments = linePoints(cdscatter, {
xaxis: xa,
yaxis: ya,
trace: trace,
connectGaps: trace.connectgaps,
baseTolerance: Math.max(line.width || 1, 3) / 4,
shape: line.shape,
backoff: line.backoff,
simplify: line.simplify,
fill: trace.fill
});
// since we already have the pixel segments here, use them to make
// polygons for hover on fill; we first merge segments where the fill
// is connected into "fillsegments"; the actual polygon construction
// is deferred to later to distinguish between self and tonext/tozero fills.
// TODO: can we skip this if hoveron!=fills? That would mean we
// need to redraw when you change hoveron...
fillsegments = new Array(segments.length);
var fillsegmentCount = 0;
for (i = 0; i < segments.length; i++) {
var curpoints;
var pts = segments[i];
if (!curpoints || !ownFillDir) {
curpoints = pts.slice();
fillsegments[fillsegmentCount] = curpoints;
fillsegmentCount++;
} else {
curpoints.push.apply(curpoints, pts);
}
}
trace._fillElement = null;
trace._fillExclusionElement = prevFillElement;
trace._fillsegments = fillsegments.slice(0, fillsegmentCount);
fillsegments = trace._fillsegments;
if (segments.length) {
pt0 = segments[0][0].slice();
lastSegment = segments[segments.length - 1];
pt1 = lastSegment[lastSegment.length - 1].slice();
}
makeUpdate = function (isEnter) {
return function (pts) {
thispath = pathfn(pts);
thisrevpath = revpathfn(pts); // side-effect: reverses input
// calculate SVG path over all segments for fills
if (!fullpath) {
fullpath = thispath;
revpath = thisrevpath;
} else if (ownFillDir) {
// for fills with fill direction: ignore gaps
fullpath += 'L' + thispath.substr(1);
revpath = thisrevpath + ('L' + revpath.substr(1));
} else {
fullpath += 'Z' + thispath;
revpath = thisrevpath + 'Z' + revpath;
}
// actual lines get drawn here, with gaps between segments if requested
if (subTypes.hasLines(trace)) {
var el = d3.select(this);
// This makes the coloring work correctly:
el.datum(cdscatter);
if (isEnter) {
transition(el.style('opacity', 0).attr('d', thispath).call(Drawing.lineGroupStyle)).style('opacity', 1);
} else {
var sel = transition(el);
sel.attr('d', thispath);
Drawing.singleLineStyle(cdscatter, sel);
}
}
};
};
}
var lineJoin = lines.selectAll('.js-line').data(segments);
transition(lineJoin.exit()).style('opacity', 0).remove();
lineJoin.each(makeUpdate(false));
lineJoin.enter().append('path').classed('js-line', true).style('vector-effect', isStatic ? 'none' : 'non-scaling-stroke').call(Drawing.lineGroupStyle).each(makeUpdate(true));
Drawing.setClipUrl(lineJoin, plotinfo.layerClipId, gd);
function clearFill(selection) {
transition(selection).attr('d', 'M0,0Z');
}
// helper functions to create polygons for hoveron fill detection
var makeSelfPolygons = function () {
var polygons = new Array(fillsegments.length);
for (i = 0; i < fillsegments.length; i++) {
polygons[i] = polygonTester(fillsegments[i]);
}
return polygons;
};
var makePolygonsToPrevious = function (prevFillsegments) {
var polygons, i;
if (!prevFillsegments || prevFillsegments.length === 0) {
// if there are no fill segments of a previous trace, stretch the
// polygon to the relevant axis
polygons = new Array(fillsegments.length);
for (i = 0; i < fillsegments.length; i++) {
var pt0 = fillsegments[i][0].slice();
var pt1 = fillsegments[i][fillsegments[i].length - 1].slice();
pt0[fillAxisIndex] = pt1[fillAxisIndex] = fillAxisZero;
var zeropoints = [pt1, pt0];
var polypoints = zeropoints.concat(fillsegments[i]);
polygons[i] = polygonTester(polypoints);
}
} else {
// if there are more than one previous fill segment, the
// way that fills work is to "self" fill all but the last segments
// of the previous and then fill from the new trace to the last
// segment of the previous.
polygons = new Array(prevFillsegments.length - 1 + fillsegments.length);
for (i = 0; i < prevFillsegments.length - 1; i++) {
polygons[i] = polygonTester(prevFillsegments[i]);
}
var reversedPrevFillsegment = prevFillsegments[prevFillsegments.length - 1].slice();
reversedPrevFillsegment.reverse();
for (i = 0; i < fillsegments.length; i++) {
polygons[prevFillsegments.length - 1 + i] = polygonTester(fillsegments[i].concat(reversedPrevFillsegment));
}
}
return polygons;
};
// draw fills and create hover detection polygons
if (segments.length) {
if (ownFillEl3) {
ownFillEl3.datum(cdscatter);
if (pt0 && pt1) {
// TODO(2023-12-10): this is always true if segments is not empty (?)
if (ownFillDir) {
pt0[fillAxisIndex] = pt1[fillAxisIndex] = fillAxisZero;
// fill to zero: full trace path, plus extension of
// the endpoints to the appropriate axis
// For the sake of animations, wrap the points around so that
// the points on the axes are the first two points. Otherwise
// animations get a little crazy if the number of points changes.
transition(ownFillEl3).attr('d', 'M' + pt1 + 'L' + pt0 + 'L' + fullpath.substr(1)).call(Drawing.singleFillStyle, gd);
// create hover polygons that extend to the axis as well.
thisPolygons = makePolygonsToPrevious(null); // polygon to axis
} else {
// fill to self: just join the path to itself
transition(ownFillEl3).attr('d', fullpath + 'Z').call(Drawing.singleFillStyle, gd);
// and simply emit hover polygons for each segment
thisPolygons = makeSelfPolygons();
}
}
trace._polygons = thisPolygons;
trace._fillElement = ownFillEl3;
} else if (tonext) {
if (trace.fill.substr(0, 6) === 'tonext' && fullpath && prevRevpath) {
// fill to next: full trace path, plus the previous path reversed
if (trace.fill === 'tonext') {
// tonext: for use by concentric shapes, like manually constructed
// contours, we just add the two paths closed on themselves.
// This makes strange results if one path is *not* entirely
// inside the other, but then that is a strange usage.
transition(tonext).attr('d', fullpath + 'Z' + prevRevpath + 'Z').call(Drawing.singleFillStyle, gd);
// and simply emit hover polygons for each segment
thisPolygons = makeSelfPolygons();
// we add the polygons of the previous trace which causes hover
// detection to ignore points contained in them.
trace._polygons = thisPolygons.concat(prevPolygons); // this does not modify thisPolygons, on purpose
} else {
// tonextx/y: for now just connect endpoints with lines. This is
// the correct behavior if the endpoints are at the same value of
// y/x, but if they *aren't*, we should ideally do more complicated
// things depending on whether the new endpoint projects onto the
// existing curve or off the end of it
transition(tonext).attr('d', fullpath + 'L' + prevRevpath.substr(1) + 'Z').call(Drawing.singleFillStyle, gd);
// create hover polygons that extend to the previous trace.
thisPolygons = makePolygonsToPrevious(prevFillsegments);
// in this case our polygons do not cover that of previous traces,
// so must not include previous trace polygons for hover detection.
trace._polygons = thisPolygons;
}
trace._fillElement = tonext;
} else {
clearFill(tonext);
}
}
trace._prevRevpath = revpath;
} else {
if (ownFillEl3) clearFill(ownFillEl3);else if (tonext) clearFill(tonext);
trace._prevRevpath = null;
}
trace._ownPolygons = thisPolygons;
function visFilter(d) {
return d.filter(function (v) {
return !v.gap && v.vis;
});
}
function visFilterWithGaps(d) {
return d.filter(function (v) {
return v.vis;
});
}
function gapFilter(d) {
return d.filter(function (v) {
return !v.gap;
});
}
function keyFunc(d) {
return d.id;
}
// Returns a function if the trace is keyed, otherwise returns undefined
function getKeyFunc(trace) {
if (trace.ids) {
return keyFunc;
}
}
function hideFilter() {
return false;
}
function makePoints(points, text, cdscatter) {
var join, selection, hasNode;
var trace = cdscatter[0].trace;
var showMarkers = subTypes.hasMarkers(trace);
var showText = subTypes.hasText(trace);
var keyFunc = getKeyFunc(trace);
var markerFilter = hideFilter;
var textFilter = hideFilter;
if (showMarkers || showText) {
var showFilter = identity;
// if we're stacking, "infer zero" gap mode gets markers in the
// gap points - because we've inferred a zero there - but other
// modes (currently "interpolate", later "interrupt" hopefully)
// we don't draw generated markers
var stackGroup = trace.stackgroup;
var isInferZero = stackGroup && gd._fullLayout._scatterStackOpts[xa._id + ya._id][stackGroup].stackgaps === 'infer zero';
if (trace.marker.maxdisplayed || trace._needsCull) {
showFilter = isInferZero ? visFilterWithGaps : visFilter;
} else if (stackGroup && !isInferZero) {
showFilter = gapFilter;
}
if (showMarkers) markerFilter = showFilter;
if (showText) textFilter = showFilter;
}
// marker points
selection = points.selectAll('path.point');
join = selection.data(markerFilter, keyFunc);
var enter = join.enter().append('path').classed('point', true);
if (hasTransition) {
enter.call(Drawing.pointStyle, trace, gd).call(Drawing.translatePoints, xa, ya).style('opacity', 0).transition().style('opacity', 1);
}
join.order();
var styleFns;
if (showMarkers) {
styleFns = Drawing.makePointStyleFns(trace);
}
join.each(function (d) {
var el = d3.select(this);
var sel = transition(el);
hasNode = Drawing.translatePoint(d, sel, xa, ya);
if (hasNode) {
Drawing.singlePointStyle(d, sel, trace, styleFns, gd);
if (plotinfo.layerClipId) {
Drawing.hideOutsideRangePoint(d, sel, xa, ya, trace.xcalendar, trace.ycalendar);
}
if (trace.customdata) {
el.classed('plotly-customdata', d.data !== null && d.data !== undefined);
}
} else {
sel.remove();
}
});
if (hasTransition) {
join.exit().transition().style('opacity', 0).remove();
} else {
join.exit().remove();
}
// text points
selection = text.selectAll('g');
join = selection.data(textFilter, keyFunc);
// each text needs to go in its own 'g' in case
// it gets converted to mathjax
join.enter().append('g').classed('textpoint', true).append('text');
join.order();
join.each(function (d) {
var g = d3.select(this);
var sel = transition(g.select('text'));
hasNode = Drawing.translatePoint(d, sel, xa, ya);
if (hasNode) {
if (plotinfo.layerClipId) {
Drawing.hideOutsideRangePoint(d, g, xa, ya, trace.xcalendar, trace.ycalendar);
}
} else {
g.remove();
}
});
join.selectAll('text').call(Drawing.textPointStyle, trace, gd).each(function (d) {
// This just *has* to be totally custom because of SVG text positioning :(
// It's obviously copied from translatePoint; we just can't use that
var x = xa.c2p(d.x);
var y = ya.c2p(d.y);
d3.select(this).selectAll('tspan.line').each(function () {
transition(d3.select(this)).attr({
x: x,
y: y
});
});
});
join.exit().remove();
}
points.datum(cdscatter);
text.datum(cdscatter);
makePoints(points, text, cdscatter);
// lastly, clip points groups of `cliponaxis !== false` traces
// on `plotinfo._hasClipOnAxisFalse === true` subplots
var hasClipOnAxisFalse = trace.cliponaxis === false;
var clipUrl = hasClipOnAxisFalse ? null : plotinfo.layerClipId;
Drawing.setClipUrl(points, clipUrl, gd);
Drawing.setClipUrl(text, clipUrl, gd);
}
function selectMarkers(gd, idx, plotinfo, cdscatter, cdscatterAll) {
var xa = plotinfo.xaxis;
var ya = plotinfo.yaxis;
var xr = d3.extent(Lib.simpleMap(xa.range, xa.r2c));
var yr = d3.extent(Lib.simpleMap(ya.range, ya.r2c));
var trace = cdscatter[0].trace;
if (!subTypes.hasMarkers(trace)) return;
// if marker.maxdisplayed is used, select a maximum of
// mnum markers to show, from the set that are in the viewport
var mnum = trace.marker.maxdisplayed;
// TODO: remove some as we get away from the viewport?
if (mnum === 0) return;
var cd = cdscatter.filter(function (v) {
return v.x >= xr[0] && v.x <= xr[1] && v.y >= yr[0] && v.y <= yr[1];
});
var inc = Math.ceil(cd.length / mnum);
var tnum = 0;
cdscatterAll.forEach(function (cdj, j) {
var tracei = cdj[0].trace;
if (subTypes.hasMarkers(tracei) && tracei.marker.maxdisplayed > 0 && j < idx) {
tnum++;
}
});
// if multiple traces use maxdisplayed, stagger which markers we
// display this formula offsets successive traces by 1/3 of the
// increment, adding an extra small amount after each triplet so
// it's not quite periodic
var i0 = Math.round(tnum * inc / 3 + Math.floor(tnum / 3) * inc / 7.1);
// for error bars: save in cd which markers to show
// so we don't have to repeat this
cdscatter.forEach(function (v) {
delete v.vis;
});
cd.forEach(function (v, i) {
if (Math.round((i + i0) % inc) === 0) v.vis = true;
});
}
/***/ }),
/***/ 1560:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var subtypes = __webpack_require__(3028);
module.exports = function selectPoints(searchInfo, selectionTester) {
var cd = searchInfo.cd;
var xa = searchInfo.xaxis;
var ya = searchInfo.yaxis;
var selection = [];
var trace = cd[0].trace;
var i;
var di;
var x;
var y;
var hasOnlyLines = !subtypes.hasMarkers(trace) && !subtypes.hasText(trace);
if (hasOnlyLines) return [];
if (selectionTester === false) {
// clear selection
for (i = 0; i < cd.length; i++) {
cd[i].selected = 0;
}
} else {
for (i = 0; i < cd.length; i++) {
di = cd[i];
x = xa.c2p(di.x);
y = ya.c2p(di.y);
if (di.i !== null && selectionTester.contains([x, y], false, i, searchInfo)) {
selection.push({
pointNumber: di.i,
x: xa.c2d(di.x),
y: ya.c2d(di.y)
});
di.selected = 1;
} else {
di.selected = 0;
}
}
}
return selection;
};
/***/ }),
/***/ 3912:
/***/ (function(module) {
"use strict";
var perStackAttrs = ['orientation', 'groupnorm', 'stackgaps'];
module.exports = function handleStackDefaults(traceIn, traceOut, layout, coerce) {
var stackOpts = layout._scatterStackOpts;
var stackGroup = coerce('stackgroup');
if (stackGroup) {
// use independent stacking options per subplot
var subplot = traceOut.xaxis + traceOut.yaxis;
var subplotStackOpts = stackOpts[subplot];
if (!subplotStackOpts) subplotStackOpts = stackOpts[subplot] = {};
var groupOpts = subplotStackOpts[stackGroup];
var firstTrace = false;
if (groupOpts) {
groupOpts.traces.push(traceOut);
} else {
groupOpts = subplotStackOpts[stackGroup] = {
// keep track of trace indices for use during stacking calculations
// this will be filled in during `calc` and used during `crossTraceCalc`
// so it's OK if we don't recreate it during a non-calc edit
traceIndices: [],
// Hold on to the whole set of prior traces
// First one is most important, so we can clear defaults
// there if we find explicit values only in later traces.
// We're only going to *use* the values stored in groupOpts,
// but for the editor and validate we want things self-consistent
// The full set of traces is used only to fix `fill` default if
// we find `orientation: 'h'` beyond the first trace
traces: [traceOut]
};
firstTrace = true;
}
// TODO: how is this going to work with groupby transforms?
// in principle it should be OK I guess, as long as explicit group styles
// don't override explicit base-trace styles?
var dflts = {
orientation: traceOut.x && !traceOut.y ? 'h' : 'v'
};
for (var i = 0; i < perStackAttrs.length; i++) {
var attr = perStackAttrs[i];
var attrFound = attr + 'Found';
if (!groupOpts[attrFound]) {
var traceHasAttr = traceIn[attr] !== undefined;
var isOrientation = attr === 'orientation';
if (traceHasAttr || firstTrace) {
groupOpts[attr] = coerce(attr, dflts[attr]);
if (isOrientation) {
groupOpts.fillDflt = groupOpts[attr] === 'h' ? 'tonextx' : 'tonexty';
}
if (traceHasAttr) {
// Note: this will show a value here even if it's invalid
// in which case it will revert to default.
groupOpts[attrFound] = true;
// Note: only one trace in the stack will get a _fullData
// entry for a given stack-wide attribute. If no traces
// (or the first trace) specify that attribute, the
// first trace will get it. If the first trace does NOT
// specify it but some later trace does, then it gets
// removed from the first trace and only included in the
// one that specified it. This is mostly important for
// editors (that want to see the full values to know
// what settings are available) and Plotly.react diffing.
// Editors may want to use fullLayout._scatterStackOpts
// directly and make these settings available from all
// traces in the stack... then set the new value into
// the first trace, and clear all later traces.
if (!firstTrace) {
delete groupOpts.traces[0][attr];
// orientation can affect default fill of previous traces
if (isOrientation) {
for (var j = 0; j < groupOpts.traces.length - 1; j++) {
var trace2 = groupOpts.traces[j];
if (trace2._input.fill !== trace2.fill) {
trace2.fill = groupOpts.fillDflt;
}
}
}
}
}
}
}
}
return groupOpts;
}
};
/***/ }),
/***/ 6844:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var d3 = __webpack_require__(3428);
var Drawing = __webpack_require__(3616);
var Registry = __webpack_require__(4040);
function style(gd) {
var s = d3.select(gd).selectAll('g.trace.scatter');
s.style('opacity', function (d) {
return d[0].trace.opacity;
});
s.selectAll('g.points').each(function (d) {
var sel = d3.select(this);
var trace = d.trace || d[0].trace;
stylePoints(sel, trace, gd);
});
s.selectAll('g.text').each(function (d) {
var sel = d3.select(this);
var trace = d.trace || d[0].trace;
styleText(sel, trace, gd);
});
s.selectAll('g.trace path.js-line').call(Drawing.lineGroupStyle);
s.selectAll('g.trace path.js-fill').call(Drawing.fillGroupStyle, gd, false);
Registry.getComponentMethod('errorbars', 'style')(s);
}
function stylePoints(sel, trace, gd) {
Drawing.pointStyle(sel.selectAll('path.point'), trace, gd);
}
function styleText(sel, trace, gd) {
Drawing.textPointStyle(sel.selectAll('text'), trace, gd);
}
function styleOnSelect(gd, cd, sel) {
var trace = cd[0].trace;
if (trace.selectedpoints) {
Drawing.selectedPointStyle(sel.selectAll('path.point'), trace);
Drawing.selectedTextStyle(sel.selectAll('text'), trace);
} else {
stylePoints(sel, trace, gd);
styleText(sel, trace, gd);
}
}
module.exports = {
style: style,
stylePoints: stylePoints,
styleText: styleText,
styleOnSelect: styleOnSelect
};
/***/ }),
/***/ 3028:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Lib = __webpack_require__(3400);
var isTypedArraySpec = (__webpack_require__(8116).isTypedArraySpec);
module.exports = {
hasLines: function (trace) {
return trace.visible && trace.mode && trace.mode.indexOf('lines') !== -1;
},
hasMarkers: function (trace) {
return trace.visible && (trace.mode && trace.mode.indexOf('markers') !== -1 ||
// until splom implements 'mode'
trace.type === 'splom');
},
hasText: function (trace) {
return trace.visible && trace.mode && trace.mode.indexOf('text') !== -1;
},
isBubble: function (trace) {
var marker = trace.marker;
return Lib.isPlainObject(marker) && (Lib.isArrayOrTypedArray(marker.size) || isTypedArraySpec(marker.size));
}
};
/***/ }),
/***/ 124:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Lib = __webpack_require__(3400);
/*
* opts: object of flags to control features not all text users support
* noSelect: caller does not support selected/unselected attribute containers
*/
module.exports = function (traceIn, traceOut, layout, coerce, opts) {
opts = opts || {};
coerce('textposition');
Lib.coerceFont(coerce, 'textfont', opts.font || layout.font);
if (!opts.noSelect) {
coerce('selected.textfont.color');
coerce('unselected.textfont.color');
}
};
/***/ }),
/***/ 3980:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Lib = __webpack_require__(3400);
var Registry = __webpack_require__(4040);
module.exports = function handleXYDefaults(traceIn, traceOut, layout, coerce) {
var x = coerce('x');
var y = coerce('y');
var len;
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleTraceDefaults');
handleCalendarDefaults(traceIn, traceOut, ['x', 'y'], layout);
if (x) {
var xlen = Lib.minRowLength(x);
if (y) {
len = Math.min(xlen, Lib.minRowLength(y));
} else {
len = xlen;
coerce('y0');
coerce('dy');
}
} else {
if (!y) return 0;
len = Lib.minRowLength(y);
coerce('x0');
coerce('dx');
}
traceOut._length = len;
return len;
};
/***/ }),
/***/ 6096:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var hovertemplateAttrs = (__webpack_require__(1776)/* .hovertemplateAttrs */ .Ks);
var texttemplateAttrs = (__webpack_require__(1776)/* .texttemplateAttrs */ .Gw);
var makeFillcolorAttr = __webpack_require__(3544);
var scatterAttrs = __webpack_require__(2904);
var baseAttrs = __webpack_require__(5464);
var colorAttributes = __webpack_require__(9084);
var dash = (__webpack_require__(8192)/* .dash */ .u);
var extendFlat = (__webpack_require__(2880).extendFlat);
var overrideAll = (__webpack_require__(7824).overrideAll);
var scatterMarkerAttrs = scatterAttrs.marker;
var scatterLineAttrs = scatterAttrs.line;
var scatterMarkerLineAttrs = scatterMarkerAttrs.line;
module.exports = overrideAll({
lon: {
valType: 'data_array'
},
lat: {
valType: 'data_array'
},
locations: {
valType: 'data_array'
},
locationmode: {
valType: 'enumerated',
values: ['ISO-3', 'USA-states', 'country names', 'geojson-id'],
dflt: 'ISO-3'
},
geojson: {
valType: 'any',
editType: 'calc'
},
featureidkey: {
valType: 'string',
editType: 'calc',
dflt: 'id'
},
mode: extendFlat({}, scatterAttrs.mode, {
dflt: 'markers'
}),
text: extendFlat({}, scatterAttrs.text, {}),
texttemplate: texttemplateAttrs({
editType: 'plot'
}, {
keys: ['lat', 'lon', 'location', 'text']
}),
hovertext: extendFlat({}, scatterAttrs.hovertext, {}),
textfont: scatterAttrs.textfont,
textposition: scatterAttrs.textposition,
line: {
color: scatterLineAttrs.color,
width: scatterLineAttrs.width,
dash: dash
},
connectgaps: scatterAttrs.connectgaps,
marker: extendFlat({
symbol: scatterMarkerAttrs.symbol,
opacity: scatterMarkerAttrs.opacity,
angle: scatterMarkerAttrs.angle,
angleref: extendFlat({}, scatterMarkerAttrs.angleref, {
values: ['previous', 'up', 'north']
}),
standoff: scatterMarkerAttrs.standoff,
size: scatterMarkerAttrs.size,
sizeref: scatterMarkerAttrs.sizeref,
sizemin: scatterMarkerAttrs.sizemin,
sizemode: scatterMarkerAttrs.sizemode,
colorbar: scatterMarkerAttrs.colorbar,
line: extendFlat({
width: scatterMarkerLineAttrs.width
}, colorAttributes('marker.line')),
gradient: scatterMarkerAttrs.gradient
}, colorAttributes('marker')),
fill: {
valType: 'enumerated',
values: ['none', 'toself'],
dflt: 'none'
},
fillcolor: makeFillcolorAttr(),
selected: scatterAttrs.selected,
unselected: scatterAttrs.unselected,
hoverinfo: extendFlat({}, baseAttrs.hoverinfo, {
flags: ['lon', 'lat', 'location', 'text', 'name']
}),
hovertemplate: hovertemplateAttrs()
}, 'calc', 'nested');
/***/ }),
/***/ 5212:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var isNumeric = __webpack_require__(8248);
var BADNUM = (__webpack_require__(9032).BADNUM);
var calcMarkerColorscale = __webpack_require__(136);
var arraysToCalcdata = __webpack_require__(148);
var calcSelection = __webpack_require__(4500);
var isArrayOrTypedArray = (__webpack_require__(3400).isArrayOrTypedArray);
var _ = (__webpack_require__(3400)._);
function isNonBlankString(v) {
return v && typeof v === 'string';
}
module.exports = function calc(gd, trace) {
var hasLocationData = isArrayOrTypedArray(trace.locations);
var len = hasLocationData ? trace.locations.length : trace._length;
var calcTrace = new Array(len);
var isValidLoc;
if (trace.geojson) {
isValidLoc = function (v) {
return isNonBlankString(v) || isNumeric(v);
};
} else {
isValidLoc = isNonBlankString;
}
for (var i = 0; i < len; i++) {
var calcPt = calcTrace[i] = {};
if (hasLocationData) {
var loc = trace.locations[i];
calcPt.loc = isValidLoc(loc) ? loc : null;
} else {
var lon = trace.lon[i];
var lat = trace.lat[i];
if (isNumeric(lon) && isNumeric(lat)) calcPt.lonlat = [+lon, +lat];else calcPt.lonlat = [BADNUM, BADNUM];
}
}
arraysToCalcdata(calcTrace, trace);
calcMarkerColorscale(gd, trace);
calcSelection(calcTrace, trace);
if (len) {
calcTrace[0].t = {
labels: {
lat: _(gd, 'lat:') + ' ',
lon: _(gd, 'lon:') + ' '
}
};
}
return calcTrace;
};
/***/ }),
/***/ 1512:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var hovertemplateAttrs = (__webpack_require__(1776)/* .hovertemplateAttrs */ .Ks);
var texttemplateAttrs = (__webpack_require__(1776)/* .texttemplateAttrs */ .Gw);
var makeFillcolorAttr = __webpack_require__(3544);
var scatterGeoAttrs = __webpack_require__(6096);
var scatterAttrs = __webpack_require__(2904);
var mapboxAttrs = __webpack_require__(5232);
var baseAttrs = __webpack_require__(5464);
var colorScaleAttrs = __webpack_require__(9084);
var extendFlat = (__webpack_require__(2880).extendFlat);
var overrideAll = (__webpack_require__(7824).overrideAll);
var mapboxLayoutAtributes = __webpack_require__(5232);
var lineAttrs = scatterGeoAttrs.line;
var markerAttrs = scatterGeoAttrs.marker;
module.exports = overrideAll({
lon: scatterGeoAttrs.lon,
lat: scatterGeoAttrs.lat,
cluster: {
enabled: {
valType: 'boolean'
},
maxzoom: extendFlat({}, mapboxLayoutAtributes.layers.maxzoom, {}),
step: {
valType: 'number',
arrayOk: true,
dflt: -1,
min: -1
},
size: {
valType: 'number',
arrayOk: true,
dflt: 20,
min: 0
},
color: {
valType: 'color',
arrayOk: true
},
opacity: extendFlat({}, markerAttrs.opacity, {
dflt: 1
})
},
// locations
// locationmode
mode: extendFlat({}, scatterAttrs.mode, {
dflt: 'markers'
}),
text: extendFlat({}, scatterAttrs.text, {}),
texttemplate: texttemplateAttrs({
editType: 'plot'
}, {
keys: ['lat', 'lon', 'text']
}),
hovertext: extendFlat({}, scatterAttrs.hovertext, {}),
line: {
color: lineAttrs.color,
width: lineAttrs.width
// TODO
// dash: dash
},
connectgaps: scatterAttrs.connectgaps,
marker: extendFlat({
symbol: {
valType: 'string',
dflt: 'circle',
arrayOk: true
},
angle: {
valType: 'number',
dflt: 'auto',
arrayOk: true
},
allowoverlap: {
valType: 'boolean',
dflt: false
},
opacity: markerAttrs.opacity,
size: markerAttrs.size,
sizeref: markerAttrs.sizeref,
sizemin: markerAttrs.sizemin,
sizemode: markerAttrs.sizemode
}, colorScaleAttrs('marker')
// line
),
fill: scatterGeoAttrs.fill,
fillcolor: makeFillcolorAttr(),
textfont: mapboxAttrs.layers.symbol.textfont,
textposition: mapboxAttrs.layers.symbol.textposition,
below: {
valType: 'string'
},
selected: {
marker: scatterAttrs.selected.marker
},
unselected: {
marker: scatterAttrs.unselected.marker
},
hoverinfo: extendFlat({}, baseAttrs.hoverinfo, {
flags: ['lon', 'lat', 'text', 'name']
}),
hovertemplate: hovertemplateAttrs()
}, 'calc', 'nested');
/***/ }),
/***/ 9392:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var isNumeric = __webpack_require__(8248);
var Lib = __webpack_require__(3400);
var BADNUM = (__webpack_require__(9032).BADNUM);
var geoJsonUtils = __webpack_require__(4808);
var Colorscale = __webpack_require__(8932);
var Drawing = __webpack_require__(3616);
var makeBubbleSizeFn = __webpack_require__(7152);
var subTypes = __webpack_require__(3028);
var convertTextOpts = __webpack_require__(4270);
var appendArrayPointValue = (__webpack_require__(624).appendArrayPointValue);
var NEWLINES = (__webpack_require__(2736).NEWLINES);
var BR_TAG_ALL = (__webpack_require__(2736).BR_TAG_ALL);
module.exports = function convert(gd, calcTrace) {
var trace = calcTrace[0].trace;
var isVisible = trace.visible === true && trace._length !== 0;
var hasFill = trace.fill !== 'none';
var hasLines = subTypes.hasLines(trace);
var hasMarkers = subTypes.hasMarkers(trace);
var hasText = subTypes.hasText(trace);
var hasCircles = hasMarkers && trace.marker.symbol === 'circle';
var hasSymbols = hasMarkers && trace.marker.symbol !== 'circle';
var hasCluster = trace.cluster && trace.cluster.enabled;
var fill = initContainer('fill');
var line = initContainer('line');
var circle = initContainer('circle');
var symbol = initContainer('symbol');
var opts = {
fill: fill,
line: line,
circle: circle,
symbol: symbol
};
// early return if not visible or placeholder
if (!isVisible) return opts;
// fill layer and line layer use the same coords
var lineCoords;
if (hasFill || hasLines) {
lineCoords = geoJsonUtils.calcTraceToLineCoords(calcTrace);
}
if (hasFill) {
fill.geojson = geoJsonUtils.makePolygon(lineCoords);
fill.layout.visibility = 'visible';
Lib.extendFlat(fill.paint, {
'fill-color': trace.fillcolor
});
}
if (hasLines) {
line.geojson = geoJsonUtils.makeLine(lineCoords);
line.layout.visibility = 'visible';
Lib.extendFlat(line.paint, {
'line-width': trace.line.width,
'line-color': trace.line.color,
'line-opacity': trace.opacity
});
// TODO convert line.dash into line-dasharray
}
if (hasCircles) {
var circleOpts = makeCircleOpts(calcTrace);
circle.geojson = circleOpts.geojson;
circle.layout.visibility = 'visible';
if (hasCluster) {
circle.filter = ['!', ['has', 'point_count']];
opts.cluster = {
type: 'circle',
filter: ['has', 'point_count'],
layout: {
visibility: 'visible'
},
paint: {
'circle-color': arrayifyAttribute(trace.cluster.color, trace.cluster.step),
'circle-radius': arrayifyAttribute(trace.cluster.size, trace.cluster.step),
'circle-opacity': arrayifyAttribute(trace.cluster.opacity, trace.cluster.step)
}
};
opts.clusterCount = {
type: 'symbol',
filter: ['has', 'point_count'],
paint: {},
layout: {
'text-field': '{point_count_abbreviated}',
'text-font': ['Open Sans Regular', 'Arial Unicode MS Regular'],
'text-size': 12
}
};
}
Lib.extendFlat(circle.paint, {
'circle-color': circleOpts.mcc,
'circle-radius': circleOpts.mrc,
'circle-opacity': circleOpts.mo
});
}
if (hasCircles && hasCluster) {
circle.filter = ['!', ['has', 'point_count']];
}
if (hasSymbols || hasText) {
symbol.geojson = makeSymbolGeoJSON(calcTrace, gd);
Lib.extendFlat(symbol.layout, {
visibility: 'visible',
'icon-image': '{symbol}-15',
'text-field': '{text}'
});
if (hasSymbols) {
Lib.extendFlat(symbol.layout, {
'icon-size': trace.marker.size / 10
});
if ('angle' in trace.marker && trace.marker.angle !== 'auto') {
Lib.extendFlat(symbol.layout, {
// unfortunately cant use {angle} do to this issue:
// https://github.com/mapbox/mapbox-gl-js/issues/873
'icon-rotate': {
type: 'identity',
property: 'angle'
},
'icon-rotation-alignment': 'map'
});
}
symbol.layout['icon-allow-overlap'] = trace.marker.allowoverlap;
Lib.extendFlat(symbol.paint, {
'icon-opacity': trace.opacity * trace.marker.opacity,
// TODO does not work ??
'icon-color': trace.marker.color
});
}
if (hasText) {
var iconSize = (trace.marker || {}).size;
var textOpts = convertTextOpts(trace.textposition, iconSize);
// all data-driven below !!
Lib.extendFlat(symbol.layout, {
'text-size': trace.textfont.size,
'text-anchor': textOpts.anchor,
'text-offset': textOpts.offset,
'text-font': trace.textfont.family.split(', ')
});
Lib.extendFlat(symbol.paint, {
'text-color': trace.textfont.color,
'text-opacity': trace.opacity
});
}
}
return opts;
};
function initContainer(type) {
return {
type: type,
geojson: geoJsonUtils.makeBlank(),
layout: {
visibility: 'none'
},
filter: null,
paint: {}
};
}
function makeCircleOpts(calcTrace) {
var trace = calcTrace[0].trace;
var marker = trace.marker;
var selectedpoints = trace.selectedpoints;
var arrayColor = Lib.isArrayOrTypedArray(marker.color);
var arraySize = Lib.isArrayOrTypedArray(marker.size);
var arrayOpacity = Lib.isArrayOrTypedArray(marker.opacity);
var i;
function addTraceOpacity(o) {
return trace.opacity * o;
}
function size2radius(s) {
return s / 2;
}
var colorFn;
if (arrayColor) {
if (Colorscale.hasColorscale(trace, 'marker')) {
colorFn = Colorscale.makeColorScaleFuncFromTrace(marker);
} else {
colorFn = Lib.identity;
}
}
var sizeFn;
if (arraySize) {
sizeFn = makeBubbleSizeFn(trace);
}
var opacityFn;
if (arrayOpacity) {
opacityFn = function (mo) {
var mo2 = isNumeric(mo) ? +Lib.constrain(mo, 0, 1) : 0;
return addTraceOpacity(mo2);
};
}
var features = [];
for (i = 0; i < calcTrace.length; i++) {
var calcPt = calcTrace[i];
var lonlat = calcPt.lonlat;
if (isBADNUM(lonlat)) continue;
var props = {};
if (colorFn) props.mcc = calcPt.mcc = colorFn(calcPt.mc);
if (sizeFn) props.mrc = calcPt.mrc = sizeFn(calcPt.ms);
if (opacityFn) props.mo = opacityFn(calcPt.mo);
if (selectedpoints) props.selected = calcPt.selected || 0;
features.push({
type: 'Feature',
id: i + 1,
geometry: {
type: 'Point',
coordinates: lonlat
},
properties: props
});
}
var fns;
if (selectedpoints) {
fns = Drawing.makeSelectedPointStyleFns(trace);
for (i = 0; i < features.length; i++) {
var d = features[i].properties;
if (fns.selectedOpacityFn) {
d.mo = addTraceOpacity(fns.selectedOpacityFn(d));
}
if (fns.selectedColorFn) {
d.mcc = fns.selectedColorFn(d);
}
if (fns.selectedSizeFn) {
d.mrc = fns.selectedSizeFn(d);
}
}
}
return {
geojson: {
type: 'FeatureCollection',
features: features
},
mcc: arrayColor || fns && fns.selectedColorFn ? {
type: 'identity',
property: 'mcc'
} : marker.color,
mrc: arraySize || fns && fns.selectedSizeFn ? {
type: 'identity',
property: 'mrc'
} : size2radius(marker.size),
mo: arrayOpacity || fns && fns.selectedOpacityFn ? {
type: 'identity',
property: 'mo'
} : addTraceOpacity(marker.opacity)
};
}
function makeSymbolGeoJSON(calcTrace, gd) {
var fullLayout = gd._fullLayout;
var trace = calcTrace[0].trace;
var marker = trace.marker || {};
var symbol = marker.symbol;
var angle = marker.angle;
var fillSymbol = symbol !== 'circle' ? getFillFunc(symbol) : blankFillFunc;
var fillAngle = angle !== 'auto' ? getFillFunc(angle, true) : blankFillFunc;
var fillText = subTypes.hasText(trace) ? getFillFunc(trace.text) : blankFillFunc;
var features = [];
for (var i = 0; i < calcTrace.length; i++) {
var calcPt = calcTrace[i];
if (isBADNUM(calcPt.lonlat)) continue;
var texttemplate = trace.texttemplate;
var text;
if (texttemplate) {
var tt = Array.isArray(texttemplate) ? texttemplate[i] || '' : texttemplate;
var labels = trace._module.formatLabels(calcPt, trace, fullLayout);
var pointValues = {};
appendArrayPointValue(pointValues, trace, calcPt.i);
var meta = trace._meta || {};
text = Lib.texttemplateString(tt, labels, fullLayout._d3locale, pointValues, calcPt, meta);
} else {
text = fillText(i);
}
if (text) {
text = text.replace(NEWLINES, '').replace(BR_TAG_ALL, '\n');
}
features.push({
type: 'Feature',
geometry: {
type: 'Point',
coordinates: calcPt.lonlat
},
properties: {
symbol: fillSymbol(i),
angle: fillAngle(i),
text: text
}
});
}
return {
type: 'FeatureCollection',
features: features
};
}
function getFillFunc(attr, numeric) {
if (Lib.isArrayOrTypedArray(attr)) {
if (numeric) {
return function (i) {
return isNumeric(attr[i]) ? +attr[i] : 0;
};
}
return function (i) {
return attr[i];
};
} else if (attr) {
return function () {
return attr;
};
} else {
return blankFillFunc;
}
}
function blankFillFunc() {
return '';
}
// only need to check lon (OR lat)
function isBADNUM(lonlat) {
return lonlat[0] === BADNUM;
}
function arrayifyAttribute(values, step) {
var newAttribute;
if (Lib.isArrayOrTypedArray(values) && Lib.isArrayOrTypedArray(step)) {
newAttribute = ['step', ['get', 'point_count'], values[0]];
for (var idx = 1; idx < values.length; idx++) {
newAttribute.push(step[idx - 1], values[idx]);
}
} else {
newAttribute = values;
}
return newAttribute;
}
/***/ }),
/***/ 5752:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Lib = __webpack_require__(3400);
var subTypes = __webpack_require__(3028);
var handleMarkerDefaults = __webpack_require__(4428);
var handleLineDefaults = __webpack_require__(6828);
var handleTextDefaults = __webpack_require__(124);
var handleFillColorDefaults = __webpack_require__(840);
var attributes = __webpack_require__(1512);
// Must use one of the following fonts as the family, else default to 'Open Sans Regular'
// See https://github.com/openmaptiles/fonts/blob/gh-pages/fontstacks.json
var supportedFonts = ['Metropolis Black Italic', 'Metropolis Black', 'Metropolis Bold Italic', 'Metropolis Bold', 'Metropolis Extra Bold Italic', 'Metropolis Extra Bold', 'Metropolis Extra Light Italic', 'Metropolis Extra Light', 'Metropolis Light Italic', 'Metropolis Light', 'Metropolis Medium Italic', 'Metropolis Medium', 'Metropolis Regular Italic', 'Metropolis Regular', 'Metropolis Semi Bold Italic', 'Metropolis Semi Bold', 'Metropolis Thin Italic', 'Metropolis Thin', 'Open Sans Bold Italic', 'Open Sans Bold', 'Open Sans Extra Bold Italic', 'Open Sans Extra Bold', 'Open Sans Italic', 'Open Sans Light Italic', 'Open Sans Light', 'Open Sans Regular', 'Open Sans Semibold Italic', 'Open Sans Semibold', 'Klokantech Noto Sans Bold', 'Klokantech Noto Sans CJK Bold', 'Klokantech Noto Sans CJK Regular', 'Klokantech Noto Sans Italic', 'Klokantech Noto Sans Regular'];
module.exports = function supplyDefaults(traceIn, traceOut, defaultColor, layout) {
function coerce(attr, dflt) {
return Lib.coerce(traceIn, traceOut, attributes, attr, dflt);
}
function coerce2(attr, dflt) {
return Lib.coerce2(traceIn, traceOut, attributes, attr, dflt);
}
var len = handleLonLatDefaults(traceIn, traceOut, coerce);
if (!len) {
traceOut.visible = false;
return;
}
coerce('text');
coerce('texttemplate');
coerce('hovertext');
coerce('hovertemplate');
coerce('mode');
coerce('below');
if (subTypes.hasMarkers(traceOut)) {
handleMarkerDefaults(traceIn, traceOut, defaultColor, layout, coerce, {
noLine: true,
noAngle: true
});
coerce('marker.allowoverlap');
coerce('marker.angle');
// array marker.size and marker.color are only supported with circles
var marker = traceOut.marker;
if (marker.symbol !== 'circle') {
if (Lib.isArrayOrTypedArray(marker.size)) marker.size = marker.size[0];
if (Lib.isArrayOrTypedArray(marker.color)) marker.color = marker.color[0];
}
}
if (subTypes.hasLines(traceOut)) {
handleLineDefaults(traceIn, traceOut, defaultColor, layout, coerce, {
noDash: true
});
coerce('connectgaps');
}
var clusterMaxzoom = coerce2('cluster.maxzoom');
var clusterStep = coerce2('cluster.step');
var clusterColor = coerce2('cluster.color', traceOut.marker && traceOut.marker.color || defaultColor);
var clusterSize = coerce2('cluster.size');
var clusterOpacity = coerce2('cluster.opacity');
var clusterEnabledDflt = clusterMaxzoom !== false || clusterStep !== false || clusterColor !== false || clusterSize !== false || clusterOpacity !== false;
coerce('cluster.enabled', clusterEnabledDflt);
if (subTypes.hasText(traceOut)) {
handleTextDefaults(traceIn, traceOut, layout, coerce, {
noSelect: true,
font: {
family: supportedFonts.indexOf(layout.font.family) !== -1 ? layout.font.family : 'Open Sans Regular',
size: layout.font.size,
color: layout.font.color
}
});
}
coerce('fill');
if (traceOut.fill !== 'none') {
handleFillColorDefaults(traceIn, traceOut, defaultColor, coerce);
}
Lib.coerceSelectionMarkerOpacity(traceOut, coerce);
};
function handleLonLatDefaults(traceIn, traceOut, coerce) {
var lon = coerce('lon') || [];
var lat = coerce('lat') || [];
var len = Math.min(lon.length, lat.length);
traceOut._length = len;
return len;
}
/***/ }),
/***/ 7920:
/***/ (function(module) {
"use strict";
module.exports = function eventData(out, pt) {
out.lon = pt.lon;
out.lat = pt.lat;
return out;
};
/***/ }),
/***/ 1960:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Axes = __webpack_require__(4460);
module.exports = function formatLabels(cdi, trace, fullLayout) {
var labels = {};
var subplot = fullLayout[trace.subplot]._subplot;
var ax = subplot.mockAxis;
var lonlat = cdi.lonlat;
labels.lonLabel = Axes.tickText(ax, ax.c2l(lonlat[0]), true).text;
labels.latLabel = Axes.tickText(ax, ax.c2l(lonlat[1]), true).text;
return labels;
};
/***/ }),
/***/ 3312:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Fx = __webpack_require__(3024);
var Lib = __webpack_require__(3400);
var getTraceColor = __webpack_require__(4928);
var fillText = Lib.fillText;
var BADNUM = (__webpack_require__(9032).BADNUM);
var LAYER_PREFIX = (__webpack_require__(7552).traceLayerPrefix);
function hoverPoints(pointData, xval, yval) {
var cd = pointData.cd;
var trace = cd[0].trace;
var xa = pointData.xa;
var ya = pointData.ya;
var subplot = pointData.subplot;
var clusteredPointsIds = [];
var layer = LAYER_PREFIX + trace.uid + '-circle';
var hasCluster = trace.cluster && trace.cluster.enabled;
if (hasCluster) {
var elems = subplot.map.queryRenderedFeatures(null, {
layers: [layer]
});
clusteredPointsIds = elems.map(function (elem) {
return elem.id;
});
}
// compute winding number about [-180, 180] globe
var winding = xval >= 0 ? Math.floor((xval + 180) / 360) : Math.ceil((xval - 180) / 360);
// shift longitude to [-180, 180] to determine closest point
var lonShift = winding * 360;
var xval2 = xval - lonShift;
function distFn(d) {
var lonlat = d.lonlat;
if (lonlat[0] === BADNUM) return Infinity;
if (hasCluster && clusteredPointsIds.indexOf(d.i + 1) === -1) return Infinity;
var lon = Lib.modHalf(lonlat[0], 360);
var lat = lonlat[1];
var pt = subplot.project([lon, lat]);
var dx = pt.x - xa.c2p([xval2, lat]);
var dy = pt.y - ya.c2p([lon, yval]);
var rad = Math.max(3, d.mrc || 0);
return Math.max(Math.sqrt(dx * dx + dy * dy) - rad, 1 - 3 / rad);
}
Fx.getClosest(cd, distFn, pointData);
// skip the rest (for this trace) if we didn't find a close point
if (pointData.index === false) return;
var di = cd[pointData.index];
var lonlat = di.lonlat;
var lonlatShifted = [Lib.modHalf(lonlat[0], 360) + lonShift, lonlat[1]];
// shift labels back to original winded globe
var xc = xa.c2p(lonlatShifted);
var yc = ya.c2p(lonlatShifted);
var rad = di.mrc || 1;
pointData.x0 = xc - rad;
pointData.x1 = xc + rad;
pointData.y0 = yc - rad;
pointData.y1 = yc + rad;
var fullLayout = {};
fullLayout[trace.subplot] = {
_subplot: subplot
};
var labels = trace._module.formatLabels(di, trace, fullLayout);
pointData.lonLabel = labels.lonLabel;
pointData.latLabel = labels.latLabel;
pointData.color = getTraceColor(trace, di);
pointData.extraText = getExtraText(trace, di, cd[0].t.labels);
pointData.hovertemplate = trace.hovertemplate;
return [pointData];
}
function getExtraText(trace, di, labels) {
if (trace.hovertemplate) return;
var hoverinfo = di.hi || trace.hoverinfo;
var parts = hoverinfo.split('+');
var isAll = parts.indexOf('all') !== -1;
var hasLon = parts.indexOf('lon') !== -1;
var hasLat = parts.indexOf('lat') !== -1;
var lonlat = di.lonlat;
var text = [];
// TODO should we use a mock axis to format hover?
// If so, we'll need to make precision be zoom-level dependent
function format(v) {
return v + '\u00B0';
}
if (isAll || hasLon && hasLat) {
text.push('(' + format(lonlat[1]) + ', ' + format(lonlat[0]) + ')');
} else if (hasLon) {
text.push(labels.lon + format(lonlat[0]));
} else if (hasLat) {
text.push(labels.lat + format(lonlat[1]));
}
if (isAll || parts.indexOf('text') !== -1) {
fillText(di, trace, text);
}
return text.join('
');
}
module.exports = {
hoverPoints: hoverPoints,
getExtraText: getExtraText
};
/***/ }),
/***/ 1572:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
module.exports = {
attributes: __webpack_require__(1512),
supplyDefaults: __webpack_require__(5752),
colorbar: __webpack_require__(5528),
formatLabels: __webpack_require__(1960),
calc: __webpack_require__(5212),
plot: __webpack_require__(9660),
hoverPoints: (__webpack_require__(3312).hoverPoints),
eventData: __webpack_require__(7920),
selectPoints: __webpack_require__(404),
styleOnSelect: function (_, cd) {
if (cd) {
var trace = cd[0].trace;
trace._glTrace.update(cd);
}
},
moduleType: 'trace',
name: 'scattermapbox',
basePlotModule: __webpack_require__(1308),
categories: ['mapbox', 'gl', 'symbols', 'showLegend', 'scatter-like'],
meta: {}
};
/***/ }),
/***/ 9660:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Lib = __webpack_require__(3400);
var convert = __webpack_require__(9392);
var LAYER_PREFIX = (__webpack_require__(7552).traceLayerPrefix);
var ORDER = {
cluster: ['cluster', 'clusterCount', 'circle'],
nonCluster: ['fill', 'line', 'circle', 'symbol']
};
function ScatterMapbox(subplot, uid, clusterEnabled, isHidden) {
this.type = 'scattermapbox';
this.subplot = subplot;
this.uid = uid;
this.clusterEnabled = clusterEnabled;
this.isHidden = isHidden;
this.sourceIds = {
fill: 'source-' + uid + '-fill',
line: 'source-' + uid + '-line',
circle: 'source-' + uid + '-circle',
symbol: 'source-' + uid + '-symbol',
cluster: 'source-' + uid + '-circle',
clusterCount: 'source-' + uid + '-circle'
};
this.layerIds = {
fill: LAYER_PREFIX + uid + '-fill',
line: LAYER_PREFIX + uid + '-line',
circle: LAYER_PREFIX + uid + '-circle',
symbol: LAYER_PREFIX + uid + '-symbol',
cluster: LAYER_PREFIX + uid + '-cluster',
clusterCount: LAYER_PREFIX + uid + '-cluster-count'
};
// We could merge the 'fill' source with the 'line' source and
// the 'circle' source with the 'symbol' source if ever having
// for up-to 4 sources per 'scattermapbox' traces becomes a problem.
// previous 'below' value,
// need this to update it properly
this.below = null;
}
var proto = ScatterMapbox.prototype;
proto.addSource = function (k, opts, cluster) {
var sourceOpts = {
type: 'geojson',
data: opts.geojson
};
if (cluster && cluster.enabled) {
Lib.extendFlat(sourceOpts, {
cluster: true,
clusterMaxZoom: cluster.maxzoom
});
}
var isSourceExists = this.subplot.map.getSource(this.sourceIds[k]);
if (isSourceExists) {
isSourceExists.setData(opts.geojson);
} else {
this.subplot.map.addSource(this.sourceIds[k], sourceOpts);
}
};
proto.setSourceData = function (k, opts) {
this.subplot.map.getSource(this.sourceIds[k]).setData(opts.geojson);
};
proto.addLayer = function (k, opts, below) {
var source = {
type: opts.type,
id: this.layerIds[k],
source: this.sourceIds[k],
layout: opts.layout,
paint: opts.paint
};
if (opts.filter) {
source.filter = opts.filter;
}
var currentLayerId = this.layerIds[k];
var layerExist;
var layers = this.subplot.getMapLayers();
for (var i = 0; i < layers.length; i++) {
if (layers[i].id === currentLayerId) {
layerExist = true;
break;
}
}
if (layerExist) {
this.subplot.setOptions(currentLayerId, 'setLayoutProperty', source.layout);
if (source.layout.visibility === 'visible') {
this.subplot.setOptions(currentLayerId, 'setPaintProperty', source.paint);
}
} else {
this.subplot.addLayer(source, below);
}
};
proto.update = function update(calcTrace) {
var trace = calcTrace[0].trace;
var subplot = this.subplot;
var map = subplot.map;
var optsAll = convert(subplot.gd, calcTrace);
var below = subplot.belowLookup['trace-' + this.uid];
var hasCluster = !!(trace.cluster && trace.cluster.enabled);
var hadCluster = !!this.clusterEnabled;
var lThis = this;
function addCluster(noSource) {
if (!noSource) lThis.addSource('circle', optsAll.circle, trace.cluster);
var order = ORDER.cluster;
for (var i = 0; i < order.length; i++) {
var k = order[i];
var opts = optsAll[k];
lThis.addLayer(k, opts, below);
}
}
function removeCluster(noSource) {
var order = ORDER.cluster;
for (var i = order.length - 1; i >= 0; i--) {
var k = order[i];
map.removeLayer(lThis.layerIds[k]);
}
if (!noSource) map.removeSource(lThis.sourceIds.circle);
}
function addNonCluster(noSource) {
var order = ORDER.nonCluster;
for (var i = 0; i < order.length; i++) {
var k = order[i];
var opts = optsAll[k];
if (!noSource) lThis.addSource(k, opts);
lThis.addLayer(k, opts, below);
}
}
function removeNonCluster(noSource) {
var order = ORDER.nonCluster;
for (var i = order.length - 1; i >= 0; i--) {
var k = order[i];
map.removeLayer(lThis.layerIds[k]);
if (!noSource) map.removeSource(lThis.sourceIds[k]);
}
}
function remove(noSource) {
if (hadCluster) removeCluster(noSource);else removeNonCluster(noSource);
}
function add(noSource) {
if (hasCluster) addCluster(noSource);else addNonCluster(noSource);
}
function repaint() {
var order = hasCluster ? ORDER.cluster : ORDER.nonCluster;
for (var i = 0; i < order.length; i++) {
var k = order[i];
var opts = optsAll[k];
if (!opts) continue;
subplot.setOptions(lThis.layerIds[k], 'setLayoutProperty', opts.layout);
if (opts.layout.visibility === 'visible') {
if (k !== 'cluster') {
lThis.setSourceData(k, opts);
}
subplot.setOptions(lThis.layerIds[k], 'setPaintProperty', opts.paint);
}
}
}
var wasHidden = this.isHidden;
var isHidden = trace.visible !== true;
if (isHidden) {
if (!wasHidden) remove();
} else if (wasHidden) {
if (!isHidden) add();
} else if (hadCluster !== hasCluster) {
remove();
add();
} else if (this.below !== below) {
remove(true);
add(true);
repaint();
} else {
repaint();
}
this.clusterEnabled = hasCluster;
this.isHidden = isHidden;
this.below = below;
// link ref for quick update during selections
calcTrace[0].trace._glTrace = this;
};
proto.dispose = function dispose() {
var map = this.subplot.map;
var order = this.clusterEnabled ? ORDER.cluster : ORDER.nonCluster;
for (var i = order.length - 1; i >= 0; i--) {
var k = order[i];
map.removeLayer(this.layerIds[k]);
map.removeSource(this.sourceIds[k]);
}
};
module.exports = function createScatterMapbox(subplot, calcTrace) {
var trace = calcTrace[0].trace;
var hasCluster = trace.cluster && trace.cluster.enabled;
var isHidden = trace.visible !== true;
var scatterMapbox = new ScatterMapbox(subplot, trace.uid, hasCluster, isHidden);
var optsAll = convert(subplot.gd, calcTrace);
var below = scatterMapbox.below = subplot.belowLookup['trace-' + trace.uid];
var i, k, opts;
if (hasCluster) {
scatterMapbox.addSource('circle', optsAll.circle, trace.cluster);
for (i = 0; i < ORDER.cluster.length; i++) {
k = ORDER.cluster[i];
opts = optsAll[k];
scatterMapbox.addLayer(k, opts, below);
}
} else {
for (i = 0; i < ORDER.nonCluster.length; i++) {
k = ORDER.nonCluster[i];
opts = optsAll[k];
scatterMapbox.addSource(k, opts, trace.cluster);
scatterMapbox.addLayer(k, opts, below);
}
}
// link ref for quick update during selections
calcTrace[0].trace._glTrace = scatterMapbox;
return scatterMapbox;
};
/***/ }),
/***/ 404:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var Lib = __webpack_require__(3400);
var subtypes = __webpack_require__(3028);
var BADNUM = (__webpack_require__(9032).BADNUM);
module.exports = function selectPoints(searchInfo, selectionTester) {
var cd = searchInfo.cd;
var xa = searchInfo.xaxis;
var ya = searchInfo.yaxis;
var selection = [];
var trace = cd[0].trace;
var i;
if (!subtypes.hasMarkers(trace)) return [];
if (selectionTester === false) {
for (i = 0; i < cd.length; i++) {
cd[i].selected = 0;
}
} else {
for (i = 0; i < cd.length; i++) {
var di = cd[i];
var lonlat = di.lonlat;
if (lonlat[0] !== BADNUM) {
var lonlat2 = [Lib.modHalf(lonlat[0], 360), lonlat[1]];
var xy = [xa.c2p(lonlat2), ya.c2p(lonlat2)];
if (selectionTester.contains(xy, null, i, searchInfo)) {
selection.push({
pointNumber: i,
lon: lonlat[0],
lat: lonlat[1]
});
di.selected = 1;
} else {
di.selected = 0;
}
}
}
}
return selection;
};
/***/ }),
/***/ 1843:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
var Axes = __webpack_require__(4460);
var Lib = __webpack_require__(3400);
var PlotSchema = __webpack_require__(3060);
var pointsAccessorFunction = (__webpack_require__(468)/* .pointsAccessorFunction */ .W);
var BADNUM = (__webpack_require__(9032).BADNUM);
exports.moduleType = 'transform';
exports.name = 'aggregate';
var attrs = exports.attributes = {
enabled: {
valType: 'boolean',
dflt: true,
editType: 'calc'
},
groups: {
// TODO: groupby should support string or array grouping this way too
// currently groupby only allows a grouping array
valType: 'string',
strict: true,
noBlank: true,
arrayOk: true,
dflt: 'x',
editType: 'calc'
},
aggregations: {
_isLinkedToArray: 'aggregation',
target: {
valType: 'string',
editType: 'calc'
},
func: {
valType: 'enumerated',
values: ['count', 'sum', 'avg', 'median', 'mode', 'rms', 'stddev', 'min', 'max', 'first', 'last', 'change', 'range'],
dflt: 'first',
editType: 'calc'
},
funcmode: {
valType: 'enumerated',
values: ['sample', 'population'],
dflt: 'sample',
editType: 'calc'
},
enabled: {
valType: 'boolean',
dflt: true,
editType: 'calc'
},
editType: 'calc'
},
editType: 'calc'
};
var aggAttrs = attrs.aggregations;
/**
* Supply transform attributes defaults
*
* @param {object} transformIn
* object linked to trace.transforms[i] with 'func' set to exports.name
* @param {object} traceOut
* the _fullData trace this transform applies to
* @param {object} layout
* the plot's (not-so-full) layout
* @param {object} traceIn
* the input data trace this transform applies to
*
* @return {object} transformOut
* copy of transformIn that contains attribute defaults
*/
exports.supplyDefaults = function (transformIn, traceOut) {
var transformOut = {};
var i;
function coerce(attr, dflt) {
return Lib.coerce(transformIn, transformOut, attrs, attr, dflt);
}
var enabled = coerce('enabled');
if (!enabled) return transformOut;
/*
* Normally _arrayAttrs is calculated during doCalc, but that comes later.
* Anyway this can change due to *count* aggregations (see below) so it's not
* necessarily the same set.
*
* For performance we turn it into an object of truthy values
* we'll use 1 for arrays we haven't aggregated yet, 0 for finished arrays,
* as distinct from undefined which means this array isn't present in the input
* missing arrays can still be aggregate outputs for *count* aggregations.
*/
var arrayAttrArray = PlotSchema.findArrayAttributes(traceOut);
var arrayAttrs = {};
for (i = 0; i < arrayAttrArray.length; i++) arrayAttrs[arrayAttrArray[i]] = 1;
var groups = coerce('groups');
if (!Array.isArray(groups)) {
if (!arrayAttrs[groups]) {
transformOut.enabled = false;
return transformOut;
}
arrayAttrs[groups] = 0;
}
var aggregationsIn = transformIn.aggregations || [];
var aggregationsOut = transformOut.aggregations = new Array(aggregationsIn.length);
var aggregationOut;
function coercei(attr, dflt) {
return Lib.coerce(aggregationsIn[i], aggregationOut, aggAttrs, attr, dflt);
}
for (i = 0; i < aggregationsIn.length; i++) {
aggregationOut = {
_index: i
};
var target = coercei('target');
var func = coercei('func');
var enabledi = coercei('enabled');
// add this aggregation to the output only if it's the first instance
// of a valid target attribute - or an unused target attribute with "count"
if (enabledi && target && (arrayAttrs[target] || func === 'count' && arrayAttrs[target] === undefined)) {
if (func === 'stddev') coercei('funcmode');
arrayAttrs[target] = 0;
aggregationsOut[i] = aggregationOut;
} else aggregationsOut[i] = {
enabled: false,
_index: i
};
}
// any array attributes we haven't yet covered, fill them with the default aggregation
for (i = 0; i < arrayAttrArray.length; i++) {
if (arrayAttrs[arrayAttrArray[i]]) {
aggregationsOut.push({
target: arrayAttrArray[i],
func: aggAttrs.func.dflt,
enabled: true,
_index: -1
});
}
}
return transformOut;
};
exports.calcTransform = function (gd, trace, opts) {
if (!opts.enabled) return;
var groups = opts.groups;
var groupArray = Lib.getTargetArray(trace, {
target: groups
});
if (!groupArray) return;
var i, vi, groupIndex, newGrouping;
var groupIndices = {};
var indexToPoints = {};
var groupings = [];
var originalPointsAccessor = pointsAccessorFunction(trace.transforms, opts);
var len = groupArray.length;
if (trace._length) len = Math.min(len, trace._length);
for (i = 0; i < len; i++) {
vi = groupArray[i];
groupIndex = groupIndices[vi];
if (groupIndex === undefined) {
groupIndices[vi] = groupings.length;
newGrouping = [i];
groupings.push(newGrouping);
indexToPoints[groupIndices[vi]] = originalPointsAccessor(i);
} else {
groupings[groupIndex].push(i);
indexToPoints[groupIndices[vi]] = (indexToPoints[groupIndices[vi]] || []).concat(originalPointsAccessor(i));
}
}
opts._indexToPoints = indexToPoints;
var aggregations = opts.aggregations;
for (i = 0; i < aggregations.length; i++) {
aggregateOneArray(gd, trace, groupings, aggregations[i]);
}
if (typeof groups === 'string') {
aggregateOneArray(gd, trace, groupings, {
target: groups,
func: 'first',
enabled: true
});
}
trace._length = groupings.length;
};
function aggregateOneArray(gd, trace, groupings, aggregation) {
if (!aggregation.enabled) return;
var attr = aggregation.target;
var targetNP = Lib.nestedProperty(trace, attr);
var arrayIn = targetNP.get();
var conversions = Axes.getDataConversions(gd, trace, attr, arrayIn);
var func = getAggregateFunction(aggregation, conversions);
var arrayOut = new Array(groupings.length);
for (var i = 0; i < groupings.length; i++) {
arrayOut[i] = func(arrayIn, groupings[i]);
}
targetNP.set(arrayOut);
if (aggregation.func === 'count') {
// count does not depend on an input array, so it's likely not part of _arrayAttrs yet
// but after this transform it most definitely *is* an array attribute.
Lib.pushUnique(trace._arrayAttrs, attr);
}
}
function getAggregateFunction(opts, conversions) {
var func = opts.func;
var d2c = conversions.d2c;
var c2d = conversions.c2d;
switch (func) {
// count, first, and last don't depend on anything about the data
// point back to pure functions for performance
case 'count':
return count;
case 'first':
return first;
case 'last':
return last;
case 'sum':
// This will produce output in all cases even though it's nonsensical
// for date or category data.
return function (array, indices) {
var total = 0;
for (var i = 0; i < indices.length; i++) {
var vi = d2c(array[indices[i]]);
if (vi !== BADNUM) total += vi;
}
return c2d(total);
};
case 'avg':
// Generally meaningless for category data but it still does something.
return function (array, indices) {
var total = 0;
var cnt = 0;
for (var i = 0; i < indices.length; i++) {
var vi = d2c(array[indices[i]]);
if (vi !== BADNUM) {
total += vi;
cnt++;
}
}
return cnt ? c2d(total / cnt) : BADNUM;
};
case 'min':
return function (array, indices) {
var out = Infinity;
for (var i = 0; i < indices.length; i++) {
var vi = d2c(array[indices[i]]);
if (vi !== BADNUM) out = Math.min(out, vi);
}
return out === Infinity ? BADNUM : c2d(out);
};
case 'max':
return function (array, indices) {
var out = -Infinity;
for (var i = 0; i < indices.length; i++) {
var vi = d2c(array[indices[i]]);
if (vi !== BADNUM) out = Math.max(out, vi);
}
return out === -Infinity ? BADNUM : c2d(out);
};
case 'range':
return function (array, indices) {
var min = Infinity;
var max = -Infinity;
for (var i = 0; i < indices.length; i++) {
var vi = d2c(array[indices[i]]);
if (vi !== BADNUM) {
min = Math.min(min, vi);
max = Math.max(max, vi);
}
}
return max === -Infinity || min === Infinity ? BADNUM : c2d(max - min);
};
case 'change':
return function (array, indices) {
var first = d2c(array[indices[0]]);
var last = d2c(array[indices[indices.length - 1]]);
return first === BADNUM || last === BADNUM ? BADNUM : c2d(last - first);
};
case 'median':
return function (array, indices) {
var sortCalc = [];
for (var i = 0; i < indices.length; i++) {
var vi = d2c(array[indices[i]]);
if (vi !== BADNUM) sortCalc.push(vi);
}
if (!sortCalc.length) return BADNUM;
sortCalc.sort(Lib.sorterAsc);
var mid = (sortCalc.length - 1) / 2;
return c2d((sortCalc[Math.floor(mid)] + sortCalc[Math.ceil(mid)]) / 2);
};
case 'mode':
return function (array, indices) {
var counts = {};
var maxCnt = 0;
var out = BADNUM;
for (var i = 0; i < indices.length; i++) {
var vi = d2c(array[indices[i]]);
if (vi !== BADNUM) {
var counti = counts[vi] = (counts[vi] || 0) + 1;
if (counti > maxCnt) {
maxCnt = counti;
out = vi;
}
}
}
return maxCnt ? c2d(out) : BADNUM;
};
case 'rms':
return function (array, indices) {
var total = 0;
var cnt = 0;
for (var i = 0; i < indices.length; i++) {
var vi = d2c(array[indices[i]]);
if (vi !== BADNUM) {
total += vi * vi;
cnt++;
}
}
return cnt ? c2d(Math.sqrt(total / cnt)) : BADNUM;
};
case 'stddev':
return function (array, indices) {
// balance numerical stability with performance:
// so that we call d2c once per element but don't need to
// store them, reference all to the first element
var total = 0;
var total2 = 0;
var cnt = 1;
var v0 = BADNUM;
var i;
for (i = 0; i < indices.length && v0 === BADNUM; i++) {
v0 = d2c(array[indices[i]]);
}
if (v0 === BADNUM) return BADNUM;
for (; i < indices.length; i++) {
var vi = d2c(array[indices[i]]);
if (vi !== BADNUM) {
var dv = vi - v0;
total += dv;
total2 += dv * dv;
cnt++;
}
}
// This is population std dev, if we want sample std dev
// we would need (...) / (cnt - 1)
// Also note there's no c2d here - that means for dates the result
// is a number of milliseconds, and for categories it's a number
// of category differences, which is not generically meaningful but
// as in other cases we don't forbid it.
var norm = opts.funcmode === 'sample' ? cnt - 1 : cnt;
// this is debatable: should a count of 1 return sample stddev of
// 0 or undefined?
if (!norm) return 0;
return Math.sqrt((total2 - total * total / cnt) / norm);
};
}
}
function count(array, indices) {
return indices.length;
}
function first(array, indices) {
return array[indices[0]];
}
function last(array, indices) {
return array[indices[indices.length - 1]];
}
/***/ }),
/***/ 6744:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
var Lib = __webpack_require__(3400);
var Registry = __webpack_require__(4040);
var Axes = __webpack_require__(4460);
var pointsAccessorFunction = (__webpack_require__(468)/* .pointsAccessorFunction */ .W);
var filterOps = __webpack_require__(9104);
var COMPARISON_OPS = filterOps.COMPARISON_OPS;
var INTERVAL_OPS = filterOps.INTERVAL_OPS;
var SET_OPS = filterOps.SET_OPS;
exports.moduleType = 'transform';
exports.name = 'filter';
exports.attributes = {
enabled: {
valType: 'boolean',
dflt: true,
editType: 'calc'
},
target: {
valType: 'string',
strict: true,
noBlank: true,
arrayOk: true,
dflt: 'x',
editType: 'calc'
},
operation: {
valType: 'enumerated',
values: [].concat(COMPARISON_OPS).concat(INTERVAL_OPS).concat(SET_OPS),
dflt: '=',
editType: 'calc'
},
value: {
valType: 'any',
dflt: 0,
editType: 'calc'
},
preservegaps: {
valType: 'boolean',
dflt: false,
editType: 'calc'
},
editType: 'calc'
};
exports.supplyDefaults = function (transformIn) {
var transformOut = {};
function coerce(attr, dflt) {
return Lib.coerce(transformIn, transformOut, exports.attributes, attr, dflt);
}
var enabled = coerce('enabled');
if (enabled) {
var target = coerce('target');
if (Lib.isArrayOrTypedArray(target) && target.length === 0) {
transformOut.enabled = false;
return transformOut;
}
coerce('preservegaps');
coerce('operation');
coerce('value');
var handleCalendarDefaults = Registry.getComponentMethod('calendars', 'handleDefaults');
handleCalendarDefaults(transformIn, transformOut, 'valuecalendar', null);
handleCalendarDefaults(transformIn, transformOut, 'targetcalendar', null);
}
return transformOut;
};
exports.calcTransform = function (gd, trace, opts) {
if (!opts.enabled) return;
var targetArray = Lib.getTargetArray(trace, opts);
if (!targetArray) return;
var target = opts.target;
var len = targetArray.length;
if (trace._length) len = Math.min(len, trace._length);
var targetCalendar = opts.targetcalendar;
var arrayAttrs = trace._arrayAttrs;
var preservegaps = opts.preservegaps;
// even if you provide targetcalendar, if target is a string and there
// is a calendar attribute matching target it will get used instead.
if (typeof target === 'string') {
var attrTargetCalendar = Lib.nestedProperty(trace, target + 'calendar').get();
if (attrTargetCalendar) targetCalendar = attrTargetCalendar;
}
var d2c = Axes.getDataToCoordFunc(gd, trace, target, targetArray);
var filterFunc = getFilterFunc(opts, d2c, targetCalendar);
var originalArrays = {};
var indexToPoints = {};
var index = 0;
function forAllAttrs(fn, index) {
for (var j = 0; j < arrayAttrs.length; j++) {
var np = Lib.nestedProperty(trace, arrayAttrs[j]);
fn(np, index);
}
}
var initFn;
var fillFn;
if (preservegaps) {
initFn = function (np) {
originalArrays[np.astr] = Lib.extendDeep([], np.get());
np.set(new Array(len));
};
fillFn = function (np, index) {
var val = originalArrays[np.astr][index];
np.get()[index] = val;
};
} else {
initFn = function (np) {
originalArrays[np.astr] = Lib.extendDeep([], np.get());
np.set([]);
};
fillFn = function (np, index) {
var val = originalArrays[np.astr][index];
np.get().push(val);
};
}
// copy all original array attribute values, and clear arrays in trace
forAllAttrs(initFn);
var originalPointsAccessor = pointsAccessorFunction(trace.transforms, opts);
// loop through filter array, fill trace arrays if passed
for (var i = 0; i < len; i++) {
var passed = filterFunc(targetArray[i]);
if (passed) {
forAllAttrs(fillFn, i);
indexToPoints[index++] = originalPointsAccessor(i);
} else if (preservegaps) index++;
}
opts._indexToPoints = indexToPoints;
trace._length = index;
};
function getFilterFunc(opts, d2c, targetCalendar) {
var operation = opts.operation;
var value = opts.value;
var hasArrayValue = Lib.isArrayOrTypedArray(value);
function isOperationIn(array) {
return array.indexOf(operation) !== -1;
}
var d2cValue = function (v) {
return d2c(v, 0, opts.valuecalendar);
};
var d2cTarget = function (v) {
return d2c(v, 0, targetCalendar);
};
var coercedValue;
if (isOperationIn(COMPARISON_OPS)) {
coercedValue = hasArrayValue ? d2cValue(value[0]) : d2cValue(value);
} else if (isOperationIn(INTERVAL_OPS)) {
coercedValue = hasArrayValue ? [d2cValue(value[0]), d2cValue(value[1])] : [d2cValue(value), d2cValue(value)];
} else if (isOperationIn(SET_OPS)) {
coercedValue = hasArrayValue ? value.map(d2cValue) : [d2cValue(value)];
}
switch (operation) {
case '=':
return function (v) {
return d2cTarget(v) === coercedValue;
};
case '!=':
return function (v) {
return d2cTarget(v) !== coercedValue;
};
case '<':
return function (v) {
return d2cTarget(v) < coercedValue;
};
case '<=':
return function (v) {
return d2cTarget(v) <= coercedValue;
};
case '>':
return function (v) {
return d2cTarget(v) > coercedValue;
};
case '>=':
return function (v) {
return d2cTarget(v) >= coercedValue;
};
case '[]':
return function (v) {
var cv = d2cTarget(v);
return cv >= coercedValue[0] && cv <= coercedValue[1];
};
case '()':
return function (v) {
var cv = d2cTarget(v);
return cv > coercedValue[0] && cv < coercedValue[1];
};
case '[)':
return function (v) {
var cv = d2cTarget(v);
return cv >= coercedValue[0] && cv < coercedValue[1];
};
case '(]':
return function (v) {
var cv = d2cTarget(v);
return cv > coercedValue[0] && cv <= coercedValue[1];
};
case '][':
return function (v) {
var cv = d2cTarget(v);
return cv <= coercedValue[0] || cv >= coercedValue[1];
};
case ')(':
return function (v) {
var cv = d2cTarget(v);
return cv < coercedValue[0] || cv > coercedValue[1];
};
case '](':
return function (v) {
var cv = d2cTarget(v);
return cv <= coercedValue[0] || cv > coercedValue[1];
};
case ')[':
return function (v) {
var cv = d2cTarget(v);
return cv < coercedValue[0] || cv >= coercedValue[1];
};
case '{}':
return function (v) {
return coercedValue.indexOf(d2cTarget(v)) !== -1;
};
case '}{':
return function (v) {
return coercedValue.indexOf(d2cTarget(v)) === -1;
};
}
}
/***/ }),
/***/ 2028:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
var Lib = __webpack_require__(3400);
var PlotSchema = __webpack_require__(3060);
var Plots = __webpack_require__(7316);
var pointsAccessorFunction = (__webpack_require__(468)/* .pointsAccessorFunction */ .W);
exports.moduleType = 'transform';
exports.name = 'groupby';
exports.attributes = {
enabled: {
valType: 'boolean',
dflt: true,
editType: 'calc'
},
groups: {
valType: 'data_array',
dflt: [],
editType: 'calc'
},
nameformat: {
valType: 'string',
editType: 'calc'
},
styles: {
_isLinkedToArray: 'style',
target: {
valType: 'string',
editType: 'calc'
},
value: {
valType: 'any',
dflt: {},
editType: 'calc',
_compareAsJSON: true
},
editType: 'calc'
},
editType: 'calc'
};
/**
* Supply transform attributes defaults
*
* @param {object} transformIn
* object linked to trace.transforms[i] with 'type' set to exports.name
* @param {object} traceOut
* the _fullData trace this transform applies to
* @param {object} layout
* the plot's (not-so-full) layout
* @param {object} traceIn
* the input data trace this transform applies to
*
* @return {object} transformOut
* copy of transformIn that contains attribute defaults
*/
exports.supplyDefaults = function (transformIn, traceOut, layout) {
var i;
var transformOut = {};
function coerce(attr, dflt) {
return Lib.coerce(transformIn, transformOut, exports.attributes, attr, dflt);
}
var enabled = coerce('enabled');
if (!enabled) return transformOut;
coerce('groups');
coerce('nameformat', layout._dataLength > 1 ? '%{group} (%{trace})' : '%{group}');
var styleIn = transformIn.styles;
var styleOut = transformOut.styles = [];
if (styleIn) {
for (i = 0; i < styleIn.length; i++) {
var thisStyle = styleOut[i] = {};
Lib.coerce(styleIn[i], styleOut[i], exports.attributes.styles, 'target');
var value = Lib.coerce(styleIn[i], styleOut[i], exports.attributes.styles, 'value');
// so that you can edit value in place and have Plotly.react notice it, or
// rebuild it every time and have Plotly.react NOT think it changed:
// use _compareAsJSON to say we should diff the _JSON_value
if (Lib.isPlainObject(value)) thisStyle.value = Lib.extendDeep({}, value);else if (value) delete thisStyle.value;
}
}
return transformOut;
};
/**
* Apply transform !!!
*
* @param {array} data
* array of transformed traces (is [fullTrace] upon first transform)
*
* @param {object} state
* state object which includes:
* - transform {object} full transform attributes
* - fullTrace {object} full trace object which is being transformed
* - fullData {array} full pre-transform(s) data array
* - layout {object} the plot's (not-so-full) layout
*
* @return {object} newData
* array of transformed traces
*/
exports.transform = function (data, state) {
var newTraces, i, j;
var newData = [];
for (i = 0; i < data.length; i++) {
newTraces = transformOne(data[i], state);
for (j = 0; j < newTraces.length; j++) {
newData.push(newTraces[j]);
}
}
return newData;
};
function transformOne(trace, state) {
var i, j, k, attr, srcArray, groupName, newTrace, transforms, arrayLookup;
var groupNameObj;
var opts = state.transform;
var transformIndex = state.transformIndex;
var groups = trace.transforms[transformIndex].groups;
var originalPointsAccessor = pointsAccessorFunction(trace.transforms, opts);
if (!Lib.isArrayOrTypedArray(groups) || groups.length === 0) {
return [trace];
}
var groupNames = Lib.filterUnique(groups);
var newData = new Array(groupNames.length);
var len = groups.length;
var arrayAttrs = PlotSchema.findArrayAttributes(trace);
var styles = opts.styles || [];
var styleLookup = {};
for (i = 0; i < styles.length; i++) {
styleLookup[styles[i].target] = styles[i].value;
}
if (opts.styles) {
groupNameObj = Lib.keyedContainer(opts, 'styles', 'target', 'value.name');
}
// An index to map group name --> expanded trace index
var indexLookup = {};
var indexCnts = {};
for (i = 0; i < groupNames.length; i++) {
groupName = groupNames[i];
indexLookup[groupName] = i;
indexCnts[groupName] = 0;
// Start with a deep extend that just copies array references.
newTrace = newData[i] = Lib.extendDeepNoArrays({}, trace);
newTrace._group = groupName;
newTrace.transforms[transformIndex]._indexToPoints = {};
var suppliedName = null;
if (groupNameObj) {
suppliedName = groupNameObj.get(groupName);
}
if (suppliedName || suppliedName === '') {
newTrace.name = suppliedName;
} else {
newTrace.name = Lib.templateString(opts.nameformat, {
trace: trace.name,
group: groupName
});
}
// In order for groups to apply correctly to other transform data (e.g.
// a filter transform), we have to break the connection and clone the
// transforms so that each group writes grouped values into a different
// destination. This function does not break the array reference
// connection between the split transforms it creates. That's handled in
// initialize, which creates a new empty array for each arrayAttr.
transforms = newTrace.transforms;
newTrace.transforms = [];
for (j = 0; j < transforms.length; j++) {
newTrace.transforms[j] = Lib.extendDeepNoArrays({}, transforms[j]);
}
// Initialize empty arrays for the arrayAttrs, to be split in the next step
for (j = 0; j < arrayAttrs.length; j++) {
Lib.nestedProperty(newTrace, arrayAttrs[j]).set([]);
}
}
// For each array attribute including those nested inside this and other
// transforms (small note that we technically only need to do this for
// transforms that have not yet been applied):
for (k = 0; k < arrayAttrs.length; k++) {
attr = arrayAttrs[k];
// Cache all the arrays to which we'll push:
for (j = 0, arrayLookup = []; j < groupNames.length; j++) {
arrayLookup[j] = Lib.nestedProperty(newData[j], attr).get();
}
// Get the input data:
srcArray = Lib.nestedProperty(trace, attr).get();
// Send each data point to the appropriate expanded trace:
for (j = 0; j < len; j++) {
// Map group data --> trace index --> array and push data onto it
arrayLookup[indexLookup[groups[j]]].push(srcArray[j]);
}
}
for (j = 0; j < len; j++) {
newTrace = newData[indexLookup[groups[j]]];
var indexToPoints = newTrace.transforms[transformIndex]._indexToPoints;
indexToPoints[indexCnts[groups[j]]] = originalPointsAccessor(j);
indexCnts[groups[j]]++;
}
for (i = 0; i < groupNames.length; i++) {
groupName = groupNames[i];
newTrace = newData[i];
Plots.clearExpandedTraceDefaultColors(newTrace);
// there's no need to coerce styleLookup[groupName] here
// as another round of supplyDefaults is done on the transformed traces
newTrace = Lib.extendDeepNoArrays(newTrace, styleLookup[groupName] || {});
}
return newData;
}
/***/ }),
/***/ 468:
/***/ (function(__unused_webpack_module, exports) {
"use strict";
exports.W = function (transforms, opts) {
var tr;
var prevIndexToPoints;
for (var i = 0; i < transforms.length; i++) {
tr = transforms[i];
if (tr === opts) break;
if (!tr._indexToPoints || tr.enabled === false) continue;
prevIndexToPoints = tr._indexToPoints;
}
var originalPointsAccessor = prevIndexToPoints ? function (i) {
return prevIndexToPoints[i];
} : function (i) {
return [i];
};
return originalPointsAccessor;
};
/***/ }),
/***/ 6272:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
var Lib = __webpack_require__(3400);
var Axes = __webpack_require__(4460);
var pointsAccessorFunction = (__webpack_require__(468)/* .pointsAccessorFunction */ .W);
var BADNUM = (__webpack_require__(9032).BADNUM);
exports.moduleType = 'transform';
exports.name = 'sort';
exports.attributes = {
enabled: {
valType: 'boolean',
dflt: true,
editType: 'calc'
},
target: {
valType: 'string',
strict: true,
noBlank: true,
arrayOk: true,
dflt: 'x',
editType: 'calc'
},
order: {
valType: 'enumerated',
values: ['ascending', 'descending'],
dflt: 'ascending',
editType: 'calc'
},
editType: 'calc'
};
exports.supplyDefaults = function (transformIn) {
var transformOut = {};
function coerce(attr, dflt) {
return Lib.coerce(transformIn, transformOut, exports.attributes, attr, dflt);
}
var enabled = coerce('enabled');
if (enabled) {
coerce('target');
coerce('order');
}
return transformOut;
};
exports.calcTransform = function (gd, trace, opts) {
if (!opts.enabled) return;
var targetArray = Lib.getTargetArray(trace, opts);
if (!targetArray) return;
var target = opts.target;
var len = targetArray.length;
if (trace._length) len = Math.min(len, trace._length);
var arrayAttrs = trace._arrayAttrs;
var d2c = Axes.getDataToCoordFunc(gd, trace, target, targetArray);
var indices = getIndices(opts, targetArray, d2c, len);
var originalPointsAccessor = pointsAccessorFunction(trace.transforms, opts);
var indexToPoints = {};
var i, j;
for (i = 0; i < arrayAttrs.length; i++) {
var np = Lib.nestedProperty(trace, arrayAttrs[i]);
var arrayOld = np.get();
var arrayNew = new Array(len);
for (j = 0; j < len; j++) {
arrayNew[j] = arrayOld[indices[j]];
}
np.set(arrayNew);
}
for (j = 0; j < len; j++) {
indexToPoints[j] = originalPointsAccessor(indices[j]);
}
opts._indexToPoints = indexToPoints;
trace._length = len;
};
function getIndices(opts, targetArray, d2c, len) {
var sortedArray = new Array(len);
var indices = new Array(len);
var i;
for (i = 0; i < len; i++) {
sortedArray[i] = {
v: targetArray[i],
i: i
};
}
sortedArray.sort(getSortFunc(opts, d2c));
for (i = 0; i < len; i++) {
indices[i] = sortedArray[i].i;
}
return indices;
}
function getSortFunc(opts, d2c) {
switch (opts.order) {
case 'ascending':
return function (a, b) {
var ac = d2c(a.v);
var bc = d2c(b.v);
if (ac === BADNUM) {
return 1;
}
if (bc === BADNUM) {
return -1;
}
return ac - bc;
};
case 'descending':
return function (a, b) {
var ac = d2c(a.v);
var bc = d2c(b.v);
if (ac === BADNUM) {
return 1;
}
if (bc === BADNUM) {
return -1;
}
return bc - ac;
};
}
}
/***/ }),
/***/ 5788:
/***/ (function(__unused_webpack_module, exports) {
"use strict";
// package version injected by `npm run preprocess`
exports.version = '2.31.0';
/***/ }),
/***/ 5928:
/***/ (function(module) {
"use strict";
module.exports = isMobile;
module.exports.isMobile = isMobile;
module.exports["default"] = isMobile;
var mobileRE = /(android|bb\d+|meego).+mobile|armv7l|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series[46]0|samsungbrowser.*mobile|symbian|treo|up\.(browser|link)|vodafone|wap|windows (ce|phone)|xda|xiino/i;
var notMobileRE = /CrOS/;
var tabletRE = /android|ipad|playbook|silk/i;
function isMobile(opts) {
if (!opts) opts = {};
var ua = opts.ua;
if (!ua && typeof navigator !== 'undefined') ua = navigator.userAgent;
if (ua && ua.headers && typeof ua.headers['user-agent'] === 'string') {
ua = ua.headers['user-agent'];
}
if (typeof ua !== 'string') return false;
var result = mobileRE.test(ua) && !notMobileRE.test(ua) || !!opts.tablet && tabletRE.test(ua);
if (!result && opts.tablet && opts.featureDetect && navigator && navigator.maxTouchPoints > 1 && ua.indexOf('Macintosh') !== -1 && ua.indexOf('Safari') !== -1) {
result = true;
}
return result;
}
/***/ }),
/***/ 3428:
/***/ (function(module, exports, __webpack_require__) {
var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_RESULT__;!function() {
var d3 = {
version: "3.8.0"
};
var d3_arraySlice = [].slice, d3_array = function(list) {
return d3_arraySlice.call(list);
};
var d3_document = self.document;
function d3_documentElement(node) {
return node && (node.ownerDocument || node.document || node).documentElement;
}
function d3_window(node) {
return node && (node.ownerDocument && node.ownerDocument.defaultView || node.document && node || node.defaultView);
}
if (d3_document) {
try {
d3_array(d3_document.documentElement.childNodes)[0].nodeType;
} catch (e) {
d3_array = function(list) {
var i = list.length, array = new Array(i);
while (i--) array[i] = list[i];
return array;
};
}
}
if (!Date.now) Date.now = function() {
return +new Date();
};
if (d3_document) {
try {
d3_document.createElement("DIV").style.setProperty("opacity", 0, "");
} catch (error) {
var d3_element_prototype = this.Element.prototype, d3_element_setAttribute = d3_element_prototype.setAttribute, d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, d3_style_prototype = this.CSSStyleDeclaration.prototype, d3_style_setProperty = d3_style_prototype.setProperty;
d3_element_prototype.setAttribute = function(name, value) {
d3_element_setAttribute.call(this, name, value + "");
};
d3_element_prototype.setAttributeNS = function(space, local, value) {
d3_element_setAttributeNS.call(this, space, local, value + "");
};
d3_style_prototype.setProperty = function(name, value, priority) {
d3_style_setProperty.call(this, name, value + "", priority);
};
}
}
d3.ascending = d3_ascending;
function d3_ascending(a, b) {
return a < b ? -1 : a > b ? 1 : a >= b ? 0 : NaN;
}
d3.descending = function(a, b) {
return b < a ? -1 : b > a ? 1 : b >= a ? 0 : NaN;
};
d3.min = function(array, f) {
var i = -1, n = array.length, a, b;
if (arguments.length === 1) {
while (++i < n) if ((b = array[i]) != null && b >= b) {
a = b;
break;
}
while (++i < n) if ((b = array[i]) != null && a > b) a = b;
} else {
while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
a = b;
break;
}
while (++i < n) if ((b = f.call(array, array[i], i)) != null && a > b) a = b;
}
return a;
};
d3.max = function(array, f) {
var i = -1, n = array.length, a, b;
if (arguments.length === 1) {
while (++i < n) if ((b = array[i]) != null && b >= b) {
a = b;
break;
}
while (++i < n) if ((b = array[i]) != null && b > a) a = b;
} else {
while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
a = b;
break;
}
while (++i < n) if ((b = f.call(array, array[i], i)) != null && b > a) a = b;
}
return a;
};
d3.extent = function(array, f) {
var i = -1, n = array.length, a, b, c;
if (arguments.length === 1) {
while (++i < n) if ((b = array[i]) != null && b >= b) {
a = c = b;
break;
}
while (++i < n) if ((b = array[i]) != null) {
if (a > b) a = b;
if (c < b) c = b;
}
} else {
while (++i < n) if ((b = f.call(array, array[i], i)) != null && b >= b) {
a = c = b;
break;
}
while (++i < n) if ((b = f.call(array, array[i], i)) != null) {
if (a > b) a = b;
if (c < b) c = b;
}
}
return [ a, c ];
};
function d3_number(x) {
return x === null ? NaN : +x;
}
function d3_numeric(x) {
return !isNaN(x);
}
d3.sum = function(array, f) {
var s = 0, n = array.length, a, i = -1;
if (arguments.length === 1) {
while (++i < n) if (d3_numeric(a = +array[i])) s += a;
} else {
while (++i < n) if (d3_numeric(a = +f.call(array, array[i], i))) s += a;
}
return s;
};
d3.mean = function(array, f) {
var s = 0, n = array.length, a, i = -1, j = n;
if (arguments.length === 1) {
while (++i < n) if (d3_numeric(a = d3_number(array[i]))) s += a; else --j;
} else {
while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) s += a; else --j;
}
if (j) return s / j;
};
d3.quantile = function(values, p) {
var H = (values.length - 1) * p + 1, h = Math.floor(H), v = +values[h - 1], e = H - h;
return e ? v + e * (values[h] - v) : v;
};
d3.median = function(array, f) {
var numbers = [], n = array.length, a, i = -1;
if (arguments.length === 1) {
while (++i < n) if (d3_numeric(a = d3_number(array[i]))) numbers.push(a);
} else {
while (++i < n) if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) numbers.push(a);
}
if (numbers.length) return d3.quantile(numbers.sort(d3_ascending), .5);
};
d3.variance = function(array, f) {
var n = array.length, m = 0, a, d, s = 0, i = -1, j = 0;
if (arguments.length === 1) {
while (++i < n) {
if (d3_numeric(a = d3_number(array[i]))) {
d = a - m;
m += d / ++j;
s += d * (a - m);
}
}
} else {
while (++i < n) {
if (d3_numeric(a = d3_number(f.call(array, array[i], i)))) {
d = a - m;
m += d / ++j;
s += d * (a - m);
}
}
}
if (j > 1) return s / (j - 1);
};
d3.deviation = function() {
var v = d3.variance.apply(this, arguments);
return v ? Math.sqrt(v) : v;
};
function d3_bisector(compare) {
return {
left: function(a, x, lo, hi) {
if (arguments.length < 3) lo = 0;
if (arguments.length < 4) hi = a.length;
while (lo < hi) {
var mid = lo + hi >>> 1;
if (compare(a[mid], x) < 0) lo = mid + 1; else hi = mid;
}
return lo;
},
right: function(a, x, lo, hi) {
if (arguments.length < 3) lo = 0;
if (arguments.length < 4) hi = a.length;
while (lo < hi) {
var mid = lo + hi >>> 1;
if (compare(a[mid], x) > 0) hi = mid; else lo = mid + 1;
}
return lo;
}
};
}
var d3_bisect = d3_bisector(d3_ascending);
d3.bisectLeft = d3_bisect.left;
d3.bisect = d3.bisectRight = d3_bisect.right;
d3.bisector = function(f) {
return d3_bisector(f.length === 1 ? function(d, x) {
return d3_ascending(f(d), x);
} : f);
};
d3.shuffle = function(array, i0, i1) {
if ((m = arguments.length) < 3) {
i1 = array.length;
if (m < 2) i0 = 0;
}
var m = i1 - i0, t, i;
while (m) {
i = Math.random() * m-- | 0;
t = array[m + i0], array[m + i0] = array[i + i0], array[i + i0] = t;
}
return array;
};
d3.permute = function(array, indexes) {
var i = indexes.length, permutes = new Array(i);
while (i--) permutes[i] = array[indexes[i]];
return permutes;
};
d3.pairs = function(array) {
var i = 0, n = array.length - 1, p0, p1 = array[0], pairs = new Array(n < 0 ? 0 : n);
while (i < n) pairs[i] = [ p0 = p1, p1 = array[++i] ];
return pairs;
};
d3.transpose = function(matrix) {
if (!(n = matrix.length)) return [];
for (var i = -1, m = d3.min(matrix, d3_transposeLength), transpose = new Array(m); ++i < m; ) {
for (var j = -1, n, row = transpose[i] = new Array(n); ++j < n; ) {
row[j] = matrix[j][i];
}
}
return transpose;
};
function d3_transposeLength(d) {
return d.length;
}
d3.zip = function() {
return d3.transpose(arguments);
};
d3.keys = function(map) {
var keys = [];
for (var key in map) keys.push(key);
return keys;
};
d3.values = function(map) {
var values = [];
for (var key in map) values.push(map[key]);
return values;
};
d3.entries = function(map) {
var entries = [];
for (var key in map) entries.push({
key: key,
value: map[key]
});
return entries;
};
d3.merge = function(arrays) {
var n = arrays.length, m, i = -1, j = 0, merged, array;
while (++i < n) j += arrays[i].length;
merged = new Array(j);
while (--n >= 0) {
array = arrays[n];
m = array.length;
while (--m >= 0) {
merged[--j] = array[m];
}
}
return merged;
};
var abs = Math.abs;
d3.range = function(start, stop, step) {
if (arguments.length < 3) {
step = 1;
if (arguments.length < 2) {
stop = start;
start = 0;
}
}
if ((stop - start) / step === Infinity) throw new Error("infinite range");
var range = [], k = d3_range_integerScale(abs(step)), i = -1, j;
start *= k, stop *= k, step *= k;
if (step < 0) while ((j = start + step * ++i) > stop) range.push(j / k); else while ((j = start + step * ++i) < stop) range.push(j / k);
return range;
};
function d3_range_integerScale(x) {
var k = 1;
while (x * k % 1) k *= 10;
return k;
}
function d3_class(ctor, properties) {
for (var key in properties) {
Object.defineProperty(ctor.prototype, key, {
value: properties[key],
enumerable: false
});
}
}
d3.map = function(object, f) {
var map = new d3_Map();
if (object instanceof d3_Map) {
object.forEach(function(key, value) {
map.set(key, value);
});
} else if (Array.isArray(object)) {
var i = -1, n = object.length, o;
if (arguments.length === 1) while (++i < n) map.set(i, object[i]); else while (++i < n) map.set(f.call(object, o = object[i], i), o);
} else {
for (var key in object) map.set(key, object[key]);
}
return map;
};
function d3_Map() {
this._ = Object.create(null);
}
var d3_map_proto = "__proto__", d3_map_zero = "\x00";
d3_class(d3_Map, {
has: d3_map_has,
get: function(key) {
return this._[d3_map_escape(key)];
},
set: function(key, value) {
return this._[d3_map_escape(key)] = value;
},
remove: d3_map_remove,
keys: d3_map_keys,
values: function() {
var values = [];
for (var key in this._) values.push(this._[key]);
return values;
},
entries: function() {
var entries = [];
for (var key in this._) entries.push({
key: d3_map_unescape(key),
value: this._[key]
});
return entries;
},
size: d3_map_size,
empty: d3_map_empty,
forEach: function(f) {
for (var key in this._) f.call(this, d3_map_unescape(key), this._[key]);
}
});
function d3_map_escape(key) {
return (key += "") === d3_map_proto || key[0] === d3_map_zero ? d3_map_zero + key : key;
}
function d3_map_unescape(key) {
return (key += "")[0] === d3_map_zero ? key.slice(1) : key;
}
function d3_map_has(key) {
return d3_map_escape(key) in this._;
}
function d3_map_remove(key) {
return (key = d3_map_escape(key)) in this._ && delete this._[key];
}
function d3_map_keys() {
var keys = [];
for (var key in this._) keys.push(d3_map_unescape(key));
return keys;
}
function d3_map_size() {
var size = 0;
for (var key in this._) ++size;
return size;
}
function d3_map_empty() {
for (var key in this._) return false;
return true;
}
d3.nest = function() {
var nest = {}, keys = [], sortKeys = [], sortValues, rollup;
function map(mapType, array, depth) {
if (depth >= keys.length) return rollup ? rollup.call(nest, array) : sortValues ? array.sort(sortValues) : array;
var i = -1, n = array.length, key = keys[depth++], keyValue, object, setter, valuesByKey = new d3_Map(), values;
while (++i < n) {
if (values = valuesByKey.get(keyValue = key(object = array[i]))) {
values.push(object);
} else {
valuesByKey.set(keyValue, [ object ]);
}
}
if (mapType) {
object = mapType();
setter = function(keyValue, values) {
object.set(keyValue, map(mapType, values, depth));
};
} else {
object = {};
setter = function(keyValue, values) {
object[keyValue] = map(mapType, values, depth);
};
}
valuesByKey.forEach(setter);
return object;
}
function entries(map, depth) {
if (depth >= keys.length) return map;
var array = [], sortKey = sortKeys[depth++];
map.forEach(function(key, keyMap) {
array.push({
key: key,
values: entries(keyMap, depth)
});
});
return sortKey ? array.sort(function(a, b) {
return sortKey(a.key, b.key);
}) : array;
}
nest.map = function(array, mapType) {
return map(mapType, array, 0);
};
nest.entries = function(array) {
return entries(map(d3.map, array, 0), 0);
};
nest.key = function(d) {
keys.push(d);
return nest;
};
nest.sortKeys = function(order) {
sortKeys[keys.length - 1] = order;
return nest;
};
nest.sortValues = function(order) {
sortValues = order;
return nest;
};
nest.rollup = function(f) {
rollup = f;
return nest;
};
return nest;
};
d3.set = function(array) {
var set = new d3_Set();
if (array) for (var i = 0, n = array.length; i < n; ++i) set.add(array[i]);
return set;
};
function d3_Set() {
this._ = Object.create(null);
}
d3_class(d3_Set, {
has: d3_map_has,
add: function(key) {
this._[d3_map_escape(key += "")] = true;
return key;
},
remove: d3_map_remove,
values: d3_map_keys,
size: d3_map_size,
empty: d3_map_empty,
forEach: function(f) {
for (var key in this._) f.call(this, d3_map_unescape(key));
}
});
d3.behavior = {};
function d3_identity(d) {
return d;
}
d3.rebind = function(target, source) {
var i = 1, n = arguments.length, method;
while (++i < n) target[method = arguments[i]] = d3_rebind(target, source, source[method]);
return target;
};
function d3_rebind(target, source, method) {
return function() {
var value = method.apply(source, arguments);
return value === source ? target : value;
};
}
function d3_vendorSymbol(object, name) {
if (name in object) return name;
name = name.charAt(0).toUpperCase() + name.slice(1);
for (var i = 0, n = d3_vendorPrefixes.length; i < n; ++i) {
var prefixName = d3_vendorPrefixes[i] + name;
if (prefixName in object) return prefixName;
}
}
var d3_vendorPrefixes = [ "webkit", "ms", "moz", "Moz", "o", "O" ];
function d3_noop() {}
d3.dispatch = function() {
var dispatch = new d3_dispatch(), i = -1, n = arguments.length;
while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
return dispatch;
};
function d3_dispatch() {}
d3_dispatch.prototype.on = function(type, listener) {
var i = type.indexOf("."), name = "";
if (i >= 0) {
name = type.slice(i + 1);
type = type.slice(0, i);
}
if (type) return arguments.length < 2 ? this[type].on(name) : this[type].on(name, listener);
if (arguments.length === 2) {
if (listener == null) for (type in this) {
if (this.hasOwnProperty(type)) this[type].on(name, null);
}
return this;
}
};
function d3_dispatch_event(dispatch) {
var listeners = [], listenerByName = new d3_Map();
function event() {
var z = listeners, i = -1, n = z.length, l;
while (++i < n) if (l = z[i].on) l.apply(this, arguments);
return dispatch;
}
event.on = function(name, listener) {
var l = listenerByName.get(name), i;
if (arguments.length < 2) return l && l.on;
if (l) {
l.on = null;
listeners = listeners.slice(0, i = listeners.indexOf(l)).concat(listeners.slice(i + 1));
listenerByName.remove(name);
}
if (listener) listeners.push(listenerByName.set(name, {
on: listener
}));
return dispatch;
};
return event;
}
d3.event = null;
function d3_eventPreventDefault() {
d3.event.preventDefault();
}
function d3_eventSource() {
var e = d3.event, s;
while (s = e.sourceEvent) e = s;
return e;
}
function d3_eventDispatch(target) {
var dispatch = new d3_dispatch(), i = 0, n = arguments.length;
while (++i < n) dispatch[arguments[i]] = d3_dispatch_event(dispatch);
dispatch.of = function(thiz, argumentz) {
return function(e1) {
try {
var e0 = e1.sourceEvent = d3.event;
e1.target = target;
d3.event = e1;
dispatch[e1.type].apply(thiz, argumentz);
} finally {
d3.event = e0;
}
};
};
return dispatch;
}
d3.requote = function(s) {
return s.replace(d3_requote_re, "\\$&");
};
var d3_requote_re = /[\\\^\$\*\+\?\|\[\]\(\)\.\{\}]/g;
var d3_subclass = {}.__proto__ ? function(object, prototype) {
object.__proto__ = prototype;
} : function(object, prototype) {
for (var property in prototype) object[property] = prototype[property];
};
function d3_selection(groups) {
d3_subclass(groups, d3_selectionPrototype);
return groups;
}
var d3_select = function(s, n) {
return n.querySelector(s);
}, d3_selectAll = function(s, n) {
return n.querySelectorAll(s);
}, d3_selectMatches = function(n, s) {
var d3_selectMatcher = n.matches || n[d3_vendorSymbol(n, "matchesSelector")];
d3_selectMatches = function(n, s) {
return d3_selectMatcher.call(n, s);
};
return d3_selectMatches(n, s);
};
if (typeof Sizzle === "function") {
d3_select = function(s, n) {
return Sizzle(s, n)[0] || null;
};
d3_selectAll = Sizzle;
d3_selectMatches = Sizzle.matchesSelector;
}
d3.selection = function() {
return d3.select(d3_document.documentElement);
};
var d3_selectionPrototype = d3.selection.prototype = [];
d3_selectionPrototype.select = function(selector) {
var subgroups = [], subgroup, subnode, group, node;
selector = d3_selection_selector(selector);
for (var j = -1, m = this.length; ++j < m; ) {
subgroups.push(subgroup = []);
subgroup.parentNode = (group = this[j]).parentNode;
for (var i = -1, n = group.length; ++i < n; ) {
if (node = group[i]) {
subgroup.push(subnode = selector.call(node, node.__data__, i, j));
if (subnode && "__data__" in node) subnode.__data__ = node.__data__;
} else {
subgroup.push(null);
}
}
}
return d3_selection(subgroups);
};
function d3_selection_selector(selector) {
return typeof selector === "function" ? selector : function() {
return d3_select(selector, this);
};
}
d3_selectionPrototype.selectAll = function(selector) {
var subgroups = [], subgroup, node;
selector = d3_selection_selectorAll(selector);
for (var j = -1, m = this.length; ++j < m; ) {
for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
if (node = group[i]) {
subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
subgroup.parentNode = node;
}
}
}
return d3_selection(subgroups);
};
function d3_selection_selectorAll(selector) {
return typeof selector === "function" ? selector : function() {
return d3_selectAll(selector, this);
};
}
var d3_nsXhtml = "http://www.w3.org/1999/xhtml";
var d3_nsPrefix = {
svg: "http://www.w3.org/2000/svg",
xhtml: d3_nsXhtml,
xlink: "http://www.w3.org/1999/xlink",
xml: "http://www.w3.org/XML/1998/namespace",
xmlns: "http://www.w3.org/2000/xmlns/"
};
d3.ns = {
prefix: d3_nsPrefix,
qualify: function(name) {
var i = name.indexOf(":"), prefix = name;
if (i >= 0 && (prefix = name.slice(0, i)) !== "xmlns") name = name.slice(i + 1);
return d3_nsPrefix.hasOwnProperty(prefix) ? {
space: d3_nsPrefix[prefix],
local: name
} : name;
}
};
d3_selectionPrototype.attr = function(name, value) {
if (arguments.length < 2) {
if (typeof name === "string") {
var node = this.node();
name = d3.ns.qualify(name);
return name.local ? node.getAttributeNS(name.space, name.local) : node.getAttribute(name);
}
for (value in name) this.each(d3_selection_attr(value, name[value]));
return this;
}
return this.each(d3_selection_attr(name, value));
};
function d3_selection_attr(name, value) {
name = d3.ns.qualify(name);
function attrNull() {
this.removeAttribute(name);
}
function attrNullNS() {
this.removeAttributeNS(name.space, name.local);
}
function attrConstant() {
this.setAttribute(name, value);
}
function attrConstantNS() {
this.setAttributeNS(name.space, name.local, value);
}
function attrFunction() {
var x = value.apply(this, arguments);
if (x == null) this.removeAttribute(name); else this.setAttribute(name, x);
}
function attrFunctionNS() {
var x = value.apply(this, arguments);
if (x == null) this.removeAttributeNS(name.space, name.local); else this.setAttributeNS(name.space, name.local, x);
}
return value == null ? name.local ? attrNullNS : attrNull : typeof value === "function" ? name.local ? attrFunctionNS : attrFunction : name.local ? attrConstantNS : attrConstant;
}
function d3_collapse(s) {
return s.trim().replace(/\s+/g, " ");
}
d3_selectionPrototype.classed = function(name, value) {
if (arguments.length < 2) {
if (typeof name === "string") {
var node = this.node(), n = (name = d3_selection_classes(name)).length, i = -1;
if (value = node.classList) {
while (++i < n) if (!value.contains(name[i])) return false;
} else {
value = node.getAttribute("class");
while (++i < n) if (!d3_selection_classedRe(name[i]).test(value)) return false;
}
return true;
}
for (value in name) this.each(d3_selection_classed(value, name[value]));
return this;
}
return this.each(d3_selection_classed(name, value));
};
function d3_selection_classedRe(name) {
return new RegExp("(?:^|\\s+)" + d3.requote(name) + "(?:\\s+|$)", "g");
}
function d3_selection_classes(name) {
return (name + "").trim().split(/^|\s+/);
}
function d3_selection_classed(name, value) {
name = d3_selection_classes(name).map(d3_selection_classedName);
var n = name.length;
function classedConstant() {
var i = -1;
while (++i < n) name[i](this, value);
}
function classedFunction() {
var i = -1, x = value.apply(this, arguments);
while (++i < n) name[i](this, x);
}
return typeof value === "function" ? classedFunction : classedConstant;
}
function d3_selection_classedName(name) {
var re = d3_selection_classedRe(name);
return function(node, value) {
if (c = node.classList) return value ? c.add(name) : c.remove(name);
var c = node.getAttribute("class") || "";
if (value) {
re.lastIndex = 0;
if (!re.test(c)) node.setAttribute("class", d3_collapse(c + " " + name));
} else {
node.setAttribute("class", d3_collapse(c.replace(re, " ")));
}
};
}
d3_selectionPrototype.style = function(name, value, priority) {
var n = arguments.length;
if (n < 3) {
if (typeof name !== "string") {
if (n < 2) value = "";
for (priority in name) this.each(d3_selection_style(priority, name[priority], value));
return this;
}
if (n < 2) {
var node = this.node();
return d3_window(node).getComputedStyle(node, null).getPropertyValue(name);
}
priority = "";
}
return this.each(d3_selection_style(name, value, priority));
};
function d3_selection_style(name, value, priority) {
function styleNull() {
this.style.removeProperty(name);
}
function styleConstant() {
this.style.setProperty(name, value, priority);
}
function styleFunction() {
var x = value.apply(this, arguments);
if (x == null) this.style.removeProperty(name); else this.style.setProperty(name, x, priority);
}
return value == null ? styleNull : typeof value === "function" ? styleFunction : styleConstant;
}
d3_selectionPrototype.property = function(name, value) {
if (arguments.length < 2) {
if (typeof name === "string") return this.node()[name];
for (value in name) this.each(d3_selection_property(value, name[value]));
return this;
}
return this.each(d3_selection_property(name, value));
};
function d3_selection_property(name, value) {
function propertyNull() {
delete this[name];
}
function propertyConstant() {
this[name] = value;
}
function propertyFunction() {
var x = value.apply(this, arguments);
if (x == null) delete this[name]; else this[name] = x;
}
return value == null ? propertyNull : typeof value === "function" ? propertyFunction : propertyConstant;
}
d3_selectionPrototype.text = function(value) {
return arguments.length ? this.each(typeof value === "function" ? function() {
var v = value.apply(this, arguments);
this.textContent = v == null ? "" : v;
} : value == null ? function() {
this.textContent = "";
} : function() {
this.textContent = value;
}) : this.node().textContent;
};
d3_selectionPrototype.html = function(value) {
return arguments.length ? this.each(typeof value === "function" ? function() {
var v = value.apply(this, arguments);
this.innerHTML = v == null ? "" : v;
} : value == null ? function() {
this.innerHTML = "";
} : function() {
this.innerHTML = value;
}) : this.node().innerHTML;
};
d3_selectionPrototype.append = function(name) {
name = d3_selection_creator(name);
return this.select(function() {
return this.appendChild(name.apply(this, arguments));
});
};
function d3_selection_creator(name) {
function create() {
var document = this.ownerDocument, namespace = this.namespaceURI;
return namespace === d3_nsXhtml && document.documentElement.namespaceURI === d3_nsXhtml ? document.createElement(name) : document.createElementNS(namespace, name);
}
function createNS() {
return this.ownerDocument.createElementNS(name.space, name.local);
}
return typeof name === "function" ? name : (name = d3.ns.qualify(name)).local ? createNS : create;
}
d3_selectionPrototype.insert = function(name, before) {
name = d3_selection_creator(name);
before = d3_selection_selector(before);
return this.select(function() {
return this.insertBefore(name.apply(this, arguments), before.apply(this, arguments) || null);
});
};
d3_selectionPrototype.remove = function() {
return this.each(d3_selectionRemove);
};
function d3_selectionRemove() {
var parent = this.parentNode;
if (parent) parent.removeChild(this);
}
d3_selectionPrototype.data = function(value, key) {
var i = -1, n = this.length, group, node;
if (!arguments.length) {
value = new Array(n = (group = this[0]).length);
while (++i < n) {
if (node = group[i]) {
value[i] = node.__data__;
}
}
return value;
}
function bind(group, groupData) {
var i, n = group.length, m = groupData.length, n0 = Math.min(n, m), updateNodes = new Array(m), enterNodes = new Array(m), exitNodes = new Array(n), node, nodeData;
if (key) {
var nodeByKeyValue = new d3_Map(), keyValues = new Array(n), keyValue;
for (i = -1; ++i < n; ) {
if (node = group[i]) {
if (nodeByKeyValue.has(keyValue = key.call(node, node.__data__, i))) {
exitNodes[i] = node;
} else {
nodeByKeyValue.set(keyValue, node);
}
keyValues[i] = keyValue;
}
}
for (i = -1; ++i < m; ) {
if (!(node = nodeByKeyValue.get(keyValue = key.call(groupData, nodeData = groupData[i], i)))) {
enterNodes[i] = d3_selection_dataNode(nodeData);
} else if (node !== true) {
updateNodes[i] = node;
node.__data__ = nodeData;
}
nodeByKeyValue.set(keyValue, true);
}
for (i = -1; ++i < n; ) {
if (i in keyValues && nodeByKeyValue.get(keyValues[i]) !== true) {
exitNodes[i] = group[i];
}
}
} else {
for (i = -1; ++i < n0; ) {
node = group[i];
nodeData = groupData[i];
if (node) {
node.__data__ = nodeData;
updateNodes[i] = node;
} else {
enterNodes[i] = d3_selection_dataNode(nodeData);
}
}
for (;i < m; ++i) {
enterNodes[i] = d3_selection_dataNode(groupData[i]);
}
for (;i < n; ++i) {
exitNodes[i] = group[i];
}
}
enterNodes.update = updateNodes;
enterNodes.parentNode = updateNodes.parentNode = exitNodes.parentNode = group.parentNode;
enter.push(enterNodes);
update.push(updateNodes);
exit.push(exitNodes);
}
var enter = d3_selection_enter([]), update = d3_selection([]), exit = d3_selection([]);
if (typeof value === "function") {
while (++i < n) {
bind(group = this[i], value.call(group, group.parentNode.__data__, i));
}
} else {
while (++i < n) {
bind(group = this[i], value);
}
}
update.enter = function() {
return enter;
};
update.exit = function() {
return exit;
};
return update;
};
function d3_selection_dataNode(data) {
return {
__data__: data
};
}
d3_selectionPrototype.datum = function(value) {
return arguments.length ? this.property("__data__", value) : this.property("__data__");
};
d3_selectionPrototype.filter = function(filter) {
var subgroups = [], subgroup, group, node;
if (typeof filter !== "function") filter = d3_selection_filter(filter);
for (var j = 0, m = this.length; j < m; j++) {
subgroups.push(subgroup = []);
subgroup.parentNode = (group = this[j]).parentNode;
for (var i = 0, n = group.length; i < n; i++) {
if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
subgroup.push(node);
}
}
}
return d3_selection(subgroups);
};
function d3_selection_filter(selector) {
return function() {
return d3_selectMatches(this, selector);
};
}
d3_selectionPrototype.order = function() {
for (var j = -1, m = this.length; ++j < m; ) {
for (var group = this[j], i = group.length - 1, next = group[i], node; --i >= 0; ) {
if (node = group[i]) {
if (next && next !== node.nextSibling) next.parentNode.insertBefore(node, next);
next = node;
}
}
}
return this;
};
d3_selectionPrototype.sort = function(comparator) {
comparator = d3_selection_sortComparator.apply(this, arguments);
for (var j = -1, m = this.length; ++j < m; ) this[j].sort(comparator);
return this.order();
};
function d3_selection_sortComparator(comparator) {
if (!arguments.length) comparator = d3_ascending;
return function(a, b) {
return a && b ? comparator(a.__data__, b.__data__) : !a - !b;
};
}
d3_selectionPrototype.each = function(callback) {
return d3_selection_each(this, function(node, i, j) {
callback.call(node, node.__data__, i, j);
});
};
function d3_selection_each(groups, callback) {
for (var j = 0, m = groups.length; j < m; j++) {
for (var group = groups[j], i = 0, n = group.length, node; i < n; i++) {
if (node = group[i]) callback(node, i, j);
}
}
return groups;
}
d3_selectionPrototype.call = function(callback) {
var args = d3_array(arguments);
callback.apply(args[0] = this, args);
return this;
};
d3_selectionPrototype.empty = function() {
return !this.node();
};
d3_selectionPrototype.node = function() {
for (var j = 0, m = this.length; j < m; j++) {
for (var group = this[j], i = 0, n = group.length; i < n; i++) {
var node = group[i];
if (node) return node;
}
}
return null;
};
d3_selectionPrototype.size = function() {
var n = 0;
d3_selection_each(this, function() {
++n;
});
return n;
};
function d3_selection_enter(selection) {
d3_subclass(selection, d3_selection_enterPrototype);
return selection;
}
var d3_selection_enterPrototype = [];
d3.selection.enter = d3_selection_enter;
d3.selection.enter.prototype = d3_selection_enterPrototype;
d3_selection_enterPrototype.append = d3_selectionPrototype.append;
d3_selection_enterPrototype.empty = d3_selectionPrototype.empty;
d3_selection_enterPrototype.node = d3_selectionPrototype.node;
d3_selection_enterPrototype.call = d3_selectionPrototype.call;
d3_selection_enterPrototype.size = d3_selectionPrototype.size;
d3_selection_enterPrototype.select = function(selector) {
var subgroups = [], subgroup, subnode, upgroup, group, node;
for (var j = -1, m = this.length; ++j < m; ) {
upgroup = (group = this[j]).update;
subgroups.push(subgroup = []);
subgroup.parentNode = group.parentNode;
for (var i = -1, n = group.length; ++i < n; ) {
if (node = group[i]) {
subgroup.push(upgroup[i] = subnode = selector.call(group.parentNode, node.__data__, i, j));
subnode.__data__ = node.__data__;
} else {
subgroup.push(null);
}
}
}
return d3_selection(subgroups);
};
d3_selection_enterPrototype.insert = function(name, before) {
if (arguments.length < 2) before = d3_selection_enterInsertBefore(this);
return d3_selectionPrototype.insert.call(this, name, before);
};
function d3_selection_enterInsertBefore(enter) {
var i0, j0;
return function(d, i, j) {
var group = enter[j].update, n = group.length, node;
if (j != j0) j0 = j, i0 = 0;
if (i >= i0) i0 = i + 1;
while (!(node = group[i0]) && ++i0 < n) ;
return node;
};
}
d3.select = function(node) {
var group;
if (typeof node === "string") {
group = [ d3_select(node, d3_document) ];
group.parentNode = d3_document.documentElement;
} else {
group = [ node ];
group.parentNode = d3_documentElement(node);
}
return d3_selection([ group ]);
};
d3.selectAll = function(nodes) {
var group;
if (typeof nodes === "string") {
group = d3_array(d3_selectAll(nodes, d3_document));
group.parentNode = d3_document.documentElement;
} else {
group = d3_array(nodes);
group.parentNode = null;
}
return d3_selection([ group ]);
};
d3_selectionPrototype.on = function(type, listener, capture) {
var n = arguments.length;
if (n < 3) {
if (typeof type !== "string") {
if (n < 2) listener = false;
for (capture in type) this.each(d3_selection_on(capture, type[capture], listener));
return this;
}
if (n < 2) return (n = this.node()["__on" + type]) && n._;
capture = false;
}
return this.each(d3_selection_on(type, listener, capture));
};
function d3_selection_on(type, listener, capture) {
var name = "__on" + type, i = type.indexOf("."), wrap = d3_selection_onListener;
if (i > 0) type = type.slice(0, i);
var filter = d3_selection_onFilters.get(type);
if (filter) type = filter, wrap = d3_selection_onFilter;
function onRemove() {
var l = this[name];
if (l) {
this.removeEventListener(type, l, l.$);
delete this[name];
}
}
function onAdd() {
var l = wrap(listener, d3_array(arguments));
onRemove.call(this);
this.addEventListener(type, this[name] = l, l.$ = capture);
l._ = listener;
}
function removeAll() {
var re = new RegExp("^__on([^.]+)" + d3.requote(type) + "$"), match;
for (var name in this) {
if (match = name.match(re)) {
var l = this[name];
this.removeEventListener(match[1], l, l.$);
delete this[name];
}
}
}
return i ? listener ? onAdd : onRemove : listener ? d3_noop : removeAll;
}
var d3_selection_onFilters = d3.map({
mouseenter: "mouseover",
mouseleave: "mouseout"
});
if (d3_document) {
d3_selection_onFilters.forEach(function(k) {
if ("on" + k in d3_document) d3_selection_onFilters.remove(k);
});
}
function d3_selection_onListener(listener, argumentz) {
return function(e) {
var o = d3.event;
d3.event = e;
argumentz[0] = this.__data__;
try {
listener.apply(this, argumentz);
} finally {
d3.event = o;
}
};
}
function d3_selection_onFilter(listener, argumentz) {
var l = d3_selection_onListener(listener, argumentz);
return function(e) {
var target = this, related = e.relatedTarget;
if (!related || related !== target && !(related.compareDocumentPosition(target) & 8)) {
l.call(target, e);
}
};
}
var d3_event_dragSelect, d3_event_dragId = 0;
function d3_event_dragSuppress(node) {
var name = ".dragsuppress-" + ++d3_event_dragId, click = "click" + name, w = d3.select(d3_window(node)).on("touchmove" + name, d3_eventPreventDefault).on("dragstart" + name, d3_eventPreventDefault).on("selectstart" + name, d3_eventPreventDefault);
if (d3_event_dragSelect == null) {
d3_event_dragSelect = "onselectstart" in node ? false : d3_vendorSymbol(node.style, "userSelect");
}
if (d3_event_dragSelect) {
var style = d3_documentElement(node).style, select = style[d3_event_dragSelect];
style[d3_event_dragSelect] = "none";
}
return function(suppressClick) {
w.on(name, null);
if (d3_event_dragSelect) style[d3_event_dragSelect] = select;
if (suppressClick) {
var off = function() {
w.on(click, null);
};
w.on(click, function() {
d3_eventPreventDefault();
off();
}, true);
setTimeout(off, 0);
}
};
}
d3.mouse = function(container) {
return d3_mousePoint(container, d3_eventSource());
};
var d3_mouse_bug44083 = this.navigator && /WebKit/.test(this.navigator.userAgent) ? -1 : 0;
function d3_mousePoint(container, e) {
if (e.changedTouches) e = e.changedTouches[0];
var svg = container.ownerSVGElement || container;
if (svg.createSVGPoint) {
var point = svg.createSVGPoint();
if (d3_mouse_bug44083 < 0) {
var window = d3_window(container);
if (window.scrollX || window.scrollY) {
svg = d3.select("body").append("svg").style({
position: "absolute",
top: 0,
left: 0,
margin: 0,
padding: 0,
border: "none"
}, "important");
var ctm = svg[0][0].getScreenCTM();
d3_mouse_bug44083 = !(ctm.f || ctm.e);
svg.remove();
}
}
if (d3_mouse_bug44083) point.x = e.pageX, point.y = e.pageY; else point.x = e.clientX,
point.y = e.clientY;
point = point.matrixTransform(container.getScreenCTM().inverse());
return [ point.x, point.y ];
}
var rect = container.getBoundingClientRect();
return [ e.clientX - rect.left - container.clientLeft, e.clientY - rect.top - container.clientTop ];
}
d3.touch = function(container, touches, identifier) {
if (arguments.length < 3) identifier = touches, touches = d3_eventSource().changedTouches;
if (touches) for (var i = 0, n = touches.length, touch; i < n; ++i) {
if ((touch = touches[i]).identifier === identifier) {
return d3_mousePoint(container, touch);
}
}
};
d3.behavior.drag = function() {
var event = d3_eventDispatch(drag, "drag", "dragstart", "dragend"), origin = null, mousedown = dragstart(d3_noop, d3.mouse, d3_window, "mousemove", "mouseup"), touchstart = dragstart(d3_behavior_dragTouchId, d3.touch, d3_identity, "touchmove", "touchend");
function drag() {
this.on("mousedown.drag", mousedown).on("touchstart.drag", touchstart);
}
function dragstart(id, position, subject, move, end) {
return function() {
var that = this, target = d3.event.target.correspondingElement || d3.event.target, parent = that.parentNode, dispatch = event.of(that, arguments), dragged = 0, dragId = id(), dragName = ".drag" + (dragId == null ? "" : "-" + dragId), dragOffset, dragSubject = d3.select(subject(target)).on(move + dragName, moved).on(end + dragName, ended), dragRestore = d3_event_dragSuppress(target), position0 = position(parent, dragId);
if (origin) {
dragOffset = origin.apply(that, arguments);
dragOffset = [ dragOffset.x - position0[0], dragOffset.y - position0[1] ];
} else {
dragOffset = [ 0, 0 ];
}
dispatch({
type: "dragstart"
});
function moved() {
var position1 = position(parent, dragId), dx, dy;
if (!position1) return;
dx = position1[0] - position0[0];
dy = position1[1] - position0[1];
dragged |= dx | dy;
position0 = position1;
dispatch({
type: "drag",
x: position1[0] + dragOffset[0],
y: position1[1] + dragOffset[1],
dx: dx,
dy: dy
});
}
function ended() {
if (!position(parent, dragId)) return;
dragSubject.on(move + dragName, null).on(end + dragName, null);
dragRestore(dragged);
dispatch({
type: "dragend"
});
}
};
}
drag.origin = function(x) {
if (!arguments.length) return origin;
origin = x;
return drag;
};
return d3.rebind(drag, event, "on");
};
function d3_behavior_dragTouchId() {
return d3.event.changedTouches[0].identifier;
}
d3.touches = function(container, touches) {
if (arguments.length < 2) touches = d3_eventSource().touches;
return touches ? d3_array(touches).map(function(touch) {
var point = d3_mousePoint(container, touch);
point.identifier = touch.identifier;
return point;
}) : [];
};
var ε = 1e-6, ε2 = ε * ε, π = Math.PI, τ = 2 * π, τε = τ - ε, halfπ = π / 2, d3_radians = π / 180, d3_degrees = 180 / π;
function d3_sgn(x) {
return x > 0 ? 1 : x < 0 ? -1 : 0;
}
function d3_cross2d(a, b, c) {
return (b[0] - a[0]) * (c[1] - a[1]) - (b[1] - a[1]) * (c[0] - a[0]);
}
function d3_acos(x) {
return x > 1 ? 0 : x < -1 ? π : Math.acos(x);
}
function d3_asin(x) {
return x > 1 ? halfπ : x < -1 ? -halfπ : Math.asin(x);
}
function d3_sinh(x) {
return ((x = Math.exp(x)) - 1 / x) / 2;
}
function d3_cosh(x) {
return ((x = Math.exp(x)) + 1 / x) / 2;
}
function d3_tanh(x) {
return ((x = Math.exp(2 * x)) - 1) / (x + 1);
}
function d3_haversin(x) {
return (x = Math.sin(x / 2)) * x;
}
var ρ = Math.SQRT2, ρ2 = 2, ρ4 = 4;
d3.interpolateZoom = function(p0, p1) {
var ux0 = p0[0], uy0 = p0[1], w0 = p0[2], ux1 = p1[0], uy1 = p1[1], w1 = p1[2], dx = ux1 - ux0, dy = uy1 - uy0, d2 = dx * dx + dy * dy, i, S;
if (d2 < ε2) {
S = Math.log(w1 / w0) / ρ;
i = function(t) {
return [ ux0 + t * dx, uy0 + t * dy, w0 * Math.exp(ρ * t * S) ];
};
} else {
var d1 = Math.sqrt(d2), b0 = (w1 * w1 - w0 * w0 + ρ4 * d2) / (2 * w0 * ρ2 * d1), b1 = (w1 * w1 - w0 * w0 - ρ4 * d2) / (2 * w1 * ρ2 * d1), r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0), r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
S = (r1 - r0) / ρ;
i = function(t) {
var s = t * S, coshr0 = d3_cosh(r0), u = w0 / (ρ2 * d1) * (coshr0 * d3_tanh(ρ * s + r0) - d3_sinh(r0));
return [ ux0 + u * dx, uy0 + u * dy, w0 * coshr0 / d3_cosh(ρ * s + r0) ];
};
}
i.duration = S * 1e3;
return i;
};
d3.behavior.zoom = function() {
var view = {
x: 0,
y: 0,
k: 1
}, translate0, center0, center, size = [ 960, 500 ], scaleExtent = d3_behavior_zoomInfinity, duration = 250, zooming = 0, mousedown = "mousedown.zoom", mousemove = "mousemove.zoom", mouseup = "mouseup.zoom", mousewheelTimer, touchstart = "touchstart.zoom", touchtime, event = d3_eventDispatch(zoom, "zoomstart", "zoom", "zoomend"), x0, x1, y0, y1;
if (!d3_behavior_zoomWheel) {
d3_behavior_zoomWheel = "onwheel" in d3_document ? (d3_behavior_zoomDelta = function() {
return -d3.event.deltaY * (d3.event.deltaMode ? 120 : 1);
}, "wheel") : "onmousewheel" in d3_document ? (d3_behavior_zoomDelta = function() {
return d3.event.wheelDelta;
}, "mousewheel") : (d3_behavior_zoomDelta = function() {
return -d3.event.detail;
}, "MozMousePixelScroll");
}
function zoom(g) {
g.on(mousedown, mousedowned).on(d3_behavior_zoomWheel + ".zoom", mousewheeled).on("dblclick.zoom", dblclicked).on(touchstart, touchstarted);
}
zoom.event = function(g) {
g.each(function() {
var dispatch = event.of(this, arguments), view1 = view;
if (d3_transitionInheritId) {
d3.select(this).transition().each("start.zoom", function() {
view = this.__chart__ || {
x: 0,
y: 0,
k: 1
};
zoomstarted(dispatch);
}).tween("zoom:zoom", function() {
var dx = size[0], dy = size[1], cx = center0 ? center0[0] : dx / 2, cy = center0 ? center0[1] : dy / 2, i = d3.interpolateZoom([ (cx - view.x) / view.k, (cy - view.y) / view.k, dx / view.k ], [ (cx - view1.x) / view1.k, (cy - view1.y) / view1.k, dx / view1.k ]);
return function(t) {
var l = i(t), k = dx / l[2];
this.__chart__ = view = {
x: cx - l[0] * k,
y: cy - l[1] * k,
k: k
};
zoomed(dispatch);
};
}).each("interrupt.zoom", function() {
zoomended(dispatch);
}).each("end.zoom", function() {
zoomended(dispatch);
});
} else {
this.__chart__ = view;
zoomstarted(dispatch);
zoomed(dispatch);
zoomended(dispatch);
}
});
};
zoom.translate = function(_) {
if (!arguments.length) return [ view.x, view.y ];
view = {
x: +_[0],
y: +_[1],
k: view.k
};
rescale();
return zoom;
};
zoom.scale = function(_) {
if (!arguments.length) return view.k;
view = {
x: view.x,
y: view.y,
k: null
};
scaleTo(+_);
rescale();
return zoom;
};
zoom.scaleExtent = function(_) {
if (!arguments.length) return scaleExtent;
scaleExtent = _ == null ? d3_behavior_zoomInfinity : [ +_[0], +_[1] ];
return zoom;
};
zoom.center = function(_) {
if (!arguments.length) return center;
center = _ && [ +_[0], +_[1] ];
return zoom;
};
zoom.size = function(_) {
if (!arguments.length) return size;
size = _ && [ +_[0], +_[1] ];
return zoom;
};
zoom.duration = function(_) {
if (!arguments.length) return duration;
duration = +_;
return zoom;
};
zoom.x = function(z) {
if (!arguments.length) return x1;
x1 = z;
x0 = z.copy();
view = {
x: 0,
y: 0,
k: 1
};
return zoom;
};
zoom.y = function(z) {
if (!arguments.length) return y1;
y1 = z;
y0 = z.copy();
view = {
x: 0,
y: 0,
k: 1
};
return zoom;
};
function location(p) {
return [ (p[0] - view.x) / view.k, (p[1] - view.y) / view.k ];
}
function point(l) {
return [ l[0] * view.k + view.x, l[1] * view.k + view.y ];
}
function scaleTo(s) {
view.k = Math.max(scaleExtent[0], Math.min(scaleExtent[1], s));
}
function translateTo(p, l) {
l = point(l);
view.x += p[0] - l[0];
view.y += p[1] - l[1];
}
function zoomTo(that, p, l, k) {
that.__chart__ = {
x: view.x,
y: view.y,
k: view.k
};
scaleTo(Math.pow(2, k));
translateTo(center0 = p, l);
that = d3.select(that);
if (duration > 0) that = that.transition().duration(duration);
that.call(zoom.event);
}
function rescale() {
if (x1) x1.domain(x0.range().map(function(x) {
return (x - view.x) / view.k;
}).map(x0.invert));
if (y1) y1.domain(y0.range().map(function(y) {
return (y - view.y) / view.k;
}).map(y0.invert));
}
function zoomstarted(dispatch) {
if (!zooming++) dispatch({
type: "zoomstart"
});
}
function zoomed(dispatch) {
rescale();
dispatch({
type: "zoom",
scale: view.k,
translate: [ view.x, view.y ]
});
}
function zoomended(dispatch) {
if (!--zooming) dispatch({
type: "zoomend"
}), center0 = null;
}
function mousedowned() {
var that = this, dispatch = event.of(that, arguments), dragged = 0, subject = d3.select(d3_window(that)).on(mousemove, moved).on(mouseup, ended), location0 = location(d3.mouse(that)), dragRestore = d3_event_dragSuppress(that);
d3_selection_interrupt.call(that);
zoomstarted(dispatch);
function moved() {
dragged = 1;
translateTo(d3.mouse(that), location0);
zoomed(dispatch);
}
function ended() {
subject.on(mousemove, null).on(mouseup, null);
dragRestore(dragged);
zoomended(dispatch);
}
}
function touchstarted() {
var that = this, dispatch = event.of(that, arguments), locations0 = {}, distance0 = 0, scale0, zoomName = ".zoom-" + d3.event.changedTouches[0].identifier, touchmove = "touchmove" + zoomName, touchend = "touchend" + zoomName, targets = [], subject = d3.select(that), dragRestore = d3_event_dragSuppress(that);
started();
zoomstarted(dispatch);
subject.on(mousedown, null).on(touchstart, started);
function relocate() {
var touches = d3.touches(that);
scale0 = view.k;
touches.forEach(function(t) {
if (t.identifier in locations0) locations0[t.identifier] = location(t);
});
return touches;
}
function started() {
var target = d3.event.target;
d3.select(target).on(touchmove, moved).on(touchend, ended);
targets.push(target);
var changed = d3.event.changedTouches;
for (var i = 0, n = changed.length; i < n; ++i) {
locations0[changed[i].identifier] = null;
}
var touches = relocate(), now = Date.now();
if (touches.length === 1) {
if (now - touchtime < 500) {
var p = touches[0];
zoomTo(that, p, locations0[p.identifier], Math.floor(Math.log(view.k) / Math.LN2) + 1);
d3_eventPreventDefault();
}
touchtime = now;
} else if (touches.length > 1) {
var p = touches[0], q = touches[1], dx = p[0] - q[0], dy = p[1] - q[1];
distance0 = dx * dx + dy * dy;
}
}
function moved() {
var touches = d3.touches(that), p0, l0, p1, l1;
d3_selection_interrupt.call(that);
for (var i = 0, n = touches.length; i < n; ++i, l1 = null) {
p1 = touches[i];
if (l1 = locations0[p1.identifier]) {
if (l0) break;
p0 = p1, l0 = l1;
}
}
if (l1) {
var distance1 = (distance1 = p1[0] - p0[0]) * distance1 + (distance1 = p1[1] - p0[1]) * distance1, scale1 = distance0 && Math.sqrt(distance1 / distance0);
p0 = [ (p0[0] + p1[0]) / 2, (p0[1] + p1[1]) / 2 ];
l0 = [ (l0[0] + l1[0]) / 2, (l0[1] + l1[1]) / 2 ];
scaleTo(scale1 * scale0);
}
touchtime = null;
translateTo(p0, l0);
zoomed(dispatch);
}
function ended() {
if (d3.event.touches.length) {
var changed = d3.event.changedTouches;
for (var i = 0, n = changed.length; i < n; ++i) {
delete locations0[changed[i].identifier];
}
for (var identifier in locations0) {
return void relocate();
}
}
d3.selectAll(targets).on(zoomName, null);
subject.on(mousedown, mousedowned).on(touchstart, touchstarted);
dragRestore();
zoomended(dispatch);
}
}
function mousewheeled() {
var dispatch = event.of(this, arguments);
if (mousewheelTimer) clearTimeout(mousewheelTimer); else d3_selection_interrupt.call(this),
translate0 = location(center0 = center || d3.mouse(this)), zoomstarted(dispatch);
mousewheelTimer = setTimeout(function() {
mousewheelTimer = null;
zoomended(dispatch);
}, 50);
d3_eventPreventDefault();
scaleTo(Math.pow(2, d3_behavior_zoomDelta() * .002) * view.k);
translateTo(center0, translate0);
zoomed(dispatch);
}
function dblclicked() {
var p = d3.mouse(this), k = Math.log(view.k) / Math.LN2;
zoomTo(this, p, location(p), d3.event.shiftKey ? Math.ceil(k) - 1 : Math.floor(k) + 1);
}
return d3.rebind(zoom, event, "on");
};
var d3_behavior_zoomInfinity = [ 0, Infinity ], d3_behavior_zoomDelta, d3_behavior_zoomWheel;
d3.color = d3_color;
function d3_color() {}
d3_color.prototype.toString = function() {
return this.rgb() + "";
};
d3.hsl = d3_hsl;
function d3_hsl(h, s, l) {
return this instanceof d3_hsl ? void (this.h = +h, this.s = +s, this.l = +l) : arguments.length < 2 ? h instanceof d3_hsl ? new d3_hsl(h.h, h.s, h.l) : d3_rgb_parse("" + h, d3_rgb_hsl, d3_hsl) : new d3_hsl(h, s, l);
}
var d3_hslPrototype = d3_hsl.prototype = new d3_color();
d3_hslPrototype.brighter = function(k) {
k = Math.pow(.7, arguments.length ? k : 1);
return new d3_hsl(this.h, this.s, this.l / k);
};
d3_hslPrototype.darker = function(k) {
k = Math.pow(.7, arguments.length ? k : 1);
return new d3_hsl(this.h, this.s, k * this.l);
};
d3_hslPrototype.rgb = function() {
return d3_hsl_rgb(this.h, this.s, this.l);
};
function d3_hsl_rgb(h, s, l) {
var m1, m2;
h = isNaN(h) ? 0 : (h %= 360) < 0 ? h + 360 : h;
s = isNaN(s) ? 0 : s < 0 ? 0 : s > 1 ? 1 : s;
l = l < 0 ? 0 : l > 1 ? 1 : l;
m2 = l <= .5 ? l * (1 + s) : l + s - l * s;
m1 = 2 * l - m2;
function v(h) {
if (h > 360) h -= 360; else if (h < 0) h += 360;
if (h < 60) return m1 + (m2 - m1) * h / 60;
if (h < 180) return m2;
if (h < 240) return m1 + (m2 - m1) * (240 - h) / 60;
return m1;
}
function vv(h) {
return Math.round(v(h) * 255);
}
return new d3_rgb(vv(h + 120), vv(h), vv(h - 120));
}
d3.hcl = d3_hcl;
function d3_hcl(h, c, l) {
return this instanceof d3_hcl ? void (this.h = +h, this.c = +c, this.l = +l) : arguments.length < 2 ? h instanceof d3_hcl ? new d3_hcl(h.h, h.c, h.l) : h instanceof d3_lab ? d3_lab_hcl(h.l, h.a, h.b) : d3_lab_hcl((h = d3_rgb_lab((h = d3.rgb(h)).r, h.g, h.b)).l, h.a, h.b) : new d3_hcl(h, c, l);
}
var d3_hclPrototype = d3_hcl.prototype = new d3_color();
d3_hclPrototype.brighter = function(k) {
return new d3_hcl(this.h, this.c, Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)));
};
d3_hclPrototype.darker = function(k) {
return new d3_hcl(this.h, this.c, Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)));
};
d3_hclPrototype.rgb = function() {
return d3_hcl_lab(this.h, this.c, this.l).rgb();
};
function d3_hcl_lab(h, c, l) {
if (isNaN(h)) h = 0;
if (isNaN(c)) c = 0;
return new d3_lab(l, Math.cos(h *= d3_radians) * c, Math.sin(h) * c);
}
d3.lab = d3_lab;
function d3_lab(l, a, b) {
return this instanceof d3_lab ? void (this.l = +l, this.a = +a, this.b = +b) : arguments.length < 2 ? l instanceof d3_lab ? new d3_lab(l.l, l.a, l.b) : l instanceof d3_hcl ? d3_hcl_lab(l.h, l.c, l.l) : d3_rgb_lab((l = d3_rgb(l)).r, l.g, l.b) : new d3_lab(l, a, b);
}
var d3_lab_K = 18;
var d3_lab_X = .95047, d3_lab_Y = 1, d3_lab_Z = 1.08883;
var d3_labPrototype = d3_lab.prototype = new d3_color();
d3_labPrototype.brighter = function(k) {
return new d3_lab(Math.min(100, this.l + d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
};
d3_labPrototype.darker = function(k) {
return new d3_lab(Math.max(0, this.l - d3_lab_K * (arguments.length ? k : 1)), this.a, this.b);
};
d3_labPrototype.rgb = function() {
return d3_lab_rgb(this.l, this.a, this.b);
};
function d3_lab_rgb(l, a, b) {
var y = (l + 16) / 116, x = y + a / 500, z = y - b / 200;
x = d3_lab_xyz(x) * d3_lab_X;
y = d3_lab_xyz(y) * d3_lab_Y;
z = d3_lab_xyz(z) * d3_lab_Z;
return new d3_rgb(d3_xyz_rgb(3.2404542 * x - 1.5371385 * y - .4985314 * z), d3_xyz_rgb(-.969266 * x + 1.8760108 * y + .041556 * z), d3_xyz_rgb(.0556434 * x - .2040259 * y + 1.0572252 * z));
}
function d3_lab_hcl(l, a, b) {
return l > 0 ? new d3_hcl(Math.atan2(b, a) * d3_degrees, Math.sqrt(a * a + b * b), l) : new d3_hcl(NaN, NaN, l);
}
function d3_lab_xyz(x) {
return x > .206893034 ? x * x * x : (x - 4 / 29) / 7.787037;
}
function d3_xyz_lab(x) {
return x > .008856 ? Math.pow(x, 1 / 3) : 7.787037 * x + 4 / 29;
}
function d3_xyz_rgb(r) {
return Math.round(255 * (r <= .00304 ? 12.92 * r : 1.055 * Math.pow(r, 1 / 2.4) - .055));
}
d3.rgb = d3_rgb;
function d3_rgb(r, g, b) {
return this instanceof d3_rgb ? void (this.r = ~~r, this.g = ~~g, this.b = ~~b) : arguments.length < 2 ? r instanceof d3_rgb ? new d3_rgb(r.r, r.g, r.b) : d3_rgb_parse("" + r, d3_rgb, d3_hsl_rgb) : new d3_rgb(r, g, b);
}
function d3_rgbNumber(value) {
return new d3_rgb(value >> 16, value >> 8 & 255, value & 255);
}
function d3_rgbString(value) {
return d3_rgbNumber(value) + "";
}
var d3_rgbPrototype = d3_rgb.prototype = new d3_color();
d3_rgbPrototype.brighter = function(k) {
k = Math.pow(.7, arguments.length ? k : 1);
var r = this.r, g = this.g, b = this.b, i = 30;
if (!r && !g && !b) return new d3_rgb(i, i, i);
if (r && r < i) r = i;
if (g && g < i) g = i;
if (b && b < i) b = i;
return new d3_rgb(Math.min(255, r / k), Math.min(255, g / k), Math.min(255, b / k));
};
d3_rgbPrototype.darker = function(k) {
k = Math.pow(.7, arguments.length ? k : 1);
return new d3_rgb(k * this.r, k * this.g, k * this.b);
};
d3_rgbPrototype.hsl = function() {
return d3_rgb_hsl(this.r, this.g, this.b);
};
d3_rgbPrototype.toString = function() {
return "#" + d3_rgb_hex(this.r) + d3_rgb_hex(this.g) + d3_rgb_hex(this.b);
};
function d3_rgb_hex(v) {
return v < 16 ? "0" + Math.max(0, v).toString(16) : Math.min(255, v).toString(16);
}
function d3_rgb_parse(format, rgb, hsl) {
var r = 0, g = 0, b = 0, m1, m2, color;
m1 = /([a-z]+)\((.*)\)/.exec(format = format.toLowerCase());
if (m1) {
m2 = m1[2].split(",");
switch (m1[1]) {
case "hsl":
{
return hsl(parseFloat(m2[0]), parseFloat(m2[1]) / 100, parseFloat(m2[2]) / 100);
}
case "rgb":
{
return rgb(d3_rgb_parseNumber(m2[0]), d3_rgb_parseNumber(m2[1]), d3_rgb_parseNumber(m2[2]));
}
}
}
if (color = d3_rgb_names.get(format)) {
return rgb(color.r, color.g, color.b);
}
if (format != null && format.charAt(0) === "#" && !isNaN(color = parseInt(format.slice(1), 16))) {
if (format.length === 4) {
r = (color & 3840) >> 4;
r = r >> 4 | r;
g = color & 240;
g = g >> 4 | g;
b = color & 15;
b = b << 4 | b;
} else if (format.length === 7) {
r = (color & 16711680) >> 16;
g = (color & 65280) >> 8;
b = color & 255;
}
}
return rgb(r, g, b);
}
function d3_rgb_hsl(r, g, b) {
var min = Math.min(r /= 255, g /= 255, b /= 255), max = Math.max(r, g, b), d = max - min, h, s, l = (max + min) / 2;
if (d) {
s = l < .5 ? d / (max + min) : d / (2 - max - min);
if (r == max) h = (g - b) / d + (g < b ? 6 : 0); else if (g == max) h = (b - r) / d + 2; else h = (r - g) / d + 4;
h *= 60;
} else {
h = NaN;
s = l > 0 && l < 1 ? 0 : h;
}
return new d3_hsl(h, s, l);
}
function d3_rgb_lab(r, g, b) {
r = d3_rgb_xyz(r);
g = d3_rgb_xyz(g);
b = d3_rgb_xyz(b);
var x = d3_xyz_lab((.4124564 * r + .3575761 * g + .1804375 * b) / d3_lab_X), y = d3_xyz_lab((.2126729 * r + .7151522 * g + .072175 * b) / d3_lab_Y), z = d3_xyz_lab((.0193339 * r + .119192 * g + .9503041 * b) / d3_lab_Z);
return d3_lab(116 * y - 16, 500 * (x - y), 200 * (y - z));
}
function d3_rgb_xyz(r) {
return (r /= 255) <= .04045 ? r / 12.92 : Math.pow((r + .055) / 1.055, 2.4);
}
function d3_rgb_parseNumber(c) {
var f = parseFloat(c);
return c.charAt(c.length - 1) === "%" ? Math.round(f * 2.55) : f;
}
var d3_rgb_names = d3.map({
aliceblue: 15792383,
antiquewhite: 16444375,
aqua: 65535,
aquamarine: 8388564,
azure: 15794175,
beige: 16119260,
bisque: 16770244,
black: 0,
blanchedalmond: 16772045,
blue: 255,
blueviolet: 9055202,
brown: 10824234,
burlywood: 14596231,
cadetblue: 6266528,
chartreuse: 8388352,
chocolate: 13789470,
coral: 16744272,
cornflowerblue: 6591981,
cornsilk: 16775388,
crimson: 14423100,
cyan: 65535,
darkblue: 139,
darkcyan: 35723,
darkgoldenrod: 12092939,
darkgray: 11119017,
darkgreen: 25600,
darkgrey: 11119017,
darkkhaki: 12433259,
darkmagenta: 9109643,
darkolivegreen: 5597999,
darkorange: 16747520,
darkorchid: 10040012,
darkred: 9109504,
darksalmon: 15308410,
darkseagreen: 9419919,
darkslateblue: 4734347,
darkslategray: 3100495,
darkslategrey: 3100495,
darkturquoise: 52945,
darkviolet: 9699539,
deeppink: 16716947,
deepskyblue: 49151,
dimgray: 6908265,
dimgrey: 6908265,
dodgerblue: 2003199,
firebrick: 11674146,
floralwhite: 16775920,
forestgreen: 2263842,
fuchsia: 16711935,
gainsboro: 14474460,
ghostwhite: 16316671,
gold: 16766720,
goldenrod: 14329120,
gray: 8421504,
green: 32768,
greenyellow: 11403055,
grey: 8421504,
honeydew: 15794160,
hotpink: 16738740,
indianred: 13458524,
indigo: 4915330,
ivory: 16777200,
khaki: 15787660,
lavender: 15132410,
lavenderblush: 16773365,
lawngreen: 8190976,
lemonchiffon: 16775885,
lightblue: 11393254,
lightcoral: 15761536,
lightcyan: 14745599,
lightgoldenrodyellow: 16448210,
lightgray: 13882323,
lightgreen: 9498256,
lightgrey: 13882323,
lightpink: 16758465,
lightsalmon: 16752762,
lightseagreen: 2142890,
lightskyblue: 8900346,
lightslategray: 7833753,
lightslategrey: 7833753,
lightsteelblue: 11584734,
lightyellow: 16777184,
lime: 65280,
limegreen: 3329330,
linen: 16445670,
magenta: 16711935,
maroon: 8388608,
mediumaquamarine: 6737322,
mediumblue: 205,
mediumorchid: 12211667,
mediumpurple: 9662683,
mediumseagreen: 3978097,
mediumslateblue: 8087790,
mediumspringgreen: 64154,
mediumturquoise: 4772300,
mediumvioletred: 13047173,
midnightblue: 1644912,
mintcream: 16121850,
mistyrose: 16770273,
moccasin: 16770229,
navajowhite: 16768685,
navy: 128,
oldlace: 16643558,
olive: 8421376,
olivedrab: 7048739,
orange: 16753920,
orangered: 16729344,
orchid: 14315734,
palegoldenrod: 15657130,
palegreen: 10025880,
paleturquoise: 11529966,
palevioletred: 14381203,
papayawhip: 16773077,
peachpuff: 16767673,
peru: 13468991,
pink: 16761035,
plum: 14524637,
powderblue: 11591910,
purple: 8388736,
rebeccapurple: 6697881,
red: 16711680,
rosybrown: 12357519,
royalblue: 4286945,
saddlebrown: 9127187,
salmon: 16416882,
sandybrown: 16032864,
seagreen: 3050327,
seashell: 16774638,
sienna: 10506797,
silver: 12632256,
skyblue: 8900331,
slateblue: 6970061,
slategray: 7372944,
slategrey: 7372944,
snow: 16775930,
springgreen: 65407,
steelblue: 4620980,
tan: 13808780,
teal: 32896,
thistle: 14204888,
tomato: 16737095,
turquoise: 4251856,
violet: 15631086,
wheat: 16113331,
white: 16777215,
whitesmoke: 16119285,
yellow: 16776960,
yellowgreen: 10145074
});
d3_rgb_names.forEach(function(key, value) {
d3_rgb_names.set(key, d3_rgbNumber(value));
});
function d3_functor(v) {
return typeof v === "function" ? v : function() {
return v;
};
}
d3.functor = d3_functor;
d3.xhr = d3_xhrType(d3_identity);
function d3_xhrType(response) {
return function(url, mimeType, callback) {
if (arguments.length === 2 && typeof mimeType === "function") callback = mimeType,
mimeType = null;
return d3_xhr(url, mimeType, response, callback);
};
}
function d3_xhr(url, mimeType, response, callback) {
var xhr = {}, dispatch = d3.dispatch("beforesend", "progress", "load", "error"), headers = {}, request = new XMLHttpRequest(), responseType = null;
if (self.XDomainRequest && !("withCredentials" in request) && /^(http(s)?:)?\/\//.test(url)) request = new XDomainRequest();
"onload" in request ? request.onload = request.onerror = respond : request.onreadystatechange = function() {
request.readyState > 3 && respond();
};
function respond() {
var status = request.status, result;
if (!status && d3_xhrHasResponse(request) || status >= 200 && status < 300 || status === 304) {
try {
result = response.call(xhr, request);
} catch (e) {
dispatch.error.call(xhr, e);
return;
}
dispatch.load.call(xhr, result);
} else {
dispatch.error.call(xhr, request);
}
}
request.onprogress = function(event) {
var o = d3.event;
d3.event = event;
try {
dispatch.progress.call(xhr, request);
} finally {
d3.event = o;
}
};
xhr.header = function(name, value) {
name = (name + "").toLowerCase();
if (arguments.length < 2) return headers[name];
if (value == null) delete headers[name]; else headers[name] = value + "";
return xhr;
};
xhr.mimeType = function(value) {
if (!arguments.length) return mimeType;
mimeType = value == null ? null : value + "";
return xhr;
};
xhr.responseType = function(value) {
if (!arguments.length) return responseType;
responseType = value;
return xhr;
};
xhr.response = function(value) {
response = value;
return xhr;
};
[ "get", "post" ].forEach(function(method) {
xhr[method] = function() {
return xhr.send.apply(xhr, [ method ].concat(d3_array(arguments)));
};
});
xhr.send = function(method, data, callback) {
if (arguments.length === 2 && typeof data === "function") callback = data, data = null;
request.open(method, url, true);
if (mimeType != null && !("accept" in headers)) headers["accept"] = mimeType + ",*/*";
if (request.setRequestHeader) for (var name in headers) request.setRequestHeader(name, headers[name]);
if (mimeType != null && request.overrideMimeType) request.overrideMimeType(mimeType);
if (responseType != null) request.responseType = responseType;
if (callback != null) xhr.on("error", callback).on("load", function(request) {
callback(null, request);
});
dispatch.beforesend.call(xhr, request);
request.send(data == null ? null : data);
return xhr;
};
xhr.abort = function() {
request.abort();
return xhr;
};
d3.rebind(xhr, dispatch, "on");
return callback == null ? xhr : xhr.get(d3_xhr_fixCallback(callback));
}
function d3_xhr_fixCallback(callback) {
return callback.length === 1 ? function(error, request) {
callback(error == null ? request : null);
} : callback;
}
function d3_xhrHasResponse(request) {
var type = request.responseType;
return type && type !== "text" ? request.response : request.responseText;
}
d3.dsv = function(delimiter, mimeType) {
var reFormat = new RegExp('["' + delimiter + "\n]"), delimiterCode = delimiter.charCodeAt(0);
function dsv(url, row, callback) {
if (arguments.length < 3) callback = row, row = null;
var xhr = d3_xhr(url, mimeType, row == null ? response : typedResponse(row), callback);
xhr.row = function(_) {
return arguments.length ? xhr.response((row = _) == null ? response : typedResponse(_)) : row;
};
return xhr;
}
function response(request) {
return dsv.parse(request.responseText);
}
function typedResponse(f) {
return function(request) {
return dsv.parse(request.responseText, f);
};
}
dsv.parse = function(text, f) {
var o;
return dsv.parseRows(text, function(row, i) {
if (o) return o(row, i - 1);
var a = function(d) {
var obj = {};
var len = row.length;
for (var k = 0; k < len; ++k) {
obj[row[k]] = d[k];
}
return obj;
};
o = f ? function(row, i) {
return f(a(row), i);
} : a;
});
};
dsv.parseRows = function(text, f) {
var EOL = {}, EOF = {}, rows = [], N = text.length, I = 0, n = 0, t, eol;
function token() {
if (I >= N) return EOF;
if (eol) return eol = false, EOL;
var j = I;
if (text.charCodeAt(j) === 34) {
var i = j;
while (i++ < N) {
if (text.charCodeAt(i) === 34) {
if (text.charCodeAt(i + 1) !== 34) break;
++i;
}
}
I = i + 2;
var c = text.charCodeAt(i + 1);
if (c === 13) {
eol = true;
if (text.charCodeAt(i + 2) === 10) ++I;
} else if (c === 10) {
eol = true;
}
return text.slice(j + 1, i).replace(/""/g, '"');
}
while (I < N) {
var c = text.charCodeAt(I++), k = 1;
if (c === 10) eol = true; else if (c === 13) {
eol = true;
if (text.charCodeAt(I) === 10) ++I, ++k;
} else if (c !== delimiterCode) continue;
return text.slice(j, I - k);
}
return text.slice(j);
}
while ((t = token()) !== EOF) {
var a = [];
while (t !== EOL && t !== EOF) {
a.push(t);
t = token();
}
if (f && (a = f(a, n++)) == null) continue;
rows.push(a);
}
return rows;
};
dsv.format = function(rows) {
if (Array.isArray(rows[0])) return dsv.formatRows(rows);
var fieldSet = new d3_Set(), fields = [];
rows.forEach(function(row) {
for (var field in row) {
if (!fieldSet.has(field)) {
fields.push(fieldSet.add(field));
}
}
});
return [ fields.map(formatValue).join(delimiter) ].concat(rows.map(function(row) {
return fields.map(function(field) {
return formatValue(row[field]);
}).join(delimiter);
})).join("\n");
};
dsv.formatRows = function(rows) {
return rows.map(formatRow).join("\n");
};
function formatRow(row) {
return row.map(formatValue).join(delimiter);
}
function formatValue(text) {
return reFormat.test(text) ? '"' + text.replace(/\"/g, '""') + '"' : text;
}
return dsv;
};
d3.csv = d3.dsv(",", "text/csv");
d3.tsv = d3.dsv(" ", "text/tab-separated-values");
var d3_timer_queueHead, d3_timer_queueTail, d3_timer_interval, d3_timer_timeout, d3_timer_frame = this[d3_vendorSymbol(this, "requestAnimationFrame")] || function(callback) {
setTimeout(callback, 17);
};
d3.timer = function() {
d3_timer.apply(this, arguments);
};
function d3_timer(callback, delay, then) {
var n = arguments.length;
if (n < 2) delay = 0;
if (n < 3) then = Date.now();
var time = then + delay, timer = {
c: callback,
t: time,
n: null
};
if (d3_timer_queueTail) d3_timer_queueTail.n = timer; else d3_timer_queueHead = timer;
d3_timer_queueTail = timer;
if (!d3_timer_interval) {
d3_timer_timeout = clearTimeout(d3_timer_timeout);
d3_timer_interval = 1;
d3_timer_frame(d3_timer_step);
}
return timer;
}
function d3_timer_step() {
var now = d3_timer_mark(), delay = d3_timer_sweep() - now;
if (delay > 24) {
if (isFinite(delay)) {
clearTimeout(d3_timer_timeout);
d3_timer_timeout = setTimeout(d3_timer_step, delay);
}
d3_timer_interval = 0;
} else {
d3_timer_interval = 1;
d3_timer_frame(d3_timer_step);
}
}
d3.timer.flush = function() {
d3_timer_mark();
d3_timer_sweep();
};
function d3_timer_mark() {
var now = Date.now(), timer = d3_timer_queueHead;
while (timer) {
if (now >= timer.t && timer.c(now - timer.t)) timer.c = null;
timer = timer.n;
}
return now;
}
function d3_timer_sweep() {
var t0, t1 = d3_timer_queueHead, time = Infinity;
while (t1) {
if (t1.c) {
if (t1.t < time) time = t1.t;
t1 = (t0 = t1).n;
} else {
t1 = t0 ? t0.n = t1.n : d3_timer_queueHead = t1.n;
}
}
d3_timer_queueTail = t0;
return time;
}
d3.round = function(x, n) {
return n ? Math.round(x * (n = Math.pow(10, n))) / n : Math.round(x);
};
d3.geom = {};
function d3_geom_pointX(d) {
return d[0];
}
function d3_geom_pointY(d) {
return d[1];
}
d3.geom.hull = function(vertices) {
var x = d3_geom_pointX, y = d3_geom_pointY;
if (arguments.length) return hull(vertices);
function hull(data) {
if (data.length < 3) return [];
var fx = d3_functor(x), fy = d3_functor(y), i, n = data.length, points = [], flippedPoints = [];
for (i = 0; i < n; i++) {
points.push([ +fx.call(this, data[i], i), +fy.call(this, data[i], i), i ]);
}
points.sort(d3_geom_hullOrder);
for (i = 0; i < n; i++) flippedPoints.push([ points[i][0], -points[i][1] ]);
var upper = d3_geom_hullUpper(points), lower = d3_geom_hullUpper(flippedPoints);
var skipLeft = lower[0] === upper[0], skipRight = lower[lower.length - 1] === upper[upper.length - 1], polygon = [];
for (i = upper.length - 1; i >= 0; --i) polygon.push(data[points[upper[i]][2]]);
for (i = +skipLeft; i < lower.length - skipRight; ++i) polygon.push(data[points[lower[i]][2]]);
return polygon;
}
hull.x = function(_) {
return arguments.length ? (x = _, hull) : x;
};
hull.y = function(_) {
return arguments.length ? (y = _, hull) : y;
};
return hull;
};
function d3_geom_hullUpper(points) {
var n = points.length, hull = [ 0, 1 ], hs = 2;
for (var i = 2; i < n; i++) {
while (hs > 1 && d3_cross2d(points[hull[hs - 2]], points[hull[hs - 1]], points[i]) <= 0) --hs;
hull[hs++] = i;
}
return hull.slice(0, hs);
}
function d3_geom_hullOrder(a, b) {
return a[0] - b[0] || a[1] - b[1];
}
d3.geom.polygon = function(coordinates) {
d3_subclass(coordinates, d3_geom_polygonPrototype);
return coordinates;
};
var d3_geom_polygonPrototype = d3.geom.polygon.prototype = [];
d3_geom_polygonPrototype.area = function() {
var i = -1, n = this.length, a, b = this[n - 1], area = 0;
while (++i < n) {
a = b;
b = this[i];
area += a[1] * b[0] - a[0] * b[1];
}
return area * .5;
};
d3_geom_polygonPrototype.centroid = function(k) {
var i = -1, n = this.length, x = 0, y = 0, a, b = this[n - 1], c;
if (!arguments.length) k = -1 / (6 * this.area());
while (++i < n) {
a = b;
b = this[i];
c = a[0] * b[1] - b[0] * a[1];
x += (a[0] + b[0]) * c;
y += (a[1] + b[1]) * c;
}
return [ x * k, y * k ];
};
d3_geom_polygonPrototype.clip = function(subject) {
var input, closed = d3_geom_polygonClosed(subject), i = -1, n = this.length - d3_geom_polygonClosed(this), j, m, a = this[n - 1], b, c, d;
while (++i < n) {
input = subject.slice();
subject.length = 0;
b = this[i];
c = input[(m = input.length - closed) - 1];
j = -1;
while (++j < m) {
d = input[j];
if (d3_geom_polygonInside(d, a, b)) {
if (!d3_geom_polygonInside(c, a, b)) {
subject.push(d3_geom_polygonIntersect(c, d, a, b));
}
subject.push(d);
} else if (d3_geom_polygonInside(c, a, b)) {
subject.push(d3_geom_polygonIntersect(c, d, a, b));
}
c = d;
}
if (closed) subject.push(subject[0]);
a = b;
}
return subject;
};
function d3_geom_polygonInside(p, a, b) {
return (b[0] - a[0]) * (p[1] - a[1]) < (b[1] - a[1]) * (p[0] - a[0]);
}
function d3_geom_polygonIntersect(c, d, a, b) {
var x1 = c[0], x3 = a[0], x21 = d[0] - x1, x43 = b[0] - x3, y1 = c[1], y3 = a[1], y21 = d[1] - y1, y43 = b[1] - y3, ua = (x43 * (y1 - y3) - y43 * (x1 - x3)) / (y43 * x21 - x43 * y21);
return [ x1 + ua * x21, y1 + ua * y21 ];
}
function d3_geom_polygonClosed(coordinates) {
var a = coordinates[0], b = coordinates[coordinates.length - 1];
return !(a[0] - b[0] || a[1] - b[1]);
}
var d3_geom_voronoiEdges, d3_geom_voronoiCells, d3_geom_voronoiBeaches, d3_geom_voronoiBeachPool = [], d3_geom_voronoiFirstCircle, d3_geom_voronoiCircles, d3_geom_voronoiCirclePool = [];
function d3_geom_voronoiBeach() {
d3_geom_voronoiRedBlackNode(this);
this.edge = this.site = this.circle = null;
}
function d3_geom_voronoiCreateBeach(site) {
var beach = d3_geom_voronoiBeachPool.pop() || new d3_geom_voronoiBeach();
beach.site = site;
return beach;
}
function d3_geom_voronoiDetachBeach(beach) {
d3_geom_voronoiDetachCircle(beach);
d3_geom_voronoiBeaches.remove(beach);
d3_geom_voronoiBeachPool.push(beach);
d3_geom_voronoiRedBlackNode(beach);
}
function d3_geom_voronoiRemoveBeach(beach) {
var circle = beach.circle, x = circle.x, y = circle.cy, vertex = {
x: x,
y: y
}, previous = beach.P, next = beach.N, disappearing = [ beach ];
d3_geom_voronoiDetachBeach(beach);
var lArc = previous;
while (lArc.circle && abs(x - lArc.circle.x) < ε && abs(y - lArc.circle.cy) < ε) {
previous = lArc.P;
disappearing.unshift(lArc);
d3_geom_voronoiDetachBeach(lArc);
lArc = previous;
}
disappearing.unshift(lArc);
d3_geom_voronoiDetachCircle(lArc);
var rArc = next;
while (rArc.circle && abs(x - rArc.circle.x) < ε && abs(y - rArc.circle.cy) < ε) {
next = rArc.N;
disappearing.push(rArc);
d3_geom_voronoiDetachBeach(rArc);
rArc = next;
}
disappearing.push(rArc);
d3_geom_voronoiDetachCircle(rArc);
var nArcs = disappearing.length, iArc;
for (iArc = 1; iArc < nArcs; ++iArc) {
rArc = disappearing[iArc];
lArc = disappearing[iArc - 1];
d3_geom_voronoiSetEdgeEnd(rArc.edge, lArc.site, rArc.site, vertex);
}
lArc = disappearing[0];
rArc = disappearing[nArcs - 1];
rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, rArc.site, null, vertex);
d3_geom_voronoiAttachCircle(lArc);
d3_geom_voronoiAttachCircle(rArc);
}
function d3_geom_voronoiAddBeach(site) {
var x = site.x, directrix = site.y, lArc, rArc, dxl, dxr, node = d3_geom_voronoiBeaches._;
while (node) {
dxl = d3_geom_voronoiLeftBreakPoint(node, directrix) - x;
if (dxl > ε) node = node.L; else {
dxr = x - d3_geom_voronoiRightBreakPoint(node, directrix);
if (dxr > ε) {
if (!node.R) {
lArc = node;
break;
}
node = node.R;
} else {
if (dxl > -ε) {
lArc = node.P;
rArc = node;
} else if (dxr > -ε) {
lArc = node;
rArc = node.N;
} else {
lArc = rArc = node;
}
break;
}
}
}
var newArc = d3_geom_voronoiCreateBeach(site);
d3_geom_voronoiBeaches.insert(lArc, newArc);
if (!lArc && !rArc) return;
if (lArc === rArc) {
d3_geom_voronoiDetachCircle(lArc);
rArc = d3_geom_voronoiCreateBeach(lArc.site);
d3_geom_voronoiBeaches.insert(newArc, rArc);
newArc.edge = rArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
d3_geom_voronoiAttachCircle(lArc);
d3_geom_voronoiAttachCircle(rArc);
return;
}
if (!rArc) {
newArc.edge = d3_geom_voronoiCreateEdge(lArc.site, newArc.site);
return;
}
d3_geom_voronoiDetachCircle(lArc);
d3_geom_voronoiDetachCircle(rArc);
var lSite = lArc.site, ax = lSite.x, ay = lSite.y, bx = site.x - ax, by = site.y - ay, rSite = rArc.site, cx = rSite.x - ax, cy = rSite.y - ay, d = 2 * (bx * cy - by * cx), hb = bx * bx + by * by, hc = cx * cx + cy * cy, vertex = {
x: (cy * hb - by * hc) / d + ax,
y: (bx * hc - cx * hb) / d + ay
};
d3_geom_voronoiSetEdgeEnd(rArc.edge, lSite, rSite, vertex);
newArc.edge = d3_geom_voronoiCreateEdge(lSite, site, null, vertex);
rArc.edge = d3_geom_voronoiCreateEdge(site, rSite, null, vertex);
d3_geom_voronoiAttachCircle(lArc);
d3_geom_voronoiAttachCircle(rArc);
}
function d3_geom_voronoiLeftBreakPoint(arc, directrix) {
var site = arc.site, rfocx = site.x, rfocy = site.y, pby2 = rfocy - directrix;
if (!pby2) return rfocx;
var lArc = arc.P;
if (!lArc) return -Infinity;
site = lArc.site;
var lfocx = site.x, lfocy = site.y, plby2 = lfocy - directrix;
if (!plby2) return lfocx;
var hl = lfocx - rfocx, aby2 = 1 / pby2 - 1 / plby2, b = hl / plby2;
if (aby2) return (-b + Math.sqrt(b * b - 2 * aby2 * (hl * hl / (-2 * plby2) - lfocy + plby2 / 2 + rfocy - pby2 / 2))) / aby2 + rfocx;
return (rfocx + lfocx) / 2;
}
function d3_geom_voronoiRightBreakPoint(arc, directrix) {
var rArc = arc.N;
if (rArc) return d3_geom_voronoiLeftBreakPoint(rArc, directrix);
var site = arc.site;
return site.y === directrix ? site.x : Infinity;
}
function d3_geom_voronoiCell(site) {
this.site = site;
this.edges = [];
}
d3_geom_voronoiCell.prototype.prepare = function() {
var halfEdges = this.edges, iHalfEdge = halfEdges.length, edge;
while (iHalfEdge--) {
edge = halfEdges[iHalfEdge].edge;
if (!edge.b || !edge.a) halfEdges.splice(iHalfEdge, 1);
}
halfEdges.sort(d3_geom_voronoiHalfEdgeOrder);
return halfEdges.length;
};
function d3_geom_voronoiCloseCells(extent) {
var x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], x2, y2, x3, y3, cells = d3_geom_voronoiCells, iCell = cells.length, cell, iHalfEdge, halfEdges, nHalfEdges, start, end;
while (iCell--) {
cell = cells[iCell];
if (!cell || !cell.prepare()) continue;
halfEdges = cell.edges;
nHalfEdges = halfEdges.length;
iHalfEdge = 0;
while (iHalfEdge < nHalfEdges) {
end = halfEdges[iHalfEdge].end(), x3 = end.x, y3 = end.y;
start = halfEdges[++iHalfEdge % nHalfEdges].start(), x2 = start.x, y2 = start.y;
if (abs(x3 - x2) > ε || abs(y3 - y2) > ε) {
halfEdges.splice(iHalfEdge, 0, new d3_geom_voronoiHalfEdge(d3_geom_voronoiCreateBorderEdge(cell.site, end, abs(x3 - x0) < ε && y1 - y3 > ε ? {
x: x0,
y: abs(x2 - x0) < ε ? y2 : y1
} : abs(y3 - y1) < ε && x1 - x3 > ε ? {
x: abs(y2 - y1) < ε ? x2 : x1,
y: y1
} : abs(x3 - x1) < ε && y3 - y0 > ε ? {
x: x1,
y: abs(x2 - x1) < ε ? y2 : y0
} : abs(y3 - y0) < ε && x3 - x0 > ε ? {
x: abs(y2 - y0) < ε ? x2 : x0,
y: y0
} : null), cell.site, null));
++nHalfEdges;
}
}
}
}
function d3_geom_voronoiHalfEdgeOrder(a, b) {
return b.angle - a.angle;
}
function d3_geom_voronoiCircle() {
d3_geom_voronoiRedBlackNode(this);
this.x = this.y = this.arc = this.site = this.cy = null;
}
function d3_geom_voronoiAttachCircle(arc) {
var lArc = arc.P, rArc = arc.N;
if (!lArc || !rArc) return;
var lSite = lArc.site, cSite = arc.site, rSite = rArc.site;
if (lSite === rSite) return;
var bx = cSite.x, by = cSite.y, ax = lSite.x - bx, ay = lSite.y - by, cx = rSite.x - bx, cy = rSite.y - by;
var d = 2 * (ax * cy - ay * cx);
if (d >= -ε2) return;
var ha = ax * ax + ay * ay, hc = cx * cx + cy * cy, x = (cy * ha - ay * hc) / d, y = (ax * hc - cx * ha) / d, cy = y + by;
var circle = d3_geom_voronoiCirclePool.pop() || new d3_geom_voronoiCircle();
circle.arc = arc;
circle.site = cSite;
circle.x = x + bx;
circle.y = cy + Math.sqrt(x * x + y * y);
circle.cy = cy;
arc.circle = circle;
var before = null, node = d3_geom_voronoiCircles._;
while (node) {
if (circle.y < node.y || circle.y === node.y && circle.x <= node.x) {
if (node.L) node = node.L; else {
before = node.P;
break;
}
} else {
if (node.R) node = node.R; else {
before = node;
break;
}
}
}
d3_geom_voronoiCircles.insert(before, circle);
if (!before) d3_geom_voronoiFirstCircle = circle;
}
function d3_geom_voronoiDetachCircle(arc) {
var circle = arc.circle;
if (circle) {
if (!circle.P) d3_geom_voronoiFirstCircle = circle.N;
d3_geom_voronoiCircles.remove(circle);
d3_geom_voronoiCirclePool.push(circle);
d3_geom_voronoiRedBlackNode(circle);
arc.circle = null;
}
}
function d3_geom_clipLine(x0, y0, x1, y1) {
return function(line) {
var a = line.a, b = line.b, ax = a.x, ay = a.y, bx = b.x, by = b.y, t0 = 0, t1 = 1, dx = bx - ax, dy = by - ay, r;
r = x0 - ax;
if (!dx && r > 0) return;
r /= dx;
if (dx < 0) {
if (r < t0) return;
if (r < t1) t1 = r;
} else if (dx > 0) {
if (r > t1) return;
if (r > t0) t0 = r;
}
r = x1 - ax;
if (!dx && r < 0) return;
r /= dx;
if (dx < 0) {
if (r > t1) return;
if (r > t0) t0 = r;
} else if (dx > 0) {
if (r < t0) return;
if (r < t1) t1 = r;
}
r = y0 - ay;
if (!dy && r > 0) return;
r /= dy;
if (dy < 0) {
if (r < t0) return;
if (r < t1) t1 = r;
} else if (dy > 0) {
if (r > t1) return;
if (r > t0) t0 = r;
}
r = y1 - ay;
if (!dy && r < 0) return;
r /= dy;
if (dy < 0) {
if (r > t1) return;
if (r > t0) t0 = r;
} else if (dy > 0) {
if (r < t0) return;
if (r < t1) t1 = r;
}
if (t0 > 0) line.a = {
x: ax + t0 * dx,
y: ay + t0 * dy
};
if (t1 < 1) line.b = {
x: ax + t1 * dx,
y: ay + t1 * dy
};
return line;
};
}
function d3_geom_voronoiClipEdges(extent) {
var edges = d3_geom_voronoiEdges, clip = d3_geom_clipLine(extent[0][0], extent[0][1], extent[1][0], extent[1][1]), i = edges.length, e;
while (i--) {
e = edges[i];
if (!d3_geom_voronoiConnectEdge(e, extent) || !clip(e) || abs(e.a.x - e.b.x) < ε && abs(e.a.y - e.b.y) < ε) {
e.a = e.b = null;
edges.splice(i, 1);
}
}
}
function d3_geom_voronoiConnectEdge(edge, extent) {
var vb = edge.b;
if (vb) return true;
var va = edge.a, x0 = extent[0][0], x1 = extent[1][0], y0 = extent[0][1], y1 = extent[1][1], lSite = edge.l, rSite = edge.r, lx = lSite.x, ly = lSite.y, rx = rSite.x, ry = rSite.y, fx = (lx + rx) / 2, fy = (ly + ry) / 2, fm, fb;
if (ry === ly) {
if (fx < x0 || fx >= x1) return;
if (lx > rx) {
if (!va) va = {
x: fx,
y: y0
}; else if (va.y >= y1) return;
vb = {
x: fx,
y: y1
};
} else {
if (!va) va = {
x: fx,
y: y1
}; else if (va.y < y0) return;
vb = {
x: fx,
y: y0
};
}
} else {
fm = (lx - rx) / (ry - ly);
fb = fy - fm * fx;
if (fm < -1 || fm > 1) {
if (lx > rx) {
if (!va) va = {
x: (y0 - fb) / fm,
y: y0
}; else if (va.y >= y1) return;
vb = {
x: (y1 - fb) / fm,
y: y1
};
} else {
if (!va) va = {
x: (y1 - fb) / fm,
y: y1
}; else if (va.y < y0) return;
vb = {
x: (y0 - fb) / fm,
y: y0
};
}
} else {
if (ly < ry) {
if (!va) va = {
x: x0,
y: fm * x0 + fb
}; else if (va.x >= x1) return;
vb = {
x: x1,
y: fm * x1 + fb
};
} else {
if (!va) va = {
x: x1,
y: fm * x1 + fb
}; else if (va.x < x0) return;
vb = {
x: x0,
y: fm * x0 + fb
};
}
}
}
edge.a = va;
edge.b = vb;
return true;
}
function d3_geom_voronoiEdge(lSite, rSite) {
this.l = lSite;
this.r = rSite;
this.a = this.b = null;
}
function d3_geom_voronoiCreateEdge(lSite, rSite, va, vb) {
var edge = new d3_geom_voronoiEdge(lSite, rSite);
d3_geom_voronoiEdges.push(edge);
if (va) d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, va);
if (vb) d3_geom_voronoiSetEdgeEnd(edge, rSite, lSite, vb);
d3_geom_voronoiCells[lSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, lSite, rSite));
d3_geom_voronoiCells[rSite.i].edges.push(new d3_geom_voronoiHalfEdge(edge, rSite, lSite));
return edge;
}
function d3_geom_voronoiCreateBorderEdge(lSite, va, vb) {
var edge = new d3_geom_voronoiEdge(lSite, null);
edge.a = va;
edge.b = vb;
d3_geom_voronoiEdges.push(edge);
return edge;
}
function d3_geom_voronoiSetEdgeEnd(edge, lSite, rSite, vertex) {
if (!edge.a && !edge.b) {
edge.a = vertex;
edge.l = lSite;
edge.r = rSite;
} else if (edge.l === rSite) {
edge.b = vertex;
} else {
edge.a = vertex;
}
}
function d3_geom_voronoiHalfEdge(edge, lSite, rSite) {
var va = edge.a, vb = edge.b;
this.edge = edge;
this.site = lSite;
this.angle = rSite ? Math.atan2(rSite.y - lSite.y, rSite.x - lSite.x) : edge.l === lSite ? Math.atan2(vb.x - va.x, va.y - vb.y) : Math.atan2(va.x - vb.x, vb.y - va.y);
}
d3_geom_voronoiHalfEdge.prototype = {
start: function() {
return this.edge.l === this.site ? this.edge.a : this.edge.b;
},
end: function() {
return this.edge.l === this.site ? this.edge.b : this.edge.a;
}
};
function d3_geom_voronoiRedBlackTree() {
this._ = null;
}
function d3_geom_voronoiRedBlackNode(node) {
node.U = node.C = node.L = node.R = node.P = node.N = null;
}
d3_geom_voronoiRedBlackTree.prototype = {
insert: function(after, node) {
var parent, grandpa, uncle;
if (after) {
node.P = after;
node.N = after.N;
if (after.N) after.N.P = node;
after.N = node;
if (after.R) {
after = after.R;
while (after.L) after = after.L;
after.L = node;
} else {
after.R = node;
}
parent = after;
} else if (this._) {
after = d3_geom_voronoiRedBlackFirst(this._);
node.P = null;
node.N = after;
after.P = after.L = node;
parent = after;
} else {
node.P = node.N = null;
this._ = node;
parent = null;
}
node.L = node.R = null;
node.U = parent;
node.C = true;
after = node;
while (parent && parent.C) {
grandpa = parent.U;
if (parent === grandpa.L) {
uncle = grandpa.R;
if (uncle && uncle.C) {
parent.C = uncle.C = false;
grandpa.C = true;
after = grandpa;
} else {
if (after === parent.R) {
d3_geom_voronoiRedBlackRotateLeft(this, parent);
after = parent;
parent = after.U;
}
parent.C = false;
grandpa.C = true;
d3_geom_voronoiRedBlackRotateRight(this, grandpa);
}
} else {
uncle = grandpa.L;
if (uncle && uncle.C) {
parent.C = uncle.C = false;
grandpa.C = true;
after = grandpa;
} else {
if (after === parent.L) {
d3_geom_voronoiRedBlackRotateRight(this, parent);
after = parent;
parent = after.U;
}
parent.C = false;
grandpa.C = true;
d3_geom_voronoiRedBlackRotateLeft(this, grandpa);
}
}
parent = after.U;
}
this._.C = false;
},
remove: function(node) {
if (node.N) node.N.P = node.P;
if (node.P) node.P.N = node.N;
node.N = node.P = null;
var parent = node.U, sibling, left = node.L, right = node.R, next, red;
if (!left) next = right; else if (!right) next = left; else next = d3_geom_voronoiRedBlackFirst(right);
if (parent) {
if (parent.L === node) parent.L = next; else parent.R = next;
} else {
this._ = next;
}
if (left && right) {
red = next.C;
next.C = node.C;
next.L = left;
left.U = next;
if (next !== right) {
parent = next.U;
next.U = node.U;
node = next.R;
parent.L = node;
next.R = right;
right.U = next;
} else {
next.U = parent;
parent = next;
node = next.R;
}
} else {
red = node.C;
node = next;
}
if (node) node.U = parent;
if (red) return;
if (node && node.C) {
node.C = false;
return;
}
do {
if (node === this._) break;
if (node === parent.L) {
sibling = parent.R;
if (sibling.C) {
sibling.C = false;
parent.C = true;
d3_geom_voronoiRedBlackRotateLeft(this, parent);
sibling = parent.R;
}
if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
if (!sibling.R || !sibling.R.C) {
sibling.L.C = false;
sibling.C = true;
d3_geom_voronoiRedBlackRotateRight(this, sibling);
sibling = parent.R;
}
sibling.C = parent.C;
parent.C = sibling.R.C = false;
d3_geom_voronoiRedBlackRotateLeft(this, parent);
node = this._;
break;
}
} else {
sibling = parent.L;
if (sibling.C) {
sibling.C = false;
parent.C = true;
d3_geom_voronoiRedBlackRotateRight(this, parent);
sibling = parent.L;
}
if (sibling.L && sibling.L.C || sibling.R && sibling.R.C) {
if (!sibling.L || !sibling.L.C) {
sibling.R.C = false;
sibling.C = true;
d3_geom_voronoiRedBlackRotateLeft(this, sibling);
sibling = parent.L;
}
sibling.C = parent.C;
parent.C = sibling.L.C = false;
d3_geom_voronoiRedBlackRotateRight(this, parent);
node = this._;
break;
}
}
sibling.C = true;
node = parent;
parent = parent.U;
} while (!node.C);
if (node) node.C = false;
}
};
function d3_geom_voronoiRedBlackRotateLeft(tree, node) {
var p = node, q = node.R, parent = p.U;
if (parent) {
if (parent.L === p) parent.L = q; else parent.R = q;
} else {
tree._ = q;
}
q.U = parent;
p.U = q;
p.R = q.L;
if (p.R) p.R.U = p;
q.L = p;
}
function d3_geom_voronoiRedBlackRotateRight(tree, node) {
var p = node, q = node.L, parent = p.U;
if (parent) {
if (parent.L === p) parent.L = q; else parent.R = q;
} else {
tree._ = q;
}
q.U = parent;
p.U = q;
p.L = q.R;
if (p.L) p.L.U = p;
q.R = p;
}
function d3_geom_voronoiRedBlackFirst(node) {
while (node.L) node = node.L;
return node;
}
function d3_geom_voronoi(sites, bbox) {
var site = sites.sort(d3_geom_voronoiVertexOrder).pop(), x0, y0, circle;
d3_geom_voronoiEdges = [];
d3_geom_voronoiCells = new Array(sites.length);
d3_geom_voronoiBeaches = new d3_geom_voronoiRedBlackTree();
d3_geom_voronoiCircles = new d3_geom_voronoiRedBlackTree();
while (true) {
circle = d3_geom_voronoiFirstCircle;
if (site && (!circle || site.y < circle.y || site.y === circle.y && site.x < circle.x)) {
if (site.x !== x0 || site.y !== y0) {
d3_geom_voronoiCells[site.i] = new d3_geom_voronoiCell(site);
d3_geom_voronoiAddBeach(site);
x0 = site.x, y0 = site.y;
}
site = sites.pop();
} else if (circle) {
d3_geom_voronoiRemoveBeach(circle.arc);
} else {
break;
}
}
if (bbox) d3_geom_voronoiClipEdges(bbox), d3_geom_voronoiCloseCells(bbox);
var diagram = {
cells: d3_geom_voronoiCells,
edges: d3_geom_voronoiEdges
};
d3_geom_voronoiBeaches = d3_geom_voronoiCircles = d3_geom_voronoiEdges = d3_geom_voronoiCells = null;
return diagram;
}
function d3_geom_voronoiVertexOrder(a, b) {
return b.y - a.y || b.x - a.x;
}
d3.geom.voronoi = function(points) {
var x = d3_geom_pointX, y = d3_geom_pointY, fx = x, fy = y, clipExtent = d3_geom_voronoiClipExtent;
if (points) return voronoi(points);
function voronoi(data) {
var polygons = new Array(data.length), x0 = clipExtent[0][0], y0 = clipExtent[0][1], x1 = clipExtent[1][0], y1 = clipExtent[1][1];
d3_geom_voronoi(sites(data), clipExtent).cells.forEach(function(cell, i) {
var edges = cell.edges, site = cell.site, polygon = polygons[i] = edges.length ? edges.map(function(e) {
var s = e.start();
return [ s.x, s.y ];
}) : site.x >= x0 && site.x <= x1 && site.y >= y0 && site.y <= y1 ? [ [ x0, y1 ], [ x1, y1 ], [ x1, y0 ], [ x0, y0 ] ] : [];
polygon.point = data[i];
});
return polygons;
}
function sites(data) {
return data.map(function(d, i) {
return {
x: Math.round(fx(d, i) / ε) * ε,
y: Math.round(fy(d, i) / ε) * ε,
i: i
};
});
}
voronoi.links = function(data) {
return d3_geom_voronoi(sites(data)).edges.filter(function(edge) {
return edge.l && edge.r;
}).map(function(edge) {
return {
source: data[edge.l.i],
target: data[edge.r.i]
};
});
};
voronoi.triangles = function(data) {
var triangles = [];
d3_geom_voronoi(sites(data)).cells.forEach(function(cell, i) {
var site = cell.site, edges = cell.edges.sort(d3_geom_voronoiHalfEdgeOrder), j = -1, m = edges.length, e0, s0, e1 = edges[m - 1].edge, s1 = e1.l === site ? e1.r : e1.l;
while (++j < m) {
e0 = e1;
s0 = s1;
e1 = edges[j].edge;
s1 = e1.l === site ? e1.r : e1.l;
if (i < s0.i && i < s1.i && d3_geom_voronoiTriangleArea(site, s0, s1) < 0) {
triangles.push([ data[i], data[s0.i], data[s1.i] ]);
}
}
});
return triangles;
};
voronoi.x = function(_) {
return arguments.length ? (fx = d3_functor(x = _), voronoi) : x;
};
voronoi.y = function(_) {
return arguments.length ? (fy = d3_functor(y = _), voronoi) : y;
};
voronoi.clipExtent = function(_) {
if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent;
clipExtent = _ == null ? d3_geom_voronoiClipExtent : _;
return voronoi;
};
voronoi.size = function(_) {
if (!arguments.length) return clipExtent === d3_geom_voronoiClipExtent ? null : clipExtent && clipExtent[1];
return voronoi.clipExtent(_ && [ [ 0, 0 ], _ ]);
};
return voronoi;
};
var d3_geom_voronoiClipExtent = [ [ -1e6, -1e6 ], [ 1e6, 1e6 ] ];
function d3_geom_voronoiTriangleArea(a, b, c) {
return (a.x - c.x) * (b.y - a.y) - (a.x - b.x) * (c.y - a.y);
}
d3.geom.delaunay = function(vertices) {
return d3.geom.voronoi().triangles(vertices);
};
d3.geom.quadtree = function(points, x1, y1, x2, y2) {
var x = d3_geom_pointX, y = d3_geom_pointY, compat;
if (compat = arguments.length) {
x = d3_geom_quadtreeCompatX;
y = d3_geom_quadtreeCompatY;
if (compat === 3) {
y2 = y1;
x2 = x1;
y1 = x1 = 0;
}
return quadtree(points);
}
function quadtree(data) {
var d, fx = d3_functor(x), fy = d3_functor(y), xs, ys, i, n, x1_, y1_, x2_, y2_;
if (x1 != null) {
x1_ = x1, y1_ = y1, x2_ = x2, y2_ = y2;
} else {
x2_ = y2_ = -(x1_ = y1_ = Infinity);
xs = [], ys = [];
n = data.length;
if (compat) for (i = 0; i < n; ++i) {
d = data[i];
if (d.x < x1_) x1_ = d.x;
if (d.y < y1_) y1_ = d.y;
if (d.x > x2_) x2_ = d.x;
if (d.y > y2_) y2_ = d.y;
xs.push(d.x);
ys.push(d.y);
} else for (i = 0; i < n; ++i) {
var x_ = +fx(d = data[i], i), y_ = +fy(d, i);
if (x_ < x1_) x1_ = x_;
if (y_ < y1_) y1_ = y_;
if (x_ > x2_) x2_ = x_;
if (y_ > y2_) y2_ = y_;
xs.push(x_);
ys.push(y_);
}
}
var dx = x2_ - x1_, dy = y2_ - y1_;
if (dx > dy) y2_ = y1_ + dx; else x2_ = x1_ + dy;
function insert(n, d, x, y, x1, y1, x2, y2) {
if (isNaN(x) || isNaN(y)) return;
if (n.leaf) {
var nx = n.x, ny = n.y;
if (nx != null) {
if (abs(nx - x) + abs(ny - y) < .01) {
insertChild(n, d, x, y, x1, y1, x2, y2);
} else {
var nPoint = n.point;
n.x = n.y = n.point = null;
insertChild(n, nPoint, nx, ny, x1, y1, x2, y2);
insertChild(n, d, x, y, x1, y1, x2, y2);
}
} else {
n.x = x, n.y = y, n.point = d;
}
} else {
insertChild(n, d, x, y, x1, y1, x2, y2);
}
}
function insertChild(n, d, x, y, x1, y1, x2, y2) {
var xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym, i = below << 1 | right;
n.leaf = false;
n = n.nodes[i] || (n.nodes[i] = d3_geom_quadtreeNode());
if (right) x1 = xm; else x2 = xm;
if (below) y1 = ym; else y2 = ym;
insert(n, d, x, y, x1, y1, x2, y2);
}
var root = d3_geom_quadtreeNode();
root.add = function(d) {
insert(root, d, +fx(d, ++i), +fy(d, i), x1_, y1_, x2_, y2_);
};
root.visit = function(f) {
d3_geom_quadtreeVisit(f, root, x1_, y1_, x2_, y2_);
};
root.find = function(point) {
return d3_geom_quadtreeFind(root, point[0], point[1], x1_, y1_, x2_, y2_);
};
i = -1;
if (x1 == null) {
while (++i < n) {
insert(root, data[i], xs[i], ys[i], x1_, y1_, x2_, y2_);
}
--i;
} else data.forEach(root.add);
xs = ys = data = d = null;
return root;
}
quadtree.x = function(_) {
return arguments.length ? (x = _, quadtree) : x;
};
quadtree.y = function(_) {
return arguments.length ? (y = _, quadtree) : y;
};
quadtree.extent = function(_) {
if (!arguments.length) return x1 == null ? null : [ [ x1, y1 ], [ x2, y2 ] ];
if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = +_[0][0], y1 = +_[0][1], x2 = +_[1][0],
y2 = +_[1][1];
return quadtree;
};
quadtree.size = function(_) {
if (!arguments.length) return x1 == null ? null : [ x2 - x1, y2 - y1 ];
if (_ == null) x1 = y1 = x2 = y2 = null; else x1 = y1 = 0, x2 = +_[0], y2 = +_[1];
return quadtree;
};
return quadtree;
};
function d3_geom_quadtreeCompatX(d) {
return d.x;
}
function d3_geom_quadtreeCompatY(d) {
return d.y;
}
function d3_geom_quadtreeNode() {
return {
leaf: true,
nodes: [],
point: null,
x: null,
y: null
};
}
function d3_geom_quadtreeVisit(f, node, x1, y1, x2, y2) {
if (!f(node, x1, y1, x2, y2)) {
var sx = (x1 + x2) * .5, sy = (y1 + y2) * .5, children = node.nodes;
if (children[0]) d3_geom_quadtreeVisit(f, children[0], x1, y1, sx, sy);
if (children[1]) d3_geom_quadtreeVisit(f, children[1], sx, y1, x2, sy);
if (children[2]) d3_geom_quadtreeVisit(f, children[2], x1, sy, sx, y2);
if (children[3]) d3_geom_quadtreeVisit(f, children[3], sx, sy, x2, y2);
}
}
function d3_geom_quadtreeFind(root, x, y, x0, y0, x3, y3) {
var minDistance2 = Infinity, closestPoint;
(function find(node, x1, y1, x2, y2) {
if (x1 > x3 || y1 > y3 || x2 < x0 || y2 < y0) return;
if (point = node.point) {
var point, dx = x - node.x, dy = y - node.y, distance2 = dx * dx + dy * dy;
if (distance2 < minDistance2) {
var distance = Math.sqrt(minDistance2 = distance2);
x0 = x - distance, y0 = y - distance;
x3 = x + distance, y3 = y + distance;
closestPoint = point;
}
}
var children = node.nodes, xm = (x1 + x2) * .5, ym = (y1 + y2) * .5, right = x >= xm, below = y >= ym;
for (var i = below << 1 | right, j = i + 4; i < j; ++i) {
if (node = children[i & 3]) switch (i & 3) {
case 0:
find(node, x1, y1, xm, ym);
break;
case 1:
find(node, xm, y1, x2, ym);
break;
case 2:
find(node, x1, ym, xm, y2);
break;
case 3:
find(node, xm, ym, x2, y2);
break;
}
}
})(root, x0, y0, x3, y3);
return closestPoint;
}
d3.interpolateRgb = d3_interpolateRgb;
function d3_interpolateRgb(a, b) {
a = d3.rgb(a);
b = d3.rgb(b);
var ar = a.r, ag = a.g, ab = a.b, br = b.r - ar, bg = b.g - ag, bb = b.b - ab;
return function(t) {
return "#" + d3_rgb_hex(Math.round(ar + br * t)) + d3_rgb_hex(Math.round(ag + bg * t)) + d3_rgb_hex(Math.round(ab + bb * t));
};
}
d3.interpolateObject = d3_interpolateObject;
function d3_interpolateObject(a, b) {
var i = {}, c = {}, k;
for (k in a) {
if (k in b) {
i[k] = d3_interpolate(a[k], b[k]);
} else {
c[k] = a[k];
}
}
for (k in b) {
if (!(k in a)) {
c[k] = b[k];
}
}
return function(t) {
for (k in i) c[k] = i[k](t);
return c;
};
}
d3.interpolateNumber = d3_interpolateNumber;
function d3_interpolateNumber(a, b) {
a = +a, b = +b;
return function(t) {
return a * (1 - t) + b * t;
};
}
d3.interpolateString = d3_interpolateString;
function d3_interpolateString(a, b) {
var bi = d3_interpolate_numberA.lastIndex = d3_interpolate_numberB.lastIndex = 0, am, bm, bs, i = -1, s = [], q = [];
a = a + "", b = b + "";
while ((am = d3_interpolate_numberA.exec(a)) && (bm = d3_interpolate_numberB.exec(b))) {
if ((bs = bm.index) > bi) {
bs = b.slice(bi, bs);
if (s[i]) s[i] += bs; else s[++i] = bs;
}
if ((am = am[0]) === (bm = bm[0])) {
if (s[i]) s[i] += bm; else s[++i] = bm;
} else {
s[++i] = null;
q.push({
i: i,
x: d3_interpolateNumber(am, bm)
});
}
bi = d3_interpolate_numberB.lastIndex;
}
if (bi < b.length) {
bs = b.slice(bi);
if (s[i]) s[i] += bs; else s[++i] = bs;
}
return s.length < 2 ? q[0] ? (b = q[0].x, function(t) {
return b(t) + "";
}) : function() {
return b;
} : (b = q.length, function(t) {
for (var i = 0, o; i < b; ++i) s[(o = q[i]).i] = o.x(t);
return s.join("");
});
}
var d3_interpolate_numberA = /[-+]?(?:\d+\.?\d*|\.?\d+)(?:[eE][-+]?\d+)?/g, d3_interpolate_numberB = new RegExp(d3_interpolate_numberA.source, "g");
d3.interpolate = d3_interpolate;
function d3_interpolate(a, b) {
var i = d3.interpolators.length, f;
while (--i >= 0 && !(f = d3.interpolators[i](a, b))) ;
return f;
}
d3.interpolators = [ function(a, b) {
var t = typeof b;
return (t === "string" ? d3_rgb_names.has(b.toLowerCase()) || /^(#|rgb\(|hsl\()/i.test(b) ? d3_interpolateRgb : d3_interpolateString : b instanceof d3_color ? d3_interpolateRgb : Array.isArray(b) ? d3_interpolateArray : t === "object" && isNaN(b) ? d3_interpolateObject : d3_interpolateNumber)(a, b);
} ];
d3.interpolateArray = d3_interpolateArray;
function d3_interpolateArray(a, b) {
var x = [], c = [], na = a.length, nb = b.length, n0 = Math.min(a.length, b.length), i;
for (i = 0; i < n0; ++i) x.push(d3_interpolate(a[i], b[i]));
for (;i < na; ++i) c[i] = a[i];
for (;i < nb; ++i) c[i] = b[i];
return function(t) {
for (i = 0; i < n0; ++i) c[i] = x[i](t);
return c;
};
}
var d3_ease_default = function() {
return d3_identity;
};
var d3_ease = d3.map({
linear: d3_ease_default,
poly: d3_ease_poly,
quad: function() {
return d3_ease_quad;
},
cubic: function() {
return d3_ease_cubic;
},
sin: function() {
return d3_ease_sin;
},
exp: function() {
return d3_ease_exp;
},
circle: function() {
return d3_ease_circle;
},
elastic: d3_ease_elastic,
back: d3_ease_back,
bounce: function() {
return d3_ease_bounce;
}
});
var d3_ease_mode = d3.map({
"in": d3_identity,
out: d3_ease_reverse,
"in-out": d3_ease_reflect,
"out-in": function(f) {
return d3_ease_reflect(d3_ease_reverse(f));
}
});
d3.ease = function(name) {
var i = name.indexOf("-"), t = i >= 0 ? name.slice(0, i) : name, m = i >= 0 ? name.slice(i + 1) : "in";
t = d3_ease.get(t) || d3_ease_default;
m = d3_ease_mode.get(m) || d3_identity;
return d3_ease_clamp(m(t.apply(null, d3_arraySlice.call(arguments, 1))));
};
function d3_ease_clamp(f) {
return function(t) {
return t <= 0 ? 0 : t >= 1 ? 1 : f(t);
};
}
function d3_ease_reverse(f) {
return function(t) {
return 1 - f(1 - t);
};
}
function d3_ease_reflect(f) {
return function(t) {
return .5 * (t < .5 ? f(2 * t) : 2 - f(2 - 2 * t));
};
}
function d3_ease_quad(t) {
return t * t;
}
function d3_ease_cubic(t) {
return t * t * t;
}
function d3_ease_cubicInOut(t) {
if (t <= 0) return 0;
if (t >= 1) return 1;
var t2 = t * t, t3 = t2 * t;
return 4 * (t < .5 ? t3 : 3 * (t - t2) + t3 - .75);
}
function d3_ease_poly(e) {
return function(t) {
return Math.pow(t, e);
};
}
function d3_ease_sin(t) {
return 1 - Math.cos(t * halfπ);
}
function d3_ease_exp(t) {
return Math.pow(2, 10 * (t - 1));
}
function d3_ease_circle(t) {
return 1 - Math.sqrt(1 - t * t);
}
function d3_ease_elastic(a, p) {
var s;
if (arguments.length < 2) p = .45;
if (arguments.length) s = p / τ * Math.asin(1 / a); else a = 1, s = p / 4;
return function(t) {
return 1 + a * Math.pow(2, -10 * t) * Math.sin((t - s) * τ / p);
};
}
function d3_ease_back(s) {
if (!s) s = 1.70158;
return function(t) {
return t * t * ((s + 1) * t - s);
};
}
function d3_ease_bounce(t) {
return t < 1 / 2.75 ? 7.5625 * t * t : t < 2 / 2.75 ? 7.5625 * (t -= 1.5 / 2.75) * t + .75 : t < 2.5 / 2.75 ? 7.5625 * (t -= 2.25 / 2.75) * t + .9375 : 7.5625 * (t -= 2.625 / 2.75) * t + .984375;
}
d3.interpolateHcl = d3_interpolateHcl;
function d3_interpolateHcl(a, b) {
a = d3.hcl(a);
b = d3.hcl(b);
var ah = a.h, ac = a.c, al = a.l, bh = b.h - ah, bc = b.c - ac, bl = b.l - al;
if (isNaN(bc)) bc = 0, ac = isNaN(ac) ? b.c : ac;
if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
return function(t) {
return d3_hcl_lab(ah + bh * t, ac + bc * t, al + bl * t) + "";
};
}
d3.interpolateHsl = d3_interpolateHsl;
function d3_interpolateHsl(a, b) {
a = d3.hsl(a);
b = d3.hsl(b);
var ah = a.h, as = a.s, al = a.l, bh = b.h - ah, bs = b.s - as, bl = b.l - al;
if (isNaN(bs)) bs = 0, as = isNaN(as) ? b.s : as;
if (isNaN(bh)) bh = 0, ah = isNaN(ah) ? b.h : ah; else if (bh > 180) bh -= 360; else if (bh < -180) bh += 360;
return function(t) {
return d3_hsl_rgb(ah + bh * t, as + bs * t, al + bl * t) + "";
};
}
d3.interpolateLab = d3_interpolateLab;
function d3_interpolateLab(a, b) {
a = d3.lab(a);
b = d3.lab(b);
var al = a.l, aa = a.a, ab = a.b, bl = b.l - al, ba = b.a - aa, bb = b.b - ab;
return function(t) {
return d3_lab_rgb(al + bl * t, aa + ba * t, ab + bb * t) + "";
};
}
d3.interpolateRound = d3_interpolateRound;
function d3_interpolateRound(a, b) {
b -= a;
return function(t) {
return Math.round(a + b * t);
};
}
d3.transform = function(string) {
var g = d3_document.createElementNS(d3.ns.prefix.svg, "g");
return (d3.transform = function(string) {
if (string != null) {
g.setAttribute("transform", string);
var t = g.transform.baseVal.consolidate();
}
return new d3_transform(t ? t.matrix : d3_transformIdentity);
})(string);
};
function d3_transform(m) {
var r0 = [ m.a, m.b ], r1 = [ m.c, m.d ], kx = d3_transformNormalize(r0), kz = d3_transformDot(r0, r1), ky = d3_transformNormalize(d3_transformCombine(r1, r0, -kz)) || 0;
if (r0[0] * r1[1] < r1[0] * r0[1]) {
r0[0] *= -1;
r0[1] *= -1;
kx *= -1;
kz *= -1;
}
this.rotate = (kx ? Math.atan2(r0[1], r0[0]) : Math.atan2(-r1[0], r1[1])) * d3_degrees;
this.translate = [ m.e, m.f ];
this.scale = [ kx, ky ];
this.skew = ky ? Math.atan2(kz, ky) * d3_degrees : 0;
}
d3_transform.prototype.toString = function() {
return "translate(" + this.translate + ")rotate(" + this.rotate + ")skewX(" + this.skew + ")scale(" + this.scale + ")";
};
function d3_transformDot(a, b) {
return a[0] * b[0] + a[1] * b[1];
}
function d3_transformNormalize(a) {
var k = Math.sqrt(d3_transformDot(a, a));
if (k) {
a[0] /= k;
a[1] /= k;
}
return k;
}
function d3_transformCombine(a, b, k) {
a[0] += k * b[0];
a[1] += k * b[1];
return a;
}
var d3_transformIdentity = {
a: 1,
b: 0,
c: 0,
d: 1,
e: 0,
f: 0
};
d3.interpolateTransform = d3_interpolateTransform;
function d3_interpolateTransformPop(s) {
return s.length ? s.pop() + "," : "";
}
function d3_interpolateTranslate(ta, tb, s, q) {
if (ta[0] !== tb[0] || ta[1] !== tb[1]) {
var i = s.push("translate(", null, ",", null, ")");
q.push({
i: i - 4,
x: d3_interpolateNumber(ta[0], tb[0])
}, {
i: i - 2,
x: d3_interpolateNumber(ta[1], tb[1])
});
} else if (tb[0] || tb[1]) {
s.push("translate(" + tb + ")");
}
}
function d3_interpolateRotate(ra, rb, s, q) {
if (ra !== rb) {
if (ra - rb > 180) rb += 360; else if (rb - ra > 180) ra += 360;
q.push({
i: s.push(d3_interpolateTransformPop(s) + "rotate(", null, ")") - 2,
x: d3_interpolateNumber(ra, rb)
});
} else if (rb) {
s.push(d3_interpolateTransformPop(s) + "rotate(" + rb + ")");
}
}
function d3_interpolateSkew(wa, wb, s, q) {
if (wa !== wb) {
q.push({
i: s.push(d3_interpolateTransformPop(s) + "skewX(", null, ")") - 2,
x: d3_interpolateNumber(wa, wb)
});
} else if (wb) {
s.push(d3_interpolateTransformPop(s) + "skewX(" + wb + ")");
}
}
function d3_interpolateScale(ka, kb, s, q) {
if (ka[0] !== kb[0] || ka[1] !== kb[1]) {
var i = s.push(d3_interpolateTransformPop(s) + "scale(", null, ",", null, ")");
q.push({
i: i - 4,
x: d3_interpolateNumber(ka[0], kb[0])
}, {
i: i - 2,
x: d3_interpolateNumber(ka[1], kb[1])
});
} else if (kb[0] !== 1 || kb[1] !== 1) {
s.push(d3_interpolateTransformPop(s) + "scale(" + kb + ")");
}
}
function d3_interpolateTransform(a, b) {
var s = [], q = [];
a = d3.transform(a), b = d3.transform(b);
d3_interpolateTranslate(a.translate, b.translate, s, q);
d3_interpolateRotate(a.rotate, b.rotate, s, q);
d3_interpolateSkew(a.skew, b.skew, s, q);
d3_interpolateScale(a.scale, b.scale, s, q);
a = b = null;
return function(t) {
var i = -1, n = q.length, o;
while (++i < n) s[(o = q[i]).i] = o.x(t);
return s.join("");
};
}
function d3_uninterpolateNumber(a, b) {
b = (b -= a = +a) || 1 / b;
return function(x) {
return (x - a) / b;
};
}
function d3_uninterpolateClamp(a, b) {
b = (b -= a = +a) || 1 / b;
return function(x) {
return Math.max(0, Math.min(1, (x - a) / b));
};
}
d3.layout = {};
d3.layout.bundle = function() {
return function(links) {
var paths = [], i = -1, n = links.length;
while (++i < n) paths.push(d3_layout_bundlePath(links[i]));
return paths;
};
};
function d3_layout_bundlePath(link) {
var start = link.source, end = link.target, lca = d3_layout_bundleLeastCommonAncestor(start, end), points = [ start ];
while (start !== lca) {
start = start.parent;
points.push(start);
}
var k = points.length;
while (end !== lca) {
points.splice(k, 0, end);
end = end.parent;
}
return points;
}
function d3_layout_bundleAncestors(node) {
var ancestors = [], parent = node.parent;
while (parent != null) {
ancestors.push(node);
node = parent;
parent = parent.parent;
}
ancestors.push(node);
return ancestors;
}
function d3_layout_bundleLeastCommonAncestor(a, b) {
if (a === b) return a;
var aNodes = d3_layout_bundleAncestors(a), bNodes = d3_layout_bundleAncestors(b), aNode = aNodes.pop(), bNode = bNodes.pop(), sharedNode = null;
while (aNode === bNode) {
sharedNode = aNode;
aNode = aNodes.pop();
bNode = bNodes.pop();
}
return sharedNode;
}
d3.layout.chord = function() {
var chord = {}, chords, groups, matrix, n, padding = 0, sortGroups, sortSubgroups, sortChords;
function relayout() {
var subgroups = {}, groupSums = [], groupIndex = d3.range(n), subgroupIndex = [], k, x, x0, i, j;
chords = [];
groups = [];
k = 0, i = -1;
while (++i < n) {
x = 0, j = -1;
while (++j < n) {
x += matrix[i][j];
}
groupSums.push(x);
subgroupIndex.push(d3.range(n));
k += x;
}
if (sortGroups) {
groupIndex.sort(function(a, b) {
return sortGroups(groupSums[a], groupSums[b]);
});
}
if (sortSubgroups) {
subgroupIndex.forEach(function(d, i) {
d.sort(function(a, b) {
return sortSubgroups(matrix[i][a], matrix[i][b]);
});
});
}
k = (τ - padding * n) / k;
x = 0, i = -1;
while (++i < n) {
x0 = x, j = -1;
while (++j < n) {
var di = groupIndex[i], dj = subgroupIndex[di][j], v = matrix[di][dj], a0 = x, a1 = x += v * k;
subgroups[di + "-" + dj] = {
index: di,
subindex: dj,
startAngle: a0,
endAngle: a1,
value: v
};
}
groups[di] = {
index: di,
startAngle: x0,
endAngle: x,
value: groupSums[di]
};
x += padding;
}
i = -1;
while (++i < n) {
j = i - 1;
while (++j < n) {
var source = subgroups[i + "-" + j], target = subgroups[j + "-" + i];
if (source.value || target.value) {
chords.push(source.value < target.value ? {
source: target,
target: source
} : {
source: source,
target: target
});
}
}
}
if (sortChords) resort();
}
function resort() {
chords.sort(function(a, b) {
return sortChords((a.source.value + a.target.value) / 2, (b.source.value + b.target.value) / 2);
});
}
chord.matrix = function(x) {
if (!arguments.length) return matrix;
n = (matrix = x) && matrix.length;
chords = groups = null;
return chord;
};
chord.padding = function(x) {
if (!arguments.length) return padding;
padding = x;
chords = groups = null;
return chord;
};
chord.sortGroups = function(x) {
if (!arguments.length) return sortGroups;
sortGroups = x;
chords = groups = null;
return chord;
};
chord.sortSubgroups = function(x) {
if (!arguments.length) return sortSubgroups;
sortSubgroups = x;
chords = null;
return chord;
};
chord.sortChords = function(x) {
if (!arguments.length) return sortChords;
sortChords = x;
if (chords) resort();
return chord;
};
chord.chords = function() {
if (!chords) relayout();
return chords;
};
chord.groups = function() {
if (!groups) relayout();
return groups;
};
return chord;
};
d3.layout.force = function() {
var force = {}, event = d3.dispatch("start", "tick", "end"), timer, size = [ 1, 1 ], drag, alpha, friction = .9, linkDistance = d3_layout_forceLinkDistance, linkStrength = d3_layout_forceLinkStrength, charge = -30, chargeDistance2 = d3_layout_forceChargeDistance2, gravity = .1, theta2 = .64, nodes = [], links = [], distances, strengths, charges;
function repulse(node) {
return function(quad, x1, _, x2) {
if (quad.point !== node) {
var dx = quad.cx - node.x, dy = quad.cy - node.y, dw = x2 - x1, dn = dx * dx + dy * dy;
if (dw * dw / theta2 < dn) {
if (dn < chargeDistance2) {
var k = quad.charge / dn;
node.px -= dx * k;
node.py -= dy * k;
}
return true;
}
if (quad.point && dn && dn < chargeDistance2) {
var k = quad.pointCharge / dn;
node.px -= dx * k;
node.py -= dy * k;
}
}
return !quad.charge;
};
}
force.tick = function() {
if ((alpha *= .99) < .005) {
timer = null;
event.end({
type: "end",
alpha: alpha = 0
});
return true;
}
var n = nodes.length, m = links.length, q, i, o, s, t, l, k, x, y;
for (i = 0; i < m; ++i) {
o = links[i];
s = o.source;
t = o.target;
x = t.x - s.x;
y = t.y - s.y;
if (l = x * x + y * y) {
l = alpha * strengths[i] * ((l = Math.sqrt(l)) - distances[i]) / l;
x *= l;
y *= l;
t.x -= x * (k = s.weight + t.weight ? s.weight / (s.weight + t.weight) : .5);
t.y -= y * k;
s.x += x * (k = 1 - k);
s.y += y * k;
}
}
if (k = alpha * gravity) {
x = size[0] / 2;
y = size[1] / 2;
i = -1;
if (k) while (++i < n) {
o = nodes[i];
o.x += (x - o.x) * k;
o.y += (y - o.y) * k;
}
}
if (charge) {
d3_layout_forceAccumulate(q = d3.geom.quadtree(nodes), alpha, charges);
i = -1;
while (++i < n) {
if (!(o = nodes[i]).fixed) {
q.visit(repulse(o));
}
}
}
i = -1;
while (++i < n) {
o = nodes[i];
if (o.fixed) {
o.x = o.px;
o.y = o.py;
} else {
o.x -= (o.px - (o.px = o.x)) * friction;
o.y -= (o.py - (o.py = o.y)) * friction;
}
}
event.tick({
type: "tick",
alpha: alpha
});
};
force.nodes = function(x) {
if (!arguments.length) return nodes;
nodes = x;
return force;
};
force.links = function(x) {
if (!arguments.length) return links;
links = x;
return force;
};
force.size = function(x) {
if (!arguments.length) return size;
size = x;
return force;
};
force.linkDistance = function(x) {
if (!arguments.length) return linkDistance;
linkDistance = typeof x === "function" ? x : +x;
return force;
};
force.distance = force.linkDistance;
force.linkStrength = function(x) {
if (!arguments.length) return linkStrength;
linkStrength = typeof x === "function" ? x : +x;
return force;
};
force.friction = function(x) {
if (!arguments.length) return friction;
friction = +x;
return force;
};
force.charge = function(x) {
if (!arguments.length) return charge;
charge = typeof x === "function" ? x : +x;
return force;
};
force.chargeDistance = function(x) {
if (!arguments.length) return Math.sqrt(chargeDistance2);
chargeDistance2 = x * x;
return force;
};
force.gravity = function(x) {
if (!arguments.length) return gravity;
gravity = +x;
return force;
};
force.theta = function(x) {
if (!arguments.length) return Math.sqrt(theta2);
theta2 = x * x;
return force;
};
force.alpha = function(x) {
if (!arguments.length) return alpha;
x = +x;
if (alpha) {
if (x > 0) {
alpha = x;
} else {
timer.c = null, timer.t = NaN, timer = null;
event.end({
type: "end",
alpha: alpha = 0
});
}
} else if (x > 0) {
event.start({
type: "start",
alpha: alpha = x
});
timer = d3_timer(force.tick);
}
return force;
};
force.start = function() {
var i, n = nodes.length, m = links.length, w = size[0], h = size[1], neighbors, o;
for (i = 0; i < n; ++i) {
(o = nodes[i]).index = i;
o.weight = 0;
}
for (i = 0; i < m; ++i) {
o = links[i];
if (typeof o.source == "number") o.source = nodes[o.source];
if (typeof o.target == "number") o.target = nodes[o.target];
++o.source.weight;
++o.target.weight;
}
for (i = 0; i < n; ++i) {
o = nodes[i];
if (isNaN(o.x)) o.x = position("x", w);
if (isNaN(o.y)) o.y = position("y", h);
if (isNaN(o.px)) o.px = o.x;
if (isNaN(o.py)) o.py = o.y;
}
distances = [];
if (typeof linkDistance === "function") for (i = 0; i < m; ++i) distances[i] = +linkDistance.call(this, links[i], i); else for (i = 0; i < m; ++i) distances[i] = linkDistance;
strengths = [];
if (typeof linkStrength === "function") for (i = 0; i < m; ++i) strengths[i] = +linkStrength.call(this, links[i], i); else for (i = 0; i < m; ++i) strengths[i] = linkStrength;
charges = [];
if (typeof charge === "function") for (i = 0; i < n; ++i) charges[i] = +charge.call(this, nodes[i], i); else for (i = 0; i < n; ++i) charges[i] = charge;
function position(dimension, size) {
if (!neighbors) {
neighbors = new Array(n);
for (j = 0; j < n; ++j) {
neighbors[j] = [];
}
for (j = 0; j < m; ++j) {
var o = links[j];
neighbors[o.source.index].push(o.target);
neighbors[o.target.index].push(o.source);
}
}
var candidates = neighbors[i], j = -1, l = candidates.length, x;
while (++j < l) if (!isNaN(x = candidates[j][dimension])) return x;
return Math.random() * size;
}
return force.resume();
};
force.resume = function() {
return force.alpha(.1);
};
force.stop = function() {
return force.alpha(0);
};
force.drag = function() {
if (!drag) drag = d3.behavior.drag().origin(d3_identity).on("dragstart.force", d3_layout_forceDragstart).on("drag.force", dragmove).on("dragend.force", d3_layout_forceDragend);
if (!arguments.length) return drag;
this.on("mouseover.force", d3_layout_forceMouseover).on("mouseout.force", d3_layout_forceMouseout).call(drag);
};
function dragmove(d) {
d.px = d3.event.x, d.py = d3.event.y;
force.resume();
}
return d3.rebind(force, event, "on");
};
function d3_layout_forceDragstart(d) {
d.fixed |= 2;
}
function d3_layout_forceDragend(d) {
d.fixed &= ~6;
}
function d3_layout_forceMouseover(d) {
d.fixed |= 4;
d.px = d.x, d.py = d.y;
}
function d3_layout_forceMouseout(d) {
d.fixed &= ~4;
}
function d3_layout_forceAccumulate(quad, alpha, charges) {
var cx = 0, cy = 0;
quad.charge = 0;
if (!quad.leaf) {
var nodes = quad.nodes, n = nodes.length, i = -1, c;
while (++i < n) {
c = nodes[i];
if (c == null) continue;
d3_layout_forceAccumulate(c, alpha, charges);
quad.charge += c.charge;
cx += c.charge * c.cx;
cy += c.charge * c.cy;
}
}
if (quad.point) {
if (!quad.leaf) {
quad.point.x += Math.random() - .5;
quad.point.y += Math.random() - .5;
}
var k = alpha * charges[quad.point.index];
quad.charge += quad.pointCharge = k;
cx += k * quad.point.x;
cy += k * quad.point.y;
}
quad.cx = cx / quad.charge;
quad.cy = cy / quad.charge;
}
var d3_layout_forceLinkDistance = 20, d3_layout_forceLinkStrength = 1, d3_layout_forceChargeDistance2 = Infinity;
d3.layout.hierarchy = function() {
var sort = d3_layout_hierarchySort, children = d3_layout_hierarchyChildren, value = d3_layout_hierarchyValue;
function hierarchy(root) {
var stack = [ root ], nodes = [], node;
root.depth = 0;
while ((node = stack.pop()) != null) {
nodes.push(node);
if ((childs = children.call(hierarchy, node, node.depth)) && (n = childs.length)) {
var n, childs, child;
while (--n >= 0) {
stack.push(child = childs[n]);
child.parent = node;
child.depth = node.depth + 1;
}
if (value) node.value = 0;
node.children = childs;
} else {
if (value) node.value = +value.call(hierarchy, node, node.depth) || 0;
delete node.children;
}
}
d3_layout_hierarchyVisitAfter(root, function(node) {
var childs, parent;
if (sort && (childs = node.children)) childs.sort(sort);
if (value && (parent = node.parent)) parent.value += node.value;
});
return nodes;
}
hierarchy.sort = function(x) {
if (!arguments.length) return sort;
sort = x;
return hierarchy;
};
hierarchy.children = function(x) {
if (!arguments.length) return children;
children = x;
return hierarchy;
};
hierarchy.value = function(x) {
if (!arguments.length) return value;
value = x;
return hierarchy;
};
hierarchy.revalue = function(root) {
if (value) {
d3_layout_hierarchyVisitBefore(root, function(node) {
if (node.children) node.value = 0;
});
d3_layout_hierarchyVisitAfter(root, function(node) {
var parent;
if (!node.children) node.value = +value.call(hierarchy, node, node.depth) || 0;
if (parent = node.parent) parent.value += node.value;
});
}
return root;
};
return hierarchy;
};
function d3_layout_hierarchyRebind(object, hierarchy) {
d3.rebind(object, hierarchy, "sort", "children", "value");
object.nodes = object;
object.links = d3_layout_hierarchyLinks;
return object;
}
function d3_layout_hierarchyVisitBefore(node, callback) {
var nodes = [ node ];
while ((node = nodes.pop()) != null) {
callback(node);
if ((children = node.children) && (n = children.length)) {
var n, children;
while (--n >= 0) nodes.push(children[n]);
}
}
}
function d3_layout_hierarchyVisitAfter(node, callback) {
var nodes = [ node ], nodes2 = [];
while ((node = nodes.pop()) != null) {
nodes2.push(node);
if ((children = node.children) && (n = children.length)) {
var i = -1, n, children;
while (++i < n) nodes.push(children[i]);
}
}
while ((node = nodes2.pop()) != null) {
callback(node);
}
}
function d3_layout_hierarchyChildren(d) {
return d.children;
}
function d3_layout_hierarchyValue(d) {
return d.value;
}
function d3_layout_hierarchySort(a, b) {
return b.value - a.value;
}
function d3_layout_hierarchyLinks(nodes) {
return d3.merge(nodes.map(function(parent) {
return (parent.children || []).map(function(child) {
return {
source: parent,
target: child
};
});
}));
}
d3.layout.partition = function() {
var hierarchy = d3.layout.hierarchy(), size = [ 1, 1 ];
function position(node, x, dx, dy) {
var children = node.children;
node.x = x;
node.y = node.depth * dy;
node.dx = dx;
node.dy = dy;
if (children && (n = children.length)) {
var i = -1, n, c, d;
dx = node.value ? dx / node.value : 0;
while (++i < n) {
position(c = children[i], x, d = c.value * dx, dy);
x += d;
}
}
}
function depth(node) {
var children = node.children, d = 0;
if (children && (n = children.length)) {
var i = -1, n;
while (++i < n) d = Math.max(d, depth(children[i]));
}
return 1 + d;
}
function partition(d, i) {
var nodes = hierarchy.call(this, d, i);
position(nodes[0], 0, size[0], size[1] / depth(nodes[0]));
return nodes;
}
partition.size = function(x) {
if (!arguments.length) return size;
size = x;
return partition;
};
return d3_layout_hierarchyRebind(partition, hierarchy);
};
d3.layout.pie = function() {
var value = Number, sort = d3_layout_pieSortByValue, startAngle = 0, endAngle = τ, padAngle = 0;
function pie(data) {
var n = data.length, values = data.map(function(d, i) {
return +value.call(pie, d, i);
}), a = +(typeof startAngle === "function" ? startAngle.apply(this, arguments) : startAngle), da = (typeof endAngle === "function" ? endAngle.apply(this, arguments) : endAngle) - a, p = Math.min(Math.abs(da) / n, +(typeof padAngle === "function" ? padAngle.apply(this, arguments) : padAngle)), pa = p * (da < 0 ? -1 : 1), sum = d3.sum(values), k = sum ? (da - n * pa) / sum : 0, index = d3.range(n), arcs = [], v;
if (sort != null) index.sort(sort === d3_layout_pieSortByValue ? function(i, j) {
return values[j] - values[i];
} : function(i, j) {
return sort(data[i], data[j]);
});
index.forEach(function(i) {
arcs[i] = {
data: data[i],
value: v = values[i],
startAngle: a,
endAngle: a += v * k + pa,
padAngle: p
};
});
return arcs;
}
pie.value = function(_) {
if (!arguments.length) return value;
value = _;
return pie;
};
pie.sort = function(_) {
if (!arguments.length) return sort;
sort = _;
return pie;
};
pie.startAngle = function(_) {
if (!arguments.length) return startAngle;
startAngle = _;
return pie;
};
pie.endAngle = function(_) {
if (!arguments.length) return endAngle;
endAngle = _;
return pie;
};
pie.padAngle = function(_) {
if (!arguments.length) return padAngle;
padAngle = _;
return pie;
};
return pie;
};
var d3_layout_pieSortByValue = {};
d3.layout.stack = function() {
var values = d3_identity, order = d3_layout_stackOrderDefault, offset = d3_layout_stackOffsetZero, out = d3_layout_stackOut, x = d3_layout_stackX, y = d3_layout_stackY;
function stack(data, index) {
if (!(n = data.length)) return data;
var series = data.map(function(d, i) {
return values.call(stack, d, i);
});
var points = series.map(function(d) {
return d.map(function(v, i) {
return [ x.call(stack, v, i), y.call(stack, v, i) ];
});
});
var orders = order.call(stack, points, index);
series = d3.permute(series, orders);
points = d3.permute(points, orders);
var offsets = offset.call(stack, points, index);
var m = series[0].length, n, i, j, o;
for (j = 0; j < m; ++j) {
out.call(stack, series[0][j], o = offsets[j], points[0][j][1]);
for (i = 1; i < n; ++i) {
out.call(stack, series[i][j], o += points[i - 1][j][1], points[i][j][1]);
}
}
return data;
}
stack.values = function(x) {
if (!arguments.length) return values;
values = x;
return stack;
};
stack.order = function(x) {
if (!arguments.length) return order;
order = typeof x === "function" ? x : d3_layout_stackOrders.get(x) || d3_layout_stackOrderDefault;
return stack;
};
stack.offset = function(x) {
if (!arguments.length) return offset;
offset = typeof x === "function" ? x : d3_layout_stackOffsets.get(x) || d3_layout_stackOffsetZero;
return stack;
};
stack.x = function(z) {
if (!arguments.length) return x;
x = z;
return stack;
};
stack.y = function(z) {
if (!arguments.length) return y;
y = z;
return stack;
};
stack.out = function(z) {
if (!arguments.length) return out;
out = z;
return stack;
};
return stack;
};
function d3_layout_stackX(d) {
return d.x;
}
function d3_layout_stackY(d) {
return d.y;
}
function d3_layout_stackOut(d, y0, y) {
d.y0 = y0;
d.y = y;
}
var d3_layout_stackOrders = d3.map({
"inside-out": function(data) {
var n = data.length, i, j, max = data.map(d3_layout_stackMaxIndex), sums = data.map(d3_layout_stackReduceSum), index = d3.range(n).sort(function(a, b) {
return max[a] - max[b];
}), top = 0, bottom = 0, tops = [], bottoms = [];
for (i = 0; i < n; ++i) {
j = index[i];
if (top < bottom) {
top += sums[j];
tops.push(j);
} else {
bottom += sums[j];
bottoms.push(j);
}
}
return bottoms.reverse().concat(tops);
},
reverse: function(data) {
return d3.range(data.length).reverse();
},
"default": d3_layout_stackOrderDefault
});
var d3_layout_stackOffsets = d3.map({
silhouette: function(data) {
var n = data.length, m = data[0].length, sums = [], max = 0, i, j, o, y0 = [];
for (j = 0; j < m; ++j) {
for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
if (o > max) max = o;
sums.push(o);
}
for (j = 0; j < m; ++j) {
y0[j] = (max - sums[j]) / 2;
}
return y0;
},
wiggle: function(data) {
var n = data.length, x = data[0], m = x.length, i, j, k, s1, s2, s3, dx, o, o0, y0 = [];
y0[0] = o = o0 = 0;
for (j = 1; j < m; ++j) {
for (i = 0, s1 = 0; i < n; ++i) s1 += data[i][j][1];
for (i = 0, s2 = 0, dx = x[j][0] - x[j - 1][0]; i < n; ++i) {
for (k = 0, s3 = (data[i][j][1] - data[i][j - 1][1]) / (2 * dx); k < i; ++k) {
s3 += (data[k][j][1] - data[k][j - 1][1]) / dx;
}
s2 += s3 * data[i][j][1];
}
y0[j] = o -= s1 ? s2 / s1 * dx : 0;
if (o < o0) o0 = o;
}
for (j = 0; j < m; ++j) y0[j] -= o0;
return y0;
},
expand: function(data) {
var n = data.length, m = data[0].length, k = 1 / n, i, j, o, y0 = [];
for (j = 0; j < m; ++j) {
for (i = 0, o = 0; i < n; i++) o += data[i][j][1];
if (o) for (i = 0; i < n; i++) data[i][j][1] /= o; else for (i = 0; i < n; i++) data[i][j][1] = k;
}
for (j = 0; j < m; ++j) y0[j] = 0;
return y0;
},
zero: d3_layout_stackOffsetZero
});
function d3_layout_stackOrderDefault(data) {
return d3.range(data.length);
}
function d3_layout_stackOffsetZero(data) {
var j = -1, m = data[0].length, y0 = [];
while (++j < m) y0[j] = 0;
return y0;
}
function d3_layout_stackMaxIndex(array) {
var i = 1, j = 0, v = array[0][1], k, n = array.length;
for (;i < n; ++i) {
if ((k = array[i][1]) > v) {
j = i;
v = k;
}
}
return j;
}
function d3_layout_stackReduceSum(d) {
return d.reduce(d3_layout_stackSum, 0);
}
function d3_layout_stackSum(p, d) {
return p + d[1];
}
d3.layout.histogram = function() {
var frequency = true, valuer = Number, ranger = d3_layout_histogramRange, binner = d3_layout_histogramBinSturges;
function histogram(data, i) {
var bins = [], values = data.map(valuer, this), range = ranger.call(this, values, i), thresholds = binner.call(this, range, values, i), bin, i = -1, n = values.length, m = thresholds.length - 1, k = frequency ? 1 : 1 / n, x;
while (++i < m) {
bin = bins[i] = [];
bin.dx = thresholds[i + 1] - (bin.x = thresholds[i]);
bin.y = 0;
}
if (m > 0) {
i = -1;
while (++i < n) {
x = values[i];
if (x >= range[0] && x <= range[1]) {
bin = bins[d3.bisect(thresholds, x, 1, m) - 1];
bin.y += k;
bin.push(data[i]);
}
}
}
return bins;
}
histogram.value = function(x) {
if (!arguments.length) return valuer;
valuer = x;
return histogram;
};
histogram.range = function(x) {
if (!arguments.length) return ranger;
ranger = d3_functor(x);
return histogram;
};
histogram.bins = function(x) {
if (!arguments.length) return binner;
binner = typeof x === "number" ? function(range) {
return d3_layout_histogramBinFixed(range, x);
} : d3_functor(x);
return histogram;
};
histogram.frequency = function(x) {
if (!arguments.length) return frequency;
frequency = !!x;
return histogram;
};
return histogram;
};
function d3_layout_histogramBinSturges(range, values) {
return d3_layout_histogramBinFixed(range, Math.ceil(Math.log(values.length) / Math.LN2 + 1));
}
function d3_layout_histogramBinFixed(range, n) {
var x = -1, b = +range[0], m = (range[1] - b) / n, f = [];
while (++x <= n) f[x] = m * x + b;
return f;
}
function d3_layout_histogramRange(values) {
return [ d3.min(values), d3.max(values) ];
}
d3.layout.pack = function() {
var hierarchy = d3.layout.hierarchy().sort(d3_layout_packSort), padding = 0, size = [ 1, 1 ], radius;
function pack(d, i) {
var nodes = hierarchy.call(this, d, i), root = nodes[0], w = size[0], h = size[1], r = radius == null ? Math.sqrt : typeof radius === "function" ? radius : function() {
return radius;
};
root.x = root.y = 0;
d3_layout_hierarchyVisitAfter(root, function(d) {
d.r = +r(d.value);
});
d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
if (padding) {
var dr = padding * (radius ? 1 : Math.max(2 * root.r / w, 2 * root.r / h)) / 2;
d3_layout_hierarchyVisitAfter(root, function(d) {
d.r += dr;
});
d3_layout_hierarchyVisitAfter(root, d3_layout_packSiblings);
d3_layout_hierarchyVisitAfter(root, function(d) {
d.r -= dr;
});
}
d3_layout_packTransform(root, w / 2, h / 2, radius ? 1 : 1 / Math.max(2 * root.r / w, 2 * root.r / h));
return nodes;
}
pack.size = function(_) {
if (!arguments.length) return size;
size = _;
return pack;
};
pack.radius = function(_) {
if (!arguments.length) return radius;
radius = _ == null || typeof _ === "function" ? _ : +_;
return pack;
};
pack.padding = function(_) {
if (!arguments.length) return padding;
padding = +_;
return pack;
};
return d3_layout_hierarchyRebind(pack, hierarchy);
};
function d3_layout_packSort(a, b) {
return a.value - b.value;
}
function d3_layout_packInsert(a, b) {
var c = a._pack_next;
a._pack_next = b;
b._pack_prev = a;
b._pack_next = c;
c._pack_prev = b;
}
function d3_layout_packSplice(a, b) {
a._pack_next = b;
b._pack_prev = a;
}
function d3_layout_packIntersects(a, b) {
var dx = b.x - a.x, dy = b.y - a.y, dr = a.r + b.r;
return .999 * dr * dr > dx * dx + dy * dy;
}
function d3_layout_packSiblings(node) {
if (!(nodes = node.children) || !(n = nodes.length)) return;
var nodes, xMin = Infinity, xMax = -Infinity, yMin = Infinity, yMax = -Infinity, a, b, c, i, j, k, n;
function bound(node) {
xMin = Math.min(node.x - node.r, xMin);
xMax = Math.max(node.x + node.r, xMax);
yMin = Math.min(node.y - node.r, yMin);
yMax = Math.max(node.y + node.r, yMax);
}
nodes.forEach(d3_layout_packLink);
a = nodes[0];
a.x = -a.r;
a.y = 0;
bound(a);
if (n > 1) {
b = nodes[1];
b.x = b.r;
b.y = 0;
bound(b);
if (n > 2) {
c = nodes[2];
d3_layout_packPlace(a, b, c);
bound(c);
d3_layout_packInsert(a, c);
a._pack_prev = c;
d3_layout_packInsert(c, b);
b = a._pack_next;
for (i = 3; i < n; i++) {
d3_layout_packPlace(a, b, c = nodes[i]);
var isect = 0, s1 = 1, s2 = 1;
for (j = b._pack_next; j !== b; j = j._pack_next, s1++) {
if (d3_layout_packIntersects(j, c)) {
isect = 1;
break;
}
}
if (isect == 1) {
for (k = a._pack_prev; k !== j._pack_prev; k = k._pack_prev, s2++) {
if (d3_layout_packIntersects(k, c)) {
break;
}
}
}
if (isect) {
if (s1 < s2 || s1 == s2 && b.r < a.r) d3_layout_packSplice(a, b = j); else d3_layout_packSplice(a = k, b);
i--;
} else {
d3_layout_packInsert(a, c);
b = c;
bound(c);
}
}
}
}
var cx = (xMin + xMax) / 2, cy = (yMin + yMax) / 2, cr = 0;
for (i = 0; i < n; i++) {
c = nodes[i];
c.x -= cx;
c.y -= cy;
cr = Math.max(cr, c.r + Math.sqrt(c.x * c.x + c.y * c.y));
}
node.r = cr;
nodes.forEach(d3_layout_packUnlink);
}
function d3_layout_packLink(node) {
node._pack_next = node._pack_prev = node;
}
function d3_layout_packUnlink(node) {
delete node._pack_next;
delete node._pack_prev;
}
function d3_layout_packTransform(node, x, y, k) {
var children = node.children;
node.x = x += k * node.x;
node.y = y += k * node.y;
node.r *= k;
if (children) {
var i = -1, n = children.length;
while (++i < n) d3_layout_packTransform(children[i], x, y, k);
}
}
function d3_layout_packPlace(a, b, c) {
var db = a.r + c.r, dx = b.x - a.x, dy = b.y - a.y;
if (db && (dx || dy)) {
var da = b.r + c.r, dc = dx * dx + dy * dy;
da *= da;
db *= db;
var x = .5 + (db - da) / (2 * dc), y = Math.sqrt(Math.max(0, 2 * da * (db + dc) - (db -= dc) * db - da * da)) / (2 * dc);
c.x = a.x + x * dx + y * dy;
c.y = a.y + x * dy - y * dx;
} else {
c.x = a.x + db;
c.y = a.y;
}
}
d3.layout.tree = function() {
var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = null;
function tree(d, i) {
var nodes = hierarchy.call(this, d, i), root0 = nodes[0], root1 = wrapTree(root0);
d3_layout_hierarchyVisitAfter(root1, firstWalk), root1.parent.m = -root1.z;
d3_layout_hierarchyVisitBefore(root1, secondWalk);
if (nodeSize) d3_layout_hierarchyVisitBefore(root0, sizeNode); else {
var left = root0, right = root0, bottom = root0;
d3_layout_hierarchyVisitBefore(root0, function(node) {
if (node.x < left.x) left = node;
if (node.x > right.x) right = node;
if (node.depth > bottom.depth) bottom = node;
});
var tx = separation(left, right) / 2 - left.x, kx = size[0] / (right.x + separation(right, left) / 2 + tx), ky = size[1] / (bottom.depth || 1);
d3_layout_hierarchyVisitBefore(root0, function(node) {
node.x = (node.x + tx) * kx;
node.y = node.depth * ky;
});
}
return nodes;
}
function wrapTree(root0) {
var root1 = {
A: null,
children: [ root0 ]
}, queue = [ root1 ], node1;
while ((node1 = queue.pop()) != null) {
for (var children = node1.children, child, i = 0, n = children.length; i < n; ++i) {
queue.push((children[i] = child = {
_: children[i],
parent: node1,
children: (child = children[i].children) && child.slice() || [],
A: null,
a: null,
z: 0,
m: 0,
c: 0,
s: 0,
t: null,
i: i
}).a = child);
}
}
return root1.children[0];
}
function firstWalk(v) {
var children = v.children, siblings = v.parent.children, w = v.i ? siblings[v.i - 1] : null;
if (children.length) {
d3_layout_treeShift(v);
var midpoint = (children[0].z + children[children.length - 1].z) / 2;
if (w) {
v.z = w.z + separation(v._, w._);
v.m = v.z - midpoint;
} else {
v.z = midpoint;
}
} else if (w) {
v.z = w.z + separation(v._, w._);
}
v.parent.A = apportion(v, w, v.parent.A || siblings[0]);
}
function secondWalk(v) {
v._.x = v.z + v.parent.m;
v.m += v.parent.m;
}
function apportion(v, w, ancestor) {
if (w) {
var vip = v, vop = v, vim = w, vom = vip.parent.children[0], sip = vip.m, sop = vop.m, sim = vim.m, som = vom.m, shift;
while (vim = d3_layout_treeRight(vim), vip = d3_layout_treeLeft(vip), vim && vip) {
vom = d3_layout_treeLeft(vom);
vop = d3_layout_treeRight(vop);
vop.a = v;
shift = vim.z + sim - vip.z - sip + separation(vim._, vip._);
if (shift > 0) {
d3_layout_treeMove(d3_layout_treeAncestor(vim, v, ancestor), v, shift);
sip += shift;
sop += shift;
}
sim += vim.m;
sip += vip.m;
som += vom.m;
sop += vop.m;
}
if (vim && !d3_layout_treeRight(vop)) {
vop.t = vim;
vop.m += sim - sop;
}
if (vip && !d3_layout_treeLeft(vom)) {
vom.t = vip;
vom.m += sip - som;
ancestor = v;
}
}
return ancestor;
}
function sizeNode(node) {
node.x *= size[0];
node.y = node.depth * size[1];
}
tree.separation = function(x) {
if (!arguments.length) return separation;
separation = x;
return tree;
};
tree.size = function(x) {
if (!arguments.length) return nodeSize ? null : size;
nodeSize = (size = x) == null ? sizeNode : null;
return tree;
};
tree.nodeSize = function(x) {
if (!arguments.length) return nodeSize ? size : null;
nodeSize = (size = x) == null ? null : sizeNode;
return tree;
};
return d3_layout_hierarchyRebind(tree, hierarchy);
};
function d3_layout_treeSeparation(a, b) {
return a.parent == b.parent ? 1 : 2;
}
function d3_layout_treeLeft(v) {
var children = v.children;
return children.length ? children[0] : v.t;
}
function d3_layout_treeRight(v) {
var children = v.children, n;
return (n = children.length) ? children[n - 1] : v.t;
}
function d3_layout_treeMove(wm, wp, shift) {
var change = shift / (wp.i - wm.i);
wp.c -= change;
wp.s += shift;
wm.c += change;
wp.z += shift;
wp.m += shift;
}
function d3_layout_treeShift(v) {
var shift = 0, change = 0, children = v.children, i = children.length, w;
while (--i >= 0) {
w = children[i];
w.z += shift;
w.m += shift;
shift += w.s + (change += w.c);
}
}
function d3_layout_treeAncestor(vim, v, ancestor) {
return vim.a.parent === v.parent ? vim.a : ancestor;
}
d3.layout.cluster = function() {
var hierarchy = d3.layout.hierarchy().sort(null).value(null), separation = d3_layout_treeSeparation, size = [ 1, 1 ], nodeSize = false;
function cluster(d, i) {
var nodes = hierarchy.call(this, d, i), root = nodes[0], previousNode, x = 0;
d3_layout_hierarchyVisitAfter(root, function(node) {
var children = node.children;
if (children && children.length) {
node.x = d3_layout_clusterX(children);
node.y = d3_layout_clusterY(children);
} else {
node.x = previousNode ? x += separation(node, previousNode) : 0;
node.y = 0;
previousNode = node;
}
});
var left = d3_layout_clusterLeft(root), right = d3_layout_clusterRight(root), x0 = left.x - separation(left, right) / 2, x1 = right.x + separation(right, left) / 2;
d3_layout_hierarchyVisitAfter(root, nodeSize ? function(node) {
node.x = (node.x - root.x) * size[0];
node.y = (root.y - node.y) * size[1];
} : function(node) {
node.x = (node.x - x0) / (x1 - x0) * size[0];
node.y = (1 - (root.y ? node.y / root.y : 1)) * size[1];
});
return nodes;
}
cluster.separation = function(x) {
if (!arguments.length) return separation;
separation = x;
return cluster;
};
cluster.size = function(x) {
if (!arguments.length) return nodeSize ? null : size;
nodeSize = (size = x) == null;
return cluster;
};
cluster.nodeSize = function(x) {
if (!arguments.length) return nodeSize ? size : null;
nodeSize = (size = x) != null;
return cluster;
};
return d3_layout_hierarchyRebind(cluster, hierarchy);
};
function d3_layout_clusterY(children) {
return 1 + d3.max(children, function(child) {
return child.y;
});
}
function d3_layout_clusterX(children) {
return children.reduce(function(x, child) {
return x + child.x;
}, 0) / children.length;
}
function d3_layout_clusterLeft(node) {
var children = node.children;
return children && children.length ? d3_layout_clusterLeft(children[0]) : node;
}
function d3_layout_clusterRight(node) {
var children = node.children, n;
return children && (n = children.length) ? d3_layout_clusterRight(children[n - 1]) : node;
}
d3.layout.treemap = function() {
var hierarchy = d3.layout.hierarchy(), round = Math.round, size = [ 1, 1 ], padding = null, pad = d3_layout_treemapPadNull, sticky = false, stickies, mode = "squarify", ratio = .5 * (1 + Math.sqrt(5));
function scale(children, k) {
var i = -1, n = children.length, child, area;
while (++i < n) {
area = (child = children[i]).value * (k < 0 ? 0 : k);
child.area = isNaN(area) || area <= 0 ? 0 : area;
}
}
function squarify(node) {
var children = node.children;
if (children && children.length) {
var rect = pad(node), row = [], remaining = children.slice(), child, best = Infinity, score, u = mode === "slice" ? rect.dx : mode === "dice" ? rect.dy : mode === "slice-dice" ? node.depth & 1 ? rect.dy : rect.dx : Math.min(rect.dx, rect.dy), n;
scale(remaining, rect.dx * rect.dy / node.value);
row.area = 0;
while ((n = remaining.length) > 0) {
row.push(child = remaining[n - 1]);
row.area += child.area;
if (mode !== "squarify" || (score = worst(row, u)) <= best) {
remaining.pop();
best = score;
} else {
row.area -= row.pop().area;
position(row, u, rect, false);
u = Math.min(rect.dx, rect.dy);
row.length = row.area = 0;
best = Infinity;
}
}
if (row.length) {
position(row, u, rect, true);
row.length = row.area = 0;
}
children.forEach(squarify);
}
}
function stickify(node) {
var children = node.children;
if (children && children.length) {
var rect = pad(node), remaining = children.slice(), child, row = [];
scale(remaining, rect.dx * rect.dy / node.value);
row.area = 0;
while (child = remaining.pop()) {
row.push(child);
row.area += child.area;
if (child.z != null) {
position(row, child.z ? rect.dx : rect.dy, rect, !remaining.length);
row.length = row.area = 0;
}
}
children.forEach(stickify);
}
}
function worst(row, u) {
var s = row.area, r, rmax = 0, rmin = Infinity, i = -1, n = row.length;
while (++i < n) {
if (!(r = row[i].area)) continue;
if (r < rmin) rmin = r;
if (r > rmax) rmax = r;
}
s *= s;
u *= u;
return s ? Math.max(u * rmax * ratio / s, s / (u * rmin * ratio)) : Infinity;
}
function position(row, u, rect, flush) {
var i = -1, n = row.length, x = rect.x, y = rect.y, v = u ? round(row.area / u) : 0, o;
if (u == rect.dx) {
if (flush || v > rect.dy) v = rect.dy;
while (++i < n) {
o = row[i];
o.x = x;
o.y = y;
o.dy = v;
x += o.dx = Math.min(rect.x + rect.dx - x, v ? round(o.area / v) : 0);
}
o.z = true;
o.dx += rect.x + rect.dx - x;
rect.y += v;
rect.dy -= v;
} else {
if (flush || v > rect.dx) v = rect.dx;
while (++i < n) {
o = row[i];
o.x = x;
o.y = y;
o.dx = v;
y += o.dy = Math.min(rect.y + rect.dy - y, v ? round(o.area / v) : 0);
}
o.z = false;
o.dy += rect.y + rect.dy - y;
rect.x += v;
rect.dx -= v;
}
}
function treemap(d) {
var nodes = stickies || hierarchy(d), root = nodes[0];
root.x = root.y = 0;
if (root.value) root.dx = size[0], root.dy = size[1]; else root.dx = root.dy = 0;
if (stickies) hierarchy.revalue(root);
scale([ root ], root.dx * root.dy / root.value);
(stickies ? stickify : squarify)(root);
if (sticky) stickies = nodes;
return nodes;
}
treemap.size = function(x) {
if (!arguments.length) return size;
size = x;
return treemap;
};
treemap.padding = function(x) {
if (!arguments.length) return padding;
function padFunction(node) {
var p = x.call(treemap, node, node.depth);
return p == null ? d3_layout_treemapPadNull(node) : d3_layout_treemapPad(node, typeof p === "number" ? [ p, p, p, p ] : p);
}
function padConstant(node) {
return d3_layout_treemapPad(node, x);
}
var type;
pad = (padding = x) == null ? d3_layout_treemapPadNull : (type = typeof x) === "function" ? padFunction : type === "number" ? (x = [ x, x, x, x ],
padConstant) : padConstant;
return treemap;
};
treemap.round = function(x) {
if (!arguments.length) return round != Number;
round = x ? Math.round : Number;
return treemap;
};
treemap.sticky = function(x) {
if (!arguments.length) return sticky;
sticky = x;
stickies = null;
return treemap;
};
treemap.ratio = function(x) {
if (!arguments.length) return ratio;
ratio = x;
return treemap;
};
treemap.mode = function(x) {
if (!arguments.length) return mode;
mode = x + "";
return treemap;
};
return d3_layout_hierarchyRebind(treemap, hierarchy);
};
function d3_layout_treemapPadNull(node) {
return {
x: node.x,
y: node.y,
dx: node.dx,
dy: node.dy
};
}
function d3_layout_treemapPad(node, padding) {
var x = node.x + padding[3], y = node.y + padding[0], dx = node.dx - padding[1] - padding[3], dy = node.dy - padding[0] - padding[2];
if (dx < 0) {
x += dx / 2;
dx = 0;
}
if (dy < 0) {
y += dy / 2;
dy = 0;
}
return {
x: x,
y: y,
dx: dx,
dy: dy
};
}
d3.random = {
normal: function(µ, σ) {
var n = arguments.length;
if (n < 2) σ = 1;
if (n < 1) µ = 0;
return function() {
var x, y, r;
do {
x = Math.random() * 2 - 1;
y = Math.random() * 2 - 1;
r = x * x + y * y;
} while (!r || r > 1);
return µ + σ * x * Math.sqrt(-2 * Math.log(r) / r);
};
},
logNormal: function() {
var random = d3.random.normal.apply(d3, arguments);
return function() {
return Math.exp(random());
};
},
bates: function(m) {
var random = d3.random.irwinHall(m);
return function() {
return random() / m;
};
},
irwinHall: function(m) {
return function() {
for (var s = 0, j = 0; j < m; j++) s += Math.random();
return s;
};
}
};
d3.scale = {};
function d3_scaleExtent(domain) {
var start = domain[0], stop = domain[domain.length - 1];
return start < stop ? [ start, stop ] : [ stop, start ];
}
function d3_scaleRange(scale) {
return scale.rangeExtent ? scale.rangeExtent() : d3_scaleExtent(scale.range());
}
function d3_scale_bilinear(domain, range, uninterpolate, interpolate) {
var u = uninterpolate(domain[0], domain[1]), i = interpolate(range[0], range[1]);
return function(x) {
return i(u(x));
};
}
function d3_scale_nice(domain, nice) {
var i0 = 0, i1 = domain.length - 1, x0 = domain[i0], x1 = domain[i1], dx;
if (x1 < x0) {
dx = i0, i0 = i1, i1 = dx;
dx = x0, x0 = x1, x1 = dx;
}
domain[i0] = nice.floor(x0);
domain[i1] = nice.ceil(x1);
return domain;
}
function d3_scale_niceStep(step) {
return step ? {
floor: function(x) {
return Math.floor(x / step) * step;
},
ceil: function(x) {
return Math.ceil(x / step) * step;
}
} : d3_scale_niceIdentity;
}
var d3_scale_niceIdentity = {
floor: d3_identity,
ceil: d3_identity
};
function d3_scale_polylinear(domain, range, uninterpolate, interpolate) {
var u = [], i = [], j = 0, k = Math.min(domain.length, range.length) - 1;
if (domain[k] < domain[0]) {
domain = domain.slice().reverse();
range = range.slice().reverse();
}
while (++j <= k) {
u.push(uninterpolate(domain[j - 1], domain[j]));
i.push(interpolate(range[j - 1], range[j]));
}
return function(x) {
var j = d3.bisect(domain, x, 1, k) - 1;
return i[j](u[j](x));
};
}
d3.scale.linear = function() {
return d3_scale_linear([ 0, 1 ], [ 0, 1 ], d3_interpolate, false);
};
function d3_scale_linear(domain, range, interpolate, clamp) {
var output, input;
function rescale() {
var linear = Math.min(domain.length, range.length) > 2 ? d3_scale_polylinear : d3_scale_bilinear, uninterpolate = clamp ? d3_uninterpolateClamp : d3_uninterpolateNumber;
output = linear(domain, range, uninterpolate, interpolate);
input = linear(range, domain, uninterpolate, d3_interpolate);
return scale;
}
function scale(x) {
return output(x);
}
scale.invert = function(y) {
return input(y);
};
scale.domain = function(x) {
if (!arguments.length) return domain;
domain = x.map(Number);
return rescale();
};
scale.range = function(x) {
if (!arguments.length) return range;
range = x;
return rescale();
};
scale.rangeRound = function(x) {
return scale.range(x).interpolate(d3_interpolateRound);
};
scale.clamp = function(x) {
if (!arguments.length) return clamp;
clamp = x;
return rescale();
};
scale.interpolate = function(x) {
if (!arguments.length) return interpolate;
interpolate = x;
return rescale();
};
scale.ticks = function(m) {
return d3_scale_linearTicks(domain, m);
};
scale.tickFormat = function(m, format) {
return d3_scale_linearTickFormat(domain, m, format);
};
scale.nice = function(m) {
d3_scale_linearNice(domain, m);
return rescale();
};
scale.copy = function() {
return d3_scale_linear(domain, range, interpolate, clamp);
};
return rescale();
}
function d3_scale_linearRebind(scale, linear) {
return d3.rebind(scale, linear, "range", "rangeRound", "interpolate", "clamp");
}
function d3_scale_linearNice(domain, m) {
d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
d3_scale_nice(domain, d3_scale_niceStep(d3_scale_linearTickRange(domain, m)[2]));
return domain;
}
function d3_scale_linearTickRange(domain, m) {
if (m == null) m = 10;
var extent = d3_scaleExtent(domain), span = extent[1] - extent[0], step = Math.pow(10, Math.floor(Math.log(span / m) / Math.LN10)), err = m / span * step;
if (err <= .15) step *= 10; else if (err <= .35) step *= 5; else if (err <= .75) step *= 2;
extent[0] = Math.ceil(extent[0] / step) * step;
extent[1] = Math.floor(extent[1] / step) * step + step * .5;
extent[2] = step;
return extent;
}
function d3_scale_linearTicks(domain, m) {
return d3.range.apply(d3, d3_scale_linearTickRange(domain, m));
}
var d3_scale_linearFormatSignificant = {
s: 1,
g: 1,
p: 1,
r: 1,
e: 1
};
function d3_scale_linearPrecision(value) {
return -Math.floor(Math.log(value) / Math.LN10 + .01);
}
function d3_scale_linearFormatPrecision(type, range) {
var p = d3_scale_linearPrecision(range[2]);
return type in d3_scale_linearFormatSignificant ? Math.abs(p - d3_scale_linearPrecision(Math.max(abs(range[0]), abs(range[1])))) + +(type !== "e") : p - (type === "%") * 2;
}
d3.scale.log = function() {
return d3_scale_log(d3.scale.linear().domain([ 0, 1 ]), 10, true, [ 1, 10 ]);
};
function d3_scale_log(linear, base, positive, domain) {
function log(x) {
return (positive ? Math.log(x < 0 ? 0 : x) : -Math.log(x > 0 ? 0 : -x)) / Math.log(base);
}
function pow(x) {
return positive ? Math.pow(base, x) : -Math.pow(base, -x);
}
function scale(x) {
return linear(log(x));
}
scale.invert = function(x) {
return pow(linear.invert(x));
};
scale.domain = function(x) {
if (!arguments.length) return domain;
positive = x[0] >= 0;
linear.domain((domain = x.map(Number)).map(log));
return scale;
};
scale.base = function(_) {
if (!arguments.length) return base;
base = +_;
linear.domain(domain.map(log));
return scale;
};
scale.nice = function() {
var niced = d3_scale_nice(domain.map(log), positive ? Math : d3_scale_logNiceNegative);
linear.domain(niced);
domain = niced.map(pow);
return scale;
};
scale.ticks = function() {
var extent = d3_scaleExtent(domain), ticks = [], u = extent[0], v = extent[1], i = Math.floor(log(u)), j = Math.ceil(log(v)), n = base % 1 ? 2 : base;
if (isFinite(j - i)) {
if (positive) {
for (;i < j; i++) for (var k = 1; k < n; k++) ticks.push(pow(i) * k);
ticks.push(pow(i));
} else {
ticks.push(pow(i));
for (;i++ < j; ) for (var k = n - 1; k > 0; k--) ticks.push(pow(i) * k);
}
for (i = 0; ticks[i] < u; i++) {}
for (j = ticks.length; ticks[j - 1] > v; j--) {}
ticks = ticks.slice(i, j);
}
return ticks;
};
scale.copy = function() {
return d3_scale_log(linear.copy(), base, positive, domain);
};
return d3_scale_linearRebind(scale, linear);
}
var d3_scale_logNiceNegative = {
floor: function(x) {
return -Math.ceil(-x);
},
ceil: function(x) {
return -Math.floor(-x);
}
};
d3.scale.pow = function() {
return d3_scale_pow(d3.scale.linear(), 1, [ 0, 1 ]);
};
function d3_scale_pow(linear, exponent, domain) {
var powp = d3_scale_powPow(exponent), powb = d3_scale_powPow(1 / exponent);
function scale(x) {
return linear(powp(x));
}
scale.invert = function(x) {
return powb(linear.invert(x));
};
scale.domain = function(x) {
if (!arguments.length) return domain;
linear.domain((domain = x.map(Number)).map(powp));
return scale;
};
scale.ticks = function(m) {
return d3_scale_linearTicks(domain, m);
};
scale.tickFormat = function(m, format) {
return d3_scale_linearTickFormat(domain, m, format);
};
scale.nice = function(m) {
return scale.domain(d3_scale_linearNice(domain, m));
};
scale.exponent = function(x) {
if (!arguments.length) return exponent;
powp = d3_scale_powPow(exponent = x);
powb = d3_scale_powPow(1 / exponent);
linear.domain(domain.map(powp));
return scale;
};
scale.copy = function() {
return d3_scale_pow(linear.copy(), exponent, domain);
};
return d3_scale_linearRebind(scale, linear);
}
function d3_scale_powPow(e) {
return function(x) {
return x < 0 ? -Math.pow(-x, e) : Math.pow(x, e);
};
}
d3.scale.sqrt = function() {
return d3.scale.pow().exponent(.5);
};
d3.scale.ordinal = function() {
return d3_scale_ordinal([], {
t: "range",
a: [ [] ]
});
};
function d3_scale_ordinal(domain, ranger) {
var index, range, rangeBand;
function scale(x) {
return range[((index.get(x) || (ranger.t === "range" ? index.set(x, domain.push(x)) : NaN)) - 1) % range.length];
}
function steps(start, step) {
return d3.range(domain.length).map(function(i) {
return start + step * i;
});
}
scale.domain = function(x) {
if (!arguments.length) return domain;
domain = [];
index = new d3_Map();
var i = -1, n = x.length, xi;
while (++i < n) if (!index.has(xi = x[i])) index.set(xi, domain.push(xi));
return scale[ranger.t].apply(scale, ranger.a);
};
scale.range = function(x) {
if (!arguments.length) return range;
range = x;
rangeBand = 0;
ranger = {
t: "range",
a: arguments
};
return scale;
};
scale.rangePoints = function(x, padding) {
if (arguments.length < 2) padding = 0;
var start = x[0], stop = x[1], step = domain.length < 2 ? (start = (start + stop) / 2,
0) : (stop - start) / (domain.length - 1 + padding);
range = steps(start + step * padding / 2, step);
rangeBand = 0;
ranger = {
t: "rangePoints",
a: arguments
};
return scale;
};
scale.rangeRoundPoints = function(x, padding) {
if (arguments.length < 2) padding = 0;
var start = x[0], stop = x[1], step = domain.length < 2 ? (start = stop = Math.round((start + stop) / 2),
0) : (stop - start) / (domain.length - 1 + padding) | 0;
range = steps(start + Math.round(step * padding / 2 + (stop - start - (domain.length - 1 + padding) * step) / 2), step);
rangeBand = 0;
ranger = {
t: "rangeRoundPoints",
a: arguments
};
return scale;
};
scale.rangeBands = function(x, padding, outerPadding) {
if (arguments.length < 2) padding = 0;
if (arguments.length < 3) outerPadding = padding;
var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = (stop - start) / (domain.length - padding + 2 * outerPadding);
range = steps(start + step * outerPadding, step);
if (reverse) range.reverse();
rangeBand = step * (1 - padding);
ranger = {
t: "rangeBands",
a: arguments
};
return scale;
};
scale.rangeRoundBands = function(x, padding, outerPadding) {
if (arguments.length < 2) padding = 0;
if (arguments.length < 3) outerPadding = padding;
var reverse = x[1] < x[0], start = x[reverse - 0], stop = x[1 - reverse], step = Math.floor((stop - start) / (domain.length - padding + 2 * outerPadding));
range = steps(start + Math.round((stop - start - (domain.length - padding) * step) / 2), step);
if (reverse) range.reverse();
rangeBand = Math.round(step * (1 - padding));
ranger = {
t: "rangeRoundBands",
a: arguments
};
return scale;
};
scale.rangeBand = function() {
return rangeBand;
};
scale.rangeExtent = function() {
return d3_scaleExtent(ranger.a[0]);
};
scale.copy = function() {
return d3_scale_ordinal(domain, ranger);
};
return scale.domain(domain);
}
d3.scale.category10 = function() {
return d3.scale.ordinal().range(d3_category10);
};
d3.scale.category20 = function() {
return d3.scale.ordinal().range(d3_category20);
};
d3.scale.category20b = function() {
return d3.scale.ordinal().range(d3_category20b);
};
d3.scale.category20c = function() {
return d3.scale.ordinal().range(d3_category20c);
};
var d3_category10 = [ 2062260, 16744206, 2924588, 14034728, 9725885, 9197131, 14907330, 8355711, 12369186, 1556175 ].map(d3_rgbString);
var d3_category20 = [ 2062260, 11454440, 16744206, 16759672, 2924588, 10018698, 14034728, 16750742, 9725885, 12955861, 9197131, 12885140, 14907330, 16234194, 8355711, 13092807, 12369186, 14408589, 1556175, 10410725 ].map(d3_rgbString);
var d3_category20b = [ 3750777, 5395619, 7040719, 10264286, 6519097, 9216594, 11915115, 13556636, 9202993, 12426809, 15186514, 15190932, 8666169, 11356490, 14049643, 15177372, 8077683, 10834324, 13528509, 14589654 ].map(d3_rgbString);
var d3_category20c = [ 3244733, 7057110, 10406625, 13032431, 15095053, 16616764, 16625259, 16634018, 3253076, 7652470, 10607003, 13101504, 7695281, 10394312, 12369372, 14342891, 6513507, 9868950, 12434877, 14277081 ].map(d3_rgbString);
d3.scale.quantile = function() {
return d3_scale_quantile([], []);
};
function d3_scale_quantile(domain, range) {
var thresholds;
function rescale() {
var k = 0, q = range.length;
thresholds = [];
while (++k < q) thresholds[k - 1] = d3.quantile(domain, k / q);
return scale;
}
function scale(x) {
if (!isNaN(x = +x)) return range[d3.bisect(thresholds, x)];
}
scale.domain = function(x) {
if (!arguments.length) return domain;
domain = x.map(d3_number).filter(d3_numeric).sort(d3_ascending);
return rescale();
};
scale.range = function(x) {
if (!arguments.length) return range;
range = x;
return rescale();
};
scale.quantiles = function() {
return thresholds;
};
scale.invertExtent = function(y) {
y = range.indexOf(y);
return y < 0 ? [ NaN, NaN ] : [ y > 0 ? thresholds[y - 1] : domain[0], y < thresholds.length ? thresholds[y] : domain[domain.length - 1] ];
};
scale.copy = function() {
return d3_scale_quantile(domain, range);
};
return rescale();
}
d3.scale.quantize = function() {
return d3_scale_quantize(0, 1, [ 0, 1 ]);
};
function d3_scale_quantize(x0, x1, range) {
var kx, i;
function scale(x) {
return range[Math.max(0, Math.min(i, Math.floor(kx * (x - x0))))];
}
function rescale() {
kx = range.length / (x1 - x0);
i = range.length - 1;
return scale;
}
scale.domain = function(x) {
if (!arguments.length) return [ x0, x1 ];
x0 = +x[0];
x1 = +x[x.length - 1];
return rescale();
};
scale.range = function(x) {
if (!arguments.length) return range;
range = x;
return rescale();
};
scale.invertExtent = function(y) {
y = range.indexOf(y);
y = y < 0 ? NaN : y / kx + x0;
return [ y, y + 1 / kx ];
};
scale.copy = function() {
return d3_scale_quantize(x0, x1, range);
};
return rescale();
}
d3.scale.threshold = function() {
return d3_scale_threshold([ .5 ], [ 0, 1 ]);
};
function d3_scale_threshold(domain, range) {
function scale(x) {
if (x <= x) return range[d3.bisect(domain, x)];
}
scale.domain = function(_) {
if (!arguments.length) return domain;
domain = _;
return scale;
};
scale.range = function(_) {
if (!arguments.length) return range;
range = _;
return scale;
};
scale.invertExtent = function(y) {
y = range.indexOf(y);
return [ domain[y - 1], domain[y] ];
};
scale.copy = function() {
return d3_scale_threshold(domain, range);
};
return scale;
}
d3.scale.identity = function() {
return d3_scale_identity([ 0, 1 ]);
};
function d3_scale_identity(domain) {
function identity(x) {
return +x;
}
identity.invert = identity;
identity.domain = identity.range = function(x) {
if (!arguments.length) return domain;
domain = x.map(identity);
return identity;
};
identity.ticks = function(m) {
return d3_scale_linearTicks(domain, m);
};
identity.tickFormat = function(m, format) {
return d3_scale_linearTickFormat(domain, m, format);
};
identity.copy = function() {
return d3_scale_identity(domain);
};
return identity;
}
d3.svg = {};
function d3_zero() {
return 0;
}
d3.svg.arc = function() {
var innerRadius = d3_svg_arcInnerRadius, outerRadius = d3_svg_arcOuterRadius, cornerRadius = d3_zero, padRadius = d3_svg_arcAuto, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle, padAngle = d3_svg_arcPadAngle;
function arc() {
var r0 = Math.max(0, +innerRadius.apply(this, arguments)), r1 = Math.max(0, +outerRadius.apply(this, arguments)), a0 = startAngle.apply(this, arguments) - halfπ, a1 = endAngle.apply(this, arguments) - halfπ, da = Math.abs(a1 - a0), cw = a0 > a1 ? 0 : 1;
if (r1 < r0) rc = r1, r1 = r0, r0 = rc;
if (da >= τε) return circleSegment(r1, cw) + (r0 ? circleSegment(r0, 1 - cw) : "") + "Z";
var rc, cr, rp, ap, p0 = 0, p1 = 0, x0, y0, x1, y1, x2, y2, x3, y3, path = [];
if (ap = (+padAngle.apply(this, arguments) || 0) / 2) {
rp = padRadius === d3_svg_arcAuto ? Math.sqrt(r0 * r0 + r1 * r1) : +padRadius.apply(this, arguments);
if (!cw) p1 *= -1;
if (r1) p1 = d3_asin(rp / r1 * Math.sin(ap));
if (r0) p0 = d3_asin(rp / r0 * Math.sin(ap));
}
if (r1) {
x0 = r1 * Math.cos(a0 + p1);
y0 = r1 * Math.sin(a0 + p1);
x1 = r1 * Math.cos(a1 - p1);
y1 = r1 * Math.sin(a1 - p1);
var l1 = Math.abs(a1 - a0 - 2 * p1) <= π ? 0 : 1;
if (p1 && d3_svg_arcSweep(x0, y0, x1, y1) === cw ^ l1) {
var h1 = (a0 + a1) / 2;
x0 = r1 * Math.cos(h1);
y0 = r1 * Math.sin(h1);
x1 = y1 = null;
}
} else {
x0 = y0 = 0;
}
if (r0) {
x2 = r0 * Math.cos(a1 - p0);
y2 = r0 * Math.sin(a1 - p0);
x3 = r0 * Math.cos(a0 + p0);
y3 = r0 * Math.sin(a0 + p0);
var l0 = Math.abs(a0 - a1 + 2 * p0) <= π ? 0 : 1;
if (p0 && d3_svg_arcSweep(x2, y2, x3, y3) === 1 - cw ^ l0) {
var h0 = (a0 + a1) / 2;
x2 = r0 * Math.cos(h0);
y2 = r0 * Math.sin(h0);
x3 = y3 = null;
}
} else {
x2 = y2 = 0;
}
if (da > ε && (rc = Math.min(Math.abs(r1 - r0) / 2, +cornerRadius.apply(this, arguments))) > .001) {
cr = r0 < r1 ^ cw ? 0 : 1;
var rc1 = rc, rc0 = rc;
if (da < π) {
var oc = x3 == null ? [ x2, y2 ] : x1 == null ? [ x0, y0 ] : d3_geom_polygonIntersect([ x0, y0 ], [ x3, y3 ], [ x1, y1 ], [ x2, y2 ]), ax = x0 - oc[0], ay = y0 - oc[1], bx = x1 - oc[0], by = y1 - oc[1], kc = 1 / Math.sin(Math.acos((ax * bx + ay * by) / (Math.sqrt(ax * ax + ay * ay) * Math.sqrt(bx * bx + by * by))) / 2), lc = Math.sqrt(oc[0] * oc[0] + oc[1] * oc[1]);
rc0 = Math.min(rc, (r0 - lc) / (kc - 1));
rc1 = Math.min(rc, (r1 - lc) / (kc + 1));
}
if (x1 != null) {
var t30 = d3_svg_arcCornerTangents(x3 == null ? [ x2, y2 ] : [ x3, y3 ], [ x0, y0 ], r1, rc1, cw), t12 = d3_svg_arcCornerTangents([ x1, y1 ], [ x2, y2 ], r1, rc1, cw);
if (rc === rc1) {
path.push("M", t30[0], "A", rc1, ",", rc1, " 0 0,", cr, " ", t30[1], "A", r1, ",", r1, " 0 ", 1 - cw ^ d3_svg_arcSweep(t30[1][0], t30[1][1], t12[1][0], t12[1][1]), ",", cw, " ", t12[1], "A", rc1, ",", rc1, " 0 0,", cr, " ", t12[0]);
} else {
path.push("M", t30[0], "A", rc1, ",", rc1, " 0 1,", cr, " ", t12[0]);
}
} else {
path.push("M", x0, ",", y0);
}
if (x3 != null) {
var t03 = d3_svg_arcCornerTangents([ x0, y0 ], [ x3, y3 ], r0, -rc0, cw), t21 = d3_svg_arcCornerTangents([ x2, y2 ], x1 == null ? [ x0, y0 ] : [ x1, y1 ], r0, -rc0, cw);
if (rc === rc0) {
path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t21[1], "A", r0, ",", r0, " 0 ", cw ^ d3_svg_arcSweep(t21[1][0], t21[1][1], t03[1][0], t03[1][1]), ",", 1 - cw, " ", t03[1], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
} else {
path.push("L", t21[0], "A", rc0, ",", rc0, " 0 0,", cr, " ", t03[0]);
}
} else {
path.push("L", x2, ",", y2);
}
} else {
path.push("M", x0, ",", y0);
if (x1 != null) path.push("A", r1, ",", r1, " 0 ", l1, ",", cw, " ", x1, ",", y1);
path.push("L", x2, ",", y2);
if (x3 != null) path.push("A", r0, ",", r0, " 0 ", l0, ",", 1 - cw, " ", x3, ",", y3);
}
path.push("Z");
return path.join("");
}
function circleSegment(r1, cw) {
return "M0," + r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + -r1 + "A" + r1 + "," + r1 + " 0 1," + cw + " 0," + r1;
}
arc.innerRadius = function(v) {
if (!arguments.length) return innerRadius;
innerRadius = d3_functor(v);
return arc;
};
arc.outerRadius = function(v) {
if (!arguments.length) return outerRadius;
outerRadius = d3_functor(v);
return arc;
};
arc.cornerRadius = function(v) {
if (!arguments.length) return cornerRadius;
cornerRadius = d3_functor(v);
return arc;
};
arc.padRadius = function(v) {
if (!arguments.length) return padRadius;
padRadius = v == d3_svg_arcAuto ? d3_svg_arcAuto : d3_functor(v);
return arc;
};
arc.startAngle = function(v) {
if (!arguments.length) return startAngle;
startAngle = d3_functor(v);
return arc;
};
arc.endAngle = function(v) {
if (!arguments.length) return endAngle;
endAngle = d3_functor(v);
return arc;
};
arc.padAngle = function(v) {
if (!arguments.length) return padAngle;
padAngle = d3_functor(v);
return arc;
};
arc.centroid = function() {
var r = (+innerRadius.apply(this, arguments) + +outerRadius.apply(this, arguments)) / 2, a = (+startAngle.apply(this, arguments) + +endAngle.apply(this, arguments)) / 2 - halfπ;
return [ Math.cos(a) * r, Math.sin(a) * r ];
};
return arc;
};
var d3_svg_arcAuto = "auto";
function d3_svg_arcInnerRadius(d) {
return d.innerRadius;
}
function d3_svg_arcOuterRadius(d) {
return d.outerRadius;
}
function d3_svg_arcStartAngle(d) {
return d.startAngle;
}
function d3_svg_arcEndAngle(d) {
return d.endAngle;
}
function d3_svg_arcPadAngle(d) {
return d && d.padAngle;
}
function d3_svg_arcSweep(x0, y0, x1, y1) {
return (x0 - x1) * y0 - (y0 - y1) * x0 > 0 ? 0 : 1;
}
function d3_svg_arcCornerTangents(p0, p1, r1, rc, cw) {
var x01 = p0[0] - p1[0], y01 = p0[1] - p1[1], lo = (cw ? rc : -rc) / Math.sqrt(x01 * x01 + y01 * y01), ox = lo * y01, oy = -lo * x01, x1 = p0[0] + ox, y1 = p0[1] + oy, x2 = p1[0] + ox, y2 = p1[1] + oy, x3 = (x1 + x2) / 2, y3 = (y1 + y2) / 2, dx = x2 - x1, dy = y2 - y1, d2 = dx * dx + dy * dy, r = r1 - rc, D = x1 * y2 - x2 * y1, d = (dy < 0 ? -1 : 1) * Math.sqrt(Math.max(0, r * r * d2 - D * D)), cx0 = (D * dy - dx * d) / d2, cy0 = (-D * dx - dy * d) / d2, cx1 = (D * dy + dx * d) / d2, cy1 = (-D * dx + dy * d) / d2, dx0 = cx0 - x3, dy0 = cy0 - y3, dx1 = cx1 - x3, dy1 = cy1 - y3;
if (dx0 * dx0 + dy0 * dy0 > dx1 * dx1 + dy1 * dy1) cx0 = cx1, cy0 = cy1;
return [ [ cx0 - ox, cy0 - oy ], [ cx0 * r1 / r, cy0 * r1 / r ] ];
}
function d3_true() {
return true;
}
function d3_svg_line(projection) {
var x = d3_geom_pointX, y = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, tension = .7;
function line(data) {
var segments = [], points = [], i = -1, n = data.length, d, fx = d3_functor(x), fy = d3_functor(y);
function segment() {
segments.push("M", interpolate(projection(points), tension));
}
while (++i < n) {
if (defined.call(this, d = data[i], i)) {
points.push([ +fx.call(this, d, i), +fy.call(this, d, i) ]);
} else if (points.length) {
segment();
points = [];
}
}
if (points.length) segment();
return segments.length ? segments.join("") : null;
}
line.x = function(_) {
if (!arguments.length) return x;
x = _;
return line;
};
line.y = function(_) {
if (!arguments.length) return y;
y = _;
return line;
};
line.defined = function(_) {
if (!arguments.length) return defined;
defined = _;
return line;
};
line.interpolate = function(_) {
if (!arguments.length) return interpolateKey;
if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
return line;
};
line.tension = function(_) {
if (!arguments.length) return tension;
tension = _;
return line;
};
return line;
}
d3.svg.line = function() {
return d3_svg_line(d3_identity);
};
var d3_svg_lineInterpolators = d3.map({
linear: d3_svg_lineLinear,
"linear-closed": d3_svg_lineLinearClosed,
step: d3_svg_lineStep,
"step-before": d3_svg_lineStepBefore,
"step-after": d3_svg_lineStepAfter,
basis: d3_svg_lineBasis,
"basis-open": d3_svg_lineBasisOpen,
"basis-closed": d3_svg_lineBasisClosed,
bundle: d3_svg_lineBundle,
cardinal: d3_svg_lineCardinal,
"cardinal-open": d3_svg_lineCardinalOpen,
"cardinal-closed": d3_svg_lineCardinalClosed,
monotone: d3_svg_lineMonotone
});
d3_svg_lineInterpolators.forEach(function(key, value) {
value.key = key;
value.closed = /-closed$/.test(key);
});
function d3_svg_lineLinear(points) {
return points.length > 1 ? points.join("L") : points + "Z";
}
function d3_svg_lineLinearClosed(points) {
return points.join("L") + "Z";
}
function d3_svg_lineStep(points) {
var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
while (++i < n) path.push("H", (p[0] + (p = points[i])[0]) / 2, "V", p[1]);
if (n > 1) path.push("H", p[0]);
return path.join("");
}
function d3_svg_lineStepBefore(points) {
var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
while (++i < n) path.push("V", (p = points[i])[1], "H", p[0]);
return path.join("");
}
function d3_svg_lineStepAfter(points) {
var i = 0, n = points.length, p = points[0], path = [ p[0], ",", p[1] ];
while (++i < n) path.push("H", (p = points[i])[0], "V", p[1]);
return path.join("");
}
function d3_svg_lineCardinalOpen(points, tension) {
return points.length < 4 ? d3_svg_lineLinear(points) : points[1] + d3_svg_lineHermite(points.slice(1, -1), d3_svg_lineCardinalTangents(points, tension));
}
function d3_svg_lineCardinalClosed(points, tension) {
return points.length < 3 ? d3_svg_lineLinearClosed(points) : points[0] + d3_svg_lineHermite((points.push(points[0]),
points), d3_svg_lineCardinalTangents([ points[points.length - 2] ].concat(points, [ points[1] ]), tension));
}
function d3_svg_lineCardinal(points, tension) {
return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineCardinalTangents(points, tension));
}
function d3_svg_lineHermite(points, tangents) {
if (tangents.length < 1 || points.length != tangents.length && points.length != tangents.length + 2) {
return d3_svg_lineLinear(points);
}
var quad = points.length != tangents.length, path = "", p0 = points[0], p = points[1], t0 = tangents[0], t = t0, pi = 1;
if (quad) {
path += "Q" + (p[0] - t0[0] * 2 / 3) + "," + (p[1] - t0[1] * 2 / 3) + "," + p[0] + "," + p[1];
p0 = points[1];
pi = 2;
}
if (tangents.length > 1) {
t = tangents[1];
p = points[pi];
pi++;
path += "C" + (p0[0] + t0[0]) + "," + (p0[1] + t0[1]) + "," + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
for (var i = 2; i < tangents.length; i++, pi++) {
p = points[pi];
t = tangents[i];
path += "S" + (p[0] - t[0]) + "," + (p[1] - t[1]) + "," + p[0] + "," + p[1];
}
}
if (quad) {
var lp = points[pi];
path += "Q" + (p[0] + t[0] * 2 / 3) + "," + (p[1] + t[1] * 2 / 3) + "," + lp[0] + "," + lp[1];
}
return path;
}
function d3_svg_lineCardinalTangents(points, tension) {
var tangents = [], a = (1 - tension) / 2, p0, p1 = points[0], p2 = points[1], i = 1, n = points.length;
while (++i < n) {
p0 = p1;
p1 = p2;
p2 = points[i];
tangents.push([ a * (p2[0] - p0[0]), a * (p2[1] - p0[1]) ]);
}
return tangents;
}
function d3_svg_lineBasis(points) {
if (points.length < 3) return d3_svg_lineLinear(points);
var i = 1, n = points.length, pi = points[0], x0 = pi[0], y0 = pi[1], px = [ x0, x0, x0, (pi = points[1])[0] ], py = [ y0, y0, y0, pi[1] ], path = [ x0, ",", y0, "L", d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
points.push(points[n - 1]);
while (++i <= n) {
pi = points[i];
px.shift();
px.push(pi[0]);
py.shift();
py.push(pi[1]);
d3_svg_lineBasisBezier(path, px, py);
}
points.pop();
path.push("L", pi);
return path.join("");
}
function d3_svg_lineBasisOpen(points) {
if (points.length < 4) return d3_svg_lineLinear(points);
var path = [], i = -1, n = points.length, pi, px = [ 0 ], py = [ 0 ];
while (++i < 3) {
pi = points[i];
px.push(pi[0]);
py.push(pi[1]);
}
path.push(d3_svg_lineDot4(d3_svg_lineBasisBezier3, px) + "," + d3_svg_lineDot4(d3_svg_lineBasisBezier3, py));
--i;
while (++i < n) {
pi = points[i];
px.shift();
px.push(pi[0]);
py.shift();
py.push(pi[1]);
d3_svg_lineBasisBezier(path, px, py);
}
return path.join("");
}
function d3_svg_lineBasisClosed(points) {
var path, i = -1, n = points.length, m = n + 4, pi, px = [], py = [];
while (++i < 4) {
pi = points[i % n];
px.push(pi[0]);
py.push(pi[1]);
}
path = [ d3_svg_lineDot4(d3_svg_lineBasisBezier3, px), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, py) ];
--i;
while (++i < m) {
pi = points[i % n];
px.shift();
px.push(pi[0]);
py.shift();
py.push(pi[1]);
d3_svg_lineBasisBezier(path, px, py);
}
return path.join("");
}
function d3_svg_lineBundle(points, tension) {
var n = points.length - 1;
if (n) {
var x0 = points[0][0], y0 = points[0][1], dx = points[n][0] - x0, dy = points[n][1] - y0, i = -1, p, t;
while (++i <= n) {
p = points[i];
t = i / n;
p[0] = tension * p[0] + (1 - tension) * (x0 + t * dx);
p[1] = tension * p[1] + (1 - tension) * (y0 + t * dy);
}
}
return d3_svg_lineBasis(points);
}
function d3_svg_lineDot4(a, b) {
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
}
var d3_svg_lineBasisBezier1 = [ 0, 2 / 3, 1 / 3, 0 ], d3_svg_lineBasisBezier2 = [ 0, 1 / 3, 2 / 3, 0 ], d3_svg_lineBasisBezier3 = [ 0, 1 / 6, 2 / 3, 1 / 6 ];
function d3_svg_lineBasisBezier(path, x, y) {
path.push("C", d3_svg_lineDot4(d3_svg_lineBasisBezier1, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier1, y), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier2, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier2, y), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, x), ",", d3_svg_lineDot4(d3_svg_lineBasisBezier3, y));
}
function d3_svg_lineSlope(p0, p1) {
return (p1[1] - p0[1]) / (p1[0] - p0[0]);
}
function d3_svg_lineFiniteDifferences(points) {
var i = 0, j = points.length - 1, m = [], p0 = points[0], p1 = points[1], d = m[0] = d3_svg_lineSlope(p0, p1);
while (++i < j) {
m[i] = (d + (d = d3_svg_lineSlope(p0 = p1, p1 = points[i + 1]))) / 2;
}
m[i] = d;
return m;
}
function d3_svg_lineMonotoneTangents(points) {
var tangents = [], d, a, b, s, m = d3_svg_lineFiniteDifferences(points), i = -1, j = points.length - 1;
while (++i < j) {
d = d3_svg_lineSlope(points[i], points[i + 1]);
if (abs(d) < ε) {
m[i] = m[i + 1] = 0;
} else {
a = m[i] / d;
b = m[i + 1] / d;
s = a * a + b * b;
if (s > 9) {
s = d * 3 / Math.sqrt(s);
m[i] = s * a;
m[i + 1] = s * b;
}
}
}
i = -1;
while (++i <= j) {
s = (points[Math.min(j, i + 1)][0] - points[Math.max(0, i - 1)][0]) / (6 * (1 + m[i] * m[i]));
tangents.push([ s || 0, m[i] * s || 0 ]);
}
return tangents;
}
function d3_svg_lineMonotone(points) {
return points.length < 3 ? d3_svg_lineLinear(points) : points[0] + d3_svg_lineHermite(points, d3_svg_lineMonotoneTangents(points));
}
d3.svg.line.radial = function() {
var line = d3_svg_line(d3_svg_lineRadial);
line.radius = line.x, delete line.x;
line.angle = line.y, delete line.y;
return line;
};
function d3_svg_lineRadial(points) {
var point, i = -1, n = points.length, r, a;
while (++i < n) {
point = points[i];
r = point[0];
a = point[1] - halfπ;
point[0] = r * Math.cos(a);
point[1] = r * Math.sin(a);
}
return points;
}
function d3_svg_area(projection) {
var x0 = d3_geom_pointX, x1 = d3_geom_pointX, y0 = 0, y1 = d3_geom_pointY, defined = d3_true, interpolate = d3_svg_lineLinear, interpolateKey = interpolate.key, interpolateReverse = interpolate, L = "L", tension = .7;
function area(data) {
var segments = [], points0 = [], points1 = [], i = -1, n = data.length, d, fx0 = d3_functor(x0), fy0 = d3_functor(y0), fx1 = x0 === x1 ? function() {
return x;
} : d3_functor(x1), fy1 = y0 === y1 ? function() {
return y;
} : d3_functor(y1), x, y;
function segment() {
segments.push("M", interpolate(projection(points1), tension), L, interpolateReverse(projection(points0.reverse()), tension), "Z");
}
while (++i < n) {
if (defined.call(this, d = data[i], i)) {
points0.push([ x = +fx0.call(this, d, i), y = +fy0.call(this, d, i) ]);
points1.push([ +fx1.call(this, d, i), +fy1.call(this, d, i) ]);
} else if (points0.length) {
segment();
points0 = [];
points1 = [];
}
}
if (points0.length) segment();
return segments.length ? segments.join("") : null;
}
area.x = function(_) {
if (!arguments.length) return x1;
x0 = x1 = _;
return area;
};
area.x0 = function(_) {
if (!arguments.length) return x0;
x0 = _;
return area;
};
area.x1 = function(_) {
if (!arguments.length) return x1;
x1 = _;
return area;
};
area.y = function(_) {
if (!arguments.length) return y1;
y0 = y1 = _;
return area;
};
area.y0 = function(_) {
if (!arguments.length) return y0;
y0 = _;
return area;
};
area.y1 = function(_) {
if (!arguments.length) return y1;
y1 = _;
return area;
};
area.defined = function(_) {
if (!arguments.length) return defined;
defined = _;
return area;
};
area.interpolate = function(_) {
if (!arguments.length) return interpolateKey;
if (typeof _ === "function") interpolateKey = interpolate = _; else interpolateKey = (interpolate = d3_svg_lineInterpolators.get(_) || d3_svg_lineLinear).key;
interpolateReverse = interpolate.reverse || interpolate;
L = interpolate.closed ? "M" : "L";
return area;
};
area.tension = function(_) {
if (!arguments.length) return tension;
tension = _;
return area;
};
return area;
}
d3_svg_lineStepBefore.reverse = d3_svg_lineStepAfter;
d3_svg_lineStepAfter.reverse = d3_svg_lineStepBefore;
d3.svg.area = function() {
return d3_svg_area(d3_identity);
};
d3.svg.area.radial = function() {
var area = d3_svg_area(d3_svg_lineRadial);
area.radius = area.x, delete area.x;
area.innerRadius = area.x0, delete area.x0;
area.outerRadius = area.x1, delete area.x1;
area.angle = area.y, delete area.y;
area.startAngle = area.y0, delete area.y0;
area.endAngle = area.y1, delete area.y1;
return area;
};
function d3_source(d) {
return d.source;
}
function d3_target(d) {
return d.target;
}
d3.svg.chord = function() {
var source = d3_source, target = d3_target, radius = d3_svg_chordRadius, startAngle = d3_svg_arcStartAngle, endAngle = d3_svg_arcEndAngle;
function chord(d, i) {
var s = subgroup(this, source, d, i), t = subgroup(this, target, d, i);
return "M" + s.p0 + arc(s.r, s.p1, s.a1 - s.a0) + (equals(s, t) ? curve(s.r, s.p1, s.r, s.p0) : curve(s.r, s.p1, t.r, t.p0) + arc(t.r, t.p1, t.a1 - t.a0) + curve(t.r, t.p1, s.r, s.p0)) + "Z";
}
function subgroup(self, f, d, i) {
var subgroup = f.call(self, d, i), r = radius.call(self, subgroup, i), a0 = startAngle.call(self, subgroup, i) - halfπ, a1 = endAngle.call(self, subgroup, i) - halfπ;
return {
r: r,
a0: a0,
a1: a1,
p0: [ r * Math.cos(a0), r * Math.sin(a0) ],
p1: [ r * Math.cos(a1), r * Math.sin(a1) ]
};
}
function equals(a, b) {
return a.a0 == b.a0 && a.a1 == b.a1;
}
function arc(r, p, a) {
return "A" + r + "," + r + " 0 " + +(a > π) + ",1 " + p;
}
function curve(r0, p0, r1, p1) {
return "Q 0,0 " + p1;
}
chord.radius = function(v) {
if (!arguments.length) return radius;
radius = d3_functor(v);
return chord;
};
chord.source = function(v) {
if (!arguments.length) return source;
source = d3_functor(v);
return chord;
};
chord.target = function(v) {
if (!arguments.length) return target;
target = d3_functor(v);
return chord;
};
chord.startAngle = function(v) {
if (!arguments.length) return startAngle;
startAngle = d3_functor(v);
return chord;
};
chord.endAngle = function(v) {
if (!arguments.length) return endAngle;
endAngle = d3_functor(v);
return chord;
};
return chord;
};
function d3_svg_chordRadius(d) {
return d.radius;
}
d3.svg.diagonal = function() {
var source = d3_source, target = d3_target, projection = d3_svg_diagonalProjection;
function diagonal(d, i) {
var p0 = source.call(this, d, i), p3 = target.call(this, d, i), m = (p0.y + p3.y) / 2, p = [ p0, {
x: p0.x,
y: m
}, {
x: p3.x,
y: m
}, p3 ];
p = p.map(projection);
return "M" + p[0] + "C" + p[1] + " " + p[2] + " " + p[3];
}
diagonal.source = function(x) {
if (!arguments.length) return source;
source = d3_functor(x);
return diagonal;
};
diagonal.target = function(x) {
if (!arguments.length) return target;
target = d3_functor(x);
return diagonal;
};
diagonal.projection = function(x) {
if (!arguments.length) return projection;
projection = x;
return diagonal;
};
return diagonal;
};
function d3_svg_diagonalProjection(d) {
return [ d.x, d.y ];
}
d3.svg.diagonal.radial = function() {
var diagonal = d3.svg.diagonal(), projection = d3_svg_diagonalProjection, projection_ = diagonal.projection;
diagonal.projection = function(x) {
return arguments.length ? projection_(d3_svg_diagonalRadialProjection(projection = x)) : projection;
};
return diagonal;
};
function d3_svg_diagonalRadialProjection(projection) {
return function() {
var d = projection.apply(this, arguments), r = d[0], a = d[1] - halfπ;
return [ r * Math.cos(a), r * Math.sin(a) ];
};
}
d3.svg.symbol = function() {
var type = d3_svg_symbolType, size = d3_svg_symbolSize;
function symbol(d, i) {
return (d3_svg_symbols.get(type.call(this, d, i)) || d3_svg_symbolCircle)(size.call(this, d, i));
}
symbol.type = function(x) {
if (!arguments.length) return type;
type = d3_functor(x);
return symbol;
};
symbol.size = function(x) {
if (!arguments.length) return size;
size = d3_functor(x);
return symbol;
};
return symbol;
};
function d3_svg_symbolSize() {
return 64;
}
function d3_svg_symbolType() {
return "circle";
}
function d3_svg_symbolCircle(size) {
var r = Math.sqrt(size / π);
return "M0," + r + "A" + r + "," + r + " 0 1,1 0," + -r + "A" + r + "," + r + " 0 1,1 0," + r + "Z";
}
var d3_svg_symbols = d3.map({
circle: d3_svg_symbolCircle,
cross: function(size) {
var r = Math.sqrt(size / 5) / 2;
return "M" + -3 * r + "," + -r + "H" + -r + "V" + -3 * r + "H" + r + "V" + -r + "H" + 3 * r + "V" + r + "H" + r + "V" + 3 * r + "H" + -r + "V" + r + "H" + -3 * r + "Z";
},
diamond: function(size) {
var ry = Math.sqrt(size / (2 * d3_svg_symbolTan30)), rx = ry * d3_svg_symbolTan30;
return "M0," + -ry + "L" + rx + ",0" + " 0," + ry + " " + -rx + ",0" + "Z";
},
square: function(size) {
var r = Math.sqrt(size) / 2;
return "M" + -r + "," + -r + "L" + r + "," + -r + " " + r + "," + r + " " + -r + "," + r + "Z";
},
"triangle-down": function(size) {
var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
return "M0," + ry + "L" + rx + "," + -ry + " " + -rx + "," + -ry + "Z";
},
"triangle-up": function(size) {
var rx = Math.sqrt(size / d3_svg_symbolSqrt3), ry = rx * d3_svg_symbolSqrt3 / 2;
return "M0," + -ry + "L" + rx + "," + ry + " " + -rx + "," + ry + "Z";
}
});
d3.svg.symbolTypes = d3_svg_symbols.keys();
var d3_svg_symbolSqrt3 = Math.sqrt(3), d3_svg_symbolTan30 = Math.tan(30 * d3_radians);
d3_selectionPrototype.transition = function(name) {
var id = d3_transitionInheritId || ++d3_transitionId, ns = d3_transitionNamespace(name), subgroups = [], subgroup, node, transition = d3_transitionInherit || {
time: Date.now(),
ease: d3_ease_cubicInOut,
delay: 0,
duration: 250
};
for (var j = -1, m = this.length; ++j < m; ) {
subgroups.push(subgroup = []);
for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
if (node = group[i]) d3_transitionNode(node, i, ns, id, transition);
subgroup.push(node);
}
}
return d3_transition(subgroups, ns, id);
};
d3_selectionPrototype.interrupt = function(name) {
return this.each(name == null ? d3_selection_interrupt : d3_selection_interruptNS(d3_transitionNamespace(name)));
};
var d3_selection_interrupt = d3_selection_interruptNS(d3_transitionNamespace());
function d3_selection_interruptNS(ns) {
return function() {
var lock, activeId, active;
if ((lock = this[ns]) && (active = lock[activeId = lock.active])) {
active.timer.c = null;
active.timer.t = NaN;
if (--lock.count) delete lock[activeId]; else delete this[ns];
lock.active += .5;
active.event && active.event.interrupt.call(this, this.__data__, active.index);
}
};
}
function d3_transition(groups, ns, id) {
d3_subclass(groups, d3_transitionPrototype);
groups.namespace = ns;
groups.id = id;
return groups;
}
var d3_transitionPrototype = [], d3_transitionId = 0, d3_transitionInheritId, d3_transitionInherit;
d3_transitionPrototype.call = d3_selectionPrototype.call;
d3_transitionPrototype.empty = d3_selectionPrototype.empty;
d3_transitionPrototype.node = d3_selectionPrototype.node;
d3_transitionPrototype.size = d3_selectionPrototype.size;
d3.transition = function(selection, name) {
return selection && selection.transition ? d3_transitionInheritId ? selection.transition(name) : selection : d3.selection().transition(selection);
};
d3.transition.prototype = d3_transitionPrototype;
d3_transitionPrototype.select = function(selector) {
var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnode, node;
selector = d3_selection_selector(selector);
for (var j = -1, m = this.length; ++j < m; ) {
subgroups.push(subgroup = []);
for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
if ((node = group[i]) && (subnode = selector.call(node, node.__data__, i, j))) {
if ("__data__" in node) subnode.__data__ = node.__data__;
d3_transitionNode(subnode, i, ns, id, node[ns][id]);
subgroup.push(subnode);
} else {
subgroup.push(null);
}
}
}
return d3_transition(subgroups, ns, id);
};
d3_transitionPrototype.selectAll = function(selector) {
var id = this.id, ns = this.namespace, subgroups = [], subgroup, subnodes, node, subnode, transition;
selector = d3_selection_selectorAll(selector);
for (var j = -1, m = this.length; ++j < m; ) {
for (var group = this[j], i = -1, n = group.length; ++i < n; ) {
if (node = group[i]) {
transition = node[ns][id];
subnodes = selector.call(node, node.__data__, i, j);
subgroups.push(subgroup = []);
for (var k = -1, o = subnodes.length; ++k < o; ) {
if (subnode = subnodes[k]) d3_transitionNode(subnode, k, ns, id, transition);
subgroup.push(subnode);
}
}
}
}
return d3_transition(subgroups, ns, id);
};
d3_transitionPrototype.filter = function(filter) {
var subgroups = [], subgroup, group, node;
if (typeof filter !== "function") filter = d3_selection_filter(filter);
for (var j = 0, m = this.length; j < m; j++) {
subgroups.push(subgroup = []);
for (var group = this[j], i = 0, n = group.length; i < n; i++) {
if ((node = group[i]) && filter.call(node, node.__data__, i, j)) {
subgroup.push(node);
}
}
}
return d3_transition(subgroups, this.namespace, this.id);
};
d3_transitionPrototype.tween = function(name, tween) {
var id = this.id, ns = this.namespace;
if (arguments.length < 2) return this.node()[ns][id].tween.get(name);
return d3_selection_each(this, tween == null ? function(node) {
node[ns][id].tween.remove(name);
} : function(node) {
node[ns][id].tween.set(name, tween);
});
};
function d3_transition_tween(groups, name, value, tween) {
var id = groups.id, ns = groups.namespace;
return d3_selection_each(groups, typeof value === "function" ? function(node, i, j) {
node[ns][id].tween.set(name, tween(value.call(node, node.__data__, i, j)));
} : (value = tween(value), function(node) {
node[ns][id].tween.set(name, value);
}));
}
d3_transitionPrototype.attr = function(nameNS, value) {
if (arguments.length < 2) {
for (value in nameNS) this.attr(value, nameNS[value]);
return this;
}
var interpolate = nameNS == "transform" ? d3_interpolateTransform : d3_interpolate, name = d3.ns.qualify(nameNS);
function attrNull() {
this.removeAttribute(name);
}
function attrNullNS() {
this.removeAttributeNS(name.space, name.local);
}
function attrTween(b) {
return b == null ? attrNull : (b += "", function() {
var a = this.getAttribute(name), i;
return a !== b && (i = interpolate(a, b), function(t) {
this.setAttribute(name, i(t));
});
});
}
function attrTweenNS(b) {
return b == null ? attrNullNS : (b += "", function() {
var a = this.getAttributeNS(name.space, name.local), i;
return a !== b && (i = interpolate(a, b), function(t) {
this.setAttributeNS(name.space, name.local, i(t));
});
});
}
return d3_transition_tween(this, "attr." + nameNS, value, name.local ? attrTweenNS : attrTween);
};
d3_transitionPrototype.attrTween = function(nameNS, tween) {
var name = d3.ns.qualify(nameNS);
function attrTween(d, i) {
var f = tween.call(this, d, i, this.getAttribute(name));
return f && function(t) {
this.setAttribute(name, f(t));
};
}
function attrTweenNS(d, i) {
var f = tween.call(this, d, i, this.getAttributeNS(name.space, name.local));
return f && function(t) {
this.setAttributeNS(name.space, name.local, f(t));
};
}
return this.tween("attr." + nameNS, name.local ? attrTweenNS : attrTween);
};
d3_transitionPrototype.style = function(name, value, priority) {
var n = arguments.length;
if (n < 3) {
if (typeof name !== "string") {
if (n < 2) value = "";
for (priority in name) this.style(priority, name[priority], value);
return this;
}
priority = "";
}
function styleNull() {
this.style.removeProperty(name);
}
function styleString(b) {
return b == null ? styleNull : (b += "", function() {
var a = d3_window(this).getComputedStyle(this, null).getPropertyValue(name), i;
return a !== b && (i = d3_interpolate(a, b), function(t) {
this.style.setProperty(name, i(t), priority);
});
});
}
return d3_transition_tween(this, "style." + name, value, styleString);
};
d3_transitionPrototype.styleTween = function(name, tween, priority) {
if (arguments.length < 3) priority = "";
function styleTween(d, i) {
var f = tween.call(this, d, i, d3_window(this).getComputedStyle(this, null).getPropertyValue(name));
return f && function(t) {
this.style.setProperty(name, f(t), priority);
};
}
return this.tween("style." + name, styleTween);
};
d3_transitionPrototype.text = function(value) {
return d3_transition_tween(this, "text", value, d3_transition_text);
};
function d3_transition_text(b) {
if (b == null) b = "";
return function() {
this.textContent = b;
};
}
d3_transitionPrototype.remove = function() {
var ns = this.namespace;
return this.each("end.transition", function() {
var p;
if (this[ns].count < 2 && (p = this.parentNode)) p.removeChild(this);
});
};
d3_transitionPrototype.ease = function(value) {
var id = this.id, ns = this.namespace;
if (arguments.length < 1) return this.node()[ns][id].ease;
if (typeof value !== "function") value = d3.ease.apply(d3, arguments);
return d3_selection_each(this, function(node) {
node[ns][id].ease = value;
});
};
d3_transitionPrototype.delay = function(value) {
var id = this.id, ns = this.namespace;
if (arguments.length < 1) return this.node()[ns][id].delay;
return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
node[ns][id].delay = +value.call(node, node.__data__, i, j);
} : (value = +value, function(node) {
node[ns][id].delay = value;
}));
};
d3_transitionPrototype.duration = function(value) {
var id = this.id, ns = this.namespace;
if (arguments.length < 1) return this.node()[ns][id].duration;
return d3_selection_each(this, typeof value === "function" ? function(node, i, j) {
node[ns][id].duration = Math.max(1, value.call(node, node.__data__, i, j));
} : (value = Math.max(1, value), function(node) {
node[ns][id].duration = value;
}));
};
d3_transitionPrototype.each = function(type, listener) {
var id = this.id, ns = this.namespace;
if (arguments.length < 2) {
var inherit = d3_transitionInherit, inheritId = d3_transitionInheritId;
try {
d3_transitionInheritId = id;
d3_selection_each(this, function(node, i, j) {
d3_transitionInherit = node[ns][id];
type.call(node, node.__data__, i, j);
});
} finally {
d3_transitionInherit = inherit;
d3_transitionInheritId = inheritId;
}
} else {
d3_selection_each(this, function(node) {
var transition = node[ns][id];
(transition.event || (transition.event = d3.dispatch("start", "end", "interrupt"))).on(type, listener);
});
}
return this;
};
d3_transitionPrototype.transition = function() {
var id0 = this.id, id1 = ++d3_transitionId, ns = this.namespace, subgroups = [], subgroup, group, node, transition;
for (var j = 0, m = this.length; j < m; j++) {
subgroups.push(subgroup = []);
for (var group = this[j], i = 0, n = group.length; i < n; i++) {
if (node = group[i]) {
transition = node[ns][id0];
d3_transitionNode(node, i, ns, id1, {
time: transition.time,
ease: transition.ease,
delay: transition.delay + transition.duration,
duration: transition.duration
});
}
subgroup.push(node);
}
}
return d3_transition(subgroups, ns, id1);
};
function d3_transitionNamespace(name) {
return name == null ? "__transition__" : "__transition_" + name + "__";
}
function d3_transitionNode(node, i, ns, id, inherit) {
var lock = node[ns] || (node[ns] = {
active: 0,
count: 0
}), transition = lock[id], time, timer, duration, ease, tweens;
function schedule(elapsed) {
var delay = transition.delay;
timer.t = delay + time;
if (delay <= elapsed) return start(elapsed - delay);
timer.c = start;
}
function start(elapsed) {
var activeId = lock.active, active = lock[activeId];
if (active) {
active.timer.c = null;
active.timer.t = NaN;
--lock.count;
delete lock[activeId];
active.event && active.event.interrupt.call(node, node.__data__, active.index);
}
for (var cancelId in lock) {
if (+cancelId < id) {
var cancel = lock[cancelId];
cancel.timer.c = null;
cancel.timer.t = NaN;
--lock.count;
delete lock[cancelId];
}
}
timer.c = tick;
d3_timer(function() {
if (timer.c && tick(elapsed || 1)) {
timer.c = null;
timer.t = NaN;
}
return 1;
}, 0, time);
lock.active = id;
transition.event && transition.event.start.call(node, node.__data__, i);
tweens = [];
transition.tween.forEach(function(key, value) {
if (value = value.call(node, node.__data__, i)) {
tweens.push(value);
}
});
ease = transition.ease;
duration = transition.duration;
}
function tick(elapsed) {
var t = elapsed / duration, e = ease(t), n = tweens.length;
while (n > 0) {
tweens[--n].call(node, e);
}
if (t >= 1) {
transition.event && transition.event.end.call(node, node.__data__, i);
if (--lock.count) delete lock[id]; else delete node[ns];
return 1;
}
}
if (!transition) {
time = inherit.time;
timer = d3_timer(schedule, 0, time);
transition = lock[id] = {
tween: new d3_Map(),
time: time,
timer: timer,
delay: inherit.delay,
duration: inherit.duration,
ease: inherit.ease,
index: i
};
inherit = null;
++lock.count;
}
}
d3.svg.axis = function() {
var scale = d3.scale.linear(), orient = d3_svg_axisDefaultOrient, innerTickSize = 6, outerTickSize = 6, tickPadding = 3, tickArguments_ = [ 10 ], tickValues = null, tickFormat_;
function axis(g) {
g.each(function() {
var g = d3.select(this);
var scale0 = this.__chart__ || scale, scale1 = this.__chart__ = scale.copy();
var ticks = tickValues == null ? scale1.ticks ? scale1.ticks.apply(scale1, tickArguments_) : scale1.domain() : tickValues, tickFormat = tickFormat_ == null ? scale1.tickFormat ? scale1.tickFormat.apply(scale1, tickArguments_) : d3_identity : tickFormat_, tick = g.selectAll(".tick").data(ticks, scale1), tickEnter = tick.enter().insert("g", ".domain").attr("class", "tick").style("opacity", ε), tickExit = d3.transition(tick.exit()).style("opacity", ε).remove(), tickUpdate = d3.transition(tick.order()).style("opacity", 1), tickSpacing = Math.max(innerTickSize, 0) + tickPadding, tickTransform;
var range = d3_scaleRange(scale1), path = g.selectAll(".domain").data([ 0 ]), pathUpdate = (path.enter().append("path").attr("class", "domain"),
d3.transition(path));
tickEnter.append("line");
tickEnter.append("text");
var lineEnter = tickEnter.select("line"), lineUpdate = tickUpdate.select("line"), text = tick.select("text").text(tickFormat), textEnter = tickEnter.select("text"), textUpdate = tickUpdate.select("text"), sign = orient === "top" || orient === "left" ? -1 : 1, x1, x2, y1, y2;
if (orient === "bottom" || orient === "top") {
tickTransform = d3_svg_axisX, x1 = "x", y1 = "y", x2 = "x2", y2 = "y2";
text.attr("dy", sign < 0 ? "0em" : ".71em").style("text-anchor", "middle");
pathUpdate.attr("d", "M" + range[0] + "," + sign * outerTickSize + "V0H" + range[1] + "V" + sign * outerTickSize);
} else {
tickTransform = d3_svg_axisY, x1 = "y", y1 = "x", x2 = "y2", y2 = "x2";
text.attr("dy", ".32em").style("text-anchor", sign < 0 ? "end" : "start");
pathUpdate.attr("d", "M" + sign * outerTickSize + "," + range[0] + "H0V" + range[1] + "H" + sign * outerTickSize);
}
lineEnter.attr(y2, sign * innerTickSize);
textEnter.attr(y1, sign * tickSpacing);
lineUpdate.attr(x2, 0).attr(y2, sign * innerTickSize);
textUpdate.attr(x1, 0).attr(y1, sign * tickSpacing);
if (scale1.rangeBand) {
var x = scale1, dx = x.rangeBand() / 2;
scale0 = scale1 = function(d) {
return x(d) + dx;
};
} else if (scale0.rangeBand) {
scale0 = scale1;
} else {
tickExit.call(tickTransform, scale1, scale0);
}
tickEnter.call(tickTransform, scale0, scale1);
tickUpdate.call(tickTransform, scale1, scale1);
});
}
axis.scale = function(x) {
if (!arguments.length) return scale;
scale = x;
return axis;
};
axis.orient = function(x) {
if (!arguments.length) return orient;
orient = x in d3_svg_axisOrients ? x + "" : d3_svg_axisDefaultOrient;
return axis;
};
axis.ticks = function() {
if (!arguments.length) return tickArguments_;
tickArguments_ = d3_array(arguments);
return axis;
};
axis.tickValues = function(x) {
if (!arguments.length) return tickValues;
tickValues = x;
return axis;
};
axis.tickFormat = function(x) {
if (!arguments.length) return tickFormat_;
tickFormat_ = x;
return axis;
};
axis.tickSize = function(x) {
var n = arguments.length;
if (!n) return innerTickSize;
innerTickSize = +x;
outerTickSize = +arguments[n - 1];
return axis;
};
axis.innerTickSize = function(x) {
if (!arguments.length) return innerTickSize;
innerTickSize = +x;
return axis;
};
axis.outerTickSize = function(x) {
if (!arguments.length) return outerTickSize;
outerTickSize = +x;
return axis;
};
axis.tickPadding = function(x) {
if (!arguments.length) return tickPadding;
tickPadding = +x;
return axis;
};
axis.tickSubdivide = function() {
return arguments.length && axis;
};
return axis;
};
var d3_svg_axisDefaultOrient = "bottom", d3_svg_axisOrients = {
top: 1,
right: 1,
bottom: 1,
left: 1
};
function d3_svg_axisX(selection, x0, x1) {
selection.attr("transform", function(d) {
var v0 = x0(d);
return "translate(" + (isFinite(v0) ? v0 : x1(d)) + ",0)";
});
}
function d3_svg_axisY(selection, y0, y1) {
selection.attr("transform", function(d) {
var v0 = y0(d);
return "translate(0," + (isFinite(v0) ? v0 : y1(d)) + ")";
});
}
d3.svg.brush = function() {
var event = d3_eventDispatch(brush, "brushstart", "brush", "brushend"), x = null, y = null, xExtent = [ 0, 0 ], yExtent = [ 0, 0 ], xExtentDomain, yExtentDomain, xClamp = true, yClamp = true, resizes = d3_svg_brushResizes[0];
function brush(g) {
g.each(function() {
var g = d3.select(this).style("pointer-events", "all").style("-webkit-tap-highlight-color", "rgba(0,0,0,0)").on("mousedown.brush", brushstart).on("touchstart.brush", brushstart);
var background = g.selectAll(".background").data([ 0 ]);
background.enter().append("rect").attr("class", "background").style("visibility", "hidden").style("cursor", "crosshair");
g.selectAll(".extent").data([ 0 ]).enter().append("rect").attr("class", "extent").style("cursor", "move");
var resize = g.selectAll(".resize").data(resizes, d3_identity);
resize.exit().remove();
resize.enter().append("g").attr("class", function(d) {
return "resize " + d;
}).style("cursor", function(d) {
return d3_svg_brushCursor[d];
}).append("rect").attr("x", function(d) {
return /[ew]$/.test(d) ? -3 : null;
}).attr("y", function(d) {
return /^[ns]/.test(d) ? -3 : null;
}).attr("width", 6).attr("height", 6).style("visibility", "hidden");
resize.style("display", brush.empty() ? "none" : null);
var gUpdate = d3.transition(g), backgroundUpdate = d3.transition(background), range;
if (x) {
range = d3_scaleRange(x);
backgroundUpdate.attr("x", range[0]).attr("width", range[1] - range[0]);
redrawX(gUpdate);
}
if (y) {
range = d3_scaleRange(y);
backgroundUpdate.attr("y", range[0]).attr("height", range[1] - range[0]);
redrawY(gUpdate);
}
redraw(gUpdate);
});
}
brush.event = function(g) {
g.each(function() {
var event_ = event.of(this, arguments), extent1 = {
x: xExtent,
y: yExtent,
i: xExtentDomain,
j: yExtentDomain
}, extent0 = this.__chart__ || extent1;
this.__chart__ = extent1;
if (d3_transitionInheritId) {
d3.select(this).transition().each("start.brush", function() {
xExtentDomain = extent0.i;
yExtentDomain = extent0.j;
xExtent = extent0.x;
yExtent = extent0.y;
event_({
type: "brushstart"
});
}).tween("brush:brush", function() {
var xi = d3_interpolateArray(xExtent, extent1.x), yi = d3_interpolateArray(yExtent, extent1.y);
xExtentDomain = yExtentDomain = null;
return function(t) {
xExtent = extent1.x = xi(t);
yExtent = extent1.y = yi(t);
event_({
type: "brush",
mode: "resize"
});
};
}).each("end.brush", function() {
xExtentDomain = extent1.i;
yExtentDomain = extent1.j;
event_({
type: "brush",
mode: "resize"
});
event_({
type: "brushend"
});
});
} else {
event_({
type: "brushstart"
});
event_({
type: "brush",
mode: "resize"
});
event_({
type: "brushend"
});
}
});
};
function redraw(g) {
g.selectAll(".resize").attr("transform", function(d) {
return "translate(" + xExtent[+/e$/.test(d)] + "," + yExtent[+/^s/.test(d)] + ")";
});
}
function redrawX(g) {
g.select(".extent").attr("x", xExtent[0]);
g.selectAll(".extent,.n>rect,.s>rect").attr("width", xExtent[1] - xExtent[0]);
}
function redrawY(g) {
g.select(".extent").attr("y", yExtent[0]);
g.selectAll(".extent,.e>rect,.w>rect").attr("height", yExtent[1] - yExtent[0]);
}
function brushstart() {
var target = this, eventTarget = d3.select(d3.event.target), event_ = event.of(target, arguments), g = d3.select(target), resizing = eventTarget.datum(), resizingX = !/^(n|s)$/.test(resizing) && x, resizingY = !/^(e|w)$/.test(resizing) && y, dragging = eventTarget.classed("extent"), dragRestore = d3_event_dragSuppress(target), center, origin = d3.mouse(target), offset;
var w = d3.select(d3_window(target)).on("keydown.brush", keydown).on("keyup.brush", keyup);
if (d3.event.changedTouches) {
w.on("touchmove.brush", brushmove).on("touchend.brush", brushend);
} else {
w.on("mousemove.brush", brushmove).on("mouseup.brush", brushend);
}
g.interrupt().selectAll("*").interrupt();
if (dragging) {
origin[0] = xExtent[0] - origin[0];
origin[1] = yExtent[0] - origin[1];
} else if (resizing) {
var ex = +/w$/.test(resizing), ey = +/^n/.test(resizing);
offset = [ xExtent[1 - ex] - origin[0], yExtent[1 - ey] - origin[1] ];
origin[0] = xExtent[ex];
origin[1] = yExtent[ey];
} else if (d3.event.altKey) center = origin.slice();
g.style("pointer-events", "none").selectAll(".resize").style("display", null);
d3.select("body").style("cursor", eventTarget.style("cursor"));
event_({
type: "brushstart"
});
brushmove();
function keydown() {
if (d3.event.keyCode == 32) {
if (!dragging) {
center = null;
origin[0] -= xExtent[1];
origin[1] -= yExtent[1];
dragging = 2;
}
d3_eventPreventDefault();
}
}
function keyup() {
if (d3.event.keyCode == 32 && dragging == 2) {
origin[0] += xExtent[1];
origin[1] += yExtent[1];
dragging = 0;
d3_eventPreventDefault();
}
}
function brushmove() {
var point = d3.mouse(target), moved = false;
if (offset) {
point[0] += offset[0];
point[1] += offset[1];
}
if (!dragging) {
if (d3.event.altKey) {
if (!center) center = [ (xExtent[0] + xExtent[1]) / 2, (yExtent[0] + yExtent[1]) / 2 ];
origin[0] = xExtent[+(point[0] < center[0])];
origin[1] = yExtent[+(point[1] < center[1])];
} else center = null;
}
if (resizingX && move1(point, x, 0)) {
redrawX(g);
moved = true;
}
if (resizingY && move1(point, y, 1)) {
redrawY(g);
moved = true;
}
if (moved) {
redraw(g);
event_({
type: "brush",
mode: dragging ? "move" : "resize"
});
}
}
function move1(point, scale, i) {
var range = d3_scaleRange(scale), r0 = range[0], r1 = range[1], position = origin[i], extent = i ? yExtent : xExtent, size = extent[1] - extent[0], min, max;
if (dragging) {
r0 -= position;
r1 -= size + position;
}
min = (i ? yClamp : xClamp) ? Math.max(r0, Math.min(r1, point[i])) : point[i];
if (dragging) {
max = (min += position) + size;
} else {
if (center) position = Math.max(r0, Math.min(r1, 2 * center[i] - min));
if (position < min) {
max = min;
min = position;
} else {
max = position;
}
}
if (extent[0] != min || extent[1] != max) {
if (i) yExtentDomain = null; else xExtentDomain = null;
extent[0] = min;
extent[1] = max;
return true;
}
}
function brushend() {
brushmove();
g.style("pointer-events", "all").selectAll(".resize").style("display", brush.empty() ? "none" : null);
d3.select("body").style("cursor", null);
w.on("mousemove.brush", null).on("mouseup.brush", null).on("touchmove.brush", null).on("touchend.brush", null).on("keydown.brush", null).on("keyup.brush", null);
dragRestore();
event_({
type: "brushend"
});
}
}
brush.x = function(z) {
if (!arguments.length) return x;
x = z;
resizes = d3_svg_brushResizes[!x << 1 | !y];
return brush;
};
brush.y = function(z) {
if (!arguments.length) return y;
y = z;
resizes = d3_svg_brushResizes[!x << 1 | !y];
return brush;
};
brush.clamp = function(z) {
if (!arguments.length) return x && y ? [ xClamp, yClamp ] : x ? xClamp : y ? yClamp : null;
if (x && y) xClamp = !!z[0], yClamp = !!z[1]; else if (x) xClamp = !!z; else if (y) yClamp = !!z;
return brush;
};
brush.extent = function(z) {
var x0, x1, y0, y1, t;
if (!arguments.length) {
if (x) {
if (xExtentDomain) {
x0 = xExtentDomain[0], x1 = xExtentDomain[1];
} else {
x0 = xExtent[0], x1 = xExtent[1];
if (x.invert) x0 = x.invert(x0), x1 = x.invert(x1);
if (x1 < x0) t = x0, x0 = x1, x1 = t;
}
}
if (y) {
if (yExtentDomain) {
y0 = yExtentDomain[0], y1 = yExtentDomain[1];
} else {
y0 = yExtent[0], y1 = yExtent[1];
if (y.invert) y0 = y.invert(y0), y1 = y.invert(y1);
if (y1 < y0) t = y0, y0 = y1, y1 = t;
}
}
return x && y ? [ [ x0, y0 ], [ x1, y1 ] ] : x ? [ x0, x1 ] : y && [ y0, y1 ];
}
if (x) {
x0 = z[0], x1 = z[1];
if (y) x0 = x0[0], x1 = x1[0];
xExtentDomain = [ x0, x1 ];
if (x.invert) x0 = x(x0), x1 = x(x1);
if (x1 < x0) t = x0, x0 = x1, x1 = t;
if (x0 != xExtent[0] || x1 != xExtent[1]) xExtent = [ x0, x1 ];
}
if (y) {
y0 = z[0], y1 = z[1];
if (x) y0 = y0[1], y1 = y1[1];
yExtentDomain = [ y0, y1 ];
if (y.invert) y0 = y(y0), y1 = y(y1);
if (y1 < y0) t = y0, y0 = y1, y1 = t;
if (y0 != yExtent[0] || y1 != yExtent[1]) yExtent = [ y0, y1 ];
}
return brush;
};
brush.clear = function() {
if (!brush.empty()) {
xExtent = [ 0, 0 ], yExtent = [ 0, 0 ];
xExtentDomain = yExtentDomain = null;
}
return brush;
};
brush.empty = function() {
return !!x && xExtent[0] == xExtent[1] || !!y && yExtent[0] == yExtent[1];
};
return d3.rebind(brush, event, "on");
};
var d3_svg_brushCursor = {
n: "ns-resize",
e: "ew-resize",
s: "ns-resize",
w: "ew-resize",
nw: "nwse-resize",
ne: "nesw-resize",
se: "nwse-resize",
sw: "nesw-resize"
};
var d3_svg_brushResizes = [ [ "n", "e", "s", "w", "nw", "ne", "se", "sw" ], [ "e", "w" ], [ "n", "s" ], [] ];
d3.text = d3_xhrType(function(request) {
return request.responseText;
});
d3.json = function(url, callback) {
return d3_xhr(url, "application/json", d3_json, callback);
};
function d3_json(request) {
return JSON.parse(request.responseText);
}
d3.html = function(url, callback) {
return d3_xhr(url, "text/html", d3_html, callback);
};
function d3_html(request) {
var range = d3_document.createRange();
range.selectNode(d3_document.body);
return range.createContextualFragment(request.responseText);
}
d3.xml = d3_xhrType(function(request) {
return request.responseXML;
});
if (true) !(__WEBPACK_AMD_DEFINE_FACTORY__ = (d3),
__WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ?
(__WEBPACK_AMD_DEFINE_FACTORY__.call(exports, __webpack_require__, exports, module)) :
__WEBPACK_AMD_DEFINE_FACTORY__),
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); else {}
}.apply(self);
/***/ }),
/***/ 3480:
/***/ (function(module) {
/* Mapbox GL JS is licensed under the 3-Clause BSD License. Full text of license: https://github.com/mapbox/mapbox-gl-js/blob/v1.13.1/LICENSE.txt */
(function (global, factory) {
true ? module.exports = factory() :
0;
}(this, (function () { 'use strict';
/* eslint-disable */
var shared, worker, mapboxgl;
// define gets called three times: one for each chunk. we rely on the order
// they're imported to know which is which
function define(_, chunk) {
if (!shared) {
shared = chunk;
} else if (!worker) {
worker = chunk;
} else {
var workerBundleString = 'var sharedChunk = {}; (' + shared + ')(sharedChunk); (' + worker + ')(sharedChunk);'
var sharedChunk = {};
shared(sharedChunk);
mapboxgl = chunk(sharedChunk);
if (typeof window !== 'undefined') {
mapboxgl.workerUrl = window.URL.createObjectURL(new Blob([workerBundleString], { type: 'text/javascript' }));
}
}
}
define(['exports'], function (exports) { 'use strict';
function createCommonjsModule(fn, module) {
return module = { exports: {} }, fn(module, module.exports), module.exports;
}
var version = "1.13.4";
var unitbezier = UnitBezier;
function UnitBezier(p1x, p1y, p2x, p2y) {
this.cx = 3 * p1x;
this.bx = 3 * (p2x - p1x) - this.cx;
this.ax = 1 - this.cx - this.bx;
this.cy = 3 * p1y;
this.by = 3 * (p2y - p1y) - this.cy;
this.ay = 1 - this.cy - this.by;
this.p1x = p1x;
this.p1y = p2y;
this.p2x = p2x;
this.p2y = p2y;
}
UnitBezier.prototype.sampleCurveX = function (t) {
return ((this.ax * t + this.bx) * t + this.cx) * t;
};
UnitBezier.prototype.sampleCurveY = function (t) {
return ((this.ay * t + this.by) * t + this.cy) * t;
};
UnitBezier.prototype.sampleCurveDerivativeX = function (t) {
return (3 * this.ax * t + 2 * this.bx) * t + this.cx;
};
UnitBezier.prototype.solveCurveX = function (x, epsilon) {
if (typeof epsilon === 'undefined') {
epsilon = 0.000001;
}
var t0, t1, t2, x2, i;
for (t2 = x, i = 0; i < 8; i++) {
x2 = this.sampleCurveX(t2) - x;
if (Math.abs(x2) < epsilon) {
return t2;
}
var d2 = this.sampleCurveDerivativeX(t2);
if (Math.abs(d2) < 0.000001) {
break;
}
t2 = t2 - x2 / d2;
}
t0 = 0;
t1 = 1;
t2 = x;
if (t2 < t0) {
return t0;
}
if (t2 > t1) {
return t1;
}
while (t0 < t1) {
x2 = this.sampleCurveX(t2);
if (Math.abs(x2 - x) < epsilon) {
return t2;
}
if (x > x2) {
t0 = t2;
} else {
t1 = t2;
}
t2 = (t1 - t0) * 0.5 + t0;
}
return t2;
};
UnitBezier.prototype.solve = function (x, epsilon) {
return this.sampleCurveY(this.solveCurveX(x, epsilon));
};
var pointGeometry = Point;
function Point(x, y) {
this.x = x;
this.y = y;
}
Point.prototype = {
clone: function () {
return new Point(this.x, this.y);
},
add: function (p) {
return this.clone()._add(p);
},
sub: function (p) {
return this.clone()._sub(p);
},
multByPoint: function (p) {
return this.clone()._multByPoint(p);
},
divByPoint: function (p) {
return this.clone()._divByPoint(p);
},
mult: function (k) {
return this.clone()._mult(k);
},
div: function (k) {
return this.clone()._div(k);
},
rotate: function (a) {
return this.clone()._rotate(a);
},
rotateAround: function (a, p) {
return this.clone()._rotateAround(a, p);
},
matMult: function (m) {
return this.clone()._matMult(m);
},
unit: function () {
return this.clone()._unit();
},
perp: function () {
return this.clone()._perp();
},
round: function () {
return this.clone()._round();
},
mag: function () {
return Math.sqrt(this.x * this.x + this.y * this.y);
},
equals: function (other) {
return this.x === other.x && this.y === other.y;
},
dist: function (p) {
return Math.sqrt(this.distSqr(p));
},
distSqr: function (p) {
var dx = p.x - this.x, dy = p.y - this.y;
return dx * dx + dy * dy;
},
angle: function () {
return Math.atan2(this.y, this.x);
},
angleTo: function (b) {
return Math.atan2(this.y - b.y, this.x - b.x);
},
angleWith: function (b) {
return this.angleWithSep(b.x, b.y);
},
angleWithSep: function (x, y) {
return Math.atan2(this.x * y - this.y * x, this.x * x + this.y * y);
},
_matMult: function (m) {
var x = m[0] * this.x + m[1] * this.y, y = m[2] * this.x + m[3] * this.y;
this.x = x;
this.y = y;
return this;
},
_add: function (p) {
this.x += p.x;
this.y += p.y;
return this;
},
_sub: function (p) {
this.x -= p.x;
this.y -= p.y;
return this;
},
_mult: function (k) {
this.x *= k;
this.y *= k;
return this;
},
_div: function (k) {
this.x /= k;
this.y /= k;
return this;
},
_multByPoint: function (p) {
this.x *= p.x;
this.y *= p.y;
return this;
},
_divByPoint: function (p) {
this.x /= p.x;
this.y /= p.y;
return this;
},
_unit: function () {
this._div(this.mag());
return this;
},
_perp: function () {
var y = this.y;
this.y = this.x;
this.x = -y;
return this;
},
_rotate: function (angle) {
var cos = Math.cos(angle), sin = Math.sin(angle), x = cos * this.x - sin * this.y, y = sin * this.x + cos * this.y;
this.x = x;
this.y = y;
return this;
},
_rotateAround: function (angle, p) {
var cos = Math.cos(angle), sin = Math.sin(angle), x = p.x + cos * (this.x - p.x) - sin * (this.y - p.y), y = p.y + sin * (this.x - p.x) + cos * (this.y - p.y);
this.x = x;
this.y = y;
return this;
},
_round: function () {
this.x = Math.round(this.x);
this.y = Math.round(this.y);
return this;
}
};
Point.convert = function (a) {
if (a instanceof Point) {
return a;
}
if (Array.isArray(a)) {
return new Point(a[0], a[1]);
}
return a;
};
var window$1 = typeof self !== 'undefined' ? self : {};
function deepEqual(a, b) {
if (Array.isArray(a)) {
if (!Array.isArray(b) || a.length !== b.length) {
return false;
}
for (var i = 0; i < a.length; i++) {
if (!deepEqual(a[i], b[i])) {
return false;
}
}
return true;
}
if (typeof a === 'object' && a !== null && b !== null) {
if (!(typeof b === 'object')) {
return false;
}
var keys = Object.keys(a);
if (keys.length !== Object.keys(b).length) {
return false;
}
for (var key in a) {
if (!deepEqual(a[key], b[key])) {
return false;
}
}
return true;
}
return a === b;
}
var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1;
function easeCubicInOut(t) {
if (t <= 0) {
return 0;
}
if (t >= 1) {
return 1;
}
var t2 = t * t, t3 = t2 * t;
return 4 * (t < 0.5 ? t3 : 3 * (t - t2) + t3 - 0.75);
}
function bezier(p1x, p1y, p2x, p2y) {
var bezier = new unitbezier(p1x, p1y, p2x, p2y);
return function (t) {
return bezier.solve(t);
};
}
var ease = bezier(0.25, 0.1, 0.25, 1);
function clamp(n, min, max) {
return Math.min(max, Math.max(min, n));
}
function wrap(n, min, max) {
var d = max - min;
var w = ((n - min) % d + d) % d + min;
return w === min ? max : w;
}
function asyncAll(array, fn, callback) {
if (!array.length) {
return callback(null, []);
}
var remaining = array.length;
var results = new Array(array.length);
var error = null;
array.forEach(function (item, i) {
fn(item, function (err, result) {
if (err) {
error = err;
}
results[i] = result;
if (--remaining === 0) {
callback(error, results);
}
});
});
}
function values(obj) {
var result = [];
for (var k in obj) {
result.push(obj[k]);
}
return result;
}
function keysDifference(obj, other) {
var difference = [];
for (var i in obj) {
if (!(i in other)) {
difference.push(i);
}
}
return difference;
}
function extend(dest) {
var sources = [], len = arguments.length - 1;
while (len-- > 0)
sources[len] = arguments[len + 1];
for (var i = 0, list = sources; i < list.length; i += 1) {
var src = list[i];
for (var k in src) {
dest[k] = src[k];
}
}
return dest;
}
function pick(src, properties) {
var result = {};
for (var i = 0; i < properties.length; i++) {
var k = properties[i];
if (k in src) {
result[k] = src[k];
}
}
return result;
}
var id = 1;
function uniqueId() {
return id++;
}
function uuid() {
function b(a) {
return a ? (a ^ Math.random() * 16 >> a / 4).toString(16) : ([10000000] + -[1000] + -4000 + -8000 + -100000000000).replace(/[018]/g, b);
}
return b();
}
function nextPowerOfTwo(value) {
if (value <= 1) {
return 1;
}
return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
}
function validateUuid(str) {
return str ? /^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i.test(str) : false;
}
function bindAll(fns, context) {
fns.forEach(function (fn) {
if (!context[fn]) {
return;
}
context[fn] = context[fn].bind(context);
});
}
function endsWith(string, suffix) {
return string.indexOf(suffix, string.length - suffix.length) !== -1;
}
function mapObject(input, iterator, context) {
var output = {};
for (var key in input) {
output[key] = iterator.call(context || this, input[key], key, input);
}
return output;
}
function filterObject(input, iterator, context) {
var output = {};
for (var key in input) {
if (iterator.call(context || this, input[key], key, input)) {
output[key] = input[key];
}
}
return output;
}
function clone(input) {
if (Array.isArray(input)) {
return input.map(clone);
} else if (typeof input === 'object' && input) {
return mapObject(input, clone);
} else {
return input;
}
}
function arraysIntersect(a, b) {
for (var l = 0; l < a.length; l++) {
if (b.indexOf(a[l]) >= 0) {
return true;
}
}
return false;
}
var warnOnceHistory = {};
function warnOnce(message) {
if (!warnOnceHistory[message]) {
if (typeof console !== 'undefined') {
console.warn(message);
}
warnOnceHistory[message] = true;
}
}
function isCounterClockwise(a, b, c) {
return (c.y - a.y) * (b.x - a.x) > (b.y - a.y) * (c.x - a.x);
}
function calculateSignedArea(ring) {
var sum = 0;
for (var i = 0, len = ring.length, j = len - 1, p1 = void 0, p2 = void 0; i < len; j = i++) {
p1 = ring[i];
p2 = ring[j];
sum += (p2.x - p1.x) * (p1.y + p2.y);
}
return sum;
}
function sphericalToCartesian(ref) {
var r = ref[0];
var azimuthal = ref[1];
var polar = ref[2];
azimuthal += 90;
azimuthal *= Math.PI / 180;
polar *= Math.PI / 180;
return {
x: r * Math.cos(azimuthal) * Math.sin(polar),
y: r * Math.sin(azimuthal) * Math.sin(polar),
z: r * Math.cos(polar)
};
}
function isWorker() {
return typeof WorkerGlobalScope !== 'undefined' && typeof self !== 'undefined' && self instanceof WorkerGlobalScope;
}
function parseCacheControl(cacheControl) {
var re = /(?:^|(?:\s*\,\s*))([^\x00-\x20\(\)<>@\,;\:\\"\/\[\]\?\=\{\}\x7F]+)(?:\=(?:([^\x00-\x20\(\)<>@\,;\:\\"\/\[\]\?\=\{\}\x7F]+)|(?:\"((?:[^"\\]|\\.)*)\")))?/g;
var header = {};
cacheControl.replace(re, function ($0, $1, $2, $3) {
var value = $2 || $3;
header[$1] = value ? value.toLowerCase() : true;
return '';
});
if (header['max-age']) {
var maxAge = parseInt(header['max-age'], 10);
if (isNaN(maxAge)) {
delete header['max-age'];
} else {
header['max-age'] = maxAge;
}
}
return header;
}
var _isSafari = null;
function isSafari(scope) {
if (_isSafari == null) {
var userAgent = scope.navigator ? scope.navigator.userAgent : null;
_isSafari = !!scope.safari || !!(userAgent && (/\b(iPad|iPhone|iPod)\b/.test(userAgent) || !!userAgent.match('Safari') && !userAgent.match('Chrome')));
}
return _isSafari;
}
function storageAvailable(type) {
try {
var storage = window$1[type];
storage.setItem('_mapbox_test_', 1);
storage.removeItem('_mapbox_test_');
return true;
} catch (e) {
return false;
}
}
function b64EncodeUnicode(str) {
return window$1.btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) {
return String.fromCharCode(Number('0x' + p1));
}));
}
function b64DecodeUnicode(str) {
return decodeURIComponent(window$1.atob(str).split('').map(function (c) {
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
}).join(''));
}
var now = window$1.performance && window$1.performance.now ? window$1.performance.now.bind(window$1.performance) : Date.now.bind(Date);
var raf = window$1.requestAnimationFrame || window$1.mozRequestAnimationFrame || window$1.webkitRequestAnimationFrame || window$1.msRequestAnimationFrame;
var cancel = window$1.cancelAnimationFrame || window$1.mozCancelAnimationFrame || window$1.webkitCancelAnimationFrame || window$1.msCancelAnimationFrame;
var linkEl;
var reducedMotionQuery;
var exported = {
now: now,
frame: function frame(fn) {
var frame = raf(fn);
return {
cancel: function () {
return cancel(frame);
}
};
},
getImageData: function getImageData(img, padding) {
if (padding === void 0)
padding = 0;
var canvas = window$1.document.createElement('canvas');
var context = canvas.getContext('2d');
if (!context) {
throw new Error('failed to create canvas 2d context');
}
canvas.width = img.width;
canvas.height = img.height;
context.drawImage(img, 0, 0, img.width, img.height);
return context.getImageData(-padding, -padding, img.width + 2 * padding, img.height + 2 * padding);
},
resolveURL: function resolveURL(path) {
if (!linkEl) {
linkEl = window$1.document.createElement('a');
}
linkEl.href = path;
return linkEl.href;
},
hardwareConcurrency: window$1.navigator && window$1.navigator.hardwareConcurrency || 4,
get devicePixelRatio() {
return window$1.devicePixelRatio;
},
get prefersReducedMotion() {
if (!window$1.matchMedia) {
return false;
}
if (reducedMotionQuery == null) {
reducedMotionQuery = window$1.matchMedia('(prefers-reduced-motion: reduce)');
}
return reducedMotionQuery.matches;
}
};
var config = {
API_URL: 'https://api.mapbox.com',
get EVENTS_URL() {
if (!this.API_URL) {
return null;
}
if (this.API_URL.indexOf('https://api.mapbox.cn') === 0) {
return 'https://events.mapbox.cn/events/v2';
} else if (this.API_URL.indexOf('https://api.mapbox.com') === 0) {
return 'https://events.mapbox.com/events/v2';
} else {
return null;
}
},
FEEDBACK_URL: 'https://apps.mapbox.com/feedback',
REQUIRE_ACCESS_TOKEN: true,
ACCESS_TOKEN: null,
MAX_PARALLEL_IMAGE_REQUESTS: 16
};
var exported$1 = {
supported: false,
testSupport: testSupport
};
var glForTesting;
var webpCheckComplete = false;
var webpImgTest;
var webpImgTestOnloadComplete = false;
if (window$1.document) {
webpImgTest = window$1.document.createElement('img');
webpImgTest.onload = function () {
if (glForTesting) {
testWebpTextureUpload(glForTesting);
}
glForTesting = null;
webpImgTestOnloadComplete = true;
};
webpImgTest.onerror = function () {
webpCheckComplete = true;
glForTesting = null;
};
webpImgTest.src = 'data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAQAAAAfQ//73v/+BiOh/AAA=';
}
function testSupport(gl) {
if (webpCheckComplete || !webpImgTest) {
return;
}
if (webpImgTestOnloadComplete) {
testWebpTextureUpload(gl);
} else {
glForTesting = gl;
}
}
function testWebpTextureUpload(gl) {
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
try {
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, webpImgTest);
if (gl.isContextLost()) {
return;
}
exported$1.supported = true;
} catch (e) {
}
gl.deleteTexture(texture);
webpCheckComplete = true;
}
var SKU_ID = '01';
function createSkuToken() {
var TOKEN_VERSION = '1';
var base62chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
var sessionRandomizer = '';
for (var i = 0; i < 10; i++) {
sessionRandomizer += base62chars[Math.floor(Math.random() * 62)];
}
var expiration = 12 * 60 * 60 * 1000;
var token = [
TOKEN_VERSION,
SKU_ID,
sessionRandomizer
].join('');
var tokenExpiresAt = Date.now() + expiration;
return {
token: token,
tokenExpiresAt: tokenExpiresAt
};
}
var RequestManager = function RequestManager(transformRequestFn, customAccessToken) {
this._transformRequestFn = transformRequestFn;
this._customAccessToken = customAccessToken;
this._createSkuToken();
};
RequestManager.prototype._createSkuToken = function _createSkuToken() {
var skuToken = createSkuToken();
this._skuToken = skuToken.token;
this._skuTokenExpiresAt = skuToken.tokenExpiresAt;
};
RequestManager.prototype._isSkuTokenExpired = function _isSkuTokenExpired() {
return Date.now() > this._skuTokenExpiresAt;
};
RequestManager.prototype.transformRequest = function transformRequest(url, type) {
if (this._transformRequestFn) {
return this._transformRequestFn(url, type) || { url: url };
}
return { url: url };
};
RequestManager.prototype.normalizeStyleURL = function normalizeStyleURL(url, accessToken) {
if (!isMapboxURL(url)) {
return url;
}
var urlObject = parseUrl(url);
urlObject.path = '/styles/v1' + urlObject.path;
return this._makeAPIURL(urlObject, this._customAccessToken || accessToken);
};
RequestManager.prototype.normalizeGlyphsURL = function normalizeGlyphsURL(url, accessToken) {
if (!isMapboxURL(url)) {
return url;
}
var urlObject = parseUrl(url);
urlObject.path = '/fonts/v1' + urlObject.path;
return this._makeAPIURL(urlObject, this._customAccessToken || accessToken);
};
RequestManager.prototype.normalizeSourceURL = function normalizeSourceURL(url, accessToken) {
if (!isMapboxURL(url)) {
return url;
}
var urlObject = parseUrl(url);
urlObject.path = '/v4/' + urlObject.authority + '.json';
urlObject.params.push('secure');
return this._makeAPIURL(urlObject, this._customAccessToken || accessToken);
};
RequestManager.prototype.normalizeSpriteURL = function normalizeSpriteURL(url, format, extension, accessToken) {
var urlObject = parseUrl(url);
if (!isMapboxURL(url)) {
urlObject.path += '' + format + extension;
return formatUrl(urlObject);
}
urlObject.path = '/styles/v1' + urlObject.path + '/sprite' + format + extension;
return this._makeAPIURL(urlObject, this._customAccessToken || accessToken);
};
RequestManager.prototype.normalizeTileURL = function normalizeTileURL(tileURL, tileSize) {
if (this._isSkuTokenExpired()) {
this._createSkuToken();
}
if (tileURL && !isMapboxURL(tileURL)) {
return tileURL;
}
var urlObject = parseUrl(tileURL);
var imageExtensionRe = /(\.(png|jpg)\d*)(?=$)/;
var tileURLAPIPrefixRe = /^.+\/v4\//;
var suffix = exported.devicePixelRatio >= 2 || tileSize === 512 ? '@2x' : '';
var extension = exported$1.supported ? '.webp' : '$1';
urlObject.path = urlObject.path.replace(imageExtensionRe, '' + suffix + extension);
urlObject.path = urlObject.path.replace(tileURLAPIPrefixRe, '/');
urlObject.path = '/v4' + urlObject.path;
var accessToken = this._customAccessToken || getAccessToken(urlObject.params) || config.ACCESS_TOKEN;
if (config.REQUIRE_ACCESS_TOKEN && accessToken && this._skuToken) {
urlObject.params.push('sku=' + this._skuToken);
}
return this._makeAPIURL(urlObject, accessToken);
};
RequestManager.prototype.canonicalizeTileURL = function canonicalizeTileURL(url, removeAccessToken) {
var version = '/v4/';
var extensionRe = /\.[\w]+$/;
var urlObject = parseUrl(url);
if (!urlObject.path.match(/(^\/v4\/)/) || !urlObject.path.match(extensionRe)) {
return url;
}
var result = 'mapbox://tiles/';
result += urlObject.path.replace(version, '');
var params = urlObject.params;
if (removeAccessToken) {
params = params.filter(function (p) {
return !p.match(/^access_token=/);
});
}
if (params.length) {
result += '?' + params.join('&');
}
return result;
};
RequestManager.prototype.canonicalizeTileset = function canonicalizeTileset(tileJSON, sourceURL) {
var removeAccessToken = sourceURL ? isMapboxURL(sourceURL) : false;
var canonical = [];
for (var i = 0, list = tileJSON.tiles || []; i < list.length; i += 1) {
var url = list[i];
if (isMapboxHTTPURL(url)) {
canonical.push(this.canonicalizeTileURL(url, removeAccessToken));
} else {
canonical.push(url);
}
}
return canonical;
};
RequestManager.prototype._makeAPIURL = function _makeAPIURL(urlObject, accessToken) {
var help = 'See https://www.mapbox.com/api-documentation/#access-tokens-and-token-scopes';
var apiUrlObject = parseUrl(config.API_URL);
urlObject.protocol = apiUrlObject.protocol;
urlObject.authority = apiUrlObject.authority;
if (urlObject.protocol === 'http') {
var i = urlObject.params.indexOf('secure');
if (i >= 0) {
urlObject.params.splice(i, 1);
}
}
if (apiUrlObject.path !== '/') {
urlObject.path = '' + apiUrlObject.path + urlObject.path;
}
if (!config.REQUIRE_ACCESS_TOKEN) {
return formatUrl(urlObject);
}
accessToken = accessToken || config.ACCESS_TOKEN;
if (!accessToken) {
throw new Error('An API access token is required to use Mapbox GL. ' + help);
}
if (accessToken[0] === 's') {
throw new Error('Use a public access token (pk.*) with Mapbox GL, not a secret access token (sk.*). ' + help);
}
urlObject.params = urlObject.params.filter(function (d) {
return d.indexOf('access_token') === -1;
});
urlObject.params.push('access_token=' + accessToken);
return formatUrl(urlObject);
};
function isMapboxURL(url) {
return url.indexOf('mapbox:') === 0;
}
var mapboxHTTPURLRe = /^((https?:)?\/\/)?([^\/]+\.)?mapbox\.c(n|om)(\/|\?|$)/i;
function isMapboxHTTPURL(url) {
return mapboxHTTPURLRe.test(url);
}
function hasCacheDefeatingSku(url) {
return url.indexOf('sku=') > 0 && isMapboxHTTPURL(url);
}
function getAccessToken(params) {
for (var i = 0, list = params; i < list.length; i += 1) {
var param = list[i];
var match = param.match(/^access_token=(.*)$/);
if (match) {
return match[1];
}
}
return null;
}
var urlRe = /^(\w+):\/\/([^/?]*)(\/[^?]+)?\??(.+)?/;
function parseUrl(url) {
var parts = url.match(urlRe);
if (!parts) {
throw new Error('Unable to parse URL object');
}
return {
protocol: parts[1],
authority: parts[2],
path: parts[3] || '/',
params: parts[4] ? parts[4].split('&') : []
};
}
function formatUrl(obj) {
var params = obj.params.length ? '?' + obj.params.join('&') : '';
return obj.protocol + '://' + obj.authority + obj.path + params;
}
var telemEventKey = 'mapbox.eventData';
function parseAccessToken(accessToken) {
if (!accessToken) {
return null;
}
var parts = accessToken.split('.');
if (!parts || parts.length !== 3) {
return null;
}
try {
var jsonData = JSON.parse(b64DecodeUnicode(parts[1]));
return jsonData;
} catch (e) {
return null;
}
}
var TelemetryEvent = function TelemetryEvent(type) {
this.type = type;
this.anonId = null;
this.eventData = {};
this.queue = [];
this.pendingRequest = null;
};
TelemetryEvent.prototype.getStorageKey = function getStorageKey(domain) {
var tokenData = parseAccessToken(config.ACCESS_TOKEN);
var u = '';
if (tokenData && tokenData['u']) {
u = b64EncodeUnicode(tokenData['u']);
} else {
u = config.ACCESS_TOKEN || '';
}
return domain ? telemEventKey + '.' + domain + ':' + u : telemEventKey + ':' + u;
};
TelemetryEvent.prototype.fetchEventData = function fetchEventData() {
var isLocalStorageAvailable = storageAvailable('localStorage');
var storageKey = this.getStorageKey();
var uuidKey = this.getStorageKey('uuid');
if (isLocalStorageAvailable) {
try {
var data = window$1.localStorage.getItem(storageKey);
if (data) {
this.eventData = JSON.parse(data);
}
var uuid = window$1.localStorage.getItem(uuidKey);
if (uuid) {
this.anonId = uuid;
}
} catch (e) {
warnOnce('Unable to read from LocalStorage');
}
}
};
TelemetryEvent.prototype.saveEventData = function saveEventData() {
var isLocalStorageAvailable = storageAvailable('localStorage');
var storageKey = this.getStorageKey();
var uuidKey = this.getStorageKey('uuid');
if (isLocalStorageAvailable) {
try {
window$1.localStorage.setItem(uuidKey, this.anonId);
if (Object.keys(this.eventData).length >= 1) {
window$1.localStorage.setItem(storageKey, JSON.stringify(this.eventData));
}
} catch (e) {
warnOnce('Unable to write to LocalStorage');
}
}
};
TelemetryEvent.prototype.processRequests = function processRequests(_) {
};
TelemetryEvent.prototype.postEvent = function postEvent(timestamp, additionalPayload, callback, customAccessToken) {
var this$1 = this;
if (!config.EVENTS_URL) {
return;
}
var eventsUrlObject = parseUrl(config.EVENTS_URL);
eventsUrlObject.params.push('access_token=' + (customAccessToken || config.ACCESS_TOKEN || ''));
var payload = {
event: this.type,
created: new Date(timestamp).toISOString(),
sdkIdentifier: 'mapbox-gl-js',
sdkVersion: version,
skuId: SKU_ID,
userId: this.anonId
};
var finalPayload = additionalPayload ? extend(payload, additionalPayload) : payload;
var request = {
url: formatUrl(eventsUrlObject),
headers: { 'Content-Type': 'text/plain' },
body: JSON.stringify([finalPayload])
};
this.pendingRequest = postData(request, function (error) {
this$1.pendingRequest = null;
callback(error);
this$1.saveEventData();
this$1.processRequests(customAccessToken);
});
};
TelemetryEvent.prototype.queueRequest = function queueRequest(event, customAccessToken) {
this.queue.push(event);
this.processRequests(customAccessToken);
};
var MapLoadEvent = function (TelemetryEvent) {
function MapLoadEvent() {
TelemetryEvent.call(this, 'map.load');
this.success = {};
this.skuToken = '';
}
if (TelemetryEvent)
MapLoadEvent.__proto__ = TelemetryEvent;
MapLoadEvent.prototype = Object.create(TelemetryEvent && TelemetryEvent.prototype);
MapLoadEvent.prototype.constructor = MapLoadEvent;
MapLoadEvent.prototype.postMapLoadEvent = function postMapLoadEvent(tileUrls, mapId, skuToken, customAccessToken) {
this.skuToken = skuToken;
if (config.EVENTS_URL && customAccessToken || config.ACCESS_TOKEN && Array.isArray(tileUrls) && tileUrls.some(function (url) {
return isMapboxURL(url) || isMapboxHTTPURL(url);
})) {
this.queueRequest({
id: mapId,
timestamp: Date.now()
}, customAccessToken);
}
};
MapLoadEvent.prototype.processRequests = function processRequests(customAccessToken) {
var this$1 = this;
if (this.pendingRequest || this.queue.length === 0) {
return;
}
var ref = this.queue.shift();
var id = ref.id;
var timestamp = ref.timestamp;
if (id && this.success[id]) {
return;
}
if (!this.anonId) {
this.fetchEventData();
}
if (!validateUuid(this.anonId)) {
this.anonId = uuid();
}
this.postEvent(timestamp, { skuToken: this.skuToken }, function (err) {
if (!err) {
if (id) {
this$1.success[id] = true;
}
}
}, customAccessToken);
};
return MapLoadEvent;
}(TelemetryEvent);
var TurnstileEvent = function (TelemetryEvent) {
function TurnstileEvent(customAccessToken) {
TelemetryEvent.call(this, 'appUserTurnstile');
this._customAccessToken = customAccessToken;
}
if (TelemetryEvent)
TurnstileEvent.__proto__ = TelemetryEvent;
TurnstileEvent.prototype = Object.create(TelemetryEvent && TelemetryEvent.prototype);
TurnstileEvent.prototype.constructor = TurnstileEvent;
TurnstileEvent.prototype.postTurnstileEvent = function postTurnstileEvent(tileUrls, customAccessToken) {
if (config.EVENTS_URL && config.ACCESS_TOKEN && Array.isArray(tileUrls) && tileUrls.some(function (url) {
return isMapboxURL(url) || isMapboxHTTPURL(url);
})) {
this.queueRequest(Date.now(), customAccessToken);
}
};
TurnstileEvent.prototype.processRequests = function processRequests(customAccessToken) {
var this$1 = this;
if (this.pendingRequest || this.queue.length === 0) {
return;
}
if (!this.anonId || !this.eventData.lastSuccess || !this.eventData.tokenU) {
this.fetchEventData();
}
var tokenData = parseAccessToken(config.ACCESS_TOKEN);
var tokenU = tokenData ? tokenData['u'] : config.ACCESS_TOKEN;
var dueForEvent = tokenU !== this.eventData.tokenU;
if (!validateUuid(this.anonId)) {
this.anonId = uuid();
dueForEvent = true;
}
var nextUpdate = this.queue.shift();
if (this.eventData.lastSuccess) {
var lastUpdate = new Date(this.eventData.lastSuccess);
var nextDate = new Date(nextUpdate);
var daysElapsed = (nextUpdate - this.eventData.lastSuccess) / (24 * 60 * 60 * 1000);
dueForEvent = dueForEvent || daysElapsed >= 1 || daysElapsed < -1 || lastUpdate.getDate() !== nextDate.getDate();
} else {
dueForEvent = true;
}
if (!dueForEvent) {
return this.processRequests();
}
this.postEvent(nextUpdate, { 'enabled.telemetry': false }, function (err) {
if (!err) {
this$1.eventData.lastSuccess = nextUpdate;
this$1.eventData.tokenU = tokenU;
}
}, customAccessToken);
};
return TurnstileEvent;
}(TelemetryEvent);
var turnstileEvent_ = new TurnstileEvent();
var postTurnstileEvent = turnstileEvent_.postTurnstileEvent.bind(turnstileEvent_);
var mapLoadEvent_ = new MapLoadEvent();
var postMapLoadEvent = mapLoadEvent_.postMapLoadEvent.bind(mapLoadEvent_);
var CACHE_NAME = 'mapbox-tiles';
var cacheLimit = 500;
var cacheCheckThreshold = 50;
var MIN_TIME_UNTIL_EXPIRY = 1000 * 60 * 7;
var sharedCache;
function cacheOpen() {
if (window$1.caches && !sharedCache) {
sharedCache = window$1.caches.open(CACHE_NAME);
}
}
var responseConstructorSupportsReadableStream;
function prepareBody(response, callback) {
if (responseConstructorSupportsReadableStream === undefined) {
try {
new Response(new ReadableStream());
responseConstructorSupportsReadableStream = true;
} catch (e) {
responseConstructorSupportsReadableStream = false;
}
}
if (responseConstructorSupportsReadableStream) {
callback(response.body);
} else {
response.blob().then(callback);
}
}
function cachePut(request, response, requestTime) {
cacheOpen();
if (!sharedCache) {
return;
}
var options = {
status: response.status,
statusText: response.statusText,
headers: new window$1.Headers()
};
response.headers.forEach(function (v, k) {
return options.headers.set(k, v);
});
var cacheControl = parseCacheControl(response.headers.get('Cache-Control') || '');
if (cacheControl['no-store']) {
return;
}
if (cacheControl['max-age']) {
options.headers.set('Expires', new Date(requestTime + cacheControl['max-age'] * 1000).toUTCString());
}
var timeUntilExpiry = new Date(options.headers.get('Expires')).getTime() - requestTime;
if (timeUntilExpiry < MIN_TIME_UNTIL_EXPIRY) {
return;
}
prepareBody(response, function (body) {
var clonedResponse = new window$1.Response(body, options);
cacheOpen();
if (!sharedCache) {
return;
}
sharedCache.then(function (cache) {
return cache.put(stripQueryParameters(request.url), clonedResponse);
}).catch(function (e) {
return warnOnce(e.message);
});
});
}
function stripQueryParameters(url) {
var start = url.indexOf('?');
return start < 0 ? url : url.slice(0, start);
}
function cacheGet(request, callback) {
cacheOpen();
if (!sharedCache) {
return callback(null);
}
var strippedURL = stripQueryParameters(request.url);
sharedCache.then(function (cache) {
cache.match(strippedURL).then(function (response) {
var fresh = isFresh(response);
cache.delete(strippedURL);
if (fresh) {
cache.put(strippedURL, response.clone());
}
callback(null, response, fresh);
}).catch(callback);
}).catch(callback);
}
function isFresh(response) {
if (!response) {
return false;
}
var expires = new Date(response.headers.get('Expires') || 0);
var cacheControl = parseCacheControl(response.headers.get('Cache-Control') || '');
return expires > Date.now() && !cacheControl['no-cache'];
}
var globalEntryCounter = Infinity;
function cacheEntryPossiblyAdded(dispatcher) {
globalEntryCounter++;
if (globalEntryCounter > cacheCheckThreshold) {
dispatcher.getActor().send('enforceCacheSizeLimit', cacheLimit);
globalEntryCounter = 0;
}
}
function enforceCacheSizeLimit(limit) {
cacheOpen();
if (!sharedCache) {
return;
}
sharedCache.then(function (cache) {
cache.keys().then(function (keys) {
for (var i = 0; i < keys.length - limit; i++) {
cache.delete(keys[i]);
}
});
});
}
function clearTileCache(callback) {
var promise = window$1.caches.delete(CACHE_NAME);
if (callback) {
promise.catch(callback).then(function () {
return callback();
});
}
}
function setCacheLimits(limit, checkThreshold) {
cacheLimit = limit;
cacheCheckThreshold = checkThreshold;
}
var supportsOffscreenCanvas;
function offscreenCanvasSupported() {
if (supportsOffscreenCanvas == null) {
supportsOffscreenCanvas = window$1.OffscreenCanvas && new window$1.OffscreenCanvas(1, 1).getContext('2d') && typeof window$1.createImageBitmap === 'function';
}
return supportsOffscreenCanvas;
}
var ResourceType = {
Unknown: 'Unknown',
Style: 'Style',
Source: 'Source',
Tile: 'Tile',
Glyphs: 'Glyphs',
SpriteImage: 'SpriteImage',
SpriteJSON: 'SpriteJSON',
Image: 'Image'
};
if (typeof Object.freeze == 'function') {
Object.freeze(ResourceType);
}
var AJAXError = function (Error) {
function AJAXError(message, status, url) {
if (status === 401 && isMapboxHTTPURL(url)) {
message += ': you may have provided an invalid Mapbox access token. See https://www.mapbox.com/api-documentation/#access-tokens-and-token-scopes';
}
Error.call(this, message);
this.status = status;
this.url = url;
this.name = this.constructor.name;
this.message = message;
}
if (Error)
AJAXError.__proto__ = Error;
AJAXError.prototype = Object.create(Error && Error.prototype);
AJAXError.prototype.constructor = AJAXError;
AJAXError.prototype.toString = function toString() {
return this.name + ': ' + this.message + ' (' + this.status + '): ' + this.url;
};
return AJAXError;
}(Error);
var getReferrer = isWorker() ? function () {
return self.worker && self.worker.referrer;
} : function () {
return (window$1.location.protocol === 'blob:' ? window$1.parent : window$1).location.href;
};
var isFileURL = function (url) {
return /^file:/.test(url) || /^file:/.test(getReferrer()) && !/^\w+:/.test(url);
};
function makeFetchRequest(requestParameters, callback) {
var controller = new window$1.AbortController();
var request = new window$1.Request(requestParameters.url, {
method: requestParameters.method || 'GET',
body: requestParameters.body,
credentials: requestParameters.credentials,
headers: requestParameters.headers,
referrer: getReferrer(),
signal: controller.signal
});
var complete = false;
var aborted = false;
var cacheIgnoringSearch = hasCacheDefeatingSku(request.url);
if (requestParameters.type === 'json') {
request.headers.set('Accept', 'application/json');
}
var validateOrFetch = function (err, cachedResponse, responseIsFresh) {
if (aborted) {
return;
}
if (err) {
if (err.message !== 'SecurityError') {
warnOnce(err);
}
}
if (cachedResponse && responseIsFresh) {
return finishRequest(cachedResponse);
}
var requestTime = Date.now();
window$1.fetch(request).then(function (response) {
if (response.ok) {
var cacheableResponse = cacheIgnoringSearch ? response.clone() : null;
return finishRequest(response, cacheableResponse, requestTime);
} else {
return callback(new AJAXError(response.statusText, response.status, requestParameters.url));
}
}).catch(function (error) {
if (error.code === 20) {
return;
}
callback(new Error(error.message));
});
};
var finishRequest = function (response, cacheableResponse, requestTime) {
(requestParameters.type === 'arrayBuffer' ? response.arrayBuffer() : requestParameters.type === 'json' ? response.json() : response.text()).then(function (result) {
if (aborted) {
return;
}
if (cacheableResponse && requestTime) {
cachePut(request, cacheableResponse, requestTime);
}
complete = true;
callback(null, result, response.headers.get('Cache-Control'), response.headers.get('Expires'));
}).catch(function (err) {
if (!aborted) {
callback(new Error(err.message));
}
});
};
if (cacheIgnoringSearch) {
cacheGet(request, validateOrFetch);
} else {
validateOrFetch(null, null);
}
return {
cancel: function () {
aborted = true;
if (!complete) {
controller.abort();
}
}
};
}
function makeXMLHttpRequest(requestParameters, callback) {
var xhr = new window$1.XMLHttpRequest();
xhr.open(requestParameters.method || 'GET', requestParameters.url, true);
if (requestParameters.type === 'arrayBuffer') {
xhr.responseType = 'arraybuffer';
}
for (var k in requestParameters.headers) {
xhr.setRequestHeader(k, requestParameters.headers[k]);
}
if (requestParameters.type === 'json') {
xhr.responseType = 'text';
xhr.setRequestHeader('Accept', 'application/json');
}
xhr.withCredentials = requestParameters.credentials === 'include';
xhr.onerror = function () {
callback(new Error(xhr.statusText));
};
xhr.onload = function () {
if ((xhr.status >= 200 && xhr.status < 300 || xhr.status === 0) && xhr.response !== null) {
var data = xhr.response;
if (requestParameters.type === 'json') {
try {
data = JSON.parse(xhr.response);
} catch (err) {
return callback(err);
}
}
callback(null, data, xhr.getResponseHeader('Cache-Control'), xhr.getResponseHeader('Expires'));
} else {
callback(new AJAXError(xhr.statusText, xhr.status, requestParameters.url));
}
};
xhr.send(requestParameters.body);
return {
cancel: function () {
return xhr.abort();
}
};
}
var makeRequest = function (requestParameters, callback) {
if (!isFileURL(requestParameters.url)) {
if (window$1.fetch && window$1.Request && window$1.AbortController && window$1.Request.prototype.hasOwnProperty('signal')) {
return makeFetchRequest(requestParameters, callback);
}
if (isWorker() && self.worker && self.worker.actor) {
var queueOnMainThread = true;
return self.worker.actor.send('getResource', requestParameters, callback, undefined, queueOnMainThread);
}
}
return makeXMLHttpRequest(requestParameters, callback);
};
var getJSON = function (requestParameters, callback) {
return makeRequest(extend(requestParameters, { type: 'json' }), callback);
};
var getArrayBuffer = function (requestParameters, callback) {
return makeRequest(extend(requestParameters, { type: 'arrayBuffer' }), callback);
};
var postData = function (requestParameters, callback) {
return makeRequest(extend(requestParameters, { method: 'POST' }), callback);
};
function sameOrigin(url) {
var a = window$1.document.createElement('a');
a.href = url;
return a.protocol === window$1.document.location.protocol && a.host === window$1.document.location.host;
}
var transparentPngUrl = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYV2NgAAIAAAUAAarVyFEAAAAASUVORK5CYII=';
function arrayBufferToImage(data, callback, cacheControl, expires) {
var img = new window$1.Image();
var URL = window$1.URL;
img.onload = function () {
callback(null, img);
URL.revokeObjectURL(img.src);
img.onload = null;
window$1.requestAnimationFrame(function () {
img.src = transparentPngUrl;
});
};
img.onerror = function () {
return callback(new Error('Could not load image. Please make sure to use a supported image type such as PNG or JPEG. Note that SVGs are not supported.'));
};
var blob = new window$1.Blob([new Uint8Array(data)], { type: 'image/png' });
img.cacheControl = cacheControl;
img.expires = expires;
img.src = data.byteLength ? URL.createObjectURL(blob) : transparentPngUrl;
}
function arrayBufferToImageBitmap(data, callback) {
var blob = new window$1.Blob([new Uint8Array(data)], { type: 'image/png' });
window$1.createImageBitmap(blob).then(function (imgBitmap) {
callback(null, imgBitmap);
}).catch(function (e) {
callback(new Error('Could not load image because of ' + e.message + '. Please make sure to use a supported image type such as PNG or JPEG. Note that SVGs are not supported.'));
});
}
var imageQueue, numImageRequests;
var resetImageRequestQueue = function () {
imageQueue = [];
numImageRequests = 0;
};
resetImageRequestQueue();
var getImage = function (requestParameters, callback) {
if (exported$1.supported) {
if (!requestParameters.headers) {
requestParameters.headers = {};
}
requestParameters.headers.accept = 'image/webp,*/*';
}
if (numImageRequests >= config.MAX_PARALLEL_IMAGE_REQUESTS) {
var queued = {
requestParameters: requestParameters,
callback: callback,
cancelled: false,
cancel: function cancel() {
this.cancelled = true;
}
};
imageQueue.push(queued);
return queued;
}
numImageRequests++;
var advanced = false;
var advanceImageRequestQueue = function () {
if (advanced) {
return;
}
advanced = true;
numImageRequests--;
while (imageQueue.length && numImageRequests < config.MAX_PARALLEL_IMAGE_REQUESTS) {
var request = imageQueue.shift();
var requestParameters = request.requestParameters;
var callback = request.callback;
var cancelled = request.cancelled;
if (!cancelled) {
request.cancel = getImage(requestParameters, callback).cancel;
}
}
};
var request = getArrayBuffer(requestParameters, function (err, data, cacheControl, expires) {
advanceImageRequestQueue();
if (err) {
callback(err);
} else if (data) {
if (offscreenCanvasSupported()) {
arrayBufferToImageBitmap(data, callback);
} else {
arrayBufferToImage(data, callback, cacheControl, expires);
}
}
});
return {
cancel: function () {
request.cancel();
advanceImageRequestQueue();
}
};
};
var getVideo = function (urls, callback) {
var video = window$1.document.createElement('video');
video.muted = true;
video.onloadstart = function () {
callback(null, video);
};
for (var i = 0; i < urls.length; i++) {
var s = window$1.document.createElement('source');
if (!sameOrigin(urls[i])) {
video.crossOrigin = 'Anonymous';
}
s.src = urls[i];
video.appendChild(s);
}
return {
cancel: function () {
}
};
};
function _addEventListener(type, listener, listenerList) {
var listenerExists = listenerList[type] && listenerList[type].indexOf(listener) !== -1;
if (!listenerExists) {
listenerList[type] = listenerList[type] || [];
listenerList[type].push(listener);
}
}
function _removeEventListener(type, listener, listenerList) {
if (listenerList && listenerList[type]) {
var index = listenerList[type].indexOf(listener);
if (index !== -1) {
listenerList[type].splice(index, 1);
}
}
}
var Event = function Event(type, data) {
if (data === void 0)
data = {};
extend(this, data);
this.type = type;
};
var ErrorEvent = function (Event) {
function ErrorEvent(error, data) {
if (data === void 0)
data = {};
Event.call(this, 'error', extend({ error: error }, data));
}
if (Event)
ErrorEvent.__proto__ = Event;
ErrorEvent.prototype = Object.create(Event && Event.prototype);
ErrorEvent.prototype.constructor = ErrorEvent;
return ErrorEvent;
}(Event);
var Evented = function Evented() {
};
Evented.prototype.on = function on(type, listener) {
this._listeners = this._listeners || {};
_addEventListener(type, listener, this._listeners);
return this;
};
Evented.prototype.off = function off(type, listener) {
_removeEventListener(type, listener, this._listeners);
_removeEventListener(type, listener, this._oneTimeListeners);
return this;
};
Evented.prototype.once = function once(type, listener) {
this._oneTimeListeners = this._oneTimeListeners || {};
_addEventListener(type, listener, this._oneTimeListeners);
return this;
};
Evented.prototype.fire = function fire(event, properties) {
if (typeof event === 'string') {
event = new Event(event, properties || {});
}
var type = event.type;
if (this.listens(type)) {
event.target = this;
var listeners = this._listeners && this._listeners[type] ? this._listeners[type].slice() : [];
for (var i = 0, list = listeners; i < list.length; i += 1) {
var listener = list[i];
listener.call(this, event);
}
var oneTimeListeners = this._oneTimeListeners && this._oneTimeListeners[type] ? this._oneTimeListeners[type].slice() : [];
for (var i$1 = 0, list$1 = oneTimeListeners; i$1 < list$1.length; i$1 += 1) {
var listener$1 = list$1[i$1];
_removeEventListener(type, listener$1, this._oneTimeListeners);
listener$1.call(this, event);
}
var parent = this._eventedParent;
if (parent) {
extend(event, typeof this._eventedParentData === 'function' ? this._eventedParentData() : this._eventedParentData);
parent.fire(event);
}
} else if (event instanceof ErrorEvent) {
console.error(event.error);
}
return this;
};
Evented.prototype.listens = function listens(type) {
return this._listeners && this._listeners[type] && this._listeners[type].length > 0 || this._oneTimeListeners && this._oneTimeListeners[type] && this._oneTimeListeners[type].length > 0 || this._eventedParent && this._eventedParent.listens(type);
};
Evented.prototype.setEventedParent = function setEventedParent(parent, data) {
this._eventedParent = parent;
this._eventedParentData = data;
return this;
};
var $version = 8;
var $root = {
version: {
required: true,
type: "enum",
values: [
8
]
},
name: {
type: "string"
},
metadata: {
type: "*"
},
center: {
type: "array",
value: "number"
},
zoom: {
type: "number"
},
bearing: {
type: "number",
"default": 0,
period: 360,
units: "degrees"
},
pitch: {
type: "number",
"default": 0,
units: "degrees"
},
light: {
type: "light"
},
sources: {
required: true,
type: "sources"
},
sprite: {
type: "string"
},
glyphs: {
type: "string"
},
transition: {
type: "transition"
},
layers: {
required: true,
type: "array",
value: "layer"
}
};
var sources = {
"*": {
type: "source"
}
};
var source = [
"source_vector",
"source_raster",
"source_raster_dem",
"source_geojson",
"source_video",
"source_image"
];
var source_vector = {
type: {
required: true,
type: "enum",
values: {
vector: {
}
}
},
url: {
type: "string"
},
tiles: {
type: "array",
value: "string"
},
bounds: {
type: "array",
value: "number",
length: 4,
"default": [
-180,
-85.051129,
180,
85.051129
]
},
scheme: {
type: "enum",
values: {
xyz: {
},
tms: {
}
},
"default": "xyz"
},
minzoom: {
type: "number",
"default": 0
},
maxzoom: {
type: "number",
"default": 22
},
attribution: {
type: "string"
},
promoteId: {
type: "promoteId"
},
volatile: {
type: "boolean",
"default": false
},
"*": {
type: "*"
}
};
var source_raster = {
type: {
required: true,
type: "enum",
values: {
raster: {
}
}
},
url: {
type: "string"
},
tiles: {
type: "array",
value: "string"
},
bounds: {
type: "array",
value: "number",
length: 4,
"default": [
-180,
-85.051129,
180,
85.051129
]
},
minzoom: {
type: "number",
"default": 0
},
maxzoom: {
type: "number",
"default": 22
},
tileSize: {
type: "number",
"default": 512,
units: "pixels"
},
scheme: {
type: "enum",
values: {
xyz: {
},
tms: {
}
},
"default": "xyz"
},
attribution: {
type: "string"
},
volatile: {
type: "boolean",
"default": false
},
"*": {
type: "*"
}
};
var source_raster_dem = {
type: {
required: true,
type: "enum",
values: {
"raster-dem": {
}
}
},
url: {
type: "string"
},
tiles: {
type: "array",
value: "string"
},
bounds: {
type: "array",
value: "number",
length: 4,
"default": [
-180,
-85.051129,
180,
85.051129
]
},
minzoom: {
type: "number",
"default": 0
},
maxzoom: {
type: "number",
"default": 22
},
tileSize: {
type: "number",
"default": 512,
units: "pixels"
},
attribution: {
type: "string"
},
encoding: {
type: "enum",
values: {
terrarium: {
},
mapbox: {
}
},
"default": "mapbox"
},
volatile: {
type: "boolean",
"default": false
},
"*": {
type: "*"
}
};
var source_geojson = {
type: {
required: true,
type: "enum",
values: {
geojson: {
}
}
},
data: {
type: "*"
},
maxzoom: {
type: "number",
"default": 18
},
attribution: {
type: "string"
},
buffer: {
type: "number",
"default": 128,
maximum: 512,
minimum: 0
},
filter: {
type: "*"
},
tolerance: {
type: "number",
"default": 0.375
},
cluster: {
type: "boolean",
"default": false
},
clusterRadius: {
type: "number",
"default": 50,
minimum: 0
},
clusterMaxZoom: {
type: "number"
},
clusterMinPoints: {
type: "number"
},
clusterProperties: {
type: "*"
},
lineMetrics: {
type: "boolean",
"default": false
},
generateId: {
type: "boolean",
"default": false
},
promoteId: {
type: "promoteId"
}
};
var source_video = {
type: {
required: true,
type: "enum",
values: {
video: {
}
}
},
urls: {
required: true,
type: "array",
value: "string"
},
coordinates: {
required: true,
type: "array",
length: 4,
value: {
type: "array",
length: 2,
value: "number"
}
}
};
var source_image = {
type: {
required: true,
type: "enum",
values: {
image: {
}
}
},
url: {
required: true,
type: "string"
},
coordinates: {
required: true,
type: "array",
length: 4,
value: {
type: "array",
length: 2,
value: "number"
}
}
};
var layer = {
id: {
type: "string",
required: true
},
type: {
type: "enum",
values: {
fill: {
},
line: {
},
symbol: {
},
circle: {
},
heatmap: {
},
"fill-extrusion": {
},
raster: {
},
hillshade: {
},
background: {
}
},
required: true
},
metadata: {
type: "*"
},
source: {
type: "string"
},
"source-layer": {
type: "string"
},
minzoom: {
type: "number",
minimum: 0,
maximum: 24
},
maxzoom: {
type: "number",
minimum: 0,
maximum: 24
},
filter: {
type: "filter"
},
layout: {
type: "layout"
},
paint: {
type: "paint"
}
};
var layout = [
"layout_fill",
"layout_line",
"layout_circle",
"layout_heatmap",
"layout_fill-extrusion",
"layout_symbol",
"layout_raster",
"layout_hillshade",
"layout_background"
];
var layout_background = {
visibility: {
type: "enum",
values: {
visible: {
},
none: {
}
},
"default": "visible",
"property-type": "constant"
}
};
var layout_fill = {
"fill-sort-key": {
type: "number",
expression: {
interpolated: false,
parameters: [
"zoom",
"feature"
]
},
"property-type": "data-driven"
},
visibility: {
type: "enum",
values: {
visible: {
},
none: {
}
},
"default": "visible",
"property-type": "constant"
}
};
var layout_circle = {
"circle-sort-key": {
type: "number",
expression: {
interpolated: false,
parameters: [
"zoom",
"feature"
]
},
"property-type": "data-driven"
},
visibility: {
type: "enum",
values: {
visible: {
},
none: {
}
},
"default": "visible",
"property-type": "constant"
}
};
var layout_heatmap = {
visibility: {
type: "enum",
values: {
visible: {
},
none: {
}
},
"default": "visible",
"property-type": "constant"
}
};
var layout_line = {
"line-cap": {
type: "enum",
values: {
butt: {
},
round: {
},
square: {
}
},
"default": "butt",
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"line-join": {
type: "enum",
values: {
bevel: {
},
round: {
},
miter: {
}
},
"default": "miter",
expression: {
interpolated: false,
parameters: [
"zoom",
"feature"
]
},
"property-type": "data-driven"
},
"line-miter-limit": {
type: "number",
"default": 2,
requires: [
{
"line-join": "miter"
}
],
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"line-round-limit": {
type: "number",
"default": 1.05,
requires: [
{
"line-join": "round"
}
],
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"line-sort-key": {
type: "number",
expression: {
interpolated: false,
parameters: [
"zoom",
"feature"
]
},
"property-type": "data-driven"
},
visibility: {
type: "enum",
values: {
visible: {
},
none: {
}
},
"default": "visible",
"property-type": "constant"
}
};
var layout_symbol = {
"symbol-placement": {
type: "enum",
values: {
point: {
},
line: {
},
"line-center": {
}
},
"default": "point",
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"symbol-spacing": {
type: "number",
"default": 250,
minimum: 1,
units: "pixels",
requires: [
{
"symbol-placement": "line"
}
],
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"symbol-avoid-edges": {
type: "boolean",
"default": false,
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"symbol-sort-key": {
type: "number",
expression: {
interpolated: false,
parameters: [
"zoom",
"feature"
]
},
"property-type": "data-driven"
},
"symbol-z-order": {
type: "enum",
values: {
auto: {
},
"viewport-y": {
},
source: {
}
},
"default": "auto",
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"icon-allow-overlap": {
type: "boolean",
"default": false,
requires: [
"icon-image"
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"icon-ignore-placement": {
type: "boolean",
"default": false,
requires: [
"icon-image"
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"icon-optional": {
type: "boolean",
"default": false,
requires: [
"icon-image",
"text-field"
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"icon-rotation-alignment": {
type: "enum",
values: {
map: {
},
viewport: {
},
auto: {
}
},
"default": "auto",
requires: [
"icon-image"
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"icon-size": {
type: "number",
"default": 1,
minimum: 0,
units: "factor of the original icon size",
requires: [
"icon-image"
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature"
]
},
"property-type": "data-driven"
},
"icon-text-fit": {
type: "enum",
values: {
none: {
},
width: {
},
height: {
},
both: {
}
},
"default": "none",
requires: [
"icon-image",
"text-field"
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"icon-text-fit-padding": {
type: "array",
value: "number",
length: 4,
"default": [
0,
0,
0,
0
],
units: "pixels",
requires: [
"icon-image",
"text-field",
{
"icon-text-fit": [
"both",
"width",
"height"
]
}
],
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"icon-image": {
type: "resolvedImage",
tokens: true,
expression: {
interpolated: false,
parameters: [
"zoom",
"feature"
]
},
"property-type": "data-driven"
},
"icon-rotate": {
type: "number",
"default": 0,
period: 360,
units: "degrees",
requires: [
"icon-image"
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature"
]
},
"property-type": "data-driven"
},
"icon-padding": {
type: "number",
"default": 2,
minimum: 0,
units: "pixels",
requires: [
"icon-image"
],
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"icon-keep-upright": {
type: "boolean",
"default": false,
requires: [
"icon-image",
{
"icon-rotation-alignment": "map"
},
{
"symbol-placement": [
"line",
"line-center"
]
}
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"icon-offset": {
type: "array",
value: "number",
length: 2,
"default": [
0,
0
],
requires: [
"icon-image"
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature"
]
},
"property-type": "data-driven"
},
"icon-anchor": {
type: "enum",
values: {
center: {
},
left: {
},
right: {
},
top: {
},
bottom: {
},
"top-left": {
},
"top-right": {
},
"bottom-left": {
},
"bottom-right": {
}
},
"default": "center",
requires: [
"icon-image"
],
expression: {
interpolated: false,
parameters: [
"zoom",
"feature"
]
},
"property-type": "data-driven"
},
"icon-pitch-alignment": {
type: "enum",
values: {
map: {
},
viewport: {
},
auto: {
}
},
"default": "auto",
requires: [
"icon-image"
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"text-pitch-alignment": {
type: "enum",
values: {
map: {
},
viewport: {
},
auto: {
}
},
"default": "auto",
requires: [
"text-field"
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"text-rotation-alignment": {
type: "enum",
values: {
map: {
},
viewport: {
},
auto: {
}
},
"default": "auto",
requires: [
"text-field"
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"text-field": {
type: "formatted",
"default": "",
tokens: true,
expression: {
interpolated: false,
parameters: [
"zoom",
"feature"
]
},
"property-type": "data-driven"
},
"text-font": {
type: "array",
value: "string",
"default": [
"Open Sans Regular",
"Arial Unicode MS Regular"
],
requires: [
"text-field"
],
expression: {
interpolated: false,
parameters: [
"zoom",
"feature"
]
},
"property-type": "data-driven"
},
"text-size": {
type: "number",
"default": 16,
minimum: 0,
units: "pixels",
requires: [
"text-field"
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature"
]
},
"property-type": "data-driven"
},
"text-max-width": {
type: "number",
"default": 10,
minimum: 0,
units: "ems",
requires: [
"text-field"
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature"
]
},
"property-type": "data-driven"
},
"text-line-height": {
type: "number",
"default": 1.2,
units: "ems",
requires: [
"text-field"
],
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"text-letter-spacing": {
type: "number",
"default": 0,
units: "ems",
requires: [
"text-field"
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature"
]
},
"property-type": "data-driven"
},
"text-justify": {
type: "enum",
values: {
auto: {
},
left: {
},
center: {
},
right: {
}
},
"default": "center",
requires: [
"text-field"
],
expression: {
interpolated: false,
parameters: [
"zoom",
"feature"
]
},
"property-type": "data-driven"
},
"text-radial-offset": {
type: "number",
units: "ems",
"default": 0,
requires: [
"text-field"
],
"property-type": "data-driven",
expression: {
interpolated: true,
parameters: [
"zoom",
"feature"
]
}
},
"text-variable-anchor": {
type: "array",
value: "enum",
values: {
center: {
},
left: {
},
right: {
},
top: {
},
bottom: {
},
"top-left": {
},
"top-right": {
},
"bottom-left": {
},
"bottom-right": {
}
},
requires: [
"text-field",
{
"symbol-placement": [
"point"
]
}
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"text-anchor": {
type: "enum",
values: {
center: {
},
left: {
},
right: {
},
top: {
},
bottom: {
},
"top-left": {
},
"top-right": {
},
"bottom-left": {
},
"bottom-right": {
}
},
"default": "center",
requires: [
"text-field",
{
"!": "text-variable-anchor"
}
],
expression: {
interpolated: false,
parameters: [
"zoom",
"feature"
]
},
"property-type": "data-driven"
},
"text-max-angle": {
type: "number",
"default": 45,
units: "degrees",
requires: [
"text-field",
{
"symbol-placement": [
"line",
"line-center"
]
}
],
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"text-writing-mode": {
type: "array",
value: "enum",
values: {
horizontal: {
},
vertical: {
}
},
requires: [
"text-field",
{
"symbol-placement": [
"point"
]
}
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"text-rotate": {
type: "number",
"default": 0,
period: 360,
units: "degrees",
requires: [
"text-field"
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature"
]
},
"property-type": "data-driven"
},
"text-padding": {
type: "number",
"default": 2,
minimum: 0,
units: "pixels",
requires: [
"text-field"
],
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"text-keep-upright": {
type: "boolean",
"default": true,
requires: [
"text-field",
{
"text-rotation-alignment": "map"
},
{
"symbol-placement": [
"line",
"line-center"
]
}
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"text-transform": {
type: "enum",
values: {
none: {
},
uppercase: {
},
lowercase: {
}
},
"default": "none",
requires: [
"text-field"
],
expression: {
interpolated: false,
parameters: [
"zoom",
"feature"
]
},
"property-type": "data-driven"
},
"text-offset": {
type: "array",
value: "number",
units: "ems",
length: 2,
"default": [
0,
0
],
requires: [
"text-field",
{
"!": "text-radial-offset"
}
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature"
]
},
"property-type": "data-driven"
},
"text-allow-overlap": {
type: "boolean",
"default": false,
requires: [
"text-field"
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"text-ignore-placement": {
type: "boolean",
"default": false,
requires: [
"text-field"
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"text-optional": {
type: "boolean",
"default": false,
requires: [
"text-field",
"icon-image"
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
visibility: {
type: "enum",
values: {
visible: {
},
none: {
}
},
"default": "visible",
"property-type": "constant"
}
};
var layout_raster = {
visibility: {
type: "enum",
values: {
visible: {
},
none: {
}
},
"default": "visible",
"property-type": "constant"
}
};
var layout_hillshade = {
visibility: {
type: "enum",
values: {
visible: {
},
none: {
}
},
"default": "visible",
"property-type": "constant"
}
};
var filter = {
type: "array",
value: "*"
};
var filter_operator = {
type: "enum",
values: {
"==": {
},
"!=": {
},
">": {
},
">=": {
},
"<": {
},
"<=": {
},
"in": {
},
"!in": {
},
all: {
},
any: {
},
none: {
},
has: {
},
"!has": {
},
within: {
}
}
};
var geometry_type = {
type: "enum",
values: {
Point: {
},
LineString: {
},
Polygon: {
}
}
};
var function_stop = {
type: "array",
minimum: 0,
maximum: 24,
value: [
"number",
"color"
],
length: 2
};
var expression = {
type: "array",
value: "*",
minimum: 1
};
var light = {
anchor: {
type: "enum",
"default": "viewport",
values: {
map: {
},
viewport: {
}
},
"property-type": "data-constant",
transition: false,
expression: {
interpolated: false,
parameters: [
"zoom"
]
}
},
position: {
type: "array",
"default": [
1.15,
210,
30
],
length: 3,
value: "number",
"property-type": "data-constant",
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom"
]
}
},
color: {
type: "color",
"property-type": "data-constant",
"default": "#ffffff",
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
transition: true
},
intensity: {
type: "number",
"property-type": "data-constant",
"default": 0.5,
minimum: 0,
maximum: 1,
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
transition: true
}
};
var paint = [
"paint_fill",
"paint_line",
"paint_circle",
"paint_heatmap",
"paint_fill-extrusion",
"paint_symbol",
"paint_raster",
"paint_hillshade",
"paint_background"
];
var paint_fill = {
"fill-antialias": {
type: "boolean",
"default": true,
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"fill-opacity": {
type: "number",
"default": 1,
minimum: 0,
maximum: 1,
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"fill-color": {
type: "color",
"default": "#000000",
transition: true,
requires: [
{
"!": "fill-pattern"
}
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"fill-outline-color": {
type: "color",
transition: true,
requires: [
{
"!": "fill-pattern"
},
{
"fill-antialias": true
}
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"fill-translate": {
type: "array",
value: "number",
length: 2,
"default": [
0,
0
],
transition: true,
units: "pixels",
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"fill-translate-anchor": {
type: "enum",
values: {
map: {
},
viewport: {
}
},
"default": "map",
requires: [
"fill-translate"
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"fill-pattern": {
type: "resolvedImage",
transition: true,
expression: {
interpolated: false,
parameters: [
"zoom",
"feature"
]
},
"property-type": "cross-faded-data-driven"
}
};
var paint_line = {
"line-opacity": {
type: "number",
"default": 1,
minimum: 0,
maximum: 1,
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"line-color": {
type: "color",
"default": "#000000",
transition: true,
requires: [
{
"!": "line-pattern"
}
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"line-translate": {
type: "array",
value: "number",
length: 2,
"default": [
0,
0
],
transition: true,
units: "pixels",
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"line-translate-anchor": {
type: "enum",
values: {
map: {
},
viewport: {
}
},
"default": "map",
requires: [
"line-translate"
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"line-width": {
type: "number",
"default": 1,
minimum: 0,
transition: true,
units: "pixels",
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"line-gap-width": {
type: "number",
"default": 0,
minimum: 0,
transition: true,
units: "pixels",
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"line-offset": {
type: "number",
"default": 0,
transition: true,
units: "pixels",
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"line-blur": {
type: "number",
"default": 0,
minimum: 0,
transition: true,
units: "pixels",
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"line-dasharray": {
type: "array",
value: "number",
minimum: 0,
transition: true,
units: "line widths",
requires: [
{
"!": "line-pattern"
}
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "cross-faded"
},
"line-pattern": {
type: "resolvedImage",
transition: true,
expression: {
interpolated: false,
parameters: [
"zoom",
"feature"
]
},
"property-type": "cross-faded-data-driven"
},
"line-gradient": {
type: "color",
transition: false,
requires: [
{
"!": "line-dasharray"
},
{
"!": "line-pattern"
},
{
source: "geojson",
has: {
lineMetrics: true
}
}
],
expression: {
interpolated: true,
parameters: [
"line-progress"
]
},
"property-type": "color-ramp"
}
};
var paint_circle = {
"circle-radius": {
type: "number",
"default": 5,
minimum: 0,
transition: true,
units: "pixels",
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"circle-color": {
type: "color",
"default": "#000000",
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"circle-blur": {
type: "number",
"default": 0,
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"circle-opacity": {
type: "number",
"default": 1,
minimum: 0,
maximum: 1,
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"circle-translate": {
type: "array",
value: "number",
length: 2,
"default": [
0,
0
],
transition: true,
units: "pixels",
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"circle-translate-anchor": {
type: "enum",
values: {
map: {
},
viewport: {
}
},
"default": "map",
requires: [
"circle-translate"
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"circle-pitch-scale": {
type: "enum",
values: {
map: {
},
viewport: {
}
},
"default": "map",
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"circle-pitch-alignment": {
type: "enum",
values: {
map: {
},
viewport: {
}
},
"default": "viewport",
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"circle-stroke-width": {
type: "number",
"default": 0,
minimum: 0,
transition: true,
units: "pixels",
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"circle-stroke-color": {
type: "color",
"default": "#000000",
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"circle-stroke-opacity": {
type: "number",
"default": 1,
minimum: 0,
maximum: 1,
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
}
};
var paint_heatmap = {
"heatmap-radius": {
type: "number",
"default": 30,
minimum: 1,
transition: true,
units: "pixels",
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"heatmap-weight": {
type: "number",
"default": 1,
minimum: 0,
transition: false,
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"heatmap-intensity": {
type: "number",
"default": 1,
minimum: 0,
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"heatmap-color": {
type: "color",
"default": [
"interpolate",
[
"linear"
],
[
"heatmap-density"
],
0,
"rgba(0, 0, 255, 0)",
0.1,
"royalblue",
0.3,
"cyan",
0.5,
"lime",
0.7,
"yellow",
1,
"red"
],
transition: false,
expression: {
interpolated: true,
parameters: [
"heatmap-density"
]
},
"property-type": "color-ramp"
},
"heatmap-opacity": {
type: "number",
"default": 1,
minimum: 0,
maximum: 1,
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
}
};
var paint_symbol = {
"icon-opacity": {
type: "number",
"default": 1,
minimum: 0,
maximum: 1,
transition: true,
requires: [
"icon-image"
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"icon-color": {
type: "color",
"default": "#000000",
transition: true,
requires: [
"icon-image"
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"icon-halo-color": {
type: "color",
"default": "rgba(0, 0, 0, 0)",
transition: true,
requires: [
"icon-image"
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"icon-halo-width": {
type: "number",
"default": 0,
minimum: 0,
transition: true,
units: "pixels",
requires: [
"icon-image"
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"icon-halo-blur": {
type: "number",
"default": 0,
minimum: 0,
transition: true,
units: "pixels",
requires: [
"icon-image"
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"icon-translate": {
type: "array",
value: "number",
length: 2,
"default": [
0,
0
],
transition: true,
units: "pixels",
requires: [
"icon-image"
],
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"icon-translate-anchor": {
type: "enum",
values: {
map: {
},
viewport: {
}
},
"default": "map",
requires: [
"icon-image",
"icon-translate"
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"text-opacity": {
type: "number",
"default": 1,
minimum: 0,
maximum: 1,
transition: true,
requires: [
"text-field"
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"text-color": {
type: "color",
"default": "#000000",
transition: true,
overridable: true,
requires: [
"text-field"
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"text-halo-color": {
type: "color",
"default": "rgba(0, 0, 0, 0)",
transition: true,
requires: [
"text-field"
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"text-halo-width": {
type: "number",
"default": 0,
minimum: 0,
transition: true,
units: "pixels",
requires: [
"text-field"
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"text-halo-blur": {
type: "number",
"default": 0,
minimum: 0,
transition: true,
units: "pixels",
requires: [
"text-field"
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"text-translate": {
type: "array",
value: "number",
length: 2,
"default": [
0,
0
],
transition: true,
units: "pixels",
requires: [
"text-field"
],
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"text-translate-anchor": {
type: "enum",
values: {
map: {
},
viewport: {
}
},
"default": "map",
requires: [
"text-field",
"text-translate"
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
}
};
var paint_raster = {
"raster-opacity": {
type: "number",
"default": 1,
minimum: 0,
maximum: 1,
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"raster-hue-rotate": {
type: "number",
"default": 0,
period: 360,
transition: true,
units: "degrees",
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"raster-brightness-min": {
type: "number",
"default": 0,
minimum: 0,
maximum: 1,
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"raster-brightness-max": {
type: "number",
"default": 1,
minimum: 0,
maximum: 1,
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"raster-saturation": {
type: "number",
"default": 0,
minimum: -1,
maximum: 1,
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"raster-contrast": {
type: "number",
"default": 0,
minimum: -1,
maximum: 1,
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"raster-resampling": {
type: "enum",
values: {
linear: {
},
nearest: {
}
},
"default": "linear",
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"raster-fade-duration": {
type: "number",
"default": 300,
minimum: 0,
transition: false,
units: "milliseconds",
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
}
};
var paint_hillshade = {
"hillshade-illumination-direction": {
type: "number",
"default": 335,
minimum: 0,
maximum: 359,
transition: false,
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"hillshade-illumination-anchor": {
type: "enum",
values: {
map: {
},
viewport: {
}
},
"default": "viewport",
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"hillshade-exaggeration": {
type: "number",
"default": 0.5,
minimum: 0,
maximum: 1,
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"hillshade-shadow-color": {
type: "color",
"default": "#000000",
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"hillshade-highlight-color": {
type: "color",
"default": "#FFFFFF",
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"hillshade-accent-color": {
type: "color",
"default": "#000000",
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
}
};
var paint_background = {
"background-color": {
type: "color",
"default": "#000000",
transition: true,
requires: [
{
"!": "background-pattern"
}
],
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"background-pattern": {
type: "resolvedImage",
transition: true,
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "cross-faded"
},
"background-opacity": {
type: "number",
"default": 1,
minimum: 0,
maximum: 1,
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
}
};
var transition = {
duration: {
type: "number",
"default": 300,
minimum: 0,
units: "milliseconds"
},
delay: {
type: "number",
"default": 0,
minimum: 0,
units: "milliseconds"
}
};
var promoteId = {
"*": {
type: "string"
}
};
var spec = {
$version: $version,
$root: $root,
sources: sources,
source: source,
source_vector: source_vector,
source_raster: source_raster,
source_raster_dem: source_raster_dem,
source_geojson: source_geojson,
source_video: source_video,
source_image: source_image,
layer: layer,
layout: layout,
layout_background: layout_background,
layout_fill: layout_fill,
layout_circle: layout_circle,
layout_heatmap: layout_heatmap,
"layout_fill-extrusion": {
visibility: {
type: "enum",
values: {
visible: {
},
none: {
}
},
"default": "visible",
"property-type": "constant"
}
},
layout_line: layout_line,
layout_symbol: layout_symbol,
layout_raster: layout_raster,
layout_hillshade: layout_hillshade,
filter: filter,
filter_operator: filter_operator,
geometry_type: geometry_type,
"function": {
expression: {
type: "expression"
},
stops: {
type: "array",
value: "function_stop"
},
base: {
type: "number",
"default": 1,
minimum: 0
},
property: {
type: "string",
"default": "$zoom"
},
type: {
type: "enum",
values: {
identity: {
},
exponential: {
},
interval: {
},
categorical: {
}
},
"default": "exponential"
},
colorSpace: {
type: "enum",
values: {
rgb: {
},
lab: {
},
hcl: {
}
},
"default": "rgb"
},
"default": {
type: "*",
required: false
}
},
function_stop: function_stop,
expression: expression,
light: light,
paint: paint,
paint_fill: paint_fill,
"paint_fill-extrusion": {
"fill-extrusion-opacity": {
type: "number",
"default": 1,
minimum: 0,
maximum: 1,
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"fill-extrusion-color": {
type: "color",
"default": "#000000",
transition: true,
requires: [
{
"!": "fill-extrusion-pattern"
}
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"fill-extrusion-translate": {
type: "array",
value: "number",
length: 2,
"default": [
0,
0
],
transition: true,
units: "pixels",
expression: {
interpolated: true,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"fill-extrusion-translate-anchor": {
type: "enum",
values: {
map: {
},
viewport: {
}
},
"default": "map",
requires: [
"fill-extrusion-translate"
],
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
},
"fill-extrusion-pattern": {
type: "resolvedImage",
transition: true,
expression: {
interpolated: false,
parameters: [
"zoom",
"feature"
]
},
"property-type": "cross-faded-data-driven"
},
"fill-extrusion-height": {
type: "number",
"default": 0,
minimum: 0,
units: "meters",
transition: true,
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"fill-extrusion-base": {
type: "number",
"default": 0,
minimum: 0,
units: "meters",
transition: true,
requires: [
"fill-extrusion-height"
],
expression: {
interpolated: true,
parameters: [
"zoom",
"feature",
"feature-state"
]
},
"property-type": "data-driven"
},
"fill-extrusion-vertical-gradient": {
type: "boolean",
"default": true,
transition: false,
expression: {
interpolated: false,
parameters: [
"zoom"
]
},
"property-type": "data-constant"
}
},
paint_line: paint_line,
paint_circle: paint_circle,
paint_heatmap: paint_heatmap,
paint_symbol: paint_symbol,
paint_raster: paint_raster,
paint_hillshade: paint_hillshade,
paint_background: paint_background,
transition: transition,
"property-type": {
"data-driven": {
type: "property-type"
},
"cross-faded": {
type: "property-type"
},
"cross-faded-data-driven": {
type: "property-type"
},
"color-ramp": {
type: "property-type"
},
"data-constant": {
type: "property-type"
},
constant: {
type: "property-type"
}
},
promoteId: promoteId
};
var ValidationError = function ValidationError(key, value, message, identifier) {
this.message = (key ? key + ': ' : '') + message;
if (identifier) {
this.identifier = identifier;
}
if (value !== null && value !== undefined && value.__line__) {
this.line = value.__line__;
}
};
function validateConstants(options) {
var key = options.key;
var constants = options.value;
if (constants) {
return [new ValidationError(key, constants, 'constants have been deprecated as of v8')];
} else {
return [];
}
}
function extend$1 (output) {
var inputs = [], len = arguments.length - 1;
while (len-- > 0)
inputs[len] = arguments[len + 1];
for (var i = 0, list = inputs; i < list.length; i += 1) {
var input = list[i];
for (var k in input) {
output[k] = input[k];
}
}
return output;
}
function unbundle(value) {
if (value instanceof Number || value instanceof String || value instanceof Boolean) {
return value.valueOf();
} else {
return value;
}
}
function deepUnbundle(value) {
if (Array.isArray(value)) {
return value.map(deepUnbundle);
} else if (value instanceof Object && !(value instanceof Number || value instanceof String || value instanceof Boolean)) {
var unbundledValue = {};
for (var key in value) {
unbundledValue[key] = deepUnbundle(value[key]);
}
return unbundledValue;
}
return unbundle(value);
}
var ParsingError = function (Error) {
function ParsingError(key, message) {
Error.call(this, message);
this.message = message;
this.key = key;
}
if (Error)
ParsingError.__proto__ = Error;
ParsingError.prototype = Object.create(Error && Error.prototype);
ParsingError.prototype.constructor = ParsingError;
return ParsingError;
}(Error);
var Scope = function Scope(parent, bindings) {
if (bindings === void 0)
bindings = [];
this.parent = parent;
this.bindings = {};
for (var i = 0, list = bindings; i < list.length; i += 1) {
var ref = list[i];
var name = ref[0];
var expression = ref[1];
this.bindings[name] = expression;
}
};
Scope.prototype.concat = function concat(bindings) {
return new Scope(this, bindings);
};
Scope.prototype.get = function get(name) {
if (this.bindings[name]) {
return this.bindings[name];
}
if (this.parent) {
return this.parent.get(name);
}
throw new Error(name + ' not found in scope.');
};
Scope.prototype.has = function has(name) {
if (this.bindings[name]) {
return true;
}
return this.parent ? this.parent.has(name) : false;
};
var NullType = { kind: 'null' };
var NumberType = { kind: 'number' };
var StringType = { kind: 'string' };
var BooleanType = { kind: 'boolean' };
var ColorType = { kind: 'color' };
var ObjectType = { kind: 'object' };
var ValueType = { kind: 'value' };
var ErrorType = { kind: 'error' };
var CollatorType = { kind: 'collator' };
var FormattedType = { kind: 'formatted' };
var ResolvedImageType = { kind: 'resolvedImage' };
function array(itemType, N) {
return {
kind: 'array',
itemType: itemType,
N: N
};
}
function toString(type) {
if (type.kind === 'array') {
var itemType = toString(type.itemType);
return typeof type.N === 'number' ? 'array<' + itemType + ', ' + type.N + '>' : type.itemType.kind === 'value' ? 'array' : 'array<' + itemType + '>';
} else {
return type.kind;
}
}
var valueMemberTypes = [
NullType,
NumberType,
StringType,
BooleanType,
ColorType,
FormattedType,
ObjectType,
array(ValueType),
ResolvedImageType
];
function checkSubtype(expected, t) {
if (t.kind === 'error') {
return null;
} else if (expected.kind === 'array') {
if (t.kind === 'array' && (t.N === 0 && t.itemType.kind === 'value' || !checkSubtype(expected.itemType, t.itemType)) && (typeof expected.N !== 'number' || expected.N === t.N)) {
return null;
}
} else if (expected.kind === t.kind) {
return null;
} else if (expected.kind === 'value') {
for (var i = 0, list = valueMemberTypes; i < list.length; i += 1) {
var memberType = list[i];
if (!checkSubtype(memberType, t)) {
return null;
}
}
}
return 'Expected ' + toString(expected) + ' but found ' + toString(t) + ' instead.';
}
function isValidType(provided, allowedTypes) {
return allowedTypes.some(function (t) {
return t.kind === provided.kind;
});
}
function isValidNativeType(provided, allowedTypes) {
return allowedTypes.some(function (t) {
if (t === 'null') {
return provided === null;
} else if (t === 'array') {
return Array.isArray(provided);
} else if (t === 'object') {
return provided && !Array.isArray(provided) && typeof provided === 'object';
} else {
return t === typeof provided;
}
});
}
var csscolorparser = createCommonjsModule(function (module, exports) {
var kCSSColorTable = {
'transparent': [
0,
0,
0,
0
],
'aliceblue': [
240,
248,
255,
1
],
'antiquewhite': [
250,
235,
215,
1
],
'aqua': [
0,
255,
255,
1
],
'aquamarine': [
127,
255,
212,
1
],
'azure': [
240,
255,
255,
1
],
'beige': [
245,
245,
220,
1
],
'bisque': [
255,
228,
196,
1
],
'black': [
0,
0,
0,
1
],
'blanchedalmond': [
255,
235,
205,
1
],
'blue': [
0,
0,
255,
1
],
'blueviolet': [
138,
43,
226,
1
],
'brown': [
165,
42,
42,
1
],
'burlywood': [
222,
184,
135,
1
],
'cadetblue': [
95,
158,
160,
1
],
'chartreuse': [
127,
255,
0,
1
],
'chocolate': [
210,
105,
30,
1
],
'coral': [
255,
127,
80,
1
],
'cornflowerblue': [
100,
149,
237,
1
],
'cornsilk': [
255,
248,
220,
1
],
'crimson': [
220,
20,
60,
1
],
'cyan': [
0,
255,
255,
1
],
'darkblue': [
0,
0,
139,
1
],
'darkcyan': [
0,
139,
139,
1
],
'darkgoldenrod': [
184,
134,
11,
1
],
'darkgray': [
169,
169,
169,
1
],
'darkgreen': [
0,
100,
0,
1
],
'darkgrey': [
169,
169,
169,
1
],
'darkkhaki': [
189,
183,
107,
1
],
'darkmagenta': [
139,
0,
139,
1
],
'darkolivegreen': [
85,
107,
47,
1
],
'darkorange': [
255,
140,
0,
1
],
'darkorchid': [
153,
50,
204,
1
],
'darkred': [
139,
0,
0,
1
],
'darksalmon': [
233,
150,
122,
1
],
'darkseagreen': [
143,
188,
143,
1
],
'darkslateblue': [
72,
61,
139,
1
],
'darkslategray': [
47,
79,
79,
1
],
'darkslategrey': [
47,
79,
79,
1
],
'darkturquoise': [
0,
206,
209,
1
],
'darkviolet': [
148,
0,
211,
1
],
'deeppink': [
255,
20,
147,
1
],
'deepskyblue': [
0,
191,
255,
1
],
'dimgray': [
105,
105,
105,
1
],
'dimgrey': [
105,
105,
105,
1
],
'dodgerblue': [
30,
144,
255,
1
],
'firebrick': [
178,
34,
34,
1
],
'floralwhite': [
255,
250,
240,
1
],
'forestgreen': [
34,
139,
34,
1
],
'fuchsia': [
255,
0,
255,
1
],
'gainsboro': [
220,
220,
220,
1
],
'ghostwhite': [
248,
248,
255,
1
],
'gold': [
255,
215,
0,
1
],
'goldenrod': [
218,
165,
32,
1
],
'gray': [
128,
128,
128,
1
],
'green': [
0,
128,
0,
1
],
'greenyellow': [
173,
255,
47,
1
],
'grey': [
128,
128,
128,
1
],
'honeydew': [
240,
255,
240,
1
],
'hotpink': [
255,
105,
180,
1
],
'indianred': [
205,
92,
92,
1
],
'indigo': [
75,
0,
130,
1
],
'ivory': [
255,
255,
240,
1
],
'khaki': [
240,
230,
140,
1
],
'lavender': [
230,
230,
250,
1
],
'lavenderblush': [
255,
240,
245,
1
],
'lawngreen': [
124,
252,
0,
1
],
'lemonchiffon': [
255,
250,
205,
1
],
'lightblue': [
173,
216,
230,
1
],
'lightcoral': [
240,
128,
128,
1
],
'lightcyan': [
224,
255,
255,
1
],
'lightgoldenrodyellow': [
250,
250,
210,
1
],
'lightgray': [
211,
211,
211,
1
],
'lightgreen': [
144,
238,
144,
1
],
'lightgrey': [
211,
211,
211,
1
],
'lightpink': [
255,
182,
193,
1
],
'lightsalmon': [
255,
160,
122,
1
],
'lightseagreen': [
32,
178,
170,
1
],
'lightskyblue': [
135,
206,
250,
1
],
'lightslategray': [
119,
136,
153,
1
],
'lightslategrey': [
119,
136,
153,
1
],
'lightsteelblue': [
176,
196,
222,
1
],
'lightyellow': [
255,
255,
224,
1
],
'lime': [
0,
255,
0,
1
],
'limegreen': [
50,
205,
50,
1
],
'linen': [
250,
240,
230,
1
],
'magenta': [
255,
0,
255,
1
],
'maroon': [
128,
0,
0,
1
],
'mediumaquamarine': [
102,
205,
170,
1
],
'mediumblue': [
0,
0,
205,
1
],
'mediumorchid': [
186,
85,
211,
1
],
'mediumpurple': [
147,
112,
219,
1
],
'mediumseagreen': [
60,
179,
113,
1
],
'mediumslateblue': [
123,
104,
238,
1
],
'mediumspringgreen': [
0,
250,
154,
1
],
'mediumturquoise': [
72,
209,
204,
1
],
'mediumvioletred': [
199,
21,
133,
1
],
'midnightblue': [
25,
25,
112,
1
],
'mintcream': [
245,
255,
250,
1
],
'mistyrose': [
255,
228,
225,
1
],
'moccasin': [
255,
228,
181,
1
],
'navajowhite': [
255,
222,
173,
1
],
'navy': [
0,
0,
128,
1
],
'oldlace': [
253,
245,
230,
1
],
'olive': [
128,
128,
0,
1
],
'olivedrab': [
107,
142,
35,
1
],
'orange': [
255,
165,
0,
1
],
'orangered': [
255,
69,
0,
1
],
'orchid': [
218,
112,
214,
1
],
'palegoldenrod': [
238,
232,
170,
1
],
'palegreen': [
152,
251,
152,
1
],
'paleturquoise': [
175,
238,
238,
1
],
'palevioletred': [
219,
112,
147,
1
],
'papayawhip': [
255,
239,
213,
1
],
'peachpuff': [
255,
218,
185,
1
],
'peru': [
205,
133,
63,
1
],
'pink': [
255,
192,
203,
1
],
'plum': [
221,
160,
221,
1
],
'powderblue': [
176,
224,
230,
1
],
'purple': [
128,
0,
128,
1
],
'rebeccapurple': [
102,
51,
153,
1
],
'red': [
255,
0,
0,
1
],
'rosybrown': [
188,
143,
143,
1
],
'royalblue': [
65,
105,
225,
1
],
'saddlebrown': [
139,
69,
19,
1
],
'salmon': [
250,
128,
114,
1
],
'sandybrown': [
244,
164,
96,
1
],
'seagreen': [
46,
139,
87,
1
],
'seashell': [
255,
245,
238,
1
],
'sienna': [
160,
82,
45,
1
],
'silver': [
192,
192,
192,
1
],
'skyblue': [
135,
206,
235,
1
],
'slateblue': [
106,
90,
205,
1
],
'slategray': [
112,
128,
144,
1
],
'slategrey': [
112,
128,
144,
1
],
'snow': [
255,
250,
250,
1
],
'springgreen': [
0,
255,
127,
1
],
'steelblue': [
70,
130,
180,
1
],
'tan': [
210,
180,
140,
1
],
'teal': [
0,
128,
128,
1
],
'thistle': [
216,
191,
216,
1
],
'tomato': [
255,
99,
71,
1
],
'turquoise': [
64,
224,
208,
1
],
'violet': [
238,
130,
238,
1
],
'wheat': [
245,
222,
179,
1
],
'white': [
255,
255,
255,
1
],
'whitesmoke': [
245,
245,
245,
1
],
'yellow': [
255,
255,
0,
1
],
'yellowgreen': [
154,
205,
50,
1
]
};
function clamp_css_byte(i) {
i = Math.round(i);
return i < 0 ? 0 : i > 255 ? 255 : i;
}
function clamp_css_float(f) {
return f < 0 ? 0 : f > 1 ? 1 : f;
}
function parse_css_int(str) {
if (str[str.length - 1] === '%') {
return clamp_css_byte(parseFloat(str) / 100 * 255);
}
return clamp_css_byte(parseInt(str));
}
function parse_css_float(str) {
if (str[str.length - 1] === '%') {
return clamp_css_float(parseFloat(str) / 100);
}
return clamp_css_float(parseFloat(str));
}
function css_hue_to_rgb(m1, m2, h) {
if (h < 0) {
h += 1;
} else if (h > 1) {
h -= 1;
}
if (h * 6 < 1) {
return m1 + (m2 - m1) * h * 6;
}
if (h * 2 < 1) {
return m2;
}
if (h * 3 < 2) {
return m1 + (m2 - m1) * (2 / 3 - h) * 6;
}
return m1;
}
function parseCSSColor(css_str) {
var str = css_str.replace(/ /g, '').toLowerCase();
if (str in kCSSColorTable) {
return kCSSColorTable[str].slice();
}
if (str[0] === '#') {
if (str.length === 4) {
var iv = parseInt(str.substr(1), 16);
if (!(iv >= 0 && iv <= 4095)) {
return null;
}
return [
(iv & 3840) >> 4 | (iv & 3840) >> 8,
iv & 240 | (iv & 240) >> 4,
iv & 15 | (iv & 15) << 4,
1
];
} else if (str.length === 7) {
var iv = parseInt(str.substr(1), 16);
if (!(iv >= 0 && iv <= 16777215)) {
return null;
}
return [
(iv & 16711680) >> 16,
(iv & 65280) >> 8,
iv & 255,
1
];
}
return null;
}
var op = str.indexOf('('), ep = str.indexOf(')');
if (op !== -1 && ep + 1 === str.length) {
var fname = str.substr(0, op);
var params = str.substr(op + 1, ep - (op + 1)).split(',');
var alpha = 1;
switch (fname) {
case 'rgba':
if (params.length !== 4) {
return null;
}
alpha = parse_css_float(params.pop());
case 'rgb':
if (params.length !== 3) {
return null;
}
return [
parse_css_int(params[0]),
parse_css_int(params[1]),
parse_css_int(params[2]),
alpha
];
case 'hsla':
if (params.length !== 4) {
return null;
}
alpha = parse_css_float(params.pop());
case 'hsl':
if (params.length !== 3) {
return null;
}
var h = (parseFloat(params[0]) % 360 + 360) % 360 / 360;
var s = parse_css_float(params[1]);
var l = parse_css_float(params[2]);
var m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
var m1 = l * 2 - m2;
return [
clamp_css_byte(css_hue_to_rgb(m1, m2, h + 1 / 3) * 255),
clamp_css_byte(css_hue_to_rgb(m1, m2, h) * 255),
clamp_css_byte(css_hue_to_rgb(m1, m2, h - 1 / 3) * 255),
alpha
];
default:
return null;
}
}
return null;
}
try {
exports.parseCSSColor = parseCSSColor;
} catch (e) {
}
});
var csscolorparser_1 = csscolorparser.parseCSSColor;
var Color = function Color(r, g, b, a) {
if (a === void 0)
a = 1;
this.r = r;
this.g = g;
this.b = b;
this.a = a;
};
Color.parse = function parse(input) {
if (!input) {
return undefined;
}
if (input instanceof Color) {
return input;
}
if (typeof input !== 'string') {
return undefined;
}
var rgba = csscolorparser_1(input);
if (!rgba) {
return undefined;
}
return new Color(rgba[0] / 255 * rgba[3], rgba[1] / 255 * rgba[3], rgba[2] / 255 * rgba[3], rgba[3]);
};
Color.prototype.toString = function toString() {
var ref = this.toArray();
var r = ref[0];
var g = ref[1];
var b = ref[2];
var a = ref[3];
return 'rgba(' + Math.round(r) + ',' + Math.round(g) + ',' + Math.round(b) + ',' + a + ')';
};
Color.prototype.toArray = function toArray() {
var ref = this;
var r = ref.r;
var g = ref.g;
var b = ref.b;
var a = ref.a;
return a === 0 ? [
0,
0,
0,
0
] : [
r * 255 / a,
g * 255 / a,
b * 255 / a,
a
];
};
Color.black = new Color(0, 0, 0, 1);
Color.white = new Color(1, 1, 1, 1);
Color.transparent = new Color(0, 0, 0, 0);
Color.red = new Color(1, 0, 0, 1);
var Collator = function Collator(caseSensitive, diacriticSensitive, locale) {
if (caseSensitive) {
this.sensitivity = diacriticSensitive ? 'variant' : 'case';
} else {
this.sensitivity = diacriticSensitive ? 'accent' : 'base';
}
this.locale = locale;
this.collator = new Intl.Collator(this.locale ? this.locale : [], {
sensitivity: this.sensitivity,
usage: 'search'
});
};
Collator.prototype.compare = function compare(lhs, rhs) {
return this.collator.compare(lhs, rhs);
};
Collator.prototype.resolvedLocale = function resolvedLocale() {
return new Intl.Collator(this.locale ? this.locale : []).resolvedOptions().locale;
};
var FormattedSection = function FormattedSection(text, image, scale, fontStack, textColor) {
this.text = text;
this.image = image;
this.scale = scale;
this.fontStack = fontStack;
this.textColor = textColor;
};
var Formatted = function Formatted(sections) {
this.sections = sections;
};
Formatted.fromString = function fromString(unformatted) {
return new Formatted([new FormattedSection(unformatted, null, null, null, null)]);
};
Formatted.prototype.isEmpty = function isEmpty() {
if (this.sections.length === 0) {
return true;
}
return !this.sections.some(function (section) {
return section.text.length !== 0 || section.image && section.image.name.length !== 0;
});
};
Formatted.factory = function factory(text) {
if (text instanceof Formatted) {
return text;
} else {
return Formatted.fromString(text);
}
};
Formatted.prototype.toString = function toString() {
if (this.sections.length === 0) {
return '';
}
return this.sections.map(function (section) {
return section.text;
}).join('');
};
Formatted.prototype.serialize = function serialize() {
var serialized = ['format'];
for (var i = 0, list = this.sections; i < list.length; i += 1) {
var section = list[i];
if (section.image) {
serialized.push([
'image',
section.image.name
]);
continue;
}
serialized.push(section.text);
var options = {};
if (section.fontStack) {
options['text-font'] = [
'literal',
section.fontStack.split(',')
];
}
if (section.scale) {
options['font-scale'] = section.scale;
}
if (section.textColor) {
options['text-color'] = ['rgba'].concat(section.textColor.toArray());
}
serialized.push(options);
}
return serialized;
};
var ResolvedImage = function ResolvedImage(options) {
this.name = options.name;
this.available = options.available;
};
ResolvedImage.prototype.toString = function toString() {
return this.name;
};
ResolvedImage.fromString = function fromString(name) {
if (!name) {
return null;
}
return new ResolvedImage({
name: name,
available: false
});
};
ResolvedImage.prototype.serialize = function serialize() {
return [
'image',
this.name
];
};
function validateRGBA(r, g, b, a) {
if (!(typeof r === 'number' && r >= 0 && r <= 255 && typeof g === 'number' && g >= 0 && g <= 255 && typeof b === 'number' && b >= 0 && b <= 255)) {
var value = typeof a === 'number' ? [
r,
g,
b,
a
] : [
r,
g,
b
];
return 'Invalid rgba value [' + value.join(', ') + ']: \'r\', \'g\', and \'b\' must be between 0 and 255.';
}
if (!(typeof a === 'undefined' || typeof a === 'number' && a >= 0 && a <= 1)) {
return 'Invalid rgba value [' + [
r,
g,
b,
a
].join(', ') + ']: \'a\' must be between 0 and 1.';
}
return null;
}
function isValue(mixed) {
if (mixed === null) {
return true;
} else if (typeof mixed === 'string') {
return true;
} else if (typeof mixed === 'boolean') {
return true;
} else if (typeof mixed === 'number') {
return true;
} else if (mixed instanceof Color) {
return true;
} else if (mixed instanceof Collator) {
return true;
} else if (mixed instanceof Formatted) {
return true;
} else if (mixed instanceof ResolvedImage) {
return true;
} else if (Array.isArray(mixed)) {
for (var i = 0, list = mixed; i < list.length; i += 1) {
var item = list[i];
if (!isValue(item)) {
return false;
}
}
return true;
} else if (typeof mixed === 'object') {
for (var key in mixed) {
if (!isValue(mixed[key])) {
return false;
}
}
return true;
} else {
return false;
}
}
function typeOf(value) {
if (value === null) {
return NullType;
} else if (typeof value === 'string') {
return StringType;
} else if (typeof value === 'boolean') {
return BooleanType;
} else if (typeof value === 'number') {
return NumberType;
} else if (value instanceof Color) {
return ColorType;
} else if (value instanceof Collator) {
return CollatorType;
} else if (value instanceof Formatted) {
return FormattedType;
} else if (value instanceof ResolvedImage) {
return ResolvedImageType;
} else if (Array.isArray(value)) {
var length = value.length;
var itemType;
for (var i = 0, list = value; i < list.length; i += 1) {
var item = list[i];
var t = typeOf(item);
if (!itemType) {
itemType = t;
} else if (itemType === t) {
continue;
} else {
itemType = ValueType;
break;
}
}
return array(itemType || ValueType, length);
} else {
return ObjectType;
}
}
function toString$1(value) {
var type = typeof value;
if (value === null) {
return '';
} else if (type === 'string' || type === 'number' || type === 'boolean') {
return String(value);
} else if (value instanceof Color || value instanceof Formatted || value instanceof ResolvedImage) {
return value.toString();
} else {
return JSON.stringify(value);
}
}
var Literal = function Literal(type, value) {
this.type = type;
this.value = value;
};
Literal.parse = function parse(args, context) {
if (args.length !== 2) {
return context.error('\'literal\' expression requires exactly one argument, but found ' + (args.length - 1) + ' instead.');
}
if (!isValue(args[1])) {
return context.error('invalid value');
}
var value = args[1];
var type = typeOf(value);
var expected = context.expectedType;
if (type.kind === 'array' && type.N === 0 && expected && expected.kind === 'array' && (typeof expected.N !== 'number' || expected.N === 0)) {
type = expected;
}
return new Literal(type, value);
};
Literal.prototype.evaluate = function evaluate() {
return this.value;
};
Literal.prototype.eachChild = function eachChild() {
};
Literal.prototype.outputDefined = function outputDefined() {
return true;
};
Literal.prototype.serialize = function serialize() {
if (this.type.kind === 'array' || this.type.kind === 'object') {
return [
'literal',
this.value
];
} else if (this.value instanceof Color) {
return ['rgba'].concat(this.value.toArray());
} else if (this.value instanceof Formatted) {
return this.value.serialize();
} else {
return this.value;
}
};
var RuntimeError = function RuntimeError(message) {
this.name = 'ExpressionEvaluationError';
this.message = message;
};
RuntimeError.prototype.toJSON = function toJSON() {
return this.message;
};
var types = {
string: StringType,
number: NumberType,
boolean: BooleanType,
object: ObjectType
};
var Assertion = function Assertion(type, args) {
this.type = type;
this.args = args;
};
Assertion.parse = function parse(args, context) {
if (args.length < 2) {
return context.error('Expected at least one argument.');
}
var i = 1;
var type;
var name = args[0];
if (name === 'array') {
var itemType;
if (args.length > 2) {
var type$1 = args[1];
if (typeof type$1 !== 'string' || !(type$1 in types) || type$1 === 'object') {
return context.error('The item type argument of "array" must be one of string, number, boolean', 1);
}
itemType = types[type$1];
i++;
} else {
itemType = ValueType;
}
var N;
if (args.length > 3) {
if (args[2] !== null && (typeof args[2] !== 'number' || args[2] < 0 || args[2] !== Math.floor(args[2]))) {
return context.error('The length argument to "array" must be a positive integer literal', 2);
}
N = args[2];
i++;
}
type = array(itemType, N);
} else {
type = types[name];
}
var parsed = [];
for (; i < args.length; i++) {
var input = context.parse(args[i], i, ValueType);
if (!input) {
return null;
}
parsed.push(input);
}
return new Assertion(type, parsed);
};
Assertion.prototype.evaluate = function evaluate(ctx) {
for (var i = 0; i < this.args.length; i++) {
var value = this.args[i].evaluate(ctx);
var error = checkSubtype(this.type, typeOf(value));
if (!error) {
return value;
} else if (i === this.args.length - 1) {
throw new RuntimeError('Expected value to be of type ' + toString(this.type) + ', but found ' + toString(typeOf(value)) + ' instead.');
}
}
return null;
};
Assertion.prototype.eachChild = function eachChild(fn) {
this.args.forEach(fn);
};
Assertion.prototype.outputDefined = function outputDefined() {
return this.args.every(function (arg) {
return arg.outputDefined();
});
};
Assertion.prototype.serialize = function serialize() {
var type = this.type;
var serialized = [type.kind];
if (type.kind === 'array') {
var itemType = type.itemType;
if (itemType.kind === 'string' || itemType.kind === 'number' || itemType.kind === 'boolean') {
serialized.push(itemType.kind);
var N = type.N;
if (typeof N === 'number' || this.args.length > 1) {
serialized.push(N);
}
}
}
return serialized.concat(this.args.map(function (arg) {
return arg.serialize();
}));
};
var FormatExpression = function FormatExpression(sections) {
this.type = FormattedType;
this.sections = sections;
};
FormatExpression.parse = function parse(args, context) {
if (args.length < 2) {
return context.error('Expected at least one argument.');
}
var firstArg = args[1];
if (!Array.isArray(firstArg) && typeof firstArg === 'object') {
return context.error('First argument must be an image or text section.');
}
var sections = [];
var nextTokenMayBeObject = false;
for (var i = 1; i <= args.length - 1; ++i) {
var arg = args[i];
if (nextTokenMayBeObject && typeof arg === 'object' && !Array.isArray(arg)) {
nextTokenMayBeObject = false;
var scale = null;
if (arg['font-scale']) {
scale = context.parse(arg['font-scale'], 1, NumberType);
if (!scale) {
return null;
}
}
var font = null;
if (arg['text-font']) {
font = context.parse(arg['text-font'], 1, array(StringType));
if (!font) {
return null;
}
}
var textColor = null;
if (arg['text-color']) {
textColor = context.parse(arg['text-color'], 1, ColorType);
if (!textColor) {
return null;
}
}
var lastExpression = sections[sections.length - 1];
lastExpression.scale = scale;
lastExpression.font = font;
lastExpression.textColor = textColor;
} else {
var content = context.parse(args[i], 1, ValueType);
if (!content) {
return null;
}
var kind = content.type.kind;
if (kind !== 'string' && kind !== 'value' && kind !== 'null' && kind !== 'resolvedImage') {
return context.error('Formatted text type must be \'string\', \'value\', \'image\' or \'null\'.');
}
nextTokenMayBeObject = true;
sections.push({
content: content,
scale: null,
font: null,
textColor: null
});
}
}
return new FormatExpression(sections);
};
FormatExpression.prototype.evaluate = function evaluate(ctx) {
var evaluateSection = function (section) {
var evaluatedContent = section.content.evaluate(ctx);
if (typeOf(evaluatedContent) === ResolvedImageType) {
return new FormattedSection('', evaluatedContent, null, null, null);
}
return new FormattedSection(toString$1(evaluatedContent), null, section.scale ? section.scale.evaluate(ctx) : null, section.font ? section.font.evaluate(ctx).join(',') : null, section.textColor ? section.textColor.evaluate(ctx) : null);
};
return new Formatted(this.sections.map(evaluateSection));
};
FormatExpression.prototype.eachChild = function eachChild(fn) {
for (var i = 0, list = this.sections; i < list.length; i += 1) {
var section = list[i];
fn(section.content);
if (section.scale) {
fn(section.scale);
}
if (section.font) {
fn(section.font);
}
if (section.textColor) {
fn(section.textColor);
}
}
};
FormatExpression.prototype.outputDefined = function outputDefined() {
return false;
};
FormatExpression.prototype.serialize = function serialize() {
var serialized = ['format'];
for (var i = 0, list = this.sections; i < list.length; i += 1) {
var section = list[i];
serialized.push(section.content.serialize());
var options = {};
if (section.scale) {
options['font-scale'] = section.scale.serialize();
}
if (section.font) {
options['text-font'] = section.font.serialize();
}
if (section.textColor) {
options['text-color'] = section.textColor.serialize();
}
serialized.push(options);
}
return serialized;
};
var ImageExpression = function ImageExpression(input) {
this.type = ResolvedImageType;
this.input = input;
};
ImageExpression.parse = function parse(args, context) {
if (args.length !== 2) {
return context.error('Expected two arguments.');
}
var name = context.parse(args[1], 1, StringType);
if (!name) {
return context.error('No image name provided.');
}
return new ImageExpression(name);
};
ImageExpression.prototype.evaluate = function evaluate(ctx) {
var evaluatedImageName = this.input.evaluate(ctx);
var value = ResolvedImage.fromString(evaluatedImageName);
if (value && ctx.availableImages) {
value.available = ctx.availableImages.indexOf(evaluatedImageName) > -1;
}
return value;
};
ImageExpression.prototype.eachChild = function eachChild(fn) {
fn(this.input);
};
ImageExpression.prototype.outputDefined = function outputDefined() {
return false;
};
ImageExpression.prototype.serialize = function serialize() {
return [
'image',
this.input.serialize()
];
};
var types$1 = {
'to-boolean': BooleanType,
'to-color': ColorType,
'to-number': NumberType,
'to-string': StringType
};
var Coercion = function Coercion(type, args) {
this.type = type;
this.args = args;
};
Coercion.parse = function parse(args, context) {
if (args.length < 2) {
return context.error('Expected at least one argument.');
}
var name = args[0];
if ((name === 'to-boolean' || name === 'to-string') && args.length !== 2) {
return context.error('Expected one argument.');
}
var type = types$1[name];
var parsed = [];
for (var i = 1; i < args.length; i++) {
var input = context.parse(args[i], i, ValueType);
if (!input) {
return null;
}
parsed.push(input);
}
return new Coercion(type, parsed);
};
Coercion.prototype.evaluate = function evaluate(ctx) {
if (this.type.kind === 'boolean') {
return Boolean(this.args[0].evaluate(ctx));
} else if (this.type.kind === 'color') {
var input;
var error;
for (var i = 0, list = this.args; i < list.length; i += 1) {
var arg = list[i];
input = arg.evaluate(ctx);
error = null;
if (input instanceof Color) {
return input;
} else if (typeof input === 'string') {
var c = ctx.parseColor(input);
if (c) {
return c;
}
} else if (Array.isArray(input)) {
if (input.length < 3 || input.length > 4) {
error = 'Invalid rbga value ' + JSON.stringify(input) + ': expected an array containing either three or four numeric values.';
} else {
error = validateRGBA(input[0], input[1], input[2], input[3]);
}
if (!error) {
return new Color(input[0] / 255, input[1] / 255, input[2] / 255, input[3]);
}
}
}
throw new RuntimeError(error || 'Could not parse color from value \'' + (typeof input === 'string' ? input : String(JSON.stringify(input))) + '\'');
} else if (this.type.kind === 'number') {
var value = null;
for (var i$1 = 0, list$1 = this.args; i$1 < list$1.length; i$1 += 1) {
var arg$1 = list$1[i$1];
value = arg$1.evaluate(ctx);
if (value === null) {
return 0;
}
var num = Number(value);
if (isNaN(num)) {
continue;
}
return num;
}
throw new RuntimeError('Could not convert ' + JSON.stringify(value) + ' to number.');
} else if (this.type.kind === 'formatted') {
return Formatted.fromString(toString$1(this.args[0].evaluate(ctx)));
} else if (this.type.kind === 'resolvedImage') {
return ResolvedImage.fromString(toString$1(this.args[0].evaluate(ctx)));
} else {
return toString$1(this.args[0].evaluate(ctx));
}
};
Coercion.prototype.eachChild = function eachChild(fn) {
this.args.forEach(fn);
};
Coercion.prototype.outputDefined = function outputDefined() {
return this.args.every(function (arg) {
return arg.outputDefined();
});
};
Coercion.prototype.serialize = function serialize() {
if (this.type.kind === 'formatted') {
return new FormatExpression([{
content: this.args[0],
scale: null,
font: null,
textColor: null
}]).serialize();
}
if (this.type.kind === 'resolvedImage') {
return new ImageExpression(this.args[0]).serialize();
}
var serialized = ['to-' + this.type.kind];
this.eachChild(function (child) {
serialized.push(child.serialize());
});
return serialized;
};
var geometryTypes = [
'Unknown',
'Point',
'LineString',
'Polygon'
];
var EvaluationContext = function EvaluationContext() {
this.globals = null;
this.feature = null;
this.featureState = null;
this.formattedSection = null;
this._parseColorCache = {};
this.availableImages = null;
this.canonical = null;
};
EvaluationContext.prototype.id = function id() {
return this.feature && 'id' in this.feature ? this.feature.id : null;
};
EvaluationContext.prototype.geometryType = function geometryType() {
return this.feature ? typeof this.feature.type === 'number' ? geometryTypes[this.feature.type] : this.feature.type : null;
};
EvaluationContext.prototype.geometry = function geometry() {
return this.feature && 'geometry' in this.feature ? this.feature.geometry : null;
};
EvaluationContext.prototype.canonicalID = function canonicalID() {
return this.canonical;
};
EvaluationContext.prototype.properties = function properties() {
return this.feature && this.feature.properties || {};
};
EvaluationContext.prototype.parseColor = function parseColor(input) {
var cached = this._parseColorCache[input];
if (!cached) {
cached = this._parseColorCache[input] = Color.parse(input);
}
return cached;
};
var CompoundExpression = function CompoundExpression(name, type, evaluate, args) {
this.name = name;
this.type = type;
this._evaluate = evaluate;
this.args = args;
};
CompoundExpression.prototype.evaluate = function evaluate(ctx) {
return this._evaluate(ctx, this.args);
};
CompoundExpression.prototype.eachChild = function eachChild(fn) {
this.args.forEach(fn);
};
CompoundExpression.prototype.outputDefined = function outputDefined() {
return false;
};
CompoundExpression.prototype.serialize = function serialize() {
return [this.name].concat(this.args.map(function (arg) {
return arg.serialize();
}));
};
CompoundExpression.parse = function parse(args, context) {
var ref$1;
var op = args[0];
var definition = CompoundExpression.definitions[op];
if (!definition) {
return context.error('Unknown expression "' + op + '". If you wanted a literal array, use ["literal", [...]].', 0);
}
var type = Array.isArray(definition) ? definition[0] : definition.type;
var availableOverloads = Array.isArray(definition) ? [[
definition[1],
definition[2]
]] : definition.overloads;
var overloads = availableOverloads.filter(function (ref) {
var signature = ref[0];
return !Array.isArray(signature) || signature.length === args.length - 1;
});
var signatureContext = null;
for (var i$3 = 0, list = overloads; i$3 < list.length; i$3 += 1) {
var ref = list[i$3];
var params = ref[0];
var evaluate = ref[1];
signatureContext = new ParsingContext(context.registry, context.path, null, context.scope);
var parsedArgs = [];
var argParseFailed = false;
for (var i = 1; i < args.length; i++) {
var arg = args[i];
var expectedType = Array.isArray(params) ? params[i - 1] : params.type;
var parsed = signatureContext.parse(arg, 1 + parsedArgs.length, expectedType);
if (!parsed) {
argParseFailed = true;
break;
}
parsedArgs.push(parsed);
}
if (argParseFailed) {
continue;
}
if (Array.isArray(params)) {
if (params.length !== parsedArgs.length) {
signatureContext.error('Expected ' + params.length + ' arguments, but found ' + parsedArgs.length + ' instead.');
continue;
}
}
for (var i$1 = 0; i$1 < parsedArgs.length; i$1++) {
var expected = Array.isArray(params) ? params[i$1] : params.type;
var arg$1 = parsedArgs[i$1];
signatureContext.concat(i$1 + 1).checkSubtype(expected, arg$1.type);
}
if (signatureContext.errors.length === 0) {
return new CompoundExpression(op, type, evaluate, parsedArgs);
}
}
if (overloads.length === 1) {
(ref$1 = context.errors).push.apply(ref$1, signatureContext.errors);
} else {
var expected$1 = overloads.length ? overloads : availableOverloads;
var signatures = expected$1.map(function (ref) {
var params = ref[0];
return stringifySignature(params);
}).join(' | ');
var actualTypes = [];
for (var i$2 = 1; i$2 < args.length; i$2++) {
var parsed$1 = context.parse(args[i$2], 1 + actualTypes.length);
if (!parsed$1) {
return null;
}
actualTypes.push(toString(parsed$1.type));
}
context.error('Expected arguments of type ' + signatures + ', but found (' + actualTypes.join(', ') + ') instead.');
}
return null;
};
CompoundExpression.register = function register(registry, definitions) {
CompoundExpression.definitions = definitions;
for (var name in definitions) {
registry[name] = CompoundExpression;
}
};
function stringifySignature(signature) {
if (Array.isArray(signature)) {
return '(' + signature.map(toString).join(', ') + ')';
} else {
return '(' + toString(signature.type) + '...)';
}
}
var CollatorExpression = function CollatorExpression(caseSensitive, diacriticSensitive, locale) {
this.type = CollatorType;
this.locale = locale;
this.caseSensitive = caseSensitive;
this.diacriticSensitive = diacriticSensitive;
};
CollatorExpression.parse = function parse(args, context) {
if (args.length !== 2) {
return context.error('Expected one argument.');
}
var options = args[1];
if (typeof options !== 'object' || Array.isArray(options)) {
return context.error('Collator options argument must be an object.');
}
var caseSensitive = context.parse(options['case-sensitive'] === undefined ? false : options['case-sensitive'], 1, BooleanType);
if (!caseSensitive) {
return null;
}
var diacriticSensitive = context.parse(options['diacritic-sensitive'] === undefined ? false : options['diacritic-sensitive'], 1, BooleanType);
if (!diacriticSensitive) {
return null;
}
var locale = null;
if (options['locale']) {
locale = context.parse(options['locale'], 1, StringType);
if (!locale) {
return null;
}
}
return new CollatorExpression(caseSensitive, diacriticSensitive, locale);
};
CollatorExpression.prototype.evaluate = function evaluate(ctx) {
return new Collator(this.caseSensitive.evaluate(ctx), this.diacriticSensitive.evaluate(ctx), this.locale ? this.locale.evaluate(ctx) : null);
};
CollatorExpression.prototype.eachChild = function eachChild(fn) {
fn(this.caseSensitive);
fn(this.diacriticSensitive);
if (this.locale) {
fn(this.locale);
}
};
CollatorExpression.prototype.outputDefined = function outputDefined() {
return false;
};
CollatorExpression.prototype.serialize = function serialize() {
var options = {};
options['case-sensitive'] = this.caseSensitive.serialize();
options['diacritic-sensitive'] = this.diacriticSensitive.serialize();
if (this.locale) {
options['locale'] = this.locale.serialize();
}
return [
'collator',
options
];
};
var EXTENT = 8192;
function updateBBox(bbox, coord) {
bbox[0] = Math.min(bbox[0], coord[0]);
bbox[1] = Math.min(bbox[1], coord[1]);
bbox[2] = Math.max(bbox[2], coord[0]);
bbox[3] = Math.max(bbox[3], coord[1]);
}
function mercatorXfromLng(lng) {
return (180 + lng) / 360;
}
function mercatorYfromLat(lat) {
return (180 - 180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 360))) / 360;
}
function boxWithinBox(bbox1, bbox2) {
if (bbox1[0] <= bbox2[0]) {
return false;
}
if (bbox1[2] >= bbox2[2]) {
return false;
}
if (bbox1[1] <= bbox2[1]) {
return false;
}
if (bbox1[3] >= bbox2[3]) {
return false;
}
return true;
}
function getTileCoordinates(p, canonical) {
var x = mercatorXfromLng(p[0]);
var y = mercatorYfromLat(p[1]);
var tilesAtZoom = Math.pow(2, canonical.z);
return [
Math.round(x * tilesAtZoom * EXTENT),
Math.round(y * tilesAtZoom * EXTENT)
];
}
function onBoundary(p, p1, p2) {
var x1 = p[0] - p1[0];
var y1 = p[1] - p1[1];
var x2 = p[0] - p2[0];
var y2 = p[1] - p2[1];
return x1 * y2 - x2 * y1 === 0 && x1 * x2 <= 0 && y1 * y2 <= 0;
}
function rayIntersect(p, p1, p2) {
return p1[1] > p[1] !== p2[1] > p[1] && p[0] < (p2[0] - p1[0]) * (p[1] - p1[1]) / (p2[1] - p1[1]) + p1[0];
}
function pointWithinPolygon(point, rings) {
var inside = false;
for (var i = 0, len = rings.length; i < len; i++) {
var ring = rings[i];
for (var j = 0, len2 = ring.length; j < len2 - 1; j++) {
if (onBoundary(point, ring[j], ring[j + 1])) {
return false;
}
if (rayIntersect(point, ring[j], ring[j + 1])) {
inside = !inside;
}
}
}
return inside;
}
function pointWithinPolygons(point, polygons) {
for (var i = 0; i < polygons.length; i++) {
if (pointWithinPolygon(point, polygons[i])) {
return true;
}
}
return false;
}
function perp(v1, v2) {
return v1[0] * v2[1] - v1[1] * v2[0];
}
function twoSided(p1, p2, q1, q2) {
var x1 = p1[0] - q1[0];
var y1 = p1[1] - q1[1];
var x2 = p2[0] - q1[0];
var y2 = p2[1] - q1[1];
var x3 = q2[0] - q1[0];
var y3 = q2[1] - q1[1];
var det1 = x1 * y3 - x3 * y1;
var det2 = x2 * y3 - x3 * y2;
if (det1 > 0 && det2 < 0 || det1 < 0 && det2 > 0) {
return true;
}
return false;
}
function lineIntersectLine(a, b, c, d) {
var vectorP = [
b[0] - a[0],
b[1] - a[1]
];
var vectorQ = [
d[0] - c[0],
d[1] - c[1]
];
if (perp(vectorQ, vectorP) === 0) {
return false;
}
if (twoSided(a, b, c, d) && twoSided(c, d, a, b)) {
return true;
}
return false;
}
function lineIntersectPolygon(p1, p2, polygon) {
for (var i = 0, list = polygon; i < list.length; i += 1) {
var ring = list[i];
for (var j = 0; j < ring.length - 1; ++j) {
if (lineIntersectLine(p1, p2, ring[j], ring[j + 1])) {
return true;
}
}
}
return false;
}
function lineStringWithinPolygon(line, polygon) {
for (var i = 0; i < line.length; ++i) {
if (!pointWithinPolygon(line[i], polygon)) {
return false;
}
}
for (var i$1 = 0; i$1 < line.length - 1; ++i$1) {
if (lineIntersectPolygon(line[i$1], line[i$1 + 1], polygon)) {
return false;
}
}
return true;
}
function lineStringWithinPolygons(line, polygons) {
for (var i = 0; i < polygons.length; i++) {
if (lineStringWithinPolygon(line, polygons[i])) {
return true;
}
}
return false;
}
function getTilePolygon(coordinates, bbox, canonical) {
var polygon = [];
for (var i = 0; i < coordinates.length; i++) {
var ring = [];
for (var j = 0; j < coordinates[i].length; j++) {
var coord = getTileCoordinates(coordinates[i][j], canonical);
updateBBox(bbox, coord);
ring.push(coord);
}
polygon.push(ring);
}
return polygon;
}
function getTilePolygons(coordinates, bbox, canonical) {
var polygons = [];
for (var i = 0; i < coordinates.length; i++) {
var polygon = getTilePolygon(coordinates[i], bbox, canonical);
polygons.push(polygon);
}
return polygons;
}
function updatePoint(p, bbox, polyBBox, worldSize) {
if (p[0] < polyBBox[0] || p[0] > polyBBox[2]) {
var halfWorldSize = worldSize * 0.5;
var shift = p[0] - polyBBox[0] > halfWorldSize ? -worldSize : polyBBox[0] - p[0] > halfWorldSize ? worldSize : 0;
if (shift === 0) {
shift = p[0] - polyBBox[2] > halfWorldSize ? -worldSize : polyBBox[2] - p[0] > halfWorldSize ? worldSize : 0;
}
p[0] += shift;
}
updateBBox(bbox, p);
}
function resetBBox(bbox) {
bbox[0] = bbox[1] = Infinity;
bbox[2] = bbox[3] = -Infinity;
}
function getTilePoints(geometry, pointBBox, polyBBox, canonical) {
var worldSize = Math.pow(2, canonical.z) * EXTENT;
var shifts = [
canonical.x * EXTENT,
canonical.y * EXTENT
];
var tilePoints = [];
for (var i$1 = 0, list$1 = geometry; i$1 < list$1.length; i$1 += 1) {
var points = list$1[i$1];
for (var i = 0, list = points; i < list.length; i += 1) {
var point = list[i];
var p = [
point.x + shifts[0],
point.y + shifts[1]
];
updatePoint(p, pointBBox, polyBBox, worldSize);
tilePoints.push(p);
}
}
return tilePoints;
}
function getTileLines(geometry, lineBBox, polyBBox, canonical) {
var worldSize = Math.pow(2, canonical.z) * EXTENT;
var shifts = [
canonical.x * EXTENT,
canonical.y * EXTENT
];
var tileLines = [];
for (var i$1 = 0, list$1 = geometry; i$1 < list$1.length; i$1 += 1) {
var line = list$1[i$1];
var tileLine = [];
for (var i = 0, list = line; i < list.length; i += 1) {
var point = list[i];
var p = [
point.x + shifts[0],
point.y + shifts[1]
];
updateBBox(lineBBox, p);
tileLine.push(p);
}
tileLines.push(tileLine);
}
if (lineBBox[2] - lineBBox[0] <= worldSize / 2) {
resetBBox(lineBBox);
for (var i$3 = 0, list$3 = tileLines; i$3 < list$3.length; i$3 += 1) {
var line$1 = list$3[i$3];
for (var i$2 = 0, list$2 = line$1; i$2 < list$2.length; i$2 += 1) {
var p$1 = list$2[i$2];
updatePoint(p$1, lineBBox, polyBBox, worldSize);
}
}
}
return tileLines;
}
function pointsWithinPolygons(ctx, polygonGeometry) {
var pointBBox = [
Infinity,
Infinity,
-Infinity,
-Infinity
];
var polyBBox = [
Infinity,
Infinity,
-Infinity,
-Infinity
];
var canonical = ctx.canonicalID();
if (polygonGeometry.type === 'Polygon') {
var tilePolygon = getTilePolygon(polygonGeometry.coordinates, polyBBox, canonical);
var tilePoints = getTilePoints(ctx.geometry(), pointBBox, polyBBox, canonical);
if (!boxWithinBox(pointBBox, polyBBox)) {
return false;
}
for (var i = 0, list = tilePoints; i < list.length; i += 1) {
var point = list[i];
if (!pointWithinPolygon(point, tilePolygon)) {
return false;
}
}
}
if (polygonGeometry.type === 'MultiPolygon') {
var tilePolygons = getTilePolygons(polygonGeometry.coordinates, polyBBox, canonical);
var tilePoints$1 = getTilePoints(ctx.geometry(), pointBBox, polyBBox, canonical);
if (!boxWithinBox(pointBBox, polyBBox)) {
return false;
}
for (var i$1 = 0, list$1 = tilePoints$1; i$1 < list$1.length; i$1 += 1) {
var point$1 = list$1[i$1];
if (!pointWithinPolygons(point$1, tilePolygons)) {
return false;
}
}
}
return true;
}
function linesWithinPolygons(ctx, polygonGeometry) {
var lineBBox = [
Infinity,
Infinity,
-Infinity,
-Infinity
];
var polyBBox = [
Infinity,
Infinity,
-Infinity,
-Infinity
];
var canonical = ctx.canonicalID();
if (polygonGeometry.type === 'Polygon') {
var tilePolygon = getTilePolygon(polygonGeometry.coordinates, polyBBox, canonical);
var tileLines = getTileLines(ctx.geometry(), lineBBox, polyBBox, canonical);
if (!boxWithinBox(lineBBox, polyBBox)) {
return false;
}
for (var i = 0, list = tileLines; i < list.length; i += 1) {
var line = list[i];
if (!lineStringWithinPolygon(line, tilePolygon)) {
return false;
}
}
}
if (polygonGeometry.type === 'MultiPolygon') {
var tilePolygons = getTilePolygons(polygonGeometry.coordinates, polyBBox, canonical);
var tileLines$1 = getTileLines(ctx.geometry(), lineBBox, polyBBox, canonical);
if (!boxWithinBox(lineBBox, polyBBox)) {
return false;
}
for (var i$1 = 0, list$1 = tileLines$1; i$1 < list$1.length; i$1 += 1) {
var line$1 = list$1[i$1];
if (!lineStringWithinPolygons(line$1, tilePolygons)) {
return false;
}
}
}
return true;
}
var Within = function Within(geojson, geometries) {
this.type = BooleanType;
this.geojson = geojson;
this.geometries = geometries;
};
Within.parse = function parse(args, context) {
if (args.length !== 2) {
return context.error('\'within\' expression requires exactly one argument, but found ' + (args.length - 1) + ' instead.');
}
if (isValue(args[1])) {
var geojson = args[1];
if (geojson.type === 'FeatureCollection') {
for (var i = 0; i < geojson.features.length; ++i) {
var type = geojson.features[i].geometry.type;
if (type === 'Polygon' || type === 'MultiPolygon') {
return new Within(geojson, geojson.features[i].geometry);
}
}
} else if (geojson.type === 'Feature') {
var type$1 = geojson.geometry.type;
if (type$1 === 'Polygon' || type$1 === 'MultiPolygon') {
return new Within(geojson, geojson.geometry);
}
} else if (geojson.type === 'Polygon' || geojson.type === 'MultiPolygon') {
return new Within(geojson, geojson);
}
}
return context.error('\'within\' expression requires valid geojson object that contains polygon geometry type.');
};
Within.prototype.evaluate = function evaluate(ctx) {
if (ctx.geometry() != null && ctx.canonicalID() != null) {
if (ctx.geometryType() === 'Point') {
return pointsWithinPolygons(ctx, this.geometries);
} else if (ctx.geometryType() === 'LineString') {
return linesWithinPolygons(ctx, this.geometries);
}
}
return false;
};
Within.prototype.eachChild = function eachChild() {
};
Within.prototype.outputDefined = function outputDefined() {
return true;
};
Within.prototype.serialize = function serialize() {
return [
'within',
this.geojson
];
};
function isFeatureConstant(e) {
if (e instanceof CompoundExpression) {
if (e.name === 'get' && e.args.length === 1) {
return false;
} else if (e.name === 'feature-state') {
return false;
} else if (e.name === 'has' && e.args.length === 1) {
return false;
} else if (e.name === 'properties' || e.name === 'geometry-type' || e.name === 'id') {
return false;
} else if (/^filter-/.test(e.name)) {
return false;
}
}
if (e instanceof Within) {
return false;
}
var result = true;
e.eachChild(function (arg) {
if (result && !isFeatureConstant(arg)) {
result = false;
}
});
return result;
}
function isStateConstant(e) {
if (e instanceof CompoundExpression) {
if (e.name === 'feature-state') {
return false;
}
}
var result = true;
e.eachChild(function (arg) {
if (result && !isStateConstant(arg)) {
result = false;
}
});
return result;
}
function isGlobalPropertyConstant(e, properties) {
if (e instanceof CompoundExpression && properties.indexOf(e.name) >= 0) {
return false;
}
var result = true;
e.eachChild(function (arg) {
if (result && !isGlobalPropertyConstant(arg, properties)) {
result = false;
}
});
return result;
}
var Var = function Var(name, boundExpression) {
this.type = boundExpression.type;
this.name = name;
this.boundExpression = boundExpression;
};
Var.parse = function parse(args, context) {
if (args.length !== 2 || typeof args[1] !== 'string') {
return context.error('\'var\' expression requires exactly one string literal argument.');
}
var name = args[1];
if (!context.scope.has(name)) {
return context.error('Unknown variable "' + name + '". Make sure "' + name + '" has been bound in an enclosing "let" expression before using it.', 1);
}
return new Var(name, context.scope.get(name));
};
Var.prototype.evaluate = function evaluate(ctx) {
return this.boundExpression.evaluate(ctx);
};
Var.prototype.eachChild = function eachChild() {
};
Var.prototype.outputDefined = function outputDefined() {
return false;
};
Var.prototype.serialize = function serialize() {
return [
'var',
this.name
];
};
var ParsingContext = function ParsingContext(registry, path, expectedType, scope, errors) {
if (path === void 0)
path = [];
if (scope === void 0)
scope = new Scope();
if (errors === void 0)
errors = [];
this.registry = registry;
this.path = path;
this.key = path.map(function (part) {
return '[' + part + ']';
}).join('');
this.scope = scope;
this.errors = errors;
this.expectedType = expectedType;
};
ParsingContext.prototype.parse = function parse(expr, index, expectedType, bindings, options) {
if (options === void 0)
options = {};
if (index) {
return this.concat(index, expectedType, bindings)._parse(expr, options);
}
return this._parse(expr, options);
};
ParsingContext.prototype._parse = function _parse(expr, options) {
if (expr === null || typeof expr === 'string' || typeof expr === 'boolean' || typeof expr === 'number') {
expr = [
'literal',
expr
];
}
function annotate(parsed, type, typeAnnotation) {
if (typeAnnotation === 'assert') {
return new Assertion(type, [parsed]);
} else if (typeAnnotation === 'coerce') {
return new Coercion(type, [parsed]);
} else {
return parsed;
}
}
if (Array.isArray(expr)) {
if (expr.length === 0) {
return this.error('Expected an array with at least one element. If you wanted a literal array, use ["literal", []].');
}
var op = expr[0];
if (typeof op !== 'string') {
this.error('Expression name must be a string, but found ' + typeof op + ' instead. If you wanted a literal array, use ["literal", [...]].', 0);
return null;
}
var Expr = this.registry[op];
if (Expr) {
var parsed = Expr.parse(expr, this);
if (!parsed) {
return null;
}
if (this.expectedType) {
var expected = this.expectedType;
var actual = parsed.type;
if ((expected.kind === 'string' || expected.kind === 'number' || expected.kind === 'boolean' || expected.kind === 'object' || expected.kind === 'array') && actual.kind === 'value') {
parsed = annotate(parsed, expected, options.typeAnnotation || 'assert');
} else if ((expected.kind === 'color' || expected.kind === 'formatted' || expected.kind === 'resolvedImage') && (actual.kind === 'value' || actual.kind === 'string')) {
parsed = annotate(parsed, expected, options.typeAnnotation || 'coerce');
} else if (this.checkSubtype(expected, actual)) {
return null;
}
}
if (!(parsed instanceof Literal) && parsed.type.kind !== 'resolvedImage' && isConstant(parsed)) {
var ec = new EvaluationContext();
try {
parsed = new Literal(parsed.type, parsed.evaluate(ec));
} catch (e) {
this.error(e.message);
return null;
}
}
return parsed;
}
return this.error('Unknown expression "' + op + '". If you wanted a literal array, use ["literal", [...]].', 0);
} else if (typeof expr === 'undefined') {
return this.error('\'undefined\' value invalid. Use null instead.');
} else if (typeof expr === 'object') {
return this.error('Bare objects invalid. Use ["literal", {...}] instead.');
} else {
return this.error('Expected an array, but found ' + typeof expr + ' instead.');
}
};
ParsingContext.prototype.concat = function concat(index, expectedType, bindings) {
var path = typeof index === 'number' ? this.path.concat(index) : this.path;
var scope = bindings ? this.scope.concat(bindings) : this.scope;
return new ParsingContext(this.registry, path, expectedType || null, scope, this.errors);
};
ParsingContext.prototype.error = function error(error$1) {
var keys = [], len = arguments.length - 1;
while (len-- > 0)
keys[len] = arguments[len + 1];
var key = '' + this.key + keys.map(function (k) {
return '[' + k + ']';
}).join('');
this.errors.push(new ParsingError(key, error$1));
};
ParsingContext.prototype.checkSubtype = function checkSubtype$1(expected, t) {
var error = checkSubtype(expected, t);
if (error) {
this.error(error);
}
return error;
};
function isConstant(expression) {
if (expression instanceof Var) {
return isConstant(expression.boundExpression);
} else if (expression instanceof CompoundExpression && expression.name === 'error') {
return false;
} else if (expression instanceof CollatorExpression) {
return false;
} else if (expression instanceof Within) {
return false;
}
var isTypeAnnotation = expression instanceof Coercion || expression instanceof Assertion;
var childrenConstant = true;
expression.eachChild(function (child) {
if (isTypeAnnotation) {
childrenConstant = childrenConstant && isConstant(child);
} else {
childrenConstant = childrenConstant && child instanceof Literal;
}
});
if (!childrenConstant) {
return false;
}
return isFeatureConstant(expression) && isGlobalPropertyConstant(expression, [
'zoom',
'heatmap-density',
'line-progress',
'accumulated',
'is-supported-script'
]);
}
function findStopLessThanOrEqualTo(stops, input) {
var lastIndex = stops.length - 1;
var lowerIndex = 0;
var upperIndex = lastIndex;
var currentIndex = 0;
var currentValue, nextValue;
while (lowerIndex <= upperIndex) {
currentIndex = Math.floor((lowerIndex + upperIndex) / 2);
currentValue = stops[currentIndex];
nextValue = stops[currentIndex + 1];
if (currentValue <= input) {
if (currentIndex === lastIndex || input < nextValue) {
return currentIndex;
}
lowerIndex = currentIndex + 1;
} else if (currentValue > input) {
upperIndex = currentIndex - 1;
} else {
throw new RuntimeError('Input is not a number.');
}
}
return 0;
}
var Step = function Step(type, input, stops) {
this.type = type;
this.input = input;
this.labels = [];
this.outputs = [];
for (var i = 0, list = stops; i < list.length; i += 1) {
var ref = list[i];
var label = ref[0];
var expression = ref[1];
this.labels.push(label);
this.outputs.push(expression);
}
};
Step.parse = function parse(args, context) {
if (args.length - 1 < 4) {
return context.error('Expected at least 4 arguments, but found only ' + (args.length - 1) + '.');
}
if ((args.length - 1) % 2 !== 0) {
return context.error('Expected an even number of arguments.');
}
var input = context.parse(args[1], 1, NumberType);
if (!input) {
return null;
}
var stops = [];
var outputType = null;
if (context.expectedType && context.expectedType.kind !== 'value') {
outputType = context.expectedType;
}
for (var i = 1; i < args.length; i += 2) {
var label = i === 1 ? -Infinity : args[i];
var value = args[i + 1];
var labelKey = i;
var valueKey = i + 1;
if (typeof label !== 'number') {
return context.error('Input/output pairs for "step" expressions must be defined using literal numeric values (not computed expressions) for the input values.', labelKey);
}
if (stops.length && stops[stops.length - 1][0] >= label) {
return context.error('Input/output pairs for "step" expressions must be arranged with input values in strictly ascending order.', labelKey);
}
var parsed = context.parse(value, valueKey, outputType);
if (!parsed) {
return null;
}
outputType = outputType || parsed.type;
stops.push([
label,
parsed
]);
}
return new Step(outputType, input, stops);
};
Step.prototype.evaluate = function evaluate(ctx) {
var labels = this.labels;
var outputs = this.outputs;
if (labels.length === 1) {
return outputs[0].evaluate(ctx);
}
var value = this.input.evaluate(ctx);
if (value <= labels[0]) {
return outputs[0].evaluate(ctx);
}
var stopCount = labels.length;
if (value >= labels[stopCount - 1]) {
return outputs[stopCount - 1].evaluate(ctx);
}
var index = findStopLessThanOrEqualTo(labels, value);
return outputs[index].evaluate(ctx);
};
Step.prototype.eachChild = function eachChild(fn) {
fn(this.input);
for (var i = 0, list = this.outputs; i < list.length; i += 1) {
var expression = list[i];
fn(expression);
}
};
Step.prototype.outputDefined = function outputDefined() {
return this.outputs.every(function (out) {
return out.outputDefined();
});
};
Step.prototype.serialize = function serialize() {
var serialized = [
'step',
this.input.serialize()
];
for (var i = 0; i < this.labels.length; i++) {
if (i > 0) {
serialized.push(this.labels[i]);
}
serialized.push(this.outputs[i].serialize());
}
return serialized;
};
function number(a, b, t) {
return a * (1 - t) + b * t;
}
function color(from, to, t) {
return new Color(number(from.r, to.r, t), number(from.g, to.g, t), number(from.b, to.b, t), number(from.a, to.a, t));
}
function array$1(from, to, t) {
return from.map(function (d, i) {
return number(d, to[i], t);
});
}
var interpolate = /*#__PURE__*/Object.freeze({
__proto__: null,
number: number,
color: color,
array: array$1
});
var Xn = 0.95047, Yn = 1, Zn = 1.08883, t0 = 4 / 29, t1 = 6 / 29, t2 = 3 * t1 * t1, t3 = t1 * t1 * t1, deg2rad = Math.PI / 180, rad2deg = 180 / Math.PI;
function xyz2lab(t) {
return t > t3 ? Math.pow(t, 1 / 3) : t / t2 + t0;
}
function lab2xyz(t) {
return t > t1 ? t * t * t : t2 * (t - t0);
}
function xyz2rgb(x) {
return 255 * (x <= 0.0031308 ? 12.92 * x : 1.055 * Math.pow(x, 1 / 2.4) - 0.055);
}
function rgb2xyz(x) {
x /= 255;
return x <= 0.04045 ? x / 12.92 : Math.pow((x + 0.055) / 1.055, 2.4);
}
function rgbToLab(rgbColor) {
var b = rgb2xyz(rgbColor.r), a = rgb2xyz(rgbColor.g), l = rgb2xyz(rgbColor.b), x = xyz2lab((0.4124564 * b + 0.3575761 * a + 0.1804375 * l) / Xn), y = xyz2lab((0.2126729 * b + 0.7151522 * a + 0.072175 * l) / Yn), z = xyz2lab((0.0193339 * b + 0.119192 * a + 0.9503041 * l) / Zn);
return {
l: 116 * y - 16,
a: 500 * (x - y),
b: 200 * (y - z),
alpha: rgbColor.a
};
}
function labToRgb(labColor) {
var y = (labColor.l + 16) / 116, x = isNaN(labColor.a) ? y : y + labColor.a / 500, z = isNaN(labColor.b) ? y : y - labColor.b / 200;
y = Yn * lab2xyz(y);
x = Xn * lab2xyz(x);
z = Zn * lab2xyz(z);
return new Color(xyz2rgb(3.2404542 * x - 1.5371385 * y - 0.4985314 * z), xyz2rgb(-0.969266 * x + 1.8760108 * y + 0.041556 * z), xyz2rgb(0.0556434 * x - 0.2040259 * y + 1.0572252 * z), labColor.alpha);
}
function interpolateLab(from, to, t) {
return {
l: number(from.l, to.l, t),
a: number(from.a, to.a, t),
b: number(from.b, to.b, t),
alpha: number(from.alpha, to.alpha, t)
};
}
function rgbToHcl(rgbColor) {
var ref = rgbToLab(rgbColor);
var l = ref.l;
var a = ref.a;
var b = ref.b;
var h = Math.atan2(b, a) * rad2deg;
return {
h: h < 0 ? h + 360 : h,
c: Math.sqrt(a * a + b * b),
l: l,
alpha: rgbColor.a
};
}
function hclToRgb(hclColor) {
var h = hclColor.h * deg2rad, c = hclColor.c, l = hclColor.l;
return labToRgb({
l: l,
a: Math.cos(h) * c,
b: Math.sin(h) * c,
alpha: hclColor.alpha
});
}
function interpolateHue(a, b, t) {
var d = b - a;
return a + t * (d > 180 || d < -180 ? d - 360 * Math.round(d / 360) : d);
}
function interpolateHcl(from, to, t) {
return {
h: interpolateHue(from.h, to.h, t),
c: number(from.c, to.c, t),
l: number(from.l, to.l, t),
alpha: number(from.alpha, to.alpha, t)
};
}
var lab = {
forward: rgbToLab,
reverse: labToRgb,
interpolate: interpolateLab
};
var hcl = {
forward: rgbToHcl,
reverse: hclToRgb,
interpolate: interpolateHcl
};
var colorSpaces = /*#__PURE__*/Object.freeze({
__proto__: null,
lab: lab,
hcl: hcl
});
var Interpolate = function Interpolate(type, operator, interpolation, input, stops) {
this.type = type;
this.operator = operator;
this.interpolation = interpolation;
this.input = input;
this.labels = [];
this.outputs = [];
for (var i = 0, list = stops; i < list.length; i += 1) {
var ref = list[i];
var label = ref[0];
var expression = ref[1];
this.labels.push(label);
this.outputs.push(expression);
}
};
Interpolate.interpolationFactor = function interpolationFactor(interpolation, input, lower, upper) {
var t = 0;
if (interpolation.name === 'exponential') {
t = exponentialInterpolation(input, interpolation.base, lower, upper);
} else if (interpolation.name === 'linear') {
t = exponentialInterpolation(input, 1, lower, upper);
} else if (interpolation.name === 'cubic-bezier') {
var c = interpolation.controlPoints;
var ub = new unitbezier(c[0], c[1], c[2], c[3]);
t = ub.solve(exponentialInterpolation(input, 1, lower, upper));
}
return t;
};
Interpolate.parse = function parse(args, context) {
var operator = args[0];
var interpolation = args[1];
var input = args[2];
var rest = args.slice(3);
if (!Array.isArray(interpolation) || interpolation.length === 0) {
return context.error('Expected an interpolation type expression.', 1);
}
if (interpolation[0] === 'linear') {
interpolation = { name: 'linear' };
} else if (interpolation[0] === 'exponential') {
var base = interpolation[1];
if (typeof base !== 'number') {
return context.error('Exponential interpolation requires a numeric base.', 1, 1);
}
interpolation = {
name: 'exponential',
base: base
};
} else if (interpolation[0] === 'cubic-bezier') {
var controlPoints = interpolation.slice(1);
if (controlPoints.length !== 4 || controlPoints.some(function (t) {
return typeof t !== 'number' || t < 0 || t > 1;
})) {
return context.error('Cubic bezier interpolation requires four numeric arguments with values between 0 and 1.', 1);
}
interpolation = {
name: 'cubic-bezier',
controlPoints: controlPoints
};
} else {
return context.error('Unknown interpolation type ' + String(interpolation[0]), 1, 0);
}
if (args.length - 1 < 4) {
return context.error('Expected at least 4 arguments, but found only ' + (args.length - 1) + '.');
}
if ((args.length - 1) % 2 !== 0) {
return context.error('Expected an even number of arguments.');
}
input = context.parse(input, 2, NumberType);
if (!input) {
return null;
}
var stops = [];
var outputType = null;
if (operator === 'interpolate-hcl' || operator === 'interpolate-lab') {
outputType = ColorType;
} else if (context.expectedType && context.expectedType.kind !== 'value') {
outputType = context.expectedType;
}
for (var i = 0; i < rest.length; i += 2) {
var label = rest[i];
var value = rest[i + 1];
var labelKey = i + 3;
var valueKey = i + 4;
if (typeof label !== 'number') {
return context.error('Input/output pairs for "interpolate" expressions must be defined using literal numeric values (not computed expressions) for the input values.', labelKey);
}
if (stops.length && stops[stops.length - 1][0] >= label) {
return context.error('Input/output pairs for "interpolate" expressions must be arranged with input values in strictly ascending order.', labelKey);
}
var parsed = context.parse(value, valueKey, outputType);
if (!parsed) {
return null;
}
outputType = outputType || parsed.type;
stops.push([
label,
parsed
]);
}
if (outputType.kind !== 'number' && outputType.kind !== 'color' && !(outputType.kind === 'array' && outputType.itemType.kind === 'number' && typeof outputType.N === 'number')) {
return context.error('Type ' + toString(outputType) + ' is not interpolatable.');
}
return new Interpolate(outputType, operator, interpolation, input, stops);
};
Interpolate.prototype.evaluate = function evaluate(ctx) {
var labels = this.labels;
var outputs = this.outputs;
if (labels.length === 1) {
return outputs[0].evaluate(ctx);
}
var value = this.input.evaluate(ctx);
if (value <= labels[0]) {
return outputs[0].evaluate(ctx);
}
var stopCount = labels.length;
if (value >= labels[stopCount - 1]) {
return outputs[stopCount - 1].evaluate(ctx);
}
var index = findStopLessThanOrEqualTo(labels, value);
var lower = labels[index];
var upper = labels[index + 1];
var t = Interpolate.interpolationFactor(this.interpolation, value, lower, upper);
var outputLower = outputs[index].evaluate(ctx);
var outputUpper = outputs[index + 1].evaluate(ctx);
if (this.operator === 'interpolate') {
return interpolate[this.type.kind.toLowerCase()](outputLower, outputUpper, t);
} else if (this.operator === 'interpolate-hcl') {
return hcl.reverse(hcl.interpolate(hcl.forward(outputLower), hcl.forward(outputUpper), t));
} else {
return lab.reverse(lab.interpolate(lab.forward(outputLower), lab.forward(outputUpper), t));
}
};
Interpolate.prototype.eachChild = function eachChild(fn) {
fn(this.input);
for (var i = 0, list = this.outputs; i < list.length; i += 1) {
var expression = list[i];
fn(expression);
}
};
Interpolate.prototype.outputDefined = function outputDefined() {
return this.outputs.every(function (out) {
return out.outputDefined();
});
};
Interpolate.prototype.serialize = function serialize() {
var interpolation;
if (this.interpolation.name === 'linear') {
interpolation = ['linear'];
} else if (this.interpolation.name === 'exponential') {
if (this.interpolation.base === 1) {
interpolation = ['linear'];
} else {
interpolation = [
'exponential',
this.interpolation.base
];
}
} else {
interpolation = ['cubic-bezier'].concat(this.interpolation.controlPoints);
}
var serialized = [
this.operator,
interpolation,
this.input.serialize()
];
for (var i = 0; i < this.labels.length; i++) {
serialized.push(this.labels[i], this.outputs[i].serialize());
}
return serialized;
};
function exponentialInterpolation(input, base, lowerValue, upperValue) {
var difference = upperValue - lowerValue;
var progress = input - lowerValue;
if (difference === 0) {
return 0;
} else if (base === 1) {
return progress / difference;
} else {
return (Math.pow(base, progress) - 1) / (Math.pow(base, difference) - 1);
}
}
var Coalesce = function Coalesce(type, args) {
this.type = type;
this.args = args;
};
Coalesce.parse = function parse(args, context) {
if (args.length < 2) {
return context.error('Expectected at least one argument.');
}
var outputType = null;
var expectedType = context.expectedType;
if (expectedType && expectedType.kind !== 'value') {
outputType = expectedType;
}
var parsedArgs = [];
for (var i = 0, list = args.slice(1); i < list.length; i += 1) {
var arg = list[i];
var parsed = context.parse(arg, 1 + parsedArgs.length, outputType, undefined, { typeAnnotation: 'omit' });
if (!parsed) {
return null;
}
outputType = outputType || parsed.type;
parsedArgs.push(parsed);
}
var needsAnnotation = expectedType && parsedArgs.some(function (arg) {
return checkSubtype(expectedType, arg.type);
});
return needsAnnotation ? new Coalesce(ValueType, parsedArgs) : new Coalesce(outputType, parsedArgs);
};
Coalesce.prototype.evaluate = function evaluate(ctx) {
var result = null;
var argCount = 0;
var requestedImageName;
for (var i = 0, list = this.args; i < list.length; i += 1) {
var arg = list[i];
argCount++;
result = arg.evaluate(ctx);
if (result && result instanceof ResolvedImage && !result.available) {
if (!requestedImageName) {
requestedImageName = result.name;
}
result = null;
if (argCount === this.args.length) {
result = requestedImageName;
}
}
if (result !== null) {
break;
}
}
return result;
};
Coalesce.prototype.eachChild = function eachChild(fn) {
this.args.forEach(fn);
};
Coalesce.prototype.outputDefined = function outputDefined() {
return this.args.every(function (arg) {
return arg.outputDefined();
});
};
Coalesce.prototype.serialize = function serialize() {
var serialized = ['coalesce'];
this.eachChild(function (child) {
serialized.push(child.serialize());
});
return serialized;
};
var Let = function Let(bindings, result) {
this.type = result.type;
this.bindings = [].concat(bindings);
this.result = result;
};
Let.prototype.evaluate = function evaluate(ctx) {
return this.result.evaluate(ctx);
};
Let.prototype.eachChild = function eachChild(fn) {
for (var i = 0, list = this.bindings; i < list.length; i += 1) {
var binding = list[i];
fn(binding[1]);
}
fn(this.result);
};
Let.parse = function parse(args, context) {
if (args.length < 4) {
return context.error('Expected at least 3 arguments, but found ' + (args.length - 1) + ' instead.');
}
var bindings = [];
for (var i = 1; i < args.length - 1; i += 2) {
var name = args[i];
if (typeof name !== 'string') {
return context.error('Expected string, but found ' + typeof name + ' instead.', i);
}
if (/[^a-zA-Z0-9_]/.test(name)) {
return context.error('Variable names must contain only alphanumeric characters or \'_\'.', i);
}
var value = context.parse(args[i + 1], i + 1);
if (!value) {
return null;
}
bindings.push([
name,
value
]);
}
var result = context.parse(args[args.length - 1], args.length - 1, context.expectedType, bindings);
if (!result) {
return null;
}
return new Let(bindings, result);
};
Let.prototype.outputDefined = function outputDefined() {
return this.result.outputDefined();
};
Let.prototype.serialize = function serialize() {
var serialized = ['let'];
for (var i = 0, list = this.bindings; i < list.length; i += 1) {
var ref = list[i];
var name = ref[0];
var expr = ref[1];
serialized.push(name, expr.serialize());
}
serialized.push(this.result.serialize());
return serialized;
};
var At = function At(type, index, input) {
this.type = type;
this.index = index;
this.input = input;
};
At.parse = function parse(args, context) {
if (args.length !== 3) {
return context.error('Expected 2 arguments, but found ' + (args.length - 1) + ' instead.');
}
var index = context.parse(args[1], 1, NumberType);
var input = context.parse(args[2], 2, array(context.expectedType || ValueType));
if (!index || !input) {
return null;
}
var t = input.type;
return new At(t.itemType, index, input);
};
At.prototype.evaluate = function evaluate(ctx) {
var index = this.index.evaluate(ctx);
var array = this.input.evaluate(ctx);
if (index < 0) {
throw new RuntimeError('Array index out of bounds: ' + index + ' < 0.');
}
if (index >= array.length) {
throw new RuntimeError('Array index out of bounds: ' + index + ' > ' + (array.length - 1) + '.');
}
if (index !== Math.floor(index)) {
throw new RuntimeError('Array index must be an integer, but found ' + index + ' instead.');
}
return array[index];
};
At.prototype.eachChild = function eachChild(fn) {
fn(this.index);
fn(this.input);
};
At.prototype.outputDefined = function outputDefined() {
return false;
};
At.prototype.serialize = function serialize() {
return [
'at',
this.index.serialize(),
this.input.serialize()
];
};
var In = function In(needle, haystack) {
this.type = BooleanType;
this.needle = needle;
this.haystack = haystack;
};
In.parse = function parse(args, context) {
if (args.length !== 3) {
return context.error('Expected 2 arguments, but found ' + (args.length - 1) + ' instead.');
}
var needle = context.parse(args[1], 1, ValueType);
var haystack = context.parse(args[2], 2, ValueType);
if (!needle || !haystack) {
return null;
}
if (!isValidType(needle.type, [
BooleanType,
StringType,
NumberType,
NullType,
ValueType
])) {
return context.error('Expected first argument to be of type boolean, string, number or null, but found ' + toString(needle.type) + ' instead');
}
return new In(needle, haystack);
};
In.prototype.evaluate = function evaluate(ctx) {
var needle = this.needle.evaluate(ctx);
var haystack = this.haystack.evaluate(ctx);
if (!haystack) {
return false;
}
if (!isValidNativeType(needle, [
'boolean',
'string',
'number',
'null'
])) {
throw new RuntimeError('Expected first argument to be of type boolean, string, number or null, but found ' + toString(typeOf(needle)) + ' instead.');
}
if (!isValidNativeType(haystack, [
'string',
'array'
])) {
throw new RuntimeError('Expected second argument to be of type array or string, but found ' + toString(typeOf(haystack)) + ' instead.');
}
return haystack.indexOf(needle) >= 0;
};
In.prototype.eachChild = function eachChild(fn) {
fn(this.needle);
fn(this.haystack);
};
In.prototype.outputDefined = function outputDefined() {
return true;
};
In.prototype.serialize = function serialize() {
return [
'in',
this.needle.serialize(),
this.haystack.serialize()
];
};
var IndexOf = function IndexOf(needle, haystack, fromIndex) {
this.type = NumberType;
this.needle = needle;
this.haystack = haystack;
this.fromIndex = fromIndex;
};
IndexOf.parse = function parse(args, context) {
if (args.length <= 2 || args.length >= 5) {
return context.error('Expected 3 or 4 arguments, but found ' + (args.length - 1) + ' instead.');
}
var needle = context.parse(args[1], 1, ValueType);
var haystack = context.parse(args[2], 2, ValueType);
if (!needle || !haystack) {
return null;
}
if (!isValidType(needle.type, [
BooleanType,
StringType,
NumberType,
NullType,
ValueType
])) {
return context.error('Expected first argument to be of type boolean, string, number or null, but found ' + toString(needle.type) + ' instead');
}
if (args.length === 4) {
var fromIndex = context.parse(args[3], 3, NumberType);
if (!fromIndex) {
return null;
}
return new IndexOf(needle, haystack, fromIndex);
} else {
return new IndexOf(needle, haystack);
}
};
IndexOf.prototype.evaluate = function evaluate(ctx) {
var needle = this.needle.evaluate(ctx);
var haystack = this.haystack.evaluate(ctx);
if (!isValidNativeType(needle, [
'boolean',
'string',
'number',
'null'
])) {
throw new RuntimeError('Expected first argument to be of type boolean, string, number or null, but found ' + toString(typeOf(needle)) + ' instead.');
}
if (!isValidNativeType(haystack, [
'string',
'array'
])) {
throw new RuntimeError('Expected second argument to be of type array or string, but found ' + toString(typeOf(haystack)) + ' instead.');
}
if (this.fromIndex) {
var fromIndex = this.fromIndex.evaluate(ctx);
return haystack.indexOf(needle, fromIndex);
}
return haystack.indexOf(needle);
};
IndexOf.prototype.eachChild = function eachChild(fn) {
fn(this.needle);
fn(this.haystack);
if (this.fromIndex) {
fn(this.fromIndex);
}
};
IndexOf.prototype.outputDefined = function outputDefined() {
return false;
};
IndexOf.prototype.serialize = function serialize() {
if (this.fromIndex != null && this.fromIndex !== undefined) {
var fromIndex = this.fromIndex.serialize();
return [
'index-of',
this.needle.serialize(),
this.haystack.serialize(),
fromIndex
];
}
return [
'index-of',
this.needle.serialize(),
this.haystack.serialize()
];
};
var Match = function Match(inputType, outputType, input, cases, outputs, otherwise) {
this.inputType = inputType;
this.type = outputType;
this.input = input;
this.cases = cases;
this.outputs = outputs;
this.otherwise = otherwise;
};
Match.parse = function parse(args, context) {
if (args.length < 5) {
return context.error('Expected at least 4 arguments, but found only ' + (args.length - 1) + '.');
}
if (args.length % 2 !== 1) {
return context.error('Expected an even number of arguments.');
}
var inputType;
var outputType;
if (context.expectedType && context.expectedType.kind !== 'value') {
outputType = context.expectedType;
}
var cases = {};
var outputs = [];
for (var i = 2; i < args.length - 1; i += 2) {
var labels = args[i];
var value = args[i + 1];
if (!Array.isArray(labels)) {
labels = [labels];
}
var labelContext = context.concat(i);
if (labels.length === 0) {
return labelContext.error('Expected at least one branch label.');
}
for (var i$1 = 0, list = labels; i$1 < list.length; i$1 += 1) {
var label = list[i$1];
if (typeof label !== 'number' && typeof label !== 'string') {
return labelContext.error('Branch labels must be numbers or strings.');
} else if (typeof label === 'number' && Math.abs(label) > Number.MAX_SAFE_INTEGER) {
return labelContext.error('Branch labels must be integers no larger than ' + Number.MAX_SAFE_INTEGER + '.');
} else if (typeof label === 'number' && Math.floor(label) !== label) {
return labelContext.error('Numeric branch labels must be integer values.');
} else if (!inputType) {
inputType = typeOf(label);
} else if (labelContext.checkSubtype(inputType, typeOf(label))) {
return null;
}
if (typeof cases[String(label)] !== 'undefined') {
return labelContext.error('Branch labels must be unique.');
}
cases[String(label)] = outputs.length;
}
var result = context.parse(value, i, outputType);
if (!result) {
return null;
}
outputType = outputType || result.type;
outputs.push(result);
}
var input = context.parse(args[1], 1, ValueType);
if (!input) {
return null;
}
var otherwise = context.parse(args[args.length - 1], args.length - 1, outputType);
if (!otherwise) {
return null;
}
if (input.type.kind !== 'value' && context.concat(1).checkSubtype(inputType, input.type)) {
return null;
}
return new Match(inputType, outputType, input, cases, outputs, otherwise);
};
Match.prototype.evaluate = function evaluate(ctx) {
var input = this.input.evaluate(ctx);
var output = typeOf(input) === this.inputType && this.outputs[this.cases[input]] || this.otherwise;
return output.evaluate(ctx);
};
Match.prototype.eachChild = function eachChild(fn) {
fn(this.input);
this.outputs.forEach(fn);
fn(this.otherwise);
};
Match.prototype.outputDefined = function outputDefined() {
return this.outputs.every(function (out) {
return out.outputDefined();
}) && this.otherwise.outputDefined();
};
Match.prototype.serialize = function serialize() {
var this$1 = this;
var serialized = [
'match',
this.input.serialize()
];
var sortedLabels = Object.keys(this.cases).sort();
var groupedByOutput = [];
var outputLookup = {};
for (var i = 0, list = sortedLabels; i < list.length; i += 1) {
var label = list[i];
var outputIndex = outputLookup[this.cases[label]];
if (outputIndex === undefined) {
outputLookup[this.cases[label]] = groupedByOutput.length;
groupedByOutput.push([
this.cases[label],
[label]
]);
} else {
groupedByOutput[outputIndex][1].push(label);
}
}
var coerceLabel = function (label) {
return this$1.inputType.kind === 'number' ? Number(label) : label;
};
for (var i$1 = 0, list$1 = groupedByOutput; i$1 < list$1.length; i$1 += 1) {
var ref = list$1[i$1];
var outputIndex = ref[0];
var labels = ref[1];
if (labels.length === 1) {
serialized.push(coerceLabel(labels[0]));
} else {
serialized.push(labels.map(coerceLabel));
}
serialized.push(this.outputs[outputIndex$1].serialize());
}
serialized.push(this.otherwise.serialize());
return serialized;
};
var Case = function Case(type, branches, otherwise) {
this.type = type;
this.branches = branches;
this.otherwise = otherwise;
};
Case.parse = function parse(args, context) {
if (args.length < 4) {
return context.error('Expected at least 3 arguments, but found only ' + (args.length - 1) + '.');
}
if (args.length % 2 !== 0) {
return context.error('Expected an odd number of arguments.');
}
var outputType;
if (context.expectedType && context.expectedType.kind !== 'value') {
outputType = context.expectedType;
}
var branches = [];
for (var i = 1; i < args.length - 1; i += 2) {
var test = context.parse(args[i], i, BooleanType);
if (!test) {
return null;
}
var result = context.parse(args[i + 1], i + 1, outputType);
if (!result) {
return null;
}
branches.push([
test,
result
]);
outputType = outputType || result.type;
}
var otherwise = context.parse(args[args.length - 1], args.length - 1, outputType);
if (!otherwise) {
return null;
}
return new Case(outputType, branches, otherwise);
};
Case.prototype.evaluate = function evaluate(ctx) {
for (var i = 0, list = this.branches; i < list.length; i += 1) {
var ref = list[i];
var test = ref[0];
var expression = ref[1];
if (test.evaluate(ctx)) {
return expression.evaluate(ctx);
}
}
return this.otherwise.evaluate(ctx);
};
Case.prototype.eachChild = function eachChild(fn) {
for (var i = 0, list = this.branches; i < list.length; i += 1) {
var ref = list[i];
var test = ref[0];
var expression = ref[1];
fn(test);
fn(expression);
}
fn(this.otherwise);
};
Case.prototype.outputDefined = function outputDefined() {
return this.branches.every(function (ref) {
var _ = ref[0];
var out = ref[1];
return out.outputDefined();
}) && this.otherwise.outputDefined();
};
Case.prototype.serialize = function serialize() {
var serialized = ['case'];
this.eachChild(function (child) {
serialized.push(child.serialize());
});
return serialized;
};
var Slice = function Slice(type, input, beginIndex, endIndex) {
this.type = type;
this.input = input;
this.beginIndex = beginIndex;
this.endIndex = endIndex;
};
Slice.parse = function parse(args, context) {
if (args.length <= 2 || args.length >= 5) {
return context.error('Expected 3 or 4 arguments, but found ' + (args.length - 1) + ' instead.');
}
var input = context.parse(args[1], 1, ValueType);
var beginIndex = context.parse(args[2], 2, NumberType);
if (!input || !beginIndex) {
return null;
}
if (!isValidType(input.type, [
array(ValueType),
StringType,
ValueType
])) {
return context.error('Expected first argument to be of type array or string, but found ' + toString(input.type) + ' instead');
}
if (args.length === 4) {
var endIndex = context.parse(args[3], 3, NumberType);
if (!endIndex) {
return null;
}
return new Slice(input.type, input, beginIndex, endIndex);
} else {
return new Slice(input.type, input, beginIndex);
}
};
Slice.prototype.evaluate = function evaluate(ctx) {
var input = this.input.evaluate(ctx);
var beginIndex = this.beginIndex.evaluate(ctx);
if (!isValidNativeType(input, [
'string',
'array'
])) {
throw new RuntimeError('Expected first argument to be of type array or string, but found ' + toString(typeOf(input)) + ' instead.');
}
if (this.endIndex) {
var endIndex = this.endIndex.evaluate(ctx);
return input.slice(beginIndex, endIndex);
}
return input.slice(beginIndex);
};
Slice.prototype.eachChild = function eachChild(fn) {
fn(this.input);
fn(this.beginIndex);
if (this.endIndex) {
fn(this.endIndex);
}
};
Slice.prototype.outputDefined = function outputDefined() {
return false;
};
Slice.prototype.serialize = function serialize() {
if (this.endIndex != null && this.endIndex !== undefined) {
var endIndex = this.endIndex.serialize();
return [
'slice',
this.input.serialize(),
this.beginIndex.serialize(),
endIndex
];
}
return [
'slice',
this.input.serialize(),
this.beginIndex.serialize()
];
};
function isComparableType(op, type) {
if (op === '==' || op === '!=') {
return type.kind === 'boolean' || type.kind === 'string' || type.kind === 'number' || type.kind === 'null' || type.kind === 'value';
} else {
return type.kind === 'string' || type.kind === 'number' || type.kind === 'value';
}
}
function eq(ctx, a, b) {
return a === b;
}
function neq(ctx, a, b) {
return a !== b;
}
function lt(ctx, a, b) {
return a < b;
}
function gt(ctx, a, b) {
return a > b;
}
function lteq(ctx, a, b) {
return a <= b;
}
function gteq(ctx, a, b) {
return a >= b;
}
function eqCollate(ctx, a, b, c) {
return c.compare(a, b) === 0;
}
function neqCollate(ctx, a, b, c) {
return !eqCollate(ctx, a, b, c);
}
function ltCollate(ctx, a, b, c) {
return c.compare(a, b) < 0;
}
function gtCollate(ctx, a, b, c) {
return c.compare(a, b) > 0;
}
function lteqCollate(ctx, a, b, c) {
return c.compare(a, b) <= 0;
}
function gteqCollate(ctx, a, b, c) {
return c.compare(a, b) >= 0;
}
function makeComparison(op, compareBasic, compareWithCollator) {
var isOrderComparison = op !== '==' && op !== '!=';
return function () {
function Comparison(lhs, rhs, collator) {
this.type = BooleanType;
this.lhs = lhs;
this.rhs = rhs;
this.collator = collator;
this.hasUntypedArgument = lhs.type.kind === 'value' || rhs.type.kind === 'value';
}
Comparison.parse = function parse(args, context) {
if (args.length !== 3 && args.length !== 4) {
return context.error('Expected two or three arguments.');
}
var op = args[0];
var lhs = context.parse(args[1], 1, ValueType);
if (!lhs) {
return null;
}
if (!isComparableType(op, lhs.type)) {
return context.concat(1).error('"' + op + '" comparisons are not supported for type \'' + toString(lhs.type) + '\'.');
}
var rhs = context.parse(args[2], 2, ValueType);
if (!rhs) {
return null;
}
if (!isComparableType(op, rhs.type)) {
return context.concat(2).error('"' + op + '" comparisons are not supported for type \'' + toString(rhs.type) + '\'.');
}
if (lhs.type.kind !== rhs.type.kind && lhs.type.kind !== 'value' && rhs.type.kind !== 'value') {
return context.error('Cannot compare types \'' + toString(lhs.type) + '\' and \'' + toString(rhs.type) + '\'.');
}
if (isOrderComparison) {
if (lhs.type.kind === 'value' && rhs.type.kind !== 'value') {
lhs = new Assertion(rhs.type, [lhs]);
} else if (lhs.type.kind !== 'value' && rhs.type.kind === 'value') {
rhs = new Assertion(lhs.type, [rhs]);
}
}
var collator = null;
if (args.length === 4) {
if (lhs.type.kind !== 'string' && rhs.type.kind !== 'string' && lhs.type.kind !== 'value' && rhs.type.kind !== 'value') {
return context.error('Cannot use collator to compare non-string types.');
}
collator = context.parse(args[3], 3, CollatorType);
if (!collator) {
return null;
}
}
return new Comparison(lhs, rhs, collator);
};
Comparison.prototype.evaluate = function evaluate(ctx) {
var lhs = this.lhs.evaluate(ctx);
var rhs = this.rhs.evaluate(ctx);
if (isOrderComparison && this.hasUntypedArgument) {
var lt = typeOf(lhs);
var rt = typeOf(rhs);
if (lt.kind !== rt.kind || !(lt.kind === 'string' || lt.kind === 'number')) {
throw new RuntimeError('Expected arguments for "' + op + '" to be (string, string) or (number, number), but found (' + lt.kind + ', ' + rt.kind + ') instead.');
}
}
if (this.collator && !isOrderComparison && this.hasUntypedArgument) {
var lt$1 = typeOf(lhs);
var rt$1 = typeOf(rhs);
if (lt$1.kind !== 'string' || rt$1.kind !== 'string') {
return compareBasic(ctx, lhs, rhs);
}
}
return this.collator ? compareWithCollator(ctx, lhs, rhs, this.collator.evaluate(ctx)) : compareBasic(ctx, lhs, rhs);
};
Comparison.prototype.eachChild = function eachChild(fn) {
fn(this.lhs);
fn(this.rhs);
if (this.collator) {
fn(this.collator);
}
};
Comparison.prototype.outputDefined = function outputDefined() {
return true;
};
Comparison.prototype.serialize = function serialize() {
var serialized = [op];
this.eachChild(function (child) {
serialized.push(child.serialize());
});
return serialized;
};
return Comparison;
}();
}
var Equals = makeComparison('==', eq, eqCollate);
var NotEquals = makeComparison('!=', neq, neqCollate);
var LessThan = makeComparison('<', lt, ltCollate);
var GreaterThan = makeComparison('>', gt, gtCollate);
var LessThanOrEqual = makeComparison('<=', lteq, lteqCollate);
var GreaterThanOrEqual = makeComparison('>=', gteq, gteqCollate);
var NumberFormat = function NumberFormat(number, locale, currency, minFractionDigits, maxFractionDigits) {
this.type = StringType;
this.number = number;
this.locale = locale;
this.currency = currency;
this.minFractionDigits = minFractionDigits;
this.maxFractionDigits = maxFractionDigits;
};
NumberFormat.parse = function parse(args, context) {
if (args.length !== 3) {
return context.error('Expected two arguments.');
}
var number = context.parse(args[1], 1, NumberType);
if (!number) {
return null;
}
var options = args[2];
if (typeof options !== 'object' || Array.isArray(options)) {
return context.error('NumberFormat options argument must be an object.');
}
var locale = null;
if (options['locale']) {
locale = context.parse(options['locale'], 1, StringType);
if (!locale) {
return null;
}
}
var currency = null;
if (options['currency']) {
currency = context.parse(options['currency'], 1, StringType);
if (!currency) {
return null;
}
}
var minFractionDigits = null;
if (options['min-fraction-digits']) {
minFractionDigits = context.parse(options['min-fraction-digits'], 1, NumberType);
if (!minFractionDigits) {
return null;
}
}
var maxFractionDigits = null;
if (options['max-fraction-digits']) {
maxFractionDigits = context.parse(options['max-fraction-digits'], 1, NumberType);
if (!maxFractionDigits) {
return null;
}
}
return new NumberFormat(number, locale, currency, minFractionDigits, maxFractionDigits);
};
NumberFormat.prototype.evaluate = function evaluate(ctx) {
return new Intl.NumberFormat(this.locale ? this.locale.evaluate(ctx) : [], {
style: this.currency ? 'currency' : 'decimal',
currency: this.currency ? this.currency.evaluate(ctx) : undefined,
minimumFractionDigits: this.minFractionDigits ? this.minFractionDigits.evaluate(ctx) : undefined,
maximumFractionDigits: this.maxFractionDigits ? this.maxFractionDigits.evaluate(ctx) : undefined
}).format(this.number.evaluate(ctx));
};
NumberFormat.prototype.eachChild = function eachChild(fn) {
fn(this.number);
if (this.locale) {
fn(this.locale);
}
if (this.currency) {
fn(this.currency);
}
if (this.minFractionDigits) {
fn(this.minFractionDigits);
}
if (this.maxFractionDigits) {
fn(this.maxFractionDigits);
}
};
NumberFormat.prototype.outputDefined = function outputDefined() {
return false;
};
NumberFormat.prototype.serialize = function serialize() {
var options = {};
if (this.locale) {
options['locale'] = this.locale.serialize();
}
if (this.currency) {
options['currency'] = this.currency.serialize();
}
if (this.minFractionDigits) {
options['min-fraction-digits'] = this.minFractionDigits.serialize();
}
if (this.maxFractionDigits) {
options['max-fraction-digits'] = this.maxFractionDigits.serialize();
}
return [
'number-format',
this.number.serialize(),
options
];
};
var Length = function Length(input) {
this.type = NumberType;
this.input = input;
};
Length.parse = function parse(args, context) {
if (args.length !== 2) {
return context.error('Expected 1 argument, but found ' + (args.length - 1) + ' instead.');
}
var input = context.parse(args[1], 1);
if (!input) {
return null;
}
if (input.type.kind !== 'array' && input.type.kind !== 'string' && input.type.kind !== 'value') {
return context.error('Expected argument of type string or array, but found ' + toString(input.type) + ' instead.');
}
return new Length(input);
};
Length.prototype.evaluate = function evaluate(ctx) {
var input = this.input.evaluate(ctx);
if (typeof input === 'string') {
return input.length;
} else if (Array.isArray(input)) {
return input.length;
} else {
throw new RuntimeError('Expected value to be of type string or array, but found ' + toString(typeOf(input)) + ' instead.');
}
};
Length.prototype.eachChild = function eachChild(fn) {
fn(this.input);
};
Length.prototype.outputDefined = function outputDefined() {
return false;
};
Length.prototype.serialize = function serialize() {
var serialized = ['length'];
this.eachChild(function (child) {
serialized.push(child.serialize());
});
return serialized;
};
var expressions = {
'==': Equals,
'!=': NotEquals,
'>': GreaterThan,
'<': LessThan,
'>=': GreaterThanOrEqual,
'<=': LessThanOrEqual,
'array': Assertion,
'at': At,
'boolean': Assertion,
'case': Case,
'coalesce': Coalesce,
'collator': CollatorExpression,
'format': FormatExpression,
'image': ImageExpression,
'in': In,
'index-of': IndexOf,
'interpolate': Interpolate,
'interpolate-hcl': Interpolate,
'interpolate-lab': Interpolate,
'length': Length,
'let': Let,
'literal': Literal,
'match': Match,
'number': Assertion,
'number-format': NumberFormat,
'object': Assertion,
'slice': Slice,
'step': Step,
'string': Assertion,
'to-boolean': Coercion,
'to-color': Coercion,
'to-number': Coercion,
'to-string': Coercion,
'var': Var,
'within': Within
};
function rgba(ctx, ref) {
var r = ref[0];
var g = ref[1];
var b = ref[2];
var a = ref[3];
r = r.evaluate(ctx);
g = g.evaluate(ctx);
b = b.evaluate(ctx);
var alpha = a ? a.evaluate(ctx) : 1;
var error = validateRGBA(r, g, b, alpha);
if (error) {
throw new RuntimeError(error);
}
return new Color(r / 255 * alpha, g / 255 * alpha, b / 255 * alpha, alpha);
}
function has(key, obj) {
return key in obj;
}
function get(key, obj) {
var v = obj[key];
return typeof v === 'undefined' ? null : v;
}
function binarySearch(v, a, i, j) {
while (i <= j) {
var m = i + j >> 1;
if (a[m] === v) {
return true;
}
if (a[m] > v) {
j = m - 1;
} else {
i = m + 1;
}
}
return false;
}
function varargs(type) {
return { type: type };
}
CompoundExpression.register(expressions, {
'error': [
ErrorType,
[StringType],
function (ctx, ref) {
var v = ref[0];
throw new RuntimeError(v.evaluate(ctx));
}
],
'typeof': [
StringType,
[ValueType],
function (ctx, ref) {
var v = ref[0];
return toString(typeOf(v.evaluate(ctx)));
}
],
'to-rgba': [
array(NumberType, 4),
[ColorType],
function (ctx, ref) {
var v = ref[0];
return v.evaluate(ctx).toArray();
}
],
'rgb': [
ColorType,
[
NumberType,
NumberType,
NumberType
],
rgba
],
'rgba': [
ColorType,
[
NumberType,
NumberType,
NumberType,
NumberType
],
rgba
],
'has': {
type: BooleanType,
overloads: [
[
[StringType],
function (ctx, ref) {
var key = ref[0];
return has(key.evaluate(ctx), ctx.properties());
}
],
[
[
StringType,
ObjectType
],
function (ctx, ref) {
var key = ref[0];
var obj = ref[1];
return has(key.evaluate(ctx), obj.evaluate(ctx));
}
]
]
},
'get': {
type: ValueType,
overloads: [
[
[StringType],
function (ctx, ref) {
var key = ref[0];
return get(key.evaluate(ctx), ctx.properties());
}
],
[
[
StringType,
ObjectType
],
function (ctx, ref) {
var key = ref[0];
var obj = ref[1];
return get(key.evaluate(ctx), obj.evaluate(ctx));
}
]
]
},
'feature-state': [
ValueType,
[StringType],
function (ctx, ref) {
var key = ref[0];
return get(key.evaluate(ctx), ctx.featureState || {});
}
],
'properties': [
ObjectType,
[],
function (ctx) {
return ctx.properties();
}
],
'geometry-type': [
StringType,
[],
function (ctx) {
return ctx.geometryType();
}
],
'id': [
ValueType,
[],
function (ctx) {
return ctx.id();
}
],
'zoom': [
NumberType,
[],
function (ctx) {
return ctx.globals.zoom;
}
],
'heatmap-density': [
NumberType,
[],
function (ctx) {
return ctx.globals.heatmapDensity || 0;
}
],
'line-progress': [
NumberType,
[],
function (ctx) {
return ctx.globals.lineProgress || 0;
}
],
'accumulated': [
ValueType,
[],
function (ctx) {
return ctx.globals.accumulated === undefined ? null : ctx.globals.accumulated;
}
],
'+': [
NumberType,
varargs(NumberType),
function (ctx, args) {
var result = 0;
for (var i = 0, list = args; i < list.length; i += 1) {
var arg = list[i];
result += arg.evaluate(ctx);
}
return result;
}
],
'*': [
NumberType,
varargs(NumberType),
function (ctx, args) {
var result = 1;
for (var i = 0, list = args; i < list.length; i += 1) {
var arg = list[i];
result *= arg.evaluate(ctx);
}
return result;
}
],
'-': {
type: NumberType,
overloads: [
[
[
NumberType,
NumberType
],
function (ctx, ref) {
var a = ref[0];
var b = ref[1];
return a.evaluate(ctx) - b.evaluate(ctx);
}
],
[
[NumberType],
function (ctx, ref) {
var a = ref[0];
return -a.evaluate(ctx);
}
]
]
},
'/': [
NumberType,
[
NumberType,
NumberType
],
function (ctx, ref) {
var a = ref[0];
var b = ref[1];
return a.evaluate(ctx) / b.evaluate(ctx);
}
],
'%': [
NumberType,
[
NumberType,
NumberType
],
function (ctx, ref) {
var a = ref[0];
var b = ref[1];
return a.evaluate(ctx) % b.evaluate(ctx);
}
],
'ln2': [
NumberType,
[],
function () {
return Math.LN2;
}
],
'pi': [
NumberType,
[],
function () {
return Math.PI;
}
],
'e': [
NumberType,
[],
function () {
return Math.E;
}
],
'^': [
NumberType,
[
NumberType,
NumberType
],
function (ctx, ref) {
var b = ref[0];
var e = ref[1];
return Math.pow(b.evaluate(ctx), e.evaluate(ctx));
}
],
'sqrt': [
NumberType,
[NumberType],
function (ctx, ref) {
var x = ref[0];
return Math.sqrt(x.evaluate(ctx));
}
],
'log10': [
NumberType,
[NumberType],
function (ctx, ref) {
var n = ref[0];
return Math.log(n.evaluate(ctx)) / Math.LN10;
}
],
'ln': [
NumberType,
[NumberType],
function (ctx, ref) {
var n = ref[0];
return Math.log(n.evaluate(ctx));
}
],
'log2': [
NumberType,
[NumberType],
function (ctx, ref) {
var n = ref[0];
return Math.log(n.evaluate(ctx)) / Math.LN2;
}
],
'sin': [
NumberType,
[NumberType],
function (ctx, ref) {
var n = ref[0];
return Math.sin(n.evaluate(ctx));
}
],
'cos': [
NumberType,
[NumberType],
function (ctx, ref) {
var n = ref[0];
return Math.cos(n.evaluate(ctx));
}
],
'tan': [
NumberType,
[NumberType],
function (ctx, ref) {
var n = ref[0];
return Math.tan(n.evaluate(ctx));
}
],
'asin': [
NumberType,
[NumberType],
function (ctx, ref) {
var n = ref[0];
return Math.asin(n.evaluate(ctx));
}
],
'acos': [
NumberType,
[NumberType],
function (ctx, ref) {
var n = ref[0];
return Math.acos(n.evaluate(ctx));
}
],
'atan': [
NumberType,
[NumberType],
function (ctx, ref) {
var n = ref[0];
return Math.atan(n.evaluate(ctx));
}
],
'min': [
NumberType,
varargs(NumberType),
function (ctx, args) {
return Math.min.apply(Math, args.map(function (arg) {
return arg.evaluate(ctx);
}));
}
],
'max': [
NumberType,
varargs(NumberType),
function (ctx, args) {
return Math.max.apply(Math, args.map(function (arg) {
return arg.evaluate(ctx);
}));
}
],
'abs': [
NumberType,
[NumberType],
function (ctx, ref) {
var n = ref[0];
return Math.abs(n.evaluate(ctx));
}
],
'round': [
NumberType,
[NumberType],
function (ctx, ref) {
var n = ref[0];
var v = n.evaluate(ctx);
return v < 0 ? -Math.round(-v) : Math.round(v);
}
],
'floor': [
NumberType,
[NumberType],
function (ctx, ref) {
var n = ref[0];
return Math.floor(n.evaluate(ctx));
}
],
'ceil': [
NumberType,
[NumberType],
function (ctx, ref) {
var n = ref[0];
return Math.ceil(n.evaluate(ctx));
}
],
'filter-==': [
BooleanType,
[
StringType,
ValueType
],
function (ctx, ref) {
var k = ref[0];
var v = ref[1];
return ctx.properties()[k.value] === v.value;
}
],
'filter-id-==': [
BooleanType,
[ValueType],
function (ctx, ref) {
var v = ref[0];
return ctx.id() === v.value;
}
],
'filter-type-==': [
BooleanType,
[StringType],
function (ctx, ref) {
var v = ref[0];
return ctx.geometryType() === v.value;
}
],
'filter-<': [
BooleanType,
[
StringType,
ValueType
],
function (ctx, ref) {
var k = ref[0];
var v = ref[1];
var a = ctx.properties()[k.value];
var b = v.value;
return typeof a === typeof b && a < b;
}
],
'filter-id-<': [
BooleanType,
[ValueType],
function (ctx, ref) {
var v = ref[0];
var a = ctx.id();
var b = v.value;
return typeof a === typeof b && a < b;
}
],
'filter->': [
BooleanType,
[
StringType,
ValueType
],
function (ctx, ref) {
var k = ref[0];
var v = ref[1];
var a = ctx.properties()[k.value];
var b = v.value;
return typeof a === typeof b && a > b;
}
],
'filter-id->': [
BooleanType,
[ValueType],
function (ctx, ref) {
var v = ref[0];
var a = ctx.id();
var b = v.value;
return typeof a === typeof b && a > b;
}
],
'filter-<=': [
BooleanType,
[
StringType,
ValueType
],
function (ctx, ref) {
var k = ref[0];
var v = ref[1];
var a = ctx.properties()[k.value];
var b = v.value;
return typeof a === typeof b && a <= b;
}
],
'filter-id-<=': [
BooleanType,
[ValueType],
function (ctx, ref) {
var v = ref[0];
var a = ctx.id();
var b = v.value;
return typeof a === typeof b && a <= b;
}
],
'filter->=': [
BooleanType,
[
StringType,
ValueType
],
function (ctx, ref) {
var k = ref[0];
var v = ref[1];
var a = ctx.properties()[k.value];
var b = v.value;
return typeof a === typeof b && a >= b;
}
],
'filter-id->=': [
BooleanType,
[ValueType],
function (ctx, ref) {
var v = ref[0];
var a = ctx.id();
var b = v.value;
return typeof a === typeof b && a >= b;
}
],
'filter-has': [
BooleanType,
[ValueType],
function (ctx, ref) {
var k = ref[0];
return k.value in ctx.properties();
}
],
'filter-has-id': [
BooleanType,
[],
function (ctx) {
return ctx.id() !== null && ctx.id() !== undefined;
}
],
'filter-type-in': [
BooleanType,
[array(StringType)],
function (ctx, ref) {
var v = ref[0];
return v.value.indexOf(ctx.geometryType()) >= 0;
}
],
'filter-id-in': [
BooleanType,
[array(ValueType)],
function (ctx, ref) {
var v = ref[0];
return v.value.indexOf(ctx.id()) >= 0;
}
],
'filter-in-small': [
BooleanType,
[
StringType,
array(ValueType)
],
function (ctx, ref) {
var k = ref[0];
var v = ref[1];
return v.value.indexOf(ctx.properties()[k.value]) >= 0;
}
],
'filter-in-large': [
BooleanType,
[
StringType,
array(ValueType)
],
function (ctx, ref) {
var k = ref[0];
var v = ref[1];
return binarySearch(ctx.properties()[k.value], v.value, 0, v.value.length - 1);
}
],
'all': {
type: BooleanType,
overloads: [
[
[
BooleanType,
BooleanType
],
function (ctx, ref) {
var a = ref[0];
var b = ref[1];
return a.evaluate(ctx) && b.evaluate(ctx);
}
],
[
varargs(BooleanType),
function (ctx, args) {
for (var i = 0, list = args; i < list.length; i += 1) {
var arg = list[i];
if (!arg.evaluate(ctx)) {
return false;
}
}
return true;
}
]
]
},
'any': {
type: BooleanType,
overloads: [
[
[
BooleanType,
BooleanType
],
function (ctx, ref) {
var a = ref[0];
var b = ref[1];
return a.evaluate(ctx) || b.evaluate(ctx);
}
],
[
varargs(BooleanType),
function (ctx, args) {
for (var i = 0, list = args; i < list.length; i += 1) {
var arg = list[i];
if (arg.evaluate(ctx)) {
return true;
}
}
return false;
}
]
]
},
'!': [
BooleanType,
[BooleanType],
function (ctx, ref) {
var b = ref[0];
return !b.evaluate(ctx);
}
],
'is-supported-script': [
BooleanType,
[StringType],
function (ctx, ref) {
var s = ref[0];
var isSupportedScript = ctx.globals && ctx.globals.isSupportedScript;
if (isSupportedScript) {
return isSupportedScript(s.evaluate(ctx));
}
return true;
}
],
'upcase': [
StringType,
[StringType],
function (ctx, ref) {
var s = ref[0];
return s.evaluate(ctx).toUpperCase();
}
],
'downcase': [
StringType,
[StringType],
function (ctx, ref) {
var s = ref[0];
return s.evaluate(ctx).toLowerCase();
}
],
'concat': [
StringType,
varargs(ValueType),
function (ctx, args) {
return args.map(function (arg) {
return toString$1(arg.evaluate(ctx));
}).join('');
}
],
'resolved-locale': [
StringType,
[CollatorType],
function (ctx, ref) {
var collator = ref[0];
return collator.evaluate(ctx).resolvedLocale();
}
]
});
function success(value) {
return {
result: 'success',
value: value
};
}
function error(value) {
return {
result: 'error',
value: value
};
}
function supportsPropertyExpression(spec) {
return spec['property-type'] === 'data-driven' || spec['property-type'] === 'cross-faded-data-driven';
}
function supportsZoomExpression(spec) {
return !!spec.expression && spec.expression.parameters.indexOf('zoom') > -1;
}
function supportsInterpolation(spec) {
return !!spec.expression && spec.expression.interpolated;
}
function getType(val) {
if (val instanceof Number) {
return 'number';
} else if (val instanceof String) {
return 'string';
} else if (val instanceof Boolean) {
return 'boolean';
} else if (Array.isArray(val)) {
return 'array';
} else if (val === null) {
return 'null';
} else {
return typeof val;
}
}
function isFunction(value) {
return typeof value === 'object' && value !== null && !Array.isArray(value);
}
function identityFunction(x) {
return x;
}
function createFunction(parameters, propertySpec) {
var isColor = propertySpec.type === 'color';
var zoomAndFeatureDependent = parameters.stops && typeof parameters.stops[0][0] === 'object';
var featureDependent = zoomAndFeatureDependent || parameters.property !== undefined;
var zoomDependent = zoomAndFeatureDependent || !featureDependent;
var type = parameters.type || (supportsInterpolation(propertySpec) ? 'exponential' : 'interval');
if (isColor) {
parameters = extend$1({}, parameters);
if (parameters.stops) {
parameters.stops = parameters.stops.map(function (stop) {
return [
stop[0],
Color.parse(stop[1])
];
});
}
if (parameters.default) {
parameters.default = Color.parse(parameters.default);
} else {
parameters.default = Color.parse(propertySpec.default);
}
}
if (parameters.colorSpace && parameters.colorSpace !== 'rgb' && !colorSpaces[parameters.colorSpace]) {
throw new Error('Unknown color space: ' + parameters.colorSpace);
}
var innerFun;
var hashedStops;
var categoricalKeyType;
if (type === 'exponential') {
innerFun = evaluateExponentialFunction;
} else if (type === 'interval') {
innerFun = evaluateIntervalFunction;
} else if (type === 'categorical') {
innerFun = evaluateCategoricalFunction;
hashedStops = Object.create(null);
for (var i = 0, list = parameters.stops; i < list.length; i += 1) {
var stop = list[i];
hashedStops[stop[0]] = stop[1];
}
categoricalKeyType = typeof parameters.stops[0][0];
} else if (type === 'identity') {
innerFun = evaluateIdentityFunction;
} else {
throw new Error('Unknown function type "' + type + '"');
}
if (zoomAndFeatureDependent) {
var featureFunctions = {};
var zoomStops = [];
for (var s = 0; s < parameters.stops.length; s++) {
var stop$1 = parameters.stops[s];
var zoom = stop$1[0].zoom;
if (featureFunctions[zoom] === undefined) {
featureFunctions[zoom] = {
zoom: zoom,
type: parameters.type,
property: parameters.property,
default: parameters.default,
stops: []
};
zoomStops.push(zoom);
}
featureFunctions[zoom].stops.push([
stop$1[0].value,
stop$1[1]
]);
}
var featureFunctionStops = [];
for (var i$1 = 0, list$1 = zoomStops; i$1 < list$1.length; i$1 += 1) {
var z = list$1[i$1];
featureFunctionStops.push([
featureFunctions[z].zoom,
createFunction(featureFunctions[z], propertySpec)
]);
}
var interpolationType = { name: 'linear' };
return {
kind: 'composite',
interpolationType: interpolationType,
interpolationFactor: Interpolate.interpolationFactor.bind(undefined, interpolationType),
zoomStops: featureFunctionStops.map(function (s) {
return s[0];
}),
evaluate: function evaluate(ref, properties) {
var zoom = ref.zoom;
return evaluateExponentialFunction({
stops: featureFunctionStops,
base: parameters.base
}, propertySpec, zoom).evaluate(zoom, properties);
}
};
} else if (zoomDependent) {
var interpolationType$1 = type === 'exponential' ? {
name: 'exponential',
base: parameters.base !== undefined ? parameters.base : 1
} : null;
return {
kind: 'camera',
interpolationType: interpolationType$1,
interpolationFactor: Interpolate.interpolationFactor.bind(undefined, interpolationType$1),
zoomStops: parameters.stops.map(function (s) {
return s[0];
}),
evaluate: function (ref) {
var zoom = ref.zoom;
return innerFun(parameters, propertySpec, zoom, hashedStops, categoricalKeyType);
}
};
} else {
return {
kind: 'source',
evaluate: function evaluate(_, feature) {
var value = feature && feature.properties ? feature.properties[parameters.property] : undefined;
if (value === undefined) {
return coalesce(parameters.default, propertySpec.default);
}
return innerFun(parameters, propertySpec, value, hashedStops, categoricalKeyType);
}
};
}
}
function coalesce(a, b, c) {
if (a !== undefined) {
return a;
}
if (b !== undefined) {
return b;
}
if (c !== undefined) {
return c;
}
}
function evaluateCategoricalFunction(parameters, propertySpec, input, hashedStops, keyType) {
var evaluated = typeof input === keyType ? hashedStops[input] : undefined;
return coalesce(evaluated, parameters.default, propertySpec.default);
}
function evaluateIntervalFunction(parameters, propertySpec, input) {
if (getType(input) !== 'number') {
return coalesce(parameters.default, propertySpec.default);
}
var n = parameters.stops.length;
if (n === 1) {
return parameters.stops[0][1];
}
if (input <= parameters.stops[0][0]) {
return parameters.stops[0][1];
}
if (input >= parameters.stops[n - 1][0]) {
return parameters.stops[n - 1][1];
}
var index = findStopLessThanOrEqualTo(parameters.stops.map(function (stop) {
return stop[0];
}), input);
return parameters.stops[index][1];
}
function evaluateExponentialFunction(parameters, propertySpec, input) {
var base = parameters.base !== undefined ? parameters.base : 1;
if (getType(input) !== 'number') {
return coalesce(parameters.default, propertySpec.default);
}
var n = parameters.stops.length;
if (n === 1) {
return parameters.stops[0][1];
}
if (input <= parameters.stops[0][0]) {
return parameters.stops[0][1];
}
if (input >= parameters.stops[n - 1][0]) {
return parameters.stops[n - 1][1];
}
var index = findStopLessThanOrEqualTo(parameters.stops.map(function (stop) {
return stop[0];
}), input);
var t = interpolationFactor(input, base, parameters.stops[index][0], parameters.stops[index + 1][0]);
var outputLower = parameters.stops[index][1];
var outputUpper = parameters.stops[index + 1][1];
var interp = interpolate[propertySpec.type] || identityFunction;
if (parameters.colorSpace && parameters.colorSpace !== 'rgb') {
var colorspace = colorSpaces[parameters.colorSpace];
interp = function (a, b) {
return colorspace.reverse(colorspace.interpolate(colorspace.forward(a), colorspace.forward(b), t));
};
}
if (typeof outputLower.evaluate === 'function') {
return {
evaluate: function evaluate() {
var args = [], len = arguments.length;
while (len--)
args[len] = arguments[len];
var evaluatedLower = outputLower.evaluate.apply(undefined, args);
var evaluatedUpper = outputUpper.evaluate.apply(undefined, args);
if (evaluatedLower === undefined || evaluatedUpper === undefined) {
return undefined;
}
return interp(evaluatedLower, evaluatedUpper, t);
}
};
}
return interp(outputLower, outputUpper, t);
}
function evaluateIdentityFunction(parameters, propertySpec, input) {
if (propertySpec.type === 'color') {
input = Color.parse(input);
} else if (propertySpec.type === 'formatted') {
input = Formatted.fromString(input.toString());
} else if (propertySpec.type === 'resolvedImage') {
input = ResolvedImage.fromString(input.toString());
} else if (getType(input) !== propertySpec.type && (propertySpec.type !== 'enum' || !propertySpec.values[input])) {
input = undefined;
}
return coalesce(input, parameters.default, propertySpec.default);
}
function interpolationFactor(input, base, lowerValue, upperValue) {
var difference = upperValue - lowerValue;
var progress = input - lowerValue;
if (difference === 0) {
return 0;
} else if (base === 1) {
return progress / difference;
} else {
return (Math.pow(base, progress) - 1) / (Math.pow(base, difference) - 1);
}
}
var StyleExpression = function StyleExpression(expression, propertySpec) {
this.expression = expression;
this._warningHistory = {};
this._evaluator = new EvaluationContext();
this._defaultValue = propertySpec ? getDefaultValue(propertySpec) : null;
this._enumValues = propertySpec && propertySpec.type === 'enum' ? propertySpec.values : null;
};
StyleExpression.prototype.evaluateWithoutErrorHandling = function evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection) {
this._evaluator.globals = globals;
this._evaluator.feature = feature;
this._evaluator.featureState = featureState;
this._evaluator.canonical = canonical;
this._evaluator.availableImages = availableImages || null;
this._evaluator.formattedSection = formattedSection;
return this.expression.evaluate(this._evaluator);
};
StyleExpression.prototype.evaluate = function evaluate(globals, feature, featureState, canonical, availableImages, formattedSection) {
this._evaluator.globals = globals;
this._evaluator.feature = feature || null;
this._evaluator.featureState = featureState || null;
this._evaluator.canonical = canonical;
this._evaluator.availableImages = availableImages || null;
this._evaluator.formattedSection = formattedSection || null;
try {
var val = this.expression.evaluate(this._evaluator);
if (val === null || val === undefined || typeof val === 'number' && val !== val) {
return this._defaultValue;
}
if (this._enumValues && !(val in this._enumValues)) {
throw new RuntimeError('Expected value to be one of ' + Object.keys(this._enumValues).map(function (v) {
return JSON.stringify(v);
}).join(', ') + ', but found ' + JSON.stringify(val) + ' instead.');
}
return val;
} catch (e) {
if (!this._warningHistory[e.message]) {
this._warningHistory[e.message] = true;
if (typeof console !== 'undefined') {
console.warn(e.message);
}
}
return this._defaultValue;
}
};
function isExpression(expression) {
return Array.isArray(expression) && expression.length > 0 && typeof expression[0] === 'string' && expression[0] in expressions;
}
function createExpression(expression, propertySpec) {
var parser = new ParsingContext(expressions, [], propertySpec ? getExpectedType(propertySpec) : undefined);
var parsed = parser.parse(expression, undefined, undefined, undefined, propertySpec && propertySpec.type === 'string' ? { typeAnnotation: 'coerce' } : undefined);
if (!parsed) {
return error(parser.errors);
}
return success(new StyleExpression(parsed, propertySpec));
}
var ZoomConstantExpression = function ZoomConstantExpression(kind, expression) {
this.kind = kind;
this._styleExpression = expression;
this.isStateDependent = kind !== 'constant' && !isStateConstant(expression.expression);
};
ZoomConstantExpression.prototype.evaluateWithoutErrorHandling = function evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection) {
return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection);
};
ZoomConstantExpression.prototype.evaluate = function evaluate(globals, feature, featureState, canonical, availableImages, formattedSection) {
return this._styleExpression.evaluate(globals, feature, featureState, canonical, availableImages, formattedSection);
};
var ZoomDependentExpression = function ZoomDependentExpression(kind, expression, zoomStops, interpolationType) {
this.kind = kind;
this.zoomStops = zoomStops;
this._styleExpression = expression;
this.isStateDependent = kind !== 'camera' && !isStateConstant(expression.expression);
this.interpolationType = interpolationType;
};
ZoomDependentExpression.prototype.evaluateWithoutErrorHandling = function evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection) {
return this._styleExpression.evaluateWithoutErrorHandling(globals, feature, featureState, canonical, availableImages, formattedSection);
};
ZoomDependentExpression.prototype.evaluate = function evaluate(globals, feature, featureState, canonical, availableImages, formattedSection) {
return this._styleExpression.evaluate(globals, feature, featureState, canonical, availableImages, formattedSection);
};
ZoomDependentExpression.prototype.interpolationFactor = function interpolationFactor(input, lower, upper) {
if (this.interpolationType) {
return Interpolate.interpolationFactor(this.interpolationType, input, lower, upper);
} else {
return 0;
}
};
function createPropertyExpression(expression, propertySpec) {
expression = createExpression(expression, propertySpec);
if (expression.result === 'error') {
return expression;
}
var parsed = expression.value.expression;
var isFeatureConstant$1 = isFeatureConstant(parsed);
if (!isFeatureConstant$1 && !supportsPropertyExpression(propertySpec)) {
return error([new ParsingError('', 'data expressions not supported')]);
}
var isZoomConstant = isGlobalPropertyConstant(parsed, ['zoom']);
if (!isZoomConstant && !supportsZoomExpression(propertySpec)) {
return error([new ParsingError('', 'zoom expressions not supported')]);
}
var zoomCurve = findZoomCurve(parsed);
if (!zoomCurve && !isZoomConstant) {
return error([new ParsingError('', '"zoom" expression may only be used as input to a top-level "step" or "interpolate" expression.')]);
} else if (zoomCurve instanceof ParsingError) {
return error([zoomCurve]);
} else if (zoomCurve instanceof Interpolate && !supportsInterpolation(propertySpec)) {
return error([new ParsingError('', '"interpolate" expressions cannot be used with this property')]);
}
if (!zoomCurve) {
return success(isFeatureConstant$1 ? new ZoomConstantExpression('constant', expression.value) : new ZoomConstantExpression('source', expression.value));
}
var interpolationType = zoomCurve instanceof Interpolate ? zoomCurve.interpolation : undefined;
return success(isFeatureConstant$1 ? new ZoomDependentExpression('camera', expression.value, zoomCurve.labels, interpolationType) : new ZoomDependentExpression('composite', expression.value, zoomCurve.labels, interpolationType));
}
var StylePropertyFunction = function StylePropertyFunction(parameters, specification) {
this._parameters = parameters;
this._specification = specification;
extend$1(this, createFunction(this._parameters, this._specification));
};
StylePropertyFunction.deserialize = function deserialize(serialized) {
return new StylePropertyFunction(serialized._parameters, serialized._specification);
};
StylePropertyFunction.serialize = function serialize(input) {
return {
_parameters: input._parameters,
_specification: input._specification
};
};
function normalizePropertyExpression(value, specification) {
if (isFunction(value)) {
return new StylePropertyFunction(value, specification);
} else if (isExpression(value)) {
var expression = createPropertyExpression(value, specification);
if (expression.result === 'error') {
throw new Error(expression.value.map(function (err) {
return err.key + ': ' + err.message;
}).join(', '));
}
return expression.value;
} else {
var constant = value;
if (typeof value === 'string' && specification.type === 'color') {
constant = Color.parse(value);
}
return {
kind: 'constant',
evaluate: function () {
return constant;
}
};
}
}
function findZoomCurve(expression) {
var result = null;
if (expression instanceof Let) {
result = findZoomCurve(expression.result);
} else if (expression instanceof Coalesce) {
for (var i = 0, list = expression.args; i < list.length; i += 1) {
var arg = list[i];
result = findZoomCurve(arg);
if (result) {
break;
}
}
} else if ((expression instanceof Step || expression instanceof Interpolate) && expression.input instanceof CompoundExpression && expression.input.name === 'zoom') {
result = expression;
}
if (result instanceof ParsingError) {
return result;
}
expression.eachChild(function (child) {
var childResult = findZoomCurve(child);
if (childResult instanceof ParsingError) {
result = childResult;
} else if (!result && childResult) {
result = new ParsingError('', '"zoom" expression may only be used as input to a top-level "step" or "interpolate" expression.');
} else if (result && childResult && result !== childResult) {
result = new ParsingError('', 'Only one zoom-based "step" or "interpolate" subexpression may be used in an expression.');
}
});
return result;
}
function getExpectedType(spec) {
var types = {
color: ColorType,
string: StringType,
number: NumberType,
enum: StringType,
boolean: BooleanType,
formatted: FormattedType,
resolvedImage: ResolvedImageType
};
if (spec.type === 'array') {
return array(types[spec.value] || ValueType, spec.length);
}
return types[spec.type];
}
function getDefaultValue(spec) {
if (spec.type === 'color' && isFunction(spec.default)) {
return new Color(0, 0, 0, 0);
} else if (spec.type === 'color') {
return Color.parse(spec.default) || null;
} else if (spec.default === undefined) {
return null;
} else {
return spec.default;
}
}
function validateObject(options) {
var key = options.key;
var object = options.value;
var elementSpecs = options.valueSpec || {};
var elementValidators = options.objectElementValidators || {};
var style = options.style;
var styleSpec = options.styleSpec;
var errors = [];
var type = getType(object);
if (type !== 'object') {
return [new ValidationError(key, object, 'object expected, ' + type + ' found')];
}
for (var objectKey in object) {
var elementSpecKey = objectKey.split('.')[0];
var elementSpec = elementSpecs[elementSpecKey] || elementSpecs['*'];
var validateElement = void 0;
if (elementValidators[elementSpecKey]) {
validateElement = elementValidators[elementSpecKey];
} else if (elementSpecs[elementSpecKey]) {
validateElement = validate;
} else if (elementValidators['*']) {
validateElement = elementValidators['*'];
} else if (elementSpecs['*']) {
validateElement = validate;
} else {
errors.push(new ValidationError(key, object[objectKey], 'unknown property "' + objectKey + '"'));
continue;
}
errors = errors.concat(validateElement({
key: (key ? key + '.' : key) + objectKey,
value: object[objectKey],
valueSpec: elementSpec,
style: style,
styleSpec: styleSpec,
object: object,
objectKey: objectKey
}, object));
}
for (var elementSpecKey$1 in elementSpecs) {
if (elementValidators[elementSpecKey$1]) {
continue;
}
if (elementSpecs[elementSpecKey$1].required && elementSpecs[elementSpecKey$1]['default'] === undefined && object[elementSpecKey$1] === undefined) {
errors.push(new ValidationError(key, object, 'missing required property "' + elementSpecKey$1 + '"'));
}
}
return errors;
}
function validateArray(options) {
var array = options.value;
var arraySpec = options.valueSpec;
var style = options.style;
var styleSpec = options.styleSpec;
var key = options.key;
var validateArrayElement = options.arrayElementValidator || validate;
if (getType(array) !== 'array') {
return [new ValidationError(key, array, 'array expected, ' + getType(array) + ' found')];
}
if (arraySpec.length && array.length !== arraySpec.length) {
return [new ValidationError(key, array, 'array length ' + arraySpec.length + ' expected, length ' + array.length + ' found')];
}
if (arraySpec['min-length'] && array.length < arraySpec['min-length']) {
return [new ValidationError(key, array, 'array length at least ' + arraySpec['min-length'] + ' expected, length ' + array.length + ' found')];
}
var arrayElementSpec = {
'type': arraySpec.value,
'values': arraySpec.values
};
if (styleSpec.$version < 7) {
arrayElementSpec.function = arraySpec.function;
}
if (getType(arraySpec.value) === 'object') {
arrayElementSpec = arraySpec.value;
}
var errors = [];
for (var i = 0; i < array.length; i++) {
errors = errors.concat(validateArrayElement({
array: array,
arrayIndex: i,
value: array[i],
valueSpec: arrayElementSpec,
style: style,
styleSpec: styleSpec,
key: key + '[' + i + ']'
}));
}
return errors;
}
function validateNumber(options) {
var key = options.key;
var value = options.value;
var valueSpec = options.valueSpec;
var type = getType(value);
if (type === 'number' && value !== value) {
type = 'NaN';
}
if (type !== 'number') {
return [new ValidationError(key, value, 'number expected, ' + type + ' found')];
}
if ('minimum' in valueSpec && value < valueSpec.minimum) {
return [new ValidationError(key, value, value + ' is less than the minimum value ' + valueSpec.minimum)];
}
if ('maximum' in valueSpec && value > valueSpec.maximum) {
return [new ValidationError(key, value, value + ' is greater than the maximum value ' + valueSpec.maximum)];
}
return [];
}
function validateFunction(options) {
var functionValueSpec = options.valueSpec;
var functionType = unbundle(options.value.type);
var stopKeyType;
var stopDomainValues = {};
var previousStopDomainValue;
var previousStopDomainZoom;
var isZoomFunction = functionType !== 'categorical' && options.value.property === undefined;
var isPropertyFunction = !isZoomFunction;
var isZoomAndPropertyFunction = getType(options.value.stops) === 'array' && getType(options.value.stops[0]) === 'array' && getType(options.value.stops[0][0]) === 'object';
var errors = validateObject({
key: options.key,
value: options.value,
valueSpec: options.styleSpec.function,
style: options.style,
styleSpec: options.styleSpec,
objectElementValidators: {
stops: validateFunctionStops,
default: validateFunctionDefault
}
});
if (functionType === 'identity' && isZoomFunction) {
errors.push(new ValidationError(options.key, options.value, 'missing required property "property"'));
}
if (functionType !== 'identity' && !options.value.stops) {
errors.push(new ValidationError(options.key, options.value, 'missing required property "stops"'));
}
if (functionType === 'exponential' && options.valueSpec.expression && !supportsInterpolation(options.valueSpec)) {
errors.push(new ValidationError(options.key, options.value, 'exponential functions not supported'));
}
if (options.styleSpec.$version >= 8) {
if (isPropertyFunction && !supportsPropertyExpression(options.valueSpec)) {
errors.push(new ValidationError(options.key, options.value, 'property functions not supported'));
} else if (isZoomFunction && !supportsZoomExpression(options.valueSpec)) {
errors.push(new ValidationError(options.key, options.value, 'zoom functions not supported'));
}
}
if ((functionType === 'categorical' || isZoomAndPropertyFunction) && options.value.property === undefined) {
errors.push(new ValidationError(options.key, options.value, '"property" property is required'));
}
return errors;
function validateFunctionStops(options) {
if (functionType === 'identity') {
return [new ValidationError(options.key, options.value, 'identity function may not have a "stops" property')];
}
var errors = [];
var value = options.value;
errors = errors.concat(validateArray({
key: options.key,
value: value,
valueSpec: options.valueSpec,
style: options.style,
styleSpec: options.styleSpec,
arrayElementValidator: validateFunctionStop
}));
if (getType(value) === 'array' && value.length === 0) {
errors.push(new ValidationError(options.key, value, 'array must have at least one stop'));
}
return errors;
}
function validateFunctionStop(options) {
var errors = [];
var value = options.value;
var key = options.key;
if (getType(value) !== 'array') {
return [new ValidationError(key, value, 'array expected, ' + getType(value) + ' found')];
}
if (value.length !== 2) {
return [new ValidationError(key, value, 'array length 2 expected, length ' + value.length + ' found')];
}
if (isZoomAndPropertyFunction) {
if (getType(value[0]) !== 'object') {
return [new ValidationError(key, value, 'object expected, ' + getType(value[0]) + ' found')];
}
if (value[0].zoom === undefined) {
return [new ValidationError(key, value, 'object stop key must have zoom')];
}
if (value[0].value === undefined) {
return [new ValidationError(key, value, 'object stop key must have value')];
}
if (previousStopDomainZoom && previousStopDomainZoom > unbundle(value[0].zoom)) {
return [new ValidationError(key, value[0].zoom, 'stop zoom values must appear in ascending order')];
}
if (unbundle(value[0].zoom) !== previousStopDomainZoom) {
previousStopDomainZoom = unbundle(value[0].zoom);
previousStopDomainValue = undefined;
stopDomainValues = {};
}
errors = errors.concat(validateObject({
key: key + '[0]',
value: value[0],
valueSpec: { zoom: {} },
style: options.style,
styleSpec: options.styleSpec,
objectElementValidators: {
zoom: validateNumber,
value: validateStopDomainValue
}
}));
} else {
errors = errors.concat(validateStopDomainValue({
key: key + '[0]',
value: value[0],
valueSpec: {},
style: options.style,
styleSpec: options.styleSpec
}, value));
}
if (isExpression(deepUnbundle(value[1]))) {
return errors.concat([new ValidationError(key + '[1]', value[1], 'expressions are not allowed in function stops.')]);
}
return errors.concat(validate({
key: key + '[1]',
value: value[1],
valueSpec: functionValueSpec,
style: options.style,
styleSpec: options.styleSpec
}));
}
function validateStopDomainValue(options, stop) {
var type = getType(options.value);
var value = unbundle(options.value);
var reportValue = options.value !== null ? options.value : stop;
if (!stopKeyType) {
stopKeyType = type;
} else if (type !== stopKeyType) {
return [new ValidationError(options.key, reportValue, type + ' stop domain type must match previous stop domain type ' + stopKeyType)];
}
if (type !== 'number' && type !== 'string' && type !== 'boolean') {
return [new ValidationError(options.key, reportValue, 'stop domain value must be a number, string, or boolean')];
}
if (type !== 'number' && functionType !== 'categorical') {
var message = 'number expected, ' + type + ' found';
if (supportsPropertyExpression(functionValueSpec) && functionType === undefined) {
message += '\nIf you intended to use a categorical function, specify `"type": "categorical"`.';
}
return [new ValidationError(options.key, reportValue, message)];
}
if (functionType === 'categorical' && type === 'number' && (!isFinite(value) || Math.floor(value) !== value)) {
return [new ValidationError(options.key, reportValue, 'integer expected, found ' + value)];
}
if (functionType !== 'categorical' && type === 'number' && previousStopDomainValue !== undefined && value < previousStopDomainValue) {
return [new ValidationError(options.key, reportValue, 'stop domain values must appear in ascending order')];
} else {
previousStopDomainValue = value;
}
if (functionType === 'categorical' && value in stopDomainValues) {
return [new ValidationError(options.key, reportValue, 'stop domain values must be unique')];
} else {
stopDomainValues[value] = true;
}
return [];
}
function validateFunctionDefault(options) {
return validate({
key: options.key,
value: options.value,
valueSpec: functionValueSpec,
style: options.style,
styleSpec: options.styleSpec
});
}
}
function validateExpression(options) {
var expression = (options.expressionContext === 'property' ? createPropertyExpression : createExpression)(deepUnbundle(options.value), options.valueSpec);
if (expression.result === 'error') {
return expression.value.map(function (error) {
return new ValidationError('' + options.key + error.key, options.value, error.message);
});
}
var expressionObj = expression.value.expression || expression.value._styleExpression.expression;
if (options.expressionContext === 'property' && options.propertyKey === 'text-font' && !expressionObj.outputDefined()) {
return [new ValidationError(options.key, options.value, 'Invalid data expression for "' + options.propertyKey + '". Output values must be contained as literals within the expression.')];
}
if (options.expressionContext === 'property' && options.propertyType === 'layout' && !isStateConstant(expressionObj)) {
return [new ValidationError(options.key, options.value, '"feature-state" data expressions are not supported with layout properties.')];
}
if (options.expressionContext === 'filter' && !isStateConstant(expressionObj)) {
return [new ValidationError(options.key, options.value, '"feature-state" data expressions are not supported with filters.')];
}
if (options.expressionContext && options.expressionContext.indexOf('cluster') === 0) {
if (!isGlobalPropertyConstant(expressionObj, [
'zoom',
'feature-state'
])) {
return [new ValidationError(options.key, options.value, '"zoom" and "feature-state" expressions are not supported with cluster properties.')];
}
if (options.expressionContext === 'cluster-initial' && !isFeatureConstant(expressionObj)) {
return [new ValidationError(options.key, options.value, 'Feature data expressions are not supported with initial expression part of cluster properties.')];
}
}
return [];
}
function validateBoolean(options) {
var value = options.value;
var key = options.key;
var type = getType(value);
if (type !== 'boolean') {
return [new ValidationError(key, value, 'boolean expected, ' + type + ' found')];
}
return [];
}
function validateColor(options) {
var key = options.key;
var value = options.value;
var type = getType(value);
if (type !== 'string') {
return [new ValidationError(key, value, 'color expected, ' + type + ' found')];
}
if (csscolorparser_1(value) === null) {
return [new ValidationError(key, value, 'color expected, "' + value + '" found')];
}
return [];
}
function validateEnum(options) {
var key = options.key;
var value = options.value;
var valueSpec = options.valueSpec;
var errors = [];
if (Array.isArray(valueSpec.values)) {
if (valueSpec.values.indexOf(unbundle(value)) === -1) {
errors.push(new ValidationError(key, value, 'expected one of [' + valueSpec.values.join(', ') + '], ' + JSON.stringify(value) + ' found'));
}
} else {
if (Object.keys(valueSpec.values).indexOf(unbundle(value)) === -1) {
errors.push(new ValidationError(key, value, 'expected one of [' + Object.keys(valueSpec.values).join(', ') + '], ' + JSON.stringify(value) + ' found'));
}
}
return errors;
}
function isExpressionFilter(filter) {
if (filter === true || filter === false) {
return true;
}
if (!Array.isArray(filter) || filter.length === 0) {
return false;
}
switch (filter[0]) {
case 'has':
return filter.length >= 2 && filter[1] !== '$id' && filter[1] !== '$type';
case 'in':
return filter.length >= 3 && (typeof filter[1] !== 'string' || Array.isArray(filter[2]));
case '!in':
case '!has':
case 'none':
return false;
case '==':
case '!=':
case '>':
case '>=':
case '<':
case '<=':
return filter.length !== 3 || (Array.isArray(filter[1]) || Array.isArray(filter[2]));
case 'any':
case 'all':
for (var i = 0, list = filter.slice(1); i < list.length; i += 1) {
var f = list[i];
if (!isExpressionFilter(f) && typeof f !== 'boolean') {
return false;
}
}
return true;
default:
return true;
}
}
var filterSpec = {
'type': 'boolean',
'default': false,
'transition': false,
'property-type': 'data-driven',
'expression': {
'interpolated': false,
'parameters': [
'zoom',
'feature'
]
}
};
function createFilter(filter) {
if (filter === null || filter === undefined) {
return {
filter: function () {
return true;
},
needGeometry: false
};
}
if (!isExpressionFilter(filter)) {
filter = convertFilter(filter);
}
var compiled = createExpression(filter, filterSpec);
if (compiled.result === 'error') {
throw new Error(compiled.value.map(function (err) {
return err.key + ': ' + err.message;
}).join(', '));
} else {
var needGeometry = geometryNeeded(filter);
return {
filter: function (globalProperties, feature, canonical) {
return compiled.value.evaluate(globalProperties, feature, {}, canonical);
},
needGeometry: needGeometry
};
}
}
function compare(a, b) {
return a < b ? -1 : a > b ? 1 : 0;
}
function geometryNeeded(filter) {
if (!Array.isArray(filter)) {
return false;
}
if (filter[0] === 'within') {
return true;
}
for (var index = 1; index < filter.length; index++) {
if (geometryNeeded(filter[index])) {
return true;
}
}
return false;
}
function convertFilter(filter) {
if (!filter) {
return true;
}
var op = filter[0];
if (filter.length <= 1) {
return op !== 'any';
}
var converted = op === '==' ? convertComparisonOp(filter[1], filter[2], '==') : op === '!=' ? convertNegation(convertComparisonOp(filter[1], filter[2], '==')) : op === '<' || op === '>' || op === '<=' || op === '>=' ? convertComparisonOp(filter[1], filter[2], op) : op === 'any' ? convertDisjunctionOp(filter.slice(1)) : op === 'all' ? ['all'].concat(filter.slice(1).map(convertFilter)) : op === 'none' ? ['all'].concat(filter.slice(1).map(convertFilter).map(convertNegation)) : op === 'in' ? convertInOp(filter[1], filter.slice(2)) : op === '!in' ? convertNegation(convertInOp(filter[1], filter.slice(2))) : op === 'has' ? convertHasOp(filter[1]) : op === '!has' ? convertNegation(convertHasOp(filter[1])) : op === 'within' ? filter : true;
return converted;
}
function convertComparisonOp(property, value, op) {
switch (property) {
case '$type':
return [
'filter-type-' + op,
value
];
case '$id':
return [
'filter-id-' + op,
value
];
default:
return [
'filter-' + op,
property,
value
];
}
}
function convertDisjunctionOp(filters) {
return ['any'].concat(filters.map(convertFilter));
}
function convertInOp(property, values) {
if (values.length === 0) {
return false;
}
switch (property) {
case '$type':
return [
'filter-type-in',
[
'literal',
values
]
];
case '$id':
return [
'filter-id-in',
[
'literal',
values
]
];
default:
if (values.length > 200 && !values.some(function (v) {
return typeof v !== typeof values[0];
})) {
return [
'filter-in-large',
property,
[
'literal',
values.sort(compare)
]
];
} else {
return [
'filter-in-small',
property,
[
'literal',
values
]
];
}
}
}
function convertHasOp(property) {
switch (property) {
case '$type':
return true;
case '$id':
return ['filter-has-id'];
default:
return [
'filter-has',
property
];
}
}
function convertNegation(filter) {
return [
'!',
filter
];
}
function validateFilter(options) {
if (isExpressionFilter(deepUnbundle(options.value))) {
return validateExpression(extend$1({}, options, {
expressionContext: 'filter',
valueSpec: { value: 'boolean' }
}));
} else {
return validateNonExpressionFilter(options);
}
}
function validateNonExpressionFilter(options) {
var value = options.value;
var key = options.key;
if (getType(value) !== 'array') {
return [new ValidationError(key, value, 'array expected, ' + getType(value) + ' found')];
}
var styleSpec = options.styleSpec;
var type;
var errors = [];
if (value.length < 1) {
return [new ValidationError(key, value, 'filter array must have at least 1 element')];
}
errors = errors.concat(validateEnum({
key: key + '[0]',
value: value[0],
valueSpec: styleSpec.filter_operator,
style: options.style,
styleSpec: options.styleSpec
}));
switch (unbundle(value[0])) {
case '<':
case '<=':
case '>':
case '>=':
if (value.length >= 2 && unbundle(value[1]) === '$type') {
errors.push(new ValidationError(key, value, '"$type" cannot be use with operator "' + value[0] + '"'));
}
case '==':
case '!=':
if (value.length !== 3) {
errors.push(new ValidationError(key, value, 'filter array for operator "' + value[0] + '" must have 3 elements'));
}
case 'in':
case '!in':
if (value.length >= 2) {
type = getType(value[1]);
if (type !== 'string') {
errors.push(new ValidationError(key + '[1]', value[1], 'string expected, ' + type + ' found'));
}
}
for (var i = 2; i < value.length; i++) {
type = getType(value[i]);
if (unbundle(value[1]) === '$type') {
errors = errors.concat(validateEnum({
key: key + '[' + i + ']',
value: value[i],
valueSpec: styleSpec.geometry_type,
style: options.style,
styleSpec: options.styleSpec
}));
} else if (type !== 'string' && type !== 'number' && type !== 'boolean') {
errors.push(new ValidationError(key + '[' + i + ']', value[i], 'string, number, or boolean expected, ' + type + ' found'));
}
}
break;
case 'any':
case 'all':
case 'none':
for (var i$1 = 1; i$1 < value.length; i$1++) {
errors = errors.concat(validateNonExpressionFilter({
key: key + '[' + i$1 + ']',
value: value[i$1],
style: options.style,
styleSpec: options.styleSpec
}));
}
break;
case 'has':
case '!has':
type = getType(value[1]);
if (value.length !== 2) {
errors.push(new ValidationError(key, value, 'filter array for "' + value[0] + '" operator must have 2 elements'));
} else if (type !== 'string') {
errors.push(new ValidationError(key + '[1]', value[1], 'string expected, ' + type + ' found'));
}
break;
case 'within':
type = getType(value[1]);
if (value.length !== 2) {
errors.push(new ValidationError(key, value, 'filter array for "' + value[0] + '" operator must have 2 elements'));
} else if (type !== 'object') {
errors.push(new ValidationError(key + '[1]', value[1], 'object expected, ' + type + ' found'));
}
break;
}
return errors;
}
function validateProperty(options, propertyType) {
var key = options.key;
var style = options.style;
var styleSpec = options.styleSpec;
var value = options.value;
var propertyKey = options.objectKey;
var layerSpec = styleSpec[propertyType + '_' + options.layerType];
if (!layerSpec) {
return [];
}
var transitionMatch = propertyKey.match(/^(.*)-transition$/);
if (propertyType === 'paint' && transitionMatch && layerSpec[transitionMatch[1]] && layerSpec[transitionMatch[1]].transition) {
return validate({
key: key,
value: value,
valueSpec: styleSpec.transition,
style: style,
styleSpec: styleSpec
});
}
var valueSpec = options.valueSpec || layerSpec[propertyKey];
if (!valueSpec) {
return [new ValidationError(key, value, 'unknown property "' + propertyKey + '"')];
}
var tokenMatch;
if (getType(value) === 'string' && supportsPropertyExpression(valueSpec) && !valueSpec.tokens && (tokenMatch = /^{([^}]+)}$/.exec(value))) {
return [new ValidationError(key, value, '"' + propertyKey + '" does not support interpolation syntax\n' + 'Use an identity property function instead: `{ "type": "identity", "property": ' + JSON.stringify(tokenMatch[1]) + ' }`.')];
}
var errors = [];
if (options.layerType === 'symbol') {
if (propertyKey === 'text-field' && style && !style.glyphs) {
errors.push(new ValidationError(key, value, 'use of "text-field" requires a style "glyphs" property'));
}
if (propertyKey === 'text-font' && isFunction(deepUnbundle(value)) && unbundle(value.type) === 'identity') {
errors.push(new ValidationError(key, value, '"text-font" does not support identity functions'));
}
}
return errors.concat(validate({
key: options.key,
value: value,
valueSpec: valueSpec,
style: style,
styleSpec: styleSpec,
expressionContext: 'property',
propertyType: propertyType,
propertyKey: propertyKey
}));
}
function validatePaintProperty(options) {
return validateProperty(options, 'paint');
}
function validateLayoutProperty(options) {
return validateProperty(options, 'layout');
}
function validateLayer(options) {
var errors = [];
var layer = options.value;
var key = options.key;
var style = options.style;
var styleSpec = options.styleSpec;
if (!layer.type && !layer.ref) {
errors.push(new ValidationError(key, layer, 'either "type" or "ref" is required'));
}
var type = unbundle(layer.type);
var ref = unbundle(layer.ref);
if (layer.id) {
var layerId = unbundle(layer.id);
for (var i = 0; i < options.arrayIndex; i++) {
var otherLayer = style.layers[i];
if (unbundle(otherLayer.id) === layerId) {
errors.push(new ValidationError(key, layer.id, 'duplicate layer id "' + layer.id + '", previously used at line ' + otherLayer.id.__line__));
}
}
}
if ('ref' in layer) {
[
'type',
'source',
'source-layer',
'filter',
'layout'
].forEach(function (p) {
if (p in layer) {
errors.push(new ValidationError(key, layer[p], '"' + p + '" is prohibited for ref layers'));
}
});
var parent;
style.layers.forEach(function (layer) {
if (unbundle(layer.id) === ref) {
parent = layer;
}
});
if (!parent) {
errors.push(new ValidationError(key, layer.ref, 'ref layer "' + ref + '" not found'));
} else if (parent.ref) {
errors.push(new ValidationError(key, layer.ref, 'ref cannot reference another ref layer'));
} else {
type = unbundle(parent.type);
}
} else if (type !== 'background') {
if (!layer.source) {
errors.push(new ValidationError(key, layer, 'missing required property "source"'));
} else {
var source = style.sources && style.sources[layer.source];
var sourceType = source && unbundle(source.type);
if (!source) {
errors.push(new ValidationError(key, layer.source, 'source "' + layer.source + '" not found'));
} else if (sourceType === 'vector' && type === 'raster') {
errors.push(new ValidationError(key, layer.source, 'layer "' + layer.id + '" requires a raster source'));
} else if (sourceType === 'raster' && type !== 'raster') {
errors.push(new ValidationError(key, layer.source, 'layer "' + layer.id + '" requires a vector source'));
} else if (sourceType === 'vector' && !layer['source-layer']) {
errors.push(new ValidationError(key, layer, 'layer "' + layer.id + '" must specify a "source-layer"'));
} else if (sourceType === 'raster-dem' && type !== 'hillshade') {
errors.push(new ValidationError(key, layer.source, 'raster-dem source can only be used with layer type \'hillshade\'.'));
} else if (type === 'line' && layer.paint && layer.paint['line-gradient'] && (sourceType !== 'geojson' || !source.lineMetrics)) {
errors.push(new ValidationError(key, layer, 'layer "' + layer.id + '" specifies a line-gradient, which requires a GeoJSON source with `lineMetrics` enabled.'));
}
}
}
errors = errors.concat(validateObject({
key: key,
value: layer,
valueSpec: styleSpec.layer,
style: options.style,
styleSpec: options.styleSpec,
objectElementValidators: {
'*': function _() {
return [];
},
type: function type() {
return validate({
key: key + '.type',
value: layer.type,
valueSpec: styleSpec.layer.type,
style: options.style,
styleSpec: options.styleSpec,
object: layer,
objectKey: 'type'
});
},
filter: validateFilter,
layout: function layout(options) {
return validateObject({
layer: layer,
key: options.key,
value: options.value,
style: options.style,
styleSpec: options.styleSpec,
objectElementValidators: {
'*': function _(options) {
return validateLayoutProperty(extend$1({ layerType: type }, options));
}
}
});
},
paint: function paint(options) {
return validateObject({
layer: layer,
key: options.key,
value: options.value,
style: options.style,
styleSpec: options.styleSpec,
objectElementValidators: {
'*': function _(options) {
return validatePaintProperty(extend$1({ layerType: type }, options));
}
}
});
}
}
}));
return errors;
}
function validateString(options) {
var value = options.value;
var key = options.key;
var type = getType(value);
if (type !== 'string') {
return [new ValidationError(key, value, 'string expected, ' + type + ' found')];
}
return [];
}
var objectElementValidators = { promoteId: validatePromoteId };
function validateSource(options) {
var value = options.value;
var key = options.key;
var styleSpec = options.styleSpec;
var style = options.style;
if (!value.type) {
return [new ValidationError(key, value, '"type" is required')];
}
var type = unbundle(value.type);
var errors;
switch (type) {
case 'vector':
case 'raster':
case 'raster-dem':
errors = validateObject({
key: key,
value: value,
valueSpec: styleSpec['source_' + type.replace('-', '_')],
style: options.style,
styleSpec: styleSpec,
objectElementValidators: objectElementValidators
});
return errors;
case 'geojson':
errors = validateObject({
key: key,
value: value,
valueSpec: styleSpec.source_geojson,
style: style,
styleSpec: styleSpec,
objectElementValidators: objectElementValidators
});
if (value.cluster) {
for (var prop in value.clusterProperties) {
var ref = value.clusterProperties[prop];
var operator = ref[0];
var mapExpr = ref[1];
var reduceExpr = typeof operator === 'string' ? [
operator,
['accumulated'],
[
'get',
prop
]
] : operator;
errors.push.apply(errors, validateExpression({
key: key + '.' + prop + '.map',
value: mapExpr,
expressionContext: 'cluster-map'
}));
errors.push.apply(errors, validateExpression({
key: key + '.' + prop + '.reduce',
value: reduceExpr,
expressionContext: 'cluster-reduce'
}));
}
}
return errors;
case 'video':
return validateObject({
key: key,
value: value,
valueSpec: styleSpec.source_video,
style: style,
styleSpec: styleSpec
});
case 'image':
return validateObject({
key: key,
value: value,
valueSpec: styleSpec.source_image,
style: style,
styleSpec: styleSpec
});
case 'canvas':
return [new ValidationError(key, null, 'Please use runtime APIs to add canvas sources, rather than including them in stylesheets.', 'source.canvas')];
default:
return validateEnum({
key: key + '.type',
value: value.type,
valueSpec: {
values: [
'vector',
'raster',
'raster-dem',
'geojson',
'video',
'image'
]
},
style: style,
styleSpec: styleSpec
});
}
}
function validatePromoteId(ref) {
var key = ref.key;
var value = ref.value;
if (getType(value) === 'string') {
return validateString({
key: key,
value: value
});
} else {
var errors = [];
for (var prop in value) {
errors.push.apply(errors, validateString({
key: key + '.' + prop,
value: value[prop]
}));
}
return errors;
}
}
function validateLight(options) {
var light = options.value;
var styleSpec = options.styleSpec;
var lightSpec = styleSpec.light;
var style = options.style;
var errors = [];
var rootType = getType(light);
if (light === undefined) {
return errors;
} else if (rootType !== 'object') {
errors = errors.concat([new ValidationError('light', light, 'object expected, ' + rootType + ' found')]);
return errors;
}
for (var key in light) {
var transitionMatch = key.match(/^(.*)-transition$/);
if (transitionMatch && lightSpec[transitionMatch[1]] && lightSpec[transitionMatch[1]].transition) {
errors = errors.concat(validate({
key: key,
value: light[key],
valueSpec: styleSpec.transition,
style: style,
styleSpec: styleSpec
}));
} else if (lightSpec[key]) {
errors = errors.concat(validate({
key: key,
value: light[key],
valueSpec: lightSpec[key],
style: style,
styleSpec: styleSpec
}));
} else {
errors = errors.concat([new ValidationError(key, light[key], 'unknown property "' + key + '"')]);
}
}
return errors;
}
function validateFormatted(options) {
if (validateString(options).length === 0) {
return [];
}
return validateExpression(options);
}
function validateImage(options) {
if (validateString(options).length === 0) {
return [];
}
return validateExpression(options);
}
var VALIDATORS = {
'*': function _() {
return [];
},
'array': validateArray,
'boolean': validateBoolean,
'number': validateNumber,
'color': validateColor,
'constants': validateConstants,
'enum': validateEnum,
'filter': validateFilter,
'function': validateFunction,
'layer': validateLayer,
'object': validateObject,
'source': validateSource,
'light': validateLight,
'string': validateString,
'formatted': validateFormatted,
'resolvedImage': validateImage
};
function validate(options) {
var value = options.value;
var valueSpec = options.valueSpec;
var styleSpec = options.styleSpec;
if (valueSpec.expression && isFunction(unbundle(value))) {
return validateFunction(options);
} else if (valueSpec.expression && isExpression(deepUnbundle(value))) {
return validateExpression(options);
} else if (valueSpec.type && VALIDATORS[valueSpec.type]) {
return VALIDATORS[valueSpec.type](options);
} else {
var valid = validateObject(extend$1({}, options, { valueSpec: valueSpec.type ? styleSpec[valueSpec.type] : valueSpec }));
return valid;
}
}
function validateGlyphsURL (options) {
var value = options.value;
var key = options.key;
var errors = validateString(options);
if (errors.length) {
return errors;
}
if (value.indexOf('{fontstack}') === -1) {
errors.push(new ValidationError(key, value, '"glyphs" url must include a "{fontstack}" token'));
}
if (value.indexOf('{range}') === -1) {
errors.push(new ValidationError(key, value, '"glyphs" url must include a "{range}" token'));
}
return errors;
}
function validateStyleMin(style, styleSpec) {
if (styleSpec === void 0)
styleSpec = spec;
var errors = [];
errors = errors.concat(validate({
key: '',
value: style,
valueSpec: styleSpec.$root,
styleSpec: styleSpec,
style: style,
objectElementValidators: {
glyphs: validateGlyphsURL,
'*': function _() {
return [];
}
}
}));
if (style.constants) {
errors = errors.concat(validateConstants({
key: 'constants',
value: style.constants,
style: style,
styleSpec: styleSpec
}));
}
return sortErrors(errors);
}
validateStyleMin.source = wrapCleanErrors(validateSource);
validateStyleMin.light = wrapCleanErrors(validateLight);
validateStyleMin.layer = wrapCleanErrors(validateLayer);
validateStyleMin.filter = wrapCleanErrors(validateFilter);
validateStyleMin.paintProperty = wrapCleanErrors(validatePaintProperty);
validateStyleMin.layoutProperty = wrapCleanErrors(validateLayoutProperty);
function sortErrors(errors) {
return [].concat(errors).sort(function (a, b) {
return a.line - b.line;
});
}
function wrapCleanErrors(inner) {
return function () {
var args = [], len = arguments.length;
while (len--)
args[len] = arguments[len];
return sortErrors(inner.apply(this, args));
};
}
var validateStyle = validateStyleMin;
var validateLight$1 = validateStyle.light;
var validatePaintProperty$1 = validateStyle.paintProperty;
var validateLayoutProperty$1 = validateStyle.layoutProperty;
function emitValidationErrors(emitter, errors) {
var hasErrors = false;
if (errors && errors.length) {
for (var i = 0, list = errors; i < list.length; i += 1) {
var error = list[i];
emitter.fire(new ErrorEvent(new Error(error.message)));
hasErrors = true;
}
}
return hasErrors;
}
var gridIndex = GridIndex;
var NUM_PARAMS = 3;
function GridIndex(extent, n, padding) {
var cells = this.cells = [];
if (extent instanceof ArrayBuffer) {
this.arrayBuffer = extent;
var array = new Int32Array(this.arrayBuffer);
extent = array[0];
n = array[1];
padding = array[2];
this.d = n + 2 * padding;
for (var k = 0; k < this.d * this.d; k++) {
var start = array[NUM_PARAMS + k];
var end = array[NUM_PARAMS + k + 1];
cells.push(start === end ? null : array.subarray(start, end));
}
var keysOffset = array[NUM_PARAMS + cells.length];
var bboxesOffset = array[NUM_PARAMS + cells.length + 1];
this.keys = array.subarray(keysOffset, bboxesOffset);
this.bboxes = array.subarray(bboxesOffset);
this.insert = this._insertReadonly;
} else {
this.d = n + 2 * padding;
for (var i = 0; i < this.d * this.d; i++) {
cells.push([]);
}
this.keys = [];
this.bboxes = [];
}
this.n = n;
this.extent = extent;
this.padding = padding;
this.scale = n / extent;
this.uid = 0;
var p = padding / n * extent;
this.min = -p;
this.max = extent + p;
}
GridIndex.prototype.insert = function (key, x1, y1, x2, y2) {
this._forEachCell(x1, y1, x2, y2, this._insertCell, this.uid++);
this.keys.push(key);
this.bboxes.push(x1);
this.bboxes.push(y1);
this.bboxes.push(x2);
this.bboxes.push(y2);
};
GridIndex.prototype._insertReadonly = function () {
throw 'Cannot insert into a GridIndex created from an ArrayBuffer.';
};
GridIndex.prototype._insertCell = function (x1, y1, x2, y2, cellIndex, uid) {
this.cells[cellIndex].push(uid);
};
GridIndex.prototype.query = function (x1, y1, x2, y2, intersectionTest) {
var min = this.min;
var max = this.max;
if (x1 <= min && y1 <= min && max <= x2 && max <= y2 && !intersectionTest) {
return Array.prototype.slice.call(this.keys);
} else {
var result = [];
var seenUids = {};
this._forEachCell(x1, y1, x2, y2, this._queryCell, result, seenUids, intersectionTest);
return result;
}
};
GridIndex.prototype._queryCell = function (x1, y1, x2, y2, cellIndex, result, seenUids, intersectionTest) {
var cell = this.cells[cellIndex];
if (cell !== null) {
var keys = this.keys;
var bboxes = this.bboxes;
for (var u = 0; u < cell.length; u++) {
var uid = cell[u];
if (seenUids[uid] === undefined) {
var offset = uid * 4;
if (intersectionTest ? intersectionTest(bboxes[offset + 0], bboxes[offset + 1], bboxes[offset + 2], bboxes[offset + 3]) : x1 <= bboxes[offset + 2] && y1 <= bboxes[offset + 3] && x2 >= bboxes[offset + 0] && y2 >= bboxes[offset + 1]) {
seenUids[uid] = true;
result.push(keys[uid]);
} else {
seenUids[uid] = false;
}
}
}
}
};
GridIndex.prototype._forEachCell = function (x1, y1, x2, y2, fn, arg1, arg2, intersectionTest) {
var cx1 = this._convertToCellCoord(x1);
var cy1 = this._convertToCellCoord(y1);
var cx2 = this._convertToCellCoord(x2);
var cy2 = this._convertToCellCoord(y2);
for (var x = cx1; x <= cx2; x++) {
for (var y = cy1; y <= cy2; y++) {
var cellIndex = this.d * y + x;
if (intersectionTest && !intersectionTest(this._convertFromCellCoord(x), this._convertFromCellCoord(y), this._convertFromCellCoord(x + 1), this._convertFromCellCoord(y + 1))) {
continue;
}
if (fn.call(this, x1, y1, x2, y2, cellIndex, arg1, arg2, intersectionTest)) {
return;
}
}
}
};
GridIndex.prototype._convertFromCellCoord = function (x) {
return (x - this.padding) / this.scale;
};
GridIndex.prototype._convertToCellCoord = function (x) {
return Math.max(0, Math.min(this.d - 1, Math.floor(x * this.scale) + this.padding));
};
GridIndex.prototype.toArrayBuffer = function () {
if (this.arrayBuffer) {
return this.arrayBuffer;
}
var cells = this.cells;
var metadataLength = NUM_PARAMS + this.cells.length + 1 + 1;
var totalCellLength = 0;
for (var i = 0; i < this.cells.length; i++) {
totalCellLength += this.cells[i].length;
}
var array = new Int32Array(metadataLength + totalCellLength + this.keys.length + this.bboxes.length);
array[0] = this.extent;
array[1] = this.n;
array[2] = this.padding;
var offset = metadataLength;
for (var k = 0; k < cells.length; k++) {
var cell = cells[k];
array[NUM_PARAMS + k] = offset;
array.set(cell, offset);
offset += cell.length;
}
array[NUM_PARAMS + cells.length] = offset;
array.set(this.keys, offset);
offset += this.keys.length;
array[NUM_PARAMS + cells.length + 1] = offset;
array.set(this.bboxes, offset);
offset += this.bboxes.length;
return array.buffer;
};
var ImageData = window$1.ImageData;
var ImageBitmap = window$1.ImageBitmap;
var registry = {};
function register(name, klass, options) {
if (options === void 0)
options = {};
Object.defineProperty(klass, '_classRegistryKey', {
value: name,
writeable: false
});
registry[name] = {
klass: klass,
omit: options.omit || [],
shallow: options.shallow || []
};
}
register('Object', Object);
gridIndex.serialize = function serialize(grid, transferables) {
var buffer = grid.toArrayBuffer();
if (transferables) {
transferables.push(buffer);
}
return { buffer: buffer };
};
gridIndex.deserialize = function deserialize(serialized) {
return new gridIndex(serialized.buffer);
};
register('Grid', gridIndex);
register('Color', Color);
register('Error', Error);
register('ResolvedImage', ResolvedImage);
register('StylePropertyFunction', StylePropertyFunction);
register('StyleExpression', StyleExpression, { omit: ['_evaluator'] });
register('ZoomDependentExpression', ZoomDependentExpression);
register('ZoomConstantExpression', ZoomConstantExpression);
register('CompoundExpression', CompoundExpression, { omit: ['_evaluate'] });
for (var name in expressions) {
if (expressions[name]._classRegistryKey) {
continue;
}
register('Expression_' + name, expressions[name]);
}
function isArrayBuffer(val) {
return val && typeof ArrayBuffer !== 'undefined' && (val instanceof ArrayBuffer || val.constructor && val.constructor.name === 'ArrayBuffer');
}
function isImageBitmap(val) {
return ImageBitmap && val instanceof ImageBitmap;
}
function serialize(input, transferables) {
if (input === null || input === undefined || typeof input === 'boolean' || typeof input === 'number' || typeof input === 'string' || input instanceof Boolean || input instanceof Number || input instanceof String || input instanceof Date || input instanceof RegExp) {
return input;
}
if (isArrayBuffer(input) || isImageBitmap(input)) {
if (transferables) {
transferables.push(input);
}
return input;
}
if (ArrayBuffer.isView(input)) {
var view = input;
if (transferables) {
transferables.push(view.buffer);
}
return view;
}
if (input instanceof ImageData) {
if (transferables) {
transferables.push(input.data.buffer);
}
return input;
}
if (Array.isArray(input)) {
var serialized = [];
for (var i = 0, list = input; i < list.length; i += 1) {
var item = list[i];
serialized.push(serialize(item, transferables));
}
return serialized;
}
if (typeof input === 'object') {
var klass = input.constructor;
var name = klass._classRegistryKey;
if (!name) {
throw new Error('can\'t serialize object of unregistered class');
}
var properties = klass.serialize ? klass.serialize(input, transferables) : {};
if (!klass.serialize) {
for (var key in input) {
if (!input.hasOwnProperty(key)) {
continue;
}
if (registry[name].omit.indexOf(key) >= 0) {
continue;
}
var property = input[key];
properties[key] = registry[name].shallow.indexOf(key) >= 0 ? property : serialize(property, transferables);
}
if (input instanceof Error) {
properties.message = input.message;
}
}
if (properties.$name) {
throw new Error('$name property is reserved for worker serialization logic.');
}
if (name !== 'Object') {
properties.$name = name;
}
return properties;
}
throw new Error('can\'t serialize object of type ' + typeof input);
}
function deserialize(input) {
if (input === null || input === undefined || typeof input === 'boolean' || typeof input === 'number' || typeof input === 'string' || input instanceof Boolean || input instanceof Number || input instanceof String || input instanceof Date || input instanceof RegExp || isArrayBuffer(input) || isImageBitmap(input) || ArrayBuffer.isView(input) || input instanceof ImageData) {
return input;
}
if (Array.isArray(input)) {
return input.map(deserialize);
}
if (typeof input === 'object') {
var name = input.$name || 'Object';
var ref = registry[name];
var klass = ref.klass;
if (!klass) {
throw new Error('can\'t deserialize unregistered class ' + name);
}
if (klass.deserialize) {
return klass.deserialize(input);
}
var result = Object.create(klass.prototype);
for (var i = 0, list = Object.keys(input); i < list.length; i += 1) {
var key = list[i];
if (key === '$name') {
continue;
}
var value = input[key];
result[key] = registry[name].shallow.indexOf(key) >= 0 ? value : deserialize(value);
}
return result;
}
throw new Error('can\'t deserialize object of type ' + typeof input);
}
var ZoomHistory = function ZoomHistory() {
this.first = true;
};
ZoomHistory.prototype.update = function update(z, now) {
var floorZ = Math.floor(z);
if (this.first) {
this.first = false;
this.lastIntegerZoom = floorZ;
this.lastIntegerZoomTime = 0;
this.lastZoom = z;
this.lastFloorZoom = floorZ;
return true;
}
if (this.lastFloorZoom > floorZ) {
this.lastIntegerZoom = floorZ + 1;
this.lastIntegerZoomTime = now;
} else if (this.lastFloorZoom < floorZ) {
this.lastIntegerZoom = floorZ;
this.lastIntegerZoomTime = now;
}
if (z !== this.lastZoom) {
this.lastZoom = z;
this.lastFloorZoom = floorZ;
return true;
}
return false;
};
var unicodeBlockLookup = {
'Latin-1 Supplement': function (char) {
return char >= 128 && char <= 255;
},
'Arabic': function (char) {
return char >= 1536 && char <= 1791;
},
'Arabic Supplement': function (char) {
return char >= 1872 && char <= 1919;
},
'Arabic Extended-A': function (char) {
return char >= 2208 && char <= 2303;
},
'Hangul Jamo': function (char) {
return char >= 4352 && char <= 4607;
},
'Unified Canadian Aboriginal Syllabics': function (char) {
return char >= 5120 && char <= 5759;
},
'Khmer': function (char) {
return char >= 6016 && char <= 6143;
},
'Unified Canadian Aboriginal Syllabics Extended': function (char) {
return char >= 6320 && char <= 6399;
},
'General Punctuation': function (char) {
return char >= 8192 && char <= 8303;
},
'Letterlike Symbols': function (char) {
return char >= 8448 && char <= 8527;
},
'Number Forms': function (char) {
return char >= 8528 && char <= 8591;
},
'Miscellaneous Technical': function (char) {
return char >= 8960 && char <= 9215;
},
'Control Pictures': function (char) {
return char >= 9216 && char <= 9279;
},
'Optical Character Recognition': function (char) {
return char >= 9280 && char <= 9311;
},
'Enclosed Alphanumerics': function (char) {
return char >= 9312 && char <= 9471;
},
'Geometric Shapes': function (char) {
return char >= 9632 && char <= 9727;
},
'Miscellaneous Symbols': function (char) {
return char >= 9728 && char <= 9983;
},
'Miscellaneous Symbols and Arrows': function (char) {
return char >= 11008 && char <= 11263;
},
'CJK Radicals Supplement': function (char) {
return char >= 11904 && char <= 12031;
},
'Kangxi Radicals': function (char) {
return char >= 12032 && char <= 12255;
},
'Ideographic Description Characters': function (char) {
return char >= 12272 && char <= 12287;
},
'CJK Symbols and Punctuation': function (char) {
return char >= 12288 && char <= 12351;
},
'Hiragana': function (char) {
return char >= 12352 && char <= 12447;
},
'Katakana': function (char) {
return char >= 12448 && char <= 12543;
},
'Bopomofo': function (char) {
return char >= 12544 && char <= 12591;
},
'Hangul Compatibility Jamo': function (char) {
return char >= 12592 && char <= 12687;
},
'Kanbun': function (char) {
return char >= 12688 && char <= 12703;
},
'Bopomofo Extended': function (char) {
return char >= 12704 && char <= 12735;
},
'CJK Strokes': function (char) {
return char >= 12736 && char <= 12783;
},
'Katakana Phonetic Extensions': function (char) {
return char >= 12784 && char <= 12799;
},
'Enclosed CJK Letters and Months': function (char) {
return char >= 12800 && char <= 13055;
},
'CJK Compatibility': function (char) {
return char >= 13056 && char <= 13311;
},
'CJK Unified Ideographs Extension A': function (char) {
return char >= 13312 && char <= 19903;
},
'Yijing Hexagram Symbols': function (char) {
return char >= 19904 && char <= 19967;
},
'CJK Unified Ideographs': function (char) {
return char >= 19968 && char <= 40959;
},
'Yi Syllables': function (char) {
return char >= 40960 && char <= 42127;
},
'Yi Radicals': function (char) {
return char >= 42128 && char <= 42191;
},
'Hangul Jamo Extended-A': function (char) {
return char >= 43360 && char <= 43391;
},
'Hangul Syllables': function (char) {
return char >= 44032 && char <= 55215;
},
'Hangul Jamo Extended-B': function (char) {
return char >= 55216 && char <= 55295;
},
'Private Use Area': function (char) {
return char >= 57344 && char <= 63743;
},
'CJK Compatibility Ideographs': function (char) {
return char >= 63744 && char <= 64255;
},
'Arabic Presentation Forms-A': function (char) {
return char >= 64336 && char <= 65023;
},
'Vertical Forms': function (char) {
return char >= 65040 && char <= 65055;
},
'CJK Compatibility Forms': function (char) {
return char >= 65072 && char <= 65103;
},
'Small Form Variants': function (char) {
return char >= 65104 && char <= 65135;
},
'Arabic Presentation Forms-B': function (char) {
return char >= 65136 && char <= 65279;
},
'Halfwidth and Fullwidth Forms': function (char) {
return char >= 65280 && char <= 65519;
}
};
function allowsVerticalWritingMode(chars) {
for (var i = 0, list = chars; i < list.length; i += 1) {
var char = list[i];
if (charHasUprightVerticalOrientation(char.charCodeAt(0))) {
return true;
}
}
return false;
}
function allowsLetterSpacing(chars) {
for (var i = 0, list = chars; i < list.length; i += 1) {
var char = list[i];
if (!charAllowsLetterSpacing(char.charCodeAt(0))) {
return false;
}
}
return true;
}
function charAllowsLetterSpacing(char) {
if (unicodeBlockLookup['Arabic'](char)) {
return false;
}
if (unicodeBlockLookup['Arabic Supplement'](char)) {
return false;
}
if (unicodeBlockLookup['Arabic Extended-A'](char)) {
return false;
}
if (unicodeBlockLookup['Arabic Presentation Forms-A'](char)) {
return false;
}
if (unicodeBlockLookup['Arabic Presentation Forms-B'](char)) {
return false;
}
return true;
}
function charAllowsIdeographicBreaking(char) {
if (char < 11904) {
return false;
}
if (unicodeBlockLookup['Bopomofo Extended'](char)) {
return true;
}
if (unicodeBlockLookup['Bopomofo'](char)) {
return true;
}
if (unicodeBlockLookup['CJK Compatibility Forms'](char)) {
return true;
}
if (unicodeBlockLookup['CJK Compatibility Ideographs'](char)) {
return true;
}
if (unicodeBlockLookup['CJK Compatibility'](char)) {
return true;
}
if (unicodeBlockLookup['CJK Radicals Supplement'](char)) {
return true;
}
if (unicodeBlockLookup['CJK Strokes'](char)) {
return true;
}
if (unicodeBlockLookup['CJK Symbols and Punctuation'](char)) {
return true;
}
if (unicodeBlockLookup['CJK Unified Ideographs Extension A'](char)) {
return true;
}
if (unicodeBlockLookup['CJK Unified Ideographs'](char)) {
return true;
}
if (unicodeBlockLookup['Enclosed CJK Letters and Months'](char)) {
return true;
}
if (unicodeBlockLookup['Halfwidth and Fullwidth Forms'](char)) {
return true;
}
if (unicodeBlockLookup['Hiragana'](char)) {
return true;
}
if (unicodeBlockLookup['Ideographic Description Characters'](char)) {
return true;
}
if (unicodeBlockLookup['Kangxi Radicals'](char)) {
return true;
}
if (unicodeBlockLookup['Katakana Phonetic Extensions'](char)) {
return true;
}
if (unicodeBlockLookup['Katakana'](char)) {
return true;
}
if (unicodeBlockLookup['Vertical Forms'](char)) {
return true;
}
if (unicodeBlockLookup['Yi Radicals'](char)) {
return true;
}
if (unicodeBlockLookup['Yi Syllables'](char)) {
return true;
}
return false;
}
function charHasUprightVerticalOrientation(char) {
if (char === 746 || char === 747) {
return true;
}
if (char < 4352) {
return false;
}
if (unicodeBlockLookup['Bopomofo Extended'](char)) {
return true;
}
if (unicodeBlockLookup['Bopomofo'](char)) {
return true;
}
if (unicodeBlockLookup['CJK Compatibility Forms'](char)) {
if (!(char >= 65097 && char <= 65103)) {
return true;
}
}
if (unicodeBlockLookup['CJK Compatibility Ideographs'](char)) {
return true;
}
if (unicodeBlockLookup['CJK Compatibility'](char)) {
return true;
}
if (unicodeBlockLookup['CJK Radicals Supplement'](char)) {
return true;
}
if (unicodeBlockLookup['CJK Strokes'](char)) {
return true;
}
if (unicodeBlockLookup['CJK Symbols and Punctuation'](char)) {
if (!(char >= 12296 && char <= 12305) && !(char >= 12308 && char <= 12319) && char !== 12336) {
return true;
}
}
if (unicodeBlockLookup['CJK Unified Ideographs Extension A'](char)) {
return true;
}
if (unicodeBlockLookup['CJK Unified Ideographs'](char)) {
return true;
}
if (unicodeBlockLookup['Enclosed CJK Letters and Months'](char)) {
return true;
}
if (unicodeBlockLookup['Hangul Compatibility Jamo'](char)) {
return true;
}
if (unicodeBlockLookup['Hangul Jamo Extended-A'](char)) {
return true;
}
if (unicodeBlockLookup['Hangul Jamo Extended-B'](char)) {
return true;
}
if (unicodeBlockLookup['Hangul Jamo'](char)) {
return true;
}
if (unicodeBlockLookup['Hangul Syllables'](char)) {
return true;
}
if (unicodeBlockLookup['Hiragana'](char)) {
return true;
}
if (unicodeBlockLookup['Ideographic Description Characters'](char)) {
return true;
}
if (unicodeBlockLookup['Kanbun'](char)) {
return true;
}
if (unicodeBlockLookup['Kangxi Radicals'](char)) {
return true;
}
if (unicodeBlockLookup['Katakana Phonetic Extensions'](char)) {
return true;
}
if (unicodeBlockLookup['Katakana'](char)) {
if (char !== 12540) {
return true;
}
}
if (unicodeBlockLookup['Halfwidth and Fullwidth Forms'](char)) {
if (char !== 65288 && char !== 65289 && char !== 65293 && !(char >= 65306 && char <= 65310) && char !== 65339 && char !== 65341 && char !== 65343 && !(char >= 65371 && char <= 65503) && char !== 65507 && !(char >= 65512 && char <= 65519)) {
return true;
}
}
if (unicodeBlockLookup['Small Form Variants'](char)) {
if (!(char >= 65112 && char <= 65118) && !(char >= 65123 && char <= 65126)) {
return true;
}
}
if (unicodeBlockLookup['Unified Canadian Aboriginal Syllabics'](char)) {
return true;
}
if (unicodeBlockLookup['Unified Canadian Aboriginal Syllabics Extended'](char)) {
return true;
}
if (unicodeBlockLookup['Vertical Forms'](char)) {
return true;
}
if (unicodeBlockLookup['Yijing Hexagram Symbols'](char)) {
return true;
}
if (unicodeBlockLookup['Yi Syllables'](char)) {
return true;
}
if (unicodeBlockLookup['Yi Radicals'](char)) {
return true;
}
return false;
}
function charHasNeutralVerticalOrientation(char) {
if (unicodeBlockLookup['Latin-1 Supplement'](char)) {
if (char === 167 || char === 169 || char === 174 || char === 177 || char === 188 || char === 189 || char === 190 || char === 215 || char === 247) {
return true;
}
}
if (unicodeBlockLookup['General Punctuation'](char)) {
if (char === 8214 || char === 8224 || char === 8225 || char === 8240 || char === 8241 || char === 8251 || char === 8252 || char === 8258 || char === 8263 || char === 8264 || char === 8265 || char === 8273) {
return true;
}
}
if (unicodeBlockLookup['Letterlike Symbols'](char)) {
return true;
}
if (unicodeBlockLookup['Number Forms'](char)) {
return true;
}
if (unicodeBlockLookup['Miscellaneous Technical'](char)) {
if (char >= 8960 && char <= 8967 || char >= 8972 && char <= 8991 || char >= 8996 && char <= 9000 || char === 9003 || char >= 9085 && char <= 9114 || char >= 9150 && char <= 9165 || char === 9167 || char >= 9169 && char <= 9179 || char >= 9186 && char <= 9215) {
return true;
}
}
if (unicodeBlockLookup['Control Pictures'](char) && char !== 9251) {
return true;
}
if (unicodeBlockLookup['Optical Character Recognition'](char)) {
return true;
}
if (unicodeBlockLookup['Enclosed Alphanumerics'](char)) {
return true;
}
if (unicodeBlockLookup['Geometric Shapes'](char)) {
return true;
}
if (unicodeBlockLookup['Miscellaneous Symbols'](char)) {
if (!(char >= 9754 && char <= 9759)) {
return true;
}
}
if (unicodeBlockLookup['Miscellaneous Symbols and Arrows'](char)) {
if (char >= 11026 && char <= 11055 || char >= 11088 && char <= 11097 || char >= 11192 && char <= 11243) {
return true;
}
}
if (unicodeBlockLookup['CJK Symbols and Punctuation'](char)) {
return true;
}
if (unicodeBlockLookup['Katakana'](char)) {
return true;
}
if (unicodeBlockLookup['Private Use Area'](char)) {
return true;
}
if (unicodeBlockLookup['CJK Compatibility Forms'](char)) {
return true;
}
if (unicodeBlockLookup['Small Form Variants'](char)) {
return true;
}
if (unicodeBlockLookup['Halfwidth and Fullwidth Forms'](char)) {
return true;
}
if (char === 8734 || char === 8756 || char === 8757 || char >= 9984 && char <= 10087 || char >= 10102 && char <= 10131 || char === 65532 || char === 65533) {
return true;
}
return false;
}
function charHasRotatedVerticalOrientation(char) {
return !(charHasUprightVerticalOrientation(char) || charHasNeutralVerticalOrientation(char));
}
function charInComplexShapingScript(char) {
return unicodeBlockLookup['Arabic'](char) || unicodeBlockLookup['Arabic Supplement'](char) || unicodeBlockLookup['Arabic Extended-A'](char) || unicodeBlockLookup['Arabic Presentation Forms-A'](char) || unicodeBlockLookup['Arabic Presentation Forms-B'](char);
}
function charInRTLScript(char) {
return char >= 1424 && char <= 2303 || unicodeBlockLookup['Arabic Presentation Forms-A'](char) || unicodeBlockLookup['Arabic Presentation Forms-B'](char);
}
function charInSupportedScript(char, canRenderRTL) {
if (!canRenderRTL && charInRTLScript(char)) {
return false;
}
if (char >= 2304 && char <= 3583 || char >= 3840 && char <= 4255 || unicodeBlockLookup['Khmer'](char)) {
return false;
}
return true;
}
function stringContainsRTLText(chars) {
for (var i = 0, list = chars; i < list.length; i += 1) {
var char = list[i];
if (charInRTLScript(char.charCodeAt(0))) {
return true;
}
}
return false;
}
function isStringInSupportedScript(chars, canRenderRTL) {
for (var i = 0, list = chars; i < list.length; i += 1) {
var char = list[i];
if (!charInSupportedScript(char.charCodeAt(0), canRenderRTL)) {
return false;
}
}
return true;
}
var status = {
unavailable: 'unavailable',
deferred: 'deferred',
loading: 'loading',
loaded: 'loaded',
error: 'error'
};
var _completionCallback = null;
var pluginStatus = status.unavailable;
var pluginURL = null;
var triggerPluginCompletionEvent = function (error) {
if (error && typeof error === 'string' && error.indexOf('NetworkError') > -1) {
pluginStatus = status.error;
}
if (_completionCallback) {
_completionCallback(error);
}
};
function sendPluginStateToWorker() {
evented.fire(new Event('pluginStateChange', {
pluginStatus: pluginStatus,
pluginURL: pluginURL
}));
}
var evented = new Evented();
var getRTLTextPluginStatus = function () {
return pluginStatus;
};
var registerForPluginStateChange = function (callback) {
callback({
pluginStatus: pluginStatus,
pluginURL: pluginURL
});
evented.on('pluginStateChange', callback);
return callback;
};
var setRTLTextPlugin = function (url, callback, deferred) {
if (deferred === void 0)
deferred = false;
if (pluginStatus === status.deferred || pluginStatus === status.loading || pluginStatus === status.loaded) {
throw new Error('setRTLTextPlugin cannot be called multiple times.');
}
pluginURL = exported.resolveURL(url);
pluginStatus = status.deferred;
_completionCallback = callback;
sendPluginStateToWorker();
if (!deferred) {
downloadRTLTextPlugin();
}
};
var downloadRTLTextPlugin = function () {
if (pluginStatus !== status.deferred || !pluginURL) {
throw new Error('rtl-text-plugin cannot be downloaded unless a pluginURL is specified');
}
pluginStatus = status.loading;
sendPluginStateToWorker();
if (pluginURL) {
getArrayBuffer({ url: pluginURL }, function (error) {
if (error) {
triggerPluginCompletionEvent(error);
} else {
pluginStatus = status.loaded;
sendPluginStateToWorker();
}
});
}
};
var plugin = {
applyArabicShaping: null,
processBidirectionalText: null,
processStyledBidirectionalText: null,
isLoaded: function isLoaded() {
return pluginStatus === status.loaded || plugin.applyArabicShaping != null;
},
isLoading: function isLoading() {
return pluginStatus === status.loading;
},
setState: function setState(state) {
pluginStatus = state.pluginStatus;
pluginURL = state.pluginURL;
},
isParsed: function isParsed() {
return plugin.applyArabicShaping != null && plugin.processBidirectionalText != null && plugin.processStyledBidirectionalText != null;
},
getPluginURL: function getPluginURL() {
return pluginURL;
}
};
var lazyLoadRTLTextPlugin = function () {
if (!plugin.isLoading() && !plugin.isLoaded() && getRTLTextPluginStatus() === 'deferred') {
downloadRTLTextPlugin();
}
};
var EvaluationParameters = function EvaluationParameters(zoom, options) {
this.zoom = zoom;
if (options) {
this.now = options.now;
this.fadeDuration = options.fadeDuration;
this.zoomHistory = options.zoomHistory;
this.transition = options.transition;
} else {
this.now = 0;
this.fadeDuration = 0;
this.zoomHistory = new ZoomHistory();
this.transition = {};
}
};
EvaluationParameters.prototype.isSupportedScript = function isSupportedScript(str) {
return isStringInSupportedScript(str, plugin.isLoaded());
};
EvaluationParameters.prototype.crossFadingFactor = function crossFadingFactor() {
if (this.fadeDuration === 0) {
return 1;
} else {
return Math.min((this.now - this.zoomHistory.lastIntegerZoomTime) / this.fadeDuration, 1);
}
};
EvaluationParameters.prototype.getCrossfadeParameters = function getCrossfadeParameters() {
var z = this.zoom;
var fraction = z - Math.floor(z);
var t = this.crossFadingFactor();
return z > this.zoomHistory.lastIntegerZoom ? {
fromScale: 2,
toScale: 1,
t: fraction + (1 - fraction) * t
} : {
fromScale: 0.5,
toScale: 1,
t: 1 - (1 - t) * fraction
};
};
var PropertyValue = function PropertyValue(property, value) {
this.property = property;
this.value = value;
this.expression = normalizePropertyExpression(value === undefined ? property.specification.default : value, property.specification);
};
PropertyValue.prototype.isDataDriven = function isDataDriven() {
return this.expression.kind === 'source' || this.expression.kind === 'composite';
};
PropertyValue.prototype.possiblyEvaluate = function possiblyEvaluate(parameters, canonical, availableImages) {
return this.property.possiblyEvaluate(this, parameters, canonical, availableImages);
};
var TransitionablePropertyValue = function TransitionablePropertyValue(property) {
this.property = property;
this.value = new PropertyValue(property, undefined);
};
TransitionablePropertyValue.prototype.transitioned = function transitioned(parameters, prior) {
return new TransitioningPropertyValue(this.property, this.value, prior, extend({}, parameters.transition, this.transition), parameters.now);
};
TransitionablePropertyValue.prototype.untransitioned = function untransitioned() {
return new TransitioningPropertyValue(this.property, this.value, null, {}, 0);
};
var Transitionable = function Transitionable(properties) {
this._properties = properties;
this._values = Object.create(properties.defaultTransitionablePropertyValues);
};
Transitionable.prototype.getValue = function getValue(name) {
return clone(this._values[name].value.value);
};
Transitionable.prototype.setValue = function setValue(name, value) {
if (!this._values.hasOwnProperty(name)) {
this._values[name] = new TransitionablePropertyValue(this._values[name].property);
}
this._values[name].value = new PropertyValue(this._values[name].property, value === null ? undefined : clone(value));
};
Transitionable.prototype.getTransition = function getTransition(name) {
return clone(this._values[name].transition);
};
Transitionable.prototype.setTransition = function setTransition(name, value) {
if (!this._values.hasOwnProperty(name)) {
this._values[name] = new TransitionablePropertyValue(this._values[name].property);
}
this._values[name].transition = clone(value) || undefined;
};
Transitionable.prototype.serialize = function serialize() {
var result = {};
for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
var property = list[i];
var value = this.getValue(property);
if (value !== undefined) {
result[property] = value;
}
var transition = this.getTransition(property);
if (transition !== undefined) {
result[property + '-transition'] = transition;
}
}
return result;
};
Transitionable.prototype.transitioned = function transitioned(parameters, prior) {
var result = new Transitioning(this._properties);
for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
var property = list[i];
result._values[property] = this._values[property].transitioned(parameters, prior._values[property]);
}
return result;
};
Transitionable.prototype.untransitioned = function untransitioned() {
var result = new Transitioning(this._properties);
for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
var property = list[i];
result._values[property] = this._values[property].untransitioned();
}
return result;
};
var TransitioningPropertyValue = function TransitioningPropertyValue(property, value, prior, transition, now) {
this.property = property;
this.value = value;
this.begin = now + transition.delay || 0;
this.end = this.begin + transition.duration || 0;
if (property.specification.transition && (transition.delay || transition.duration)) {
this.prior = prior;
}
};
TransitioningPropertyValue.prototype.possiblyEvaluate = function possiblyEvaluate(parameters, canonical, availableImages) {
var now = parameters.now || 0;
var finalValue = this.value.possiblyEvaluate(parameters, canonical, availableImages);
var prior = this.prior;
if (!prior) {
return finalValue;
} else if (now > this.end) {
this.prior = null;
return finalValue;
} else if (this.value.isDataDriven()) {
this.prior = null;
return finalValue;
} else if (now < this.begin) {
return prior.possiblyEvaluate(parameters, canonical, availableImages);
} else {
var t = (now - this.begin) / (this.end - this.begin);
return this.property.interpolate(prior.possiblyEvaluate(parameters, canonical, availableImages), finalValue, easeCubicInOut(t));
}
};
var Transitioning = function Transitioning(properties) {
this._properties = properties;
this._values = Object.create(properties.defaultTransitioningPropertyValues);
};
Transitioning.prototype.possiblyEvaluate = function possiblyEvaluate(parameters, canonical, availableImages) {
var result = new PossiblyEvaluated(this._properties);
for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
var property = list[i];
result._values[property] = this._values[property].possiblyEvaluate(parameters, canonical, availableImages);
}
return result;
};
Transitioning.prototype.hasTransition = function hasTransition() {
for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
var property = list[i];
if (this._values[property].prior) {
return true;
}
}
return false;
};
var Layout = function Layout(properties) {
this._properties = properties;
this._values = Object.create(properties.defaultPropertyValues);
};
Layout.prototype.getValue = function getValue(name) {
return clone(this._values[name].value);
};
Layout.prototype.setValue = function setValue(name, value) {
this._values[name] = new PropertyValue(this._values[name].property, value === null ? undefined : clone(value));
};
Layout.prototype.serialize = function serialize() {
var result = {};
for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
var property = list[i];
var value = this.getValue(property);
if (value !== undefined) {
result[property] = value;
}
}
return result;
};
Layout.prototype.possiblyEvaluate = function possiblyEvaluate(parameters, canonical, availableImages) {
var result = new PossiblyEvaluated(this._properties);
for (var i = 0, list = Object.keys(this._values); i < list.length; i += 1) {
var property = list[i];
result._values[property] = this._values[property].possiblyEvaluate(parameters, canonical, availableImages);
}
return result;
};
var PossiblyEvaluatedPropertyValue = function PossiblyEvaluatedPropertyValue(property, value, parameters) {
this.property = property;
this.value = value;
this.parameters = parameters;
};
PossiblyEvaluatedPropertyValue.prototype.isConstant = function isConstant() {
return this.value.kind === 'constant';
};
PossiblyEvaluatedPropertyValue.prototype.constantOr = function constantOr(value) {
if (this.value.kind === 'constant') {
return this.value.value;
} else {
return value;
}
};
PossiblyEvaluatedPropertyValue.prototype.evaluate = function evaluate(feature, featureState, canonical, availableImages) {
return this.property.evaluate(this.value, this.parameters, feature, featureState, canonical, availableImages);
};
var PossiblyEvaluated = function PossiblyEvaluated(properties) {
this._properties = properties;
this._values = Object.create(properties.defaultPossiblyEvaluatedValues);
};
PossiblyEvaluated.prototype.get = function get(name) {
return this._values[name];
};
var DataConstantProperty = function DataConstantProperty(specification) {
this.specification = specification;
};
DataConstantProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters) {
return value.expression.evaluate(parameters);
};
DataConstantProperty.prototype.interpolate = function interpolate$1(a, b, t) {
var interp = interpolate[this.specification.type];
if (interp) {
return interp(a, b, t);
} else {
return a;
}
};
var DataDrivenProperty = function DataDrivenProperty(specification, overrides) {
this.specification = specification;
this.overrides = overrides;
};
DataDrivenProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters, canonical, availableImages) {
if (value.expression.kind === 'constant' || value.expression.kind === 'camera') {
return new PossiblyEvaluatedPropertyValue(this, {
kind: 'constant',
value: value.expression.evaluate(parameters, null, {}, canonical, availableImages)
}, parameters);
} else {
return new PossiblyEvaluatedPropertyValue(this, value.expression, parameters);
}
};
DataDrivenProperty.prototype.interpolate = function interpolate$2(a, b, t) {
if (a.value.kind !== 'constant' || b.value.kind !== 'constant') {
return a;
}
if (a.value.value === undefined || b.value.value === undefined) {
return new PossiblyEvaluatedPropertyValue(this, {
kind: 'constant',
value: undefined
}, a.parameters);
}
var interp = interpolate[this.specification.type];
if (interp) {
return new PossiblyEvaluatedPropertyValue(this, {
kind: 'constant',
value: interp(a.value.value, b.value.value, t)
}, a.parameters);
} else {
return a;
}
};
DataDrivenProperty.prototype.evaluate = function evaluate(value, parameters, feature, featureState, canonical, availableImages) {
if (value.kind === 'constant') {
return value.value;
} else {
return value.evaluate(parameters, feature, featureState, canonical, availableImages);
}
};
var CrossFadedDataDrivenProperty = function (DataDrivenProperty) {
function CrossFadedDataDrivenProperty() {
DataDrivenProperty.apply(this, arguments);
}
if (DataDrivenProperty)
CrossFadedDataDrivenProperty.__proto__ = DataDrivenProperty;
CrossFadedDataDrivenProperty.prototype = Object.create(DataDrivenProperty && DataDrivenProperty.prototype);
CrossFadedDataDrivenProperty.prototype.constructor = CrossFadedDataDrivenProperty;
CrossFadedDataDrivenProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters, canonical, availableImages) {
if (value.value === undefined) {
return new PossiblyEvaluatedPropertyValue(this, {
kind: 'constant',
value: undefined
}, parameters);
} else if (value.expression.kind === 'constant') {
var evaluatedValue = value.expression.evaluate(parameters, null, {}, canonical, availableImages);
var isImageExpression = value.property.specification.type === 'resolvedImage';
var constantValue = isImageExpression && typeof evaluatedValue !== 'string' ? evaluatedValue.name : evaluatedValue;
var constant = this._calculate(constantValue, constantValue, constantValue, parameters);
return new PossiblyEvaluatedPropertyValue(this, {
kind: 'constant',
value: constant
}, parameters);
} else if (value.expression.kind === 'camera') {
var cameraVal = this._calculate(value.expression.evaluate({ zoom: parameters.zoom - 1 }), value.expression.evaluate({ zoom: parameters.zoom }), value.expression.evaluate({ zoom: parameters.zoom + 1 }), parameters);
return new PossiblyEvaluatedPropertyValue(this, {
kind: 'constant',
value: cameraVal
}, parameters);
} else {
return new PossiblyEvaluatedPropertyValue(this, value.expression, parameters);
}
};
CrossFadedDataDrivenProperty.prototype.evaluate = function evaluate(value, globals, feature, featureState, canonical, availableImages) {
if (value.kind === 'source') {
var constant = value.evaluate(globals, feature, featureState, canonical, availableImages);
return this._calculate(constant, constant, constant, globals);
} else if (value.kind === 'composite') {
return this._calculate(value.evaluate({ zoom: Math.floor(globals.zoom) - 1 }, feature, featureState), value.evaluate({ zoom: Math.floor(globals.zoom) }, feature, featureState), value.evaluate({ zoom: Math.floor(globals.zoom) + 1 }, feature, featureState), globals);
} else {
return value.value;
}
};
CrossFadedDataDrivenProperty.prototype._calculate = function _calculate(min, mid, max, parameters) {
var z = parameters.zoom;
return z > parameters.zoomHistory.lastIntegerZoom ? {
from: min,
to: mid
} : {
from: max,
to: mid
};
};
CrossFadedDataDrivenProperty.prototype.interpolate = function interpolate(a) {
return a;
};
return CrossFadedDataDrivenProperty;
}(DataDrivenProperty);
var CrossFadedProperty = function CrossFadedProperty(specification) {
this.specification = specification;
};
CrossFadedProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters, canonical, availableImages) {
if (value.value === undefined) {
return undefined;
} else if (value.expression.kind === 'constant') {
var constant = value.expression.evaluate(parameters, null, {}, canonical, availableImages);
return this._calculate(constant, constant, constant, parameters);
} else {
return this._calculate(value.expression.evaluate(new EvaluationParameters(Math.floor(parameters.zoom - 1), parameters)), value.expression.evaluate(new EvaluationParameters(Math.floor(parameters.zoom), parameters)), value.expression.evaluate(new EvaluationParameters(Math.floor(parameters.zoom + 1), parameters)), parameters);
}
};
CrossFadedProperty.prototype._calculate = function _calculate(min, mid, max, parameters) {
var z = parameters.zoom;
return z > parameters.zoomHistory.lastIntegerZoom ? {
from: min,
to: mid
} : {
from: max,
to: mid
};
};
CrossFadedProperty.prototype.interpolate = function interpolate(a) {
return a;
};
var ColorRampProperty = function ColorRampProperty(specification) {
this.specification = specification;
};
ColorRampProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters, canonical, availableImages) {
return !!value.expression.evaluate(parameters, null, {}, canonical, availableImages);
};
ColorRampProperty.prototype.interpolate = function interpolate() {
return false;
};
var Properties = function Properties(properties) {
this.properties = properties;
this.defaultPropertyValues = {};
this.defaultTransitionablePropertyValues = {};
this.defaultTransitioningPropertyValues = {};
this.defaultPossiblyEvaluatedValues = {};
this.overridableProperties = [];
for (var property in properties) {
var prop = properties[property];
if (prop.specification.overridable) {
this.overridableProperties.push(property);
}
var defaultPropertyValue = this.defaultPropertyValues[property] = new PropertyValue(prop, undefined);
var defaultTransitionablePropertyValue = this.defaultTransitionablePropertyValues[property] = new TransitionablePropertyValue(prop);
this.defaultTransitioningPropertyValues[property] = defaultTransitionablePropertyValue.untransitioned();
this.defaultPossiblyEvaluatedValues[property] = defaultPropertyValue.possiblyEvaluate({});
}
};
register('DataDrivenProperty', DataDrivenProperty);
register('DataConstantProperty', DataConstantProperty);
register('CrossFadedDataDrivenProperty', CrossFadedDataDrivenProperty);
register('CrossFadedProperty', CrossFadedProperty);
register('ColorRampProperty', ColorRampProperty);
var TRANSITION_SUFFIX = '-transition';
var StyleLayer = function (Evented) {
function StyleLayer(layer, properties) {
Evented.call(this);
this.id = layer.id;
this.type = layer.type;
this._featureFilter = {
filter: function () {
return true;
},
needGeometry: false
};
if (layer.type === 'custom') {
return;
}
layer = layer;
this.metadata = layer.metadata;
this.minzoom = layer.minzoom;
this.maxzoom = layer.maxzoom;
if (layer.type !== 'background') {
this.source = layer.source;
this.sourceLayer = layer['source-layer'];
this.filter = layer.filter;
}
if (properties.layout) {
this._unevaluatedLayout = new Layout(properties.layout);
}
if (properties.paint) {
this._transitionablePaint = new Transitionable(properties.paint);
for (var property in layer.paint) {
this.setPaintProperty(property, layer.paint[property], { validate: false });
}
for (var property$1 in layer.layout) {
this.setLayoutProperty(property$1, layer.layout[property$1], { validate: false });
}
this._transitioningPaint = this._transitionablePaint.untransitioned();
this.paint = new PossiblyEvaluated(properties.paint);
}
}
if (Evented)
StyleLayer.__proto__ = Evented;
StyleLayer.prototype = Object.create(Evented && Evented.prototype);
StyleLayer.prototype.constructor = StyleLayer;
StyleLayer.prototype.getCrossfadeParameters = function getCrossfadeParameters() {
return this._crossfadeParameters;
};
StyleLayer.prototype.getLayoutProperty = function getLayoutProperty(name) {
if (name === 'visibility') {
return this.visibility;
}
return this._unevaluatedLayout.getValue(name);
};
StyleLayer.prototype.setLayoutProperty = function setLayoutProperty(name, value, options) {
if (options === void 0)
options = {};
if (value !== null && value !== undefined) {
var key = 'layers.' + this.id + '.layout.' + name;
if (this._validate(validateLayoutProperty$1, key, name, value, options)) {
return;
}
}
if (name === 'visibility') {
this.visibility = value;
return;
}
this._unevaluatedLayout.setValue(name, value);
};
StyleLayer.prototype.getPaintProperty = function getPaintProperty(name) {
if (endsWith(name, TRANSITION_SUFFIX)) {
return this._transitionablePaint.getTransition(name.slice(0, -TRANSITION_SUFFIX.length));
} else {
return this._transitionablePaint.getValue(name);
}
};
StyleLayer.prototype.setPaintProperty = function setPaintProperty(name, value, options) {
if (options === void 0)
options = {};
if (value !== null && value !== undefined) {
var key = 'layers.' + this.id + '.paint.' + name;
if (this._validate(validatePaintProperty$1, key, name, value, options)) {
return false;
}
}
if (endsWith(name, TRANSITION_SUFFIX)) {
this._transitionablePaint.setTransition(name.slice(0, -TRANSITION_SUFFIX.length), value || undefined);
return false;
} else {
var transitionable = this._transitionablePaint._values[name];
var isCrossFadedProperty = transitionable.property.specification['property-type'] === 'cross-faded-data-driven';
var wasDataDriven = transitionable.value.isDataDriven();
var oldValue = transitionable.value;
this._transitionablePaint.setValue(name, value);
this._handleSpecialPaintPropertyUpdate(name);
var newValue = this._transitionablePaint._values[name].value;
var isDataDriven = newValue.isDataDriven();
return isDataDriven || wasDataDriven || isCrossFadedProperty || this._handleOverridablePaintPropertyUpdate(name, oldValue, newValue);
}
};
StyleLayer.prototype._handleSpecialPaintPropertyUpdate = function _handleSpecialPaintPropertyUpdate(_) {
};
StyleLayer.prototype._handleOverridablePaintPropertyUpdate = function _handleOverridablePaintPropertyUpdate(name, oldValue, newValue) {
return false;
};
StyleLayer.prototype.isHidden = function isHidden(zoom) {
if (this.minzoom && zoom < this.minzoom) {
return true;
}
if (this.maxzoom && zoom >= this.maxzoom) {
return true;
}
return this.visibility === 'none';
};
StyleLayer.prototype.updateTransitions = function updateTransitions(parameters) {
this._transitioningPaint = this._transitionablePaint.transitioned(parameters, this._transitioningPaint);
};
StyleLayer.prototype.hasTransition = function hasTransition() {
return this._transitioningPaint.hasTransition();
};
StyleLayer.prototype.recalculate = function recalculate(parameters, availableImages) {
if (parameters.getCrossfadeParameters) {
this._crossfadeParameters = parameters.getCrossfadeParameters();
}
if (this._unevaluatedLayout) {
this.layout = this._unevaluatedLayout.possiblyEvaluate(parameters, undefined, availableImages);
}
this.paint = this._transitioningPaint.possiblyEvaluate(parameters, undefined, availableImages);
};
StyleLayer.prototype.serialize = function serialize() {
var output = {
'id': this.id,
'type': this.type,
'source': this.source,
'source-layer': this.sourceLayer,
'metadata': this.metadata,
'minzoom': this.minzoom,
'maxzoom': this.maxzoom,
'filter': this.filter,
'layout': this._unevaluatedLayout && this._unevaluatedLayout.serialize(),
'paint': this._transitionablePaint && this._transitionablePaint.serialize()
};
if (this.visibility) {
output.layout = output.layout || {};
output.layout.visibility = this.visibility;
}
return filterObject(output, function (value, key) {
return value !== undefined && !(key === 'layout' && !Object.keys(value).length) && !(key === 'paint' && !Object.keys(value).length);
});
};
StyleLayer.prototype._validate = function _validate(validate, key, name, value, options) {
if (options === void 0)
options = {};
if (options && options.validate === false) {
return false;
}
return emitValidationErrors(this, validate.call(validateStyle, {
key: key,
layerType: this.type,
objectKey: name,
value: value,
styleSpec: spec,
style: {
glyphs: true,
sprite: true
}
}));
};
StyleLayer.prototype.is3D = function is3D() {
return false;
};
StyleLayer.prototype.isTileClipped = function isTileClipped() {
return false;
};
StyleLayer.prototype.hasOffscreenPass = function hasOffscreenPass() {
return false;
};
StyleLayer.prototype.resize = function resize() {
};
StyleLayer.prototype.isStateDependent = function isStateDependent() {
for (var property in this.paint._values) {
var value = this.paint.get(property);
if (!(value instanceof PossiblyEvaluatedPropertyValue) || !supportsPropertyExpression(value.property.specification)) {
continue;
}
if ((value.value.kind === 'source' || value.value.kind === 'composite') && value.value.isStateDependent) {
return true;
}
}
return false;
};
return StyleLayer;
}(Evented);
var viewTypes = {
'Int8': Int8Array,
'Uint8': Uint8Array,
'Int16': Int16Array,
'Uint16': Uint16Array,
'Int32': Int32Array,
'Uint32': Uint32Array,
'Float32': Float32Array
};
var Struct = function Struct(structArray, index) {
this._structArray = structArray;
this._pos1 = index * this.size;
this._pos2 = this._pos1 / 2;
this._pos4 = this._pos1 / 4;
this._pos8 = this._pos1 / 8;
};
var DEFAULT_CAPACITY = 128;
var RESIZE_MULTIPLIER = 5;
var StructArray = function StructArray() {
this.isTransferred = false;
this.capacity = -1;
this.resize(0);
};
StructArray.serialize = function serialize(array, transferables) {
array._trim();
if (transferables) {
array.isTransferred = true;
transferables.push(array.arrayBuffer);
}
return {
length: array.length,
arrayBuffer: array.arrayBuffer
};
};
StructArray.deserialize = function deserialize(input) {
var structArray = Object.create(this.prototype);
structArray.arrayBuffer = input.arrayBuffer;
structArray.length = input.length;
structArray.capacity = input.arrayBuffer.byteLength / structArray.bytesPerElement;
structArray._refreshViews();
return structArray;
};
StructArray.prototype._trim = function _trim() {
if (this.length !== this.capacity) {
this.capacity = this.length;
this.arrayBuffer = this.arrayBuffer.slice(0, this.length * this.bytesPerElement);
this._refreshViews();
}
};
StructArray.prototype.clear = function clear() {
this.length = 0;
};
StructArray.prototype.resize = function resize(n) {
this.reserve(n);
this.length = n;
};
StructArray.prototype.reserve = function reserve(n) {
if (n > this.capacity) {
this.capacity = Math.max(n, Math.floor(this.capacity * RESIZE_MULTIPLIER), DEFAULT_CAPACITY);
this.arrayBuffer = new ArrayBuffer(this.capacity * this.bytesPerElement);
var oldUint8Array = this.uint8;
this._refreshViews();
if (oldUint8Array) {
this.uint8.set(oldUint8Array);
}
}
};
StructArray.prototype._refreshViews = function _refreshViews() {
throw new Error('_refreshViews() must be implemented by each concrete StructArray layout');
};
function createLayout(members, alignment) {
if (alignment === void 0)
alignment = 1;
var offset = 0;
var maxSize = 0;
var layoutMembers = members.map(function (member) {
var typeSize = sizeOf(member.type);
var memberOffset = offset = align(offset, Math.max(alignment, typeSize));
var components = member.components || 1;
maxSize = Math.max(maxSize, typeSize);
offset += typeSize * components;
return {
name: member.name,
type: member.type,
components: components,
offset: memberOffset
};
});
var size = align(offset, Math.max(maxSize, alignment));
return {
members: layoutMembers,
size: size,
alignment: alignment
};
}
function sizeOf(type) {
return viewTypes[type].BYTES_PER_ELEMENT;
}
function align(offset, size) {
return Math.ceil(offset / size) * size;
}
var StructArrayLayout2i4 = function (StructArray) {
function StructArrayLayout2i4() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout2i4.__proto__ = StructArray;
StructArrayLayout2i4.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout2i4.prototype.constructor = StructArrayLayout2i4;
StructArrayLayout2i4.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.int16 = new Int16Array(this.arrayBuffer);
};
StructArrayLayout2i4.prototype.emplaceBack = function emplaceBack(v0, v1) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0, v1);
};
StructArrayLayout2i4.prototype.emplace = function emplace(i, v0, v1) {
var o2 = i * 2;
this.int16[o2 + 0] = v0;
this.int16[o2 + 1] = v1;
return i;
};
return StructArrayLayout2i4;
}(StructArray);
StructArrayLayout2i4.prototype.bytesPerElement = 4;
register('StructArrayLayout2i4', StructArrayLayout2i4);
var StructArrayLayout4i8 = function (StructArray) {
function StructArrayLayout4i8() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout4i8.__proto__ = StructArray;
StructArrayLayout4i8.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout4i8.prototype.constructor = StructArrayLayout4i8;
StructArrayLayout4i8.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.int16 = new Int16Array(this.arrayBuffer);
};
StructArrayLayout4i8.prototype.emplaceBack = function emplaceBack(v0, v1, v2, v3) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0, v1, v2, v3);
};
StructArrayLayout4i8.prototype.emplace = function emplace(i, v0, v1, v2, v3) {
var o2 = i * 4;
this.int16[o2 + 0] = v0;
this.int16[o2 + 1] = v1;
this.int16[o2 + 2] = v2;
this.int16[o2 + 3] = v3;
return i;
};
return StructArrayLayout4i8;
}(StructArray);
StructArrayLayout4i8.prototype.bytesPerElement = 8;
register('StructArrayLayout4i8', StructArrayLayout4i8);
var StructArrayLayout2i4i12 = function (StructArray) {
function StructArrayLayout2i4i12() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout2i4i12.__proto__ = StructArray;
StructArrayLayout2i4i12.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout2i4i12.prototype.constructor = StructArrayLayout2i4i12;
StructArrayLayout2i4i12.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.int16 = new Int16Array(this.arrayBuffer);
};
StructArrayLayout2i4i12.prototype.emplaceBack = function emplaceBack(v0, v1, v2, v3, v4, v5) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0, v1, v2, v3, v4, v5);
};
StructArrayLayout2i4i12.prototype.emplace = function emplace(i, v0, v1, v2, v3, v4, v5) {
var o2 = i * 6;
this.int16[o2 + 0] = v0;
this.int16[o2 + 1] = v1;
this.int16[o2 + 2] = v2;
this.int16[o2 + 3] = v3;
this.int16[o2 + 4] = v4;
this.int16[o2 + 5] = v5;
return i;
};
return StructArrayLayout2i4i12;
}(StructArray);
StructArrayLayout2i4i12.prototype.bytesPerElement = 12;
register('StructArrayLayout2i4i12', StructArrayLayout2i4i12);
var StructArrayLayout2i4ub8 = function (StructArray) {
function StructArrayLayout2i4ub8() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout2i4ub8.__proto__ = StructArray;
StructArrayLayout2i4ub8.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout2i4ub8.prototype.constructor = StructArrayLayout2i4ub8;
StructArrayLayout2i4ub8.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.int16 = new Int16Array(this.arrayBuffer);
};
StructArrayLayout2i4ub8.prototype.emplaceBack = function emplaceBack(v0, v1, v2, v3, v4, v5) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0, v1, v2, v3, v4, v5);
};
StructArrayLayout2i4ub8.prototype.emplace = function emplace(i, v0, v1, v2, v3, v4, v5) {
var o2 = i * 4;
var o1 = i * 8;
this.int16[o2 + 0] = v0;
this.int16[o2 + 1] = v1;
this.uint8[o1 + 4] = v2;
this.uint8[o1 + 5] = v3;
this.uint8[o1 + 6] = v4;
this.uint8[o1 + 7] = v5;
return i;
};
return StructArrayLayout2i4ub8;
}(StructArray);
StructArrayLayout2i4ub8.prototype.bytesPerElement = 8;
register('StructArrayLayout2i4ub8', StructArrayLayout2i4ub8);
var StructArrayLayout2f8 = function (StructArray) {
function StructArrayLayout2f8() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout2f8.__proto__ = StructArray;
StructArrayLayout2f8.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout2f8.prototype.constructor = StructArrayLayout2f8;
StructArrayLayout2f8.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.float32 = new Float32Array(this.arrayBuffer);
};
StructArrayLayout2f8.prototype.emplaceBack = function emplaceBack(v0, v1) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0, v1);
};
StructArrayLayout2f8.prototype.emplace = function emplace(i, v0, v1) {
var o4 = i * 2;
this.float32[o4 + 0] = v0;
this.float32[o4 + 1] = v1;
return i;
};
return StructArrayLayout2f8;
}(StructArray);
StructArrayLayout2f8.prototype.bytesPerElement = 8;
register('StructArrayLayout2f8', StructArrayLayout2f8);
var StructArrayLayout10ui20 = function (StructArray) {
function StructArrayLayout10ui20() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout10ui20.__proto__ = StructArray;
StructArrayLayout10ui20.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout10ui20.prototype.constructor = StructArrayLayout10ui20;
StructArrayLayout10ui20.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.uint16 = new Uint16Array(this.arrayBuffer);
};
StructArrayLayout10ui20.prototype.emplaceBack = function emplaceBack(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9);
};
StructArrayLayout10ui20.prototype.emplace = function emplace(i, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9) {
var o2 = i * 10;
this.uint16[o2 + 0] = v0;
this.uint16[o2 + 1] = v1;
this.uint16[o2 + 2] = v2;
this.uint16[o2 + 3] = v3;
this.uint16[o2 + 4] = v4;
this.uint16[o2 + 5] = v5;
this.uint16[o2 + 6] = v6;
this.uint16[o2 + 7] = v7;
this.uint16[o2 + 8] = v8;
this.uint16[o2 + 9] = v9;
return i;
};
return StructArrayLayout10ui20;
}(StructArray);
StructArrayLayout10ui20.prototype.bytesPerElement = 20;
register('StructArrayLayout10ui20', StructArrayLayout10ui20);
var StructArrayLayout4i4ui4i24 = function (StructArray) {
function StructArrayLayout4i4ui4i24() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout4i4ui4i24.__proto__ = StructArray;
StructArrayLayout4i4ui4i24.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout4i4ui4i24.prototype.constructor = StructArrayLayout4i4ui4i24;
StructArrayLayout4i4ui4i24.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.int16 = new Int16Array(this.arrayBuffer);
this.uint16 = new Uint16Array(this.arrayBuffer);
};
StructArrayLayout4i4ui4i24.prototype.emplaceBack = function emplaceBack(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11);
};
StructArrayLayout4i4ui4i24.prototype.emplace = function emplace(i, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) {
var o2 = i * 12;
this.int16[o2 + 0] = v0;
this.int16[o2 + 1] = v1;
this.int16[o2 + 2] = v2;
this.int16[o2 + 3] = v3;
this.uint16[o2 + 4] = v4;
this.uint16[o2 + 5] = v5;
this.uint16[o2 + 6] = v6;
this.uint16[o2 + 7] = v7;
this.int16[o2 + 8] = v8;
this.int16[o2 + 9] = v9;
this.int16[o2 + 10] = v10;
this.int16[o2 + 11] = v11;
return i;
};
return StructArrayLayout4i4ui4i24;
}(StructArray);
StructArrayLayout4i4ui4i24.prototype.bytesPerElement = 24;
register('StructArrayLayout4i4ui4i24', StructArrayLayout4i4ui4i24);
var StructArrayLayout3f12 = function (StructArray) {
function StructArrayLayout3f12() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout3f12.__proto__ = StructArray;
StructArrayLayout3f12.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout3f12.prototype.constructor = StructArrayLayout3f12;
StructArrayLayout3f12.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.float32 = new Float32Array(this.arrayBuffer);
};
StructArrayLayout3f12.prototype.emplaceBack = function emplaceBack(v0, v1, v2) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0, v1, v2);
};
StructArrayLayout3f12.prototype.emplace = function emplace(i, v0, v1, v2) {
var o4 = i * 3;
this.float32[o4 + 0] = v0;
this.float32[o4 + 1] = v1;
this.float32[o4 + 2] = v2;
return i;
};
return StructArrayLayout3f12;
}(StructArray);
StructArrayLayout3f12.prototype.bytesPerElement = 12;
register('StructArrayLayout3f12', StructArrayLayout3f12);
var StructArrayLayout1ul4 = function (StructArray) {
function StructArrayLayout1ul4() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout1ul4.__proto__ = StructArray;
StructArrayLayout1ul4.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout1ul4.prototype.constructor = StructArrayLayout1ul4;
StructArrayLayout1ul4.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.uint32 = new Uint32Array(this.arrayBuffer);
};
StructArrayLayout1ul4.prototype.emplaceBack = function emplaceBack(v0) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0);
};
StructArrayLayout1ul4.prototype.emplace = function emplace(i, v0) {
var o4 = i * 1;
this.uint32[o4 + 0] = v0;
return i;
};
return StructArrayLayout1ul4;
}(StructArray);
StructArrayLayout1ul4.prototype.bytesPerElement = 4;
register('StructArrayLayout1ul4', StructArrayLayout1ul4);
var StructArrayLayout6i1ul2ui20 = function (StructArray) {
function StructArrayLayout6i1ul2ui20() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout6i1ul2ui20.__proto__ = StructArray;
StructArrayLayout6i1ul2ui20.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout6i1ul2ui20.prototype.constructor = StructArrayLayout6i1ul2ui20;
StructArrayLayout6i1ul2ui20.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.int16 = new Int16Array(this.arrayBuffer);
this.uint32 = new Uint32Array(this.arrayBuffer);
this.uint16 = new Uint16Array(this.arrayBuffer);
};
StructArrayLayout6i1ul2ui20.prototype.emplaceBack = function emplaceBack(v0, v1, v2, v3, v4, v5, v6, v7, v8) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0, v1, v2, v3, v4, v5, v6, v7, v8);
};
StructArrayLayout6i1ul2ui20.prototype.emplace = function emplace(i, v0, v1, v2, v3, v4, v5, v6, v7, v8) {
var o2 = i * 10;
var o4 = i * 5;
this.int16[o2 + 0] = v0;
this.int16[o2 + 1] = v1;
this.int16[o2 + 2] = v2;
this.int16[o2 + 3] = v3;
this.int16[o2 + 4] = v4;
this.int16[o2 + 5] = v5;
this.uint32[o4 + 3] = v6;
this.uint16[o2 + 8] = v7;
this.uint16[o2 + 9] = v8;
return i;
};
return StructArrayLayout6i1ul2ui20;
}(StructArray);
StructArrayLayout6i1ul2ui20.prototype.bytesPerElement = 20;
register('StructArrayLayout6i1ul2ui20', StructArrayLayout6i1ul2ui20);
var StructArrayLayout2i2i2i12 = function (StructArray) {
function StructArrayLayout2i2i2i12() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout2i2i2i12.__proto__ = StructArray;
StructArrayLayout2i2i2i12.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout2i2i2i12.prototype.constructor = StructArrayLayout2i2i2i12;
StructArrayLayout2i2i2i12.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.int16 = new Int16Array(this.arrayBuffer);
};
StructArrayLayout2i2i2i12.prototype.emplaceBack = function emplaceBack(v0, v1, v2, v3, v4, v5) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0, v1, v2, v3, v4, v5);
};
StructArrayLayout2i2i2i12.prototype.emplace = function emplace(i, v0, v1, v2, v3, v4, v5) {
var o2 = i * 6;
this.int16[o2 + 0] = v0;
this.int16[o2 + 1] = v1;
this.int16[o2 + 2] = v2;
this.int16[o2 + 3] = v3;
this.int16[o2 + 4] = v4;
this.int16[o2 + 5] = v5;
return i;
};
return StructArrayLayout2i2i2i12;
}(StructArray);
StructArrayLayout2i2i2i12.prototype.bytesPerElement = 12;
register('StructArrayLayout2i2i2i12', StructArrayLayout2i2i2i12);
var StructArrayLayout2f1f2i16 = function (StructArray) {
function StructArrayLayout2f1f2i16() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout2f1f2i16.__proto__ = StructArray;
StructArrayLayout2f1f2i16.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout2f1f2i16.prototype.constructor = StructArrayLayout2f1f2i16;
StructArrayLayout2f1f2i16.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.float32 = new Float32Array(this.arrayBuffer);
this.int16 = new Int16Array(this.arrayBuffer);
};
StructArrayLayout2f1f2i16.prototype.emplaceBack = function emplaceBack(v0, v1, v2, v3, v4) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0, v1, v2, v3, v4);
};
StructArrayLayout2f1f2i16.prototype.emplace = function emplace(i, v0, v1, v2, v3, v4) {
var o4 = i * 4;
var o2 = i * 8;
this.float32[o4 + 0] = v0;
this.float32[o4 + 1] = v1;
this.float32[o4 + 2] = v2;
this.int16[o2 + 6] = v3;
this.int16[o2 + 7] = v4;
return i;
};
return StructArrayLayout2f1f2i16;
}(StructArray);
StructArrayLayout2f1f2i16.prototype.bytesPerElement = 16;
register('StructArrayLayout2f1f2i16', StructArrayLayout2f1f2i16);
var StructArrayLayout2ub2f12 = function (StructArray) {
function StructArrayLayout2ub2f12() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout2ub2f12.__proto__ = StructArray;
StructArrayLayout2ub2f12.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout2ub2f12.prototype.constructor = StructArrayLayout2ub2f12;
StructArrayLayout2ub2f12.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.float32 = new Float32Array(this.arrayBuffer);
};
StructArrayLayout2ub2f12.prototype.emplaceBack = function emplaceBack(v0, v1, v2, v3) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0, v1, v2, v3);
};
StructArrayLayout2ub2f12.prototype.emplace = function emplace(i, v0, v1, v2, v3) {
var o1 = i * 12;
var o4 = i * 3;
this.uint8[o1 + 0] = v0;
this.uint8[o1 + 1] = v1;
this.float32[o4 + 1] = v2;
this.float32[o4 + 2] = v3;
return i;
};
return StructArrayLayout2ub2f12;
}(StructArray);
StructArrayLayout2ub2f12.prototype.bytesPerElement = 12;
register('StructArrayLayout2ub2f12', StructArrayLayout2ub2f12);
var StructArrayLayout3ui6 = function (StructArray) {
function StructArrayLayout3ui6() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout3ui6.__proto__ = StructArray;
StructArrayLayout3ui6.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout3ui6.prototype.constructor = StructArrayLayout3ui6;
StructArrayLayout3ui6.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.uint16 = new Uint16Array(this.arrayBuffer);
};
StructArrayLayout3ui6.prototype.emplaceBack = function emplaceBack(v0, v1, v2) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0, v1, v2);
};
StructArrayLayout3ui6.prototype.emplace = function emplace(i, v0, v1, v2) {
var o2 = i * 3;
this.uint16[o2 + 0] = v0;
this.uint16[o2 + 1] = v1;
this.uint16[o2 + 2] = v2;
return i;
};
return StructArrayLayout3ui6;
}(StructArray);
StructArrayLayout3ui6.prototype.bytesPerElement = 6;
register('StructArrayLayout3ui6', StructArrayLayout3ui6);
var StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48 = function (StructArray) {
function StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48.__proto__ = StructArray;
StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48.prototype.constructor = StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48;
StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.int16 = new Int16Array(this.arrayBuffer);
this.uint16 = new Uint16Array(this.arrayBuffer);
this.uint32 = new Uint32Array(this.arrayBuffer);
this.float32 = new Float32Array(this.arrayBuffer);
};
StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48.prototype.emplaceBack = function emplaceBack(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16);
};
StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48.prototype.emplace = function emplace(i, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) {
var o2 = i * 24;
var o4 = i * 12;
var o1 = i * 48;
this.int16[o2 + 0] = v0;
this.int16[o2 + 1] = v1;
this.uint16[o2 + 2] = v2;
this.uint16[o2 + 3] = v3;
this.uint32[o4 + 2] = v4;
this.uint32[o4 + 3] = v5;
this.uint32[o4 + 4] = v6;
this.uint16[o2 + 10] = v7;
this.uint16[o2 + 11] = v8;
this.uint16[o2 + 12] = v9;
this.float32[o4 + 7] = v10;
this.float32[o4 + 8] = v11;
this.uint8[o1 + 36] = v12;
this.uint8[o1 + 37] = v13;
this.uint8[o1 + 38] = v14;
this.uint32[o4 + 10] = v15;
this.int16[o2 + 22] = v16;
return i;
};
return StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48;
}(StructArray);
StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48.prototype.bytesPerElement = 48;
register('StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48', StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48);
var StructArrayLayout8i15ui1ul4f68 = function (StructArray) {
function StructArrayLayout8i15ui1ul4f68() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout8i15ui1ul4f68.__proto__ = StructArray;
StructArrayLayout8i15ui1ul4f68.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout8i15ui1ul4f68.prototype.constructor = StructArrayLayout8i15ui1ul4f68;
StructArrayLayout8i15ui1ul4f68.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.int16 = new Int16Array(this.arrayBuffer);
this.uint16 = new Uint16Array(this.arrayBuffer);
this.uint32 = new Uint32Array(this.arrayBuffer);
this.float32 = new Float32Array(this.arrayBuffer);
};
StructArrayLayout8i15ui1ul4f68.prototype.emplaceBack = function emplaceBack(v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27);
};
StructArrayLayout8i15ui1ul4f68.prototype.emplace = function emplace(i, v0, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27) {
var o2 = i * 34;
var o4 = i * 17;
this.int16[o2 + 0] = v0;
this.int16[o2 + 1] = v1;
this.int16[o2 + 2] = v2;
this.int16[o2 + 3] = v3;
this.int16[o2 + 4] = v4;
this.int16[o2 + 5] = v5;
this.int16[o2 + 6] = v6;
this.int16[o2 + 7] = v7;
this.uint16[o2 + 8] = v8;
this.uint16[o2 + 9] = v9;
this.uint16[o2 + 10] = v10;
this.uint16[o2 + 11] = v11;
this.uint16[o2 + 12] = v12;
this.uint16[o2 + 13] = v13;
this.uint16[o2 + 14] = v14;
this.uint16[o2 + 15] = v15;
this.uint16[o2 + 16] = v16;
this.uint16[o2 + 17] = v17;
this.uint16[o2 + 18] = v18;
this.uint16[o2 + 19] = v19;
this.uint16[o2 + 20] = v20;
this.uint16[o2 + 21] = v21;
this.uint16[o2 + 22] = v22;
this.uint32[o4 + 12] = v23;
this.float32[o4 + 13] = v24;
this.float32[o4 + 14] = v25;
this.float32[o4 + 15] = v26;
this.float32[o4 + 16] = v27;
return i;
};
return StructArrayLayout8i15ui1ul4f68;
}(StructArray);
StructArrayLayout8i15ui1ul4f68.prototype.bytesPerElement = 68;
register('StructArrayLayout8i15ui1ul4f68', StructArrayLayout8i15ui1ul4f68);
var StructArrayLayout1f4 = function (StructArray) {
function StructArrayLayout1f4() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout1f4.__proto__ = StructArray;
StructArrayLayout1f4.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout1f4.prototype.constructor = StructArrayLayout1f4;
StructArrayLayout1f4.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.float32 = new Float32Array(this.arrayBuffer);
};
StructArrayLayout1f4.prototype.emplaceBack = function emplaceBack(v0) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0);
};
StructArrayLayout1f4.prototype.emplace = function emplace(i, v0) {
var o4 = i * 1;
this.float32[o4 + 0] = v0;
return i;
};
return StructArrayLayout1f4;
}(StructArray);
StructArrayLayout1f4.prototype.bytesPerElement = 4;
register('StructArrayLayout1f4', StructArrayLayout1f4);
var StructArrayLayout3i6 = function (StructArray) {
function StructArrayLayout3i6() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout3i6.__proto__ = StructArray;
StructArrayLayout3i6.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout3i6.prototype.constructor = StructArrayLayout3i6;
StructArrayLayout3i6.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.int16 = new Int16Array(this.arrayBuffer);
};
StructArrayLayout3i6.prototype.emplaceBack = function emplaceBack(v0, v1, v2) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0, v1, v2);
};
StructArrayLayout3i6.prototype.emplace = function emplace(i, v0, v1, v2) {
var o2 = i * 3;
this.int16[o2 + 0] = v0;
this.int16[o2 + 1] = v1;
this.int16[o2 + 2] = v2;
return i;
};
return StructArrayLayout3i6;
}(StructArray);
StructArrayLayout3i6.prototype.bytesPerElement = 6;
register('StructArrayLayout3i6', StructArrayLayout3i6);
var StructArrayLayout1ul2ui8 = function (StructArray) {
function StructArrayLayout1ul2ui8() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout1ul2ui8.__proto__ = StructArray;
StructArrayLayout1ul2ui8.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout1ul2ui8.prototype.constructor = StructArrayLayout1ul2ui8;
StructArrayLayout1ul2ui8.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.uint32 = new Uint32Array(this.arrayBuffer);
this.uint16 = new Uint16Array(this.arrayBuffer);
};
StructArrayLayout1ul2ui8.prototype.emplaceBack = function emplaceBack(v0, v1, v2) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0, v1, v2);
};
StructArrayLayout1ul2ui8.prototype.emplace = function emplace(i, v0, v1, v2) {
var o4 = i * 2;
var o2 = i * 4;
this.uint32[o4 + 0] = v0;
this.uint16[o2 + 2] = v1;
this.uint16[o2 + 3] = v2;
return i;
};
return StructArrayLayout1ul2ui8;
}(StructArray);
StructArrayLayout1ul2ui8.prototype.bytesPerElement = 8;
register('StructArrayLayout1ul2ui8', StructArrayLayout1ul2ui8);
var StructArrayLayout2ui4 = function (StructArray) {
function StructArrayLayout2ui4() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout2ui4.__proto__ = StructArray;
StructArrayLayout2ui4.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout2ui4.prototype.constructor = StructArrayLayout2ui4;
StructArrayLayout2ui4.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.uint16 = new Uint16Array(this.arrayBuffer);
};
StructArrayLayout2ui4.prototype.emplaceBack = function emplaceBack(v0, v1) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0, v1);
};
StructArrayLayout2ui4.prototype.emplace = function emplace(i, v0, v1) {
var o2 = i * 2;
this.uint16[o2 + 0] = v0;
this.uint16[o2 + 1] = v1;
return i;
};
return StructArrayLayout2ui4;
}(StructArray);
StructArrayLayout2ui4.prototype.bytesPerElement = 4;
register('StructArrayLayout2ui4', StructArrayLayout2ui4);
var StructArrayLayout1ui2 = function (StructArray) {
function StructArrayLayout1ui2() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout1ui2.__proto__ = StructArray;
StructArrayLayout1ui2.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout1ui2.prototype.constructor = StructArrayLayout1ui2;
StructArrayLayout1ui2.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.uint16 = new Uint16Array(this.arrayBuffer);
};
StructArrayLayout1ui2.prototype.emplaceBack = function emplaceBack(v0) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0);
};
StructArrayLayout1ui2.prototype.emplace = function emplace(i, v0) {
var o2 = i * 1;
this.uint16[o2 + 0] = v0;
return i;
};
return StructArrayLayout1ui2;
}(StructArray);
StructArrayLayout1ui2.prototype.bytesPerElement = 2;
register('StructArrayLayout1ui2', StructArrayLayout1ui2);
var StructArrayLayout4f16 = function (StructArray) {
function StructArrayLayout4f16() {
StructArray.apply(this, arguments);
}
if (StructArray)
StructArrayLayout4f16.__proto__ = StructArray;
StructArrayLayout4f16.prototype = Object.create(StructArray && StructArray.prototype);
StructArrayLayout4f16.prototype.constructor = StructArrayLayout4f16;
StructArrayLayout4f16.prototype._refreshViews = function _refreshViews() {
this.uint8 = new Uint8Array(this.arrayBuffer);
this.float32 = new Float32Array(this.arrayBuffer);
};
StructArrayLayout4f16.prototype.emplaceBack = function emplaceBack(v0, v1, v2, v3) {
var i = this.length;
this.resize(i + 1);
return this.emplace(i, v0, v1, v2, v3);
};
StructArrayLayout4f16.prototype.emplace = function emplace(i, v0, v1, v2, v3) {
var o4 = i * 4;
this.float32[o4 + 0] = v0;
this.float32[o4 + 1] = v1;
this.float32[o4 + 2] = v2;
this.float32[o4 + 3] = v3;
return i;
};
return StructArrayLayout4f16;
}(StructArray);
StructArrayLayout4f16.prototype.bytesPerElement = 16;
register('StructArrayLayout4f16', StructArrayLayout4f16);
var CollisionBoxStruct = function (Struct) {
function CollisionBoxStruct() {
Struct.apply(this, arguments);
}
if (Struct)
CollisionBoxStruct.__proto__ = Struct;
CollisionBoxStruct.prototype = Object.create(Struct && Struct.prototype);
CollisionBoxStruct.prototype.constructor = CollisionBoxStruct;
var prototypeAccessors = {
anchorPointX: { configurable: true },
anchorPointY: { configurable: true },
x1: { configurable: true },
y1: { configurable: true },
x2: { configurable: true },
y2: { configurable: true },
featureIndex: { configurable: true },
sourceLayerIndex: { configurable: true },
bucketIndex: { configurable: true },
anchorPoint: { configurable: true }
};
prototypeAccessors.anchorPointX.get = function () {
return this._structArray.int16[this._pos2 + 0];
};
prototypeAccessors.anchorPointY.get = function () {
return this._structArray.int16[this._pos2 + 1];
};
prototypeAccessors.x1.get = function () {
return this._structArray.int16[this._pos2 + 2];
};
prototypeAccessors.y1.get = function () {
return this._structArray.int16[this._pos2 + 3];
};
prototypeAccessors.x2.get = function () {
return this._structArray.int16[this._pos2 + 4];
};
prototypeAccessors.y2.get = function () {
return this._structArray.int16[this._pos2 + 5];
};
prototypeAccessors.featureIndex.get = function () {
return this._structArray.uint32[this._pos4 + 3];
};
prototypeAccessors.sourceLayerIndex.get = function () {
return this._structArray.uint16[this._pos2 + 8];
};
prototypeAccessors.bucketIndex.get = function () {
return this._structArray.uint16[this._pos2 + 9];
};
prototypeAccessors.anchorPoint.get = function () {
return new pointGeometry(this.anchorPointX, this.anchorPointY);
};
Object.defineProperties(CollisionBoxStruct.prototype, prototypeAccessors);
return CollisionBoxStruct;
}(Struct);
CollisionBoxStruct.prototype.size = 20;
var CollisionBoxArray = function (StructArrayLayout6i1ul2ui20) {
function CollisionBoxArray() {
StructArrayLayout6i1ul2ui20.apply(this, arguments);
}
if (StructArrayLayout6i1ul2ui20)
CollisionBoxArray.__proto__ = StructArrayLayout6i1ul2ui20;
CollisionBoxArray.prototype = Object.create(StructArrayLayout6i1ul2ui20 && StructArrayLayout6i1ul2ui20.prototype);
CollisionBoxArray.prototype.constructor = CollisionBoxArray;
CollisionBoxArray.prototype.get = function get(index) {
return new CollisionBoxStruct(this, index);
};
return CollisionBoxArray;
}(StructArrayLayout6i1ul2ui20);
register('CollisionBoxArray', CollisionBoxArray);
var PlacedSymbolStruct = function (Struct) {
function PlacedSymbolStruct() {
Struct.apply(this, arguments);
}
if (Struct)
PlacedSymbolStruct.__proto__ = Struct;
PlacedSymbolStruct.prototype = Object.create(Struct && Struct.prototype);
PlacedSymbolStruct.prototype.constructor = PlacedSymbolStruct;
var prototypeAccessors$1 = {
anchorX: { configurable: true },
anchorY: { configurable: true },
glyphStartIndex: { configurable: true },
numGlyphs: { configurable: true },
vertexStartIndex: { configurable: true },
lineStartIndex: { configurable: true },
lineLength: { configurable: true },
segment: { configurable: true },
lowerSize: { configurable: true },
upperSize: { configurable: true },
lineOffsetX: { configurable: true },
lineOffsetY: { configurable: true },
writingMode: { configurable: true },
placedOrientation: { configurable: true },
hidden: { configurable: true },
crossTileID: { configurable: true },
associatedIconIndex: { configurable: true }
};
prototypeAccessors$1.anchorX.get = function () {
return this._structArray.int16[this._pos2 + 0];
};
prototypeAccessors$1.anchorY.get = function () {
return this._structArray.int16[this._pos2 + 1];
};
prototypeAccessors$1.glyphStartIndex.get = function () {
return this._structArray.uint16[this._pos2 + 2];
};
prototypeAccessors$1.numGlyphs.get = function () {
return this._structArray.uint16[this._pos2 + 3];
};
prototypeAccessors$1.vertexStartIndex.get = function () {
return this._structArray.uint32[this._pos4 + 2];
};
prototypeAccessors$1.lineStartIndex.get = function () {
return this._structArray.uint32[this._pos4 + 3];
};
prototypeAccessors$1.lineLength.get = function () {
return this._structArray.uint32[this._pos4 + 4];
};
prototypeAccessors$1.segment.get = function () {
return this._structArray.uint16[this._pos2 + 10];
};
prototypeAccessors$1.lowerSize.get = function () {
return this._structArray.uint16[this._pos2 + 11];
};
prototypeAccessors$1.upperSize.get = function () {
return this._structArray.uint16[this._pos2 + 12];
};
prototypeAccessors$1.lineOffsetX.get = function () {
return this._structArray.float32[this._pos4 + 7];
};
prototypeAccessors$1.lineOffsetY.get = function () {
return this._structArray.float32[this._pos4 + 8];
};
prototypeAccessors$1.writingMode.get = function () {
return this._structArray.uint8[this._pos1 + 36];
};
prototypeAccessors$1.placedOrientation.get = function () {
return this._structArray.uint8[this._pos1 + 37];
};
prototypeAccessors$1.placedOrientation.set = function (x) {
this._structArray.uint8[this._pos1 + 37] = x;
};
prototypeAccessors$1.hidden.get = function () {
return this._structArray.uint8[this._pos1 + 38];
};
prototypeAccessors$1.hidden.set = function (x) {
this._structArray.uint8[this._pos1 + 38] = x;
};
prototypeAccessors$1.crossTileID.get = function () {
return this._structArray.uint32[this._pos4 + 10];
};
prototypeAccessors$1.crossTileID.set = function (x) {
this._structArray.uint32[this._pos4 + 10] = x;
};
prototypeAccessors$1.associatedIconIndex.get = function () {
return this._structArray.int16[this._pos2 + 22];
};
Object.defineProperties(PlacedSymbolStruct.prototype, prototypeAccessors$1);
return PlacedSymbolStruct;
}(Struct);
PlacedSymbolStruct.prototype.size = 48;
var PlacedSymbolArray = function (StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48) {
function PlacedSymbolArray() {
StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48.apply(this, arguments);
}
if (StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48)
PlacedSymbolArray.__proto__ = StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48;
PlacedSymbolArray.prototype = Object.create(StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48 && StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48.prototype);
PlacedSymbolArray.prototype.constructor = PlacedSymbolArray;
PlacedSymbolArray.prototype.get = function get(index) {
return new PlacedSymbolStruct(this, index);
};
return PlacedSymbolArray;
}(StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48);
register('PlacedSymbolArray', PlacedSymbolArray);
var SymbolInstanceStruct = function (Struct) {
function SymbolInstanceStruct() {
Struct.apply(this, arguments);
}
if (Struct)
SymbolInstanceStruct.__proto__ = Struct;
SymbolInstanceStruct.prototype = Object.create(Struct && Struct.prototype);
SymbolInstanceStruct.prototype.constructor = SymbolInstanceStruct;
var prototypeAccessors$2 = {
anchorX: { configurable: true },
anchorY: { configurable: true },
rightJustifiedTextSymbolIndex: { configurable: true },
centerJustifiedTextSymbolIndex: { configurable: true },
leftJustifiedTextSymbolIndex: { configurable: true },
verticalPlacedTextSymbolIndex: { configurable: true },
placedIconSymbolIndex: { configurable: true },
verticalPlacedIconSymbolIndex: { configurable: true },
key: { configurable: true },
textBoxStartIndex: { configurable: true },
textBoxEndIndex: { configurable: true },
verticalTextBoxStartIndex: { configurable: true },
verticalTextBoxEndIndex: { configurable: true },
iconBoxStartIndex: { configurable: true },
iconBoxEndIndex: { configurable: true },
verticalIconBoxStartIndex: { configurable: true },
verticalIconBoxEndIndex: { configurable: true },
featureIndex: { configurable: true },
numHorizontalGlyphVertices: { configurable: true },
numVerticalGlyphVertices: { configurable: true },
numIconVertices: { configurable: true },
numVerticalIconVertices: { configurable: true },
useRuntimeCollisionCircles: { configurable: true },
crossTileID: { configurable: true },
textBoxScale: { configurable: true },
textOffset0: { configurable: true },
textOffset1: { configurable: true },
collisionCircleDiameter: { configurable: true }
};
prototypeAccessors$2.anchorX.get = function () {
return this._structArray.int16[this._pos2 + 0];
};
prototypeAccessors$2.anchorY.get = function () {
return this._structArray.int16[this._pos2 + 1];
};
prototypeAccessors$2.rightJustifiedTextSymbolIndex.get = function () {
return this._structArray.int16[this._pos2 + 2];
};
prototypeAccessors$2.centerJustifiedTextSymbolIndex.get = function () {
return this._structArray.int16[this._pos2 + 3];
};
prototypeAccessors$2.leftJustifiedTextSymbolIndex.get = function () {
return this._structArray.int16[this._pos2 + 4];
};
prototypeAccessors$2.verticalPlacedTextSymbolIndex.get = function () {
return this._structArray.int16[this._pos2 + 5];
};
prototypeAccessors$2.placedIconSymbolIndex.get = function () {
return this._structArray.int16[this._pos2 + 6];
};
prototypeAccessors$2.verticalPlacedIconSymbolIndex.get = function () {
return this._structArray.int16[this._pos2 + 7];
};
prototypeAccessors$2.key.get = function () {
return this._structArray.uint16[this._pos2 + 8];
};
prototypeAccessors$2.textBoxStartIndex.get = function () {
return this._structArray.uint16[this._pos2 + 9];
};
prototypeAccessors$2.textBoxEndIndex.get = function () {
return this._structArray.uint16[this._pos2 + 10];
};
prototypeAccessors$2.verticalTextBoxStartIndex.get = function () {
return this._structArray.uint16[this._pos2 + 11];
};
prototypeAccessors$2.verticalTextBoxEndIndex.get = function () {
return this._structArray.uint16[this._pos2 + 12];
};
prototypeAccessors$2.iconBoxStartIndex.get = function () {
return this._structArray.uint16[this._pos2 + 13];
};
prototypeAccessors$2.iconBoxEndIndex.get = function () {
return this._structArray.uint16[this._pos2 + 14];
};
prototypeAccessors$2.verticalIconBoxStartIndex.get = function () {
return this._structArray.uint16[this._pos2 + 15];
};
prototypeAccessors$2.verticalIconBoxEndIndex.get = function () {
return this._structArray.uint16[this._pos2 + 16];
};
prototypeAccessors$2.featureIndex.get = function () {
return this._structArray.uint16[this._pos2 + 17];
};
prototypeAccessors$2.numHorizontalGlyphVertices.get = function () {
return this._structArray.uint16[this._pos2 + 18];
};
prototypeAccessors$2.numVerticalGlyphVertices.get = function () {
return this._structArray.uint16[this._pos2 + 19];
};
prototypeAccessors$2.numIconVertices.get = function () {
return this._structArray.uint16[this._pos2 + 20];
};
prototypeAccessors$2.numVerticalIconVertices.get = function () {
return this._structArray.uint16[this._pos2 + 21];
};
prototypeAccessors$2.useRuntimeCollisionCircles.get = function () {
return this._structArray.uint16[this._pos2 + 22];
};
prototypeAccessors$2.crossTileID.get = function () {
return this._structArray.uint32[this._pos4 + 12];
};
prototypeAccessors$2.crossTileID.set = function (x) {
this._structArray.uint32[this._pos4 + 12] = x;
};
prototypeAccessors$2.textBoxScale.get = function () {
return this._structArray.float32[this._pos4 + 13];
};
prototypeAccessors$2.textOffset0.get = function () {
return this._structArray.float32[this._pos4 + 14];
};
prototypeAccessors$2.textOffset1.get = function () {
return this._structArray.float32[this._pos4 + 15];
};
prototypeAccessors$2.collisionCircleDiameter.get = function () {
return this._structArray.float32[this._pos4 + 16];
};
Object.defineProperties(SymbolInstanceStruct.prototype, prototypeAccessors$2);
return SymbolInstanceStruct;
}(Struct);
SymbolInstanceStruct.prototype.size = 68;
var SymbolInstanceArray = function (StructArrayLayout8i15ui1ul4f68) {
function SymbolInstanceArray() {
StructArrayLayout8i15ui1ul4f68.apply(this, arguments);
}
if (StructArrayLayout8i15ui1ul4f68)
SymbolInstanceArray.__proto__ = StructArrayLayout8i15ui1ul4f68;
SymbolInstanceArray.prototype = Object.create(StructArrayLayout8i15ui1ul4f68 && StructArrayLayout8i15ui1ul4f68.prototype);
SymbolInstanceArray.prototype.constructor = SymbolInstanceArray;
SymbolInstanceArray.prototype.get = function get(index) {
return new SymbolInstanceStruct(this, index);
};
return SymbolInstanceArray;
}(StructArrayLayout8i15ui1ul4f68);
register('SymbolInstanceArray', SymbolInstanceArray);
var GlyphOffsetArray = function (StructArrayLayout1f4) {
function GlyphOffsetArray() {
StructArrayLayout1f4.apply(this, arguments);
}
if (StructArrayLayout1f4)
GlyphOffsetArray.__proto__ = StructArrayLayout1f4;
GlyphOffsetArray.prototype = Object.create(StructArrayLayout1f4 && StructArrayLayout1f4.prototype);
GlyphOffsetArray.prototype.constructor = GlyphOffsetArray;
GlyphOffsetArray.prototype.getoffsetX = function getoffsetX(index) {
return this.float32[index * 1 + 0];
};
return GlyphOffsetArray;
}(StructArrayLayout1f4);
register('GlyphOffsetArray', GlyphOffsetArray);
var SymbolLineVertexArray = function (StructArrayLayout3i6) {
function SymbolLineVertexArray() {
StructArrayLayout3i6.apply(this, arguments);
}
if (StructArrayLayout3i6)
SymbolLineVertexArray.__proto__ = StructArrayLayout3i6;
SymbolLineVertexArray.prototype = Object.create(StructArrayLayout3i6 && StructArrayLayout3i6.prototype);
SymbolLineVertexArray.prototype.constructor = SymbolLineVertexArray;
SymbolLineVertexArray.prototype.getx = function getx(index) {
return this.int16[index * 3 + 0];
};
SymbolLineVertexArray.prototype.gety = function gety(index) {
return this.int16[index * 3 + 1];
};
SymbolLineVertexArray.prototype.gettileUnitDistanceFromAnchor = function gettileUnitDistanceFromAnchor(index) {
return this.int16[index * 3 + 2];
};
return SymbolLineVertexArray;
}(StructArrayLayout3i6);
register('SymbolLineVertexArray', SymbolLineVertexArray);
var FeatureIndexStruct = function (Struct) {
function FeatureIndexStruct() {
Struct.apply(this, arguments);
}
if (Struct)
FeatureIndexStruct.__proto__ = Struct;
FeatureIndexStruct.prototype = Object.create(Struct && Struct.prototype);
FeatureIndexStruct.prototype.constructor = FeatureIndexStruct;
var prototypeAccessors$3 = {
featureIndex: { configurable: true },
sourceLayerIndex: { configurable: true },
bucketIndex: { configurable: true }
};
prototypeAccessors$3.featureIndex.get = function () {
return this._structArray.uint32[this._pos4 + 0];
};
prototypeAccessors$3.sourceLayerIndex.get = function () {
return this._structArray.uint16[this._pos2 + 2];
};
prototypeAccessors$3.bucketIndex.get = function () {
return this._structArray.uint16[this._pos2 + 3];
};
Object.defineProperties(FeatureIndexStruct.prototype, prototypeAccessors$3);
return FeatureIndexStruct;
}(Struct);
FeatureIndexStruct.prototype.size = 8;
var FeatureIndexArray = function (StructArrayLayout1ul2ui8) {
function FeatureIndexArray() {
StructArrayLayout1ul2ui8.apply(this, arguments);
}
if (StructArrayLayout1ul2ui8)
FeatureIndexArray.__proto__ = StructArrayLayout1ul2ui8;
FeatureIndexArray.prototype = Object.create(StructArrayLayout1ul2ui8 && StructArrayLayout1ul2ui8.prototype);
FeatureIndexArray.prototype.constructor = FeatureIndexArray;
FeatureIndexArray.prototype.get = function get(index) {
return new FeatureIndexStruct(this, index);
};
return FeatureIndexArray;
}(StructArrayLayout1ul2ui8);
register('FeatureIndexArray', FeatureIndexArray);
var layout$1 = createLayout([{
name: 'a_pos',
components: 2,
type: 'Int16'
}], 4);
var members = layout$1.members;
var SegmentVector = function SegmentVector(segments) {
if (segments === void 0)
segments = [];
this.segments = segments;
};
SegmentVector.prototype.prepareSegment = function prepareSegment(numVertices, layoutVertexArray, indexArray, sortKey) {
var segment = this.segments[this.segments.length - 1];
if (numVertices > SegmentVector.MAX_VERTEX_ARRAY_LENGTH) {
warnOnce('Max vertices per segment is ' + SegmentVector.MAX_VERTEX_ARRAY_LENGTH + ': bucket requested ' + numVertices);
}
if (!segment || segment.vertexLength + numVertices > SegmentVector.MAX_VERTEX_ARRAY_LENGTH || segment.sortKey !== sortKey) {
segment = {
vertexOffset: layoutVertexArray.length,
primitiveOffset: indexArray.length,
vertexLength: 0,
primitiveLength: 0
};
if (sortKey !== undefined) {
segment.sortKey = sortKey;
}
this.segments.push(segment);
}
return segment;
};
SegmentVector.prototype.get = function get() {
return this.segments;
};
SegmentVector.prototype.destroy = function destroy() {
for (var i = 0, list = this.segments; i < list.length; i += 1) {
var segment = list[i];
for (var k in segment.vaos) {
segment.vaos[k].destroy();
}
}
};
SegmentVector.simpleSegment = function simpleSegment(vertexOffset, primitiveOffset, vertexLength, primitiveLength) {
return new SegmentVector([{
vertexOffset: vertexOffset,
primitiveOffset: primitiveOffset,
vertexLength: vertexLength,
primitiveLength: primitiveLength,
vaos: {},
sortKey: 0
}]);
};
SegmentVector.MAX_VERTEX_ARRAY_LENGTH = Math.pow(2, 16) - 1;
register('SegmentVector', SegmentVector);
function packUint8ToFloat(a, b) {
a = clamp(Math.floor(a), 0, 255);
b = clamp(Math.floor(b), 0, 255);
return 256 * a + b;
}
var patternAttributes = createLayout([
{
name: 'a_pattern_from',
components: 4,
type: 'Uint16'
},
{
name: 'a_pattern_to',
components: 4,
type: 'Uint16'
},
{
name: 'a_pixel_ratio_from',
components: 1,
type: 'Uint16'
},
{
name: 'a_pixel_ratio_to',
components: 1,
type: 'Uint16'
}
]);
var murmurhash3_gc = createCommonjsModule(function (module) {
function murmurhash3_32_gc(key, seed) {
var remainder, bytes, h1, h1b, c1, c2, k1, i;
remainder = key.length & 3;
bytes = key.length - remainder;
h1 = seed;
c1 = 3432918353;
c2 = 461845907;
i = 0;
while (i < bytes) {
k1 = key.charCodeAt(i) & 255 | (key.charCodeAt(++i) & 255) << 8 | (key.charCodeAt(++i) & 255) << 16 | (key.charCodeAt(++i) & 255) << 24;
++i;
k1 = (k1 & 65535) * c1 + (((k1 >>> 16) * c1 & 65535) << 16) & 4294967295;
k1 = k1 << 15 | k1 >>> 17;
k1 = (k1 & 65535) * c2 + (((k1 >>> 16) * c2 & 65535) << 16) & 4294967295;
h1 ^= k1;
h1 = h1 << 13 | h1 >>> 19;
h1b = (h1 & 65535) * 5 + (((h1 >>> 16) * 5 & 65535) << 16) & 4294967295;
h1 = (h1b & 65535) + 27492 + (((h1b >>> 16) + 58964 & 65535) << 16);
}
k1 = 0;
switch (remainder) {
case 3:
k1 ^= (key.charCodeAt(i + 2) & 255) << 16;
case 2:
k1 ^= (key.charCodeAt(i + 1) & 255) << 8;
case 1:
k1 ^= key.charCodeAt(i) & 255;
k1 = (k1 & 65535) * c1 + (((k1 >>> 16) * c1 & 65535) << 16) & 4294967295;
k1 = k1 << 15 | k1 >>> 17;
k1 = (k1 & 65535) * c2 + (((k1 >>> 16) * c2 & 65535) << 16) & 4294967295;
h1 ^= k1;
}
h1 ^= key.length;
h1 ^= h1 >>> 16;
h1 = (h1 & 65535) * 2246822507 + (((h1 >>> 16) * 2246822507 & 65535) << 16) & 4294967295;
h1 ^= h1 >>> 13;
h1 = (h1 & 65535) * 3266489909 + (((h1 >>> 16) * 3266489909 & 65535) << 16) & 4294967295;
h1 ^= h1 >>> 16;
return h1 >>> 0;
}
{
module.exports = murmurhash3_32_gc;
}
});
var murmurhash2_gc = createCommonjsModule(function (module) {
function murmurhash2_32_gc(str, seed) {
var l = str.length, h = seed ^ l, i = 0, k;
while (l >= 4) {
k = str.charCodeAt(i) & 255 | (str.charCodeAt(++i) & 255) << 8 | (str.charCodeAt(++i) & 255) << 16 | (str.charCodeAt(++i) & 255) << 24;
k = (k & 65535) * 1540483477 + (((k >>> 16) * 1540483477 & 65535) << 16);
k ^= k >>> 24;
k = (k & 65535) * 1540483477 + (((k >>> 16) * 1540483477 & 65535) << 16);
h = (h & 65535) * 1540483477 + (((h >>> 16) * 1540483477 & 65535) << 16) ^ k;
l -= 4;
++i;
}
switch (l) {
case 3:
h ^= (str.charCodeAt(i + 2) & 255) << 16;
case 2:
h ^= (str.charCodeAt(i + 1) & 255) << 8;
case 1:
h ^= str.charCodeAt(i) & 255;
h = (h & 65535) * 1540483477 + (((h >>> 16) * 1540483477 & 65535) << 16);
}
h ^= h >>> 13;
h = (h & 65535) * 1540483477 + (((h >>> 16) * 1540483477 & 65535) << 16);
h ^= h >>> 15;
return h >>> 0;
}
{
module.exports = murmurhash2_32_gc;
}
});
var murmurhashJs = murmurhash3_gc;
var murmur3_1 = murmurhash3_gc;
var murmur2_1 = murmurhash2_gc;
murmurhashJs.murmur3 = murmur3_1;
murmurhashJs.murmur2 = murmur2_1;
var FeaturePositionMap = function FeaturePositionMap() {
this.ids = [];
this.positions = [];
this.indexed = false;
};
FeaturePositionMap.prototype.add = function add(id, index, start, end) {
this.ids.push(getNumericId(id));
this.positions.push(index, start, end);
};
FeaturePositionMap.prototype.getPositions = function getPositions(id) {
var intId = getNumericId(id);
var i = 0;
var j = this.ids.length - 1;
while (i < j) {
var m = i + j >> 1;
if (this.ids[m] >= intId) {
j = m;
} else {
i = m + 1;
}
}
var positions = [];
while (this.ids[i] === intId) {
var index = this.positions[3 * i];
var start = this.positions[3 * i + 1];
var end = this.positions[3 * i + 2];
positions.push({
index: index,
start: start,
end: end
});
i++;
}
return positions;
};
FeaturePositionMap.serialize = function serialize(map, transferables) {
var ids = new Float64Array(map.ids);
var positions = new Uint32Array(map.positions);
sort(ids, positions, 0, ids.length - 1);
if (transferables) {
transferables.push(ids.buffer, positions.buffer);
}
return {
ids: ids,
positions: positions
};
};
FeaturePositionMap.deserialize = function deserialize(obj) {
var map = new FeaturePositionMap();
map.ids = obj.ids;
map.positions = obj.positions;
map.indexed = true;
return map;
};
var MAX_SAFE_INTEGER$1 = Math.pow(2, 53) - 1;
function getNumericId(value) {
var numValue = +value;
if (!isNaN(numValue) && numValue <= MAX_SAFE_INTEGER$1) {
return numValue;
}
return murmurhashJs(String(value));
}
function sort(ids, positions, left, right) {
while (left < right) {
var pivot = ids[left + right >> 1];
var i = left - 1;
var j = right + 1;
while (true) {
do {
i++;
} while (ids[i] < pivot);
do {
j--;
} while (ids[j] > pivot);
if (i >= j) {
break;
}
swap(ids, i, j);
swap(positions, 3 * i, 3 * j);
swap(positions, 3 * i + 1, 3 * j + 1);
swap(positions, 3 * i + 2, 3 * j + 2);
}
if (j - left < right - j) {
sort(ids, positions, left, j);
left = j + 1;
} else {
sort(ids, positions, j + 1, right);
right = j;
}
}
}
function swap(arr, i, j) {
var tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
register('FeaturePositionMap', FeaturePositionMap);
var Uniform = function Uniform(context, location) {
this.gl = context.gl;
this.location = location;
};
var Uniform1i = function (Uniform) {
function Uniform1i(context, location) {
Uniform.call(this, context, location);
this.current = 0;
}
if (Uniform)
Uniform1i.__proto__ = Uniform;
Uniform1i.prototype = Object.create(Uniform && Uniform.prototype);
Uniform1i.prototype.constructor = Uniform1i;
Uniform1i.prototype.set = function set(v) {
if (this.current !== v) {
this.current = v;
this.gl.uniform1i(this.location, v);
}
};
return Uniform1i;
}(Uniform);
var Uniform1f = function (Uniform) {
function Uniform1f(context, location) {
Uniform.call(this, context, location);
this.current = 0;
}
if (Uniform)
Uniform1f.__proto__ = Uniform;
Uniform1f.prototype = Object.create(Uniform && Uniform.prototype);
Uniform1f.prototype.constructor = Uniform1f;
Uniform1f.prototype.set = function set(v) {
if (this.current !== v) {
this.current = v;
this.gl.uniform1f(this.location, v);
}
};
return Uniform1f;
}(Uniform);
var Uniform2f = function (Uniform) {
function Uniform2f(context, location) {
Uniform.call(this, context, location);
this.current = [
0,
0
];
}
if (Uniform)
Uniform2f.__proto__ = Uniform;
Uniform2f.prototype = Object.create(Uniform && Uniform.prototype);
Uniform2f.prototype.constructor = Uniform2f;
Uniform2f.prototype.set = function set(v) {
if (v[0] !== this.current[0] || v[1] !== this.current[1]) {
this.current = v;
this.gl.uniform2f(this.location, v[0], v[1]);
}
};
return Uniform2f;
}(Uniform);
var Uniform3f = function (Uniform) {
function Uniform3f(context, location) {
Uniform.call(this, context, location);
this.current = [
0,
0,
0
];
}
if (Uniform)
Uniform3f.__proto__ = Uniform;
Uniform3f.prototype = Object.create(Uniform && Uniform.prototype);
Uniform3f.prototype.constructor = Uniform3f;
Uniform3f.prototype.set = function set(v) {
if (v[0] !== this.current[0] || v[1] !== this.current[1] || v[2] !== this.current[2]) {
this.current = v;
this.gl.uniform3f(this.location, v[0], v[1], v[2]);
}
};
return Uniform3f;
}(Uniform);
var Uniform4f = function (Uniform) {
function Uniform4f(context, location) {
Uniform.call(this, context, location);
this.current = [
0,
0,
0,
0
];
}
if (Uniform)
Uniform4f.__proto__ = Uniform;
Uniform4f.prototype = Object.create(Uniform && Uniform.prototype);
Uniform4f.prototype.constructor = Uniform4f;
Uniform4f.prototype.set = function set(v) {
if (v[0] !== this.current[0] || v[1] !== this.current[1] || v[2] !== this.current[2] || v[3] !== this.current[3]) {
this.current = v;
this.gl.uniform4f(this.location, v[0], v[1], v[2], v[3]);
}
};
return Uniform4f;
}(Uniform);
var UniformColor = function (Uniform) {
function UniformColor(context, location) {
Uniform.call(this, context, location);
this.current = Color.transparent;
}
if (Uniform)
UniformColor.__proto__ = Uniform;
UniformColor.prototype = Object.create(Uniform && Uniform.prototype);
UniformColor.prototype.constructor = UniformColor;
UniformColor.prototype.set = function set(v) {
if (v.r !== this.current.r || v.g !== this.current.g || v.b !== this.current.b || v.a !== this.current.a) {
this.current = v;
this.gl.uniform4f(this.location, v.r, v.g, v.b, v.a);
}
};
return UniformColor;
}(Uniform);
var emptyMat4 = new Float32Array(16);
var UniformMatrix4f = function (Uniform) {
function UniformMatrix4f(context, location) {
Uniform.call(this, context, location);
this.current = emptyMat4;
}
if (Uniform)
UniformMatrix4f.__proto__ = Uniform;
UniformMatrix4f.prototype = Object.create(Uniform && Uniform.prototype);
UniformMatrix4f.prototype.constructor = UniformMatrix4f;
UniformMatrix4f.prototype.set = function set(v) {
if (v[12] !== this.current[12] || v[0] !== this.current[0]) {
this.current = v;
this.gl.uniformMatrix4fv(this.location, false, v);
return;
}
for (var i = 1; i < 16; i++) {
if (v[i] !== this.current[i]) {
this.current = v;
this.gl.uniformMatrix4fv(this.location, false, v);
break;
}
}
};
return UniformMatrix4f;
}(Uniform);
function packColor(color) {
return [
packUint8ToFloat(255 * color.r, 255 * color.g),
packUint8ToFloat(255 * color.b, 255 * color.a)
];
}
var ConstantBinder = function ConstantBinder(value, names, type) {
this.value = value;
this.uniformNames = names.map(function (name) {
return 'u_' + name;
});
this.type = type;
};
ConstantBinder.prototype.setUniform = function setUniform(uniform, globals, currentValue) {
uniform.set(currentValue.constantOr(this.value));
};
ConstantBinder.prototype.getBinding = function getBinding(context, location, _) {
return this.type === 'color' ? new UniformColor(context, location) : new Uniform1f(context, location);
};
var CrossFadedConstantBinder = function CrossFadedConstantBinder(value, names) {
this.uniformNames = names.map(function (name) {
return 'u_' + name;
});
this.patternFrom = null;
this.patternTo = null;
this.pixelRatioFrom = 1;
this.pixelRatioTo = 1;
};
CrossFadedConstantBinder.prototype.setConstantPatternPositions = function setConstantPatternPositions(posTo, posFrom) {
this.pixelRatioFrom = posFrom.pixelRatio;
this.pixelRatioTo = posTo.pixelRatio;
this.patternFrom = posFrom.tlbr;
this.patternTo = posTo.tlbr;
};
CrossFadedConstantBinder.prototype.setUniform = function setUniform(uniform, globals, currentValue, uniformName) {
var pos = uniformName === 'u_pattern_to' ? this.patternTo : uniformName === 'u_pattern_from' ? this.patternFrom : uniformName === 'u_pixel_ratio_to' ? this.pixelRatioTo : uniformName === 'u_pixel_ratio_from' ? this.pixelRatioFrom : null;
if (pos) {
uniform.set(pos);
}
};
CrossFadedConstantBinder.prototype.getBinding = function getBinding(context, location, name) {
return name.substr(0, 9) === 'u_pattern' ? new Uniform4f(context, location) : new Uniform1f(context, location);
};
var SourceExpressionBinder = function SourceExpressionBinder(expression, names, type, PaintVertexArray) {
this.expression = expression;
this.type = type;
this.maxValue = 0;
this.paintVertexAttributes = names.map(function (name) {
return {
name: 'a_' + name,
type: 'Float32',
components: type === 'color' ? 2 : 1,
offset: 0
};
});
this.paintVertexArray = new PaintVertexArray();
};
SourceExpressionBinder.prototype.populatePaintArray = function populatePaintArray(newLength, feature, imagePositions, canonical, formattedSection) {
var start = this.paintVertexArray.length;
var value = this.expression.evaluate(new EvaluationParameters(0), feature, {}, canonical, [], formattedSection);
this.paintVertexArray.resize(newLength);
this._setPaintValue(start, newLength, value);
};
SourceExpressionBinder.prototype.updatePaintArray = function updatePaintArray(start, end, feature, featureState) {
var value = this.expression.evaluate({ zoom: 0 }, feature, featureState);
this._setPaintValue(start, end, value);
};
SourceExpressionBinder.prototype._setPaintValue = function _setPaintValue(start, end, value) {
if (this.type === 'color') {
var color = packColor(value);
for (var i = start; i < end; i++) {
this.paintVertexArray.emplace(i, color[0], color[1]);
}
} else {
for (var i$1 = start; i$1 < end; i$1++) {
this.paintVertexArray.emplace(i$1, value);
}
this.maxValue = Math.max(this.maxValue, Math.abs(value));
}
};
SourceExpressionBinder.prototype.upload = function upload(context) {
if (this.paintVertexArray && this.paintVertexArray.arrayBuffer) {
if (this.paintVertexBuffer && this.paintVertexBuffer.buffer) {
this.paintVertexBuffer.updateData(this.paintVertexArray);
} else {
this.paintVertexBuffer = context.createVertexBuffer(this.paintVertexArray, this.paintVertexAttributes, this.expression.isStateDependent);
}
}
};
SourceExpressionBinder.prototype.destroy = function destroy() {
if (this.paintVertexBuffer) {
this.paintVertexBuffer.destroy();
}
};
var CompositeExpressionBinder = function CompositeExpressionBinder(expression, names, type, useIntegerZoom, zoom, PaintVertexArray) {
this.expression = expression;
this.uniformNames = names.map(function (name) {
return 'u_' + name + '_t';
});
this.type = type;
this.useIntegerZoom = useIntegerZoom;
this.zoom = zoom;
this.maxValue = 0;
this.paintVertexAttributes = names.map(function (name) {
return {
name: 'a_' + name,
type: 'Float32',
components: type === 'color' ? 4 : 2,
offset: 0
};
});
this.paintVertexArray = new PaintVertexArray();
};
CompositeExpressionBinder.prototype.populatePaintArray = function populatePaintArray(newLength, feature, imagePositions, canonical, formattedSection) {
var min = this.expression.evaluate(new EvaluationParameters(this.zoom), feature, {}, canonical, [], formattedSection);
var max = this.expression.evaluate(new EvaluationParameters(this.zoom + 1), feature, {}, canonical, [], formattedSection);
var start = this.paintVertexArray.length;
this.paintVertexArray.resize(newLength);
this._setPaintValue(start, newLength, min, max);
};
CompositeExpressionBinder.prototype.updatePaintArray = function updatePaintArray(start, end, feature, featureState) {
var min = this.expression.evaluate({ zoom: this.zoom }, feature, featureState);
var max = this.expression.evaluate({ zoom: this.zoom + 1 }, feature, featureState);
this._setPaintValue(start, end, min, max);
};
CompositeExpressionBinder.prototype._setPaintValue = function _setPaintValue(start, end, min, max) {
if (this.type === 'color') {
var minColor = packColor(min);
var maxColor = packColor(max);
for (var i = start; i < end; i++) {
this.paintVertexArray.emplace(i, minColor[0], minColor[1], maxColor[0], maxColor[1]);
}
} else {
for (var i$1 = start; i$1 < end; i$1++) {
this.paintVertexArray.emplace(i$1, min, max);
}
this.maxValue = Math.max(this.maxValue, Math.abs(min), Math.abs(max));
}
};
CompositeExpressionBinder.prototype.upload = function upload(context) {
if (this.paintVertexArray && this.paintVertexArray.arrayBuffer) {
if (this.paintVertexBuffer && this.paintVertexBuffer.buffer) {
this.paintVertexBuffer.updateData(this.paintVertexArray);
} else {
this.paintVertexBuffer = context.createVertexBuffer(this.paintVertexArray, this.paintVertexAttributes, this.expression.isStateDependent);
}
}
};
CompositeExpressionBinder.prototype.destroy = function destroy() {
if (this.paintVertexBuffer) {
this.paintVertexBuffer.destroy();
}
};
CompositeExpressionBinder.prototype.setUniform = function setUniform(uniform, globals) {
var currentZoom = this.useIntegerZoom ? Math.floor(globals.zoom) : globals.zoom;
var factor = clamp(this.expression.interpolationFactor(currentZoom, this.zoom, this.zoom + 1), 0, 1);
uniform.set(factor);
};
CompositeExpressionBinder.prototype.getBinding = function getBinding(context, location, _) {
return new Uniform1f(context, location);
};
var CrossFadedCompositeBinder = function CrossFadedCompositeBinder(expression, type, useIntegerZoom, zoom, PaintVertexArray, layerId) {
this.expression = expression;
this.type = type;
this.useIntegerZoom = useIntegerZoom;
this.zoom = zoom;
this.layerId = layerId;
this.zoomInPaintVertexArray = new PaintVertexArray();
this.zoomOutPaintVertexArray = new PaintVertexArray();
};
CrossFadedCompositeBinder.prototype.populatePaintArray = function populatePaintArray(length, feature, imagePositions) {
var start = this.zoomInPaintVertexArray.length;
this.zoomInPaintVertexArray.resize(length);
this.zoomOutPaintVertexArray.resize(length);
this._setPaintValues(start, length, feature.patterns && feature.patterns[this.layerId], imagePositions);
};
CrossFadedCompositeBinder.prototype.updatePaintArray = function updatePaintArray(start, end, feature, featureState, imagePositions) {
this._setPaintValues(start, end, feature.patterns && feature.patterns[this.layerId], imagePositions);
};
CrossFadedCompositeBinder.prototype._setPaintValues = function _setPaintValues(start, end, patterns, positions) {
if (!positions || !patterns) {
return;
}
var min = patterns.min;
var mid = patterns.mid;
var max = patterns.max;
var imageMin = positions[min];
var imageMid = positions[mid];
var imageMax = positions[max];
if (!imageMin || !imageMid || !imageMax) {
return;
}
for (var i = start; i < end; i++) {
this.zoomInPaintVertexArray.emplace(i, imageMid.tl[0], imageMid.tl[1], imageMid.br[0], imageMid.br[1], imageMin.tl[0], imageMin.tl[1], imageMin.br[0], imageMin.br[1], imageMid.pixelRatio, imageMin.pixelRatio);
this.zoomOutPaintVertexArray.emplace(i, imageMid.tl[0], imageMid.tl[1], imageMid.br[0], imageMid.br[1], imageMax.tl[0], imageMax.tl[1], imageMax.br[0], imageMax.br[1], imageMid.pixelRatio, imageMax.pixelRatio);
}
};
CrossFadedCompositeBinder.prototype.upload = function upload(context) {
if (this.zoomInPaintVertexArray && this.zoomInPaintVertexArray.arrayBuffer && this.zoomOutPaintVertexArray && this.zoomOutPaintVertexArray.arrayBuffer) {
this.zoomInPaintVertexBuffer = context.createVertexBuffer(this.zoomInPaintVertexArray, patternAttributes.members, this.expression.isStateDependent);
this.zoomOutPaintVertexBuffer = context.createVertexBuffer(this.zoomOutPaintVertexArray, patternAttributes.members, this.expression.isStateDependent);
}
};
CrossFadedCompositeBinder.prototype.destroy = function destroy() {
if (this.zoomOutPaintVertexBuffer) {
this.zoomOutPaintVertexBuffer.destroy();
}
if (this.zoomInPaintVertexBuffer) {
this.zoomInPaintVertexBuffer.destroy();
}
};
var ProgramConfiguration = function ProgramConfiguration(layer, zoom, filterProperties) {
this.binders = {};
this._buffers = [];
var keys = [];
for (var property in layer.paint._values) {
if (!filterProperties(property)) {
continue;
}
var value = layer.paint.get(property);
if (!(value instanceof PossiblyEvaluatedPropertyValue) || !supportsPropertyExpression(value.property.specification)) {
continue;
}
var names = paintAttributeNames(property, layer.type);
var expression = value.value;
var type = value.property.specification.type;
var useIntegerZoom = value.property.useIntegerZoom;
var propType = value.property.specification['property-type'];
var isCrossFaded = propType === 'cross-faded' || propType === 'cross-faded-data-driven';
if (expression.kind === 'constant') {
this.binders[property] = isCrossFaded ? new CrossFadedConstantBinder(expression.value, names) : new ConstantBinder(expression.value, names, type);
keys.push('/u_' + property);
} else if (expression.kind === 'source' || isCrossFaded) {
var StructArrayLayout = layoutType(property, type, 'source');
this.binders[property] = isCrossFaded ? new CrossFadedCompositeBinder(expression, type, useIntegerZoom, zoom, StructArrayLayout, layer.id) : new SourceExpressionBinder(expression, names, type, StructArrayLayout);
keys.push('/a_' + property);
} else {
var StructArrayLayout$1 = layoutType(property, type, 'composite');
this.binders[property] = new CompositeExpressionBinder(expression, names, type, useIntegerZoom, zoom, StructArrayLayout$1);
keys.push('/z_' + property);
}
}
this.cacheKey = keys.sort().join('');
};
ProgramConfiguration.prototype.getMaxValue = function getMaxValue(property) {
var binder = this.binders[property];
return binder instanceof SourceExpressionBinder || binder instanceof CompositeExpressionBinder ? binder.maxValue : 0;
};
ProgramConfiguration.prototype.populatePaintArrays = function populatePaintArrays(newLength, feature, imagePositions, canonical, formattedSection) {
for (var property in this.binders) {
var binder = this.binders[property];
if (binder instanceof SourceExpressionBinder || binder instanceof CompositeExpressionBinder || binder instanceof CrossFadedCompositeBinder) {
binder.populatePaintArray(newLength, feature, imagePositions, canonical, formattedSection);
}
}
};
ProgramConfiguration.prototype.setConstantPatternPositions = function setConstantPatternPositions(posTo, posFrom) {
for (var property in this.binders) {
var binder = this.binders[property];
if (binder instanceof CrossFadedConstantBinder) {
binder.setConstantPatternPositions(posTo, posFrom);
}
}
};
ProgramConfiguration.prototype.updatePaintArrays = function updatePaintArrays(featureStates, featureMap, vtLayer, layer, imagePositions) {
var dirty = false;
for (var id in featureStates) {
var positions = featureMap.getPositions(id);
for (var i = 0, list = positions; i < list.length; i += 1) {
var pos = list[i];
var feature = vtLayer.feature(pos.index);
for (var property in this.binders) {
var binder = this.binders[property];
if ((binder instanceof SourceExpressionBinder || binder instanceof CompositeExpressionBinder || binder instanceof CrossFadedCompositeBinder) && binder.expression.isStateDependent === true) {
var value = layer.paint.get(property);
binder.expression = value.value;
binder.updatePaintArray(pos.start, pos.end, feature, featureStates[id], imagePositions);
dirty = true;
}
}
}
}
return dirty;
};
ProgramConfiguration.prototype.defines = function defines() {
var result = [];
for (var property in this.binders) {
var binder = this.binders[property];
if (binder instanceof ConstantBinder || binder instanceof CrossFadedConstantBinder) {
result.push.apply(result, binder.uniformNames.map(function (name) {
return '#define HAS_UNIFORM_' + name;
}));
}
}
return result;
};
ProgramConfiguration.prototype.getBinderAttributes = function getBinderAttributes() {
var result = [];
for (var property in this.binders) {
var binder = this.binders[property];
if (binder instanceof SourceExpressionBinder || binder instanceof CompositeExpressionBinder) {
for (var i = 0; i < binder.paintVertexAttributes.length; i++) {
result.push(binder.paintVertexAttributes[i].name);
}
} else if (binder instanceof CrossFadedCompositeBinder) {
for (var i$1 = 0; i$1 < patternAttributes.members.length; i$1++) {
result.push(patternAttributes.members[i$1].name);
}
}
}
return result;
};
ProgramConfiguration.prototype.getBinderUniforms = function getBinderUniforms() {
var uniforms = [];
for (var property in this.binders) {
var binder = this.binders[property];
if (binder instanceof ConstantBinder || binder instanceof CrossFadedConstantBinder || binder instanceof CompositeExpressionBinder) {
for (var i = 0, list = binder.uniformNames; i < list.length; i += 1) {
var uniformName = list[i];
uniforms.push(uniformName);
}
}
}
return uniforms;
};
ProgramConfiguration.prototype.getPaintVertexBuffers = function getPaintVertexBuffers() {
return this._buffers;
};
ProgramConfiguration.prototype.getUniforms = function getUniforms(context, locations) {
var uniforms = [];
for (var property in this.binders) {
var binder = this.binders[property];
if (binder instanceof ConstantBinder || binder instanceof CrossFadedConstantBinder || binder instanceof CompositeExpressionBinder) {
for (var i = 0, list = binder.uniformNames; i < list.length; i += 1) {
var name = list[i];
if (locations[name]) {
var binding = binder.getBinding(context, locations[name], name);
uniforms.push({
name: name,
property: property,
binding: binding
});
}
}
}
}
return uniforms;
};
ProgramConfiguration.prototype.setUniforms = function setUniforms(context, binderUniforms, properties, globals) {
for (var i = 0, list = binderUniforms; i < list.length; i += 1) {
var ref = list[i];
var name = ref.name;
var property = ref.property;
var binding = ref.binding;
this.binders[property].setUniform(binding, globals, properties.get(property), name);
}
};
ProgramConfiguration.prototype.updatePaintBuffers = function updatePaintBuffers(crossfade) {
this._buffers = [];
for (var property in this.binders) {
var binder = this.binders[property];
if (crossfade && binder instanceof CrossFadedCompositeBinder) {
var patternVertexBuffer = crossfade.fromScale === 2 ? binder.zoomInPaintVertexBuffer : binder.zoomOutPaintVertexBuffer;
if (patternVertexBuffer) {
this._buffers.push(patternVertexBuffer);
}
} else if ((binder instanceof SourceExpressionBinder || binder instanceof CompositeExpressionBinder) && binder.paintVertexBuffer) {
this._buffers.push(binder.paintVertexBuffer);
}
}
};
ProgramConfiguration.prototype.upload = function upload(context) {
for (var property in this.binders) {
var binder = this.binders[property];
if (binder instanceof SourceExpressionBinder || binder instanceof CompositeExpressionBinder || binder instanceof CrossFadedCompositeBinder) {
binder.upload(context);
}
}
this.updatePaintBuffers();
};
ProgramConfiguration.prototype.destroy = function destroy() {
for (var property in this.binders) {
var binder = this.binders[property];
if (binder instanceof SourceExpressionBinder || binder instanceof CompositeExpressionBinder || binder instanceof CrossFadedCompositeBinder) {
binder.destroy();
}
}
};
var ProgramConfigurationSet = function ProgramConfigurationSet(layers, zoom, filterProperties) {
if (filterProperties === void 0)
filterProperties = function () {
return true;
};
this.programConfigurations = {};
for (var i = 0, list = layers; i < list.length; i += 1) {
var layer = list[i];
this.programConfigurations[layer.id] = new ProgramConfiguration(layer, zoom, filterProperties);
}
this.needsUpload = false;
this._featureMap = new FeaturePositionMap();
this._bufferOffset = 0;
};
ProgramConfigurationSet.prototype.populatePaintArrays = function populatePaintArrays(length, feature, index, imagePositions, canonical, formattedSection) {
for (var key in this.programConfigurations) {
this.programConfigurations[key].populatePaintArrays(length, feature, imagePositions, canonical, formattedSection);
}
if (feature.id !== undefined) {
this._featureMap.add(feature.id, index, this._bufferOffset, length);
}
this._bufferOffset = length;
this.needsUpload = true;
};
ProgramConfigurationSet.prototype.updatePaintArrays = function updatePaintArrays(featureStates, vtLayer, layers, imagePositions) {
for (var i = 0, list = layers; i < list.length; i += 1) {
var layer = list[i];
this.needsUpload = this.programConfigurations[layer.id].updatePaintArrays(featureStates, this._featureMap, vtLayer, layer, imagePositions) || this.needsUpload;
}
};
ProgramConfigurationSet.prototype.get = function get(layerId) {
return this.programConfigurations[layerId];
};
ProgramConfigurationSet.prototype.upload = function upload(context) {
if (!this.needsUpload) {
return;
}
for (var layerId in this.programConfigurations) {
this.programConfigurations[layerId].upload(context);
}
this.needsUpload = false;
};
ProgramConfigurationSet.prototype.destroy = function destroy() {
for (var layerId in this.programConfigurations) {
this.programConfigurations[layerId].destroy();
}
};
function paintAttributeNames(property, type) {
var attributeNameExceptions = {
'text-opacity': ['opacity'],
'icon-opacity': ['opacity'],
'text-color': ['fill_color'],
'icon-color': ['fill_color'],
'text-halo-color': ['halo_color'],
'icon-halo-color': ['halo_color'],
'text-halo-blur': ['halo_blur'],
'icon-halo-blur': ['halo_blur'],
'text-halo-width': ['halo_width'],
'icon-halo-width': ['halo_width'],
'line-gap-width': ['gapwidth'],
'line-pattern': [
'pattern_to',
'pattern_from',
'pixel_ratio_to',
'pixel_ratio_from'
],
'fill-pattern': [
'pattern_to',
'pattern_from',
'pixel_ratio_to',
'pixel_ratio_from'
],
'fill-extrusion-pattern': [
'pattern_to',
'pattern_from',
'pixel_ratio_to',
'pixel_ratio_from'
]
};
return attributeNameExceptions[property] || [property.replace(type + '-', '').replace(/-/g, '_')];
}
function getLayoutException(property) {
var propertyExceptions = {
'line-pattern': {
'source': StructArrayLayout10ui20,
'composite': StructArrayLayout10ui20
},
'fill-pattern': {
'source': StructArrayLayout10ui20,
'composite': StructArrayLayout10ui20
},
'fill-extrusion-pattern': {
'source': StructArrayLayout10ui20,
'composite': StructArrayLayout10ui20
}
};
return propertyExceptions[property];
}
function layoutType(property, type, binderType) {
var defaultLayouts = {
'color': {
'source': StructArrayLayout2f8,
'composite': StructArrayLayout4f16
},
'number': {
'source': StructArrayLayout1f4,
'composite': StructArrayLayout2f8
}
};
var layoutException = getLayoutException(property);
return layoutException && layoutException[binderType] || defaultLayouts[type][binderType];
}
register('ConstantBinder', ConstantBinder);
register('CrossFadedConstantBinder', CrossFadedConstantBinder);
register('SourceExpressionBinder', SourceExpressionBinder);
register('CrossFadedCompositeBinder', CrossFadedCompositeBinder);
register('CompositeExpressionBinder', CompositeExpressionBinder);
register('ProgramConfiguration', ProgramConfiguration, { omit: ['_buffers'] });
register('ProgramConfigurationSet', ProgramConfigurationSet);
var EXTENT$1 = 8192;
var BITS = 15;
var MAX = Math.pow(2, BITS - 1) - 1;
var MIN = -MAX - 1;
function loadGeometry(feature) {
var scale = EXTENT$1 / feature.extent;
var geometry = feature.loadGeometry();
for (var r = 0; r < geometry.length; r++) {
var ring = geometry[r];
for (var p = 0; p < ring.length; p++) {
var point = ring[p];
var x = Math.round(point.x * scale);
var y = Math.round(point.y * scale);
point.x = clamp(x, MIN, MAX);
point.y = clamp(y, MIN, MAX);
if (x < point.x || x > point.x + 1 || y < point.y || y > point.y + 1) {
warnOnce('Geometry exceeds allowed extent, reduce your vector tile buffer size');
}
}
}
return geometry;
}
function toEvaluationFeature(feature, needGeometry) {
return {
type: feature.type,
id: feature.id,
properties: feature.properties,
geometry: needGeometry ? loadGeometry(feature) : []
};
}
function addCircleVertex(layoutVertexArray, x, y, extrudeX, extrudeY) {
layoutVertexArray.emplaceBack(x * 2 + (extrudeX + 1) / 2, y * 2 + (extrudeY + 1) / 2);
}
var CircleBucket = function CircleBucket(options) {
this.zoom = options.zoom;
this.overscaling = options.overscaling;
this.layers = options.layers;
this.layerIds = this.layers.map(function (layer) {
return layer.id;
});
this.index = options.index;
this.hasPattern = false;
this.layoutVertexArray = new StructArrayLayout2i4();
this.indexArray = new StructArrayLayout3ui6();
this.segments = new SegmentVector();
this.programConfigurations = new ProgramConfigurationSet(options.layers, options.zoom);
this.stateDependentLayerIds = this.layers.filter(function (l) {
return l.isStateDependent();
}).map(function (l) {
return l.id;
});
};
CircleBucket.prototype.populate = function populate(features, options, canonical) {
var styleLayer = this.layers[0];
var bucketFeatures = [];
var circleSortKey = null;
if (styleLayer.type === 'circle') {
circleSortKey = styleLayer.layout.get('circle-sort-key');
}
for (var i = 0, list = features; i < list.length; i += 1) {
var ref = list[i];
var feature = ref.feature;
var id = ref.id;
var index = ref.index;
var sourceLayerIndex = ref.sourceLayerIndex;
var needGeometry = this.layers[0]._featureFilter.needGeometry;
var evaluationFeature = toEvaluationFeature(feature, needGeometry);
if (!this.layers[0]._featureFilter.filter(new EvaluationParameters(this.zoom), evaluationFeature, canonical)) {
continue;
}
var sortKey = circleSortKey ? circleSortKey.evaluate(evaluationFeature, {}, canonical) : undefined;
var bucketFeature = {
id: id,
properties: feature.properties,
type: feature.type,
sourceLayerIndex: sourceLayerIndex,
index: index,
geometry: needGeometry ? evaluationFeature.geometry : loadGeometry(feature),
patterns: {},
sortKey: sortKey
};
bucketFeatures.push(bucketFeature);
}
if (circleSortKey) {
bucketFeatures.sort(function (a, b) {
return a.sortKey - b.sortKey;
});
}
for (var i$1 = 0, list$1 = bucketFeatures; i$1 < list$1.length; i$1 += 1) {
var bucketFeature$1 = list$1[i$1];
var ref$1 = bucketFeature$1;
var geometry = ref$1.geometry;
var index$1 = ref$1.index;
var sourceLayerIndex$1 = ref$1.sourceLayerIndex;
var feature$1 = features[index$1].feature;
this.addFeature(bucketFeature$1, geometry, index$1, canonical);
options.featureIndex.insert(feature$1, geometry, index$1, sourceLayerIndex$1, this.index);
}
};
CircleBucket.prototype.update = function update(states, vtLayer, imagePositions) {
if (!this.stateDependentLayers.length) {
return;
}
this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, imagePositions);
};
CircleBucket.prototype.isEmpty = function isEmpty() {
return this.layoutVertexArray.length === 0;
};
CircleBucket.prototype.uploadPending = function uploadPending() {
return !this.uploaded || this.programConfigurations.needsUpload;
};
CircleBucket.prototype.upload = function upload(context) {
if (!this.uploaded) {
this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, members);
this.indexBuffer = context.createIndexBuffer(this.indexArray);
}
this.programConfigurations.upload(context);
this.uploaded = true;
};
CircleBucket.prototype.destroy = function destroy() {
if (!this.layoutVertexBuffer) {
return;
}
this.layoutVertexBuffer.destroy();
this.indexBuffer.destroy();
this.programConfigurations.destroy();
this.segments.destroy();
};
CircleBucket.prototype.addFeature = function addFeature(feature, geometry, index, canonical) {
for (var i$1 = 0, list$1 = geometry; i$1 < list$1.length; i$1 += 1) {
var ring = list$1[i$1];
for (var i = 0, list = ring; i < list.length; i += 1) {
var point = list[i];
var x = point.x;
var y = point.y;
if (x < 0 || x >= EXTENT$1 || y < 0 || y >= EXTENT$1) {
continue;
}
var segment = this.segments.prepareSegment(4, this.layoutVertexArray, this.indexArray, feature.sortKey);
var index$1 = segment.vertexLength;
addCircleVertex(this.layoutVertexArray, x, y, -1, -1);
addCircleVertex(this.layoutVertexArray, x, y, 1, -1);
addCircleVertex(this.layoutVertexArray, x, y, 1, 1);
addCircleVertex(this.layoutVertexArray, x, y, -1, 1);
this.indexArray.emplaceBack(index$1, index$1 + 1, index$1 + 2);
this.indexArray.emplaceBack(index$1, index$1 + 3, index$1 + 2);
segment.vertexLength += 4;
segment.primitiveLength += 2;
}
}
this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, {}, canonical);
};
register('CircleBucket', CircleBucket, { omit: ['layers'] });
function polygonIntersectsPolygon(polygonA, polygonB) {
for (var i = 0; i < polygonA.length; i++) {
if (polygonContainsPoint(polygonB, polygonA[i])) {
return true;
}
}
for (var i$1 = 0; i$1 < polygonB.length; i$1++) {
if (polygonContainsPoint(polygonA, polygonB[i$1])) {
return true;
}
}
if (lineIntersectsLine(polygonA, polygonB)) {
return true;
}
return false;
}
function polygonIntersectsBufferedPoint(polygon, point, radius) {
if (polygonContainsPoint(polygon, point)) {
return true;
}
if (pointIntersectsBufferedLine(point, polygon, radius)) {
return true;
}
return false;
}
function polygonIntersectsMultiPolygon(polygon, multiPolygon) {
if (polygon.length === 1) {
return multiPolygonContainsPoint(multiPolygon, polygon[0]);
}
for (var m = 0; m < multiPolygon.length; m++) {
var ring = multiPolygon[m];
for (var n = 0; n < ring.length; n++) {
if (polygonContainsPoint(polygon, ring[n])) {
return true;
}
}
}
for (var i = 0; i < polygon.length; i++) {
if (multiPolygonContainsPoint(multiPolygon, polygon[i])) {
return true;
}
}
for (var k = 0; k < multiPolygon.length; k++) {
if (lineIntersectsLine(polygon, multiPolygon[k])) {
return true;
}
}
return false;
}
function polygonIntersectsBufferedMultiLine(polygon, multiLine, radius) {
for (var i = 0; i < multiLine.length; i++) {
var line = multiLine[i];
if (polygon.length >= 3) {
for (var k = 0; k < line.length; k++) {
if (polygonContainsPoint(polygon, line[k])) {
return true;
}
}
}
if (lineIntersectsBufferedLine(polygon, line, radius)) {
return true;
}
}
return false;
}
function lineIntersectsBufferedLine(lineA, lineB, radius) {
if (lineA.length > 1) {
if (lineIntersectsLine(lineA, lineB)) {
return true;
}
for (var j = 0; j < lineB.length; j++) {
if (pointIntersectsBufferedLine(lineB[j], lineA, radius)) {
return true;
}
}
}
for (var k = 0; k < lineA.length; k++) {
if (pointIntersectsBufferedLine(lineA[k], lineB, radius)) {
return true;
}
}
return false;
}
function lineIntersectsLine(lineA, lineB) {
if (lineA.length === 0 || lineB.length === 0) {
return false;
}
for (var i = 0; i < lineA.length - 1; i++) {
var a0 = lineA[i];
var a1 = lineA[i + 1];
for (var j = 0; j < lineB.length - 1; j++) {
var b0 = lineB[j];
var b1 = lineB[j + 1];
if (lineSegmentIntersectsLineSegment(a0, a1, b0, b1)) {
return true;
}
}
}
return false;
}
function lineSegmentIntersectsLineSegment(a0, a1, b0, b1) {
return isCounterClockwise(a0, b0, b1) !== isCounterClockwise(a1, b0, b1) && isCounterClockwise(a0, a1, b0) !== isCounterClockwise(a0, a1, b1);
}
function pointIntersectsBufferedLine(p, line, radius) {
var radiusSquared = radius * radius;
if (line.length === 1) {
return p.distSqr(line[0]) < radiusSquared;
}
for (var i = 1; i < line.length; i++) {
var v = line[i - 1], w = line[i];
if (distToSegmentSquared(p, v, w) < radiusSquared) {
return true;
}
}
return false;
}
function distToSegmentSquared(p, v, w) {
var l2 = v.distSqr(w);
if (l2 === 0) {
return p.distSqr(v);
}
var t = ((p.x - v.x) * (w.x - v.x) + (p.y - v.y) * (w.y - v.y)) / l2;
if (t < 0) {
return p.distSqr(v);
}
if (t > 1) {
return p.distSqr(w);
}
return p.distSqr(w.sub(v)._mult(t)._add(v));
}
function multiPolygonContainsPoint(rings, p) {
var c = false, ring, p1, p2;
for (var k = 0; k < rings.length; k++) {
ring = rings[k];
for (var i = 0, j = ring.length - 1; i < ring.length; j = i++) {
p1 = ring[i];
p2 = ring[j];
if (p1.y > p.y !== p2.y > p.y && p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x) {
c = !c;
}
}
}
return c;
}
function polygonContainsPoint(ring, p) {
var c = false;
for (var i = 0, j = ring.length - 1; i < ring.length; j = i++) {
var p1 = ring[i];
var p2 = ring[j];
if (p1.y > p.y !== p2.y > p.y && p.x < (p2.x - p1.x) * (p.y - p1.y) / (p2.y - p1.y) + p1.x) {
c = !c;
}
}
return c;
}
function polygonIntersectsBox(ring, boxX1, boxY1, boxX2, boxY2) {
for (var i$1 = 0, list = ring; i$1 < list.length; i$1 += 1) {
var p = list[i$1];
if (boxX1 <= p.x && boxY1 <= p.y && boxX2 >= p.x && boxY2 >= p.y) {
return true;
}
}
var corners = [
new pointGeometry(boxX1, boxY1),
new pointGeometry(boxX1, boxY2),
new pointGeometry(boxX2, boxY2),
new pointGeometry(boxX2, boxY1)
];
if (ring.length > 2) {
for (var i$2 = 0, list$1 = corners; i$2 < list$1.length; i$2 += 1) {
var corner = list$1[i$2];
if (polygonContainsPoint(ring, corner)) {
return true;
}
}
}
for (var i = 0; i < ring.length - 1; i++) {
var p1 = ring[i];
var p2 = ring[i + 1];
if (edgeIntersectsBox(p1, p2, corners)) {
return true;
}
}
return false;
}
function edgeIntersectsBox(e1, e2, corners) {
var tl = corners[0];
var br = corners[2];
if (e1.x < tl.x && e2.x < tl.x || e1.x > br.x && e2.x > br.x || e1.y < tl.y && e2.y < tl.y || e1.y > br.y && e2.y > br.y) {
return false;
}
var dir = isCounterClockwise(e1, e2, corners[0]);
return dir !== isCounterClockwise(e1, e2, corners[1]) || dir !== isCounterClockwise(e1, e2, corners[2]) || dir !== isCounterClockwise(e1, e2, corners[3]);
}
function getMaximumPaintValue(property, layer, bucket) {
var value = layer.paint.get(property).value;
if (value.kind === 'constant') {
return value.value;
} else {
return bucket.programConfigurations.get(layer.id).getMaxValue(property);
}
}
function translateDistance(translate) {
return Math.sqrt(translate[0] * translate[0] + translate[1] * translate[1]);
}
function translate(queryGeometry, translate, translateAnchor, bearing, pixelsToTileUnits) {
if (!translate[0] && !translate[1]) {
return queryGeometry;
}
var pt = pointGeometry.convert(translate)._mult(pixelsToTileUnits);
if (translateAnchor === 'viewport') {
pt._rotate(-bearing);
}
var translated = [];
for (var i = 0; i < queryGeometry.length; i++) {
var point = queryGeometry[i];
translated.push(point.sub(pt));
}
return translated;
}
var layout$2 = new Properties({ 'circle-sort-key': new DataDrivenProperty(spec['layout_circle']['circle-sort-key']) });
var paint$1 = new Properties({
'circle-radius': new DataDrivenProperty(spec['paint_circle']['circle-radius']),
'circle-color': new DataDrivenProperty(spec['paint_circle']['circle-color']),
'circle-blur': new DataDrivenProperty(spec['paint_circle']['circle-blur']),
'circle-opacity': new DataDrivenProperty(spec['paint_circle']['circle-opacity']),
'circle-translate': new DataConstantProperty(spec['paint_circle']['circle-translate']),
'circle-translate-anchor': new DataConstantProperty(spec['paint_circle']['circle-translate-anchor']),
'circle-pitch-scale': new DataConstantProperty(spec['paint_circle']['circle-pitch-scale']),
'circle-pitch-alignment': new DataConstantProperty(spec['paint_circle']['circle-pitch-alignment']),
'circle-stroke-width': new DataDrivenProperty(spec['paint_circle']['circle-stroke-width']),
'circle-stroke-color': new DataDrivenProperty(spec['paint_circle']['circle-stroke-color']),
'circle-stroke-opacity': new DataDrivenProperty(spec['paint_circle']['circle-stroke-opacity'])
});
var properties = {
paint: paint$1,
layout: layout$2
};
var ARRAY_TYPE = typeof Float32Array !== 'undefined' ? Float32Array : Array;
if (!Math.hypot) {
Math.hypot = function () {
var arguments$1 = arguments;
var y = 0, i = arguments.length;
while (i--) {
y += arguments$1[i] * arguments$1[i];
}
return Math.sqrt(y);
};
}
function create() {
var out = new ARRAY_TYPE(4);
if (ARRAY_TYPE != Float32Array) {
out[1] = 0;
out[2] = 0;
}
out[0] = 1;
out[3] = 1;
return out;
}
function rotate(out, a, rad) {
var a0 = a[0], a1 = a[1], a2 = a[2], a3 = a[3];
var s = Math.sin(rad);
var c = Math.cos(rad);
out[0] = a0 * c + a2 * s;
out[1] = a1 * c + a3 * s;
out[2] = a0 * -s + a2 * c;
out[3] = a1 * -s + a3 * c;
return out;
}
function create$1() {
var out = new ARRAY_TYPE(9);
if (ARRAY_TYPE != Float32Array) {
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[5] = 0;
out[6] = 0;
out[7] = 0;
}
out[0] = 1;
out[4] = 1;
out[8] = 1;
return out;
}
function fromRotation(out, rad) {
var s = Math.sin(rad), c = Math.cos(rad);
out[0] = c;
out[1] = s;
out[2] = 0;
out[3] = -s;
out[4] = c;
out[5] = 0;
out[6] = 0;
out[7] = 0;
out[8] = 1;
return out;
}
function create$2() {
var out = new ARRAY_TYPE(16);
if (ARRAY_TYPE != Float32Array) {
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 0;
out[6] = 0;
out[7] = 0;
out[8] = 0;
out[9] = 0;
out[11] = 0;
out[12] = 0;
out[13] = 0;
out[14] = 0;
}
out[0] = 1;
out[5] = 1;
out[10] = 1;
out[15] = 1;
return out;
}
function clone$1(a) {
var out = new ARRAY_TYPE(16);
out[0] = a[0];
out[1] = a[1];
out[2] = a[2];
out[3] = a[3];
out[4] = a[4];
out[5] = a[5];
out[6] = a[6];
out[7] = a[7];
out[8] = a[8];
out[9] = a[9];
out[10] = a[10];
out[11] = a[11];
out[12] = a[12];
out[13] = a[13];
out[14] = a[14];
out[15] = a[15];
return out;
}
function identity(out) {
out[0] = 1;
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 0;
out[5] = 1;
out[6] = 0;
out[7] = 0;
out[8] = 0;
out[9] = 0;
out[10] = 1;
out[11] = 0;
out[12] = 0;
out[13] = 0;
out[14] = 0;
out[15] = 1;
return out;
}
function invert(out, a) {
var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
var a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
var a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
var a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
var b00 = a00 * a11 - a01 * a10;
var b01 = a00 * a12 - a02 * a10;
var b02 = a00 * a13 - a03 * a10;
var b03 = a01 * a12 - a02 * a11;
var b04 = a01 * a13 - a03 * a11;
var b05 = a02 * a13 - a03 * a12;
var b06 = a20 * a31 - a21 * a30;
var b07 = a20 * a32 - a22 * a30;
var b08 = a20 * a33 - a23 * a30;
var b09 = a21 * a32 - a22 * a31;
var b10 = a21 * a33 - a23 * a31;
var b11 = a22 * a33 - a23 * a32;
var det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
if (!det) {
return null;
}
det = 1 / det;
out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
return out;
}
function multiply(out, a, b) {
var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3];
var a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7];
var a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11];
var a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
out[0] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
out[1] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
out[2] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
out[3] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
b0 = b[4];
b1 = b[5];
b2 = b[6];
b3 = b[7];
out[4] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
out[5] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
out[6] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
out[7] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
b0 = b[8];
b1 = b[9];
b2 = b[10];
b3 = b[11];
out[8] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
out[9] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
out[10] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
out[11] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
b0 = b[12];
b1 = b[13];
b2 = b[14];
b3 = b[15];
out[12] = b0 * a00 + b1 * a10 + b2 * a20 + b3 * a30;
out[13] = b0 * a01 + b1 * a11 + b2 * a21 + b3 * a31;
out[14] = b0 * a02 + b1 * a12 + b2 * a22 + b3 * a32;
out[15] = b0 * a03 + b1 * a13 + b2 * a23 + b3 * a33;
return out;
}
function translate$1(out, a, v) {
var x = v[0], y = v[1], z = v[2];
var a00, a01, a02, a03;
var a10, a11, a12, a13;
var a20, a21, a22, a23;
if (a === out) {
out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
} else {
a00 = a[0];
a01 = a[1];
a02 = a[2];
a03 = a[3];
a10 = a[4];
a11 = a[5];
a12 = a[6];
a13 = a[7];
a20 = a[8];
a21 = a[9];
a22 = a[10];
a23 = a[11];
out[0] = a00;
out[1] = a01;
out[2] = a02;
out[3] = a03;
out[4] = a10;
out[5] = a11;
out[6] = a12;
out[7] = a13;
out[8] = a20;
out[9] = a21;
out[10] = a22;
out[11] = a23;
out[12] = a00 * x + a10 * y + a20 * z + a[12];
out[13] = a01 * x + a11 * y + a21 * z + a[13];
out[14] = a02 * x + a12 * y + a22 * z + a[14];
out[15] = a03 * x + a13 * y + a23 * z + a[15];
}
return out;
}
function scale(out, a, v) {
var x = v[0], y = v[1], z = v[2];
out[0] = a[0] * x;
out[1] = a[1] * x;
out[2] = a[2] * x;
out[3] = a[3] * x;
out[4] = a[4] * y;
out[5] = a[5] * y;
out[6] = a[6] * y;
out[7] = a[7] * y;
out[8] = a[8] * z;
out[9] = a[9] * z;
out[10] = a[10] * z;
out[11] = a[11] * z;
out[12] = a[12];
out[13] = a[13];
out[14] = a[14];
out[15] = a[15];
return out;
}
function rotateX(out, a, rad) {
var s = Math.sin(rad);
var c = Math.cos(rad);
var a10 = a[4];
var a11 = a[5];
var a12 = a[6];
var a13 = a[7];
var a20 = a[8];
var a21 = a[9];
var a22 = a[10];
var a23 = a[11];
if (a !== out) {
out[0] = a[0];
out[1] = a[1];
out[2] = a[2];
out[3] = a[3];
out[12] = a[12];
out[13] = a[13];
out[14] = a[14];
out[15] = a[15];
}
out[4] = a10 * c + a20 * s;
out[5] = a11 * c + a21 * s;
out[6] = a12 * c + a22 * s;
out[7] = a13 * c + a23 * s;
out[8] = a20 * c - a10 * s;
out[9] = a21 * c - a11 * s;
out[10] = a22 * c - a12 * s;
out[11] = a23 * c - a13 * s;
return out;
}
function rotateZ(out, a, rad) {
var s = Math.sin(rad);
var c = Math.cos(rad);
var a00 = a[0];
var a01 = a[1];
var a02 = a[2];
var a03 = a[3];
var a10 = a[4];
var a11 = a[5];
var a12 = a[6];
var a13 = a[7];
if (a !== out) {
out[8] = a[8];
out[9] = a[9];
out[10] = a[10];
out[11] = a[11];
out[12] = a[12];
out[13] = a[13];
out[14] = a[14];
out[15] = a[15];
}
out[0] = a00 * c + a10 * s;
out[1] = a01 * c + a11 * s;
out[2] = a02 * c + a12 * s;
out[3] = a03 * c + a13 * s;
out[4] = a10 * c - a00 * s;
out[5] = a11 * c - a01 * s;
out[6] = a12 * c - a02 * s;
out[7] = a13 * c - a03 * s;
return out;
}
function perspective(out, fovy, aspect, near, far) {
var f = 1 / Math.tan(fovy / 2), nf;
out[0] = f / aspect;
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 0;
out[5] = f;
out[6] = 0;
out[7] = 0;
out[8] = 0;
out[9] = 0;
out[11] = -1;
out[12] = 0;
out[13] = 0;
out[15] = 0;
if (far != null && far !== Infinity) {
nf = 1 / (near - far);
out[10] = (far + near) * nf;
out[14] = 2 * far * near * nf;
} else {
out[10] = -1;
out[14] = -2 * near;
}
return out;
}
function ortho(out, left, right, bottom, top, near, far) {
var lr = 1 / (left - right);
var bt = 1 / (bottom - top);
var nf = 1 / (near - far);
out[0] = -2 * lr;
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 0;
out[5] = -2 * bt;
out[6] = 0;
out[7] = 0;
out[8] = 0;
out[9] = 0;
out[10] = 2 * nf;
out[11] = 0;
out[12] = (left + right) * lr;
out[13] = (top + bottom) * bt;
out[14] = (far + near) * nf;
out[15] = 1;
return out;
}
var mul = multiply;
function create$3() {
var out = new ARRAY_TYPE(3);
if (ARRAY_TYPE != Float32Array) {
out[0] = 0;
out[1] = 0;
out[2] = 0;
}
return out;
}
function clone$2(a) {
var out = new ARRAY_TYPE(3);
out[0] = a[0];
out[1] = a[1];
out[2] = a[2];
return out;
}
function add(out, a, b) {
out[0] = a[0] + b[0];
out[1] = a[1] + b[1];
out[2] = a[2] + b[2];
return out;
}
function subtract(out, a, b) {
out[0] = a[0] - b[0];
out[1] = a[1] - b[1];
out[2] = a[2] - b[2];
return out;
}
function scale$1(out, a, b) {
out[0] = a[0] * b;
out[1] = a[1] * b;
out[2] = a[2] * b;
return out;
}
function normalize(out, a) {
var x = a[0];
var y = a[1];
var z = a[2];
var len = x * x + y * y + z * z;
if (len > 0) {
len = 1 / Math.sqrt(len);
}
out[0] = a[0] * len;
out[1] = a[1] * len;
out[2] = a[2] * len;
return out;
}
function dot(a, b) {
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
}
function cross(out, a, b) {
var ax = a[0], ay = a[1], az = a[2];
var bx = b[0], by = b[1], bz = b[2];
out[0] = ay * bz - az * by;
out[1] = az * bx - ax * bz;
out[2] = ax * by - ay * bx;
return out;
}
function transformMat3(out, a, m) {
var x = a[0], y = a[1], z = a[2];
out[0] = x * m[0] + y * m[3] + z * m[6];
out[1] = x * m[1] + y * m[4] + z * m[7];
out[2] = x * m[2] + y * m[5] + z * m[8];
return out;
}
var sub = subtract;
var forEach = function () {
var vec = create$3();
return function (a, stride, offset, count, fn, arg) {
var i, l;
if (!stride) {
stride = 3;
}
if (!offset) {
offset = 0;
}
if (count) {
l = Math.min(count * stride + offset, a.length);
} else {
l = a.length;
}
for (i = offset; i < l; i += stride) {
vec[0] = a[i];
vec[1] = a[i + 1];
vec[2] = a[i + 2];
fn(vec, vec, arg);
a[i] = vec[0];
a[i + 1] = vec[1];
a[i + 2] = vec[2];
}
return a;
};
}();
function create$4() {
var out = new ARRAY_TYPE(4);
if (ARRAY_TYPE != Float32Array) {
out[0] = 0;
out[1] = 0;
out[2] = 0;
out[3] = 0;
}
return out;
}
function scale$2(out, a, b) {
out[0] = a[0] * b;
out[1] = a[1] * b;
out[2] = a[2] * b;
out[3] = a[3] * b;
return out;
}
function dot$1(a, b) {
return a[0] * b[0] + a[1] * b[1] + a[2] * b[2] + a[3] * b[3];
}
function transformMat4(out, a, m) {
var x = a[0], y = a[1], z = a[2], w = a[3];
out[0] = m[0] * x + m[4] * y + m[8] * z + m[12] * w;
out[1] = m[1] * x + m[5] * y + m[9] * z + m[13] * w;
out[2] = m[2] * x + m[6] * y + m[10] * z + m[14] * w;
out[3] = m[3] * x + m[7] * y + m[11] * z + m[15] * w;
return out;
}
var forEach$1 = function () {
var vec = create$4();
return function (a, stride, offset, count, fn, arg) {
var i, l;
if (!stride) {
stride = 4;
}
if (!offset) {
offset = 0;
}
if (count) {
l = Math.min(count * stride + offset, a.length);
} else {
l = a.length;
}
for (i = offset; i < l; i += stride) {
vec[0] = a[i];
vec[1] = a[i + 1];
vec[2] = a[i + 2];
vec[3] = a[i + 3];
fn(vec, vec, arg);
a[i] = vec[0];
a[i + 1] = vec[1];
a[i + 2] = vec[2];
a[i + 3] = vec[3];
}
return a;
};
}();
function create$5() {
var out = new ARRAY_TYPE(2);
if (ARRAY_TYPE != Float32Array) {
out[0] = 0;
out[1] = 0;
}
return out;
}
function squaredLength(a) {
var x = a[0], y = a[1];
return x * x + y * y;
}
var sqrLen = squaredLength;
var forEach$2 = function () {
var vec = create$5();
return function (a, stride, offset, count, fn, arg) {
var i, l;
if (!stride) {
stride = 2;
}
if (!offset) {
offset = 0;
}
if (count) {
l = Math.min(count * stride + offset, a.length);
} else {
l = a.length;
}
for (i = offset; i < l; i += stride) {
vec[0] = a[i];
vec[1] = a[i + 1];
fn(vec, vec, arg);
a[i] = vec[0];
a[i + 1] = vec[1];
}
return a;
};
}();
var CircleStyleLayer = function (StyleLayer) {
function CircleStyleLayer(layer) {
StyleLayer.call(this, layer, properties);
}
if (StyleLayer)
CircleStyleLayer.__proto__ = StyleLayer;
CircleStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
CircleStyleLayer.prototype.constructor = CircleStyleLayer;
CircleStyleLayer.prototype.createBucket = function createBucket(parameters) {
return new CircleBucket(parameters);
};
CircleStyleLayer.prototype.queryRadius = function queryRadius(bucket) {
var circleBucket = bucket;
return getMaximumPaintValue('circle-radius', this, circleBucket) + getMaximumPaintValue('circle-stroke-width', this, circleBucket) + translateDistance(this.paint.get('circle-translate'));
};
CircleStyleLayer.prototype.queryIntersectsFeature = function queryIntersectsFeature(queryGeometry, feature, featureState, geometry, zoom, transform, pixelsToTileUnits, pixelPosMatrix) {
var translatedPolygon = translate(queryGeometry, this.paint.get('circle-translate'), this.paint.get('circle-translate-anchor'), transform.angle, pixelsToTileUnits);
var radius = this.paint.get('circle-radius').evaluate(feature, featureState);
var stroke = this.paint.get('circle-stroke-width').evaluate(feature, featureState);
var size = radius + stroke;
var alignWithMap = this.paint.get('circle-pitch-alignment') === 'map';
var transformedPolygon = alignWithMap ? translatedPolygon : projectQueryGeometry(translatedPolygon, pixelPosMatrix);
var transformedSize = alignWithMap ? size * pixelsToTileUnits : size;
for (var i$1 = 0, list$1 = geometry; i$1 < list$1.length; i$1 += 1) {
var ring = list$1[i$1];
for (var i = 0, list = ring; i < list.length; i += 1) {
var point = list[i];
var transformedPoint = alignWithMap ? point : projectPoint(point, pixelPosMatrix);
var adjustedSize = transformedSize;
var projectedCenter = transformMat4([], [
point.x,
point.y,
0,
1
], pixelPosMatrix);
if (this.paint.get('circle-pitch-scale') === 'viewport' && this.paint.get('circle-pitch-alignment') === 'map') {
adjustedSize *= projectedCenter[3] / transform.cameraToCenterDistance;
} else if (this.paint.get('circle-pitch-scale') === 'map' && this.paint.get('circle-pitch-alignment') === 'viewport') {
adjustedSize *= transform.cameraToCenterDistance / projectedCenter[3];
}
if (polygonIntersectsBufferedPoint(transformedPolygon, transformedPoint, adjustedSize)) {
return true;
}
}
}
return false;
};
return CircleStyleLayer;
}(StyleLayer);
function projectPoint(p, pixelPosMatrix) {
var point = transformMat4([], [
p.x,
p.y,
0,
1
], pixelPosMatrix);
return new pointGeometry(point[0] / point[3], point[1] / point[3]);
}
function projectQueryGeometry(queryGeometry, pixelPosMatrix) {
return queryGeometry.map(function (p) {
return projectPoint(p, pixelPosMatrix);
});
}
var HeatmapBucket = function (CircleBucket) {
function HeatmapBucket() {
CircleBucket.apply(this, arguments);
}
if (CircleBucket)
HeatmapBucket.__proto__ = CircleBucket;
HeatmapBucket.prototype = Object.create(CircleBucket && CircleBucket.prototype);
HeatmapBucket.prototype.constructor = HeatmapBucket;
return HeatmapBucket;
}(CircleBucket);
register('HeatmapBucket', HeatmapBucket, { omit: ['layers'] });
function createImage(image, ref, channels, data) {
var width = ref.width;
var height = ref.height;
if (!data) {
data = new Uint8Array(width * height * channels);
} else if (data instanceof Uint8ClampedArray) {
data = new Uint8Array(data.buffer);
} else if (data.length !== width * height * channels) {
throw new RangeError('mismatched image size');
}
image.width = width;
image.height = height;
image.data = data;
return image;
}
function resizeImage(image, ref, channels) {
var width = ref.width;
var height = ref.height;
if (width === image.width && height === image.height) {
return;
}
var newImage = createImage({}, {
width: width,
height: height
}, channels);
copyImage(image, newImage, {
x: 0,
y: 0
}, {
x: 0,
y: 0
}, {
width: Math.min(image.width, width),
height: Math.min(image.height, height)
}, channels);
image.width = width;
image.height = height;
image.data = newImage.data;
}
function copyImage(srcImg, dstImg, srcPt, dstPt, size, channels) {
if (size.width === 0 || size.height === 0) {
return dstImg;
}
if (size.width > srcImg.width || size.height > srcImg.height || srcPt.x > srcImg.width - size.width || srcPt.y > srcImg.height - size.height) {
throw new RangeError('out of range source coordinates for image copy');
}
if (size.width > dstImg.width || size.height > dstImg.height || dstPt.x > dstImg.width - size.width || dstPt.y > dstImg.height - size.height) {
throw new RangeError('out of range destination coordinates for image copy');
}
var srcData = srcImg.data;
var dstData = dstImg.data;
for (var y = 0; y < size.height; y++) {
var srcOffset = ((srcPt.y + y) * srcImg.width + srcPt.x) * channels;
var dstOffset = ((dstPt.y + y) * dstImg.width + dstPt.x) * channels;
for (var i = 0; i < size.width * channels; i++) {
dstData[dstOffset + i] = srcData[srcOffset + i];
}
}
return dstImg;
}
var AlphaImage = function AlphaImage(size, data) {
createImage(this, size, 1, data);
};
AlphaImage.prototype.resize = function resize(size) {
resizeImage(this, size, 1);
};
AlphaImage.prototype.clone = function clone() {
return new AlphaImage({
width: this.width,
height: this.height
}, new Uint8Array(this.data));
};
AlphaImage.copy = function copy(srcImg, dstImg, srcPt, dstPt, size) {
copyImage(srcImg, dstImg, srcPt, dstPt, size, 1);
};
var RGBAImage = function RGBAImage(size, data) {
createImage(this, size, 4, data);
};
RGBAImage.prototype.resize = function resize(size) {
resizeImage(this, size, 4);
};
RGBAImage.prototype.replace = function replace(data, copy) {
if (copy) {
this.data.set(data);
} else if (data instanceof Uint8ClampedArray) {
this.data = new Uint8Array(data.buffer);
} else {
this.data = data;
}
};
RGBAImage.prototype.clone = function clone() {
return new RGBAImage({
width: this.width,
height: this.height
}, new Uint8Array(this.data));
};
RGBAImage.copy = function copy(srcImg, dstImg, srcPt, dstPt, size) {
copyImage(srcImg, dstImg, srcPt, dstPt, size, 4);
};
register('AlphaImage', AlphaImage);
register('RGBAImage', RGBAImage);
var paint$2 = new Properties({
'heatmap-radius': new DataDrivenProperty(spec['paint_heatmap']['heatmap-radius']),
'heatmap-weight': new DataDrivenProperty(spec['paint_heatmap']['heatmap-weight']),
'heatmap-intensity': new DataConstantProperty(spec['paint_heatmap']['heatmap-intensity']),
'heatmap-color': new ColorRampProperty(spec['paint_heatmap']['heatmap-color']),
'heatmap-opacity': new DataConstantProperty(spec['paint_heatmap']['heatmap-opacity'])
});
var properties$1 = { paint: paint$2 };
function renderColorRamp(params) {
var evaluationGlobals = {};
var width = params.resolution || 256;
var height = params.clips ? params.clips.length : 1;
var image = params.image || new RGBAImage({
width: width,
height: height
});
var renderPixel = function (stride, index, progress) {
evaluationGlobals[params.evaluationKey] = progress;
var pxColor = params.expression.evaluate(evaluationGlobals);
image.data[stride + index + 0] = Math.floor(pxColor.r * 255 / pxColor.a);
image.data[stride + index + 1] = Math.floor(pxColor.g * 255 / pxColor.a);
image.data[stride + index + 2] = Math.floor(pxColor.b * 255 / pxColor.a);
image.data[stride + index + 3] = Math.floor(pxColor.a * 255);
};
if (!params.clips) {
for (var i = 0, j = 0; i < width; i++, j += 4) {
var progress = i / (width - 1);
renderPixel(0, j, progress);
}
} else {
for (var clip = 0, stride = 0; clip < height; ++clip, stride += width * 4) {
for (var i$1 = 0, j$1 = 0; i$1 < width; i$1++, j$1 += 4) {
var progress$1 = i$1 / (width - 1);
var ref = params.clips[clip];
var start = ref.start;
var end = ref.end;
var evaluationProgress = start * (1 - progress$1) + end * progress$1;
renderPixel(stride, j$1, evaluationProgress);
}
}
}
return image;
}
var HeatmapStyleLayer = function (StyleLayer) {
function HeatmapStyleLayer(layer) {
StyleLayer.call(this, layer, properties$1);
this._updateColorRamp();
}
if (StyleLayer)
HeatmapStyleLayer.__proto__ = StyleLayer;
HeatmapStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
HeatmapStyleLayer.prototype.constructor = HeatmapStyleLayer;
HeatmapStyleLayer.prototype.createBucket = function createBucket(options) {
return new HeatmapBucket(options);
};
HeatmapStyleLayer.prototype._handleSpecialPaintPropertyUpdate = function _handleSpecialPaintPropertyUpdate(name) {
if (name === 'heatmap-color') {
this._updateColorRamp();
}
};
HeatmapStyleLayer.prototype._updateColorRamp = function _updateColorRamp() {
var expression = this._transitionablePaint._values['heatmap-color'].value.expression;
this.colorRamp = renderColorRamp({
expression: expression,
evaluationKey: 'heatmapDensity',
image: this.colorRamp
});
this.colorRampTexture = null;
};
HeatmapStyleLayer.prototype.resize = function resize() {
if (this.heatmapFbo) {
this.heatmapFbo.destroy();
this.heatmapFbo = null;
}
};
HeatmapStyleLayer.prototype.queryRadius = function queryRadius() {
return 0;
};
HeatmapStyleLayer.prototype.queryIntersectsFeature = function queryIntersectsFeature() {
return false;
};
HeatmapStyleLayer.prototype.hasOffscreenPass = function hasOffscreenPass() {
return this.paint.get('heatmap-opacity') !== 0 && this.visibility !== 'none';
};
return HeatmapStyleLayer;
}(StyleLayer);
var paint$3 = new Properties({
'hillshade-illumination-direction': new DataConstantProperty(spec['paint_hillshade']['hillshade-illumination-direction']),
'hillshade-illumination-anchor': new DataConstantProperty(spec['paint_hillshade']['hillshade-illumination-anchor']),
'hillshade-exaggeration': new DataConstantProperty(spec['paint_hillshade']['hillshade-exaggeration']),
'hillshade-shadow-color': new DataConstantProperty(spec['paint_hillshade']['hillshade-shadow-color']),
'hillshade-highlight-color': new DataConstantProperty(spec['paint_hillshade']['hillshade-highlight-color']),
'hillshade-accent-color': new DataConstantProperty(spec['paint_hillshade']['hillshade-accent-color'])
});
var properties$2 = { paint: paint$3 };
var HillshadeStyleLayer = function (StyleLayer) {
function HillshadeStyleLayer(layer) {
StyleLayer.call(this, layer, properties$2);
}
if (StyleLayer)
HillshadeStyleLayer.__proto__ = StyleLayer;
HillshadeStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
HillshadeStyleLayer.prototype.constructor = HillshadeStyleLayer;
HillshadeStyleLayer.prototype.hasOffscreenPass = function hasOffscreenPass() {
return this.paint.get('hillshade-exaggeration') !== 0 && this.visibility !== 'none';
};
return HillshadeStyleLayer;
}(StyleLayer);
var layout$3 = createLayout([{
name: 'a_pos',
components: 2,
type: 'Int16'
}], 4);
var members$1 = layout$3.members;
var earcut_1 = earcut;
var default_1 = earcut;
function earcut(data, holeIndices, dim) {
dim = dim || 2;
var hasHoles = holeIndices && holeIndices.length, outerLen = hasHoles ? holeIndices[0] * dim : data.length, outerNode = linkedList(data, 0, outerLen, dim, true), triangles = [];
if (!outerNode || outerNode.next === outerNode.prev) {
return triangles;
}
var minX, minY, maxX, maxY, x, y, invSize;
if (hasHoles) {
outerNode = eliminateHoles(data, holeIndices, outerNode, dim);
}
if (data.length > 80 * dim) {
minX = maxX = data[0];
minY = maxY = data[1];
for (var i = dim; i < outerLen; i += dim) {
x = data[i];
y = data[i + 1];
if (x < minX) {
minX = x;
}
if (y < minY) {
minY = y;
}
if (x > maxX) {
maxX = x;
}
if (y > maxY) {
maxY = y;
}
}
invSize = Math.max(maxX - minX, maxY - minY);
invSize = invSize !== 0 ? 1 / invSize : 0;
}
earcutLinked(outerNode, triangles, dim, minX, minY, invSize);
return triangles;
}
function linkedList(data, start, end, dim, clockwise) {
var i, last;
if (clockwise === signedArea(data, start, end, dim) > 0) {
for (i = start; i < end; i += dim) {
last = insertNode(i, data[i], data[i + 1], last);
}
} else {
for (i = end - dim; i >= start; i -= dim) {
last = insertNode(i, data[i], data[i + 1], last);
}
}
if (last && equals(last, last.next)) {
removeNode(last);
last = last.next;
}
return last;
}
function filterPoints(start, end) {
if (!start) {
return start;
}
if (!end) {
end = start;
}
var p = start, again;
do {
again = false;
if (!p.steiner && (equals(p, p.next) || area(p.prev, p, p.next) === 0)) {
removeNode(p);
p = end = p.prev;
if (p === p.next) {
break;
}
again = true;
} else {
p = p.next;
}
} while (again || p !== end);
return end;
}
function earcutLinked(ear, triangles, dim, minX, minY, invSize, pass) {
if (!ear) {
return;
}
if (!pass && invSize) {
indexCurve(ear, minX, minY, invSize);
}
var stop = ear, prev, next;
while (ear.prev !== ear.next) {
prev = ear.prev;
next = ear.next;
if (invSize ? isEarHashed(ear, minX, minY, invSize) : isEar(ear)) {
triangles.push(prev.i / dim);
triangles.push(ear.i / dim);
triangles.push(next.i / dim);
removeNode(ear);
ear = next.next;
stop = next.next;
continue;
}
ear = next;
if (ear === stop) {
if (!pass) {
earcutLinked(filterPoints(ear), triangles, dim, minX, minY, invSize, 1);
} else if (pass === 1) {
ear = cureLocalIntersections(filterPoints(ear), triangles, dim);
earcutLinked(ear, triangles, dim, minX, minY, invSize, 2);
} else if (pass === 2) {
splitEarcut(ear, triangles, dim, minX, minY, invSize);
}
break;
}
}
}
function isEar(ear) {
var a = ear.prev, b = ear, c = ear.next;
if (area(a, b, c) >= 0) {
return false;
}
var p = ear.next.next;
while (p !== ear.prev) {
if (pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0) {
return false;
}
p = p.next;
}
return true;
}
function isEarHashed(ear, minX, minY, invSize) {
var a = ear.prev, b = ear, c = ear.next;
if (area(a, b, c) >= 0) {
return false;
}
var minTX = a.x < b.x ? a.x < c.x ? a.x : c.x : b.x < c.x ? b.x : c.x, minTY = a.y < b.y ? a.y < c.y ? a.y : c.y : b.y < c.y ? b.y : c.y, maxTX = a.x > b.x ? a.x > c.x ? a.x : c.x : b.x > c.x ? b.x : c.x, maxTY = a.y > b.y ? a.y > c.y ? a.y : c.y : b.y > c.y ? b.y : c.y;
var minZ = zOrder(minTX, minTY, minX, minY, invSize), maxZ = zOrder(maxTX, maxTY, minX, minY, invSize);
var p = ear.prevZ, n = ear.nextZ;
while (p && p.z >= minZ && n && n.z <= maxZ) {
if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0) {
return false;
}
p = p.prevZ;
if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0) {
return false;
}
n = n.nextZ;
}
while (p && p.z >= minZ) {
if (p !== ear.prev && p !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, p.x, p.y) && area(p.prev, p, p.next) >= 0) {
return false;
}
p = p.prevZ;
}
while (n && n.z <= maxZ) {
if (n !== ear.prev && n !== ear.next && pointInTriangle(a.x, a.y, b.x, b.y, c.x, c.y, n.x, n.y) && area(n.prev, n, n.next) >= 0) {
return false;
}
n = n.nextZ;
}
return true;
}
function cureLocalIntersections(start, triangles, dim) {
var p = start;
do {
var a = p.prev, b = p.next.next;
if (!equals(a, b) && intersects(a, p, p.next, b) && locallyInside(a, b) && locallyInside(b, a)) {
triangles.push(a.i / dim);
triangles.push(p.i / dim);
triangles.push(b.i / dim);
removeNode(p);
removeNode(p.next);
p = start = b;
}
p = p.next;
} while (p !== start);
return filterPoints(p);
}
function splitEarcut(start, triangles, dim, minX, minY, invSize) {
var a = start;
do {
var b = a.next.next;
while (b !== a.prev) {
if (a.i !== b.i && isValidDiagonal(a, b)) {
var c = splitPolygon(a, b);
a = filterPoints(a, a.next);
c = filterPoints(c, c.next);
earcutLinked(a, triangles, dim, minX, minY, invSize);
earcutLinked(c, triangles, dim, minX, minY, invSize);
return;
}
b = b.next;
}
a = a.next;
} while (a !== start);
}
function eliminateHoles(data, holeIndices, outerNode, dim) {
var queue = [], i, len, start, end, list;
for (i = 0, len = holeIndices.length; i < len; i++) {
start = holeIndices[i] * dim;
end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
list = linkedList(data, start, end, dim, false);
if (list === list.next) {
list.steiner = true;
}
queue.push(getLeftmost(list));
}
queue.sort(compareX);
for (i = 0; i < queue.length; i++) {
eliminateHole(queue[i], outerNode);
outerNode = filterPoints(outerNode, outerNode.next);
}
return outerNode;
}
function compareX(a, b) {
return a.x - b.x;
}
function eliminateHole(hole, outerNode) {
outerNode = findHoleBridge(hole, outerNode);
if (outerNode) {
var b = splitPolygon(outerNode, hole);
filterPoints(outerNode, outerNode.next);
filterPoints(b, b.next);
}
}
function findHoleBridge(hole, outerNode) {
var p = outerNode, hx = hole.x, hy = hole.y, qx = -Infinity, m;
do {
if (hy <= p.y && hy >= p.next.y && p.next.y !== p.y) {
var x = p.x + (hy - p.y) * (p.next.x - p.x) / (p.next.y - p.y);
if (x <= hx && x > qx) {
qx = x;
if (x === hx) {
if (hy === p.y) {
return p;
}
if (hy === p.next.y) {
return p.next;
}
}
m = p.x < p.next.x ? p : p.next;
}
}
p = p.next;
} while (p !== outerNode);
if (!m) {
return null;
}
if (hx === qx) {
return m;
}
var stop = m, mx = m.x, my = m.y, tanMin = Infinity, tan;
p = m;
do {
if (hx >= p.x && p.x >= mx && hx !== p.x && pointInTriangle(hy < my ? hx : qx, hy, mx, my, hy < my ? qx : hx, hy, p.x, p.y)) {
tan = Math.abs(hy - p.y) / (hx - p.x);
if (locallyInside(p, hole) && (tan < tanMin || tan === tanMin && (p.x > m.x || p.x === m.x && sectorContainsSector(m, p)))) {
m = p;
tanMin = tan;
}
}
p = p.next;
} while (p !== stop);
return m;
}
function sectorContainsSector(m, p) {
return area(m.prev, m, p.prev) < 0 && area(p.next, m, m.next) < 0;
}
function indexCurve(start, minX, minY, invSize) {
var p = start;
do {
if (p.z === null) {
p.z = zOrder(p.x, p.y, minX, minY, invSize);
}
p.prevZ = p.prev;
p.nextZ = p.next;
p = p.next;
} while (p !== start);
p.prevZ.nextZ = null;
p.prevZ = null;
sortLinked(p);
}
function sortLinked(list) {
var i, p, q, e, tail, numMerges, pSize, qSize, inSize = 1;
do {
p = list;
list = null;
tail = null;
numMerges = 0;
while (p) {
numMerges++;
q = p;
pSize = 0;
for (i = 0; i < inSize; i++) {
pSize++;
q = q.nextZ;
if (!q) {
break;
}
}
qSize = inSize;
while (pSize > 0 || qSize > 0 && q) {
if (pSize !== 0 && (qSize === 0 || !q || p.z <= q.z)) {
e = p;
p = p.nextZ;
pSize--;
} else {
e = q;
q = q.nextZ;
qSize--;
}
if (tail) {
tail.nextZ = e;
} else {
list = e;
}
e.prevZ = tail;
tail = e;
}
p = q;
}
tail.nextZ = null;
inSize *= 2;
} while (numMerges > 1);
return list;
}
function zOrder(x, y, minX, minY, invSize) {
x = 32767 * (x - minX) * invSize;
y = 32767 * (y - minY) * invSize;
x = (x | x << 8) & 16711935;
x = (x | x << 4) & 252645135;
x = (x | x << 2) & 858993459;
x = (x | x << 1) & 1431655765;
y = (y | y << 8) & 16711935;
y = (y | y << 4) & 252645135;
y = (y | y << 2) & 858993459;
y = (y | y << 1) & 1431655765;
return x | y << 1;
}
function getLeftmost(start) {
var p = start, leftmost = start;
do {
if (p.x < leftmost.x || p.x === leftmost.x && p.y < leftmost.y) {
leftmost = p;
}
p = p.next;
} while (p !== start);
return leftmost;
}
function pointInTriangle(ax, ay, bx, by, cx, cy, px, py) {
return (cx - px) * (ay - py) - (ax - px) * (cy - py) >= 0 && (ax - px) * (by - py) - (bx - px) * (ay - py) >= 0 && (bx - px) * (cy - py) - (cx - px) * (by - py) >= 0;
}
function isValidDiagonal(a, b) {
return a.next.i !== b.i && a.prev.i !== b.i && !intersectsPolygon(a, b) && (locallyInside(a, b) && locallyInside(b, a) && middleInside(a, b) && (area(a.prev, a, b.prev) || area(a, b.prev, b)) || equals(a, b) && area(a.prev, a, a.next) > 0 && area(b.prev, b, b.next) > 0);
}
function area(p, q, r) {
return (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
}
function equals(p1, p2) {
return p1.x === p2.x && p1.y === p2.y;
}
function intersects(p1, q1, p2, q2) {
var o1 = sign(area(p1, q1, p2));
var o2 = sign(area(p1, q1, q2));
var o3 = sign(area(p2, q2, p1));
var o4 = sign(area(p2, q2, q1));
if (o1 !== o2 && o3 !== o4) {
return true;
}
if (o1 === 0 && onSegment(p1, p2, q1)) {
return true;
}
if (o2 === 0 && onSegment(p1, q2, q1)) {
return true;
}
if (o3 === 0 && onSegment(p2, p1, q2)) {
return true;
}
if (o4 === 0 && onSegment(p2, q1, q2)) {
return true;
}
return false;
}
function onSegment(p, q, r) {
return q.x <= Math.max(p.x, r.x) && q.x >= Math.min(p.x, r.x) && q.y <= Math.max(p.y, r.y) && q.y >= Math.min(p.y, r.y);
}
function sign(num) {
return num > 0 ? 1 : num < 0 ? -1 : 0;
}
function intersectsPolygon(a, b) {
var p = a;
do {
if (p.i !== a.i && p.next.i !== a.i && p.i !== b.i && p.next.i !== b.i && intersects(p, p.next, a, b)) {
return true;
}
p = p.next;
} while (p !== a);
return false;
}
function locallyInside(a, b) {
return area(a.prev, a, a.next) < 0 ? area(a, b, a.next) >= 0 && area(a, a.prev, b) >= 0 : area(a, b, a.prev) < 0 || area(a, a.next, b) < 0;
}
function middleInside(a, b) {
var p = a, inside = false, px = (a.x + b.x) / 2, py = (a.y + b.y) / 2;
do {
if (p.y > py !== p.next.y > py && p.next.y !== p.y && px < (p.next.x - p.x) * (py - p.y) / (p.next.y - p.y) + p.x) {
inside = !inside;
}
p = p.next;
} while (p !== a);
return inside;
}
function splitPolygon(a, b) {
var a2 = new Node(a.i, a.x, a.y), b2 = new Node(b.i, b.x, b.y), an = a.next, bp = b.prev;
a.next = b;
b.prev = a;
a2.next = an;
an.prev = a2;
b2.next = a2;
a2.prev = b2;
bp.next = b2;
b2.prev = bp;
return b2;
}
function insertNode(i, x, y, last) {
var p = new Node(i, x, y);
if (!last) {
p.prev = p;
p.next = p;
} else {
p.next = last.next;
p.prev = last;
last.next.prev = p;
last.next = p;
}
return p;
}
function removeNode(p) {
p.next.prev = p.prev;
p.prev.next = p.next;
if (p.prevZ) {
p.prevZ.nextZ = p.nextZ;
}
if (p.nextZ) {
p.nextZ.prevZ = p.prevZ;
}
}
function Node(i, x, y) {
this.i = i;
this.x = x;
this.y = y;
this.prev = null;
this.next = null;
this.z = null;
this.prevZ = null;
this.nextZ = null;
this.steiner = false;
}
earcut.deviation = function (data, holeIndices, dim, triangles) {
var hasHoles = holeIndices && holeIndices.length;
var outerLen = hasHoles ? holeIndices[0] * dim : data.length;
var polygonArea = Math.abs(signedArea(data, 0, outerLen, dim));
if (hasHoles) {
for (var i = 0, len = holeIndices.length; i < len; i++) {
var start = holeIndices[i] * dim;
var end = i < len - 1 ? holeIndices[i + 1] * dim : data.length;
polygonArea -= Math.abs(signedArea(data, start, end, dim));
}
}
var trianglesArea = 0;
for (i = 0; i < triangles.length; i += 3) {
var a = triangles[i] * dim;
var b = triangles[i + 1] * dim;
var c = triangles[i + 2] * dim;
trianglesArea += Math.abs((data[a] - data[c]) * (data[b + 1] - data[a + 1]) - (data[a] - data[b]) * (data[c + 1] - data[a + 1]));
}
return polygonArea === 0 && trianglesArea === 0 ? 0 : Math.abs((trianglesArea - polygonArea) / polygonArea);
};
function signedArea(data, start, end, dim) {
var sum = 0;
for (var i = start, j = end - dim; i < end; i += dim) {
sum += (data[j] - data[i]) * (data[i + 1] + data[j + 1]);
j = i;
}
return sum;
}
earcut.flatten = function (data) {
var dim = data[0][0].length, result = {
vertices: [],
holes: [],
dimensions: dim
}, holeIndex = 0;
for (var i = 0; i < data.length; i++) {
for (var j = 0; j < data[i].length; j++) {
for (var d = 0; d < dim; d++) {
result.vertices.push(data[i][j][d]);
}
}
if (i > 0) {
holeIndex += data[i - 1].length;
result.holes.push(holeIndex);
}
}
return result;
};
earcut_1.default = default_1;
function quickselect(arr, k, left, right, compare) {
quickselectStep(arr, k, left || 0, right || arr.length - 1, compare || defaultCompare);
}
function quickselectStep(arr, k, left, right, compare) {
while (right > left) {
if (right - left > 600) {
var n = right - left + 1;
var m = k - left + 1;
var z = Math.log(n);
var s = 0.5 * Math.exp(2 * z / 3);
var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
var newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
quickselectStep(arr, k, newLeft, newRight, compare);
}
var t = arr[k];
var i = left;
var j = right;
swap$1(arr, left, k);
if (compare(arr[right], t) > 0) {
swap$1(arr, left, right);
}
while (i < j) {
swap$1(arr, i, j);
i++;
j--;
while (compare(arr[i], t) < 0) {
i++;
}
while (compare(arr[j], t) > 0) {
j--;
}
}
if (compare(arr[left], t) === 0) {
swap$1(arr, left, j);
} else {
j++;
swap$1(arr, j, right);
}
if (j <= k) {
left = j + 1;
}
if (k <= j) {
right = j - 1;
}
}
}
function swap$1(arr, i, j) {
var tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
function defaultCompare(a, b) {
return a < b ? -1 : a > b ? 1 : 0;
}
function classifyRings(rings, maxRings) {
var len = rings.length;
if (len <= 1) {
return [rings];
}
var polygons = [];
var polygon, ccw;
for (var i = 0; i < len; i++) {
var area = calculateSignedArea(rings[i]);
if (area === 0) {
continue;
}
rings[i].area = Math.abs(area);
if (ccw === undefined) {
ccw = area < 0;
}
if (ccw === area < 0) {
if (polygon) {
polygons.push(polygon);
}
polygon = [rings[i]];
} else {
polygon.push(rings[i]);
}
}
if (polygon) {
polygons.push(polygon);
}
if (maxRings > 1) {
for (var j = 0; j < polygons.length; j++) {
if (polygons[j].length <= maxRings) {
continue;
}
quickselect(polygons[j], maxRings, 1, polygons[j].length - 1, compareAreas);
polygons[j] = polygons[j].slice(0, maxRings);
}
}
return polygons;
}
function compareAreas(a, b) {
return b.area - a.area;
}
function hasPattern(type, layers, options) {
var patterns = options.patternDependencies;
var hasPattern = false;
for (var i = 0, list = layers; i < list.length; i += 1) {
var layer = list[i];
var patternProperty = layer.paint.get(type + '-pattern');
if (!patternProperty.isConstant()) {
hasPattern = true;
}
var constantPattern = patternProperty.constantOr(null);
if (constantPattern) {
hasPattern = true;
patterns[constantPattern.to] = true;
patterns[constantPattern.from] = true;
}
}
return hasPattern;
}
function addPatternDependencies(type, layers, patternFeature, zoom, options) {
var patterns = options.patternDependencies;
for (var i = 0, list = layers; i < list.length; i += 1) {
var layer = list[i];
var patternProperty = layer.paint.get(type + '-pattern');
var patternPropertyValue = patternProperty.value;
if (patternPropertyValue.kind !== 'constant') {
var min = patternPropertyValue.evaluate({ zoom: zoom - 1 }, patternFeature, {}, options.availableImages);
var mid = patternPropertyValue.evaluate({ zoom: zoom }, patternFeature, {}, options.availableImages);
var max = patternPropertyValue.evaluate({ zoom: zoom + 1 }, patternFeature, {}, options.availableImages);
min = min && min.name ? min.name : min;
mid = mid && mid.name ? mid.name : mid;
max = max && max.name ? max.name : max;
patterns[min] = true;
patterns[mid] = true;
patterns[max] = true;
patternFeature.patterns[layer.id] = {
min: min,
mid: mid,
max: max
};
}
}
return patternFeature;
}
var EARCUT_MAX_RINGS = 500;
var FillBucket = function FillBucket(options) {
this.zoom = options.zoom;
this.overscaling = options.overscaling;
this.layers = options.layers;
this.layerIds = this.layers.map(function (layer) {
return layer.id;
});
this.index = options.index;
this.hasPattern = false;
this.patternFeatures = [];
this.layoutVertexArray = new StructArrayLayout2i4();
this.indexArray = new StructArrayLayout3ui6();
this.indexArray2 = new StructArrayLayout2ui4();
this.programConfigurations = new ProgramConfigurationSet(options.layers, options.zoom);
this.segments = new SegmentVector();
this.segments2 = new SegmentVector();
this.stateDependentLayerIds = this.layers.filter(function (l) {
return l.isStateDependent();
}).map(function (l) {
return l.id;
});
};
FillBucket.prototype.populate = function populate(features, options, canonical) {
this.hasPattern = hasPattern('fill', this.layers, options);
var fillSortKey = this.layers[0].layout.get('fill-sort-key');
var bucketFeatures = [];
for (var i = 0, list = features; i < list.length; i += 1) {
var ref = list[i];
var feature = ref.feature;
var id = ref.id;
var index = ref.index;
var sourceLayerIndex = ref.sourceLayerIndex;
var needGeometry = this.layers[0]._featureFilter.needGeometry;
var evaluationFeature = toEvaluationFeature(feature, needGeometry);
if (!this.layers[0]._featureFilter.filter(new EvaluationParameters(this.zoom), evaluationFeature, canonical)) {
continue;
}
var sortKey = fillSortKey ? fillSortKey.evaluate(evaluationFeature, {}, canonical, options.availableImages) : undefined;
var bucketFeature = {
id: id,
properties: feature.properties,
type: feature.type,
sourceLayerIndex: sourceLayerIndex,
index: index,
geometry: needGeometry ? evaluationFeature.geometry : loadGeometry(feature),
patterns: {},
sortKey: sortKey
};
bucketFeatures.push(bucketFeature);
}
if (fillSortKey) {
bucketFeatures.sort(function (a, b) {
return a.sortKey - b.sortKey;
});
}
for (var i$1 = 0, list$1 = bucketFeatures; i$1 < list$1.length; i$1 += 1) {
var bucketFeature$1 = list$1[i$1];
var ref$1 = bucketFeature$1;
var geometry = ref$1.geometry;
var index$1 = ref$1.index;
var sourceLayerIndex$1 = ref$1.sourceLayerIndex;
if (this.hasPattern) {
var patternFeature = addPatternDependencies('fill', this.layers, bucketFeature$1, this.zoom, options);
this.patternFeatures.push(patternFeature);
} else {
this.addFeature(bucketFeature$1, geometry, index$1, canonical, {});
}
var feature$1 = features[index$1].feature;
options.featureIndex.insert(feature$1, geometry, index$1, sourceLayerIndex$1, this.index);
}
};
FillBucket.prototype.update = function update(states, vtLayer, imagePositions) {
if (!this.stateDependentLayers.length) {
return;
}
this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, imagePositions);
};
FillBucket.prototype.addFeatures = function addFeatures(options, canonical, imagePositions) {
for (var i = 0, list = this.patternFeatures; i < list.length; i += 1) {
var feature = list[i];
this.addFeature(feature, feature.geometry, feature.index, canonical, imagePositions);
}
};
FillBucket.prototype.isEmpty = function isEmpty() {
return this.layoutVertexArray.length === 0;
};
FillBucket.prototype.uploadPending = function uploadPending() {
return !this.uploaded || this.programConfigurations.needsUpload;
};
FillBucket.prototype.upload = function upload(context) {
if (!this.uploaded) {
this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, members$1);
this.indexBuffer = context.createIndexBuffer(this.indexArray);
this.indexBuffer2 = context.createIndexBuffer(this.indexArray2);
}
this.programConfigurations.upload(context);
this.uploaded = true;
};
FillBucket.prototype.destroy = function destroy() {
if (!this.layoutVertexBuffer) {
return;
}
this.layoutVertexBuffer.destroy();
this.indexBuffer.destroy();
this.indexBuffer2.destroy();
this.programConfigurations.destroy();
this.segments.destroy();
this.segments2.destroy();
};
FillBucket.prototype.addFeature = function addFeature(feature, geometry, index, canonical, imagePositions) {
for (var i$4 = 0, list$2 = classifyRings(geometry, EARCUT_MAX_RINGS); i$4 < list$2.length; i$4 += 1) {
var polygon = list$2[i$4];
var numVertices = 0;
for (var i$2 = 0, list = polygon; i$2 < list.length; i$2 += 1) {
var ring = list[i$2];
numVertices += ring.length;
}
var triangleSegment = this.segments.prepareSegment(numVertices, this.layoutVertexArray, this.indexArray);
var triangleIndex = triangleSegment.vertexLength;
var flattened = [];
var holeIndices = [];
for (var i$3 = 0, list$1 = polygon; i$3 < list$1.length; i$3 += 1) {
var ring$1 = list$1[i$3];
if (ring$1.length === 0) {
continue;
}
if (ring$1 !== polygon[0]) {
holeIndices.push(flattened.length / 2);
}
var lineSegment = this.segments2.prepareSegment(ring$1.length, this.layoutVertexArray, this.indexArray2);
var lineIndex = lineSegment.vertexLength;
this.layoutVertexArray.emplaceBack(ring$1[0].x, ring$1[0].y);
this.indexArray2.emplaceBack(lineIndex + ring$1.length - 1, lineIndex);
flattened.push(ring$1[0].x);
flattened.push(ring$1[0].y);
for (var i = 1; i < ring$1.length; i++) {
this.layoutVertexArray.emplaceBack(ring$1[i].x, ring$1[i].y);
this.indexArray2.emplaceBack(lineIndex + i - 1, lineIndex + i);
flattened.push(ring$1[i].x);
flattened.push(ring$1[i].y);
}
lineSegment.vertexLength += ring$1.length;
lineSegment.primitiveLength += ring$1.length;
}
var indices = earcut_1(flattened, holeIndices);
for (var i$1 = 0; i$1 < indices.length; i$1 += 3) {
this.indexArray.emplaceBack(triangleIndex + indices[i$1], triangleIndex + indices[i$1 + 1], triangleIndex + indices[i$1 + 2]);
}
triangleSegment.vertexLength += numVertices;
triangleSegment.primitiveLength += indices.length / 3;
}
this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, imagePositions, canonical);
};
register('FillBucket', FillBucket, {
omit: [
'layers',
'patternFeatures'
]
});
var layout$4 = new Properties({ 'fill-sort-key': new DataDrivenProperty(spec['layout_fill']['fill-sort-key']) });
var paint$4 = new Properties({
'fill-antialias': new DataConstantProperty(spec['paint_fill']['fill-antialias']),
'fill-opacity': new DataDrivenProperty(spec['paint_fill']['fill-opacity']),
'fill-color': new DataDrivenProperty(spec['paint_fill']['fill-color']),
'fill-outline-color': new DataDrivenProperty(spec['paint_fill']['fill-outline-color']),
'fill-translate': new DataConstantProperty(spec['paint_fill']['fill-translate']),
'fill-translate-anchor': new DataConstantProperty(spec['paint_fill']['fill-translate-anchor']),
'fill-pattern': new CrossFadedDataDrivenProperty(spec['paint_fill']['fill-pattern'])
});
var properties$3 = {
paint: paint$4,
layout: layout$4
};
var FillStyleLayer = function (StyleLayer) {
function FillStyleLayer(layer) {
StyleLayer.call(this, layer, properties$3);
}
if (StyleLayer)
FillStyleLayer.__proto__ = StyleLayer;
FillStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
FillStyleLayer.prototype.constructor = FillStyleLayer;
FillStyleLayer.prototype.recalculate = function recalculate(parameters, availableImages) {
StyleLayer.prototype.recalculate.call(this, parameters, availableImages);
var outlineColor = this.paint._values['fill-outline-color'];
if (outlineColor.value.kind === 'constant' && outlineColor.value.value === undefined) {
this.paint._values['fill-outline-color'] = this.paint._values['fill-color'];
}
};
FillStyleLayer.prototype.createBucket = function createBucket(parameters) {
return new FillBucket(parameters);
};
FillStyleLayer.prototype.queryRadius = function queryRadius() {
return translateDistance(this.paint.get('fill-translate'));
};
FillStyleLayer.prototype.queryIntersectsFeature = function queryIntersectsFeature(queryGeometry, feature, featureState, geometry, zoom, transform, pixelsToTileUnits) {
var translatedPolygon = translate(queryGeometry, this.paint.get('fill-translate'), this.paint.get('fill-translate-anchor'), transform.angle, pixelsToTileUnits);
return polygonIntersectsMultiPolygon(translatedPolygon, geometry);
};
FillStyleLayer.prototype.isTileClipped = function isTileClipped() {
return true;
};
return FillStyleLayer;
}(StyleLayer);
var layout$5 = createLayout([
{
name: 'a_pos',
components: 2,
type: 'Int16'
},
{
name: 'a_normal_ed',
components: 4,
type: 'Int16'
}
], 4);
var members$2 = layout$5.members;
var vectortilefeature = VectorTileFeature;
function VectorTileFeature(pbf, end, extent, keys, values) {
this.properties = {};
this.extent = extent;
this.type = 0;
this._pbf = pbf;
this._geometry = -1;
this._keys = keys;
this._values = values;
pbf.readFields(readFeature, this, end);
}
function readFeature(tag, feature, pbf) {
if (tag == 1) {
feature.id = pbf.readVarint();
} else if (tag == 2) {
readTag(pbf, feature);
} else if (tag == 3) {
feature.type = pbf.readVarint();
} else if (tag == 4) {
feature._geometry = pbf.pos;
}
}
function readTag(pbf, feature) {
var end = pbf.readVarint() + pbf.pos;
while (pbf.pos < end) {
var key = feature._keys[pbf.readVarint()], value = feature._values[pbf.readVarint()];
feature.properties[key] = value;
}
}
VectorTileFeature.types = [
'Unknown',
'Point',
'LineString',
'Polygon'
];
VectorTileFeature.prototype.loadGeometry = function () {
var pbf = this._pbf;
pbf.pos = this._geometry;
var end = pbf.readVarint() + pbf.pos, cmd = 1, length = 0, x = 0, y = 0, lines = [], line;
while (pbf.pos < end) {
if (length <= 0) {
var cmdLen = pbf.readVarint();
cmd = cmdLen & 7;
length = cmdLen >> 3;
}
length--;
if (cmd === 1 || cmd === 2) {
x += pbf.readSVarint();
y += pbf.readSVarint();
if (cmd === 1) {
if (line) {
lines.push(line);
}
line = [];
}
line.push(new pointGeometry(x, y));
} else if (cmd === 7) {
if (line) {
line.push(line[0].clone());
}
} else {
throw new Error('unknown command ' + cmd);
}
}
if (line) {
lines.push(line);
}
return lines;
};
VectorTileFeature.prototype.bbox = function () {
var pbf = this._pbf;
pbf.pos = this._geometry;
var end = pbf.readVarint() + pbf.pos, cmd = 1, length = 0, x = 0, y = 0, x1 = Infinity, x2 = -Infinity, y1 = Infinity, y2 = -Infinity;
while (pbf.pos < end) {
if (length <= 0) {
var cmdLen = pbf.readVarint();
cmd = cmdLen & 7;
length = cmdLen >> 3;
}
length--;
if (cmd === 1 || cmd === 2) {
x += pbf.readSVarint();
y += pbf.readSVarint();
if (x < x1) {
x1 = x;
}
if (x > x2) {
x2 = x;
}
if (y < y1) {
y1 = y;
}
if (y > y2) {
y2 = y;
}
} else if (cmd !== 7) {
throw new Error('unknown command ' + cmd);
}
}
return [
x1,
y1,
x2,
y2
];
};
VectorTileFeature.prototype.toGeoJSON = function (x, y, z) {
var size = this.extent * Math.pow(2, z), x0 = this.extent * x, y0 = this.extent * y, coords = this.loadGeometry(), type = VectorTileFeature.types[this.type], i, j;
function project(line) {
for (var j = 0; j < line.length; j++) {
var p = line[j], y2 = 180 - (p.y + y0) * 360 / size;
line[j] = [
(p.x + x0) * 360 / size - 180,
360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90
];
}
}
switch (this.type) {
case 1:
var points = [];
for (i = 0; i < coords.length; i++) {
points[i] = coords[i][0];
}
coords = points;
project(coords);
break;
case 2:
for (i = 0; i < coords.length; i++) {
project(coords[i]);
}
break;
case 3:
coords = classifyRings$1(coords);
for (i = 0; i < coords.length; i++) {
for (j = 0; j < coords[i].length; j++) {
project(coords[i][j]);
}
}
break;
}
if (coords.length === 1) {
coords = coords[0];
} else {
type = 'Multi' + type;
}
var result = {
type: 'Feature',
geometry: {
type: type,
coordinates: coords
},
properties: this.properties
};
if ('id' in this) {
result.id = this.id;
}
return result;
};
function classifyRings$1(rings) {
var len = rings.length;
if (len <= 1) {
return [rings];
}
var polygons = [], polygon, ccw;
for (var i = 0; i < len; i++) {
var area = signedArea$1(rings[i]);
if (area === 0) {
continue;
}
if (ccw === undefined) {
ccw = area < 0;
}
if (ccw === area < 0) {
if (polygon) {
polygons.push(polygon);
}
polygon = [rings[i]];
} else {
polygon.push(rings[i]);
}
}
if (polygon) {
polygons.push(polygon);
}
return polygons;
}
function signedArea$1(ring) {
var sum = 0;
for (var i = 0, len = ring.length, j = len - 1, p1, p2; i < len; j = i++) {
p1 = ring[i];
p2 = ring[j];
sum += (p2.x - p1.x) * (p1.y + p2.y);
}
return sum;
}
var vectortilelayer = VectorTileLayer;
function VectorTileLayer(pbf, end) {
this.version = 1;
this.name = null;
this.extent = 4096;
this.length = 0;
this._pbf = pbf;
this._keys = [];
this._values = [];
this._features = [];
pbf.readFields(readLayer, this, end);
this.length = this._features.length;
}
function readLayer(tag, layer, pbf) {
if (tag === 15) {
layer.version = pbf.readVarint();
} else if (tag === 1) {
layer.name = pbf.readString();
} else if (tag === 5) {
layer.extent = pbf.readVarint();
} else if (tag === 2) {
layer._features.push(pbf.pos);
} else if (tag === 3) {
layer._keys.push(pbf.readString());
} else if (tag === 4) {
layer._values.push(readValueMessage(pbf));
}
}
function readValueMessage(pbf) {
var value = null, end = pbf.readVarint() + pbf.pos;
while (pbf.pos < end) {
var tag = pbf.readVarint() >> 3;
value = tag === 1 ? pbf.readString() : tag === 2 ? pbf.readFloat() : tag === 3 ? pbf.readDouble() : tag === 4 ? pbf.readVarint64() : tag === 5 ? pbf.readVarint() : tag === 6 ? pbf.readSVarint() : tag === 7 ? pbf.readBoolean() : null;
}
return value;
}
VectorTileLayer.prototype.feature = function (i) {
if (i < 0 || i >= this._features.length) {
throw new Error('feature index out of bounds');
}
this._pbf.pos = this._features[i];
var end = this._pbf.readVarint() + this._pbf.pos;
return new vectortilefeature(this._pbf, end, this.extent, this._keys, this._values);
};
var vectortile = VectorTile;
function VectorTile(pbf, end) {
this.layers = pbf.readFields(readTile, {}, end);
}
function readTile(tag, layers, pbf) {
if (tag === 3) {
var layer = new vectortilelayer(pbf, pbf.readVarint() + pbf.pos);
if (layer.length) {
layers[layer.name] = layer;
}
}
}
var VectorTile$1 = vectortile;
var VectorTileFeature$1 = vectortilefeature;
var VectorTileLayer$1 = vectortilelayer;
var vectorTile = {
VectorTile: VectorTile$1,
VectorTileFeature: VectorTileFeature$1,
VectorTileLayer: VectorTileLayer$1
};
var vectorTileFeatureTypes = vectorTile.VectorTileFeature.types;
var EARCUT_MAX_RINGS$1 = 500;
var FACTOR = Math.pow(2, 13);
function addVertex(vertexArray, x, y, nx, ny, nz, t, e) {
vertexArray.emplaceBack(x, y, Math.floor(nx * FACTOR) * 2 + t, ny * FACTOR * 2, nz * FACTOR * 2, Math.round(e));
}
var FillExtrusionBucket = function FillExtrusionBucket(options) {
this.zoom = options.zoom;
this.overscaling = options.overscaling;
this.layers = options.layers;
this.layerIds = this.layers.map(function (layer) {
return layer.id;
});
this.index = options.index;
this.hasPattern = false;
this.layoutVertexArray = new StructArrayLayout2i4i12();
this.indexArray = new StructArrayLayout3ui6();
this.programConfigurations = new ProgramConfigurationSet(options.layers, options.zoom);
this.segments = new SegmentVector();
this.stateDependentLayerIds = this.layers.filter(function (l) {
return l.isStateDependent();
}).map(function (l) {
return l.id;
});
};
FillExtrusionBucket.prototype.populate = function populate(features, options, canonical) {
this.features = [];
this.hasPattern = hasPattern('fill-extrusion', this.layers, options);
for (var i = 0, list = features; i < list.length; i += 1) {
var ref = list[i];
var feature = ref.feature;
var id = ref.id;
var index = ref.index;
var sourceLayerIndex = ref.sourceLayerIndex;
var needGeometry = this.layers[0]._featureFilter.needGeometry;
var evaluationFeature = toEvaluationFeature(feature, needGeometry);
if (!this.layers[0]._featureFilter.filter(new EvaluationParameters(this.zoom), evaluationFeature, canonical)) {
continue;
}
var bucketFeature = {
id: id,
sourceLayerIndex: sourceLayerIndex,
index: index,
geometry: needGeometry ? evaluationFeature.geometry : loadGeometry(feature),
properties: feature.properties,
type: feature.type,
patterns: {}
};
if (this.hasPattern) {
this.features.push(addPatternDependencies('fill-extrusion', this.layers, bucketFeature, this.zoom, options));
} else {
this.addFeature(bucketFeature, bucketFeature.geometry, index, canonical, {});
}
options.featureIndex.insert(feature, bucketFeature.geometry, index, sourceLayerIndex, this.index, true);
}
};
FillExtrusionBucket.prototype.addFeatures = function addFeatures(options, canonical, imagePositions) {
for (var i = 0, list = this.features; i < list.length; i += 1) {
var feature = list[i];
var geometry = feature.geometry;
this.addFeature(feature, geometry, feature.index, canonical, imagePositions);
}
};
FillExtrusionBucket.prototype.update = function update(states, vtLayer, imagePositions) {
if (!this.stateDependentLayers.length) {
return;
}
this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, imagePositions);
};
FillExtrusionBucket.prototype.isEmpty = function isEmpty() {
return this.layoutVertexArray.length === 0;
};
FillExtrusionBucket.prototype.uploadPending = function uploadPending() {
return !this.uploaded || this.programConfigurations.needsUpload;
};
FillExtrusionBucket.prototype.upload = function upload(context) {
if (!this.uploaded) {
this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, members$2);
this.indexBuffer = context.createIndexBuffer(this.indexArray);
}
this.programConfigurations.upload(context);
this.uploaded = true;
};
FillExtrusionBucket.prototype.destroy = function destroy() {
if (!this.layoutVertexBuffer) {
return;
}
this.layoutVertexBuffer.destroy();
this.indexBuffer.destroy();
this.programConfigurations.destroy();
this.segments.destroy();
};
FillExtrusionBucket.prototype.addFeature = function addFeature(feature, geometry, index, canonical, imagePositions) {
for (var i$4 = 0, list$3 = classifyRings(geometry, EARCUT_MAX_RINGS$1); i$4 < list$3.length; i$4 += 1) {
var polygon = list$3[i$4];
var numVertices = 0;
for (var i$1 = 0, list = polygon; i$1 < list.length; i$1 += 1) {
var ring = list[i$1];
numVertices += ring.length;
}
var segment = this.segments.prepareSegment(4, this.layoutVertexArray, this.indexArray);
for (var i$2 = 0, list$1 = polygon; i$2 < list$1.length; i$2 += 1) {
var ring$1 = list$1[i$2];
if (ring$1.length === 0) {
continue;
}
if (isEntirelyOutside(ring$1)) {
continue;
}
var edgeDistance = 0;
for (var p = 0; p < ring$1.length; p++) {
var p1 = ring$1[p];
if (p >= 1) {
var p2 = ring$1[p - 1];
if (!isBoundaryEdge(p1, p2)) {
if (segment.vertexLength + 4 > SegmentVector.MAX_VERTEX_ARRAY_LENGTH) {
segment = this.segments.prepareSegment(4, this.layoutVertexArray, this.indexArray);
}
var perp = p1.sub(p2)._perp()._unit();
var dist = p2.dist(p1);
if (edgeDistance + dist > 32768) {
edgeDistance = 0;
}
addVertex(this.layoutVertexArray, p1.x, p1.y, perp.x, perp.y, 0, 0, edgeDistance);
addVertex(this.layoutVertexArray, p1.x, p1.y, perp.x, perp.y, 0, 1, edgeDistance);
edgeDistance += dist;
addVertex(this.layoutVertexArray, p2.x, p2.y, perp.x, perp.y, 0, 0, edgeDistance);
addVertex(this.layoutVertexArray, p2.x, p2.y, perp.x, perp.y, 0, 1, edgeDistance);
var bottomRight = segment.vertexLength;
this.indexArray.emplaceBack(bottomRight, bottomRight + 2, bottomRight + 1);
this.indexArray.emplaceBack(bottomRight + 1, bottomRight + 2, bottomRight + 3);
segment.vertexLength += 4;
segment.primitiveLength += 2;
}
}
}
}
if (segment.vertexLength + numVertices > SegmentVector.MAX_VERTEX_ARRAY_LENGTH) {
segment = this.segments.prepareSegment(numVertices, this.layoutVertexArray, this.indexArray);
}
if (vectorTileFeatureTypes[feature.type] !== 'Polygon') {
continue;
}
var flattened = [];
var holeIndices = [];
var triangleIndex = segment.vertexLength;
for (var i$3 = 0, list$2 = polygon; i$3 < list$2.length; i$3 += 1) {
var ring$2 = list$2[i$3];
if (ring$2.length === 0) {
continue;
}
if (ring$2 !== polygon[0]) {
holeIndices.push(flattened.length / 2);
}
for (var i = 0; i < ring$2.length; i++) {
var p$1 = ring$2[i];
addVertex(this.layoutVertexArray, p$1.x, p$1.y, 0, 0, 1, 1, 0);
flattened.push(p$1.x);
flattened.push(p$1.y);
}
}
var indices = earcut_1(flattened, holeIndices);
for (var j = 0; j < indices.length; j += 3) {
this.indexArray.emplaceBack(triangleIndex + indices[j], triangleIndex + indices[j + 2], triangleIndex + indices[j + 1]);
}
segment.primitiveLength += indices.length / 3;
segment.vertexLength += numVertices;
}
this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, imagePositions, canonical);
};
register('FillExtrusionBucket', FillExtrusionBucket, {
omit: [
'layers',
'features'
]
});
function isBoundaryEdge(p1, p2) {
return p1.x === p2.x && (p1.x < 0 || p1.x > EXTENT$1) || p1.y === p2.y && (p1.y < 0 || p1.y > EXTENT$1);
}
function isEntirelyOutside(ring) {
return ring.every(function (p) {
return p.x < 0;
}) || ring.every(function (p) {
return p.x > EXTENT$1;
}) || ring.every(function (p) {
return p.y < 0;
}) || ring.every(function (p) {
return p.y > EXTENT$1;
});
}
var paint$5 = new Properties({
'fill-extrusion-opacity': new DataConstantProperty(spec['paint_fill-extrusion']['fill-extrusion-opacity']),
'fill-extrusion-color': new DataDrivenProperty(spec['paint_fill-extrusion']['fill-extrusion-color']),
'fill-extrusion-translate': new DataConstantProperty(spec['paint_fill-extrusion']['fill-extrusion-translate']),
'fill-extrusion-translate-anchor': new DataConstantProperty(spec['paint_fill-extrusion']['fill-extrusion-translate-anchor']),
'fill-extrusion-pattern': new CrossFadedDataDrivenProperty(spec['paint_fill-extrusion']['fill-extrusion-pattern']),
'fill-extrusion-height': new DataDrivenProperty(spec['paint_fill-extrusion']['fill-extrusion-height']),
'fill-extrusion-base': new DataDrivenProperty(spec['paint_fill-extrusion']['fill-extrusion-base']),
'fill-extrusion-vertical-gradient': new DataConstantProperty(spec['paint_fill-extrusion']['fill-extrusion-vertical-gradient'])
});
var properties$4 = { paint: paint$5 };
var FillExtrusionStyleLayer = function (StyleLayer) {
function FillExtrusionStyleLayer(layer) {
StyleLayer.call(this, layer, properties$4);
}
if (StyleLayer)
FillExtrusionStyleLayer.__proto__ = StyleLayer;
FillExtrusionStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
FillExtrusionStyleLayer.prototype.constructor = FillExtrusionStyleLayer;
FillExtrusionStyleLayer.prototype.createBucket = function createBucket(parameters) {
return new FillExtrusionBucket(parameters);
};
FillExtrusionStyleLayer.prototype.queryRadius = function queryRadius() {
return translateDistance(this.paint.get('fill-extrusion-translate'));
};
FillExtrusionStyleLayer.prototype.is3D = function is3D() {
return true;
};
FillExtrusionStyleLayer.prototype.queryIntersectsFeature = function queryIntersectsFeature(queryGeometry, feature, featureState, geometry, zoom, transform, pixelsToTileUnits, pixelPosMatrix) {
var translatedPolygon = translate(queryGeometry, this.paint.get('fill-extrusion-translate'), this.paint.get('fill-extrusion-translate-anchor'), transform.angle, pixelsToTileUnits);
var height = this.paint.get('fill-extrusion-height').evaluate(feature, featureState);
var base = this.paint.get('fill-extrusion-base').evaluate(feature, featureState);
var projectedQueryGeometry = projectQueryGeometry$1(translatedPolygon, pixelPosMatrix, transform, 0);
var projected = projectExtrusion(geometry, base, height, pixelPosMatrix);
var projectedBase = projected[0];
var projectedTop = projected[1];
return checkIntersection(projectedBase, projectedTop, projectedQueryGeometry);
};
return FillExtrusionStyleLayer;
}(StyleLayer);
function dot$2(a, b) {
return a.x * b.x + a.y * b.y;
}
function getIntersectionDistance(projectedQueryGeometry, projectedFace) {
if (projectedQueryGeometry.length === 1) {
var i = 0;
var a = projectedFace[i++];
var b;
while (!b || a.equals(b)) {
b = projectedFace[i++];
if (!b) {
return Infinity;
}
}
for (; i < projectedFace.length; i++) {
var c = projectedFace[i];
var p = projectedQueryGeometry[0];
var ab = b.sub(a);
var ac = c.sub(a);
var ap = p.sub(a);
var dotABAB = dot$2(ab, ab);
var dotABAC = dot$2(ab, ac);
var dotACAC = dot$2(ac, ac);
var dotAPAB = dot$2(ap, ab);
var dotAPAC = dot$2(ap, ac);
var denom = dotABAB * dotACAC - dotABAC * dotABAC;
var v = (dotACAC * dotAPAB - dotABAC * dotAPAC) / denom;
var w = (dotABAB * dotAPAC - dotABAC * dotAPAB) / denom;
var u = 1 - v - w;
var distance = a.z * u + b.z * v + c.z * w;
if (isFinite(distance)) {
return distance;
}
}
return Infinity;
} else {
var closestDistance = Infinity;
for (var i$1 = 0, list = projectedFace; i$1 < list.length; i$1 += 1) {
var p$1 = list[i$1];
closestDistance = Math.min(closestDistance, p$1.z);
}
return closestDistance;
}
}
function checkIntersection(projectedBase, projectedTop, projectedQueryGeometry) {
var closestDistance = Infinity;
if (polygonIntersectsMultiPolygon(projectedQueryGeometry, projectedTop)) {
closestDistance = getIntersectionDistance(projectedQueryGeometry, projectedTop[0]);
}
for (var r = 0; r < projectedTop.length; r++) {
var ringTop = projectedTop[r];
var ringBase = projectedBase[r];
for (var p = 0; p < ringTop.length - 1; p++) {
var topA = ringTop[p];
var topB = ringTop[p + 1];
var baseA = ringBase[p];
var baseB = ringBase[p + 1];
var face = [
topA,
topB,
baseB,
baseA,
topA
];
if (polygonIntersectsPolygon(projectedQueryGeometry, face)) {
closestDistance = Math.min(closestDistance, getIntersectionDistance(projectedQueryGeometry, face));
}
}
}
return closestDistance === Infinity ? false : closestDistance;
}
function projectExtrusion(geometry, zBase, zTop, m) {
var projectedBase = [];
var projectedTop = [];
var baseXZ = m[8] * zBase;
var baseYZ = m[9] * zBase;
var baseZZ = m[10] * zBase;
var baseWZ = m[11] * zBase;
var topXZ = m[8] * zTop;
var topYZ = m[9] * zTop;
var topZZ = m[10] * zTop;
var topWZ = m[11] * zTop;
for (var i$1 = 0, list$1 = geometry; i$1 < list$1.length; i$1 += 1) {
var r = list$1[i$1];
var ringBase = [];
var ringTop = [];
for (var i = 0, list = r; i < list.length; i += 1) {
var p = list[i];
var x = p.x;
var y = p.y;
var sX = m[0] * x + m[4] * y + m[12];
var sY = m[1] * x + m[5] * y + m[13];
var sZ = m[2] * x + m[6] * y + m[14];
var sW = m[3] * x + m[7] * y + m[15];
var baseX = sX + baseXZ;
var baseY = sY + baseYZ;
var baseZ = sZ + baseZZ;
var baseW = sW + baseWZ;
var topX = sX + topXZ;
var topY = sY + topYZ;
var topZ = sZ + topZZ;
var topW = sW + topWZ;
var b = new pointGeometry(baseX / baseW, baseY / baseW);
b.z = baseZ / baseW;
ringBase.push(b);
var t = new pointGeometry(topX / topW, topY / topW);
t.z = topZ / topW;
ringTop.push(t);
}
projectedBase.push(ringBase);
projectedTop.push(ringTop);
}
return [
projectedBase,
projectedTop
];
}
function projectQueryGeometry$1(queryGeometry, pixelPosMatrix, transform, z) {
var projectedQueryGeometry = [];
for (var i = 0, list = queryGeometry; i < list.length; i += 1) {
var p = list[i];
var v = [
p.x,
p.y,
z,
1
];
transformMat4(v, v, pixelPosMatrix);
projectedQueryGeometry.push(new pointGeometry(v[0] / v[3], v[1] / v[3]));
}
return projectedQueryGeometry;
}
var lineLayoutAttributes = createLayout([
{
name: 'a_pos_normal',
components: 2,
type: 'Int16'
},
{
name: 'a_data',
components: 4,
type: 'Uint8'
}
], 4);
var members$3 = lineLayoutAttributes.members;
var lineLayoutAttributesExt = createLayout([
{
name: 'a_uv_x',
components: 1,
type: 'Float32'
},
{
name: 'a_split_index',
components: 1,
type: 'Float32'
}
]);
var members$4 = lineLayoutAttributesExt.members;
var vectorTileFeatureTypes$1 = vectorTile.VectorTileFeature.types;
var EXTRUDE_SCALE = 63;
var COS_HALF_SHARP_CORNER = Math.cos(75 / 2 * (Math.PI / 180));
var SHARP_CORNER_OFFSET = 15;
var DEG_PER_TRIANGLE = 20;
var LINE_DISTANCE_BUFFER_BITS = 15;
var LINE_DISTANCE_SCALE = 1 / 2;
var MAX_LINE_DISTANCE = Math.pow(2, LINE_DISTANCE_BUFFER_BITS - 1) / LINE_DISTANCE_SCALE;
var LineBucket = function LineBucket(options) {
var this$1 = this;
this.zoom = options.zoom;
this.overscaling = options.overscaling;
this.layers = options.layers;
this.layerIds = this.layers.map(function (layer) {
return layer.id;
});
this.index = options.index;
this.hasPattern = false;
this.patternFeatures = [];
this.lineClipsArray = [];
this.gradients = {};
this.layers.forEach(function (layer) {
this$1.gradients[layer.id] = {};
});
this.layoutVertexArray = new StructArrayLayout2i4ub8();
this.layoutVertexArray2 = new StructArrayLayout2f8();
this.indexArray = new StructArrayLayout3ui6();
this.programConfigurations = new ProgramConfigurationSet(options.layers, options.zoom);
this.segments = new SegmentVector();
this.maxLineLength = 0;
this.stateDependentLayerIds = this.layers.filter(function (l) {
return l.isStateDependent();
}).map(function (l) {
return l.id;
});
};
LineBucket.prototype.populate = function populate(features, options, canonical) {
this.hasPattern = hasPattern('line', this.layers, options);
var lineSortKey = this.layers[0].layout.get('line-sort-key');
var bucketFeatures = [];
for (var i = 0, list = features; i < list.length; i += 1) {
var ref = list[i];
var feature = ref.feature;
var id = ref.id;
var index = ref.index;
var sourceLayerIndex = ref.sourceLayerIndex;
var needGeometry = this.layers[0]._featureFilter.needGeometry;
var evaluationFeature = toEvaluationFeature(feature, needGeometry);
if (!this.layers[0]._featureFilter.filter(new EvaluationParameters(this.zoom), evaluationFeature, canonical)) {
continue;
}
var sortKey = lineSortKey ? lineSortKey.evaluate(evaluationFeature, {}, canonical) : undefined;
var bucketFeature = {
id: id,
properties: feature.properties,
type: feature.type,
sourceLayerIndex: sourceLayerIndex,
index: index,
geometry: needGeometry ? evaluationFeature.geometry : loadGeometry(feature),
patterns: {},
sortKey: sortKey
};
bucketFeatures.push(bucketFeature);
}
if (lineSortKey) {
bucketFeatures.sort(function (a, b) {
return a.sortKey - b.sortKey;
});
}
for (var i$1 = 0, list$1 = bucketFeatures; i$1 < list$1.length; i$1 += 1) {
var bucketFeature$1 = list$1[i$1];
var ref$1 = bucketFeature$1;
var geometry = ref$1.geometry;
var index$1 = ref$1.index;
var sourceLayerIndex$1 = ref$1.sourceLayerIndex;
if (this.hasPattern) {
var patternBucketFeature = addPatternDependencies('line', this.layers, bucketFeature$1, this.zoom, options);
this.patternFeatures.push(patternBucketFeature);
} else {
this.addFeature(bucketFeature$1, geometry, index$1, canonical, {});
}
var feature$1 = features[index$1].feature;
options.featureIndex.insert(feature$1, geometry, index$1, sourceLayerIndex$1, this.index);
}
};
LineBucket.prototype.update = function update(states, vtLayer, imagePositions) {
if (!this.stateDependentLayers.length) {
return;
}
this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, imagePositions);
};
LineBucket.prototype.addFeatures = function addFeatures(options, canonical, imagePositions) {
for (var i = 0, list = this.patternFeatures; i < list.length; i += 1) {
var feature = list[i];
this.addFeature(feature, feature.geometry, feature.index, canonical, imagePositions);
}
};
LineBucket.prototype.isEmpty = function isEmpty() {
return this.layoutVertexArray.length === 0;
};
LineBucket.prototype.uploadPending = function uploadPending() {
return !this.uploaded || this.programConfigurations.needsUpload;
};
LineBucket.prototype.upload = function upload(context) {
if (!this.uploaded) {
if (this.layoutVertexArray2.length !== 0) {
this.layoutVertexBuffer2 = context.createVertexBuffer(this.layoutVertexArray2, members$4);
}
this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, members$3);
this.indexBuffer = context.createIndexBuffer(this.indexArray);
}
this.programConfigurations.upload(context);
this.uploaded = true;
};
LineBucket.prototype.destroy = function destroy() {
if (!this.layoutVertexBuffer) {
return;
}
this.layoutVertexBuffer.destroy();
this.indexBuffer.destroy();
this.programConfigurations.destroy();
this.segments.destroy();
};
LineBucket.prototype.lineFeatureClips = function lineFeatureClips(feature) {
if (!!feature.properties && feature.properties.hasOwnProperty('mapbox_clip_start') && feature.properties.hasOwnProperty('mapbox_clip_end')) {
var start = +feature.properties['mapbox_clip_start'];
var end = +feature.properties['mapbox_clip_end'];
return {
start: start,
end: end
};
}
};
LineBucket.prototype.addFeature = function addFeature(feature, geometry, index, canonical, imagePositions) {
var layout = this.layers[0].layout;
var join = layout.get('line-join').evaluate(feature, {});
var cap = layout.get('line-cap');
var miterLimit = layout.get('line-miter-limit');
var roundLimit = layout.get('line-round-limit');
this.lineClips = this.lineFeatureClips(feature);
for (var i = 0, list = geometry; i < list.length; i += 1) {
var line = list[i];
this.addLine(line, feature, join, cap, miterLimit, roundLimit);
}
this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, imagePositions, canonical);
};
LineBucket.prototype.addLine = function addLine(vertices, feature, join, cap, miterLimit, roundLimit) {
this.distance = 0;
this.scaledDistance = 0;
this.totalDistance = 0;
if (this.lineClips) {
this.lineClipsArray.push(this.lineClips);
for (var i = 0; i < vertices.length - 1; i++) {
this.totalDistance += vertices[i].dist(vertices[i + 1]);
}
this.updateScaledDistance();
this.maxLineLength = Math.max(this.maxLineLength, this.totalDistance);
}
var isPolygon = vectorTileFeatureTypes$1[feature.type] === 'Polygon';
var len = vertices.length;
while (len >= 2 && vertices[len - 1].equals(vertices[len - 2])) {
len--;
}
var first = 0;
while (first < len - 1 && vertices[first].equals(vertices[first + 1])) {
first++;
}
if (len < (isPolygon ? 3 : 2)) {
return;
}
if (join === 'bevel') {
miterLimit = 1.05;
}
var sharpCornerOffset = this.overscaling <= 16 ? SHARP_CORNER_OFFSET * EXTENT$1 / (512 * this.overscaling) : 0;
var segment = this.segments.prepareSegment(len * 10, this.layoutVertexArray, this.indexArray);
var currentVertex;
var prevVertex = undefined;
var nextVertex = undefined;
var prevNormal = undefined;
var nextNormal = undefined;
this.e1 = this.e2 = -1;
if (isPolygon) {
currentVertex = vertices[len - 2];
nextNormal = vertices[first].sub(currentVertex)._unit()._perp();
}
for (var i$1 = first; i$1 < len; i$1++) {
nextVertex = i$1 === len - 1 ? isPolygon ? vertices[first + 1] : undefined : vertices[i$1 + 1];
if (nextVertex && vertices[i$1].equals(nextVertex)) {
continue;
}
if (nextNormal) {
prevNormal = nextNormal;
}
if (currentVertex) {
prevVertex = currentVertex;
}
currentVertex = vertices[i$1];
nextNormal = nextVertex ? nextVertex.sub(currentVertex)._unit()._perp() : prevNormal;
prevNormal = prevNormal || nextNormal;
var joinNormal = prevNormal.add(nextNormal);
if (joinNormal.x !== 0 || joinNormal.y !== 0) {
joinNormal._unit();
}
var cosAngle = prevNormal.x * nextNormal.x + prevNormal.y * nextNormal.y;
var cosHalfAngle = joinNormal.x * nextNormal.x + joinNormal.y * nextNormal.y;
var miterLength = cosHalfAngle !== 0 ? 1 / cosHalfAngle : Infinity;
var approxAngle = 2 * Math.sqrt(2 - 2 * cosHalfAngle);
var isSharpCorner = cosHalfAngle < COS_HALF_SHARP_CORNER && prevVertex && nextVertex;
var lineTurnsLeft = prevNormal.x * nextNormal.y - prevNormal.y * nextNormal.x > 0;
if (isSharpCorner && i$1 > first) {
var prevSegmentLength = currentVertex.dist(prevVertex);
if (prevSegmentLength > 2 * sharpCornerOffset) {
var newPrevVertex = currentVertex.sub(currentVertex.sub(prevVertex)._mult(sharpCornerOffset / prevSegmentLength)._round());
this.updateDistance(prevVertex, newPrevVertex);
this.addCurrentVertex(newPrevVertex, prevNormal, 0, 0, segment);
prevVertex = newPrevVertex;
}
}
var middleVertex = prevVertex && nextVertex;
var currentJoin = middleVertex ? join : isPolygon ? 'butt' : cap;
if (middleVertex && currentJoin === 'round') {
if (miterLength < roundLimit) {
currentJoin = 'miter';
} else if (miterLength <= 2) {
currentJoin = 'fakeround';
}
}
if (currentJoin === 'miter' && miterLength > miterLimit) {
currentJoin = 'bevel';
}
if (currentJoin === 'bevel') {
if (miterLength > 2) {
currentJoin = 'flipbevel';
}
if (miterLength < miterLimit) {
currentJoin = 'miter';
}
}
if (prevVertex) {
this.updateDistance(prevVertex, currentVertex);
}
if (currentJoin === 'miter') {
joinNormal._mult(miterLength);
this.addCurrentVertex(currentVertex, joinNormal, 0, 0, segment);
} else if (currentJoin === 'flipbevel') {
if (miterLength > 100) {
joinNormal = nextNormal.mult(-1);
} else {
var bevelLength = miterLength * prevNormal.add(nextNormal).mag() / prevNormal.sub(nextNormal).mag();
joinNormal._perp()._mult(bevelLength * (lineTurnsLeft ? -1 : 1));
}
this.addCurrentVertex(currentVertex, joinNormal, 0, 0, segment);
this.addCurrentVertex(currentVertex, joinNormal.mult(-1), 0, 0, segment);
} else if (currentJoin === 'bevel' || currentJoin === 'fakeround') {
var offset = -Math.sqrt(miterLength * miterLength - 1);
var offsetA = lineTurnsLeft ? offset : 0;
var offsetB = lineTurnsLeft ? 0 : offset;
if (prevVertex) {
this.addCurrentVertex(currentVertex, prevNormal, offsetA, offsetB, segment);
}
if (currentJoin === 'fakeround') {
var n = Math.round(approxAngle * 180 / Math.PI / DEG_PER_TRIANGLE);
for (var m = 1; m < n; m++) {
var t = m / n;
if (t !== 0.5) {
var t2 = t - 0.5;
var A = 1.0904 + cosAngle * (-3.2452 + cosAngle * (3.55645 - cosAngle * 1.43519));
var B = 0.848013 + cosAngle * (-1.06021 + cosAngle * 0.215638);
t = t + t * t2 * (t - 1) * (A * t2 * t2 + B);
}
var extrude = nextNormal.sub(prevNormal)._mult(t)._add(prevNormal)._unit()._mult(lineTurnsLeft ? -1 : 1);
this.addHalfVertex(currentVertex, extrude.x, extrude.y, false, lineTurnsLeft, 0, segment);
}
}
if (nextVertex) {
this.addCurrentVertex(currentVertex, nextNormal, -offsetA, -offsetB, segment);
}
} else if (currentJoin === 'butt') {
this.addCurrentVertex(currentVertex, joinNormal, 0, 0, segment);
} else if (currentJoin === 'square') {
var offset$1 = prevVertex ? 1 : -1;
this.addCurrentVertex(currentVertex, joinNormal, offset$1, offset$1, segment);
} else if (currentJoin === 'round') {
if (prevVertex) {
this.addCurrentVertex(currentVertex, prevNormal, 0, 0, segment);
this.addCurrentVertex(currentVertex, prevNormal, 1, 1, segment, true);
}
if (nextVertex) {
this.addCurrentVertex(currentVertex, nextNormal, -1, -1, segment, true);
this.addCurrentVertex(currentVertex, nextNormal, 0, 0, segment);
}
}
if (isSharpCorner && i$1 < len - 1) {
var nextSegmentLength = currentVertex.dist(nextVertex);
if (nextSegmentLength > 2 * sharpCornerOffset) {
var newCurrentVertex = currentVertex.add(nextVertex.sub(currentVertex)._mult(sharpCornerOffset / nextSegmentLength)._round());
this.updateDistance(currentVertex, newCurrentVertex);
this.addCurrentVertex(newCurrentVertex, nextNormal, 0, 0, segment);
currentVertex = newCurrentVertex;
}
}
}
};
LineBucket.prototype.addCurrentVertex = function addCurrentVertex(p, normal, endLeft, endRight, segment, round) {
if (round === void 0)
round = false;
var leftX = normal.x + normal.y * endLeft;
var leftY = normal.y - normal.x * endLeft;
var rightX = -normal.x + normal.y * endRight;
var rightY = -normal.y - normal.x * endRight;
this.addHalfVertex(p, leftX, leftY, round, false, endLeft, segment);
this.addHalfVertex(p, rightX, rightY, round, true, -endRight, segment);
if (this.distance > MAX_LINE_DISTANCE / 2 && this.totalDistance === 0) {
this.distance = 0;
this.addCurrentVertex(p, normal, endLeft, endRight, segment, round);
}
};
LineBucket.prototype.addHalfVertex = function addHalfVertex(ref, extrudeX, extrudeY, round, up, dir, segment) {
var x = ref.x;
var y = ref.y;
var totalDistance = this.lineClips ? this.scaledDistance * (MAX_LINE_DISTANCE - 1) : this.scaledDistance;
var linesofarScaled = totalDistance * LINE_DISTANCE_SCALE;
this.layoutVertexArray.emplaceBack((x << 1) + (round ? 1 : 0), (y << 1) + (up ? 1 : 0), Math.round(EXTRUDE_SCALE * extrudeX) + 128, Math.round(EXTRUDE_SCALE * extrudeY) + 128, (dir === 0 ? 0 : dir < 0 ? -1 : 1) + 1 | (linesofarScaled & 63) << 2, linesofarScaled >> 6);
if (this.lineClips) {
var progressRealigned = this.scaledDistance - this.lineClips.start;
var endClipRealigned = this.lineClips.end - this.lineClips.start;
var uvX = progressRealigned / endClipRealigned;
this.layoutVertexArray2.emplaceBack(uvX, this.lineClipsArray.length);
}
var e = segment.vertexLength++;
if (this.e1 >= 0 && this.e2 >= 0) {
this.indexArray.emplaceBack(this.e1, this.e2, e);
segment.primitiveLength++;
}
if (up) {
this.e2 = e;
} else {
this.e1 = e;
}
};
LineBucket.prototype.updateScaledDistance = function updateScaledDistance() {
this.scaledDistance = this.lineClips ? this.lineClips.start + (this.lineClips.end - this.lineClips.start) * this.distance / this.totalDistance : this.distance;
};
LineBucket.prototype.updateDistance = function updateDistance(prev, next) {
this.distance += prev.dist(next);
this.updateScaledDistance();
};
register('LineBucket', LineBucket, {
omit: [
'layers',
'patternFeatures'
]
});
var layout$6 = new Properties({
'line-cap': new DataConstantProperty(spec['layout_line']['line-cap']),
'line-join': new DataDrivenProperty(spec['layout_line']['line-join']),
'line-miter-limit': new DataConstantProperty(spec['layout_line']['line-miter-limit']),
'line-round-limit': new DataConstantProperty(spec['layout_line']['line-round-limit']),
'line-sort-key': new DataDrivenProperty(spec['layout_line']['line-sort-key'])
});
var paint$6 = new Properties({
'line-opacity': new DataDrivenProperty(spec['paint_line']['line-opacity']),
'line-color': new DataDrivenProperty(spec['paint_line']['line-color']),
'line-translate': new DataConstantProperty(spec['paint_line']['line-translate']),
'line-translate-anchor': new DataConstantProperty(spec['paint_line']['line-translate-anchor']),
'line-width': new DataDrivenProperty(spec['paint_line']['line-width']),
'line-gap-width': new DataDrivenProperty(spec['paint_line']['line-gap-width']),
'line-offset': new DataDrivenProperty(spec['paint_line']['line-offset']),
'line-blur': new DataDrivenProperty(spec['paint_line']['line-blur']),
'line-dasharray': new CrossFadedProperty(spec['paint_line']['line-dasharray']),
'line-pattern': new CrossFadedDataDrivenProperty(spec['paint_line']['line-pattern']),
'line-gradient': new ColorRampProperty(spec['paint_line']['line-gradient'])
});
var properties$5 = {
paint: paint$6,
layout: layout$6
};
var LineFloorwidthProperty = function (DataDrivenProperty) {
function LineFloorwidthProperty() {
DataDrivenProperty.apply(this, arguments);
}
if (DataDrivenProperty)
LineFloorwidthProperty.__proto__ = DataDrivenProperty;
LineFloorwidthProperty.prototype = Object.create(DataDrivenProperty && DataDrivenProperty.prototype);
LineFloorwidthProperty.prototype.constructor = LineFloorwidthProperty;
LineFloorwidthProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters) {
parameters = new EvaluationParameters(Math.floor(parameters.zoom), {
now: parameters.now,
fadeDuration: parameters.fadeDuration,
zoomHistory: parameters.zoomHistory,
transition: parameters.transition
});
return DataDrivenProperty.prototype.possiblyEvaluate.call(this, value, parameters);
};
LineFloorwidthProperty.prototype.evaluate = function evaluate(value, globals, feature, featureState) {
globals = extend({}, globals, { zoom: Math.floor(globals.zoom) });
return DataDrivenProperty.prototype.evaluate.call(this, value, globals, feature, featureState);
};
return LineFloorwidthProperty;
}(DataDrivenProperty);
var lineFloorwidthProperty = new LineFloorwidthProperty(properties$5.paint.properties['line-width'].specification);
lineFloorwidthProperty.useIntegerZoom = true;
var LineStyleLayer = function (StyleLayer) {
function LineStyleLayer(layer) {
StyleLayer.call(this, layer, properties$5);
this.gradientVersion = 0;
}
if (StyleLayer)
LineStyleLayer.__proto__ = StyleLayer;
LineStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
LineStyleLayer.prototype.constructor = LineStyleLayer;
LineStyleLayer.prototype._handleSpecialPaintPropertyUpdate = function _handleSpecialPaintPropertyUpdate(name) {
if (name === 'line-gradient') {
var expression = this._transitionablePaint._values['line-gradient'].value.expression;
this.stepInterpolant = expression._styleExpression.expression instanceof Step;
this.gradientVersion = (this.gradientVersion + 1) % MAX_SAFE_INTEGER;
}
};
LineStyleLayer.prototype.gradientExpression = function gradientExpression() {
return this._transitionablePaint._values['line-gradient'].value.expression;
};
LineStyleLayer.prototype.recalculate = function recalculate(parameters, availableImages) {
StyleLayer.prototype.recalculate.call(this, parameters, availableImages);
this.paint._values['line-floorwidth'] = lineFloorwidthProperty.possiblyEvaluate(this._transitioningPaint._values['line-width'].value, parameters);
};
LineStyleLayer.prototype.createBucket = function createBucket(parameters) {
return new LineBucket(parameters);
};
LineStyleLayer.prototype.queryRadius = function queryRadius(bucket) {
var lineBucket = bucket;
var width = getLineWidth(getMaximumPaintValue('line-width', this, lineBucket), getMaximumPaintValue('line-gap-width', this, lineBucket));
var offset = getMaximumPaintValue('line-offset', this, lineBucket);
return width / 2 + Math.abs(offset) + translateDistance(this.paint.get('line-translate'));
};
LineStyleLayer.prototype.queryIntersectsFeature = function queryIntersectsFeature(queryGeometry, feature, featureState, geometry, zoom, transform, pixelsToTileUnits) {
var translatedPolygon = translate(queryGeometry, this.paint.get('line-translate'), this.paint.get('line-translate-anchor'), transform.angle, pixelsToTileUnits);
var halfWidth = pixelsToTileUnits / 2 * getLineWidth(this.paint.get('line-width').evaluate(feature, featureState), this.paint.get('line-gap-width').evaluate(feature, featureState));
var lineOffset = this.paint.get('line-offset').evaluate(feature, featureState);
if (lineOffset) {
geometry = offsetLine(geometry, lineOffset * pixelsToTileUnits);
}
return polygonIntersectsBufferedMultiLine(translatedPolygon, geometry, halfWidth);
};
LineStyleLayer.prototype.isTileClipped = function isTileClipped() {
return true;
};
return LineStyleLayer;
}(StyleLayer);
function getLineWidth(lineWidth, lineGapWidth) {
if (lineGapWidth > 0) {
return lineGapWidth + 2 * lineWidth;
} else {
return lineWidth;
}
}
function offsetLine(rings, offset) {
var newRings = [];
var zero = new pointGeometry(0, 0);
for (var k = 0; k < rings.length; k++) {
var ring = rings[k];
var newRing = [];
for (var i = 0; i < ring.length; i++) {
var a = ring[i - 1];
var b = ring[i];
var c = ring[i + 1];
var aToB = i === 0 ? zero : b.sub(a)._unit()._perp();
var bToC = i === ring.length - 1 ? zero : c.sub(b)._unit()._perp();
var extrude = aToB._add(bToC)._unit();
var cosHalfAngle = extrude.x * bToC.x + extrude.y * bToC.y;
extrude._mult(1 / cosHalfAngle);
newRing.push(extrude._mult(offset)._add(b));
}
newRings.push(newRing);
}
return newRings;
}
var symbolLayoutAttributes = createLayout([
{
name: 'a_pos_offset',
components: 4,
type: 'Int16'
},
{
name: 'a_data',
components: 4,
type: 'Uint16'
},
{
name: 'a_pixeloffset',
components: 4,
type: 'Int16'
}
], 4);
var dynamicLayoutAttributes = createLayout([{
name: 'a_projected_pos',
components: 3,
type: 'Float32'
}], 4);
var placementOpacityAttributes = createLayout([{
name: 'a_fade_opacity',
components: 1,
type: 'Uint32'
}], 4);
var collisionVertexAttributes = createLayout([
{
name: 'a_placed',
components: 2,
type: 'Uint8'
},
{
name: 'a_shift',
components: 2,
type: 'Float32'
}
]);
var collisionBox = createLayout([
{
type: 'Int16',
name: 'anchorPointX'
},
{
type: 'Int16',
name: 'anchorPointY'
},
{
type: 'Int16',
name: 'x1'
},
{
type: 'Int16',
name: 'y1'
},
{
type: 'Int16',
name: 'x2'
},
{
type: 'Int16',
name: 'y2'
},
{
type: 'Uint32',
name: 'featureIndex'
},
{
type: 'Uint16',
name: 'sourceLayerIndex'
},
{
type: 'Uint16',
name: 'bucketIndex'
}
]);
var collisionBoxLayout = createLayout([
{
name: 'a_pos',
components: 2,
type: 'Int16'
},
{
name: 'a_anchor_pos',
components: 2,
type: 'Int16'
},
{
name: 'a_extrude',
components: 2,
type: 'Int16'
}
], 4);
var collisionCircleLayout = createLayout([
{
name: 'a_pos',
components: 2,
type: 'Float32'
},
{
name: 'a_radius',
components: 1,
type: 'Float32'
},
{
name: 'a_flags',
components: 2,
type: 'Int16'
}
], 4);
var quadTriangle = createLayout([{
name: 'triangle',
components: 3,
type: 'Uint16'
}]);
var placement = createLayout([
{
type: 'Int16',
name: 'anchorX'
},
{
type: 'Int16',
name: 'anchorY'
},
{
type: 'Uint16',
name: 'glyphStartIndex'
},
{
type: 'Uint16',
name: 'numGlyphs'
},
{
type: 'Uint32',
name: 'vertexStartIndex'
},
{
type: 'Uint32',
name: 'lineStartIndex'
},
{
type: 'Uint32',
name: 'lineLength'
},
{
type: 'Uint16',
name: 'segment'
},
{
type: 'Uint16',
name: 'lowerSize'
},
{
type: 'Uint16',
name: 'upperSize'
},
{
type: 'Float32',
name: 'lineOffsetX'
},
{
type: 'Float32',
name: 'lineOffsetY'
},
{
type: 'Uint8',
name: 'writingMode'
},
{
type: 'Uint8',
name: 'placedOrientation'
},
{
type: 'Uint8',
name: 'hidden'
},
{
type: 'Uint32',
name: 'crossTileID'
},
{
type: 'Int16',
name: 'associatedIconIndex'
}
]);
var symbolInstance = createLayout([
{
type: 'Int16',
name: 'anchorX'
},
{
type: 'Int16',
name: 'anchorY'
},
{
type: 'Int16',
name: 'rightJustifiedTextSymbolIndex'
},
{
type: 'Int16',
name: 'centerJustifiedTextSymbolIndex'
},
{
type: 'Int16',
name: 'leftJustifiedTextSymbolIndex'
},
{
type: 'Int16',
name: 'verticalPlacedTextSymbolIndex'
},
{
type: 'Int16',
name: 'placedIconSymbolIndex'
},
{
type: 'Int16',
name: 'verticalPlacedIconSymbolIndex'
},
{
type: 'Uint16',
name: 'key'
},
{
type: 'Uint16',
name: 'textBoxStartIndex'
},
{
type: 'Uint16',
name: 'textBoxEndIndex'
},
{
type: 'Uint16',
name: 'verticalTextBoxStartIndex'
},
{
type: 'Uint16',
name: 'verticalTextBoxEndIndex'
},
{
type: 'Uint16',
name: 'iconBoxStartIndex'
},
{
type: 'Uint16',
name: 'iconBoxEndIndex'
},
{
type: 'Uint16',
name: 'verticalIconBoxStartIndex'
},
{
type: 'Uint16',
name: 'verticalIconBoxEndIndex'
},
{
type: 'Uint16',
name: 'featureIndex'
},
{
type: 'Uint16',
name: 'numHorizontalGlyphVertices'
},
{
type: 'Uint16',
name: 'numVerticalGlyphVertices'
},
{
type: 'Uint16',
name: 'numIconVertices'
},
{
type: 'Uint16',
name: 'numVerticalIconVertices'
},
{
type: 'Uint16',
name: 'useRuntimeCollisionCircles'
},
{
type: 'Uint32',
name: 'crossTileID'
},
{
type: 'Float32',
name: 'textBoxScale'
},
{
type: 'Float32',
components: 2,
name: 'textOffset'
},
{
type: 'Float32',
name: 'collisionCircleDiameter'
}
]);
var glyphOffset = createLayout([{
type: 'Float32',
name: 'offsetX'
}]);
var lineVertex = createLayout([
{
type: 'Int16',
name: 'x'
},
{
type: 'Int16',
name: 'y'
},
{
type: 'Int16',
name: 'tileUnitDistanceFromAnchor'
}
]);
function transformText(text, layer, feature) {
var transform = layer.layout.get('text-transform').evaluate(feature, {});
if (transform === 'uppercase') {
text = text.toLocaleUpperCase();
} else if (transform === 'lowercase') {
text = text.toLocaleLowerCase();
}
if (plugin.applyArabicShaping) {
text = plugin.applyArabicShaping(text);
}
return text;
}
function transformText$1 (text, layer, feature) {
text.sections.forEach(function (section) {
section.text = transformText(section.text, layer, feature);
});
return text;
}
function mergeLines (features) {
var leftIndex = {};
var rightIndex = {};
var mergedFeatures = [];
var mergedIndex = 0;
function add(k) {
mergedFeatures.push(features[k]);
mergedIndex++;
}
function mergeFromRight(leftKey, rightKey, geom) {
var i = rightIndex[leftKey];
delete rightIndex[leftKey];
rightIndex[rightKey] = i;
mergedFeatures[i].geometry[0].pop();
mergedFeatures[i].geometry[0] = mergedFeatures[i].geometry[0].concat(geom[0]);
return i;
}
function mergeFromLeft(leftKey, rightKey, geom) {
var i = leftIndex[rightKey];
delete leftIndex[rightKey];
leftIndex[leftKey] = i;
mergedFeatures[i].geometry[0].shift();
mergedFeatures[i].geometry[0] = geom[0].concat(mergedFeatures[i].geometry[0]);
return i;
}
function getKey(text, geom, onRight) {
var point = onRight ? geom[0][geom[0].length - 1] : geom[0][0];
return text + ':' + point.x + ':' + point.y;
}
for (var k = 0; k < features.length; k++) {
var feature = features[k];
var geom = feature.geometry;
var text = feature.text ? feature.text.toString() : null;
if (!text) {
add(k);
continue;
}
var leftKey = getKey(text, geom), rightKey = getKey(text, geom, true);
if (leftKey in rightIndex && rightKey in leftIndex && rightIndex[leftKey] !== leftIndex[rightKey]) {
var j = mergeFromLeft(leftKey, rightKey, geom);
var i = mergeFromRight(leftKey, rightKey, mergedFeatures[j].geometry);
delete leftIndex[leftKey];
delete rightIndex[rightKey];
rightIndex[getKey(text, mergedFeatures[i].geometry, true)] = i;
mergedFeatures[j].geometry = null;
} else if (leftKey in rightIndex) {
mergeFromRight(leftKey, rightKey, geom);
} else if (rightKey in leftIndex) {
mergeFromLeft(leftKey, rightKey, geom);
} else {
add(k);
leftIndex[leftKey] = mergedIndex - 1;
rightIndex[rightKey] = mergedIndex - 1;
}
}
return mergedFeatures.filter(function (f) {
return f.geometry;
});
}
var verticalizedCharacterMap = {
'!': '\uFE15',
'#': '\uFF03',
'$': '\uFF04',
'%': '\uFF05',
'&': '\uFF06',
'(': '\uFE35',
')': '\uFE36',
'*': '\uFF0A',
'+': '\uFF0B',
',': '\uFE10',
'-': '\uFE32',
'.': '\u30FB',
'/': '\uFF0F',
':': '\uFE13',
';': '\uFE14',
'<': '\uFE3F',
'=': '\uFF1D',
'>': '\uFE40',
'?': '\uFE16',
'@': '\uFF20',
'[': '\uFE47',
'\\': '\uFF3C',
']': '\uFE48',
'^': '\uFF3E',
'_': '︳',
'`': '\uFF40',
'{': '\uFE37',
'|': '\u2015',
'}': '\uFE38',
'~': '\uFF5E',
'\xA2': '\uFFE0',
'\xA3': '\uFFE1',
'\xA5': '\uFFE5',
'\xA6': '\uFFE4',
'\xAC': '\uFFE2',
'\xAF': '\uFFE3',
'\u2013': '\uFE32',
'\u2014': '\uFE31',
'\u2018': '\uFE43',
'\u2019': '\uFE44',
'\u201C': '\uFE41',
'\u201D': '\uFE42',
'\u2026': '\uFE19',
'\u2027': '\u30FB',
'\u20A9': '\uFFE6',
'\u3001': '\uFE11',
'\u3002': '\uFE12',
'\u3008': '\uFE3F',
'\u3009': '\uFE40',
'\u300A': '\uFE3D',
'\u300B': '\uFE3E',
'\u300C': '\uFE41',
'\u300D': '\uFE42',
'\u300E': '\uFE43',
'\u300F': '\uFE44',
'\u3010': '\uFE3B',
'\u3011': '\uFE3C',
'\u3014': '\uFE39',
'\u3015': '\uFE3A',
'\u3016': '\uFE17',
'\u3017': '\uFE18',
'\uFF01': '\uFE15',
'\uFF08': '\uFE35',
'\uFF09': '\uFE36',
'\uFF0C': '\uFE10',
'\uFF0D': '\uFE32',
'\uFF0E': '\u30FB',
'\uFF1A': '\uFE13',
'\uFF1B': '\uFE14',
'\uFF1C': '\uFE3F',
'\uFF1E': '\uFE40',
'\uFF1F': '\uFE16',
'\uFF3B': '\uFE47',
'\uFF3D': '\uFE48',
'_': '︳',
'\uFF5B': '\uFE37',
'\uFF5C': '\u2015',
'\uFF5D': '\uFE38',
'\uFF5F': '\uFE35',
'\uFF60': '\uFE36',
'\uFF61': '\uFE12',
'\uFF62': '\uFE41',
'\uFF63': '\uFE42'
};
function verticalizePunctuation(input) {
var output = '';
for (var i = 0; i < input.length; i++) {
var nextCharCode = input.charCodeAt(i + 1) || null;
var prevCharCode = input.charCodeAt(i - 1) || null;
var canReplacePunctuation = (!nextCharCode || !charHasRotatedVerticalOrientation(nextCharCode) || verticalizedCharacterMap[input[i + 1]]) && (!prevCharCode || !charHasRotatedVerticalOrientation(prevCharCode) || verticalizedCharacterMap[input[i - 1]]);
if (canReplacePunctuation && verticalizedCharacterMap[input[i]]) {
output += verticalizedCharacterMap[input[i]];
} else {
output += input[i];
}
}
return output;
}
var ONE_EM = 24;
var read = function (buffer, offset, isLE, mLen, nBytes) {
var e, m;
var eLen = nBytes * 8 - mLen - 1;
var eMax = (1 << eLen) - 1;
var eBias = eMax >> 1;
var nBits = -7;
var i = isLE ? nBytes - 1 : 0;
var d = isLE ? -1 : 1;
var s = buffer[offset + i];
i += d;
e = s & (1 << -nBits) - 1;
s >>= -nBits;
nBits += eLen;
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {
}
m = e & (1 << -nBits) - 1;
e >>= -nBits;
nBits += mLen;
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {
}
if (e === 0) {
e = 1 - eBias;
} else if (e === eMax) {
return m ? NaN : (s ? -1 : 1) * Infinity;
} else {
m = m + Math.pow(2, mLen);
e = e - eBias;
}
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
};
var write = function (buffer, value, offset, isLE, mLen, nBytes) {
var e, m, c;
var eLen = nBytes * 8 - mLen - 1;
var eMax = (1 << eLen) - 1;
var eBias = eMax >> 1;
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
var i = isLE ? 0 : nBytes - 1;
var d = isLE ? 1 : -1;
var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
value = Math.abs(value);
if (isNaN(value) || value === Infinity) {
m = isNaN(value) ? 1 : 0;
e = eMax;
} else {
e = Math.floor(Math.log(value) / Math.LN2);
if (value * (c = Math.pow(2, -e)) < 1) {
e--;
c *= 2;
}
if (e + eBias >= 1) {
value += rt / c;
} else {
value += rt * Math.pow(2, 1 - eBias);
}
if (value * c >= 2) {
e++;
c /= 2;
}
if (e + eBias >= eMax) {
m = 0;
e = eMax;
} else if (e + eBias >= 1) {
m = (value * c - 1) * Math.pow(2, mLen);
e = e + eBias;
} else {
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen);
e = 0;
}
}
for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) {
}
e = e << mLen | m;
eLen += mLen;
for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) {
}
buffer[offset + i - d] |= s * 128;
};
var ieee754 = {
read: read,
write: write
};
var pbf = Pbf;
function Pbf(buf) {
this.buf = ArrayBuffer.isView && ArrayBuffer.isView(buf) ? buf : new Uint8Array(buf || 0);
this.pos = 0;
this.type = 0;
this.length = this.buf.length;
}
Pbf.Varint = 0;
Pbf.Fixed64 = 1;
Pbf.Bytes = 2;
Pbf.Fixed32 = 5;
var SHIFT_LEFT_32 = (1 << 16) * (1 << 16), SHIFT_RIGHT_32 = 1 / SHIFT_LEFT_32;
var TEXT_DECODER_MIN_LENGTH = 12;
var utf8TextDecoder = typeof TextDecoder === 'undefined' ? null : new TextDecoder('utf8');
Pbf.prototype = {
destroy: function () {
this.buf = null;
},
readFields: function (readField, result, end) {
end = end || this.length;
while (this.pos < end) {
var val = this.readVarint(), tag = val >> 3, startPos = this.pos;
this.type = val & 7;
readField(tag, result, this);
if (this.pos === startPos) {
this.skip(val);
}
}
return result;
},
readMessage: function (readField, result) {
return this.readFields(readField, result, this.readVarint() + this.pos);
},
readFixed32: function () {
var val = readUInt32(this.buf, this.pos);
this.pos += 4;
return val;
},
readSFixed32: function () {
var val = readInt32(this.buf, this.pos);
this.pos += 4;
return val;
},
readFixed64: function () {
var val = readUInt32(this.buf, this.pos) + readUInt32(this.buf, this.pos + 4) * SHIFT_LEFT_32;
this.pos += 8;
return val;
},
readSFixed64: function () {
var val = readUInt32(this.buf, this.pos) + readInt32(this.buf, this.pos + 4) * SHIFT_LEFT_32;
this.pos += 8;
return val;
},
readFloat: function () {
var val = ieee754.read(this.buf, this.pos, true, 23, 4);
this.pos += 4;
return val;
},
readDouble: function () {
var val = ieee754.read(this.buf, this.pos, true, 52, 8);
this.pos += 8;
return val;
},
readVarint: function (isSigned) {
var buf = this.buf, val, b;
b = buf[this.pos++];
val = b & 127;
if (b < 128) {
return val;
}
b = buf[this.pos++];
val |= (b & 127) << 7;
if (b < 128) {
return val;
}
b = buf[this.pos++];
val |= (b & 127) << 14;
if (b < 128) {
return val;
}
b = buf[this.pos++];
val |= (b & 127) << 21;
if (b < 128) {
return val;
}
b = buf[this.pos];
val |= (b & 15) << 28;
return readVarintRemainder(val, isSigned, this);
},
readVarint64: function () {
return this.readVarint(true);
},
readSVarint: function () {
var num = this.readVarint();
return num % 2 === 1 ? (num + 1) / -2 : num / 2;
},
readBoolean: function () {
return Boolean(this.readVarint());
},
readString: function () {
var end = this.readVarint() + this.pos;
var pos = this.pos;
this.pos = end;
if (end - pos >= TEXT_DECODER_MIN_LENGTH && utf8TextDecoder) {
return readUtf8TextDecoder(this.buf, pos, end);
}
return readUtf8(this.buf, pos, end);
},
readBytes: function () {
var end = this.readVarint() + this.pos, buffer = this.buf.subarray(this.pos, end);
this.pos = end;
return buffer;
},
readPackedVarint: function (arr, isSigned) {
if (this.type !== Pbf.Bytes) {
return arr.push(this.readVarint(isSigned));
}
var end = readPackedEnd(this);
arr = arr || [];
while (this.pos < end) {
arr.push(this.readVarint(isSigned));
}
return arr;
},
readPackedSVarint: function (arr) {
if (this.type !== Pbf.Bytes) {
return arr.push(this.readSVarint());
}
var end = readPackedEnd(this);
arr = arr || [];
while (this.pos < end) {
arr.push(this.readSVarint());
}
return arr;
},
readPackedBoolean: function (arr) {
if (this.type !== Pbf.Bytes) {
return arr.push(this.readBoolean());
}
var end = readPackedEnd(this);
arr = arr || [];
while (this.pos < end) {
arr.push(this.readBoolean());
}
return arr;
},
readPackedFloat: function (arr) {
if (this.type !== Pbf.Bytes) {
return arr.push(this.readFloat());
}
var end = readPackedEnd(this);
arr = arr || [];
while (this.pos < end) {
arr.push(this.readFloat());
}
return arr;
},
readPackedDouble: function (arr) {
if (this.type !== Pbf.Bytes) {
return arr.push(this.readDouble());
}
var end = readPackedEnd(this);
arr = arr || [];
while (this.pos < end) {
arr.push(this.readDouble());
}
return arr;
},
readPackedFixed32: function (arr) {
if (this.type !== Pbf.Bytes) {
return arr.push(this.readFixed32());
}
var end = readPackedEnd(this);
arr = arr || [];
while (this.pos < end) {
arr.push(this.readFixed32());
}
return arr;
},
readPackedSFixed32: function (arr) {
if (this.type !== Pbf.Bytes) {
return arr.push(this.readSFixed32());
}
var end = readPackedEnd(this);
arr = arr || [];
while (this.pos < end) {
arr.push(this.readSFixed32());
}
return arr;
},
readPackedFixed64: function (arr) {
if (this.type !== Pbf.Bytes) {
return arr.push(this.readFixed64());
}
var end = readPackedEnd(this);
arr = arr || [];
while (this.pos < end) {
arr.push(this.readFixed64());
}
return arr;
},
readPackedSFixed64: function (arr) {
if (this.type !== Pbf.Bytes) {
return arr.push(this.readSFixed64());
}
var end = readPackedEnd(this);
arr = arr || [];
while (this.pos < end) {
arr.push(this.readSFixed64());
}
return arr;
},
skip: function (val) {
var type = val & 7;
if (type === Pbf.Varint) {
while (this.buf[this.pos++] > 127) {
}
} else if (type === Pbf.Bytes) {
this.pos = this.readVarint() + this.pos;
} else if (type === Pbf.Fixed32) {
this.pos += 4;
} else if (type === Pbf.Fixed64) {
this.pos += 8;
} else {
throw new Error('Unimplemented type: ' + type);
}
},
writeTag: function (tag, type) {
this.writeVarint(tag << 3 | type);
},
realloc: function (min) {
var length = this.length || 16;
while (length < this.pos + min) {
length *= 2;
}
if (length !== this.length) {
var buf = new Uint8Array(length);
buf.set(this.buf);
this.buf = buf;
this.length = length;
}
},
finish: function () {
this.length = this.pos;
this.pos = 0;
return this.buf.subarray(0, this.length);
},
writeFixed32: function (val) {
this.realloc(4);
writeInt32(this.buf, val, this.pos);
this.pos += 4;
},
writeSFixed32: function (val) {
this.realloc(4);
writeInt32(this.buf, val, this.pos);
this.pos += 4;
},
writeFixed64: function (val) {
this.realloc(8);
writeInt32(this.buf, val & -1, this.pos);
writeInt32(this.buf, Math.floor(val * SHIFT_RIGHT_32), this.pos + 4);
this.pos += 8;
},
writeSFixed64: function (val) {
this.realloc(8);
writeInt32(this.buf, val & -1, this.pos);
writeInt32(this.buf, Math.floor(val * SHIFT_RIGHT_32), this.pos + 4);
this.pos += 8;
},
writeVarint: function (val) {
val = +val || 0;
if (val > 268435455 || val < 0) {
writeBigVarint(val, this);
return;
}
this.realloc(4);
this.buf[this.pos++] = val & 127 | (val > 127 ? 128 : 0);
if (val <= 127) {
return;
}
this.buf[this.pos++] = (val >>>= 7) & 127 | (val > 127 ? 128 : 0);
if (val <= 127) {
return;
}
this.buf[this.pos++] = (val >>>= 7) & 127 | (val > 127 ? 128 : 0);
if (val <= 127) {
return;
}
this.buf[this.pos++] = val >>> 7 & 127;
},
writeSVarint: function (val) {
this.writeVarint(val < 0 ? -val * 2 - 1 : val * 2);
},
writeBoolean: function (val) {
this.writeVarint(Boolean(val));
},
writeString: function (str) {
str = String(str);
this.realloc(str.length * 4);
this.pos++;
var startPos = this.pos;
this.pos = writeUtf8(this.buf, str, this.pos);
var len = this.pos - startPos;
if (len >= 128) {
makeRoomForExtraLength(startPos, len, this);
}
this.pos = startPos - 1;
this.writeVarint(len);
this.pos += len;
},
writeFloat: function (val) {
this.realloc(4);
ieee754.write(this.buf, val, this.pos, true, 23, 4);
this.pos += 4;
},
writeDouble: function (val) {
this.realloc(8);
ieee754.write(this.buf, val, this.pos, true, 52, 8);
this.pos += 8;
},
writeBytes: function (buffer) {
var len = buffer.length;
this.writeVarint(len);
this.realloc(len);
for (var i = 0; i < len; i++) {
this.buf[this.pos++] = buffer[i];
}
},
writeRawMessage: function (fn, obj) {
this.pos++;
var startPos = this.pos;
fn(obj, this);
var len = this.pos - startPos;
if (len >= 128) {
makeRoomForExtraLength(startPos, len, this);
}
this.pos = startPos - 1;
this.writeVarint(len);
this.pos += len;
},
writeMessage: function (tag, fn, obj) {
this.writeTag(tag, Pbf.Bytes);
this.writeRawMessage(fn, obj);
},
writePackedVarint: function (tag, arr) {
if (arr.length) {
this.writeMessage(tag, writePackedVarint, arr);
}
},
writePackedSVarint: function (tag, arr) {
if (arr.length) {
this.writeMessage(tag, writePackedSVarint, arr);
}
},
writePackedBoolean: function (tag, arr) {
if (arr.length) {
this.writeMessage(tag, writePackedBoolean, arr);
}
},
writePackedFloat: function (tag, arr) {
if (arr.length) {
this.writeMessage(tag, writePackedFloat, arr);
}
},
writePackedDouble: function (tag, arr) {
if (arr.length) {
this.writeMessage(tag, writePackedDouble, arr);
}
},
writePackedFixed32: function (tag, arr) {
if (arr.length) {
this.writeMessage(tag, writePackedFixed32, arr);
}
},
writePackedSFixed32: function (tag, arr) {
if (arr.length) {
this.writeMessage(tag, writePackedSFixed32, arr);
}
},
writePackedFixed64: function (tag, arr) {
if (arr.length) {
this.writeMessage(tag, writePackedFixed64, arr);
}
},
writePackedSFixed64: function (tag, arr) {
if (arr.length) {
this.writeMessage(tag, writePackedSFixed64, arr);
}
},
writeBytesField: function (tag, buffer) {
this.writeTag(tag, Pbf.Bytes);
this.writeBytes(buffer);
},
writeFixed32Field: function (tag, val) {
this.writeTag(tag, Pbf.Fixed32);
this.writeFixed32(val);
},
writeSFixed32Field: function (tag, val) {
this.writeTag(tag, Pbf.Fixed32);
this.writeSFixed32(val);
},
writeFixed64Field: function (tag, val) {
this.writeTag(tag, Pbf.Fixed64);
this.writeFixed64(val);
},
writeSFixed64Field: function (tag, val) {
this.writeTag(tag, Pbf.Fixed64);
this.writeSFixed64(val);
},
writeVarintField: function (tag, val) {
this.writeTag(tag, Pbf.Varint);
this.writeVarint(val);
},
writeSVarintField: function (tag, val) {
this.writeTag(tag, Pbf.Varint);
this.writeSVarint(val);
},
writeStringField: function (tag, str) {
this.writeTag(tag, Pbf.Bytes);
this.writeString(str);
},
writeFloatField: function (tag, val) {
this.writeTag(tag, Pbf.Fixed32);
this.writeFloat(val);
},
writeDoubleField: function (tag, val) {
this.writeTag(tag, Pbf.Fixed64);
this.writeDouble(val);
},
writeBooleanField: function (tag, val) {
this.writeVarintField(tag, Boolean(val));
}
};
function readVarintRemainder(l, s, p) {
var buf = p.buf, h, b;
b = buf[p.pos++];
h = (b & 112) >> 4;
if (b < 128) {
return toNum(l, h, s);
}
b = buf[p.pos++];
h |= (b & 127) << 3;
if (b < 128) {
return toNum(l, h, s);
}
b = buf[p.pos++];
h |= (b & 127) << 10;
if (b < 128) {
return toNum(l, h, s);
}
b = buf[p.pos++];
h |= (b & 127) << 17;
if (b < 128) {
return toNum(l, h, s);
}
b = buf[p.pos++];
h |= (b & 127) << 24;
if (b < 128) {
return toNum(l, h, s);
}
b = buf[p.pos++];
h |= (b & 1) << 31;
if (b < 128) {
return toNum(l, h, s);
}
throw new Error('Expected varint not more than 10 bytes');
}
function readPackedEnd(pbf) {
return pbf.type === Pbf.Bytes ? pbf.readVarint() + pbf.pos : pbf.pos + 1;
}
function toNum(low, high, isSigned) {
if (isSigned) {
return high * 4294967296 + (low >>> 0);
}
return (high >>> 0) * 4294967296 + (low >>> 0);
}
function writeBigVarint(val, pbf) {
var low, high;
if (val >= 0) {
low = val % 4294967296 | 0;
high = val / 4294967296 | 0;
} else {
low = ~(-val % 4294967296);
high = ~(-val / 4294967296);
if (low ^ 4294967295) {
low = low + 1 | 0;
} else {
low = 0;
high = high + 1 | 0;
}
}
if (val >= 18446744073709552000 || val < -18446744073709552000) {
throw new Error('Given varint doesn\'t fit into 10 bytes');
}
pbf.realloc(10);
writeBigVarintLow(low, high, pbf);
writeBigVarintHigh(high, pbf);
}
function writeBigVarintLow(low, high, pbf) {
pbf.buf[pbf.pos++] = low & 127 | 128;
low >>>= 7;
pbf.buf[pbf.pos++] = low & 127 | 128;
low >>>= 7;
pbf.buf[pbf.pos++] = low & 127 | 128;
low >>>= 7;
pbf.buf[pbf.pos++] = low & 127 | 128;
low >>>= 7;
pbf.buf[pbf.pos] = low & 127;
}
function writeBigVarintHigh(high, pbf) {
var lsb = (high & 7) << 4;
pbf.buf[pbf.pos++] |= lsb | ((high >>>= 3) ? 128 : 0);
if (!high) {
return;
}
pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0);
if (!high) {
return;
}
pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0);
if (!high) {
return;
}
pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0);
if (!high) {
return;
}
pbf.buf[pbf.pos++] = high & 127 | ((high >>>= 7) ? 128 : 0);
if (!high) {
return;
}
pbf.buf[pbf.pos++] = high & 127;
}
function makeRoomForExtraLength(startPos, len, pbf) {
var extraLen = len <= 16383 ? 1 : len <= 2097151 ? 2 : len <= 268435455 ? 3 : Math.floor(Math.log(len) / (Math.LN2 * 7));
pbf.realloc(extraLen);
for (var i = pbf.pos - 1; i >= startPos; i--) {
pbf.buf[i + extraLen] = pbf.buf[i];
}
}
function writePackedVarint(arr, pbf) {
for (var i = 0; i < arr.length; i++) {
pbf.writeVarint(arr[i]);
}
}
function writePackedSVarint(arr, pbf) {
for (var i = 0; i < arr.length; i++) {
pbf.writeSVarint(arr[i]);
}
}
function writePackedFloat(arr, pbf) {
for (var i = 0; i < arr.length; i++) {
pbf.writeFloat(arr[i]);
}
}
function writePackedDouble(arr, pbf) {
for (var i = 0; i < arr.length; i++) {
pbf.writeDouble(arr[i]);
}
}
function writePackedBoolean(arr, pbf) {
for (var i = 0; i < arr.length; i++) {
pbf.writeBoolean(arr[i]);
}
}
function writePackedFixed32(arr, pbf) {
for (var i = 0; i < arr.length; i++) {
pbf.writeFixed32(arr[i]);
}
}
function writePackedSFixed32(arr, pbf) {
for (var i = 0; i < arr.length; i++) {
pbf.writeSFixed32(arr[i]);
}
}
function writePackedFixed64(arr, pbf) {
for (var i = 0; i < arr.length; i++) {
pbf.writeFixed64(arr[i]);
}
}
function writePackedSFixed64(arr, pbf) {
for (var i = 0; i < arr.length; i++) {
pbf.writeSFixed64(arr[i]);
}
}
function readUInt32(buf, pos) {
return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + buf[pos + 3] * 16777216;
}
function writeInt32(buf, val, pos) {
buf[pos] = val;
buf[pos + 1] = val >>> 8;
buf[pos + 2] = val >>> 16;
buf[pos + 3] = val >>> 24;
}
function readInt32(buf, pos) {
return (buf[pos] | buf[pos + 1] << 8 | buf[pos + 2] << 16) + (buf[pos + 3] << 24);
}
function readUtf8(buf, pos, end) {
var str = '';
var i = pos;
while (i < end) {
var b0 = buf[i];
var c = null;
var bytesPerSequence = b0 > 239 ? 4 : b0 > 223 ? 3 : b0 > 191 ? 2 : 1;
if (i + bytesPerSequence > end) {
break;
}
var b1, b2, b3;
if (bytesPerSequence === 1) {
if (b0 < 128) {
c = b0;
}
} else if (bytesPerSequence === 2) {
b1 = buf[i + 1];
if ((b1 & 192) === 128) {
c = (b0 & 31) << 6 | b1 & 63;
if (c <= 127) {
c = null;
}
}
} else if (bytesPerSequence === 3) {
b1 = buf[i + 1];
b2 = buf[i + 2];
if ((b1 & 192) === 128 && (b2 & 192) === 128) {
c = (b0 & 15) << 12 | (b1 & 63) << 6 | b2 & 63;
if (c <= 2047 || c >= 55296 && c <= 57343) {
c = null;
}
}
} else if (bytesPerSequence === 4) {
b1 = buf[i + 1];
b2 = buf[i + 2];
b3 = buf[i + 3];
if ((b1 & 192) === 128 && (b2 & 192) === 128 && (b3 & 192) === 128) {
c = (b0 & 15) << 18 | (b1 & 63) << 12 | (b2 & 63) << 6 | b3 & 63;
if (c <= 65535 || c >= 1114112) {
c = null;
}
}
}
if (c === null) {
c = 65533;
bytesPerSequence = 1;
} else if (c > 65535) {
c -= 65536;
str += String.fromCharCode(c >>> 10 & 1023 | 55296);
c = 56320 | c & 1023;
}
str += String.fromCharCode(c);
i += bytesPerSequence;
}
return str;
}
function readUtf8TextDecoder(buf, pos, end) {
return utf8TextDecoder.decode(buf.subarray(pos, end));
}
function writeUtf8(buf, str, pos) {
for (var i = 0, c, lead; i < str.length; i++) {
c = str.charCodeAt(i);
if (c > 55295 && c < 57344) {
if (lead) {
if (c < 56320) {
buf[pos++] = 239;
buf[pos++] = 191;
buf[pos++] = 189;
lead = c;
continue;
} else {
c = lead - 55296 << 10 | c - 56320 | 65536;
lead = null;
}
} else {
if (c > 56319 || i + 1 === str.length) {
buf[pos++] = 239;
buf[pos++] = 191;
buf[pos++] = 189;
} else {
lead = c;
}
continue;
}
} else if (lead) {
buf[pos++] = 239;
buf[pos++] = 191;
buf[pos++] = 189;
lead = null;
}
if (c < 128) {
buf[pos++] = c;
} else {
if (c < 2048) {
buf[pos++] = c >> 6 | 192;
} else {
if (c < 65536) {
buf[pos++] = c >> 12 | 224;
} else {
buf[pos++] = c >> 18 | 240;
buf[pos++] = c >> 12 & 63 | 128;
}
buf[pos++] = c >> 6 & 63 | 128;
}
buf[pos++] = c & 63 | 128;
}
}
return pos;
}
var border = 3;
function readFontstacks(tag, glyphs, pbf) {
if (tag === 1) {
pbf.readMessage(readFontstack, glyphs);
}
}
function readFontstack(tag, glyphs, pbf) {
if (tag === 3) {
var ref = pbf.readMessage(readGlyph, {});
var id = ref.id;
var bitmap = ref.bitmap;
var width = ref.width;
var height = ref.height;
var left = ref.left;
var top = ref.top;
var advance = ref.advance;
glyphs.push({
id: id,
bitmap: new AlphaImage({
width: width + 2 * border,
height: height + 2 * border
}, bitmap),
metrics: {
width: width,
height: height,
left: left,
top: top,
advance: advance
}
});
}
}
function readGlyph(tag, glyph, pbf) {
if (tag === 1) {
glyph.id = pbf.readVarint();
} else if (tag === 2) {
glyph.bitmap = pbf.readBytes();
} else if (tag === 3) {
glyph.width = pbf.readVarint();
} else if (tag === 4) {
glyph.height = pbf.readVarint();
} else if (tag === 5) {
glyph.left = pbf.readSVarint();
} else if (tag === 6) {
glyph.top = pbf.readSVarint();
} else if (tag === 7) {
glyph.advance = pbf.readVarint();
}
}
function parseGlyphPBF (data) {
return new pbf(data).readFields(readFontstacks, []);
}
var GLYPH_PBF_BORDER = border;
function potpack(boxes) {
// calculate total box area and maximum box width
var area = 0;
var maxWidth = 0;
for (var i$1 = 0, list = boxes; i$1 < list.length; i$1 += 1) {
var box = list[i$1];
area += box.w * box.h;
maxWidth = Math.max(maxWidth, box.w);
}
// sort the boxes for insertion by height, descending
boxes.sort(function (a, b) { return b.h - a.h; });
// aim for a squarish resulting container,
// slightly adjusted for sub-100% space utilization
var startWidth = Math.max(Math.ceil(Math.sqrt(area / 0.95)), maxWidth);
// start with a single empty space, unbounded at the bottom
var spaces = [{x: 0, y: 0, w: startWidth, h: Infinity}];
var width = 0;
var height = 0;
for (var i$2 = 0, list$1 = boxes; i$2 < list$1.length; i$2 += 1) {
// look through spaces backwards so that we check smaller spaces first
var box$1 = list$1[i$2];
for (var i = spaces.length - 1; i >= 0; i--) {
var space = spaces[i];
// look for empty spaces that can accommodate the current box
if (box$1.w > space.w || box$1.h > space.h) { continue; }
// found the space; add the box to its top-left corner
// |-------|-------|
// | box | |
// |_______| |
// | space |
// |_______________|
box$1.x = space.x;
box$1.y = space.y;
height = Math.max(height, box$1.y + box$1.h);
width = Math.max(width, box$1.x + box$1.w);
if (box$1.w === space.w && box$1.h === space.h) {
// space matches the box exactly; remove it
var last = spaces.pop();
if (i < spaces.length) { spaces[i] = last; }
} else if (box$1.h === space.h) {
// space matches the box height; update it accordingly
// |-------|---------------|
// | box | updated space |
// |_______|_______________|
space.x += box$1.w;
space.w -= box$1.w;
} else if (box$1.w === space.w) {
// space matches the box width; update it accordingly
// |---------------|
// | box |
// |_______________|
// | updated space |
// |_______________|
space.y += box$1.h;
space.h -= box$1.h;
} else {
// otherwise the box splits the space into two spaces
// |-------|-----------|
// | box | new space |
// |_______|___________|
// | updated space |
// |___________________|
spaces.push({
x: space.x + box$1.w,
y: space.y,
w: space.w - box$1.w,
h: box$1.h
});
space.y += box$1.h;
space.h -= box$1.h;
}
break;
}
}
return {
w: width, // container width
h: height, // container height
fill: (area / (width * height)) || 0 // space utilization
};
}
var IMAGE_PADDING = 1;
var ImagePosition = function ImagePosition(paddedRect, ref) {
var pixelRatio = ref.pixelRatio;
var version = ref.version;
var stretchX = ref.stretchX;
var stretchY = ref.stretchY;
var content = ref.content;
this.paddedRect = paddedRect;
this.pixelRatio = pixelRatio;
this.stretchX = stretchX;
this.stretchY = stretchY;
this.content = content;
this.version = version;
};
var prototypeAccessors = {
tl: { configurable: true },
br: { configurable: true },
tlbr: { configurable: true },
displaySize: { configurable: true }
};
prototypeAccessors.tl.get = function () {
return [
this.paddedRect.x + IMAGE_PADDING,
this.paddedRect.y + IMAGE_PADDING
];
};
prototypeAccessors.br.get = function () {
return [
this.paddedRect.x + this.paddedRect.w - IMAGE_PADDING,
this.paddedRect.y + this.paddedRect.h - IMAGE_PADDING
];
};
prototypeAccessors.tlbr.get = function () {
return this.tl.concat(this.br);
};
prototypeAccessors.displaySize.get = function () {
return [
(this.paddedRect.w - IMAGE_PADDING * 2) / this.pixelRatio,
(this.paddedRect.h - IMAGE_PADDING * 2) / this.pixelRatio
];
};
Object.defineProperties(ImagePosition.prototype, prototypeAccessors);
var ImageAtlas = function ImageAtlas(icons, patterns) {
var iconPositions = {}, patternPositions = {};
this.haveRenderCallbacks = [];
var bins = [];
this.addImages(icons, iconPositions, bins);
this.addImages(patterns, patternPositions, bins);
var ref = potpack(bins);
var w = ref.w;
var h = ref.h;
var image = new RGBAImage({
width: w || 1,
height: h || 1
});
for (var id in icons) {
var src = icons[id];
var bin = iconPositions[id].paddedRect;
RGBAImage.copy(src.data, image, {
x: 0,
y: 0
}, {
x: bin.x + IMAGE_PADDING,
y: bin.y + IMAGE_PADDING
}, src.data);
}
for (var id$1 in patterns) {
var src$1 = patterns[id$1];
var bin$1 = patternPositions[id$1].paddedRect;
var x = bin$1.x + IMAGE_PADDING, y = bin$1.y + IMAGE_PADDING, w$1 = src$1.data.width, h$1 = src$1.data.height;
RGBAImage.copy(src$1.data, image, {
x: 0,
y: 0
}, {
x: x,
y: y
}, src$1.data);
RGBAImage.copy(src$1.data, image, {
x: 0,
y: h$1 - 1
}, {
x: x,
y: y - 1
}, {
width: w$1,
height: 1
});
RGBAImage.copy(src$1.data, image, {
x: 0,
y: 0
}, {
x: x,
y: y + h$1
}, {
width: w$1,
height: 1
});
RGBAImage.copy(src$1.data, image, {
x: w$1 - 1,
y: 0
}, {
x: x - 1,
y: y
}, {
width: 1,
height: h$1
});
RGBAImage.copy(src$1.data, image, {
x: 0,
y: 0
}, {
x: x + w$1,
y: y
}, {
width: 1,
height: h$1
});
}
this.image = image;
this.iconPositions = iconPositions;
this.patternPositions = patternPositions;
};
ImageAtlas.prototype.addImages = function addImages(images, positions, bins) {
for (var id in images) {
var src = images[id];
var bin = {
x: 0,
y: 0,
w: src.data.width + 2 * IMAGE_PADDING,
h: src.data.height + 2 * IMAGE_PADDING
};
bins.push(bin);
positions[id] = new ImagePosition(bin, src);
if (src.hasRenderCallback) {
this.haveRenderCallbacks.push(id);
}
}
};
ImageAtlas.prototype.patchUpdatedImages = function patchUpdatedImages(imageManager, texture) {
imageManager.dispatchRenderCallbacks(this.haveRenderCallbacks);
for (var name in imageManager.updatedImages) {
this.patchUpdatedImage(this.iconPositions[name], imageManager.getImage(name), texture);
this.patchUpdatedImage(this.patternPositions[name], imageManager.getImage(name), texture);
}
};
ImageAtlas.prototype.patchUpdatedImage = function patchUpdatedImage(position, image, texture) {
if (!position || !image) {
return;
}
if (position.version === image.version) {
return;
}
position.version = image.version;
var ref = position.tl;
var x = ref[0];
var y = ref[1];
texture.update(image.data, undefined, {
x: x,
y: y
});
};
register('ImagePosition', ImagePosition);
register('ImageAtlas', ImageAtlas);
var WritingMode = {
horizontal: 1,
vertical: 2,
horizontalOnly: 3
};
var SHAPING_DEFAULT_OFFSET = -17;
function isEmpty(positionedLines) {
for (var i = 0, list = positionedLines; i < list.length; i += 1) {
var line = list[i];
if (line.positionedGlyphs.length !== 0) {
return false;
}
}
return true;
}
var PUAbegin = 57344;
var PUAend = 63743;
var SectionOptions = function SectionOptions() {
this.scale = 1;
this.fontStack = '';
this.imageName = null;
};
SectionOptions.forText = function forText(scale, fontStack) {
var textOptions = new SectionOptions();
textOptions.scale = scale || 1;
textOptions.fontStack = fontStack;
return textOptions;
};
SectionOptions.forImage = function forImage(imageName) {
var imageOptions = new SectionOptions();
imageOptions.imageName = imageName;
return imageOptions;
};
var TaggedString = function TaggedString() {
this.text = '';
this.sectionIndex = [];
this.sections = [];
this.imageSectionID = null;
};
TaggedString.fromFeature = function fromFeature(text, defaultFontStack) {
var result = new TaggedString();
for (var i = 0; i < text.sections.length; i++) {
var section = text.sections[i];
if (!section.image) {
result.addTextSection(section, defaultFontStack);
} else {
result.addImageSection(section);
}
}
return result;
};
TaggedString.prototype.length = function length() {
return this.text.length;
};
TaggedString.prototype.getSection = function getSection(index) {
return this.sections[this.sectionIndex[index]];
};
TaggedString.prototype.getSectionIndex = function getSectionIndex(index) {
return this.sectionIndex[index];
};
TaggedString.prototype.getCharCode = function getCharCode(index) {
return this.text.charCodeAt(index);
};
TaggedString.prototype.verticalizePunctuation = function verticalizePunctuation$1() {
this.text = verticalizePunctuation(this.text);
};
TaggedString.prototype.trim = function trim() {
var beginningWhitespace = 0;
for (var i = 0; i < this.text.length && whitespace[this.text.charCodeAt(i)]; i++) {
beginningWhitespace++;
}
var trailingWhitespace = this.text.length;
for (var i$1 = this.text.length - 1; i$1 >= 0 && i$1 >= beginningWhitespace && whitespace[this.text.charCodeAt(i$1)]; i$1--) {
trailingWhitespace--;
}
this.text = this.text.substring(beginningWhitespace, trailingWhitespace);
this.sectionIndex = this.sectionIndex.slice(beginningWhitespace, trailingWhitespace);
};
TaggedString.prototype.substring = function substring(start, end) {
var substring = new TaggedString();
substring.text = this.text.substring(start, end);
substring.sectionIndex = this.sectionIndex.slice(start, end);
substring.sections = this.sections;
return substring;
};
TaggedString.prototype.toString = function toString() {
return this.text;
};
TaggedString.prototype.getMaxScale = function getMaxScale() {
var this$1 = this;
return this.sectionIndex.reduce(function (max, index) {
return Math.max(max, this$1.sections[index].scale);
}, 0);
};
TaggedString.prototype.addTextSection = function addTextSection(section, defaultFontStack) {
this.text += section.text;
this.sections.push(SectionOptions.forText(section.scale, section.fontStack || defaultFontStack));
var index = this.sections.length - 1;
for (var i = 0; i < section.text.length; ++i) {
this.sectionIndex.push(index);
}
};
TaggedString.prototype.addImageSection = function addImageSection(section) {
var imageName = section.image ? section.image.name : '';
if (imageName.length === 0) {
warnOnce('Can\'t add FormattedSection with an empty image.');
return;
}
var nextImageSectionCharCode = this.getNextImageSectionCharCode();
if (!nextImageSectionCharCode) {
warnOnce('Reached maximum number of images ' + (PUAend - PUAbegin + 2));
return;
}
this.text += String.fromCharCode(nextImageSectionCharCode);
this.sections.push(SectionOptions.forImage(imageName));
this.sectionIndex.push(this.sections.length - 1);
};
TaggedString.prototype.getNextImageSectionCharCode = function getNextImageSectionCharCode() {
if (!this.imageSectionID) {
this.imageSectionID = PUAbegin;
return this.imageSectionID;
}
if (this.imageSectionID >= PUAend) {
return null;
}
return ++this.imageSectionID;
};
function breakLines(input, lineBreakPoints) {
var lines = [];
var text = input.text;
var start = 0;
for (var i = 0, list = lineBreakPoints; i < list.length; i += 1) {
var lineBreak = list[i];
lines.push(input.substring(start, lineBreak));
start = lineBreak;
}
if (start < text.length) {
lines.push(input.substring(start, text.length));
}
return lines;
}
function shapeText(text, glyphMap, glyphPositions, imagePositions, defaultFontStack, maxWidth, lineHeight, textAnchor, textJustify, spacing, translate, writingMode, allowVerticalPlacement, symbolPlacement, layoutTextSize, layoutTextSizeThisZoom) {
var logicalInput = TaggedString.fromFeature(text, defaultFontStack);
if (writingMode === WritingMode.vertical) {
logicalInput.verticalizePunctuation();
}
var lines;
var processBidirectionalText = plugin.processBidirectionalText;
var processStyledBidirectionalText = plugin.processStyledBidirectionalText;
if (processBidirectionalText && logicalInput.sections.length === 1) {
lines = [];
var untaggedLines = processBidirectionalText(logicalInput.toString(), determineLineBreaks(logicalInput, spacing, maxWidth, glyphMap, imagePositions, symbolPlacement, layoutTextSize));
for (var i$1 = 0, list = untaggedLines; i$1 < list.length; i$1 += 1) {
var line = list[i$1];
var taggedLine = new TaggedString();
taggedLine.text = line;
taggedLine.sections = logicalInput.sections;
for (var i = 0; i < line.length; i++) {
taggedLine.sectionIndex.push(0);
}
lines.push(taggedLine);
}
} else if (processStyledBidirectionalText) {
lines = [];
var processedLines = processStyledBidirectionalText(logicalInput.text, logicalInput.sectionIndex, determineLineBreaks(logicalInput, spacing, maxWidth, glyphMap, imagePositions, symbolPlacement, layoutTextSize));
for (var i$2 = 0, list$1 = processedLines; i$2 < list$1.length; i$2 += 1) {
var line$1 = list$1[i$2];
var taggedLine$1 = new TaggedString();
taggedLine$1.text = line$1[0];
taggedLine$1.sectionIndex = line$1[1];
taggedLine$1.sections = logicalInput.sections;
lines.push(taggedLine$1);
}
} else {
lines = breakLines(logicalInput, determineLineBreaks(logicalInput, spacing, maxWidth, glyphMap, imagePositions, symbolPlacement, layoutTextSize));
}
var positionedLines = [];
var shaping = {
positionedLines: positionedLines,
text: logicalInput.toString(),
top: translate[1],
bottom: translate[1],
left: translate[0],
right: translate[0],
writingMode: writingMode,
iconsInText: false,
verticalizable: false
};
shapeLines(shaping, glyphMap, glyphPositions, imagePositions, lines, lineHeight, textAnchor, textJustify, writingMode, spacing, allowVerticalPlacement, layoutTextSizeThisZoom);
if (isEmpty(positionedLines)) {
return false;
}
return shaping;
}
var whitespace = {};
whitespace[9] = true;
whitespace[10] = true;
whitespace[11] = true;
whitespace[12] = true;
whitespace[13] = true;
whitespace[32] = true;
var breakable = {};
breakable[10] = true;
breakable[32] = true;
breakable[38] = true;
breakable[40] = true;
breakable[41] = true;
breakable[43] = true;
breakable[45] = true;
breakable[47] = true;
breakable[173] = true;
breakable[183] = true;
breakable[8203] = true;
breakable[8208] = true;
breakable[8211] = true;
breakable[8231] = true;
function getGlyphAdvance(codePoint, section, glyphMap, imagePositions, spacing, layoutTextSize) {
if (!section.imageName) {
var positions = glyphMap[section.fontStack];
var glyph = positions && positions[codePoint];
if (!glyph) {
return 0;
}
return glyph.metrics.advance * section.scale + spacing;
} else {
var imagePosition = imagePositions[section.imageName];
if (!imagePosition) {
return 0;
}
return imagePosition.displaySize[0] * section.scale * ONE_EM / layoutTextSize + spacing;
}
}
function determineAverageLineWidth(logicalInput, spacing, maxWidth, glyphMap, imagePositions, layoutTextSize) {
var totalWidth = 0;
for (var index = 0; index < logicalInput.length(); index++) {
var section = logicalInput.getSection(index);
totalWidth += getGlyphAdvance(logicalInput.getCharCode(index), section, glyphMap, imagePositions, spacing, layoutTextSize);
}
var lineCount = Math.max(1, Math.ceil(totalWidth / maxWidth));
return totalWidth / lineCount;
}
function calculateBadness(lineWidth, targetWidth, penalty, isLastBreak) {
var raggedness = Math.pow(lineWidth - targetWidth, 2);
if (isLastBreak) {
if (lineWidth < targetWidth) {
return raggedness / 2;
} else {
return raggedness * 2;
}
}
return raggedness + Math.abs(penalty) * penalty;
}
function calculatePenalty(codePoint, nextCodePoint, penalizableIdeographicBreak) {
var penalty = 0;
if (codePoint === 10) {
penalty -= 10000;
}
if (penalizableIdeographicBreak) {
penalty += 150;
}
if (codePoint === 40 || codePoint === 65288) {
penalty += 50;
}
if (nextCodePoint === 41 || nextCodePoint === 65289) {
penalty += 50;
}
return penalty;
}
function evaluateBreak(breakIndex, breakX, targetWidth, potentialBreaks, penalty, isLastBreak) {
var bestPriorBreak = null;
var bestBreakBadness = calculateBadness(breakX, targetWidth, penalty, isLastBreak);
for (var i = 0, list = potentialBreaks; i < list.length; i += 1) {
var potentialBreak = list[i];
var lineWidth = breakX - potentialBreak.x;
var breakBadness = calculateBadness(lineWidth, targetWidth, penalty, isLastBreak) + potentialBreak.badness;
if (breakBadness <= bestBreakBadness) {
bestPriorBreak = potentialBreak;
bestBreakBadness = breakBadness;
}
}
return {
index: breakIndex,
x: breakX,
priorBreak: bestPriorBreak,
badness: bestBreakBadness
};
}
function leastBadBreaks(lastLineBreak) {
if (!lastLineBreak) {
return [];
}
return leastBadBreaks(lastLineBreak.priorBreak).concat(lastLineBreak.index);
}
function determineLineBreaks(logicalInput, spacing, maxWidth, glyphMap, imagePositions, symbolPlacement, layoutTextSize) {
if (symbolPlacement !== 'point') {
return [];
}
if (!logicalInput) {
return [];
}
var potentialLineBreaks = [];
var targetWidth = determineAverageLineWidth(logicalInput, spacing, maxWidth, glyphMap, imagePositions, layoutTextSize);
var hasServerSuggestedBreakpoints = logicalInput.text.indexOf('\u200B') >= 0;
var currentX = 0;
for (var i = 0; i < logicalInput.length(); i++) {
var section = logicalInput.getSection(i);
var codePoint = logicalInput.getCharCode(i);
if (!whitespace[codePoint]) {
currentX += getGlyphAdvance(codePoint, section, glyphMap, imagePositions, spacing, layoutTextSize);
}
if (i < logicalInput.length() - 1) {
var ideographicBreak = charAllowsIdeographicBreaking(codePoint);
if (breakable[codePoint] || ideographicBreak || section.imageName) {
potentialLineBreaks.push(evaluateBreak(i + 1, currentX, targetWidth, potentialLineBreaks, calculatePenalty(codePoint, logicalInput.getCharCode(i + 1), ideographicBreak && hasServerSuggestedBreakpoints), false));
}
}
}
return leastBadBreaks(evaluateBreak(logicalInput.length(), currentX, targetWidth, potentialLineBreaks, 0, true));
}
function getAnchorAlignment(anchor) {
var horizontalAlign = 0.5, verticalAlign = 0.5;
switch (anchor) {
case 'right':
case 'top-right':
case 'bottom-right':
horizontalAlign = 1;
break;
case 'left':
case 'top-left':
case 'bottom-left':
horizontalAlign = 0;
break;
}
switch (anchor) {
case 'bottom':
case 'bottom-right':
case 'bottom-left':
verticalAlign = 1;
break;
case 'top':
case 'top-right':
case 'top-left':
verticalAlign = 0;
break;
}
return {
horizontalAlign: horizontalAlign,
verticalAlign: verticalAlign
};
}
function shapeLines(shaping, glyphMap, glyphPositions, imagePositions, lines, lineHeight, textAnchor, textJustify, writingMode, spacing, allowVerticalPlacement, layoutTextSizeThisZoom) {
var x = 0;
var y = SHAPING_DEFAULT_OFFSET;
var maxLineLength = 0;
var maxLineHeight = 0;
var justify = textJustify === 'right' ? 1 : textJustify === 'left' ? 0 : 0.5;
var lineIndex = 0;
for (var i$1 = 0, list = lines; i$1 < list.length; i$1 += 1) {
var line = list[i$1];
line.trim();
var lineMaxScale = line.getMaxScale();
var maxLineOffset = (lineMaxScale - 1) * ONE_EM;
var positionedLine = {
positionedGlyphs: [],
lineOffset: 0
};
shaping.positionedLines[lineIndex] = positionedLine;
var positionedGlyphs = positionedLine.positionedGlyphs;
var lineOffset = 0;
if (!line.length()) {
y += lineHeight;
++lineIndex;
continue;
}
for (var i = 0; i < line.length(); i++) {
var section = line.getSection(i);
var sectionIndex = line.getSectionIndex(i);
var codePoint = line.getCharCode(i);
var baselineOffset = 0;
var metrics = null;
var rect = null;
var imageName = null;
var verticalAdvance = ONE_EM;
var vertical = !(writingMode === WritingMode.horizontal || !allowVerticalPlacement && !charHasUprightVerticalOrientation(codePoint) || allowVerticalPlacement && (whitespace[codePoint] || charInComplexShapingScript(codePoint)));
if (!section.imageName) {
var positions = glyphPositions[section.fontStack];
var glyphPosition = positions && positions[codePoint];
if (glyphPosition && glyphPosition.rect) {
rect = glyphPosition.rect;
metrics = glyphPosition.metrics;
} else {
var glyphs = glyphMap[section.fontStack];
var glyph = glyphs && glyphs[codePoint];
if (!glyph) {
continue;
}
metrics = glyph.metrics;
}
baselineOffset = (lineMaxScale - section.scale) * ONE_EM;
} else {
var imagePosition = imagePositions[section.imageName];
if (!imagePosition) {
continue;
}
imageName = section.imageName;
shaping.iconsInText = shaping.iconsInText || true;
rect = imagePosition.paddedRect;
var size = imagePosition.displaySize;
section.scale = section.scale * ONE_EM / layoutTextSizeThisZoom;
metrics = {
width: size[0],
height: size[1],
left: IMAGE_PADDING,
top: -GLYPH_PBF_BORDER,
advance: vertical ? size[1] : size[0]
};
var imageOffset = ONE_EM - size[1] * section.scale;
baselineOffset = maxLineOffset + imageOffset;
verticalAdvance = metrics.advance;
var offset = vertical ? size[0] * section.scale - ONE_EM * lineMaxScale : size[1] * section.scale - ONE_EM * lineMaxScale;
if (offset > 0 && offset > lineOffset) {
lineOffset = offset;
}
}
if (!vertical) {
positionedGlyphs.push({
glyph: codePoint,
imageName: imageName,
x: x,
y: y + baselineOffset,
vertical: vertical,
scale: section.scale,
fontStack: section.fontStack,
sectionIndex: sectionIndex,
metrics: metrics,
rect: rect
});
x += metrics.advance * section.scale + spacing;
} else {
shaping.verticalizable = true;
positionedGlyphs.push({
glyph: codePoint,
imageName: imageName,
x: x,
y: y + baselineOffset,
vertical: vertical,
scale: section.scale,
fontStack: section.fontStack,
sectionIndex: sectionIndex,
metrics: metrics,
rect: rect
});
x += verticalAdvance * section.scale + spacing;
}
}
if (positionedGlyphs.length !== 0) {
var lineLength = x - spacing;
maxLineLength = Math.max(lineLength, maxLineLength);
justifyLine(positionedGlyphs, 0, positionedGlyphs.length - 1, justify, lineOffset);
}
x = 0;
var currentLineHeight = lineHeight * lineMaxScale + lineOffset;
positionedLine.lineOffset = Math.max(lineOffset, maxLineOffset);
y += currentLineHeight;
maxLineHeight = Math.max(currentLineHeight, maxLineHeight);
++lineIndex;
}
var height = y - SHAPING_DEFAULT_OFFSET;
var ref = getAnchorAlignment(textAnchor);
var horizontalAlign = ref.horizontalAlign;
var verticalAlign = ref.verticalAlign;
align$1(shaping.positionedLines, justify, horizontalAlign, verticalAlign, maxLineLength, maxLineHeight, lineHeight, height, lines.length);
shaping.top += -verticalAlign * height;
shaping.bottom = shaping.top + height;
shaping.left += -horizontalAlign * maxLineLength;
shaping.right = shaping.left + maxLineLength;
}
function justifyLine(positionedGlyphs, start, end, justify, lineOffset) {
if (!justify && !lineOffset) {
return;
}
var lastPositionedGlyph = positionedGlyphs[end];
var lastAdvance = lastPositionedGlyph.metrics.advance * lastPositionedGlyph.scale;
var lineIndent = (positionedGlyphs[end].x + lastAdvance) * justify;
for (var j = start; j <= end; j++) {
positionedGlyphs[j].x -= lineIndent;
positionedGlyphs[j].y += lineOffset;
}
}
function align$1(positionedLines, justify, horizontalAlign, verticalAlign, maxLineLength, maxLineHeight, lineHeight, blockHeight, lineCount) {
var shiftX = (justify - horizontalAlign) * maxLineLength;
var shiftY = 0;
if (maxLineHeight !== lineHeight) {
shiftY = -blockHeight * verticalAlign - SHAPING_DEFAULT_OFFSET;
} else {
shiftY = (-verticalAlign * lineCount + 0.5) * lineHeight;
}
for (var i$1 = 0, list$1 = positionedLines; i$1 < list$1.length; i$1 += 1) {
var line = list$1[i$1];
for (var i = 0, list = line.positionedGlyphs; i < list.length; i += 1) {
var positionedGlyph = list[i];
positionedGlyph.x += shiftX;
positionedGlyph.y += shiftY;
}
}
}
function shapeIcon(image, iconOffset, iconAnchor) {
var ref = getAnchorAlignment(iconAnchor);
var horizontalAlign = ref.horizontalAlign;
var verticalAlign = ref.verticalAlign;
var dx = iconOffset[0];
var dy = iconOffset[1];
var x1 = dx - image.displaySize[0] * horizontalAlign;
var x2 = x1 + image.displaySize[0];
var y1 = dy - image.displaySize[1] * verticalAlign;
var y2 = y1 + image.displaySize[1];
return {
image: image,
top: y1,
bottom: y2,
left: x1,
right: x2
};
}
function fitIconToText(shapedIcon, shapedText, textFit, padding, iconOffset, fontScale) {
var image = shapedIcon.image;
var collisionPadding;
if (image.content) {
var content = image.content;
var pixelRatio = image.pixelRatio || 1;
collisionPadding = [
content[0] / pixelRatio,
content[1] / pixelRatio,
image.displaySize[0] - content[2] / pixelRatio,
image.displaySize[1] - content[3] / pixelRatio
];
}
var textLeft = shapedText.left * fontScale;
var textRight = shapedText.right * fontScale;
var top, right, bottom, left;
if (textFit === 'width' || textFit === 'both') {
left = iconOffset[0] + textLeft - padding[3];
right = iconOffset[0] + textRight + padding[1];
} else {
left = iconOffset[0] + (textLeft + textRight - image.displaySize[0]) / 2;
right = left + image.displaySize[0];
}
var textTop = shapedText.top * fontScale;
var textBottom = shapedText.bottom * fontScale;
if (textFit === 'height' || textFit === 'both') {
top = iconOffset[1] + textTop - padding[0];
bottom = iconOffset[1] + textBottom + padding[2];
} else {
top = iconOffset[1] + (textTop + textBottom - image.displaySize[1]) / 2;
bottom = top + image.displaySize[1];
}
return {
image: image,
top: top,
right: right,
bottom: bottom,
left: left,
collisionPadding: collisionPadding
};
}
var Anchor = function (Point) {
function Anchor(x, y, angle, segment) {
Point.call(this, x, y);
this.angle = angle;
if (segment !== undefined) {
this.segment = segment;
}
}
if (Point)
Anchor.__proto__ = Point;
Anchor.prototype = Object.create(Point && Point.prototype);
Anchor.prototype.constructor = Anchor;
Anchor.prototype.clone = function clone() {
return new Anchor(this.x, this.y, this.angle, this.segment);
};
return Anchor;
}(pointGeometry);
register('Anchor', Anchor);
var SIZE_PACK_FACTOR = 128;
function getSizeData(tileZoom, value) {
var expression = value.expression;
if (expression.kind === 'constant') {
var layoutSize = expression.evaluate(new EvaluationParameters(tileZoom + 1));
return {
kind: 'constant',
layoutSize: layoutSize
};
} else if (expression.kind === 'source') {
return { kind: 'source' };
} else {
var zoomStops = expression.zoomStops;
var interpolationType = expression.interpolationType;
var lower = 0;
while (lower < zoomStops.length && zoomStops[lower] <= tileZoom) {
lower++;
}
lower = Math.max(0, lower - 1);
var upper = lower;
while (upper < zoomStops.length && zoomStops[upper] < tileZoom + 1) {
upper++;
}
upper = Math.min(zoomStops.length - 1, upper);
var minZoom = zoomStops[lower];
var maxZoom = zoomStops[upper];
if (expression.kind === 'composite') {
return {
kind: 'composite',
minZoom: minZoom,
maxZoom: maxZoom,
interpolationType: interpolationType
};
}
var minSize = expression.evaluate(new EvaluationParameters(minZoom));
var maxSize = expression.evaluate(new EvaluationParameters(maxZoom));
return {
kind: 'camera',
minZoom: minZoom,
maxZoom: maxZoom,
minSize: minSize,
maxSize: maxSize,
interpolationType: interpolationType
};
}
}
function evaluateSizeForFeature(sizeData, ref, ref$1) {
var uSize = ref.uSize;
var uSizeT = ref.uSizeT;
var lowerSize = ref$1.lowerSize;
var upperSize = ref$1.upperSize;
if (sizeData.kind === 'source') {
return lowerSize / SIZE_PACK_FACTOR;
} else if (sizeData.kind === 'composite') {
return number(lowerSize / SIZE_PACK_FACTOR, upperSize / SIZE_PACK_FACTOR, uSizeT);
}
return uSize;
}
function evaluateSizeForZoom(sizeData, zoom) {
var uSizeT = 0;
var uSize = 0;
if (sizeData.kind === 'constant') {
uSize = sizeData.layoutSize;
} else if (sizeData.kind !== 'source') {
var interpolationType = sizeData.interpolationType;
var minZoom = sizeData.minZoom;
var maxZoom = sizeData.maxZoom;
var t = !interpolationType ? 0 : clamp(Interpolate.interpolationFactor(interpolationType, zoom, minZoom, maxZoom), 0, 1);
if (sizeData.kind === 'camera') {
uSize = number(sizeData.minSize, sizeData.maxSize, t);
} else {
uSizeT = t;
}
}
return {
uSizeT: uSizeT,
uSize: uSize
};
}
var symbolSize = /*#__PURE__*/Object.freeze({
__proto__: null,
getSizeData: getSizeData,
evaluateSizeForFeature: evaluateSizeForFeature,
evaluateSizeForZoom: evaluateSizeForZoom,
SIZE_PACK_FACTOR: SIZE_PACK_FACTOR
});
function checkMaxAngle(line, anchor, labelLength, windowSize, maxAngle) {
if (anchor.segment === undefined) {
return true;
}
var p = anchor;
var index = anchor.segment + 1;
var anchorDistance = 0;
while (anchorDistance > -labelLength / 2) {
index--;
if (index < 0) {
return false;
}
anchorDistance -= line[index].dist(p);
p = line[index];
}
anchorDistance += line[index].dist(line[index + 1]);
index++;
var recentCorners = [];
var recentAngleDelta = 0;
while (anchorDistance < labelLength / 2) {
var prev = line[index - 1];
var current = line[index];
var next = line[index + 1];
if (!next) {
return false;
}
var angleDelta = prev.angleTo(current) - current.angleTo(next);
angleDelta = Math.abs((angleDelta + 3 * Math.PI) % (Math.PI * 2) - Math.PI);
recentCorners.push({
distance: anchorDistance,
angleDelta: angleDelta
});
recentAngleDelta += angleDelta;
while (anchorDistance - recentCorners[0].distance > windowSize) {
recentAngleDelta -= recentCorners.shift().angleDelta;
}
if (recentAngleDelta > maxAngle) {
return false;
}
index++;
anchorDistance += current.dist(next);
}
return true;
}
function getLineLength(line) {
var lineLength = 0;
for (var k = 0; k < line.length - 1; k++) {
lineLength += line[k].dist(line[k + 1]);
}
return lineLength;
}
function getAngleWindowSize(shapedText, glyphSize, boxScale) {
return shapedText ? 3 / 5 * glyphSize * boxScale : 0;
}
function getShapedLabelLength(shapedText, shapedIcon) {
return Math.max(shapedText ? shapedText.right - shapedText.left : 0, shapedIcon ? shapedIcon.right - shapedIcon.left : 0);
}
function getCenterAnchor(line, maxAngle, shapedText, shapedIcon, glyphSize, boxScale) {
var angleWindowSize = getAngleWindowSize(shapedText, glyphSize, boxScale);
var labelLength = getShapedLabelLength(shapedText, shapedIcon) * boxScale;
var prevDistance = 0;
var centerDistance = getLineLength(line) / 2;
for (var i = 0; i < line.length - 1; i++) {
var a = line[i], b = line[i + 1];
var segmentDistance = a.dist(b);
if (prevDistance + segmentDistance > centerDistance) {
var t = (centerDistance - prevDistance) / segmentDistance, x = number(a.x, b.x, t), y = number(a.y, b.y, t);
var anchor = new Anchor(x, y, b.angleTo(a), i);
anchor._round();
if (!angleWindowSize || checkMaxAngle(line, anchor, labelLength, angleWindowSize, maxAngle)) {
return anchor;
} else {
return;
}
}
prevDistance += segmentDistance;
}
}
function getAnchors(line, spacing, maxAngle, shapedText, shapedIcon, glyphSize, boxScale, overscaling, tileExtent) {
var angleWindowSize = getAngleWindowSize(shapedText, glyphSize, boxScale);
var shapedLabelLength = getShapedLabelLength(shapedText, shapedIcon);
var labelLength = shapedLabelLength * boxScale;
var isLineContinued = line[0].x === 0 || line[0].x === tileExtent || line[0].y === 0 || line[0].y === tileExtent;
if (spacing - labelLength < spacing / 4) {
spacing = labelLength + spacing / 4;
}
var fixedExtraOffset = glyphSize * 2;
var offset = !isLineContinued ? (shapedLabelLength / 2 + fixedExtraOffset) * boxScale * overscaling % spacing : spacing / 2 * overscaling % spacing;
return resample(line, offset, spacing, angleWindowSize, maxAngle, labelLength, isLineContinued, false, tileExtent);
}
function resample(line, offset, spacing, angleWindowSize, maxAngle, labelLength, isLineContinued, placeAtMiddle, tileExtent) {
var halfLabelLength = labelLength / 2;
var lineLength = getLineLength(line);
var distance = 0, markedDistance = offset - spacing;
var anchors = [];
for (var i = 0; i < line.length - 1; i++) {
var a = line[i], b = line[i + 1];
var segmentDist = a.dist(b), angle = b.angleTo(a);
while (markedDistance + spacing < distance + segmentDist) {
markedDistance += spacing;
var t = (markedDistance - distance) / segmentDist, x = number(a.x, b.x, t), y = number(a.y, b.y, t);
if (x >= 0 && x < tileExtent && y >= 0 && y < tileExtent && markedDistance - halfLabelLength >= 0 && markedDistance + halfLabelLength <= lineLength) {
var anchor = new Anchor(x, y, angle, i);
anchor._round();
if (!angleWindowSize || checkMaxAngle(line, anchor, labelLength, angleWindowSize, maxAngle)) {
anchors.push(anchor);
}
}
}
distance += segmentDist;
}
if (!placeAtMiddle && !anchors.length && !isLineContinued) {
anchors = resample(line, distance / 2, spacing, angleWindowSize, maxAngle, labelLength, isLineContinued, true, tileExtent);
}
return anchors;
}
function clipLine(lines, x1, y1, x2, y2) {
var clippedLines = [];
for (var l = 0; l < lines.length; l++) {
var line = lines[l];
var clippedLine = void 0;
for (var i = 0; i < line.length - 1; i++) {
var p0 = line[i];
var p1 = line[i + 1];
if (p0.x < x1 && p1.x < x1) {
continue;
} else if (p0.x < x1) {
p0 = new pointGeometry(x1, p0.y + (p1.y - p0.y) * ((x1 - p0.x) / (p1.x - p0.x)))._round();
} else if (p1.x < x1) {
p1 = new pointGeometry(x1, p0.y + (p1.y - p0.y) * ((x1 - p0.x) / (p1.x - p0.x)))._round();
}
if (p0.y < y1 && p1.y < y1) {
continue;
} else if (p0.y < y1) {
p0 = new pointGeometry(p0.x + (p1.x - p0.x) * ((y1 - p0.y) / (p1.y - p0.y)), y1)._round();
} else if (p1.y < y1) {
p1 = new pointGeometry(p0.x + (p1.x - p0.x) * ((y1 - p0.y) / (p1.y - p0.y)), y1)._round();
}
if (p0.x >= x2 && p1.x >= x2) {
continue;
} else if (p0.x >= x2) {
p0 = new pointGeometry(x2, p0.y + (p1.y - p0.y) * ((x2 - p0.x) / (p1.x - p0.x)))._round();
} else if (p1.x >= x2) {
p1 = new pointGeometry(x2, p0.y + (p1.y - p0.y) * ((x2 - p0.x) / (p1.x - p0.x)))._round();
}
if (p0.y >= y2 && p1.y >= y2) {
continue;
} else if (p0.y >= y2) {
p0 = new pointGeometry(p0.x + (p1.x - p0.x) * ((y2 - p0.y) / (p1.y - p0.y)), y2)._round();
} else if (p1.y >= y2) {
p1 = new pointGeometry(p0.x + (p1.x - p0.x) * ((y2 - p0.y) / (p1.y - p0.y)), y2)._round();
}
if (!clippedLine || !p0.equals(clippedLine[clippedLine.length - 1])) {
clippedLine = [p0];
clippedLines.push(clippedLine);
}
clippedLine.push(p1);
}
}
return clippedLines;
}
var border$1 = IMAGE_PADDING;
function getIconQuads(shapedIcon, iconRotate, isSDFIcon, hasIconTextFit) {
var quads = [];
var image = shapedIcon.image;
var pixelRatio = image.pixelRatio;
var imageWidth = image.paddedRect.w - 2 * border$1;
var imageHeight = image.paddedRect.h - 2 * border$1;
var iconWidth = shapedIcon.right - shapedIcon.left;
var iconHeight = shapedIcon.bottom - shapedIcon.top;
var stretchX = image.stretchX || [[
0,
imageWidth
]];
var stretchY = image.stretchY || [[
0,
imageHeight
]];
var reduceRanges = function (sum, range) {
return sum + range[1] - range[0];
};
var stretchWidth = stretchX.reduce(reduceRanges, 0);
var stretchHeight = stretchY.reduce(reduceRanges, 0);
var fixedWidth = imageWidth - stretchWidth;
var fixedHeight = imageHeight - stretchHeight;
var stretchOffsetX = 0;
var stretchContentWidth = stretchWidth;
var stretchOffsetY = 0;
var stretchContentHeight = stretchHeight;
var fixedOffsetX = 0;
var fixedContentWidth = fixedWidth;
var fixedOffsetY = 0;
var fixedContentHeight = fixedHeight;
if (image.content && hasIconTextFit) {
var content = image.content;
stretchOffsetX = sumWithinRange(stretchX, 0, content[0]);
stretchOffsetY = sumWithinRange(stretchY, 0, content[1]);
stretchContentWidth = sumWithinRange(stretchX, content[0], content[2]);
stretchContentHeight = sumWithinRange(stretchY, content[1], content[3]);
fixedOffsetX = content[0] - stretchOffsetX;
fixedOffsetY = content[1] - stretchOffsetY;
fixedContentWidth = content[2] - content[0] - stretchContentWidth;
fixedContentHeight = content[3] - content[1] - stretchContentHeight;
}
var makeBox = function (left, top, right, bottom) {
var leftEm = getEmOffset(left.stretch - stretchOffsetX, stretchContentWidth, iconWidth, shapedIcon.left);
var leftPx = getPxOffset(left.fixed - fixedOffsetX, fixedContentWidth, left.stretch, stretchWidth);
var topEm = getEmOffset(top.stretch - stretchOffsetY, stretchContentHeight, iconHeight, shapedIcon.top);
var topPx = getPxOffset(top.fixed - fixedOffsetY, fixedContentHeight, top.stretch, stretchHeight);
var rightEm = getEmOffset(right.stretch - stretchOffsetX, stretchContentWidth, iconWidth, shapedIcon.left);
var rightPx = getPxOffset(right.fixed - fixedOffsetX, fixedContentWidth, right.stretch, stretchWidth);
var bottomEm = getEmOffset(bottom.stretch - stretchOffsetY, stretchContentHeight, iconHeight, shapedIcon.top);
var bottomPx = getPxOffset(bottom.fixed - fixedOffsetY, fixedContentHeight, bottom.stretch, stretchHeight);
var tl = new pointGeometry(leftEm, topEm);
var tr = new pointGeometry(rightEm, topEm);
var br = new pointGeometry(rightEm, bottomEm);
var bl = new pointGeometry(leftEm, bottomEm);
var pixelOffsetTL = new pointGeometry(leftPx / pixelRatio, topPx / pixelRatio);
var pixelOffsetBR = new pointGeometry(rightPx / pixelRatio, bottomPx / pixelRatio);
var angle = iconRotate * Math.PI / 180;
if (angle) {
var sin = Math.sin(angle), cos = Math.cos(angle), matrix = [
cos,
-sin,
sin,
cos
];
tl._matMult(matrix);
tr._matMult(matrix);
bl._matMult(matrix);
br._matMult(matrix);
}
var x1 = left.stretch + left.fixed;
var x2 = right.stretch + right.fixed;
var y1 = top.stretch + top.fixed;
var y2 = bottom.stretch + bottom.fixed;
var subRect = {
x: image.paddedRect.x + border$1 + x1,
y: image.paddedRect.y + border$1 + y1,
w: x2 - x1,
h: y2 - y1
};
var minFontScaleX = fixedContentWidth / pixelRatio / iconWidth;
var minFontScaleY = fixedContentHeight / pixelRatio / iconHeight;
return {
tl: tl,
tr: tr,
bl: bl,
br: br,
tex: subRect,
writingMode: undefined,
glyphOffset: [
0,
0
],
sectionIndex: 0,
pixelOffsetTL: pixelOffsetTL,
pixelOffsetBR: pixelOffsetBR,
minFontScaleX: minFontScaleX,
minFontScaleY: minFontScaleY,
isSDF: isSDFIcon
};
};
if (!hasIconTextFit || !image.stretchX && !image.stretchY) {
quads.push(makeBox({
fixed: 0,
stretch: -1
}, {
fixed: 0,
stretch: -1
}, {
fixed: 0,
stretch: imageWidth + 1
}, {
fixed: 0,
stretch: imageHeight + 1
}));
} else {
var xCuts = stretchZonesToCuts(stretchX, fixedWidth, stretchWidth);
var yCuts = stretchZonesToCuts(stretchY, fixedHeight, stretchHeight);
for (var xi = 0; xi < xCuts.length - 1; xi++) {
var x1 = xCuts[xi];
var x2 = xCuts[xi + 1];
for (var yi = 0; yi < yCuts.length - 1; yi++) {
var y1 = yCuts[yi];
var y2 = yCuts[yi + 1];
quads.push(makeBox(x1, y1, x2, y2));
}
}
}
return quads;
}
function sumWithinRange(ranges, min, max) {
var sum = 0;
for (var i = 0, list = ranges; i < list.length; i += 1) {
var range = list[i];
sum += Math.max(min, Math.min(max, range[1])) - Math.max(min, Math.min(max, range[0]));
}
return sum;
}
function stretchZonesToCuts(stretchZones, fixedSize, stretchSize) {
var cuts = [{
fixed: -border$1,
stretch: 0
}];
for (var i = 0, list = stretchZones; i < list.length; i += 1) {
var ref = list[i];
var c1 = ref[0];
var c2 = ref[1];
var last = cuts[cuts.length - 1];
cuts.push({
fixed: c1 - last.stretch,
stretch: last.stretch
});
cuts.push({
fixed: c1 - last.stretch,
stretch: last.stretch + (c2 - c1)
});
}
cuts.push({
fixed: fixedSize + border$1,
stretch: stretchSize
});
return cuts;
}
function getEmOffset(stretchOffset, stretchSize, iconSize, iconOffset) {
return stretchOffset / stretchSize * iconSize + iconOffset;
}
function getPxOffset(fixedOffset, fixedSize, stretchOffset, stretchSize) {
return fixedOffset - fixedSize * stretchOffset / stretchSize;
}
function getGlyphQuads(anchor, shaping, textOffset, layer, alongLine, feature, imageMap, allowVerticalPlacement) {
var textRotate = layer.layout.get('text-rotate').evaluate(feature, {}) * Math.PI / 180;
var quads = [];
for (var i$1 = 0, list$1 = shaping.positionedLines; i$1 < list$1.length; i$1 += 1) {
var line = list$1[i$1];
for (var i = 0, list = line.positionedGlyphs; i < list.length; i += 1) {
var positionedGlyph = list[i];
if (!positionedGlyph.rect) {
continue;
}
var textureRect = positionedGlyph.rect || {};
var glyphPadding = 1;
var rectBuffer = GLYPH_PBF_BORDER + glyphPadding;
var isSDF = true;
var pixelRatio = 1;
var lineOffset = 0;
var rotateVerticalGlyph = (alongLine || allowVerticalPlacement) && positionedGlyph.vertical;
var halfAdvance = positionedGlyph.metrics.advance * positionedGlyph.scale / 2;
if (allowVerticalPlacement && shaping.verticalizable) {
var scaledGlyphOffset = (positionedGlyph.scale - 1) * ONE_EM;
var imageOffset = (ONE_EM - positionedGlyph.metrics.width * positionedGlyph.scale) / 2;
lineOffset = line.lineOffset / 2 - (positionedGlyph.imageName ? -imageOffset : scaledGlyphOffset);
}
if (positionedGlyph.imageName) {
var image = imageMap[positionedGlyph.imageName];
isSDF = image.sdf;
pixelRatio = image.pixelRatio;
rectBuffer = IMAGE_PADDING / pixelRatio;
}
var glyphOffset = alongLine ? [
positionedGlyph.x + halfAdvance,
positionedGlyph.y
] : [
0,
0
];
var builtInOffset = alongLine ? [
0,
0
] : [
positionedGlyph.x + halfAdvance + textOffset[0],
positionedGlyph.y + textOffset[1] - lineOffset
];
var verticalizedLabelOffset = [
0,
0
];
if (rotateVerticalGlyph) {
verticalizedLabelOffset = builtInOffset;
builtInOffset = [
0,
0
];
}
var x1 = (positionedGlyph.metrics.left - rectBuffer) * positionedGlyph.scale - halfAdvance + builtInOffset[0];
var y1 = (-positionedGlyph.metrics.top - rectBuffer) * positionedGlyph.scale + builtInOffset[1];
var x2 = x1 + textureRect.w * positionedGlyph.scale / pixelRatio;
var y2 = y1 + textureRect.h * positionedGlyph.scale / pixelRatio;
var tl = new pointGeometry(x1, y1);
var tr = new pointGeometry(x2, y1);
var bl = new pointGeometry(x1, y2);
var br = new pointGeometry(x2, y2);
if (rotateVerticalGlyph) {
var center = new pointGeometry(-halfAdvance, halfAdvance - SHAPING_DEFAULT_OFFSET);
var verticalRotation = -Math.PI / 2;
var xHalfWidthOffsetCorrection = ONE_EM / 2 - halfAdvance;
var yImageOffsetCorrection = positionedGlyph.imageName ? xHalfWidthOffsetCorrection : 0;
var halfWidthOffsetCorrection = new pointGeometry(5 - SHAPING_DEFAULT_OFFSET - xHalfWidthOffsetCorrection, -yImageOffsetCorrection);
var verticalOffsetCorrection = new (Function.prototype.bind.apply(pointGeometry, [null].concat(verticalizedLabelOffset)))();
tl._rotateAround(verticalRotation, center)._add(halfWidthOffsetCorrection)._add(verticalOffsetCorrection);
tr._rotateAround(verticalRotation, center)._add(halfWidthOffsetCorrection)._add(verticalOffsetCorrection);
bl._rotateAround(verticalRotation, center)._add(halfWidthOffsetCorrection)._add(verticalOffsetCorrection);
br._rotateAround(verticalRotation, center)._add(halfWidthOffsetCorrection)._add(verticalOffsetCorrection);
}
if (textRotate) {
var sin = Math.sin(textRotate), cos = Math.cos(textRotate), matrix = [
cos,
-sin,
sin,
cos
];
tl._matMult(matrix);
tr._matMult(matrix);
bl._matMult(matrix);
br._matMult(matrix);
}
var pixelOffsetTL = new pointGeometry(0, 0);
var pixelOffsetBR = new pointGeometry(0, 0);
var minFontScaleX = 0;
var minFontScaleY = 0;
quads.push({
tl: tl,
tr: tr,
bl: bl,
br: br,
tex: textureRect,
writingMode: shaping.writingMode,
glyphOffset: glyphOffset,
sectionIndex: positionedGlyph.sectionIndex,
isSDF: isSDF,
pixelOffsetTL: pixelOffsetTL,
pixelOffsetBR: pixelOffsetBR,
minFontScaleX: minFontScaleX,
minFontScaleY: minFontScaleY
});
}
}
return quads;
}
var CollisionFeature = function CollisionFeature(collisionBoxArray, anchor, featureIndex, sourceLayerIndex, bucketIndex, shaped, boxScale, padding, alignLine, rotate) {
this.boxStartIndex = collisionBoxArray.length;
if (alignLine) {
var top = shaped.top;
var bottom = shaped.bottom;
var collisionPadding = shaped.collisionPadding;
if (collisionPadding) {
top -= collisionPadding[1];
bottom += collisionPadding[3];
}
var height = bottom - top;
if (height > 0) {
height = Math.max(10, height);
this.circleDiameter = height;
}
} else {
var y1 = shaped.top * boxScale - padding;
var y2 = shaped.bottom * boxScale + padding;
var x1 = shaped.left * boxScale - padding;
var x2 = shaped.right * boxScale + padding;
var collisionPadding$1 = shaped.collisionPadding;
if (collisionPadding$1) {
x1 -= collisionPadding$1[0] * boxScale;
y1 -= collisionPadding$1[1] * boxScale;
x2 += collisionPadding$1[2] * boxScale;
y2 += collisionPadding$1[3] * boxScale;
}
if (rotate) {
var tl = new pointGeometry(x1, y1);
var tr = new pointGeometry(x2, y1);
var bl = new pointGeometry(x1, y2);
var br = new pointGeometry(x2, y2);
var rotateRadians = rotate * Math.PI / 180;
tl._rotate(rotateRadians);
tr._rotate(rotateRadians);
bl._rotate(rotateRadians);
br._rotate(rotateRadians);
x1 = Math.min(tl.x, tr.x, bl.x, br.x);
x2 = Math.max(tl.x, tr.x, bl.x, br.x);
y1 = Math.min(tl.y, tr.y, bl.y, br.y);
y2 = Math.max(tl.y, tr.y, bl.y, br.y);
}
collisionBoxArray.emplaceBack(anchor.x, anchor.y, x1, y1, x2, y2, featureIndex, sourceLayerIndex, bucketIndex);
}
this.boxEndIndex = collisionBoxArray.length;
};
var TinyQueue = function TinyQueue(data, compare) {
if (data === void 0)
data = [];
if (compare === void 0)
compare = defaultCompare$1;
this.data = data;
this.length = this.data.length;
this.compare = compare;
if (this.length > 0) {
for (var i = (this.length >> 1) - 1; i >= 0; i--) {
this._down(i);
}
}
};
TinyQueue.prototype.push = function push(item) {
this.data.push(item);
this.length++;
this._up(this.length - 1);
};
TinyQueue.prototype.pop = function pop() {
if (this.length === 0) {
return undefined;
}
var top = this.data[0];
var bottom = this.data.pop();
this.length--;
if (this.length > 0) {
this.data[0] = bottom;
this._down(0);
}
return top;
};
TinyQueue.prototype.peek = function peek() {
return this.data[0];
};
TinyQueue.prototype._up = function _up(pos) {
var ref = this;
var data = ref.data;
var compare = ref.compare;
var item = data[pos];
while (pos > 0) {
var parent = pos - 1 >> 1;
var current = data[parent];
if (compare(item, current) >= 0) {
break;
}
data[pos] = current;
pos = parent;
}
data[pos] = item;
};
TinyQueue.prototype._down = function _down(pos) {
var ref = this;
var data = ref.data;
var compare = ref.compare;
var halfLength = this.length >> 1;
var item = data[pos];
while (pos < halfLength) {
var left = (pos << 1) + 1;
var best = data[left];
var right = left + 1;
if (right < this.length && compare(data[right], best) < 0) {
left = right;
best = data[right];
}
if (compare(best, item) >= 0) {
break;
}
data[pos] = best;
pos = left;
}
data[pos] = item;
};
function defaultCompare$1(a, b) {
return a < b ? -1 : a > b ? 1 : 0;
}
function findPoleOfInaccessibility (polygonRings, precision, debug) {
if (precision === void 0)
precision = 1;
if (debug === void 0)
debug = false;
var minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
var outerRing = polygonRings[0];
for (var i = 0; i < outerRing.length; i++) {
var p = outerRing[i];
if (!i || p.x < minX) {
minX = p.x;
}
if (!i || p.y < minY) {
minY = p.y;
}
if (!i || p.x > maxX) {
maxX = p.x;
}
if (!i || p.y > maxY) {
maxY = p.y;
}
}
var width = maxX - minX;
var height = maxY - minY;
var cellSize = Math.min(width, height);
var h = cellSize / 2;
var cellQueue = new TinyQueue([], compareMax);
if (cellSize === 0) {
return new pointGeometry(minX, minY);
}
for (var x = minX; x < maxX; x += cellSize) {
for (var y = minY; y < maxY; y += cellSize) {
cellQueue.push(new Cell(x + h, y + h, h, polygonRings));
}
}
var bestCell = getCentroidCell(polygonRings);
var numProbes = cellQueue.length;
while (cellQueue.length) {
var cell = cellQueue.pop();
if (cell.d > bestCell.d || !bestCell.d) {
bestCell = cell;
if (debug) {
console.log('found best %d after %d probes', Math.round(10000 * cell.d) / 10000, numProbes);
}
}
if (cell.max - bestCell.d <= precision) {
continue;
}
h = cell.h / 2;
cellQueue.push(new Cell(cell.p.x - h, cell.p.y - h, h, polygonRings));
cellQueue.push(new Cell(cell.p.x + h, cell.p.y - h, h, polygonRings));
cellQueue.push(new Cell(cell.p.x - h, cell.p.y + h, h, polygonRings));
cellQueue.push(new Cell(cell.p.x + h, cell.p.y + h, h, polygonRings));
numProbes += 4;
}
if (debug) {
console.log('num probes: ' + numProbes);
console.log('best distance: ' + bestCell.d);
}
return bestCell.p;
}
function compareMax(a, b) {
return b.max - a.max;
}
function Cell(x, y, h, polygon) {
this.p = new pointGeometry(x, y);
this.h = h;
this.d = pointToPolygonDist(this.p, polygon);
this.max = this.d + this.h * Math.SQRT2;
}
function pointToPolygonDist(p, polygon) {
var inside = false;
var minDistSq = Infinity;
for (var k = 0; k < polygon.length; k++) {
var ring = polygon[k];
for (var i = 0, len = ring.length, j = len - 1; i < len; j = i++) {
var a = ring[i];
var b = ring[j];
if (a.y > p.y !== b.y > p.y && p.x < (b.x - a.x) * (p.y - a.y) / (b.y - a.y) + a.x) {
inside = !inside;
}
minDistSq = Math.min(minDistSq, distToSegmentSquared(p, a, b));
}
}
return (inside ? 1 : -1) * Math.sqrt(minDistSq);
}
function getCentroidCell(polygon) {
var area = 0;
var x = 0;
var y = 0;
var points = polygon[0];
for (var i = 0, len = points.length, j = len - 1; i < len; j = i++) {
var a = points[i];
var b = points[j];
var f = a.x * b.y - b.x * a.y;
x += (a.x + b.x) * f;
y += (a.y + b.y) * f;
area += f * 3;
}
return new Cell(x / area, y / area, 0, polygon);
}
var baselineOffset = 7;
var INVALID_TEXT_OFFSET = Number.POSITIVE_INFINITY;
function evaluateVariableOffset(anchor, offset) {
function fromRadialOffset(anchor, radialOffset) {
var x = 0, y = 0;
if (radialOffset < 0) {
radialOffset = 0;
}
var hypotenuse = radialOffset / Math.sqrt(2);
switch (anchor) {
case 'top-right':
case 'top-left':
y = hypotenuse - baselineOffset;
break;
case 'bottom-right':
case 'bottom-left':
y = -hypotenuse + baselineOffset;
break;
case 'bottom':
y = -radialOffset + baselineOffset;
break;
case 'top':
y = radialOffset - baselineOffset;
break;
}
switch (anchor) {
case 'top-right':
case 'bottom-right':
x = -hypotenuse;
break;
case 'top-left':
case 'bottom-left':
x = hypotenuse;
break;
case 'left':
x = radialOffset;
break;
case 'right':
x = -radialOffset;
break;
}
return [
x,
y
];
}
function fromTextOffset(anchor, offsetX, offsetY) {
var x = 0, y = 0;
offsetX = Math.abs(offsetX);
offsetY = Math.abs(offsetY);
switch (anchor) {
case 'top-right':
case 'top-left':
case 'top':
y = offsetY - baselineOffset;
break;
case 'bottom-right':
case 'bottom-left':
case 'bottom':
y = -offsetY + baselineOffset;
break;
}
switch (anchor) {
case 'top-right':
case 'bottom-right':
case 'right':
x = -offsetX;
break;
case 'top-left':
case 'bottom-left':
case 'left':
x = offsetX;
break;
}
return [
x,
y
];
}
return offset[1] !== INVALID_TEXT_OFFSET ? fromTextOffset(anchor, offset[0], offset[1]) : fromRadialOffset(anchor, offset[0]);
}
function performSymbolLayout(bucket, glyphMap, glyphPositions, imageMap, imagePositions, showCollisionBoxes, canonical) {
bucket.createArrays();
var tileSize = 512 * bucket.overscaling;
bucket.tilePixelRatio = EXTENT$1 / tileSize;
bucket.compareText = {};
bucket.iconsNeedLinear = false;
var layout = bucket.layers[0].layout;
var unevaluatedLayoutValues = bucket.layers[0]._unevaluatedLayout._values;
var sizes = {};
if (bucket.textSizeData.kind === 'composite') {
var ref = bucket.textSizeData;
var minZoom = ref.minZoom;
var maxZoom = ref.maxZoom;
sizes.compositeTextSizes = [
unevaluatedLayoutValues['text-size'].possiblyEvaluate(new EvaluationParameters(minZoom), canonical),
unevaluatedLayoutValues['text-size'].possiblyEvaluate(new EvaluationParameters(maxZoom), canonical)
];
}
if (bucket.iconSizeData.kind === 'composite') {
var ref$1 = bucket.iconSizeData;
var minZoom$1 = ref$1.minZoom;
var maxZoom$1 = ref$1.maxZoom;
sizes.compositeIconSizes = [
unevaluatedLayoutValues['icon-size'].possiblyEvaluate(new EvaluationParameters(minZoom$1), canonical),
unevaluatedLayoutValues['icon-size'].possiblyEvaluate(new EvaluationParameters(maxZoom$1), canonical)
];
}
sizes.layoutTextSize = unevaluatedLayoutValues['text-size'].possiblyEvaluate(new EvaluationParameters(bucket.zoom + 1), canonical);
sizes.layoutIconSize = unevaluatedLayoutValues['icon-size'].possiblyEvaluate(new EvaluationParameters(bucket.zoom + 1), canonical);
sizes.textMaxSize = unevaluatedLayoutValues['text-size'].possiblyEvaluate(new EvaluationParameters(18));
var lineHeight = layout.get('text-line-height') * ONE_EM;
var textAlongLine = layout.get('text-rotation-alignment') === 'map' && layout.get('symbol-placement') !== 'point';
var keepUpright = layout.get('text-keep-upright');
var textSize = layout.get('text-size');
var loop = function () {
var feature = list[i$1];
var fontstack = layout.get('text-font').evaluate(feature, {}, canonical).join(',');
var layoutTextSizeThisZoom = textSize.evaluate(feature, {}, canonical);
var layoutTextSize = sizes.layoutTextSize.evaluate(feature, {}, canonical);
var layoutIconSize = sizes.layoutIconSize.evaluate(feature, {}, canonical);
var shapedTextOrientations = {
horizontal: {},
vertical: undefined
};
var text = feature.text;
var textOffset = [
0,
0
];
if (text) {
var unformattedText = text.toString();
var spacing = layout.get('text-letter-spacing').evaluate(feature, {}, canonical) * ONE_EM;
var spacingIfAllowed = allowsLetterSpacing(unformattedText) ? spacing : 0;
var textAnchor = layout.get('text-anchor').evaluate(feature, {}, canonical);
var variableTextAnchor = layout.get('text-variable-anchor');
if (!variableTextAnchor) {
var radialOffset = layout.get('text-radial-offset').evaluate(feature, {}, canonical);
if (radialOffset) {
textOffset = evaluateVariableOffset(textAnchor, [
radialOffset * ONE_EM,
INVALID_TEXT_OFFSET
]);
} else {
textOffset = layout.get('text-offset').evaluate(feature, {}, canonical).map(function (t) {
return t * ONE_EM;
});
}
}
var textJustify = textAlongLine ? 'center' : layout.get('text-justify').evaluate(feature, {}, canonical);
var symbolPlacement = layout.get('symbol-placement');
var maxWidth = symbolPlacement === 'point' ? layout.get('text-max-width').evaluate(feature, {}, canonical) * ONE_EM : 0;
var addVerticalShapingForPointLabelIfNeeded = function () {
if (bucket.allowVerticalPlacement && allowsVerticalWritingMode(unformattedText)) {
shapedTextOrientations.vertical = shapeText(text, glyphMap, glyphPositions, imagePositions, fontstack, maxWidth, lineHeight, textAnchor, 'left', spacingIfAllowed, textOffset, WritingMode.vertical, true, symbolPlacement, layoutTextSize, layoutTextSizeThisZoom);
}
};
if (!textAlongLine && variableTextAnchor) {
var justifications = textJustify === 'auto' ? variableTextAnchor.map(function (a) {
return getAnchorJustification(a);
}) : [textJustify];
var singleLine = false;
for (var i = 0; i < justifications.length; i++) {
var justification = justifications[i];
if (shapedTextOrientations.horizontal[justification]) {
continue;
}
if (singleLine) {
shapedTextOrientations.horizontal[justification] = shapedTextOrientations.horizontal[0];
} else {
var shaping = shapeText(text, glyphMap, glyphPositions, imagePositions, fontstack, maxWidth, lineHeight, 'center', justification, spacingIfAllowed, textOffset, WritingMode.horizontal, false, symbolPlacement, layoutTextSize, layoutTextSizeThisZoom);
if (shaping) {
shapedTextOrientations.horizontal[justification] = shaping;
singleLine = shaping.positionedLines.length === 1;
}
}
}
addVerticalShapingForPointLabelIfNeeded();
} else {
if (textJustify === 'auto') {
textJustify = getAnchorJustification(textAnchor);
}
var shaping$1 = shapeText(text, glyphMap, glyphPositions, imagePositions, fontstack, maxWidth, lineHeight, textAnchor, textJustify, spacingIfAllowed, textOffset, WritingMode.horizontal, false, symbolPlacement, layoutTextSize, layoutTextSizeThisZoom);
if (shaping$1) {
shapedTextOrientations.horizontal[textJustify] = shaping$1;
}
addVerticalShapingForPointLabelIfNeeded();
if (allowsVerticalWritingMode(unformattedText) && textAlongLine && keepUpright) {
shapedTextOrientations.vertical = shapeText(text, glyphMap, glyphPositions, imagePositions, fontstack, maxWidth, lineHeight, textAnchor, textJustify, spacingIfAllowed, textOffset, WritingMode.vertical, false, symbolPlacement, layoutTextSize, layoutTextSizeThisZoom);
}
}
}
var shapedIcon = void 0;
var isSDFIcon = false;
if (feature.icon && feature.icon.name) {
var image = imageMap[feature.icon.name];
if (image) {
shapedIcon = shapeIcon(imagePositions[feature.icon.name], layout.get('icon-offset').evaluate(feature, {}, canonical), layout.get('icon-anchor').evaluate(feature, {}, canonical));
isSDFIcon = image.sdf;
if (bucket.sdfIcons === undefined) {
bucket.sdfIcons = image.sdf;
} else if (bucket.sdfIcons !== image.sdf) {
warnOnce('Style sheet warning: Cannot mix SDF and non-SDF icons in one buffer');
}
if (image.pixelRatio !== bucket.pixelRatio) {
bucket.iconsNeedLinear = true;
} else if (layout.get('icon-rotate').constantOr(1) !== 0) {
bucket.iconsNeedLinear = true;
}
}
}
var shapedText = getDefaultHorizontalShaping(shapedTextOrientations.horizontal) || shapedTextOrientations.vertical;
bucket.iconsInText = shapedText ? shapedText.iconsInText : false;
if (shapedText || shapedIcon) {
addFeature(bucket, feature, shapedTextOrientations, shapedIcon, imageMap, sizes, layoutTextSize, layoutIconSize, textOffset, isSDFIcon, canonical);
}
};
for (var i$1 = 0, list = bucket.features; i$1 < list.length; i$1 += 1)
loop();
if (showCollisionBoxes) {
bucket.generateCollisionDebugBuffers();
}
}
function getAnchorJustification(anchor) {
switch (anchor) {
case 'right':
case 'top-right':
case 'bottom-right':
return 'right';
case 'left':
case 'top-left':
case 'bottom-left':
return 'left';
}
return 'center';
}
function addFeature(bucket, feature, shapedTextOrientations, shapedIcon, imageMap, sizes, layoutTextSize, layoutIconSize, textOffset, isSDFIcon, canonical) {
var textMaxSize = sizes.textMaxSize.evaluate(feature, {});
if (textMaxSize === undefined) {
textMaxSize = layoutTextSize;
}
var layout = bucket.layers[0].layout;
var iconOffset = layout.get('icon-offset').evaluate(feature, {}, canonical);
var defaultHorizontalShaping = getDefaultHorizontalShaping(shapedTextOrientations.horizontal);
var glyphSize = 24, fontScale = layoutTextSize / glyphSize, textBoxScale = bucket.tilePixelRatio * fontScale, textMaxBoxScale = bucket.tilePixelRatio * textMaxSize / glyphSize, iconBoxScale = bucket.tilePixelRatio * layoutIconSize, symbolMinDistance = bucket.tilePixelRatio * layout.get('symbol-spacing'), textPadding = layout.get('text-padding') * bucket.tilePixelRatio, iconPadding = layout.get('icon-padding') * bucket.tilePixelRatio, textMaxAngle = layout.get('text-max-angle') / 180 * Math.PI, textAlongLine = layout.get('text-rotation-alignment') === 'map' && layout.get('symbol-placement') !== 'point', iconAlongLine = layout.get('icon-rotation-alignment') === 'map' && layout.get('symbol-placement') !== 'point', symbolPlacement = layout.get('symbol-placement'), textRepeatDistance = symbolMinDistance / 2;
var iconTextFit = layout.get('icon-text-fit');
var verticallyShapedIcon;
if (shapedIcon && iconTextFit !== 'none') {
if (bucket.allowVerticalPlacement && shapedTextOrientations.vertical) {
verticallyShapedIcon = fitIconToText(shapedIcon, shapedTextOrientations.vertical, iconTextFit, layout.get('icon-text-fit-padding'), iconOffset, fontScale);
}
if (defaultHorizontalShaping) {
shapedIcon = fitIconToText(shapedIcon, defaultHorizontalShaping, iconTextFit, layout.get('icon-text-fit-padding'), iconOffset, fontScale);
}
}
var addSymbolAtAnchor = function (line, anchor) {
if (anchor.x < 0 || anchor.x >= EXTENT$1 || anchor.y < 0 || anchor.y >= EXTENT$1) {
return;
}
addSymbol(bucket, anchor, line, shapedTextOrientations, shapedIcon, imageMap, verticallyShapedIcon, bucket.layers[0], bucket.collisionBoxArray, feature.index, feature.sourceLayerIndex, bucket.index, textBoxScale, textPadding, textAlongLine, textOffset, iconBoxScale, iconPadding, iconAlongLine, iconOffset, feature, sizes, isSDFIcon, canonical, layoutTextSize);
};
if (symbolPlacement === 'line') {
for (var i$1 = 0, list$1 = clipLine(feature.geometry, 0, 0, EXTENT$1, EXTENT$1); i$1 < list$1.length; i$1 += 1) {
var line = list$1[i$1];
var anchors = getAnchors(line, symbolMinDistance, textMaxAngle, shapedTextOrientations.vertical || defaultHorizontalShaping, shapedIcon, glyphSize, textMaxBoxScale, bucket.overscaling, EXTENT$1);
for (var i = 0, list = anchors; i < list.length; i += 1) {
var anchor = list[i];
var shapedText = defaultHorizontalShaping;
if (!shapedText || !anchorIsTooClose(bucket, shapedText.text, textRepeatDistance, anchor)) {
addSymbolAtAnchor(line, anchor);
}
}
}
} else if (symbolPlacement === 'line-center') {
for (var i$2 = 0, list$2 = feature.geometry; i$2 < list$2.length; i$2 += 1) {
var line$1 = list$2[i$2];
if (line$1.length > 1) {
var anchor$1 = getCenterAnchor(line$1, textMaxAngle, shapedTextOrientations.vertical || defaultHorizontalShaping, shapedIcon, glyphSize, textMaxBoxScale);
if (anchor$1) {
addSymbolAtAnchor(line$1, anchor$1);
}
}
}
} else if (feature.type === 'Polygon') {
for (var i$3 = 0, list$3 = classifyRings(feature.geometry, 0); i$3 < list$3.length; i$3 += 1) {
var polygon = list$3[i$3];
var poi = findPoleOfInaccessibility(polygon, 16);
addSymbolAtAnchor(polygon[0], new Anchor(poi.x, poi.y, 0));
}
} else if (feature.type === 'LineString') {
for (var i$4 = 0, list$4 = feature.geometry; i$4 < list$4.length; i$4 += 1) {
var line$2 = list$4[i$4];
addSymbolAtAnchor(line$2, new Anchor(line$2[0].x, line$2[0].y, 0));
}
} else if (feature.type === 'Point') {
for (var i$6 = 0, list$6 = feature.geometry; i$6 < list$6.length; i$6 += 1) {
var points = list$6[i$6];
for (var i$5 = 0, list$5 = points; i$5 < list$5.length; i$5 += 1) {
var point = list$5[i$5];
addSymbolAtAnchor([point], new Anchor(point.x, point.y, 0));
}
}
}
}
var MAX_GLYPH_ICON_SIZE = 255;
var MAX_PACKED_SIZE = MAX_GLYPH_ICON_SIZE * SIZE_PACK_FACTOR;
function addTextVertices(bucket, anchor, shapedText, imageMap, layer, textAlongLine, feature, textOffset, lineArray, writingMode, placementTypes, placedTextSymbolIndices, placedIconIndex, sizes, canonical) {
var glyphQuads = getGlyphQuads(anchor, shapedText, textOffset, layer, textAlongLine, feature, imageMap, bucket.allowVerticalPlacement);
var sizeData = bucket.textSizeData;
var textSizeData = null;
if (sizeData.kind === 'source') {
textSizeData = [SIZE_PACK_FACTOR * layer.layout.get('text-size').evaluate(feature, {})];
if (textSizeData[0] > MAX_PACKED_SIZE) {
warnOnce(bucket.layerIds[0] + ': Value for "text-size" is >= ' + MAX_GLYPH_ICON_SIZE + '. Reduce your "text-size".');
}
} else if (sizeData.kind === 'composite') {
textSizeData = [
SIZE_PACK_FACTOR * sizes.compositeTextSizes[0].evaluate(feature, {}, canonical),
SIZE_PACK_FACTOR * sizes.compositeTextSizes[1].evaluate(feature, {}, canonical)
];
if (textSizeData[0] > MAX_PACKED_SIZE || textSizeData[1] > MAX_PACKED_SIZE) {
warnOnce(bucket.layerIds[0] + ': Value for "text-size" is >= ' + MAX_GLYPH_ICON_SIZE + '. Reduce your "text-size".');
}
}
bucket.addSymbols(bucket.text, glyphQuads, textSizeData, textOffset, textAlongLine, feature, writingMode, anchor, lineArray.lineStartIndex, lineArray.lineLength, placedIconIndex, canonical);
for (var i = 0, list = placementTypes; i < list.length; i += 1) {
var placementType = list[i];
placedTextSymbolIndices[placementType] = bucket.text.placedSymbolArray.length - 1;
}
return glyphQuads.length * 4;
}
function getDefaultHorizontalShaping(horizontalShaping) {
for (var justification in horizontalShaping) {
return horizontalShaping[justification];
}
return null;
}
function addSymbol(bucket, anchor, line, shapedTextOrientations, shapedIcon, imageMap, verticallyShapedIcon, layer, collisionBoxArray, featureIndex, sourceLayerIndex, bucketIndex, textBoxScale, textPadding, textAlongLine, textOffset, iconBoxScale, iconPadding, iconAlongLine, iconOffset, feature, sizes, isSDFIcon, canonical, layoutTextSize) {
var assign;
var lineArray = bucket.addToLineVertexArray(anchor, line);
var textCollisionFeature, iconCollisionFeature, verticalTextCollisionFeature, verticalIconCollisionFeature;
var numIconVertices = 0;
var numVerticalIconVertices = 0;
var numHorizontalGlyphVertices = 0;
var numVerticalGlyphVertices = 0;
var placedIconSymbolIndex = -1;
var verticalPlacedIconSymbolIndex = -1;
var placedTextSymbolIndices = {};
var key = murmurhashJs('');
var textOffset0 = 0;
var textOffset1 = 0;
if (layer._unevaluatedLayout.getValue('text-radial-offset') === undefined) {
assign = layer.layout.get('text-offset').evaluate(feature, {}, canonical).map(function (t) {
return t * ONE_EM;
}), textOffset0 = assign[0], textOffset1 = assign[1];
} else {
textOffset0 = layer.layout.get('text-radial-offset').evaluate(feature, {}, canonical) * ONE_EM;
textOffset1 = INVALID_TEXT_OFFSET;
}
if (bucket.allowVerticalPlacement && shapedTextOrientations.vertical) {
var textRotation = layer.layout.get('text-rotate').evaluate(feature, {}, canonical);
var verticalTextRotation = textRotation + 90;
var verticalShaping = shapedTextOrientations.vertical;
verticalTextCollisionFeature = new CollisionFeature(collisionBoxArray, anchor, featureIndex, sourceLayerIndex, bucketIndex, verticalShaping, textBoxScale, textPadding, textAlongLine, verticalTextRotation);
if (verticallyShapedIcon) {
verticalIconCollisionFeature = new CollisionFeature(collisionBoxArray, anchor, featureIndex, sourceLayerIndex, bucketIndex, verticallyShapedIcon, iconBoxScale, iconPadding, textAlongLine, verticalTextRotation);
}
}
if (shapedIcon) {
var iconRotate = layer.layout.get('icon-rotate').evaluate(feature, {});
var hasIconTextFit = layer.layout.get('icon-text-fit') !== 'none';
var iconQuads = getIconQuads(shapedIcon, iconRotate, isSDFIcon, hasIconTextFit);
var verticalIconQuads = verticallyShapedIcon ? getIconQuads(verticallyShapedIcon, iconRotate, isSDFIcon, hasIconTextFit) : undefined;
iconCollisionFeature = new CollisionFeature(collisionBoxArray, anchor, featureIndex, sourceLayerIndex, bucketIndex, shapedIcon, iconBoxScale, iconPadding, false, iconRotate);
numIconVertices = iconQuads.length * 4;
var sizeData = bucket.iconSizeData;
var iconSizeData = null;
if (sizeData.kind === 'source') {
iconSizeData = [SIZE_PACK_FACTOR * layer.layout.get('icon-size').evaluate(feature, {})];
if (iconSizeData[0] > MAX_PACKED_SIZE) {
warnOnce(bucket.layerIds[0] + ': Value for "icon-size" is >= ' + MAX_GLYPH_ICON_SIZE + '. Reduce your "icon-size".');
}
} else if (sizeData.kind === 'composite') {
iconSizeData = [
SIZE_PACK_FACTOR * sizes.compositeIconSizes[0].evaluate(feature, {}, canonical),
SIZE_PACK_FACTOR * sizes.compositeIconSizes[1].evaluate(feature, {}, canonical)
];
if (iconSizeData[0] > MAX_PACKED_SIZE || iconSizeData[1] > MAX_PACKED_SIZE) {
warnOnce(bucket.layerIds[0] + ': Value for "icon-size" is >= ' + MAX_GLYPH_ICON_SIZE + '. Reduce your "icon-size".');
}
}
bucket.addSymbols(bucket.icon, iconQuads, iconSizeData, iconOffset, iconAlongLine, feature, false, anchor, lineArray.lineStartIndex, lineArray.lineLength, -1, canonical);
placedIconSymbolIndex = bucket.icon.placedSymbolArray.length - 1;
if (verticalIconQuads) {
numVerticalIconVertices = verticalIconQuads.length * 4;
bucket.addSymbols(bucket.icon, verticalIconQuads, iconSizeData, iconOffset, iconAlongLine, feature, WritingMode.vertical, anchor, lineArray.lineStartIndex, lineArray.lineLength, -1, canonical);
verticalPlacedIconSymbolIndex = bucket.icon.placedSymbolArray.length - 1;
}
}
for (var justification in shapedTextOrientations.horizontal) {
var shaping = shapedTextOrientations.horizontal[justification];
if (!textCollisionFeature) {
key = murmurhashJs(shaping.text);
var textRotate = layer.layout.get('text-rotate').evaluate(feature, {}, canonical);
textCollisionFeature = new CollisionFeature(collisionBoxArray, anchor, featureIndex, sourceLayerIndex, bucketIndex, shaping, textBoxScale, textPadding, textAlongLine, textRotate);
}
var singleLine = shaping.positionedLines.length === 1;
numHorizontalGlyphVertices += addTextVertices(bucket, anchor, shaping, imageMap, layer, textAlongLine, feature, textOffset, lineArray, shapedTextOrientations.vertical ? WritingMode.horizontal : WritingMode.horizontalOnly, singleLine ? Object.keys(shapedTextOrientations.horizontal) : [justification], placedTextSymbolIndices, placedIconSymbolIndex, sizes, canonical);
if (singleLine) {
break;
}
}
if (shapedTextOrientations.vertical) {
numVerticalGlyphVertices += addTextVertices(bucket, anchor, shapedTextOrientations.vertical, imageMap, layer, textAlongLine, feature, textOffset, lineArray, WritingMode.vertical, ['vertical'], placedTextSymbolIndices, verticalPlacedIconSymbolIndex, sizes, canonical);
}
var textBoxStartIndex = textCollisionFeature ? textCollisionFeature.boxStartIndex : bucket.collisionBoxArray.length;
var textBoxEndIndex = textCollisionFeature ? textCollisionFeature.boxEndIndex : bucket.collisionBoxArray.length;
var verticalTextBoxStartIndex = verticalTextCollisionFeature ? verticalTextCollisionFeature.boxStartIndex : bucket.collisionBoxArray.length;
var verticalTextBoxEndIndex = verticalTextCollisionFeature ? verticalTextCollisionFeature.boxEndIndex : bucket.collisionBoxArray.length;
var iconBoxStartIndex = iconCollisionFeature ? iconCollisionFeature.boxStartIndex : bucket.collisionBoxArray.length;
var iconBoxEndIndex = iconCollisionFeature ? iconCollisionFeature.boxEndIndex : bucket.collisionBoxArray.length;
var verticalIconBoxStartIndex = verticalIconCollisionFeature ? verticalIconCollisionFeature.boxStartIndex : bucket.collisionBoxArray.length;
var verticalIconBoxEndIndex = verticalIconCollisionFeature ? verticalIconCollisionFeature.boxEndIndex : bucket.collisionBoxArray.length;
var collisionCircleDiameter = -1;
var getCollisionCircleHeight = function (feature, prevHeight) {
if (feature && feature.circleDiameter) {
return Math.max(feature.circleDiameter, prevHeight);
}
return prevHeight;
};
collisionCircleDiameter = getCollisionCircleHeight(textCollisionFeature, collisionCircleDiameter);
collisionCircleDiameter = getCollisionCircleHeight(verticalTextCollisionFeature, collisionCircleDiameter);
collisionCircleDiameter = getCollisionCircleHeight(iconCollisionFeature, collisionCircleDiameter);
collisionCircleDiameter = getCollisionCircleHeight(verticalIconCollisionFeature, collisionCircleDiameter);
var useRuntimeCollisionCircles = collisionCircleDiameter > -1 ? 1 : 0;
if (useRuntimeCollisionCircles) {
collisionCircleDiameter *= layoutTextSize / ONE_EM;
}
if (bucket.glyphOffsetArray.length >= SymbolBucket.MAX_GLYPHS) {
warnOnce('Too many glyphs being rendered in a tile. See https://github.com/mapbox/mapbox-gl-js/issues/2907');
}
if (feature.sortKey !== undefined) {
bucket.addToSortKeyRanges(bucket.symbolInstances.length, feature.sortKey);
}
bucket.symbolInstances.emplaceBack(anchor.x, anchor.y, placedTextSymbolIndices.right >= 0 ? placedTextSymbolIndices.right : -1, placedTextSymbolIndices.center >= 0 ? placedTextSymbolIndices.center : -1, placedTextSymbolIndices.left >= 0 ? placedTextSymbolIndices.left : -1, placedTextSymbolIndices.vertical || -1, placedIconSymbolIndex, verticalPlacedIconSymbolIndex, key, textBoxStartIndex, textBoxEndIndex, verticalTextBoxStartIndex, verticalTextBoxEndIndex, iconBoxStartIndex, iconBoxEndIndex, verticalIconBoxStartIndex, verticalIconBoxEndIndex, featureIndex, numHorizontalGlyphVertices, numVerticalGlyphVertices, numIconVertices, numVerticalIconVertices, useRuntimeCollisionCircles, 0, textBoxScale, textOffset0, textOffset1, collisionCircleDiameter);
}
function anchorIsTooClose(bucket, text, repeatDistance, anchor) {
var compareText = bucket.compareText;
if (!(text in compareText)) {
compareText[text] = [];
} else {
var otherAnchors = compareText[text];
for (var k = otherAnchors.length - 1; k >= 0; k--) {
if (anchor.dist(otherAnchors[k]) < repeatDistance) {
return true;
}
}
}
compareText[text].push(anchor);
return false;
}
var vectorTileFeatureTypes$2 = vectorTile.VectorTileFeature.types;
var shaderOpacityAttributes = [{
name: 'a_fade_opacity',
components: 1,
type: 'Uint8',
offset: 0
}];
function addVertex$1(array, anchorX, anchorY, ox, oy, tx, ty, sizeVertex, isSDF, pixelOffsetX, pixelOffsetY, minFontScaleX, minFontScaleY) {
var aSizeX = sizeVertex ? Math.min(MAX_PACKED_SIZE, Math.round(sizeVertex[0])) : 0;
var aSizeY = sizeVertex ? Math.min(MAX_PACKED_SIZE, Math.round(sizeVertex[1])) : 0;
array.emplaceBack(anchorX, anchorY, Math.round(ox * 32), Math.round(oy * 32), tx, ty, (aSizeX << 1) + (isSDF ? 1 : 0), aSizeY, pixelOffsetX * 16, pixelOffsetY * 16, minFontScaleX * 256, minFontScaleY * 256);
}
function addDynamicAttributes(dynamicLayoutVertexArray, p, angle) {
dynamicLayoutVertexArray.emplaceBack(p.x, p.y, angle);
dynamicLayoutVertexArray.emplaceBack(p.x, p.y, angle);
dynamicLayoutVertexArray.emplaceBack(p.x, p.y, angle);
dynamicLayoutVertexArray.emplaceBack(p.x, p.y, angle);
}
function containsRTLText(formattedText) {
for (var i = 0, list = formattedText.sections; i < list.length; i += 1) {
var section = list[i];
if (stringContainsRTLText(section.text)) {
return true;
}
}
return false;
}
var SymbolBuffers = function SymbolBuffers(programConfigurations) {
this.layoutVertexArray = new StructArrayLayout4i4ui4i24();
this.indexArray = new StructArrayLayout3ui6();
this.programConfigurations = programConfigurations;
this.segments = new SegmentVector();
this.dynamicLayoutVertexArray = new StructArrayLayout3f12();
this.opacityVertexArray = new StructArrayLayout1ul4();
this.placedSymbolArray = new PlacedSymbolArray();
};
SymbolBuffers.prototype.isEmpty = function isEmpty() {
return this.layoutVertexArray.length === 0 && this.indexArray.length === 0 && this.dynamicLayoutVertexArray.length === 0 && this.opacityVertexArray.length === 0;
};
SymbolBuffers.prototype.upload = function upload(context, dynamicIndexBuffer, upload$1, update) {
if (this.isEmpty()) {
return;
}
if (upload$1) {
this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, symbolLayoutAttributes.members);
this.indexBuffer = context.createIndexBuffer(this.indexArray, dynamicIndexBuffer);
this.dynamicLayoutVertexBuffer = context.createVertexBuffer(this.dynamicLayoutVertexArray, dynamicLayoutAttributes.members, true);
this.opacityVertexBuffer = context.createVertexBuffer(this.opacityVertexArray, shaderOpacityAttributes, true);
this.opacityVertexBuffer.itemSize = 1;
}
if (upload$1 || update) {
this.programConfigurations.upload(context);
}
};
SymbolBuffers.prototype.destroy = function destroy() {
if (!this.layoutVertexBuffer) {
return;
}
this.layoutVertexBuffer.destroy();
this.indexBuffer.destroy();
this.programConfigurations.destroy();
this.segments.destroy();
this.dynamicLayoutVertexBuffer.destroy();
this.opacityVertexBuffer.destroy();
};
register('SymbolBuffers', SymbolBuffers);
var CollisionBuffers = function CollisionBuffers(LayoutArray, layoutAttributes, IndexArray) {
this.layoutVertexArray = new LayoutArray();
this.layoutAttributes = layoutAttributes;
this.indexArray = new IndexArray();
this.segments = new SegmentVector();
this.collisionVertexArray = new StructArrayLayout2ub2f12();
};
CollisionBuffers.prototype.upload = function upload(context) {
this.layoutVertexBuffer = context.createVertexBuffer(this.layoutVertexArray, this.layoutAttributes);
this.indexBuffer = context.createIndexBuffer(this.indexArray);
this.collisionVertexBuffer = context.createVertexBuffer(this.collisionVertexArray, collisionVertexAttributes.members, true);
};
CollisionBuffers.prototype.destroy = function destroy() {
if (!this.layoutVertexBuffer) {
return;
}
this.layoutVertexBuffer.destroy();
this.indexBuffer.destroy();
this.segments.destroy();
this.collisionVertexBuffer.destroy();
};
register('CollisionBuffers', CollisionBuffers);
var SymbolBucket = function SymbolBucket(options) {
this.collisionBoxArray = options.collisionBoxArray;
this.zoom = options.zoom;
this.overscaling = options.overscaling;
this.layers = options.layers;
this.layerIds = this.layers.map(function (layer) {
return layer.id;
});
this.index = options.index;
this.pixelRatio = options.pixelRatio;
this.sourceLayerIndex = options.sourceLayerIndex;
this.hasPattern = false;
this.hasRTLText = false;
this.sortKeyRanges = [];
this.collisionCircleArray = [];
this.placementInvProjMatrix = identity([]);
this.placementViewportMatrix = identity([]);
var layer = this.layers[0];
var unevaluatedLayoutValues = layer._unevaluatedLayout._values;
this.textSizeData = getSizeData(this.zoom, unevaluatedLayoutValues['text-size']);
this.iconSizeData = getSizeData(this.zoom, unevaluatedLayoutValues['icon-size']);
var layout = this.layers[0].layout;
var sortKey = layout.get('symbol-sort-key');
var zOrder = layout.get('symbol-z-order');
this.canOverlap = layout.get('text-allow-overlap') || layout.get('icon-allow-overlap') || layout.get('text-ignore-placement') || layout.get('icon-ignore-placement');
this.sortFeaturesByKey = zOrder !== 'viewport-y' && sortKey.constantOr(1) !== undefined;
var zOrderByViewportY = zOrder === 'viewport-y' || zOrder === 'auto' && !this.sortFeaturesByKey;
this.sortFeaturesByY = zOrderByViewportY && this.canOverlap;
if (layout.get('symbol-placement') === 'point') {
this.writingModes = layout.get('text-writing-mode').map(function (wm) {
return WritingMode[wm];
});
}
this.stateDependentLayerIds = this.layers.filter(function (l) {
return l.isStateDependent();
}).map(function (l) {
return l.id;
});
this.sourceID = options.sourceID;
};
SymbolBucket.prototype.createArrays = function createArrays() {
this.text = new SymbolBuffers(new ProgramConfigurationSet(this.layers, this.zoom, function (property) {
return /^text/.test(property);
}));
this.icon = new SymbolBuffers(new ProgramConfigurationSet(this.layers, this.zoom, function (property) {
return /^icon/.test(property);
}));
this.glyphOffsetArray = new GlyphOffsetArray();
this.lineVertexArray = new SymbolLineVertexArray();
this.symbolInstances = new SymbolInstanceArray();
};
SymbolBucket.prototype.calculateGlyphDependencies = function calculateGlyphDependencies(text, stack, textAlongLine, allowVerticalPlacement, doesAllowVerticalWritingMode) {
for (var i = 0; i < text.length; i++) {
stack[text.charCodeAt(i)] = true;
if ((textAlongLine || allowVerticalPlacement) && doesAllowVerticalWritingMode) {
var verticalChar = verticalizedCharacterMap[text.charAt(i)];
if (verticalChar) {
stack[verticalChar.charCodeAt(0)] = true;
}
}
}
};
SymbolBucket.prototype.populate = function populate(features, options, canonical) {
var layer = this.layers[0];
var layout = layer.layout;
var textFont = layout.get('text-font');
var textField = layout.get('text-field');
var iconImage = layout.get('icon-image');
var hasText = (textField.value.kind !== 'constant' || textField.value.value instanceof Formatted && !textField.value.value.isEmpty() || textField.value.value.toString().length > 0) && (textFont.value.kind !== 'constant' || textFont.value.value.length > 0);
var hasIcon = iconImage.value.kind !== 'constant' || !!iconImage.value.value || Object.keys(iconImage.parameters).length > 0;
var symbolSortKey = layout.get('symbol-sort-key');
this.features = [];
if (!hasText && !hasIcon) {
return;
}
var icons = options.iconDependencies;
var stacks = options.glyphDependencies;
var availableImages = options.availableImages;
var globalProperties = new EvaluationParameters(this.zoom);
for (var i$1 = 0, list$1 = features; i$1 < list$1.length; i$1 += 1) {
var ref = list$1[i$1];
var feature = ref.feature;
var id = ref.id;
var index = ref.index;
var sourceLayerIndex = ref.sourceLayerIndex;
var needGeometry = layer._featureFilter.needGeometry;
var evaluationFeature = toEvaluationFeature(feature, needGeometry);
if (!layer._featureFilter.filter(globalProperties, evaluationFeature, canonical)) {
continue;
}
if (!needGeometry) {
evaluationFeature.geometry = loadGeometry(feature);
}
var text = void 0;
if (hasText) {
var resolvedTokens = layer.getValueAndResolveTokens('text-field', evaluationFeature, canonical, availableImages);
var formattedText = Formatted.factory(resolvedTokens);
if (containsRTLText(formattedText)) {
this.hasRTLText = true;
}
if (!this.hasRTLText || getRTLTextPluginStatus() === 'unavailable' || this.hasRTLText && plugin.isParsed()) {
text = transformText$1(formattedText, layer, evaluationFeature);
}
}
var icon = void 0;
if (hasIcon) {
var resolvedTokens$1 = layer.getValueAndResolveTokens('icon-image', evaluationFeature, canonical, availableImages);
if (resolvedTokens$1 instanceof ResolvedImage) {
icon = resolvedTokens$1;
} else {
icon = ResolvedImage.fromString(resolvedTokens$1);
}
}
if (!text && !icon) {
continue;
}
var sortKey = this.sortFeaturesByKey ? symbolSortKey.evaluate(evaluationFeature, {}, canonical) : undefined;
var symbolFeature = {
id: id,
text: text,
icon: icon,
index: index,
sourceLayerIndex: sourceLayerIndex,
geometry: evaluationFeature.geometry,
properties: feature.properties,
type: vectorTileFeatureTypes$2[feature.type],
sortKey: sortKey
};
this.features.push(symbolFeature);
if (icon) {
icons[icon.name] = true;
}
if (text) {
var fontStack = textFont.evaluate(evaluationFeature, {}, canonical).join(',');
var textAlongLine = layout.get('text-rotation-alignment') === 'map' && layout.get('symbol-placement') !== 'point';
this.allowVerticalPlacement = this.writingModes && this.writingModes.indexOf(WritingMode.vertical) >= 0;
for (var i = 0, list = text.sections; i < list.length; i += 1) {
var section = list[i];
if (!section.image) {
var doesAllowVerticalWritingMode = allowsVerticalWritingMode(text.toString());
var sectionFont = section.fontStack || fontStack;
var sectionStack = stacks[sectionFont] = stacks[sectionFont] || {};
this.calculateGlyphDependencies(section.text, sectionStack, textAlongLine, this.allowVerticalPlacement, doesAllowVerticalWritingMode);
} else {
icons[section.image.name] = true;
}
}
}
}
if (layout.get('symbol-placement') === 'line') {
this.features = mergeLines(this.features);
}
if (this.sortFeaturesByKey) {
this.features.sort(function (a, b) {
return a.sortKey - b.sortKey;
});
}
};
SymbolBucket.prototype.update = function update(states, vtLayer, imagePositions) {
if (!this.stateDependentLayers.length) {
return;
}
this.text.programConfigurations.updatePaintArrays(states, vtLayer, this.layers, imagePositions);
this.icon.programConfigurations.updatePaintArrays(states, vtLayer, this.layers, imagePositions);
};
SymbolBucket.prototype.isEmpty = function isEmpty() {
return this.symbolInstances.length === 0 && !this.hasRTLText;
};
SymbolBucket.prototype.uploadPending = function uploadPending() {
return !this.uploaded || this.text.programConfigurations.needsUpload || this.icon.programConfigurations.needsUpload;
};
SymbolBucket.prototype.upload = function upload(context) {
if (!this.uploaded && this.hasDebugData()) {
this.textCollisionBox.upload(context);
this.iconCollisionBox.upload(context);
}
this.text.upload(context, this.sortFeaturesByY, !this.uploaded, this.text.programConfigurations.needsUpload);
this.icon.upload(context, this.sortFeaturesByY, !this.uploaded, this.icon.programConfigurations.needsUpload);
this.uploaded = true;
};
SymbolBucket.prototype.destroyDebugData = function destroyDebugData() {
this.textCollisionBox.destroy();
this.iconCollisionBox.destroy();
};
SymbolBucket.prototype.destroy = function destroy() {
this.text.destroy();
this.icon.destroy();
if (this.hasDebugData()) {
this.destroyDebugData();
}
};
SymbolBucket.prototype.addToLineVertexArray = function addToLineVertexArray(anchor, line) {
var lineStartIndex = this.lineVertexArray.length;
if (anchor.segment !== undefined) {
var sumForwardLength = anchor.dist(line[anchor.segment + 1]);
var sumBackwardLength = anchor.dist(line[anchor.segment]);
var vertices = {};
for (var i = anchor.segment + 1; i < line.length; i++) {
vertices[i] = {
x: line[i].x,
y: line[i].y,
tileUnitDistanceFromAnchor: sumForwardLength
};
if (i < line.length - 1) {
sumForwardLength += line[i + 1].dist(line[i]);
}
}
for (var i$1 = anchor.segment || 0; i$1 >= 0; i$1--) {
vertices[i$1] = {
x: line[i$1].x,
y: line[i$1].y,
tileUnitDistanceFromAnchor: sumBackwardLength
};
if (i$1 > 0) {
sumBackwardLength += line[i$1 - 1].dist(line[i$1]);
}
}
for (var i$2 = 0; i$2 < line.length; i$2++) {
var vertex = vertices[i$2];
this.lineVertexArray.emplaceBack(vertex.x, vertex.y, vertex.tileUnitDistanceFromAnchor);
}
}
return {
lineStartIndex: lineStartIndex,
lineLength: this.lineVertexArray.length - lineStartIndex
};
};
SymbolBucket.prototype.addSymbols = function addSymbols(arrays, quads, sizeVertex, lineOffset, alongLine, feature, writingMode, labelAnchor, lineStartIndex, lineLength, associatedIconIndex, canonical) {
var indexArray = arrays.indexArray;
var layoutVertexArray = arrays.layoutVertexArray;
var segment = arrays.segments.prepareSegment(4 * quads.length, layoutVertexArray, indexArray, this.canOverlap ? feature.sortKey : undefined);
var glyphOffsetArrayStart = this.glyphOffsetArray.length;
var vertexStartIndex = segment.vertexLength;
var angle = this.allowVerticalPlacement && writingMode === WritingMode.vertical ? Math.PI / 2 : 0;
var sections = feature.text && feature.text.sections;
for (var i = 0; i < quads.length; i++) {
var ref = quads[i];
var tl = ref.tl;
var tr = ref.tr;
var bl = ref.bl;
var br = ref.br;
var tex = ref.tex;
var pixelOffsetTL = ref.pixelOffsetTL;
var pixelOffsetBR = ref.pixelOffsetBR;
var minFontScaleX = ref.minFontScaleX;
var minFontScaleY = ref.minFontScaleY;
var glyphOffset = ref.glyphOffset;
var isSDF = ref.isSDF;
var sectionIndex = ref.sectionIndex;
var index = segment.vertexLength;
var y = glyphOffset[1];
addVertex$1(layoutVertexArray, labelAnchor.x, labelAnchor.y, tl.x, y + tl.y, tex.x, tex.y, sizeVertex, isSDF, pixelOffsetTL.x, pixelOffsetTL.y, minFontScaleX, minFontScaleY);
addVertex$1(layoutVertexArray, labelAnchor.x, labelAnchor.y, tr.x, y + tr.y, tex.x + tex.w, tex.y, sizeVertex, isSDF, pixelOffsetBR.x, pixelOffsetTL.y, minFontScaleX, minFontScaleY);
addVertex$1(layoutVertexArray, labelAnchor.x, labelAnchor.y, bl.x, y + bl.y, tex.x, tex.y + tex.h, sizeVertex, isSDF, pixelOffsetTL.x, pixelOffsetBR.y, minFontScaleX, minFontScaleY);
addVertex$1(layoutVertexArray, labelAnchor.x, labelAnchor.y, br.x, y + br.y, tex.x + tex.w, tex.y + tex.h, sizeVertex, isSDF, pixelOffsetBR.x, pixelOffsetBR.y, minFontScaleX, minFontScaleY);
addDynamicAttributes(arrays.dynamicLayoutVertexArray, labelAnchor, angle);
indexArray.emplaceBack(index, index + 1, index + 2);
indexArray.emplaceBack(index + 1, index + 2, index + 3);
segment.vertexLength += 4;
segment.primitiveLength += 2;
this.glyphOffsetArray.emplaceBack(glyphOffset[0]);
if (i === quads.length - 1 || sectionIndex !== quads[i + 1].sectionIndex) {
arrays.programConfigurations.populatePaintArrays(layoutVertexArray.length, feature, feature.index, {}, canonical, sections && sections[sectionIndex]);
}
}
arrays.placedSymbolArray.emplaceBack(labelAnchor.x, labelAnchor.y, glyphOffsetArrayStart, this.glyphOffsetArray.length - glyphOffsetArrayStart, vertexStartIndex, lineStartIndex, lineLength, labelAnchor.segment, sizeVertex ? sizeVertex[0] : 0, sizeVertex ? sizeVertex[1] : 0, lineOffset[0], lineOffset[1], writingMode, 0, false, 0, associatedIconIndex);
};
SymbolBucket.prototype._addCollisionDebugVertex = function _addCollisionDebugVertex(layoutVertexArray, collisionVertexArray, point, anchorX, anchorY, extrude) {
collisionVertexArray.emplaceBack(0, 0);
return layoutVertexArray.emplaceBack(point.x, point.y, anchorX, anchorY, Math.round(extrude.x), Math.round(extrude.y));
};
SymbolBucket.prototype.addCollisionDebugVertices = function addCollisionDebugVertices(x1, y1, x2, y2, arrays, boxAnchorPoint, symbolInstance) {
var segment = arrays.segments.prepareSegment(4, arrays.layoutVertexArray, arrays.indexArray);
var index = segment.vertexLength;
var layoutVertexArray = arrays.layoutVertexArray;
var collisionVertexArray = arrays.collisionVertexArray;
var anchorX = symbolInstance.anchorX;
var anchorY = symbolInstance.anchorY;
this._addCollisionDebugVertex(layoutVertexArray, collisionVertexArray, boxAnchorPoint, anchorX, anchorY, new pointGeometry(x1, y1));
this._addCollisionDebugVertex(layoutVertexArray, collisionVertexArray, boxAnchorPoint, anchorX, anchorY, new pointGeometry(x2, y1));
this._addCollisionDebugVertex(layoutVertexArray, collisionVertexArray, boxAnchorPoint, anchorX, anchorY, new pointGeometry(x2, y2));
this._addCollisionDebugVertex(layoutVertexArray, collisionVertexArray, boxAnchorPoint, anchorX, anchorY, new pointGeometry(x1, y2));
segment.vertexLength += 4;
var indexArray = arrays.indexArray;
indexArray.emplaceBack(index, index + 1);
indexArray.emplaceBack(index + 1, index + 2);
indexArray.emplaceBack(index + 2, index + 3);
indexArray.emplaceBack(index + 3, index);
segment.primitiveLength += 4;
};
SymbolBucket.prototype.addDebugCollisionBoxes = function addDebugCollisionBoxes(startIndex, endIndex, symbolInstance, isText) {
for (var b = startIndex; b < endIndex; b++) {
var box = this.collisionBoxArray.get(b);
var x1 = box.x1;
var y1 = box.y1;
var x2 = box.x2;
var y2 = box.y2;
this.addCollisionDebugVertices(x1, y1, x2, y2, isText ? this.textCollisionBox : this.iconCollisionBox, box.anchorPoint, symbolInstance);
}
};
SymbolBucket.prototype.generateCollisionDebugBuffers = function generateCollisionDebugBuffers() {
if (this.hasDebugData()) {
this.destroyDebugData();
}
this.textCollisionBox = new CollisionBuffers(StructArrayLayout2i2i2i12, collisionBoxLayout.members, StructArrayLayout2ui4);
this.iconCollisionBox = new CollisionBuffers(StructArrayLayout2i2i2i12, collisionBoxLayout.members, StructArrayLayout2ui4);
for (var i = 0; i < this.symbolInstances.length; i++) {
var symbolInstance = this.symbolInstances.get(i);
this.addDebugCollisionBoxes(symbolInstance.textBoxStartIndex, symbolInstance.textBoxEndIndex, symbolInstance, true);
this.addDebugCollisionBoxes(symbolInstance.verticalTextBoxStartIndex, symbolInstance.verticalTextBoxEndIndex, symbolInstance, true);
this.addDebugCollisionBoxes(symbolInstance.iconBoxStartIndex, symbolInstance.iconBoxEndIndex, symbolInstance, false);
this.addDebugCollisionBoxes(symbolInstance.verticalIconBoxStartIndex, symbolInstance.verticalIconBoxEndIndex, symbolInstance, false);
}
};
SymbolBucket.prototype._deserializeCollisionBoxesForSymbol = function _deserializeCollisionBoxesForSymbol(collisionBoxArray, textStartIndex, textEndIndex, verticalTextStartIndex, verticalTextEndIndex, iconStartIndex, iconEndIndex, verticalIconStartIndex, verticalIconEndIndex) {
var collisionArrays = {};
for (var k = textStartIndex; k < textEndIndex; k++) {
var box = collisionBoxArray.get(k);
collisionArrays.textBox = {
x1: box.x1,
y1: box.y1,
x2: box.x2,
y2: box.y2,
anchorPointX: box.anchorPointX,
anchorPointY: box.anchorPointY
};
collisionArrays.textFeatureIndex = box.featureIndex;
break;
}
for (var k$1 = verticalTextStartIndex; k$1 < verticalTextEndIndex; k$1++) {
var box$1 = collisionBoxArray.get(k$1);
collisionArrays.verticalTextBox = {
x1: box$1.x1,
y1: box$1.y1,
x2: box$1.x2,
y2: box$1.y2,
anchorPointX: box$1.anchorPointX,
anchorPointY: box$1.anchorPointY
};
collisionArrays.verticalTextFeatureIndex = box$1.featureIndex;
break;
}
for (var k$2 = iconStartIndex; k$2 < iconEndIndex; k$2++) {
var box$2 = collisionBoxArray.get(k$2);
collisionArrays.iconBox = {
x1: box$2.x1,
y1: box$2.y1,
x2: box$2.x2,
y2: box$2.y2,
anchorPointX: box$2.anchorPointX,
anchorPointY: box$2.anchorPointY
};
collisionArrays.iconFeatureIndex = box$2.featureIndex;
break;
}
for (var k$3 = verticalIconStartIndex; k$3 < verticalIconEndIndex; k$3++) {
var box$3 = collisionBoxArray.get(k$3);
collisionArrays.verticalIconBox = {
x1: box$3.x1,
y1: box$3.y1,
x2: box$3.x2,
y2: box$3.y2,
anchorPointX: box$3.anchorPointX,
anchorPointY: box$3.anchorPointY
};
collisionArrays.verticalIconFeatureIndex = box$3.featureIndex;
break;
}
return collisionArrays;
};
SymbolBucket.prototype.deserializeCollisionBoxes = function deserializeCollisionBoxes(collisionBoxArray) {
this.collisionArrays = [];
for (var i = 0; i < this.symbolInstances.length; i++) {
var symbolInstance = this.symbolInstances.get(i);
this.collisionArrays.push(this._deserializeCollisionBoxesForSymbol(collisionBoxArray, symbolInstance.textBoxStartIndex, symbolInstance.textBoxEndIndex, symbolInstance.verticalTextBoxStartIndex, symbolInstance.verticalTextBoxEndIndex, symbolInstance.iconBoxStartIndex, symbolInstance.iconBoxEndIndex, symbolInstance.verticalIconBoxStartIndex, symbolInstance.verticalIconBoxEndIndex));
}
};
SymbolBucket.prototype.hasTextData = function hasTextData() {
return this.text.segments.get().length > 0;
};
SymbolBucket.prototype.hasIconData = function hasIconData() {
return this.icon.segments.get().length > 0;
};
SymbolBucket.prototype.hasDebugData = function hasDebugData() {
return this.textCollisionBox && this.iconCollisionBox;
};
SymbolBucket.prototype.hasTextCollisionBoxData = function hasTextCollisionBoxData() {
return this.hasDebugData() && this.textCollisionBox.segments.get().length > 0;
};
SymbolBucket.prototype.hasIconCollisionBoxData = function hasIconCollisionBoxData() {
return this.hasDebugData() && this.iconCollisionBox.segments.get().length > 0;
};
SymbolBucket.prototype.addIndicesForPlacedSymbol = function addIndicesForPlacedSymbol(iconOrText, placedSymbolIndex) {
var placedSymbol = iconOrText.placedSymbolArray.get(placedSymbolIndex);
var endIndex = placedSymbol.vertexStartIndex + placedSymbol.numGlyphs * 4;
for (var vertexIndex = placedSymbol.vertexStartIndex; vertexIndex < endIndex; vertexIndex += 4) {
iconOrText.indexArray.emplaceBack(vertexIndex, vertexIndex + 1, vertexIndex + 2);
iconOrText.indexArray.emplaceBack(vertexIndex + 1, vertexIndex + 2, vertexIndex + 3);
}
};
SymbolBucket.prototype.getSortedSymbolIndexes = function getSortedSymbolIndexes(angle) {
if (this.sortedAngle === angle && this.symbolInstanceIndexes !== undefined) {
return this.symbolInstanceIndexes;
}
var sin = Math.sin(angle);
var cos = Math.cos(angle);
var rotatedYs = [];
var featureIndexes = [];
var result = [];
for (var i = 0; i < this.symbolInstances.length; ++i) {
result.push(i);
var symbolInstance = this.symbolInstances.get(i);
rotatedYs.push(Math.round(sin * symbolInstance.anchorX + cos * symbolInstance.anchorY) | 0);
featureIndexes.push(symbolInstance.featureIndex);
}
result.sort(function (aIndex, bIndex) {
return rotatedYs[aIndex] - rotatedYs[bIndex] || featureIndexes[bIndex] - featureIndexes[aIndex];
});
return result;
};
SymbolBucket.prototype.addToSortKeyRanges = function addToSortKeyRanges(symbolInstanceIndex, sortKey) {
var last = this.sortKeyRanges[this.sortKeyRanges.length - 1];
if (last && last.sortKey === sortKey) {
last.symbolInstanceEnd = symbolInstanceIndex + 1;
} else {
this.sortKeyRanges.push({
sortKey: sortKey,
symbolInstanceStart: symbolInstanceIndex,
symbolInstanceEnd: symbolInstanceIndex + 1
});
}
};
SymbolBucket.prototype.sortFeatures = function sortFeatures(angle) {
var this$1 = this;
if (!this.sortFeaturesByY) {
return;
}
if (this.sortedAngle === angle) {
return;
}
if (this.text.segments.get().length > 1 || this.icon.segments.get().length > 1) {
return;
}
this.symbolInstanceIndexes = this.getSortedSymbolIndexes(angle);
this.sortedAngle = angle;
this.text.indexArray.clear();
this.icon.indexArray.clear();
this.featureSortOrder = [];
for (var i$1 = 0, list = this.symbolInstanceIndexes; i$1 < list.length; i$1 += 1) {
var i = list[i$1];
var symbolInstance = this.symbolInstances.get(i);
this.featureSortOrder.push(symbolInstance.featureIndex);
[
symbolInstance.rightJustifiedTextSymbolIndex,
symbolInstance.centerJustifiedTextSymbolIndex,
symbolInstance.leftJustifiedTextSymbolIndex
].forEach(function (index, i, array) {
if (index >= 0 && array.indexOf(index) === i) {
this$1.addIndicesForPlacedSymbol(this$1.text, index);
}
});
if (symbolInstance.verticalPlacedTextSymbolIndex >= 0) {
this.addIndicesForPlacedSymbol(this.text, symbolInstance.verticalPlacedTextSymbolIndex);
}
if (symbolInstance.placedIconSymbolIndex >= 0) {
this.addIndicesForPlacedSymbol(this.icon, symbolInstance.placedIconSymbolIndex);
}
if (symbolInstance.verticalPlacedIconSymbolIndex >= 0) {
this.addIndicesForPlacedSymbol(this.icon, symbolInstance.verticalPlacedIconSymbolIndex);
}
}
if (this.text.indexBuffer) {
this.text.indexBuffer.updateData(this.text.indexArray);
}
if (this.icon.indexBuffer) {
this.icon.indexBuffer.updateData(this.icon.indexArray);
}
};
register('SymbolBucket', SymbolBucket, {
omit: [
'layers',
'collisionBoxArray',
'features',
'compareText'
]
});
SymbolBucket.MAX_GLYPHS = 65535;
SymbolBucket.addDynamicAttributes = addDynamicAttributes;
function resolveTokens(properties, text) {
return text.replace(/{([^{}]+)}/g, function (match, key) {
return key in properties ? String(properties[key]) : '';
});
}
var layout$7 = new Properties({
'symbol-placement': new DataConstantProperty(spec['layout_symbol']['symbol-placement']),
'symbol-spacing': new DataConstantProperty(spec['layout_symbol']['symbol-spacing']),
'symbol-avoid-edges': new DataConstantProperty(spec['layout_symbol']['symbol-avoid-edges']),
'symbol-sort-key': new DataDrivenProperty(spec['layout_symbol']['symbol-sort-key']),
'symbol-z-order': new DataConstantProperty(spec['layout_symbol']['symbol-z-order']),
'icon-allow-overlap': new DataConstantProperty(spec['layout_symbol']['icon-allow-overlap']),
'icon-ignore-placement': new DataConstantProperty(spec['layout_symbol']['icon-ignore-placement']),
'icon-optional': new DataConstantProperty(spec['layout_symbol']['icon-optional']),
'icon-rotation-alignment': new DataConstantProperty(spec['layout_symbol']['icon-rotation-alignment']),
'icon-size': new DataDrivenProperty(spec['layout_symbol']['icon-size']),
'icon-text-fit': new DataConstantProperty(spec['layout_symbol']['icon-text-fit']),
'icon-text-fit-padding': new DataConstantProperty(spec['layout_symbol']['icon-text-fit-padding']),
'icon-image': new DataDrivenProperty(spec['layout_symbol']['icon-image']),
'icon-rotate': new DataDrivenProperty(spec['layout_symbol']['icon-rotate']),
'icon-padding': new DataConstantProperty(spec['layout_symbol']['icon-padding']),
'icon-keep-upright': new DataConstantProperty(spec['layout_symbol']['icon-keep-upright']),
'icon-offset': new DataDrivenProperty(spec['layout_symbol']['icon-offset']),
'icon-anchor': new DataDrivenProperty(spec['layout_symbol']['icon-anchor']),
'icon-pitch-alignment': new DataConstantProperty(spec['layout_symbol']['icon-pitch-alignment']),
'text-pitch-alignment': new DataConstantProperty(spec['layout_symbol']['text-pitch-alignment']),
'text-rotation-alignment': new DataConstantProperty(spec['layout_symbol']['text-rotation-alignment']),
'text-field': new DataDrivenProperty(spec['layout_symbol']['text-field']),
'text-font': new DataDrivenProperty(spec['layout_symbol']['text-font']),
'text-size': new DataDrivenProperty(spec['layout_symbol']['text-size']),
'text-max-width': new DataDrivenProperty(spec['layout_symbol']['text-max-width']),
'text-line-height': new DataConstantProperty(spec['layout_symbol']['text-line-height']),
'text-letter-spacing': new DataDrivenProperty(spec['layout_symbol']['text-letter-spacing']),
'text-justify': new DataDrivenProperty(spec['layout_symbol']['text-justify']),
'text-radial-offset': new DataDrivenProperty(spec['layout_symbol']['text-radial-offset']),
'text-variable-anchor': new DataConstantProperty(spec['layout_symbol']['text-variable-anchor']),
'text-anchor': new DataDrivenProperty(spec['layout_symbol']['text-anchor']),
'text-max-angle': new DataConstantProperty(spec['layout_symbol']['text-max-angle']),
'text-writing-mode': new DataConstantProperty(spec['layout_symbol']['text-writing-mode']),
'text-rotate': new DataDrivenProperty(spec['layout_symbol']['text-rotate']),
'text-padding': new DataConstantProperty(spec['layout_symbol']['text-padding']),
'text-keep-upright': new DataConstantProperty(spec['layout_symbol']['text-keep-upright']),
'text-transform': new DataDrivenProperty(spec['layout_symbol']['text-transform']),
'text-offset': new DataDrivenProperty(spec['layout_symbol']['text-offset']),
'text-allow-overlap': new DataConstantProperty(spec['layout_symbol']['text-allow-overlap']),
'text-ignore-placement': new DataConstantProperty(spec['layout_symbol']['text-ignore-placement']),
'text-optional': new DataConstantProperty(spec['layout_symbol']['text-optional'])
});
var paint$7 = new Properties({
'icon-opacity': new DataDrivenProperty(spec['paint_symbol']['icon-opacity']),
'icon-color': new DataDrivenProperty(spec['paint_symbol']['icon-color']),
'icon-halo-color': new DataDrivenProperty(spec['paint_symbol']['icon-halo-color']),
'icon-halo-width': new DataDrivenProperty(spec['paint_symbol']['icon-halo-width']),
'icon-halo-blur': new DataDrivenProperty(spec['paint_symbol']['icon-halo-blur']),
'icon-translate': new DataConstantProperty(spec['paint_symbol']['icon-translate']),
'icon-translate-anchor': new DataConstantProperty(spec['paint_symbol']['icon-translate-anchor']),
'text-opacity': new DataDrivenProperty(spec['paint_symbol']['text-opacity']),
'text-color': new DataDrivenProperty(spec['paint_symbol']['text-color'], {
runtimeType: ColorType,
getOverride: function (o) {
return o.textColor;
},
hasOverride: function (o) {
return !!o.textColor;
}
}),
'text-halo-color': new DataDrivenProperty(spec['paint_symbol']['text-halo-color']),
'text-halo-width': new DataDrivenProperty(spec['paint_symbol']['text-halo-width']),
'text-halo-blur': new DataDrivenProperty(spec['paint_symbol']['text-halo-blur']),
'text-translate': new DataConstantProperty(spec['paint_symbol']['text-translate']),
'text-translate-anchor': new DataConstantProperty(spec['paint_symbol']['text-translate-anchor'])
});
var properties$6 = {
paint: paint$7,
layout: layout$7
};
var FormatSectionOverride = function FormatSectionOverride(defaultValue) {
this.type = defaultValue.property.overrides ? defaultValue.property.overrides.runtimeType : NullType;
this.defaultValue = defaultValue;
};
FormatSectionOverride.prototype.evaluate = function evaluate(ctx) {
if (ctx.formattedSection) {
var overrides = this.defaultValue.property.overrides;
if (overrides && overrides.hasOverride(ctx.formattedSection)) {
return overrides.getOverride(ctx.formattedSection);
}
}
if (ctx.feature && ctx.featureState) {
return this.defaultValue.evaluate(ctx.feature, ctx.featureState);
}
return this.defaultValue.property.specification.default;
};
FormatSectionOverride.prototype.eachChild = function eachChild(fn) {
if (!this.defaultValue.isConstant()) {
var expr = this.defaultValue.value;
fn(expr._styleExpression.expression);
}
};
FormatSectionOverride.prototype.outputDefined = function outputDefined() {
return false;
};
FormatSectionOverride.prototype.serialize = function serialize() {
return null;
};
register('FormatSectionOverride', FormatSectionOverride, { omit: ['defaultValue'] });
var SymbolStyleLayer = function (StyleLayer) {
function SymbolStyleLayer(layer) {
StyleLayer.call(this, layer, properties$6);
}
if (StyleLayer)
SymbolStyleLayer.__proto__ = StyleLayer;
SymbolStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
SymbolStyleLayer.prototype.constructor = SymbolStyleLayer;
SymbolStyleLayer.prototype.recalculate = function recalculate(parameters, availableImages) {
StyleLayer.prototype.recalculate.call(this, parameters, availableImages);
if (this.layout.get('icon-rotation-alignment') === 'auto') {
if (this.layout.get('symbol-placement') !== 'point') {
this.layout._values['icon-rotation-alignment'] = 'map';
} else {
this.layout._values['icon-rotation-alignment'] = 'viewport';
}
}
if (this.layout.get('text-rotation-alignment') === 'auto') {
if (this.layout.get('symbol-placement') !== 'point') {
this.layout._values['text-rotation-alignment'] = 'map';
} else {
this.layout._values['text-rotation-alignment'] = 'viewport';
}
}
if (this.layout.get('text-pitch-alignment') === 'auto') {
this.layout._values['text-pitch-alignment'] = this.layout.get('text-rotation-alignment');
}
if (this.layout.get('icon-pitch-alignment') === 'auto') {
this.layout._values['icon-pitch-alignment'] = this.layout.get('icon-rotation-alignment');
}
if (this.layout.get('symbol-placement') === 'point') {
var writingModes = this.layout.get('text-writing-mode');
if (writingModes) {
var deduped = [];
for (var i = 0, list = writingModes; i < list.length; i += 1) {
var m = list[i];
if (deduped.indexOf(m) < 0) {
deduped.push(m);
}
}
this.layout._values['text-writing-mode'] = deduped;
} else {
this.layout._values['text-writing-mode'] = ['horizontal'];
}
}
this._setPaintOverrides();
};
SymbolStyleLayer.prototype.getValueAndResolveTokens = function getValueAndResolveTokens(name, feature, canonical, availableImages) {
var value = this.layout.get(name).evaluate(feature, {}, canonical, availableImages);
var unevaluated = this._unevaluatedLayout._values[name];
if (!unevaluated.isDataDriven() && !isExpression(unevaluated.value) && value) {
return resolveTokens(feature.properties, value);
}
return value;
};
SymbolStyleLayer.prototype.createBucket = function createBucket(parameters) {
return new SymbolBucket(parameters);
};
SymbolStyleLayer.prototype.queryRadius = function queryRadius() {
return 0;
};
SymbolStyleLayer.prototype.queryIntersectsFeature = function queryIntersectsFeature() {
return false;
};
SymbolStyleLayer.prototype._setPaintOverrides = function _setPaintOverrides() {
for (var i = 0, list = properties$6.paint.overridableProperties; i < list.length; i += 1) {
var overridable = list[i];
if (!SymbolStyleLayer.hasPaintOverride(this.layout, overridable)) {
continue;
}
var overriden = this.paint.get(overridable);
var override = new FormatSectionOverride(overriden);
var styleExpression = new StyleExpression(override, overriden.property.specification);
var expression = null;
if (overriden.value.kind === 'constant' || overriden.value.kind === 'source') {
expression = new ZoomConstantExpression('source', styleExpression);
} else {
expression = new ZoomDependentExpression('composite', styleExpression, overriden.value.zoomStops, overriden.value._interpolationType);
}
this.paint._values[overridable] = new PossiblyEvaluatedPropertyValue(overriden.property, expression, overriden.parameters);
}
};
SymbolStyleLayer.prototype._handleOverridablePaintPropertyUpdate = function _handleOverridablePaintPropertyUpdate(name, oldValue, newValue) {
if (!this.layout || oldValue.isDataDriven() || newValue.isDataDriven()) {
return false;
}
return SymbolStyleLayer.hasPaintOverride(this.layout, name);
};
SymbolStyleLayer.hasPaintOverride = function hasPaintOverride(layout, propertyName) {
var textField = layout.get('text-field');
var property = properties$6.paint.properties[propertyName];
var hasOverrides = false;
var checkSections = function (sections) {
for (var i = 0, list = sections; i < list.length; i += 1) {
var section = list[i];
if (property.overrides && property.overrides.hasOverride(section)) {
hasOverrides = true;
return;
}
}
};
if (textField.value.kind === 'constant' && textField.value.value instanceof Formatted) {
checkSections(textField.value.value.sections);
} else if (textField.value.kind === 'source') {
var checkExpression = function (expression) {
if (hasOverrides) {
return;
}
if (expression instanceof Literal && typeOf(expression.value) === FormattedType) {
var formatted = expression.value;
checkSections(formatted.sections);
} else if (expression instanceof FormatExpression) {
checkSections(expression.sections);
} else {
expression.eachChild(checkExpression);
}
};
var expr = textField.value;
if (expr._styleExpression) {
checkExpression(expr._styleExpression.expression);
}
}
return hasOverrides;
};
return SymbolStyleLayer;
}(StyleLayer);
var paint$8 = new Properties({
'background-color': new DataConstantProperty(spec['paint_background']['background-color']),
'background-pattern': new CrossFadedProperty(spec['paint_background']['background-pattern']),
'background-opacity': new DataConstantProperty(spec['paint_background']['background-opacity'])
});
var properties$7 = { paint: paint$8 };
var BackgroundStyleLayer = function (StyleLayer) {
function BackgroundStyleLayer(layer) {
StyleLayer.call(this, layer, properties$7);
}
if (StyleLayer)
BackgroundStyleLayer.__proto__ = StyleLayer;
BackgroundStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
BackgroundStyleLayer.prototype.constructor = BackgroundStyleLayer;
return BackgroundStyleLayer;
}(StyleLayer);
var paint$9 = new Properties({
'raster-opacity': new DataConstantProperty(spec['paint_raster']['raster-opacity']),
'raster-hue-rotate': new DataConstantProperty(spec['paint_raster']['raster-hue-rotate']),
'raster-brightness-min': new DataConstantProperty(spec['paint_raster']['raster-brightness-min']),
'raster-brightness-max': new DataConstantProperty(spec['paint_raster']['raster-brightness-max']),
'raster-saturation': new DataConstantProperty(spec['paint_raster']['raster-saturation']),
'raster-contrast': new DataConstantProperty(spec['paint_raster']['raster-contrast']),
'raster-resampling': new DataConstantProperty(spec['paint_raster']['raster-resampling']),
'raster-fade-duration': new DataConstantProperty(spec['paint_raster']['raster-fade-duration'])
});
var properties$8 = { paint: paint$9 };
var RasterStyleLayer = function (StyleLayer) {
function RasterStyleLayer(layer) {
StyleLayer.call(this, layer, properties$8);
}
if (StyleLayer)
RasterStyleLayer.__proto__ = StyleLayer;
RasterStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
RasterStyleLayer.prototype.constructor = RasterStyleLayer;
return RasterStyleLayer;
}(StyleLayer);
function validateCustomStyleLayer(layerObject) {
var errors = [];
var id = layerObject.id;
if (id === undefined) {
errors.push({ message: 'layers.' + id + ': missing required property "id"' });
}
if (layerObject.render === undefined) {
errors.push({ message: 'layers.' + id + ': missing required method "render"' });
}
if (layerObject.renderingMode && layerObject.renderingMode !== '2d' && layerObject.renderingMode !== '3d') {
errors.push({ message: 'layers.' + id + ': property "renderingMode" must be either "2d" or "3d"' });
}
return errors;
}
var CustomStyleLayer = function (StyleLayer) {
function CustomStyleLayer(implementation) {
StyleLayer.call(this, implementation, {});
this.implementation = implementation;
}
if (StyleLayer)
CustomStyleLayer.__proto__ = StyleLayer;
CustomStyleLayer.prototype = Object.create(StyleLayer && StyleLayer.prototype);
CustomStyleLayer.prototype.constructor = CustomStyleLayer;
CustomStyleLayer.prototype.is3D = function is3D() {
return this.implementation.renderingMode === '3d';
};
CustomStyleLayer.prototype.hasOffscreenPass = function hasOffscreenPass() {
return this.implementation.prerender !== undefined;
};
CustomStyleLayer.prototype.recalculate = function recalculate() {
};
CustomStyleLayer.prototype.updateTransitions = function updateTransitions() {
};
CustomStyleLayer.prototype.hasTransition = function hasTransition() {
};
CustomStyleLayer.prototype.serialize = function serialize() {
};
CustomStyleLayer.prototype.onAdd = function onAdd(map) {
if (this.implementation.onAdd) {
this.implementation.onAdd(map, map.painter.context.gl);
}
};
CustomStyleLayer.prototype.onRemove = function onRemove(map) {
if (this.implementation.onRemove) {
this.implementation.onRemove(map, map.painter.context.gl);
}
};
return CustomStyleLayer;
}(StyleLayer);
var subclasses = {
circle: CircleStyleLayer,
heatmap: HeatmapStyleLayer,
hillshade: HillshadeStyleLayer,
fill: FillStyleLayer,
'fill-extrusion': FillExtrusionStyleLayer,
line: LineStyleLayer,
symbol: SymbolStyleLayer,
background: BackgroundStyleLayer,
raster: RasterStyleLayer
};
function createStyleLayer(layer) {
if (layer.type === 'custom') {
return new CustomStyleLayer(layer);
} else {
return new subclasses[layer.type](layer);
}
}
var HTMLImageElement = window$1.HTMLImageElement;
var HTMLCanvasElement = window$1.HTMLCanvasElement;
var HTMLVideoElement = window$1.HTMLVideoElement;
var ImageData$1 = window$1.ImageData;
var ImageBitmap$1 = window$1.ImageBitmap;
var Texture = function Texture(context, image, format, options) {
this.context = context;
this.format = format;
this.texture = context.gl.createTexture();
this.update(image, options);
};
Texture.prototype.update = function update(image, options, position) {
var width = image.width;
var height = image.height;
var resize = (!this.size || this.size[0] !== width || this.size[1] !== height) && !position;
var ref = this;
var context = ref.context;
var gl = context.gl;
this.useMipmap = Boolean(options && options.useMipmap);
gl.bindTexture(gl.TEXTURE_2D, this.texture);
context.pixelStoreUnpackFlipY.set(false);
context.pixelStoreUnpack.set(1);
context.pixelStoreUnpackPremultiplyAlpha.set(this.format === gl.RGBA && (!options || options.premultiply !== false));
if (resize) {
this.size = [
width,
height
];
if (image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof HTMLVideoElement || image instanceof ImageData$1 || ImageBitmap$1 && image instanceof ImageBitmap$1) {
gl.texImage2D(gl.TEXTURE_2D, 0, this.format, this.format, gl.UNSIGNED_BYTE, image);
} else {
gl.texImage2D(gl.TEXTURE_2D, 0, this.format, width, height, 0, this.format, gl.UNSIGNED_BYTE, image.data);
}
} else {
var ref$1 = position || {
x: 0,
y: 0
};
var x = ref$1.x;
var y = ref$1.y;
if (image instanceof HTMLImageElement || image instanceof HTMLCanvasElement || image instanceof HTMLVideoElement || image instanceof ImageData$1 || ImageBitmap$1 && image instanceof ImageBitmap$1) {
gl.texSubImage2D(gl.TEXTURE_2D, 0, x, y, gl.RGBA, gl.UNSIGNED_BYTE, image);
} else {
gl.texSubImage2D(gl.TEXTURE_2D, 0, x, y, width, height, gl.RGBA, gl.UNSIGNED_BYTE, image.data);
}
}
if (this.useMipmap && this.isSizePowerOfTwo()) {
gl.generateMipmap(gl.TEXTURE_2D);
}
};
Texture.prototype.bind = function bind(filter, wrap, minFilter) {
var ref = this;
var context = ref.context;
var gl = context.gl;
gl.bindTexture(gl.TEXTURE_2D, this.texture);
if (minFilter === gl.LINEAR_MIPMAP_NEAREST && !this.isSizePowerOfTwo()) {
minFilter = gl.LINEAR;
}
if (filter !== this.filter) {
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, minFilter || filter);
this.filter = filter;
}
if (wrap !== this.wrap) {
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrap);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrap);
this.wrap = wrap;
}
};
Texture.prototype.isSizePowerOfTwo = function isSizePowerOfTwo() {
return this.size[0] === this.size[1] && Math.log(this.size[0]) / Math.LN2 % 1 === 0;
};
Texture.prototype.destroy = function destroy() {
var ref = this.context;
var gl = ref.gl;
gl.deleteTexture(this.texture);
this.texture = null;
};
var ThrottledInvoker = function ThrottledInvoker(callback) {
var this$1 = this;
this._callback = callback;
this._triggered = false;
if (typeof MessageChannel !== 'undefined') {
this._channel = new MessageChannel();
this._channel.port2.onmessage = function () {
this$1._triggered = false;
this$1._callback();
};
}
};
ThrottledInvoker.prototype.trigger = function trigger() {
var this$1 = this;
if (!this._triggered) {
this._triggered = true;
if (this._channel) {
this._channel.port1.postMessage(true);
} else {
setTimeout(function () {
this$1._triggered = false;
this$1._callback();
}, 0);
}
}
};
ThrottledInvoker.prototype.remove = function remove() {
delete this._channel;
this._callback = function () {
};
};
var Actor = function Actor(target, parent, mapId) {
this.target = target;
this.parent = parent;
this.mapId = mapId;
this.callbacks = {};
this.tasks = {};
this.taskQueue = [];
this.cancelCallbacks = {};
bindAll([
'receive',
'process'
], this);
this.invoker = new ThrottledInvoker(this.process);
this.target.addEventListener('message', this.receive, false);
this.globalScope = isWorker() ? target : window$1;
};
Actor.prototype.send = function send(type, data, callback, targetMapId, mustQueue) {
var this$1 = this;
if (mustQueue === void 0)
mustQueue = false;
var id = Math.round(Math.random() * 1000000000000000000).toString(36).substring(0, 10);
if (callback) {
this.callbacks[id] = callback;
}
var buffers = isSafari(this.globalScope) ? undefined : [];
this.target.postMessage({
id: id,
type: type,
hasCallback: !!callback,
targetMapId: targetMapId,
mustQueue: mustQueue,
sourceMapId: this.mapId,
data: serialize(data, buffers)
}, buffers);
return {
cancel: function () {
if (callback) {
delete this$1.callbacks[id];
}
this$1.target.postMessage({
id: id,
type: '
',
targetMapId: targetMapId,
sourceMapId: this$1.mapId
});
}
};
};
Actor.prototype.receive = function receive(message) {
var data = message.data, id = data.id;
if (!id) {
return;
}
if (data.targetMapId && this.mapId !== data.targetMapId) {
return;
}
if (data.type === '') {
delete this.tasks[id];
var cancel = this.cancelCallbacks[id];
delete this.cancelCallbacks[id];
if (cancel) {
cancel();
}
} else {
if (isWorker() || data.mustQueue) {
this.tasks[id] = data;
this.taskQueue.push(id);
this.invoker.trigger();
} else {
this.processTask(id, data);
}
}
};
Actor.prototype.process = function process() {
if (!this.taskQueue.length) {
return;
}
var id = this.taskQueue.shift();
var task = this.tasks[id];
delete this.tasks[id];
if (this.taskQueue.length) {
this.invoker.trigger();
}
if (!task) {
return;
}
this.processTask(id, task);
};
Actor.prototype.processTask = function processTask(id, task) {
var this$1 = this;
if (task.type === '') {
var callback = this.callbacks[id];
delete this.callbacks[id];
if (callback) {
if (task.error) {
callback(deserialize(task.error));
} else {
callback(null, deserialize(task.data));
}
}
} else {
var completed = false;
var buffers = isSafari(this.globalScope) ? undefined : [];
var done = task.hasCallback ? function (err, data) {
completed = true;
delete this$1.cancelCallbacks[id];
this$1.target.postMessage({
id: id,
type: '',
sourceMapId: this$1.mapId,
error: err ? serialize(err) : null,
data: serialize(data, buffers)
}, buffers);
} : function (_) {
completed = true;
};
var callback$1 = null;
var params = deserialize(task.data);
if (this.parent[task.type]) {
callback$1 = this.parent[task.type](task.sourceMapId, params, done);
} else if (this.parent.getWorkerSource) {
var keys = task.type.split('.');
var scope = this.parent.getWorkerSource(task.sourceMapId, keys[0], params.source);
callback$1 = scope[keys[1]](params, done);
} else {
done(new Error('Could not find function ' + task.type));
}
if (!completed && callback$1 && callback$1.cancel) {
this.cancelCallbacks[id] = callback$1.cancel;
}
}
};
Actor.prototype.remove = function remove() {
this.invoker.remove();
this.target.removeEventListener('message', this.receive, false);
};
/**
* getTileBBox
*
* @param {Number} x Tile coordinate x
* @param {Number} y Tile coordinate y
* @param {Number} z Tile zoom
* @returns {String} String of the bounding box
*/
function getTileBBox(x, y, z) {
// for Google/OSM tile scheme we need to alter the y
y = (Math.pow(2, z) - y - 1);
var min = getMercCoords(x * 256, y * 256, z),
max = getMercCoords((x + 1) * 256, (y + 1) * 256, z);
return min[0] + ',' + min[1] + ',' + max[0] + ',' + max[1];
}
/**
* getMercCoords
*
* @param {Number} x Pixel coordinate x
* @param {Number} y Pixel coordinate y
* @param {Number} z Tile zoom
* @returns {Array} [x, y]
*/
function getMercCoords(x, y, z) {
var resolution = (2 * Math.PI * 6378137 / 256) / Math.pow(2, z),
merc_x = (x * resolution - 2 * Math.PI * 6378137 / 2.0),
merc_y = (y * resolution - 2 * Math.PI * 6378137 / 2.0);
return [merc_x, merc_y];
}
var LngLatBounds = function LngLatBounds(sw, ne) {
if (!sw) ; else if (ne) {
this.setSouthWest(sw).setNorthEast(ne);
} else if (sw.length === 4) {
this.setSouthWest([
sw[0],
sw[1]
]).setNorthEast([
sw[2],
sw[3]
]);
} else {
this.setSouthWest(sw[0]).setNorthEast(sw[1]);
}
};
LngLatBounds.prototype.setNorthEast = function setNorthEast(ne) {
this._ne = ne instanceof LngLat ? new LngLat(ne.lng, ne.lat) : LngLat.convert(ne);
return this;
};
LngLatBounds.prototype.setSouthWest = function setSouthWest(sw) {
this._sw = sw instanceof LngLat ? new LngLat(sw.lng, sw.lat) : LngLat.convert(sw);
return this;
};
LngLatBounds.prototype.extend = function extend(obj) {
var sw = this._sw, ne = this._ne;
var sw2, ne2;
if (obj instanceof LngLat) {
sw2 = obj;
ne2 = obj;
} else if (obj instanceof LngLatBounds) {
sw2 = obj._sw;
ne2 = obj._ne;
if (!sw2 || !ne2) {
return this;
}
} else {
if (Array.isArray(obj)) {
if (obj.length === 4 || obj.every(Array.isArray)) {
var lngLatBoundsObj = obj;
return this.extend(LngLatBounds.convert(lngLatBoundsObj));
} else {
var lngLatObj = obj;
return this.extend(LngLat.convert(lngLatObj));
}
}
return this;
}
if (!sw && !ne) {
this._sw = new LngLat(sw2.lng, sw2.lat);
this._ne = new LngLat(ne2.lng, ne2.lat);
} else {
sw.lng = Math.min(sw2.lng, sw.lng);
sw.lat = Math.min(sw2.lat, sw.lat);
ne.lng = Math.max(ne2.lng, ne.lng);
ne.lat = Math.max(ne2.lat, ne.lat);
}
return this;
};
LngLatBounds.prototype.getCenter = function getCenter() {
return new LngLat((this._sw.lng + this._ne.lng) / 2, (this._sw.lat + this._ne.lat) / 2);
};
LngLatBounds.prototype.getSouthWest = function getSouthWest() {
return this._sw;
};
LngLatBounds.prototype.getNorthEast = function getNorthEast() {
return this._ne;
};
LngLatBounds.prototype.getNorthWest = function getNorthWest() {
return new LngLat(this.getWest(), this.getNorth());
};
LngLatBounds.prototype.getSouthEast = function getSouthEast() {
return new LngLat(this.getEast(), this.getSouth());
};
LngLatBounds.prototype.getWest = function getWest() {
return this._sw.lng;
};
LngLatBounds.prototype.getSouth = function getSouth() {
return this._sw.lat;
};
LngLatBounds.prototype.getEast = function getEast() {
return this._ne.lng;
};
LngLatBounds.prototype.getNorth = function getNorth() {
return this._ne.lat;
};
LngLatBounds.prototype.toArray = function toArray() {
return [
this._sw.toArray(),
this._ne.toArray()
];
};
LngLatBounds.prototype.toString = function toString() {
return 'LngLatBounds(' + this._sw.toString() + ', ' + this._ne.toString() + ')';
};
LngLatBounds.prototype.isEmpty = function isEmpty() {
return !(this._sw && this._ne);
};
LngLatBounds.prototype.contains = function contains(lnglat) {
var ref = LngLat.convert(lnglat);
var lng = ref.lng;
var lat = ref.lat;
var containsLatitude = this._sw.lat <= lat && lat <= this._ne.lat;
var containsLongitude = this._sw.lng <= lng && lng <= this._ne.lng;
if (this._sw.lng > this._ne.lng) {
containsLongitude = this._sw.lng >= lng && lng >= this._ne.lng;
}
return containsLatitude && containsLongitude;
};
LngLatBounds.convert = function convert(input) {
if (!input || input instanceof LngLatBounds) {
return input;
}
return new LngLatBounds(input);
};
var earthRadius = 6371008.8;
var LngLat = function LngLat(lng, lat) {
if (isNaN(lng) || isNaN(lat)) {
throw new Error('Invalid LngLat object: (' + lng + ', ' + lat + ')');
}
this.lng = +lng;
this.lat = +lat;
if (this.lat > 90 || this.lat < -90) {
throw new Error('Invalid LngLat latitude value: must be between -90 and 90');
}
};
LngLat.prototype.wrap = function wrap$1() {
return new LngLat(wrap(this.lng, -180, 180), this.lat);
};
LngLat.prototype.toArray = function toArray() {
return [
this.lng,
this.lat
];
};
LngLat.prototype.toString = function toString() {
return 'LngLat(' + this.lng + ', ' + this.lat + ')';
};
LngLat.prototype.distanceTo = function distanceTo(lngLat) {
var rad = Math.PI / 180;
var lat1 = this.lat * rad;
var lat2 = lngLat.lat * rad;
var a = Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos((lngLat.lng - this.lng) * rad);
var maxMeters = earthRadius * Math.acos(Math.min(a, 1));
return maxMeters;
};
LngLat.prototype.toBounds = function toBounds(radius) {
if (radius === void 0)
radius = 0;
var earthCircumferenceInMetersAtEquator = 40075017;
var latAccuracy = 360 * radius / earthCircumferenceInMetersAtEquator, lngAccuracy = latAccuracy / Math.cos(Math.PI / 180 * this.lat);
return new LngLatBounds(new LngLat(this.lng - lngAccuracy, this.lat - latAccuracy), new LngLat(this.lng + lngAccuracy, this.lat + latAccuracy));
};
LngLat.convert = function convert(input) {
if (input instanceof LngLat) {
return input;
}
if (Array.isArray(input) && (input.length === 2 || input.length === 3)) {
return new LngLat(Number(input[0]), Number(input[1]));
}
if (!Array.isArray(input) && typeof input === 'object' && input !== null) {
return new LngLat(Number('lng' in input ? input.lng : input.lon), Number(input.lat));
}
throw new Error('`LngLatLike` argument must be specified as a LngLat instance, an object {lng: , lat: }, an object {lon: , lat: }, or an array of [, ]');
};
var earthCircumfrence = 2 * Math.PI * earthRadius;
function circumferenceAtLatitude(latitude) {
return earthCircumfrence * Math.cos(latitude * Math.PI / 180);
}
function mercatorXfromLng$1(lng) {
return (180 + lng) / 360;
}
function mercatorYfromLat$1(lat) {
return (180 - 180 / Math.PI * Math.log(Math.tan(Math.PI / 4 + lat * Math.PI / 360))) / 360;
}
function mercatorZfromAltitude(altitude, lat) {
return altitude / circumferenceAtLatitude(lat);
}
function lngFromMercatorX(x) {
return x * 360 - 180;
}
function latFromMercatorY(y) {
var y2 = 180 - y * 360;
return 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
}
function altitudeFromMercatorZ(z, y) {
return z * circumferenceAtLatitude(latFromMercatorY(y));
}
function mercatorScale(lat) {
return 1 / Math.cos(lat * Math.PI / 180);
}
var MercatorCoordinate = function MercatorCoordinate(x, y, z) {
if (z === void 0)
z = 0;
this.x = +x;
this.y = +y;
this.z = +z;
};
MercatorCoordinate.fromLngLat = function fromLngLat(lngLatLike, altitude) {
if (altitude === void 0)
altitude = 0;
var lngLat = LngLat.convert(lngLatLike);
return new MercatorCoordinate(mercatorXfromLng$1(lngLat.lng), mercatorYfromLat$1(lngLat.lat), mercatorZfromAltitude(altitude, lngLat.lat));
};
MercatorCoordinate.prototype.toLngLat = function toLngLat() {
return new LngLat(lngFromMercatorX(this.x), latFromMercatorY(this.y));
};
MercatorCoordinate.prototype.toAltitude = function toAltitude() {
return altitudeFromMercatorZ(this.z, this.y);
};
MercatorCoordinate.prototype.meterInMercatorCoordinateUnits = function meterInMercatorCoordinateUnits() {
return 1 / earthCircumfrence * mercatorScale(latFromMercatorY(this.y));
};
var CanonicalTileID = function CanonicalTileID(z, x, y) {
this.z = z;
this.x = x;
this.y = y;
this.key = calculateKey(0, z, z, x, y);
};
CanonicalTileID.prototype.equals = function equals(id) {
return this.z === id.z && this.x === id.x && this.y === id.y;
};
CanonicalTileID.prototype.url = function url(urls, scheme) {
var bbox = getTileBBox(this.x, this.y, this.z);
var quadkey = getQuadkey(this.z, this.x, this.y);
return urls[(this.x + this.y) % urls.length].replace('{prefix}', (this.x % 16).toString(16) + (this.y % 16).toString(16)).replace('{z}', String(this.z)).replace('{x}', String(this.x)).replace('{y}', String(scheme === 'tms' ? Math.pow(2, this.z) - this.y - 1 : this.y)).replace('{quadkey}', quadkey).replace('{bbox-epsg-3857}', bbox);
};
CanonicalTileID.prototype.getTilePoint = function getTilePoint(coord) {
var tilesAtZoom = Math.pow(2, this.z);
return new pointGeometry((coord.x * tilesAtZoom - this.x) * EXTENT$1, (coord.y * tilesAtZoom - this.y) * EXTENT$1);
};
CanonicalTileID.prototype.toString = function toString() {
return this.z + '/' + this.x + '/' + this.y;
};
var UnwrappedTileID = function UnwrappedTileID(wrap, canonical) {
this.wrap = wrap;
this.canonical = canonical;
this.key = calculateKey(wrap, canonical.z, canonical.z, canonical.x, canonical.y);
};
var OverscaledTileID = function OverscaledTileID(overscaledZ, wrap, z, x, y) {
this.overscaledZ = overscaledZ;
this.wrap = wrap;
this.canonical = new CanonicalTileID(z, +x, +y);
this.key = calculateKey(wrap, overscaledZ, z, x, y);
};
OverscaledTileID.prototype.equals = function equals(id) {
return this.overscaledZ === id.overscaledZ && this.wrap === id.wrap && this.canonical.equals(id.canonical);
};
OverscaledTileID.prototype.scaledTo = function scaledTo(targetZ) {
var zDifference = this.canonical.z - targetZ;
if (targetZ > this.canonical.z) {
return new OverscaledTileID(targetZ, this.wrap, this.canonical.z, this.canonical.x, this.canonical.y);
} else {
return new OverscaledTileID(targetZ, this.wrap, targetZ, this.canonical.x >> zDifference, this.canonical.y >> zDifference);
}
};
OverscaledTileID.prototype.calculateScaledKey = function calculateScaledKey(targetZ, withWrap) {
var zDifference = this.canonical.z - targetZ;
if (targetZ > this.canonical.z) {
return calculateKey(this.wrap * +withWrap, targetZ, this.canonical.z, this.canonical.x, this.canonical.y);
} else {
return calculateKey(this.wrap * +withWrap, targetZ, targetZ, this.canonical.x >> zDifference, this.canonical.y >> zDifference);
}
};
OverscaledTileID.prototype.isChildOf = function isChildOf(parent) {
if (parent.wrap !== this.wrap) {
return false;
}
var zDifference = this.canonical.z - parent.canonical.z;
return parent.overscaledZ === 0 || parent.overscaledZ < this.overscaledZ && parent.canonical.x === this.canonical.x >> zDifference && parent.canonical.y === this.canonical.y >> zDifference;
};
OverscaledTileID.prototype.children = function children(sourceMaxZoom) {
if (this.overscaledZ >= sourceMaxZoom) {
return [new OverscaledTileID(this.overscaledZ + 1, this.wrap, this.canonical.z, this.canonical.x, this.canonical.y)];
}
var z = this.canonical.z + 1;
var x = this.canonical.x * 2;
var y = this.canonical.y * 2;
return [
new OverscaledTileID(z, this.wrap, z, x, y),
new OverscaledTileID(z, this.wrap, z, x + 1, y),
new OverscaledTileID(z, this.wrap, z, x, y + 1),
new OverscaledTileID(z, this.wrap, z, x + 1, y + 1)
];
};
OverscaledTileID.prototype.isLessThan = function isLessThan(rhs) {
if (this.wrap < rhs.wrap) {
return true;
}
if (this.wrap > rhs.wrap) {
return false;
}
if (this.overscaledZ < rhs.overscaledZ) {
return true;
}
if (this.overscaledZ > rhs.overscaledZ) {
return false;
}
if (this.canonical.x < rhs.canonical.x) {
return true;
}
if (this.canonical.x > rhs.canonical.x) {
return false;
}
if (this.canonical.y < rhs.canonical.y) {
return true;
}
return false;
};
OverscaledTileID.prototype.wrapped = function wrapped() {
return new OverscaledTileID(this.overscaledZ, 0, this.canonical.z, this.canonical.x, this.canonical.y);
};
OverscaledTileID.prototype.unwrapTo = function unwrapTo(wrap) {
return new OverscaledTileID(this.overscaledZ, wrap, this.canonical.z, this.canonical.x, this.canonical.y);
};
OverscaledTileID.prototype.overscaleFactor = function overscaleFactor() {
return Math.pow(2, this.overscaledZ - this.canonical.z);
};
OverscaledTileID.prototype.toUnwrapped = function toUnwrapped() {
return new UnwrappedTileID(this.wrap, this.canonical);
};
OverscaledTileID.prototype.toString = function toString() {
return this.overscaledZ + '/' + this.canonical.x + '/' + this.canonical.y;
};
OverscaledTileID.prototype.getTilePoint = function getTilePoint(coord) {
return this.canonical.getTilePoint(new MercatorCoordinate(coord.x - this.wrap, coord.y));
};
function calculateKey(wrap, overscaledZ, z, x, y) {
wrap *= 2;
if (wrap < 0) {
wrap = wrap * -1 - 1;
}
var dim = 1 << z;
return (dim * dim * wrap + dim * y + x).toString(36) + z.toString(36) + overscaledZ.toString(36);
}
function getQuadkey(z, x, y) {
var quadkey = '', mask;
for (var i = z; i > 0; i--) {
mask = 1 << i - 1;
quadkey += (x & mask ? 1 : 0) + (y & mask ? 2 : 0);
}
return quadkey;
}
register('CanonicalTileID', CanonicalTileID);
register('OverscaledTileID', OverscaledTileID, { omit: ['posMatrix'] });
var DEMData = function DEMData(uid, data, encoding) {
this.uid = uid;
if (data.height !== data.width) {
throw new RangeError('DEM tiles must be square');
}
if (encoding && encoding !== 'mapbox' && encoding !== 'terrarium') {
return warnOnce('"' + encoding + '" is not a valid encoding type. Valid types include "mapbox" and "terrarium".');
}
this.stride = data.height;
var dim = this.dim = data.height - 2;
this.data = new Uint32Array(data.data.buffer);
this.encoding = encoding || 'mapbox';
for (var x = 0; x < dim; x++) {
this.data[this._idx(-1, x)] = this.data[this._idx(0, x)];
this.data[this._idx(dim, x)] = this.data[this._idx(dim - 1, x)];
this.data[this._idx(x, -1)] = this.data[this._idx(x, 0)];
this.data[this._idx(x, dim)] = this.data[this._idx(x, dim - 1)];
}
this.data[this._idx(-1, -1)] = this.data[this._idx(0, 0)];
this.data[this._idx(dim, -1)] = this.data[this._idx(dim - 1, 0)];
this.data[this._idx(-1, dim)] = this.data[this._idx(0, dim - 1)];
this.data[this._idx(dim, dim)] = this.data[this._idx(dim - 1, dim - 1)];
};
DEMData.prototype.get = function get(x, y) {
var pixels = new Uint8Array(this.data.buffer);
var index = this._idx(x, y) * 4;
var unpack = this.encoding === 'terrarium' ? this._unpackTerrarium : this._unpackMapbox;
return unpack(pixels[index], pixels[index + 1], pixels[index + 2]);
};
DEMData.prototype.getUnpackVector = function getUnpackVector() {
return this.encoding === 'terrarium' ? [
256,
1,
1 / 256,
32768
] : [
6553.6,
25.6,
0.1,
10000
];
};
DEMData.prototype._idx = function _idx(x, y) {
if (x < -1 || x >= this.dim + 1 || y < -1 || y >= this.dim + 1) {
throw new RangeError('out of range source coordinates for DEM data');
}
return (y + 1) * this.stride + (x + 1);
};
DEMData.prototype._unpackMapbox = function _unpackMapbox(r, g, b) {
return (r * 256 * 256 + g * 256 + b) / 10 - 10000;
};
DEMData.prototype._unpackTerrarium = function _unpackTerrarium(r, g, b) {
return r * 256 + g + b / 256 - 32768;
};
DEMData.prototype.getPixels = function getPixels() {
return new RGBAImage({
width: this.stride,
height: this.stride
}, new Uint8Array(this.data.buffer));
};
DEMData.prototype.backfillBorder = function backfillBorder(borderTile, dx, dy) {
if (this.dim !== borderTile.dim) {
throw new Error('dem dimension mismatch');
}
var xMin = dx * this.dim, xMax = dx * this.dim + this.dim, yMin = dy * this.dim, yMax = dy * this.dim + this.dim;
switch (dx) {
case -1:
xMin = xMax - 1;
break;
case 1:
xMax = xMin + 1;
break;
}
switch (dy) {
case -1:
yMin = yMax - 1;
break;
case 1:
yMax = yMin + 1;
break;
}
var ox = -dx * this.dim;
var oy = -dy * this.dim;
for (var y = yMin; y < yMax; y++) {
for (var x = xMin; x < xMax; x++) {
this.data[this._idx(x, y)] = borderTile.data[this._idx(x + ox, y + oy)];
}
}
};
register('DEMData', DEMData);
function deserialize$1(input, style) {
var output = {};
if (!style) {
return output;
}
var loop = function () {
var bucket = list$1[i$1];
var layers = bucket.layerIds.map(function (id) {
return style.getLayer(id);
}).filter(Boolean);
if (layers.length === 0) {
return;
}
bucket.layers = layers;
if (bucket.stateDependentLayerIds) {
bucket.stateDependentLayers = bucket.stateDependentLayerIds.map(function (lId) {
return layers.filter(function (l) {
return l.id === lId;
})[0];
});
}
for (var i = 0, list = layers; i < list.length; i += 1) {
var layer = list[i];
output[layer.id] = bucket;
}
};
for (var i$1 = 0, list$1 = input; i$1 < list$1.length; i$1 += 1)
loop();
return output;
}
var DictionaryCoder = function DictionaryCoder(strings) {
this._stringToNumber = {};
this._numberToString = [];
for (var i = 0; i < strings.length; i++) {
var string = strings[i];
this._stringToNumber[string] = i;
this._numberToString[i] = string;
}
};
DictionaryCoder.prototype.encode = function encode(string) {
return this._stringToNumber[string];
};
DictionaryCoder.prototype.decode = function decode(n) {
return this._numberToString[n];
};
var Feature = function Feature(vectorTileFeature, z, x, y, id) {
this.type = 'Feature';
this._vectorTileFeature = vectorTileFeature;
vectorTileFeature._z = z;
vectorTileFeature._x = x;
vectorTileFeature._y = y;
this.properties = vectorTileFeature.properties;
this.id = id;
};
var prototypeAccessors$1 = { geometry: { configurable: true } };
prototypeAccessors$1.geometry.get = function () {
if (this._geometry === undefined) {
this._geometry = this._vectorTileFeature.toGeoJSON(this._vectorTileFeature._x, this._vectorTileFeature._y, this._vectorTileFeature._z).geometry;
}
return this._geometry;
};
prototypeAccessors$1.geometry.set = function (g) {
this._geometry = g;
};
Feature.prototype.toJSON = function toJSON() {
var json = { geometry: this.geometry };
for (var i in this) {
if (i === '_geometry' || i === '_vectorTileFeature') {
continue;
}
json[i] = this[i];
}
return json;
};
Object.defineProperties(Feature.prototype, prototypeAccessors$1);
var SourceFeatureState = function SourceFeatureState() {
this.state = {};
this.stateChanges = {};
this.deletedStates = {};
};
SourceFeatureState.prototype.updateState = function updateState(sourceLayer, featureId, newState) {
var feature = String(featureId);
this.stateChanges[sourceLayer] = this.stateChanges[sourceLayer] || {};
this.stateChanges[sourceLayer][feature] = this.stateChanges[sourceLayer][feature] || {};
extend(this.stateChanges[sourceLayer][feature], newState);
if (this.deletedStates[sourceLayer] === null) {
this.deletedStates[sourceLayer] = {};
for (var ft in this.state[sourceLayer]) {
if (ft !== feature) {
this.deletedStates[sourceLayer][ft] = null;
}
}
} else {
var featureDeletionQueued = this.deletedStates[sourceLayer] && this.deletedStates[sourceLayer][feature] === null;
if (featureDeletionQueued) {
this.deletedStates[sourceLayer][feature] = {};
for (var prop in this.state[sourceLayer][feature]) {
if (!newState[prop]) {
this.deletedStates[sourceLayer][feature][prop] = null;
}
}
} else {
for (var key in newState) {
var deletionInQueue = this.deletedStates[sourceLayer] && this.deletedStates[sourceLayer][feature] && this.deletedStates[sourceLayer][feature][key] === null;
if (deletionInQueue) {
delete this.deletedStates[sourceLayer][feature][key];
}
}
}
}
};
SourceFeatureState.prototype.removeFeatureState = function removeFeatureState(sourceLayer, featureId, key) {
var sourceLayerDeleted = this.deletedStates[sourceLayer] === null;
if (sourceLayerDeleted) {
return;
}
var feature = String(featureId);
this.deletedStates[sourceLayer] = this.deletedStates[sourceLayer] || {};
if (key && featureId !== undefined) {
if (this.deletedStates[sourceLayer][feature] !== null) {
this.deletedStates[sourceLayer][feature] = this.deletedStates[sourceLayer][feature] || {};
this.deletedStates[sourceLayer][feature][key] = null;
}
} else if (featureId !== undefined) {
var updateInQueue = this.stateChanges[sourceLayer] && this.stateChanges[sourceLayer][feature];
if (updateInQueue) {
this.deletedStates[sourceLayer][feature] = {};
for (key in this.stateChanges[sourceLayer][feature]) {
this.deletedStates[sourceLayer][feature][key] = null;
}
} else {
this.deletedStates[sourceLayer][feature] = null;
}
} else {
this.deletedStates[sourceLayer] = null;
}
};
SourceFeatureState.prototype.getState = function getState(sourceLayer, featureId) {
var feature = String(featureId);
var base = this.state[sourceLayer] || {};
var changes = this.stateChanges[sourceLayer] || {};
var reconciledState = extend({}, base[feature], changes[feature]);
if (this.deletedStates[sourceLayer] === null) {
return {};
} else if (this.deletedStates[sourceLayer]) {
var featureDeletions = this.deletedStates[sourceLayer][featureId];
if (featureDeletions === null) {
return {};
}
for (var prop in featureDeletions) {
delete reconciledState[prop];
}
}
return reconciledState;
};
SourceFeatureState.prototype.initializeTileState = function initializeTileState(tile, painter) {
tile.setFeatureState(this.state, painter);
};
SourceFeatureState.prototype.coalesceChanges = function coalesceChanges(tiles, painter) {
var featuresChanged = {};
for (var sourceLayer in this.stateChanges) {
this.state[sourceLayer] = this.state[sourceLayer] || {};
var layerStates = {};
for (var feature in this.stateChanges[sourceLayer]) {
if (!this.state[sourceLayer][feature]) {
this.state[sourceLayer][feature] = {};
}
extend(this.state[sourceLayer][feature], this.stateChanges[sourceLayer][feature]);
layerStates[feature] = this.state[sourceLayer][feature];
}
featuresChanged[sourceLayer] = layerStates;
}
for (var sourceLayer$1 in this.deletedStates) {
this.state[sourceLayer$1] = this.state[sourceLayer$1] || {};
var layerStates$1 = {};
if (this.deletedStates[sourceLayer$1] === null) {
for (var ft in this.state[sourceLayer$1]) {
layerStates$1[ft] = {};
this.state[sourceLayer$1][ft] = {};
}
} else {
for (var feature$1 in this.deletedStates[sourceLayer$1]) {
var deleteWholeFeatureState = this.deletedStates[sourceLayer$1][feature$1] === null;
if (deleteWholeFeatureState) {
this.state[sourceLayer$1][feature$1] = {};
} else {
for (var i = 0, list = Object.keys(this.deletedStates[sourceLayer$1][feature$1]); i < list.length; i += 1) {
var key = list[i];
delete this.state[sourceLayer$1][feature$1][key];
}
}
layerStates$1[feature$1] = this.state[sourceLayer$1][feature$1];
}
}
featuresChanged[sourceLayer$1] = featuresChanged[sourceLayer$1] || {};
extend(featuresChanged[sourceLayer$1], layerStates$1);
}
this.stateChanges = {};
this.deletedStates = {};
if (Object.keys(featuresChanged).length === 0) {
return;
}
for (var id in tiles) {
var tile = tiles[id];
tile.setFeatureState(featuresChanged, painter);
}
};
var FeatureIndex = function FeatureIndex(tileID, promoteId) {
this.tileID = tileID;
this.x = tileID.canonical.x;
this.y = tileID.canonical.y;
this.z = tileID.canonical.z;
this.grid = new gridIndex(EXTENT$1, 16, 0);
this.grid3D = new gridIndex(EXTENT$1, 16, 0);
this.featureIndexArray = new FeatureIndexArray();
this.promoteId = promoteId;
};
FeatureIndex.prototype.insert = function insert(feature, geometry, featureIndex, sourceLayerIndex, bucketIndex, is3D) {
var key = this.featureIndexArray.length;
this.featureIndexArray.emplaceBack(featureIndex, sourceLayerIndex, bucketIndex);
var grid = is3D ? this.grid3D : this.grid;
for (var r = 0; r < geometry.length; r++) {
var ring = geometry[r];
var bbox = [
Infinity,
Infinity,
-Infinity,
-Infinity
];
for (var i = 0; i < ring.length; i++) {
var p = ring[i];
bbox[0] = Math.min(bbox[0], p.x);
bbox[1] = Math.min(bbox[1], p.y);
bbox[2] = Math.max(bbox[2], p.x);
bbox[3] = Math.max(bbox[3], p.y);
}
if (bbox[0] < EXTENT$1 && bbox[1] < EXTENT$1 && bbox[2] >= 0 && bbox[3] >= 0) {
grid.insert(key, bbox[0], bbox[1], bbox[2], bbox[3]);
}
}
};
FeatureIndex.prototype.loadVTLayers = function loadVTLayers() {
if (!this.vtLayers) {
this.vtLayers = new vectorTile.VectorTile(new pbf(this.rawTileData)).layers;
this.sourceLayerCoder = new DictionaryCoder(this.vtLayers ? Object.keys(this.vtLayers).sort() : ['_geojsonTileLayer']);
}
return this.vtLayers;
};
FeatureIndex.prototype.query = function query(args, styleLayers, serializedLayers, sourceFeatureState) {
var this$1 = this;
this.loadVTLayers();
var params = args.params || {}, pixelsToTileUnits = EXTENT$1 / args.tileSize / args.scale, filter = createFilter(params.filter);
var queryGeometry = args.queryGeometry;
var queryPadding = args.queryPadding * pixelsToTileUnits;
var bounds = getBounds(queryGeometry);
var matching = this.grid.query(bounds.minX - queryPadding, bounds.minY - queryPadding, bounds.maxX + queryPadding, bounds.maxY + queryPadding);
var cameraBounds = getBounds(args.cameraQueryGeometry);
var matching3D = this.grid3D.query(cameraBounds.minX - queryPadding, cameraBounds.minY - queryPadding, cameraBounds.maxX + queryPadding, cameraBounds.maxY + queryPadding, function (bx1, by1, bx2, by2) {
return polygonIntersectsBox(args.cameraQueryGeometry, bx1 - queryPadding, by1 - queryPadding, bx2 + queryPadding, by2 + queryPadding);
});
for (var i = 0, list = matching3D; i < list.length; i += 1) {
var key = list[i];
matching.push(key);
}
matching.sort(topDownFeatureComparator);
var result = {};
var previousIndex;
var loop = function (k) {
var index = matching[k];
if (index === previousIndex) {
return;
}
previousIndex = index;
var match = this$1.featureIndexArray.get(index);
var featureGeometry = null;
this$1.loadMatchingFeature(result, match.bucketIndex, match.sourceLayerIndex, match.featureIndex, filter, params.layers, params.availableImages, styleLayers, serializedLayers, sourceFeatureState, function (feature, styleLayer, featureState) {
if (!featureGeometry) {
featureGeometry = loadGeometry(feature);
}
return styleLayer.queryIntersectsFeature(queryGeometry, feature, featureState, featureGeometry, this$1.z, args.transform, pixelsToTileUnits, args.pixelPosMatrix);
});
};
for (var k = 0; k < matching.length; k++)
loop(k);
return result;
};
FeatureIndex.prototype.loadMatchingFeature = function loadMatchingFeature(result, bucketIndex, sourceLayerIndex, featureIndex, filter, filterLayerIDs, availableImages, styleLayers, serializedLayers, sourceFeatureState, intersectionTest) {
var layerIDs = this.bucketLayerIDs[bucketIndex];
if (filterLayerIDs && !arraysIntersect(filterLayerIDs, layerIDs)) {
return;
}
var sourceLayerName = this.sourceLayerCoder.decode(sourceLayerIndex);
var sourceLayer = this.vtLayers[sourceLayerName];
var feature = sourceLayer.feature(featureIndex);
if (filter.needGeometry) {
var evaluationFeature = toEvaluationFeature(feature, true);
if (!filter.filter(new EvaluationParameters(this.tileID.overscaledZ), evaluationFeature, this.tileID.canonical)) {
return;
}
} else if (!filter.filter(new EvaluationParameters(this.tileID.overscaledZ), feature)) {
return;
}
var id = this.getId(feature, sourceLayerName);
for (var l = 0; l < layerIDs.length; l++) {
var layerID = layerIDs[l];
if (filterLayerIDs && filterLayerIDs.indexOf(layerID) < 0) {
continue;
}
var styleLayer = styleLayers[layerID];
if (!styleLayer) {
continue;
}
var featureState = {};
if (id !== undefined && sourceFeatureState) {
featureState = sourceFeatureState.getState(styleLayer.sourceLayer || '_geojsonTileLayer', id);
}
var serializedLayer = extend({}, serializedLayers[layerID]);
serializedLayer.paint = evaluateProperties(serializedLayer.paint, styleLayer.paint, feature, featureState, availableImages);
serializedLayer.layout = evaluateProperties(serializedLayer.layout, styleLayer.layout, feature, featureState, availableImages);
var intersectionZ = !intersectionTest || intersectionTest(feature, styleLayer, featureState);
if (!intersectionZ) {
continue;
}
var geojsonFeature = new Feature(feature, this.z, this.x, this.y, id);
geojsonFeature.layer = serializedLayer;
var layerResult = result[layerID];
if (layerResult === undefined) {
layerResult = result[layerID] = [];
}
layerResult.push({
featureIndex: featureIndex,
feature: geojsonFeature,
intersectionZ: intersectionZ
});
}
};
FeatureIndex.prototype.lookupSymbolFeatures = function lookupSymbolFeatures(symbolFeatureIndexes, serializedLayers, bucketIndex, sourceLayerIndex, filterSpec, filterLayerIDs, availableImages, styleLayers) {
var result = {};
this.loadVTLayers();
var filter = createFilter(filterSpec);
for (var i = 0, list = symbolFeatureIndexes; i < list.length; i += 1) {
var symbolFeatureIndex = list[i];
this.loadMatchingFeature(result, bucketIndex, sourceLayerIndex, symbolFeatureIndex, filter, filterLayerIDs, availableImages, styleLayers, serializedLayers);
}
return result;
};
FeatureIndex.prototype.hasLayer = function hasLayer(id) {
for (var i$1 = 0, list$1 = this.bucketLayerIDs; i$1 < list$1.length; i$1 += 1) {
var layerIDs = list$1[i$1];
for (var i = 0, list = layerIDs; i < list.length; i += 1) {
var layerID = list[i];
if (id === layerID) {
return true;
}
}
}
return false;
};
FeatureIndex.prototype.getId = function getId(feature, sourceLayerId) {
var id = feature.id;
if (this.promoteId) {
var propName = typeof this.promoteId === 'string' ? this.promoteId : this.promoteId[sourceLayerId];
id = feature.properties[propName];
if (typeof id === 'boolean') {
id = Number(id);
}
}
return id;
};
register('FeatureIndex', FeatureIndex, {
omit: [
'rawTileData',
'sourceLayerCoder'
]
});
function evaluateProperties(serializedProperties, styleLayerProperties, feature, featureState, availableImages) {
return mapObject(serializedProperties, function (property, key) {
var prop = styleLayerProperties instanceof PossiblyEvaluated ? styleLayerProperties.get(key) : null;
return prop && prop.evaluate ? prop.evaluate(feature, featureState, availableImages) : prop;
});
}
function getBounds(geometry) {
var minX = Infinity;
var minY = Infinity;
var maxX = -Infinity;
var maxY = -Infinity;
for (var i = 0, list = geometry; i < list.length; i += 1) {
var p = list[i];
minX = Math.min(minX, p.x);
minY = Math.min(minY, p.y);
maxX = Math.max(maxX, p.x);
maxY = Math.max(maxY, p.y);
}
return {
minX: minX,
minY: minY,
maxX: maxX,
maxY: maxY
};
}
function topDownFeatureComparator(a, b) {
return b - a;
}
var CLOCK_SKEW_RETRY_TIMEOUT = 30000;
var Tile = function Tile(tileID, size) {
this.tileID = tileID;
this.uid = uniqueId();
this.uses = 0;
this.tileSize = size;
this.buckets = {};
this.expirationTime = null;
this.queryPadding = 0;
this.hasSymbolBuckets = false;
this.hasRTLText = false;
this.dependencies = {};
this.expiredRequestCount = 0;
this.state = 'loading';
};
Tile.prototype.registerFadeDuration = function registerFadeDuration(duration) {
var fadeEndTime = duration + this.timeAdded;
if (fadeEndTime < exported.now()) {
return;
}
if (this.fadeEndTime && fadeEndTime < this.fadeEndTime) {
return;
}
this.fadeEndTime = fadeEndTime;
};
Tile.prototype.wasRequested = function wasRequested() {
return this.state === 'errored' || this.state === 'loaded' || this.state === 'reloading';
};
Tile.prototype.loadVectorData = function loadVectorData(data, painter, justReloaded) {
if (this.hasData()) {
this.unloadVectorData();
}
this.state = 'loaded';
if (!data) {
this.collisionBoxArray = new CollisionBoxArray();
return;
}
if (data.featureIndex) {
this.latestFeatureIndex = data.featureIndex;
if (data.rawTileData) {
this.latestRawTileData = data.rawTileData;
this.latestFeatureIndex.rawTileData = data.rawTileData;
} else if (this.latestRawTileData) {
this.latestFeatureIndex.rawTileData = this.latestRawTileData;
}
}
this.collisionBoxArray = data.collisionBoxArray;
this.buckets = deserialize$1(data.buckets, painter.style);
this.hasSymbolBuckets = false;
for (var id in this.buckets) {
var bucket = this.buckets[id];
if (bucket instanceof SymbolBucket) {
this.hasSymbolBuckets = true;
if (justReloaded) {
bucket.justReloaded = true;
} else {
break;
}
}
}
this.hasRTLText = false;
if (this.hasSymbolBuckets) {
for (var id$1 in this.buckets) {
var bucket$1 = this.buckets[id$1];
if (bucket$1 instanceof SymbolBucket) {
if (bucket$1.hasRTLText) {
this.hasRTLText = true;
lazyLoadRTLTextPlugin();
break;
}
}
}
}
this.queryPadding = 0;
for (var id$2 in this.buckets) {
var bucket$2 = this.buckets[id$2];
this.queryPadding = Math.max(this.queryPadding, painter.style.getLayer(id$2).queryRadius(bucket$2));
}
if (data.imageAtlas) {
this.imageAtlas = data.imageAtlas;
}
if (data.glyphAtlasImage) {
this.glyphAtlasImage = data.glyphAtlasImage;
}
};
Tile.prototype.unloadVectorData = function unloadVectorData() {
for (var id in this.buckets) {
this.buckets[id].destroy();
}
this.buckets = {};
if (this.imageAtlasTexture) {
this.imageAtlasTexture.destroy();
}
if (this.imageAtlas) {
this.imageAtlas = null;
}
if (this.glyphAtlasTexture) {
this.glyphAtlasTexture.destroy();
}
this.latestFeatureIndex = null;
this.state = 'unloaded';
};
Tile.prototype.getBucket = function getBucket(layer) {
return this.buckets[layer.id];
};
Tile.prototype.upload = function upload(context) {
for (var id in this.buckets) {
var bucket = this.buckets[id];
if (bucket.uploadPending()) {
bucket.upload(context);
}
}
var gl = context.gl;
if (this.imageAtlas && !this.imageAtlas.uploaded) {
this.imageAtlasTexture = new Texture(context, this.imageAtlas.image, gl.RGBA);
this.imageAtlas.uploaded = true;
}
if (this.glyphAtlasImage) {
this.glyphAtlasTexture = new Texture(context, this.glyphAtlasImage, gl.ALPHA);
this.glyphAtlasImage = null;
}
};
Tile.prototype.prepare = function prepare(imageManager) {
if (this.imageAtlas) {
this.imageAtlas.patchUpdatedImages(imageManager, this.imageAtlasTexture);
}
};
Tile.prototype.queryRenderedFeatures = function queryRenderedFeatures(layers, serializedLayers, sourceFeatureState, queryGeometry, cameraQueryGeometry, scale, params, transform, maxPitchScaleFactor, pixelPosMatrix) {
if (!this.latestFeatureIndex || !this.latestFeatureIndex.rawTileData) {
return {};
}
return this.latestFeatureIndex.query({
queryGeometry: queryGeometry,
cameraQueryGeometry: cameraQueryGeometry,
scale: scale,
tileSize: this.tileSize,
pixelPosMatrix: pixelPosMatrix,
transform: transform,
params: params,
queryPadding: this.queryPadding * maxPitchScaleFactor
}, layers, serializedLayers, sourceFeatureState);
};
Tile.prototype.querySourceFeatures = function querySourceFeatures(result, params) {
var featureIndex = this.latestFeatureIndex;
if (!featureIndex || !featureIndex.rawTileData) {
return;
}
var vtLayers = featureIndex.loadVTLayers();
var sourceLayer = params ? params.sourceLayer : '';
var layer = vtLayers._geojsonTileLayer || vtLayers[sourceLayer];
if (!layer) {
return;
}
var filter = createFilter(params && params.filter);
var ref = this.tileID.canonical;
var z = ref.z;
var x = ref.x;
var y = ref.y;
var coord = {
z: z,
x: x,
y: y
};
for (var i = 0; i < layer.length; i++) {
var feature = layer.feature(i);
if (filter.needGeometry) {
var evaluationFeature = toEvaluationFeature(feature, true);
if (!filter.filter(new EvaluationParameters(this.tileID.overscaledZ), evaluationFeature, this.tileID.canonical)) {
continue;
}
} else if (!filter.filter(new EvaluationParameters(this.tileID.overscaledZ), feature)) {
continue;
}
var id = featureIndex.getId(feature, sourceLayer);
var geojsonFeature = new Feature(feature, z, x, y, id);
geojsonFeature.tile = coord;
result.push(geojsonFeature);
}
};
Tile.prototype.hasData = function hasData() {
return this.state === 'loaded' || this.state === 'reloading' || this.state === 'expired';
};
Tile.prototype.patternsLoaded = function patternsLoaded() {
return this.imageAtlas && !!Object.keys(this.imageAtlas.patternPositions).length;
};
Tile.prototype.setExpiryData = function setExpiryData(data) {
var prior = this.expirationTime;
if (data.cacheControl) {
var parsedCC = parseCacheControl(data.cacheControl);
if (parsedCC['max-age']) {
this.expirationTime = Date.now() + parsedCC['max-age'] * 1000;
}
} else if (data.expires) {
this.expirationTime = new Date(data.expires).getTime();
}
if (this.expirationTime) {
var now = Date.now();
var isExpired = false;
if (this.expirationTime > now) {
isExpired = false;
} else if (!prior) {
isExpired = true;
} else if (this.expirationTime < prior) {
isExpired = true;
} else {
var delta = this.expirationTime - prior;
if (!delta) {
isExpired = true;
} else {
this.expirationTime = now + Math.max(delta, CLOCK_SKEW_RETRY_TIMEOUT);
}
}
if (isExpired) {
this.expiredRequestCount++;
this.state = 'expired';
} else {
this.expiredRequestCount = 0;
}
}
};
Tile.prototype.getExpiryTimeout = function getExpiryTimeout() {
if (this.expirationTime) {
if (this.expiredRequestCount) {
return 1000 * (1 << Math.min(this.expiredRequestCount - 1, 31));
} else {
return Math.min(this.expirationTime - new Date().getTime(), Math.pow(2, 31) - 1);
}
}
};
Tile.prototype.setFeatureState = function setFeatureState(states, painter) {
if (!this.latestFeatureIndex || !this.latestFeatureIndex.rawTileData || Object.keys(states).length === 0) {
return;
}
var vtLayers = this.latestFeatureIndex.loadVTLayers();
for (var id in this.buckets) {
if (!painter.style.hasLayer(id)) {
continue;
}
var bucket = this.buckets[id];
var sourceLayerId = bucket.layers[0]['sourceLayer'] || '_geojsonTileLayer';
var sourceLayer = vtLayers[sourceLayerId];
var sourceLayerStates = states[sourceLayerId];
if (!sourceLayer || !sourceLayerStates || Object.keys(sourceLayerStates).length === 0) {
continue;
}
bucket.update(sourceLayerStates, sourceLayer, this.imageAtlas && this.imageAtlas.patternPositions || {});
var layer = painter && painter.style && painter.style.getLayer(id);
if (layer) {
this.queryPadding = Math.max(this.queryPadding, layer.queryRadius(bucket));
}
}
};
Tile.prototype.holdingForFade = function holdingForFade() {
return this.symbolFadeHoldUntil !== undefined;
};
Tile.prototype.symbolFadeFinished = function symbolFadeFinished() {
return !this.symbolFadeHoldUntil || this.symbolFadeHoldUntil < exported.now();
};
Tile.prototype.clearFadeHold = function clearFadeHold() {
this.symbolFadeHoldUntil = undefined;
};
Tile.prototype.setHoldDuration = function setHoldDuration(duration) {
this.symbolFadeHoldUntil = exported.now() + duration;
};
Tile.prototype.setDependencies = function setDependencies(namespace, dependencies) {
var index = {};
for (var i = 0, list = dependencies; i < list.length; i += 1) {
var dep = list[i];
index[dep] = true;
}
this.dependencies[namespace] = index;
};
Tile.prototype.hasDependency = function hasDependency(namespaces, keys) {
for (var i$1 = 0, list$1 = namespaces; i$1 < list$1.length; i$1 += 1) {
var namespace = list$1[i$1];
var dependencies = this.dependencies[namespace];
if (dependencies) {
for (var i = 0, list = keys; i < list.length; i += 1) {
var key = list[i];
if (dependencies[key]) {
return true;
}
}
}
}
return false;
};
var refProperties = [
'type',
'source',
'source-layer',
'minzoom',
'maxzoom',
'filter',
'layout'
];
var performance = window$1.performance;
var RequestPerformance = function RequestPerformance(request) {
this._marks = {
start: [
request.url,
'start'
].join('#'),
end: [
request.url,
'end'
].join('#'),
measure: request.url.toString()
};
performance.mark(this._marks.start);
};
RequestPerformance.prototype.finish = function finish() {
performance.mark(this._marks.end);
var resourceTimingData = performance.getEntriesByName(this._marks.measure);
if (resourceTimingData.length === 0) {
performance.measure(this._marks.measure, this._marks.start, this._marks.end);
resourceTimingData = performance.getEntriesByName(this._marks.measure);
performance.clearMarks(this._marks.start);
performance.clearMarks(this._marks.end);
performance.clearMeasures(this._marks.measure);
}
return resourceTimingData;
};
exports.Actor = Actor;
exports.AlphaImage = AlphaImage;
exports.CanonicalTileID = CanonicalTileID;
exports.CollisionBoxArray = CollisionBoxArray;
exports.Color = Color;
exports.DEMData = DEMData;
exports.DataConstantProperty = DataConstantProperty;
exports.DictionaryCoder = DictionaryCoder;
exports.EXTENT = EXTENT$1;
exports.ErrorEvent = ErrorEvent;
exports.EvaluationParameters = EvaluationParameters;
exports.Event = Event;
exports.Evented = Evented;
exports.FeatureIndex = FeatureIndex;
exports.FillBucket = FillBucket;
exports.FillExtrusionBucket = FillExtrusionBucket;
exports.ImageAtlas = ImageAtlas;
exports.ImagePosition = ImagePosition;
exports.LineBucket = LineBucket;
exports.LngLat = LngLat;
exports.LngLatBounds = LngLatBounds;
exports.MercatorCoordinate = MercatorCoordinate;
exports.ONE_EM = ONE_EM;
exports.OverscaledTileID = OverscaledTileID;
exports.Point = pointGeometry;
exports.Point$1 = pointGeometry;
exports.Properties = Properties;
exports.Protobuf = pbf;
exports.RGBAImage = RGBAImage;
exports.RequestManager = RequestManager;
exports.RequestPerformance = RequestPerformance;
exports.ResourceType = ResourceType;
exports.SegmentVector = SegmentVector;
exports.SourceFeatureState = SourceFeatureState;
exports.StructArrayLayout1ui2 = StructArrayLayout1ui2;
exports.StructArrayLayout2f1f2i16 = StructArrayLayout2f1f2i16;
exports.StructArrayLayout2i4 = StructArrayLayout2i4;
exports.StructArrayLayout3ui6 = StructArrayLayout3ui6;
exports.StructArrayLayout4i8 = StructArrayLayout4i8;
exports.SymbolBucket = SymbolBucket;
exports.Texture = Texture;
exports.Tile = Tile;
exports.Transitionable = Transitionable;
exports.Uniform1f = Uniform1f;
exports.Uniform1i = Uniform1i;
exports.Uniform2f = Uniform2f;
exports.Uniform3f = Uniform3f;
exports.Uniform4f = Uniform4f;
exports.UniformColor = UniformColor;
exports.UniformMatrix4f = UniformMatrix4f;
exports.UnwrappedTileID = UnwrappedTileID;
exports.ValidationError = ValidationError;
exports.WritingMode = WritingMode;
exports.ZoomHistory = ZoomHistory;
exports.add = add;
exports.addDynamicAttributes = addDynamicAttributes;
exports.asyncAll = asyncAll;
exports.bezier = bezier;
exports.bindAll = bindAll;
exports.browser = exported;
exports.cacheEntryPossiblyAdded = cacheEntryPossiblyAdded;
exports.clamp = clamp;
exports.clearTileCache = clearTileCache;
exports.clipLine = clipLine;
exports.clone = clone$1;
exports.clone$1 = clone;
exports.clone$2 = clone$2;
exports.collisionCircleLayout = collisionCircleLayout;
exports.config = config;
exports.create = create$2;
exports.create$1 = create$1;
exports.create$2 = create;
exports.createCommonjsModule = createCommonjsModule;
exports.createExpression = createExpression;
exports.createLayout = createLayout;
exports.createStyleLayer = createStyleLayer;
exports.cross = cross;
exports.deepEqual = deepEqual;
exports.dot = dot;
exports.dot$1 = dot$1;
exports.ease = ease;
exports.emitValidationErrors = emitValidationErrors;
exports.endsWith = endsWith;
exports.enforceCacheSizeLimit = enforceCacheSizeLimit;
exports.evaluateSizeForFeature = evaluateSizeForFeature;
exports.evaluateSizeForZoom = evaluateSizeForZoom;
exports.evaluateVariableOffset = evaluateVariableOffset;
exports.evented = evented;
exports.extend = extend;
exports.featureFilter = createFilter;
exports.filterObject = filterObject;
exports.fromRotation = fromRotation;
exports.getAnchorAlignment = getAnchorAlignment;
exports.getAnchorJustification = getAnchorJustification;
exports.getArrayBuffer = getArrayBuffer;
exports.getImage = getImage;
exports.getJSON = getJSON;
exports.getRTLTextPluginStatus = getRTLTextPluginStatus;
exports.getReferrer = getReferrer;
exports.getVideo = getVideo;
exports.identity = identity;
exports.invert = invert;
exports.isChar = unicodeBlockLookup;
exports.isMapboxURL = isMapboxURL;
exports.keysDifference = keysDifference;
exports.makeRequest = makeRequest;
exports.mapObject = mapObject;
exports.mercatorXfromLng = mercatorXfromLng$1;
exports.mercatorYfromLat = mercatorYfromLat$1;
exports.mercatorZfromAltitude = mercatorZfromAltitude;
exports.mul = mul;
exports.multiply = multiply;
exports.mvt = vectorTile;
exports.nextPowerOfTwo = nextPowerOfTwo;
exports.normalize = normalize;
exports.number = number;
exports.offscreenCanvasSupported = offscreenCanvasSupported;
exports.ortho = ortho;
exports.parseGlyphPBF = parseGlyphPBF;
exports.pbf = pbf;
exports.performSymbolLayout = performSymbolLayout;
exports.perspective = perspective;
exports.pick = pick;
exports.plugin = plugin;
exports.polygonIntersectsPolygon = polygonIntersectsPolygon;
exports.postMapLoadEvent = postMapLoadEvent;
exports.postTurnstileEvent = postTurnstileEvent;
exports.potpack = potpack;
exports.refProperties = refProperties;
exports.register = register;
exports.registerForPluginStateChange = registerForPluginStateChange;
exports.renderColorRamp = renderColorRamp;
exports.rotate = rotate;
exports.rotateX = rotateX;
exports.rotateZ = rotateZ;
exports.scale = scale;
exports.scale$1 = scale$2;
exports.scale$2 = scale$1;
exports.setCacheLimits = setCacheLimits;
exports.setRTLTextPlugin = setRTLTextPlugin;
exports.sphericalToCartesian = sphericalToCartesian;
exports.sqrLen = sqrLen;
exports.styleSpec = spec;
exports.sub = sub;
exports.symbolSize = symbolSize;
exports.transformMat3 = transformMat3;
exports.transformMat4 = transformMat4;
exports.translate = translate$1;
exports.triggerPluginCompletionEvent = triggerPluginCompletionEvent;
exports.uniqueId = uniqueId;
exports.validateCustomStyleLayer = validateCustomStyleLayer;
exports.validateLight = validateLight$1;
exports.validateStyle = validateStyle;
exports.values = values;
exports.vectorTile = vectorTile;
exports.version = version;
exports.warnOnce = warnOnce;
exports.webpSupported = exported$1;
exports.window = window$1;
exports.wrap = wrap;
});
define(['./shared'], function (performance) { 'use strict';
function stringify(obj) {
var type = typeof obj;
if (type === 'number' || type === 'boolean' || type === 'string' || obj === undefined || obj === null) {
return JSON.stringify(obj);
}
if (Array.isArray(obj)) {
var str$1 = '[';
for (var i$1 = 0, list = obj; i$1 < list.length; i$1 += 1) {
var val = list[i$1];
str$1 += stringify(val) + ',';
}
return str$1 + ']';
}
var keys = Object.keys(obj).sort();
var str = '{';
for (var i = 0; i < keys.length; i++) {
str += JSON.stringify(keys[i]) + ':' + stringify(obj[keys[i]]) + ',';
}
return str + '}';
}
function getKey(layer) {
var key = '';
for (var i = 0, list = performance.refProperties; i < list.length; i += 1) {
var k = list[i];
key += '/' + stringify(layer[k]);
}
return key;
}
function groupByLayout(layers, cachedKeys) {
var groups = {};
for (var i = 0; i < layers.length; i++) {
var k = cachedKeys && cachedKeys[layers[i].id] || getKey(layers[i]);
if (cachedKeys) {
cachedKeys[layers[i].id] = k;
}
var group = groups[k];
if (!group) {
group = groups[k] = [];
}
group.push(layers[i]);
}
var result = [];
for (var k$1 in groups) {
result.push(groups[k$1]);
}
return result;
}
var StyleLayerIndex = function StyleLayerIndex(layerConfigs) {
this.keyCache = {};
if (layerConfigs) {
this.replace(layerConfigs);
}
};
StyleLayerIndex.prototype.replace = function replace(layerConfigs) {
this._layerConfigs = {};
this._layers = {};
this.update(layerConfigs, []);
};
StyleLayerIndex.prototype.update = function update(layerConfigs, removedIds) {
var this$1 = this;
for (var i = 0, list = layerConfigs; i < list.length; i += 1) {
var layerConfig = list[i];
this._layerConfigs[layerConfig.id] = layerConfig;
var layer = this._layers[layerConfig.id] = performance.createStyleLayer(layerConfig);
layer._featureFilter = performance.featureFilter(layer.filter);
if (this.keyCache[layerConfig.id]) {
delete this.keyCache[layerConfig.id];
}
}
for (var i$1 = 0, list$1 = removedIds; i$1 < list$1.length; i$1 += 1) {
var id = list$1[i$1];
delete this.keyCache[id];
delete this._layerConfigs[id];
delete this._layers[id];
}
this.familiesBySource = {};
var groups = groupByLayout(performance.values(this._layerConfigs), this.keyCache);
for (var i$2 = 0, list$2 = groups; i$2 < list$2.length; i$2 += 1) {
var layerConfigs$1 = list$2[i$2];
var layers = layerConfigs$1.map(function (layerConfig) {
return this$1._layers[layerConfig.id];
});
var layer$1 = layers[0];
if (layer$1.visibility === 'none') {
continue;
}
var sourceId = layer$1.source || '';
var sourceGroup = this.familiesBySource[sourceId];
if (!sourceGroup) {
sourceGroup = this.familiesBySource[sourceId] = {};
}
var sourceLayerId = layer$1.sourceLayer || '_geojsonTileLayer';
var sourceLayerFamilies = sourceGroup[sourceLayerId];
if (!sourceLayerFamilies) {
sourceLayerFamilies = sourceGroup[sourceLayerId] = [];
}
sourceLayerFamilies.push(layers);
}
};
var padding = 1;
var GlyphAtlas = function GlyphAtlas(stacks) {
var positions = {};
var bins = [];
for (var stack in stacks) {
var glyphs = stacks[stack];
var stackPositions = positions[stack] = {};
for (var id in glyphs) {
var src = glyphs[+id];
if (!src || src.bitmap.width === 0 || src.bitmap.height === 0) {
continue;
}
var bin = {
x: 0,
y: 0,
w: src.bitmap.width + 2 * padding,
h: src.bitmap.height + 2 * padding
};
bins.push(bin);
stackPositions[id] = {
rect: bin,
metrics: src.metrics
};
}
}
var ref = performance.potpack(bins);
var w = ref.w;
var h = ref.h;
var image = new performance.AlphaImage({
width: w || 1,
height: h || 1
});
for (var stack$1 in stacks) {
var glyphs$1 = stacks[stack$1];
for (var id$1 in glyphs$1) {
var src$1 = glyphs$1[+id$1];
if (!src$1 || src$1.bitmap.width === 0 || src$1.bitmap.height === 0) {
continue;
}
var bin$1 = positions[stack$1][id$1].rect;
performance.AlphaImage.copy(src$1.bitmap, image, {
x: 0,
y: 0
}, {
x: bin$1.x + padding,
y: bin$1.y + padding
}, src$1.bitmap);
}
}
this.image = image;
this.positions = positions;
};
performance.register('GlyphAtlas', GlyphAtlas);
var WorkerTile = function WorkerTile(params) {
this.tileID = new performance.OverscaledTileID(params.tileID.overscaledZ, params.tileID.wrap, params.tileID.canonical.z, params.tileID.canonical.x, params.tileID.canonical.y);
this.uid = params.uid;
this.zoom = params.zoom;
this.pixelRatio = params.pixelRatio;
this.tileSize = params.tileSize;
this.source = params.source;
this.overscaling = this.tileID.overscaleFactor();
this.showCollisionBoxes = params.showCollisionBoxes;
this.collectResourceTiming = !!params.collectResourceTiming;
this.returnDependencies = !!params.returnDependencies;
this.promoteId = params.promoteId;
};
WorkerTile.prototype.parse = function parse(data, layerIndex, availableImages, actor, callback) {
var this$1 = this;
this.status = 'parsing';
this.data = data;
this.collisionBoxArray = new performance.CollisionBoxArray();
var sourceLayerCoder = new performance.DictionaryCoder(Object.keys(data.layers).sort());
var featureIndex = new performance.FeatureIndex(this.tileID, this.promoteId);
featureIndex.bucketLayerIDs = [];
var buckets = {};
var options = {
featureIndex: featureIndex,
iconDependencies: {},
patternDependencies: {},
glyphDependencies: {},
availableImages: availableImages
};
var layerFamilies = layerIndex.familiesBySource[this.source];
for (var sourceLayerId in layerFamilies) {
var sourceLayer = data.layers[sourceLayerId];
if (!sourceLayer) {
continue;
}
if (sourceLayer.version === 1) {
performance.warnOnce('Vector tile source "' + this.source + '" layer "' + sourceLayerId + '" ' + 'does not use vector tile spec v2 and therefore may have some rendering errors.');
}
var sourceLayerIndex = sourceLayerCoder.encode(sourceLayerId);
var features = [];
for (var index = 0; index < sourceLayer.length; index++) {
var feature = sourceLayer.feature(index);
var id = featureIndex.getId(feature, sourceLayerId);
features.push({
feature: feature,
id: id,
index: index,
sourceLayerIndex: sourceLayerIndex
});
}
for (var i = 0, list = layerFamilies[sourceLayerId]; i < list.length; i += 1) {
var family = list[i];
var layer = family[0];
if (layer.minzoom && this.zoom < Math.floor(layer.minzoom)) {
continue;
}
if (layer.maxzoom && this.zoom >= layer.maxzoom) {
continue;
}
if (layer.visibility === 'none') {
continue;
}
recalculateLayers(family, this.zoom, availableImages);
var bucket = buckets[layer.id] = layer.createBucket({
index: featureIndex.bucketLayerIDs.length,
layers: family,
zoom: this.zoom,
pixelRatio: this.pixelRatio,
overscaling: this.overscaling,
collisionBoxArray: this.collisionBoxArray,
sourceLayerIndex: sourceLayerIndex,
sourceID: this.source
});
bucket.populate(features, options, this.tileID.canonical);
featureIndex.bucketLayerIDs.push(family.map(function (l) {
return l.id;
}));
}
}
var error;
var glyphMap;
var iconMap;
var patternMap;
var stacks = performance.mapObject(options.glyphDependencies, function (glyphs) {
return Object.keys(glyphs).map(Number);
});
if (Object.keys(stacks).length) {
actor.send('getGlyphs', {
uid: this.uid,
stacks: stacks
}, function (err, result) {
if (!error) {
error = err;
glyphMap = result;
maybePrepare.call(this$1);
}
});
} else {
glyphMap = {};
}
var icons = Object.keys(options.iconDependencies);
if (icons.length) {
actor.send('getImages', {
icons: icons,
source: this.source,
tileID: this.tileID,
type: 'icons'
}, function (err, result) {
if (!error) {
error = err;
iconMap = result;
maybePrepare.call(this$1);
}
});
} else {
iconMap = {};
}
var patterns = Object.keys(options.patternDependencies);
if (patterns.length) {
actor.send('getImages', {
icons: patterns,
source: this.source,
tileID: this.tileID,
type: 'patterns'
}, function (err, result) {
if (!error) {
error = err;
patternMap = result;
maybePrepare.call(this$1);
}
});
} else {
patternMap = {};
}
maybePrepare.call(this);
function maybePrepare() {
if (error) {
return callback(error);
} else if (glyphMap && iconMap && patternMap) {
var glyphAtlas = new GlyphAtlas(glyphMap);
var imageAtlas = new performance.ImageAtlas(iconMap, patternMap);
for (var key in buckets) {
var bucket = buckets[key];
if (bucket instanceof performance.SymbolBucket) {
recalculateLayers(bucket.layers, this.zoom, availableImages);
performance.performSymbolLayout(bucket, glyphMap, glyphAtlas.positions, iconMap, imageAtlas.iconPositions, this.showCollisionBoxes, this.tileID.canonical);
} else if (bucket.hasPattern && (bucket instanceof performance.LineBucket || bucket instanceof performance.FillBucket || bucket instanceof performance.FillExtrusionBucket)) {
recalculateLayers(bucket.layers, this.zoom, availableImages);
bucket.addFeatures(options, this.tileID.canonical, imageAtlas.patternPositions);
}
}
this.status = 'done';
callback(null, {
buckets: performance.values(buckets).filter(function (b) {
return !b.isEmpty();
}),
featureIndex: featureIndex,
collisionBoxArray: this.collisionBoxArray,
glyphAtlasImage: glyphAtlas.image,
imageAtlas: imageAtlas,
glyphMap: this.returnDependencies ? glyphMap : null,
iconMap: this.returnDependencies ? iconMap : null,
glyphPositions: this.returnDependencies ? glyphAtlas.positions : null
});
}
}
};
function recalculateLayers(layers, zoom, availableImages) {
var parameters = new performance.EvaluationParameters(zoom);
for (var i = 0, list = layers; i < list.length; i += 1) {
var layer = list[i];
layer.recalculate(parameters, availableImages);
}
}
function loadVectorTile(params, callback) {
var request = performance.getArrayBuffer(params.request, function (err, data, cacheControl, expires) {
if (err) {
callback(err);
} else if (data) {
callback(null, {
vectorTile: new performance.vectorTile.VectorTile(new performance.pbf(data)),
rawData: data,
cacheControl: cacheControl,
expires: expires
});
}
});
return function () {
request.cancel();
callback();
};
}
var VectorTileWorkerSource = function VectorTileWorkerSource(actor, layerIndex, availableImages, loadVectorData) {
this.actor = actor;
this.layerIndex = layerIndex;
this.availableImages = availableImages;
this.loadVectorData = loadVectorData || loadVectorTile;
this.loading = {};
this.loaded = {};
};
VectorTileWorkerSource.prototype.loadTile = function loadTile(params, callback) {
var this$1 = this;
var uid = params.uid;
if (!this.loading) {
this.loading = {};
}
var perf = params && params.request && params.request.collectResourceTiming ? new performance.RequestPerformance(params.request) : false;
var workerTile = this.loading[uid] = new WorkerTile(params);
workerTile.abort = this.loadVectorData(params, function (err, response) {
delete this$1.loading[uid];
if (err || !response) {
workerTile.status = 'done';
this$1.loaded[uid] = workerTile;
return callback(err);
}
var rawTileData = response.rawData;
var cacheControl = {};
if (response.expires) {
cacheControl.expires = response.expires;
}
if (response.cacheControl) {
cacheControl.cacheControl = response.cacheControl;
}
var resourceTiming = {};
if (perf) {
var resourceTimingData = perf.finish();
if (resourceTimingData) {
resourceTiming.resourceTiming = JSON.parse(JSON.stringify(resourceTimingData));
}
}
workerTile.vectorTile = response.vectorTile;
workerTile.parse(response.vectorTile, this$1.layerIndex, this$1.availableImages, this$1.actor, function (err, result) {
if (err || !result) {
return callback(err);
}
callback(null, performance.extend({ rawTileData: rawTileData.slice(0) }, result, cacheControl, resourceTiming));
});
this$1.loaded = this$1.loaded || {};
this$1.loaded[uid] = workerTile;
});
};
VectorTileWorkerSource.prototype.reloadTile = function reloadTile(params, callback) {
var this$1 = this;
var loaded = this.loaded, uid = params.uid, vtSource = this;
if (loaded && loaded[uid]) {
var workerTile = loaded[uid];
workerTile.showCollisionBoxes = params.showCollisionBoxes;
var done = function (err, data) {
var reloadCallback = workerTile.reloadCallback;
if (reloadCallback) {
delete workerTile.reloadCallback;
workerTile.parse(workerTile.vectorTile, vtSource.layerIndex, this$1.availableImages, vtSource.actor, reloadCallback);
}
callback(err, data);
};
if (workerTile.status === 'parsing') {
workerTile.reloadCallback = done;
} else if (workerTile.status === 'done') {
if (workerTile.vectorTile) {
workerTile.parse(workerTile.vectorTile, this.layerIndex, this.availableImages, this.actor, done);
} else {
done();
}
}
}
};
VectorTileWorkerSource.prototype.abortTile = function abortTile(params, callback) {
var loading = this.loading, uid = params.uid;
if (loading && loading[uid] && loading[uid].abort) {
loading[uid].abort();
delete loading[uid];
}
callback();
};
VectorTileWorkerSource.prototype.removeTile = function removeTile(params, callback) {
var loaded = this.loaded, uid = params.uid;
if (loaded && loaded[uid]) {
delete loaded[uid];
}
callback();
};
var ImageBitmap = performance.window.ImageBitmap;
var RasterDEMTileWorkerSource = function RasterDEMTileWorkerSource() {
this.loaded = {};
};
RasterDEMTileWorkerSource.prototype.loadTile = function loadTile(params, callback) {
var uid = params.uid;
var encoding = params.encoding;
var rawImageData = params.rawImageData;
var imagePixels = ImageBitmap && rawImageData instanceof ImageBitmap ? this.getImageData(rawImageData) : rawImageData;
var dem = new performance.DEMData(uid, imagePixels, encoding);
this.loaded = this.loaded || {};
this.loaded[uid] = dem;
callback(null, dem);
};
RasterDEMTileWorkerSource.prototype.getImageData = function getImageData(imgBitmap) {
if (!this.offscreenCanvas || !this.offscreenCanvasContext) {
this.offscreenCanvas = new OffscreenCanvas(imgBitmap.width, imgBitmap.height);
this.offscreenCanvasContext = this.offscreenCanvas.getContext('2d');
}
this.offscreenCanvas.width = imgBitmap.width;
this.offscreenCanvas.height = imgBitmap.height;
this.offscreenCanvasContext.drawImage(imgBitmap, 0, 0, imgBitmap.width, imgBitmap.height);
var imgData = this.offscreenCanvasContext.getImageData(-1, -1, imgBitmap.width + 2, imgBitmap.height + 2);
this.offscreenCanvasContext.clearRect(0, 0, this.offscreenCanvas.width, this.offscreenCanvas.height);
return new performance.RGBAImage({
width: imgData.width,
height: imgData.height
}, imgData.data);
};
RasterDEMTileWorkerSource.prototype.removeTile = function removeTile(params) {
var loaded = this.loaded, uid = params.uid;
if (loaded && loaded[uid]) {
delete loaded[uid];
}
};
var geojsonRewind = rewind;
function rewind(gj, outer) {
var type = gj && gj.type, i;
if (type === 'FeatureCollection') {
for (i = 0; i < gj.features.length; i++) {
rewind(gj.features[i], outer);
}
} else if (type === 'GeometryCollection') {
for (i = 0; i < gj.geometries.length; i++) {
rewind(gj.geometries[i], outer);
}
} else if (type === 'Feature') {
rewind(gj.geometry, outer);
} else if (type === 'Polygon') {
rewindRings(gj.coordinates, outer);
} else if (type === 'MultiPolygon') {
for (i = 0; i < gj.coordinates.length; i++) {
rewindRings(gj.coordinates[i], outer);
}
}
return gj;
}
function rewindRings(rings, outer) {
if (rings.length === 0) {
return;
}
rewindRing(rings[0], outer);
for (var i = 1; i < rings.length; i++) {
rewindRing(rings[i], !outer);
}
}
function rewindRing(ring, dir) {
var area = 0;
for (var i = 0, len = ring.length, j = len - 1; i < len; j = i++) {
area += (ring[i][0] - ring[j][0]) * (ring[j][1] + ring[i][1]);
}
if (area >= 0 !== !!dir) {
ring.reverse();
}
}
var toGeoJSON = performance.vectorTile.VectorTileFeature.prototype.toGeoJSON;
var FeatureWrapper = function FeatureWrapper(feature) {
this._feature = feature;
this.extent = performance.EXTENT;
this.type = feature.type;
this.properties = feature.tags;
if ('id' in feature && !isNaN(feature.id)) {
this.id = parseInt(feature.id, 10);
}
};
FeatureWrapper.prototype.loadGeometry = function loadGeometry() {
if (this._feature.type === 1) {
var geometry = [];
for (var i = 0, list = this._feature.geometry; i < list.length; i += 1) {
var point = list[i];
geometry.push([new performance.Point$1(point[0], point[1])]);
}
return geometry;
} else {
var geometry$1 = [];
for (var i$2 = 0, list$2 = this._feature.geometry; i$2 < list$2.length; i$2 += 1) {
var ring = list$2[i$2];
var newRing = [];
for (var i$1 = 0, list$1 = ring; i$1 < list$1.length; i$1 += 1) {
var point$1 = list$1[i$1];
newRing.push(new performance.Point$1(point$1[0], point$1[1]));
}
geometry$1.push(newRing);
}
return geometry$1;
}
};
FeatureWrapper.prototype.toGeoJSON = function toGeoJSON$1(x, y, z) {
return toGeoJSON.call(this, x, y, z);
};
var GeoJSONWrapper = function GeoJSONWrapper(features) {
this.layers = { '_geojsonTileLayer': this };
this.name = '_geojsonTileLayer';
this.extent = performance.EXTENT;
this.length = features.length;
this._features = features;
};
GeoJSONWrapper.prototype.feature = function feature(i) {
return new FeatureWrapper(this._features[i]);
};
var VectorTileFeature = performance.vectorTile.VectorTileFeature;
var geojson_wrapper = GeoJSONWrapper$1;
function GeoJSONWrapper$1(features, options) {
this.options = options || {};
this.features = features;
this.length = features.length;
}
GeoJSONWrapper$1.prototype.feature = function (i) {
return new FeatureWrapper$1(this.features[i], this.options.extent);
};
function FeatureWrapper$1(feature, extent) {
this.id = typeof feature.id === 'number' ? feature.id : undefined;
this.type = feature.type;
this.rawGeometry = feature.type === 1 ? [feature.geometry] : feature.geometry;
this.properties = feature.tags;
this.extent = extent || 4096;
}
FeatureWrapper$1.prototype.loadGeometry = function () {
var rings = this.rawGeometry;
this.geometry = [];
for (var i = 0; i < rings.length; i++) {
var ring = rings[i];
var newRing = [];
for (var j = 0; j < ring.length; j++) {
newRing.push(new performance.Point$1(ring[j][0], ring[j][1]));
}
this.geometry.push(newRing);
}
return this.geometry;
};
FeatureWrapper$1.prototype.bbox = function () {
if (!this.geometry) {
this.loadGeometry();
}
var rings = this.geometry;
var x1 = Infinity;
var x2 = -Infinity;
var y1 = Infinity;
var y2 = -Infinity;
for (var i = 0; i < rings.length; i++) {
var ring = rings[i];
for (var j = 0; j < ring.length; j++) {
var coord = ring[j];
x1 = Math.min(x1, coord.x);
x2 = Math.max(x2, coord.x);
y1 = Math.min(y1, coord.y);
y2 = Math.max(y2, coord.y);
}
}
return [
x1,
y1,
x2,
y2
];
};
FeatureWrapper$1.prototype.toGeoJSON = VectorTileFeature.prototype.toGeoJSON;
var vtPbf = fromVectorTileJs;
var fromVectorTileJs_1 = fromVectorTileJs;
var fromGeojsonVt_1 = fromGeojsonVt;
var GeoJSONWrapper_1 = geojson_wrapper;
function fromVectorTileJs(tile) {
var out = new performance.pbf();
writeTile(tile, out);
return out.finish();
}
function fromGeojsonVt(layers, options) {
options = options || {};
var l = {};
for (var k in layers) {
l[k] = new geojson_wrapper(layers[k].features, options);
l[k].name = k;
l[k].version = options.version;
l[k].extent = options.extent;
}
return fromVectorTileJs({ layers: l });
}
function writeTile(tile, pbf) {
for (var key in tile.layers) {
pbf.writeMessage(3, writeLayer, tile.layers[key]);
}
}
function writeLayer(layer, pbf) {
pbf.writeVarintField(15, layer.version || 1);
pbf.writeStringField(1, layer.name || '');
pbf.writeVarintField(5, layer.extent || 4096);
var i;
var context = {
keys: [],
values: [],
keycache: {},
valuecache: {}
};
for (i = 0; i < layer.length; i++) {
context.feature = layer.feature(i);
pbf.writeMessage(2, writeFeature, context);
}
var keys = context.keys;
for (i = 0; i < keys.length; i++) {
pbf.writeStringField(3, keys[i]);
}
var values = context.values;
for (i = 0; i < values.length; i++) {
pbf.writeMessage(4, writeValue, values[i]);
}
}
function writeFeature(context, pbf) {
var feature = context.feature;
if (feature.id !== undefined) {
pbf.writeVarintField(1, feature.id);
}
pbf.writeMessage(2, writeProperties, context);
pbf.writeVarintField(3, feature.type);
pbf.writeMessage(4, writeGeometry, feature);
}
function writeProperties(context, pbf) {
var feature = context.feature;
var keys = context.keys;
var values = context.values;
var keycache = context.keycache;
var valuecache = context.valuecache;
for (var key in feature.properties) {
var keyIndex = keycache[key];
if (typeof keyIndex === 'undefined') {
keys.push(key);
keyIndex = keys.length - 1;
keycache[key] = keyIndex;
}
pbf.writeVarint(keyIndex);
var value = feature.properties[key];
var type = typeof value;
if (type !== 'string' && type !== 'boolean' && type !== 'number') {
value = JSON.stringify(value);
}
var valueKey = type + ':' + value;
var valueIndex = valuecache[valueKey];
if (typeof valueIndex === 'undefined') {
values.push(value);
valueIndex = values.length - 1;
valuecache[valueKey] = valueIndex;
}
pbf.writeVarint(valueIndex);
}
}
function command(cmd, length) {
return (length << 3) + (cmd & 7);
}
function zigzag(num) {
return num << 1 ^ num >> 31;
}
function writeGeometry(feature, pbf) {
var geometry = feature.loadGeometry();
var type = feature.type;
var x = 0;
var y = 0;
var rings = geometry.length;
for (var r = 0; r < rings; r++) {
var ring = geometry[r];
var count = 1;
if (type === 1) {
count = ring.length;
}
pbf.writeVarint(command(1, count));
var lineCount = type === 3 ? ring.length - 1 : ring.length;
for (var i = 0; i < lineCount; i++) {
if (i === 1 && type !== 1) {
pbf.writeVarint(command(2, lineCount - 1));
}
var dx = ring[i].x - x;
var dy = ring[i].y - y;
pbf.writeVarint(zigzag(dx));
pbf.writeVarint(zigzag(dy));
x += dx;
y += dy;
}
if (type === 3) {
pbf.writeVarint(command(7, 1));
}
}
}
function writeValue(value, pbf) {
var type = typeof value;
if (type === 'string') {
pbf.writeStringField(1, value);
} else if (type === 'boolean') {
pbf.writeBooleanField(7, value);
} else if (type === 'number') {
if (value % 1 !== 0) {
pbf.writeDoubleField(3, value);
} else if (value < 0) {
pbf.writeSVarintField(6, value);
} else {
pbf.writeVarintField(5, value);
}
}
}
vtPbf.fromVectorTileJs = fromVectorTileJs_1;
vtPbf.fromGeojsonVt = fromGeojsonVt_1;
vtPbf.GeoJSONWrapper = GeoJSONWrapper_1;
function sortKD(ids, coords, nodeSize, left, right, depth) {
if (right - left <= nodeSize) {
return;
}
var m = left + right >> 1;
select(ids, coords, m, left, right, depth % 2);
sortKD(ids, coords, nodeSize, left, m - 1, depth + 1);
sortKD(ids, coords, nodeSize, m + 1, right, depth + 1);
}
function select(ids, coords, k, left, right, inc) {
while (right > left) {
if (right - left > 600) {
var n = right - left + 1;
var m = k - left + 1;
var z = Math.log(n);
var s = 0.5 * Math.exp(2 * z / 3);
var sd = 0.5 * Math.sqrt(z * s * (n - s) / n) * (m - n / 2 < 0 ? -1 : 1);
var newLeft = Math.max(left, Math.floor(k - m * s / n + sd));
var newRight = Math.min(right, Math.floor(k + (n - m) * s / n + sd));
select(ids, coords, k, newLeft, newRight, inc);
}
var t = coords[2 * k + inc];
var i = left;
var j = right;
swapItem(ids, coords, left, k);
if (coords[2 * right + inc] > t) {
swapItem(ids, coords, left, right);
}
while (i < j) {
swapItem(ids, coords, i, j);
i++;
j--;
while (coords[2 * i + inc] < t) {
i++;
}
while (coords[2 * j + inc] > t) {
j--;
}
}
if (coords[2 * left + inc] === t) {
swapItem(ids, coords, left, j);
} else {
j++;
swapItem(ids, coords, j, right);
}
if (j <= k) {
left = j + 1;
}
if (k <= j) {
right = j - 1;
}
}
}
function swapItem(ids, coords, i, j) {
swap(ids, i, j);
swap(coords, 2 * i, 2 * j);
swap(coords, 2 * i + 1, 2 * j + 1);
}
function swap(arr, i, j) {
var tmp = arr[i];
arr[i] = arr[j];
arr[j] = tmp;
}
function range(ids, coords, minX, minY, maxX, maxY, nodeSize) {
var stack = [
0,
ids.length - 1,
0
];
var result = [];
var x, y;
while (stack.length) {
var axis = stack.pop();
var right = stack.pop();
var left = stack.pop();
if (right - left <= nodeSize) {
for (var i = left; i <= right; i++) {
x = coords[2 * i];
y = coords[2 * i + 1];
if (x >= minX && x <= maxX && y >= minY && y <= maxY) {
result.push(ids[i]);
}
}
continue;
}
var m = Math.floor((left + right) / 2);
x = coords[2 * m];
y = coords[2 * m + 1];
if (x >= minX && x <= maxX && y >= minY && y <= maxY) {
result.push(ids[m]);
}
var nextAxis = (axis + 1) % 2;
if (axis === 0 ? minX <= x : minY <= y) {
stack.push(left);
stack.push(m - 1);
stack.push(nextAxis);
}
if (axis === 0 ? maxX >= x : maxY >= y) {
stack.push(m + 1);
stack.push(right);
stack.push(nextAxis);
}
}
return result;
}
function within(ids, coords, qx, qy, r, nodeSize) {
var stack = [
0,
ids.length - 1,
0
];
var result = [];
var r2 = r * r;
while (stack.length) {
var axis = stack.pop();
var right = stack.pop();
var left = stack.pop();
if (right - left <= nodeSize) {
for (var i = left; i <= right; i++) {
if (sqDist(coords[2 * i], coords[2 * i + 1], qx, qy) <= r2) {
result.push(ids[i]);
}
}
continue;
}
var m = Math.floor((left + right) / 2);
var x = coords[2 * m];
var y = coords[2 * m + 1];
if (sqDist(x, y, qx, qy) <= r2) {
result.push(ids[m]);
}
var nextAxis = (axis + 1) % 2;
if (axis === 0 ? qx - r <= x : qy - r <= y) {
stack.push(left);
stack.push(m - 1);
stack.push(nextAxis);
}
if (axis === 0 ? qx + r >= x : qy + r >= y) {
stack.push(m + 1);
stack.push(right);
stack.push(nextAxis);
}
}
return result;
}
function sqDist(ax, ay, bx, by) {
var dx = ax - bx;
var dy = ay - by;
return dx * dx + dy * dy;
}
var defaultGetX = function (p) {
return p[0];
};
var defaultGetY = function (p) {
return p[1];
};
var KDBush = function KDBush(points, getX, getY, nodeSize, ArrayType) {
if (getX === void 0)
getX = defaultGetX;
if (getY === void 0)
getY = defaultGetY;
if (nodeSize === void 0)
nodeSize = 64;
if (ArrayType === void 0)
ArrayType = Float64Array;
this.nodeSize = nodeSize;
this.points = points;
var IndexArrayType = points.length < 65536 ? Uint16Array : Uint32Array;
var ids = this.ids = new IndexArrayType(points.length);
var coords = this.coords = new ArrayType(points.length * 2);
for (var i = 0; i < points.length; i++) {
ids[i] = i;
coords[2 * i] = getX(points[i]);
coords[2 * i + 1] = getY(points[i]);
}
sortKD(ids, coords, nodeSize, 0, ids.length - 1, 0);
};
KDBush.prototype.range = function range$1(minX, minY, maxX, maxY) {
return range(this.ids, this.coords, minX, minY, maxX, maxY, this.nodeSize);
};
KDBush.prototype.within = function within$1(x, y, r) {
return within(this.ids, this.coords, x, y, r, this.nodeSize);
};
var defaultOptions = {
minZoom: 0,
maxZoom: 16,
minPoints: 2,
radius: 40,
extent: 512,
nodeSize: 64,
log: false,
generateId: false,
reduce: null,
map: function (props) {
return props;
}
};
var Supercluster = function Supercluster(options) {
this.options = extend(Object.create(defaultOptions), options);
this.trees = new Array(this.options.maxZoom + 1);
};
Supercluster.prototype.load = function load(points) {
var ref = this.options;
var log = ref.log;
var minZoom = ref.minZoom;
var maxZoom = ref.maxZoom;
var nodeSize = ref.nodeSize;
if (log) {
console.time('total time');
}
var timerId = 'prepare ' + points.length + ' points';
if (log) {
console.time(timerId);
}
this.points = points;
var clusters = [];
for (var i = 0; i < points.length; i++) {
if (!points[i].geometry) {
continue;
}
clusters.push(createPointCluster(points[i], i));
}
this.trees[maxZoom + 1] = new KDBush(clusters, getX, getY, nodeSize, Float32Array);
if (log) {
console.timeEnd(timerId);
}
for (var z = maxZoom; z >= minZoom; z--) {
var now = +Date.now();
clusters = this._cluster(clusters, z);
this.trees[z] = new KDBush(clusters, getX, getY, nodeSize, Float32Array);
if (log) {
console.log('z%d: %d clusters in %dms', z, clusters.length, +Date.now() - now);
}
}
if (log) {
console.timeEnd('total time');
}
return this;
};
Supercluster.prototype.getClusters = function getClusters(bbox, zoom) {
var minLng = ((bbox[0] + 180) % 360 + 360) % 360 - 180;
var minLat = Math.max(-90, Math.min(90, bbox[1]));
var maxLng = bbox[2] === 180 ? 180 : ((bbox[2] + 180) % 360 + 360) % 360 - 180;
var maxLat = Math.max(-90, Math.min(90, bbox[3]));
if (bbox[2] - bbox[0] >= 360) {
minLng = -180;
maxLng = 180;
} else if (minLng > maxLng) {
var easternHem = this.getClusters([
minLng,
minLat,
180,
maxLat
], zoom);
var westernHem = this.getClusters([
-180,
minLat,
maxLng,
maxLat
], zoom);
return easternHem.concat(westernHem);
}
var tree = this.trees[this._limitZoom(zoom)];
var ids = tree.range(lngX(minLng), latY(maxLat), lngX(maxLng), latY(minLat));
var clusters = [];
for (var i = 0, list = ids; i < list.length; i += 1) {
var id = list[i];
var c = tree.points[id];
clusters.push(c.numPoints ? getClusterJSON(c) : this.points[c.index]);
}
return clusters;
};
Supercluster.prototype.getChildren = function getChildren(clusterId) {
var originId = this._getOriginId(clusterId);
var originZoom = this._getOriginZoom(clusterId);
var errorMsg = 'No cluster with the specified id.';
var index = this.trees[originZoom];
if (!index) {
throw new Error(errorMsg);
}
var origin = index.points[originId];
if (!origin) {
throw new Error(errorMsg);
}
var r = this.options.radius / (this.options.extent * Math.pow(2, originZoom - 1));
var ids = index.within(origin.x, origin.y, r);
var children = [];
for (var i = 0, list = ids; i < list.length; i += 1) {
var id = list[i];
var c = index.points[id];
if (c.parentId === clusterId) {
children.push(c.numPoints ? getClusterJSON(c) : this.points[c.index]);
}
}
if (children.length === 0) {
throw new Error(errorMsg);
}
return children;
};
Supercluster.prototype.getLeaves = function getLeaves(clusterId, limit, offset) {
limit = limit || 10;
offset = offset || 0;
var leaves = [];
this._appendLeaves(leaves, clusterId, limit, offset, 0);
return leaves;
};
Supercluster.prototype.getTile = function getTile(z, x, y) {
var tree = this.trees[this._limitZoom(z)];
var z2 = Math.pow(2, z);
var ref = this.options;
var extent = ref.extent;
var radius = ref.radius;
var p = radius / extent;
var top = (y - p) / z2;
var bottom = (y + 1 + p) / z2;
var tile = { features: [] };
this._addTileFeatures(tree.range((x - p) / z2, top, (x + 1 + p) / z2, bottom), tree.points, x, y, z2, tile);
if (x === 0) {
this._addTileFeatures(tree.range(1 - p / z2, top, 1, bottom), tree.points, z2, y, z2, tile);
}
if (x === z2 - 1) {
this._addTileFeatures(tree.range(0, top, p / z2, bottom), tree.points, -1, y, z2, tile);
}
return tile.features.length ? tile : null;
};
Supercluster.prototype.getClusterExpansionZoom = function getClusterExpansionZoom(clusterId) {
var expansionZoom = this._getOriginZoom(clusterId) - 1;
while (expansionZoom <= this.options.maxZoom) {
var children = this.getChildren(clusterId);
expansionZoom++;
if (children.length !== 1) {
break;
}
clusterId = children[0].properties.cluster_id;
}
return expansionZoom;
};
Supercluster.prototype._appendLeaves = function _appendLeaves(result, clusterId, limit, offset, skipped) {
var children = this.getChildren(clusterId);
for (var i = 0, list = children; i < list.length; i += 1) {
var child = list[i];
var props = child.properties;
if (props && props.cluster) {
if (skipped + props.point_count <= offset) {
skipped += props.point_count;
} else {
skipped = this._appendLeaves(result, props.cluster_id, limit, offset, skipped);
}
} else if (skipped < offset) {
skipped++;
} else {
result.push(child);
}
if (result.length === limit) {
break;
}
}
return skipped;
};
Supercluster.prototype._addTileFeatures = function _addTileFeatures(ids, points, x, y, z2, tile) {
for (var i$1 = 0, list = ids; i$1 < list.length; i$1 += 1) {
var i = list[i$1];
var c = points[i];
var isCluster = c.numPoints;
var f = {
type: 1,
geometry: [[
Math.round(this.options.extent * (c.x * z2 - x)),
Math.round(this.options.extent * (c.y * z2 - y))
]],
tags: isCluster ? getClusterProperties(c) : this.points[c.index].properties
};
var id = void 0;
if (isCluster) {
id = c.id;
} else if (this.options.generateId) {
id = c.index;
} else if (this.points[c.index].id) {
id = this.points[c.index].id;
}
if (id !== undefined) {
f.id = id;
}
tile.features.push(f);
}
};
Supercluster.prototype._limitZoom = function _limitZoom(z) {
return Math.max(this.options.minZoom, Math.min(+z, this.options.maxZoom + 1));
};
Supercluster.prototype._cluster = function _cluster(points, zoom) {
var clusters = [];
var ref = this.options;
var radius = ref.radius;
var extent = ref.extent;
var reduce = ref.reduce;
var minPoints = ref.minPoints;
var r = radius / (extent * Math.pow(2, zoom));
for (var i = 0; i < points.length; i++) {
var p = points[i];
if (p.zoom <= zoom) {
continue;
}
p.zoom = zoom;
var tree = this.trees[zoom + 1];
var neighborIds = tree.within(p.x, p.y, r);
var numPointsOrigin = p.numPoints || 1;
var numPoints = numPointsOrigin;
for (var i$1 = 0, list = neighborIds; i$1 < list.length; i$1 += 1) {
var neighborId = list[i$1];
var b = tree.points[neighborId];
if (b.zoom > zoom) {
numPoints += b.numPoints || 1;
}
}
if (numPoints >= minPoints) {
var wx = p.x * numPointsOrigin;
var wy = p.y * numPointsOrigin;
var clusterProperties = reduce && numPointsOrigin > 1 ? this._map(p, true) : null;
var id = (i << 5) + (zoom + 1) + this.points.length;
for (var i$2 = 0, list$1 = neighborIds; i$2 < list$1.length; i$2 += 1) {
var neighborId$1 = list$1[i$2];
var b$1 = tree.points[neighborId$1];
if (b$1.zoom <= zoom) {
continue;
}
b$1.zoom = zoom;
var numPoints2 = b$1.numPoints || 1;
wx += b$1.x * numPoints2;
wy += b$1.y * numPoints2;
b$1.parentId = id;
if (reduce) {
if (!clusterProperties) {
clusterProperties = this._map(p, true);
}
reduce(clusterProperties, this._map(b$1));
}
}
p.parentId = id;
clusters.push(createCluster(wx / numPoints, wy / numPoints, id, numPoints, clusterProperties));
} else {
clusters.push(p);
if (numPoints > 1) {
for (var i$3 = 0, list$2 = neighborIds; i$3 < list$2.length; i$3 += 1) {
var neighborId$2 = list$2[i$3];
var b$2 = tree.points[neighborId$2];
if (b$2.zoom <= zoom) {
continue;
}
b$2.zoom = zoom;
clusters.push(b$2);
}
}
}
}
return clusters;
};
Supercluster.prototype._getOriginId = function _getOriginId(clusterId) {
return clusterId - this.points.length >> 5;
};
Supercluster.prototype._getOriginZoom = function _getOriginZoom(clusterId) {
return (clusterId - this.points.length) % 32;
};
Supercluster.prototype._map = function _map(point, clone) {
if (point.numPoints) {
return clone ? extend({}, point.properties) : point.properties;
}
var original = this.points[point.index].properties;
var result = this.options.map(original);
return clone && result === original ? extend({}, result) : result;
};
function createCluster(x, y, id, numPoints, properties) {
return {
x: x,
y: y,
zoom: Infinity,
id: id,
parentId: -1,
numPoints: numPoints,
properties: properties
};
}
function createPointCluster(p, id) {
var ref = p.geometry.coordinates;
var x = ref[0];
var y = ref[1];
return {
x: lngX(x),
y: latY(y),
zoom: Infinity,
index: id,
parentId: -1
};
}
function getClusterJSON(cluster) {
return {
type: 'Feature',
id: cluster.id,
properties: getClusterProperties(cluster),
geometry: {
type: 'Point',
coordinates: [
xLng(cluster.x),
yLat(cluster.y)
]
}
};
}
function getClusterProperties(cluster) {
var count = cluster.numPoints;
var abbrev = count >= 10000 ? Math.round(count / 1000) + 'k' : count >= 1000 ? Math.round(count / 100) / 10 + 'k' : count;
return extend(extend({}, cluster.properties), {
cluster: true,
cluster_id: cluster.id,
point_count: count,
point_count_abbreviated: abbrev
});
}
function lngX(lng) {
return lng / 360 + 0.5;
}
function latY(lat) {
var sin = Math.sin(lat * Math.PI / 180);
var y = 0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI;
return y < 0 ? 0 : y > 1 ? 1 : y;
}
function xLng(x) {
return (x - 0.5) * 360;
}
function yLat(y) {
var y2 = (180 - y * 360) * Math.PI / 180;
return 360 * Math.atan(Math.exp(y2)) / Math.PI - 90;
}
function extend(dest, src) {
for (var id in src) {
dest[id] = src[id];
}
return dest;
}
function getX(p) {
return p.x;
}
function getY(p) {
return p.y;
}
function simplify(coords, first, last, sqTolerance) {
var maxSqDist = sqTolerance;
var mid = last - first >> 1;
var minPosToMid = last - first;
var index;
var ax = coords[first];
var ay = coords[first + 1];
var bx = coords[last];
var by = coords[last + 1];
for (var i = first + 3; i < last; i += 3) {
var d = getSqSegDist(coords[i], coords[i + 1], ax, ay, bx, by);
if (d > maxSqDist) {
index = i;
maxSqDist = d;
} else if (d === maxSqDist) {
var posToMid = Math.abs(i - mid);
if (posToMid < minPosToMid) {
index = i;
minPosToMid = posToMid;
}
}
}
if (maxSqDist > sqTolerance) {
if (index - first > 3) {
simplify(coords, first, index, sqTolerance);
}
coords[index + 2] = maxSqDist;
if (last - index > 3) {
simplify(coords, index, last, sqTolerance);
}
}
}
function getSqSegDist(px, py, x, y, bx, by) {
var dx = bx - x;
var dy = by - y;
if (dx !== 0 || dy !== 0) {
var t = ((px - x) * dx + (py - y) * dy) / (dx * dx + dy * dy);
if (t > 1) {
x = bx;
y = by;
} else if (t > 0) {
x += dx * t;
y += dy * t;
}
}
dx = px - x;
dy = py - y;
return dx * dx + dy * dy;
}
function createFeature(id, type, geom, tags) {
var feature = {
id: typeof id === 'undefined' ? null : id,
type: type,
geometry: geom,
tags: tags,
minX: Infinity,
minY: Infinity,
maxX: -Infinity,
maxY: -Infinity
};
calcBBox(feature);
return feature;
}
function calcBBox(feature) {
var geom = feature.geometry;
var type = feature.type;
if (type === 'Point' || type === 'MultiPoint' || type === 'LineString') {
calcLineBBox(feature, geom);
} else if (type === 'Polygon' || type === 'MultiLineString') {
for (var i = 0; i < geom.length; i++) {
calcLineBBox(feature, geom[i]);
}
} else if (type === 'MultiPolygon') {
for (i = 0; i < geom.length; i++) {
for (var j = 0; j < geom[i].length; j++) {
calcLineBBox(feature, geom[i][j]);
}
}
}
}
function calcLineBBox(feature, geom) {
for (var i = 0; i < geom.length; i += 3) {
feature.minX = Math.min(feature.minX, geom[i]);
feature.minY = Math.min(feature.minY, geom[i + 1]);
feature.maxX = Math.max(feature.maxX, geom[i]);
feature.maxY = Math.max(feature.maxY, geom[i + 1]);
}
}
function convert(data, options) {
var features = [];
if (data.type === 'FeatureCollection') {
for (var i = 0; i < data.features.length; i++) {
convertFeature(features, data.features[i], options, i);
}
} else if (data.type === 'Feature') {
convertFeature(features, data, options);
} else {
convertFeature(features, { geometry: data }, options);
}
return features;
}
function convertFeature(features, geojson, options, index) {
if (!geojson.geometry) {
return;
}
var coords = geojson.geometry.coordinates;
var type = geojson.geometry.type;
var tolerance = Math.pow(options.tolerance / ((1 << options.maxZoom) * options.extent), 2);
var geometry = [];
var id = geojson.id;
if (options.promoteId) {
id = geojson.properties[options.promoteId];
} else if (options.generateId) {
id = index || 0;
}
if (type === 'Point') {
convertPoint(coords, geometry);
} else if (type === 'MultiPoint') {
for (var i = 0; i < coords.length; i++) {
convertPoint(coords[i], geometry);
}
} else if (type === 'LineString') {
convertLine(coords, geometry, tolerance, false);
} else if (type === 'MultiLineString') {
if (options.lineMetrics) {
for (i = 0; i < coords.length; i++) {
geometry = [];
convertLine(coords[i], geometry, tolerance, false);
features.push(createFeature(id, 'LineString', geometry, geojson.properties));
}
return;
} else {
convertLines(coords, geometry, tolerance, false);
}
} else if (type === 'Polygon') {
convertLines(coords, geometry, tolerance, true);
} else if (type === 'MultiPolygon') {
for (i = 0; i < coords.length; i++) {
var polygon = [];
convertLines(coords[i], polygon, tolerance, true);
geometry.push(polygon);
}
} else if (type === 'GeometryCollection') {
for (i = 0; i < geojson.geometry.geometries.length; i++) {
convertFeature(features, {
id: id,
geometry: geojson.geometry.geometries[i],
properties: geojson.properties
}, options, index);
}
return;
} else {
throw new Error('Input data is not a valid GeoJSON object.');
}
features.push(createFeature(id, type, geometry, geojson.properties));
}
function convertPoint(coords, out) {
out.push(projectX(coords[0]));
out.push(projectY(coords[1]));
out.push(0);
}
function convertLine(ring, out, tolerance, isPolygon) {
var x0, y0;
var size = 0;
for (var j = 0; j < ring.length; j++) {
var x = projectX(ring[j][0]);
var y = projectY(ring[j][1]);
out.push(x);
out.push(y);
out.push(0);
if (j > 0) {
if (isPolygon) {
size += (x0 * y - x * y0) / 2;
} else {
size += Math.sqrt(Math.pow(x - x0, 2) + Math.pow(y - y0, 2));
}
}
x0 = x;
y0 = y;
}
var last = out.length - 3;
out[2] = 1;
simplify(out, 0, last, tolerance);
out[last + 2] = 1;
out.size = Math.abs(size);
out.start = 0;
out.end = out.size;
}
function convertLines(rings, out, tolerance, isPolygon) {
for (var i = 0; i < rings.length; i++) {
var geom = [];
convertLine(rings[i], geom, tolerance, isPolygon);
out.push(geom);
}
}
function projectX(x) {
return x / 360 + 0.5;
}
function projectY(y) {
var sin = Math.sin(y * Math.PI / 180);
var y2 = 0.5 - 0.25 * Math.log((1 + sin) / (1 - sin)) / Math.PI;
return y2 < 0 ? 0 : y2 > 1 ? 1 : y2;
}
function clip(features, scale, k1, k2, axis, minAll, maxAll, options) {
k1 /= scale;
k2 /= scale;
if (minAll >= k1 && maxAll < k2) {
return features;
} else if (maxAll < k1 || minAll >= k2) {
return null;
}
var clipped = [];
for (var i = 0; i < features.length; i++) {
var feature = features[i];
var geometry = feature.geometry;
var type = feature.type;
var min = axis === 0 ? feature.minX : feature.minY;
var max = axis === 0 ? feature.maxX : feature.maxY;
if (min >= k1 && max < k2) {
clipped.push(feature);
continue;
} else if (max < k1 || min >= k2) {
continue;
}
var newGeometry = [];
if (type === 'Point' || type === 'MultiPoint') {
clipPoints(geometry, newGeometry, k1, k2, axis);
} else if (type === 'LineString') {
clipLine(geometry, newGeometry, k1, k2, axis, false, options.lineMetrics);
} else if (type === 'MultiLineString') {
clipLines(geometry, newGeometry, k1, k2, axis, false);
} else if (type === 'Polygon') {
clipLines(geometry, newGeometry, k1, k2, axis, true);
} else if (type === 'MultiPolygon') {
for (var j = 0; j < geometry.length; j++) {
var polygon = [];
clipLines(geometry[j], polygon, k1, k2, axis, true);
if (polygon.length) {
newGeometry.push(polygon);
}
}
}
if (newGeometry.length) {
if (options.lineMetrics && type === 'LineString') {
for (j = 0; j < newGeometry.length; j++) {
clipped.push(createFeature(feature.id, type, newGeometry[j], feature.tags));
}
continue;
}
if (type === 'LineString' || type === 'MultiLineString') {
if (newGeometry.length === 1) {
type = 'LineString';
newGeometry = newGeometry[0];
} else {
type = 'MultiLineString';
}
}
if (type === 'Point' || type === 'MultiPoint') {
type = newGeometry.length === 3 ? 'Point' : 'MultiPoint';
}
clipped.push(createFeature(feature.id, type, newGeometry, feature.tags));
}
}
return clipped.length ? clipped : null;
}
function clipPoints(geom, newGeom, k1, k2, axis) {
for (var i = 0; i < geom.length; i += 3) {
var a = geom[i + axis];
if (a >= k1 && a <= k2) {
newGeom.push(geom[i]);
newGeom.push(geom[i + 1]);
newGeom.push(geom[i + 2]);
}
}
}
function clipLine(geom, newGeom, k1, k2, axis, isPolygon, trackMetrics) {
var slice = newSlice(geom);
var intersect = axis === 0 ? intersectX : intersectY;
var len = geom.start;
var segLen, t;
for (var i = 0; i < geom.length - 3; i += 3) {
var ax = geom[i];
var ay = geom[i + 1];
var az = geom[i + 2];
var bx = geom[i + 3];
var by = geom[i + 4];
var a = axis === 0 ? ax : ay;
var b = axis === 0 ? bx : by;
var exited = false;
if (trackMetrics) {
segLen = Math.sqrt(Math.pow(ax - bx, 2) + Math.pow(ay - by, 2));
}
if (a < k1) {
if (b > k1) {
t = intersect(slice, ax, ay, bx, by, k1);
if (trackMetrics) {
slice.start = len + segLen * t;
}
}
} else if (a > k2) {
if (b < k2) {
t = intersect(slice, ax, ay, bx, by, k2);
if (trackMetrics) {
slice.start = len + segLen * t;
}
}
} else {
addPoint(slice, ax, ay, az);
}
if (b < k1 && a >= k1) {
t = intersect(slice, ax, ay, bx, by, k1);
exited = true;
}
if (b > k2 && a <= k2) {
t = intersect(slice, ax, ay, bx, by, k2);
exited = true;
}
if (!isPolygon && exited) {
if (trackMetrics) {
slice.end = len + segLen * t;
}
newGeom.push(slice);
slice = newSlice(geom);
}
if (trackMetrics) {
len += segLen;
}
}
var last = geom.length - 3;
ax = geom[last];
ay = geom[last + 1];
az = geom[last + 2];
a = axis === 0 ? ax : ay;
if (a >= k1 && a <= k2) {
addPoint(slice, ax, ay, az);
}
last = slice.length - 3;
if (isPolygon && last >= 3 && (slice[last] !== slice[0] || slice[last + 1] !== slice[1])) {
addPoint(slice, slice[0], slice[1], slice[2]);
}
if (slice.length) {
newGeom.push(slice);
}
}
function newSlice(line) {
var slice = [];
slice.size = line.size;
slice.start = line.start;
slice.end = line.end;
return slice;
}
function clipLines(geom, newGeom, k1, k2, axis, isPolygon) {
for (var i = 0; i < geom.length; i++) {
clipLine(geom[i], newGeom, k1, k2, axis, isPolygon, false);
}
}
function addPoint(out, x, y, z) {
out.push(x);
out.push(y);
out.push(z);
}
function intersectX(out, ax, ay, bx, by, x) {
var t = (x - ax) / (bx - ax);
out.push(x);
out.push(ay + (by - ay) * t);
out.push(1);
return t;
}
function intersectY(out, ax, ay, bx, by, y) {
var t = (y - ay) / (by - ay);
out.push(ax + (bx - ax) * t);
out.push(y);
out.push(1);
return t;
}
function wrap(features, options) {
var buffer = options.buffer / options.extent;
var merged = features;
var left = clip(features, 1, -1 - buffer, buffer, 0, -1, 2, options);
var right = clip(features, 1, 1 - buffer, 2 + buffer, 0, -1, 2, options);
if (left || right) {
merged = clip(features, 1, -buffer, 1 + buffer, 0, -1, 2, options) || [];
if (left) {
merged = shiftFeatureCoords(left, 1).concat(merged);
}
if (right) {
merged = merged.concat(shiftFeatureCoords(right, -1));
}
}
return merged;
}
function shiftFeatureCoords(features, offset) {
var newFeatures = [];
for (var i = 0; i < features.length; i++) {
var feature = features[i], type = feature.type;
var newGeometry;
if (type === 'Point' || type === 'MultiPoint' || type === 'LineString') {
newGeometry = shiftCoords(feature.geometry, offset);
} else if (type === 'MultiLineString' || type === 'Polygon') {
newGeometry = [];
for (var j = 0; j < feature.geometry.length; j++) {
newGeometry.push(shiftCoords(feature.geometry[j], offset));
}
} else if (type === 'MultiPolygon') {
newGeometry = [];
for (j = 0; j < feature.geometry.length; j++) {
var newPolygon = [];
for (var k = 0; k < feature.geometry[j].length; k++) {
newPolygon.push(shiftCoords(feature.geometry[j][k], offset));
}
newGeometry.push(newPolygon);
}
}
newFeatures.push(createFeature(feature.id, type, newGeometry, feature.tags));
}
return newFeatures;
}
function shiftCoords(points, offset) {
var newPoints = [];
newPoints.size = points.size;
if (points.start !== undefined) {
newPoints.start = points.start;
newPoints.end = points.end;
}
for (var i = 0; i < points.length; i += 3) {
newPoints.push(points[i] + offset, points[i + 1], points[i + 2]);
}
return newPoints;
}
function transformTile(tile, extent) {
if (tile.transformed) {
return tile;
}
var z2 = 1 << tile.z, tx = tile.x, ty = tile.y, i, j, k;
for (i = 0; i < tile.features.length; i++) {
var feature = tile.features[i], geom = feature.geometry, type = feature.type;
feature.geometry = [];
if (type === 1) {
for (j = 0; j < geom.length; j += 2) {
feature.geometry.push(transformPoint(geom[j], geom[j + 1], extent, z2, tx, ty));
}
} else {
for (j = 0; j < geom.length; j++) {
var ring = [];
for (k = 0; k < geom[j].length; k += 2) {
ring.push(transformPoint(geom[j][k], geom[j][k + 1], extent, z2, tx, ty));
}
feature.geometry.push(ring);
}
}
}
tile.transformed = true;
return tile;
}
function transformPoint(x, y, extent, z2, tx, ty) {
return [
Math.round(extent * (x * z2 - tx)),
Math.round(extent * (y * z2 - ty))
];
}
function createTile(features, z, tx, ty, options) {
var tolerance = z === options.maxZoom ? 0 : options.tolerance / ((1 << z) * options.extent);
var tile = {
features: [],
numPoints: 0,
numSimplified: 0,
numFeatures: 0,
source: null,
x: tx,
y: ty,
z: z,
transformed: false,
minX: 2,
minY: 1,
maxX: -1,
maxY: 0
};
for (var i = 0; i < features.length; i++) {
tile.numFeatures++;
addFeature(tile, features[i], tolerance, options);
var minX = features[i].minX;
var minY = features[i].minY;
var maxX = features[i].maxX;
var maxY = features[i].maxY;
if (minX < tile.minX) {
tile.minX = minX;
}
if (minY < tile.minY) {
tile.minY = minY;
}
if (maxX > tile.maxX) {
tile.maxX = maxX;
}
if (maxY > tile.maxY) {
tile.maxY = maxY;
}
}
return tile;
}
function addFeature(tile, feature, tolerance, options) {
var geom = feature.geometry, type = feature.type, simplified = [];
if (type === 'Point' || type === 'MultiPoint') {
for (var i = 0; i < geom.length; i += 3) {
simplified.push(geom[i]);
simplified.push(geom[i + 1]);
tile.numPoints++;
tile.numSimplified++;
}
} else if (type === 'LineString') {
addLine(simplified, geom, tile, tolerance, false, false);
} else if (type === 'MultiLineString' || type === 'Polygon') {
for (i = 0; i < geom.length; i++) {
addLine(simplified, geom[i], tile, tolerance, type === 'Polygon', i === 0);
}
} else if (type === 'MultiPolygon') {
for (var k = 0; k < geom.length; k++) {
var polygon = geom[k];
for (i = 0; i < polygon.length; i++) {
addLine(simplified, polygon[i], tile, tolerance, true, i === 0);
}
}
}
if (simplified.length) {
var tags = feature.tags || null;
if (type === 'LineString' && options.lineMetrics) {
tags = {};
for (var key in feature.tags) {
tags[key] = feature.tags[key];
}
tags['mapbox_clip_start'] = geom.start / geom.size;
tags['mapbox_clip_end'] = geom.end / geom.size;
}
var tileFeature = {
geometry: simplified,
type: type === 'Polygon' || type === 'MultiPolygon' ? 3 : type === 'LineString' || type === 'MultiLineString' ? 2 : 1,
tags: tags
};
if (feature.id !== null) {
tileFeature.id = feature.id;
}
tile.features.push(tileFeature);
}
}
function addLine(result, geom, tile, tolerance, isPolygon, isOuter) {
var sqTolerance = tolerance * tolerance;
if (tolerance > 0 && geom.size < (isPolygon ? sqTolerance : tolerance)) {
tile.numPoints += geom.length / 3;
return;
}
var ring = [];
for (var i = 0; i < geom.length; i += 3) {
if (tolerance === 0 || geom[i + 2] > sqTolerance) {
tile.numSimplified++;
ring.push(geom[i]);
ring.push(geom[i + 1]);
}
tile.numPoints++;
}
if (isPolygon) {
rewind$1(ring, isOuter);
}
result.push(ring);
}
function rewind$1(ring, clockwise) {
var area = 0;
for (var i = 0, len = ring.length, j = len - 2; i < len; j = i, i += 2) {
area += (ring[i] - ring[j]) * (ring[i + 1] + ring[j + 1]);
}
if (area > 0 === clockwise) {
for (i = 0, len = ring.length; i < len / 2; i += 2) {
var x = ring[i];
var y = ring[i + 1];
ring[i] = ring[len - 2 - i];
ring[i + 1] = ring[len - 1 - i];
ring[len - 2 - i] = x;
ring[len - 1 - i] = y;
}
}
}
function geojsonvt(data, options) {
return new GeoJSONVT(data, options);
}
function GeoJSONVT(data, options) {
options = this.options = extend$1(Object.create(this.options), options);
var debug = options.debug;
if (debug) {
console.time('preprocess data');
}
if (options.maxZoom < 0 || options.maxZoom > 24) {
throw new Error('maxZoom should be in the 0-24 range');
}
if (options.promoteId && options.generateId) {
throw new Error('promoteId and generateId cannot be used together.');
}
var features = convert(data, options);
this.tiles = {};
this.tileCoords = [];
if (debug) {
console.timeEnd('preprocess data');
console.log('index: maxZoom: %d, maxPoints: %d', options.indexMaxZoom, options.indexMaxPoints);
console.time('generate tiles');
this.stats = {};
this.total = 0;
}
features = wrap(features, options);
if (features.length) {
this.splitTile(features, 0, 0, 0);
}
if (debug) {
if (features.length) {
console.log('features: %d, points: %d', this.tiles[0].numFeatures, this.tiles[0].numPoints);
}
console.timeEnd('generate tiles');
console.log('tiles generated:', this.total, JSON.stringify(this.stats));
}
}
GeoJSONVT.prototype.options = {
maxZoom: 14,
indexMaxZoom: 5,
indexMaxPoints: 100000,
tolerance: 3,
extent: 4096,
buffer: 64,
lineMetrics: false,
promoteId: null,
generateId: false,
debug: 0
};
GeoJSONVT.prototype.splitTile = function (features, z, x, y, cz, cx, cy) {
var stack = [
features,
z,
x,
y
], options = this.options, debug = options.debug;
while (stack.length) {
y = stack.pop();
x = stack.pop();
z = stack.pop();
features = stack.pop();
var z2 = 1 << z, id = toID(z, x, y), tile = this.tiles[id];
if (!tile) {
if (debug > 1) {
console.time('creation');
}
tile = this.tiles[id] = createTile(features, z, x, y, options);
this.tileCoords.push({
z: z,
x: x,
y: y
});
if (debug) {
if (debug > 1) {
console.log('tile z%d-%d-%d (features: %d, points: %d, simplified: %d)', z, x, y, tile.numFeatures, tile.numPoints, tile.numSimplified);
console.timeEnd('creation');
}
var key = 'z' + z;
this.stats[key] = (this.stats[key] || 0) + 1;
this.total++;
}
}
tile.source = features;
if (!cz) {
if (z === options.indexMaxZoom || tile.numPoints <= options.indexMaxPoints) {
continue;
}
} else {
if (z === options.maxZoom || z === cz) {
continue;
}
var m = 1 << cz - z;
if (x !== Math.floor(cx / m) || y !== Math.floor(cy / m)) {
continue;
}
}
tile.source = null;
if (features.length === 0) {
continue;
}
if (debug > 1) {
console.time('clipping');
}
var k1 = 0.5 * options.buffer / options.extent, k2 = 0.5 - k1, k3 = 0.5 + k1, k4 = 1 + k1, tl, bl, tr, br, left, right;
tl = bl = tr = br = null;
left = clip(features, z2, x - k1, x + k3, 0, tile.minX, tile.maxX, options);
right = clip(features, z2, x + k2, x + k4, 0, tile.minX, tile.maxX, options);
features = null;
if (left) {
tl = clip(left, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, options);
bl = clip(left, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, options);
left = null;
}
if (right) {
tr = clip(right, z2, y - k1, y + k3, 1, tile.minY, tile.maxY, options);
br = clip(right, z2, y + k2, y + k4, 1, tile.minY, tile.maxY, options);
right = null;
}
if (debug > 1) {
console.timeEnd('clipping');
}
stack.push(tl || [], z + 1, x * 2, y * 2);
stack.push(bl || [], z + 1, x * 2, y * 2 + 1);
stack.push(tr || [], z + 1, x * 2 + 1, y * 2);
stack.push(br || [], z + 1, x * 2 + 1, y * 2 + 1);
}
};
GeoJSONVT.prototype.getTile = function (z, x, y) {
var options = this.options, extent = options.extent, debug = options.debug;
if (z < 0 || z > 24) {
return null;
}
var z2 = 1 << z;
x = (x % z2 + z2) % z2;
var id = toID(z, x, y);
if (this.tiles[id]) {
return transformTile(this.tiles[id], extent);
}
if (debug > 1) {
console.log('drilling down to z%d-%d-%d', z, x, y);
}
var z0 = z, x0 = x, y0 = y, parent;
while (!parent && z0 > 0) {
z0--;
x0 = Math.floor(x0 / 2);
y0 = Math.floor(y0 / 2);
parent = this.tiles[toID(z0, x0, y0)];
}
if (!parent || !parent.source) {
return null;
}
if (debug > 1) {
console.log('found parent tile z%d-%d-%d', z0, x0, y0);
}
if (debug > 1) {
console.time('drilling down');
}
this.splitTile(parent.source, z0, x0, y0, z, x, y);
if (debug > 1) {
console.timeEnd('drilling down');
}
return this.tiles[id] ? transformTile(this.tiles[id], extent) : null;
};
function toID(z, x, y) {
return ((1 << z) * y + x) * 32 + z;
}
function extend$1(dest, src) {
for (var i in src) {
dest[i] = src[i];
}
return dest;
}
function loadGeoJSONTile(params, callback) {
var canonical = params.tileID.canonical;
if (!this._geoJSONIndex) {
return callback(null, null);
}
var geoJSONTile = this._geoJSONIndex.getTile(canonical.z, canonical.x, canonical.y);
if (!geoJSONTile) {
return callback(null, null);
}
var geojsonWrapper = new GeoJSONWrapper(geoJSONTile.features);
var pbf = vtPbf(geojsonWrapper);
if (pbf.byteOffset !== 0 || pbf.byteLength !== pbf.buffer.byteLength) {
pbf = new Uint8Array(pbf);
}
callback(null, {
vectorTile: geojsonWrapper,
rawData: pbf.buffer
});
}
var GeoJSONWorkerSource = function (VectorTileWorkerSource) {
function GeoJSONWorkerSource(actor, layerIndex, availableImages, loadGeoJSON) {
VectorTileWorkerSource.call(this, actor, layerIndex, availableImages, loadGeoJSONTile);
if (loadGeoJSON) {
this.loadGeoJSON = loadGeoJSON;
}
}
if (VectorTileWorkerSource)
GeoJSONWorkerSource.__proto__ = VectorTileWorkerSource;
GeoJSONWorkerSource.prototype = Object.create(VectorTileWorkerSource && VectorTileWorkerSource.prototype);
GeoJSONWorkerSource.prototype.constructor = GeoJSONWorkerSource;
GeoJSONWorkerSource.prototype.loadData = function loadData(params, callback) {
if (this._pendingCallback) {
this._pendingCallback(null, { abandoned: true });
}
this._pendingCallback = callback;
this._pendingLoadDataParams = params;
if (this._state && this._state !== 'Idle') {
this._state = 'NeedsLoadData';
} else {
this._state = 'Coalescing';
this._loadData();
}
};
GeoJSONWorkerSource.prototype._loadData = function _loadData() {
var this$1 = this;
if (!this._pendingCallback || !this._pendingLoadDataParams) {
return;
}
var callback = this._pendingCallback;
var params = this._pendingLoadDataParams;
delete this._pendingCallback;
delete this._pendingLoadDataParams;
var perf = params && params.request && params.request.collectResourceTiming ? new performance.RequestPerformance(params.request) : false;
this.loadGeoJSON(params, function (err, data) {
if (err || !data) {
return callback(err);
} else if (typeof data !== 'object') {
return callback(new Error('Input data given to \'' + params.source + '\' is not a valid GeoJSON object.'));
} else {
geojsonRewind(data, true);
try {
if (params.filter) {
var compiled = performance.createExpression(params.filter, {
type: 'boolean',
'property-type': 'data-driven',
overridable: false,
transition: false
});
if (compiled.result === 'error') {
throw new Error(compiled.value.map(function (err) {
return err.key + ': ' + err.message;
}).join(', '));
}
var features = data.features.filter(function (feature) {
return compiled.value.evaluate({ zoom: 0 }, feature);
});
data = {
type: 'FeatureCollection',
features: features
};
}
this$1._geoJSONIndex = params.cluster ? new Supercluster(getSuperclusterOptions(params)).load(data.features) : geojsonvt(data, params.geojsonVtOptions);
} catch (err) {
return callback(err);
}
this$1.loaded = {};
var result = {};
if (perf) {
var resourceTimingData = perf.finish();
if (resourceTimingData) {
result.resourceTiming = {};
result.resourceTiming[params.source] = JSON.parse(JSON.stringify(resourceTimingData));
}
}
callback(null, result);
}
});
};
GeoJSONWorkerSource.prototype.coalesce = function coalesce() {
if (this._state === 'Coalescing') {
this._state = 'Idle';
} else if (this._state === 'NeedsLoadData') {
this._state = 'Coalescing';
this._loadData();
}
};
GeoJSONWorkerSource.prototype.reloadTile = function reloadTile(params, callback) {
var loaded = this.loaded, uid = params.uid;
if (loaded && loaded[uid]) {
return VectorTileWorkerSource.prototype.reloadTile.call(this, params, callback);
} else {
return this.loadTile(params, callback);
}
};
GeoJSONWorkerSource.prototype.loadGeoJSON = function loadGeoJSON(params, callback) {
if (params.request) {
performance.getJSON(params.request, callback);
} else if (typeof params.data === 'string') {
try {
return callback(null, JSON.parse(params.data));
} catch (e) {
return callback(new Error('Input data given to \'' + params.source + '\' is not a valid GeoJSON object.'));
}
} else {
return callback(new Error('Input data given to \'' + params.source + '\' is not a valid GeoJSON object.'));
}
};
GeoJSONWorkerSource.prototype.removeSource = function removeSource(params, callback) {
if (this._pendingCallback) {
this._pendingCallback(null, { abandoned: true });
}
callback();
};
GeoJSONWorkerSource.prototype.getClusterExpansionZoom = function getClusterExpansionZoom(params, callback) {
try {
callback(null, this._geoJSONIndex.getClusterExpansionZoom(params.clusterId));
} catch (e) {
callback(e);
}
};
GeoJSONWorkerSource.prototype.getClusterChildren = function getClusterChildren(params, callback) {
try {
callback(null, this._geoJSONIndex.getChildren(params.clusterId));
} catch (e) {
callback(e);
}
};
GeoJSONWorkerSource.prototype.getClusterLeaves = function getClusterLeaves(params, callback) {
try {
callback(null, this._geoJSONIndex.getLeaves(params.clusterId, params.limit, params.offset));
} catch (e) {
callback(e);
}
};
return GeoJSONWorkerSource;
}(VectorTileWorkerSource);
function getSuperclusterOptions(ref) {
var superclusterOptions = ref.superclusterOptions;
var clusterProperties = ref.clusterProperties;
if (!clusterProperties || !superclusterOptions) {
return superclusterOptions;
}
var mapExpressions = {};
var reduceExpressions = {};
var globals = {
accumulated: null,
zoom: 0
};
var feature = { properties: null };
var propertyNames = Object.keys(clusterProperties);
for (var i = 0, list = propertyNames; i < list.length; i += 1) {
var key = list[i];
var ref$1 = clusterProperties[key];
var operator = ref$1[0];
var mapExpression = ref$1[1];
var mapExpressionParsed = performance.createExpression(mapExpression);
var reduceExpressionParsed = performance.createExpression(typeof operator === 'string' ? [
operator,
['accumulated'],
[
'get',
key
]
] : operator);
mapExpressions[key] = mapExpressionParsed.value;
reduceExpressions[key] = reduceExpressionParsed.value;
}
superclusterOptions.map = function (pointProperties) {
feature.properties = pointProperties;
var properties = {};
for (var i = 0, list = propertyNames; i < list.length; i += 1) {
var key = list[i];
properties[key] = mapExpressions[key].evaluate(globals, feature);
}
return properties;
};
superclusterOptions.reduce = function (accumulated, clusterProperties) {
feature.properties = clusterProperties;
for (var i = 0, list = propertyNames; i < list.length; i += 1) {
var key = list[i];
globals.accumulated = accumulated[key];
accumulated[key] = reduceExpressions[key].evaluate(globals, feature);
}
};
return superclusterOptions;
}
var Worker = function Worker(self) {
var this$1 = this;
this.self = self;
this.actor = new performance.Actor(self, this);
this.layerIndexes = {};
this.availableImages = {};
this.workerSourceTypes = {
vector: VectorTileWorkerSource,
geojson: GeoJSONWorkerSource
};
this.workerSources = {};
this.demWorkerSources = {};
this.self.registerWorkerSource = function (name, WorkerSource) {
if (this$1.workerSourceTypes[name]) {
throw new Error('Worker source with name "' + name + '" already registered.');
}
this$1.workerSourceTypes[name] = WorkerSource;
};
this.self.registerRTLTextPlugin = function (rtlTextPlugin) {
if (performance.plugin.isParsed()) {
throw new Error('RTL text plugin already registered.');
}
performance.plugin['applyArabicShaping'] = rtlTextPlugin.applyArabicShaping;
performance.plugin['processBidirectionalText'] = rtlTextPlugin.processBidirectionalText;
performance.plugin['processStyledBidirectionalText'] = rtlTextPlugin.processStyledBidirectionalText;
};
};
Worker.prototype.setReferrer = function setReferrer(mapID, referrer) {
this.referrer = referrer;
};
Worker.prototype.setImages = function setImages(mapId, images, callback) {
this.availableImages[mapId] = images;
for (var workerSource in this.workerSources[mapId]) {
var ws = this.workerSources[mapId][workerSource];
for (var source in ws) {
ws[source].availableImages = images;
}
}
callback();
};
Worker.prototype.setLayers = function setLayers(mapId, layers, callback) {
this.getLayerIndex(mapId).replace(layers);
callback();
};
Worker.prototype.updateLayers = function updateLayers(mapId, params, callback) {
this.getLayerIndex(mapId).update(params.layers, params.removedIds);
callback();
};
Worker.prototype.loadTile = function loadTile(mapId, params, callback) {
this.getWorkerSource(mapId, params.type, params.source).loadTile(params, callback);
};
Worker.prototype.loadDEMTile = function loadDEMTile(mapId, params, callback) {
this.getDEMWorkerSource(mapId, params.source).loadTile(params, callback);
};
Worker.prototype.reloadTile = function reloadTile(mapId, params, callback) {
this.getWorkerSource(mapId, params.type, params.source).reloadTile(params, callback);
};
Worker.prototype.abortTile = function abortTile(mapId, params, callback) {
this.getWorkerSource(mapId, params.type, params.source).abortTile(params, callback);
};
Worker.prototype.removeTile = function removeTile(mapId, params, callback) {
this.getWorkerSource(mapId, params.type, params.source).removeTile(params, callback);
};
Worker.prototype.removeDEMTile = function removeDEMTile(mapId, params) {
this.getDEMWorkerSource(mapId, params.source).removeTile(params);
};
Worker.prototype.removeSource = function removeSource(mapId, params, callback) {
if (!this.workerSources[mapId] || !this.workerSources[mapId][params.type] || !this.workerSources[mapId][params.type][params.source]) {
return;
}
var worker = this.workerSources[mapId][params.type][params.source];
delete this.workerSources[mapId][params.type][params.source];
if (worker.removeSource !== undefined) {
worker.removeSource(params, callback);
} else {
callback();
}
};
Worker.prototype.loadWorkerSource = function loadWorkerSource(map, params, callback) {
try {
this.self.importScripts(params.url);
callback();
} catch (e) {
callback(e.toString());
}
};
Worker.prototype.syncRTLPluginState = function syncRTLPluginState(map, state, callback) {
try {
performance.plugin.setState(state);
var pluginURL = performance.plugin.getPluginURL();
if (performance.plugin.isLoaded() && !performance.plugin.isParsed() && pluginURL != null) {
this.self.importScripts(pluginURL);
var complete = performance.plugin.isParsed();
var error = complete ? undefined : new Error('RTL Text Plugin failed to import scripts from ' + pluginURL);
callback(error, complete);
}
} catch (e) {
callback(e.toString());
}
};
Worker.prototype.getAvailableImages = function getAvailableImages(mapId) {
var availableImages = this.availableImages[mapId];
if (!availableImages) {
availableImages = [];
}
return availableImages;
};
Worker.prototype.getLayerIndex = function getLayerIndex(mapId) {
var layerIndexes = this.layerIndexes[mapId];
if (!layerIndexes) {
layerIndexes = this.layerIndexes[mapId] = new StyleLayerIndex();
}
return layerIndexes;
};
Worker.prototype.getWorkerSource = function getWorkerSource(mapId, type, source) {
var this$1 = this;
if (!this.workerSources[mapId]) {
this.workerSources[mapId] = {};
}
if (!this.workerSources[mapId][type]) {
this.workerSources[mapId][type] = {};
}
if (!this.workerSources[mapId][type][source]) {
var actor = {
send: function (type, data, callback) {
this$1.actor.send(type, data, callback, mapId);
}
};
this.workerSources[mapId][type][source] = new this.workerSourceTypes[type](actor, this.getLayerIndex(mapId), this.getAvailableImages(mapId));
}
return this.workerSources[mapId][type][source];
};
Worker.prototype.getDEMWorkerSource = function getDEMWorkerSource(mapId, source) {
if (!this.demWorkerSources[mapId]) {
this.demWorkerSources[mapId] = {};
}
if (!this.demWorkerSources[mapId][source]) {
this.demWorkerSources[mapId][source] = new RasterDEMTileWorkerSource();
}
return this.demWorkerSources[mapId][source];
};
Worker.prototype.enforceCacheSizeLimit = function enforceCacheSizeLimit$1(mapId, limit) {
performance.enforceCacheSizeLimit(limit);
};
if (typeof WorkerGlobalScope !== 'undefined' && typeof self !== 'undefined' && self instanceof WorkerGlobalScope) {
self.worker = new Worker(self);
}
return Worker;
});
define(['./shared'], function (performance) { 'use strict';
var mapboxGlSupported = performance.createCommonjsModule(function (module) {
if ( module.exports) {
module.exports = isSupported;
} else if (window) {
window.mapboxgl = window.mapboxgl || {};
window.mapboxgl.supported = isSupported;
window.mapboxgl.notSupportedReason = notSupportedReason;
}
function isSupported(options) {
return !notSupportedReason(options);
}
function notSupportedReason(options) {
if (!isBrowser()) {
return 'not a browser';
}
if (!isArraySupported()) {
return 'insufficent Array support';
}
if (!isFunctionSupported()) {
return 'insufficient Function support';
}
if (!isObjectSupported()) {
return 'insufficient Object support';
}
if (!isJSONSupported()) {
return 'insufficient JSON support';
}
if (!isWorkerSupported()) {
return 'insufficient worker support';
}
if (!isUint8ClampedArraySupported()) {
return 'insufficient Uint8ClampedArray support';
}
if (!isArrayBufferSupported()) {
return 'insufficient ArrayBuffer support';
}
if (!isCanvasGetImageDataSupported()) {
return 'insufficient Canvas/getImageData support';
}
if (!isWebGLSupportedCached(options && options.failIfMajorPerformanceCaveat)) {
return 'insufficient WebGL support';
}
}
function isBrowser() {
return typeof window !== 'undefined' && typeof document !== 'undefined';
}
function isArraySupported() {
return Array.prototype && Array.prototype.every && Array.prototype.filter && Array.prototype.forEach && Array.prototype.indexOf && Array.prototype.lastIndexOf && Array.prototype.map && Array.prototype.some && Array.prototype.reduce && Array.prototype.reduceRight && Array.isArray;
}
function isFunctionSupported() {
return Function.prototype && Function.prototype.bind;
}
function isObjectSupported() {
return Object.keys && Object.create && Object.getPrototypeOf && Object.getOwnPropertyNames && Object.isSealed && Object.isFrozen && Object.isExtensible && Object.getOwnPropertyDescriptor && Object.defineProperty && Object.defineProperties && Object.seal && Object.freeze && Object.preventExtensions;
}
function isJSONSupported() {
return 'JSON' in window && 'parse' in JSON && 'stringify' in JSON;
}
function isWorkerSupported() {
if (!('Worker' in window && 'Blob' in window && 'URL' in window)) {
return false;
}
var blob = new Blob([''], { type: 'text/javascript' });
var workerURL = URL.createObjectURL(blob);
var supported;
var worker;
try {
worker = new Worker(workerURL);
supported = true;
} catch (e) {
supported = false;
}
if (worker) {
worker.terminate();
}
URL.revokeObjectURL(workerURL);
return supported;
}
function isUint8ClampedArraySupported() {
return 'Uint8ClampedArray' in window;
}
function isArrayBufferSupported() {
return ArrayBuffer.isView;
}
function isCanvasGetImageDataSupported() {
var canvas = document.createElement('canvas');
canvas.width = canvas.height = 1;
var context = canvas.getContext('2d');
if (!context) {
return false;
}
var imageData = context.getImageData(0, 0, 1, 1);
return imageData && imageData.width === canvas.width;
}
var isWebGLSupportedCache = {};
function isWebGLSupportedCached(failIfMajorPerformanceCaveat) {
if (isWebGLSupportedCache[failIfMajorPerformanceCaveat] === undefined) {
isWebGLSupportedCache[failIfMajorPerformanceCaveat] = isWebGLSupported(failIfMajorPerformanceCaveat);
}
return isWebGLSupportedCache[failIfMajorPerformanceCaveat];
}
isSupported.webGLContextAttributes = {
antialias: false,
alpha: true,
stencil: true,
depth: true
};
function getWebGLContext(failIfMajorPerformanceCaveat) {
var canvas = document.createElement('canvas');
var attributes = Object.create(isSupported.webGLContextAttributes);
attributes.failIfMajorPerformanceCaveat = failIfMajorPerformanceCaveat;
if (canvas.probablySupportsContext) {
return canvas.probablySupportsContext('webgl', attributes) || canvas.probablySupportsContext('experimental-webgl', attributes);
} else if (canvas.supportsContext) {
return canvas.supportsContext('webgl', attributes) || canvas.supportsContext('experimental-webgl', attributes);
} else {
return canvas.getContext('webgl', attributes) || canvas.getContext('experimental-webgl', attributes);
}
}
function isWebGLSupported(failIfMajorPerformanceCaveat) {
var gl = getWebGLContext(failIfMajorPerformanceCaveat);
if (!gl) {
return false;
}
var shader = gl.createShader(gl.VERTEX_SHADER);
if (!shader || gl.isContextLost()) {
return false;
}
gl.shaderSource(shader, 'void main() {}');
gl.compileShader(shader);
return gl.getShaderParameter(shader, gl.COMPILE_STATUS) === true;
}
});
var DOM = {};
DOM.create = function (tagName, className, container) {
var el = performance.window.document.createElement(tagName);
if (className !== undefined) {
el.className = className;
}
if (container) {
container.appendChild(el);
}
return el;
};
DOM.createNS = function (namespaceURI, tagName) {
var el = performance.window.document.createElementNS(namespaceURI, tagName);
return el;
};
var docStyle = performance.window.document && performance.window.document.documentElement.style;
function testProp(props) {
if (!docStyle) {
return props[0];
}
for (var i = 0; i < props.length; i++) {
if (props[i] in docStyle) {
return props[i];
}
}
return props[0];
}
var selectProp = testProp([
'userSelect',
'MozUserSelect',
'WebkitUserSelect',
'msUserSelect'
]);
var userSelect;
DOM.disableDrag = function () {
if (docStyle && selectProp) {
userSelect = docStyle[selectProp];
docStyle[selectProp] = 'none';
}
};
DOM.enableDrag = function () {
if (docStyle && selectProp) {
docStyle[selectProp] = userSelect;
}
};
var transformProp = testProp([
'transform',
'WebkitTransform'
]);
DOM.setTransform = function (el, value) {
el.style[transformProp] = value;
};
var passiveSupported = false;
try {
var options$1 = Object.defineProperty({}, 'passive', {
get: function get() {
passiveSupported = true;
}
});
performance.window.addEventListener('test', options$1, options$1);
performance.window.removeEventListener('test', options$1, options$1);
} catch (err) {
passiveSupported = false;
}
DOM.addEventListener = function (target, type, callback, options) {
if (options === void 0)
options = {};
if ('passive' in options && passiveSupported) {
target.addEventListener(type, callback, options);
} else {
target.addEventListener(type, callback, options.capture);
}
};
DOM.removeEventListener = function (target, type, callback, options) {
if (options === void 0)
options = {};
if ('passive' in options && passiveSupported) {
target.removeEventListener(type, callback, options);
} else {
target.removeEventListener(type, callback, options.capture);
}
};
var suppressClick = function (e) {
e.preventDefault();
e.stopPropagation();
performance.window.removeEventListener('click', suppressClick, true);
};
DOM.suppressClick = function () {
performance.window.addEventListener('click', suppressClick, true);
performance.window.setTimeout(function () {
performance.window.removeEventListener('click', suppressClick, true);
}, 0);
};
DOM.mousePos = function (el, e) {
var rect = el.getBoundingClientRect();
return new performance.Point(e.clientX - rect.left - el.clientLeft, e.clientY - rect.top - el.clientTop);
};
DOM.touchPos = function (el, touches) {
var rect = el.getBoundingClientRect(), points = [];
for (var i = 0; i < touches.length; i++) {
points.push(new performance.Point(touches[i].clientX - rect.left - el.clientLeft, touches[i].clientY - rect.top - el.clientTop));
}
return points;
};
DOM.mouseButton = function (e) {
if (typeof performance.window.InstallTrigger !== 'undefined' && e.button === 2 && e.ctrlKey && performance.window.navigator.platform.toUpperCase().indexOf('MAC') >= 0) {
return 0;
}
return e.button;
};
DOM.remove = function (node) {
if (node.parentNode) {
node.parentNode.removeChild(node);
}
};
function loadSprite (baseURL, requestManager, callback) {
var json, image, error;
var format = performance.browser.devicePixelRatio > 1 ? '@2x' : '';
var jsonRequest = performance.getJSON(requestManager.transformRequest(requestManager.normalizeSpriteURL(baseURL, format, '.json'), performance.ResourceType.SpriteJSON), function (err, data) {
jsonRequest = null;
if (!error) {
error = err;
json = data;
maybeComplete();
}
});
var imageRequest = performance.getImage(requestManager.transformRequest(requestManager.normalizeSpriteURL(baseURL, format, '.png'), performance.ResourceType.SpriteImage), function (err, img) {
imageRequest = null;
if (!error) {
error = err;
image = img;
maybeComplete();
}
});
function maybeComplete() {
if (error) {
callback(error);
} else if (json && image) {
var imageData = performance.browser.getImageData(image);
var result = {};
for (var id in json) {
var ref = json[id];
var width = ref.width;
var height = ref.height;
var x = ref.x;
var y = ref.y;
var sdf = ref.sdf;
var pixelRatio = ref.pixelRatio;
var stretchX = ref.stretchX;
var stretchY = ref.stretchY;
var content = ref.content;
var data = new performance.RGBAImage({
width: width,
height: height
});
performance.RGBAImage.copy(imageData, data, {
x: x,
y: y
}, {
x: 0,
y: 0
}, {
width: width,
height: height
});
result[id] = {
data: data,
pixelRatio: pixelRatio,
sdf: sdf,
stretchX: stretchX,
stretchY: stretchY,
content: content
};
}
callback(null, result);
}
}
return {
cancel: function cancel() {
if (jsonRequest) {
jsonRequest.cancel();
jsonRequest = null;
}
if (imageRequest) {
imageRequest.cancel();
imageRequest = null;
}
}
};
}
function renderStyleImage(image) {
var userImage = image.userImage;
if (userImage && userImage.render) {
var updated = userImage.render();
if (updated) {
image.data.replace(new Uint8Array(userImage.data.buffer));
return true;
}
}
return false;
}
var padding = 1;
var ImageManager = function (Evented) {
function ImageManager() {
Evented.call(this);
this.images = {};
this.updatedImages = {};
this.callbackDispatchedThisFrame = {};
this.loaded = false;
this.requestors = [];
this.patterns = {};
this.atlasImage = new performance.RGBAImage({
width: 1,
height: 1
});
this.dirty = true;
}
if (Evented)
ImageManager.__proto__ = Evented;
ImageManager.prototype = Object.create(Evented && Evented.prototype);
ImageManager.prototype.constructor = ImageManager;
ImageManager.prototype.isLoaded = function isLoaded() {
return this.loaded;
};
ImageManager.prototype.setLoaded = function setLoaded(loaded) {
if (this.loaded === loaded) {
return;
}
this.loaded = loaded;
if (loaded) {
for (var i = 0, list = this.requestors; i < list.length; i += 1) {
var ref = list[i];
var ids = ref.ids;
var callback = ref.callback;
this._notify(ids, callback);
}
this.requestors = [];
}
};
ImageManager.prototype.getImage = function getImage(id) {
return this.images[id];
};
ImageManager.prototype.addImage = function addImage(id, image) {
if (this._validate(id, image)) {
this.images[id] = image;
}
};
ImageManager.prototype._validate = function _validate(id, image) {
var valid = true;
if (!this._validateStretch(image.stretchX, image.data && image.data.width)) {
this.fire(new performance.ErrorEvent(new Error('Image "' + id + '" has invalid "stretchX" value')));
valid = false;
}
if (!this._validateStretch(image.stretchY, image.data && image.data.height)) {
this.fire(new performance.ErrorEvent(new Error('Image "' + id + '" has invalid "stretchY" value')));
valid = false;
}
if (!this._validateContent(image.content, image)) {
this.fire(new performance.ErrorEvent(new Error('Image "' + id + '" has invalid "content" value')));
valid = false;
}
return valid;
};
ImageManager.prototype._validateStretch = function _validateStretch(stretch, size) {
if (!stretch) {
return true;
}
var last = 0;
for (var i = 0, list = stretch; i < list.length; i += 1) {
var part = list[i];
if (part[0] < last || part[1] < part[0] || size < part[1]) {
return false;
}
last = part[1];
}
return true;
};
ImageManager.prototype._validateContent = function _validateContent(content, image) {
if (!content) {
return true;
}
if (content.length !== 4) {
return false;
}
if (content[0] < 0 || image.data.width < content[0]) {
return false;
}
if (content[1] < 0 || image.data.height < content[1]) {
return false;
}
if (content[2] < 0 || image.data.width < content[2]) {
return false;
}
if (content[3] < 0 || image.data.height < content[3]) {
return false;
}
if (content[2] < content[0]) {
return false;
}
if (content[3] < content[1]) {
return false;
}
return true;
};
ImageManager.prototype.updateImage = function updateImage(id, image) {
var oldImage = this.images[id];
image.version = oldImage.version + 1;
this.images[id] = image;
this.updatedImages[id] = true;
};
ImageManager.prototype.removeImage = function removeImage(id) {
var image = this.images[id];
delete this.images[id];
delete this.patterns[id];
if (image.userImage && image.userImage.onRemove) {
image.userImage.onRemove();
}
};
ImageManager.prototype.listImages = function listImages() {
return Object.keys(this.images);
};
ImageManager.prototype.getImages = function getImages(ids, callback) {
var hasAllDependencies = true;
if (!this.isLoaded()) {
for (var i = 0, list = ids; i < list.length; i += 1) {
var id = list[i];
if (!this.images[id]) {
hasAllDependencies = false;
}
}
}
if (this.isLoaded() || hasAllDependencies) {
this._notify(ids, callback);
} else {
this.requestors.push({
ids: ids,
callback: callback
});
}
};
ImageManager.prototype._notify = function _notify(ids, callback) {
var response = {};
for (var i = 0, list = ids; i < list.length; i += 1) {
var id = list[i];
if (!this.images[id]) {
this.fire(new performance.Event('styleimagemissing', { id: id }));
}
var image = this.images[id];
if (image) {
response[id] = {
data: image.data.clone(),
pixelRatio: image.pixelRatio,
sdf: image.sdf,
version: image.version,
stretchX: image.stretchX,
stretchY: image.stretchY,
content: image.content,
hasRenderCallback: Boolean(image.userImage && image.userImage.render)
};
} else {
performance.warnOnce('Image "' + id + '" could not be loaded. Please make sure you have added the image with map.addImage() or a "sprite" property in your style. You can provide missing images by listening for the "styleimagemissing" map event.');
}
}
callback(null, response);
};
ImageManager.prototype.getPixelSize = function getPixelSize() {
var ref = this.atlasImage;
var width = ref.width;
var height = ref.height;
return {
width: width,
height: height
};
};
ImageManager.prototype.getPattern = function getPattern(id) {
var pattern = this.patterns[id];
var image = this.getImage(id);
if (!image) {
return null;
}
if (pattern && pattern.position.version === image.version) {
return pattern.position;
}
if (!pattern) {
var w = image.data.width + padding * 2;
var h = image.data.height + padding * 2;
var bin = {
w: w,
h: h,
x: 0,
y: 0
};
var position = new performance.ImagePosition(bin, image);
this.patterns[id] = {
bin: bin,
position: position
};
} else {
pattern.position.version = image.version;
}
this._updatePatternAtlas();
return this.patterns[id].position;
};
ImageManager.prototype.bind = function bind(context) {
var gl = context.gl;
if (!this.atlasTexture) {
this.atlasTexture = new performance.Texture(context, this.atlasImage, gl.RGBA);
} else if (this.dirty) {
this.atlasTexture.update(this.atlasImage);
this.dirty = false;
}
this.atlasTexture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
};
ImageManager.prototype._updatePatternAtlas = function _updatePatternAtlas() {
var bins = [];
for (var id in this.patterns) {
bins.push(this.patterns[id].bin);
}
var ref = performance.potpack(bins);
var w = ref.w;
var h = ref.h;
var dst = this.atlasImage;
dst.resize({
width: w || 1,
height: h || 1
});
for (var id$1 in this.patterns) {
var ref$1 = this.patterns[id$1];
var bin = ref$1.bin;
var x = bin.x + padding;
var y = bin.y + padding;
var src = this.images[id$1].data;
var w$1 = src.width;
var h$1 = src.height;
performance.RGBAImage.copy(src, dst, {
x: 0,
y: 0
}, {
x: x,
y: y
}, {
width: w$1,
height: h$1
});
performance.RGBAImage.copy(src, dst, {
x: 0,
y: h$1 - 1
}, {
x: x,
y: y - 1
}, {
width: w$1,
height: 1
});
performance.RGBAImage.copy(src, dst, {
x: 0,
y: 0
}, {
x: x,
y: y + h$1
}, {
width: w$1,
height: 1
});
performance.RGBAImage.copy(src, dst, {
x: w$1 - 1,
y: 0
}, {
x: x - 1,
y: y
}, {
width: 1,
height: h$1
});
performance.RGBAImage.copy(src, dst, {
x: 0,
y: 0
}, {
x: x + w$1,
y: y
}, {
width: 1,
height: h$1
});
}
this.dirty = true;
};
ImageManager.prototype.beginFrame = function beginFrame() {
this.callbackDispatchedThisFrame = {};
};
ImageManager.prototype.dispatchRenderCallbacks = function dispatchRenderCallbacks(ids) {
for (var i = 0, list = ids; i < list.length; i += 1) {
var id = list[i];
if (this.callbackDispatchedThisFrame[id]) {
continue;
}
this.callbackDispatchedThisFrame[id] = true;
var image = this.images[id];
var updated = renderStyleImage(image);
if (updated) {
this.updateImage(id, image);
}
}
};
return ImageManager;
}(performance.Evented);
function loadGlyphRange (fontstack, range, urlTemplate, requestManager, callback) {
var begin = range * 256;
var end = begin + 255;
var request = requestManager.transformRequest(requestManager.normalizeGlyphsURL(urlTemplate).replace('{fontstack}', fontstack).replace('{range}', begin + '-' + end), performance.ResourceType.Glyphs);
performance.getArrayBuffer(request, function (err, data) {
if (err) {
callback(err);
} else if (data) {
var glyphs = {};
for (var i = 0, list = performance.parseGlyphPBF(data); i < list.length; i += 1) {
var glyph = list[i];
glyphs[glyph.id] = glyph;
}
callback(null, glyphs);
}
});
}
var tinySdf = TinySDF;
var default_1 = TinySDF;
var INF = 100000000000000000000;
function TinySDF(fontSize, buffer, radius, cutoff, fontFamily, fontWeight) {
this.fontSize = fontSize || 24;
this.buffer = buffer === undefined ? 3 : buffer;
this.cutoff = cutoff || 0.25;
this.fontFamily = fontFamily || 'sans-serif';
this.fontWeight = fontWeight || 'normal';
this.radius = radius || 8;
var size = this.size = this.fontSize + this.buffer * 2;
this.canvas = document.createElement('canvas');
this.canvas.width = this.canvas.height = size;
this.ctx = this.canvas.getContext('2d');
this.ctx.font = this.fontWeight + ' ' + this.fontSize + 'px ' + this.fontFamily;
this.ctx.textBaseline = 'middle';
this.ctx.fillStyle = 'black';
this.gridOuter = new Float64Array(size * size);
this.gridInner = new Float64Array(size * size);
this.f = new Float64Array(size);
this.d = new Float64Array(size);
this.z = new Float64Array(size + 1);
this.v = new Int16Array(size);
this.middle = Math.round(size / 2 * (navigator.userAgent.indexOf('Gecko/') >= 0 ? 1.2 : 1));
}
TinySDF.prototype.draw = function (char) {
this.ctx.clearRect(0, 0, this.size, this.size);
this.ctx.fillText(char, this.buffer, this.middle);
var imgData = this.ctx.getImageData(0, 0, this.size, this.size);
var alphaChannel = new Uint8ClampedArray(this.size * this.size);
for (var i = 0; i < this.size * this.size; i++) {
var a = imgData.data[i * 4 + 3] / 255;
this.gridOuter[i] = a === 1 ? 0 : a === 0 ? INF : Math.pow(Math.max(0, 0.5 - a), 2);
this.gridInner[i] = a === 1 ? INF : a === 0 ? 0 : Math.pow(Math.max(0, a - 0.5), 2);
}
edt(this.gridOuter, this.size, this.size, this.f, this.d, this.v, this.z);
edt(this.gridInner, this.size, this.size, this.f, this.d, this.v, this.z);
for (i = 0; i < this.size * this.size; i++) {
var d = this.gridOuter[i] - this.gridInner[i];
alphaChannel[i] = Math.max(0, Math.min(255, Math.round(255 - 255 * (d / this.radius + this.cutoff))));
}
return alphaChannel;
};
function edt(data, width, height, f, d, v, z) {
for (var x = 0; x < width; x++) {
for (var y = 0; y < height; y++) {
f[y] = data[y * width + x];
}
edt1d(f, d, v, z, height);
for (y = 0; y < height; y++) {
data[y * width + x] = d[y];
}
}
for (y = 0; y < height; y++) {
for (x = 0; x < width; x++) {
f[x] = data[y * width + x];
}
edt1d(f, d, v, z, width);
for (x = 0; x < width; x++) {
data[y * width + x] = Math.sqrt(d[x]);
}
}
}
function edt1d(f, d, v, z, n) {
v[0] = 0;
z[0] = -INF;
z[1] = +INF;
for (var q = 1, k = 0; q < n; q++) {
var s = (f[q] + q * q - (f[v[k]] + v[k] * v[k])) / (2 * q - 2 * v[k]);
while (s <= z[k]) {
k--;
s = (f[q] + q * q - (f[v[k]] + v[k] * v[k])) / (2 * q - 2 * v[k]);
}
k++;
v[k] = q;
z[k] = s;
z[k + 1] = +INF;
}
for (q = 0, k = 0; q < n; q++) {
while (z[k + 1] < q) {
k++;
}
d[q] = (q - v[k]) * (q - v[k]) + f[v[k]];
}
}
tinySdf.default = default_1;
var GlyphManager = function GlyphManager(requestManager, localIdeographFontFamily) {
this.requestManager = requestManager;
this.localIdeographFontFamily = localIdeographFontFamily;
this.entries = {};
};
GlyphManager.prototype.setURL = function setURL(url) {
this.url = url;
};
GlyphManager.prototype.getGlyphs = function getGlyphs(glyphs, callback) {
var this$1 = this;
var all = [];
for (var stack in glyphs) {
for (var i = 0, list = glyphs[stack]; i < list.length; i += 1) {
var id = list[i];
all.push({
stack: stack,
id: id
});
}
}
performance.asyncAll(all, function (ref, callback) {
var stack = ref.stack;
var id = ref.id;
var entry = this$1.entries[stack];
if (!entry) {
entry = this$1.entries[stack] = {
glyphs: {},
requests: {},
ranges: {}
};
}
var glyph = entry.glyphs[id];
if (glyph !== undefined) {
callback(null, {
stack: stack,
id: id,
glyph: glyph
});
return;
}
glyph = this$1._tinySDF(entry, stack, id);
if (glyph) {
entry.glyphs[id] = glyph;
callback(null, {
stack: stack,
id: id,
glyph: glyph
});
return;
}
var range = Math.floor(id / 256);
if (range * 256 > 65535) {
callback(new Error('glyphs > 65535 not supported'));
return;
}
if (entry.ranges[range]) {
callback(null, {
stack: stack,
id: id,
glyph: glyph
});
return;
}
var requests = entry.requests[range];
if (!requests) {
requests = entry.requests[range] = [];
GlyphManager.loadGlyphRange(stack, range, this$1.url, this$1.requestManager, function (err, response) {
if (response) {
for (var id in response) {
if (!this$1._doesCharSupportLocalGlyph(+id)) {
entry.glyphs[+id] = response[+id];
}
}
entry.ranges[range] = true;
}
for (var i = 0, list = requests; i < list.length; i += 1) {
var cb = list[i];
cb(err, response);
}
delete entry.requests[range];
});
}
requests.push(function (err, result) {
if (err) {
callback(err);
} else if (result) {
callback(null, {
stack: stack,
id: id,
glyph: result[id] || null
});
}
});
}, function (err, glyphs) {
if (err) {
callback(err);
} else if (glyphs) {
var result = {};
for (var i = 0, list = glyphs; i < list.length; i += 1) {
var ref = list[i];
var stack = ref.stack;
var id = ref.id;
var glyph = ref.glyph;
(result[stack] || (result[stack] = {}))[id] = glyph && {
id: glyph.id,
bitmap: glyph.bitmap.clone(),
metrics: glyph.metrics
};
}
callback(null, result);
}
});
};
GlyphManager.prototype._doesCharSupportLocalGlyph = function _doesCharSupportLocalGlyph(id) {
return !!this.localIdeographFontFamily && (performance.isChar['CJK Unified Ideographs'](id) || performance.isChar['Hangul Syllables'](id) || performance.isChar['Hiragana'](id) || performance.isChar['Katakana'](id));
};
GlyphManager.prototype._tinySDF = function _tinySDF(entry, stack, id) {
var family = this.localIdeographFontFamily;
if (!family) {
return;
}
if (!this._doesCharSupportLocalGlyph(id)) {
return;
}
var tinySDF = entry.tinySDF;
if (!tinySDF) {
var fontWeight = '400';
if (/bold/i.test(stack)) {
fontWeight = '900';
} else if (/medium/i.test(stack)) {
fontWeight = '500';
} else if (/light/i.test(stack)) {
fontWeight = '200';
}
tinySDF = entry.tinySDF = new GlyphManager.TinySDF(24, 3, 8, 0.25, family, fontWeight);
}
return {
id: id,
bitmap: new performance.AlphaImage({
width: 30,
height: 30
}, tinySDF.draw(String.fromCharCode(id))),
metrics: {
width: 24,
height: 24,
left: 0,
top: -8,
advance: 24
}
};
};
GlyphManager.loadGlyphRange = loadGlyphRange;
GlyphManager.TinySDF = tinySdf;
var LightPositionProperty = function LightPositionProperty() {
this.specification = performance.styleSpec.light.position;
};
LightPositionProperty.prototype.possiblyEvaluate = function possiblyEvaluate(value, parameters) {
return performance.sphericalToCartesian(value.expression.evaluate(parameters));
};
LightPositionProperty.prototype.interpolate = function interpolate$1(a, b, t) {
return {
x: performance.number(a.x, b.x, t),
y: performance.number(a.y, b.y, t),
z: performance.number(a.z, b.z, t)
};
};
var properties = new performance.Properties({
'anchor': new performance.DataConstantProperty(performance.styleSpec.light.anchor),
'position': new LightPositionProperty(),
'color': new performance.DataConstantProperty(performance.styleSpec.light.color),
'intensity': new performance.DataConstantProperty(performance.styleSpec.light.intensity)
});
var TRANSITION_SUFFIX = '-transition';
var Light = function (Evented) {
function Light(lightOptions) {
Evented.call(this);
this._transitionable = new performance.Transitionable(properties);
this.setLight(lightOptions);
this._transitioning = this._transitionable.untransitioned();
}
if (Evented)
Light.__proto__ = Evented;
Light.prototype = Object.create(Evented && Evented.prototype);
Light.prototype.constructor = Light;
Light.prototype.getLight = function getLight() {
return this._transitionable.serialize();
};
Light.prototype.setLight = function setLight(light, options) {
if (options === void 0)
options = {};
if (this._validate(performance.validateLight, light, options)) {
return;
}
for (var name in light) {
var value = light[name];
if (performance.endsWith(name, TRANSITION_SUFFIX)) {
this._transitionable.setTransition(name.slice(0, -TRANSITION_SUFFIX.length), value);
} else {
this._transitionable.setValue(name, value);
}
}
};
Light.prototype.updateTransitions = function updateTransitions(parameters) {
this._transitioning = this._transitionable.transitioned(parameters, this._transitioning);
};
Light.prototype.hasTransition = function hasTransition() {
return this._transitioning.hasTransition();
};
Light.prototype.recalculate = function recalculate(parameters) {
this.properties = this._transitioning.possiblyEvaluate(parameters);
};
Light.prototype._validate = function _validate(validate, value, options) {
if (options && options.validate === false) {
return false;
}
return performance.emitValidationErrors(this, validate.call(performance.validateStyle, performance.extend({
value: value,
style: {
glyphs: true,
sprite: true
},
styleSpec: performance.styleSpec
})));
};
return Light;
}(performance.Evented);
var LineAtlas = function LineAtlas(width, height) {
this.width = width;
this.height = height;
this.nextRow = 0;
this.data = new Uint8Array(this.width * this.height);
this.dashEntry = {};
};
LineAtlas.prototype.getDash = function getDash(dasharray, round) {
var key = dasharray.join(',') + String(round);
if (!this.dashEntry[key]) {
this.dashEntry[key] = this.addDash(dasharray, round);
}
return this.dashEntry[key];
};
LineAtlas.prototype.getDashRanges = function getDashRanges(dasharray, lineAtlasWidth, stretch) {
var oddDashArray = dasharray.length % 2 === 1;
var ranges = [];
var left = oddDashArray ? -dasharray[dasharray.length - 1] * stretch : 0;
var right = dasharray[0] * stretch;
var isDash = true;
ranges.push({
left: left,
right: right,
isDash: isDash,
zeroLength: dasharray[0] === 0
});
var currentDashLength = dasharray[0];
for (var i = 1; i < dasharray.length; i++) {
isDash = !isDash;
var dashLength = dasharray[i];
left = currentDashLength * stretch;
currentDashLength += dashLength;
right = currentDashLength * stretch;
ranges.push({
left: left,
right: right,
isDash: isDash,
zeroLength: dashLength === 0
});
}
return ranges;
};
LineAtlas.prototype.addRoundDash = function addRoundDash(ranges, stretch, n) {
var halfStretch = stretch / 2;
for (var y = -n; y <= n; y++) {
var row = this.nextRow + n + y;
var index = this.width * row;
var currIndex = 0;
var range = ranges[currIndex];
for (var x = 0; x < this.width; x++) {
if (x / range.right > 1) {
range = ranges[++currIndex];
}
var distLeft = Math.abs(x - range.left);
var distRight = Math.abs(x - range.right);
var minDist = Math.min(distLeft, distRight);
var signedDistance = void 0;
var distMiddle = y / n * (halfStretch + 1);
if (range.isDash) {
var distEdge = halfStretch - Math.abs(distMiddle);
signedDistance = Math.sqrt(minDist * minDist + distEdge * distEdge);
} else {
signedDistance = halfStretch - Math.sqrt(minDist * minDist + distMiddle * distMiddle);
}
this.data[index + x] = Math.max(0, Math.min(255, signedDistance + 128));
}
}
};
LineAtlas.prototype.addRegularDash = function addRegularDash(ranges) {
for (var i = ranges.length - 1; i >= 0; --i) {
var part = ranges[i];
var next = ranges[i + 1];
if (part.zeroLength) {
ranges.splice(i, 1);
} else if (next && next.isDash === part.isDash) {
next.left = part.left;
ranges.splice(i, 1);
}
}
var first = ranges[0];
var last = ranges[ranges.length - 1];
if (first.isDash === last.isDash) {
first.left = last.left - this.width;
last.right = first.right + this.width;
}
var index = this.width * this.nextRow;
var currIndex = 0;
var range = ranges[currIndex];
for (var x = 0; x < this.width; x++) {
if (x / range.right > 1) {
range = ranges[++currIndex];
}
var distLeft = Math.abs(x - range.left);
var distRight = Math.abs(x - range.right);
var minDist = Math.min(distLeft, distRight);
var signedDistance = range.isDash ? minDist : -minDist;
this.data[index + x] = Math.max(0, Math.min(255, signedDistance + 128));
}
};
LineAtlas.prototype.addDash = function addDash(dasharray, round) {
var n = round ? 7 : 0;
var height = 2 * n + 1;
if (this.nextRow + height > this.height) {
performance.warnOnce('LineAtlas out of space');
return null;
}
var length = 0;
for (var i = 0; i < dasharray.length; i++) {
length += dasharray[i];
}
if (length !== 0) {
var stretch = this.width / length;
var ranges = this.getDashRanges(dasharray, this.width, stretch);
if (round) {
this.addRoundDash(ranges, stretch, n);
} else {
this.addRegularDash(ranges);
}
}
var dashEntry = {
y: (this.nextRow + n + 0.5) / this.height,
height: 2 * n / this.height,
width: length
};
this.nextRow += height;
this.dirty = true;
return dashEntry;
};
LineAtlas.prototype.bind = function bind(context) {
var gl = context.gl;
if (!this.texture) {
this.texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, this.texture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.REPEAT);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.ALPHA, this.width, this.height, 0, gl.ALPHA, gl.UNSIGNED_BYTE, this.data);
} else {
gl.bindTexture(gl.TEXTURE_2D, this.texture);
if (this.dirty) {
this.dirty = false;
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, this.width, this.height, gl.ALPHA, gl.UNSIGNED_BYTE, this.data);
}
}
};
var Dispatcher = function Dispatcher(workerPool, parent) {
this.workerPool = workerPool;
this.actors = [];
this.currentActor = 0;
this.id = performance.uniqueId();
var workers = this.workerPool.acquire(this.id);
for (var i = 0; i < workers.length; i++) {
var worker = workers[i];
var actor = new Dispatcher.Actor(worker, parent, this.id);
actor.name = 'Worker ' + i;
this.actors.push(actor);
}
};
Dispatcher.prototype.broadcast = function broadcast(type, data, cb) {
cb = cb || function () {
};
performance.asyncAll(this.actors, function (actor, done) {
actor.send(type, data, done);
}, cb);
};
Dispatcher.prototype.getActor = function getActor() {
this.currentActor = (this.currentActor + 1) % this.actors.length;
return this.actors[this.currentActor];
};
Dispatcher.prototype.remove = function remove() {
this.actors.forEach(function (actor) {
actor.remove();
});
this.actors = [];
this.workerPool.release(this.id);
};
Dispatcher.Actor = performance.Actor;
function loadTileJSON (options, requestManager, callback) {
var loaded = function (err, tileJSON) {
if (err) {
return callback(err);
} else if (tileJSON) {
var result = performance.pick(performance.extend(tileJSON, options), [
'tiles',
'minzoom',
'maxzoom',
'attribution',
'mapbox_logo',
'bounds',
'scheme',
'tileSize',
'encoding'
]);
if (tileJSON.vector_layers) {
result.vectorLayers = tileJSON.vector_layers;
result.vectorLayerIds = result.vectorLayers.map(function (layer) {
return layer.id;
});
}
result.tiles = requestManager.canonicalizeTileset(result, options.url);
callback(null, result);
}
};
if (options.url) {
return performance.getJSON(requestManager.transformRequest(requestManager.normalizeSourceURL(options.url), performance.ResourceType.Source), loaded);
} else {
return performance.browser.frame(function () {
return loaded(null, options);
});
}
}
var TileBounds = function TileBounds(bounds, minzoom, maxzoom) {
this.bounds = performance.LngLatBounds.convert(this.validateBounds(bounds));
this.minzoom = minzoom || 0;
this.maxzoom = maxzoom || 24;
};
TileBounds.prototype.validateBounds = function validateBounds(bounds) {
if (!Array.isArray(bounds) || bounds.length !== 4) {
return [
-180,
-90,
180,
90
];
}
return [
Math.max(-180, bounds[0]),
Math.max(-90, bounds[1]),
Math.min(180, bounds[2]),
Math.min(90, bounds[3])
];
};
TileBounds.prototype.contains = function contains(tileID) {
var worldSize = Math.pow(2, tileID.z);
var level = {
minX: Math.floor(performance.mercatorXfromLng(this.bounds.getWest()) * worldSize),
minY: Math.floor(performance.mercatorYfromLat(this.bounds.getNorth()) * worldSize),
maxX: Math.ceil(performance.mercatorXfromLng(this.bounds.getEast()) * worldSize),
maxY: Math.ceil(performance.mercatorYfromLat(this.bounds.getSouth()) * worldSize)
};
var hit = tileID.x >= level.minX && tileID.x < level.maxX && tileID.y >= level.minY && tileID.y < level.maxY;
return hit;
};
var VectorTileSource = function (Evented) {
function VectorTileSource(id, options, dispatcher, eventedParent) {
Evented.call(this);
this.id = id;
this.dispatcher = dispatcher;
this.type = 'vector';
this.minzoom = 0;
this.maxzoom = 22;
this.scheme = 'xyz';
this.tileSize = 512;
this.reparseOverscaled = true;
this.isTileClipped = true;
this._loaded = false;
performance.extend(this, performance.pick(options, [
'url',
'scheme',
'tileSize',
'promoteId'
]));
this._options = performance.extend({ type: 'vector' }, options);
this._collectResourceTiming = options.collectResourceTiming;
if (this.tileSize !== 512) {
throw new Error('vector tile sources must have a tileSize of 512');
}
this.setEventedParent(eventedParent);
}
if (Evented)
VectorTileSource.__proto__ = Evented;
VectorTileSource.prototype = Object.create(Evented && Evented.prototype);
VectorTileSource.prototype.constructor = VectorTileSource;
VectorTileSource.prototype.load = function load() {
var this$1 = this;
this._loaded = false;
this.fire(new performance.Event('dataloading', { dataType: 'source' }));
this._tileJSONRequest = loadTileJSON(this._options, this.map._requestManager, function (err, tileJSON) {
this$1._tileJSONRequest = null;
this$1._loaded = true;
if (err) {
this$1.fire(new performance.ErrorEvent(err));
} else if (tileJSON) {
performance.extend(this$1, tileJSON);
if (tileJSON.bounds) {
this$1.tileBounds = new TileBounds(tileJSON.bounds, this$1.minzoom, this$1.maxzoom);
}
performance.postTurnstileEvent(tileJSON.tiles, this$1.map._requestManager._customAccessToken);
performance.postMapLoadEvent(tileJSON.tiles, this$1.map._getMapId(), this$1.map._requestManager._skuToken, this$1.map._requestManager._customAccessToken);
this$1.fire(new performance.Event('data', {
dataType: 'source',
sourceDataType: 'metadata'
}));
this$1.fire(new performance.Event('data', {
dataType: 'source',
sourceDataType: 'content'
}));
}
});
};
VectorTileSource.prototype.loaded = function loaded() {
return this._loaded;
};
VectorTileSource.prototype.hasTile = function hasTile(tileID) {
return !this.tileBounds || this.tileBounds.contains(tileID.canonical);
};
VectorTileSource.prototype.onAdd = function onAdd(map) {
this.map = map;
this.load();
};
VectorTileSource.prototype.setSourceProperty = function setSourceProperty(callback) {
if (this._tileJSONRequest) {
this._tileJSONRequest.cancel();
}
callback();
var sourceCache = this.map.style.sourceCaches[this.id];
sourceCache.clearTiles();
this.load();
};
VectorTileSource.prototype.setTiles = function setTiles(tiles) {
var this$1 = this;
this.setSourceProperty(function () {
this$1._options.tiles = tiles;
});
return this;
};
VectorTileSource.prototype.setUrl = function setUrl(url) {
var this$1 = this;
this.setSourceProperty(function () {
this$1.url = url;
this$1._options.url = url;
});
return this;
};
VectorTileSource.prototype.onRemove = function onRemove() {
if (this._tileJSONRequest) {
this._tileJSONRequest.cancel();
this._tileJSONRequest = null;
}
};
VectorTileSource.prototype.serialize = function serialize() {
return performance.extend({}, this._options);
};
VectorTileSource.prototype.loadTile = function loadTile(tile, callback) {
var url = this.map._requestManager.normalizeTileURL(tile.tileID.canonical.url(this.tiles, this.scheme));
var params = {
request: this.map._requestManager.transformRequest(url, performance.ResourceType.Tile),
uid: tile.uid,
tileID: tile.tileID,
zoom: tile.tileID.overscaledZ,
tileSize: this.tileSize * tile.tileID.overscaleFactor(),
type: this.type,
source: this.id,
pixelRatio: performance.browser.devicePixelRatio,
showCollisionBoxes: this.map.showCollisionBoxes,
promoteId: this.promoteId
};
params.request.collectResourceTiming = this._collectResourceTiming;
if (!tile.actor || tile.state === 'expired') {
tile.actor = this.dispatcher.getActor();
tile.request = tile.actor.send('loadTile', params, done.bind(this));
} else if (tile.state === 'loading') {
tile.reloadCallback = callback;
} else {
tile.request = tile.actor.send('reloadTile', params, done.bind(this));
}
function done(err, data) {
delete tile.request;
if (tile.aborted) {
return callback(null);
}
if (err && err.status !== 404) {
return callback(err);
}
if (data && data.resourceTiming) {
tile.resourceTiming = data.resourceTiming;
}
if (this.map._refreshExpiredTiles && data) {
tile.setExpiryData(data);
}
tile.loadVectorData(data, this.map.painter);
performance.cacheEntryPossiblyAdded(this.dispatcher);
callback(null);
if (tile.reloadCallback) {
this.loadTile(tile, tile.reloadCallback);
tile.reloadCallback = null;
}
}
};
VectorTileSource.prototype.abortTile = function abortTile(tile) {
if (tile.request) {
tile.request.cancel();
delete tile.request;
}
if (tile.actor) {
tile.actor.send('abortTile', {
uid: tile.uid,
type: this.type,
source: this.id
}, undefined);
}
};
VectorTileSource.prototype.unloadTile = function unloadTile(tile) {
tile.unloadVectorData();
if (tile.actor) {
tile.actor.send('removeTile', {
uid: tile.uid,
type: this.type,
source: this.id
}, undefined);
}
};
VectorTileSource.prototype.hasTransition = function hasTransition() {
return false;
};
return VectorTileSource;
}(performance.Evented);
var RasterTileSource = function (Evented) {
function RasterTileSource(id, options, dispatcher, eventedParent) {
Evented.call(this);
this.id = id;
this.dispatcher = dispatcher;
this.setEventedParent(eventedParent);
this.type = 'raster';
this.minzoom = 0;
this.maxzoom = 22;
this.roundZoom = true;
this.scheme = 'xyz';
this.tileSize = 512;
this._loaded = false;
this._options = performance.extend({ type: 'raster' }, options);
performance.extend(this, performance.pick(options, [
'url',
'scheme',
'tileSize'
]));
}
if (Evented)
RasterTileSource.__proto__ = Evented;
RasterTileSource.prototype = Object.create(Evented && Evented.prototype);
RasterTileSource.prototype.constructor = RasterTileSource;
RasterTileSource.prototype.load = function load() {
var this$1 = this;
this._loaded = false;
this.fire(new performance.Event('dataloading', { dataType: 'source' }));
this._tileJSONRequest = loadTileJSON(this._options, this.map._requestManager, function (err, tileJSON) {
this$1._tileJSONRequest = null;
this$1._loaded = true;
if (err) {
this$1.fire(new performance.ErrorEvent(err));
} else if (tileJSON) {
performance.extend(this$1, tileJSON);
if (tileJSON.bounds) {
this$1.tileBounds = new TileBounds(tileJSON.bounds, this$1.minzoom, this$1.maxzoom);
}
performance.postTurnstileEvent(tileJSON.tiles);
performance.postMapLoadEvent(tileJSON.tiles, this$1.map._getMapId(), this$1.map._requestManager._skuToken);
this$1.fire(new performance.Event('data', {
dataType: 'source',
sourceDataType: 'metadata'
}));
this$1.fire(new performance.Event('data', {
dataType: 'source',
sourceDataType: 'content'
}));
}
});
};
RasterTileSource.prototype.loaded = function loaded() {
return this._loaded;
};
RasterTileSource.prototype.onAdd = function onAdd(map) {
this.map = map;
this.load();
};
RasterTileSource.prototype.onRemove = function onRemove() {
if (this._tileJSONRequest) {
this._tileJSONRequest.cancel();
this._tileJSONRequest = null;
}
};
RasterTileSource.prototype.serialize = function serialize() {
return performance.extend({}, this._options);
};
RasterTileSource.prototype.hasTile = function hasTile(tileID) {
return !this.tileBounds || this.tileBounds.contains(tileID.canonical);
};
RasterTileSource.prototype.loadTile = function loadTile(tile, callback) {
var this$1 = this;
var url = this.map._requestManager.normalizeTileURL(tile.tileID.canonical.url(this.tiles, this.scheme), this.tileSize);
tile.request = performance.getImage(this.map._requestManager.transformRequest(url, performance.ResourceType.Tile), function (err, img) {
delete tile.request;
if (tile.aborted) {
tile.state = 'unloaded';
callback(null);
} else if (err) {
tile.state = 'errored';
callback(err);
} else if (img) {
if (this$1.map._refreshExpiredTiles) {
tile.setExpiryData(img);
}
delete img.cacheControl;
delete img.expires;
var context = this$1.map.painter.context;
var gl = context.gl;
tile.texture = this$1.map.painter.getTileTexture(img.width);
if (tile.texture) {
tile.texture.update(img, { useMipmap: true });
} else {
tile.texture = new performance.Texture(context, img, gl.RGBA, { useMipmap: true });
tile.texture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE, gl.LINEAR_MIPMAP_NEAREST);
if (context.extTextureFilterAnisotropic) {
gl.texParameterf(gl.TEXTURE_2D, context.extTextureFilterAnisotropic.TEXTURE_MAX_ANISOTROPY_EXT, context.extTextureFilterAnisotropicMax);
}
}
tile.state = 'loaded';
performance.cacheEntryPossiblyAdded(this$1.dispatcher);
callback(null);
}
});
};
RasterTileSource.prototype.abortTile = function abortTile(tile, callback) {
if (tile.request) {
tile.request.cancel();
delete tile.request;
}
callback();
};
RasterTileSource.prototype.unloadTile = function unloadTile(tile, callback) {
if (tile.texture) {
this.map.painter.saveTileTexture(tile.texture);
}
callback();
};
RasterTileSource.prototype.hasTransition = function hasTransition() {
return false;
};
return RasterTileSource;
}(performance.Evented);
var RasterDEMTileSource = function (RasterTileSource) {
function RasterDEMTileSource(id, options, dispatcher, eventedParent) {
RasterTileSource.call(this, id, options, dispatcher, eventedParent);
this.type = 'raster-dem';
this.maxzoom = 22;
this._options = performance.extend({ type: 'raster-dem' }, options);
this.encoding = options.encoding || 'mapbox';
}
if (RasterTileSource)
RasterDEMTileSource.__proto__ = RasterTileSource;
RasterDEMTileSource.prototype = Object.create(RasterTileSource && RasterTileSource.prototype);
RasterDEMTileSource.prototype.constructor = RasterDEMTileSource;
RasterDEMTileSource.prototype.serialize = function serialize() {
return {
type: 'raster-dem',
url: this.url,
tileSize: this.tileSize,
tiles: this.tiles,
bounds: this.bounds,
encoding: this.encoding
};
};
RasterDEMTileSource.prototype.loadTile = function loadTile(tile, callback) {
var url = this.map._requestManager.normalizeTileURL(tile.tileID.canonical.url(this.tiles, this.scheme), this.tileSize);
tile.request = performance.getImage(this.map._requestManager.transformRequest(url, performance.ResourceType.Tile), imageLoaded.bind(this));
tile.neighboringTiles = this._getNeighboringTiles(tile.tileID);
function imageLoaded(err, img) {
delete tile.request;
if (tile.aborted) {
tile.state = 'unloaded';
callback(null);
} else if (err) {
tile.state = 'errored';
callback(err);
} else if (img) {
if (this.map._refreshExpiredTiles) {
tile.setExpiryData(img);
}
delete img.cacheControl;
delete img.expires;
var transfer = performance.window.ImageBitmap && img instanceof performance.window.ImageBitmap && performance.offscreenCanvasSupported();
var rawImageData = transfer ? img : performance.browser.getImageData(img, 1);
var params = {
uid: tile.uid,
coord: tile.tileID,
source: this.id,
rawImageData: rawImageData,
encoding: this.encoding
};
if (!tile.actor || tile.state === 'expired') {
tile.actor = this.dispatcher.getActor();
tile.actor.send('loadDEMTile', params, done.bind(this));
}
}
}
function done(err, dem) {
if (err) {
tile.state = 'errored';
callback(err);
}
if (dem) {
tile.dem = dem;
tile.needsHillshadePrepare = true;
tile.state = 'loaded';
callback(null);
}
}
};
RasterDEMTileSource.prototype._getNeighboringTiles = function _getNeighboringTiles(tileID) {
var canonical = tileID.canonical;
var dim = Math.pow(2, canonical.z);
var px = (canonical.x - 1 + dim) % dim;
var pxw = canonical.x === 0 ? tileID.wrap - 1 : tileID.wrap;
var nx = (canonical.x + 1 + dim) % dim;
var nxw = canonical.x + 1 === dim ? tileID.wrap + 1 : tileID.wrap;
var neighboringTiles = {};
neighboringTiles[new performance.OverscaledTileID(tileID.overscaledZ, pxw, canonical.z, px, canonical.y).key] = { backfilled: false };
neighboringTiles[new performance.OverscaledTileID(tileID.overscaledZ, nxw, canonical.z, nx, canonical.y).key] = { backfilled: false };
if (canonical.y > 0) {
neighboringTiles[new performance.OverscaledTileID(tileID.overscaledZ, pxw, canonical.z, px, canonical.y - 1).key] = { backfilled: false };
neighboringTiles[new performance.OverscaledTileID(tileID.overscaledZ, tileID.wrap, canonical.z, canonical.x, canonical.y - 1).key] = { backfilled: false };
neighboringTiles[new performance.OverscaledTileID(tileID.overscaledZ, nxw, canonical.z, nx, canonical.y - 1).key] = { backfilled: false };
}
if (canonical.y + 1 < dim) {
neighboringTiles[new performance.OverscaledTileID(tileID.overscaledZ, pxw, canonical.z, px, canonical.y + 1).key] = { backfilled: false };
neighboringTiles[new performance.OverscaledTileID(tileID.overscaledZ, tileID.wrap, canonical.z, canonical.x, canonical.y + 1).key] = { backfilled: false };
neighboringTiles[new performance.OverscaledTileID(tileID.overscaledZ, nxw, canonical.z, nx, canonical.y + 1).key] = { backfilled: false };
}
return neighboringTiles;
};
RasterDEMTileSource.prototype.unloadTile = function unloadTile(tile) {
if (tile.demTexture) {
this.map.painter.saveTileTexture(tile.demTexture);
}
if (tile.fbo) {
tile.fbo.destroy();
delete tile.fbo;
}
if (tile.dem) {
delete tile.dem;
}
delete tile.neighboringTiles;
tile.state = 'unloaded';
if (tile.actor) {
tile.actor.send('removeDEMTile', {
uid: tile.uid,
source: this.id
});
}
};
return RasterDEMTileSource;
}(RasterTileSource);
var GeoJSONSource = function (Evented) {
function GeoJSONSource(id, options, dispatcher, eventedParent) {
Evented.call(this);
this.id = id;
this.type = 'geojson';
this.minzoom = 0;
this.maxzoom = 18;
this.tileSize = 512;
this.isTileClipped = true;
this.reparseOverscaled = true;
this._removed = false;
this._loaded = false;
this.actor = dispatcher.getActor();
this.setEventedParent(eventedParent);
this._data = options.data;
this._options = performance.extend({}, options);
this._collectResourceTiming = options.collectResourceTiming;
this._resourceTiming = [];
if (options.maxzoom !== undefined) {
this.maxzoom = options.maxzoom;
}
if (options.type) {
this.type = options.type;
}
if (options.attribution) {
this.attribution = options.attribution;
}
this.promoteId = options.promoteId;
var scale = performance.EXTENT / this.tileSize;
this.workerOptions = performance.extend({
source: this.id,
cluster: options.cluster || false,
geojsonVtOptions: {
buffer: (options.buffer !== undefined ? options.buffer : 128) * scale,
tolerance: (options.tolerance !== undefined ? options.tolerance : 0.375) * scale,
extent: performance.EXTENT,
maxZoom: this.maxzoom,
lineMetrics: options.lineMetrics || false,
generateId: options.generateId || false
},
superclusterOptions: {
maxZoom: options.clusterMaxZoom !== undefined ? Math.min(options.clusterMaxZoom, this.maxzoom - 1) : this.maxzoom - 1,
minPoints: Math.max(2, options.clusterMinPoints || 2),
extent: performance.EXTENT,
radius: (options.clusterRadius || 50) * scale,
log: false,
generateId: options.generateId || false
},
clusterProperties: options.clusterProperties,
filter: options.filter
}, options.workerOptions);
}
if (Evented)
GeoJSONSource.__proto__ = Evented;
GeoJSONSource.prototype = Object.create(Evented && Evented.prototype);
GeoJSONSource.prototype.constructor = GeoJSONSource;
GeoJSONSource.prototype.load = function load() {
var this$1 = this;
this.fire(new performance.Event('dataloading', { dataType: 'source' }));
this._updateWorkerData(function (err) {
if (err) {
this$1.fire(new performance.ErrorEvent(err));
return;
}
var data = {
dataType: 'source',
sourceDataType: 'metadata'
};
if (this$1._collectResourceTiming && this$1._resourceTiming && this$1._resourceTiming.length > 0) {
data.resourceTiming = this$1._resourceTiming;
this$1._resourceTiming = [];
}
this$1.fire(new performance.Event('data', data));
});
};
GeoJSONSource.prototype.onAdd = function onAdd(map) {
this.map = map;
this.load();
};
GeoJSONSource.prototype.setData = function setData(data) {
var this$1 = this;
this._data = data;
this.fire(new performance.Event('dataloading', { dataType: 'source' }));
this._updateWorkerData(function (err) {
if (err) {
this$1.fire(new performance.ErrorEvent(err));
return;
}
var data = {
dataType: 'source',
sourceDataType: 'content'
};
if (this$1._collectResourceTiming && this$1._resourceTiming && this$1._resourceTiming.length > 0) {
data.resourceTiming = this$1._resourceTiming;
this$1._resourceTiming = [];
}
this$1.fire(new performance.Event('data', data));
});
return this;
};
GeoJSONSource.prototype.getClusterExpansionZoom = function getClusterExpansionZoom(clusterId, callback) {
this.actor.send('geojson.getClusterExpansionZoom', {
clusterId: clusterId,
source: this.id
}, callback);
return this;
};
GeoJSONSource.prototype.getClusterChildren = function getClusterChildren(clusterId, callback) {
this.actor.send('geojson.getClusterChildren', {
clusterId: clusterId,
source: this.id
}, callback);
return this;
};
GeoJSONSource.prototype.getClusterLeaves = function getClusterLeaves(clusterId, limit, offset, callback) {
this.actor.send('geojson.getClusterLeaves', {
source: this.id,
clusterId: clusterId,
limit: limit,
offset: offset
}, callback);
return this;
};
GeoJSONSource.prototype._updateWorkerData = function _updateWorkerData(callback) {
var this$1 = this;
this._loaded = false;
var options = performance.extend({}, this.workerOptions);
var data = this._data;
if (typeof data === 'string') {
options.request = this.map._requestManager.transformRequest(performance.browser.resolveURL(data), performance.ResourceType.Source);
options.request.collectResourceTiming = this._collectResourceTiming;
} else {
options.data = JSON.stringify(data);
}
this.actor.send(this.type + '.loadData', options, function (err, result) {
if (this$1._removed || result && result.abandoned) {
return;
}
this$1._loaded = true;
if (result && result.resourceTiming && result.resourceTiming[this$1.id]) {
this$1._resourceTiming = result.resourceTiming[this$1.id].slice(0);
}
this$1.actor.send(this$1.type + '.coalesce', { source: options.source }, null);
callback(err);
});
};
GeoJSONSource.prototype.loaded = function loaded() {
return this._loaded;
};
GeoJSONSource.prototype.loadTile = function loadTile(tile, callback) {
var this$1 = this;
var message = !tile.actor ? 'loadTile' : 'reloadTile';
tile.actor = this.actor;
var params = {
type: this.type,
uid: tile.uid,
tileID: tile.tileID,
zoom: tile.tileID.overscaledZ,
maxZoom: this.maxzoom,
tileSize: this.tileSize,
source: this.id,
pixelRatio: performance.browser.devicePixelRatio,
showCollisionBoxes: this.map.showCollisionBoxes,
promoteId: this.promoteId
};
tile.request = this.actor.send(message, params, function (err, data) {
delete tile.request;
tile.unloadVectorData();
if (tile.aborted) {
return callback(null);
}
if (err) {
return callback(err);
}
tile.loadVectorData(data, this$1.map.painter, message === 'reloadTile');
return callback(null);
});
};
GeoJSONSource.prototype.abortTile = function abortTile(tile) {
if (tile.request) {
tile.request.cancel();
delete tile.request;
}
tile.aborted = true;
};
GeoJSONSource.prototype.unloadTile = function unloadTile(tile) {
tile.unloadVectorData();
this.actor.send('removeTile', {
uid: tile.uid,
type: this.type,
source: this.id
});
};
GeoJSONSource.prototype.onRemove = function onRemove() {
this._removed = true;
this.actor.send('removeSource', {
type: this.type,
source: this.id
});
};
GeoJSONSource.prototype.serialize = function serialize() {
return performance.extend({}, this._options, {
type: this.type,
data: this._data
});
};
GeoJSONSource.prototype.hasTransition = function hasTransition() {
return false;
};
return GeoJSONSource;
}(performance.Evented);
var rasterBoundsAttributes = performance.createLayout([
{
name: 'a_pos',
type: 'Int16',
components: 2
},
{
name: 'a_texture_pos',
type: 'Int16',
components: 2
}
]);
var ImageSource = function (Evented) {
function ImageSource(id, options, dispatcher, eventedParent) {
Evented.call(this);
this.id = id;
this.dispatcher = dispatcher;
this.coordinates = options.coordinates;
this.type = 'image';
this.minzoom = 0;
this.maxzoom = 22;
this.tileSize = 512;
this.tiles = {};
this._loaded = false;
this.setEventedParent(eventedParent);
this.options = options;
}
if (Evented)
ImageSource.__proto__ = Evented;
ImageSource.prototype = Object.create(Evented && Evented.prototype);
ImageSource.prototype.constructor = ImageSource;
ImageSource.prototype.load = function load(newCoordinates, successCallback) {
var this$1 = this;
this._loaded = false;
this.fire(new performance.Event('dataloading', { dataType: 'source' }));
this.url = this.options.url;
performance.getImage(this.map._requestManager.transformRequest(this.url, performance.ResourceType.Image), function (err, image) {
this$1._loaded = true;
if (err) {
this$1.fire(new performance.ErrorEvent(err));
} else if (image) {
this$1.image = image;
if (newCoordinates) {
this$1.coordinates = newCoordinates;
}
if (successCallback) {
successCallback();
}
this$1._finishLoading();
}
});
};
ImageSource.prototype.loaded = function loaded() {
return this._loaded;
};
ImageSource.prototype.updateImage = function updateImage(options) {
var this$1 = this;
if (!this.image || !options.url) {
return this;
}
this.options.url = options.url;
this.load(options.coordinates, function () {
this$1.texture = null;
});
return this;
};
ImageSource.prototype._finishLoading = function _finishLoading() {
if (this.map) {
this.setCoordinates(this.coordinates);
this.fire(new performance.Event('data', {
dataType: 'source',
sourceDataType: 'metadata'
}));
}
};
ImageSource.prototype.onAdd = function onAdd(map) {
this.map = map;
this.load();
};
ImageSource.prototype.setCoordinates = function setCoordinates(coordinates) {
var this$1 = this;
this.coordinates = coordinates;
var cornerCoords = coordinates.map(performance.MercatorCoordinate.fromLngLat);
this.tileID = getCoordinatesCenterTileID(cornerCoords);
this.minzoom = this.maxzoom = this.tileID.z;
var tileCoords = cornerCoords.map(function (coord) {
return this$1.tileID.getTilePoint(coord)._round();
});
this._boundsArray = new performance.StructArrayLayout4i8();
this._boundsArray.emplaceBack(tileCoords[0].x, tileCoords[0].y, 0, 0);
this._boundsArray.emplaceBack(tileCoords[1].x, tileCoords[1].y, performance.EXTENT, 0);
this._boundsArray.emplaceBack(tileCoords[3].x, tileCoords[3].y, 0, performance.EXTENT);
this._boundsArray.emplaceBack(tileCoords[2].x, tileCoords[2].y, performance.EXTENT, performance.EXTENT);
if (this.boundsBuffer) {
this.boundsBuffer.destroy();
delete this.boundsBuffer;
}
this.fire(new performance.Event('data', {
dataType: 'source',
sourceDataType: 'content'
}));
return this;
};
ImageSource.prototype.prepare = function prepare() {
if (Object.keys(this.tiles).length === 0 || !this.image) {
return;
}
var context = this.map.painter.context;
var gl = context.gl;
if (!this.boundsBuffer) {
this.boundsBuffer = context.createVertexBuffer(this._boundsArray, rasterBoundsAttributes.members);
}
if (!this.boundsSegments) {
this.boundsSegments = performance.SegmentVector.simpleSegment(0, 0, 4, 2);
}
if (!this.texture) {
this.texture = new performance.Texture(context, this.image, gl.RGBA);
this.texture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
}
for (var w in this.tiles) {
var tile = this.tiles[w];
if (tile.state !== 'loaded') {
tile.state = 'loaded';
tile.texture = this.texture;
}
}
};
ImageSource.prototype.loadTile = function loadTile(tile, callback) {
if (this.tileID && this.tileID.equals(tile.tileID.canonical)) {
this.tiles[String(tile.tileID.wrap)] = tile;
tile.buckets = {};
callback(null);
} else {
tile.state = 'errored';
callback(null);
}
};
ImageSource.prototype.serialize = function serialize() {
return {
type: 'image',
url: this.options.url,
coordinates: this.coordinates
};
};
ImageSource.prototype.hasTransition = function hasTransition() {
return false;
};
return ImageSource;
}(performance.Evented);
function getCoordinatesCenterTileID(coords) {
var minX = Infinity;
var minY = Infinity;
var maxX = -Infinity;
var maxY = -Infinity;
for (var i = 0, list = coords; i < list.length; i += 1) {
var coord = list[i];
minX = Math.min(minX, coord.x);
minY = Math.min(minY, coord.y);
maxX = Math.max(maxX, coord.x);
maxY = Math.max(maxY, coord.y);
}
var dx = maxX - minX;
var dy = maxY - minY;
var dMax = Math.max(dx, dy);
var zoom = Math.max(0, Math.floor(-Math.log(dMax) / Math.LN2));
var tilesAtZoom = Math.pow(2, zoom);
return new performance.CanonicalTileID(zoom, Math.floor((minX + maxX) / 2 * tilesAtZoom), Math.floor((minY + maxY) / 2 * tilesAtZoom));
}
var VideoSource = function (ImageSource) {
function VideoSource(id, options, dispatcher, eventedParent) {
ImageSource.call(this, id, options, dispatcher, eventedParent);
this.roundZoom = true;
this.type = 'video';
this.options = options;
}
if (ImageSource)
VideoSource.__proto__ = ImageSource;
VideoSource.prototype = Object.create(ImageSource && ImageSource.prototype);
VideoSource.prototype.constructor = VideoSource;
VideoSource.prototype.load = function load() {
var this$1 = this;
this._loaded = false;
var options = this.options;
this.urls = [];
for (var i = 0, list = options.urls; i < list.length; i += 1) {
var url = list[i];
this.urls.push(this.map._requestManager.transformRequest(url, performance.ResourceType.Source).url);
}
performance.getVideo(this.urls, function (err, video) {
this$1._loaded = true;
if (err) {
this$1.fire(new performance.ErrorEvent(err));
} else if (video) {
this$1.video = video;
this$1.video.loop = true;
this$1.video.addEventListener('playing', function () {
this$1.map.triggerRepaint();
});
if (this$1.map) {
this$1.video.play();
}
this$1._finishLoading();
}
});
};
VideoSource.prototype.pause = function pause() {
if (this.video) {
this.video.pause();
}
};
VideoSource.prototype.play = function play() {
if (this.video) {
this.video.play();
}
};
VideoSource.prototype.seek = function seek(seconds) {
if (this.video) {
var seekableRange = this.video.seekable;
if (seconds < seekableRange.start(0) || seconds > seekableRange.end(0)) {
this.fire(new performance.ErrorEvent(new performance.ValidationError('sources.' + this.id, null, 'Playback for this video can be set only between the ' + seekableRange.start(0) + ' and ' + seekableRange.end(0) + '-second mark.')));
} else {
this.video.currentTime = seconds;
}
}
};
VideoSource.prototype.getVideo = function getVideo() {
return this.video;
};
VideoSource.prototype.onAdd = function onAdd(map) {
if (this.map) {
return;
}
this.map = map;
this.load();
if (this.video) {
this.video.play();
this.setCoordinates(this.coordinates);
}
};
VideoSource.prototype.prepare = function prepare() {
if (Object.keys(this.tiles).length === 0 || this.video.readyState < 2) {
return;
}
var context = this.map.painter.context;
var gl = context.gl;
if (!this.boundsBuffer) {
this.boundsBuffer = context.createVertexBuffer(this._boundsArray, rasterBoundsAttributes.members);
}
if (!this.boundsSegments) {
this.boundsSegments = performance.SegmentVector.simpleSegment(0, 0, 4, 2);
}
if (!this.texture) {
this.texture = new performance.Texture(context, this.video, gl.RGBA);
this.texture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
} else if (!this.video.paused) {
this.texture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, this.video);
}
for (var w in this.tiles) {
var tile = this.tiles[w];
if (tile.state !== 'loaded') {
tile.state = 'loaded';
tile.texture = this.texture;
}
}
};
VideoSource.prototype.serialize = function serialize() {
return {
type: 'video',
urls: this.urls,
coordinates: this.coordinates
};
};
VideoSource.prototype.hasTransition = function hasTransition() {
return this.video && !this.video.paused;
};
return VideoSource;
}(ImageSource);
var CanvasSource = function (ImageSource) {
function CanvasSource(id, options, dispatcher, eventedParent) {
ImageSource.call(this, id, options, dispatcher, eventedParent);
if (!options.coordinates) {
this.fire(new performance.ErrorEvent(new performance.ValidationError('sources.' + id, null, 'missing required property "coordinates"')));
} else if (!Array.isArray(options.coordinates) || options.coordinates.length !== 4 || options.coordinates.some(function (c) {
return !Array.isArray(c) || c.length !== 2 || c.some(function (l) {
return typeof l !== 'number';
});
})) {
this.fire(new performance.ErrorEvent(new performance.ValidationError('sources.' + id, null, '"coordinates" property must be an array of 4 longitude/latitude array pairs')));
}
if (options.animate && typeof options.animate !== 'boolean') {
this.fire(new performance.ErrorEvent(new performance.ValidationError('sources.' + id, null, 'optional "animate" property must be a boolean value')));
}
if (!options.canvas) {
this.fire(new performance.ErrorEvent(new performance.ValidationError('sources.' + id, null, 'missing required property "canvas"')));
} else if (typeof options.canvas !== 'string' && !(options.canvas instanceof performance.window.HTMLCanvasElement)) {
this.fire(new performance.ErrorEvent(new performance.ValidationError('sources.' + id, null, '"canvas" must be either a string representing the ID of the canvas element from which to read, or an HTMLCanvasElement instance')));
}
this.options = options;
this.animate = options.animate !== undefined ? options.animate : true;
}
if (ImageSource)
CanvasSource.__proto__ = ImageSource;
CanvasSource.prototype = Object.create(ImageSource && ImageSource.prototype);
CanvasSource.prototype.constructor = CanvasSource;
CanvasSource.prototype.load = function load() {
this._loaded = true;
if (!this.canvas) {
this.canvas = this.options.canvas instanceof performance.window.HTMLCanvasElement ? this.options.canvas : performance.window.document.getElementById(this.options.canvas);
}
this.width = this.canvas.width;
this.height = this.canvas.height;
if (this._hasInvalidDimensions()) {
this.fire(new performance.ErrorEvent(new Error('Canvas dimensions cannot be less than or equal to zero.')));
return;
}
this.play = function () {
this._playing = true;
this.map.triggerRepaint();
};
this.pause = function () {
if (this._playing) {
this.prepare();
this._playing = false;
}
};
this._finishLoading();
};
CanvasSource.prototype.getCanvas = function getCanvas() {
return this.canvas;
};
CanvasSource.prototype.onAdd = function onAdd(map) {
this.map = map;
this.load();
if (this.canvas) {
if (this.animate) {
this.play();
}
}
};
CanvasSource.prototype.onRemove = function onRemove() {
this.pause();
};
CanvasSource.prototype.prepare = function prepare() {
var resize = false;
if (this.canvas.width !== this.width) {
this.width = this.canvas.width;
resize = true;
}
if (this.canvas.height !== this.height) {
this.height = this.canvas.height;
resize = true;
}
if (this._hasInvalidDimensions()) {
return;
}
if (Object.keys(this.tiles).length === 0) {
return;
}
var context = this.map.painter.context;
var gl = context.gl;
if (!this.boundsBuffer) {
this.boundsBuffer = context.createVertexBuffer(this._boundsArray, rasterBoundsAttributes.members);
}
if (!this.boundsSegments) {
this.boundsSegments = performance.SegmentVector.simpleSegment(0, 0, 4, 2);
}
if (!this.texture) {
this.texture = new performance.Texture(context, this.canvas, gl.RGBA, { premultiply: true });
} else if (resize || this._playing) {
this.texture.update(this.canvas, { premultiply: true });
}
for (var w in this.tiles) {
var tile = this.tiles[w];
if (tile.state !== 'loaded') {
tile.state = 'loaded';
tile.texture = this.texture;
}
}
};
CanvasSource.prototype.serialize = function serialize() {
return {
type: 'canvas',
coordinates: this.coordinates
};
};
CanvasSource.prototype.hasTransition = function hasTransition() {
return this._playing;
};
CanvasSource.prototype._hasInvalidDimensions = function _hasInvalidDimensions() {
for (var i = 0, list = [
this.canvas.width,
this.canvas.height
]; i < list.length; i += 1) {
var x = list[i];
if (isNaN(x) || x <= 0) {
return true;
}
}
return false;
};
return CanvasSource;
}(ImageSource);
var sourceTypes = {
vector: VectorTileSource,
raster: RasterTileSource,
'raster-dem': RasterDEMTileSource,
geojson: GeoJSONSource,
video: VideoSource,
image: ImageSource,
canvas: CanvasSource
};
var create = function (id, specification, dispatcher, eventedParent) {
var source = new sourceTypes[specification.type](id, specification, dispatcher, eventedParent);
if (source.id !== id) {
throw new Error('Expected Source id to be ' + id + ' instead of ' + source.id);
}
performance.bindAll([
'load',
'abort',
'unload',
'serialize',
'prepare'
], source);
return source;
};
var getType = function (name) {
return sourceTypes[name];
};
var setType = function (name, type) {
sourceTypes[name] = type;
};
function getPixelPosMatrix(transform, tileID) {
var t = performance.identity([]);
performance.translate(t, t, [
1,
1,
0
]);
performance.scale(t, t, [
transform.width * 0.5,
transform.height * 0.5,
1
]);
return performance.multiply(t, t, transform.calculatePosMatrix(tileID.toUnwrapped()));
}
function queryIncludes3DLayer(layers, styleLayers, sourceID) {
if (layers) {
for (var i = 0, list = layers; i < list.length; i += 1) {
var layerID = list[i];
var layer = styleLayers[layerID];
if (layer && layer.source === sourceID && layer.type === 'fill-extrusion') {
return true;
}
}
} else {
for (var key in styleLayers) {
var layer$1 = styleLayers[key];
if (layer$1.source === sourceID && layer$1.type === 'fill-extrusion') {
return true;
}
}
}
return false;
}
function queryRenderedFeatures(sourceCache, styleLayers, serializedLayers, queryGeometry, params, transform) {
var has3DLayer = queryIncludes3DLayer(params && params.layers, styleLayers, sourceCache.id);
var maxPitchScaleFactor = transform.maxPitchScaleFactor();
var tilesIn = sourceCache.tilesIn(queryGeometry, maxPitchScaleFactor, has3DLayer);
tilesIn.sort(sortTilesIn);
var renderedFeatureLayers = [];
for (var i = 0, list = tilesIn; i < list.length; i += 1) {
var tileIn = list[i];
renderedFeatureLayers.push({
wrappedTileID: tileIn.tileID.wrapped().key,
queryResults: tileIn.tile.queryRenderedFeatures(styleLayers, serializedLayers, sourceCache._state, tileIn.queryGeometry, tileIn.cameraQueryGeometry, tileIn.scale, params, transform, maxPitchScaleFactor, getPixelPosMatrix(sourceCache.transform, tileIn.tileID))
});
}
var result = mergeRenderedFeatureLayers(renderedFeatureLayers);
for (var layerID in result) {
result[layerID].forEach(function (featureWrapper) {
var feature = featureWrapper.feature;
var state = sourceCache.getFeatureState(feature.layer['source-layer'], feature.id);
feature.source = feature.layer.source;
if (feature.layer['source-layer']) {
feature.sourceLayer = feature.layer['source-layer'];
}
feature.state = state;
});
}
return result;
}
function queryRenderedSymbols(styleLayers, serializedLayers, sourceCaches, queryGeometry, params, collisionIndex, retainedQueryData) {
var result = {};
var renderedSymbols = collisionIndex.queryRenderedSymbols(queryGeometry);
var bucketQueryData = [];
for (var i = 0, list = Object.keys(renderedSymbols).map(Number); i < list.length; i += 1) {
var bucketInstanceId = list[i];
bucketQueryData.push(retainedQueryData[bucketInstanceId]);
}
bucketQueryData.sort(sortTilesIn);
var loop = function () {
var queryData = list$2[i$2];
var bucketSymbols = queryData.featureIndex.lookupSymbolFeatures(renderedSymbols[queryData.bucketInstanceId], serializedLayers, queryData.bucketIndex, queryData.sourceLayerIndex, params.filter, params.layers, params.availableImages, styleLayers);
for (var layerID in bucketSymbols) {
var resultFeatures = result[layerID] = result[layerID] || [];
var layerSymbols = bucketSymbols[layerID];
layerSymbols.sort(function (a, b) {
var featureSortOrder = queryData.featureSortOrder;
if (featureSortOrder) {
var sortedA = featureSortOrder.indexOf(a.featureIndex);
var sortedB = featureSortOrder.indexOf(b.featureIndex);
return sortedB - sortedA;
} else {
return b.featureIndex - a.featureIndex;
}
});
for (var i$1 = 0, list$1 = layerSymbols; i$1 < list$1.length; i$1 += 1) {
var symbolFeature = list$1[i$1];
resultFeatures.push(symbolFeature);
}
}
};
for (var i$2 = 0, list$2 = bucketQueryData; i$2 < list$2.length; i$2 += 1)
loop();
var loop$1 = function (layerName) {
result[layerName].forEach(function (featureWrapper) {
var feature = featureWrapper.feature;
var layer = styleLayers[layerName];
var sourceCache = sourceCaches[layer.source];
var state = sourceCache.getFeatureState(feature.layer['source-layer'], feature.id);
feature.source = feature.layer.source;
if (feature.layer['source-layer']) {
feature.sourceLayer = feature.layer['source-layer'];
}
feature.state = state;
});
};
for (var layerName in result)
loop$1(layerName);
return result;
}
function querySourceFeatures(sourceCache, params) {
var tiles = sourceCache.getRenderableIds().map(function (id) {
return sourceCache.getTileByID(id);
});
var result = [];
var dataTiles = {};
for (var i = 0; i < tiles.length; i++) {
var tile = tiles[i];
var dataID = tile.tileID.canonical.key;
if (!dataTiles[dataID]) {
dataTiles[dataID] = true;
tile.querySourceFeatures(result, params);
}
}
return result;
}
function sortTilesIn(a, b) {
var idA = a.tileID;
var idB = b.tileID;
return idA.overscaledZ - idB.overscaledZ || idA.canonical.y - idB.canonical.y || idA.wrap - idB.wrap || idA.canonical.x - idB.canonical.x;
}
function mergeRenderedFeatureLayers(tiles) {
var result = {};
var wrappedIDLayerMap = {};
for (var i$1 = 0, list$1 = tiles; i$1 < list$1.length; i$1 += 1) {
var tile = list$1[i$1];
var queryResults = tile.queryResults;
var wrappedID = tile.wrappedTileID;
var wrappedIDLayers = wrappedIDLayerMap[wrappedID] = wrappedIDLayerMap[wrappedID] || {};
for (var layerID in queryResults) {
var tileFeatures = queryResults[layerID];
var wrappedIDFeatures = wrappedIDLayers[layerID] = wrappedIDLayers[layerID] || {};
var resultFeatures = result[layerID] = result[layerID] || [];
for (var i = 0, list = tileFeatures; i < list.length; i += 1) {
var tileFeature = list[i];
if (!wrappedIDFeatures[tileFeature.featureIndex]) {
wrappedIDFeatures[tileFeature.featureIndex] = true;
resultFeatures.push(tileFeature);
}
}
}
}
return result;
}
var TileCache = function TileCache(max, onRemove) {
this.max = max;
this.onRemove = onRemove;
this.reset();
};
TileCache.prototype.reset = function reset() {
for (var key in this.data) {
for (var i = 0, list = this.data[key]; i < list.length; i += 1) {
var removedData = list[i];
if (removedData.timeout) {
clearTimeout(removedData.timeout);
}
this.onRemove(removedData.value);
}
}
this.data = {};
this.order = [];
return this;
};
TileCache.prototype.add = function add(tileID, data, expiryTimeout) {
var this$1 = this;
var key = tileID.wrapped().key;
if (this.data[key] === undefined) {
this.data[key] = [];
}
var dataWrapper = {
value: data,
timeout: undefined
};
if (expiryTimeout !== undefined) {
dataWrapper.timeout = setTimeout(function () {
this$1.remove(tileID, dataWrapper);
}, expiryTimeout);
}
this.data[key].push(dataWrapper);
this.order.push(key);
if (this.order.length > this.max) {
var removedData = this._getAndRemoveByKey(this.order[0]);
if (removedData) {
this.onRemove(removedData);
}
}
return this;
};
TileCache.prototype.has = function has(tileID) {
return tileID.wrapped().key in this.data;
};
TileCache.prototype.getAndRemove = function getAndRemove(tileID) {
if (!this.has(tileID)) {
return null;
}
return this._getAndRemoveByKey(tileID.wrapped().key);
};
TileCache.prototype._getAndRemoveByKey = function _getAndRemoveByKey(key) {
var data = this.data[key].shift();
if (data.timeout) {
clearTimeout(data.timeout);
}
if (this.data[key].length === 0) {
delete this.data[key];
}
this.order.splice(this.order.indexOf(key), 1);
return data.value;
};
TileCache.prototype.getByKey = function getByKey(key) {
var data = this.data[key];
return data ? data[0].value : null;
};
TileCache.prototype.get = function get(tileID) {
if (!this.has(tileID)) {
return null;
}
var data = this.data[tileID.wrapped().key][0];
return data.value;
};
TileCache.prototype.remove = function remove(tileID, value) {
if (!this.has(tileID)) {
return this;
}
var key = tileID.wrapped().key;
var dataIndex = value === undefined ? 0 : this.data[key].indexOf(value);
var data = this.data[key][dataIndex];
this.data[key].splice(dataIndex, 1);
if (data.timeout) {
clearTimeout(data.timeout);
}
if (this.data[key].length === 0) {
delete this.data[key];
}
this.onRemove(data.value);
this.order.splice(this.order.indexOf(key), 1);
return this;
};
TileCache.prototype.setMaxSize = function setMaxSize(max) {
this.max = max;
while (this.order.length > this.max) {
var removedData = this._getAndRemoveByKey(this.order[0]);
if (removedData) {
this.onRemove(removedData);
}
}
return this;
};
TileCache.prototype.filter = function filter(filterFn) {
var removed = [];
for (var key in this.data) {
for (var i = 0, list = this.data[key]; i < list.length; i += 1) {
var entry = list[i];
if (!filterFn(entry.value)) {
removed.push(entry);
}
}
}
for (var i$1 = 0, list$1 = removed; i$1 < list$1.length; i$1 += 1) {
var r = list$1[i$1];
this.remove(r.value.tileID, r);
}
};
var IndexBuffer = function IndexBuffer(context, array, dynamicDraw) {
this.context = context;
var gl = context.gl;
this.buffer = gl.createBuffer();
this.dynamicDraw = Boolean(dynamicDraw);
this.context.unbindVAO();
context.bindElementBuffer.set(this.buffer);
gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, array.arrayBuffer, this.dynamicDraw ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW);
if (!this.dynamicDraw) {
delete array.arrayBuffer;
}
};
IndexBuffer.prototype.bind = function bind() {
this.context.bindElementBuffer.set(this.buffer);
};
IndexBuffer.prototype.updateData = function updateData(array) {
var gl = this.context.gl;
this.context.unbindVAO();
this.bind();
gl.bufferSubData(gl.ELEMENT_ARRAY_BUFFER, 0, array.arrayBuffer);
};
IndexBuffer.prototype.destroy = function destroy() {
var gl = this.context.gl;
if (this.buffer) {
gl.deleteBuffer(this.buffer);
delete this.buffer;
}
};
var AttributeType = {
Int8: 'BYTE',
Uint8: 'UNSIGNED_BYTE',
Int16: 'SHORT',
Uint16: 'UNSIGNED_SHORT',
Int32: 'INT',
Uint32: 'UNSIGNED_INT',
Float32: 'FLOAT'
};
var VertexBuffer = function VertexBuffer(context, array, attributes, dynamicDraw) {
this.length = array.length;
this.attributes = attributes;
this.itemSize = array.bytesPerElement;
this.dynamicDraw = dynamicDraw;
this.context = context;
var gl = context.gl;
this.buffer = gl.createBuffer();
context.bindVertexBuffer.set(this.buffer);
gl.bufferData(gl.ARRAY_BUFFER, array.arrayBuffer, this.dynamicDraw ? gl.DYNAMIC_DRAW : gl.STATIC_DRAW);
if (!this.dynamicDraw) {
delete array.arrayBuffer;
}
};
VertexBuffer.prototype.bind = function bind() {
this.context.bindVertexBuffer.set(this.buffer);
};
VertexBuffer.prototype.updateData = function updateData(array) {
var gl = this.context.gl;
this.bind();
gl.bufferSubData(gl.ARRAY_BUFFER, 0, array.arrayBuffer);
};
VertexBuffer.prototype.enableAttributes = function enableAttributes(gl, program) {
for (var j = 0; j < this.attributes.length; j++) {
var member = this.attributes[j];
var attribIndex = program.attributes[member.name];
if (attribIndex !== undefined) {
gl.enableVertexAttribArray(attribIndex);
}
}
};
VertexBuffer.prototype.setVertexAttribPointers = function setVertexAttribPointers(gl, program, vertexOffset) {
for (var j = 0; j < this.attributes.length; j++) {
var member = this.attributes[j];
var attribIndex = program.attributes[member.name];
if (attribIndex !== undefined) {
gl.vertexAttribPointer(attribIndex, member.components, gl[AttributeType[member.type]], false, this.itemSize, member.offset + this.itemSize * (vertexOffset || 0));
}
}
};
VertexBuffer.prototype.destroy = function destroy() {
var gl = this.context.gl;
if (this.buffer) {
gl.deleteBuffer(this.buffer);
delete this.buffer;
}
};
var BaseValue = function BaseValue(context) {
this.gl = context.gl;
this.default = this.getDefault();
this.current = this.default;
this.dirty = false;
};
BaseValue.prototype.get = function get() {
return this.current;
};
BaseValue.prototype.set = function set(value) {
};
BaseValue.prototype.getDefault = function getDefault() {
return this.default;
};
BaseValue.prototype.setDefault = function setDefault() {
this.set(this.default);
};
var ClearColor = function (BaseValue) {
function ClearColor() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
ClearColor.__proto__ = BaseValue;
ClearColor.prototype = Object.create(BaseValue && BaseValue.prototype);
ClearColor.prototype.constructor = ClearColor;
ClearColor.prototype.getDefault = function getDefault() {
return performance.Color.transparent;
};
ClearColor.prototype.set = function set(v) {
var c = this.current;
if (v.r === c.r && v.g === c.g && v.b === c.b && v.a === c.a && !this.dirty) {
return;
}
this.gl.clearColor(v.r, v.g, v.b, v.a);
this.current = v;
this.dirty = false;
};
return ClearColor;
}(BaseValue);
var ClearDepth = function (BaseValue) {
function ClearDepth() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
ClearDepth.__proto__ = BaseValue;
ClearDepth.prototype = Object.create(BaseValue && BaseValue.prototype);
ClearDepth.prototype.constructor = ClearDepth;
ClearDepth.prototype.getDefault = function getDefault() {
return 1;
};
ClearDepth.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
this.gl.clearDepth(v);
this.current = v;
this.dirty = false;
};
return ClearDepth;
}(BaseValue);
var ClearStencil = function (BaseValue) {
function ClearStencil() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
ClearStencil.__proto__ = BaseValue;
ClearStencil.prototype = Object.create(BaseValue && BaseValue.prototype);
ClearStencil.prototype.constructor = ClearStencil;
ClearStencil.prototype.getDefault = function getDefault() {
return 0;
};
ClearStencil.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
this.gl.clearStencil(v);
this.current = v;
this.dirty = false;
};
return ClearStencil;
}(BaseValue);
var ColorMask = function (BaseValue) {
function ColorMask() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
ColorMask.__proto__ = BaseValue;
ColorMask.prototype = Object.create(BaseValue && BaseValue.prototype);
ColorMask.prototype.constructor = ColorMask;
ColorMask.prototype.getDefault = function getDefault() {
return [
true,
true,
true,
true
];
};
ColorMask.prototype.set = function set(v) {
var c = this.current;
if (v[0] === c[0] && v[1] === c[1] && v[2] === c[2] && v[3] === c[3] && !this.dirty) {
return;
}
this.gl.colorMask(v[0], v[1], v[2], v[3]);
this.current = v;
this.dirty = false;
};
return ColorMask;
}(BaseValue);
var DepthMask = function (BaseValue) {
function DepthMask() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
DepthMask.__proto__ = BaseValue;
DepthMask.prototype = Object.create(BaseValue && BaseValue.prototype);
DepthMask.prototype.constructor = DepthMask;
DepthMask.prototype.getDefault = function getDefault() {
return true;
};
DepthMask.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
this.gl.depthMask(v);
this.current = v;
this.dirty = false;
};
return DepthMask;
}(BaseValue);
var StencilMask = function (BaseValue) {
function StencilMask() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
StencilMask.__proto__ = BaseValue;
StencilMask.prototype = Object.create(BaseValue && BaseValue.prototype);
StencilMask.prototype.constructor = StencilMask;
StencilMask.prototype.getDefault = function getDefault() {
return 255;
};
StencilMask.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
this.gl.stencilMask(v);
this.current = v;
this.dirty = false;
};
return StencilMask;
}(BaseValue);
var StencilFunc = function (BaseValue) {
function StencilFunc() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
StencilFunc.__proto__ = BaseValue;
StencilFunc.prototype = Object.create(BaseValue && BaseValue.prototype);
StencilFunc.prototype.constructor = StencilFunc;
StencilFunc.prototype.getDefault = function getDefault() {
return {
func: this.gl.ALWAYS,
ref: 0,
mask: 255
};
};
StencilFunc.prototype.set = function set(v) {
var c = this.current;
if (v.func === c.func && v.ref === c.ref && v.mask === c.mask && !this.dirty) {
return;
}
this.gl.stencilFunc(v.func, v.ref, v.mask);
this.current = v;
this.dirty = false;
};
return StencilFunc;
}(BaseValue);
var StencilOp = function (BaseValue) {
function StencilOp() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
StencilOp.__proto__ = BaseValue;
StencilOp.prototype = Object.create(BaseValue && BaseValue.prototype);
StencilOp.prototype.constructor = StencilOp;
StencilOp.prototype.getDefault = function getDefault() {
var gl = this.gl;
return [
gl.KEEP,
gl.KEEP,
gl.KEEP
];
};
StencilOp.prototype.set = function set(v) {
var c = this.current;
if (v[0] === c[0] && v[1] === c[1] && v[2] === c[2] && !this.dirty) {
return;
}
this.gl.stencilOp(v[0], v[1], v[2]);
this.current = v;
this.dirty = false;
};
return StencilOp;
}(BaseValue);
var StencilTest = function (BaseValue) {
function StencilTest() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
StencilTest.__proto__ = BaseValue;
StencilTest.prototype = Object.create(BaseValue && BaseValue.prototype);
StencilTest.prototype.constructor = StencilTest;
StencilTest.prototype.getDefault = function getDefault() {
return false;
};
StencilTest.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
var gl = this.gl;
if (v) {
gl.enable(gl.STENCIL_TEST);
} else {
gl.disable(gl.STENCIL_TEST);
}
this.current = v;
this.dirty = false;
};
return StencilTest;
}(BaseValue);
var DepthRange = function (BaseValue) {
function DepthRange() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
DepthRange.__proto__ = BaseValue;
DepthRange.prototype = Object.create(BaseValue && BaseValue.prototype);
DepthRange.prototype.constructor = DepthRange;
DepthRange.prototype.getDefault = function getDefault() {
return [
0,
1
];
};
DepthRange.prototype.set = function set(v) {
var c = this.current;
if (v[0] === c[0] && v[1] === c[1] && !this.dirty) {
return;
}
this.gl.depthRange(v[0], v[1]);
this.current = v;
this.dirty = false;
};
return DepthRange;
}(BaseValue);
var DepthTest = function (BaseValue) {
function DepthTest() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
DepthTest.__proto__ = BaseValue;
DepthTest.prototype = Object.create(BaseValue && BaseValue.prototype);
DepthTest.prototype.constructor = DepthTest;
DepthTest.prototype.getDefault = function getDefault() {
return false;
};
DepthTest.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
var gl = this.gl;
if (v) {
gl.enable(gl.DEPTH_TEST);
} else {
gl.disable(gl.DEPTH_TEST);
}
this.current = v;
this.dirty = false;
};
return DepthTest;
}(BaseValue);
var DepthFunc = function (BaseValue) {
function DepthFunc() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
DepthFunc.__proto__ = BaseValue;
DepthFunc.prototype = Object.create(BaseValue && BaseValue.prototype);
DepthFunc.prototype.constructor = DepthFunc;
DepthFunc.prototype.getDefault = function getDefault() {
return this.gl.LESS;
};
DepthFunc.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
this.gl.depthFunc(v);
this.current = v;
this.dirty = false;
};
return DepthFunc;
}(BaseValue);
var Blend = function (BaseValue) {
function Blend() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
Blend.__proto__ = BaseValue;
Blend.prototype = Object.create(BaseValue && BaseValue.prototype);
Blend.prototype.constructor = Blend;
Blend.prototype.getDefault = function getDefault() {
return false;
};
Blend.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
var gl = this.gl;
if (v) {
gl.enable(gl.BLEND);
} else {
gl.disable(gl.BLEND);
}
this.current = v;
this.dirty = false;
};
return Blend;
}(BaseValue);
var BlendFunc = function (BaseValue) {
function BlendFunc() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
BlendFunc.__proto__ = BaseValue;
BlendFunc.prototype = Object.create(BaseValue && BaseValue.prototype);
BlendFunc.prototype.constructor = BlendFunc;
BlendFunc.prototype.getDefault = function getDefault() {
var gl = this.gl;
return [
gl.ONE,
gl.ZERO
];
};
BlendFunc.prototype.set = function set(v) {
var c = this.current;
if (v[0] === c[0] && v[1] === c[1] && !this.dirty) {
return;
}
this.gl.blendFunc(v[0], v[1]);
this.current = v;
this.dirty = false;
};
return BlendFunc;
}(BaseValue);
var BlendColor = function (BaseValue) {
function BlendColor() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
BlendColor.__proto__ = BaseValue;
BlendColor.prototype = Object.create(BaseValue && BaseValue.prototype);
BlendColor.prototype.constructor = BlendColor;
BlendColor.prototype.getDefault = function getDefault() {
return performance.Color.transparent;
};
BlendColor.prototype.set = function set(v) {
var c = this.current;
if (v.r === c.r && v.g === c.g && v.b === c.b && v.a === c.a && !this.dirty) {
return;
}
this.gl.blendColor(v.r, v.g, v.b, v.a);
this.current = v;
this.dirty = false;
};
return BlendColor;
}(BaseValue);
var BlendEquation = function (BaseValue) {
function BlendEquation() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
BlendEquation.__proto__ = BaseValue;
BlendEquation.prototype = Object.create(BaseValue && BaseValue.prototype);
BlendEquation.prototype.constructor = BlendEquation;
BlendEquation.prototype.getDefault = function getDefault() {
return this.gl.FUNC_ADD;
};
BlendEquation.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
this.gl.blendEquation(v);
this.current = v;
this.dirty = false;
};
return BlendEquation;
}(BaseValue);
var CullFace = function (BaseValue) {
function CullFace() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
CullFace.__proto__ = BaseValue;
CullFace.prototype = Object.create(BaseValue && BaseValue.prototype);
CullFace.prototype.constructor = CullFace;
CullFace.prototype.getDefault = function getDefault() {
return false;
};
CullFace.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
var gl = this.gl;
if (v) {
gl.enable(gl.CULL_FACE);
} else {
gl.disable(gl.CULL_FACE);
}
this.current = v;
this.dirty = false;
};
return CullFace;
}(BaseValue);
var CullFaceSide = function (BaseValue) {
function CullFaceSide() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
CullFaceSide.__proto__ = BaseValue;
CullFaceSide.prototype = Object.create(BaseValue && BaseValue.prototype);
CullFaceSide.prototype.constructor = CullFaceSide;
CullFaceSide.prototype.getDefault = function getDefault() {
return this.gl.BACK;
};
CullFaceSide.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
this.gl.cullFace(v);
this.current = v;
this.dirty = false;
};
return CullFaceSide;
}(BaseValue);
var FrontFace = function (BaseValue) {
function FrontFace() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
FrontFace.__proto__ = BaseValue;
FrontFace.prototype = Object.create(BaseValue && BaseValue.prototype);
FrontFace.prototype.constructor = FrontFace;
FrontFace.prototype.getDefault = function getDefault() {
return this.gl.CCW;
};
FrontFace.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
this.gl.frontFace(v);
this.current = v;
this.dirty = false;
};
return FrontFace;
}(BaseValue);
var Program = function (BaseValue) {
function Program() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
Program.__proto__ = BaseValue;
Program.prototype = Object.create(BaseValue && BaseValue.prototype);
Program.prototype.constructor = Program;
Program.prototype.getDefault = function getDefault() {
return null;
};
Program.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
this.gl.useProgram(v);
this.current = v;
this.dirty = false;
};
return Program;
}(BaseValue);
var ActiveTextureUnit = function (BaseValue) {
function ActiveTextureUnit() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
ActiveTextureUnit.__proto__ = BaseValue;
ActiveTextureUnit.prototype = Object.create(BaseValue && BaseValue.prototype);
ActiveTextureUnit.prototype.constructor = ActiveTextureUnit;
ActiveTextureUnit.prototype.getDefault = function getDefault() {
return this.gl.TEXTURE0;
};
ActiveTextureUnit.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
this.gl.activeTexture(v);
this.current = v;
this.dirty = false;
};
return ActiveTextureUnit;
}(BaseValue);
var Viewport = function (BaseValue) {
function Viewport() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
Viewport.__proto__ = BaseValue;
Viewport.prototype = Object.create(BaseValue && BaseValue.prototype);
Viewport.prototype.constructor = Viewport;
Viewport.prototype.getDefault = function getDefault() {
var gl = this.gl;
return [
0,
0,
gl.drawingBufferWidth,
gl.drawingBufferHeight
];
};
Viewport.prototype.set = function set(v) {
var c = this.current;
if (v[0] === c[0] && v[1] === c[1] && v[2] === c[2] && v[3] === c[3] && !this.dirty) {
return;
}
this.gl.viewport(v[0], v[1], v[2], v[3]);
this.current = v;
this.dirty = false;
};
return Viewport;
}(BaseValue);
var BindFramebuffer = function (BaseValue) {
function BindFramebuffer() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
BindFramebuffer.__proto__ = BaseValue;
BindFramebuffer.prototype = Object.create(BaseValue && BaseValue.prototype);
BindFramebuffer.prototype.constructor = BindFramebuffer;
BindFramebuffer.prototype.getDefault = function getDefault() {
return null;
};
BindFramebuffer.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
var gl = this.gl;
gl.bindFramebuffer(gl.FRAMEBUFFER, v);
this.current = v;
this.dirty = false;
};
return BindFramebuffer;
}(BaseValue);
var BindRenderbuffer = function (BaseValue) {
function BindRenderbuffer() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
BindRenderbuffer.__proto__ = BaseValue;
BindRenderbuffer.prototype = Object.create(BaseValue && BaseValue.prototype);
BindRenderbuffer.prototype.constructor = BindRenderbuffer;
BindRenderbuffer.prototype.getDefault = function getDefault() {
return null;
};
BindRenderbuffer.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
var gl = this.gl;
gl.bindRenderbuffer(gl.RENDERBUFFER, v);
this.current = v;
this.dirty = false;
};
return BindRenderbuffer;
}(BaseValue);
var BindTexture = function (BaseValue) {
function BindTexture() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
BindTexture.__proto__ = BaseValue;
BindTexture.prototype = Object.create(BaseValue && BaseValue.prototype);
BindTexture.prototype.constructor = BindTexture;
BindTexture.prototype.getDefault = function getDefault() {
return null;
};
BindTexture.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
var gl = this.gl;
gl.bindTexture(gl.TEXTURE_2D, v);
this.current = v;
this.dirty = false;
};
return BindTexture;
}(BaseValue);
var BindVertexBuffer = function (BaseValue) {
function BindVertexBuffer() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
BindVertexBuffer.__proto__ = BaseValue;
BindVertexBuffer.prototype = Object.create(BaseValue && BaseValue.prototype);
BindVertexBuffer.prototype.constructor = BindVertexBuffer;
BindVertexBuffer.prototype.getDefault = function getDefault() {
return null;
};
BindVertexBuffer.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
var gl = this.gl;
gl.bindBuffer(gl.ARRAY_BUFFER, v);
this.current = v;
this.dirty = false;
};
return BindVertexBuffer;
}(BaseValue);
var BindElementBuffer = function (BaseValue) {
function BindElementBuffer() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
BindElementBuffer.__proto__ = BaseValue;
BindElementBuffer.prototype = Object.create(BaseValue && BaseValue.prototype);
BindElementBuffer.prototype.constructor = BindElementBuffer;
BindElementBuffer.prototype.getDefault = function getDefault() {
return null;
};
BindElementBuffer.prototype.set = function set(v) {
var gl = this.gl;
gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, v);
this.current = v;
this.dirty = false;
};
return BindElementBuffer;
}(BaseValue);
var BindVertexArrayOES = function (BaseValue) {
function BindVertexArrayOES(context) {
BaseValue.call(this, context);
this.vao = context.extVertexArrayObject;
}
if (BaseValue)
BindVertexArrayOES.__proto__ = BaseValue;
BindVertexArrayOES.prototype = Object.create(BaseValue && BaseValue.prototype);
BindVertexArrayOES.prototype.constructor = BindVertexArrayOES;
BindVertexArrayOES.prototype.getDefault = function getDefault() {
return null;
};
BindVertexArrayOES.prototype.set = function set(v) {
if (!this.vao || v === this.current && !this.dirty) {
return;
}
this.vao.bindVertexArrayOES(v);
this.current = v;
this.dirty = false;
};
return BindVertexArrayOES;
}(BaseValue);
var PixelStoreUnpack = function (BaseValue) {
function PixelStoreUnpack() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
PixelStoreUnpack.__proto__ = BaseValue;
PixelStoreUnpack.prototype = Object.create(BaseValue && BaseValue.prototype);
PixelStoreUnpack.prototype.constructor = PixelStoreUnpack;
PixelStoreUnpack.prototype.getDefault = function getDefault() {
return 4;
};
PixelStoreUnpack.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
var gl = this.gl;
gl.pixelStorei(gl.UNPACK_ALIGNMENT, v);
this.current = v;
this.dirty = false;
};
return PixelStoreUnpack;
}(BaseValue);
var PixelStoreUnpackPremultiplyAlpha = function (BaseValue) {
function PixelStoreUnpackPremultiplyAlpha() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
PixelStoreUnpackPremultiplyAlpha.__proto__ = BaseValue;
PixelStoreUnpackPremultiplyAlpha.prototype = Object.create(BaseValue && BaseValue.prototype);
PixelStoreUnpackPremultiplyAlpha.prototype.constructor = PixelStoreUnpackPremultiplyAlpha;
PixelStoreUnpackPremultiplyAlpha.prototype.getDefault = function getDefault() {
return false;
};
PixelStoreUnpackPremultiplyAlpha.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
var gl = this.gl;
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, v);
this.current = v;
this.dirty = false;
};
return PixelStoreUnpackPremultiplyAlpha;
}(BaseValue);
var PixelStoreUnpackFlipY = function (BaseValue) {
function PixelStoreUnpackFlipY() {
BaseValue.apply(this, arguments);
}
if (BaseValue)
PixelStoreUnpackFlipY.__proto__ = BaseValue;
PixelStoreUnpackFlipY.prototype = Object.create(BaseValue && BaseValue.prototype);
PixelStoreUnpackFlipY.prototype.constructor = PixelStoreUnpackFlipY;
PixelStoreUnpackFlipY.prototype.getDefault = function getDefault() {
return false;
};
PixelStoreUnpackFlipY.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
var gl = this.gl;
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, v);
this.current = v;
this.dirty = false;
};
return PixelStoreUnpackFlipY;
}(BaseValue);
var FramebufferAttachment = function (BaseValue) {
function FramebufferAttachment(context, parent) {
BaseValue.call(this, context);
this.context = context;
this.parent = parent;
}
if (BaseValue)
FramebufferAttachment.__proto__ = BaseValue;
FramebufferAttachment.prototype = Object.create(BaseValue && BaseValue.prototype);
FramebufferAttachment.prototype.constructor = FramebufferAttachment;
FramebufferAttachment.prototype.getDefault = function getDefault() {
return null;
};
return FramebufferAttachment;
}(BaseValue);
var ColorAttachment = function (FramebufferAttachment) {
function ColorAttachment() {
FramebufferAttachment.apply(this, arguments);
}
if (FramebufferAttachment)
ColorAttachment.__proto__ = FramebufferAttachment;
ColorAttachment.prototype = Object.create(FramebufferAttachment && FramebufferAttachment.prototype);
ColorAttachment.prototype.constructor = ColorAttachment;
ColorAttachment.prototype.setDirty = function setDirty() {
this.dirty = true;
};
ColorAttachment.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
this.context.bindFramebuffer.set(this.parent);
var gl = this.gl;
gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, v, 0);
this.current = v;
this.dirty = false;
};
return ColorAttachment;
}(FramebufferAttachment);
var DepthAttachment = function (FramebufferAttachment) {
function DepthAttachment() {
FramebufferAttachment.apply(this, arguments);
}
if (FramebufferAttachment)
DepthAttachment.__proto__ = FramebufferAttachment;
DepthAttachment.prototype = Object.create(FramebufferAttachment && FramebufferAttachment.prototype);
DepthAttachment.prototype.constructor = DepthAttachment;
DepthAttachment.prototype.set = function set(v) {
if (v === this.current && !this.dirty) {
return;
}
this.context.bindFramebuffer.set(this.parent);
var gl = this.gl;
gl.framebufferRenderbuffer(gl.FRAMEBUFFER, gl.DEPTH_ATTACHMENT, gl.RENDERBUFFER, v);
this.current = v;
this.dirty = false;
};
return DepthAttachment;
}(FramebufferAttachment);
var Framebuffer = function Framebuffer(context, width, height, hasDepth) {
this.context = context;
this.width = width;
this.height = height;
var gl = context.gl;
var fbo = this.framebuffer = gl.createFramebuffer();
this.colorAttachment = new ColorAttachment(context, fbo);
if (hasDepth) {
this.depthAttachment = new DepthAttachment(context, fbo);
}
};
Framebuffer.prototype.destroy = function destroy() {
var gl = this.context.gl;
var texture = this.colorAttachment.get();
if (texture) {
gl.deleteTexture(texture);
}
if (this.depthAttachment) {
var renderbuffer = this.depthAttachment.get();
if (renderbuffer) {
gl.deleteRenderbuffer(renderbuffer);
}
}
gl.deleteFramebuffer(this.framebuffer);
};
var ALWAYS = 519;
var DepthMode = function DepthMode(depthFunc, depthMask, depthRange) {
this.func = depthFunc;
this.mask = depthMask;
this.range = depthRange;
};
DepthMode.ReadOnly = false;
DepthMode.ReadWrite = true;
DepthMode.disabled = new DepthMode(ALWAYS, DepthMode.ReadOnly, [
0,
1
]);
var ALWAYS$1 = 519;
var KEEP = 7680;
var StencilMode = function StencilMode(test, ref, mask, fail, depthFail, pass) {
this.test = test;
this.ref = ref;
this.mask = mask;
this.fail = fail;
this.depthFail = depthFail;
this.pass = pass;
};
StencilMode.disabled = new StencilMode({
func: ALWAYS$1,
mask: 0
}, 0, 0, KEEP, KEEP, KEEP);
var ZERO = 0;
var ONE = 1;
var ONE_MINUS_SRC_ALPHA = 771;
var ColorMode = function ColorMode(blendFunction, blendColor, mask) {
this.blendFunction = blendFunction;
this.blendColor = blendColor;
this.mask = mask;
};
ColorMode.Replace = [
ONE,
ZERO
];
ColorMode.disabled = new ColorMode(ColorMode.Replace, performance.Color.transparent, [
false,
false,
false,
false
]);
ColorMode.unblended = new ColorMode(ColorMode.Replace, performance.Color.transparent, [
true,
true,
true,
true
]);
ColorMode.alphaBlended = new ColorMode([
ONE,
ONE_MINUS_SRC_ALPHA
], performance.Color.transparent, [
true,
true,
true,
true
]);
var BACK = 1029;
var CCW = 2305;
var CullFaceMode = function CullFaceMode(enable, mode, frontFace) {
this.enable = enable;
this.mode = mode;
this.frontFace = frontFace;
};
CullFaceMode.disabled = new CullFaceMode(false, BACK, CCW);
CullFaceMode.backCCW = new CullFaceMode(true, BACK, CCW);
var Context = function Context(gl) {
this.gl = gl;
this.extVertexArrayObject = this.gl.getExtension('OES_vertex_array_object');
this.clearColor = new ClearColor(this);
this.clearDepth = new ClearDepth(this);
this.clearStencil = new ClearStencil(this);
this.colorMask = new ColorMask(this);
this.depthMask = new DepthMask(this);
this.stencilMask = new StencilMask(this);
this.stencilFunc = new StencilFunc(this);
this.stencilOp = new StencilOp(this);
this.stencilTest = new StencilTest(this);
this.depthRange = new DepthRange(this);
this.depthTest = new DepthTest(this);
this.depthFunc = new DepthFunc(this);
this.blend = new Blend(this);
this.blendFunc = new BlendFunc(this);
this.blendColor = new BlendColor(this);
this.blendEquation = new BlendEquation(this);
this.cullFace = new CullFace(this);
this.cullFaceSide = new CullFaceSide(this);
this.frontFace = new FrontFace(this);
this.program = new Program(this);
this.activeTexture = new ActiveTextureUnit(this);
this.viewport = new Viewport(this);
this.bindFramebuffer = new BindFramebuffer(this);
this.bindRenderbuffer = new BindRenderbuffer(this);
this.bindTexture = new BindTexture(this);
this.bindVertexBuffer = new BindVertexBuffer(this);
this.bindElementBuffer = new BindElementBuffer(this);
this.bindVertexArrayOES = this.extVertexArrayObject && new BindVertexArrayOES(this);
this.pixelStoreUnpack = new PixelStoreUnpack(this);
this.pixelStoreUnpackPremultiplyAlpha = new PixelStoreUnpackPremultiplyAlpha(this);
this.pixelStoreUnpackFlipY = new PixelStoreUnpackFlipY(this);
this.extTextureFilterAnisotropic = gl.getExtension('EXT_texture_filter_anisotropic') || gl.getExtension('MOZ_EXT_texture_filter_anisotropic') || gl.getExtension('WEBKIT_EXT_texture_filter_anisotropic');
if (this.extTextureFilterAnisotropic) {
this.extTextureFilterAnisotropicMax = gl.getParameter(this.extTextureFilterAnisotropic.MAX_TEXTURE_MAX_ANISOTROPY_EXT);
}
this.extTextureHalfFloat = gl.getExtension('OES_texture_half_float');
if (this.extTextureHalfFloat) {
gl.getExtension('OES_texture_half_float_linear');
this.extRenderToTextureHalfFloat = gl.getExtension('EXT_color_buffer_half_float');
}
this.extTimerQuery = gl.getExtension('EXT_disjoint_timer_query');
this.maxTextureSize = gl.getParameter(gl.MAX_TEXTURE_SIZE);
};
Context.prototype.setDefault = function setDefault() {
this.unbindVAO();
this.clearColor.setDefault();
this.clearDepth.setDefault();
this.clearStencil.setDefault();
this.colorMask.setDefault();
this.depthMask.setDefault();
this.stencilMask.setDefault();
this.stencilFunc.setDefault();
this.stencilOp.setDefault();
this.stencilTest.setDefault();
this.depthRange.setDefault();
this.depthTest.setDefault();
this.depthFunc.setDefault();
this.blend.setDefault();
this.blendFunc.setDefault();
this.blendColor.setDefault();
this.blendEquation.setDefault();
this.cullFace.setDefault();
this.cullFaceSide.setDefault();
this.frontFace.setDefault();
this.program.setDefault();
this.activeTexture.setDefault();
this.bindFramebuffer.setDefault();
this.pixelStoreUnpack.setDefault();
this.pixelStoreUnpackPremultiplyAlpha.setDefault();
this.pixelStoreUnpackFlipY.setDefault();
};
Context.prototype.setDirty = function setDirty() {
this.clearColor.dirty = true;
this.clearDepth.dirty = true;
this.clearStencil.dirty = true;
this.colorMask.dirty = true;
this.depthMask.dirty = true;
this.stencilMask.dirty = true;
this.stencilFunc.dirty = true;
this.stencilOp.dirty = true;
this.stencilTest.dirty = true;
this.depthRange.dirty = true;
this.depthTest.dirty = true;
this.depthFunc.dirty = true;
this.blend.dirty = true;
this.blendFunc.dirty = true;
this.blendColor.dirty = true;
this.blendEquation.dirty = true;
this.cullFace.dirty = true;
this.cullFaceSide.dirty = true;
this.frontFace.dirty = true;
this.program.dirty = true;
this.activeTexture.dirty = true;
this.viewport.dirty = true;
this.bindFramebuffer.dirty = true;
this.bindRenderbuffer.dirty = true;
this.bindTexture.dirty = true;
this.bindVertexBuffer.dirty = true;
this.bindElementBuffer.dirty = true;
if (this.extVertexArrayObject) {
this.bindVertexArrayOES.dirty = true;
}
this.pixelStoreUnpack.dirty = true;
this.pixelStoreUnpackPremultiplyAlpha.dirty = true;
this.pixelStoreUnpackFlipY.dirty = true;
};
Context.prototype.createIndexBuffer = function createIndexBuffer(array, dynamicDraw) {
return new IndexBuffer(this, array, dynamicDraw);
};
Context.prototype.createVertexBuffer = function createVertexBuffer(array, attributes, dynamicDraw) {
return new VertexBuffer(this, array, attributes, dynamicDraw);
};
Context.prototype.createRenderbuffer = function createRenderbuffer(storageFormat, width, height) {
var gl = this.gl;
var rbo = gl.createRenderbuffer();
this.bindRenderbuffer.set(rbo);
gl.renderbufferStorage(gl.RENDERBUFFER, storageFormat, width, height);
this.bindRenderbuffer.set(null);
return rbo;
};
Context.prototype.createFramebuffer = function createFramebuffer(width, height, hasDepth) {
return new Framebuffer(this, width, height, hasDepth);
};
Context.prototype.clear = function clear(ref) {
var color = ref.color;
var depth = ref.depth;
var gl = this.gl;
var mask = 0;
if (color) {
mask |= gl.COLOR_BUFFER_BIT;
this.clearColor.set(color);
this.colorMask.set([
true,
true,
true,
true
]);
}
if (typeof depth !== 'undefined') {
mask |= gl.DEPTH_BUFFER_BIT;
this.depthRange.set([
0,
1
]);
this.clearDepth.set(depth);
this.depthMask.set(true);
}
gl.clear(mask);
};
Context.prototype.setCullFace = function setCullFace(cullFaceMode) {
if (cullFaceMode.enable === false) {
this.cullFace.set(false);
} else {
this.cullFace.set(true);
this.cullFaceSide.set(cullFaceMode.mode);
this.frontFace.set(cullFaceMode.frontFace);
}
};
Context.prototype.setDepthMode = function setDepthMode(depthMode) {
if (depthMode.func === this.gl.ALWAYS && !depthMode.mask) {
this.depthTest.set(false);
} else {
this.depthTest.set(true);
this.depthFunc.set(depthMode.func);
this.depthMask.set(depthMode.mask);
this.depthRange.set(depthMode.range);
}
};
Context.prototype.setStencilMode = function setStencilMode(stencilMode) {
if (stencilMode.test.func === this.gl.ALWAYS && !stencilMode.mask) {
this.stencilTest.set(false);
} else {
this.stencilTest.set(true);
this.stencilMask.set(stencilMode.mask);
this.stencilOp.set([
stencilMode.fail,
stencilMode.depthFail,
stencilMode.pass
]);
this.stencilFunc.set({
func: stencilMode.test.func,
ref: stencilMode.ref,
mask: stencilMode.test.mask
});
}
};
Context.prototype.setColorMode = function setColorMode(colorMode) {
if (performance.deepEqual(colorMode.blendFunction, ColorMode.Replace)) {
this.blend.set(false);
} else {
this.blend.set(true);
this.blendFunc.set(colorMode.blendFunction);
this.blendColor.set(colorMode.blendColor);
}
this.colorMask.set(colorMode.mask);
};
Context.prototype.unbindVAO = function unbindVAO() {
if (this.extVertexArrayObject) {
this.bindVertexArrayOES.set(null);
}
};
var SourceCache = function (Evented) {
function SourceCache(id, options, dispatcher) {
var this$1 = this;
Evented.call(this);
this.id = id;
this.dispatcher = dispatcher;
this.on('data', function (e) {
if (e.dataType === 'source' && e.sourceDataType === 'metadata') {
this$1._sourceLoaded = true;
}
if (this$1._sourceLoaded && !this$1._paused && e.dataType === 'source' && e.sourceDataType === 'content') {
this$1.reload();
if (this$1.transform) {
this$1.update(this$1.transform);
}
}
});
this.on('error', function () {
this$1._sourceErrored = true;
});
this._source = create(id, options, dispatcher, this);
this._tiles = {};
this._cache = new TileCache(0, this._unloadTile.bind(this));
this._timers = {};
this._cacheTimers = {};
this._maxTileCacheSize = null;
this._loadedParentTiles = {};
this._coveredTiles = {};
this._state = new performance.SourceFeatureState();
}
if (Evented)
SourceCache.__proto__ = Evented;
SourceCache.prototype = Object.create(Evented && Evented.prototype);
SourceCache.prototype.constructor = SourceCache;
SourceCache.prototype.onAdd = function onAdd(map) {
this.map = map;
this._maxTileCacheSize = map ? map._maxTileCacheSize : null;
if (this._source && this._source.onAdd) {
this._source.onAdd(map);
}
};
SourceCache.prototype.onRemove = function onRemove(map) {
if (this._source && this._source.onRemove) {
this._source.onRemove(map);
}
};
SourceCache.prototype.loaded = function loaded() {
if (this._sourceErrored) {
return true;
}
if (!this._sourceLoaded) {
return false;
}
if (!this._source.loaded()) {
return false;
}
for (var t in this._tiles) {
var tile = this._tiles[t];
if (tile.state !== 'loaded' && tile.state !== 'errored') {
return false;
}
}
return true;
};
SourceCache.prototype.getSource = function getSource() {
return this._source;
};
SourceCache.prototype.pause = function pause() {
this._paused = true;
};
SourceCache.prototype.resume = function resume() {
if (!this._paused) {
return;
}
var shouldReload = this._shouldReloadOnResume;
this._paused = false;
this._shouldReloadOnResume = false;
if (shouldReload) {
this.reload();
}
if (this.transform) {
this.update(this.transform);
}
};
SourceCache.prototype._loadTile = function _loadTile(tile, callback) {
return this._source.loadTile(tile, callback);
};
SourceCache.prototype._unloadTile = function _unloadTile(tile) {
if (this._source.unloadTile) {
return this._source.unloadTile(tile, function () {
});
}
};
SourceCache.prototype._abortTile = function _abortTile(tile) {
if (this._source.abortTile) {
return this._source.abortTile(tile, function () {
});
}
};
SourceCache.prototype.serialize = function serialize() {
return this._source.serialize();
};
SourceCache.prototype.prepare = function prepare(context) {
if (this._source.prepare) {
this._source.prepare();
}
this._state.coalesceChanges(this._tiles, this.map ? this.map.painter : null);
for (var i in this._tiles) {
var tile = this._tiles[i];
tile.upload(context);
tile.prepare(this.map.style.imageManager);
}
};
SourceCache.prototype.getIds = function getIds() {
return performance.values(this._tiles).map(function (tile) {
return tile.tileID;
}).sort(compareTileId).map(function (id) {
return id.key;
});
};
SourceCache.prototype.getRenderableIds = function getRenderableIds(symbolLayer) {
var this$1 = this;
var renderables = [];
for (var id in this._tiles) {
if (this._isIdRenderable(id, symbolLayer)) {
renderables.push(this._tiles[id]);
}
}
if (symbolLayer) {
return renderables.sort(function (a_, b_) {
var a = a_.tileID;
var b = b_.tileID;
var rotatedA = new performance.Point(a.canonical.x, a.canonical.y)._rotate(this$1.transform.angle);
var rotatedB = new performance.Point(b.canonical.x, b.canonical.y)._rotate(this$1.transform.angle);
return a.overscaledZ - b.overscaledZ || rotatedB.y - rotatedA.y || rotatedB.x - rotatedA.x;
}).map(function (tile) {
return tile.tileID.key;
});
}
return renderables.map(function (tile) {
return tile.tileID;
}).sort(compareTileId).map(function (id) {
return id.key;
});
};
SourceCache.prototype.hasRenderableParent = function hasRenderableParent(tileID) {
var parentTile = this.findLoadedParent(tileID, 0);
if (parentTile) {
return this._isIdRenderable(parentTile.tileID.key);
}
return false;
};
SourceCache.prototype._isIdRenderable = function _isIdRenderable(id, symbolLayer) {
return this._tiles[id] && this._tiles[id].hasData() && !this._coveredTiles[id] && (symbolLayer || !this._tiles[id].holdingForFade());
};
SourceCache.prototype.reload = function reload() {
if (this._paused) {
this._shouldReloadOnResume = true;
return;
}
this._cache.reset();
for (var i in this._tiles) {
if (this._tiles[i].state !== 'errored') {
this._reloadTile(i, 'reloading');
}
}
};
SourceCache.prototype._reloadTile = function _reloadTile(id, state) {
var tile = this._tiles[id];
if (!tile) {
return;
}
if (tile.state !== 'loading') {
tile.state = state;
}
this._loadTile(tile, this._tileLoaded.bind(this, tile, id, state));
};
SourceCache.prototype._tileLoaded = function _tileLoaded(tile, id, previousState, err) {
if (err) {
tile.state = 'errored';
if (err.status !== 404) {
this._source.fire(new performance.ErrorEvent(err, { tile: tile }));
} else {
this.update(this.transform);
}
return;
}
tile.timeAdded = performance.browser.now();
if (previousState === 'expired') {
tile.refreshedUponExpiration = true;
}
this._setTileReloadTimer(id, tile);
if (this.getSource().type === 'raster-dem' && tile.dem) {
this._backfillDEM(tile);
}
this._state.initializeTileState(tile, this.map ? this.map.painter : null);
this._source.fire(new performance.Event('data', {
dataType: 'source',
tile: tile,
coord: tile.tileID
}));
};
SourceCache.prototype._backfillDEM = function _backfillDEM(tile) {
var renderables = this.getRenderableIds();
for (var i = 0; i < renderables.length; i++) {
var borderId = renderables[i];
if (tile.neighboringTiles && tile.neighboringTiles[borderId]) {
var borderTile = this.getTileByID(borderId);
fillBorder(tile, borderTile);
fillBorder(borderTile, tile);
}
}
function fillBorder(tile, borderTile) {
tile.needsHillshadePrepare = true;
var dx = borderTile.tileID.canonical.x - tile.tileID.canonical.x;
var dy = borderTile.tileID.canonical.y - tile.tileID.canonical.y;
var dim = Math.pow(2, tile.tileID.canonical.z);
var borderId = borderTile.tileID.key;
if (dx === 0 && dy === 0) {
return;
}
if (Math.abs(dy) > 1) {
return;
}
if (Math.abs(dx) > 1) {
if (Math.abs(dx + dim) === 1) {
dx += dim;
} else if (Math.abs(dx - dim) === 1) {
dx -= dim;
}
}
if (!borderTile.dem || !tile.dem) {
return;
}
tile.dem.backfillBorder(borderTile.dem, dx, dy);
if (tile.neighboringTiles && tile.neighboringTiles[borderId]) {
tile.neighboringTiles[borderId].backfilled = true;
}
}
};
SourceCache.prototype.getTile = function getTile(tileID) {
return this.getTileByID(tileID.key);
};
SourceCache.prototype.getTileByID = function getTileByID(id) {
return this._tiles[id];
};
SourceCache.prototype._retainLoadedChildren = function _retainLoadedChildren(idealTiles, zoom, maxCoveringZoom, retain) {
for (var id in this._tiles) {
var tile = this._tiles[id];
if (retain[id] || !tile.hasData() || tile.tileID.overscaledZ <= zoom || tile.tileID.overscaledZ > maxCoveringZoom) {
continue;
}
var topmostLoadedID = tile.tileID;
while (tile && tile.tileID.overscaledZ > zoom + 1) {
var parentID = tile.tileID.scaledTo(tile.tileID.overscaledZ - 1);
tile = this._tiles[parentID.key];
if (tile && tile.hasData()) {
topmostLoadedID = parentID;
}
}
var tileID = topmostLoadedID;
while (tileID.overscaledZ > zoom) {
tileID = tileID.scaledTo(tileID.overscaledZ - 1);
if (idealTiles[tileID.key]) {
retain[topmostLoadedID.key] = topmostLoadedID;
break;
}
}
}
};
SourceCache.prototype.findLoadedParent = function findLoadedParent(tileID, minCoveringZoom) {
if (tileID.key in this._loadedParentTiles) {
var parent = this._loadedParentTiles[tileID.key];
if (parent && parent.tileID.overscaledZ >= minCoveringZoom) {
return parent;
} else {
return null;
}
}
for (var z = tileID.overscaledZ - 1; z >= minCoveringZoom; z--) {
var parentTileID = tileID.scaledTo(z);
var tile = this._getLoadedTile(parentTileID);
if (tile) {
return tile;
}
}
};
SourceCache.prototype._getLoadedTile = function _getLoadedTile(tileID) {
var tile = this._tiles[tileID.key];
if (tile && tile.hasData()) {
return tile;
}
var cachedTile = this._cache.getByKey(tileID.wrapped().key);
return cachedTile;
};
SourceCache.prototype.updateCacheSize = function updateCacheSize(transform) {
var widthInTiles = Math.ceil(transform.width / this._source.tileSize) + 1;
var heightInTiles = Math.ceil(transform.height / this._source.tileSize) + 1;
var approxTilesInView = widthInTiles * heightInTiles;
var commonZoomRange = 5;
var viewDependentMaxSize = Math.floor(approxTilesInView * commonZoomRange);
var maxSize = typeof this._maxTileCacheSize === 'number' ? Math.min(this._maxTileCacheSize, viewDependentMaxSize) : viewDependentMaxSize;
this._cache.setMaxSize(maxSize);
};
SourceCache.prototype.handleWrapJump = function handleWrapJump(lng) {
var prevLng = this._prevLng === undefined ? lng : this._prevLng;
var lngDifference = lng - prevLng;
var worldDifference = lngDifference / 360;
var wrapDelta = Math.round(worldDifference);
this._prevLng = lng;
if (wrapDelta) {
var tiles = {};
for (var key in this._tiles) {
var tile = this._tiles[key];
tile.tileID = tile.tileID.unwrapTo(tile.tileID.wrap + wrapDelta);
tiles[tile.tileID.key] = tile;
}
this._tiles = tiles;
for (var id in this._timers) {
clearTimeout(this._timers[id]);
delete this._timers[id];
}
for (var id$1 in this._tiles) {
var tile$1 = this._tiles[id$1];
this._setTileReloadTimer(id$1, tile$1);
}
}
};
SourceCache.prototype.update = function update(transform) {
var this$1 = this;
this.transform = transform;
if (!this._sourceLoaded || this._paused) {
return;
}
this.updateCacheSize(transform);
this.handleWrapJump(this.transform.center.lng);
this._coveredTiles = {};
var idealTileIDs;
if (!this.used) {
idealTileIDs = [];
} else if (this._source.tileID) {
idealTileIDs = transform.getVisibleUnwrappedCoordinates(this._source.tileID).map(function (unwrapped) {
return new performance.OverscaledTileID(unwrapped.canonical.z, unwrapped.wrap, unwrapped.canonical.z, unwrapped.canonical.x, unwrapped.canonical.y);
});
} else {
idealTileIDs = transform.coveringTiles({
tileSize: this._source.tileSize,
minzoom: this._source.minzoom,
maxzoom: this._source.maxzoom,
roundZoom: this._source.roundZoom,
reparseOverscaled: this._source.reparseOverscaled
});
if (this._source.hasTile) {
idealTileIDs = idealTileIDs.filter(function (coord) {
return this$1._source.hasTile(coord);
});
}
}
var zoom = transform.coveringZoomLevel(this._source);
var minCoveringZoom = Math.max(zoom - SourceCache.maxOverzooming, this._source.minzoom);
var maxCoveringZoom = Math.max(zoom + SourceCache.maxUnderzooming, this._source.minzoom);
var retain = this._updateRetainedTiles(idealTileIDs, zoom);
if (isRasterType(this._source.type)) {
var parentsForFading = {};
var fadingTiles = {};
var ids = Object.keys(retain);
for (var i = 0, list = ids; i < list.length; i += 1) {
var id = list[i];
var tileID = retain[id];
var tile = this._tiles[id];
if (!tile || tile.fadeEndTime && tile.fadeEndTime <= performance.browser.now()) {
continue;
}
var parentTile = this.findLoadedParent(tileID, minCoveringZoom);
if (parentTile) {
this._addTile(parentTile.tileID);
parentsForFading[parentTile.tileID.key] = parentTile.tileID;
}
fadingTiles[id] = tileID;
}
this._retainLoadedChildren(fadingTiles, zoom, maxCoveringZoom, retain);
for (var id$1 in parentsForFading) {
if (!retain[id$1]) {
this._coveredTiles[id$1] = true;
retain[id$1] = parentsForFading[id$1];
}
}
}
for (var retainedId in retain) {
this._tiles[retainedId].clearFadeHold();
}
var remove = performance.keysDifference(this._tiles, retain);
for (var i$1 = 0, list$1 = remove; i$1 < list$1.length; i$1 += 1) {
var tileID$1 = list$1[i$1];
var tile$1 = this._tiles[tileID$1];
if (tile$1.hasSymbolBuckets && !tile$1.holdingForFade()) {
tile$1.setHoldDuration(this.map._fadeDuration);
} else if (!tile$1.hasSymbolBuckets || tile$1.symbolFadeFinished()) {
this._removeTile(tileID$1);
}
}
this._updateLoadedParentTileCache();
};
SourceCache.prototype.releaseSymbolFadeTiles = function releaseSymbolFadeTiles() {
for (var id in this._tiles) {
if (this._tiles[id].holdingForFade()) {
this._removeTile(id);
}
}
};
SourceCache.prototype._updateRetainedTiles = function _updateRetainedTiles(idealTileIDs, zoom) {
var retain = {};
var checked = {};
var minCoveringZoom = Math.max(zoom - SourceCache.maxOverzooming, this._source.minzoom);
var maxCoveringZoom = Math.max(zoom + SourceCache.maxUnderzooming, this._source.minzoom);
var missingTiles = {};
for (var i = 0, list = idealTileIDs; i < list.length; i += 1) {
var tileID = list[i];
var tile = this._addTile(tileID);
retain[tileID.key] = tileID;
if (tile.hasData()) {
continue;
}
if (zoom < this._source.maxzoom) {
missingTiles[tileID.key] = tileID;
}
}
this._retainLoadedChildren(missingTiles, zoom, maxCoveringZoom, retain);
for (var i$1 = 0, list$1 = idealTileIDs; i$1 < list$1.length; i$1 += 1) {
var tileID$1 = list$1[i$1];
var tile$1 = this._tiles[tileID$1.key];
if (tile$1.hasData()) {
continue;
}
if (zoom + 1 > this._source.maxzoom) {
var childCoord = tileID$1.children(this._source.maxzoom)[0];
var childTile = this.getTile(childCoord);
if (!!childTile && childTile.hasData()) {
retain[childCoord.key] = childCoord;
continue;
}
} else {
var children = tileID$1.children(this._source.maxzoom);
if (retain[children[0].key] && retain[children[1].key] && retain[children[2].key] && retain[children[3].key]) {
continue;
}
}
var parentWasRequested = tile$1.wasRequested();
for (var overscaledZ = tileID$1.overscaledZ - 1; overscaledZ >= minCoveringZoom; --overscaledZ) {
var parentId = tileID$1.scaledTo(overscaledZ);
if (checked[parentId.key]) {
break;
}
checked[parentId.key] = true;
tile$1 = this.getTile(parentId);
if (!tile$1 && parentWasRequested) {
tile$1 = this._addTile(parentId);
}
if (tile$1) {
retain[parentId.key] = parentId;
parentWasRequested = tile$1.wasRequested();
if (tile$1.hasData()) {
break;
}
}
}
}
return retain;
};
SourceCache.prototype._updateLoadedParentTileCache = function _updateLoadedParentTileCache() {
this._loadedParentTiles = {};
for (var tileKey in this._tiles) {
var path = [];
var parentTile = void 0;
var currentId = this._tiles[tileKey].tileID;
while (currentId.overscaledZ > 0) {
if (currentId.key in this._loadedParentTiles) {
parentTile = this._loadedParentTiles[currentId.key];
break;
}
path.push(currentId.key);
var parentId = currentId.scaledTo(currentId.overscaledZ - 1);
parentTile = this._getLoadedTile(parentId);
if (parentTile) {
break;
}
currentId = parentId;
}
for (var i = 0, list = path; i < list.length; i += 1) {
var key = list[i];
this._loadedParentTiles[key] = parentTile;
}
}
};
SourceCache.prototype._addTile = function _addTile(tileID) {
var tile = this._tiles[tileID.key];
if (tile) {
return tile;
}
tile = this._cache.getAndRemove(tileID);
if (tile) {
this._setTileReloadTimer(tileID.key, tile);
tile.tileID = tileID;
this._state.initializeTileState(tile, this.map ? this.map.painter : null);
if (this._cacheTimers[tileID.key]) {
clearTimeout(this._cacheTimers[tileID.key]);
delete this._cacheTimers[tileID.key];
this._setTileReloadTimer(tileID.key, tile);
}
}
var cached = Boolean(tile);
if (!cached) {
tile = new performance.Tile(tileID, this._source.tileSize * tileID.overscaleFactor());
this._loadTile(tile, this._tileLoaded.bind(this, tile, tileID.key, tile.state));
}
if (!tile) {
return null;
}
tile.uses++;
this._tiles[tileID.key] = tile;
if (!cached) {
this._source.fire(new performance.Event('dataloading', {
tile: tile,
coord: tile.tileID,
dataType: 'source'
}));
}
return tile;
};
SourceCache.prototype._setTileReloadTimer = function _setTileReloadTimer(id, tile) {
var this$1 = this;
if (id in this._timers) {
clearTimeout(this._timers[id]);
delete this._timers[id];
}
var expiryTimeout = tile.getExpiryTimeout();
if (expiryTimeout) {
this._timers[id] = setTimeout(function () {
this$1._reloadTile(id, 'expired');
delete this$1._timers[id];
}, expiryTimeout);
}
};
SourceCache.prototype._removeTile = function _removeTile(id) {
var tile = this._tiles[id];
if (!tile) {
return;
}
tile.uses--;
delete this._tiles[id];
if (this._timers[id]) {
clearTimeout(this._timers[id]);
delete this._timers[id];
}
if (tile.uses > 0) {
return;
}
if (tile.hasData() && tile.state !== 'reloading') {
this._cache.add(tile.tileID, tile, tile.getExpiryTimeout());
} else {
tile.aborted = true;
this._abortTile(tile);
this._unloadTile(tile);
}
};
SourceCache.prototype.clearTiles = function clearTiles() {
this._shouldReloadOnResume = false;
this._paused = false;
for (var id in this._tiles) {
this._removeTile(id);
}
this._cache.reset();
};
SourceCache.prototype.tilesIn = function tilesIn(pointQueryGeometry, maxPitchScaleFactor, has3DLayer) {
var this$1 = this;
var tileResults = [];
var transform = this.transform;
if (!transform) {
return tileResults;
}
var cameraPointQueryGeometry = has3DLayer ? transform.getCameraQueryGeometry(pointQueryGeometry) : pointQueryGeometry;
var queryGeometry = pointQueryGeometry.map(function (p) {
return transform.pointCoordinate(p);
});
var cameraQueryGeometry = cameraPointQueryGeometry.map(function (p) {
return transform.pointCoordinate(p);
});
var ids = this.getIds();
var minX = Infinity;
var minY = Infinity;
var maxX = -Infinity;
var maxY = -Infinity;
for (var i$1 = 0, list = cameraQueryGeometry; i$1 < list.length; i$1 += 1) {
var p = list[i$1];
minX = Math.min(minX, p.x);
minY = Math.min(minY, p.y);
maxX = Math.max(maxX, p.x);
maxY = Math.max(maxY, p.y);
}
var loop = function (i) {
var tile = this$1._tiles[ids[i]];
if (tile.holdingForFade()) {
return;
}
var tileID = tile.tileID;
var scale = Math.pow(2, transform.zoom - tile.tileID.overscaledZ);
var queryPadding = maxPitchScaleFactor * tile.queryPadding * performance.EXTENT / tile.tileSize / scale;
var tileSpaceBounds = [
tileID.getTilePoint(new performance.MercatorCoordinate(minX, minY)),
tileID.getTilePoint(new performance.MercatorCoordinate(maxX, maxY))
];
if (tileSpaceBounds[0].x - queryPadding < performance.EXTENT && tileSpaceBounds[0].y - queryPadding < performance.EXTENT && tileSpaceBounds[1].x + queryPadding >= 0 && tileSpaceBounds[1].y + queryPadding >= 0) {
var tileSpaceQueryGeometry = queryGeometry.map(function (c) {
return tileID.getTilePoint(c);
});
var tileSpaceCameraQueryGeometry = cameraQueryGeometry.map(function (c) {
return tileID.getTilePoint(c);
});
tileResults.push({
tile: tile,
tileID: tileID,
queryGeometry: tileSpaceQueryGeometry,
cameraQueryGeometry: tileSpaceCameraQueryGeometry,
scale: scale
});
}
};
for (var i = 0; i < ids.length; i++)
loop(i);
return tileResults;
};
SourceCache.prototype.getVisibleCoordinates = function getVisibleCoordinates(symbolLayer) {
var this$1 = this;
var coords = this.getRenderableIds(symbolLayer).map(function (id) {
return this$1._tiles[id].tileID;
});
for (var i = 0, list = coords; i < list.length; i += 1) {
var coord = list[i];
coord.posMatrix = this.transform.calculatePosMatrix(coord.toUnwrapped());
}
return coords;
};
SourceCache.prototype.hasTransition = function hasTransition() {
if (this._source.hasTransition()) {
return true;
}
if (isRasterType(this._source.type)) {
for (var id in this._tiles) {
var tile = this._tiles[id];
if (tile.fadeEndTime !== undefined && tile.fadeEndTime >= performance.browser.now()) {
return true;
}
}
}
return false;
};
SourceCache.prototype.setFeatureState = function setFeatureState(sourceLayer, featureId, state) {
sourceLayer = sourceLayer || '_geojsonTileLayer';
this._state.updateState(sourceLayer, featureId, state);
};
SourceCache.prototype.removeFeatureState = function removeFeatureState(sourceLayer, featureId, key) {
sourceLayer = sourceLayer || '_geojsonTileLayer';
this._state.removeFeatureState(sourceLayer, featureId, key);
};
SourceCache.prototype.getFeatureState = function getFeatureState(sourceLayer, featureId) {
sourceLayer = sourceLayer || '_geojsonTileLayer';
return this._state.getState(sourceLayer, featureId);
};
SourceCache.prototype.setDependencies = function setDependencies(tileKey, namespace, dependencies) {
var tile = this._tiles[tileKey];
if (tile) {
tile.setDependencies(namespace, dependencies);
}
};
SourceCache.prototype.reloadTilesForDependencies = function reloadTilesForDependencies(namespaces, keys) {
for (var id in this._tiles) {
var tile = this._tiles[id];
if (tile.hasDependency(namespaces, keys)) {
this._reloadTile(id, 'reloading');
}
}
this._cache.filter(function (tile) {
return !tile.hasDependency(namespaces, keys);
});
};
return SourceCache;
}(performance.Evented);
SourceCache.maxOverzooming = 10;
SourceCache.maxUnderzooming = 3;
function compareTileId(a, b) {
var aWrap = Math.abs(a.wrap * 2) - +(a.wrap < 0);
var bWrap = Math.abs(b.wrap * 2) - +(b.wrap < 0);
return a.overscaledZ - b.overscaledZ || bWrap - aWrap || b.canonical.y - a.canonical.y || b.canonical.x - a.canonical.x;
}
function isRasterType(type) {
return type === 'raster' || type === 'image' || type === 'video';
}
function WebWorker () {
return new performance.window.Worker(exported.workerUrl);
}
var PRELOAD_POOL_ID = 'mapboxgl_preloaded_worker_pool';
var WorkerPool = function WorkerPool() {
this.active = {};
};
WorkerPool.prototype.acquire = function acquire(mapId) {
if (!this.workers) {
this.workers = [];
while (this.workers.length < WorkerPool.workerCount) {
this.workers.push(new WebWorker());
}
}
this.active[mapId] = true;
return this.workers.slice();
};
WorkerPool.prototype.release = function release(mapId) {
delete this.active[mapId];
if (this.numActive() === 0) {
this.workers.forEach(function (w) {
w.terminate();
});
this.workers = null;
}
};
WorkerPool.prototype.isPreloaded = function isPreloaded() {
return !!this.active[PRELOAD_POOL_ID];
};
WorkerPool.prototype.numActive = function numActive() {
return Object.keys(this.active).length;
};
var availableLogicalProcessors = Math.floor(performance.browser.hardwareConcurrency / 2);
WorkerPool.workerCount = Math.max(Math.min(availableLogicalProcessors, 6), 1);
var globalWorkerPool;
function getGlobalWorkerPool() {
if (!globalWorkerPool) {
globalWorkerPool = new WorkerPool();
}
return globalWorkerPool;
}
function prewarm() {
var workerPool = getGlobalWorkerPool();
workerPool.acquire(PRELOAD_POOL_ID);
}
function clearPrewarmedResources() {
var pool = globalWorkerPool;
if (pool) {
if (pool.isPreloaded() && pool.numActive() === 1) {
pool.release(PRELOAD_POOL_ID);
globalWorkerPool = null;
} else {
console.warn('Could not clear WebWorkers since there are active Map instances that still reference it. The pre-warmed WebWorker pool can only be cleared when all map instances have been removed with map.remove()');
}
}
}
function deref(layer, parent) {
var result = {};
for (var k in layer) {
if (k !== 'ref') {
result[k] = layer[k];
}
}
performance.refProperties.forEach(function (k) {
if (k in parent) {
result[k] = parent[k];
}
});
return result;
}
function derefLayers(layers) {
layers = layers.slice();
var map = Object.create(null);
for (var i = 0; i < layers.length; i++) {
map[layers[i].id] = layers[i];
}
for (var i$1 = 0; i$1 < layers.length; i$1++) {
if ('ref' in layers[i$1]) {
layers[i$1] = deref(layers[i$1], map[layers[i$1].ref]);
}
}
return layers;
}
function emptyStyle() {
var style = {};
var version = performance.styleSpec['$version'];
for (var styleKey in performance.styleSpec['$root']) {
var spec = performance.styleSpec['$root'][styleKey];
if (spec.required) {
var value = null;
if (styleKey === 'version') {
value = version;
} else {
if (spec.type === 'array') {
value = [];
} else {
value = {};
}
}
if (value != null) {
style[styleKey] = value;
}
}
}
return style;
}
var operations = {
setStyle: 'setStyle',
addLayer: 'addLayer',
removeLayer: 'removeLayer',
setPaintProperty: 'setPaintProperty',
setLayoutProperty: 'setLayoutProperty',
setFilter: 'setFilter',
addSource: 'addSource',
removeSource: 'removeSource',
setGeoJSONSourceData: 'setGeoJSONSourceData',
setLayerZoomRange: 'setLayerZoomRange',
setLayerProperty: 'setLayerProperty',
setCenter: 'setCenter',
setZoom: 'setZoom',
setBearing: 'setBearing',
setPitch: 'setPitch',
setSprite: 'setSprite',
setGlyphs: 'setGlyphs',
setTransition: 'setTransition',
setLight: 'setLight'
};
function addSource(sourceId, after, commands) {
commands.push({
command: operations.addSource,
args: [
sourceId,
after[sourceId]
]
});
}
function removeSource(sourceId, commands, sourcesRemoved) {
commands.push({
command: operations.removeSource,
args: [sourceId]
});
sourcesRemoved[sourceId] = true;
}
function updateSource(sourceId, after, commands, sourcesRemoved) {
removeSource(sourceId, commands, sourcesRemoved);
addSource(sourceId, after, commands);
}
function canUpdateGeoJSON(before, after, sourceId) {
var prop;
for (prop in before[sourceId]) {
if (!before[sourceId].hasOwnProperty(prop)) {
continue;
}
if (prop !== 'data' && !performance.deepEqual(before[sourceId][prop], after[sourceId][prop])) {
return false;
}
}
for (prop in after[sourceId]) {
if (!after[sourceId].hasOwnProperty(prop)) {
continue;
}
if (prop !== 'data' && !performance.deepEqual(before[sourceId][prop], after[sourceId][prop])) {
return false;
}
}
return true;
}
function diffSources(before, after, commands, sourcesRemoved) {
before = before || {};
after = after || {};
var sourceId;
for (sourceId in before) {
if (!before.hasOwnProperty(sourceId)) {
continue;
}
if (!after.hasOwnProperty(sourceId)) {
removeSource(sourceId, commands, sourcesRemoved);
}
}
for (sourceId in after) {
if (!after.hasOwnProperty(sourceId)) {
continue;
}
if (!before.hasOwnProperty(sourceId)) {
addSource(sourceId, after, commands);
} else if (!performance.deepEqual(before[sourceId], after[sourceId])) {
if (before[sourceId].type === 'geojson' && after[sourceId].type === 'geojson' && canUpdateGeoJSON(before, after, sourceId)) {
commands.push({
command: operations.setGeoJSONSourceData,
args: [
sourceId,
after[sourceId].data
]
});
} else {
updateSource(sourceId, after, commands, sourcesRemoved);
}
}
}
}
function diffLayerPropertyChanges(before, after, commands, layerId, klass, command) {
before = before || {};
after = after || {};
var prop;
for (prop in before) {
if (!before.hasOwnProperty(prop)) {
continue;
}
if (!performance.deepEqual(before[prop], after[prop])) {
commands.push({
command: command,
args: [
layerId,
prop,
after[prop],
klass
]
});
}
}
for (prop in after) {
if (!after.hasOwnProperty(prop) || before.hasOwnProperty(prop)) {
continue;
}
if (!performance.deepEqual(before[prop], after[prop])) {
commands.push({
command: command,
args: [
layerId,
prop,
after[prop],
klass
]
});
}
}
}
function pluckId(layer) {
return layer.id;
}
function indexById(group, layer) {
group[layer.id] = layer;
return group;
}
function diffLayers(before, after, commands) {
before = before || [];
after = after || [];
var beforeOrder = before.map(pluckId);
var afterOrder = after.map(pluckId);
var beforeIndex = before.reduce(indexById, {});
var afterIndex = after.reduce(indexById, {});
var tracker = beforeOrder.slice();
var clean = Object.create(null);
var i, d, layerId, beforeLayer, afterLayer, insertBeforeLayerId, prop;
for (i = 0, d = 0; i < beforeOrder.length; i++) {
layerId = beforeOrder[i];
if (!afterIndex.hasOwnProperty(layerId)) {
commands.push({
command: operations.removeLayer,
args: [layerId]
});
tracker.splice(tracker.indexOf(layerId, d), 1);
} else {
d++;
}
}
for (i = 0, d = 0; i < afterOrder.length; i++) {
layerId = afterOrder[afterOrder.length - 1 - i];
if (tracker[tracker.length - 1 - i] === layerId) {
continue;
}
if (beforeIndex.hasOwnProperty(layerId)) {
commands.push({
command: operations.removeLayer,
args: [layerId]
});
tracker.splice(tracker.lastIndexOf(layerId, tracker.length - d), 1);
} else {
d++;
}
insertBeforeLayerId = tracker[tracker.length - i];
commands.push({
command: operations.addLayer,
args: [
afterIndex[layerId],
insertBeforeLayerId
]
});
tracker.splice(tracker.length - i, 0, layerId);
clean[layerId] = true;
}
for (i = 0; i < afterOrder.length; i++) {
layerId = afterOrder[i];
beforeLayer = beforeIndex[layerId];
afterLayer = afterIndex[layerId];
if (clean[layerId] || performance.deepEqual(beforeLayer, afterLayer)) {
continue;
}
if (!performance.deepEqual(beforeLayer.source, afterLayer.source) || !performance.deepEqual(beforeLayer['source-layer'], afterLayer['source-layer']) || !performance.deepEqual(beforeLayer.type, afterLayer.type)) {
commands.push({
command: operations.removeLayer,
args: [layerId]
});
insertBeforeLayerId = tracker[tracker.lastIndexOf(layerId) + 1];
commands.push({
command: operations.addLayer,
args: [
afterLayer,
insertBeforeLayerId
]
});
continue;
}
diffLayerPropertyChanges(beforeLayer.layout, afterLayer.layout, commands, layerId, null, operations.setLayoutProperty);
diffLayerPropertyChanges(beforeLayer.paint, afterLayer.paint, commands, layerId, null, operations.setPaintProperty);
if (!performance.deepEqual(beforeLayer.filter, afterLayer.filter)) {
commands.push({
command: operations.setFilter,
args: [
layerId,
afterLayer.filter
]
});
}
if (!performance.deepEqual(beforeLayer.minzoom, afterLayer.minzoom) || !performance.deepEqual(beforeLayer.maxzoom, afterLayer.maxzoom)) {
commands.push({
command: operations.setLayerZoomRange,
args: [
layerId,
afterLayer.minzoom,
afterLayer.maxzoom
]
});
}
for (prop in beforeLayer) {
if (!beforeLayer.hasOwnProperty(prop)) {
continue;
}
if (prop === 'layout' || prop === 'paint' || prop === 'filter' || prop === 'metadata' || prop === 'minzoom' || prop === 'maxzoom') {
continue;
}
if (prop.indexOf('paint.') === 0) {
diffLayerPropertyChanges(beforeLayer[prop], afterLayer[prop], commands, layerId, prop.slice(6), operations.setPaintProperty);
} else if (!performance.deepEqual(beforeLayer[prop], afterLayer[prop])) {
commands.push({
command: operations.setLayerProperty,
args: [
layerId,
prop,
afterLayer[prop]
]
});
}
}
for (prop in afterLayer) {
if (!afterLayer.hasOwnProperty(prop) || beforeLayer.hasOwnProperty(prop)) {
continue;
}
if (prop === 'layout' || prop === 'paint' || prop === 'filter' || prop === 'metadata' || prop === 'minzoom' || prop === 'maxzoom') {
continue;
}
if (prop.indexOf('paint.') === 0) {
diffLayerPropertyChanges(beforeLayer[prop], afterLayer[prop], commands, layerId, prop.slice(6), operations.setPaintProperty);
} else if (!performance.deepEqual(beforeLayer[prop], afterLayer[prop])) {
commands.push({
command: operations.setLayerProperty,
args: [
layerId,
prop,
afterLayer[prop]
]
});
}
}
}
}
function diffStyles(before, after) {
if (!before) {
return [{
command: operations.setStyle,
args: [after]
}];
}
var commands = [];
try {
if (!performance.deepEqual(before.version, after.version)) {
return [{
command: operations.setStyle,
args: [after]
}];
}
if (!performance.deepEqual(before.center, after.center)) {
commands.push({
command: operations.setCenter,
args: [after.center]
});
}
if (!performance.deepEqual(before.zoom, after.zoom)) {
commands.push({
command: operations.setZoom,
args: [after.zoom]
});
}
if (!performance.deepEqual(before.bearing, after.bearing)) {
commands.push({
command: operations.setBearing,
args: [after.bearing]
});
}
if (!performance.deepEqual(before.pitch, after.pitch)) {
commands.push({
command: operations.setPitch,
args: [after.pitch]
});
}
if (!performance.deepEqual(before.sprite, after.sprite)) {
commands.push({
command: operations.setSprite,
args: [after.sprite]
});
}
if (!performance.deepEqual(before.glyphs, after.glyphs)) {
commands.push({
command: operations.setGlyphs,
args: [after.glyphs]
});
}
if (!performance.deepEqual(before.transition, after.transition)) {
commands.push({
command: operations.setTransition,
args: [after.transition]
});
}
if (!performance.deepEqual(before.light, after.light)) {
commands.push({
command: operations.setLight,
args: [after.light]
});
}
var sourcesRemoved = {};
var removeOrAddSourceCommands = [];
diffSources(before.sources, after.sources, removeOrAddSourceCommands, sourcesRemoved);
var beforeLayers = [];
if (before.layers) {
before.layers.forEach(function (layer) {
if (sourcesRemoved[layer.source]) {
commands.push({
command: operations.removeLayer,
args: [layer.id]
});
} else {
beforeLayers.push(layer);
}
});
}
commands = commands.concat(removeOrAddSourceCommands);
diffLayers(beforeLayers, after.layers, commands);
} catch (e) {
console.warn('Unable to compute style diff:', e);
commands = [{
command: operations.setStyle,
args: [after]
}];
}
return commands;
}
var PathInterpolator = function PathInterpolator(points_, padding_) {
this.reset(points_, padding_);
};
PathInterpolator.prototype.reset = function reset(points_, padding_) {
this.points = points_ || [];
this._distances = [0];
for (var i = 1; i < this.points.length; i++) {
this._distances[i] = this._distances[i - 1] + this.points[i].dist(this.points[i - 1]);
}
this.length = this._distances[this._distances.length - 1];
this.padding = Math.min(padding_ || 0, this.length * 0.5);
this.paddedLength = this.length - this.padding * 2;
};
PathInterpolator.prototype.lerp = function lerp(t) {
if (this.points.length === 1) {
return this.points[0];
}
t = performance.clamp(t, 0, 1);
var currentIndex = 1;
var distOfCurrentIdx = this._distances[currentIndex];
var distToTarget = t * this.paddedLength + this.padding;
while (distOfCurrentIdx < distToTarget && currentIndex < this._distances.length) {
distOfCurrentIdx = this._distances[++currentIndex];
}
var idxOfPrevPoint = currentIndex - 1;
var distOfPrevIdx = this._distances[idxOfPrevPoint];
var segmentLength = distOfCurrentIdx - distOfPrevIdx;
var segmentT = segmentLength > 0 ? (distToTarget - distOfPrevIdx) / segmentLength : 0;
return this.points[idxOfPrevPoint].mult(1 - segmentT).add(this.points[currentIndex].mult(segmentT));
};
var GridIndex = function GridIndex(width, height, cellSize) {
var boxCells = this.boxCells = [];
var circleCells = this.circleCells = [];
this.xCellCount = Math.ceil(width / cellSize);
this.yCellCount = Math.ceil(height / cellSize);
for (var i = 0; i < this.xCellCount * this.yCellCount; i++) {
boxCells.push([]);
circleCells.push([]);
}
this.circleKeys = [];
this.boxKeys = [];
this.bboxes = [];
this.circles = [];
this.width = width;
this.height = height;
this.xScale = this.xCellCount / width;
this.yScale = this.yCellCount / height;
this.boxUid = 0;
this.circleUid = 0;
};
GridIndex.prototype.keysLength = function keysLength() {
return this.boxKeys.length + this.circleKeys.length;
};
GridIndex.prototype.insert = function insert(key, x1, y1, x2, y2) {
this._forEachCell(x1, y1, x2, y2, this._insertBoxCell, this.boxUid++);
this.boxKeys.push(key);
this.bboxes.push(x1);
this.bboxes.push(y1);
this.bboxes.push(x2);
this.bboxes.push(y2);
};
GridIndex.prototype.insertCircle = function insertCircle(key, x, y, radius) {
this._forEachCell(x - radius, y - radius, x + radius, y + radius, this._insertCircleCell, this.circleUid++);
this.circleKeys.push(key);
this.circles.push(x);
this.circles.push(y);
this.circles.push(radius);
};
GridIndex.prototype._insertBoxCell = function _insertBoxCell(x1, y1, x2, y2, cellIndex, uid) {
this.boxCells[cellIndex].push(uid);
};
GridIndex.prototype._insertCircleCell = function _insertCircleCell(x1, y1, x2, y2, cellIndex, uid) {
this.circleCells[cellIndex].push(uid);
};
GridIndex.prototype._query = function _query(x1, y1, x2, y2, hitTest, predicate) {
if (x2 < 0 || x1 > this.width || y2 < 0 || y1 > this.height) {
return hitTest ? false : [];
}
var result = [];
if (x1 <= 0 && y1 <= 0 && this.width <= x2 && this.height <= y2) {
if (hitTest) {
return true;
}
for (var boxUid = 0; boxUid < this.boxKeys.length; boxUid++) {
result.push({
key: this.boxKeys[boxUid],
x1: this.bboxes[boxUid * 4],
y1: this.bboxes[boxUid * 4 + 1],
x2: this.bboxes[boxUid * 4 + 2],
y2: this.bboxes[boxUid * 4 + 3]
});
}
for (var circleUid = 0; circleUid < this.circleKeys.length; circleUid++) {
var x = this.circles[circleUid * 3];
var y = this.circles[circleUid * 3 + 1];
var radius = this.circles[circleUid * 3 + 2];
result.push({
key: this.circleKeys[circleUid],
x1: x - radius,
y1: y - radius,
x2: x + radius,
y2: y + radius
});
}
return predicate ? result.filter(predicate) : result;
} else {
var queryArgs = {
hitTest: hitTest,
seenUids: {
box: {},
circle: {}
}
};
this._forEachCell(x1, y1, x2, y2, this._queryCell, result, queryArgs, predicate);
return hitTest ? result.length > 0 : result;
}
};
GridIndex.prototype._queryCircle = function _queryCircle(x, y, radius, hitTest, predicate) {
var x1 = x - radius;
var x2 = x + radius;
var y1 = y - radius;
var y2 = y + radius;
if (x2 < 0 || x1 > this.width || y2 < 0 || y1 > this.height) {
return hitTest ? false : [];
}
var result = [];
var queryArgs = {
hitTest: hitTest,
circle: {
x: x,
y: y,
radius: radius
},
seenUids: {
box: {},
circle: {}
}
};
this._forEachCell(x1, y1, x2, y2, this._queryCellCircle, result, queryArgs, predicate);
return hitTest ? result.length > 0 : result;
};
GridIndex.prototype.query = function query(x1, y1, x2, y2, predicate) {
return this._query(x1, y1, x2, y2, false, predicate);
};
GridIndex.prototype.hitTest = function hitTest(x1, y1, x2, y2, predicate) {
return this._query(x1, y1, x2, y2, true, predicate);
};
GridIndex.prototype.hitTestCircle = function hitTestCircle(x, y, radius, predicate) {
return this._queryCircle(x, y, radius, true, predicate);
};
GridIndex.prototype._queryCell = function _queryCell(x1, y1, x2, y2, cellIndex, result, queryArgs, predicate) {
var seenUids = queryArgs.seenUids;
var boxCell = this.boxCells[cellIndex];
if (boxCell !== null) {
var bboxes = this.bboxes;
for (var i = 0, list = boxCell; i < list.length; i += 1) {
var boxUid = list[i];
if (!seenUids.box[boxUid]) {
seenUids.box[boxUid] = true;
var offset = boxUid * 4;
if (x1 <= bboxes[offset + 2] && y1 <= bboxes[offset + 3] && x2 >= bboxes[offset + 0] && y2 >= bboxes[offset + 1] && (!predicate || predicate(this.boxKeys[boxUid]))) {
if (queryArgs.hitTest) {
result.push(true);
return true;
} else {
result.push({
key: this.boxKeys[boxUid],
x1: bboxes[offset],
y1: bboxes[offset + 1],
x2: bboxes[offset + 2],
y2: bboxes[offset + 3]
});
}
}
}
}
}
var circleCell = this.circleCells[cellIndex];
if (circleCell !== null) {
var circles = this.circles;
for (var i$1 = 0, list$1 = circleCell; i$1 < list$1.length; i$1 += 1) {
var circleUid = list$1[i$1];
if (!seenUids.circle[circleUid]) {
seenUids.circle[circleUid] = true;
var offset$1 = circleUid * 3;
if (this._circleAndRectCollide(circles[offset$1], circles[offset$1 + 1], circles[offset$1 + 2], x1, y1, x2, y2) && (!predicate || predicate(this.circleKeys[circleUid]))) {
if (queryArgs.hitTest) {
result.push(true);
return true;
} else {
var x = circles[offset$1];
var y = circles[offset$1 + 1];
var radius = circles[offset$1 + 2];
result.push({
key: this.circleKeys[circleUid],
x1: x - radius,
y1: y - radius,
x2: x + radius,
y2: y + radius
});
}
}
}
}
}
};
GridIndex.prototype._queryCellCircle = function _queryCellCircle(x1, y1, x2, y2, cellIndex, result, queryArgs, predicate) {
var circle = queryArgs.circle;
var seenUids = queryArgs.seenUids;
var boxCell = this.boxCells[cellIndex];
if (boxCell !== null) {
var bboxes = this.bboxes;
for (var i = 0, list = boxCell; i < list.length; i += 1) {
var boxUid = list[i];
if (!seenUids.box[boxUid]) {
seenUids.box[boxUid] = true;
var offset = boxUid * 4;
if (this._circleAndRectCollide(circle.x, circle.y, circle.radius, bboxes[offset + 0], bboxes[offset + 1], bboxes[offset + 2], bboxes[offset + 3]) && (!predicate || predicate(this.boxKeys[boxUid]))) {
result.push(true);
return true;
}
}
}
}
var circleCell = this.circleCells[cellIndex];
if (circleCell !== null) {
var circles = this.circles;
for (var i$1 = 0, list$1 = circleCell; i$1 < list$1.length; i$1 += 1) {
var circleUid = list$1[i$1];
if (!seenUids.circle[circleUid]) {
seenUids.circle[circleUid] = true;
var offset$1 = circleUid * 3;
if (this._circlesCollide(circles[offset$1], circles[offset$1 + 1], circles[offset$1 + 2], circle.x, circle.y, circle.radius) && (!predicate || predicate(this.circleKeys[circleUid]))) {
result.push(true);
return true;
}
}
}
}
};
GridIndex.prototype._forEachCell = function _forEachCell(x1, y1, x2, y2, fn, arg1, arg2, predicate) {
var cx1 = this._convertToXCellCoord(x1);
var cy1 = this._convertToYCellCoord(y1);
var cx2 = this._convertToXCellCoord(x2);
var cy2 = this._convertToYCellCoord(y2);
for (var x = cx1; x <= cx2; x++) {
for (var y = cy1; y <= cy2; y++) {
var cellIndex = this.xCellCount * y + x;
if (fn.call(this, x1, y1, x2, y2, cellIndex, arg1, arg2, predicate)) {
return;
}
}
}
};
GridIndex.prototype._convertToXCellCoord = function _convertToXCellCoord(x) {
return Math.max(0, Math.min(this.xCellCount - 1, Math.floor(x * this.xScale)));
};
GridIndex.prototype._convertToYCellCoord = function _convertToYCellCoord(y) {
return Math.max(0, Math.min(this.yCellCount - 1, Math.floor(y * this.yScale)));
};
GridIndex.prototype._circlesCollide = function _circlesCollide(x1, y1, r1, x2, y2, r2) {
var dx = x2 - x1;
var dy = y2 - y1;
var bothRadii = r1 + r2;
return bothRadii * bothRadii > dx * dx + dy * dy;
};
GridIndex.prototype._circleAndRectCollide = function _circleAndRectCollide(circleX, circleY, radius, x1, y1, x2, y2) {
var halfRectWidth = (x2 - x1) / 2;
var distX = Math.abs(circleX - (x1 + halfRectWidth));
if (distX > halfRectWidth + radius) {
return false;
}
var halfRectHeight = (y2 - y1) / 2;
var distY = Math.abs(circleY - (y1 + halfRectHeight));
if (distY > halfRectHeight + radius) {
return false;
}
if (distX <= halfRectWidth || distY <= halfRectHeight) {
return true;
}
var dx = distX - halfRectWidth;
var dy = distY - halfRectHeight;
return dx * dx + dy * dy <= radius * radius;
};
function getLabelPlaneMatrix(posMatrix, pitchWithMap, rotateWithMap, transform, pixelsToTileUnits) {
var m = performance.create();
if (pitchWithMap) {
performance.scale(m, m, [
1 / pixelsToTileUnits,
1 / pixelsToTileUnits,
1
]);
if (!rotateWithMap) {
performance.rotateZ(m, m, transform.angle);
}
} else {
performance.multiply(m, transform.labelPlaneMatrix, posMatrix);
}
return m;
}
function getGlCoordMatrix(posMatrix, pitchWithMap, rotateWithMap, transform, pixelsToTileUnits) {
if (pitchWithMap) {
var m = performance.clone(posMatrix);
performance.scale(m, m, [
pixelsToTileUnits,
pixelsToTileUnits,
1
]);
if (!rotateWithMap) {
performance.rotateZ(m, m, -transform.angle);
}
return m;
} else {
return transform.glCoordMatrix;
}
}
function project(point, matrix) {
var pos = [
point.x,
point.y,
0,
1
];
xyTransformMat4(pos, pos, matrix);
var w = pos[3];
return {
point: new performance.Point(pos[0] / w, pos[1] / w),
signedDistanceFromCamera: w
};
}
function getPerspectiveRatio(cameraToCenterDistance, signedDistanceFromCamera) {
return 0.5 + 0.5 * (cameraToCenterDistance / signedDistanceFromCamera);
}
function isVisible(anchorPos, clippingBuffer) {
var x = anchorPos[0] / anchorPos[3];
var y = anchorPos[1] / anchorPos[3];
var inPaddedViewport = x >= -clippingBuffer[0] && x <= clippingBuffer[0] && y >= -clippingBuffer[1] && y <= clippingBuffer[1];
return inPaddedViewport;
}
function updateLineLabels(bucket, posMatrix, painter, isText, labelPlaneMatrix, glCoordMatrix, pitchWithMap, keepUpright) {
var sizeData = isText ? bucket.textSizeData : bucket.iconSizeData;
var partiallyEvaluatedSize = performance.evaluateSizeForZoom(sizeData, painter.transform.zoom);
var clippingBuffer = [
256 / painter.width * 2 + 1,
256 / painter.height * 2 + 1
];
var dynamicLayoutVertexArray = isText ? bucket.text.dynamicLayoutVertexArray : bucket.icon.dynamicLayoutVertexArray;
dynamicLayoutVertexArray.clear();
var lineVertexArray = bucket.lineVertexArray;
var placedSymbols = isText ? bucket.text.placedSymbolArray : bucket.icon.placedSymbolArray;
var aspectRatio = painter.transform.width / painter.transform.height;
var useVertical = false;
for (var s = 0; s < placedSymbols.length; s++) {
var symbol = placedSymbols.get(s);
if (symbol.hidden || symbol.writingMode === performance.WritingMode.vertical && !useVertical) {
hideGlyphs(symbol.numGlyphs, dynamicLayoutVertexArray);
continue;
}
useVertical = false;
var anchorPos = [
symbol.anchorX,
symbol.anchorY,
0,
1
];
performance.transformMat4(anchorPos, anchorPos, posMatrix);
if (!isVisible(anchorPos, clippingBuffer)) {
hideGlyphs(symbol.numGlyphs, dynamicLayoutVertexArray);
continue;
}
var cameraToAnchorDistance = anchorPos[3];
var perspectiveRatio = getPerspectiveRatio(painter.transform.cameraToCenterDistance, cameraToAnchorDistance);
var fontSize = performance.evaluateSizeForFeature(sizeData, partiallyEvaluatedSize, symbol);
var pitchScaledFontSize = pitchWithMap ? fontSize / perspectiveRatio : fontSize * perspectiveRatio;
var tileAnchorPoint = new performance.Point(symbol.anchorX, symbol.anchorY);
var anchorPoint = project(tileAnchorPoint, labelPlaneMatrix).point;
var projectionCache = {};
var placeUnflipped = placeGlyphsAlongLine(symbol, pitchScaledFontSize, false, keepUpright, posMatrix, labelPlaneMatrix, glCoordMatrix, bucket.glyphOffsetArray, lineVertexArray, dynamicLayoutVertexArray, anchorPoint, tileAnchorPoint, projectionCache, aspectRatio);
useVertical = placeUnflipped.useVertical;
if (placeUnflipped.notEnoughRoom || useVertical || placeUnflipped.needsFlipping && placeGlyphsAlongLine(symbol, pitchScaledFontSize, true, keepUpright, posMatrix, labelPlaneMatrix, glCoordMatrix, bucket.glyphOffsetArray, lineVertexArray, dynamicLayoutVertexArray, anchorPoint, tileAnchorPoint, projectionCache, aspectRatio).notEnoughRoom) {
hideGlyphs(symbol.numGlyphs, dynamicLayoutVertexArray);
}
}
if (isText) {
bucket.text.dynamicLayoutVertexBuffer.updateData(dynamicLayoutVertexArray);
} else {
bucket.icon.dynamicLayoutVertexBuffer.updateData(dynamicLayoutVertexArray);
}
}
function placeFirstAndLastGlyph(fontScale, glyphOffsetArray, lineOffsetX, lineOffsetY, flip, anchorPoint, tileAnchorPoint, symbol, lineVertexArray, labelPlaneMatrix, projectionCache) {
var glyphEndIndex = symbol.glyphStartIndex + symbol.numGlyphs;
var lineStartIndex = symbol.lineStartIndex;
var lineEndIndex = symbol.lineStartIndex + symbol.lineLength;
var firstGlyphOffset = glyphOffsetArray.getoffsetX(symbol.glyphStartIndex);
var lastGlyphOffset = glyphOffsetArray.getoffsetX(glyphEndIndex - 1);
var firstPlacedGlyph = placeGlyphAlongLine(fontScale * firstGlyphOffset, lineOffsetX, lineOffsetY, flip, anchorPoint, tileAnchorPoint, symbol.segment, lineStartIndex, lineEndIndex, lineVertexArray, labelPlaneMatrix, projectionCache);
if (!firstPlacedGlyph) {
return null;
}
var lastPlacedGlyph = placeGlyphAlongLine(fontScale * lastGlyphOffset, lineOffsetX, lineOffsetY, flip, anchorPoint, tileAnchorPoint, symbol.segment, lineStartIndex, lineEndIndex, lineVertexArray, labelPlaneMatrix, projectionCache);
if (!lastPlacedGlyph) {
return null;
}
return {
first: firstPlacedGlyph,
last: lastPlacedGlyph
};
}
function requiresOrientationChange(writingMode, firstPoint, lastPoint, aspectRatio) {
if (writingMode === performance.WritingMode.horizontal) {
var rise = Math.abs(lastPoint.y - firstPoint.y);
var run = Math.abs(lastPoint.x - firstPoint.x) * aspectRatio;
if (rise > run) {
return { useVertical: true };
}
}
if (writingMode === performance.WritingMode.vertical ? firstPoint.y < lastPoint.y : firstPoint.x > lastPoint.x) {
return { needsFlipping: true };
}
return null;
}
function placeGlyphsAlongLine(symbol, fontSize, flip, keepUpright, posMatrix, labelPlaneMatrix, glCoordMatrix, glyphOffsetArray, lineVertexArray, dynamicLayoutVertexArray, anchorPoint, tileAnchorPoint, projectionCache, aspectRatio) {
var fontScale = fontSize / 24;
var lineOffsetX = symbol.lineOffsetX * fontScale;
var lineOffsetY = symbol.lineOffsetY * fontScale;
var placedGlyphs;
if (symbol.numGlyphs > 1) {
var glyphEndIndex = symbol.glyphStartIndex + symbol.numGlyphs;
var lineStartIndex = symbol.lineStartIndex;
var lineEndIndex = symbol.lineStartIndex + symbol.lineLength;
var firstAndLastGlyph = placeFirstAndLastGlyph(fontScale, glyphOffsetArray, lineOffsetX, lineOffsetY, flip, anchorPoint, tileAnchorPoint, symbol, lineVertexArray, labelPlaneMatrix, projectionCache);
if (!firstAndLastGlyph) {
return { notEnoughRoom: true };
}
var firstPoint = project(firstAndLastGlyph.first.point, glCoordMatrix).point;
var lastPoint = project(firstAndLastGlyph.last.point, glCoordMatrix).point;
if (keepUpright && !flip) {
var orientationChange = requiresOrientationChange(symbol.writingMode, firstPoint, lastPoint, aspectRatio);
if (orientationChange) {
return orientationChange;
}
}
placedGlyphs = [firstAndLastGlyph.first];
for (var glyphIndex = symbol.glyphStartIndex + 1; glyphIndex < glyphEndIndex - 1; glyphIndex++) {
placedGlyphs.push(placeGlyphAlongLine(fontScale * glyphOffsetArray.getoffsetX(glyphIndex), lineOffsetX, lineOffsetY, flip, anchorPoint, tileAnchorPoint, symbol.segment, lineStartIndex, lineEndIndex, lineVertexArray, labelPlaneMatrix, projectionCache));
}
placedGlyphs.push(firstAndLastGlyph.last);
} else {
if (keepUpright && !flip) {
var a = project(tileAnchorPoint, posMatrix).point;
var tileVertexIndex = symbol.lineStartIndex + symbol.segment + 1;
var tileSegmentEnd = new performance.Point(lineVertexArray.getx(tileVertexIndex), lineVertexArray.gety(tileVertexIndex));
var projectedVertex = project(tileSegmentEnd, posMatrix);
var b = projectedVertex.signedDistanceFromCamera > 0 ? projectedVertex.point : projectTruncatedLineSegment(tileAnchorPoint, tileSegmentEnd, a, 1, posMatrix);
var orientationChange$1 = requiresOrientationChange(symbol.writingMode, a, b, aspectRatio);
if (orientationChange$1) {
return orientationChange$1;
}
}
var singleGlyph = placeGlyphAlongLine(fontScale * glyphOffsetArray.getoffsetX(symbol.glyphStartIndex), lineOffsetX, lineOffsetY, flip, anchorPoint, tileAnchorPoint, symbol.segment, symbol.lineStartIndex, symbol.lineStartIndex + symbol.lineLength, lineVertexArray, labelPlaneMatrix, projectionCache);
if (!singleGlyph) {
return { notEnoughRoom: true };
}
placedGlyphs = [singleGlyph];
}
for (var i = 0, list = placedGlyphs; i < list.length; i += 1) {
var glyph = list[i];
performance.addDynamicAttributes(dynamicLayoutVertexArray, glyph.point, glyph.angle);
}
return {};
}
function projectTruncatedLineSegment(previousTilePoint, currentTilePoint, previousProjectedPoint, minimumLength, projectionMatrix) {
var projectedUnitVertex = project(previousTilePoint.add(previousTilePoint.sub(currentTilePoint)._unit()), projectionMatrix).point;
var projectedUnitSegment = previousProjectedPoint.sub(projectedUnitVertex);
return previousProjectedPoint.add(projectedUnitSegment._mult(minimumLength / projectedUnitSegment.mag()));
}
function placeGlyphAlongLine(offsetX, lineOffsetX, lineOffsetY, flip, anchorPoint, tileAnchorPoint, anchorSegment, lineStartIndex, lineEndIndex, lineVertexArray, labelPlaneMatrix, projectionCache) {
var combinedOffsetX = flip ? offsetX - lineOffsetX : offsetX + lineOffsetX;
var dir = combinedOffsetX > 0 ? 1 : -1;
var angle = 0;
if (flip) {
dir *= -1;
angle = Math.PI;
}
if (dir < 0) {
angle += Math.PI;
}
var currentIndex = dir > 0 ? lineStartIndex + anchorSegment : lineStartIndex + anchorSegment + 1;
var current = anchorPoint;
var prev = anchorPoint;
var distanceToPrev = 0;
var currentSegmentDistance = 0;
var absOffsetX = Math.abs(combinedOffsetX);
var pathVertices = [];
while (distanceToPrev + currentSegmentDistance <= absOffsetX) {
currentIndex += dir;
if (currentIndex < lineStartIndex || currentIndex >= lineEndIndex) {
return null;
}
prev = current;
pathVertices.push(current);
current = projectionCache[currentIndex];
if (current === undefined) {
var currentVertex = new performance.Point(lineVertexArray.getx(currentIndex), lineVertexArray.gety(currentIndex));
var projection = project(currentVertex, labelPlaneMatrix);
if (projection.signedDistanceFromCamera > 0) {
current = projectionCache[currentIndex] = projection.point;
} else {
var previousLineVertexIndex = currentIndex - dir;
var previousTilePoint = distanceToPrev === 0 ? tileAnchorPoint : new performance.Point(lineVertexArray.getx(previousLineVertexIndex), lineVertexArray.gety(previousLineVertexIndex));
current = projectTruncatedLineSegment(previousTilePoint, currentVertex, prev, absOffsetX - distanceToPrev + 1, labelPlaneMatrix);
}
}
distanceToPrev += currentSegmentDistance;
currentSegmentDistance = prev.dist(current);
}
var segmentInterpolationT = (absOffsetX - distanceToPrev) / currentSegmentDistance;
var prevToCurrent = current.sub(prev);
var p = prevToCurrent.mult(segmentInterpolationT)._add(prev);
p._add(prevToCurrent._unit()._perp()._mult(lineOffsetY * dir));
var segmentAngle = angle + Math.atan2(current.y - prev.y, current.x - prev.x);
pathVertices.push(p);
return {
point: p,
angle: segmentAngle,
path: pathVertices
};
}
var hiddenGlyphAttributes = new Float32Array([
-Infinity,
-Infinity,
0,
-Infinity,
-Infinity,
0,
-Infinity,
-Infinity,
0,
-Infinity,
-Infinity,
0
]);
function hideGlyphs(num, dynamicLayoutVertexArray) {
for (var i = 0; i < num; i++) {
var offset = dynamicLayoutVertexArray.length;
dynamicLayoutVertexArray.resize(offset + 4);
dynamicLayoutVertexArray.float32.set(hiddenGlyphAttributes, offset * 3);
}
}
function xyTransformMat4(out, a, m) {
var x = a[0], y = a[1];
out[0] = m[0] * x + m[4] * y + m[12];
out[1] = m[1] * x + m[5] * y + m[13];
out[3] = m[3] * x + m[7] * y + m[15];
return out;
}
var viewportPadding = 100;
var CollisionIndex = function CollisionIndex(transform, grid, ignoredGrid) {
if (grid === void 0)
grid = new GridIndex(transform.width + 2 * viewportPadding, transform.height + 2 * viewportPadding, 25);
if (ignoredGrid === void 0)
ignoredGrid = new GridIndex(transform.width + 2 * viewportPadding, transform.height + 2 * viewportPadding, 25);
this.transform = transform;
this.grid = grid;
this.ignoredGrid = ignoredGrid;
this.pitchfactor = Math.cos(transform._pitch) * transform.cameraToCenterDistance;
this.screenRightBoundary = transform.width + viewportPadding;
this.screenBottomBoundary = transform.height + viewportPadding;
this.gridRightBoundary = transform.width + 2 * viewportPadding;
this.gridBottomBoundary = transform.height + 2 * viewportPadding;
};
CollisionIndex.prototype.placeCollisionBox = function placeCollisionBox(collisionBox, allowOverlap, textPixelRatio, posMatrix, collisionGroupPredicate) {
var projectedPoint = this.projectAndGetPerspectiveRatio(posMatrix, collisionBox.anchorPointX, collisionBox.anchorPointY);
var tileToViewport = textPixelRatio * projectedPoint.perspectiveRatio;
var tlX = collisionBox.x1 * tileToViewport + projectedPoint.point.x;
var tlY = collisionBox.y1 * tileToViewport + projectedPoint.point.y;
var brX = collisionBox.x2 * tileToViewport + projectedPoint.point.x;
var brY = collisionBox.y2 * tileToViewport + projectedPoint.point.y;
if (!this.isInsideGrid(tlX, tlY, brX, brY) || !allowOverlap && this.grid.hitTest(tlX, tlY, brX, brY, collisionGroupPredicate)) {
return {
box: [],
offscreen: false
};
}
return {
box: [
tlX,
tlY,
brX,
brY
],
offscreen: this.isOffscreen(tlX, tlY, brX, brY)
};
};
CollisionIndex.prototype.placeCollisionCircles = function placeCollisionCircles(allowOverlap, symbol, lineVertexArray, glyphOffsetArray, fontSize, posMatrix, labelPlaneMatrix, labelToScreenMatrix, showCollisionCircles, pitchWithMap, collisionGroupPredicate, circlePixelDiameter, textPixelPadding) {
var placedCollisionCircles = [];
var tileUnitAnchorPoint = new performance.Point(symbol.anchorX, symbol.anchorY);
var screenAnchorPoint = project(tileUnitAnchorPoint, posMatrix);
var perspectiveRatio = getPerspectiveRatio(this.transform.cameraToCenterDistance, screenAnchorPoint.signedDistanceFromCamera);
var labelPlaneFontSize = pitchWithMap ? fontSize / perspectiveRatio : fontSize * perspectiveRatio;
var labelPlaneFontScale = labelPlaneFontSize / performance.ONE_EM;
var labelPlaneAnchorPoint = project(tileUnitAnchorPoint, labelPlaneMatrix).point;
var projectionCache = {};
var lineOffsetX = symbol.lineOffsetX * labelPlaneFontScale;
var lineOffsetY = symbol.lineOffsetY * labelPlaneFontScale;
var firstAndLastGlyph = placeFirstAndLastGlyph(labelPlaneFontScale, glyphOffsetArray, lineOffsetX, lineOffsetY, false, labelPlaneAnchorPoint, tileUnitAnchorPoint, symbol, lineVertexArray, labelPlaneMatrix, projectionCache);
var collisionDetected = false;
var inGrid = false;
var entirelyOffscreen = true;
if (firstAndLastGlyph) {
var radius = circlePixelDiameter * 0.5 * perspectiveRatio + textPixelPadding;
var screenPlaneMin = new performance.Point(-viewportPadding, -viewportPadding);
var screenPlaneMax = new performance.Point(this.screenRightBoundary, this.screenBottomBoundary);
var interpolator = new PathInterpolator();
var first = firstAndLastGlyph.first;
var last = firstAndLastGlyph.last;
var projectedPath = [];
for (var i = first.path.length - 1; i >= 1; i--) {
projectedPath.push(first.path[i]);
}
for (var i$1 = 1; i$1 < last.path.length; i$1++) {
projectedPath.push(last.path[i$1]);
}
var circleDist = radius * 2.5;
if (labelToScreenMatrix) {
var screenSpacePath = projectedPath.map(function (p) {
return project(p, labelToScreenMatrix);
});
if (screenSpacePath.some(function (point) {
return point.signedDistanceFromCamera <= 0;
})) {
projectedPath = [];
} else {
projectedPath = screenSpacePath.map(function (p) {
return p.point;
});
}
}
var segments = [];
if (projectedPath.length > 0) {
var minPoint = projectedPath[0].clone();
var maxPoint = projectedPath[0].clone();
for (var i$2 = 1; i$2 < projectedPath.length; i$2++) {
minPoint.x = Math.min(minPoint.x, projectedPath[i$2].x);
minPoint.y = Math.min(minPoint.y, projectedPath[i$2].y);
maxPoint.x = Math.max(maxPoint.x, projectedPath[i$2].x);
maxPoint.y = Math.max(maxPoint.y, projectedPath[i$2].y);
}
if (minPoint.x >= screenPlaneMin.x && maxPoint.x <= screenPlaneMax.x && minPoint.y >= screenPlaneMin.y && maxPoint.y <= screenPlaneMax.y) {
segments = [projectedPath];
} else if (maxPoint.x < screenPlaneMin.x || minPoint.x > screenPlaneMax.x || maxPoint.y < screenPlaneMin.y || minPoint.y > screenPlaneMax.y) {
segments = [];
} else {
segments = performance.clipLine([projectedPath], screenPlaneMin.x, screenPlaneMin.y, screenPlaneMax.x, screenPlaneMax.y);
}
}
for (var i$4 = 0, list = segments; i$4 < list.length; i$4 += 1) {
var seg = list[i$4];
interpolator.reset(seg, radius * 0.25);
var numCircles = 0;
if (interpolator.length <= 0.5 * radius) {
numCircles = 1;
} else {
numCircles = Math.ceil(interpolator.paddedLength / circleDist) + 1;
}
for (var i$3 = 0; i$3 < numCircles; i$3++) {
var t = i$3 / Math.max(numCircles - 1, 1);
var circlePosition = interpolator.lerp(t);
var centerX = circlePosition.x + viewportPadding;
var centerY = circlePosition.y + viewportPadding;
placedCollisionCircles.push(centerX, centerY, radius, 0);
var x1 = centerX - radius;
var y1 = centerY - radius;
var x2 = centerX + radius;
var y2 = centerY + radius;
entirelyOffscreen = entirelyOffscreen && this.isOffscreen(x1, y1, x2, y2);
inGrid = inGrid || this.isInsideGrid(x1, y1, x2, y2);
if (!allowOverlap) {
if (this.grid.hitTestCircle(centerX, centerY, radius, collisionGroupPredicate)) {
collisionDetected = true;
if (!showCollisionCircles) {
return {
circles: [],
offscreen: false,
collisionDetected: collisionDetected
};
}
}
}
}
}
}
return {
circles: !showCollisionCircles && collisionDetected || !inGrid ? [] : placedCollisionCircles,
offscreen: entirelyOffscreen,
collisionDetected: collisionDetected
};
};
CollisionIndex.prototype.queryRenderedSymbols = function queryRenderedSymbols(viewportQueryGeometry) {
if (viewportQueryGeometry.length === 0 || this.grid.keysLength() === 0 && this.ignoredGrid.keysLength() === 0) {
return {};
}
var query = [];
var minX = Infinity;
var minY = Infinity;
var maxX = -Infinity;
var maxY = -Infinity;
for (var i = 0, list = viewportQueryGeometry; i < list.length; i += 1) {
var point = list[i];
var gridPoint = new performance.Point(point.x + viewportPadding, point.y + viewportPadding);
minX = Math.min(minX, gridPoint.x);
minY = Math.min(minY, gridPoint.y);
maxX = Math.max(maxX, gridPoint.x);
maxY = Math.max(maxY, gridPoint.y);
query.push(gridPoint);
}
var features = this.grid.query(minX, minY, maxX, maxY).concat(this.ignoredGrid.query(minX, minY, maxX, maxY));
var seenFeatures = {};
var result = {};
for (var i$1 = 0, list$1 = features; i$1 < list$1.length; i$1 += 1) {
var feature = list$1[i$1];
var featureKey = feature.key;
if (seenFeatures[featureKey.bucketInstanceId] === undefined) {
seenFeatures[featureKey.bucketInstanceId] = {};
}
if (seenFeatures[featureKey.bucketInstanceId][featureKey.featureIndex]) {
continue;
}
var bbox = [
new performance.Point(feature.x1, feature.y1),
new performance.Point(feature.x2, feature.y1),
new performance.Point(feature.x2, feature.y2),
new performance.Point(feature.x1, feature.y2)
];
if (!performance.polygonIntersectsPolygon(query, bbox)) {
continue;
}
seenFeatures[featureKey.bucketInstanceId][featureKey.featureIndex] = true;
if (result[featureKey.bucketInstanceId] === undefined) {
result[featureKey.bucketInstanceId] = [];
}
result[featureKey.bucketInstanceId].push(featureKey.featureIndex);
}
return result;
};
CollisionIndex.prototype.insertCollisionBox = function insertCollisionBox(collisionBox, ignorePlacement, bucketInstanceId, featureIndex, collisionGroupID) {
var grid = ignorePlacement ? this.ignoredGrid : this.grid;
var key = {
bucketInstanceId: bucketInstanceId,
featureIndex: featureIndex,
collisionGroupID: collisionGroupID
};
grid.insert(key, collisionBox[0], collisionBox[1], collisionBox[2], collisionBox[3]);
};
CollisionIndex.prototype.insertCollisionCircles = function insertCollisionCircles(collisionCircles, ignorePlacement, bucketInstanceId, featureIndex, collisionGroupID) {
var grid = ignorePlacement ? this.ignoredGrid : this.grid;
var key = {
bucketInstanceId: bucketInstanceId,
featureIndex: featureIndex,
collisionGroupID: collisionGroupID
};
for (var k = 0; k < collisionCircles.length; k += 4) {
grid.insertCircle(key, collisionCircles[k], collisionCircles[k + 1], collisionCircles[k + 2]);
}
};
CollisionIndex.prototype.projectAndGetPerspectiveRatio = function projectAndGetPerspectiveRatio(posMatrix, x, y) {
var p = [
x,
y,
0,
1
];
xyTransformMat4(p, p, posMatrix);
var a = new performance.Point((p[0] / p[3] + 1) / 2 * this.transform.width + viewportPadding, (-p[1] / p[3] + 1) / 2 * this.transform.height + viewportPadding);
return {
point: a,
perspectiveRatio: 0.5 + 0.5 * (this.transform.cameraToCenterDistance / p[3])
};
};
CollisionIndex.prototype.isOffscreen = function isOffscreen(x1, y1, x2, y2) {
return x2 < viewportPadding || x1 >= this.screenRightBoundary || y2 < viewportPadding || y1 > this.screenBottomBoundary;
};
CollisionIndex.prototype.isInsideGrid = function isInsideGrid(x1, y1, x2, y2) {
return x2 >= 0 && x1 < this.gridRightBoundary && y2 >= 0 && y1 < this.gridBottomBoundary;
};
CollisionIndex.prototype.getViewportMatrix = function getViewportMatrix() {
var m = performance.identity([]);
performance.translate(m, m, [
-viewportPadding,
-viewportPadding,
0
]);
return m;
};
function pixelsToTileUnits (tile, pixelValue, z) {
return pixelValue * (performance.EXTENT / (tile.tileSize * Math.pow(2, z - tile.tileID.overscaledZ)));
}
var OpacityState = function OpacityState(prevState, increment, placed, skipFade) {
if (prevState) {
this.opacity = Math.max(0, Math.min(1, prevState.opacity + (prevState.placed ? increment : -increment)));
} else {
this.opacity = skipFade && placed ? 1 : 0;
}
this.placed = placed;
};
OpacityState.prototype.isHidden = function isHidden() {
return this.opacity === 0 && !this.placed;
};
var JointOpacityState = function JointOpacityState(prevState, increment, placedText, placedIcon, skipFade) {
this.text = new OpacityState(prevState ? prevState.text : null, increment, placedText, skipFade);
this.icon = new OpacityState(prevState ? prevState.icon : null, increment, placedIcon, skipFade);
};
JointOpacityState.prototype.isHidden = function isHidden() {
return this.text.isHidden() && this.icon.isHidden();
};
var JointPlacement = function JointPlacement(text, icon, skipFade) {
this.text = text;
this.icon = icon;
this.skipFade = skipFade;
};
var CollisionCircleArray = function CollisionCircleArray() {
this.invProjMatrix = performance.create();
this.viewportMatrix = performance.create();
this.circles = [];
};
var RetainedQueryData = function RetainedQueryData(bucketInstanceId, featureIndex, sourceLayerIndex, bucketIndex, tileID) {
this.bucketInstanceId = bucketInstanceId;
this.featureIndex = featureIndex;
this.sourceLayerIndex = sourceLayerIndex;
this.bucketIndex = bucketIndex;
this.tileID = tileID;
};
var CollisionGroups = function CollisionGroups(crossSourceCollisions) {
this.crossSourceCollisions = crossSourceCollisions;
this.maxGroupID = 0;
this.collisionGroups = {};
};
CollisionGroups.prototype.get = function get(sourceID) {
if (!this.crossSourceCollisions) {
if (!this.collisionGroups[sourceID]) {
var nextGroupID = ++this.maxGroupID;
this.collisionGroups[sourceID] = {
ID: nextGroupID,
predicate: function (key) {
return key.collisionGroupID === nextGroupID;
}
};
}
return this.collisionGroups[sourceID];
} else {
return {
ID: 0,
predicate: null
};
}
};
function calculateVariableLayoutShift(anchor, width, height, textOffset, textBoxScale) {
var ref = performance.getAnchorAlignment(anchor);
var horizontalAlign = ref.horizontalAlign;
var verticalAlign = ref.verticalAlign;
var shiftX = -(horizontalAlign - 0.5) * width;
var shiftY = -(verticalAlign - 0.5) * height;
var offset = performance.evaluateVariableOffset(anchor, textOffset);
return new performance.Point(shiftX + offset[0] * textBoxScale, shiftY + offset[1] * textBoxScale);
}
function shiftVariableCollisionBox(collisionBox, shiftX, shiftY, rotateWithMap, pitchWithMap, angle) {
var x1 = collisionBox.x1;
var x2 = collisionBox.x2;
var y1 = collisionBox.y1;
var y2 = collisionBox.y2;
var anchorPointX = collisionBox.anchorPointX;
var anchorPointY = collisionBox.anchorPointY;
var rotatedOffset = new performance.Point(shiftX, shiftY);
if (rotateWithMap) {
rotatedOffset._rotate(pitchWithMap ? angle : -angle);
}
return {
x1: x1 + rotatedOffset.x,
y1: y1 + rotatedOffset.y,
x2: x2 + rotatedOffset.x,
y2: y2 + rotatedOffset.y,
anchorPointX: anchorPointX,
anchorPointY: anchorPointY
};
}
var Placement = function Placement(transform, fadeDuration, crossSourceCollisions, prevPlacement) {
this.transform = transform.clone();
this.collisionIndex = new CollisionIndex(this.transform);
this.placements = {};
this.opacities = {};
this.variableOffsets = {};
this.stale = false;
this.commitTime = 0;
this.fadeDuration = fadeDuration;
this.retainedQueryData = {};
this.collisionGroups = new CollisionGroups(crossSourceCollisions);
this.collisionCircleArrays = {};
this.prevPlacement = prevPlacement;
if (prevPlacement) {
prevPlacement.prevPlacement = undefined;
}
this.placedOrientations = {};
};
Placement.prototype.getBucketParts = function getBucketParts(results, styleLayer, tile, sortAcrossTiles) {
var symbolBucket = tile.getBucket(styleLayer);
var bucketFeatureIndex = tile.latestFeatureIndex;
if (!symbolBucket || !bucketFeatureIndex || styleLayer.id !== symbolBucket.layerIds[0]) {
return;
}
var collisionBoxArray = tile.collisionBoxArray;
var layout = symbolBucket.layers[0].layout;
var scale = Math.pow(2, this.transform.zoom - tile.tileID.overscaledZ);
var textPixelRatio = tile.tileSize / performance.EXTENT;
var posMatrix = this.transform.calculatePosMatrix(tile.tileID.toUnwrapped());
var pitchWithMap = layout.get('text-pitch-alignment') === 'map';
var rotateWithMap = layout.get('text-rotation-alignment') === 'map';
var pixelsToTiles = pixelsToTileUnits(tile, 1, this.transform.zoom);
var textLabelPlaneMatrix = getLabelPlaneMatrix(posMatrix, pitchWithMap, rotateWithMap, this.transform, pixelsToTiles);
var labelToScreenMatrix = null;
if (pitchWithMap) {
var glMatrix = getGlCoordMatrix(posMatrix, pitchWithMap, rotateWithMap, this.transform, pixelsToTiles);
labelToScreenMatrix = performance.multiply([], this.transform.labelPlaneMatrix, glMatrix);
}
this.retainedQueryData[symbolBucket.bucketInstanceId] = new RetainedQueryData(symbolBucket.bucketInstanceId, bucketFeatureIndex, symbolBucket.sourceLayerIndex, symbolBucket.index, tile.tileID);
var parameters = {
bucket: symbolBucket,
layout: layout,
posMatrix: posMatrix,
textLabelPlaneMatrix: textLabelPlaneMatrix,
labelToScreenMatrix: labelToScreenMatrix,
scale: scale,
textPixelRatio: textPixelRatio,
holdingForFade: tile.holdingForFade(),
collisionBoxArray: collisionBoxArray,
partiallyEvaluatedTextSize: performance.evaluateSizeForZoom(symbolBucket.textSizeData, this.transform.zoom),
collisionGroup: this.collisionGroups.get(symbolBucket.sourceID)
};
if (sortAcrossTiles) {
for (var i = 0, list = symbolBucket.sortKeyRanges; i < list.length; i += 1) {
var range = list[i];
var sortKey = range.sortKey;
var symbolInstanceStart = range.symbolInstanceStart;
var symbolInstanceEnd = range.symbolInstanceEnd;
results.push({
sortKey: sortKey,
symbolInstanceStart: symbolInstanceStart,
symbolInstanceEnd: symbolInstanceEnd,
parameters: parameters
});
}
} else {
results.push({
symbolInstanceStart: 0,
symbolInstanceEnd: symbolBucket.symbolInstances.length,
parameters: parameters
});
}
};
Placement.prototype.attemptAnchorPlacement = function attemptAnchorPlacement(anchor, textBox, width, height, textBoxScale, rotateWithMap, pitchWithMap, textPixelRatio, posMatrix, collisionGroup, textAllowOverlap, symbolInstance, bucket, orientation, iconBox) {
var textOffset = [
symbolInstance.textOffset0,
symbolInstance.textOffset1
];
var shift = calculateVariableLayoutShift(anchor, width, height, textOffset, textBoxScale);
var placedGlyphBoxes = this.collisionIndex.placeCollisionBox(shiftVariableCollisionBox(textBox, shift.x, shift.y, rotateWithMap, pitchWithMap, this.transform.angle), textAllowOverlap, textPixelRatio, posMatrix, collisionGroup.predicate);
if (iconBox) {
var placedIconBoxes = this.collisionIndex.placeCollisionBox(shiftVariableCollisionBox(iconBox, shift.x, shift.y, rotateWithMap, pitchWithMap, this.transform.angle), textAllowOverlap, textPixelRatio, posMatrix, collisionGroup.predicate);
if (placedIconBoxes.box.length === 0) {
return;
}
}
if (placedGlyphBoxes.box.length > 0) {
var prevAnchor;
if (this.prevPlacement && this.prevPlacement.variableOffsets[symbolInstance.crossTileID] && this.prevPlacement.placements[symbolInstance.crossTileID] && this.prevPlacement.placements[symbolInstance.crossTileID].text) {
prevAnchor = this.prevPlacement.variableOffsets[symbolInstance.crossTileID].anchor;
}
this.variableOffsets[symbolInstance.crossTileID] = {
textOffset: textOffset,
width: width,
height: height,
anchor: anchor,
textBoxScale: textBoxScale,
prevAnchor: prevAnchor
};
this.markUsedJustification(bucket, anchor, symbolInstance, orientation);
if (bucket.allowVerticalPlacement) {
this.markUsedOrientation(bucket, orientation, symbolInstance);
this.placedOrientations[symbolInstance.crossTileID] = orientation;
}
return {
shift: shift,
placedGlyphBoxes: placedGlyphBoxes
};
}
};
Placement.prototype.placeLayerBucketPart = function placeLayerBucketPart(bucketPart, seenCrossTileIDs, showCollisionBoxes) {
var this$1 = this;
var ref = bucketPart.parameters;
var bucket = ref.bucket;
var layout = ref.layout;
var posMatrix = ref.posMatrix;
var textLabelPlaneMatrix = ref.textLabelPlaneMatrix;
var labelToScreenMatrix = ref.labelToScreenMatrix;
var textPixelRatio = ref.textPixelRatio;
var holdingForFade = ref.holdingForFade;
var collisionBoxArray = ref.collisionBoxArray;
var partiallyEvaluatedTextSize = ref.partiallyEvaluatedTextSize;
var collisionGroup = ref.collisionGroup;
var textOptional = layout.get('text-optional');
var iconOptional = layout.get('icon-optional');
var textAllowOverlap = layout.get('text-allow-overlap');
var iconAllowOverlap = layout.get('icon-allow-overlap');
var rotateWithMap = layout.get('text-rotation-alignment') === 'map';
var pitchWithMap = layout.get('text-pitch-alignment') === 'map';
var hasIconTextFit = layout.get('icon-text-fit') !== 'none';
var zOrderByViewportY = layout.get('symbol-z-order') === 'viewport-y';
var alwaysShowText = textAllowOverlap && (iconAllowOverlap || !bucket.hasIconData() || iconOptional);
var alwaysShowIcon = iconAllowOverlap && (textAllowOverlap || !bucket.hasTextData() || textOptional);
if (!bucket.collisionArrays && collisionBoxArray) {
bucket.deserializeCollisionBoxes(collisionBoxArray);
}
var placeSymbol = function (symbolInstance, collisionArrays) {
if (seenCrossTileIDs[symbolInstance.crossTileID]) {
return;
}
if (holdingForFade) {
this$1.placements[symbolInstance.crossTileID] = new JointPlacement(false, false, false);
return;
}
var placeText = false;
var placeIcon = false;
var offscreen = true;
var shift = null;
var placed = {
box: null,
offscreen: null
};
var placedVerticalText = {
box: null,
offscreen: null
};
var placedGlyphBoxes = null;
var placedGlyphCircles = null;
var placedIconBoxes = null;
var textFeatureIndex = 0;
var verticalTextFeatureIndex = 0;
var iconFeatureIndex = 0;
if (collisionArrays.textFeatureIndex) {
textFeatureIndex = collisionArrays.textFeatureIndex;
} else if (symbolInstance.useRuntimeCollisionCircles) {
textFeatureIndex = symbolInstance.featureIndex;
}
if (collisionArrays.verticalTextFeatureIndex) {
verticalTextFeatureIndex = collisionArrays.verticalTextFeatureIndex;
}
var textBox = collisionArrays.textBox;
if (textBox) {
var updatePreviousOrientationIfNotPlaced = function (isPlaced) {
var previousOrientation = performance.WritingMode.horizontal;
if (bucket.allowVerticalPlacement && !isPlaced && this$1.prevPlacement) {
var prevPlacedOrientation = this$1.prevPlacement.placedOrientations[symbolInstance.crossTileID];
if (prevPlacedOrientation) {
this$1.placedOrientations[symbolInstance.crossTileID] = prevPlacedOrientation;
previousOrientation = prevPlacedOrientation;
this$1.markUsedOrientation(bucket, previousOrientation, symbolInstance);
}
}
return previousOrientation;
};
var placeTextForPlacementModes = function (placeHorizontalFn, placeVerticalFn) {
if (bucket.allowVerticalPlacement && symbolInstance.numVerticalGlyphVertices > 0 && collisionArrays.verticalTextBox) {
for (var i = 0, list = bucket.writingModes; i < list.length; i += 1) {
var placementMode = list[i];
if (placementMode === performance.WritingMode.vertical) {
placed = placeVerticalFn();
placedVerticalText = placed;
} else {
placed = placeHorizontalFn();
}
if (placed && placed.box && placed.box.length) {
break;
}
}
} else {
placed = placeHorizontalFn();
}
};
if (!layout.get('text-variable-anchor')) {
var placeBox = function (collisionTextBox, orientation) {
var placedFeature = this$1.collisionIndex.placeCollisionBox(collisionTextBox, textAllowOverlap, textPixelRatio, posMatrix, collisionGroup.predicate);
if (placedFeature && placedFeature.box && placedFeature.box.length) {
this$1.markUsedOrientation(bucket, orientation, symbolInstance);
this$1.placedOrientations[symbolInstance.crossTileID] = orientation;
}
return placedFeature;
};
var placeHorizontal = function () {
return placeBox(textBox, performance.WritingMode.horizontal);
};
var placeVertical = function () {
var verticalTextBox = collisionArrays.verticalTextBox;
if (bucket.allowVerticalPlacement && symbolInstance.numVerticalGlyphVertices > 0 && verticalTextBox) {
return placeBox(verticalTextBox, performance.WritingMode.vertical);
}
return {
box: null,
offscreen: null
};
};
placeTextForPlacementModes(placeHorizontal, placeVertical);
updatePreviousOrientationIfNotPlaced(placed && placed.box && placed.box.length);
} else {
var anchors = layout.get('text-variable-anchor');
if (this$1.prevPlacement && this$1.prevPlacement.variableOffsets[symbolInstance.crossTileID]) {
var prevOffsets = this$1.prevPlacement.variableOffsets[symbolInstance.crossTileID];
if (anchors.indexOf(prevOffsets.anchor) > 0) {
anchors = anchors.filter(function (anchor) {
return anchor !== prevOffsets.anchor;
});
anchors.unshift(prevOffsets.anchor);
}
}
var placeBoxForVariableAnchors = function (collisionTextBox, collisionIconBox, orientation) {
var width = collisionTextBox.x2 - collisionTextBox.x1;
var height = collisionTextBox.y2 - collisionTextBox.y1;
var textBoxScale = symbolInstance.textBoxScale;
var variableIconBox = hasIconTextFit && !iconAllowOverlap ? collisionIconBox : null;
var placedBox = {
box: [],
offscreen: false
};
var placementAttempts = textAllowOverlap ? anchors.length * 2 : anchors.length;
for (var i = 0; i < placementAttempts; ++i) {
var anchor = anchors[i % anchors.length];
var allowOverlap = i >= anchors.length;
var result = this$1.attemptAnchorPlacement(anchor, collisionTextBox, width, height, textBoxScale, rotateWithMap, pitchWithMap, textPixelRatio, posMatrix, collisionGroup, allowOverlap, symbolInstance, bucket, orientation, variableIconBox);
if (result) {
placedBox = result.placedGlyphBoxes;
if (placedBox && placedBox.box && placedBox.box.length) {
placeText = true;
shift = result.shift;
break;
}
}
}
return placedBox;
};
var placeHorizontal$1 = function () {
return placeBoxForVariableAnchors(textBox, collisionArrays.iconBox, performance.WritingMode.horizontal);
};
var placeVertical$1 = function () {
var verticalTextBox = collisionArrays.verticalTextBox;
var wasPlaced = placed && placed.box && placed.box.length;
if (bucket.allowVerticalPlacement && !wasPlaced && symbolInstance.numVerticalGlyphVertices > 0 && verticalTextBox) {
return placeBoxForVariableAnchors(verticalTextBox, collisionArrays.verticalIconBox, performance.WritingMode.vertical);
}
return {
box: null,
offscreen: null
};
};
placeTextForPlacementModes(placeHorizontal$1, placeVertical$1);
if (placed) {
placeText = placed.box;
offscreen = placed.offscreen;
}
var prevOrientation = updatePreviousOrientationIfNotPlaced(placed && placed.box);
if (!placeText && this$1.prevPlacement) {
var prevOffset = this$1.prevPlacement.variableOffsets[symbolInstance.crossTileID];
if (prevOffset) {
this$1.variableOffsets[symbolInstance.crossTileID] = prevOffset;
this$1.markUsedJustification(bucket, prevOffset.anchor, symbolInstance, prevOrientation);
}
}
}
}
placedGlyphBoxes = placed;
placeText = placedGlyphBoxes && placedGlyphBoxes.box && placedGlyphBoxes.box.length > 0;
offscreen = placedGlyphBoxes && placedGlyphBoxes.offscreen;
if (symbolInstance.useRuntimeCollisionCircles) {
var placedSymbol = bucket.text.placedSymbolArray.get(symbolInstance.centerJustifiedTextSymbolIndex);
var fontSize = performance.evaluateSizeForFeature(bucket.textSizeData, partiallyEvaluatedTextSize, placedSymbol);
var textPixelPadding = layout.get('text-padding');
var circlePixelDiameter = symbolInstance.collisionCircleDiameter;
placedGlyphCircles = this$1.collisionIndex.placeCollisionCircles(textAllowOverlap, placedSymbol, bucket.lineVertexArray, bucket.glyphOffsetArray, fontSize, posMatrix, textLabelPlaneMatrix, labelToScreenMatrix, showCollisionBoxes, pitchWithMap, collisionGroup.predicate, circlePixelDiameter, textPixelPadding);
placeText = textAllowOverlap || placedGlyphCircles.circles.length > 0 && !placedGlyphCircles.collisionDetected;
offscreen = offscreen && placedGlyphCircles.offscreen;
}
if (collisionArrays.iconFeatureIndex) {
iconFeatureIndex = collisionArrays.iconFeatureIndex;
}
if (collisionArrays.iconBox) {
var placeIconFeature = function (iconBox) {
var shiftedIconBox = hasIconTextFit && shift ? shiftVariableCollisionBox(iconBox, shift.x, shift.y, rotateWithMap, pitchWithMap, this$1.transform.angle) : iconBox;
return this$1.collisionIndex.placeCollisionBox(shiftedIconBox, iconAllowOverlap, textPixelRatio, posMatrix, collisionGroup.predicate);
};
if (placedVerticalText && placedVerticalText.box && placedVerticalText.box.length && collisionArrays.verticalIconBox) {
placedIconBoxes = placeIconFeature(collisionArrays.verticalIconBox);
placeIcon = placedIconBoxes.box.length > 0;
} else {
placedIconBoxes = placeIconFeature(collisionArrays.iconBox);
placeIcon = placedIconBoxes.box.length > 0;
}
offscreen = offscreen && placedIconBoxes.offscreen;
}
var iconWithoutText = textOptional || symbolInstance.numHorizontalGlyphVertices === 0 && symbolInstance.numVerticalGlyphVertices === 0;
var textWithoutIcon = iconOptional || symbolInstance.numIconVertices === 0;
if (!iconWithoutText && !textWithoutIcon) {
placeIcon = placeText = placeIcon && placeText;
} else if (!textWithoutIcon) {
placeText = placeIcon && placeText;
} else if (!iconWithoutText) {
placeIcon = placeIcon && placeText;
}
if (placeText && placedGlyphBoxes && placedGlyphBoxes.box) {
if (placedVerticalText && placedVerticalText.box && verticalTextFeatureIndex) {
this$1.collisionIndex.insertCollisionBox(placedGlyphBoxes.box, layout.get('text-ignore-placement'), bucket.bucketInstanceId, verticalTextFeatureIndex, collisionGroup.ID);
} else {
this$1.collisionIndex.insertCollisionBox(placedGlyphBoxes.box, layout.get('text-ignore-placement'), bucket.bucketInstanceId, textFeatureIndex, collisionGroup.ID);
}
}
if (placeIcon && placedIconBoxes) {
this$1.collisionIndex.insertCollisionBox(placedIconBoxes.box, layout.get('icon-ignore-placement'), bucket.bucketInstanceId, iconFeatureIndex, collisionGroup.ID);
}
if (placedGlyphCircles) {
if (placeText) {
this$1.collisionIndex.insertCollisionCircles(placedGlyphCircles.circles, layout.get('text-ignore-placement'), bucket.bucketInstanceId, textFeatureIndex, collisionGroup.ID);
}
if (showCollisionBoxes) {
var id = bucket.bucketInstanceId;
var circleArray = this$1.collisionCircleArrays[id];
if (circleArray === undefined) {
circleArray = this$1.collisionCircleArrays[id] = new CollisionCircleArray();
}
for (var i = 0; i < placedGlyphCircles.circles.length; i += 4) {
circleArray.circles.push(placedGlyphCircles.circles[i + 0]);
circleArray.circles.push(placedGlyphCircles.circles[i + 1]);
circleArray.circles.push(placedGlyphCircles.circles[i + 2]);
circleArray.circles.push(placedGlyphCircles.collisionDetected ? 1 : 0);
}
}
}
this$1.placements[symbolInstance.crossTileID] = new JointPlacement(placeText || alwaysShowText, placeIcon || alwaysShowIcon, offscreen || bucket.justReloaded);
seenCrossTileIDs[symbolInstance.crossTileID] = true;
};
if (zOrderByViewportY) {
var symbolIndexes = bucket.getSortedSymbolIndexes(this.transform.angle);
for (var i = symbolIndexes.length - 1; i >= 0; --i) {
var symbolIndex = symbolIndexes[i];
placeSymbol(bucket.symbolInstances.get(symbolIndex), bucket.collisionArrays[symbolIndex]);
}
} else {
for (var i$1 = bucketPart.symbolInstanceStart; i$1 < bucketPart.symbolInstanceEnd; i$1++) {
placeSymbol(bucket.symbolInstances.get(i$1), bucket.collisionArrays[i$1]);
}
}
if (showCollisionBoxes && bucket.bucketInstanceId in this.collisionCircleArrays) {
var circleArray = this.collisionCircleArrays[bucket.bucketInstanceId];
performance.invert(circleArray.invProjMatrix, posMatrix);
circleArray.viewportMatrix = this.collisionIndex.getViewportMatrix();
}
bucket.justReloaded = false;
};
Placement.prototype.markUsedJustification = function markUsedJustification(bucket, placedAnchor, symbolInstance, orientation) {
var justifications = {
'left': symbolInstance.leftJustifiedTextSymbolIndex,
'center': symbolInstance.centerJustifiedTextSymbolIndex,
'right': symbolInstance.rightJustifiedTextSymbolIndex
};
var autoIndex;
if (orientation === performance.WritingMode.vertical) {
autoIndex = symbolInstance.verticalPlacedTextSymbolIndex;
} else {
autoIndex = justifications[performance.getAnchorJustification(placedAnchor)];
}
var indexes = [
symbolInstance.leftJustifiedTextSymbolIndex,
symbolInstance.centerJustifiedTextSymbolIndex,
symbolInstance.rightJustifiedTextSymbolIndex,
symbolInstance.verticalPlacedTextSymbolIndex
];
for (var i = 0, list = indexes; i < list.length; i += 1) {
var index = list[i];
if (index >= 0) {
if (autoIndex >= 0 && index !== autoIndex) {
bucket.text.placedSymbolArray.get(index).crossTileID = 0;
} else {
bucket.text.placedSymbolArray.get(index).crossTileID = symbolInstance.crossTileID;
}
}
}
};
Placement.prototype.markUsedOrientation = function markUsedOrientation(bucket, orientation, symbolInstance) {
var horizontal = orientation === performance.WritingMode.horizontal || orientation === performance.WritingMode.horizontalOnly ? orientation : 0;
var vertical = orientation === performance.WritingMode.vertical ? orientation : 0;
var horizontalIndexes = [
symbolInstance.leftJustifiedTextSymbolIndex,
symbolInstance.centerJustifiedTextSymbolIndex,
symbolInstance.rightJustifiedTextSymbolIndex
];
for (var i = 0, list = horizontalIndexes; i < list.length; i += 1) {
var index = list[i];
bucket.text.placedSymbolArray.get(index).placedOrientation = horizontal;
}
if (symbolInstance.verticalPlacedTextSymbolIndex) {
bucket.text.placedSymbolArray.get(symbolInstance.verticalPlacedTextSymbolIndex).placedOrientation = vertical;
}
};
Placement.prototype.commit = function commit(now) {
this.commitTime = now;
this.zoomAtLastRecencyCheck = this.transform.zoom;
var prevPlacement = this.prevPlacement;
var placementChanged = false;
this.prevZoomAdjustment = prevPlacement ? prevPlacement.zoomAdjustment(this.transform.zoom) : 0;
var increment = prevPlacement ? prevPlacement.symbolFadeChange(now) : 1;
var prevOpacities = prevPlacement ? prevPlacement.opacities : {};
var prevOffsets = prevPlacement ? prevPlacement.variableOffsets : {};
var prevOrientations = prevPlacement ? prevPlacement.placedOrientations : {};
for (var crossTileID in this.placements) {
var jointPlacement = this.placements[crossTileID];
var prevOpacity = prevOpacities[crossTileID];
if (prevOpacity) {
this.opacities[crossTileID] = new JointOpacityState(prevOpacity, increment, jointPlacement.text, jointPlacement.icon);
placementChanged = placementChanged || jointPlacement.text !== prevOpacity.text.placed || jointPlacement.icon !== prevOpacity.icon.placed;
} else {
this.opacities[crossTileID] = new JointOpacityState(null, increment, jointPlacement.text, jointPlacement.icon, jointPlacement.skipFade);
placementChanged = placementChanged || jointPlacement.text || jointPlacement.icon;
}
}
for (var crossTileID$1 in prevOpacities) {
var prevOpacity$1 = prevOpacities[crossTileID$1];
if (!this.opacities[crossTileID$1]) {
var jointOpacity = new JointOpacityState(prevOpacity$1, increment, false, false);
if (!jointOpacity.isHidden()) {
this.opacities[crossTileID$1] = jointOpacity;
placementChanged = placementChanged || prevOpacity$1.text.placed || prevOpacity$1.icon.placed;
}
}
}
for (var crossTileID$2 in prevOffsets) {
if (!this.variableOffsets[crossTileID$2] && this.opacities[crossTileID$2] && !this.opacities[crossTileID$2].isHidden()) {
this.variableOffsets[crossTileID$2] = prevOffsets[crossTileID$2];
}
}
for (var crossTileID$3 in prevOrientations) {
if (!this.placedOrientations[crossTileID$3] && this.opacities[crossTileID$3] && !this.opacities[crossTileID$3].isHidden()) {
this.placedOrientations[crossTileID$3] = prevOrientations[crossTileID$3];
}
}
if (placementChanged) {
this.lastPlacementChangeTime = now;
} else if (typeof this.lastPlacementChangeTime !== 'number') {
this.lastPlacementChangeTime = prevPlacement ? prevPlacement.lastPlacementChangeTime : now;
}
};
Placement.prototype.updateLayerOpacities = function updateLayerOpacities(styleLayer, tiles) {
var seenCrossTileIDs = {};
for (var i = 0, list = tiles; i < list.length; i += 1) {
var tile = list[i];
var symbolBucket = tile.getBucket(styleLayer);
if (symbolBucket && tile.latestFeatureIndex && styleLayer.id === symbolBucket.layerIds[0]) {
this.updateBucketOpacities(symbolBucket, seenCrossTileIDs, tile.collisionBoxArray);
}
}
};
Placement.prototype.updateBucketOpacities = function updateBucketOpacities(bucket, seenCrossTileIDs, collisionBoxArray) {
var this$1 = this;
if (bucket.hasTextData()) {
bucket.text.opacityVertexArray.clear();
}
if (bucket.hasIconData()) {
bucket.icon.opacityVertexArray.clear();
}
if (bucket.hasIconCollisionBoxData()) {
bucket.iconCollisionBox.collisionVertexArray.clear();
}
if (bucket.hasTextCollisionBoxData()) {
bucket.textCollisionBox.collisionVertexArray.clear();
}
var layout = bucket.layers[0].layout;
var duplicateOpacityState = new JointOpacityState(null, 0, false, false, true);
var textAllowOverlap = layout.get('text-allow-overlap');
var iconAllowOverlap = layout.get('icon-allow-overlap');
var variablePlacement = layout.get('text-variable-anchor');
var rotateWithMap = layout.get('text-rotation-alignment') === 'map';
var pitchWithMap = layout.get('text-pitch-alignment') === 'map';
var hasIconTextFit = layout.get('icon-text-fit') !== 'none';
var defaultOpacityState = new JointOpacityState(null, 0, textAllowOverlap && (iconAllowOverlap || !bucket.hasIconData() || layout.get('icon-optional')), iconAllowOverlap && (textAllowOverlap || !bucket.hasTextData() || layout.get('text-optional')), true);
if (!bucket.collisionArrays && collisionBoxArray && (bucket.hasIconCollisionBoxData() || bucket.hasTextCollisionBoxData())) {
bucket.deserializeCollisionBoxes(collisionBoxArray);
}
var addOpacities = function (iconOrText, numVertices, opacity) {
for (var i = 0; i < numVertices / 4; i++) {
iconOrText.opacityVertexArray.emplaceBack(opacity);
}
};
var loop = function (s) {
var symbolInstance = bucket.symbolInstances.get(s);
var numHorizontalGlyphVertices = symbolInstance.numHorizontalGlyphVertices;
var numVerticalGlyphVertices = symbolInstance.numVerticalGlyphVertices;
var crossTileID = symbolInstance.crossTileID;
var isDuplicate = seenCrossTileIDs[crossTileID];
var opacityState = this$1.opacities[crossTileID];
if (isDuplicate) {
opacityState = duplicateOpacityState;
} else if (!opacityState) {
opacityState = defaultOpacityState;
this$1.opacities[crossTileID] = opacityState;
}
seenCrossTileIDs[crossTileID] = true;
var hasText = numHorizontalGlyphVertices > 0 || numVerticalGlyphVertices > 0;
var hasIcon = symbolInstance.numIconVertices > 0;
var placedOrientation = this$1.placedOrientations[symbolInstance.crossTileID];
var horizontalHidden = placedOrientation === performance.WritingMode.vertical;
var verticalHidden = placedOrientation === performance.WritingMode.horizontal || placedOrientation === performance.WritingMode.horizontalOnly;
if (hasText) {
var packedOpacity = packOpacity(opacityState.text);
var horizontalOpacity = horizontalHidden ? PACKED_HIDDEN_OPACITY : packedOpacity;
addOpacities(bucket.text, numHorizontalGlyphVertices, horizontalOpacity);
var verticalOpacity = verticalHidden ? PACKED_HIDDEN_OPACITY : packedOpacity;
addOpacities(bucket.text, numVerticalGlyphVertices, verticalOpacity);
var symbolHidden = opacityState.text.isHidden();
[
symbolInstance.rightJustifiedTextSymbolIndex,
symbolInstance.centerJustifiedTextSymbolIndex,
symbolInstance.leftJustifiedTextSymbolIndex
].forEach(function (index) {
if (index >= 0) {
bucket.text.placedSymbolArray.get(index).hidden = symbolHidden || horizontalHidden ? 1 : 0;
}
});
if (symbolInstance.verticalPlacedTextSymbolIndex >= 0) {
bucket.text.placedSymbolArray.get(symbolInstance.verticalPlacedTextSymbolIndex).hidden = symbolHidden || verticalHidden ? 1 : 0;
}
var prevOffset = this$1.variableOffsets[symbolInstance.crossTileID];
if (prevOffset) {
this$1.markUsedJustification(bucket, prevOffset.anchor, symbolInstance, placedOrientation);
}
var prevOrientation = this$1.placedOrientations[symbolInstance.crossTileID];
if (prevOrientation) {
this$1.markUsedJustification(bucket, 'left', symbolInstance, prevOrientation);
this$1.markUsedOrientation(bucket, prevOrientation, symbolInstance);
}
}
if (hasIcon) {
var packedOpacity$1 = packOpacity(opacityState.icon);
var useHorizontal = !(hasIconTextFit && symbolInstance.verticalPlacedIconSymbolIndex && horizontalHidden);
if (symbolInstance.placedIconSymbolIndex >= 0) {
var horizontalOpacity$1 = useHorizontal ? packedOpacity$1 : PACKED_HIDDEN_OPACITY;
addOpacities(bucket.icon, symbolInstance.numIconVertices, horizontalOpacity$1);
bucket.icon.placedSymbolArray.get(symbolInstance.placedIconSymbolIndex).hidden = opacityState.icon.isHidden();
}
if (symbolInstance.verticalPlacedIconSymbolIndex >= 0) {
var verticalOpacity$1 = !useHorizontal ? packedOpacity$1 : PACKED_HIDDEN_OPACITY;
addOpacities(bucket.icon, symbolInstance.numVerticalIconVertices, verticalOpacity$1);
bucket.icon.placedSymbolArray.get(symbolInstance.verticalPlacedIconSymbolIndex).hidden = opacityState.icon.isHidden();
}
}
if (bucket.hasIconCollisionBoxData() || bucket.hasTextCollisionBoxData()) {
var collisionArrays = bucket.collisionArrays[s];
if (collisionArrays) {
var shift = new performance.Point(0, 0);
if (collisionArrays.textBox || collisionArrays.verticalTextBox) {
var used = true;
if (variablePlacement) {
var variableOffset = this$1.variableOffsets[crossTileID];
if (variableOffset) {
shift = calculateVariableLayoutShift(variableOffset.anchor, variableOffset.width, variableOffset.height, variableOffset.textOffset, variableOffset.textBoxScale);
if (rotateWithMap) {
shift._rotate(pitchWithMap ? this$1.transform.angle : -this$1.transform.angle);
}
} else {
used = false;
}
}
if (collisionArrays.textBox) {
updateCollisionVertices(bucket.textCollisionBox.collisionVertexArray, opacityState.text.placed, !used || horizontalHidden, shift.x, shift.y);
}
if (collisionArrays.verticalTextBox) {
updateCollisionVertices(bucket.textCollisionBox.collisionVertexArray, opacityState.text.placed, !used || verticalHidden, shift.x, shift.y);
}
}
var verticalIconUsed = Boolean(!verticalHidden && collisionArrays.verticalIconBox);
if (collisionArrays.iconBox) {
updateCollisionVertices(bucket.iconCollisionBox.collisionVertexArray, opacityState.icon.placed, verticalIconUsed, hasIconTextFit ? shift.x : 0, hasIconTextFit ? shift.y : 0);
}
if (collisionArrays.verticalIconBox) {
updateCollisionVertices(bucket.iconCollisionBox.collisionVertexArray, opacityState.icon.placed, !verticalIconUsed, hasIconTextFit ? shift.x : 0, hasIconTextFit ? shift.y : 0);
}
}
}
};
for (var s = 0; s < bucket.symbolInstances.length; s++)
loop(s);
bucket.sortFeatures(this.transform.angle);
if (this.retainedQueryData[bucket.bucketInstanceId]) {
this.retainedQueryData[bucket.bucketInstanceId].featureSortOrder = bucket.featureSortOrder;
}
if (bucket.hasTextData() && bucket.text.opacityVertexBuffer) {
bucket.text.opacityVertexBuffer.updateData(bucket.text.opacityVertexArray);
}
if (bucket.hasIconData() && bucket.icon.opacityVertexBuffer) {
bucket.icon.opacityVertexBuffer.updateData(bucket.icon.opacityVertexArray);
}
if (bucket.hasIconCollisionBoxData() && bucket.iconCollisionBox.collisionVertexBuffer) {
bucket.iconCollisionBox.collisionVertexBuffer.updateData(bucket.iconCollisionBox.collisionVertexArray);
}
if (bucket.hasTextCollisionBoxData() && bucket.textCollisionBox.collisionVertexBuffer) {
bucket.textCollisionBox.collisionVertexBuffer.updateData(bucket.textCollisionBox.collisionVertexArray);
}
if (bucket.bucketInstanceId in this.collisionCircleArrays) {
var instance = this.collisionCircleArrays[bucket.bucketInstanceId];
bucket.placementInvProjMatrix = instance.invProjMatrix;
bucket.placementViewportMatrix = instance.viewportMatrix;
bucket.collisionCircleArray = instance.circles;
delete this.collisionCircleArrays[bucket.bucketInstanceId];
}
};
Placement.prototype.symbolFadeChange = function symbolFadeChange(now) {
return this.fadeDuration === 0 ? 1 : (now - this.commitTime) / this.fadeDuration + this.prevZoomAdjustment;
};
Placement.prototype.zoomAdjustment = function zoomAdjustment(zoom) {
return Math.max(0, (this.transform.zoom - zoom) / 1.5);
};
Placement.prototype.hasTransitions = function hasTransitions(now) {
return this.stale || now - this.lastPlacementChangeTime < this.fadeDuration;
};
Placement.prototype.stillRecent = function stillRecent(now, zoom) {
var durationAdjustment = this.zoomAtLastRecencyCheck === zoom ? 1 - this.zoomAdjustment(zoom) : 1;
this.zoomAtLastRecencyCheck = zoom;
return this.commitTime + this.fadeDuration * durationAdjustment > now;
};
Placement.prototype.setStale = function setStale() {
this.stale = true;
};
function updateCollisionVertices(collisionVertexArray, placed, notUsed, shiftX, shiftY) {
collisionVertexArray.emplaceBack(placed ? 1 : 0, notUsed ? 1 : 0, shiftX || 0, shiftY || 0);
collisionVertexArray.emplaceBack(placed ? 1 : 0, notUsed ? 1 : 0, shiftX || 0, shiftY || 0);
collisionVertexArray.emplaceBack(placed ? 1 : 0, notUsed ? 1 : 0, shiftX || 0, shiftY || 0);
collisionVertexArray.emplaceBack(placed ? 1 : 0, notUsed ? 1 : 0, shiftX || 0, shiftY || 0);
}
var shift25 = Math.pow(2, 25);
var shift24 = Math.pow(2, 24);
var shift17 = Math.pow(2, 17);
var shift16 = Math.pow(2, 16);
var shift9 = Math.pow(2, 9);
var shift8 = Math.pow(2, 8);
var shift1 = Math.pow(2, 1);
function packOpacity(opacityState) {
if (opacityState.opacity === 0 && !opacityState.placed) {
return 0;
} else if (opacityState.opacity === 1 && opacityState.placed) {
return 4294967295;
}
var targetBit = opacityState.placed ? 1 : 0;
var opacityBits = Math.floor(opacityState.opacity * 127);
return opacityBits * shift25 + targetBit * shift24 + opacityBits * shift17 + targetBit * shift16 + opacityBits * shift9 + targetBit * shift8 + opacityBits * shift1 + targetBit;
}
var PACKED_HIDDEN_OPACITY = 0;
var LayerPlacement = function LayerPlacement(styleLayer) {
this._sortAcrossTiles = styleLayer.layout.get('symbol-z-order') !== 'viewport-y' && styleLayer.layout.get('symbol-sort-key').constantOr(1) !== undefined;
this._currentTileIndex = 0;
this._currentPartIndex = 0;
this._seenCrossTileIDs = {};
this._bucketParts = [];
};
LayerPlacement.prototype.continuePlacement = function continuePlacement(tiles, placement, showCollisionBoxes, styleLayer, shouldPausePlacement) {
var bucketParts = this._bucketParts;
while (this._currentTileIndex < tiles.length) {
var tile = tiles[this._currentTileIndex];
placement.getBucketParts(bucketParts, styleLayer, tile, this._sortAcrossTiles);
this._currentTileIndex++;
if (shouldPausePlacement()) {
return true;
}
}
if (this._sortAcrossTiles) {
this._sortAcrossTiles = false;
bucketParts.sort(function (a, b) {
return a.sortKey - b.sortKey;
});
}
while (this._currentPartIndex < bucketParts.length) {
var bucketPart = bucketParts[this._currentPartIndex];
placement.placeLayerBucketPart(bucketPart, this._seenCrossTileIDs, showCollisionBoxes);
this._currentPartIndex++;
if (shouldPausePlacement()) {
return true;
}
}
return false;
};
var PauseablePlacement = function PauseablePlacement(transform, order, forceFullPlacement, showCollisionBoxes, fadeDuration, crossSourceCollisions, prevPlacement) {
this.placement = new Placement(transform, fadeDuration, crossSourceCollisions, prevPlacement);
this._currentPlacementIndex = order.length - 1;
this._forceFullPlacement = forceFullPlacement;
this._showCollisionBoxes = showCollisionBoxes;
this._done = false;
};
PauseablePlacement.prototype.isDone = function isDone() {
return this._done;
};
PauseablePlacement.prototype.continuePlacement = function continuePlacement(order, layers, layerTiles) {
var this$1 = this;
var startTime = performance.browser.now();
var shouldPausePlacement = function () {
var elapsedTime = performance.browser.now() - startTime;
return this$1._forceFullPlacement ? false : elapsedTime > 2;
};
while (this._currentPlacementIndex >= 0) {
var layerId = order[this._currentPlacementIndex];
var layer = layers[layerId];
var placementZoom = this.placement.collisionIndex.transform.zoom;
if (layer.type === 'symbol' && (!layer.minzoom || layer.minzoom <= placementZoom) && (!layer.maxzoom || layer.maxzoom > placementZoom)) {
if (!this._inProgressLayer) {
this._inProgressLayer = new LayerPlacement(layer);
}
var pausePlacement = this._inProgressLayer.continuePlacement(layerTiles[layer.source], this.placement, this._showCollisionBoxes, layer, shouldPausePlacement);
if (pausePlacement) {
return;
}
delete this._inProgressLayer;
}
this._currentPlacementIndex--;
}
this._done = true;
};
PauseablePlacement.prototype.commit = function commit(now) {
this.placement.commit(now);
return this.placement;
};
var roundingFactor = 512 / performance.EXTENT / 2;
var TileLayerIndex = function TileLayerIndex(tileID, symbolInstances, bucketInstanceId) {
this.tileID = tileID;
this.indexedSymbolInstances = {};
this.bucketInstanceId = bucketInstanceId;
for (var i = 0; i < symbolInstances.length; i++) {
var symbolInstance = symbolInstances.get(i);
var key = symbolInstance.key;
if (!this.indexedSymbolInstances[key]) {
this.indexedSymbolInstances[key] = [];
}
this.indexedSymbolInstances[key].push({
crossTileID: symbolInstance.crossTileID,
coord: this.getScaledCoordinates(symbolInstance, tileID)
});
}
};
TileLayerIndex.prototype.getScaledCoordinates = function getScaledCoordinates(symbolInstance, childTileID) {
var zDifference = childTileID.canonical.z - this.tileID.canonical.z;
var scale = roundingFactor / Math.pow(2, zDifference);
return {
x: Math.floor((childTileID.canonical.x * performance.EXTENT + symbolInstance.anchorX) * scale),
y: Math.floor((childTileID.canonical.y * performance.EXTENT + symbolInstance.anchorY) * scale)
};
};
TileLayerIndex.prototype.findMatches = function findMatches(symbolInstances, newTileID, zoomCrossTileIDs) {
var tolerance = this.tileID.canonical.z < newTileID.canonical.z ? 1 : Math.pow(2, this.tileID.canonical.z - newTileID.canonical.z);
for (var i = 0; i < symbolInstances.length; i++) {
var symbolInstance = symbolInstances.get(i);
if (symbolInstance.crossTileID) {
continue;
}
var indexedInstances = this.indexedSymbolInstances[symbolInstance.key];
if (!indexedInstances) {
continue;
}
var scaledSymbolCoord = this.getScaledCoordinates(symbolInstance, newTileID);
for (var i$1 = 0, list = indexedInstances; i$1 < list.length; i$1 += 1) {
var thisTileSymbol = list[i$1];
if (Math.abs(thisTileSymbol.coord.x - scaledSymbolCoord.x) <= tolerance && Math.abs(thisTileSymbol.coord.y - scaledSymbolCoord.y) <= tolerance && !zoomCrossTileIDs[thisTileSymbol.crossTileID]) {
zoomCrossTileIDs[thisTileSymbol.crossTileID] = true;
symbolInstance.crossTileID = thisTileSymbol.crossTileID;
break;
}
}
}
};
var CrossTileIDs = function CrossTileIDs() {
this.maxCrossTileID = 0;
};
CrossTileIDs.prototype.generate = function generate() {
return ++this.maxCrossTileID;
};
var CrossTileSymbolLayerIndex = function CrossTileSymbolLayerIndex() {
this.indexes = {};
this.usedCrossTileIDs = {};
this.lng = 0;
};
CrossTileSymbolLayerIndex.prototype.handleWrapJump = function handleWrapJump(lng) {
var wrapDelta = Math.round((lng - this.lng) / 360);
if (wrapDelta !== 0) {
for (var zoom in this.indexes) {
var zoomIndexes = this.indexes[zoom];
var newZoomIndex = {};
for (var key in zoomIndexes) {
var index = zoomIndexes[key];
index.tileID = index.tileID.unwrapTo(index.tileID.wrap + wrapDelta);
newZoomIndex[index.tileID.key] = index;
}
this.indexes[zoom] = newZoomIndex;
}
}
this.lng = lng;
};
CrossTileSymbolLayerIndex.prototype.addBucket = function addBucket(tileID, bucket, crossTileIDs) {
if (this.indexes[tileID.overscaledZ] && this.indexes[tileID.overscaledZ][tileID.key]) {
if (this.indexes[tileID.overscaledZ][tileID.key].bucketInstanceId === bucket.bucketInstanceId) {
return false;
} else {
this.removeBucketCrossTileIDs(tileID.overscaledZ, this.indexes[tileID.overscaledZ][tileID.key]);
}
}
for (var i = 0; i < bucket.symbolInstances.length; i++) {
var symbolInstance = bucket.symbolInstances.get(i);
symbolInstance.crossTileID = 0;
}
if (!this.usedCrossTileIDs[tileID.overscaledZ]) {
this.usedCrossTileIDs[tileID.overscaledZ] = {};
}
var zoomCrossTileIDs = this.usedCrossTileIDs[tileID.overscaledZ];
for (var zoom in this.indexes) {
var zoomIndexes = this.indexes[zoom];
if (Number(zoom) > tileID.overscaledZ) {
for (var id in zoomIndexes) {
var childIndex = zoomIndexes[id];
if (childIndex.tileID.isChildOf(tileID)) {
childIndex.findMatches(bucket.symbolInstances, tileID, zoomCrossTileIDs);
}
}
} else {
var parentCoord = tileID.scaledTo(Number(zoom));
var parentIndex = zoomIndexes[parentCoord.key];
if (parentIndex) {
parentIndex.findMatches(bucket.symbolInstances, tileID, zoomCrossTileIDs);
}
}
}
for (var i$1 = 0; i$1 < bucket.symbolInstances.length; i$1++) {
var symbolInstance$1 = bucket.symbolInstances.get(i$1);
if (!symbolInstance$1.crossTileID) {
symbolInstance$1.crossTileID = crossTileIDs.generate();
zoomCrossTileIDs[symbolInstance$1.crossTileID] = true;
}
}
if (this.indexes[tileID.overscaledZ] === undefined) {
this.indexes[tileID.overscaledZ] = {};
}
this.indexes[tileID.overscaledZ][tileID.key] = new TileLayerIndex(tileID, bucket.symbolInstances, bucket.bucketInstanceId);
return true;
};
CrossTileSymbolLayerIndex.prototype.removeBucketCrossTileIDs = function removeBucketCrossTileIDs(zoom, removedBucket) {
for (var key in removedBucket.indexedSymbolInstances) {
for (var i = 0, list = removedBucket.indexedSymbolInstances[key]; i < list.length; i += 1) {
var symbolInstance = list[i];
delete this.usedCrossTileIDs[zoom][symbolInstance.crossTileID];
}
}
};
CrossTileSymbolLayerIndex.prototype.removeStaleBuckets = function removeStaleBuckets(currentIDs) {
var tilesChanged = false;
for (var z in this.indexes) {
var zoomIndexes = this.indexes[z];
for (var tileKey in zoomIndexes) {
if (!currentIDs[zoomIndexes[tileKey].bucketInstanceId]) {
this.removeBucketCrossTileIDs(z, zoomIndexes[tileKey]);
delete zoomIndexes[tileKey];
tilesChanged = true;
}
}
}
return tilesChanged;
};
var CrossTileSymbolIndex = function CrossTileSymbolIndex() {
this.layerIndexes = {};
this.crossTileIDs = new CrossTileIDs();
this.maxBucketInstanceId = 0;
this.bucketsInCurrentPlacement = {};
};
CrossTileSymbolIndex.prototype.addLayer = function addLayer(styleLayer, tiles, lng) {
var layerIndex = this.layerIndexes[styleLayer.id];
if (layerIndex === undefined) {
layerIndex = this.layerIndexes[styleLayer.id] = new CrossTileSymbolLayerIndex();
}
var symbolBucketsChanged = false;
var currentBucketIDs = {};
layerIndex.handleWrapJump(lng);
for (var i = 0, list = tiles; i < list.length; i += 1) {
var tile = list[i];
var symbolBucket = tile.getBucket(styleLayer);
if (!symbolBucket || styleLayer.id !== symbolBucket.layerIds[0]) {
continue;
}
if (!symbolBucket.bucketInstanceId) {
symbolBucket.bucketInstanceId = ++this.maxBucketInstanceId;
}
if (layerIndex.addBucket(tile.tileID, symbolBucket, this.crossTileIDs)) {
symbolBucketsChanged = true;
}
currentBucketIDs[symbolBucket.bucketInstanceId] = true;
}
if (layerIndex.removeStaleBuckets(currentBucketIDs)) {
symbolBucketsChanged = true;
}
return symbolBucketsChanged;
};
CrossTileSymbolIndex.prototype.pruneUnusedLayers = function pruneUnusedLayers(usedLayers) {
var usedLayerMap = {};
usedLayers.forEach(function (usedLayer) {
usedLayerMap[usedLayer] = true;
});
for (var layerId in this.layerIndexes) {
if (!usedLayerMap[layerId]) {
delete this.layerIndexes[layerId];
}
}
};
var emitValidationErrors = function (evented, errors) {
return performance.emitValidationErrors(evented, errors && errors.filter(function (error) {
return error.identifier !== 'source.canvas';
}));
};
var supportedDiffOperations = performance.pick(operations, [
'addLayer',
'removeLayer',
'setPaintProperty',
'setLayoutProperty',
'setFilter',
'addSource',
'removeSource',
'setLayerZoomRange',
'setLight',
'setTransition',
'setGeoJSONSourceData'
]);
var ignoredDiffOperations = performance.pick(operations, [
'setCenter',
'setZoom',
'setBearing',
'setPitch'
]);
var empty = emptyStyle();
var Style = function (Evented) {
function Style(map, options) {
var this$1 = this;
if (options === void 0)
options = {};
Evented.call(this);
this.map = map;
this.dispatcher = new Dispatcher(getGlobalWorkerPool(), this);
this.imageManager = new ImageManager();
this.imageManager.setEventedParent(this);
this.glyphManager = new GlyphManager(map._requestManager, options.localIdeographFontFamily);
this.lineAtlas = new LineAtlas(256, 512);
this.crossTileSymbolIndex = new CrossTileSymbolIndex();
this._layers = {};
this._serializedLayers = {};
this._order = [];
this.sourceCaches = {};
this.zoomHistory = new performance.ZoomHistory();
this._loaded = false;
this._availableImages = [];
this._resetUpdates();
this.dispatcher.broadcast('setReferrer', performance.getReferrer());
var self = this;
this._rtlTextPluginCallback = Style.registerForPluginStateChange(function (event) {
var state = {
pluginStatus: event.pluginStatus,
pluginURL: event.pluginURL
};
self.dispatcher.broadcast('syncRTLPluginState', state, function (err, results) {
performance.triggerPluginCompletionEvent(err);
if (results) {
var allComplete = results.every(function (elem) {
return elem;
});
if (allComplete) {
for (var id in self.sourceCaches) {
self.sourceCaches[id].reload();
}
}
}
});
});
this.on('data', function (event) {
if (event.dataType !== 'source' || event.sourceDataType !== 'metadata') {
return;
}
var sourceCache = this$1.sourceCaches[event.sourceId];
if (!sourceCache) {
return;
}
var source = sourceCache.getSource();
if (!source || !source.vectorLayerIds) {
return;
}
for (var layerId in this$1._layers) {
var layer = this$1._layers[layerId];
if (layer.source === source.id) {
this$1._validateLayer(layer);
}
}
});
}
if (Evented)
Style.__proto__ = Evented;
Style.prototype = Object.create(Evented && Evented.prototype);
Style.prototype.constructor = Style;
Style.prototype.loadURL = function loadURL(url, options) {
var this$1 = this;
if (options === void 0)
options = {};
this.fire(new performance.Event('dataloading', { dataType: 'style' }));
var validate = typeof options.validate === 'boolean' ? options.validate : !performance.isMapboxURL(url);
url = this.map._requestManager.normalizeStyleURL(url, options.accessToken);
var request = this.map._requestManager.transformRequest(url, performance.ResourceType.Style);
this._request = performance.getJSON(request, function (error, json) {
this$1._request = null;
if (error) {
this$1.fire(new performance.ErrorEvent(error));
} else if (json) {
this$1._load(json, validate);
}
});
};
Style.prototype.loadJSON = function loadJSON(json, options) {
var this$1 = this;
if (options === void 0)
options = {};
this.fire(new performance.Event('dataloading', { dataType: 'style' }));
this._request = performance.browser.frame(function () {
this$1._request = null;
this$1._load(json, options.validate !== false);
});
};
Style.prototype.loadEmpty = function loadEmpty() {
this.fire(new performance.Event('dataloading', { dataType: 'style' }));
this._load(empty, false);
};
Style.prototype._load = function _load(json, validate) {
if (validate && emitValidationErrors(this, performance.validateStyle(json))) {
return;
}
this._loaded = true;
this.stylesheet = json;
for (var id in json.sources) {
this.addSource(id, json.sources[id], { validate: false });
}
if (json.sprite) {
this._loadSprite(json.sprite);
} else {
this.imageManager.setLoaded(true);
}
this.glyphManager.setURL(json.glyphs);
var layers = derefLayers(this.stylesheet.layers);
this._order = layers.map(function (layer) {
return layer.id;
});
this._layers = {};
this._serializedLayers = {};
for (var i = 0, list = layers; i < list.length; i += 1) {
var layer = list[i];
layer = performance.createStyleLayer(layer);
layer.setEventedParent(this, { layer: { id: layer.id } });
this._layers[layer.id] = layer;
this._serializedLayers[layer.id] = layer.serialize();
}
this.dispatcher.broadcast('setLayers', this._serializeLayers(this._order));
this.light = new Light(this.stylesheet.light);
this.fire(new performance.Event('data', { dataType: 'style' }));
this.fire(new performance.Event('style.load'));
};
Style.prototype._loadSprite = function _loadSprite(url) {
var this$1 = this;
this._spriteRequest = loadSprite(url, this.map._requestManager, function (err, images) {
this$1._spriteRequest = null;
if (err) {
this$1.fire(new performance.ErrorEvent(err));
} else if (images) {
for (var id in images) {
this$1.imageManager.addImage(id, images[id]);
}
}
this$1.imageManager.setLoaded(true);
this$1._availableImages = this$1.imageManager.listImages();
this$1.dispatcher.broadcast('setImages', this$1._availableImages);
this$1.fire(new performance.Event('data', { dataType: 'style' }));
});
};
Style.prototype._validateLayer = function _validateLayer(layer) {
var sourceCache = this.sourceCaches[layer.source];
if (!sourceCache) {
return;
}
var sourceLayer = layer.sourceLayer;
if (!sourceLayer) {
return;
}
var source = sourceCache.getSource();
if (source.type === 'geojson' || source.vectorLayerIds && source.vectorLayerIds.indexOf(sourceLayer) === -1) {
this.fire(new performance.ErrorEvent(new Error('Source layer "' + sourceLayer + '" ' + 'does not exist on source "' + source.id + '" ' + 'as specified by style layer "' + layer.id + '"')));
}
};
Style.prototype.loaded = function loaded() {
if (!this._loaded) {
return false;
}
if (Object.keys(this._updatedSources).length) {
return false;
}
for (var id in this.sourceCaches) {
if (!this.sourceCaches[id].loaded()) {
return false;
}
}
if (!this.imageManager.isLoaded()) {
return false;
}
return true;
};
Style.prototype._serializeLayers = function _serializeLayers(ids) {
var serializedLayers = [];
for (var i = 0, list = ids; i < list.length; i += 1) {
var id = list[i];
var layer = this._layers[id];
if (layer.type !== 'custom') {
serializedLayers.push(layer.serialize());
}
}
return serializedLayers;
};
Style.prototype.hasTransitions = function hasTransitions() {
if (this.light && this.light.hasTransition()) {
return true;
}
for (var id in this.sourceCaches) {
if (this.sourceCaches[id].hasTransition()) {
return true;
}
}
for (var id$1 in this._layers) {
if (this._layers[id$1].hasTransition()) {
return true;
}
}
return false;
};
Style.prototype._checkLoaded = function _checkLoaded() {
if (!this._loaded) {
throw new Error('Style is not done loading');
}
};
Style.prototype.update = function update(parameters) {
if (!this._loaded) {
return;
}
var changed = this._changed;
if (this._changed) {
var updatedIds = Object.keys(this._updatedLayers);
var removedIds = Object.keys(this._removedLayers);
if (updatedIds.length || removedIds.length) {
this._updateWorkerLayers(updatedIds, removedIds);
}
for (var id in this._updatedSources) {
var action = this._updatedSources[id];
if (action === 'reload') {
this._reloadSource(id);
} else if (action === 'clear') {
this._clearSource(id);
}
}
this._updateTilesForChangedImages();
for (var id$1 in this._updatedPaintProps) {
this._layers[id$1].updateTransitions(parameters);
}
this.light.updateTransitions(parameters);
this._resetUpdates();
}
var sourcesUsedBefore = {};
for (var sourceId in this.sourceCaches) {
var sourceCache = this.sourceCaches[sourceId];
sourcesUsedBefore[sourceId] = sourceCache.used;
sourceCache.used = false;
}
for (var i = 0, list = this._order; i < list.length; i += 1) {
var layerId = list[i];
var layer = this._layers[layerId];
layer.recalculate(parameters, this._availableImages);
if (!layer.isHidden(parameters.zoom) && layer.source) {
this.sourceCaches[layer.source].used = true;
}
}
for (var sourceId$1 in sourcesUsedBefore) {
var sourceCache$1 = this.sourceCaches[sourceId$1];
if (sourcesUsedBefore[sourceId$1] !== sourceCache$1.used) {
sourceCache$1.fire(new performance.Event('data', {
sourceDataType: 'visibility',
dataType: 'source',
sourceId: sourceId$1
}));
}
}
this.light.recalculate(parameters);
this.z = parameters.zoom;
if (changed) {
this.fire(new performance.Event('data', { dataType: 'style' }));
}
};
Style.prototype._updateTilesForChangedImages = function _updateTilesForChangedImages() {
var changedImages = Object.keys(this._changedImages);
if (changedImages.length) {
for (var name in this.sourceCaches) {
this.sourceCaches[name].reloadTilesForDependencies([
'icons',
'patterns'
], changedImages);
}
this._changedImages = {};
}
};
Style.prototype._updateWorkerLayers = function _updateWorkerLayers(updatedIds, removedIds) {
this.dispatcher.broadcast('updateLayers', {
layers: this._serializeLayers(updatedIds),
removedIds: removedIds
});
};
Style.prototype._resetUpdates = function _resetUpdates() {
this._changed = false;
this._updatedLayers = {};
this._removedLayers = {};
this._updatedSources = {};
this._updatedPaintProps = {};
this._changedImages = {};
};
Style.prototype.setState = function setState(nextState) {
var this$1 = this;
this._checkLoaded();
if (emitValidationErrors(this, performance.validateStyle(nextState))) {
return false;
}
nextState = performance.clone$1(nextState);
nextState.layers = derefLayers(nextState.layers);
var changes = diffStyles(this.serialize(), nextState).filter(function (op) {
return !(op.command in ignoredDiffOperations);
});
if (changes.length === 0) {
return false;
}
var unimplementedOps = changes.filter(function (op) {
return !(op.command in supportedDiffOperations);
});
if (unimplementedOps.length > 0) {
throw new Error('Unimplemented: ' + unimplementedOps.map(function (op) {
return op.command;
}).join(', ') + '.');
}
changes.forEach(function (op) {
if (op.command === 'setTransition') {
return;
}
this$1[op.command].apply(this$1, op.args);
});
this.stylesheet = nextState;
return true;
};
Style.prototype.addImage = function addImage(id, image) {
if (this.getImage(id)) {
return this.fire(new performance.ErrorEvent(new Error('An image with this name already exists.')));
}
this.imageManager.addImage(id, image);
this._afterImageUpdated(id);
};
Style.prototype.updateImage = function updateImage(id, image) {
this.imageManager.updateImage(id, image);
};
Style.prototype.getImage = function getImage(id) {
return this.imageManager.getImage(id);
};
Style.prototype.removeImage = function removeImage(id) {
if (!this.getImage(id)) {
return this.fire(new performance.ErrorEvent(new Error('No image with this name exists.')));
}
this.imageManager.removeImage(id);
this._afterImageUpdated(id);
};
Style.prototype._afterImageUpdated = function _afterImageUpdated(id) {
this._availableImages = this.imageManager.listImages();
this._changedImages[id] = true;
this._changed = true;
this.dispatcher.broadcast('setImages', this._availableImages);
this.fire(new performance.Event('data', { dataType: 'style' }));
};
Style.prototype.listImages = function listImages() {
this._checkLoaded();
return this.imageManager.listImages();
};
Style.prototype.addSource = function addSource(id, source, options) {
var this$1 = this;
if (options === void 0)
options = {};
this._checkLoaded();
if (this.sourceCaches[id] !== undefined) {
throw new Error('There is already a source with this ID');
}
if (!source.type) {
throw new Error('The type property must be defined, but only the following properties were given: ' + Object.keys(source).join(', ') + '.');
}
var builtIns = [
'vector',
'raster',
'geojson',
'video',
'image'
];
var shouldValidate = builtIns.indexOf(source.type) >= 0;
if (shouldValidate && this._validate(performance.validateStyle.source, 'sources.' + id, source, null, options)) {
return;
}
if (this.map && this.map._collectResourceTiming) {
source.collectResourceTiming = true;
}
var sourceCache = this.sourceCaches[id] = new SourceCache(id, source, this.dispatcher);
sourceCache.style = this;
sourceCache.setEventedParent(this, function () {
return {
isSourceLoaded: this$1.loaded(),
source: sourceCache.serialize(),
sourceId: id
};
});
sourceCache.onAdd(this.map);
this._changed = true;
};
Style.prototype.removeSource = function removeSource(id) {
this._checkLoaded();
if (this.sourceCaches[id] === undefined) {
throw new Error('There is no source with this ID');
}
for (var layerId in this._layers) {
if (this._layers[layerId].source === id) {
return this.fire(new performance.ErrorEvent(new Error('Source "' + id + '" cannot be removed while layer "' + layerId + '" is using it.')));
}
}
var sourceCache = this.sourceCaches[id];
delete this.sourceCaches[id];
delete this._updatedSources[id];
sourceCache.fire(new performance.Event('data', {
sourceDataType: 'metadata',
dataType: 'source',
sourceId: id
}));
sourceCache.setEventedParent(null);
sourceCache.clearTiles();
if (sourceCache.onRemove) {
sourceCache.onRemove(this.map);
}
this._changed = true;
};
Style.prototype.setGeoJSONSourceData = function setGeoJSONSourceData(id, data) {
this._checkLoaded();
var geojsonSource = this.sourceCaches[id].getSource();
geojsonSource.setData(data);
this._changed = true;
};
Style.prototype.getSource = function getSource(id) {
return this.sourceCaches[id] && this.sourceCaches[id].getSource();
};
Style.prototype.addLayer = function addLayer(layerObject, before, options) {
if (options === void 0)
options = {};
this._checkLoaded();
var id = layerObject.id;
if (this.getLayer(id)) {
this.fire(new performance.ErrorEvent(new Error('Layer with id "' + id + '" already exists on this map')));
return;
}
var layer;
if (layerObject.type === 'custom') {
if (emitValidationErrors(this, performance.validateCustomStyleLayer(layerObject))) {
return;
}
layer = performance.createStyleLayer(layerObject);
} else {
if (typeof layerObject.source === 'object') {
this.addSource(id, layerObject.source);
layerObject = performance.clone$1(layerObject);
layerObject = performance.extend(layerObject, { source: id });
}
if (this._validate(performance.validateStyle.layer, 'layers.' + id, layerObject, { arrayIndex: -1 }, options)) {
return;
}
layer = performance.createStyleLayer(layerObject);
this._validateLayer(layer);
layer.setEventedParent(this, { layer: { id: id } });
this._serializedLayers[layer.id] = layer.serialize();
}
var index = before ? this._order.indexOf(before) : this._order.length;
if (before && index === -1) {
this.fire(new performance.ErrorEvent(new Error('Layer with id "' + before + '" does not exist on this map.')));
return;
}
this._order.splice(index, 0, id);
this._layerOrderChanged = true;
this._layers[id] = layer;
if (this._removedLayers[id] && layer.source && layer.type !== 'custom') {
var removed = this._removedLayers[id];
delete this._removedLayers[id];
if (removed.type !== layer.type) {
this._updatedSources[layer.source] = 'clear';
} else {
this._updatedSources[layer.source] = 'reload';
this.sourceCaches[layer.source].pause();
}
}
this._updateLayer(layer);
if (layer.onAdd) {
layer.onAdd(this.map);
}
};
Style.prototype.moveLayer = function moveLayer(id, before) {
this._checkLoaded();
this._changed = true;
var layer = this._layers[id];
if (!layer) {
this.fire(new performance.ErrorEvent(new Error('The layer \'' + id + '\' does not exist in the map\'s style and cannot be moved.')));
return;
}
if (id === before) {
return;
}
var index = this._order.indexOf(id);
this._order.splice(index, 1);
var newIndex = before ? this._order.indexOf(before) : this._order.length;
if (before && newIndex === -1) {
this.fire(new performance.ErrorEvent(new Error('Layer with id "' + before + '" does not exist on this map.')));
return;
}
this._order.splice(newIndex, 0, id);
this._layerOrderChanged = true;
};
Style.prototype.removeLayer = function removeLayer(id) {
this._checkLoaded();
var layer = this._layers[id];
if (!layer) {
this.fire(new performance.ErrorEvent(new Error('The layer \'' + id + '\' does not exist in the map\'s style and cannot be removed.')));
return;
}
layer.setEventedParent(null);
var index = this._order.indexOf(id);
this._order.splice(index, 1);
this._layerOrderChanged = true;
this._changed = true;
this._removedLayers[id] = layer;
delete this._layers[id];
delete this._serializedLayers[id];
delete this._updatedLayers[id];
delete this._updatedPaintProps[id];
if (layer.onRemove) {
layer.onRemove(this.map);
}
};
Style.prototype.getLayer = function getLayer(id) {
return this._layers[id];
};
Style.prototype.hasLayer = function hasLayer(id) {
return id in this._layers;
};
Style.prototype.setLayerZoomRange = function setLayerZoomRange(layerId, minzoom, maxzoom) {
this._checkLoaded();
var layer = this.getLayer(layerId);
if (!layer) {
this.fire(new performance.ErrorEvent(new Error('The layer \'' + layerId + '\' does not exist in the map\'s style and cannot have zoom extent.')));
return;
}
if (layer.minzoom === minzoom && layer.maxzoom === maxzoom) {
return;
}
if (minzoom != null) {
layer.minzoom = minzoom;
}
if (maxzoom != null) {
layer.maxzoom = maxzoom;
}
this._updateLayer(layer);
};
Style.prototype.setFilter = function setFilter(layerId, filter, options) {
if (options === void 0)
options = {};
this._checkLoaded();
var layer = this.getLayer(layerId);
if (!layer) {
this.fire(new performance.ErrorEvent(new Error('The layer \'' + layerId + '\' does not exist in the map\'s style and cannot be filtered.')));
return;
}
if (performance.deepEqual(layer.filter, filter)) {
return;
}
if (filter === null || filter === undefined) {
layer.filter = undefined;
this._updateLayer(layer);
return;
}
if (this._validate(performance.validateStyle.filter, 'layers.' + layer.id + '.filter', filter, null, options)) {
return;
}
layer.filter = performance.clone$1(filter);
this._updateLayer(layer);
};
Style.prototype.getFilter = function getFilter(layer) {
return performance.clone$1(this.getLayer(layer).filter);
};
Style.prototype.setLayoutProperty = function setLayoutProperty(layerId, name, value, options) {
if (options === void 0)
options = {};
this._checkLoaded();
var layer = this.getLayer(layerId);
if (!layer) {
this.fire(new performance.ErrorEvent(new Error('The layer \'' + layerId + '\' does not exist in the map\'s style and cannot be styled.')));
return;
}
if (performance.deepEqual(layer.getLayoutProperty(name), value)) {
return;
}
layer.setLayoutProperty(name, value, options);
this._updateLayer(layer);
};
Style.prototype.getLayoutProperty = function getLayoutProperty(layerId, name) {
var layer = this.getLayer(layerId);
if (!layer) {
this.fire(new performance.ErrorEvent(new Error('The layer \'' + layerId + '\' does not exist in the map\'s style.')));
return;
}
return layer.getLayoutProperty(name);
};
Style.prototype.setPaintProperty = function setPaintProperty(layerId, name, value, options) {
if (options === void 0)
options = {};
this._checkLoaded();
var layer = this.getLayer(layerId);
if (!layer) {
this.fire(new performance.ErrorEvent(new Error('The layer \'' + layerId + '\' does not exist in the map\'s style and cannot be styled.')));
return;
}
if (performance.deepEqual(layer.getPaintProperty(name), value)) {
return;
}
var requiresRelayout = layer.setPaintProperty(name, value, options);
if (requiresRelayout) {
this._updateLayer(layer);
}
this._changed = true;
this._updatedPaintProps[layerId] = true;
};
Style.prototype.getPaintProperty = function getPaintProperty(layer, name) {
return this.getLayer(layer).getPaintProperty(name);
};
Style.prototype.setFeatureState = function setFeatureState(target, state) {
this._checkLoaded();
var sourceId = target.source;
var sourceLayer = target.sourceLayer;
var sourceCache = this.sourceCaches[sourceId];
if (sourceCache === undefined) {
this.fire(new performance.ErrorEvent(new Error('The source \'' + sourceId + '\' does not exist in the map\'s style.')));
return;
}
var sourceType = sourceCache.getSource().type;
if (sourceType === 'geojson' && sourceLayer) {
this.fire(new performance.ErrorEvent(new Error('GeoJSON sources cannot have a sourceLayer parameter.')));
return;
}
if (sourceType === 'vector' && !sourceLayer) {
this.fire(new performance.ErrorEvent(new Error('The sourceLayer parameter must be provided for vector source types.')));
return;
}
if (target.id === undefined) {
this.fire(new performance.ErrorEvent(new Error('The feature id parameter must be provided.')));
}
sourceCache.setFeatureState(sourceLayer, target.id, state);
};
Style.prototype.removeFeatureState = function removeFeatureState(target, key) {
this._checkLoaded();
var sourceId = target.source;
var sourceCache = this.sourceCaches[sourceId];
if (sourceCache === undefined) {
this.fire(new performance.ErrorEvent(new Error('The source \'' + sourceId + '\' does not exist in the map\'s style.')));
return;
}
var sourceType = sourceCache.getSource().type;
var sourceLayer = sourceType === 'vector' ? target.sourceLayer : undefined;
if (sourceType === 'vector' && !sourceLayer) {
this.fire(new performance.ErrorEvent(new Error('The sourceLayer parameter must be provided for vector source types.')));
return;
}
if (key && (typeof target.id !== 'string' && typeof target.id !== 'number')) {
this.fire(new performance.ErrorEvent(new Error('A feature id is required to remove its specific state property.')));
return;
}
sourceCache.removeFeatureState(sourceLayer, target.id, key);
};
Style.prototype.getFeatureState = function getFeatureState(target) {
this._checkLoaded();
var sourceId = target.source;
var sourceLayer = target.sourceLayer;
var sourceCache = this.sourceCaches[sourceId];
if (sourceCache === undefined) {
this.fire(new performance.ErrorEvent(new Error('The source \'' + sourceId + '\' does not exist in the map\'s style.')));
return;
}
var sourceType = sourceCache.getSource().type;
if (sourceType === 'vector' && !sourceLayer) {
this.fire(new performance.ErrorEvent(new Error('The sourceLayer parameter must be provided for vector source types.')));
return;
}
if (target.id === undefined) {
this.fire(new performance.ErrorEvent(new Error('The feature id parameter must be provided.')));
}
return sourceCache.getFeatureState(sourceLayer, target.id);
};
Style.prototype.getTransition = function getTransition() {
return performance.extend({
duration: 300,
delay: 0
}, this.stylesheet && this.stylesheet.transition);
};
Style.prototype.serialize = function serialize() {
return performance.filterObject({
version: this.stylesheet.version,
name: this.stylesheet.name,
metadata: this.stylesheet.metadata,
light: this.stylesheet.light,
center: this.stylesheet.center,
zoom: this.stylesheet.zoom,
bearing: this.stylesheet.bearing,
pitch: this.stylesheet.pitch,
sprite: this.stylesheet.sprite,
glyphs: this.stylesheet.glyphs,
transition: this.stylesheet.transition,
sources: performance.mapObject(this.sourceCaches, function (source) {
return source.serialize();
}),
layers: this._serializeLayers(this._order)
}, function (value) {
return value !== undefined;
});
};
Style.prototype._updateLayer = function _updateLayer(layer) {
this._updatedLayers[layer.id] = true;
if (layer.source && !this._updatedSources[layer.source] && this.sourceCaches[layer.source].getSource().type !== 'raster') {
this._updatedSources[layer.source] = 'reload';
this.sourceCaches[layer.source].pause();
}
this._changed = true;
};
Style.prototype._flattenAndSortRenderedFeatures = function _flattenAndSortRenderedFeatures(sourceResults) {
var this$1 = this;
var isLayer3D = function (layerId) {
return this$1._layers[layerId].type === 'fill-extrusion';
};
var layerIndex = {};
var features3D = [];
for (var l = this._order.length - 1; l >= 0; l--) {
var layerId = this._order[l];
if (isLayer3D(layerId)) {
layerIndex[layerId] = l;
for (var i$2 = 0, list$1 = sourceResults; i$2 < list$1.length; i$2 += 1) {
var sourceResult = list$1[i$2];
var layerFeatures = sourceResult[layerId];
if (layerFeatures) {
for (var i$1 = 0, list = layerFeatures; i$1 < list.length; i$1 += 1) {
var featureWrapper = list[i$1];
features3D.push(featureWrapper);
}
}
}
}
}
features3D.sort(function (a, b) {
return b.intersectionZ - a.intersectionZ;
});
var features = [];
for (var l$1 = this._order.length - 1; l$1 >= 0; l$1--) {
var layerId$1 = this._order[l$1];
if (isLayer3D(layerId$1)) {
for (var i = features3D.length - 1; i >= 0; i--) {
var topmost3D = features3D[i].feature;
if (layerIndex[topmost3D.layer.id] < l$1) {
break;
}
features.push(topmost3D);
features3D.pop();
}
} else {
for (var i$4 = 0, list$3 = sourceResults; i$4 < list$3.length; i$4 += 1) {
var sourceResult$1 = list$3[i$4];
var layerFeatures$1 = sourceResult$1[layerId$1];
if (layerFeatures$1) {
for (var i$3 = 0, list$2 = layerFeatures$1; i$3 < list$2.length; i$3 += 1) {
var featureWrapper$1 = list$2[i$3];
features.push(featureWrapper$1.feature);
}
}
}
}
}
return features;
};
Style.prototype.queryRenderedFeatures = function queryRenderedFeatures$1(queryGeometry, params, transform) {
if (params && params.filter) {
this._validate(performance.validateStyle.filter, 'queryRenderedFeatures.filter', params.filter, null, params);
}
var includedSources = {};
if (params && params.layers) {
if (!Array.isArray(params.layers)) {
this.fire(new performance.ErrorEvent(new Error('parameters.layers must be an Array.')));
return [];
}
for (var i = 0, list = params.layers; i < list.length; i += 1) {
var layerId = list[i];
var layer = this._layers[layerId];
if (!layer) {
this.fire(new performance.ErrorEvent(new Error('The layer \'' + layerId + '\' does not exist in the map\'s style and cannot be queried for features.')));
return [];
}
includedSources[layer.source] = true;
}
}
var sourceResults = [];
params.availableImages = this._availableImages;
for (var id in this.sourceCaches) {
if (params.layers && !includedSources[id]) {
continue;
}
sourceResults.push(queryRenderedFeatures(this.sourceCaches[id], this._layers, this._serializedLayers, queryGeometry, params, transform));
}
if (this.placement) {
sourceResults.push(queryRenderedSymbols(this._layers, this._serializedLayers, this.sourceCaches, queryGeometry, params, this.placement.collisionIndex, this.placement.retainedQueryData));
}
return this._flattenAndSortRenderedFeatures(sourceResults);
};
Style.prototype.querySourceFeatures = function querySourceFeatures$1(sourceID, params) {
if (params && params.filter) {
this._validate(performance.validateStyle.filter, 'querySourceFeatures.filter', params.filter, null, params);
}
var sourceCache = this.sourceCaches[sourceID];
return sourceCache ? querySourceFeatures(sourceCache, params) : [];
};
Style.prototype.addSourceType = function addSourceType(name, SourceType, callback) {
if (Style.getSourceType(name)) {
return callback(new Error('A source type called "' + name + '" already exists.'));
}
Style.setSourceType(name, SourceType);
if (!SourceType.workerSourceURL) {
return callback(null, null);
}
this.dispatcher.broadcast('loadWorkerSource', {
name: name,
url: SourceType.workerSourceURL
}, callback);
};
Style.prototype.getLight = function getLight() {
return this.light.getLight();
};
Style.prototype.setLight = function setLight(lightOptions, options) {
if (options === void 0)
options = {};
this._checkLoaded();
var light = this.light.getLight();
var _update = false;
for (var key in lightOptions) {
if (!performance.deepEqual(lightOptions[key], light[key])) {
_update = true;
break;
}
}
if (!_update) {
return;
}
var parameters = {
now: performance.browser.now(),
transition: performance.extend({
duration: 300,
delay: 0
}, this.stylesheet.transition)
};
this.light.setLight(lightOptions, options);
this.light.updateTransitions(parameters);
};
Style.prototype._validate = function _validate(validate, key, value, props, options) {
if (options === void 0)
options = {};
if (options && options.validate === false) {
return false;
}
return emitValidationErrors(this, validate.call(performance.validateStyle, performance.extend({
key: key,
style: this.serialize(),
value: value,
styleSpec: performance.styleSpec
}, props)));
};
Style.prototype._remove = function _remove() {
if (this._request) {
this._request.cancel();
this._request = null;
}
if (this._spriteRequest) {
this._spriteRequest.cancel();
this._spriteRequest = null;
}
performance.evented.off('pluginStateChange', this._rtlTextPluginCallback);
for (var layerId in this._layers) {
var layer = this._layers[layerId];
layer.setEventedParent(null);
}
for (var id in this.sourceCaches) {
this.sourceCaches[id].clearTiles();
this.sourceCaches[id].setEventedParent(null);
}
this.imageManager.setEventedParent(null);
this.setEventedParent(null);
this.dispatcher.remove();
};
Style.prototype._clearSource = function _clearSource(id) {
this.sourceCaches[id].clearTiles();
};
Style.prototype._reloadSource = function _reloadSource(id) {
this.sourceCaches[id].resume();
this.sourceCaches[id].reload();
};
Style.prototype._updateSources = function _updateSources(transform) {
for (var id in this.sourceCaches) {
this.sourceCaches[id].update(transform);
}
};
Style.prototype._generateCollisionBoxes = function _generateCollisionBoxes() {
for (var id in this.sourceCaches) {
this._reloadSource(id);
}
};
Style.prototype._updatePlacement = function _updatePlacement(transform, showCollisionBoxes, fadeDuration, crossSourceCollisions, forceFullPlacement) {
if (forceFullPlacement === void 0)
forceFullPlacement = false;
var symbolBucketsChanged = false;
var placementCommitted = false;
var layerTiles = {};
for (var i = 0, list = this._order; i < list.length; i += 1) {
var layerID = list[i];
var styleLayer = this._layers[layerID];
if (styleLayer.type !== 'symbol') {
continue;
}
if (!layerTiles[styleLayer.source]) {
var sourceCache = this.sourceCaches[styleLayer.source];
layerTiles[styleLayer.source] = sourceCache.getRenderableIds(true).map(function (id) {
return sourceCache.getTileByID(id);
}).sort(function (a, b) {
return b.tileID.overscaledZ - a.tileID.overscaledZ || (a.tileID.isLessThan(b.tileID) ? -1 : 1);
});
}
var layerBucketsChanged = this.crossTileSymbolIndex.addLayer(styleLayer, layerTiles[styleLayer.source], transform.center.lng);
symbolBucketsChanged = symbolBucketsChanged || layerBucketsChanged;
}
this.crossTileSymbolIndex.pruneUnusedLayers(this._order);
forceFullPlacement = forceFullPlacement || this._layerOrderChanged || fadeDuration === 0;
if (forceFullPlacement || !this.pauseablePlacement || this.pauseablePlacement.isDone() && !this.placement.stillRecent(performance.browser.now(), transform.zoom)) {
this.pauseablePlacement = new PauseablePlacement(transform, this._order, forceFullPlacement, showCollisionBoxes, fadeDuration, crossSourceCollisions, this.placement);
this._layerOrderChanged = false;
}
if (this.pauseablePlacement.isDone()) {
this.placement.setStale();
} else {
this.pauseablePlacement.continuePlacement(this._order, this._layers, layerTiles);
if (this.pauseablePlacement.isDone()) {
this.placement = this.pauseablePlacement.commit(performance.browser.now());
placementCommitted = true;
}
if (symbolBucketsChanged) {
this.pauseablePlacement.placement.setStale();
}
}
if (placementCommitted || symbolBucketsChanged) {
for (var i$1 = 0, list$1 = this._order; i$1 < list$1.length; i$1 += 1) {
var layerID$1 = list$1[i$1];
var styleLayer$1 = this._layers[layerID$1];
if (styleLayer$1.type !== 'symbol') {
continue;
}
this.placement.updateLayerOpacities(styleLayer$1, layerTiles[styleLayer$1.source]);
}
}
var needsRerender = !this.pauseablePlacement.isDone() || this.placement.hasTransitions(performance.browser.now());
return needsRerender;
};
Style.prototype._releaseSymbolFadeTiles = function _releaseSymbolFadeTiles() {
for (var id in this.sourceCaches) {
this.sourceCaches[id].releaseSymbolFadeTiles();
}
};
Style.prototype.getImages = function getImages(mapId, params, callback) {
this.imageManager.getImages(params.icons, callback);
this._updateTilesForChangedImages();
var sourceCache = this.sourceCaches[params.source];
if (sourceCache) {
sourceCache.setDependencies(params.tileID.key, params.type, params.icons);
}
};
Style.prototype.getGlyphs = function getGlyphs(mapId, params, callback) {
this.glyphManager.getGlyphs(params.stacks, callback);
};
Style.prototype.getResource = function getResource(mapId, params, callback) {
return performance.makeRequest(params, callback);
};
return Style;
}(performance.Evented);
Style.getSourceType = getType;
Style.setSourceType = setType;
Style.registerForPluginStateChange = performance.registerForPluginStateChange;
var posAttributes = performance.createLayout([{
name: 'a_pos',
type: 'Int16',
components: 2
}]);
var preludeFrag = "#ifdef GL_ES\nprecision mediump float;\n#else\n#if !defined(lowp)\n#define lowp\n#endif\n#if !defined(mediump)\n#define mediump\n#endif\n#if !defined(highp)\n#define highp\n#endif\n#endif";
var preludeVert = "#ifdef GL_ES\nprecision highp float;\n#else\n#if !defined(lowp)\n#define lowp\n#endif\n#if !defined(mediump)\n#define mediump\n#endif\n#if !defined(highp)\n#define highp\n#endif\n#endif\nvec2 unpack_float(const float packedValue) {int packedIntValue=int(packedValue);int v0=packedIntValue/256;return vec2(v0,packedIntValue-v0*256);}vec2 unpack_opacity(const float packedOpacity) {int intOpacity=int(packedOpacity)/2;return vec2(float(intOpacity)/127.0,mod(packedOpacity,2.0));}vec4 decode_color(const vec2 encodedColor) {return vec4(unpack_float(encodedColor[0])/255.0,unpack_float(encodedColor[1])/255.0\n);}float unpack_mix_vec2(const vec2 packedValue,const float t) {return mix(packedValue[0],packedValue[1],t);}vec4 unpack_mix_color(const vec4 packedColors,const float t) {vec4 minColor=decode_color(vec2(packedColors[0],packedColors[1]));vec4 maxColor=decode_color(vec2(packedColors[2],packedColors[3]));return mix(minColor,maxColor,t);}vec2 get_pattern_pos(const vec2 pixel_coord_upper,const vec2 pixel_coord_lower,const vec2 pattern_size,const float tile_units_to_pixels,const vec2 pos) {vec2 offset=mod(mod(mod(pixel_coord_upper,pattern_size)*256.0,pattern_size)*256.0+pixel_coord_lower,pattern_size);return (tile_units_to_pixels*pos+offset)/pattern_size;}";
var backgroundFrag = "uniform vec4 u_color;uniform float u_opacity;void main() {gl_FragColor=u_color*u_opacity;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}";
var backgroundVert = "attribute vec2 a_pos;uniform mat4 u_matrix;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);}";
var backgroundPatternFrag = "uniform vec2 u_pattern_tl_a;uniform vec2 u_pattern_br_a;uniform vec2 u_pattern_tl_b;uniform vec2 u_pattern_br_b;uniform vec2 u_texsize;uniform float u_mix;uniform float u_opacity;uniform sampler2D u_image;varying vec2 v_pos_a;varying vec2 v_pos_b;void main() {vec2 imagecoord=mod(v_pos_a,1.0);vec2 pos=mix(u_pattern_tl_a/u_texsize,u_pattern_br_a/u_texsize,imagecoord);vec4 color1=texture2D(u_image,pos);vec2 imagecoord_b=mod(v_pos_b,1.0);vec2 pos2=mix(u_pattern_tl_b/u_texsize,u_pattern_br_b/u_texsize,imagecoord_b);vec4 color2=texture2D(u_image,pos2);gl_FragColor=mix(color1,color2,u_mix)*u_opacity;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}";
var backgroundPatternVert = "uniform mat4 u_matrix;uniform vec2 u_pattern_size_a;uniform vec2 u_pattern_size_b;uniform vec2 u_pixel_coord_upper;uniform vec2 u_pixel_coord_lower;uniform float u_scale_a;uniform float u_scale_b;uniform float u_tile_units_to_pixels;attribute vec2 a_pos;varying vec2 v_pos_a;varying vec2 v_pos_b;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);v_pos_a=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,u_scale_a*u_pattern_size_a,u_tile_units_to_pixels,a_pos);v_pos_b=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,u_scale_b*u_pattern_size_b,u_tile_units_to_pixels,a_pos);}";
var circleFrag = "varying vec3 v_data;\n#pragma mapbox: define highp vec4 color\n#pragma mapbox: define mediump float radius\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define highp vec4 stroke_color\n#pragma mapbox: define mediump float stroke_width\n#pragma mapbox: define lowp float stroke_opacity\nvoid main() {\n#pragma mapbox: initialize highp vec4 color\n#pragma mapbox: initialize mediump float radius\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize highp vec4 stroke_color\n#pragma mapbox: initialize mediump float stroke_width\n#pragma mapbox: initialize lowp float stroke_opacity\nvec2 extrude=v_data.xy;float extrude_length=length(extrude);lowp float antialiasblur=v_data.z;float antialiased_blur=-max(blur,antialiasblur);float opacity_t=smoothstep(0.0,antialiased_blur,extrude_length-1.0);float color_t=stroke_width < 0.01 ? 0.0 : smoothstep(antialiased_blur,0.0,extrude_length-radius/(radius+stroke_width));gl_FragColor=opacity_t*mix(color*opacity,stroke_color*stroke_opacity,color_t);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}";
var circleVert = "uniform mat4 u_matrix;uniform bool u_scale_with_map;uniform bool u_pitch_with_map;uniform vec2 u_extrude_scale;uniform lowp float u_device_pixel_ratio;uniform highp float u_camera_to_center_distance;attribute vec2 a_pos;varying vec3 v_data;\n#pragma mapbox: define highp vec4 color\n#pragma mapbox: define mediump float radius\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define highp vec4 stroke_color\n#pragma mapbox: define mediump float stroke_width\n#pragma mapbox: define lowp float stroke_opacity\nvoid main(void) {\n#pragma mapbox: initialize highp vec4 color\n#pragma mapbox: initialize mediump float radius\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize highp vec4 stroke_color\n#pragma mapbox: initialize mediump float stroke_width\n#pragma mapbox: initialize lowp float stroke_opacity\nvec2 extrude=vec2(mod(a_pos,2.0)*2.0-1.0);vec2 circle_center=floor(a_pos*0.5);if (u_pitch_with_map) {vec2 corner_position=circle_center;if (u_scale_with_map) {corner_position+=extrude*(radius+stroke_width)*u_extrude_scale;} else {vec4 projected_center=u_matrix*vec4(circle_center,0,1);corner_position+=extrude*(radius+stroke_width)*u_extrude_scale*(projected_center.w/u_camera_to_center_distance);}gl_Position=u_matrix*vec4(corner_position,0,1);} else {gl_Position=u_matrix*vec4(circle_center,0,1);if (u_scale_with_map) {gl_Position.xy+=extrude*(radius+stroke_width)*u_extrude_scale*u_camera_to_center_distance;} else {gl_Position.xy+=extrude*(radius+stroke_width)*u_extrude_scale*gl_Position.w;}}lowp float antialiasblur=1.0/u_device_pixel_ratio/(radius+stroke_width);v_data=vec3(extrude.x,extrude.y,antialiasblur);}";
var clippingMaskFrag = "void main() {gl_FragColor=vec4(1.0);}";
var clippingMaskVert = "attribute vec2 a_pos;uniform mat4 u_matrix;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);}";
var heatmapFrag = "uniform highp float u_intensity;varying vec2 v_extrude;\n#pragma mapbox: define highp float weight\n#define GAUSS_COEF 0.3989422804014327\nvoid main() {\n#pragma mapbox: initialize highp float weight\nfloat d=-0.5*3.0*3.0*dot(v_extrude,v_extrude);float val=weight*u_intensity*GAUSS_COEF*exp(d);gl_FragColor=vec4(val,1.0,1.0,1.0);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}";
var heatmapVert = "uniform mat4 u_matrix;uniform float u_extrude_scale;uniform float u_opacity;uniform float u_intensity;attribute vec2 a_pos;varying vec2 v_extrude;\n#pragma mapbox: define highp float weight\n#pragma mapbox: define mediump float radius\nconst highp float ZERO=1.0/255.0/16.0;\n#define GAUSS_COEF 0.3989422804014327\nvoid main(void) {\n#pragma mapbox: initialize highp float weight\n#pragma mapbox: initialize mediump float radius\nvec2 unscaled_extrude=vec2(mod(a_pos,2.0)*2.0-1.0);float S=sqrt(-2.0*log(ZERO/weight/u_intensity/GAUSS_COEF))/3.0;v_extrude=S*unscaled_extrude;vec2 extrude=v_extrude*radius*u_extrude_scale;vec4 pos=vec4(floor(a_pos*0.5)+extrude,0,1);gl_Position=u_matrix*pos;}";
var heatmapTextureFrag = "uniform sampler2D u_image;uniform sampler2D u_color_ramp;uniform float u_opacity;varying vec2 v_pos;void main() {float t=texture2D(u_image,v_pos).r;vec4 color=texture2D(u_color_ramp,vec2(t,0.5));gl_FragColor=color*u_opacity;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(0.0);\n#endif\n}";
var heatmapTextureVert = "uniform mat4 u_matrix;uniform vec2 u_world;attribute vec2 a_pos;varying vec2 v_pos;void main() {gl_Position=u_matrix*vec4(a_pos*u_world,0,1);v_pos.x=a_pos.x;v_pos.y=1.0-a_pos.y;}";
var collisionBoxFrag = "varying float v_placed;varying float v_notUsed;void main() {float alpha=0.5;gl_FragColor=vec4(1.0,0.0,0.0,1.0)*alpha;if (v_placed > 0.5) {gl_FragColor=vec4(0.0,0.0,1.0,0.5)*alpha;}if (v_notUsed > 0.5) {gl_FragColor*=.1;}}";
var collisionBoxVert = "attribute vec2 a_pos;attribute vec2 a_anchor_pos;attribute vec2 a_extrude;attribute vec2 a_placed;attribute vec2 a_shift;uniform mat4 u_matrix;uniform vec2 u_extrude_scale;uniform float u_camera_to_center_distance;varying float v_placed;varying float v_notUsed;void main() {vec4 projectedPoint=u_matrix*vec4(a_anchor_pos,0,1);highp float camera_to_anchor_distance=projectedPoint.w;highp float collision_perspective_ratio=clamp(0.5+0.5*(u_camera_to_center_distance/camera_to_anchor_distance),0.0,4.0);gl_Position=u_matrix*vec4(a_pos,0.0,1.0);gl_Position.xy+=(a_extrude+a_shift)*u_extrude_scale*gl_Position.w*collision_perspective_ratio;v_placed=a_placed.x;v_notUsed=a_placed.y;}";
var collisionCircleFrag = "varying float v_radius;varying vec2 v_extrude;varying float v_perspective_ratio;varying float v_collision;void main() {float alpha=0.5*min(v_perspective_ratio,1.0);float stroke_radius=0.9*max(v_perspective_ratio,1.0);float distance_to_center=length(v_extrude);float distance_to_edge=abs(distance_to_center-v_radius);float opacity_t=smoothstep(-stroke_radius,0.0,-distance_to_edge);vec4 color=mix(vec4(0.0,0.0,1.0,0.5),vec4(1.0,0.0,0.0,1.0),v_collision);gl_FragColor=color*alpha*opacity_t;}";
var collisionCircleVert = "attribute vec2 a_pos;attribute float a_radius;attribute vec2 a_flags;uniform mat4 u_matrix;uniform mat4 u_inv_matrix;uniform vec2 u_viewport_size;uniform float u_camera_to_center_distance;varying float v_radius;varying vec2 v_extrude;varying float v_perspective_ratio;varying float v_collision;vec3 toTilePosition(vec2 screenPos) {vec4 rayStart=u_inv_matrix*vec4(screenPos,-1.0,1.0);vec4 rayEnd =u_inv_matrix*vec4(screenPos, 1.0,1.0);rayStart.xyz/=rayStart.w;rayEnd.xyz /=rayEnd.w;highp float t=(0.0-rayStart.z)/(rayEnd.z-rayStart.z);return mix(rayStart.xyz,rayEnd.xyz,t);}void main() {vec2 quadCenterPos=a_pos;float radius=a_radius;float collision=a_flags.x;float vertexIdx=a_flags.y;vec2 quadVertexOffset=vec2(mix(-1.0,1.0,float(vertexIdx >=2.0)),mix(-1.0,1.0,float(vertexIdx >=1.0 && vertexIdx <=2.0)));vec2 quadVertexExtent=quadVertexOffset*radius;vec3 tilePos=toTilePosition(quadCenterPos);vec4 clipPos=u_matrix*vec4(tilePos,1.0);highp float camera_to_anchor_distance=clipPos.w;highp float collision_perspective_ratio=clamp(0.5+0.5*(u_camera_to_center_distance/camera_to_anchor_distance),0.0,4.0);float padding_factor=1.2;v_radius=radius;v_extrude=quadVertexExtent*padding_factor;v_perspective_ratio=collision_perspective_ratio;v_collision=collision;gl_Position=vec4(clipPos.xyz/clipPos.w,1.0)+vec4(quadVertexExtent*padding_factor/u_viewport_size*2.0,0.0,0.0);}";
var debugFrag = "uniform highp vec4 u_color;uniform sampler2D u_overlay;varying vec2 v_uv;void main() {vec4 overlay_color=texture2D(u_overlay,v_uv);gl_FragColor=mix(u_color,overlay_color,overlay_color.a);}";
var debugVert = "attribute vec2 a_pos;varying vec2 v_uv;uniform mat4 u_matrix;uniform float u_overlay_scale;void main() {v_uv=a_pos/8192.0;gl_Position=u_matrix*vec4(a_pos*u_overlay_scale,0,1);}";
var fillFrag = "#pragma mapbox: define highp vec4 color\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize highp vec4 color\n#pragma mapbox: initialize lowp float opacity\ngl_FragColor=color*opacity;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}";
var fillVert = "attribute vec2 a_pos;uniform mat4 u_matrix;\n#pragma mapbox: define highp vec4 color\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize highp vec4 color\n#pragma mapbox: initialize lowp float opacity\ngl_Position=u_matrix*vec4(a_pos,0,1);}";
var fillOutlineFrag = "varying vec2 v_pos;\n#pragma mapbox: define highp vec4 outline_color\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize highp vec4 outline_color\n#pragma mapbox: initialize lowp float opacity\nfloat dist=length(v_pos-gl_FragCoord.xy);float alpha=1.0-smoothstep(0.0,1.0,dist);gl_FragColor=outline_color*(alpha*opacity);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}";
var fillOutlineVert = "attribute vec2 a_pos;uniform mat4 u_matrix;uniform vec2 u_world;varying vec2 v_pos;\n#pragma mapbox: define highp vec4 outline_color\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize highp vec4 outline_color\n#pragma mapbox: initialize lowp float opacity\ngl_Position=u_matrix*vec4(a_pos,0,1);v_pos=(gl_Position.xy/gl_Position.w+1.0)/2.0*u_world;}";
var fillOutlinePatternFrag = "uniform vec2 u_texsize;uniform sampler2D u_image;uniform float u_fade;varying vec2 v_pos_a;varying vec2 v_pos_b;varying vec2 v_pos;\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp vec4 pattern_from\n#pragma mapbox: define lowp vec4 pattern_to\nvoid main() {\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize mediump vec4 pattern_from\n#pragma mapbox: initialize mediump vec4 pattern_to\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;vec2 imagecoord=mod(v_pos_a,1.0);vec2 pos=mix(pattern_tl_a/u_texsize,pattern_br_a/u_texsize,imagecoord);vec4 color1=texture2D(u_image,pos);vec2 imagecoord_b=mod(v_pos_b,1.0);vec2 pos2=mix(pattern_tl_b/u_texsize,pattern_br_b/u_texsize,imagecoord_b);vec4 color2=texture2D(u_image,pos2);float dist=length(v_pos-gl_FragCoord.xy);float alpha=1.0-smoothstep(0.0,1.0,dist);gl_FragColor=mix(color1,color2,u_fade)*alpha*opacity;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}";
var fillOutlinePatternVert = "uniform mat4 u_matrix;uniform vec2 u_world;uniform vec2 u_pixel_coord_upper;uniform vec2 u_pixel_coord_lower;uniform vec3 u_scale;attribute vec2 a_pos;varying vec2 v_pos_a;varying vec2 v_pos_b;varying vec2 v_pos;\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp vec4 pattern_from\n#pragma mapbox: define lowp vec4 pattern_to\n#pragma mapbox: define lowp float pixel_ratio_from\n#pragma mapbox: define lowp float pixel_ratio_to\nvoid main() {\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize mediump vec4 pattern_from\n#pragma mapbox: initialize mediump vec4 pattern_to\n#pragma mapbox: initialize lowp float pixel_ratio_from\n#pragma mapbox: initialize lowp float pixel_ratio_to\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;float tileRatio=u_scale.x;float fromScale=u_scale.y;float toScale=u_scale.z;gl_Position=u_matrix*vec4(a_pos,0,1);vec2 display_size_a=(pattern_br_a-pattern_tl_a)/pixel_ratio_from;vec2 display_size_b=(pattern_br_b-pattern_tl_b)/pixel_ratio_to;v_pos_a=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,fromScale*display_size_a,tileRatio,a_pos);v_pos_b=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,toScale*display_size_b,tileRatio,a_pos);v_pos=(gl_Position.xy/gl_Position.w+1.0)/2.0*u_world;}";
var fillPatternFrag = "uniform vec2 u_texsize;uniform float u_fade;uniform sampler2D u_image;varying vec2 v_pos_a;varying vec2 v_pos_b;\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp vec4 pattern_from\n#pragma mapbox: define lowp vec4 pattern_to\nvoid main() {\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize mediump vec4 pattern_from\n#pragma mapbox: initialize mediump vec4 pattern_to\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;vec2 imagecoord=mod(v_pos_a,1.0);vec2 pos=mix(pattern_tl_a/u_texsize,pattern_br_a/u_texsize,imagecoord);vec4 color1=texture2D(u_image,pos);vec2 imagecoord_b=mod(v_pos_b,1.0);vec2 pos2=mix(pattern_tl_b/u_texsize,pattern_br_b/u_texsize,imagecoord_b);vec4 color2=texture2D(u_image,pos2);gl_FragColor=mix(color1,color2,u_fade)*opacity;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}";
var fillPatternVert = "uniform mat4 u_matrix;uniform vec2 u_pixel_coord_upper;uniform vec2 u_pixel_coord_lower;uniform vec3 u_scale;attribute vec2 a_pos;varying vec2 v_pos_a;varying vec2 v_pos_b;\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp vec4 pattern_from\n#pragma mapbox: define lowp vec4 pattern_to\n#pragma mapbox: define lowp float pixel_ratio_from\n#pragma mapbox: define lowp float pixel_ratio_to\nvoid main() {\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize mediump vec4 pattern_from\n#pragma mapbox: initialize mediump vec4 pattern_to\n#pragma mapbox: initialize lowp float pixel_ratio_from\n#pragma mapbox: initialize lowp float pixel_ratio_to\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;float tileZoomRatio=u_scale.x;float fromScale=u_scale.y;float toScale=u_scale.z;vec2 display_size_a=(pattern_br_a-pattern_tl_a)/pixel_ratio_from;vec2 display_size_b=(pattern_br_b-pattern_tl_b)/pixel_ratio_to;gl_Position=u_matrix*vec4(a_pos,0,1);v_pos_a=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,fromScale*display_size_a,tileZoomRatio,a_pos);v_pos_b=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,toScale*display_size_b,tileZoomRatio,a_pos);}";
var fillExtrusionFrag = "varying vec4 v_color;void main() {gl_FragColor=v_color;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}";
var fillExtrusionVert = "uniform mat4 u_matrix;uniform vec3 u_lightcolor;uniform lowp vec3 u_lightpos;uniform lowp float u_lightintensity;uniform float u_vertical_gradient;uniform lowp float u_opacity;attribute vec2 a_pos;attribute vec4 a_normal_ed;varying vec4 v_color;\n#pragma mapbox: define highp float base\n#pragma mapbox: define highp float height\n#pragma mapbox: define highp vec4 color\nvoid main() {\n#pragma mapbox: initialize highp float base\n#pragma mapbox: initialize highp float height\n#pragma mapbox: initialize highp vec4 color\nvec3 normal=a_normal_ed.xyz;base=max(0.0,base);height=max(0.0,height);float t=mod(normal.x,2.0);gl_Position=u_matrix*vec4(a_pos,t > 0.0 ? height : base,1);float colorvalue=color.r*0.2126+color.g*0.7152+color.b*0.0722;v_color=vec4(0.0,0.0,0.0,1.0);vec4 ambientlight=vec4(0.03,0.03,0.03,1.0);color+=ambientlight;float directional=clamp(dot(normal/16384.0,u_lightpos),0.0,1.0);directional=mix((1.0-u_lightintensity),max((1.0-colorvalue+u_lightintensity),1.0),directional);if (normal.y !=0.0) {directional*=((1.0-u_vertical_gradient)+(u_vertical_gradient*clamp((t+base)*pow(height/150.0,0.5),mix(0.7,0.98,1.0-u_lightintensity),1.0)));}v_color.r+=clamp(color.r*directional*u_lightcolor.r,mix(0.0,0.3,1.0-u_lightcolor.r),1.0);v_color.g+=clamp(color.g*directional*u_lightcolor.g,mix(0.0,0.3,1.0-u_lightcolor.g),1.0);v_color.b+=clamp(color.b*directional*u_lightcolor.b,mix(0.0,0.3,1.0-u_lightcolor.b),1.0);v_color*=u_opacity;}";
var fillExtrusionPatternFrag = "uniform vec2 u_texsize;uniform float u_fade;uniform sampler2D u_image;varying vec2 v_pos_a;varying vec2 v_pos_b;varying vec4 v_lighting;\n#pragma mapbox: define lowp float base\n#pragma mapbox: define lowp float height\n#pragma mapbox: define lowp vec4 pattern_from\n#pragma mapbox: define lowp vec4 pattern_to\n#pragma mapbox: define lowp float pixel_ratio_from\n#pragma mapbox: define lowp float pixel_ratio_to\nvoid main() {\n#pragma mapbox: initialize lowp float base\n#pragma mapbox: initialize lowp float height\n#pragma mapbox: initialize mediump vec4 pattern_from\n#pragma mapbox: initialize mediump vec4 pattern_to\n#pragma mapbox: initialize lowp float pixel_ratio_from\n#pragma mapbox: initialize lowp float pixel_ratio_to\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;vec2 imagecoord=mod(v_pos_a,1.0);vec2 pos=mix(pattern_tl_a/u_texsize,pattern_br_a/u_texsize,imagecoord);vec4 color1=texture2D(u_image,pos);vec2 imagecoord_b=mod(v_pos_b,1.0);vec2 pos2=mix(pattern_tl_b/u_texsize,pattern_br_b/u_texsize,imagecoord_b);vec4 color2=texture2D(u_image,pos2);vec4 mixedColor=mix(color1,color2,u_fade);gl_FragColor=mixedColor*v_lighting;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}";
var fillExtrusionPatternVert = "uniform mat4 u_matrix;uniform vec2 u_pixel_coord_upper;uniform vec2 u_pixel_coord_lower;uniform float u_height_factor;uniform vec3 u_scale;uniform float u_vertical_gradient;uniform lowp float u_opacity;uniform vec3 u_lightcolor;uniform lowp vec3 u_lightpos;uniform lowp float u_lightintensity;attribute vec2 a_pos;attribute vec4 a_normal_ed;varying vec2 v_pos_a;varying vec2 v_pos_b;varying vec4 v_lighting;\n#pragma mapbox: define lowp float base\n#pragma mapbox: define lowp float height\n#pragma mapbox: define lowp vec4 pattern_from\n#pragma mapbox: define lowp vec4 pattern_to\n#pragma mapbox: define lowp float pixel_ratio_from\n#pragma mapbox: define lowp float pixel_ratio_to\nvoid main() {\n#pragma mapbox: initialize lowp float base\n#pragma mapbox: initialize lowp float height\n#pragma mapbox: initialize mediump vec4 pattern_from\n#pragma mapbox: initialize mediump vec4 pattern_to\n#pragma mapbox: initialize lowp float pixel_ratio_from\n#pragma mapbox: initialize lowp float pixel_ratio_to\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;float tileRatio=u_scale.x;float fromScale=u_scale.y;float toScale=u_scale.z;vec3 normal=a_normal_ed.xyz;float edgedistance=a_normal_ed.w;vec2 display_size_a=(pattern_br_a-pattern_tl_a)/pixel_ratio_from;vec2 display_size_b=(pattern_br_b-pattern_tl_b)/pixel_ratio_to;base=max(0.0,base);height=max(0.0,height);float t=mod(normal.x,2.0);float z=t > 0.0 ? height : base;gl_Position=u_matrix*vec4(a_pos,z,1);vec2 pos=normal.x==1.0 && normal.y==0.0 && normal.z==16384.0\n? a_pos\n: vec2(edgedistance,z*u_height_factor);v_pos_a=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,fromScale*display_size_a,tileRatio,pos);v_pos_b=get_pattern_pos(u_pixel_coord_upper,u_pixel_coord_lower,toScale*display_size_b,tileRatio,pos);v_lighting=vec4(0.0,0.0,0.0,1.0);float directional=clamp(dot(normal/16383.0,u_lightpos),0.0,1.0);directional=mix((1.0-u_lightintensity),max((0.5+u_lightintensity),1.0),directional);if (normal.y !=0.0) {directional*=((1.0-u_vertical_gradient)+(u_vertical_gradient*clamp((t+base)*pow(height/150.0,0.5),mix(0.7,0.98,1.0-u_lightintensity),1.0)));}v_lighting.rgb+=clamp(directional*u_lightcolor,mix(vec3(0.0),vec3(0.3),1.0-u_lightcolor),vec3(1.0));v_lighting*=u_opacity;}";
var hillshadePrepareFrag = "#ifdef GL_ES\nprecision highp float;\n#endif\nuniform sampler2D u_image;varying vec2 v_pos;uniform vec2 u_dimension;uniform float u_zoom;uniform vec4 u_unpack;float getElevation(vec2 coord,float bias) {vec4 data=texture2D(u_image,coord)*255.0;data.a=-1.0;return dot(data,u_unpack)/4.0;}void main() {vec2 epsilon=1.0/u_dimension;float a=getElevation(v_pos+vec2(-epsilon.x,-epsilon.y),0.0);float b=getElevation(v_pos+vec2(0,-epsilon.y),0.0);float c=getElevation(v_pos+vec2(epsilon.x,-epsilon.y),0.0);float d=getElevation(v_pos+vec2(-epsilon.x,0),0.0);float e=getElevation(v_pos,0.0);float f=getElevation(v_pos+vec2(epsilon.x,0),0.0);float g=getElevation(v_pos+vec2(-epsilon.x,epsilon.y),0.0);float h=getElevation(v_pos+vec2(0,epsilon.y),0.0);float i=getElevation(v_pos+vec2(epsilon.x,epsilon.y),0.0);float exaggerationFactor=u_zoom < 2.0 ? 0.4 : u_zoom < 4.5 ? 0.35 : 0.3;float exaggeration=u_zoom < 15.0 ? (u_zoom-15.0)*exaggerationFactor : 0.0;vec2 deriv=vec2((c+f+f+i)-(a+d+d+g),(g+h+h+i)-(a+b+b+c))/pow(2.0,exaggeration+(19.2562-u_zoom));gl_FragColor=clamp(vec4(deriv.x/2.0+0.5,deriv.y/2.0+0.5,1.0,1.0),0.0,1.0);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}";
var hillshadePrepareVert = "uniform mat4 u_matrix;uniform vec2 u_dimension;attribute vec2 a_pos;attribute vec2 a_texture_pos;varying vec2 v_pos;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);highp vec2 epsilon=1.0/u_dimension;float scale=(u_dimension.x-2.0)/u_dimension.x;v_pos=(a_texture_pos/8192.0)*scale+epsilon;}";
var hillshadeFrag = "uniform sampler2D u_image;varying vec2 v_pos;uniform vec2 u_latrange;uniform vec2 u_light;uniform vec4 u_shadow;uniform vec4 u_highlight;uniform vec4 u_accent;\n#define PI 3.141592653589793\nvoid main() {vec4 pixel=texture2D(u_image,v_pos);vec2 deriv=((pixel.rg*2.0)-1.0);float scaleFactor=cos(radians((u_latrange[0]-u_latrange[1])*(1.0-v_pos.y)+u_latrange[1]));float slope=atan(1.25*length(deriv)/scaleFactor);float aspect=deriv.x !=0.0 ? atan(deriv.y,-deriv.x) : PI/2.0*(deriv.y > 0.0 ? 1.0 :-1.0);float intensity=u_light.x;float azimuth=u_light.y+PI;float base=1.875-intensity*1.75;float maxValue=0.5*PI;float scaledSlope=intensity !=0.5 ? ((pow(base,slope)-1.0)/(pow(base,maxValue)-1.0))*maxValue : slope;float accent=cos(scaledSlope);vec4 accent_color=(1.0-accent)*u_accent*clamp(intensity*2.0,0.0,1.0);float shade=abs(mod((aspect+azimuth)/PI+0.5,2.0)-1.0);vec4 shade_color=mix(u_shadow,u_highlight,shade)*sin(scaledSlope)*clamp(intensity*2.0,0.0,1.0);gl_FragColor=accent_color*(1.0-shade_color.a)+shade_color;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}";
var hillshadeVert = "uniform mat4 u_matrix;attribute vec2 a_pos;attribute vec2 a_texture_pos;varying vec2 v_pos;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);v_pos=a_texture_pos/8192.0;}";
var lineFrag = "uniform lowp float u_device_pixel_ratio;varying vec2 v_width2;varying vec2 v_normal;varying float v_gamma_scale;\n#pragma mapbox: define highp vec4 color\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize highp vec4 color\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\nfloat dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);gl_FragColor=color*(alpha*opacity);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}";
var lineVert = "\n#define scale 0.015873016\nattribute vec2 a_pos_normal;attribute vec4 a_data;uniform mat4 u_matrix;uniform mediump float u_ratio;uniform vec2 u_units_to_pixels;uniform lowp float u_device_pixel_ratio;varying vec2 v_normal;varying vec2 v_width2;varying float v_gamma_scale;varying highp float v_linesofar;\n#pragma mapbox: define highp vec4 color\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define mediump float gapwidth\n#pragma mapbox: define lowp float offset\n#pragma mapbox: define mediump float width\nvoid main() {\n#pragma mapbox: initialize highp vec4 color\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize mediump float gapwidth\n#pragma mapbox: initialize lowp float offset\n#pragma mapbox: initialize mediump float width\nfloat ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;v_linesofar=(floor(a_data.z/4.0)+a_data.w*64.0)*2.0;vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);vec4 projected_extrude=u_matrix*vec4(dist/u_ratio,0.0,0.0);gl_Position=u_matrix*vec4(pos+offset2/u_ratio,0.0,1.0)+projected_extrude;float extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length(projected_extrude.xy/gl_Position.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;v_width2=vec2(outset,inset);}";
var lineGradientFrag = "uniform lowp float u_device_pixel_ratio;uniform sampler2D u_image;varying vec2 v_width2;varying vec2 v_normal;varying float v_gamma_scale;varying highp vec2 v_uv;\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\nfloat dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);vec4 color=texture2D(u_image,v_uv);gl_FragColor=color*(alpha*opacity);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}";
var lineGradientVert = "\n#define scale 0.015873016\nattribute vec2 a_pos_normal;attribute vec4 a_data;attribute float a_uv_x;attribute float a_split_index;uniform mat4 u_matrix;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;uniform vec2 u_units_to_pixels;uniform float u_image_height;varying vec2 v_normal;varying vec2 v_width2;varying float v_gamma_scale;varying highp vec2 v_uv;\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define mediump float gapwidth\n#pragma mapbox: define lowp float offset\n#pragma mapbox: define mediump float width\nvoid main() {\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize mediump float gapwidth\n#pragma mapbox: initialize lowp float offset\n#pragma mapbox: initialize mediump float width\nfloat ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;highp float texel_height=1.0/u_image_height;highp float half_texel_height=0.5*texel_height;v_uv=vec2(a_uv_x,a_split_index*texel_height-half_texel_height);vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);vec4 projected_extrude=u_matrix*vec4(dist/u_ratio,0.0,0.0);gl_Position=u_matrix*vec4(pos+offset2/u_ratio,0.0,1.0)+projected_extrude;float extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length(projected_extrude.xy/gl_Position.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;v_width2=vec2(outset,inset);}";
var linePatternFrag = "uniform lowp float u_device_pixel_ratio;uniform vec2 u_texsize;uniform float u_fade;uniform mediump vec3 u_scale;uniform sampler2D u_image;varying vec2 v_normal;varying vec2 v_width2;varying float v_linesofar;varying float v_gamma_scale;varying float v_width;\n#pragma mapbox: define lowp vec4 pattern_from\n#pragma mapbox: define lowp vec4 pattern_to\n#pragma mapbox: define lowp float pixel_ratio_from\n#pragma mapbox: define lowp float pixel_ratio_to\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize mediump vec4 pattern_from\n#pragma mapbox: initialize mediump vec4 pattern_to\n#pragma mapbox: initialize lowp float pixel_ratio_from\n#pragma mapbox: initialize lowp float pixel_ratio_to\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\nvec2 pattern_tl_a=pattern_from.xy;vec2 pattern_br_a=pattern_from.zw;vec2 pattern_tl_b=pattern_to.xy;vec2 pattern_br_b=pattern_to.zw;float tileZoomRatio=u_scale.x;float fromScale=u_scale.y;float toScale=u_scale.z;vec2 display_size_a=(pattern_br_a-pattern_tl_a)/pixel_ratio_from;vec2 display_size_b=(pattern_br_b-pattern_tl_b)/pixel_ratio_to;vec2 pattern_size_a=vec2(display_size_a.x*fromScale/tileZoomRatio,display_size_a.y);vec2 pattern_size_b=vec2(display_size_b.x*toScale/tileZoomRatio,display_size_b.y);float aspect_a=display_size_a.y/v_width;float aspect_b=display_size_b.y/v_width;float dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);float x_a=mod(v_linesofar/pattern_size_a.x*aspect_a,1.0);float x_b=mod(v_linesofar/pattern_size_b.x*aspect_b,1.0);float y=0.5*v_normal.y+0.5;vec2 texel_size=1.0/u_texsize;vec2 pos_a=mix(pattern_tl_a*texel_size-texel_size,pattern_br_a*texel_size+texel_size,vec2(x_a,y));vec2 pos_b=mix(pattern_tl_b*texel_size-texel_size,pattern_br_b*texel_size+texel_size,vec2(x_b,y));vec4 color=mix(texture2D(u_image,pos_a),texture2D(u_image,pos_b),u_fade);gl_FragColor=color*alpha*opacity;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}";
var linePatternVert = "\n#define scale 0.015873016\n#define LINE_DISTANCE_SCALE 2.0\nattribute vec2 a_pos_normal;attribute vec4 a_data;uniform mat4 u_matrix;uniform vec2 u_units_to_pixels;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;varying vec2 v_normal;varying vec2 v_width2;varying float v_linesofar;varying float v_gamma_scale;varying float v_width;\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp float offset\n#pragma mapbox: define mediump float gapwidth\n#pragma mapbox: define mediump float width\n#pragma mapbox: define lowp float floorwidth\n#pragma mapbox: define lowp vec4 pattern_from\n#pragma mapbox: define lowp vec4 pattern_to\n#pragma mapbox: define lowp float pixel_ratio_from\n#pragma mapbox: define lowp float pixel_ratio_to\nvoid main() {\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize lowp float offset\n#pragma mapbox: initialize mediump float gapwidth\n#pragma mapbox: initialize mediump float width\n#pragma mapbox: initialize lowp float floorwidth\n#pragma mapbox: initialize mediump vec4 pattern_from\n#pragma mapbox: initialize mediump vec4 pattern_to\n#pragma mapbox: initialize lowp float pixel_ratio_from\n#pragma mapbox: initialize lowp float pixel_ratio_to\nfloat ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;float a_linesofar=(floor(a_data.z/4.0)+a_data.w*64.0)*LINE_DISTANCE_SCALE;vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);vec4 projected_extrude=u_matrix*vec4(dist/u_ratio,0.0,0.0);gl_Position=u_matrix*vec4(pos+offset2/u_ratio,0.0,1.0)+projected_extrude;float extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length(projected_extrude.xy/gl_Position.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;v_linesofar=a_linesofar;v_width2=vec2(outset,inset);v_width=floorwidth;}";
var lineSDFFrag = "uniform lowp float u_device_pixel_ratio;uniform sampler2D u_image;uniform float u_sdfgamma;uniform float u_mix;varying vec2 v_normal;varying vec2 v_width2;varying vec2 v_tex_a;varying vec2 v_tex_b;varying float v_gamma_scale;\n#pragma mapbox: define highp vec4 color\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define mediump float width\n#pragma mapbox: define lowp float floorwidth\nvoid main() {\n#pragma mapbox: initialize highp vec4 color\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize mediump float width\n#pragma mapbox: initialize lowp float floorwidth\nfloat dist=length(v_normal)*v_width2.s;float blur2=(blur+1.0/u_device_pixel_ratio)*v_gamma_scale;float alpha=clamp(min(dist-(v_width2.t-blur2),v_width2.s-dist)/blur2,0.0,1.0);float sdfdist_a=texture2D(u_image,v_tex_a).a;float sdfdist_b=texture2D(u_image,v_tex_b).a;float sdfdist=mix(sdfdist_a,sdfdist_b,u_mix);alpha*=smoothstep(0.5-u_sdfgamma/floorwidth,0.5+u_sdfgamma/floorwidth,sdfdist);gl_FragColor=color*(alpha*opacity);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}";
var lineSDFVert = "\n#define scale 0.015873016\n#define LINE_DISTANCE_SCALE 2.0\nattribute vec2 a_pos_normal;attribute vec4 a_data;uniform mat4 u_matrix;uniform mediump float u_ratio;uniform lowp float u_device_pixel_ratio;uniform vec2 u_patternscale_a;uniform float u_tex_y_a;uniform vec2 u_patternscale_b;uniform float u_tex_y_b;uniform vec2 u_units_to_pixels;varying vec2 v_normal;varying vec2 v_width2;varying vec2 v_tex_a;varying vec2 v_tex_b;varying float v_gamma_scale;\n#pragma mapbox: define highp vec4 color\n#pragma mapbox: define lowp float blur\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define mediump float gapwidth\n#pragma mapbox: define lowp float offset\n#pragma mapbox: define mediump float width\n#pragma mapbox: define lowp float floorwidth\nvoid main() {\n#pragma mapbox: initialize highp vec4 color\n#pragma mapbox: initialize lowp float blur\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize mediump float gapwidth\n#pragma mapbox: initialize lowp float offset\n#pragma mapbox: initialize mediump float width\n#pragma mapbox: initialize lowp float floorwidth\nfloat ANTIALIASING=1.0/u_device_pixel_ratio/2.0;vec2 a_extrude=a_data.xy-128.0;float a_direction=mod(a_data.z,4.0)-1.0;float a_linesofar=(floor(a_data.z/4.0)+a_data.w*64.0)*LINE_DISTANCE_SCALE;vec2 pos=floor(a_pos_normal*0.5);mediump vec2 normal=a_pos_normal-2.0*pos;normal.y=normal.y*2.0-1.0;v_normal=normal;gapwidth=gapwidth/2.0;float halfwidth=width/2.0;offset=-1.0*offset;float inset=gapwidth+(gapwidth > 0.0 ? ANTIALIASING : 0.0);float outset=gapwidth+halfwidth*(gapwidth > 0.0 ? 2.0 : 1.0)+(halfwidth==0.0 ? 0.0 : ANTIALIASING);mediump vec2 dist=outset*a_extrude*scale;mediump float u=0.5*a_direction;mediump float t=1.0-abs(u);mediump vec2 offset2=offset*a_extrude*scale*normal.y*mat2(t,-u,u,t);vec4 projected_extrude=u_matrix*vec4(dist/u_ratio,0.0,0.0);gl_Position=u_matrix*vec4(pos+offset2/u_ratio,0.0,1.0)+projected_extrude;float extrude_length_without_perspective=length(dist);float extrude_length_with_perspective=length(projected_extrude.xy/gl_Position.w*u_units_to_pixels);v_gamma_scale=extrude_length_without_perspective/extrude_length_with_perspective;v_tex_a=vec2(a_linesofar*u_patternscale_a.x/floorwidth,normal.y*u_patternscale_a.y+u_tex_y_a);v_tex_b=vec2(a_linesofar*u_patternscale_b.x/floorwidth,normal.y*u_patternscale_b.y+u_tex_y_b);v_width2=vec2(outset,inset);}";
var rasterFrag = "uniform float u_fade_t;uniform float u_opacity;uniform sampler2D u_image0;uniform sampler2D u_image1;varying vec2 v_pos0;varying vec2 v_pos1;uniform float u_brightness_low;uniform float u_brightness_high;uniform float u_saturation_factor;uniform float u_contrast_factor;uniform vec3 u_spin_weights;void main() {vec4 color0=texture2D(u_image0,v_pos0);vec4 color1=texture2D(u_image1,v_pos1);if (color0.a > 0.0) {color0.rgb=color0.rgb/color0.a;}if (color1.a > 0.0) {color1.rgb=color1.rgb/color1.a;}vec4 color=mix(color0,color1,u_fade_t);color.a*=u_opacity;vec3 rgb=color.rgb;rgb=vec3(dot(rgb,u_spin_weights.xyz),dot(rgb,u_spin_weights.zxy),dot(rgb,u_spin_weights.yzx));float average=(color.r+color.g+color.b)/3.0;rgb+=(average-rgb)*u_saturation_factor;rgb=(rgb-0.5)*u_contrast_factor+0.5;vec3 u_high_vec=vec3(u_brightness_low,u_brightness_low,u_brightness_low);vec3 u_low_vec=vec3(u_brightness_high,u_brightness_high,u_brightness_high);gl_FragColor=vec4(mix(u_high_vec,u_low_vec,rgb)*color.a,color.a);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}";
var rasterVert = "uniform mat4 u_matrix;uniform vec2 u_tl_parent;uniform float u_scale_parent;uniform float u_buffer_scale;attribute vec2 a_pos;attribute vec2 a_texture_pos;varying vec2 v_pos0;varying vec2 v_pos1;void main() {gl_Position=u_matrix*vec4(a_pos,0,1);v_pos0=(((a_texture_pos/8192.0)-0.5)/u_buffer_scale )+0.5;v_pos1=(v_pos0*u_scale_parent)+u_tl_parent;}";
var symbolIconFrag = "uniform sampler2D u_texture;varying vec2 v_tex;varying float v_fade_opacity;\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize lowp float opacity\nlowp float alpha=opacity*v_fade_opacity;gl_FragColor=texture2D(u_texture,v_tex)*alpha;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}";
var symbolIconVert = "const float PI=3.141592653589793;attribute vec4 a_pos_offset;attribute vec4 a_data;attribute vec4 a_pixeloffset;attribute vec3 a_projected_pos;attribute float a_fade_opacity;uniform bool u_is_size_zoom_constant;uniform bool u_is_size_feature_constant;uniform highp float u_size_t;uniform highp float u_size;uniform highp float u_camera_to_center_distance;uniform highp float u_pitch;uniform bool u_rotate_symbol;uniform highp float u_aspect_ratio;uniform float u_fade_change;uniform mat4 u_matrix;uniform mat4 u_label_plane_matrix;uniform mat4 u_coord_matrix;uniform bool u_is_text;uniform bool u_pitch_with_map;uniform vec2 u_texsize;varying vec2 v_tex;varying float v_fade_opacity;\n#pragma mapbox: define lowp float opacity\nvoid main() {\n#pragma mapbox: initialize lowp float opacity\nvec2 a_pos=a_pos_offset.xy;vec2 a_offset=a_pos_offset.zw;vec2 a_tex=a_data.xy;vec2 a_size=a_data.zw;float a_size_min=floor(a_size[0]*0.5);vec2 a_pxoffset=a_pixeloffset.xy;vec2 a_minFontScale=a_pixeloffset.zw/256.0;highp float segment_angle=-a_projected_pos[2];float size;if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {size=mix(a_size_min,a_size[1],u_size_t)/128.0;} else if (u_is_size_zoom_constant && !u_is_size_feature_constant) {size=a_size_min/128.0;} else {size=u_size;}vec4 projectedPoint=u_matrix*vec4(a_pos,0,1);highp float camera_to_anchor_distance=projectedPoint.w;highp float distance_ratio=u_pitch_with_map ?\ncamera_to_anchor_distance/u_camera_to_center_distance :\nu_camera_to_center_distance/camera_to_anchor_distance;highp float perspective_ratio=clamp(0.5+0.5*distance_ratio,0.0,4.0);size*=perspective_ratio;float fontScale=u_is_text ? size/24.0 : size;highp float symbol_rotation=0.0;if (u_rotate_symbol) {vec4 offsetProjectedPoint=u_matrix*vec4(a_pos+vec2(1,0),0,1);vec2 a=projectedPoint.xy/projectedPoint.w;vec2 b=offsetProjectedPoint.xy/offsetProjectedPoint.w;symbol_rotation=atan((b.y-a.y)/u_aspect_ratio,b.x-a.x);}highp float angle_sin=sin(segment_angle+symbol_rotation);highp float angle_cos=cos(segment_angle+symbol_rotation);mat2 rotation_matrix=mat2(angle_cos,-1.0*angle_sin,angle_sin,angle_cos);vec4 projected_pos=u_label_plane_matrix*vec4(a_projected_pos.xy,0.0,1.0);gl_Position=u_coord_matrix*vec4(projected_pos.xy/projected_pos.w+rotation_matrix*(a_offset/32.0*max(a_minFontScale,fontScale)+a_pxoffset/16.0),0.0,1.0);v_tex=a_tex/u_texsize;vec2 fade_opacity=unpack_opacity(a_fade_opacity);float fade_change=fade_opacity[1] > 0.5 ? u_fade_change :-u_fade_change;v_fade_opacity=max(0.0,min(1.0,fade_opacity[0]+fade_change));}";
var symbolSDFFrag = "#define SDF_PX 8.0\nuniform bool u_is_halo;uniform sampler2D u_texture;uniform highp float u_gamma_scale;uniform lowp float u_device_pixel_ratio;uniform bool u_is_text;varying vec2 v_data0;varying vec3 v_data1;\n#pragma mapbox: define highp vec4 fill_color\n#pragma mapbox: define highp vec4 halo_color\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp float halo_width\n#pragma mapbox: define lowp float halo_blur\nvoid main() {\n#pragma mapbox: initialize highp vec4 fill_color\n#pragma mapbox: initialize highp vec4 halo_color\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize lowp float halo_width\n#pragma mapbox: initialize lowp float halo_blur\nfloat EDGE_GAMMA=0.105/u_device_pixel_ratio;vec2 tex=v_data0.xy;float gamma_scale=v_data1.x;float size=v_data1.y;float fade_opacity=v_data1[2];float fontScale=u_is_text ? size/24.0 : size;lowp vec4 color=fill_color;highp float gamma=EDGE_GAMMA/(fontScale*u_gamma_scale);lowp float buff=(256.0-64.0)/256.0;if (u_is_halo) {color=halo_color;gamma=(halo_blur*1.19/SDF_PX+EDGE_GAMMA)/(fontScale*u_gamma_scale);buff=(6.0-halo_width/fontScale)/SDF_PX;}lowp float dist=texture2D(u_texture,tex).a;highp float gamma_scaled=gamma*gamma_scale;highp float alpha=smoothstep(buff-gamma_scaled,buff+gamma_scaled,dist);gl_FragColor=color*(alpha*opacity*fade_opacity);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}";
var symbolSDFVert = "const float PI=3.141592653589793;attribute vec4 a_pos_offset;attribute vec4 a_data;attribute vec4 a_pixeloffset;attribute vec3 a_projected_pos;attribute float a_fade_opacity;uniform bool u_is_size_zoom_constant;uniform bool u_is_size_feature_constant;uniform highp float u_size_t;uniform highp float u_size;uniform mat4 u_matrix;uniform mat4 u_label_plane_matrix;uniform mat4 u_coord_matrix;uniform bool u_is_text;uniform bool u_pitch_with_map;uniform highp float u_pitch;uniform bool u_rotate_symbol;uniform highp float u_aspect_ratio;uniform highp float u_camera_to_center_distance;uniform float u_fade_change;uniform vec2 u_texsize;varying vec2 v_data0;varying vec3 v_data1;\n#pragma mapbox: define highp vec4 fill_color\n#pragma mapbox: define highp vec4 halo_color\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp float halo_width\n#pragma mapbox: define lowp float halo_blur\nvoid main() {\n#pragma mapbox: initialize highp vec4 fill_color\n#pragma mapbox: initialize highp vec4 halo_color\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize lowp float halo_width\n#pragma mapbox: initialize lowp float halo_blur\nvec2 a_pos=a_pos_offset.xy;vec2 a_offset=a_pos_offset.zw;vec2 a_tex=a_data.xy;vec2 a_size=a_data.zw;float a_size_min=floor(a_size[0]*0.5);vec2 a_pxoffset=a_pixeloffset.xy;highp float segment_angle=-a_projected_pos[2];float size;if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {size=mix(a_size_min,a_size[1],u_size_t)/128.0;} else if (u_is_size_zoom_constant && !u_is_size_feature_constant) {size=a_size_min/128.0;} else {size=u_size;}vec4 projectedPoint=u_matrix*vec4(a_pos,0,1);highp float camera_to_anchor_distance=projectedPoint.w;highp float distance_ratio=u_pitch_with_map ?\ncamera_to_anchor_distance/u_camera_to_center_distance :\nu_camera_to_center_distance/camera_to_anchor_distance;highp float perspective_ratio=clamp(0.5+0.5*distance_ratio,0.0,4.0);size*=perspective_ratio;float fontScale=u_is_text ? size/24.0 : size;highp float symbol_rotation=0.0;if (u_rotate_symbol) {vec4 offsetProjectedPoint=u_matrix*vec4(a_pos+vec2(1,0),0,1);vec2 a=projectedPoint.xy/projectedPoint.w;vec2 b=offsetProjectedPoint.xy/offsetProjectedPoint.w;symbol_rotation=atan((b.y-a.y)/u_aspect_ratio,b.x-a.x);}highp float angle_sin=sin(segment_angle+symbol_rotation);highp float angle_cos=cos(segment_angle+symbol_rotation);mat2 rotation_matrix=mat2(angle_cos,-1.0*angle_sin,angle_sin,angle_cos);vec4 projected_pos=u_label_plane_matrix*vec4(a_projected_pos.xy,0.0,1.0);gl_Position=u_coord_matrix*vec4(projected_pos.xy/projected_pos.w+rotation_matrix*(a_offset/32.0*fontScale+a_pxoffset),0.0,1.0);float gamma_scale=gl_Position.w;vec2 fade_opacity=unpack_opacity(a_fade_opacity);float fade_change=fade_opacity[1] > 0.5 ? u_fade_change :-u_fade_change;float interpolated_fade_opacity=max(0.0,min(1.0,fade_opacity[0]+fade_change));v_data0=a_tex/u_texsize;v_data1=vec3(gamma_scale,size,interpolated_fade_opacity);}";
var symbolTextAndIconFrag = "#define SDF_PX 8.0\n#define SDF 1.0\n#define ICON 0.0\nuniform bool u_is_halo;uniform sampler2D u_texture;uniform sampler2D u_texture_icon;uniform highp float u_gamma_scale;uniform lowp float u_device_pixel_ratio;varying vec4 v_data0;varying vec4 v_data1;\n#pragma mapbox: define highp vec4 fill_color\n#pragma mapbox: define highp vec4 halo_color\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp float halo_width\n#pragma mapbox: define lowp float halo_blur\nvoid main() {\n#pragma mapbox: initialize highp vec4 fill_color\n#pragma mapbox: initialize highp vec4 halo_color\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize lowp float halo_width\n#pragma mapbox: initialize lowp float halo_blur\nfloat fade_opacity=v_data1[2];if (v_data1.w==ICON) {vec2 tex_icon=v_data0.zw;lowp float alpha=opacity*fade_opacity;gl_FragColor=texture2D(u_texture_icon,tex_icon)*alpha;\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\nreturn;}vec2 tex=v_data0.xy;float EDGE_GAMMA=0.105/u_device_pixel_ratio;float gamma_scale=v_data1.x;float size=v_data1.y;float fontScale=size/24.0;lowp vec4 color=fill_color;highp float gamma=EDGE_GAMMA/(fontScale*u_gamma_scale);lowp float buff=(256.0-64.0)/256.0;if (u_is_halo) {color=halo_color;gamma=(halo_blur*1.19/SDF_PX+EDGE_GAMMA)/(fontScale*u_gamma_scale);buff=(6.0-halo_width/fontScale)/SDF_PX;}lowp float dist=texture2D(u_texture,tex).a;highp float gamma_scaled=gamma*gamma_scale;highp float alpha=smoothstep(buff-gamma_scaled,buff+gamma_scaled,dist);gl_FragColor=color*(alpha*opacity*fade_opacity);\n#ifdef OVERDRAW_INSPECTOR\ngl_FragColor=vec4(1.0);\n#endif\n}";
var symbolTextAndIconVert = "const float PI=3.141592653589793;attribute vec4 a_pos_offset;attribute vec4 a_data;attribute vec3 a_projected_pos;attribute float a_fade_opacity;uniform bool u_is_size_zoom_constant;uniform bool u_is_size_feature_constant;uniform highp float u_size_t;uniform highp float u_size;uniform mat4 u_matrix;uniform mat4 u_label_plane_matrix;uniform mat4 u_coord_matrix;uniform bool u_is_text;uniform bool u_pitch_with_map;uniform highp float u_pitch;uniform bool u_rotate_symbol;uniform highp float u_aspect_ratio;uniform highp float u_camera_to_center_distance;uniform float u_fade_change;uniform vec2 u_texsize;uniform vec2 u_texsize_icon;varying vec4 v_data0;varying vec4 v_data1;\n#pragma mapbox: define highp vec4 fill_color\n#pragma mapbox: define highp vec4 halo_color\n#pragma mapbox: define lowp float opacity\n#pragma mapbox: define lowp float halo_width\n#pragma mapbox: define lowp float halo_blur\nvoid main() {\n#pragma mapbox: initialize highp vec4 fill_color\n#pragma mapbox: initialize highp vec4 halo_color\n#pragma mapbox: initialize lowp float opacity\n#pragma mapbox: initialize lowp float halo_width\n#pragma mapbox: initialize lowp float halo_blur\nvec2 a_pos=a_pos_offset.xy;vec2 a_offset=a_pos_offset.zw;vec2 a_tex=a_data.xy;vec2 a_size=a_data.zw;float a_size_min=floor(a_size[0]*0.5);float is_sdf=a_size[0]-2.0*a_size_min;highp float segment_angle=-a_projected_pos[2];float size;if (!u_is_size_zoom_constant && !u_is_size_feature_constant) {size=mix(a_size_min,a_size[1],u_size_t)/128.0;} else if (u_is_size_zoom_constant && !u_is_size_feature_constant) {size=a_size_min/128.0;} else {size=u_size;}vec4 projectedPoint=u_matrix*vec4(a_pos,0,1);highp float camera_to_anchor_distance=projectedPoint.w;highp float distance_ratio=u_pitch_with_map ?\ncamera_to_anchor_distance/u_camera_to_center_distance :\nu_camera_to_center_distance/camera_to_anchor_distance;highp float perspective_ratio=clamp(0.5+0.5*distance_ratio,0.0,4.0);size*=perspective_ratio;float fontScale=size/24.0;highp float symbol_rotation=0.0;if (u_rotate_symbol) {vec4 offsetProjectedPoint=u_matrix*vec4(a_pos+vec2(1,0),0,1);vec2 a=projectedPoint.xy/projectedPoint.w;vec2 b=offsetProjectedPoint.xy/offsetProjectedPoint.w;symbol_rotation=atan((b.y-a.y)/u_aspect_ratio,b.x-a.x);}highp float angle_sin=sin(segment_angle+symbol_rotation);highp float angle_cos=cos(segment_angle+symbol_rotation);mat2 rotation_matrix=mat2(angle_cos,-1.0*angle_sin,angle_sin,angle_cos);vec4 projected_pos=u_label_plane_matrix*vec4(a_projected_pos.xy,0.0,1.0);gl_Position=u_coord_matrix*vec4(projected_pos.xy/projected_pos.w+rotation_matrix*(a_offset/32.0*fontScale),0.0,1.0);float gamma_scale=gl_Position.w;vec2 fade_opacity=unpack_opacity(a_fade_opacity);float fade_change=fade_opacity[1] > 0.5 ? u_fade_change :-u_fade_change;float interpolated_fade_opacity=max(0.0,min(1.0,fade_opacity[0]+fade_change));v_data0.xy=a_tex/u_texsize;v_data0.zw=a_tex/u_texsize_icon;v_data1=vec4(gamma_scale,size,interpolated_fade_opacity,is_sdf);}";
var prelude = compile(preludeFrag, preludeVert);
var background = compile(backgroundFrag, backgroundVert);
var backgroundPattern = compile(backgroundPatternFrag, backgroundPatternVert);
var circle = compile(circleFrag, circleVert);
var clippingMask = compile(clippingMaskFrag, clippingMaskVert);
var heatmap = compile(heatmapFrag, heatmapVert);
var heatmapTexture = compile(heatmapTextureFrag, heatmapTextureVert);
var collisionBox = compile(collisionBoxFrag, collisionBoxVert);
var collisionCircle = compile(collisionCircleFrag, collisionCircleVert);
var debug = compile(debugFrag, debugVert);
var fill = compile(fillFrag, fillVert);
var fillOutline = compile(fillOutlineFrag, fillOutlineVert);
var fillOutlinePattern = compile(fillOutlinePatternFrag, fillOutlinePatternVert);
var fillPattern = compile(fillPatternFrag, fillPatternVert);
var fillExtrusion = compile(fillExtrusionFrag, fillExtrusionVert);
var fillExtrusionPattern = compile(fillExtrusionPatternFrag, fillExtrusionPatternVert);
var hillshadePrepare = compile(hillshadePrepareFrag, hillshadePrepareVert);
var hillshade = compile(hillshadeFrag, hillshadeVert);
var line = compile(lineFrag, lineVert);
var lineGradient = compile(lineGradientFrag, lineGradientVert);
var linePattern = compile(linePatternFrag, linePatternVert);
var lineSDF = compile(lineSDFFrag, lineSDFVert);
var raster = compile(rasterFrag, rasterVert);
var symbolIcon = compile(symbolIconFrag, symbolIconVert);
var symbolSDF = compile(symbolSDFFrag, symbolSDFVert);
var symbolTextAndIcon = compile(symbolTextAndIconFrag, symbolTextAndIconVert);
function compile(fragmentSource, vertexSource) {
var re = /#pragma mapbox: ([\w]+) ([\w]+) ([\w]+) ([\w]+)/g;
var staticAttributes = vertexSource.match(/attribute ([\w]+) ([\w]+)/g);
var fragmentUniforms = fragmentSource.match(/uniform ([\w]+) ([\w]+)([\s]*)([\w]*)/g);
var vertexUniforms = vertexSource.match(/uniform ([\w]+) ([\w]+)([\s]*)([\w]*)/g);
var staticUniforms = vertexUniforms ? vertexUniforms.concat(fragmentUniforms) : fragmentUniforms;
var fragmentPragmas = {};
fragmentSource = fragmentSource.replace(re, function (match, operation, precision, type, name) {
fragmentPragmas[name] = true;
if (operation === 'define') {
return '\n#ifndef HAS_UNIFORM_u_' + name + '\nvarying ' + precision + ' ' + type + ' ' + name + ';\n#else\nuniform ' + precision + ' ' + type + ' u_' + name + ';\n#endif\n';
} else {
return '\n#ifdef HAS_UNIFORM_u_' + name + '\n ' + precision + ' ' + type + ' ' + name + ' = u_' + name + ';\n#endif\n';
}
});
vertexSource = vertexSource.replace(re, function (match, operation, precision, type, name) {
var attrType = type === 'float' ? 'vec2' : 'vec4';
var unpackType = name.match(/color/) ? 'color' : attrType;
if (fragmentPragmas[name]) {
if (operation === 'define') {
return '\n#ifndef HAS_UNIFORM_u_' + name + '\nuniform lowp float u_' + name + '_t;\nattribute ' + precision + ' ' + attrType + ' a_' + name + ';\nvarying ' + precision + ' ' + type + ' ' + name + ';\n#else\nuniform ' + precision + ' ' + type + ' u_' + name + ';\n#endif\n';
} else {
if (unpackType === 'vec4') {
return '\n#ifndef HAS_UNIFORM_u_' + name + '\n ' + name + ' = a_' + name + ';\n#else\n ' + precision + ' ' + type + ' ' + name + ' = u_' + name + ';\n#endif\n';
} else {
return '\n#ifndef HAS_UNIFORM_u_' + name + '\n ' + name + ' = unpack_mix_' + unpackType + '(a_' + name + ', u_' + name + '_t);\n#else\n ' + precision + ' ' + type + ' ' + name + ' = u_' + name + ';\n#endif\n';
}
}
} else {
if (operation === 'define') {
return '\n#ifndef HAS_UNIFORM_u_' + name + '\nuniform lowp float u_' + name + '_t;\nattribute ' + precision + ' ' + attrType + ' a_' + name + ';\n#else\nuniform ' + precision + ' ' + type + ' u_' + name + ';\n#endif\n';
} else {
if (unpackType === 'vec4') {
return '\n#ifndef HAS_UNIFORM_u_' + name + '\n ' + precision + ' ' + type + ' ' + name + ' = a_' + name + ';\n#else\n ' + precision + ' ' + type + ' ' + name + ' = u_' + name + ';\n#endif\n';
} else {
return '\n#ifndef HAS_UNIFORM_u_' + name + '\n ' + precision + ' ' + type + ' ' + name + ' = unpack_mix_' + unpackType + '(a_' + name + ', u_' + name + '_t);\n#else\n ' + precision + ' ' + type + ' ' + name + ' = u_' + name + ';\n#endif\n';
}
}
}
});
return {
fragmentSource: fragmentSource,
vertexSource: vertexSource,
staticAttributes: staticAttributes,
staticUniforms: staticUniforms
};
}
var shaders = /*#__PURE__*/Object.freeze({
__proto__: null,
prelude: prelude,
background: background,
backgroundPattern: backgroundPattern,
circle: circle,
clippingMask: clippingMask,
heatmap: heatmap,
heatmapTexture: heatmapTexture,
collisionBox: collisionBox,
collisionCircle: collisionCircle,
debug: debug,
fill: fill,
fillOutline: fillOutline,
fillOutlinePattern: fillOutlinePattern,
fillPattern: fillPattern,
fillExtrusion: fillExtrusion,
fillExtrusionPattern: fillExtrusionPattern,
hillshadePrepare: hillshadePrepare,
hillshade: hillshade,
line: line,
lineGradient: lineGradient,
linePattern: linePattern,
lineSDF: lineSDF,
raster: raster,
symbolIcon: symbolIcon,
symbolSDF: symbolSDF,
symbolTextAndIcon: symbolTextAndIcon
});
var VertexArrayObject = function VertexArrayObject() {
this.boundProgram = null;
this.boundLayoutVertexBuffer = null;
this.boundPaintVertexBuffers = [];
this.boundIndexBuffer = null;
this.boundVertexOffset = null;
this.boundDynamicVertexBuffer = null;
this.vao = null;
};
VertexArrayObject.prototype.bind = function bind(context, program, layoutVertexBuffer, paintVertexBuffers, indexBuffer, vertexOffset, dynamicVertexBuffer, dynamicVertexBuffer2) {
this.context = context;
var paintBuffersDiffer = this.boundPaintVertexBuffers.length !== paintVertexBuffers.length;
for (var i = 0; !paintBuffersDiffer && i < paintVertexBuffers.length; i++) {
if (this.boundPaintVertexBuffers[i] !== paintVertexBuffers[i]) {
paintBuffersDiffer = true;
}
}
var isFreshBindRequired = !this.vao || this.boundProgram !== program || this.boundLayoutVertexBuffer !== layoutVertexBuffer || paintBuffersDiffer || this.boundIndexBuffer !== indexBuffer || this.boundVertexOffset !== vertexOffset || this.boundDynamicVertexBuffer !== dynamicVertexBuffer || this.boundDynamicVertexBuffer2 !== dynamicVertexBuffer2;
if (!context.extVertexArrayObject || isFreshBindRequired) {
this.freshBind(program, layoutVertexBuffer, paintVertexBuffers, indexBuffer, vertexOffset, dynamicVertexBuffer, dynamicVertexBuffer2);
} else {
context.bindVertexArrayOES.set(this.vao);
if (dynamicVertexBuffer) {
dynamicVertexBuffer.bind();
}
if (indexBuffer && indexBuffer.dynamicDraw) {
indexBuffer.bind();
}
if (dynamicVertexBuffer2) {
dynamicVertexBuffer2.bind();
}
}
};
VertexArrayObject.prototype.freshBind = function freshBind(program, layoutVertexBuffer, paintVertexBuffers, indexBuffer, vertexOffset, dynamicVertexBuffer, dynamicVertexBuffer2) {
var numPrevAttributes;
var numNextAttributes = program.numAttributes;
var context = this.context;
var gl = context.gl;
if (context.extVertexArrayObject) {
if (this.vao) {
this.destroy();
}
this.vao = context.extVertexArrayObject.createVertexArrayOES();
context.bindVertexArrayOES.set(this.vao);
numPrevAttributes = 0;
this.boundProgram = program;
this.boundLayoutVertexBuffer = layoutVertexBuffer;
this.boundPaintVertexBuffers = paintVertexBuffers;
this.boundIndexBuffer = indexBuffer;
this.boundVertexOffset = vertexOffset;
this.boundDynamicVertexBuffer = dynamicVertexBuffer;
this.boundDynamicVertexBuffer2 = dynamicVertexBuffer2;
} else {
numPrevAttributes = context.currentNumAttributes || 0;
for (var i = numNextAttributes; i < numPrevAttributes; i++) {
gl.disableVertexAttribArray(i);
}
}
layoutVertexBuffer.enableAttributes(gl, program);
for (var i$1 = 0, list = paintVertexBuffers; i$1 < list.length; i$1 += 1) {
var vertexBuffer = list[i$1];
vertexBuffer.enableAttributes(gl, program);
}
if (dynamicVertexBuffer) {
dynamicVertexBuffer.enableAttributes(gl, program);
}
if (dynamicVertexBuffer2) {
dynamicVertexBuffer2.enableAttributes(gl, program);
}
layoutVertexBuffer.bind();
layoutVertexBuffer.setVertexAttribPointers(gl, program, vertexOffset);
for (var i$2 = 0, list$1 = paintVertexBuffers; i$2 < list$1.length; i$2 += 1) {
var vertexBuffer$1 = list$1[i$2];
vertexBuffer$1.bind();
vertexBuffer$1.setVertexAttribPointers(gl, program, vertexOffset);
}
if (dynamicVertexBuffer) {
dynamicVertexBuffer.bind();
dynamicVertexBuffer.setVertexAttribPointers(gl, program, vertexOffset);
}
if (indexBuffer) {
indexBuffer.bind();
}
if (dynamicVertexBuffer2) {
dynamicVertexBuffer2.bind();
dynamicVertexBuffer2.setVertexAttribPointers(gl, program, vertexOffset);
}
context.currentNumAttributes = numNextAttributes;
};
VertexArrayObject.prototype.destroy = function destroy() {
if (this.vao) {
this.context.extVertexArrayObject.deleteVertexArrayOES(this.vao);
this.vao = null;
}
};
function getTokenizedAttributesAndUniforms(array) {
var result = [];
for (var i = 0; i < array.length; i++) {
if (array[i] === null) {
continue;
}
var token = array[i].split(' ');
result.push(token.pop());
}
return result;
}
var Program$1 = function Program(context, name, source, configuration, fixedUniforms, showOverdrawInspector) {
var gl = context.gl;
this.program = gl.createProgram();
var staticAttrInfo = getTokenizedAttributesAndUniforms(source.staticAttributes);
var dynamicAttrInfo = configuration ? configuration.getBinderAttributes() : [];
var allAttrInfo = staticAttrInfo.concat(dynamicAttrInfo);
var staticUniformsInfo = source.staticUniforms ? getTokenizedAttributesAndUniforms(source.staticUniforms) : [];
var dynamicUniformsInfo = configuration ? configuration.getBinderUniforms() : [];
var uniformList = staticUniformsInfo.concat(dynamicUniformsInfo);
var allUniformsInfo = [];
for (var i$1 = 0, list = uniformList; i$1 < list.length; i$1 += 1) {
var uniform = list[i$1];
if (allUniformsInfo.indexOf(uniform) < 0) {
allUniformsInfo.push(uniform);
}
}
var defines = configuration ? configuration.defines() : [];
if (showOverdrawInspector) {
defines.push('#define OVERDRAW_INSPECTOR;');
}
var fragmentSource = defines.concat(prelude.fragmentSource, source.fragmentSource).join('\n');
var vertexSource = defines.concat(prelude.vertexSource, source.vertexSource).join('\n');
var fragmentShader = gl.createShader(gl.FRAGMENT_SHADER);
if (gl.isContextLost()) {
this.failedToCreate = true;
return;
}
gl.shaderSource(fragmentShader, fragmentSource);
gl.compileShader(fragmentShader);
gl.attachShader(this.program, fragmentShader);
var vertexShader = gl.createShader(gl.VERTEX_SHADER);
if (gl.isContextLost()) {
this.failedToCreate = true;
return;
}
gl.shaderSource(vertexShader, vertexSource);
gl.compileShader(vertexShader);
gl.attachShader(this.program, vertexShader);
this.attributes = {};
var uniformLocations = {};
this.numAttributes = allAttrInfo.length;
for (var i = 0; i < this.numAttributes; i++) {
if (allAttrInfo[i]) {
gl.bindAttribLocation(this.program, i, allAttrInfo[i]);
this.attributes[allAttrInfo[i]] = i;
}
}
gl.linkProgram(this.program);
gl.deleteShader(vertexShader);
gl.deleteShader(fragmentShader);
for (var it = 0; it < allUniformsInfo.length; it++) {
var uniform$1 = allUniformsInfo[it];
if (uniform$1 && !uniformLocations[uniform$1]) {
var uniformLocation = gl.getUniformLocation(this.program, uniform$1);
if (uniformLocation) {
uniformLocations[uniform$1] = uniformLocation;
}
}
}
this.fixedUniforms = fixedUniforms(context, uniformLocations);
this.binderUniforms = configuration ? configuration.getUniforms(context, uniformLocations) : [];
};
Program$1.prototype.draw = function draw(context, drawMode, depthMode, stencilMode, colorMode, cullFaceMode, uniformValues, layerID, layoutVertexBuffer, indexBuffer, segments, currentProperties, zoom, configuration, dynamicLayoutBuffer, dynamicLayoutBuffer2) {
var obj;
var gl = context.gl;
if (this.failedToCreate) {
return;
}
context.program.set(this.program);
context.setDepthMode(depthMode);
context.setStencilMode(stencilMode);
context.setColorMode(colorMode);
context.setCullFace(cullFaceMode);
for (var name in this.fixedUniforms) {
this.fixedUniforms[name].set(uniformValues[name]);
}
if (configuration) {
configuration.setUniforms(context, this.binderUniforms, currentProperties, { zoom: zoom });
}
var primitiveSize = (obj = {}, obj[gl.LINES] = 2, obj[gl.TRIANGLES] = 3, obj[gl.LINE_STRIP] = 1, obj)[drawMode];
for (var i = 0, list = segments.get(); i < list.length; i += 1) {
var segment = list[i];
var vaos = segment.vaos || (segment.vaos = {});
var vao = vaos[layerID] || (vaos[layerID] = new VertexArrayObject());
vao.bind(context, this, layoutVertexBuffer, configuration ? configuration.getPaintVertexBuffers() : [], indexBuffer, segment.vertexOffset, dynamicLayoutBuffer, dynamicLayoutBuffer2);
gl.drawElements(drawMode, segment.primitiveLength * primitiveSize, gl.UNSIGNED_SHORT, segment.primitiveOffset * primitiveSize * 2);
}
};
function patternUniformValues(crossfade, painter, tile) {
var tileRatio = 1 / pixelsToTileUnits(tile, 1, painter.transform.tileZoom);
var numTiles = Math.pow(2, tile.tileID.overscaledZ);
var tileSizeAtNearestZoom = tile.tileSize * Math.pow(2, painter.transform.tileZoom) / numTiles;
var pixelX = tileSizeAtNearestZoom * (tile.tileID.canonical.x + tile.tileID.wrap * numTiles);
var pixelY = tileSizeAtNearestZoom * tile.tileID.canonical.y;
return {
'u_image': 0,
'u_texsize': tile.imageAtlasTexture.size,
'u_scale': [
tileRatio,
crossfade.fromScale,
crossfade.toScale
],
'u_fade': crossfade.t,
'u_pixel_coord_upper': [
pixelX >> 16,
pixelY >> 16
],
'u_pixel_coord_lower': [
pixelX & 65535,
pixelY & 65535
]
};
}
function bgPatternUniformValues(image, crossfade, painter, tile) {
var imagePosA = painter.imageManager.getPattern(image.from.toString());
var imagePosB = painter.imageManager.getPattern(image.to.toString());
var ref = painter.imageManager.getPixelSize();
var width = ref.width;
var height = ref.height;
var numTiles = Math.pow(2, tile.tileID.overscaledZ);
var tileSizeAtNearestZoom = tile.tileSize * Math.pow(2, painter.transform.tileZoom) / numTiles;
var pixelX = tileSizeAtNearestZoom * (tile.tileID.canonical.x + tile.tileID.wrap * numTiles);
var pixelY = tileSizeAtNearestZoom * tile.tileID.canonical.y;
return {
'u_image': 0,
'u_pattern_tl_a': imagePosA.tl,
'u_pattern_br_a': imagePosA.br,
'u_pattern_tl_b': imagePosB.tl,
'u_pattern_br_b': imagePosB.br,
'u_texsize': [
width,
height
],
'u_mix': crossfade.t,
'u_pattern_size_a': imagePosA.displaySize,
'u_pattern_size_b': imagePosB.displaySize,
'u_scale_a': crossfade.fromScale,
'u_scale_b': crossfade.toScale,
'u_tile_units_to_pixels': 1 / pixelsToTileUnits(tile, 1, painter.transform.tileZoom),
'u_pixel_coord_upper': [
pixelX >> 16,
pixelY >> 16
],
'u_pixel_coord_lower': [
pixelX & 65535,
pixelY & 65535
]
};
}
var fillExtrusionUniforms = function (context, locations) {
return {
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_lightpos': new performance.Uniform3f(context, locations.u_lightpos),
'u_lightintensity': new performance.Uniform1f(context, locations.u_lightintensity),
'u_lightcolor': new performance.Uniform3f(context, locations.u_lightcolor),
'u_vertical_gradient': new performance.Uniform1f(context, locations.u_vertical_gradient),
'u_opacity': new performance.Uniform1f(context, locations.u_opacity)
};
};
var fillExtrusionPatternUniforms = function (context, locations) {
return {
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_lightpos': new performance.Uniform3f(context, locations.u_lightpos),
'u_lightintensity': new performance.Uniform1f(context, locations.u_lightintensity),
'u_lightcolor': new performance.Uniform3f(context, locations.u_lightcolor),
'u_vertical_gradient': new performance.Uniform1f(context, locations.u_vertical_gradient),
'u_height_factor': new performance.Uniform1f(context, locations.u_height_factor),
'u_image': new performance.Uniform1i(context, locations.u_image),
'u_texsize': new performance.Uniform2f(context, locations.u_texsize),
'u_pixel_coord_upper': new performance.Uniform2f(context, locations.u_pixel_coord_upper),
'u_pixel_coord_lower': new performance.Uniform2f(context, locations.u_pixel_coord_lower),
'u_scale': new performance.Uniform3f(context, locations.u_scale),
'u_fade': new performance.Uniform1f(context, locations.u_fade),
'u_opacity': new performance.Uniform1f(context, locations.u_opacity)
};
};
var fillExtrusionUniformValues = function (matrix, painter, shouldUseVerticalGradient, opacity) {
var light = painter.style.light;
var _lp = light.properties.get('position');
var lightPos = [
_lp.x,
_lp.y,
_lp.z
];
var lightMat = performance.create$1();
if (light.properties.get('anchor') === 'viewport') {
performance.fromRotation(lightMat, -painter.transform.angle);
}
performance.transformMat3(lightPos, lightPos, lightMat);
var lightColor = light.properties.get('color');
return {
'u_matrix': matrix,
'u_lightpos': lightPos,
'u_lightintensity': light.properties.get('intensity'),
'u_lightcolor': [
lightColor.r,
lightColor.g,
lightColor.b
],
'u_vertical_gradient': +shouldUseVerticalGradient,
'u_opacity': opacity
};
};
var fillExtrusionPatternUniformValues = function (matrix, painter, shouldUseVerticalGradient, opacity, coord, crossfade, tile) {
return performance.extend(fillExtrusionUniformValues(matrix, painter, shouldUseVerticalGradient, opacity), patternUniformValues(crossfade, painter, tile), { 'u_height_factor': -Math.pow(2, coord.overscaledZ) / tile.tileSize / 8 });
};
var fillUniforms = function (context, locations) {
return { 'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix) };
};
var fillPatternUniforms = function (context, locations) {
return {
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_image': new performance.Uniform1i(context, locations.u_image),
'u_texsize': new performance.Uniform2f(context, locations.u_texsize),
'u_pixel_coord_upper': new performance.Uniform2f(context, locations.u_pixel_coord_upper),
'u_pixel_coord_lower': new performance.Uniform2f(context, locations.u_pixel_coord_lower),
'u_scale': new performance.Uniform3f(context, locations.u_scale),
'u_fade': new performance.Uniform1f(context, locations.u_fade)
};
};
var fillOutlineUniforms = function (context, locations) {
return {
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_world': new performance.Uniform2f(context, locations.u_world)
};
};
var fillOutlinePatternUniforms = function (context, locations) {
return {
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_world': new performance.Uniform2f(context, locations.u_world),
'u_image': new performance.Uniform1i(context, locations.u_image),
'u_texsize': new performance.Uniform2f(context, locations.u_texsize),
'u_pixel_coord_upper': new performance.Uniform2f(context, locations.u_pixel_coord_upper),
'u_pixel_coord_lower': new performance.Uniform2f(context, locations.u_pixel_coord_lower),
'u_scale': new performance.Uniform3f(context, locations.u_scale),
'u_fade': new performance.Uniform1f(context, locations.u_fade)
};
};
var fillUniformValues = function (matrix) {
return { 'u_matrix': matrix };
};
var fillPatternUniformValues = function (matrix, painter, crossfade, tile) {
return performance.extend(fillUniformValues(matrix), patternUniformValues(crossfade, painter, tile));
};
var fillOutlineUniformValues = function (matrix, drawingBufferSize) {
return {
'u_matrix': matrix,
'u_world': drawingBufferSize
};
};
var fillOutlinePatternUniformValues = function (matrix, painter, crossfade, tile, drawingBufferSize) {
return performance.extend(fillPatternUniformValues(matrix, painter, crossfade, tile), { 'u_world': drawingBufferSize });
};
var circleUniforms = function (context, locations) {
return {
'u_camera_to_center_distance': new performance.Uniform1f(context, locations.u_camera_to_center_distance),
'u_scale_with_map': new performance.Uniform1i(context, locations.u_scale_with_map),
'u_pitch_with_map': new performance.Uniform1i(context, locations.u_pitch_with_map),
'u_extrude_scale': new performance.Uniform2f(context, locations.u_extrude_scale),
'u_device_pixel_ratio': new performance.Uniform1f(context, locations.u_device_pixel_ratio),
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix)
};
};
var circleUniformValues = function (painter, coord, tile, layer) {
var transform = painter.transform;
var pitchWithMap, extrudeScale;
if (layer.paint.get('circle-pitch-alignment') === 'map') {
var pixelRatio = pixelsToTileUnits(tile, 1, transform.zoom);
pitchWithMap = true;
extrudeScale = [
pixelRatio,
pixelRatio
];
} else {
pitchWithMap = false;
extrudeScale = transform.pixelsToGLUnits;
}
return {
'u_camera_to_center_distance': transform.cameraToCenterDistance,
'u_scale_with_map': +(layer.paint.get('circle-pitch-scale') === 'map'),
'u_matrix': painter.translatePosMatrix(coord.posMatrix, tile, layer.paint.get('circle-translate'), layer.paint.get('circle-translate-anchor')),
'u_pitch_with_map': +pitchWithMap,
'u_device_pixel_ratio': performance.browser.devicePixelRatio,
'u_extrude_scale': extrudeScale
};
};
var collisionUniforms = function (context, locations) {
return {
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_camera_to_center_distance': new performance.Uniform1f(context, locations.u_camera_to_center_distance),
'u_pixels_to_tile_units': new performance.Uniform1f(context, locations.u_pixels_to_tile_units),
'u_extrude_scale': new performance.Uniform2f(context, locations.u_extrude_scale),
'u_overscale_factor': new performance.Uniform1f(context, locations.u_overscale_factor)
};
};
var collisionCircleUniforms = function (context, locations) {
return {
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_inv_matrix': new performance.UniformMatrix4f(context, locations.u_inv_matrix),
'u_camera_to_center_distance': new performance.Uniform1f(context, locations.u_camera_to_center_distance),
'u_viewport_size': new performance.Uniform2f(context, locations.u_viewport_size)
};
};
var collisionUniformValues = function (matrix, transform, tile) {
var pixelRatio = pixelsToTileUnits(tile, 1, transform.zoom);
var scale = Math.pow(2, transform.zoom - tile.tileID.overscaledZ);
var overscaleFactor = tile.tileID.overscaleFactor();
return {
'u_matrix': matrix,
'u_camera_to_center_distance': transform.cameraToCenterDistance,
'u_pixels_to_tile_units': pixelRatio,
'u_extrude_scale': [
transform.pixelsToGLUnits[0] / (pixelRatio * scale),
transform.pixelsToGLUnits[1] / (pixelRatio * scale)
],
'u_overscale_factor': overscaleFactor
};
};
var collisionCircleUniformValues = function (matrix, invMatrix, transform) {
return {
'u_matrix': matrix,
'u_inv_matrix': invMatrix,
'u_camera_to_center_distance': transform.cameraToCenterDistance,
'u_viewport_size': [
transform.width,
transform.height
]
};
};
var debugUniforms = function (context, locations) {
return {
'u_color': new performance.UniformColor(context, locations.u_color),
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_overlay': new performance.Uniform1i(context, locations.u_overlay),
'u_overlay_scale': new performance.Uniform1f(context, locations.u_overlay_scale)
};
};
var debugUniformValues = function (matrix, color, scaleRatio) {
if (scaleRatio === void 0)
scaleRatio = 1;
return {
'u_matrix': matrix,
'u_color': color,
'u_overlay': 0,
'u_overlay_scale': scaleRatio
};
};
var clippingMaskUniforms = function (context, locations) {
return { 'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix) };
};
var clippingMaskUniformValues = function (matrix) {
return { 'u_matrix': matrix };
};
var heatmapUniforms = function (context, locations) {
return {
'u_extrude_scale': new performance.Uniform1f(context, locations.u_extrude_scale),
'u_intensity': new performance.Uniform1f(context, locations.u_intensity),
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix)
};
};
var heatmapTextureUniforms = function (context, locations) {
return {
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_world': new performance.Uniform2f(context, locations.u_world),
'u_image': new performance.Uniform1i(context, locations.u_image),
'u_color_ramp': new performance.Uniform1i(context, locations.u_color_ramp),
'u_opacity': new performance.Uniform1f(context, locations.u_opacity)
};
};
var heatmapUniformValues = function (matrix, tile, zoom, intensity) {
return {
'u_matrix': matrix,
'u_extrude_scale': pixelsToTileUnits(tile, 1, zoom),
'u_intensity': intensity
};
};
var heatmapTextureUniformValues = function (painter, layer, textureUnit, colorRampUnit) {
var matrix = performance.create();
performance.ortho(matrix, 0, painter.width, painter.height, 0, 0, 1);
var gl = painter.context.gl;
return {
'u_matrix': matrix,
'u_world': [
gl.drawingBufferWidth,
gl.drawingBufferHeight
],
'u_image': textureUnit,
'u_color_ramp': colorRampUnit,
'u_opacity': layer.paint.get('heatmap-opacity')
};
};
var hillshadeUniforms = function (context, locations) {
return {
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_image': new performance.Uniform1i(context, locations.u_image),
'u_latrange': new performance.Uniform2f(context, locations.u_latrange),
'u_light': new performance.Uniform2f(context, locations.u_light),
'u_shadow': new performance.UniformColor(context, locations.u_shadow),
'u_highlight': new performance.UniformColor(context, locations.u_highlight),
'u_accent': new performance.UniformColor(context, locations.u_accent)
};
};
var hillshadePrepareUniforms = function (context, locations) {
return {
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_image': new performance.Uniform1i(context, locations.u_image),
'u_dimension': new performance.Uniform2f(context, locations.u_dimension),
'u_zoom': new performance.Uniform1f(context, locations.u_zoom),
'u_unpack': new performance.Uniform4f(context, locations.u_unpack)
};
};
var hillshadeUniformValues = function (painter, tile, layer) {
var shadow = layer.paint.get('hillshade-shadow-color');
var highlight = layer.paint.get('hillshade-highlight-color');
var accent = layer.paint.get('hillshade-accent-color');
var azimuthal = layer.paint.get('hillshade-illumination-direction') * (Math.PI / 180);
if (layer.paint.get('hillshade-illumination-anchor') === 'viewport') {
azimuthal -= painter.transform.angle;
}
var align = !painter.options.moving;
return {
'u_matrix': painter.transform.calculatePosMatrix(tile.tileID.toUnwrapped(), align),
'u_image': 0,
'u_latrange': getTileLatRange(painter, tile.tileID),
'u_light': [
layer.paint.get('hillshade-exaggeration'),
azimuthal
],
'u_shadow': shadow,
'u_highlight': highlight,
'u_accent': accent
};
};
var hillshadeUniformPrepareValues = function (tileID, dem) {
var stride = dem.stride;
var matrix = performance.create();
performance.ortho(matrix, 0, performance.EXTENT, -performance.EXTENT, 0, 0, 1);
performance.translate(matrix, matrix, [
0,
-performance.EXTENT,
0
]);
return {
'u_matrix': matrix,
'u_image': 1,
'u_dimension': [
stride,
stride
],
'u_zoom': tileID.overscaledZ,
'u_unpack': dem.getUnpackVector()
};
};
function getTileLatRange(painter, tileID) {
var tilesAtZoom = Math.pow(2, tileID.canonical.z);
var y = tileID.canonical.y;
return [
new performance.MercatorCoordinate(0, y / tilesAtZoom).toLngLat().lat,
new performance.MercatorCoordinate(0, (y + 1) / tilesAtZoom).toLngLat().lat
];
}
var lineUniforms = function (context, locations) {
return {
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_ratio': new performance.Uniform1f(context, locations.u_ratio),
'u_device_pixel_ratio': new performance.Uniform1f(context, locations.u_device_pixel_ratio),
'u_units_to_pixels': new performance.Uniform2f(context, locations.u_units_to_pixels)
};
};
var lineGradientUniforms = function (context, locations) {
return {
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_ratio': new performance.Uniform1f(context, locations.u_ratio),
'u_device_pixel_ratio': new performance.Uniform1f(context, locations.u_device_pixel_ratio),
'u_units_to_pixels': new performance.Uniform2f(context, locations.u_units_to_pixels),
'u_image': new performance.Uniform1i(context, locations.u_image),
'u_image_height': new performance.Uniform1f(context, locations.u_image_height)
};
};
var linePatternUniforms = function (context, locations) {
return {
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_texsize': new performance.Uniform2f(context, locations.u_texsize),
'u_ratio': new performance.Uniform1f(context, locations.u_ratio),
'u_device_pixel_ratio': new performance.Uniform1f(context, locations.u_device_pixel_ratio),
'u_image': new performance.Uniform1i(context, locations.u_image),
'u_units_to_pixels': new performance.Uniform2f(context, locations.u_units_to_pixels),
'u_scale': new performance.Uniform3f(context, locations.u_scale),
'u_fade': new performance.Uniform1f(context, locations.u_fade)
};
};
var lineSDFUniforms = function (context, locations) {
return {
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_ratio': new performance.Uniform1f(context, locations.u_ratio),
'u_device_pixel_ratio': new performance.Uniform1f(context, locations.u_device_pixel_ratio),
'u_units_to_pixels': new performance.Uniform2f(context, locations.u_units_to_pixels),
'u_patternscale_a': new performance.Uniform2f(context, locations.u_patternscale_a),
'u_patternscale_b': new performance.Uniform2f(context, locations.u_patternscale_b),
'u_sdfgamma': new performance.Uniform1f(context, locations.u_sdfgamma),
'u_image': new performance.Uniform1i(context, locations.u_image),
'u_tex_y_a': new performance.Uniform1f(context, locations.u_tex_y_a),
'u_tex_y_b': new performance.Uniform1f(context, locations.u_tex_y_b),
'u_mix': new performance.Uniform1f(context, locations.u_mix)
};
};
var lineUniformValues = function (painter, tile, layer) {
var transform = painter.transform;
return {
'u_matrix': calculateMatrix(painter, tile, layer),
'u_ratio': 1 / pixelsToTileUnits(tile, 1, transform.zoom),
'u_device_pixel_ratio': performance.browser.devicePixelRatio,
'u_units_to_pixels': [
1 / transform.pixelsToGLUnits[0],
1 / transform.pixelsToGLUnits[1]
]
};
};
var lineGradientUniformValues = function (painter, tile, layer, imageHeight) {
return performance.extend(lineUniformValues(painter, tile, layer), {
'u_image': 0,
'u_image_height': imageHeight
});
};
var linePatternUniformValues = function (painter, tile, layer, crossfade) {
var transform = painter.transform;
var tileZoomRatio = calculateTileRatio(tile, transform);
return {
'u_matrix': calculateMatrix(painter, tile, layer),
'u_texsize': tile.imageAtlasTexture.size,
'u_ratio': 1 / pixelsToTileUnits(tile, 1, transform.zoom),
'u_device_pixel_ratio': performance.browser.devicePixelRatio,
'u_image': 0,
'u_scale': [
tileZoomRatio,
crossfade.fromScale,
crossfade.toScale
],
'u_fade': crossfade.t,
'u_units_to_pixels': [
1 / transform.pixelsToGLUnits[0],
1 / transform.pixelsToGLUnits[1]
]
};
};
var lineSDFUniformValues = function (painter, tile, layer, dasharray, crossfade) {
var transform = painter.transform;
var lineAtlas = painter.lineAtlas;
var tileRatio = calculateTileRatio(tile, transform);
var round = layer.layout.get('line-cap') === 'round';
var posA = lineAtlas.getDash(dasharray.from, round);
var posB = lineAtlas.getDash(dasharray.to, round);
var widthA = posA.width * crossfade.fromScale;
var widthB = posB.width * crossfade.toScale;
return performance.extend(lineUniformValues(painter, tile, layer), {
'u_patternscale_a': [
tileRatio / widthA,
-posA.height / 2
],
'u_patternscale_b': [
tileRatio / widthB,
-posB.height / 2
],
'u_sdfgamma': lineAtlas.width / (Math.min(widthA, widthB) * 256 * performance.browser.devicePixelRatio) / 2,
'u_image': 0,
'u_tex_y_a': posA.y,
'u_tex_y_b': posB.y,
'u_mix': crossfade.t
});
};
function calculateTileRatio(tile, transform) {
return 1 / pixelsToTileUnits(tile, 1, transform.tileZoom);
}
function calculateMatrix(painter, tile, layer) {
return painter.translatePosMatrix(tile.tileID.posMatrix, tile, layer.paint.get('line-translate'), layer.paint.get('line-translate-anchor'));
}
var rasterUniforms = function (context, locations) {
return {
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_tl_parent': new performance.Uniform2f(context, locations.u_tl_parent),
'u_scale_parent': new performance.Uniform1f(context, locations.u_scale_parent),
'u_buffer_scale': new performance.Uniform1f(context, locations.u_buffer_scale),
'u_fade_t': new performance.Uniform1f(context, locations.u_fade_t),
'u_opacity': new performance.Uniform1f(context, locations.u_opacity),
'u_image0': new performance.Uniform1i(context, locations.u_image0),
'u_image1': new performance.Uniform1i(context, locations.u_image1),
'u_brightness_low': new performance.Uniform1f(context, locations.u_brightness_low),
'u_brightness_high': new performance.Uniform1f(context, locations.u_brightness_high),
'u_saturation_factor': new performance.Uniform1f(context, locations.u_saturation_factor),
'u_contrast_factor': new performance.Uniform1f(context, locations.u_contrast_factor),
'u_spin_weights': new performance.Uniform3f(context, locations.u_spin_weights)
};
};
var rasterUniformValues = function (matrix, parentTL, parentScaleBy, fade, layer) {
return {
'u_matrix': matrix,
'u_tl_parent': parentTL,
'u_scale_parent': parentScaleBy,
'u_buffer_scale': 1,
'u_fade_t': fade.mix,
'u_opacity': fade.opacity * layer.paint.get('raster-opacity'),
'u_image0': 0,
'u_image1': 1,
'u_brightness_low': layer.paint.get('raster-brightness-min'),
'u_brightness_high': layer.paint.get('raster-brightness-max'),
'u_saturation_factor': saturationFactor(layer.paint.get('raster-saturation')),
'u_contrast_factor': contrastFactor(layer.paint.get('raster-contrast')),
'u_spin_weights': spinWeights(layer.paint.get('raster-hue-rotate'))
};
};
function spinWeights(angle) {
angle *= Math.PI / 180;
var s = Math.sin(angle);
var c = Math.cos(angle);
return [
(2 * c + 1) / 3,
(-Math.sqrt(3) * s - c + 1) / 3,
(Math.sqrt(3) * s - c + 1) / 3
];
}
function contrastFactor(contrast) {
return contrast > 0 ? 1 / (1 - contrast) : 1 + contrast;
}
function saturationFactor(saturation) {
return saturation > 0 ? 1 - 1 / (1.001 - saturation) : -saturation;
}
var symbolIconUniforms = function (context, locations) {
return {
'u_is_size_zoom_constant': new performance.Uniform1i(context, locations.u_is_size_zoom_constant),
'u_is_size_feature_constant': new performance.Uniform1i(context, locations.u_is_size_feature_constant),
'u_size_t': new performance.Uniform1f(context, locations.u_size_t),
'u_size': new performance.Uniform1f(context, locations.u_size),
'u_camera_to_center_distance': new performance.Uniform1f(context, locations.u_camera_to_center_distance),
'u_pitch': new performance.Uniform1f(context, locations.u_pitch),
'u_rotate_symbol': new performance.Uniform1i(context, locations.u_rotate_symbol),
'u_aspect_ratio': new performance.Uniform1f(context, locations.u_aspect_ratio),
'u_fade_change': new performance.Uniform1f(context, locations.u_fade_change),
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_label_plane_matrix': new performance.UniformMatrix4f(context, locations.u_label_plane_matrix),
'u_coord_matrix': new performance.UniformMatrix4f(context, locations.u_coord_matrix),
'u_is_text': new performance.Uniform1i(context, locations.u_is_text),
'u_pitch_with_map': new performance.Uniform1i(context, locations.u_pitch_with_map),
'u_texsize': new performance.Uniform2f(context, locations.u_texsize),
'u_texture': new performance.Uniform1i(context, locations.u_texture)
};
};
var symbolSDFUniforms = function (context, locations) {
return {
'u_is_size_zoom_constant': new performance.Uniform1i(context, locations.u_is_size_zoom_constant),
'u_is_size_feature_constant': new performance.Uniform1i(context, locations.u_is_size_feature_constant),
'u_size_t': new performance.Uniform1f(context, locations.u_size_t),
'u_size': new performance.Uniform1f(context, locations.u_size),
'u_camera_to_center_distance': new performance.Uniform1f(context, locations.u_camera_to_center_distance),
'u_pitch': new performance.Uniform1f(context, locations.u_pitch),
'u_rotate_symbol': new performance.Uniform1i(context, locations.u_rotate_symbol),
'u_aspect_ratio': new performance.Uniform1f(context, locations.u_aspect_ratio),
'u_fade_change': new performance.Uniform1f(context, locations.u_fade_change),
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_label_plane_matrix': new performance.UniformMatrix4f(context, locations.u_label_plane_matrix),
'u_coord_matrix': new performance.UniformMatrix4f(context, locations.u_coord_matrix),
'u_is_text': new performance.Uniform1i(context, locations.u_is_text),
'u_pitch_with_map': new performance.Uniform1i(context, locations.u_pitch_with_map),
'u_texsize': new performance.Uniform2f(context, locations.u_texsize),
'u_texture': new performance.Uniform1i(context, locations.u_texture),
'u_gamma_scale': new performance.Uniform1f(context, locations.u_gamma_scale),
'u_device_pixel_ratio': new performance.Uniform1f(context, locations.u_device_pixel_ratio),
'u_is_halo': new performance.Uniform1i(context, locations.u_is_halo)
};
};
var symbolTextAndIconUniforms = function (context, locations) {
return {
'u_is_size_zoom_constant': new performance.Uniform1i(context, locations.u_is_size_zoom_constant),
'u_is_size_feature_constant': new performance.Uniform1i(context, locations.u_is_size_feature_constant),
'u_size_t': new performance.Uniform1f(context, locations.u_size_t),
'u_size': new performance.Uniform1f(context, locations.u_size),
'u_camera_to_center_distance': new performance.Uniform1f(context, locations.u_camera_to_center_distance),
'u_pitch': new performance.Uniform1f(context, locations.u_pitch),
'u_rotate_symbol': new performance.Uniform1i(context, locations.u_rotate_symbol),
'u_aspect_ratio': new performance.Uniform1f(context, locations.u_aspect_ratio),
'u_fade_change': new performance.Uniform1f(context, locations.u_fade_change),
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_label_plane_matrix': new performance.UniformMatrix4f(context, locations.u_label_plane_matrix),
'u_coord_matrix': new performance.UniformMatrix4f(context, locations.u_coord_matrix),
'u_is_text': new performance.Uniform1i(context, locations.u_is_text),
'u_pitch_with_map': new performance.Uniform1i(context, locations.u_pitch_with_map),
'u_texsize': new performance.Uniform2f(context, locations.u_texsize),
'u_texsize_icon': new performance.Uniform2f(context, locations.u_texsize_icon),
'u_texture': new performance.Uniform1i(context, locations.u_texture),
'u_texture_icon': new performance.Uniform1i(context, locations.u_texture_icon),
'u_gamma_scale': new performance.Uniform1f(context, locations.u_gamma_scale),
'u_device_pixel_ratio': new performance.Uniform1f(context, locations.u_device_pixel_ratio),
'u_is_halo': new performance.Uniform1i(context, locations.u_is_halo)
};
};
var symbolIconUniformValues = function (functionType, size, rotateInShader, pitchWithMap, painter, matrix, labelPlaneMatrix, glCoordMatrix, isText, texSize) {
var transform = painter.transform;
return {
'u_is_size_zoom_constant': +(functionType === 'constant' || functionType === 'source'),
'u_is_size_feature_constant': +(functionType === 'constant' || functionType === 'camera'),
'u_size_t': size ? size.uSizeT : 0,
'u_size': size ? size.uSize : 0,
'u_camera_to_center_distance': transform.cameraToCenterDistance,
'u_pitch': transform.pitch / 360 * 2 * Math.PI,
'u_rotate_symbol': +rotateInShader,
'u_aspect_ratio': transform.width / transform.height,
'u_fade_change': painter.options.fadeDuration ? painter.symbolFadeChange : 1,
'u_matrix': matrix,
'u_label_plane_matrix': labelPlaneMatrix,
'u_coord_matrix': glCoordMatrix,
'u_is_text': +isText,
'u_pitch_with_map': +pitchWithMap,
'u_texsize': texSize,
'u_texture': 0
};
};
var symbolSDFUniformValues = function (functionType, size, rotateInShader, pitchWithMap, painter, matrix, labelPlaneMatrix, glCoordMatrix, isText, texSize, isHalo) {
var transform = painter.transform;
return performance.extend(symbolIconUniformValues(functionType, size, rotateInShader, pitchWithMap, painter, matrix, labelPlaneMatrix, glCoordMatrix, isText, texSize), {
'u_gamma_scale': pitchWithMap ? Math.cos(transform._pitch) * transform.cameraToCenterDistance : 1,
'u_device_pixel_ratio': performance.browser.devicePixelRatio,
'u_is_halo': +isHalo
});
};
var symbolTextAndIconUniformValues = function (functionType, size, rotateInShader, pitchWithMap, painter, matrix, labelPlaneMatrix, glCoordMatrix, texSizeSDF, texSizeIcon) {
return performance.extend(symbolSDFUniformValues(functionType, size, rotateInShader, pitchWithMap, painter, matrix, labelPlaneMatrix, glCoordMatrix, true, texSizeSDF, true), {
'u_texsize_icon': texSizeIcon,
'u_texture_icon': 1
});
};
var backgroundUniforms = function (context, locations) {
return {
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_opacity': new performance.Uniform1f(context, locations.u_opacity),
'u_color': new performance.UniformColor(context, locations.u_color)
};
};
var backgroundPatternUniforms = function (context, locations) {
return {
'u_matrix': new performance.UniformMatrix4f(context, locations.u_matrix),
'u_opacity': new performance.Uniform1f(context, locations.u_opacity),
'u_image': new performance.Uniform1i(context, locations.u_image),
'u_pattern_tl_a': new performance.Uniform2f(context, locations.u_pattern_tl_a),
'u_pattern_br_a': new performance.Uniform2f(context, locations.u_pattern_br_a),
'u_pattern_tl_b': new performance.Uniform2f(context, locations.u_pattern_tl_b),
'u_pattern_br_b': new performance.Uniform2f(context, locations.u_pattern_br_b),
'u_texsize': new performance.Uniform2f(context, locations.u_texsize),
'u_mix': new performance.Uniform1f(context, locations.u_mix),
'u_pattern_size_a': new performance.Uniform2f(context, locations.u_pattern_size_a),
'u_pattern_size_b': new performance.Uniform2f(context, locations.u_pattern_size_b),
'u_scale_a': new performance.Uniform1f(context, locations.u_scale_a),
'u_scale_b': new performance.Uniform1f(context, locations.u_scale_b),
'u_pixel_coord_upper': new performance.Uniform2f(context, locations.u_pixel_coord_upper),
'u_pixel_coord_lower': new performance.Uniform2f(context, locations.u_pixel_coord_lower),
'u_tile_units_to_pixels': new performance.Uniform1f(context, locations.u_tile_units_to_pixels)
};
};
var backgroundUniformValues = function (matrix, opacity, color) {
return {
'u_matrix': matrix,
'u_opacity': opacity,
'u_color': color
};
};
var backgroundPatternUniformValues = function (matrix, opacity, painter, image, tile, crossfade) {
return performance.extend(bgPatternUniformValues(image, crossfade, painter, tile), {
'u_matrix': matrix,
'u_opacity': opacity
});
};
var programUniforms = {
fillExtrusion: fillExtrusionUniforms,
fillExtrusionPattern: fillExtrusionPatternUniforms,
fill: fillUniforms,
fillPattern: fillPatternUniforms,
fillOutline: fillOutlineUniforms,
fillOutlinePattern: fillOutlinePatternUniforms,
circle: circleUniforms,
collisionBox: collisionUniforms,
collisionCircle: collisionCircleUniforms,
debug: debugUniforms,
clippingMask: clippingMaskUniforms,
heatmap: heatmapUniforms,
heatmapTexture: heatmapTextureUniforms,
hillshade: hillshadeUniforms,
hillshadePrepare: hillshadePrepareUniforms,
line: lineUniforms,
lineGradient: lineGradientUniforms,
linePattern: linePatternUniforms,
lineSDF: lineSDFUniforms,
raster: rasterUniforms,
symbolIcon: symbolIconUniforms,
symbolSDF: symbolSDFUniforms,
symbolTextAndIcon: symbolTextAndIconUniforms,
background: backgroundUniforms,
backgroundPattern: backgroundPatternUniforms
};
var quadTriangles;
function drawCollisionDebug(painter, sourceCache, layer, coords, translate, translateAnchor, isText) {
var context = painter.context;
var gl = context.gl;
var program = painter.useProgram('collisionBox');
var tileBatches = [];
var circleCount = 0;
var circleOffset = 0;
for (var i = 0; i < coords.length; i++) {
var coord = coords[i];
var tile = sourceCache.getTile(coord);
var bucket = tile.getBucket(layer);
if (!bucket) {
continue;
}
var posMatrix = coord.posMatrix;
if (translate[0] !== 0 || translate[1] !== 0) {
posMatrix = painter.translatePosMatrix(coord.posMatrix, tile, translate, translateAnchor);
}
var buffers = isText ? bucket.textCollisionBox : bucket.iconCollisionBox;
var circleArray = bucket.collisionCircleArray;
if (circleArray.length > 0) {
var invTransform = performance.create();
var transform = posMatrix;
performance.mul(invTransform, bucket.placementInvProjMatrix, painter.transform.glCoordMatrix);
performance.mul(invTransform, invTransform, bucket.placementViewportMatrix);
tileBatches.push({
circleArray: circleArray,
circleOffset: circleOffset,
transform: transform,
invTransform: invTransform
});
circleCount += circleArray.length / 4;
circleOffset = circleCount;
}
if (!buffers) {
continue;
}
program.draw(context, gl.LINES, DepthMode.disabled, StencilMode.disabled, painter.colorModeForRenderPass(), CullFaceMode.disabled, collisionUniformValues(posMatrix, painter.transform, tile), layer.id, buffers.layoutVertexBuffer, buffers.indexBuffer, buffers.segments, null, painter.transform.zoom, null, null, buffers.collisionVertexBuffer);
}
if (!isText || !tileBatches.length) {
return;
}
var circleProgram = painter.useProgram('collisionCircle');
var vertexData = new performance.StructArrayLayout2f1f2i16();
vertexData.resize(circleCount * 4);
vertexData._trim();
var vertexOffset = 0;
for (var i$2 = 0, list = tileBatches; i$2 < list.length; i$2 += 1) {
var batch = list[i$2];
for (var i$1 = 0; i$1 < batch.circleArray.length / 4; i$1++) {
var circleIdx = i$1 * 4;
var x = batch.circleArray[circleIdx + 0];
var y = batch.circleArray[circleIdx + 1];
var radius = batch.circleArray[circleIdx + 2];
var collision = batch.circleArray[circleIdx + 3];
vertexData.emplace(vertexOffset++, x, y, radius, collision, 0);
vertexData.emplace(vertexOffset++, x, y, radius, collision, 1);
vertexData.emplace(vertexOffset++, x, y, radius, collision, 2);
vertexData.emplace(vertexOffset++, x, y, radius, collision, 3);
}
}
if (!quadTriangles || quadTriangles.length < circleCount * 2) {
quadTriangles = createQuadTriangles(circleCount);
}
var indexBuffer = context.createIndexBuffer(quadTriangles, true);
var vertexBuffer = context.createVertexBuffer(vertexData, performance.collisionCircleLayout.members, true);
for (var i$3 = 0, list$1 = tileBatches; i$3 < list$1.length; i$3 += 1) {
var batch$1 = list$1[i$3];
var uniforms = collisionCircleUniformValues(batch$1.transform, batch$1.invTransform, painter.transform);
circleProgram.draw(context, gl.TRIANGLES, DepthMode.disabled, StencilMode.disabled, painter.colorModeForRenderPass(), CullFaceMode.disabled, uniforms, layer.id, vertexBuffer, indexBuffer, performance.SegmentVector.simpleSegment(0, batch$1.circleOffset * 2, batch$1.circleArray.length, batch$1.circleArray.length / 2), null, painter.transform.zoom, null, null, null);
}
vertexBuffer.destroy();
indexBuffer.destroy();
}
function createQuadTriangles(quadCount) {
var triCount = quadCount * 2;
var array = new performance.StructArrayLayout3ui6();
array.resize(triCount);
array._trim();
for (var i = 0; i < triCount; i++) {
var idx = i * 6;
array.uint16[idx + 0] = i * 4 + 0;
array.uint16[idx + 1] = i * 4 + 1;
array.uint16[idx + 2] = i * 4 + 2;
array.uint16[idx + 3] = i * 4 + 2;
array.uint16[idx + 4] = i * 4 + 3;
array.uint16[idx + 5] = i * 4 + 0;
}
return array;
}
var identityMat4 = performance.identity(new Float32Array(16));
function drawSymbols(painter, sourceCache, layer, coords, variableOffsets) {
if (painter.renderPass !== 'translucent') {
return;
}
var stencilMode = StencilMode.disabled;
var colorMode = painter.colorModeForRenderPass();
var variablePlacement = layer.layout.get('text-variable-anchor');
if (variablePlacement) {
updateVariableAnchors(coords, painter, layer, sourceCache, layer.layout.get('text-rotation-alignment'), layer.layout.get('text-pitch-alignment'), variableOffsets);
}
if (layer.paint.get('icon-opacity').constantOr(1) !== 0) {
drawLayerSymbols(painter, sourceCache, layer, coords, false, layer.paint.get('icon-translate'), layer.paint.get('icon-translate-anchor'), layer.layout.get('icon-rotation-alignment'), layer.layout.get('icon-pitch-alignment'), layer.layout.get('icon-keep-upright'), stencilMode, colorMode);
}
if (layer.paint.get('text-opacity').constantOr(1) !== 0) {
drawLayerSymbols(painter, sourceCache, layer, coords, true, layer.paint.get('text-translate'), layer.paint.get('text-translate-anchor'), layer.layout.get('text-rotation-alignment'), layer.layout.get('text-pitch-alignment'), layer.layout.get('text-keep-upright'), stencilMode, colorMode);
}
if (sourceCache.map.showCollisionBoxes) {
drawCollisionDebug(painter, sourceCache, layer, coords, layer.paint.get('text-translate'), layer.paint.get('text-translate-anchor'), true);
drawCollisionDebug(painter, sourceCache, layer, coords, layer.paint.get('icon-translate'), layer.paint.get('icon-translate-anchor'), false);
}
}
function calculateVariableRenderShift(anchor, width, height, textOffset, textBoxScale, renderTextSize) {
var ref = performance.getAnchorAlignment(anchor);
var horizontalAlign = ref.horizontalAlign;
var verticalAlign = ref.verticalAlign;
var shiftX = -(horizontalAlign - 0.5) * width;
var shiftY = -(verticalAlign - 0.5) * height;
var variableOffset = performance.evaluateVariableOffset(anchor, textOffset);
return new performance.Point((shiftX / textBoxScale + variableOffset[0]) * renderTextSize, (shiftY / textBoxScale + variableOffset[1]) * renderTextSize);
}
function updateVariableAnchors(coords, painter, layer, sourceCache, rotationAlignment, pitchAlignment, variableOffsets) {
var tr = painter.transform;
var rotateWithMap = rotationAlignment === 'map';
var pitchWithMap = pitchAlignment === 'map';
for (var i = 0, list = coords; i < list.length; i += 1) {
var coord = list[i];
var tile = sourceCache.getTile(coord);
var bucket = tile.getBucket(layer);
if (!bucket || !bucket.text || !bucket.text.segments.get().length) {
continue;
}
var sizeData = bucket.textSizeData;
var size = performance.evaluateSizeForZoom(sizeData, tr.zoom);
var pixelToTileScale = pixelsToTileUnits(tile, 1, painter.transform.zoom);
var labelPlaneMatrix = getLabelPlaneMatrix(coord.posMatrix, pitchWithMap, rotateWithMap, painter.transform, pixelToTileScale);
var updateTextFitIcon = layer.layout.get('icon-text-fit') !== 'none' && bucket.hasIconData();
if (size) {
var tileScale = Math.pow(2, tr.zoom - tile.tileID.overscaledZ);
updateVariableAnchorsForBucket(bucket, rotateWithMap, pitchWithMap, variableOffsets, performance.symbolSize, tr, labelPlaneMatrix, coord.posMatrix, tileScale, size, updateTextFitIcon);
}
}
}
function updateVariableAnchorsForBucket(bucket, rotateWithMap, pitchWithMap, variableOffsets, symbolSize, transform, labelPlaneMatrix, posMatrix, tileScale, size, updateTextFitIcon) {
var placedSymbols = bucket.text.placedSymbolArray;
var dynamicTextLayoutVertexArray = bucket.text.dynamicLayoutVertexArray;
var dynamicIconLayoutVertexArray = bucket.icon.dynamicLayoutVertexArray;
var placedTextShifts = {};
dynamicTextLayoutVertexArray.clear();
for (var s = 0; s < placedSymbols.length; s++) {
var symbol = placedSymbols.get(s);
var skipOrientation = bucket.allowVerticalPlacement && !symbol.placedOrientation;
var variableOffset = !symbol.hidden && symbol.crossTileID && !skipOrientation ? variableOffsets[symbol.crossTileID] : null;
if (!variableOffset) {
hideGlyphs(symbol.numGlyphs, dynamicTextLayoutVertexArray);
} else {
var tileAnchor = new performance.Point(symbol.anchorX, symbol.anchorY);
var projectedAnchor = project(tileAnchor, pitchWithMap ? posMatrix : labelPlaneMatrix);
var perspectiveRatio = getPerspectiveRatio(transform.cameraToCenterDistance, projectedAnchor.signedDistanceFromCamera);
var renderTextSize = symbolSize.evaluateSizeForFeature(bucket.textSizeData, size, symbol) * perspectiveRatio / performance.ONE_EM;
if (pitchWithMap) {
renderTextSize *= bucket.tilePixelRatio / tileScale;
}
var width = variableOffset.width;
var height = variableOffset.height;
var anchor = variableOffset.anchor;
var textOffset = variableOffset.textOffset;
var textBoxScale = variableOffset.textBoxScale;
var shift = calculateVariableRenderShift(anchor, width, height, textOffset, textBoxScale, renderTextSize);
var shiftedAnchor = pitchWithMap ? project(tileAnchor.add(shift), labelPlaneMatrix).point : projectedAnchor.point.add(rotateWithMap ? shift.rotate(-transform.angle) : shift);
var angle = bucket.allowVerticalPlacement && symbol.placedOrientation === performance.WritingMode.vertical ? Math.PI / 2 : 0;
for (var g = 0; g < symbol.numGlyphs; g++) {
performance.addDynamicAttributes(dynamicTextLayoutVertexArray, shiftedAnchor, angle);
}
if (updateTextFitIcon && symbol.associatedIconIndex >= 0) {
placedTextShifts[symbol.associatedIconIndex] = {
shiftedAnchor: shiftedAnchor,
angle: angle
};
}
}
}
if (updateTextFitIcon) {
dynamicIconLayoutVertexArray.clear();
var placedIcons = bucket.icon.placedSymbolArray;
for (var i = 0; i < placedIcons.length; i++) {
var placedIcon = placedIcons.get(i);
if (placedIcon.hidden) {
hideGlyphs(placedIcon.numGlyphs, dynamicIconLayoutVertexArray);
} else {
var shift$1 = placedTextShifts[i];
if (!shift$1) {
hideGlyphs(placedIcon.numGlyphs, dynamicIconLayoutVertexArray);
} else {
for (var g$1 = 0; g$1 < placedIcon.numGlyphs; g$1++) {
performance.addDynamicAttributes(dynamicIconLayoutVertexArray, shift$1.shiftedAnchor, shift$1.angle);
}
}
}
}
bucket.icon.dynamicLayoutVertexBuffer.updateData(dynamicIconLayoutVertexArray);
}
bucket.text.dynamicLayoutVertexBuffer.updateData(dynamicTextLayoutVertexArray);
}
function getSymbolProgramName(isSDF, isText, bucket) {
if (bucket.iconsInText && isText) {
return 'symbolTextAndIcon';
} else if (isSDF) {
return 'symbolSDF';
} else {
return 'symbolIcon';
}
}
function drawLayerSymbols(painter, sourceCache, layer, coords, isText, translate, translateAnchor, rotationAlignment, pitchAlignment, keepUpright, stencilMode, colorMode) {
var context = painter.context;
var gl = context.gl;
var tr = painter.transform;
var rotateWithMap = rotationAlignment === 'map';
var pitchWithMap = pitchAlignment === 'map';
var alongLine = rotateWithMap && layer.layout.get('symbol-placement') !== 'point';
var rotateInShader = rotateWithMap && !pitchWithMap && !alongLine;
var hasSortKey = layer.layout.get('symbol-sort-key').constantOr(1) !== undefined;
var sortFeaturesByKey = false;
var depthMode = painter.depthModeForSublayer(0, DepthMode.ReadOnly);
var variablePlacement = layer.layout.get('text-variable-anchor');
var tileRenderState = [];
for (var i$1 = 0, list$1 = coords; i$1 < list$1.length; i$1 += 1) {
var coord = list$1[i$1];
var tile = sourceCache.getTile(coord);
var bucket = tile.getBucket(layer);
if (!bucket) {
continue;
}
var buffers = isText ? bucket.text : bucket.icon;
if (!buffers || !buffers.segments.get().length) {
continue;
}
var programConfiguration = buffers.programConfigurations.get(layer.id);
var isSDF = isText || bucket.sdfIcons;
var sizeData = isText ? bucket.textSizeData : bucket.iconSizeData;
var transformed = pitchWithMap || tr.pitch !== 0;
var program = painter.useProgram(getSymbolProgramName(isSDF, isText, bucket), programConfiguration);
var size = performance.evaluateSizeForZoom(sizeData, tr.zoom);
var texSize = void 0;
var texSizeIcon = [
0,
0
];
var atlasTexture = void 0;
var atlasInterpolation = void 0;
var atlasTextureIcon = null;
var atlasInterpolationIcon = void 0;
if (isText) {
atlasTexture = tile.glyphAtlasTexture;
atlasInterpolation = gl.LINEAR;
texSize = tile.glyphAtlasTexture.size;
if (bucket.iconsInText) {
texSizeIcon = tile.imageAtlasTexture.size;
atlasTextureIcon = tile.imageAtlasTexture;
var zoomDependentSize = sizeData.kind === 'composite' || sizeData.kind === 'camera';
atlasInterpolationIcon = transformed || painter.options.rotating || painter.options.zooming || zoomDependentSize ? gl.LINEAR : gl.NEAREST;
}
} else {
var iconScaled = layer.layout.get('icon-size').constantOr(0) !== 1 || bucket.iconsNeedLinear;
atlasTexture = tile.imageAtlasTexture;
atlasInterpolation = isSDF || painter.options.rotating || painter.options.zooming || iconScaled || transformed ? gl.LINEAR : gl.NEAREST;
texSize = tile.imageAtlasTexture.size;
}
var s = pixelsToTileUnits(tile, 1, painter.transform.zoom);
var labelPlaneMatrix = getLabelPlaneMatrix(coord.posMatrix, pitchWithMap, rotateWithMap, painter.transform, s);
var glCoordMatrix = getGlCoordMatrix(coord.posMatrix, pitchWithMap, rotateWithMap, painter.transform, s);
var hasVariableAnchors = variablePlacement && bucket.hasTextData();
var updateTextFitIcon = layer.layout.get('icon-text-fit') !== 'none' && hasVariableAnchors && bucket.hasIconData();
if (alongLine) {
updateLineLabels(bucket, coord.posMatrix, painter, isText, labelPlaneMatrix, glCoordMatrix, pitchWithMap, keepUpright);
}
var matrix = painter.translatePosMatrix(coord.posMatrix, tile, translate, translateAnchor), uLabelPlaneMatrix = alongLine || isText && variablePlacement || updateTextFitIcon ? identityMat4 : labelPlaneMatrix, uglCoordMatrix = painter.translatePosMatrix(glCoordMatrix, tile, translate, translateAnchor, true);
var hasHalo = isSDF && layer.paint.get(isText ? 'text-halo-width' : 'icon-halo-width').constantOr(1) !== 0;
var uniformValues = void 0;
if (isSDF) {
if (!bucket.iconsInText) {
uniformValues = symbolSDFUniformValues(sizeData.kind, size, rotateInShader, pitchWithMap, painter, matrix, uLabelPlaneMatrix, uglCoordMatrix, isText, texSize, true);
} else {
uniformValues = symbolTextAndIconUniformValues(sizeData.kind, size, rotateInShader, pitchWithMap, painter, matrix, uLabelPlaneMatrix, uglCoordMatrix, texSize, texSizeIcon);
}
} else {
uniformValues = symbolIconUniformValues(sizeData.kind, size, rotateInShader, pitchWithMap, painter, matrix, uLabelPlaneMatrix, uglCoordMatrix, isText, texSize);
}
var state = {
program: program,
buffers: buffers,
uniformValues: uniformValues,
atlasTexture: atlasTexture,
atlasTextureIcon: atlasTextureIcon,
atlasInterpolation: atlasInterpolation,
atlasInterpolationIcon: atlasInterpolationIcon,
isSDF: isSDF,
hasHalo: hasHalo
};
if (hasSortKey && bucket.canOverlap) {
sortFeaturesByKey = true;
var oldSegments = buffers.segments.get();
for (var i = 0, list = oldSegments; i < list.length; i += 1) {
var segment = list[i];
tileRenderState.push({
segments: new performance.SegmentVector([segment]),
sortKey: segment.sortKey,
state: state
});
}
} else {
tileRenderState.push({
segments: buffers.segments,
sortKey: 0,
state: state
});
}
}
if (sortFeaturesByKey) {
tileRenderState.sort(function (a, b) {
return a.sortKey - b.sortKey;
});
}
for (var i$2 = 0, list$2 = tileRenderState; i$2 < list$2.length; i$2 += 1) {
var segmentState = list$2[i$2];
var state$1 = segmentState.state;
context.activeTexture.set(gl.TEXTURE0);
state$1.atlasTexture.bind(state$1.atlasInterpolation, gl.CLAMP_TO_EDGE);
if (state$1.atlasTextureIcon) {
context.activeTexture.set(gl.TEXTURE1);
if (state$1.atlasTextureIcon) {
state$1.atlasTextureIcon.bind(state$1.atlasInterpolationIcon, gl.CLAMP_TO_EDGE);
}
}
if (state$1.isSDF) {
var uniformValues$1 = state$1.uniformValues;
if (state$1.hasHalo) {
uniformValues$1['u_is_halo'] = 1;
drawSymbolElements(state$1.buffers, segmentState.segments, layer, painter, state$1.program, depthMode, stencilMode, colorMode, uniformValues$1);
}
uniformValues$1['u_is_halo'] = 0;
}
drawSymbolElements(state$1.buffers, segmentState.segments, layer, painter, state$1.program, depthMode, stencilMode, colorMode, state$1.uniformValues);
}
}
function drawSymbolElements(buffers, segments, layer, painter, program, depthMode, stencilMode, colorMode, uniformValues) {
var context = painter.context;
var gl = context.gl;
program.draw(context, gl.TRIANGLES, depthMode, stencilMode, colorMode, CullFaceMode.disabled, uniformValues, layer.id, buffers.layoutVertexBuffer, buffers.indexBuffer, segments, layer.paint, painter.transform.zoom, buffers.programConfigurations.get(layer.id), buffers.dynamicLayoutVertexBuffer, buffers.opacityVertexBuffer);
}
function drawCircles(painter, sourceCache, layer, coords) {
if (painter.renderPass !== 'translucent') {
return;
}
var opacity = layer.paint.get('circle-opacity');
var strokeWidth = layer.paint.get('circle-stroke-width');
var strokeOpacity = layer.paint.get('circle-stroke-opacity');
var sortFeaturesByKey = layer.layout.get('circle-sort-key').constantOr(1) !== undefined;
if (opacity.constantOr(1) === 0 && (strokeWidth.constantOr(1) === 0 || strokeOpacity.constantOr(1) === 0)) {
return;
}
var context = painter.context;
var gl = context.gl;
var depthMode = painter.depthModeForSublayer(0, DepthMode.ReadOnly);
var stencilMode = StencilMode.disabled;
var colorMode = painter.colorModeForRenderPass();
var segmentsRenderStates = [];
for (var i = 0; i < coords.length; i++) {
var coord = coords[i];
var tile = sourceCache.getTile(coord);
var bucket = tile.getBucket(layer);
if (!bucket) {
continue;
}
var programConfiguration = bucket.programConfigurations.get(layer.id);
var program = painter.useProgram('circle', programConfiguration);
var layoutVertexBuffer = bucket.layoutVertexBuffer;
var indexBuffer = bucket.indexBuffer;
var uniformValues = circleUniformValues(painter, coord, tile, layer);
var state = {
programConfiguration: programConfiguration,
program: program,
layoutVertexBuffer: layoutVertexBuffer,
indexBuffer: indexBuffer,
uniformValues: uniformValues
};
if (sortFeaturesByKey) {
var oldSegments = bucket.segments.get();
for (var i$1 = 0, list = oldSegments; i$1 < list.length; i$1 += 1) {
var segment = list[i$1];
segmentsRenderStates.push({
segments: new performance.SegmentVector([segment]),
sortKey: segment.sortKey,
state: state
});
}
} else {
segmentsRenderStates.push({
segments: bucket.segments,
sortKey: 0,
state: state
});
}
}
if (sortFeaturesByKey) {
segmentsRenderStates.sort(function (a, b) {
return a.sortKey - b.sortKey;
});
}
for (var i$2 = 0, list$1 = segmentsRenderStates; i$2 < list$1.length; i$2 += 1) {
var segmentsState = list$1[i$2];
var ref = segmentsState.state;
var programConfiguration$1 = ref.programConfiguration;
var program$1 = ref.program;
var layoutVertexBuffer$1 = ref.layoutVertexBuffer;
var indexBuffer$1 = ref.indexBuffer;
var uniformValues$1 = ref.uniformValues;
var segments = segmentsState.segments;
program$1.draw(context, gl.TRIANGLES, depthMode, stencilMode, colorMode, CullFaceMode.disabled, uniformValues$1, layer.id, layoutVertexBuffer$1, indexBuffer$1, segments, layer.paint, painter.transform.zoom, programConfiguration$1);
}
}
function drawHeatmap(painter, sourceCache, layer, coords) {
if (layer.paint.get('heatmap-opacity') === 0) {
return;
}
if (painter.renderPass === 'offscreen') {
var context = painter.context;
var gl = context.gl;
var stencilMode = StencilMode.disabled;
var colorMode = new ColorMode([
gl.ONE,
gl.ONE
], performance.Color.transparent, [
true,
true,
true,
true
]);
bindFramebuffer(context, painter, layer);
context.clear({ color: performance.Color.transparent });
for (var i = 0; i < coords.length; i++) {
var coord = coords[i];
if (sourceCache.hasRenderableParent(coord)) {
continue;
}
var tile = sourceCache.getTile(coord);
var bucket = tile.getBucket(layer);
if (!bucket) {
continue;
}
var programConfiguration = bucket.programConfigurations.get(layer.id);
var program = painter.useProgram('heatmap', programConfiguration);
var ref = painter.transform;
var zoom = ref.zoom;
program.draw(context, gl.TRIANGLES, DepthMode.disabled, stencilMode, colorMode, CullFaceMode.disabled, heatmapUniformValues(coord.posMatrix, tile, zoom, layer.paint.get('heatmap-intensity')), layer.id, bucket.layoutVertexBuffer, bucket.indexBuffer, bucket.segments, layer.paint, painter.transform.zoom, programConfiguration);
}
context.viewport.set([
0,
0,
painter.width,
painter.height
]);
} else if (painter.renderPass === 'translucent') {
painter.context.setColorMode(painter.colorModeForRenderPass());
renderTextureToMap(painter, layer);
}
}
function bindFramebuffer(context, painter, layer) {
var gl = context.gl;
context.activeTexture.set(gl.TEXTURE1);
context.viewport.set([
0,
0,
painter.width / 4,
painter.height / 4
]);
var fbo = layer.heatmapFbo;
if (!fbo) {
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
fbo = layer.heatmapFbo = context.createFramebuffer(painter.width / 4, painter.height / 4, false);
bindTextureToFramebuffer(context, painter, texture, fbo);
} else {
gl.bindTexture(gl.TEXTURE_2D, fbo.colorAttachment.get());
context.bindFramebuffer.set(fbo.framebuffer);
}
}
function bindTextureToFramebuffer(context, painter, texture, fbo) {
var gl = context.gl;
var internalFormat = context.extRenderToTextureHalfFloat ? context.extTextureHalfFloat.HALF_FLOAT_OES : gl.UNSIGNED_BYTE;
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, painter.width / 4, painter.height / 4, 0, gl.RGBA, internalFormat, null);
fbo.colorAttachment.set(texture);
}
function renderTextureToMap(painter, layer) {
var context = painter.context;
var gl = context.gl;
var fbo = layer.heatmapFbo;
if (!fbo) {
return;
}
context.activeTexture.set(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, fbo.colorAttachment.get());
context.activeTexture.set(gl.TEXTURE1);
var colorRampTexture = layer.colorRampTexture;
if (!colorRampTexture) {
colorRampTexture = layer.colorRampTexture = new performance.Texture(context, layer.colorRamp, gl.RGBA);
}
colorRampTexture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
painter.useProgram('heatmapTexture').draw(context, gl.TRIANGLES, DepthMode.disabled, StencilMode.disabled, painter.colorModeForRenderPass(), CullFaceMode.disabled, heatmapTextureUniformValues(painter, layer, 0, 1), layer.id, painter.viewportBuffer, painter.quadTriangleIndexBuffer, painter.viewportSegments, layer.paint, painter.transform.zoom);
}
function drawLine(painter, sourceCache, layer, coords) {
if (painter.renderPass !== 'translucent') {
return;
}
var opacity = layer.paint.get('line-opacity');
var width = layer.paint.get('line-width');
if (opacity.constantOr(1) === 0 || width.constantOr(1) === 0) {
return;
}
var depthMode = painter.depthModeForSublayer(0, DepthMode.ReadOnly);
var colorMode = painter.colorModeForRenderPass();
var dasharray = layer.paint.get('line-dasharray');
var patternProperty = layer.paint.get('line-pattern');
var image = patternProperty.constantOr(1);
var gradient = layer.paint.get('line-gradient');
var crossfade = layer.getCrossfadeParameters();
var programId = image ? 'linePattern' : dasharray ? 'lineSDF' : gradient ? 'lineGradient' : 'line';
var context = painter.context;
var gl = context.gl;
var firstTile = true;
for (var i = 0, list = coords; i < list.length; i += 1) {
var coord = list[i];
var tile = sourceCache.getTile(coord);
if (image && !tile.patternsLoaded()) {
continue;
}
var bucket = tile.getBucket(layer);
if (!bucket) {
continue;
}
var programConfiguration = bucket.programConfigurations.get(layer.id);
var prevProgram = painter.context.program.get();
var program = painter.useProgram(programId, programConfiguration);
var programChanged = firstTile || program.program !== prevProgram;
var constantPattern = patternProperty.constantOr(null);
if (constantPattern && tile.imageAtlas) {
var atlas = tile.imageAtlas;
var posTo = atlas.patternPositions[constantPattern.to.toString()];
var posFrom = atlas.patternPositions[constantPattern.from.toString()];
if (posTo && posFrom) {
programConfiguration.setConstantPatternPositions(posTo, posFrom);
}
}
var uniformValues = image ? linePatternUniformValues(painter, tile, layer, crossfade) : dasharray ? lineSDFUniformValues(painter, tile, layer, dasharray, crossfade) : gradient ? lineGradientUniformValues(painter, tile, layer, bucket.lineClipsArray.length) : lineUniformValues(painter, tile, layer);
if (image) {
context.activeTexture.set(gl.TEXTURE0);
tile.imageAtlasTexture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
programConfiguration.updatePaintBuffers(crossfade);
} else if (dasharray && (programChanged || painter.lineAtlas.dirty)) {
context.activeTexture.set(gl.TEXTURE0);
painter.lineAtlas.bind(context);
} else if (gradient) {
var layerGradient = bucket.gradients[layer.id];
var gradientTexture = layerGradient.texture;
if (layer.gradientVersion !== layerGradient.version) {
var textureResolution = 256;
if (layer.stepInterpolant) {
var sourceMaxZoom = sourceCache.getSource().maxzoom;
var potentialOverzoom = coord.canonical.z === sourceMaxZoom ? Math.ceil(1 << painter.transform.maxZoom - coord.canonical.z) : 1;
var lineLength = bucket.maxLineLength / performance.EXTENT;
var maxTilePixelSize = 1024;
var maxTextureCoverage = lineLength * maxTilePixelSize * potentialOverzoom;
textureResolution = performance.clamp(performance.nextPowerOfTwo(maxTextureCoverage), 256, context.maxTextureSize);
}
layerGradient.gradient = performance.renderColorRamp({
expression: layer.gradientExpression(),
evaluationKey: 'lineProgress',
resolution: textureResolution,
image: layerGradient.gradient || undefined,
clips: bucket.lineClipsArray
});
if (layerGradient.texture) {
layerGradient.texture.update(layerGradient.gradient);
} else {
layerGradient.texture = new performance.Texture(context, layerGradient.gradient, gl.RGBA);
}
layerGradient.version = layer.gradientVersion;
gradientTexture = layerGradient.texture;
}
context.activeTexture.set(gl.TEXTURE0);
gradientTexture.bind(layer.stepInterpolant ? gl.NEAREST : gl.LINEAR, gl.CLAMP_TO_EDGE);
}
program.draw(context, gl.TRIANGLES, depthMode, painter.stencilModeForClipping(coord), colorMode, CullFaceMode.disabled, uniformValues, layer.id, bucket.layoutVertexBuffer, bucket.indexBuffer, bucket.segments, layer.paint, painter.transform.zoom, programConfiguration, bucket.layoutVertexBuffer2);
firstTile = false;
}
}
function drawFill(painter, sourceCache, layer, coords) {
var color = layer.paint.get('fill-color');
var opacity = layer.paint.get('fill-opacity');
if (opacity.constantOr(1) === 0) {
return;
}
var colorMode = painter.colorModeForRenderPass();
var pattern = layer.paint.get('fill-pattern');
var pass = painter.opaquePassEnabledForLayer() && (!pattern.constantOr(1) && color.constantOr(performance.Color.transparent).a === 1 && opacity.constantOr(0) === 1) ? 'opaque' : 'translucent';
if (painter.renderPass === pass) {
var depthMode = painter.depthModeForSublayer(1, painter.renderPass === 'opaque' ? DepthMode.ReadWrite : DepthMode.ReadOnly);
drawFillTiles(painter, sourceCache, layer, coords, depthMode, colorMode, false);
}
if (painter.renderPass === 'translucent' && layer.paint.get('fill-antialias')) {
var depthMode$1 = painter.depthModeForSublayer(layer.getPaintProperty('fill-outline-color') ? 2 : 0, DepthMode.ReadOnly);
drawFillTiles(painter, sourceCache, layer, coords, depthMode$1, colorMode, true);
}
}
function drawFillTiles(painter, sourceCache, layer, coords, depthMode, colorMode, isOutline) {
var gl = painter.context.gl;
var patternProperty = layer.paint.get('fill-pattern');
var image = patternProperty && patternProperty.constantOr(1);
var crossfade = layer.getCrossfadeParameters();
var drawMode, programName, uniformValues, indexBuffer, segments;
if (!isOutline) {
programName = image ? 'fillPattern' : 'fill';
drawMode = gl.TRIANGLES;
} else {
programName = image && !layer.getPaintProperty('fill-outline-color') ? 'fillOutlinePattern' : 'fillOutline';
drawMode = gl.LINES;
}
for (var i = 0, list = coords; i < list.length; i += 1) {
var coord = list[i];
var tile = sourceCache.getTile(coord);
if (image && !tile.patternsLoaded()) {
continue;
}
var bucket = tile.getBucket(layer);
if (!bucket) {
continue;
}
var programConfiguration = bucket.programConfigurations.get(layer.id);
var program = painter.useProgram(programName, programConfiguration);
if (image) {
painter.context.activeTexture.set(gl.TEXTURE0);
tile.imageAtlasTexture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
programConfiguration.updatePaintBuffers(crossfade);
}
var constantPattern = patternProperty.constantOr(null);
if (constantPattern && tile.imageAtlas) {
var atlas = tile.imageAtlas;
var posTo = atlas.patternPositions[constantPattern.to.toString()];
var posFrom = atlas.patternPositions[constantPattern.from.toString()];
if (posTo && posFrom) {
programConfiguration.setConstantPatternPositions(posTo, posFrom);
}
}
var tileMatrix = painter.translatePosMatrix(coord.posMatrix, tile, layer.paint.get('fill-translate'), layer.paint.get('fill-translate-anchor'));
if (!isOutline) {
indexBuffer = bucket.indexBuffer;
segments = bucket.segments;
uniformValues = image ? fillPatternUniformValues(tileMatrix, painter, crossfade, tile) : fillUniformValues(tileMatrix);
} else {
indexBuffer = bucket.indexBuffer2;
segments = bucket.segments2;
var drawingBufferSize = [
gl.drawingBufferWidth,
gl.drawingBufferHeight
];
uniformValues = programName === 'fillOutlinePattern' && image ? fillOutlinePatternUniformValues(tileMatrix, painter, crossfade, tile, drawingBufferSize) : fillOutlineUniformValues(tileMatrix, drawingBufferSize);
}
program.draw(painter.context, drawMode, depthMode, painter.stencilModeForClipping(coord), colorMode, CullFaceMode.disabled, uniformValues, layer.id, bucket.layoutVertexBuffer, indexBuffer, segments, layer.paint, painter.transform.zoom, programConfiguration);
}
}
function draw(painter, source, layer, coords) {
var opacity = layer.paint.get('fill-extrusion-opacity');
if (opacity === 0) {
return;
}
if (painter.renderPass === 'translucent') {
var depthMode = new DepthMode(painter.context.gl.LEQUAL, DepthMode.ReadWrite, painter.depthRangeFor3D);
if (opacity === 1 && !layer.paint.get('fill-extrusion-pattern').constantOr(1)) {
var colorMode = painter.colorModeForRenderPass();
drawExtrusionTiles(painter, source, layer, coords, depthMode, StencilMode.disabled, colorMode);
} else {
drawExtrusionTiles(painter, source, layer, coords, depthMode, StencilMode.disabled, ColorMode.disabled);
drawExtrusionTiles(painter, source, layer, coords, depthMode, painter.stencilModeFor3D(), painter.colorModeForRenderPass());
}
}
}
function drawExtrusionTiles(painter, source, layer, coords, depthMode, stencilMode, colorMode) {
var context = painter.context;
var gl = context.gl;
var patternProperty = layer.paint.get('fill-extrusion-pattern');
var image = patternProperty.constantOr(1);
var crossfade = layer.getCrossfadeParameters();
var opacity = layer.paint.get('fill-extrusion-opacity');
for (var i = 0, list = coords; i < list.length; i += 1) {
var coord = list[i];
var tile = source.getTile(coord);
var bucket = tile.getBucket(layer);
if (!bucket) {
continue;
}
var programConfiguration = bucket.programConfigurations.get(layer.id);
var program = painter.useProgram(image ? 'fillExtrusionPattern' : 'fillExtrusion', programConfiguration);
if (image) {
painter.context.activeTexture.set(gl.TEXTURE0);
tile.imageAtlasTexture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
programConfiguration.updatePaintBuffers(crossfade);
}
var constantPattern = patternProperty.constantOr(null);
if (constantPattern && tile.imageAtlas) {
var atlas = tile.imageAtlas;
var posTo = atlas.patternPositions[constantPattern.to.toString()];
var posFrom = atlas.patternPositions[constantPattern.from.toString()];
if (posTo && posFrom) {
programConfiguration.setConstantPatternPositions(posTo, posFrom);
}
}
var matrix = painter.translatePosMatrix(coord.posMatrix, tile, layer.paint.get('fill-extrusion-translate'), layer.paint.get('fill-extrusion-translate-anchor'));
var shouldUseVerticalGradient = layer.paint.get('fill-extrusion-vertical-gradient');
var uniformValues = image ? fillExtrusionPatternUniformValues(matrix, painter, shouldUseVerticalGradient, opacity, coord, crossfade, tile) : fillExtrusionUniformValues(matrix, painter, shouldUseVerticalGradient, opacity);
program.draw(context, context.gl.TRIANGLES, depthMode, stencilMode, colorMode, CullFaceMode.backCCW, uniformValues, layer.id, bucket.layoutVertexBuffer, bucket.indexBuffer, bucket.segments, layer.paint, painter.transform.zoom, programConfiguration);
}
}
function drawHillshade(painter, sourceCache, layer, tileIDs) {
if (painter.renderPass !== 'offscreen' && painter.renderPass !== 'translucent') {
return;
}
var context = painter.context;
var depthMode = painter.depthModeForSublayer(0, DepthMode.ReadOnly);
var colorMode = painter.colorModeForRenderPass();
var ref = painter.renderPass === 'translucent' ? painter.stencilConfigForOverlap(tileIDs) : [
{},
tileIDs
];
var stencilModes = ref[0];
var coords = ref[1];
for (var i = 0, list = coords; i < list.length; i += 1) {
var coord = list[i];
var tile = sourceCache.getTile(coord);
if (tile.needsHillshadePrepare && painter.renderPass === 'offscreen') {
prepareHillshade(painter, tile, layer, depthMode, StencilMode.disabled, colorMode);
} else if (painter.renderPass === 'translucent') {
renderHillshade(painter, tile, layer, depthMode, stencilModes[coord.overscaledZ], colorMode);
}
}
context.viewport.set([
0,
0,
painter.width,
painter.height
]);
}
function renderHillshade(painter, tile, layer, depthMode, stencilMode, colorMode) {
var context = painter.context;
var gl = context.gl;
var fbo = tile.fbo;
if (!fbo) {
return;
}
var program = painter.useProgram('hillshade');
context.activeTexture.set(gl.TEXTURE0);
gl.bindTexture(gl.TEXTURE_2D, fbo.colorAttachment.get());
var uniformValues = hillshadeUniformValues(painter, tile, layer);
program.draw(context, gl.TRIANGLES, depthMode, stencilMode, colorMode, CullFaceMode.disabled, uniformValues, layer.id, painter.rasterBoundsBuffer, painter.quadTriangleIndexBuffer, painter.rasterBoundsSegments);
}
function prepareHillshade(painter, tile, layer, depthMode, stencilMode, colorMode) {
var context = painter.context;
var gl = context.gl;
var dem = tile.dem;
if (dem && dem.data) {
var tileSize = dem.dim;
var textureStride = dem.stride;
var pixelData = dem.getPixels();
context.activeTexture.set(gl.TEXTURE1);
context.pixelStoreUnpackPremultiplyAlpha.set(false);
tile.demTexture = tile.demTexture || painter.getTileTexture(textureStride);
if (tile.demTexture) {
var demTexture = tile.demTexture;
demTexture.update(pixelData, { premultiply: false });
demTexture.bind(gl.NEAREST, gl.CLAMP_TO_EDGE);
} else {
tile.demTexture = new performance.Texture(context, pixelData, gl.RGBA, { premultiply: false });
tile.demTexture.bind(gl.NEAREST, gl.CLAMP_TO_EDGE);
}
context.activeTexture.set(gl.TEXTURE0);
var fbo = tile.fbo;
if (!fbo) {
var renderTexture = new performance.Texture(context, {
width: tileSize,
height: tileSize,
data: null
}, gl.RGBA);
renderTexture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
fbo = tile.fbo = context.createFramebuffer(tileSize, tileSize, true);
fbo.colorAttachment.set(renderTexture.texture);
}
context.bindFramebuffer.set(fbo.framebuffer);
context.viewport.set([
0,
0,
tileSize,
tileSize
]);
painter.useProgram('hillshadePrepare').draw(context, gl.TRIANGLES, depthMode, stencilMode, colorMode, CullFaceMode.disabled, hillshadeUniformPrepareValues(tile.tileID, dem), layer.id, painter.rasterBoundsBuffer, painter.quadTriangleIndexBuffer, painter.rasterBoundsSegments);
tile.needsHillshadePrepare = false;
}
}
function drawRaster(painter, sourceCache, layer, tileIDs) {
if (painter.renderPass !== 'translucent') {
return;
}
if (layer.paint.get('raster-opacity') === 0) {
return;
}
if (!tileIDs.length) {
return;
}
var context = painter.context;
var gl = context.gl;
var source = sourceCache.getSource();
var program = painter.useProgram('raster');
var colorMode = painter.colorModeForRenderPass();
var ref = source instanceof ImageSource ? [
{},
tileIDs
] : painter.stencilConfigForOverlap(tileIDs);
var stencilModes = ref[0];
var coords = ref[1];
var minTileZ = coords[coords.length - 1].overscaledZ;
var align = !painter.options.moving;
for (var i = 0, list = coords; i < list.length; i += 1) {
var coord = list[i];
var depthMode = painter.depthModeForSublayer(coord.overscaledZ - minTileZ, layer.paint.get('raster-opacity') === 1 ? DepthMode.ReadWrite : DepthMode.ReadOnly, gl.LESS);
var tile = sourceCache.getTile(coord);
var posMatrix = painter.transform.calculatePosMatrix(coord.toUnwrapped(), align);
tile.registerFadeDuration(layer.paint.get('raster-fade-duration'));
var parentTile = sourceCache.findLoadedParent(coord, 0), fade = getFadeValues(tile, parentTile, sourceCache, layer, painter.transform);
var parentScaleBy = void 0, parentTL = void 0;
var textureFilter = layer.paint.get('raster-resampling') === 'nearest' ? gl.NEAREST : gl.LINEAR;
context.activeTexture.set(gl.TEXTURE0);
tile.texture.bind(textureFilter, gl.CLAMP_TO_EDGE, gl.LINEAR_MIPMAP_NEAREST);
context.activeTexture.set(gl.TEXTURE1);
if (parentTile) {
parentTile.texture.bind(textureFilter, gl.CLAMP_TO_EDGE, gl.LINEAR_MIPMAP_NEAREST);
parentScaleBy = Math.pow(2, parentTile.tileID.overscaledZ - tile.tileID.overscaledZ);
parentTL = [
tile.tileID.canonical.x * parentScaleBy % 1,
tile.tileID.canonical.y * parentScaleBy % 1
];
} else {
tile.texture.bind(textureFilter, gl.CLAMP_TO_EDGE, gl.LINEAR_MIPMAP_NEAREST);
}
var uniformValues = rasterUniformValues(posMatrix, parentTL || [
0,
0
], parentScaleBy || 1, fade, layer);
if (source instanceof ImageSource) {
program.draw(context, gl.TRIANGLES, depthMode, StencilMode.disabled, colorMode, CullFaceMode.disabled, uniformValues, layer.id, source.boundsBuffer, painter.quadTriangleIndexBuffer, source.boundsSegments);
} else {
program.draw(context, gl.TRIANGLES, depthMode, stencilModes[coord.overscaledZ], colorMode, CullFaceMode.disabled, uniformValues, layer.id, painter.rasterBoundsBuffer, painter.quadTriangleIndexBuffer, painter.rasterBoundsSegments);
}
}
}
function getFadeValues(tile, parentTile, sourceCache, layer, transform) {
var fadeDuration = layer.paint.get('raster-fade-duration');
if (fadeDuration > 0) {
var now = performance.browser.now();
var sinceTile = (now - tile.timeAdded) / fadeDuration;
var sinceParent = parentTile ? (now - parentTile.timeAdded) / fadeDuration : -1;
var source = sourceCache.getSource();
var idealZ = transform.coveringZoomLevel({
tileSize: source.tileSize,
roundZoom: source.roundZoom
});
var fadeIn = !parentTile || Math.abs(parentTile.tileID.overscaledZ - idealZ) > Math.abs(tile.tileID.overscaledZ - idealZ);
var childOpacity = fadeIn && tile.refreshedUponExpiration ? 1 : performance.clamp(fadeIn ? sinceTile : 1 - sinceParent, 0, 1);
if (tile.refreshedUponExpiration && sinceTile >= 1) {
tile.refreshedUponExpiration = false;
}
if (parentTile) {
return {
opacity: 1,
mix: 1 - childOpacity
};
} else {
return {
opacity: childOpacity,
mix: 0
};
}
} else {
return {
opacity: 1,
mix: 0
};
}
}
function drawBackground(painter, sourceCache, layer) {
var color = layer.paint.get('background-color');
var opacity = layer.paint.get('background-opacity');
if (opacity === 0) {
return;
}
var context = painter.context;
var gl = context.gl;
var transform = painter.transform;
var tileSize = transform.tileSize;
var image = layer.paint.get('background-pattern');
if (painter.isPatternMissing(image)) {
return;
}
var pass = !image && color.a === 1 && opacity === 1 && painter.opaquePassEnabledForLayer() ? 'opaque' : 'translucent';
if (painter.renderPass !== pass) {
return;
}
var stencilMode = StencilMode.disabled;
var depthMode = painter.depthModeForSublayer(0, pass === 'opaque' ? DepthMode.ReadWrite : DepthMode.ReadOnly);
var colorMode = painter.colorModeForRenderPass();
var program = painter.useProgram(image ? 'backgroundPattern' : 'background');
var tileIDs = transform.coveringTiles({ tileSize: tileSize });
if (image) {
context.activeTexture.set(gl.TEXTURE0);
painter.imageManager.bind(painter.context);
}
var crossfade = layer.getCrossfadeParameters();
for (var i = 0, list = tileIDs; i < list.length; i += 1) {
var tileID = list[i];
var matrix = painter.transform.calculatePosMatrix(tileID.toUnwrapped());
var uniformValues = image ? backgroundPatternUniformValues(matrix, opacity, painter, image, {
tileID: tileID,
tileSize: tileSize
}, crossfade) : backgroundUniformValues(matrix, opacity, color);
program.draw(context, gl.TRIANGLES, depthMode, stencilMode, colorMode, CullFaceMode.disabled, uniformValues, layer.id, painter.tileExtentBuffer, painter.quadTriangleIndexBuffer, painter.tileExtentSegments);
}
}
var topColor = new performance.Color(1, 0, 0, 1);
var btmColor = new performance.Color(0, 1, 0, 1);
var leftColor = new performance.Color(0, 0, 1, 1);
var rightColor = new performance.Color(1, 0, 1, 1);
var centerColor = new performance.Color(0, 1, 1, 1);
function drawDebugPadding(painter) {
var padding = painter.transform.padding;
var lineWidth = 3;
drawHorizontalLine(painter, painter.transform.height - (padding.top || 0), lineWidth, topColor);
drawHorizontalLine(painter, padding.bottom || 0, lineWidth, btmColor);
drawVerticalLine(painter, padding.left || 0, lineWidth, leftColor);
drawVerticalLine(painter, painter.transform.width - (padding.right || 0), lineWidth, rightColor);
var center = painter.transform.centerPoint;
drawCrosshair(painter, center.x, painter.transform.height - center.y, centerColor);
}
function drawCrosshair(painter, x, y, color) {
var size = 20;
var lineWidth = 2;
drawDebugSSRect(painter, x - lineWidth / 2, y - size / 2, lineWidth, size, color);
drawDebugSSRect(painter, x - size / 2, y - lineWidth / 2, size, lineWidth, color);
}
function drawHorizontalLine(painter, y, lineWidth, color) {
drawDebugSSRect(painter, 0, y + lineWidth / 2, painter.transform.width, lineWidth, color);
}
function drawVerticalLine(painter, x, lineWidth, color) {
drawDebugSSRect(painter, x - lineWidth / 2, 0, lineWidth, painter.transform.height, color);
}
function drawDebugSSRect(painter, x, y, width, height, color) {
var context = painter.context;
var gl = context.gl;
gl.enable(gl.SCISSOR_TEST);
gl.scissor(x * performance.browser.devicePixelRatio, y * performance.browser.devicePixelRatio, width * performance.browser.devicePixelRatio, height * performance.browser.devicePixelRatio);
context.clear({ color: color });
gl.disable(gl.SCISSOR_TEST);
}
function drawDebug(painter, sourceCache, coords) {
for (var i = 0; i < coords.length; i++) {
drawDebugTile(painter, sourceCache, coords[i]);
}
}
function drawDebugTile(painter, sourceCache, coord) {
var context = painter.context;
var gl = context.gl;
var posMatrix = coord.posMatrix;
var program = painter.useProgram('debug');
var depthMode = DepthMode.disabled;
var stencilMode = StencilMode.disabled;
var colorMode = painter.colorModeForRenderPass();
var id = '$debug';
context.activeTexture.set(gl.TEXTURE0);
painter.emptyTexture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
program.draw(context, gl.LINE_STRIP, depthMode, stencilMode, colorMode, CullFaceMode.disabled, debugUniformValues(posMatrix, performance.Color.red), id, painter.debugBuffer, painter.tileBorderIndexBuffer, painter.debugSegments);
var tileRawData = sourceCache.getTileByID(coord.key).latestRawTileData;
var tileByteLength = tileRawData && tileRawData.byteLength || 0;
var tileSizeKb = Math.floor(tileByteLength / 1024);
var tileSize = sourceCache.getTile(coord).tileSize;
var scaleRatio = 512 / Math.min(tileSize, 512) * (coord.overscaledZ / painter.transform.zoom) * 0.5;
var tileIdText = coord.canonical.toString();
if (coord.overscaledZ !== coord.canonical.z) {
tileIdText += ' => ' + coord.overscaledZ;
}
var tileLabel = tileIdText + ' ' + tileSizeKb + 'kb';
drawTextToOverlay(painter, tileLabel);
program.draw(context, gl.TRIANGLES, depthMode, stencilMode, ColorMode.alphaBlended, CullFaceMode.disabled, debugUniformValues(posMatrix, performance.Color.transparent, scaleRatio), id, painter.debugBuffer, painter.quadTriangleIndexBuffer, painter.debugSegments);
}
function drawTextToOverlay(painter, text) {
painter.initDebugOverlayCanvas();
var canvas = painter.debugOverlayCanvas;
var gl = painter.context.gl;
var ctx2d = painter.debugOverlayCanvas.getContext('2d');
ctx2d.clearRect(0, 0, canvas.width, canvas.height);
ctx2d.shadowColor = 'white';
ctx2d.shadowBlur = 2;
ctx2d.lineWidth = 1.5;
ctx2d.strokeStyle = 'white';
ctx2d.textBaseline = 'top';
ctx2d.font = 'bold ' + 36 + 'px Open Sans, sans-serif';
ctx2d.fillText(text, 5, 5);
ctx2d.strokeText(text, 5, 5);
painter.debugOverlayTexture.update(canvas);
painter.debugOverlayTexture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
}
function drawCustom(painter, sourceCache, layer) {
var context = painter.context;
var implementation = layer.implementation;
if (painter.renderPass === 'offscreen') {
var prerender = implementation.prerender;
if (prerender) {
painter.setCustomLayerDefaults();
context.setColorMode(painter.colorModeForRenderPass());
prerender.call(implementation, context.gl, painter.transform.customLayerMatrix());
context.setDirty();
painter.setBaseState();
}
} else if (painter.renderPass === 'translucent') {
painter.setCustomLayerDefaults();
context.setColorMode(painter.colorModeForRenderPass());
context.setStencilMode(StencilMode.disabled);
var depthMode = implementation.renderingMode === '3d' ? new DepthMode(painter.context.gl.LEQUAL, DepthMode.ReadWrite, painter.depthRangeFor3D) : painter.depthModeForSublayer(0, DepthMode.ReadOnly);
context.setDepthMode(depthMode);
implementation.render(context.gl, painter.transform.customLayerMatrix());
context.setDirty();
painter.setBaseState();
context.bindFramebuffer.set(null);
}
}
var draw$1 = {
symbol: drawSymbols,
circle: drawCircles,
heatmap: drawHeatmap,
line: drawLine,
fill: drawFill,
'fill-extrusion': draw,
hillshade: drawHillshade,
raster: drawRaster,
background: drawBackground,
debug: drawDebug,
custom: drawCustom
};
var Painter = function Painter(gl, transform) {
this.context = new Context(gl);
this.transform = transform;
this._tileTextures = {};
this.setup();
this.numSublayers = SourceCache.maxUnderzooming + SourceCache.maxOverzooming + 1;
this.depthEpsilon = 1 / Math.pow(2, 16);
this.crossTileSymbolIndex = new CrossTileSymbolIndex();
this.gpuTimers = {};
};
Painter.prototype.resize = function resize(width, height) {
this.width = width * performance.browser.devicePixelRatio;
this.height = height * performance.browser.devicePixelRatio;
this.context.viewport.set([
0,
0,
this.width,
this.height
]);
if (this.style) {
for (var i = 0, list = this.style._order; i < list.length; i += 1) {
var layerId = list[i];
this.style._layers[layerId].resize();
}
}
};
Painter.prototype.setup = function setup() {
var context = this.context;
var tileExtentArray = new performance.StructArrayLayout2i4();
tileExtentArray.emplaceBack(0, 0);
tileExtentArray.emplaceBack(performance.EXTENT, 0);
tileExtentArray.emplaceBack(0, performance.EXTENT);
tileExtentArray.emplaceBack(performance.EXTENT, performance.EXTENT);
this.tileExtentBuffer = context.createVertexBuffer(tileExtentArray, posAttributes.members);
this.tileExtentSegments = performance.SegmentVector.simpleSegment(0, 0, 4, 2);
var debugArray = new performance.StructArrayLayout2i4();
debugArray.emplaceBack(0, 0);
debugArray.emplaceBack(performance.EXTENT, 0);
debugArray.emplaceBack(0, performance.EXTENT);
debugArray.emplaceBack(performance.EXTENT, performance.EXTENT);
this.debugBuffer = context.createVertexBuffer(debugArray, posAttributes.members);
this.debugSegments = performance.SegmentVector.simpleSegment(0, 0, 4, 5);
var rasterBoundsArray = new performance.StructArrayLayout4i8();
rasterBoundsArray.emplaceBack(0, 0, 0, 0);
rasterBoundsArray.emplaceBack(performance.EXTENT, 0, performance.EXTENT, 0);
rasterBoundsArray.emplaceBack(0, performance.EXTENT, 0, performance.EXTENT);
rasterBoundsArray.emplaceBack(performance.EXTENT, performance.EXTENT, performance.EXTENT, performance.EXTENT);
this.rasterBoundsBuffer = context.createVertexBuffer(rasterBoundsArray, rasterBoundsAttributes.members);
this.rasterBoundsSegments = performance.SegmentVector.simpleSegment(0, 0, 4, 2);
var viewportArray = new performance.StructArrayLayout2i4();
viewportArray.emplaceBack(0, 0);
viewportArray.emplaceBack(1, 0);
viewportArray.emplaceBack(0, 1);
viewportArray.emplaceBack(1, 1);
this.viewportBuffer = context.createVertexBuffer(viewportArray, posAttributes.members);
this.viewportSegments = performance.SegmentVector.simpleSegment(0, 0, 4, 2);
var tileLineStripIndices = new performance.StructArrayLayout1ui2();
tileLineStripIndices.emplaceBack(0);
tileLineStripIndices.emplaceBack(1);
tileLineStripIndices.emplaceBack(3);
tileLineStripIndices.emplaceBack(2);
tileLineStripIndices.emplaceBack(0);
this.tileBorderIndexBuffer = context.createIndexBuffer(tileLineStripIndices);
var quadTriangleIndices = new performance.StructArrayLayout3ui6();
quadTriangleIndices.emplaceBack(0, 1, 2);
quadTriangleIndices.emplaceBack(2, 1, 3);
this.quadTriangleIndexBuffer = context.createIndexBuffer(quadTriangleIndices);
this.emptyTexture = new performance.Texture(context, {
width: 1,
height: 1,
data: new Uint8Array([
0,
0,
0,
0
])
}, context.gl.RGBA);
var gl = this.context.gl;
this.stencilClearMode = new StencilMode({
func: gl.ALWAYS,
mask: 0
}, 0, 255, gl.ZERO, gl.ZERO, gl.ZERO);
};
Painter.prototype.clearStencil = function clearStencil() {
var context = this.context;
var gl = context.gl;
this.nextStencilID = 1;
this.currentStencilSource = undefined;
var matrix = performance.create();
performance.ortho(matrix, 0, this.width, this.height, 0, 0, 1);
performance.scale(matrix, matrix, [
gl.drawingBufferWidth,
gl.drawingBufferHeight,
0
]);
this.useProgram('clippingMask').draw(context, gl.TRIANGLES, DepthMode.disabled, this.stencilClearMode, ColorMode.disabled, CullFaceMode.disabled, clippingMaskUniformValues(matrix), '$clipping', this.viewportBuffer, this.quadTriangleIndexBuffer, this.viewportSegments);
};
Painter.prototype._renderTileClippingMasks = function _renderTileClippingMasks(layer, tileIDs) {
if (this.currentStencilSource === layer.source || !layer.isTileClipped() || !tileIDs || !tileIDs.length) {
return;
}
this.currentStencilSource = layer.source;
var context = this.context;
var gl = context.gl;
if (this.nextStencilID + tileIDs.length > 256) {
this.clearStencil();
}
context.setColorMode(ColorMode.disabled);
context.setDepthMode(DepthMode.disabled);
var program = this.useProgram('clippingMask');
this._tileClippingMaskIDs = {};
for (var i = 0, list = tileIDs; i < list.length; i += 1) {
var tileID = list[i];
var id = this._tileClippingMaskIDs[tileID.key] = this.nextStencilID++;
program.draw(context, gl.TRIANGLES, DepthMode.disabled, new StencilMode({
func: gl.ALWAYS,
mask: 0
}, id, 255, gl.KEEP, gl.KEEP, gl.REPLACE), ColorMode.disabled, CullFaceMode.disabled, clippingMaskUniformValues(tileID.posMatrix), '$clipping', this.tileExtentBuffer, this.quadTriangleIndexBuffer, this.tileExtentSegments);
}
};
Painter.prototype.stencilModeFor3D = function stencilModeFor3D() {
this.currentStencilSource = undefined;
if (this.nextStencilID + 1 > 256) {
this.clearStencil();
}
var id = this.nextStencilID++;
var gl = this.context.gl;
return new StencilMode({
func: gl.NOTEQUAL,
mask: 255
}, id, 255, gl.KEEP, gl.KEEP, gl.REPLACE);
};
Painter.prototype.stencilModeForClipping = function stencilModeForClipping(tileID) {
var gl = this.context.gl;
return new StencilMode({
func: gl.EQUAL,
mask: 255
}, this._tileClippingMaskIDs[tileID.key], 0, gl.KEEP, gl.KEEP, gl.REPLACE);
};
Painter.prototype.stencilConfigForOverlap = function stencilConfigForOverlap(tileIDs) {
var obj;
var gl = this.context.gl;
var coords = tileIDs.sort(function (a, b) {
return b.overscaledZ - a.overscaledZ;
});
var minTileZ = coords[coords.length - 1].overscaledZ;
var stencilValues = coords[0].overscaledZ - minTileZ + 1;
if (stencilValues > 1) {
this.currentStencilSource = undefined;
if (this.nextStencilID + stencilValues > 256) {
this.clearStencil();
}
var zToStencilMode = {};
for (var i = 0; i < stencilValues; i++) {
zToStencilMode[i + minTileZ] = new StencilMode({
func: gl.GEQUAL,
mask: 255
}, i + this.nextStencilID, 255, gl.KEEP, gl.KEEP, gl.REPLACE);
}
this.nextStencilID += stencilValues;
return [
zToStencilMode,
coords
];
}
return [
(obj = {}, obj[minTileZ] = StencilMode.disabled, obj),
coords
];
};
Painter.prototype.colorModeForRenderPass = function colorModeForRenderPass() {
var gl = this.context.gl;
if (this._showOverdrawInspector) {
var numOverdrawSteps = 8;
var a = 1 / numOverdrawSteps;
return new ColorMode([
gl.CONSTANT_COLOR,
gl.ONE
], new performance.Color(a, a, a, 0), [
true,
true,
true,
true
]);
} else if (this.renderPass === 'opaque') {
return ColorMode.unblended;
} else {
return ColorMode.alphaBlended;
}
};
Painter.prototype.depthModeForSublayer = function depthModeForSublayer(n, mask, func) {
if (!this.opaquePassEnabledForLayer()) {
return DepthMode.disabled;
}
var depth = 1 - ((1 + this.currentLayer) * this.numSublayers + n) * this.depthEpsilon;
return new DepthMode(func || this.context.gl.LEQUAL, mask, [
depth,
depth
]);
};
Painter.prototype.opaquePassEnabledForLayer = function opaquePassEnabledForLayer() {
return this.currentLayer < this.opaquePassCutoff;
};
Painter.prototype.render = function render(style, options) {
var this$1 = this;
this.style = style;
this.options = options;
this.lineAtlas = style.lineAtlas;
this.imageManager = style.imageManager;
this.glyphManager = style.glyphManager;
this.symbolFadeChange = style.placement.symbolFadeChange(performance.browser.now());
this.imageManager.beginFrame();
var layerIds = this.style._order;
var sourceCaches = this.style.sourceCaches;
for (var id in sourceCaches) {
var sourceCache = sourceCaches[id];
if (sourceCache.used) {
sourceCache.prepare(this.context);
}
}
var coordsAscending = {};
var coordsDescending = {};
var coordsDescendingSymbol = {};
for (var id$1 in sourceCaches) {
var sourceCache$1 = sourceCaches[id$1];
coordsAscending[id$1] = sourceCache$1.getVisibleCoordinates();
coordsDescending[id$1] = coordsAscending[id$1].slice().reverse();
coordsDescendingSymbol[id$1] = sourceCache$1.getVisibleCoordinates(true).reverse();
}
this.opaquePassCutoff = Infinity;
for (var i = 0; i < layerIds.length; i++) {
var layerId = layerIds[i];
if (this.style._layers[layerId].is3D()) {
this.opaquePassCutoff = i;
break;
}
}
this.renderPass = 'offscreen';
for (var i$1 = 0, list = layerIds; i$1 < list.length; i$1 += 1) {
var layerId$1 = list[i$1];
var layer = this.style._layers[layerId$1];
if (!layer.hasOffscreenPass() || layer.isHidden(this.transform.zoom)) {
continue;
}
var coords = coordsDescending[layer.source];
if (layer.type !== 'custom' && !coords.length) {
continue;
}
this.renderLayer(this, sourceCaches[layer.source], layer, coords);
}
this.context.bindFramebuffer.set(null);
this.context.clear({
color: options.showOverdrawInspector ? performance.Color.black : performance.Color.transparent,
depth: 1
});
this.clearStencil();
this._showOverdrawInspector = options.showOverdrawInspector;
this.depthRangeFor3D = [
0,
1 - (style._order.length + 2) * this.numSublayers * this.depthEpsilon
];
this.renderPass = 'opaque';
for (this.currentLayer = layerIds.length - 1; this.currentLayer >= 0; this.currentLayer--) {
var layer$1 = this.style._layers[layerIds[this.currentLayer]];
var sourceCache$2 = sourceCaches[layer$1.source];
var coords$1 = coordsAscending[layer$1.source];
this._renderTileClippingMasks(layer$1, coords$1);
this.renderLayer(this, sourceCache$2, layer$1, coords$1);
}
this.renderPass = 'translucent';
for (this.currentLayer = 0; this.currentLayer < layerIds.length; this.currentLayer++) {
var layer$2 = this.style._layers[layerIds[this.currentLayer]];
var sourceCache$3 = sourceCaches[layer$2.source];
var coords$2 = (layer$2.type === 'symbol' ? coordsDescendingSymbol : coordsDescending)[layer$2.source];
this._renderTileClippingMasks(layer$2, coordsAscending[layer$2.source]);
this.renderLayer(this, sourceCache$3, layer$2, coords$2);
}
if (this.options.showTileBoundaries) {
var selectedSource;
var sourceCache$4;
var layers = performance.values(this.style._layers);
layers.forEach(function (layer) {
if (layer.source && !layer.isHidden(this$1.transform.zoom)) {
if (layer.source !== (sourceCache$4 && sourceCache$4.id)) {
sourceCache$4 = this$1.style.sourceCaches[layer.source];
}
if (!selectedSource || selectedSource.getSource().maxzoom < sourceCache$4.getSource().maxzoom) {
selectedSource = sourceCache$4;
}
}
});
if (selectedSource) {
draw$1.debug(this, selectedSource, selectedSource.getVisibleCoordinates());
}
}
if (this.options.showPadding) {
drawDebugPadding(this);
}
this.context.setDefault();
};
Painter.prototype.renderLayer = function renderLayer(painter, sourceCache, layer, coords) {
if (layer.isHidden(this.transform.zoom)) {
return;
}
if (layer.type !== 'background' && layer.type !== 'custom' && !coords.length) {
return;
}
this.id = layer.id;
this.gpuTimingStart(layer);
draw$1[layer.type](painter, sourceCache, layer, coords, this.style.placement.variableOffsets);
this.gpuTimingEnd();
};
Painter.prototype.gpuTimingStart = function gpuTimingStart(layer) {
if (!this.options.gpuTiming) {
return;
}
var ext = this.context.extTimerQuery;
var layerTimer = this.gpuTimers[layer.id];
if (!layerTimer) {
layerTimer = this.gpuTimers[layer.id] = {
calls: 0,
cpuTime: 0,
query: ext.createQueryEXT()
};
}
layerTimer.calls++;
ext.beginQueryEXT(ext.TIME_ELAPSED_EXT, layerTimer.query);
};
Painter.prototype.gpuTimingEnd = function gpuTimingEnd() {
if (!this.options.gpuTiming) {
return;
}
var ext = this.context.extTimerQuery;
ext.endQueryEXT(ext.TIME_ELAPSED_EXT);
};
Painter.prototype.collectGpuTimers = function collectGpuTimers() {
var currentLayerTimers = this.gpuTimers;
this.gpuTimers = {};
return currentLayerTimers;
};
Painter.prototype.queryGpuTimers = function queryGpuTimers(gpuTimers) {
var layers = {};
for (var layerId in gpuTimers) {
var gpuTimer = gpuTimers[layerId];
var ext = this.context.extTimerQuery;
var gpuTime = ext.getQueryObjectEXT(gpuTimer.query, ext.QUERY_RESULT_EXT) / (1000 * 1000);
ext.deleteQueryEXT(gpuTimer.query);
layers[layerId] = gpuTime;
}
return layers;
};
Painter.prototype.translatePosMatrix = function translatePosMatrix(matrix, tile, translate, translateAnchor, inViewportPixelUnitsUnits) {
if (!translate[0] && !translate[1]) {
return matrix;
}
var angle = inViewportPixelUnitsUnits ? translateAnchor === 'map' ? this.transform.angle : 0 : translateAnchor === 'viewport' ? -this.transform.angle : 0;
if (angle) {
var sinA = Math.sin(angle);
var cosA = Math.cos(angle);
translate = [
translate[0] * cosA - translate[1] * sinA,
translate[0] * sinA + translate[1] * cosA
];
}
var translation = [
inViewportPixelUnitsUnits ? translate[0] : pixelsToTileUnits(tile, translate[0], this.transform.zoom),
inViewportPixelUnitsUnits ? translate[1] : pixelsToTileUnits(tile, translate[1], this.transform.zoom),
0
];
var translatedMatrix = new Float32Array(16);
performance.translate(translatedMatrix, matrix, translation);
return translatedMatrix;
};
Painter.prototype.saveTileTexture = function saveTileTexture(texture) {
var textures = this._tileTextures[texture.size[0]];
if (!textures) {
this._tileTextures[texture.size[0]] = [texture];
} else {
textures.push(texture);
}
};
Painter.prototype.getTileTexture = function getTileTexture(size) {
var textures = this._tileTextures[size];
return textures && textures.length > 0 ? textures.pop() : null;
};
Painter.prototype.isPatternMissing = function isPatternMissing(image) {
if (!image) {
return false;
}
if (!image.from || !image.to) {
return true;
}
var imagePosA = this.imageManager.getPattern(image.from.toString());
var imagePosB = this.imageManager.getPattern(image.to.toString());
return !imagePosA || !imagePosB;
};
Painter.prototype.useProgram = function useProgram(name, programConfiguration) {
this.cache = this.cache || {};
var key = '' + name + (programConfiguration ? programConfiguration.cacheKey : '') + (this._showOverdrawInspector ? '/overdraw' : '');
if (!this.cache[key]) {
this.cache[key] = new Program$1(this.context, name, shaders[name], programConfiguration, programUniforms[name], this._showOverdrawInspector);
}
return this.cache[key];
};
Painter.prototype.setCustomLayerDefaults = function setCustomLayerDefaults() {
this.context.unbindVAO();
this.context.cullFace.setDefault();
this.context.activeTexture.setDefault();
this.context.pixelStoreUnpack.setDefault();
this.context.pixelStoreUnpackPremultiplyAlpha.setDefault();
this.context.pixelStoreUnpackFlipY.setDefault();
};
Painter.prototype.setBaseState = function setBaseState() {
var gl = this.context.gl;
this.context.cullFace.set(false);
this.context.viewport.set([
0,
0,
this.width,
this.height
]);
this.context.blendEquation.set(gl.FUNC_ADD);
};
Painter.prototype.initDebugOverlayCanvas = function initDebugOverlayCanvas() {
if (this.debugOverlayCanvas == null) {
this.debugOverlayCanvas = performance.window.document.createElement('canvas');
this.debugOverlayCanvas.width = 512;
this.debugOverlayCanvas.height = 512;
var gl = this.context.gl;
this.debugOverlayTexture = new performance.Texture(this.context, this.debugOverlayCanvas, gl.RGBA);
}
};
Painter.prototype.destroy = function destroy() {
this.emptyTexture.destroy();
if (this.debugOverlayTexture) {
this.debugOverlayTexture.destroy();
}
};
var Frustum = function Frustum(points_, planes_) {
this.points = points_;
this.planes = planes_;
};
Frustum.fromInvProjectionMatrix = function fromInvProjectionMatrix(invProj, worldSize, zoom) {
var clipSpaceCorners = [
[
-1,
1,
-1,
1
],
[
1,
1,
-1,
1
],
[
1,
-1,
-1,
1
],
[
-1,
-1,
-1,
1
],
[
-1,
1,
1,
1
],
[
1,
1,
1,
1
],
[
1,
-1,
1,
1
],
[
-1,
-1,
1,
1
]
];
var scale = Math.pow(2, zoom);
var frustumCoords = clipSpaceCorners.map(function (v) {
return performance.transformMat4([], v, invProj);
}).map(function (v) {
return performance.scale$1([], v, 1 / v[3] / worldSize * scale);
});
var frustumPlanePointIndices = [
[
0,
1,
2
],
[
6,
5,
4
],
[
0,
3,
7
],
[
2,
1,
5
],
[
3,
2,
6
],
[
0,
4,
5
]
];
var frustumPlanes = frustumPlanePointIndices.map(function (p) {
var a = performance.sub([], frustumCoords[p[0]], frustumCoords[p[1]]);
var b = performance.sub([], frustumCoords[p[2]], frustumCoords[p[1]]);
var n = performance.normalize([], performance.cross([], a, b));
var d = -performance.dot(n, frustumCoords[p[1]]);
return n.concat(d);
});
return new Frustum(frustumCoords, frustumPlanes);
};
var Aabb = function Aabb(min_, max_) {
this.min = min_;
this.max = max_;
this.center = performance.scale$2([], performance.add([], this.min, this.max), 0.5);
};
Aabb.prototype.quadrant = function quadrant(index) {
var split = [
index % 2 === 0,
index < 2
];
var qMin = performance.clone$2(this.min);
var qMax = performance.clone$2(this.max);
for (var axis = 0; axis < split.length; axis++) {
qMin[axis] = split[axis] ? this.min[axis] : this.center[axis];
qMax[axis] = split[axis] ? this.center[axis] : this.max[axis];
}
qMax[2] = this.max[2];
return new Aabb(qMin, qMax);
};
Aabb.prototype.distanceX = function distanceX(point) {
var pointOnAabb = Math.max(Math.min(this.max[0], point[0]), this.min[0]);
return pointOnAabb - point[0];
};
Aabb.prototype.distanceY = function distanceY(point) {
var pointOnAabb = Math.max(Math.min(this.max[1], point[1]), this.min[1]);
return pointOnAabb - point[1];
};
Aabb.prototype.intersects = function intersects(frustum) {
var aabbPoints = [
[
this.min[0],
this.min[1],
0,
1
],
[
this.max[0],
this.min[1],
0,
1
],
[
this.max[0],
this.max[1],
0,
1
],
[
this.min[0],
this.max[1],
0,
1
]
];
var fullyInside = true;
for (var p = 0; p < frustum.planes.length; p++) {
var plane = frustum.planes[p];
var pointsInside = 0;
for (var i = 0; i < aabbPoints.length; i++) {
pointsInside += performance.dot$1(plane, aabbPoints[i]) >= 0;
}
if (pointsInside === 0) {
return 0;
}
if (pointsInside !== aabbPoints.length) {
fullyInside = false;
}
}
if (fullyInside) {
return 2;
}
for (var axis = 0; axis < 3; axis++) {
var projMin = Number.MAX_VALUE;
var projMax = -Number.MAX_VALUE;
for (var p$1 = 0; p$1 < frustum.points.length; p$1++) {
var projectedPoint = frustum.points[p$1][axis] - this.min[axis];
projMin = Math.min(projMin, projectedPoint);
projMax = Math.max(projMax, projectedPoint);
}
if (projMax < 0 || projMin > this.max[axis] - this.min[axis]) {
return 0;
}
}
return 1;
};
var EdgeInsets = function EdgeInsets(top, bottom, left, right) {
if (top === void 0)
top = 0;
if (bottom === void 0)
bottom = 0;
if (left === void 0)
left = 0;
if (right === void 0)
right = 0;
if (isNaN(top) || top < 0 || isNaN(bottom) || bottom < 0 || isNaN(left) || left < 0 || isNaN(right) || right < 0) {
throw new Error('Invalid value for edge-insets, top, bottom, left and right must all be numbers');
}
this.top = top;
this.bottom = bottom;
this.left = left;
this.right = right;
};
EdgeInsets.prototype.interpolate = function interpolate(start, target, t) {
if (target.top != null && start.top != null) {
this.top = performance.number(start.top, target.top, t);
}
if (target.bottom != null && start.bottom != null) {
this.bottom = performance.number(start.bottom, target.bottom, t);
}
if (target.left != null && start.left != null) {
this.left = performance.number(start.left, target.left, t);
}
if (target.right != null && start.right != null) {
this.right = performance.number(start.right, target.right, t);
}
return this;
};
EdgeInsets.prototype.getCenter = function getCenter(width, height) {
var x = performance.clamp((this.left + width - this.right) / 2, 0, width);
var y = performance.clamp((this.top + height - this.bottom) / 2, 0, height);
return new performance.Point(x, y);
};
EdgeInsets.prototype.equals = function equals(other) {
return this.top === other.top && this.bottom === other.bottom && this.left === other.left && this.right === other.right;
};
EdgeInsets.prototype.clone = function clone() {
return new EdgeInsets(this.top, this.bottom, this.left, this.right);
};
EdgeInsets.prototype.toJSON = function toJSON() {
return {
top: this.top,
bottom: this.bottom,
left: this.left,
right: this.right
};
};
var Transform = function Transform(minZoom, maxZoom, minPitch, maxPitch, renderWorldCopies) {
this.tileSize = 512;
this.maxValidLatitude = 85.051129;
this._renderWorldCopies = renderWorldCopies === undefined ? true : renderWorldCopies;
this._minZoom = minZoom || 0;
this._maxZoom = maxZoom || 22;
this._minPitch = minPitch === undefined || minPitch === null ? 0 : minPitch;
this._maxPitch = maxPitch === undefined || maxPitch === null ? 60 : maxPitch;
this.setMaxBounds();
this.width = 0;
this.height = 0;
this._center = new performance.LngLat(0, 0);
this.zoom = 0;
this.angle = 0;
this._fov = 0.6435011087932844;
this._pitch = 0;
this._unmodified = true;
this._edgeInsets = new EdgeInsets();
this._posMatrixCache = {};
this._alignedPosMatrixCache = {};
};
var prototypeAccessors = {
minZoom: { configurable: true },
maxZoom: { configurable: true },
minPitch: { configurable: true },
maxPitch: { configurable: true },
renderWorldCopies: { configurable: true },
worldSize: { configurable: true },
centerOffset: { configurable: true },
size: { configurable: true },
bearing: { configurable: true },
pitch: { configurable: true },
fov: { configurable: true },
zoom: { configurable: true },
center: { configurable: true },
padding: { configurable: true },
centerPoint: { configurable: true },
unmodified: { configurable: true },
point: { configurable: true }
};
Transform.prototype.clone = function clone() {
var clone = new Transform(this._minZoom, this._maxZoom, this._minPitch, this.maxPitch, this._renderWorldCopies);
clone.tileSize = this.tileSize;
clone.latRange = this.latRange;
clone.width = this.width;
clone.height = this.height;
clone._center = this._center;
clone.zoom = this.zoom;
clone.angle = this.angle;
clone._fov = this._fov;
clone._pitch = this._pitch;
clone._unmodified = this._unmodified;
clone._edgeInsets = this._edgeInsets.clone();
clone._calcMatrices();
return clone;
};
prototypeAccessors.minZoom.get = function () {
return this._minZoom;
};
prototypeAccessors.minZoom.set = function (zoom) {
if (this._minZoom === zoom) {
return;
}
this._minZoom = zoom;
this.zoom = Math.max(this.zoom, zoom);
};
prototypeAccessors.maxZoom.get = function () {
return this._maxZoom;
};
prototypeAccessors.maxZoom.set = function (zoom) {
if (this._maxZoom === zoom) {
return;
}
this._maxZoom = zoom;
this.zoom = Math.min(this.zoom, zoom);
};
prototypeAccessors.minPitch.get = function () {
return this._minPitch;
};
prototypeAccessors.minPitch.set = function (pitch) {
if (this._minPitch === pitch) {
return;
}
this._minPitch = pitch;
this.pitch = Math.max(this.pitch, pitch);
};
prototypeAccessors.maxPitch.get = function () {
return this._maxPitch;
};
prototypeAccessors.maxPitch.set = function (pitch) {
if (this._maxPitch === pitch) {
return;
}
this._maxPitch = pitch;
this.pitch = Math.min(this.pitch, pitch);
};
prototypeAccessors.renderWorldCopies.get = function () {
return this._renderWorldCopies;
};
prototypeAccessors.renderWorldCopies.set = function (renderWorldCopies) {
if (renderWorldCopies === undefined) {
renderWorldCopies = true;
} else if (renderWorldCopies === null) {
renderWorldCopies = false;
}
this._renderWorldCopies = renderWorldCopies;
};
prototypeAccessors.worldSize.get = function () {
return this.tileSize * this.scale;
};
prototypeAccessors.centerOffset.get = function () {
return this.centerPoint._sub(this.size._div(2));
};
prototypeAccessors.size.get = function () {
return new performance.Point(this.width, this.height);
};
prototypeAccessors.bearing.get = function () {
return -this.angle / Math.PI * 180;
};
prototypeAccessors.bearing.set = function (bearing) {
var b = -performance.wrap(bearing, -180, 180) * Math.PI / 180;
if (this.angle === b) {
return;
}
this._unmodified = false;
this.angle = b;
this._calcMatrices();
this.rotationMatrix = performance.create$2();
performance.rotate(this.rotationMatrix, this.rotationMatrix, this.angle);
};
prototypeAccessors.pitch.get = function () {
return this._pitch / Math.PI * 180;
};
prototypeAccessors.pitch.set = function (pitch) {
var p = performance.clamp(pitch, this.minPitch, this.maxPitch) / 180 * Math.PI;
if (this._pitch === p) {
return;
}
this._unmodified = false;
this._pitch = p;
this._calcMatrices();
};
prototypeAccessors.fov.get = function () {
return this._fov / Math.PI * 180;
};
prototypeAccessors.fov.set = function (fov) {
fov = Math.max(0.01, Math.min(60, fov));
if (this._fov === fov) {
return;
}
this._unmodified = false;
this._fov = fov / 180 * Math.PI;
this._calcMatrices();
};
prototypeAccessors.zoom.get = function () {
return this._zoom;
};
prototypeAccessors.zoom.set = function (zoom) {
var z = Math.min(Math.max(zoom, this.minZoom), this.maxZoom);
if (this._zoom === z) {
return;
}
this._unmodified = false;
this._zoom = z;
this.scale = this.zoomScale(z);
this.tileZoom = Math.floor(z);
this.zoomFraction = z - this.tileZoom;
this._constrain();
this._calcMatrices();
};
prototypeAccessors.center.get = function () {
return this._center;
};
prototypeAccessors.center.set = function (center) {
if (center.lat === this._center.lat && center.lng === this._center.lng) {
return;
}
this._unmodified = false;
this._center = center;
this._constrain();
this._calcMatrices();
};
prototypeAccessors.padding.get = function () {
return this._edgeInsets.toJSON();
};
prototypeAccessors.padding.set = function (padding) {
if (this._edgeInsets.equals(padding)) {
return;
}
this._unmodified = false;
this._edgeInsets.interpolate(this._edgeInsets, padding, 1);
this._calcMatrices();
};
prototypeAccessors.centerPoint.get = function () {
return this._edgeInsets.getCenter(this.width, this.height);
};
Transform.prototype.isPaddingEqual = function isPaddingEqual(padding) {
return this._edgeInsets.equals(padding);
};
Transform.prototype.interpolatePadding = function interpolatePadding(start, target, t) {
this._unmodified = false;
this._edgeInsets.interpolate(start, target, t);
this._constrain();
this._calcMatrices();
};
Transform.prototype.coveringZoomLevel = function coveringZoomLevel(options) {
var z = (options.roundZoom ? Math.round : Math.floor)(this.zoom + this.scaleZoom(this.tileSize / options.tileSize));
return Math.max(0, z);
};
Transform.prototype.getVisibleUnwrappedCoordinates = function getVisibleUnwrappedCoordinates(tileID) {
var result = [new performance.UnwrappedTileID(0, tileID)];
if (this._renderWorldCopies) {
var utl = this.pointCoordinate(new performance.Point(0, 0));
var utr = this.pointCoordinate(new performance.Point(this.width, 0));
var ubl = this.pointCoordinate(new performance.Point(this.width, this.height));
var ubr = this.pointCoordinate(new performance.Point(0, this.height));
var w0 = Math.floor(Math.min(utl.x, utr.x, ubl.x, ubr.x));
var w1 = Math.floor(Math.max(utl.x, utr.x, ubl.x, ubr.x));
var extraWorldCopy = 1;
for (var w = w0 - extraWorldCopy; w <= w1 + extraWorldCopy; w++) {
if (w === 0) {
continue;
}
result.push(new performance.UnwrappedTileID(w, tileID));
}
}
return result;
};
Transform.prototype.coveringTiles = function coveringTiles(options) {
var z = this.coveringZoomLevel(options);
var actualZ = z;
if (options.minzoom !== undefined && z < options.minzoom) {
return [];
}
if (options.maxzoom !== undefined && z > options.maxzoom) {
z = options.maxzoom;
}
var centerCoord = performance.MercatorCoordinate.fromLngLat(this.center);
var numTiles = Math.pow(2, z);
var centerPoint = [
numTiles * centerCoord.x,
numTiles * centerCoord.y,
0
];
var cameraFrustum = Frustum.fromInvProjectionMatrix(this.invProjMatrix, this.worldSize, z);
var minZoom = options.minzoom || 0;
if (this.pitch <= 60 && this._edgeInsets.top < 0.1) {
minZoom = z;
}
var radiusOfMaxLvlLodInTiles = 3;
var newRootTile = function (wrap) {
return {
aabb: new Aabb([
wrap * numTiles,
0,
0
], [
(wrap + 1) * numTiles,
numTiles,
0
]),
zoom: 0,
x: 0,
y: 0,
wrap: wrap,
fullyVisible: false
};
};
var stack = [];
var result = [];
var maxZoom = z;
var overscaledZ = options.reparseOverscaled ? actualZ : z;
if (this._renderWorldCopies) {
for (var i = 1; i <= 3; i++) {
stack.push(newRootTile(-i));
stack.push(newRootTile(i));
}
}
stack.push(newRootTile(0));
while (stack.length > 0) {
var it = stack.pop();
var x = it.x;
var y = it.y;
var fullyVisible = it.fullyVisible;
if (!fullyVisible) {
var intersectResult = it.aabb.intersects(cameraFrustum);
if (intersectResult === 0) {
continue;
}
fullyVisible = intersectResult === 2;
}
var distanceX = it.aabb.distanceX(centerPoint);
var distanceY = it.aabb.distanceY(centerPoint);
var longestDim = Math.max(Math.abs(distanceX), Math.abs(distanceY));
var distToSplit = radiusOfMaxLvlLodInTiles + (1 << maxZoom - it.zoom) - 2;
if (it.zoom === maxZoom || longestDim > distToSplit && it.zoom >= minZoom) {
result.push({
tileID: new performance.OverscaledTileID(it.zoom === maxZoom ? overscaledZ : it.zoom, it.wrap, it.zoom, x, y),
distanceSq: performance.sqrLen([
centerPoint[0] - 0.5 - x,
centerPoint[1] - 0.5 - y
])
});
continue;
}
for (var i$1 = 0; i$1 < 4; i$1++) {
var childX = (x << 1) + i$1 % 2;
var childY = (y << 1) + (i$1 >> 1);
stack.push({
aabb: it.aabb.quadrant(i$1),
zoom: it.zoom + 1,
x: childX,
y: childY,
wrap: it.wrap,
fullyVisible: fullyVisible
});
}
}
return result.sort(function (a, b) {
return a.distanceSq - b.distanceSq;
}).map(function (a) {
return a.tileID;
});
};
Transform.prototype.resize = function resize(width, height) {
this.width = width;
this.height = height;
this.pixelsToGLUnits = [
2 / width,
-2 / height
];
this._constrain();
this._calcMatrices();
};
prototypeAccessors.unmodified.get = function () {
return this._unmodified;
};
Transform.prototype.zoomScale = function zoomScale(zoom) {
return Math.pow(2, zoom);
};
Transform.prototype.scaleZoom = function scaleZoom(scale) {
return Math.log(scale) / Math.LN2;
};
Transform.prototype.project = function project(lnglat) {
var lat = performance.clamp(lnglat.lat, -this.maxValidLatitude, this.maxValidLatitude);
return new performance.Point(performance.mercatorXfromLng(lnglat.lng) * this.worldSize, performance.mercatorYfromLat(lat) * this.worldSize);
};
Transform.prototype.unproject = function unproject(point) {
return new performance.MercatorCoordinate(point.x / this.worldSize, point.y / this.worldSize).toLngLat();
};
prototypeAccessors.point.get = function () {
return this.project(this.center);
};
Transform.prototype.setLocationAtPoint = function setLocationAtPoint(lnglat, point) {
var a = this.pointCoordinate(point);
var b = this.pointCoordinate(this.centerPoint);
var loc = this.locationCoordinate(lnglat);
var newCenter = new performance.MercatorCoordinate(loc.x - (a.x - b.x), loc.y - (a.y - b.y));
this.center = this.coordinateLocation(newCenter);
if (this._renderWorldCopies) {
this.center = this.center.wrap();
}
};
Transform.prototype.locationPoint = function locationPoint(lnglat) {
return this.coordinatePoint(this.locationCoordinate(lnglat));
};
Transform.prototype.pointLocation = function pointLocation(p) {
return this.coordinateLocation(this.pointCoordinate(p));
};
Transform.prototype.locationCoordinate = function locationCoordinate(lnglat) {
return performance.MercatorCoordinate.fromLngLat(lnglat);
};
Transform.prototype.coordinateLocation = function coordinateLocation(coord) {
return coord.toLngLat();
};
Transform.prototype.pointCoordinate = function pointCoordinate(p) {
var targetZ = 0;
var coord0 = [
p.x,
p.y,
0,
1
];
var coord1 = [
p.x,
p.y,
1,
1
];
performance.transformMat4(coord0, coord0, this.pixelMatrixInverse);
performance.transformMat4(coord1, coord1, this.pixelMatrixInverse);
var w0 = coord0[3];
var w1 = coord1[3];
var x0 = coord0[0] / w0;
var x1 = coord1[0] / w1;
var y0 = coord0[1] / w0;
var y1 = coord1[1] / w1;
var z0 = coord0[2] / w0;
var z1 = coord1[2] / w1;
var t = z0 === z1 ? 0 : (targetZ - z0) / (z1 - z0);
return new performance.MercatorCoordinate(performance.number(x0, x1, t) / this.worldSize, performance.number(y0, y1, t) / this.worldSize);
};
Transform.prototype.coordinatePoint = function coordinatePoint(coord) {
var p = [
coord.x * this.worldSize,
coord.y * this.worldSize,
0,
1
];
performance.transformMat4(p, p, this.pixelMatrix);
return new performance.Point(p[0] / p[3], p[1] / p[3]);
};
Transform.prototype.getBounds = function getBounds() {
return new performance.LngLatBounds().extend(this.pointLocation(new performance.Point(0, 0))).extend(this.pointLocation(new performance.Point(this.width, 0))).extend(this.pointLocation(new performance.Point(this.width, this.height))).extend(this.pointLocation(new performance.Point(0, this.height)));
};
Transform.prototype.getMaxBounds = function getMaxBounds() {
if (!this.latRange || this.latRange.length !== 2 || !this.lngRange || this.lngRange.length !== 2) {
return null;
}
return new performance.LngLatBounds([
this.lngRange[0],
this.latRange[0]
], [
this.lngRange[1],
this.latRange[1]
]);
};
Transform.prototype.setMaxBounds = function setMaxBounds(bounds) {
if (bounds) {
this.lngRange = [
bounds.getWest(),
bounds.getEast()
];
this.latRange = [
bounds.getSouth(),
bounds.getNorth()
];
this._constrain();
} else {
this.lngRange = null;
this.latRange = [
-this.maxValidLatitude,
this.maxValidLatitude
];
}
};
Transform.prototype.calculatePosMatrix = function calculatePosMatrix(unwrappedTileID, aligned) {
if (aligned === void 0)
aligned = false;
var posMatrixKey = unwrappedTileID.key;
var cache = aligned ? this._alignedPosMatrixCache : this._posMatrixCache;
if (cache[posMatrixKey]) {
return cache[posMatrixKey];
}
var canonical = unwrappedTileID.canonical;
var scale = this.worldSize / this.zoomScale(canonical.z);
var unwrappedX = canonical.x + Math.pow(2, canonical.z) * unwrappedTileID.wrap;
var posMatrix = performance.identity(new Float64Array(16));
performance.translate(posMatrix, posMatrix, [
unwrappedX * scale,
canonical.y * scale,
0
]);
performance.scale(posMatrix, posMatrix, [
scale / performance.EXTENT,
scale / performance.EXTENT,
1
]);
performance.multiply(posMatrix, aligned ? this.alignedProjMatrix : this.projMatrix, posMatrix);
cache[posMatrixKey] = new Float32Array(posMatrix);
return cache[posMatrixKey];
};
Transform.prototype.customLayerMatrix = function customLayerMatrix() {
return this.mercatorMatrix.slice();
};
Transform.prototype._constrain = function _constrain() {
if (!this.center || !this.width || !this.height || this._constraining) {
return;
}
this._constraining = true;
var minY = -90;
var maxY = 90;
var minX = -180;
var maxX = 180;
var sy, sx, x2, y2;
var size = this.size, unmodified = this._unmodified;
if (this.latRange) {
var latRange = this.latRange;
minY = performance.mercatorYfromLat(latRange[1]) * this.worldSize;
maxY = performance.mercatorYfromLat(latRange[0]) * this.worldSize;
sy = maxY - minY < size.y ? size.y / (maxY - minY) : 0;
}
if (this.lngRange) {
var lngRange = this.lngRange;
minX = performance.mercatorXfromLng(lngRange[0]) * this.worldSize;
maxX = performance.mercatorXfromLng(lngRange[1]) * this.worldSize;
sx = maxX - minX < size.x ? size.x / (maxX - minX) : 0;
}
var point = this.point;
var s = Math.max(sx || 0, sy || 0);
if (s) {
this.center = this.unproject(new performance.Point(sx ? (maxX + minX) / 2 : point.x, sy ? (maxY + minY) / 2 : point.y));
this.zoom += this.scaleZoom(s);
this._unmodified = unmodified;
this._constraining = false;
return;
}
if (this.latRange) {
var y = point.y, h2 = size.y / 2;
if (y - h2 < minY) {
y2 = minY + h2;
}
if (y + h2 > maxY) {
y2 = maxY - h2;
}
}
if (this.lngRange) {
var x = point.x, w2 = size.x / 2;
if (x - w2 < minX) {
x2 = minX + w2;
}
if (x + w2 > maxX) {
x2 = maxX - w2;
}
}
if (x2 !== undefined || y2 !== undefined) {
this.center = this.unproject(new performance.Point(x2 !== undefined ? x2 : point.x, y2 !== undefined ? y2 : point.y));
}
this._unmodified = unmodified;
this._constraining = false;
};
Transform.prototype._calcMatrices = function _calcMatrices() {
if (!this.height) {
return;
}
var halfFov = this._fov / 2;
var offset = this.centerOffset;
this.cameraToCenterDistance = 0.5 / Math.tan(halfFov) * this.height;
var groundAngle = Math.PI / 2 + this._pitch;
var fovAboveCenter = this._fov * (0.5 + offset.y / this.height);
var topHalfSurfaceDistance = Math.sin(fovAboveCenter) * this.cameraToCenterDistance / Math.sin(performance.clamp(Math.PI - groundAngle - fovAboveCenter, 0.01, Math.PI - 0.01));
var point = this.point;
var x = point.x, y = point.y;
var furthestDistance = Math.cos(Math.PI / 2 - this._pitch) * topHalfSurfaceDistance + this.cameraToCenterDistance;
var farZ = furthestDistance * 1.01;
var nearZ = this.height / 50;
var m = new Float64Array(16);
performance.perspective(m, this._fov, this.width / this.height, nearZ, farZ);
m[8] = -offset.x * 2 / this.width;
m[9] = offset.y * 2 / this.height;
performance.scale(m, m, [
1,
-1,
1
]);
performance.translate(m, m, [
0,
0,
-this.cameraToCenterDistance
]);
performance.rotateX(m, m, this._pitch);
performance.rotateZ(m, m, this.angle);
performance.translate(m, m, [
-x,
-y,
0
]);
this.mercatorMatrix = performance.scale([], m, [
this.worldSize,
this.worldSize,
this.worldSize
]);
performance.scale(m, m, [
1,
1,
performance.mercatorZfromAltitude(1, this.center.lat) * this.worldSize,
1
]);
this.projMatrix = m;
this.invProjMatrix = performance.invert([], this.projMatrix);
var xShift = this.width % 2 / 2, yShift = this.height % 2 / 2, angleCos = Math.cos(this.angle), angleSin = Math.sin(this.angle), dx = x - Math.round(x) + angleCos * xShift + angleSin * yShift, dy = y - Math.round(y) + angleCos * yShift + angleSin * xShift;
var alignedM = new Float64Array(m);
performance.translate(alignedM, alignedM, [
dx > 0.5 ? dx - 1 : dx,
dy > 0.5 ? dy - 1 : dy,
0
]);
this.alignedProjMatrix = alignedM;
m = performance.create();
performance.scale(m, m, [
this.width / 2,
-this.height / 2,
1
]);
performance.translate(m, m, [
1,
-1,
0
]);
this.labelPlaneMatrix = m;
m = performance.create();
performance.scale(m, m, [
1,
-1,
1
]);
performance.translate(m, m, [
-1,
-1,
0
]);
performance.scale(m, m, [
2 / this.width,
2 / this.height,
1
]);
this.glCoordMatrix = m;
this.pixelMatrix = performance.multiply(new Float64Array(16), this.labelPlaneMatrix, this.projMatrix);
m = performance.invert(new Float64Array(16), this.pixelMatrix);
if (!m) {
throw new Error('failed to invert matrix');
}
this.pixelMatrixInverse = m;
this._posMatrixCache = {};
this._alignedPosMatrixCache = {};
};
Transform.prototype.maxPitchScaleFactor = function maxPitchScaleFactor() {
if (!this.pixelMatrixInverse) {
return 1;
}
var coord = this.pointCoordinate(new performance.Point(0, 0));
var p = [
coord.x * this.worldSize,
coord.y * this.worldSize,
0,
1
];
var topPoint = performance.transformMat4(p, p, this.pixelMatrix);
return topPoint[3] / this.cameraToCenterDistance;
};
Transform.prototype.getCameraPoint = function getCameraPoint() {
var pitch = this._pitch;
var yOffset = Math.tan(pitch) * (this.cameraToCenterDistance || 1);
return this.centerPoint.add(new performance.Point(0, yOffset));
};
Transform.prototype.getCameraQueryGeometry = function getCameraQueryGeometry(queryGeometry) {
var c = this.getCameraPoint();
if (queryGeometry.length === 1) {
return [
queryGeometry[0],
c
];
} else {
var minX = c.x;
var minY = c.y;
var maxX = c.x;
var maxY = c.y;
for (var i = 0, list = queryGeometry; i < list.length; i += 1) {
var p = list[i];
minX = Math.min(minX, p.x);
minY = Math.min(minY, p.y);
maxX = Math.max(maxX, p.x);
maxY = Math.max(maxY, p.y);
}
return [
new performance.Point(minX, minY),
new performance.Point(maxX, minY),
new performance.Point(maxX, maxY),
new performance.Point(minX, maxY),
new performance.Point(minX, minY)
];
}
};
Object.defineProperties(Transform.prototype, prototypeAccessors);
function throttle(fn, time) {
var pending = false;
var timerId = null;
var later = function () {
timerId = null;
if (pending) {
fn();
timerId = setTimeout(later, time);
pending = false;
}
};
return function () {
pending = true;
if (!timerId) {
later();
}
return timerId;
};
}
var Hash = function Hash(hashName) {
this._hashName = hashName && encodeURIComponent(hashName);
performance.bindAll([
'_getCurrentHash',
'_onHashChange',
'_updateHash'
], this);
this._updateHash = throttle(this._updateHashUnthrottled.bind(this), 30 * 1000 / 100);
};
Hash.prototype.addTo = function addTo(map) {
this._map = map;
performance.window.addEventListener('hashchange', this._onHashChange, false);
this._map.on('moveend', this._updateHash);
return this;
};
Hash.prototype.remove = function remove() {
performance.window.removeEventListener('hashchange', this._onHashChange, false);
this._map.off('moveend', this._updateHash);
clearTimeout(this._updateHash());
delete this._map;
return this;
};
Hash.prototype.getHashString = function getHashString(mapFeedback) {
var center = this._map.getCenter(), zoom = Math.round(this._map.getZoom() * 100) / 100, precision = Math.ceil((zoom * Math.LN2 + Math.log(512 / 360 / 0.5)) / Math.LN10), m = Math.pow(10, precision), lng = Math.round(center.lng * m) / m, lat = Math.round(center.lat * m) / m, bearing = this._map.getBearing(), pitch = this._map.getPitch();
var hash = '';
if (mapFeedback) {
hash += '/' + lng + '/' + lat + '/' + zoom;
} else {
hash += zoom + '/' + lat + '/' + lng;
}
if (bearing || pitch) {
hash += '/' + Math.round(bearing * 10) / 10;
}
if (pitch) {
hash += '/' + Math.round(pitch);
}
if (this._hashName) {
var hashName = this._hashName;
var found = false;
var parts = performance.window.location.hash.slice(1).split('&').map(function (part) {
var key = part.split('=')[0];
if (key === hashName) {
found = true;
return key + '=' + hash;
}
return part;
}).filter(function (a) {
return a;
});
if (!found) {
parts.push(hashName + '=' + hash);
}
return '#' + parts.join('&');
}
return '#' + hash;
};
Hash.prototype._getCurrentHash = function _getCurrentHash() {
var this$1 = this;
var hash = performance.window.location.hash.replace('#', '');
if (this._hashName) {
var keyval;
hash.split('&').map(function (part) {
return part.split('=');
}).forEach(function (part) {
if (part[0] === this$1._hashName) {
keyval = part;
}
});
return (keyval ? keyval[1] || '' : '').split('/');
}
return hash.split('/');
};
Hash.prototype._onHashChange = function _onHashChange() {
var loc = this._getCurrentHash();
if (loc.length >= 3 && !loc.some(function (v) {
return isNaN(v);
})) {
var bearing = this._map.dragRotate.isEnabled() && this._map.touchZoomRotate.isEnabled() ? +(loc[3] || 0) : this._map.getBearing();
this._map.jumpTo({
center: [
+loc[2],
+loc[1]
],
zoom: +loc[0],
bearing: bearing,
pitch: +(loc[4] || 0)
});
return true;
}
return false;
};
Hash.prototype._updateHashUnthrottled = function _updateHashUnthrottled() {
var location = performance.window.location.href.replace(/(#.+)?$/, this.getHashString());
try {
performance.window.history.replaceState(performance.window.history.state, null, location);
} catch (SecurityError) {
}
};
var defaultInertiaOptions = {
linearity: 0.3,
easing: performance.bezier(0, 0, 0.3, 1)
};
var defaultPanInertiaOptions = performance.extend({
deceleration: 2500,
maxSpeed: 1400
}, defaultInertiaOptions);
var defaultZoomInertiaOptions = performance.extend({
deceleration: 20,
maxSpeed: 1400
}, defaultInertiaOptions);
var defaultBearingInertiaOptions = performance.extend({
deceleration: 1000,
maxSpeed: 360
}, defaultInertiaOptions);
var defaultPitchInertiaOptions = performance.extend({
deceleration: 1000,
maxSpeed: 90
}, defaultInertiaOptions);
var HandlerInertia = function HandlerInertia(map) {
this._map = map;
this.clear();
};
HandlerInertia.prototype.clear = function clear() {
this._inertiaBuffer = [];
};
HandlerInertia.prototype.record = function record(settings) {
this._drainInertiaBuffer();
this._inertiaBuffer.push({
time: performance.browser.now(),
settings: settings
});
};
HandlerInertia.prototype._drainInertiaBuffer = function _drainInertiaBuffer() {
var inertia = this._inertiaBuffer, now = performance.browser.now(), cutoff = 160;
while (inertia.length > 0 && now - inertia[0].time > cutoff) {
inertia.shift();
}
};
HandlerInertia.prototype._onMoveEnd = function _onMoveEnd(panInertiaOptions) {
this._drainInertiaBuffer();
if (this._inertiaBuffer.length < 2) {
return;
}
var deltas = {
zoom: 0,
bearing: 0,
pitch: 0,
pan: new performance.Point(0, 0),
pinchAround: undefined,
around: undefined
};
for (var i = 0, list = this._inertiaBuffer; i < list.length; i += 1) {
var ref = list[i];
var settings = ref.settings;
deltas.zoom += settings.zoomDelta || 0;
deltas.bearing += settings.bearingDelta || 0;
deltas.pitch += settings.pitchDelta || 0;
if (settings.panDelta) {
deltas.pan._add(settings.panDelta);
}
if (settings.around) {
deltas.around = settings.around;
}
if (settings.pinchAround) {
deltas.pinchAround = settings.pinchAround;
}
}
var lastEntry = this._inertiaBuffer[this._inertiaBuffer.length - 1];
var duration = lastEntry.time - this._inertiaBuffer[0].time;
var easeOptions = {};
if (deltas.pan.mag()) {
var result = calculateEasing(deltas.pan.mag(), duration, performance.extend({}, defaultPanInertiaOptions, panInertiaOptions || {}));
easeOptions.offset = deltas.pan.mult(result.amount / deltas.pan.mag());
easeOptions.center = this._map.transform.center;
extendDuration(easeOptions, result);
}
if (deltas.zoom) {
var result$1 = calculateEasing(deltas.zoom, duration, defaultZoomInertiaOptions);
easeOptions.zoom = this._map.transform.zoom + result$1.amount;
extendDuration(easeOptions, result$1);
}
if (deltas.bearing) {
var result$2 = calculateEasing(deltas.bearing, duration, defaultBearingInertiaOptions);
easeOptions.bearing = this._map.transform.bearing + performance.clamp(result$2.amount, -179, 179);
extendDuration(easeOptions, result$2);
}
if (deltas.pitch) {
var result$3 = calculateEasing(deltas.pitch, duration, defaultPitchInertiaOptions);
easeOptions.pitch = this._map.transform.pitch + result$3.amount;
extendDuration(easeOptions, result$3);
}
if (easeOptions.zoom || easeOptions.bearing) {
var last = deltas.pinchAround === undefined ? deltas.around : deltas.pinchAround;
easeOptions.around = last ? this._map.unproject(last) : this._map.getCenter();
}
this.clear();
return performance.extend(easeOptions, { noMoveStart: true });
};
function extendDuration(easeOptions, result) {
if (!easeOptions.duration || easeOptions.duration < result.duration) {
easeOptions.duration = result.duration;
easeOptions.easing = result.easing;
}
}
function calculateEasing(amount, inertiaDuration, inertiaOptions) {
var maxSpeed = inertiaOptions.maxSpeed;
var linearity = inertiaOptions.linearity;
var deceleration = inertiaOptions.deceleration;
var speed = performance.clamp(amount * linearity / (inertiaDuration / 1000), -maxSpeed, maxSpeed);
var duration = Math.abs(speed) / (deceleration * linearity);
return {
easing: inertiaOptions.easing,
duration: duration * 1000,
amount: speed * (duration / 2)
};
}
var MapMouseEvent = function (Event) {
function MapMouseEvent(type, map, originalEvent, data) {
if (data === void 0)
data = {};
var point = DOM.mousePos(map.getCanvasContainer(), originalEvent);
var lngLat = map.unproject(point);
Event.call(this, type, performance.extend({
point: point,
lngLat: lngLat,
originalEvent: originalEvent
}, data));
this._defaultPrevented = false;
this.target = map;
}
if (Event)
MapMouseEvent.__proto__ = Event;
MapMouseEvent.prototype = Object.create(Event && Event.prototype);
MapMouseEvent.prototype.constructor = MapMouseEvent;
var prototypeAccessors = { defaultPrevented: { configurable: true } };
MapMouseEvent.prototype.preventDefault = function preventDefault() {
this._defaultPrevented = true;
};
prototypeAccessors.defaultPrevented.get = function () {
return this._defaultPrevented;
};
Object.defineProperties(MapMouseEvent.prototype, prototypeAccessors);
return MapMouseEvent;
}(performance.Event);
var MapTouchEvent = function (Event) {
function MapTouchEvent(type, map, originalEvent) {
var touches = type === 'touchend' ? originalEvent.changedTouches : originalEvent.touches;
var points = DOM.touchPos(map.getCanvasContainer(), touches);
var lngLats = points.map(function (t) {
return map.unproject(t);
});
var point = points.reduce(function (prev, curr, i, arr) {
return prev.add(curr.div(arr.length));
}, new performance.Point(0, 0));
var lngLat = map.unproject(point);
Event.call(this, type, {
points: points,
point: point,
lngLats: lngLats,
lngLat: lngLat,
originalEvent: originalEvent
});
this._defaultPrevented = false;
}
if (Event)
MapTouchEvent.__proto__ = Event;
MapTouchEvent.prototype = Object.create(Event && Event.prototype);
MapTouchEvent.prototype.constructor = MapTouchEvent;
var prototypeAccessors$1 = { defaultPrevented: { configurable: true } };
MapTouchEvent.prototype.preventDefault = function preventDefault() {
this._defaultPrevented = true;
};
prototypeAccessors$1.defaultPrevented.get = function () {
return this._defaultPrevented;
};
Object.defineProperties(MapTouchEvent.prototype, prototypeAccessors$1);
return MapTouchEvent;
}(performance.Event);
var MapWheelEvent = function (Event) {
function MapWheelEvent(type, map, originalEvent) {
Event.call(this, type, { originalEvent: originalEvent });
this._defaultPrevented = false;
}
if (Event)
MapWheelEvent.__proto__ = Event;
MapWheelEvent.prototype = Object.create(Event && Event.prototype);
MapWheelEvent.prototype.constructor = MapWheelEvent;
var prototypeAccessors$2 = { defaultPrevented: { configurable: true } };
MapWheelEvent.prototype.preventDefault = function preventDefault() {
this._defaultPrevented = true;
};
prototypeAccessors$2.defaultPrevented.get = function () {
return this._defaultPrevented;
};
Object.defineProperties(MapWheelEvent.prototype, prototypeAccessors$2);
return MapWheelEvent;
}(performance.Event);
var MapEventHandler = function MapEventHandler(map, options) {
this._map = map;
this._clickTolerance = options.clickTolerance;
};
MapEventHandler.prototype.reset = function reset() {
delete this._mousedownPos;
};
MapEventHandler.prototype.wheel = function wheel(e) {
return this._firePreventable(new MapWheelEvent(e.type, this._map, e));
};
MapEventHandler.prototype.mousedown = function mousedown(e, point) {
this._mousedownPos = point;
return this._firePreventable(new MapMouseEvent(e.type, this._map, e));
};
MapEventHandler.prototype.mouseup = function mouseup(e) {
this._map.fire(new MapMouseEvent(e.type, this._map, e));
};
MapEventHandler.prototype.click = function click(e, point) {
if (this._mousedownPos && this._mousedownPos.dist(point) >= this._clickTolerance) {
return;
}
this._map.fire(new MapMouseEvent(e.type, this._map, e));
};
MapEventHandler.prototype.dblclick = function dblclick(e) {
return this._firePreventable(new MapMouseEvent(e.type, this._map, e));
};
MapEventHandler.prototype.mouseover = function mouseover(e) {
this._map.fire(new MapMouseEvent(e.type, this._map, e));
};
MapEventHandler.prototype.mouseout = function mouseout(e) {
this._map.fire(new MapMouseEvent(e.type, this._map, e));
};
MapEventHandler.prototype.touchstart = function touchstart(e) {
return this._firePreventable(new MapTouchEvent(e.type, this._map, e));
};
MapEventHandler.prototype.touchmove = function touchmove(e) {
this._map.fire(new MapTouchEvent(e.type, this._map, e));
};
MapEventHandler.prototype.touchend = function touchend(e) {
this._map.fire(new MapTouchEvent(e.type, this._map, e));
};
MapEventHandler.prototype.touchcancel = function touchcancel(e) {
this._map.fire(new MapTouchEvent(e.type, this._map, e));
};
MapEventHandler.prototype._firePreventable = function _firePreventable(mapEvent) {
this._map.fire(mapEvent);
if (mapEvent.defaultPrevented) {
return {};
}
};
MapEventHandler.prototype.isEnabled = function isEnabled() {
return true;
};
MapEventHandler.prototype.isActive = function isActive() {
return false;
};
MapEventHandler.prototype.enable = function enable() {
};
MapEventHandler.prototype.disable = function disable() {
};
var BlockableMapEventHandler = function BlockableMapEventHandler(map) {
this._map = map;
};
BlockableMapEventHandler.prototype.reset = function reset() {
this._delayContextMenu = false;
delete this._contextMenuEvent;
};
BlockableMapEventHandler.prototype.mousemove = function mousemove(e) {
this._map.fire(new MapMouseEvent(e.type, this._map, e));
};
BlockableMapEventHandler.prototype.mousedown = function mousedown() {
this._delayContextMenu = true;
};
BlockableMapEventHandler.prototype.mouseup = function mouseup() {
this._delayContextMenu = false;
if (this._contextMenuEvent) {
this._map.fire(new MapMouseEvent('contextmenu', this._map, this._contextMenuEvent));
delete this._contextMenuEvent;
}
};
BlockableMapEventHandler.prototype.contextmenu = function contextmenu(e) {
if (this._delayContextMenu) {
this._contextMenuEvent = e;
} else {
this._map.fire(new MapMouseEvent(e.type, this._map, e));
}
if (this._map.listens('contextmenu')) {
e.preventDefault();
}
};
BlockableMapEventHandler.prototype.isEnabled = function isEnabled() {
return true;
};
BlockableMapEventHandler.prototype.isActive = function isActive() {
return false;
};
BlockableMapEventHandler.prototype.enable = function enable() {
};
BlockableMapEventHandler.prototype.disable = function disable() {
};
var BoxZoomHandler = function BoxZoomHandler(map, options) {
this._map = map;
this._el = map.getCanvasContainer();
this._container = map.getContainer();
this._clickTolerance = options.clickTolerance || 1;
};
BoxZoomHandler.prototype.isEnabled = function isEnabled() {
return !!this._enabled;
};
BoxZoomHandler.prototype.isActive = function isActive() {
return !!this._active;
};
BoxZoomHandler.prototype.enable = function enable() {
if (this.isEnabled()) {
return;
}
this._enabled = true;
};
BoxZoomHandler.prototype.disable = function disable() {
if (!this.isEnabled()) {
return;
}
this._enabled = false;
};
BoxZoomHandler.prototype.mousedown = function mousedown(e, point) {
if (!this.isEnabled()) {
return;
}
if (!(e.shiftKey && e.button === 0)) {
return;
}
DOM.disableDrag();
this._startPos = this._lastPos = point;
this._active = true;
};
BoxZoomHandler.prototype.mousemoveWindow = function mousemoveWindow(e, point) {
if (!this._active) {
return;
}
var pos = point;
if (this._lastPos.equals(pos) || !this._box && pos.dist(this._startPos) < this._clickTolerance) {
return;
}
var p0 = this._startPos;
this._lastPos = pos;
if (!this._box) {
this._box = DOM.create('div', 'mapboxgl-boxzoom', this._container);
this._container.classList.add('mapboxgl-crosshair');
this._fireEvent('boxzoomstart', e);
}
var minX = Math.min(p0.x, pos.x), maxX = Math.max(p0.x, pos.x), minY = Math.min(p0.y, pos.y), maxY = Math.max(p0.y, pos.y);
DOM.setTransform(this._box, 'translate(' + minX + 'px,' + minY + 'px)');
this._box.style.width = maxX - minX + 'px';
this._box.style.height = maxY - minY + 'px';
};
BoxZoomHandler.prototype.mouseupWindow = function mouseupWindow(e, point) {
var this$1 = this;
if (!this._active) {
return;
}
if (e.button !== 0) {
return;
}
var p0 = this._startPos, p1 = point;
this.reset();
DOM.suppressClick();
if (p0.x === p1.x && p0.y === p1.y) {
this._fireEvent('boxzoomcancel', e);
} else {
this._map.fire(new performance.Event('boxzoomend', { originalEvent: e }));
return {
cameraAnimation: function (map) {
return map.fitScreenCoordinates(p0, p1, this$1._map.getBearing(), { linear: true });
}
};
}
};
BoxZoomHandler.prototype.keydown = function keydown(e) {
if (!this._active) {
return;
}
if (e.keyCode === 27) {
this.reset();
this._fireEvent('boxzoomcancel', e);
}
};
BoxZoomHandler.prototype.reset = function reset() {
this._active = false;
this._container.classList.remove('mapboxgl-crosshair');
if (this._box) {
DOM.remove(this._box);
this._box = null;
}
DOM.enableDrag();
delete this._startPos;
delete this._lastPos;
};
BoxZoomHandler.prototype._fireEvent = function _fireEvent(type, e) {
return this._map.fire(new performance.Event(type, { originalEvent: e }));
};
function indexTouches(touches, points) {
var obj = {};
for (var i = 0; i < touches.length; i++) {
obj[touches[i].identifier] = points[i];
}
return obj;
}
function getCentroid(points) {
var sum = new performance.Point(0, 0);
for (var i = 0, list = points; i < list.length; i += 1) {
var point = list[i];
sum._add(point);
}
return sum.div(points.length);
}
var MAX_TAP_INTERVAL = 500;
var MAX_TOUCH_TIME = 500;
var MAX_DIST = 30;
var SingleTapRecognizer = function SingleTapRecognizer(options) {
this.reset();
this.numTouches = options.numTouches;
};
SingleTapRecognizer.prototype.reset = function reset() {
delete this.centroid;
delete this.startTime;
delete this.touches;
this.aborted = false;
};
SingleTapRecognizer.prototype.touchstart = function touchstart(e, points, mapTouches) {
if (this.centroid || mapTouches.length > this.numTouches) {
this.aborted = true;
}
if (this.aborted) {
return;
}
if (this.startTime === undefined) {
this.startTime = e.timeStamp;
}
if (mapTouches.length === this.numTouches) {
this.centroid = getCentroid(points);
this.touches = indexTouches(mapTouches, points);
}
};
SingleTapRecognizer.prototype.touchmove = function touchmove(e, points, mapTouches) {
if (this.aborted || !this.centroid) {
return;
}
var newTouches = indexTouches(mapTouches, points);
for (var id in this.touches) {
var prevPos = this.touches[id];
var pos = newTouches[id];
if (!pos || pos.dist(prevPos) > MAX_DIST) {
this.aborted = true;
}
}
};
SingleTapRecognizer.prototype.touchend = function touchend(e, points, mapTouches) {
if (!this.centroid || e.timeStamp - this.startTime > MAX_TOUCH_TIME) {
this.aborted = true;
}
if (mapTouches.length === 0) {
var centroid = !this.aborted && this.centroid;
this.reset();
if (centroid) {
return centroid;
}
}
};
var TapRecognizer = function TapRecognizer(options) {
this.singleTap = new SingleTapRecognizer(options);
this.numTaps = options.numTaps;
this.reset();
};
TapRecognizer.prototype.reset = function reset() {
this.lastTime = Infinity;
delete this.lastTap;
this.count = 0;
this.singleTap.reset();
};
TapRecognizer.prototype.touchstart = function touchstart(e, points, mapTouches) {
this.singleTap.touchstart(e, points, mapTouches);
};
TapRecognizer.prototype.touchmove = function touchmove(e, points, mapTouches) {
this.singleTap.touchmove(e, points, mapTouches);
};
TapRecognizer.prototype.touchend = function touchend(e, points, mapTouches) {
var tap = this.singleTap.touchend(e, points, mapTouches);
if (tap) {
var soonEnough = e.timeStamp - this.lastTime < MAX_TAP_INTERVAL;
var closeEnough = !this.lastTap || this.lastTap.dist(tap) < MAX_DIST;
if (!soonEnough || !closeEnough) {
this.reset();
}
this.count++;
this.lastTime = e.timeStamp;
this.lastTap = tap;
if (this.count === this.numTaps) {
this.reset();
return tap;
}
}
};
var TapZoomHandler = function TapZoomHandler() {
this._zoomIn = new TapRecognizer({
numTouches: 1,
numTaps: 2
});
this._zoomOut = new TapRecognizer({
numTouches: 2,
numTaps: 1
});
this.reset();
};
TapZoomHandler.prototype.reset = function reset() {
this._active = false;
this._zoomIn.reset();
this._zoomOut.reset();
};
TapZoomHandler.prototype.touchstart = function touchstart(e, points, mapTouches) {
this._zoomIn.touchstart(e, points, mapTouches);
this._zoomOut.touchstart(e, points, mapTouches);
};
TapZoomHandler.prototype.touchmove = function touchmove(e, points, mapTouches) {
this._zoomIn.touchmove(e, points, mapTouches);
this._zoomOut.touchmove(e, points, mapTouches);
};
TapZoomHandler.prototype.touchend = function touchend(e, points, mapTouches) {
var this$1 = this;
var zoomInPoint = this._zoomIn.touchend(e, points, mapTouches);
var zoomOutPoint = this._zoomOut.touchend(e, points, mapTouches);
if (zoomInPoint) {
this._active = true;
e.preventDefault();
setTimeout(function () {
return this$1.reset();
}, 0);
return {
cameraAnimation: function (map) {
return map.easeTo({
duration: 300,
zoom: map.getZoom() + 1,
around: map.unproject(zoomInPoint)
}, { originalEvent: e });
}
};
} else if (zoomOutPoint) {
this._active = true;
e.preventDefault();
setTimeout(function () {
return this$1.reset();
}, 0);
return {
cameraAnimation: function (map) {
return map.easeTo({
duration: 300,
zoom: map.getZoom() - 1,
around: map.unproject(zoomOutPoint)
}, { originalEvent: e });
}
};
}
};
TapZoomHandler.prototype.touchcancel = function touchcancel() {
this.reset();
};
TapZoomHandler.prototype.enable = function enable() {
this._enabled = true;
};
TapZoomHandler.prototype.disable = function disable() {
this._enabled = false;
this.reset();
};
TapZoomHandler.prototype.isEnabled = function isEnabled() {
return this._enabled;
};
TapZoomHandler.prototype.isActive = function isActive() {
return this._active;
};
var LEFT_BUTTON = 0;
var RIGHT_BUTTON = 2;
var BUTTONS_FLAGS = {};
BUTTONS_FLAGS[LEFT_BUTTON] = 1;
BUTTONS_FLAGS[RIGHT_BUTTON] = 2;
function buttonStillPressed(e, button) {
var flag = BUTTONS_FLAGS[button];
return e.buttons === undefined || (e.buttons & flag) !== flag;
}
var MouseHandler = function MouseHandler(options) {
this.reset();
this._clickTolerance = options.clickTolerance || 1;
};
MouseHandler.prototype.reset = function reset() {
this._active = false;
this._moved = false;
delete this._lastPoint;
delete this._eventButton;
};
MouseHandler.prototype._correctButton = function _correctButton(e, button) {
return false;
};
MouseHandler.prototype._move = function _move(lastPoint, point) {
return {};
};
MouseHandler.prototype.mousedown = function mousedown(e, point) {
if (this._lastPoint) {
return;
}
var eventButton = DOM.mouseButton(e);
if (!this._correctButton(e, eventButton)) {
return;
}
this._lastPoint = point;
this._eventButton = eventButton;
};
MouseHandler.prototype.mousemoveWindow = function mousemoveWindow(e, point) {
var lastPoint = this._lastPoint;
if (!lastPoint) {
return;
}
e.preventDefault();
if (buttonStillPressed(e, this._eventButton)) {
this.reset();
return;
}
if (!this._moved && point.dist(lastPoint) < this._clickTolerance) {
return;
}
this._moved = true;
this._lastPoint = point;
return this._move(lastPoint, point);
};
MouseHandler.prototype.mouseupWindow = function mouseupWindow(e) {
if (!this._lastPoint) {
return;
}
var eventButton = DOM.mouseButton(e);
if (eventButton !== this._eventButton) {
return;
}
if (this._moved) {
DOM.suppressClick();
}
this.reset();
};
MouseHandler.prototype.enable = function enable() {
this._enabled = true;
};
MouseHandler.prototype.disable = function disable() {
this._enabled = false;
this.reset();
};
MouseHandler.prototype.isEnabled = function isEnabled() {
return this._enabled;
};
MouseHandler.prototype.isActive = function isActive() {
return this._active;
};
var MousePanHandler = function (MouseHandler) {
function MousePanHandler() {
MouseHandler.apply(this, arguments);
}
if (MouseHandler)
MousePanHandler.__proto__ = MouseHandler;
MousePanHandler.prototype = Object.create(MouseHandler && MouseHandler.prototype);
MousePanHandler.prototype.constructor = MousePanHandler;
MousePanHandler.prototype.mousedown = function mousedown(e, point) {
MouseHandler.prototype.mousedown.call(this, e, point);
if (this._lastPoint) {
this._active = true;
}
};
MousePanHandler.prototype._correctButton = function _correctButton(e, button) {
return button === LEFT_BUTTON && !e.ctrlKey;
};
MousePanHandler.prototype._move = function _move(lastPoint, point) {
return {
around: point,
panDelta: point.sub(lastPoint)
};
};
return MousePanHandler;
}(MouseHandler);
var MouseRotateHandler = function (MouseHandler) {
function MouseRotateHandler() {
MouseHandler.apply(this, arguments);
}
if (MouseHandler)
MouseRotateHandler.__proto__ = MouseHandler;
MouseRotateHandler.prototype = Object.create(MouseHandler && MouseHandler.prototype);
MouseRotateHandler.prototype.constructor = MouseRotateHandler;
MouseRotateHandler.prototype._correctButton = function _correctButton(e, button) {
return button === LEFT_BUTTON && e.ctrlKey || button === RIGHT_BUTTON;
};
MouseRotateHandler.prototype._move = function _move(lastPoint, point) {
var degreesPerPixelMoved = 0.8;
var bearingDelta = (point.x - lastPoint.x) * degreesPerPixelMoved;
if (bearingDelta) {
this._active = true;
return { bearingDelta: bearingDelta };
}
};
MouseRotateHandler.prototype.contextmenu = function contextmenu(e) {
e.preventDefault();
};
return MouseRotateHandler;
}(MouseHandler);
var MousePitchHandler = function (MouseHandler) {
function MousePitchHandler() {
MouseHandler.apply(this, arguments);
}
if (MouseHandler)
MousePitchHandler.__proto__ = MouseHandler;
MousePitchHandler.prototype = Object.create(MouseHandler && MouseHandler.prototype);
MousePitchHandler.prototype.constructor = MousePitchHandler;
MousePitchHandler.prototype._correctButton = function _correctButton(e, button) {
return button === LEFT_BUTTON && e.ctrlKey || button === RIGHT_BUTTON;
};
MousePitchHandler.prototype._move = function _move(lastPoint, point) {
var degreesPerPixelMoved = -0.5;
var pitchDelta = (point.y - lastPoint.y) * degreesPerPixelMoved;
if (pitchDelta) {
this._active = true;
return { pitchDelta: pitchDelta };
}
};
MousePitchHandler.prototype.contextmenu = function contextmenu(e) {
e.preventDefault();
};
return MousePitchHandler;
}(MouseHandler);
var TouchPanHandler = function TouchPanHandler(options) {
this._minTouches = 1;
this._clickTolerance = options.clickTolerance || 1;
this.reset();
};
TouchPanHandler.prototype.reset = function reset() {
this._active = false;
this._touches = {};
this._sum = new performance.Point(0, 0);
};
TouchPanHandler.prototype.touchstart = function touchstart(e, points, mapTouches) {
return this._calculateTransform(e, points, mapTouches);
};
TouchPanHandler.prototype.touchmove = function touchmove(e, points, mapTouches) {
if (!this._active || mapTouches.length < this._minTouches) {
return;
}
e.preventDefault();
return this._calculateTransform(e, points, mapTouches);
};
TouchPanHandler.prototype.touchend = function touchend(e, points, mapTouches) {
this._calculateTransform(e, points, mapTouches);
if (this._active && mapTouches.length < this._minTouches) {
this.reset();
}
};
TouchPanHandler.prototype.touchcancel = function touchcancel() {
this.reset();
};
TouchPanHandler.prototype._calculateTransform = function _calculateTransform(e, points, mapTouches) {
if (mapTouches.length > 0) {
this._active = true;
}
var touches = indexTouches(mapTouches, points);
var touchPointSum = new performance.Point(0, 0);
var touchDeltaSum = new performance.Point(0, 0);
var touchDeltaCount = 0;
for (var identifier in touches) {
var point = touches[identifier];
var prevPoint = this._touches[identifier];
if (prevPoint) {
touchPointSum._add(point);
touchDeltaSum._add(point.sub(prevPoint));
touchDeltaCount++;
touches[identifier] = point;
}
}
this._touches = touches;
if (touchDeltaCount < this._minTouches || !touchDeltaSum.mag()) {
return;
}
var panDelta = touchDeltaSum.div(touchDeltaCount);
this._sum._add(panDelta);
if (this._sum.mag() < this._clickTolerance) {
return;
}
var around = touchPointSum.div(touchDeltaCount);
return {
around: around,
panDelta: panDelta
};
};
TouchPanHandler.prototype.enable = function enable() {
this._enabled = true;
};
TouchPanHandler.prototype.disable = function disable() {
this._enabled = false;
this.reset();
};
TouchPanHandler.prototype.isEnabled = function isEnabled() {
return this._enabled;
};
TouchPanHandler.prototype.isActive = function isActive() {
return this._active;
};
var TwoTouchHandler = function TwoTouchHandler() {
this.reset();
};
TwoTouchHandler.prototype.reset = function reset() {
this._active = false;
delete this._firstTwoTouches;
};
TwoTouchHandler.prototype._start = function _start(points) {
};
TwoTouchHandler.prototype._move = function _move(points, pinchAround, e) {
return {};
};
TwoTouchHandler.prototype.touchstart = function touchstart(e, points, mapTouches) {
if (this._firstTwoTouches || mapTouches.length < 2) {
return;
}
this._firstTwoTouches = [
mapTouches[0].identifier,
mapTouches[1].identifier
];
this._start([
points[0],
points[1]
]);
};
TwoTouchHandler.prototype.touchmove = function touchmove(e, points, mapTouches) {
if (!this._firstTwoTouches) {
return;
}
e.preventDefault();
var ref = this._firstTwoTouches;
var idA = ref[0];
var idB = ref[1];
var a = getTouchById(mapTouches, points, idA);
var b = getTouchById(mapTouches, points, idB);
if (!a || !b) {
return;
}
var pinchAround = this._aroundCenter ? null : a.add(b).div(2);
return this._move([
a,
b
], pinchAround, e);
};
TwoTouchHandler.prototype.touchend = function touchend(e, points, mapTouches) {
if (!this._firstTwoTouches) {
return;
}
var ref = this._firstTwoTouches;
var idA = ref[0];
var idB = ref[1];
var a = getTouchById(mapTouches, points, idA);
var b = getTouchById(mapTouches, points, idB);
if (a && b) {
return;
}
if (this._active) {
DOM.suppressClick();
}
this.reset();
};
TwoTouchHandler.prototype.touchcancel = function touchcancel() {
this.reset();
};
TwoTouchHandler.prototype.enable = function enable(options) {
this._enabled = true;
this._aroundCenter = !!options && options.around === 'center';
};
TwoTouchHandler.prototype.disable = function disable() {
this._enabled = false;
this.reset();
};
TwoTouchHandler.prototype.isEnabled = function isEnabled() {
return this._enabled;
};
TwoTouchHandler.prototype.isActive = function isActive() {
return this._active;
};
function getTouchById(mapTouches, points, identifier) {
for (var i = 0; i < mapTouches.length; i++) {
if (mapTouches[i].identifier === identifier) {
return points[i];
}
}
}
var ZOOM_THRESHOLD = 0.1;
function getZoomDelta(distance, lastDistance) {
return Math.log(distance / lastDistance) / Math.LN2;
}
var TouchZoomHandler = function (TwoTouchHandler) {
function TouchZoomHandler() {
TwoTouchHandler.apply(this, arguments);
}
if (TwoTouchHandler)
TouchZoomHandler.__proto__ = TwoTouchHandler;
TouchZoomHandler.prototype = Object.create(TwoTouchHandler && TwoTouchHandler.prototype);
TouchZoomHandler.prototype.constructor = TouchZoomHandler;
TouchZoomHandler.prototype.reset = function reset() {
TwoTouchHandler.prototype.reset.call(this);
delete this._distance;
delete this._startDistance;
};
TouchZoomHandler.prototype._start = function _start(points) {
this._startDistance = this._distance = points[0].dist(points[1]);
};
TouchZoomHandler.prototype._move = function _move(points, pinchAround) {
var lastDistance = this._distance;
this._distance = points[0].dist(points[1]);
if (!this._active && Math.abs(getZoomDelta(this._distance, this._startDistance)) < ZOOM_THRESHOLD) {
return;
}
this._active = true;
return {
zoomDelta: getZoomDelta(this._distance, lastDistance),
pinchAround: pinchAround
};
};
return TouchZoomHandler;
}(TwoTouchHandler);
var ROTATION_THRESHOLD = 25;
function getBearingDelta(a, b) {
return a.angleWith(b) * 180 / Math.PI;
}
var TouchRotateHandler = function (TwoTouchHandler) {
function TouchRotateHandler() {
TwoTouchHandler.apply(this, arguments);
}
if (TwoTouchHandler)
TouchRotateHandler.__proto__ = TwoTouchHandler;
TouchRotateHandler.prototype = Object.create(TwoTouchHandler && TwoTouchHandler.prototype);
TouchRotateHandler.prototype.constructor = TouchRotateHandler;
TouchRotateHandler.prototype.reset = function reset() {
TwoTouchHandler.prototype.reset.call(this);
delete this._minDiameter;
delete this._startVector;
delete this._vector;
};
TouchRotateHandler.prototype._start = function _start(points) {
this._startVector = this._vector = points[0].sub(points[1]);
this._minDiameter = points[0].dist(points[1]);
};
TouchRotateHandler.prototype._move = function _move(points, pinchAround) {
var lastVector = this._vector;
this._vector = points[0].sub(points[1]);
if (!this._active && this._isBelowThreshold(this._vector)) {
return;
}
this._active = true;
return {
bearingDelta: getBearingDelta(this._vector, lastVector),
pinchAround: pinchAround
};
};
TouchRotateHandler.prototype._isBelowThreshold = function _isBelowThreshold(vector) {
this._minDiameter = Math.min(this._minDiameter, vector.mag());
var circumference = Math.PI * this._minDiameter;
var threshold = ROTATION_THRESHOLD / circumference * 360;
var bearingDeltaSinceStart = getBearingDelta(vector, this._startVector);
return Math.abs(bearingDeltaSinceStart) < threshold;
};
return TouchRotateHandler;
}(TwoTouchHandler);
function isVertical(vector) {
return Math.abs(vector.y) > Math.abs(vector.x);
}
var ALLOWED_SINGLE_TOUCH_TIME = 100;
var TouchPitchHandler = function (TwoTouchHandler) {
function TouchPitchHandler() {
TwoTouchHandler.apply(this, arguments);
}
if (TwoTouchHandler)
TouchPitchHandler.__proto__ = TwoTouchHandler;
TouchPitchHandler.prototype = Object.create(TwoTouchHandler && TwoTouchHandler.prototype);
TouchPitchHandler.prototype.constructor = TouchPitchHandler;
TouchPitchHandler.prototype.reset = function reset() {
TwoTouchHandler.prototype.reset.call(this);
this._valid = undefined;
delete this._firstMove;
delete this._lastPoints;
};
TouchPitchHandler.prototype._start = function _start(points) {
this._lastPoints = points;
if (isVertical(points[0].sub(points[1]))) {
this._valid = false;
}
};
TouchPitchHandler.prototype._move = function _move(points, center, e) {
var vectorA = points[0].sub(this._lastPoints[0]);
var vectorB = points[1].sub(this._lastPoints[1]);
this._valid = this.gestureBeginsVertically(vectorA, vectorB, e.timeStamp);
if (!this._valid) {
return;
}
this._lastPoints = points;
this._active = true;
var yDeltaAverage = (vectorA.y + vectorB.y) / 2;
var degreesPerPixelMoved = -0.5;
return { pitchDelta: yDeltaAverage * degreesPerPixelMoved };
};
TouchPitchHandler.prototype.gestureBeginsVertically = function gestureBeginsVertically(vectorA, vectorB, timeStamp) {
if (this._valid !== undefined) {
return this._valid;
}
var threshold = 2;
var movedA = vectorA.mag() >= threshold;
var movedB = vectorB.mag() >= threshold;
if (!movedA && !movedB) {
return;
}
if (!movedA || !movedB) {
if (this._firstMove === undefined) {
this._firstMove = timeStamp;
}
if (timeStamp - this._firstMove < ALLOWED_SINGLE_TOUCH_TIME) {
return undefined;
} else {
return false;
}
}
var isSameDirection = vectorA.y > 0 === vectorB.y > 0;
return isVertical(vectorA) && isVertical(vectorB) && isSameDirection;
};
return TouchPitchHandler;
}(TwoTouchHandler);
var defaultOptions = {
panStep: 100,
bearingStep: 15,
pitchStep: 10
};
var KeyboardHandler = function KeyboardHandler() {
var stepOptions = defaultOptions;
this._panStep = stepOptions.panStep;
this._bearingStep = stepOptions.bearingStep;
this._pitchStep = stepOptions.pitchStep;
this._rotationDisabled = false;
};
KeyboardHandler.prototype.reset = function reset() {
this._active = false;
};
KeyboardHandler.prototype.keydown = function keydown(e) {
var this$1 = this;
if (e.altKey || e.ctrlKey || e.metaKey) {
return;
}
var zoomDir = 0;
var bearingDir = 0;
var pitchDir = 0;
var xDir = 0;
var yDir = 0;
switch (e.keyCode) {
case 61:
case 107:
case 171:
case 187:
zoomDir = 1;
break;
case 189:
case 109:
case 173:
zoomDir = -1;
break;
case 37:
if (e.shiftKey) {
bearingDir = -1;
} else {
e.preventDefault();
xDir = -1;
}
break;
case 39:
if (e.shiftKey) {
bearingDir = 1;
} else {
e.preventDefault();
xDir = 1;
}
break;
case 38:
if (e.shiftKey) {
pitchDir = 1;
} else {
e.preventDefault();
yDir = -1;
}
break;
case 40:
if (e.shiftKey) {
pitchDir = -1;
} else {
e.preventDefault();
yDir = 1;
}
break;
default:
return;
}
if (this._rotationDisabled) {
bearingDir = 0;
pitchDir = 0;
}
return {
cameraAnimation: function (map) {
var zoom = map.getZoom();
map.easeTo({
duration: 300,
easeId: 'keyboardHandler',
easing: easeOut,
zoom: zoomDir ? Math.round(zoom) + zoomDir * (e.shiftKey ? 2 : 1) : zoom,
bearing: map.getBearing() + bearingDir * this$1._bearingStep,
pitch: map.getPitch() + pitchDir * this$1._pitchStep,
offset: [
-xDir * this$1._panStep,
-yDir * this$1._panStep
],
center: map.getCenter()
}, { originalEvent: e });
}
};
};
KeyboardHandler.prototype.enable = function enable() {
this._enabled = true;
};
KeyboardHandler.prototype.disable = function disable() {
this._enabled = false;
this.reset();
};
KeyboardHandler.prototype.isEnabled = function isEnabled() {
return this._enabled;
};
KeyboardHandler.prototype.isActive = function isActive() {
return this._active;
};
KeyboardHandler.prototype.disableRotation = function disableRotation() {
this._rotationDisabled = true;
};
KeyboardHandler.prototype.enableRotation = function enableRotation() {
this._rotationDisabled = false;
};
function easeOut(t) {
return t * (2 - t);
}
var wheelZoomDelta = 4.000244140625;
var defaultZoomRate = 1 / 100;
var wheelZoomRate = 1 / 450;
var maxScalePerFrame = 2;
var ScrollZoomHandler = function ScrollZoomHandler(map, handler) {
this._map = map;
this._el = map.getCanvasContainer();
this._handler = handler;
this._delta = 0;
this._defaultZoomRate = defaultZoomRate;
this._wheelZoomRate = wheelZoomRate;
performance.bindAll(['_onTimeout'], this);
};
ScrollZoomHandler.prototype.setZoomRate = function setZoomRate(zoomRate) {
this._defaultZoomRate = zoomRate;
};
ScrollZoomHandler.prototype.setWheelZoomRate = function setWheelZoomRate(wheelZoomRate) {
this._wheelZoomRate = wheelZoomRate;
};
ScrollZoomHandler.prototype.isEnabled = function isEnabled() {
return !!this._enabled;
};
ScrollZoomHandler.prototype.isActive = function isActive() {
return !!this._active || this._finishTimeout !== undefined;
};
ScrollZoomHandler.prototype.isZooming = function isZooming() {
return !!this._zooming;
};
ScrollZoomHandler.prototype.enable = function enable(options) {
if (this.isEnabled()) {
return;
}
this._enabled = true;
this._aroundCenter = options && options.around === 'center';
};
ScrollZoomHandler.prototype.disable = function disable() {
if (!this.isEnabled()) {
return;
}
this._enabled = false;
};
ScrollZoomHandler.prototype.wheel = function wheel(e) {
if (!this.isEnabled()) {
return;
}
var value = e.deltaMode === performance.window.WheelEvent.DOM_DELTA_LINE ? e.deltaY * 40 : e.deltaY;
var now = performance.browser.now(), timeDelta = now - (this._lastWheelEventTime || 0);
this._lastWheelEventTime = now;
if (value !== 0 && value % wheelZoomDelta === 0) {
this._type = 'wheel';
} else if (value !== 0 && Math.abs(value) < 4) {
this._type = 'trackpad';
} else if (timeDelta > 400) {
this._type = null;
this._lastValue = value;
this._timeout = setTimeout(this._onTimeout, 40, e);
} else if (!this._type) {
this._type = Math.abs(timeDelta * value) < 200 ? 'trackpad' : 'wheel';
if (this._timeout) {
clearTimeout(this._timeout);
this._timeout = null;
value += this._lastValue;
}
}
if (e.shiftKey && value) {
value = value / 4;
}
if (this._type) {
this._lastWheelEvent = e;
this._delta -= value;
if (!this._active) {
this._start(e);
}
}
e.preventDefault();
};
ScrollZoomHandler.prototype._onTimeout = function _onTimeout(initialEvent) {
this._type = 'wheel';
this._delta -= this._lastValue;
if (!this._active) {
this._start(initialEvent);
}
};
ScrollZoomHandler.prototype._start = function _start(e) {
if (!this._delta) {
return;
}
if (this._frameId) {
this._frameId = null;
}
this._active = true;
if (!this.isZooming()) {
this._zooming = true;
}
if (this._finishTimeout) {
clearTimeout(this._finishTimeout);
delete this._finishTimeout;
}
var pos = DOM.mousePos(this._el, e);
this._around = performance.LngLat.convert(this._aroundCenter ? this._map.getCenter() : this._map.unproject(pos));
this._aroundPoint = this._map.transform.locationPoint(this._around);
if (!this._frameId) {
this._frameId = true;
this._handler._triggerRenderFrame();
}
};
ScrollZoomHandler.prototype.renderFrame = function renderFrame() {
var this$1 = this;
if (!this._frameId) {
return;
}
this._frameId = null;
if (!this.isActive()) {
return;
}
var tr = this._map.transform;
if (this._delta !== 0) {
var zoomRate = this._type === 'wheel' && Math.abs(this._delta) > wheelZoomDelta ? this._wheelZoomRate : this._defaultZoomRate;
var scale = maxScalePerFrame / (1 + Math.exp(-Math.abs(this._delta * zoomRate)));
if (this._delta < 0 && scale !== 0) {
scale = 1 / scale;
}
var fromScale = typeof this._targetZoom === 'number' ? tr.zoomScale(this._targetZoom) : tr.scale;
this._targetZoom = Math.min(tr.maxZoom, Math.max(tr.minZoom, tr.scaleZoom(fromScale * scale)));
if (this._type === 'wheel') {
this._startZoom = tr.zoom;
this._easing = this._smoothOutEasing(200);
}
this._delta = 0;
}
var targetZoom = typeof this._targetZoom === 'number' ? this._targetZoom : tr.zoom;
var startZoom = this._startZoom;
var easing = this._easing;
var finished = false;
var zoom;
if (this._type === 'wheel' && startZoom && easing) {
var t = Math.min((performance.browser.now() - this._lastWheelEventTime) / 200, 1);
var k = easing(t);
zoom = performance.number(startZoom, targetZoom, k);
if (t < 1) {
if (!this._frameId) {
this._frameId = true;
}
} else {
finished = true;
}
} else {
zoom = targetZoom;
finished = true;
}
this._active = true;
if (finished) {
this._active = false;
this._finishTimeout = setTimeout(function () {
this$1._zooming = false;
this$1._handler._triggerRenderFrame();
delete this$1._targetZoom;
delete this$1._finishTimeout;
}, 200);
}
return {
noInertia: true,
needsRenderFrame: !finished,
zoomDelta: zoom - tr.zoom,
around: this._aroundPoint,
originalEvent: this._lastWheelEvent
};
};
ScrollZoomHandler.prototype._smoothOutEasing = function _smoothOutEasing(duration) {
var easing = performance.ease;
if (this._prevEase) {
var ease = this._prevEase, t = (performance.browser.now() - ease.start) / ease.duration, speed = ease.easing(t + 0.01) - ease.easing(t), x = 0.27 / Math.sqrt(speed * speed + 0.0001) * 0.01, y = Math.sqrt(0.27 * 0.27 - x * x);
easing = performance.bezier(x, y, 0.25, 1);
}
this._prevEase = {
start: performance.browser.now(),
duration: duration,
easing: easing
};
return easing;
};
ScrollZoomHandler.prototype.reset = function reset() {
this._active = false;
};
var DoubleClickZoomHandler = function DoubleClickZoomHandler(clickZoom, TapZoom) {
this._clickZoom = clickZoom;
this._tapZoom = TapZoom;
};
DoubleClickZoomHandler.prototype.enable = function enable() {
this._clickZoom.enable();
this._tapZoom.enable();
};
DoubleClickZoomHandler.prototype.disable = function disable() {
this._clickZoom.disable();
this._tapZoom.disable();
};
DoubleClickZoomHandler.prototype.isEnabled = function isEnabled() {
return this._clickZoom.isEnabled() && this._tapZoom.isEnabled();
};
DoubleClickZoomHandler.prototype.isActive = function isActive() {
return this._clickZoom.isActive() || this._tapZoom.isActive();
};
var ClickZoomHandler = function ClickZoomHandler() {
this.reset();
};
ClickZoomHandler.prototype.reset = function reset() {
this._active = false;
};
ClickZoomHandler.prototype.dblclick = function dblclick(e, point) {
e.preventDefault();
return {
cameraAnimation: function (map) {
map.easeTo({
duration: 300,
zoom: map.getZoom() + (e.shiftKey ? -1 : 1),
around: map.unproject(point)
}, { originalEvent: e });
}
};
};
ClickZoomHandler.prototype.enable = function enable() {
this._enabled = true;
};
ClickZoomHandler.prototype.disable = function disable() {
this._enabled = false;
this.reset();
};
ClickZoomHandler.prototype.isEnabled = function isEnabled() {
return this._enabled;
};
ClickZoomHandler.prototype.isActive = function isActive() {
return this._active;
};
var TapDragZoomHandler = function TapDragZoomHandler() {
this._tap = new TapRecognizer({
numTouches: 1,
numTaps: 1
});
this.reset();
};
TapDragZoomHandler.prototype.reset = function reset() {
this._active = false;
delete this._swipePoint;
delete this._swipeTouch;
delete this._tapTime;
this._tap.reset();
};
TapDragZoomHandler.prototype.touchstart = function touchstart(e, points, mapTouches) {
if (this._swipePoint) {
return;
}
if (this._tapTime && e.timeStamp - this._tapTime > MAX_TAP_INTERVAL) {
this.reset();
}
if (!this._tapTime) {
this._tap.touchstart(e, points, mapTouches);
} else if (mapTouches.length > 0) {
this._swipePoint = points[0];
this._swipeTouch = mapTouches[0].identifier;
}
};
TapDragZoomHandler.prototype.touchmove = function touchmove(e, points, mapTouches) {
if (!this._tapTime) {
this._tap.touchmove(e, points, mapTouches);
} else if (this._swipePoint) {
if (mapTouches[0].identifier !== this._swipeTouch) {
return;
}
var newSwipePoint = points[0];
var dist = newSwipePoint.y - this._swipePoint.y;
this._swipePoint = newSwipePoint;
e.preventDefault();
this._active = true;
return { zoomDelta: dist / 128 };
}
};
TapDragZoomHandler.prototype.touchend = function touchend(e, points, mapTouches) {
if (!this._tapTime) {
var point = this._tap.touchend(e, points, mapTouches);
if (point) {
this._tapTime = e.timeStamp;
}
} else if (this._swipePoint) {
if (mapTouches.length === 0) {
this.reset();
}
}
};
TapDragZoomHandler.prototype.touchcancel = function touchcancel() {
this.reset();
};
TapDragZoomHandler.prototype.enable = function enable() {
this._enabled = true;
};
TapDragZoomHandler.prototype.disable = function disable() {
this._enabled = false;
this.reset();
};
TapDragZoomHandler.prototype.isEnabled = function isEnabled() {
return this._enabled;
};
TapDragZoomHandler.prototype.isActive = function isActive() {
return this._active;
};
var DragPanHandler = function DragPanHandler(el, mousePan, touchPan) {
this._el = el;
this._mousePan = mousePan;
this._touchPan = touchPan;
};
DragPanHandler.prototype.enable = function enable(options) {
this._inertiaOptions = options || {};
this._mousePan.enable();
this._touchPan.enable();
this._el.classList.add('mapboxgl-touch-drag-pan');
};
DragPanHandler.prototype.disable = function disable() {
this._mousePan.disable();
this._touchPan.disable();
this._el.classList.remove('mapboxgl-touch-drag-pan');
};
DragPanHandler.prototype.isEnabled = function isEnabled() {
return this._mousePan.isEnabled() && this._touchPan.isEnabled();
};
DragPanHandler.prototype.isActive = function isActive() {
return this._mousePan.isActive() || this._touchPan.isActive();
};
var DragRotateHandler = function DragRotateHandler(options, mouseRotate, mousePitch) {
this._pitchWithRotate = options.pitchWithRotate;
this._mouseRotate = mouseRotate;
this._mousePitch = mousePitch;
};
DragRotateHandler.prototype.enable = function enable() {
this._mouseRotate.enable();
if (this._pitchWithRotate) {
this._mousePitch.enable();
}
};
DragRotateHandler.prototype.disable = function disable() {
this._mouseRotate.disable();
this._mousePitch.disable();
};
DragRotateHandler.prototype.isEnabled = function isEnabled() {
return this._mouseRotate.isEnabled() && (!this._pitchWithRotate || this._mousePitch.isEnabled());
};
DragRotateHandler.prototype.isActive = function isActive() {
return this._mouseRotate.isActive() || this._mousePitch.isActive();
};
var TouchZoomRotateHandler = function TouchZoomRotateHandler(el, touchZoom, touchRotate, tapDragZoom) {
this._el = el;
this._touchZoom = touchZoom;
this._touchRotate = touchRotate;
this._tapDragZoom = tapDragZoom;
this._rotationDisabled = false;
this._enabled = true;
};
TouchZoomRotateHandler.prototype.enable = function enable(options) {
this._touchZoom.enable(options);
if (!this._rotationDisabled) {
this._touchRotate.enable(options);
}
this._tapDragZoom.enable();
this._el.classList.add('mapboxgl-touch-zoom-rotate');
};
TouchZoomRotateHandler.prototype.disable = function disable() {
this._touchZoom.disable();
this._touchRotate.disable();
this._tapDragZoom.disable();
this._el.classList.remove('mapboxgl-touch-zoom-rotate');
};
TouchZoomRotateHandler.prototype.isEnabled = function isEnabled() {
return this._touchZoom.isEnabled() && (this._rotationDisabled || this._touchRotate.isEnabled()) && this._tapDragZoom.isEnabled();
};
TouchZoomRotateHandler.prototype.isActive = function isActive() {
return this._touchZoom.isActive() || this._touchRotate.isActive() || this._tapDragZoom.isActive();
};
TouchZoomRotateHandler.prototype.disableRotation = function disableRotation() {
this._rotationDisabled = true;
this._touchRotate.disable();
};
TouchZoomRotateHandler.prototype.enableRotation = function enableRotation() {
this._rotationDisabled = false;
if (this._touchZoom.isEnabled()) {
this._touchRotate.enable();
}
};
var isMoving = function (p) {
return p.zoom || p.drag || p.pitch || p.rotate;
};
var RenderFrameEvent = function (Event) {
function RenderFrameEvent() {
Event.apply(this, arguments);
}
if (Event)
RenderFrameEvent.__proto__ = Event;
RenderFrameEvent.prototype = Object.create(Event && Event.prototype);
RenderFrameEvent.prototype.constructor = RenderFrameEvent;
return RenderFrameEvent;
}(performance.Event);
function hasChange(result) {
return result.panDelta && result.panDelta.mag() || result.zoomDelta || result.bearingDelta || result.pitchDelta;
}
var HandlerManager = function HandlerManager(map, options) {
this._map = map;
this._el = this._map.getCanvasContainer();
this._handlers = [];
this._handlersById = {};
this._changes = [];
this._inertia = new HandlerInertia(map);
this._bearingSnap = options.bearingSnap;
this._previousActiveHandlers = {};
this._eventsInProgress = {};
this._addDefaultHandlers(options);
performance.bindAll([
'handleEvent',
'handleWindowEvent'
], this);
var el = this._el;
this._listeners = [
[
el,
'touchstart',
{ passive: true }
],
[
el,
'touchmove',
{ passive: false }
],
[
el,
'touchend',
undefined
],
[
el,
'touchcancel',
undefined
],
[
el,
'mousedown',
undefined
],
[
el,
'mousemove',
undefined
],
[
el,
'mouseup',
undefined
],
[
performance.window.document,
'mousemove',
{ capture: true }
],
[
performance.window.document,
'mouseup',
undefined
],
[
el,
'mouseover',
undefined
],
[
el,
'mouseout',
undefined
],
[
el,
'dblclick',
undefined
],
[
el,
'click',
undefined
],
[
el,
'keydown',
{ capture: false }
],
[
el,
'keyup',
undefined
],
[
el,
'wheel',
{ passive: false }
],
[
el,
'contextmenu',
undefined
],
[
performance.window,
'blur',
undefined
]
];
for (var i = 0, list = this._listeners; i < list.length; i += 1) {
var ref = list[i];
var target = ref[0];
var type = ref[1];
var listenerOptions = ref[2];
DOM.addEventListener(target, type, target === performance.window.document ? this.handleWindowEvent : this.handleEvent, listenerOptions);
}
};
HandlerManager.prototype.destroy = function destroy() {
for (var i = 0, list = this._listeners; i < list.length; i += 1) {
var ref = list[i];
var target = ref[0];
var type = ref[1];
var listenerOptions = ref[2];
DOM.removeEventListener(target, type, target === performance.window.document ? this.handleWindowEvent : this.handleEvent, listenerOptions);
}
};
HandlerManager.prototype._addDefaultHandlers = function _addDefaultHandlers(options) {
var map = this._map;
var el = map.getCanvasContainer();
this._add('mapEvent', new MapEventHandler(map, options));
var boxZoom = map.boxZoom = new BoxZoomHandler(map, options);
this._add('boxZoom', boxZoom);
var tapZoom = new TapZoomHandler();
var clickZoom = new ClickZoomHandler();
map.doubleClickZoom = new DoubleClickZoomHandler(clickZoom, tapZoom);
this._add('tapZoom', tapZoom);
this._add('clickZoom', clickZoom);
var tapDragZoom = new TapDragZoomHandler();
this._add('tapDragZoom', tapDragZoom);
var touchPitch = map.touchPitch = new TouchPitchHandler();
this._add('touchPitch', touchPitch);
var mouseRotate = new MouseRotateHandler(options);
var mousePitch = new MousePitchHandler(options);
map.dragRotate = new DragRotateHandler(options, mouseRotate, mousePitch);
this._add('mouseRotate', mouseRotate, ['mousePitch']);
this._add('mousePitch', mousePitch, ['mouseRotate']);
var mousePan = new MousePanHandler(options);
var touchPan = new TouchPanHandler(options);
map.dragPan = new DragPanHandler(el, mousePan, touchPan);
this._add('mousePan', mousePan);
this._add('touchPan', touchPan, [
'touchZoom',
'touchRotate'
]);
var touchRotate = new TouchRotateHandler();
var touchZoom = new TouchZoomHandler();
map.touchZoomRotate = new TouchZoomRotateHandler(el, touchZoom, touchRotate, tapDragZoom);
this._add('touchRotate', touchRotate, [
'touchPan',
'touchZoom'
]);
this._add('touchZoom', touchZoom, [
'touchPan',
'touchRotate'
]);
var scrollZoom = map.scrollZoom = new ScrollZoomHandler(map, this);
this._add('scrollZoom', scrollZoom, ['mousePan']);
var keyboard = map.keyboard = new KeyboardHandler();
this._add('keyboard', keyboard);
this._add('blockableMapEvent', new BlockableMapEventHandler(map));
for (var i = 0, list = [
'boxZoom',
'doubleClickZoom',
'tapDragZoom',
'touchPitch',
'dragRotate',
'dragPan',
'touchZoomRotate',
'scrollZoom',
'keyboard'
]; i < list.length; i += 1) {
var name = list[i];
if (options.interactive && options[name]) {
map[name].enable(options[name]);
}
}
};
HandlerManager.prototype._add = function _add(handlerName, handler, allowed) {
this._handlers.push({
handlerName: handlerName,
handler: handler,
allowed: allowed
});
this._handlersById[handlerName] = handler;
};
HandlerManager.prototype.stop = function stop(allowEndAnimation) {
if (this._updatingCamera) {
return;
}
for (var i = 0, list = this._handlers; i < list.length; i += 1) {
var ref = list[i];
var handler = ref.handler;
handler.reset();
}
this._inertia.clear();
this._fireEvents({}, {}, allowEndAnimation);
this._changes = [];
};
HandlerManager.prototype.isActive = function isActive() {
for (var i = 0, list = this._handlers; i < list.length; i += 1) {
var ref = list[i];
var handler = ref.handler;
if (handler.isActive()) {
return true;
}
}
return false;
};
HandlerManager.prototype.isZooming = function isZooming() {
return !!this._eventsInProgress.zoom || this._map.scrollZoom.isZooming();
};
HandlerManager.prototype.isRotating = function isRotating() {
return !!this._eventsInProgress.rotate;
};
HandlerManager.prototype.isMoving = function isMoving$1() {
return Boolean(isMoving(this._eventsInProgress)) || this.isZooming();
};
HandlerManager.prototype._blockedByActive = function _blockedByActive(activeHandlers, allowed, myName) {
for (var name in activeHandlers) {
if (name === myName) {
continue;
}
if (!allowed || allowed.indexOf(name) < 0) {
return true;
}
}
return false;
};
HandlerManager.prototype.handleWindowEvent = function handleWindowEvent(e) {
this.handleEvent(e, e.type + 'Window');
};
HandlerManager.prototype._getMapTouches = function _getMapTouches(touches) {
var mapTouches = [];
for (var i = 0, list = touches; i < list.length; i += 1) {
var t = list[i];
var target = t.target;
if (this._el.contains(target)) {
mapTouches.push(t);
}
}
return mapTouches;
};
HandlerManager.prototype.handleEvent = function handleEvent(e, eventName) {
if (e.type === 'blur') {
this.stop(true);
return;
}
this._updatingCamera = true;
var inputEvent = e.type === 'renderFrame' ? undefined : e;
var mergedHandlerResult = { needsRenderFrame: false };
var eventsInProgress = {};
var activeHandlers = {};
var mapTouches = e.touches ? this._getMapTouches(e.touches) : undefined;
var points = mapTouches ? DOM.touchPos(this._el, mapTouches) : DOM.mousePos(this._el, e);
for (var i = 0, list = this._handlers; i < list.length; i += 1) {
var ref = list[i];
var handlerName = ref.handlerName;
var handler = ref.handler;
var allowed = ref.allowed;
if (!handler.isEnabled()) {
continue;
}
var data = void 0;
if (this._blockedByActive(activeHandlers, allowed, handlerName)) {
handler.reset();
} else {
if (handler[eventName || e.type]) {
data = handler[eventName || e.type](e, points, mapTouches);
this.mergeHandlerResult(mergedHandlerResult, eventsInProgress, data, handlerName, inputEvent);
if (data && data.needsRenderFrame) {
this._triggerRenderFrame();
}
}
}
if (data || handler.isActive()) {
activeHandlers[handlerName] = handler;
}
}
var deactivatedHandlers = {};
for (var name in this._previousActiveHandlers) {
if (!activeHandlers[name]) {
deactivatedHandlers[name] = inputEvent;
}
}
this._previousActiveHandlers = activeHandlers;
if (Object.keys(deactivatedHandlers).length || hasChange(mergedHandlerResult)) {
this._changes.push([
mergedHandlerResult,
eventsInProgress,
deactivatedHandlers
]);
this._triggerRenderFrame();
}
if (Object.keys(activeHandlers).length || hasChange(mergedHandlerResult)) {
this._map._stop(true);
}
this._updatingCamera = false;
var cameraAnimation = mergedHandlerResult.cameraAnimation;
if (cameraAnimation) {
this._inertia.clear();
this._fireEvents({}, {}, true);
this._changes = [];
cameraAnimation(this._map);
}
};
HandlerManager.prototype.mergeHandlerResult = function mergeHandlerResult(mergedHandlerResult, eventsInProgress, handlerResult, name, e) {
if (!handlerResult) {
return;
}
performance.extend(mergedHandlerResult, handlerResult);
var eventData = {
handlerName: name,
originalEvent: handlerResult.originalEvent || e
};
if (handlerResult.zoomDelta !== undefined) {
eventsInProgress.zoom = eventData;
}
if (handlerResult.panDelta !== undefined) {
eventsInProgress.drag = eventData;
}
if (handlerResult.pitchDelta !== undefined) {
eventsInProgress.pitch = eventData;
}
if (handlerResult.bearingDelta !== undefined) {
eventsInProgress.rotate = eventData;
}
};
HandlerManager.prototype._applyChanges = function _applyChanges() {
var combined = {};
var combinedEventsInProgress = {};
var combinedDeactivatedHandlers = {};
for (var i = 0, list = this._changes; i < list.length; i += 1) {
var ref = list[i];
var change = ref[0];
var eventsInProgress = ref[1];
var deactivatedHandlers = ref[2];
if (change.panDelta) {
combined.panDelta = (combined.panDelta || new performance.Point(0, 0))._add(change.panDelta);
}
if (change.zoomDelta) {
combined.zoomDelta = (combined.zoomDelta || 0) + change.zoomDelta;
}
if (change.bearingDelta) {
combined.bearingDelta = (combined.bearingDelta || 0) + change.bearingDelta;
}
if (change.pitchDelta) {
combined.pitchDelta = (combined.pitchDelta || 0) + change.pitchDelta;
}
if (change.around !== undefined) {
combined.around = change.around;
}
if (change.pinchAround !== undefined) {
combined.pinchAround = change.pinchAround;
}
if (change.noInertia) {
combined.noInertia = change.noInertia;
}
performance.extend(combinedEventsInProgress, eventsInProgress);
performance.extend(combinedDeactivatedHandlers, deactivatedHandlers);
}
this._updateMapTransform(combined, combinedEventsInProgress, combinedDeactivatedHandlers);
this._changes = [];
};
HandlerManager.prototype._updateMapTransform = function _updateMapTransform(combinedResult, combinedEventsInProgress, deactivatedHandlers) {
var map = this._map;
var tr = map.transform;
if (!hasChange(combinedResult)) {
return this._fireEvents(combinedEventsInProgress, deactivatedHandlers, true);
}
var panDelta = combinedResult.panDelta;
var zoomDelta = combinedResult.zoomDelta;
var bearingDelta = combinedResult.bearingDelta;
var pitchDelta = combinedResult.pitchDelta;
var around = combinedResult.around;
var pinchAround = combinedResult.pinchAround;
if (pinchAround !== undefined) {
around = pinchAround;
}
map._stop(true);
around = around || map.transform.centerPoint;
var loc = tr.pointLocation(panDelta ? around.sub(panDelta) : around);
if (bearingDelta) {
tr.bearing += bearingDelta;
}
if (pitchDelta) {
tr.pitch += pitchDelta;
}
if (zoomDelta) {
tr.zoom += zoomDelta;
}
tr.setLocationAtPoint(loc, around);
this._map._update();
if (!combinedResult.noInertia) {
this._inertia.record(combinedResult);
}
this._fireEvents(combinedEventsInProgress, deactivatedHandlers, true);
};
HandlerManager.prototype._fireEvents = function _fireEvents(newEventsInProgress, deactivatedHandlers, allowEndAnimation) {
var this$1 = this;
var wasMoving = isMoving(this._eventsInProgress);
var nowMoving = isMoving(newEventsInProgress);
var startEvents = {};
for (var eventName in newEventsInProgress) {
var ref = newEventsInProgress[eventName];
var originalEvent = ref.originalEvent;
if (!this._eventsInProgress[eventName]) {
startEvents[eventName + 'start'] = originalEvent;
}
this._eventsInProgress[eventName] = newEventsInProgress[eventName];
}
if (!wasMoving && nowMoving) {
this._fireEvent('movestart', nowMoving.originalEvent);
}
for (var name in startEvents) {
this._fireEvent(name, startEvents[name]);
}
if (nowMoving) {
this._fireEvent('move', nowMoving.originalEvent);
}
for (var eventName$1 in newEventsInProgress) {
var ref$1 = newEventsInProgress[eventName$1];
var originalEvent$1 = ref$1.originalEvent;
this._fireEvent(eventName$1, originalEvent$1);
}
var endEvents = {};
var originalEndEvent;
for (var eventName$2 in this._eventsInProgress) {
var ref$2 = this._eventsInProgress[eventName$2];
var handlerName = ref$2.handlerName;
var originalEvent$2 = ref$2.originalEvent;
if (!this._handlersById[handlerName].isActive()) {
delete this._eventsInProgress[eventName$2];
originalEndEvent = deactivatedHandlers[handlerName] || originalEvent$2;
endEvents[eventName$2 + 'end'] = originalEndEvent;
}
}
for (var name$1 in endEvents) {
this._fireEvent(name$1, endEvents[name$1]);
}
var stillMoving = isMoving(this._eventsInProgress);
if (allowEndAnimation && (wasMoving || nowMoving) && !stillMoving) {
this._updatingCamera = true;
var inertialEase = this._inertia._onMoveEnd(this._map.dragPan._inertiaOptions);
var shouldSnapToNorth = function (bearing) {
return bearing !== 0 && -this$1._bearingSnap < bearing && bearing < this$1._bearingSnap;
};
if (inertialEase) {
if (shouldSnapToNorth(inertialEase.bearing || this._map.getBearing())) {
inertialEase.bearing = 0;
}
this._map.easeTo(inertialEase, { originalEvent: originalEndEvent });
} else {
this._map.fire(new performance.Event('moveend', { originalEvent: originalEndEvent }));
if (shouldSnapToNorth(this._map.getBearing())) {
this._map.resetNorth();
}
}
this._updatingCamera = false;
}
};
HandlerManager.prototype._fireEvent = function _fireEvent(type, e) {
this._map.fire(new performance.Event(type, e ? { originalEvent: e } : {}));
};
HandlerManager.prototype._requestFrame = function _requestFrame() {
var this$1 = this;
this._map.triggerRepaint();
return this._map._renderTaskQueue.add(function (timeStamp) {
delete this$1._frameId;
this$1.handleEvent(new RenderFrameEvent('renderFrame', { timeStamp: timeStamp }));
this$1._applyChanges();
});
};
HandlerManager.prototype._triggerRenderFrame = function _triggerRenderFrame() {
if (this._frameId === undefined) {
this._frameId = this._requestFrame();
}
};
var Camera = function (Evented) {
function Camera(transform, options) {
Evented.call(this);
this._moving = false;
this._zooming = false;
this.transform = transform;
this._bearingSnap = options.bearingSnap;
performance.bindAll(['_renderFrameCallback'], this);
}
if (Evented)
Camera.__proto__ = Evented;
Camera.prototype = Object.create(Evented && Evented.prototype);
Camera.prototype.constructor = Camera;
Camera.prototype.getCenter = function getCenter() {
return new performance.LngLat(this.transform.center.lng, this.transform.center.lat);
};
Camera.prototype.setCenter = function setCenter(center, eventData) {
return this.jumpTo({ center: center }, eventData);
};
Camera.prototype.panBy = function panBy(offset, options, eventData) {
offset = performance.Point.convert(offset).mult(-1);
return this.panTo(this.transform.center, performance.extend({ offset: offset }, options), eventData);
};
Camera.prototype.panTo = function panTo(lnglat, options, eventData) {
return this.easeTo(performance.extend({ center: lnglat }, options), eventData);
};
Camera.prototype.getZoom = function getZoom() {
return this.transform.zoom;
};
Camera.prototype.setZoom = function setZoom(zoom, eventData) {
this.jumpTo({ zoom: zoom }, eventData);
return this;
};
Camera.prototype.zoomTo = function zoomTo(zoom, options, eventData) {
return this.easeTo(performance.extend({ zoom: zoom }, options), eventData);
};
Camera.prototype.zoomIn = function zoomIn(options, eventData) {
this.zoomTo(this.getZoom() + 1, options, eventData);
return this;
};
Camera.prototype.zoomOut = function zoomOut(options, eventData) {
this.zoomTo(this.getZoom() - 1, options, eventData);
return this;
};
Camera.prototype.getBearing = function getBearing() {
return this.transform.bearing;
};
Camera.prototype.setBearing = function setBearing(bearing, eventData) {
this.jumpTo({ bearing: bearing }, eventData);
return this;
};
Camera.prototype.getPadding = function getPadding() {
return this.transform.padding;
};
Camera.prototype.setPadding = function setPadding(padding, eventData) {
this.jumpTo({ padding: padding }, eventData);
return this;
};
Camera.prototype.rotateTo = function rotateTo(bearing, options, eventData) {
return this.easeTo(performance.extend({ bearing: bearing }, options), eventData);
};
Camera.prototype.resetNorth = function resetNorth(options, eventData) {
this.rotateTo(0, performance.extend({ duration: 1000 }, options), eventData);
return this;
};
Camera.prototype.resetNorthPitch = function resetNorthPitch(options, eventData) {
this.easeTo(performance.extend({
bearing: 0,
pitch: 0,
duration: 1000
}, options), eventData);
return this;
};
Camera.prototype.snapToNorth = function snapToNorth(options, eventData) {
if (Math.abs(this.getBearing()) < this._bearingSnap) {
return this.resetNorth(options, eventData);
}
return this;
};
Camera.prototype.getPitch = function getPitch() {
return this.transform.pitch;
};
Camera.prototype.setPitch = function setPitch(pitch, eventData) {
this.jumpTo({ pitch: pitch }, eventData);
return this;
};
Camera.prototype.cameraForBounds = function cameraForBounds(bounds, options) {
bounds = performance.LngLatBounds.convert(bounds);
var bearing = options && options.bearing || 0;
return this._cameraForBoxAndBearing(bounds.getNorthWest(), bounds.getSouthEast(), bearing, options);
};
Camera.prototype._cameraForBoxAndBearing = function _cameraForBoxAndBearing(p0, p1, bearing, options) {
var defaultPadding = {
top: 0,
bottom: 0,
right: 0,
left: 0
};
options = performance.extend({
padding: defaultPadding,
offset: [
0,
0
],
maxZoom: this.transform.maxZoom
}, options);
if (typeof options.padding === 'number') {
var p = options.padding;
options.padding = {
top: p,
bottom: p,
right: p,
left: p
};
}
options.padding = performance.extend(defaultPadding, options.padding);
var tr = this.transform;
var edgePadding = tr.padding;
var p0world = tr.project(performance.LngLat.convert(p0));
var p1world = tr.project(performance.LngLat.convert(p1));
var p0rotated = p0world.rotate(-bearing * Math.PI / 180);
var p1rotated = p1world.rotate(-bearing * Math.PI / 180);
var upperRight = new performance.Point(Math.max(p0rotated.x, p1rotated.x), Math.max(p0rotated.y, p1rotated.y));
var lowerLeft = new performance.Point(Math.min(p0rotated.x, p1rotated.x), Math.min(p0rotated.y, p1rotated.y));
var size = upperRight.sub(lowerLeft);
var scaleX = (tr.width - (edgePadding.left + edgePadding.right + options.padding.left + options.padding.right)) / size.x;
var scaleY = (tr.height - (edgePadding.top + edgePadding.bottom + options.padding.top + options.padding.bottom)) / size.y;
if (scaleY < 0 || scaleX < 0) {
performance.warnOnce('Map cannot fit within canvas with the given bounds, padding, and/or offset.');
return;
}
var zoom = Math.min(tr.scaleZoom(tr.scale * Math.min(scaleX, scaleY)), options.maxZoom);
var offset = typeof options.offset.x === 'number' ? new performance.Point(options.offset.x, options.offset.y) : performance.Point.convert(options.offset);
var paddingOffsetX = (options.padding.left - options.padding.right) / 2;
var paddingOffsetY = (options.padding.top - options.padding.bottom) / 2;
var paddingOffset = new performance.Point(paddingOffsetX, paddingOffsetY);
var rotatedPaddingOffset = paddingOffset.rotate(bearing * Math.PI / 180);
var offsetAtInitialZoom = offset.add(rotatedPaddingOffset);
var offsetAtFinalZoom = offsetAtInitialZoom.mult(tr.scale / tr.zoomScale(zoom));
var center = tr.unproject(p0world.add(p1world).div(2).sub(offsetAtFinalZoom));
return {
center: center,
zoom: zoom,
bearing: bearing
};
};
Camera.prototype.fitBounds = function fitBounds(bounds, options, eventData) {
return this._fitInternal(this.cameraForBounds(bounds, options), options, eventData);
};
Camera.prototype.fitScreenCoordinates = function fitScreenCoordinates(p0, p1, bearing, options, eventData) {
return this._fitInternal(this._cameraForBoxAndBearing(this.transform.pointLocation(performance.Point.convert(p0)), this.transform.pointLocation(performance.Point.convert(p1)), bearing, options), options, eventData);
};
Camera.prototype._fitInternal = function _fitInternal(calculatedOptions, options, eventData) {
if (!calculatedOptions) {
return this;
}
options = performance.extend(calculatedOptions, options);
delete options.padding;
return options.linear ? this.easeTo(options, eventData) : this.flyTo(options, eventData);
};
Camera.prototype.jumpTo = function jumpTo(options, eventData) {
this.stop();
var tr = this.transform;
var zoomChanged = false, bearingChanged = false, pitchChanged = false;
if ('zoom' in options && tr.zoom !== +options.zoom) {
zoomChanged = true;
tr.zoom = +options.zoom;
}
if (options.center !== undefined) {
tr.center = performance.LngLat.convert(options.center);
}
if ('bearing' in options && tr.bearing !== +options.bearing) {
bearingChanged = true;
tr.bearing = +options.bearing;
}
if ('pitch' in options && tr.pitch !== +options.pitch) {
pitchChanged = true;
tr.pitch = +options.pitch;
}
if (options.padding != null && !tr.isPaddingEqual(options.padding)) {
tr.padding = options.padding;
}
this.fire(new performance.Event('movestart', eventData)).fire(new performance.Event('move', eventData));
if (zoomChanged) {
this.fire(new performance.Event('zoomstart', eventData)).fire(new performance.Event('zoom', eventData)).fire(new performance.Event('zoomend', eventData));
}
if (bearingChanged) {
this.fire(new performance.Event('rotatestart', eventData)).fire(new performance.Event('rotate', eventData)).fire(new performance.Event('rotateend', eventData));
}
if (pitchChanged) {
this.fire(new performance.Event('pitchstart', eventData)).fire(new performance.Event('pitch', eventData)).fire(new performance.Event('pitchend', eventData));
}
return this.fire(new performance.Event('moveend', eventData));
};
Camera.prototype.easeTo = function easeTo(options, eventData) {
var this$1 = this;
this._stop(false, options.easeId);
options = performance.extend({
offset: [
0,
0
],
duration: 500,
easing: performance.ease
}, options);
if (options.animate === false || !options.essential && performance.browser.prefersReducedMotion) {
options.duration = 0;
}
var tr = this.transform, startZoom = this.getZoom(), startBearing = this.getBearing(), startPitch = this.getPitch(), startPadding = this.getPadding(), zoom = 'zoom' in options ? +options.zoom : startZoom, bearing = 'bearing' in options ? this._normalizeBearing(options.bearing, startBearing) : startBearing, pitch = 'pitch' in options ? +options.pitch : startPitch, padding = 'padding' in options ? options.padding : tr.padding;
var offsetAsPoint = performance.Point.convert(options.offset);
var pointAtOffset = tr.centerPoint.add(offsetAsPoint);
var locationAtOffset = tr.pointLocation(pointAtOffset);
var center = performance.LngLat.convert(options.center || locationAtOffset);
this._normalizeCenter(center);
var from = tr.project(locationAtOffset);
var delta = tr.project(center).sub(from);
var finalScale = tr.zoomScale(zoom - startZoom);
var around, aroundPoint;
if (options.around) {
around = performance.LngLat.convert(options.around);
aroundPoint = tr.locationPoint(around);
}
var currently = {
moving: this._moving,
zooming: this._zooming,
rotating: this._rotating,
pitching: this._pitching
};
this._zooming = this._zooming || zoom !== startZoom;
this._rotating = this._rotating || startBearing !== bearing;
this._pitching = this._pitching || pitch !== startPitch;
this._padding = !tr.isPaddingEqual(padding);
this._easeId = options.easeId;
this._prepareEase(eventData, options.noMoveStart, currently);
this._ease(function (k) {
if (this$1._zooming) {
tr.zoom = performance.number(startZoom, zoom, k);
}
if (this$1._rotating) {
tr.bearing = performance.number(startBearing, bearing, k);
}
if (this$1._pitching) {
tr.pitch = performance.number(startPitch, pitch, k);
}
if (this$1._padding) {
tr.interpolatePadding(startPadding, padding, k);
pointAtOffset = tr.centerPoint.add(offsetAsPoint);
}
if (around) {
tr.setLocationAtPoint(around, aroundPoint);
} else {
var scale = tr.zoomScale(tr.zoom - startZoom);
var base = zoom > startZoom ? Math.min(2, finalScale) : Math.max(0.5, finalScale);
var speedup = Math.pow(base, 1 - k);
var newCenter = tr.unproject(from.add(delta.mult(k * speedup)).mult(scale));
tr.setLocationAtPoint(tr.renderWorldCopies ? newCenter.wrap() : newCenter, pointAtOffset);
}
this$1._fireMoveEvents(eventData);
}, function (interruptingEaseId) {
this$1._afterEase(eventData, interruptingEaseId);
}, options);
return this;
};
Camera.prototype._prepareEase = function _prepareEase(eventData, noMoveStart, currently) {
if (currently === void 0)
currently = {};
this._moving = true;
if (!noMoveStart && !currently.moving) {
this.fire(new performance.Event('movestart', eventData));
}
if (this._zooming && !currently.zooming) {
this.fire(new performance.Event('zoomstart', eventData));
}
if (this._rotating && !currently.rotating) {
this.fire(new performance.Event('rotatestart', eventData));
}
if (this._pitching && !currently.pitching) {
this.fire(new performance.Event('pitchstart', eventData));
}
};
Camera.prototype._fireMoveEvents = function _fireMoveEvents(eventData) {
this.fire(new performance.Event('move', eventData));
if (this._zooming) {
this.fire(new performance.Event('zoom', eventData));
}
if (this._rotating) {
this.fire(new performance.Event('rotate', eventData));
}
if (this._pitching) {
this.fire(new performance.Event('pitch', eventData));
}
};
Camera.prototype._afterEase = function _afterEase(eventData, easeId) {
if (this._easeId && easeId && this._easeId === easeId) {
return;
}
delete this._easeId;
var wasZooming = this._zooming;
var wasRotating = this._rotating;
var wasPitching = this._pitching;
this._moving = false;
this._zooming = false;
this._rotating = false;
this._pitching = false;
this._padding = false;
if (wasZooming) {
this.fire(new performance.Event('zoomend', eventData));
}
if (wasRotating) {
this.fire(new performance.Event('rotateend', eventData));
}
if (wasPitching) {
this.fire(new performance.Event('pitchend', eventData));
}
this.fire(new performance.Event('moveend', eventData));
};
Camera.prototype.flyTo = function flyTo(options, eventData) {
var this$1 = this;
if (!options.essential && performance.browser.prefersReducedMotion) {
var coercedOptions = performance.pick(options, [
'center',
'zoom',
'bearing',
'pitch',
'around'
]);
return this.jumpTo(coercedOptions, eventData);
}
this.stop();
options = performance.extend({
offset: [
0,
0
],
speed: 1.2,
curve: 1.42,
easing: performance.ease
}, options);
var tr = this.transform, startZoom = this.getZoom(), startBearing = this.getBearing(), startPitch = this.getPitch(), startPadding = this.getPadding();
var zoom = 'zoom' in options ? performance.clamp(+options.zoom, tr.minZoom, tr.maxZoom) : startZoom;
var bearing = 'bearing' in options ? this._normalizeBearing(options.bearing, startBearing) : startBearing;
var pitch = 'pitch' in options ? +options.pitch : startPitch;
var padding = 'padding' in options ? options.padding : tr.padding;
var scale = tr.zoomScale(zoom - startZoom);
var offsetAsPoint = performance.Point.convert(options.offset);
var pointAtOffset = tr.centerPoint.add(offsetAsPoint);
var locationAtOffset = tr.pointLocation(pointAtOffset);
var center = performance.LngLat.convert(options.center || locationAtOffset);
this._normalizeCenter(center);
var from = tr.project(locationAtOffset);
var delta = tr.project(center).sub(from);
var rho = options.curve;
var w0 = Math.max(tr.width, tr.height), w1 = w0 / scale, u1 = delta.mag();
if ('minZoom' in options) {
var minZoom = performance.clamp(Math.min(options.minZoom, startZoom, zoom), tr.minZoom, tr.maxZoom);
var wMax = w0 / tr.zoomScale(minZoom - startZoom);
rho = Math.sqrt(wMax / u1 * 2);
}
var rho2 = rho * rho;
function r(i) {
var b = (w1 * w1 - w0 * w0 + (i ? -1 : 1) * rho2 * rho2 * u1 * u1) / (2 * (i ? w1 : w0) * rho2 * u1);
return Math.log(Math.sqrt(b * b + 1) - b);
}
function sinh(n) {
return (Math.exp(n) - Math.exp(-n)) / 2;
}
function cosh(n) {
return (Math.exp(n) + Math.exp(-n)) / 2;
}
function tanh(n) {
return sinh(n) / cosh(n);
}
var r0 = r(0);
var w = function (s) {
return cosh(r0) / cosh(r0 + rho * s);
};
var u = function (s) {
return w0 * ((cosh(r0) * tanh(r0 + rho * s) - sinh(r0)) / rho2) / u1;
};
var S = (r(1) - r0) / rho;
if (Math.abs(u1) < 0.000001 || !isFinite(S)) {
if (Math.abs(w0 - w1) < 0.000001) {
return this.easeTo(options, eventData);
}
var k = w1 < w0 ? -1 : 1;
S = Math.abs(Math.log(w1 / w0)) / rho;
u = function () {
return 0;
};
w = function (s) {
return Math.exp(k * rho * s);
};
}
if ('duration' in options) {
options.duration = +options.duration;
} else {
var V = 'screenSpeed' in options ? +options.screenSpeed / rho : +options.speed;
options.duration = 1000 * S / V;
}
if (options.maxDuration && options.duration > options.maxDuration) {
options.duration = 0;
}
this._zooming = true;
this._rotating = startBearing !== bearing;
this._pitching = pitch !== startPitch;
this._padding = !tr.isPaddingEqual(padding);
this._prepareEase(eventData, false);
this._ease(function (k) {
var s = k * S;
var scale = 1 / w(s);
tr.zoom = k === 1 ? zoom : startZoom + tr.scaleZoom(scale);
if (this$1._rotating) {
tr.bearing = performance.number(startBearing, bearing, k);
}
if (this$1._pitching) {
tr.pitch = performance.number(startPitch, pitch, k);
}
if (this$1._padding) {
tr.interpolatePadding(startPadding, padding, k);
pointAtOffset = tr.centerPoint.add(offsetAsPoint);
}
var newCenter = k === 1 ? center : tr.unproject(from.add(delta.mult(u(s))).mult(scale));
tr.setLocationAtPoint(tr.renderWorldCopies ? newCenter.wrap() : newCenter, pointAtOffset);
this$1._fireMoveEvents(eventData);
}, function () {
return this$1._afterEase(eventData);
}, options);
return this;
};
Camera.prototype.isEasing = function isEasing() {
return !!this._easeFrameId;
};
Camera.prototype.stop = function stop() {
return this._stop();
};
Camera.prototype._stop = function _stop(allowGestures, easeId) {
if (this._easeFrameId) {
this._cancelRenderFrame(this._easeFrameId);
delete this._easeFrameId;
delete this._onEaseFrame;
}
if (this._onEaseEnd) {
var onEaseEnd = this._onEaseEnd;
delete this._onEaseEnd;
onEaseEnd.call(this, easeId);
}
if (!allowGestures) {
var handlers = this.handlers;
if (handlers) {
handlers.stop(false);
}
}
return this;
};
Camera.prototype._ease = function _ease(frame, finish, options) {
if (options.animate === false || options.duration === 0) {
frame(1);
finish();
} else {
this._easeStart = performance.browser.now();
this._easeOptions = options;
this._onEaseFrame = frame;
this._onEaseEnd = finish;
this._easeFrameId = this._requestRenderFrame(this._renderFrameCallback);
}
};
Camera.prototype._renderFrameCallback = function _renderFrameCallback() {
var t = Math.min((performance.browser.now() - this._easeStart) / this._easeOptions.duration, 1);
this._onEaseFrame(this._easeOptions.easing(t));
if (t < 1) {
this._easeFrameId = this._requestRenderFrame(this._renderFrameCallback);
} else {
this.stop();
}
};
Camera.prototype._normalizeBearing = function _normalizeBearing(bearing, currentBearing) {
bearing = performance.wrap(bearing, -180, 180);
var diff = Math.abs(bearing - currentBearing);
if (Math.abs(bearing - 360 - currentBearing) < diff) {
bearing -= 360;
}
if (Math.abs(bearing + 360 - currentBearing) < diff) {
bearing += 360;
}
return bearing;
};
Camera.prototype._normalizeCenter = function _normalizeCenter(center) {
var tr = this.transform;
if (!tr.renderWorldCopies || tr.lngRange) {
return;
}
var delta = center.lng - tr.center.lng;
center.lng += delta > 180 ? -360 : delta < -180 ? 360 : 0;
};
return Camera;
}(performance.Evented);
var AttributionControl = function AttributionControl(options) {
if (options === void 0)
options = {};
this.options = options;
performance.bindAll([
'_toggleAttribution',
'_updateEditLink',
'_updateData',
'_updateCompact'
], this);
};
AttributionControl.prototype.getDefaultPosition = function getDefaultPosition() {
return 'bottom-right';
};
AttributionControl.prototype.onAdd = function onAdd(map) {
var compact = this.options && this.options.compact;
this._map = map;
this._container = DOM.create('div', 'mapboxgl-ctrl mapboxgl-ctrl-attrib');
this._compactButton = DOM.create('button', 'mapboxgl-ctrl-attrib-button', this._container);
this._compactButton.addEventListener('click', this._toggleAttribution);
this._setElementTitle(this._compactButton, 'ToggleAttribution');
this._innerContainer = DOM.create('div', 'mapboxgl-ctrl-attrib-inner', this._container);
this._innerContainer.setAttribute('role', 'list');
if (compact) {
this._container.classList.add('mapboxgl-compact');
}
this._updateAttributions();
this._updateEditLink();
this._map.on('styledata', this._updateData);
this._map.on('sourcedata', this._updateData);
this._map.on('moveend', this._updateEditLink);
if (compact === undefined) {
this._map.on('resize', this._updateCompact);
this._updateCompact();
}
return this._container;
};
AttributionControl.prototype.onRemove = function onRemove() {
DOM.remove(this._container);
this._map.off('styledata', this._updateData);
this._map.off('sourcedata', this._updateData);
this._map.off('moveend', this._updateEditLink);
this._map.off('resize', this._updateCompact);
this._map = undefined;
this._attribHTML = undefined;
};
AttributionControl.prototype._setElementTitle = function _setElementTitle(element, title) {
var str = this._map._getUIString('AttributionControl.' + title);
element.title = str;
element.setAttribute('aria-label', str);
};
AttributionControl.prototype._toggleAttribution = function _toggleAttribution() {
if (this._container.classList.contains('mapboxgl-compact-show')) {
this._container.classList.remove('mapboxgl-compact-show');
this._compactButton.setAttribute('aria-pressed', 'false');
} else {
this._container.classList.add('mapboxgl-compact-show');
this._compactButton.setAttribute('aria-pressed', 'true');
}
};
AttributionControl.prototype._updateEditLink = function _updateEditLink() {
var editLink = this._editLink;
if (!editLink) {
editLink = this._editLink = this._container.querySelector('.mapbox-improve-map');
}
var params = [
{
key: 'owner',
value: this.styleOwner
},
{
key: 'id',
value: this.styleId
},
{
key: 'access_token',
value: this._map._requestManager._customAccessToken || performance.config.ACCESS_TOKEN
}
];
if (editLink) {
var paramString = params.reduce(function (acc, next, i) {
if (next.value) {
acc += next.key + '=' + next.value + (i < params.length - 1 ? '&' : '');
}
return acc;
}, '?');
editLink.href = performance.config.FEEDBACK_URL + '/' + paramString + (this._map._hash ? this._map._hash.getHashString(true) : '');
editLink.rel = 'noopener nofollow';
this._setElementTitle(editLink, 'MapFeedback');
}
};
AttributionControl.prototype._updateData = function _updateData(e) {
if (e && (e.sourceDataType === 'metadata' || e.sourceDataType === 'visibility' || e.dataType === 'style')) {
this._updateAttributions();
this._updateEditLink();
}
};
AttributionControl.prototype._updateAttributions = function _updateAttributions() {
if (!this._map.style) {
return;
}
var attributions = [];
if (this.options.customAttribution) {
if (Array.isArray(this.options.customAttribution)) {
attributions = attributions.concat(this.options.customAttribution.map(function (attribution) {
if (typeof attribution !== 'string') {
return '';
}
return attribution;
}));
} else if (typeof this.options.customAttribution === 'string') {
attributions.push(this.options.customAttribution);
}
}
if (this._map.style.stylesheet) {
var stylesheet = this._map.style.stylesheet;
this.styleOwner = stylesheet.owner;
this.styleId = stylesheet.id;
}
var sourceCaches = this._map.style.sourceCaches;
for (var id in sourceCaches) {
var sourceCache = sourceCaches[id];
if (sourceCache.used) {
var source = sourceCache.getSource();
if (source.attribution && attributions.indexOf(source.attribution) < 0) {
attributions.push(source.attribution);
}
}
}
attributions.sort(function (a, b) {
return a.length - b.length;
});
attributions = attributions.filter(function (attrib, i) {
for (var j = i + 1; j < attributions.length; j++) {
if (attributions[j].indexOf(attrib) >= 0) {
return false;
}
}
return true;
});
var attribHTML = attributions.join(' | ');
if (attribHTML === this._attribHTML) {
return;
}
this._attribHTML = attribHTML;
if (attributions.length) {
this._innerContainer.innerHTML = attribHTML;
this._container.classList.remove('mapboxgl-attrib-empty');
} else {
this._container.classList.add('mapboxgl-attrib-empty');
}
this._editLink = null;
};
AttributionControl.prototype._updateCompact = function _updateCompact() {
if (this._map.getCanvasContainer().offsetWidth <= 640) {
this._container.classList.add('mapboxgl-compact');
} else {
this._container.classList.remove('mapboxgl-compact', 'mapboxgl-compact-show');
}
};
var LogoControl = function LogoControl() {
performance.bindAll(['_updateLogo'], this);
performance.bindAll(['_updateCompact'], this);
};
LogoControl.prototype.onAdd = function onAdd(map) {
this._map = map;
this._container = DOM.create('div', 'mapboxgl-ctrl');
var anchor = DOM.create('a', 'mapboxgl-ctrl-logo');
anchor.target = '_blank';
anchor.rel = 'noopener nofollow';
anchor.href = 'https://www.mapbox.com/';
anchor.setAttribute('aria-label', this._map._getUIString('LogoControl.Title'));
anchor.setAttribute('rel', 'noopener nofollow');
this._container.appendChild(anchor);
this._container.style.display = 'none';
this._map.on('sourcedata', this._updateLogo);
this._updateLogo();
this._map.on('resize', this._updateCompact);
this._updateCompact();
return this._container;
};
LogoControl.prototype.onRemove = function onRemove() {
DOM.remove(this._container);
this._map.off('sourcedata', this._updateLogo);
this._map.off('resize', this._updateCompact);
};
LogoControl.prototype.getDefaultPosition = function getDefaultPosition() {
return 'bottom-left';
};
LogoControl.prototype._updateLogo = function _updateLogo(e) {
if (!e || e.sourceDataType === 'metadata') {
this._container.style.display = this._logoRequired() ? 'block' : 'none';
}
};
LogoControl.prototype._logoRequired = function _logoRequired() {
if (!this._map.style) {
return;
}
var sourceCaches = this._map.style.sourceCaches;
for (var id in sourceCaches) {
var source = sourceCaches[id].getSource();
if (source.mapbox_logo) {
return true;
}
}
return false;
};
LogoControl.prototype._updateCompact = function _updateCompact() {
var containerChildren = this._container.children;
if (containerChildren.length) {
var anchor = containerChildren[0];
if (this._map.getCanvasContainer().offsetWidth < 250) {
anchor.classList.add('mapboxgl-compact');
} else {
anchor.classList.remove('mapboxgl-compact');
}
}
};
var TaskQueue = function TaskQueue() {
this._queue = [];
this._id = 0;
this._cleared = false;
this._currentlyRunning = false;
};
TaskQueue.prototype.add = function add(callback) {
var id = ++this._id;
var queue = this._queue;
queue.push({
callback: callback,
id: id,
cancelled: false
});
return id;
};
TaskQueue.prototype.remove = function remove(id) {
var running = this._currentlyRunning;
var queue = running ? this._queue.concat(running) : this._queue;
for (var i = 0, list = queue; i < list.length; i += 1) {
var task = list[i];
if (task.id === id) {
task.cancelled = true;
return;
}
}
};
TaskQueue.prototype.run = function run(timeStamp) {
if (timeStamp === void 0)
timeStamp = 0;
var queue = this._currentlyRunning = this._queue;
this._queue = [];
for (var i = 0, list = queue; i < list.length; i += 1) {
var task = list[i];
if (task.cancelled) {
continue;
}
task.callback(timeStamp);
if (this._cleared) {
break;
}
}
this._cleared = false;
this._currentlyRunning = false;
};
TaskQueue.prototype.clear = function clear() {
if (this._currentlyRunning) {
this._cleared = true;
}
this._queue = [];
};
var defaultLocale = {
'AttributionControl.ToggleAttribution': 'Toggle attribution',
'AttributionControl.MapFeedback': 'Map feedback',
'FullscreenControl.Enter': 'Enter fullscreen',
'FullscreenControl.Exit': 'Exit fullscreen',
'GeolocateControl.FindMyLocation': 'Find my location',
'GeolocateControl.LocationNotAvailable': 'Location not available',
'LogoControl.Title': 'Mapbox logo',
'NavigationControl.ResetBearing': 'Reset bearing to north',
'NavigationControl.ZoomIn': 'Zoom in',
'NavigationControl.ZoomOut': 'Zoom out',
'ScaleControl.Feet': 'ft',
'ScaleControl.Meters': 'm',
'ScaleControl.Kilometers': 'km',
'ScaleControl.Miles': 'mi',
'ScaleControl.NauticalMiles': 'nm'
};
var HTMLImageElement = performance.window.HTMLImageElement;
var HTMLElement = performance.window.HTMLElement;
var ImageBitmap = performance.window.ImageBitmap;
var defaultMinZoom = -2;
var defaultMaxZoom = 22;
var defaultMinPitch = 0;
var defaultMaxPitch = 60;
var defaultOptions$1 = {
center: [
0,
0
],
zoom: 0,
bearing: 0,
pitch: 0,
minZoom: defaultMinZoom,
maxZoom: defaultMaxZoom,
minPitch: defaultMinPitch,
maxPitch: defaultMaxPitch,
interactive: true,
scrollZoom: true,
boxZoom: true,
dragRotate: true,
dragPan: true,
keyboard: true,
doubleClickZoom: true,
touchZoomRotate: true,
touchPitch: true,
bearingSnap: 7,
clickTolerance: 3,
pitchWithRotate: true,
hash: false,
attributionControl: true,
failIfMajorPerformanceCaveat: false,
preserveDrawingBuffer: false,
trackResize: true,
renderWorldCopies: true,
refreshExpiredTiles: true,
maxTileCacheSize: null,
localIdeographFontFamily: 'sans-serif',
transformRequest: null,
accessToken: null,
fadeDuration: 300,
crossSourceCollisions: true
};
var Map = function (Camera) {
function Map(options) {
var this$1 = this;
options = performance.extend({}, defaultOptions$1, options);
if (options.minZoom != null && options.maxZoom != null && options.minZoom > options.maxZoom) {
throw new Error('maxZoom must be greater than or equal to minZoom');
}
if (options.minPitch != null && options.maxPitch != null && options.minPitch > options.maxPitch) {
throw new Error('maxPitch must be greater than or equal to minPitch');
}
if (options.minPitch != null && options.minPitch < defaultMinPitch) {
throw new Error('minPitch must be greater than or equal to ' + defaultMinPitch);
}
if (options.maxPitch != null && options.maxPitch > defaultMaxPitch) {
throw new Error('maxPitch must be less than or equal to ' + defaultMaxPitch);
}
var transform = new Transform(options.minZoom, options.maxZoom, options.minPitch, options.maxPitch, options.renderWorldCopies);
Camera.call(this, transform, options);
this._interactive = options.interactive;
this._maxTileCacheSize = options.maxTileCacheSize;
this._failIfMajorPerformanceCaveat = options.failIfMajorPerformanceCaveat;
this._preserveDrawingBuffer = options.preserveDrawingBuffer;
this._antialias = options.antialias;
this._trackResize = options.trackResize;
this._bearingSnap = options.bearingSnap;
this._refreshExpiredTiles = options.refreshExpiredTiles;
this._fadeDuration = options.fadeDuration;
this._crossSourceCollisions = options.crossSourceCollisions;
this._crossFadingFactor = 1;
this._collectResourceTiming = options.collectResourceTiming;
this._renderTaskQueue = new TaskQueue();
this._controls = [];
this._mapId = performance.uniqueId();
this._locale = performance.extend({}, defaultLocale, options.locale);
this._clickTolerance = options.clickTolerance;
this._requestManager = new performance.RequestManager(options.transformRequest, options.accessToken);
if (typeof options.container === 'string') {
this._container = performance.window.document.getElementById(options.container);
if (!this._container) {
throw new Error('Container \'' + options.container + '\' not found.');
}
} else if (options.container instanceof HTMLElement) {
this._container = options.container;
} else {
throw new Error('Invalid type: \'container\' must be a String or HTMLElement.');
}
if (options.maxBounds) {
this.setMaxBounds(options.maxBounds);
}
performance.bindAll([
'_onWindowOnline',
'_onWindowResize',
'_onMapScroll',
'_contextLost',
'_contextRestored'
], this);
this._setupContainer();
this._setupPainter();
if (this.painter === undefined) {
throw new Error('Failed to initialize WebGL.');
}
this.on('move', function () {
return this$1._update(false);
});
this.on('moveend', function () {
return this$1._update(false);
});
this.on('zoom', function () {
return this$1._update(true);
});
if (typeof performance.window !== 'undefined') {
performance.window.addEventListener('online', this._onWindowOnline, false);
performance.window.addEventListener('resize', this._onWindowResize, false);
performance.window.addEventListener('orientationchange', this._onWindowResize, false);
}
this.handlers = new HandlerManager(this, options);
var hashName = typeof options.hash === 'string' && options.hash || undefined;
this._hash = options.hash && new Hash(hashName).addTo(this);
if (!this._hash || !this._hash._onHashChange()) {
this.jumpTo({
center: options.center,
zoom: options.zoom,
bearing: options.bearing,
pitch: options.pitch
});
if (options.bounds) {
this.resize();
this.fitBounds(options.bounds, performance.extend({}, options.fitBoundsOptions, { duration: 0 }));
}
}
this.resize();
this._localIdeographFontFamily = options.localIdeographFontFamily;
if (options.style) {
this.setStyle(options.style, { localIdeographFontFamily: options.localIdeographFontFamily });
}
if (options.attributionControl) {
this.addControl(new AttributionControl({ customAttribution: options.customAttribution }));
}
this.addControl(new LogoControl(), options.logoPosition);
this.on('style.load', function () {
if (this$1.transform.unmodified) {
this$1.jumpTo(this$1.style.stylesheet);
}
});
this.on('data', function (event) {
this$1._update(event.dataType === 'style');
this$1.fire(new performance.Event(event.dataType + 'data', event));
});
this.on('dataloading', function (event) {
this$1.fire(new performance.Event(event.dataType + 'dataloading', event));
});
}
if (Camera)
Map.__proto__ = Camera;
Map.prototype = Object.create(Camera && Camera.prototype);
Map.prototype.constructor = Map;
var prototypeAccessors = {
showTileBoundaries: { configurable: true },
showPadding: { configurable: true },
showCollisionBoxes: { configurable: true },
showOverdrawInspector: { configurable: true },
repaint: { configurable: true },
vertices: { configurable: true },
version: { configurable: true }
};
Map.prototype._getMapId = function _getMapId() {
return this._mapId;
};
Map.prototype.addControl = function addControl(control, position) {
if (position === undefined) {
if (control.getDefaultPosition) {
position = control.getDefaultPosition();
} else {
position = 'top-right';
}
}
if (!control || !control.onAdd) {
return this.fire(new performance.ErrorEvent(new Error('Invalid argument to map.addControl(). Argument must be a control with onAdd and onRemove methods.')));
}
var controlElement = control.onAdd(this);
this._controls.push(control);
var positionContainer = this._controlPositions[position];
if (position.indexOf('bottom') !== -1) {
positionContainer.insertBefore(controlElement, positionContainer.firstChild);
} else {
positionContainer.appendChild(controlElement);
}
return this;
};
Map.prototype.removeControl = function removeControl(control) {
if (!control || !control.onRemove) {
return this.fire(new performance.ErrorEvent(new Error('Invalid argument to map.removeControl(). Argument must be a control with onAdd and onRemove methods.')));
}
var ci = this._controls.indexOf(control);
if (ci > -1) {
this._controls.splice(ci, 1);
}
control.onRemove(this);
return this;
};
Map.prototype.hasControl = function hasControl(control) {
return this._controls.indexOf(control) > -1;
};
Map.prototype.resize = function resize(eventData) {
var dimensions = this._containerDimensions();
var width = dimensions[0];
var height = dimensions[1];
this._resizeCanvas(width, height);
this.transform.resize(width, height);
this.painter.resize(width, height);
var fireMoving = !this._moving;
if (fireMoving) {
this.stop();
this.fire(new performance.Event('movestart', eventData)).fire(new performance.Event('move', eventData));
}
this.fire(new performance.Event('resize', eventData));
if (fireMoving) {
this.fire(new performance.Event('moveend', eventData));
}
return this;
};
Map.prototype.getBounds = function getBounds() {
return this.transform.getBounds();
};
Map.prototype.getMaxBounds = function getMaxBounds() {
return this.transform.getMaxBounds();
};
Map.prototype.setMaxBounds = function setMaxBounds(bounds) {
this.transform.setMaxBounds(performance.LngLatBounds.convert(bounds));
return this._update();
};
Map.prototype.setMinZoom = function setMinZoom(minZoom) {
minZoom = minZoom === null || minZoom === undefined ? defaultMinZoom : minZoom;
if (minZoom >= defaultMinZoom && minZoom <= this.transform.maxZoom) {
this.transform.minZoom = minZoom;
this._update();
if (this.getZoom() < minZoom) {
this.setZoom(minZoom);
}
return this;
} else {
throw new Error('minZoom must be between ' + defaultMinZoom + ' and the current maxZoom, inclusive');
}
};
Map.prototype.getMinZoom = function getMinZoom() {
return this.transform.minZoom;
};
Map.prototype.setMaxZoom = function setMaxZoom(maxZoom) {
maxZoom = maxZoom === null || maxZoom === undefined ? defaultMaxZoom : maxZoom;
if (maxZoom >= this.transform.minZoom) {
this.transform.maxZoom = maxZoom;
this._update();
if (this.getZoom() > maxZoom) {
this.setZoom(maxZoom);
}
return this;
} else {
throw new Error('maxZoom must be greater than the current minZoom');
}
};
Map.prototype.getMaxZoom = function getMaxZoom() {
return this.transform.maxZoom;
};
Map.prototype.setMinPitch = function setMinPitch(minPitch) {
minPitch = minPitch === null || minPitch === undefined ? defaultMinPitch : minPitch;
if (minPitch < defaultMinPitch) {
throw new Error('minPitch must be greater than or equal to ' + defaultMinPitch);
}
if (minPitch >= defaultMinPitch && minPitch <= this.transform.maxPitch) {
this.transform.minPitch = minPitch;
this._update();
if (this.getPitch() < minPitch) {
this.setPitch(minPitch);
}
return this;
} else {
throw new Error('minPitch must be between ' + defaultMinPitch + ' and the current maxPitch, inclusive');
}
};
Map.prototype.getMinPitch = function getMinPitch() {
return this.transform.minPitch;
};
Map.prototype.setMaxPitch = function setMaxPitch(maxPitch) {
maxPitch = maxPitch === null || maxPitch === undefined ? defaultMaxPitch : maxPitch;
if (maxPitch > defaultMaxPitch) {
throw new Error('maxPitch must be less than or equal to ' + defaultMaxPitch);
}
if (maxPitch >= this.transform.minPitch) {
this.transform.maxPitch = maxPitch;
this._update();
if (this.getPitch() > maxPitch) {
this.setPitch(maxPitch);
}
return this;
} else {
throw new Error('maxPitch must be greater than the current minPitch');
}
};
Map.prototype.getMaxPitch = function getMaxPitch() {
return this.transform.maxPitch;
};
Map.prototype.getRenderWorldCopies = function getRenderWorldCopies() {
return this.transform.renderWorldCopies;
};
Map.prototype.setRenderWorldCopies = function setRenderWorldCopies(renderWorldCopies) {
this.transform.renderWorldCopies = renderWorldCopies;
return this._update();
};
Map.prototype.project = function project(lnglat) {
return this.transform.locationPoint(performance.LngLat.convert(lnglat));
};
Map.prototype.unproject = function unproject(point) {
return this.transform.pointLocation(performance.Point.convert(point));
};
Map.prototype.isMoving = function isMoving() {
return this._moving || this.handlers.isMoving();
};
Map.prototype.isZooming = function isZooming() {
return this._zooming || this.handlers.isZooming();
};
Map.prototype.isRotating = function isRotating() {
return this._rotating || this.handlers.isRotating();
};
Map.prototype._createDelegatedListener = function _createDelegatedListener(type, layerId, listener) {
var this$1 = this;
var obj;
if (type === 'mouseenter' || type === 'mouseover') {
var mousein = false;
var mousemove = function (e) {
var features = this$1.getLayer(layerId) ? this$1.queryRenderedFeatures(e.point, { layers: [layerId] }) : [];
if (!features.length) {
mousein = false;
} else if (!mousein) {
mousein = true;
listener.call(this$1, new MapMouseEvent(type, this$1, e.originalEvent, { features: features }));
}
};
var mouseout = function () {
mousein = false;
};
return {
layer: layerId,
listener: listener,
delegates: {
mousemove: mousemove,
mouseout: mouseout
}
};
} else if (type === 'mouseleave' || type === 'mouseout') {
var mousein$1 = false;
var mousemove$1 = function (e) {
var features = this$1.getLayer(layerId) ? this$1.queryRenderedFeatures(e.point, { layers: [layerId] }) : [];
if (features.length) {
mousein$1 = true;
} else if (mousein$1) {
mousein$1 = false;
listener.call(this$1, new MapMouseEvent(type, this$1, e.originalEvent));
}
};
var mouseout$1 = function (e) {
if (mousein$1) {
mousein$1 = false;
listener.call(this$1, new MapMouseEvent(type, this$1, e.originalEvent));
}
};
return {
layer: layerId,
listener: listener,
delegates: {
mousemove: mousemove$1,
mouseout: mouseout$1
}
};
} else {
var delegate = function (e) {
var features = this$1.getLayer(layerId) ? this$1.queryRenderedFeatures(e.point, { layers: [layerId] }) : [];
if (features.length) {
e.features = features;
listener.call(this$1, e);
delete e.features;
}
};
return {
layer: layerId,
listener: listener,
delegates: (obj = {}, obj[type] = delegate, obj)
};
}
};
Map.prototype.on = function on(type, layerId, listener) {
if (listener === undefined) {
return Camera.prototype.on.call(this, type, layerId);
}
var delegatedListener = this._createDelegatedListener(type, layerId, listener);
this._delegatedListeners = this._delegatedListeners || {};
this._delegatedListeners[type] = this._delegatedListeners[type] || [];
this._delegatedListeners[type].push(delegatedListener);
for (var event in delegatedListener.delegates) {
this.on(event, delegatedListener.delegates[event]);
}
return this;
};
Map.prototype.once = function once(type, layerId, listener) {
if (listener === undefined) {
return Camera.prototype.once.call(this, type, layerId);
}
var delegatedListener = this._createDelegatedListener(type, layerId, listener);
for (var event in delegatedListener.delegates) {
this.once(event, delegatedListener.delegates[event]);
}
return this;
};
Map.prototype.off = function off(type, layerId, listener) {
var this$1 = this;
if (listener === undefined) {
return Camera.prototype.off.call(this, type, layerId);
}
var removeDelegatedListener = function (delegatedListeners) {
var listeners = delegatedListeners[type];
for (var i = 0; i < listeners.length; i++) {
var delegatedListener = listeners[i];
if (delegatedListener.layer === layerId && delegatedListener.listener === listener) {
for (var event in delegatedListener.delegates) {
this$1.off(event, delegatedListener.delegates[event]);
}
listeners.splice(i, 1);
return this$1;
}
}
};
if (this._delegatedListeners && this._delegatedListeners[type]) {
removeDelegatedListener(this._delegatedListeners);
}
return this;
};
Map.prototype.queryRenderedFeatures = function queryRenderedFeatures(geometry, options) {
if (!this.style) {
return [];
}
if (options === undefined && geometry !== undefined && !(geometry instanceof performance.Point) && !Array.isArray(geometry)) {
options = geometry;
geometry = undefined;
}
options = options || {};
geometry = geometry || [
[
0,
0
],
[
this.transform.width,
this.transform.height
]
];
var queryGeometry;
if (geometry instanceof performance.Point || typeof geometry[0] === 'number') {
queryGeometry = [performance.Point.convert(geometry)];
} else {
var tl = performance.Point.convert(geometry[0]);
var br = performance.Point.convert(geometry[1]);
queryGeometry = [
tl,
new performance.Point(br.x, tl.y),
br,
new performance.Point(tl.x, br.y),
tl
];
}
return this.style.queryRenderedFeatures(queryGeometry, options, this.transform);
};
Map.prototype.querySourceFeatures = function querySourceFeatures(sourceId, parameters) {
return this.style.querySourceFeatures(sourceId, parameters);
};
Map.prototype.setStyle = function setStyle(style, options) {
options = performance.extend({}, { localIdeographFontFamily: this._localIdeographFontFamily }, options);
if (options.diff !== false && options.localIdeographFontFamily === this._localIdeographFontFamily && this.style && style) {
this._diffStyle(style, options);
return this;
} else {
this._localIdeographFontFamily = options.localIdeographFontFamily;
return this._updateStyle(style, options);
}
};
Map.prototype._getUIString = function _getUIString(key) {
var str = this._locale[key];
if (str == null) {
throw new Error('Missing UI string \'' + key + '\'');
}
return str;
};
Map.prototype._updateStyle = function _updateStyle(style, options) {
if (this.style) {
this.style.setEventedParent(null);
this.style._remove();
}
if (!style) {
delete this.style;
return this;
} else {
this.style = new Style(this, options || {});
}
this.style.setEventedParent(this, { style: this.style });
if (typeof style === 'string') {
this.style.loadURL(style);
} else {
this.style.loadJSON(style);
}
return this;
};
Map.prototype._lazyInitEmptyStyle = function _lazyInitEmptyStyle() {
if (!this.style) {
this.style = new Style(this, {});
this.style.setEventedParent(this, { style: this.style });
this.style.loadEmpty();
}
};
Map.prototype._diffStyle = function _diffStyle(style, options) {
var this$1 = this;
if (typeof style === 'string') {
var url = this._requestManager.normalizeStyleURL(style);
var request = this._requestManager.transformRequest(url, performance.ResourceType.Style);
performance.getJSON(request, function (error, json) {
if (error) {
this$1.fire(new performance.ErrorEvent(error));
} else if (json) {
this$1._updateDiff(json, options);
}
});
} else if (typeof style === 'object') {
this._updateDiff(style, options);
}
};
Map.prototype._updateDiff = function _updateDiff(style, options) {
try {
if (this.style.setState(style)) {
this._update(true);
}
} catch (e) {
performance.warnOnce('Unable to perform style diff: ' + (e.message || e.error || e) + '. Rebuilding the style from scratch.');
this._updateStyle(style, options);
}
};
Map.prototype.getStyle = function getStyle() {
if (this.style) {
return this.style.serialize();
}
};
Map.prototype.isStyleLoaded = function isStyleLoaded() {
if (!this.style) {
return performance.warnOnce('There is no style added to the map.');
}
return this.style.loaded();
};
Map.prototype.addSource = function addSource(id, source) {
this._lazyInitEmptyStyle();
this.style.addSource(id, source);
return this._update(true);
};
Map.prototype.isSourceLoaded = function isSourceLoaded(id) {
var source = this.style && this.style.sourceCaches[id];
if (source === undefined) {
this.fire(new performance.ErrorEvent(new Error('There is no source with ID \'' + id + '\'')));
return;
}
return source.loaded();
};
Map.prototype.areTilesLoaded = function areTilesLoaded() {
var sources = this.style && this.style.sourceCaches;
for (var id in sources) {
var source = sources[id];
var tiles = source._tiles;
for (var t in tiles) {
var tile = tiles[t];
if (!(tile.state === 'loaded' || tile.state === 'errored')) {
return false;
}
}
}
return true;
};
Map.prototype.addSourceType = function addSourceType(name, SourceType, callback) {
this._lazyInitEmptyStyle();
return this.style.addSourceType(name, SourceType, callback);
};
Map.prototype.removeSource = function removeSource(id) {
this.style.removeSource(id);
return this._update(true);
};
Map.prototype.getSource = function getSource(id) {
return this.style.getSource(id);
};
Map.prototype.addImage = function addImage(id, image, ref) {
if (ref === void 0)
ref = {};
var pixelRatio = ref.pixelRatio;
if (pixelRatio === void 0)
pixelRatio = 1;
var sdf = ref.sdf;
if (sdf === void 0)
sdf = false;
var stretchX = ref.stretchX;
var stretchY = ref.stretchY;
var content = ref.content;
this._lazyInitEmptyStyle();
var version = 0;
if (image instanceof HTMLImageElement || ImageBitmap && image instanceof ImageBitmap) {
var ref$1 = performance.browser.getImageData(image);
var width = ref$1.width;
var height = ref$1.height;
var data = ref$1.data;
this.style.addImage(id, {
data: new performance.RGBAImage({
width: width,
height: height
}, data),
pixelRatio: pixelRatio,
stretchX: stretchX,
stretchY: stretchY,
content: content,
sdf: sdf,
version: version
});
} else if (image.width === undefined || image.height === undefined) {
return this.fire(new performance.ErrorEvent(new Error('Invalid arguments to map.addImage(). The second argument must be an `HTMLImageElement`, `ImageData`, `ImageBitmap`, ' + 'or object with `width`, `height`, and `data` properties with the same format as `ImageData`')));
} else {
var width$1 = image.width;
var height$1 = image.height;
var data$1 = image.data;
var userImage = image;
this.style.addImage(id, {
data: new performance.RGBAImage({
width: width$1,
height: height$1
}, new Uint8Array(data$1)),
pixelRatio: pixelRatio,
stretchX: stretchX,
stretchY: stretchY,
content: content,
sdf: sdf,
version: version,
userImage: userImage
});
if (userImage.onAdd) {
userImage.onAdd(this, id);
}
}
};
Map.prototype.updateImage = function updateImage(id, image) {
var existingImage = this.style.getImage(id);
if (!existingImage) {
return this.fire(new performance.ErrorEvent(new Error('The map has no image with that id. If you are adding a new image use `map.addImage(...)` instead.')));
}
var imageData = image instanceof HTMLImageElement || ImageBitmap && image instanceof ImageBitmap ? performance.browser.getImageData(image) : image;
var width = imageData.width;
var height = imageData.height;
var data = imageData.data;
if (width === undefined || height === undefined) {
return this.fire(new performance.ErrorEvent(new Error('Invalid arguments to map.updateImage(). The second argument must be an `HTMLImageElement`, `ImageData`, `ImageBitmap`, ' + 'or object with `width`, `height`, and `data` properties with the same format as `ImageData`')));
}
if (width !== existingImage.data.width || height !== existingImage.data.height) {
return this.fire(new performance.ErrorEvent(new Error('The width and height of the updated image must be that same as the previous version of the image')));
}
var copy = !(image instanceof HTMLImageElement || ImageBitmap && image instanceof ImageBitmap);
existingImage.data.replace(data, copy);
this.style.updateImage(id, existingImage);
};
Map.prototype.hasImage = function hasImage(id) {
if (!id) {
this.fire(new performance.ErrorEvent(new Error('Missing required image id')));
return false;
}
return !!this.style.getImage(id);
};
Map.prototype.removeImage = function removeImage(id) {
this.style.removeImage(id);
};
Map.prototype.loadImage = function loadImage(url, callback) {
performance.getImage(this._requestManager.transformRequest(url, performance.ResourceType.Image), callback);
};
Map.prototype.listImages = function listImages() {
return this.style.listImages();
};
Map.prototype.addLayer = function addLayer(layer, beforeId) {
this._lazyInitEmptyStyle();
this.style.addLayer(layer, beforeId);
return this._update(true);
};
Map.prototype.moveLayer = function moveLayer(id, beforeId) {
this.style.moveLayer(id, beforeId);
return this._update(true);
};
Map.prototype.removeLayer = function removeLayer(id) {
this.style.removeLayer(id);
return this._update(true);
};
Map.prototype.getLayer = function getLayer(id) {
return this.style.getLayer(id);
};
Map.prototype.setLayerZoomRange = function setLayerZoomRange(layerId, minzoom, maxzoom) {
this.style.setLayerZoomRange(layerId, minzoom, maxzoom);
return this._update(true);
};
Map.prototype.setFilter = function setFilter(layerId, filter, options) {
if (options === void 0)
options = {};
this.style.setFilter(layerId, filter, options);
return this._update(true);
};
Map.prototype.getFilter = function getFilter(layerId) {
return this.style.getFilter(layerId);
};
Map.prototype.setPaintProperty = function setPaintProperty(layerId, name, value, options) {
if (options === void 0)
options = {};
this.style.setPaintProperty(layerId, name, value, options);
return this._update(true);
};
Map.prototype.getPaintProperty = function getPaintProperty(layerId, name) {
return this.style.getPaintProperty(layerId, name);
};
Map.prototype.setLayoutProperty = function setLayoutProperty(layerId, name, value, options) {
if (options === void 0)
options = {};
this.style.setLayoutProperty(layerId, name, value, options);
return this._update(true);
};
Map.prototype.getLayoutProperty = function getLayoutProperty(layerId, name) {
return this.style.getLayoutProperty(layerId, name);
};
Map.prototype.setLight = function setLight(light, options) {
if (options === void 0)
options = {};
this._lazyInitEmptyStyle();
this.style.setLight(light, options);
return this._update(true);
};
Map.prototype.getLight = function getLight() {
return this.style.getLight();
};
Map.prototype.setFeatureState = function setFeatureState(feature, state) {
this.style.setFeatureState(feature, state);
return this._update();
};
Map.prototype.removeFeatureState = function removeFeatureState(target, key) {
this.style.removeFeatureState(target, key);
return this._update();
};
Map.prototype.getFeatureState = function getFeatureState(feature) {
return this.style.getFeatureState(feature);
};
Map.prototype.getContainer = function getContainer() {
return this._container;
};
Map.prototype.getCanvasContainer = function getCanvasContainer() {
return this._canvasContainer;
};
Map.prototype.getCanvas = function getCanvas() {
return this._canvas;
};
Map.prototype._containerDimensions = function _containerDimensions() {
var width = 0;
var height = 0;
if (this._container) {
width = this._container.clientWidth || 400;
height = this._container.clientHeight || 300;
}
return [
width,
height
];
};
Map.prototype._detectMissingCSS = function _detectMissingCSS() {
var computedColor = performance.window.getComputedStyle(this._missingCSSCanary).getPropertyValue('background-color');
if (computedColor !== 'rgb(250, 128, 114)') {
performance.warnOnce('This page appears to be missing CSS declarations for ' + 'Mapbox GL JS, which may cause the map to display incorrectly. ' + 'Please ensure your page includes mapbox-gl.css, as described ' + 'in https://www.mapbox.com/mapbox-gl-js/api/.');
}
};
Map.prototype._setupContainer = function _setupContainer() {
var container = this._container;
container.classList.add('mapboxgl-map');
var missingCSSCanary = this._missingCSSCanary = DOM.create('div', 'mapboxgl-canary', container);
missingCSSCanary.style.visibility = 'hidden';
this._detectMissingCSS();
var canvasContainer = this._canvasContainer = DOM.create('div', 'mapboxgl-canvas-container', container);
if (this._interactive) {
canvasContainer.classList.add('mapboxgl-interactive');
}
this._canvas = DOM.create('canvas', 'mapboxgl-canvas', canvasContainer);
this._canvas.addEventListener('webglcontextlost', this._contextLost, false);
this._canvas.addEventListener('webglcontextrestored', this._contextRestored, false);
this._canvas.setAttribute('tabindex', '0');
this._canvas.setAttribute('aria-label', 'Map');
this._canvas.setAttribute('role', 'region');
var dimensions = this._containerDimensions();
this._resizeCanvas(dimensions[0], dimensions[1]);
var controlContainer = this._controlContainer = DOM.create('div', 'mapboxgl-control-container', container);
var positions = this._controlPositions = {};
[
'top-left',
'top-right',
'bottom-left',
'bottom-right'
].forEach(function (positionName) {
positions[positionName] = DOM.create('div', 'mapboxgl-ctrl-' + positionName, controlContainer);
});
this._container.addEventListener('scroll', this._onMapScroll, false);
};
Map.prototype._resizeCanvas = function _resizeCanvas(width, height) {
var pixelRatio = performance.browser.devicePixelRatio || 1;
this._canvas.width = pixelRatio * width;
this._canvas.height = pixelRatio * height;
this._canvas.style.width = width + 'px';
this._canvas.style.height = height + 'px';
};
Map.prototype._setupPainter = function _setupPainter() {
var attributes = performance.extend({}, mapboxGlSupported.webGLContextAttributes, {
failIfMajorPerformanceCaveat: this._failIfMajorPerformanceCaveat,
preserveDrawingBuffer: this._preserveDrawingBuffer,
antialias: this._antialias || false
});
var gl = this._canvas.getContext('webgl', attributes) || this._canvas.getContext('experimental-webgl', attributes);
if (!gl) {
this.fire(new performance.ErrorEvent(new Error('Failed to initialize WebGL')));
return;
}
this.painter = new Painter(gl, this.transform);
performance.webpSupported.testSupport(gl);
};
Map.prototype._contextLost = function _contextLost(event) {
event.preventDefault();
if (this._frame) {
this._frame.cancel();
this._frame = null;
}
this.fire(new performance.Event('webglcontextlost', { originalEvent: event }));
};
Map.prototype._contextRestored = function _contextRestored(event) {
this._setupPainter();
this.resize();
this._update();
this.fire(new performance.Event('webglcontextrestored', { originalEvent: event }));
};
Map.prototype._onMapScroll = function _onMapScroll(event) {
if (event.target !== this._container) {
return;
}
this._container.scrollTop = 0;
this._container.scrollLeft = 0;
return false;
};
Map.prototype.loaded = function loaded() {
return !this._styleDirty && !this._sourcesDirty && !!this.style && this.style.loaded();
};
Map.prototype._update = function _update(updateStyle) {
if (!this.style) {
return this;
}
this._styleDirty = this._styleDirty || updateStyle;
this._sourcesDirty = true;
this.triggerRepaint();
return this;
};
Map.prototype._requestRenderFrame = function _requestRenderFrame(callback) {
this._update();
return this._renderTaskQueue.add(callback);
};
Map.prototype._cancelRenderFrame = function _cancelRenderFrame(id) {
this._renderTaskQueue.remove(id);
};
Map.prototype._render = function _render(paintStartTimeStamp) {
var this$1 = this;
var gpuTimer, frameStartTime = 0;
var extTimerQuery = this.painter.context.extTimerQuery;
if (this.listens('gpu-timing-frame')) {
gpuTimer = extTimerQuery.createQueryEXT();
extTimerQuery.beginQueryEXT(extTimerQuery.TIME_ELAPSED_EXT, gpuTimer);
frameStartTime = performance.browser.now();
}
this.painter.context.setDirty();
this.painter.setBaseState();
this._renderTaskQueue.run(paintStartTimeStamp);
if (this._removed) {
return;
}
var crossFading = false;
if (this.style && this._styleDirty) {
this._styleDirty = false;
var zoom = this.transform.zoom;
var now = performance.browser.now();
this.style.zoomHistory.update(zoom, now);
var parameters = new performance.EvaluationParameters(zoom, {
now: now,
fadeDuration: this._fadeDuration,
zoomHistory: this.style.zoomHistory,
transition: this.style.getTransition()
});
var factor = parameters.crossFadingFactor();
if (factor !== 1 || factor !== this._crossFadingFactor) {
crossFading = true;
this._crossFadingFactor = factor;
}
this.style.update(parameters);
}
if (this.style && this._sourcesDirty) {
this._sourcesDirty = false;
this.style._updateSources(this.transform);
}
this._placementDirty = this.style && this.style._updatePlacement(this.painter.transform, this.showCollisionBoxes, this._fadeDuration, this._crossSourceCollisions);
this.painter.render(this.style, {
showTileBoundaries: this.showTileBoundaries,
showOverdrawInspector: this._showOverdrawInspector,
rotating: this.isRotating(),
zooming: this.isZooming(),
moving: this.isMoving(),
fadeDuration: this._fadeDuration,
showPadding: this.showPadding,
gpuTiming: !!this.listens('gpu-timing-layer')
});
this.fire(new performance.Event('render'));
if (this.loaded() && !this._loaded) {
this._loaded = true;
this.fire(new performance.Event('load'));
}
if (this.style && (this.style.hasTransitions() || crossFading)) {
this._styleDirty = true;
}
if (this.style && !this._placementDirty) {
this.style._releaseSymbolFadeTiles();
}
if (this.listens('gpu-timing-frame')) {
var renderCPUTime = performance.browser.now() - frameStartTime;
extTimerQuery.endQueryEXT(extTimerQuery.TIME_ELAPSED_EXT, gpuTimer);
setTimeout(function () {
var renderGPUTime = extTimerQuery.getQueryObjectEXT(gpuTimer, extTimerQuery.QUERY_RESULT_EXT) / (1000 * 1000);
extTimerQuery.deleteQueryEXT(gpuTimer);
this$1.fire(new performance.Event('gpu-timing-frame', {
cpuTime: renderCPUTime,
gpuTime: renderGPUTime
}));
}, 50);
}
if (this.listens('gpu-timing-layer')) {
var frameLayerQueries = this.painter.collectGpuTimers();
setTimeout(function () {
var renderedLayerTimes = this$1.painter.queryGpuTimers(frameLayerQueries);
this$1.fire(new performance.Event('gpu-timing-layer', { layerTimes: renderedLayerTimes }));
}, 50);
}
var somethingDirty = this._sourcesDirty || this._styleDirty || this._placementDirty;
if (somethingDirty || this._repaint) {
this.triggerRepaint();
} else if (!this.isMoving() && this.loaded()) {
this.fire(new performance.Event('idle'));
}
if (this._loaded && !this._fullyLoaded && !somethingDirty) {
this._fullyLoaded = true;
}
return this;
};
Map.prototype.remove = function remove() {
if (this._hash) {
this._hash.remove();
}
for (var i = 0, list = this._controls; i < list.length; i += 1) {
var control = list[i];
control.onRemove(this);
}
this._controls = [];
if (this._frame) {
this._frame.cancel();
this._frame = null;
}
this._renderTaskQueue.clear();
this.painter.destroy();
this.handlers.destroy();
delete this.handlers;
this.setStyle(null);
if (typeof performance.window !== 'undefined') {
performance.window.removeEventListener('resize', this._onWindowResize, false);
performance.window.removeEventListener('orientationchange', this._onWindowResize, false);
performance.window.removeEventListener('online', this._onWindowOnline, false);
}
var extension = this.painter.context.gl.getExtension('WEBGL_lose_context');
if (extension && extension.loseContext) {
extension.loseContext();
}
removeNode(this._canvasContainer);
removeNode(this._controlContainer);
removeNode(this._missingCSSCanary);
this._container.classList.remove('mapboxgl-map');
this._removed = true;
this.fire(new performance.Event('remove'));
};
Map.prototype.triggerRepaint = function triggerRepaint() {
var this$1 = this;
if (this.style && !this._frame) {
this._frame = performance.browser.frame(function (paintStartTimeStamp) {
this$1._frame = null;
this$1._render(paintStartTimeStamp);
});
}
};
Map.prototype._onWindowOnline = function _onWindowOnline() {
this._update();
};
Map.prototype._onWindowResize = function _onWindowResize(event) {
if (this._trackResize) {
this.resize({ originalEvent: event })._update();
}
};
prototypeAccessors.showTileBoundaries.get = function () {
return !!this._showTileBoundaries;
};
prototypeAccessors.showTileBoundaries.set = function (value) {
if (this._showTileBoundaries === value) {
return;
}
this._showTileBoundaries = value;
this._update();
};
prototypeAccessors.showPadding.get = function () {
return !!this._showPadding;
};
prototypeAccessors.showPadding.set = function (value) {
if (this._showPadding === value) {
return;
}
this._showPadding = value;
this._update();
};
prototypeAccessors.showCollisionBoxes.get = function () {
return !!this._showCollisionBoxes;
};
prototypeAccessors.showCollisionBoxes.set = function (value) {
if (this._showCollisionBoxes === value) {
return;
}
this._showCollisionBoxes = value;
if (value) {
this.style._generateCollisionBoxes();
} else {
this._update();
}
};
prototypeAccessors.showOverdrawInspector.get = function () {
return !!this._showOverdrawInspector;
};
prototypeAccessors.showOverdrawInspector.set = function (value) {
if (this._showOverdrawInspector === value) {
return;
}
this._showOverdrawInspector = value;
this._update();
};
prototypeAccessors.repaint.get = function () {
return !!this._repaint;
};
prototypeAccessors.repaint.set = function (value) {
if (this._repaint !== value) {
this._repaint = value;
this.triggerRepaint();
}
};
prototypeAccessors.vertices.get = function () {
return !!this._vertices;
};
prototypeAccessors.vertices.set = function (value) {
this._vertices = value;
this._update();
};
Map.prototype._setCacheLimits = function _setCacheLimits(limit, checkThreshold) {
performance.setCacheLimits(limit, checkThreshold);
};
prototypeAccessors.version.get = function () {
return performance.version;
};
Object.defineProperties(Map.prototype, prototypeAccessors);
return Map;
}(Camera);
function removeNode(node) {
if (node.parentNode) {
node.parentNode.removeChild(node);
}
}
var defaultOptions$2 = {
showCompass: true,
showZoom: true,
visualizePitch: false
};
var NavigationControl = function NavigationControl(options) {
var this$1 = this;
this.options = performance.extend({}, defaultOptions$2, options);
this._container = DOM.create('div', 'mapboxgl-ctrl mapboxgl-ctrl-group');
this._container.addEventListener('contextmenu', function (e) {
return e.preventDefault();
});
if (this.options.showZoom) {
performance.bindAll([
'_setButtonTitle',
'_updateZoomButtons'
], this);
this._zoomInButton = this._createButton('mapboxgl-ctrl-zoom-in', function (e) {
return this$1._map.zoomIn({}, { originalEvent: e });
});
DOM.create('span', 'mapboxgl-ctrl-icon', this._zoomInButton).setAttribute('aria-hidden', true);
this._zoomOutButton = this._createButton('mapboxgl-ctrl-zoom-out', function (e) {
return this$1._map.zoomOut({}, { originalEvent: e });
});
DOM.create('span', 'mapboxgl-ctrl-icon', this._zoomOutButton).setAttribute('aria-hidden', true);
}
if (this.options.showCompass) {
performance.bindAll(['_rotateCompassArrow'], this);
this._compass = this._createButton('mapboxgl-ctrl-compass', function (e) {
if (this$1.options.visualizePitch) {
this$1._map.resetNorthPitch({}, { originalEvent: e });
} else {
this$1._map.resetNorth({}, { originalEvent: e });
}
});
this._compassIcon = DOM.create('span', 'mapboxgl-ctrl-icon', this._compass);
this._compassIcon.setAttribute('aria-hidden', true);
}
};
NavigationControl.prototype._updateZoomButtons = function _updateZoomButtons() {
var zoom = this._map.getZoom();
var isMax = zoom === this._map.getMaxZoom();
var isMin = zoom === this._map.getMinZoom();
this._zoomInButton.disabled = isMax;
this._zoomOutButton.disabled = isMin;
this._zoomInButton.setAttribute('aria-disabled', isMax.toString());
this._zoomOutButton.setAttribute('aria-disabled', isMin.toString());
};
NavigationControl.prototype._rotateCompassArrow = function _rotateCompassArrow() {
var rotate = this.options.visualizePitch ? 'scale(' + 1 / Math.pow(Math.cos(this._map.transform.pitch * (Math.PI / 180)), 0.5) + ') rotateX(' + this._map.transform.pitch + 'deg) rotateZ(' + this._map.transform.angle * (180 / Math.PI) + 'deg)' : 'rotate(' + this._map.transform.angle * (180 / Math.PI) + 'deg)';
this._compassIcon.style.transform = rotate;
};
NavigationControl.prototype.onAdd = function onAdd(map) {
this._map = map;
if (this.options.showZoom) {
this._setButtonTitle(this._zoomInButton, 'ZoomIn');
this._setButtonTitle(this._zoomOutButton, 'ZoomOut');
this._map.on('zoom', this._updateZoomButtons);
this._updateZoomButtons();
}
if (this.options.showCompass) {
this._setButtonTitle(this._compass, 'ResetBearing');
if (this.options.visualizePitch) {
this._map.on('pitch', this._rotateCompassArrow);
}
this._map.on('rotate', this._rotateCompassArrow);
this._rotateCompassArrow();
this._handler = new MouseRotateWrapper(this._map, this._compass, this.options.visualizePitch);
}
return this._container;
};
NavigationControl.prototype.onRemove = function onRemove() {
DOM.remove(this._container);
if (this.options.showZoom) {
this._map.off('zoom', this._updateZoomButtons);
}
if (this.options.showCompass) {
if (this.options.visualizePitch) {
this._map.off('pitch', this._rotateCompassArrow);
}
this._map.off('rotate', this._rotateCompassArrow);
this._handler.off();
delete this._handler;
}
delete this._map;
};
NavigationControl.prototype._createButton = function _createButton(className, fn) {
var a = DOM.create('button', className, this._container);
a.type = 'button';
a.addEventListener('click', fn);
return a;
};
NavigationControl.prototype._setButtonTitle = function _setButtonTitle(button, title) {
var str = this._map._getUIString('NavigationControl.' + title);
button.title = str;
button.setAttribute('aria-label', str);
};
var MouseRotateWrapper = function MouseRotateWrapper(map, element, pitch) {
if (pitch === void 0)
pitch = false;
this._clickTolerance = 10;
this.element = element;
this.mouseRotate = new MouseRotateHandler({ clickTolerance: map.dragRotate._mouseRotate._clickTolerance });
this.map = map;
if (pitch) {
this.mousePitch = new MousePitchHandler({ clickTolerance: map.dragRotate._mousePitch._clickTolerance });
}
performance.bindAll([
'mousedown',
'mousemove',
'mouseup',
'touchstart',
'touchmove',
'touchend',
'reset'
], this);
DOM.addEventListener(element, 'mousedown', this.mousedown);
DOM.addEventListener(element, 'touchstart', this.touchstart, { passive: false });
DOM.addEventListener(element, 'touchmove', this.touchmove);
DOM.addEventListener(element, 'touchend', this.touchend);
DOM.addEventListener(element, 'touchcancel', this.reset);
};
MouseRotateWrapper.prototype.down = function down(e, point) {
this.mouseRotate.mousedown(e, point);
if (this.mousePitch) {
this.mousePitch.mousedown(e, point);
}
DOM.disableDrag();
};
MouseRotateWrapper.prototype.move = function move(e, point) {
var map = this.map;
var r = this.mouseRotate.mousemoveWindow(e, point);
if (r && r.bearingDelta) {
map.setBearing(map.getBearing() + r.bearingDelta);
}
if (this.mousePitch) {
var p = this.mousePitch.mousemoveWindow(e, point);
if (p && p.pitchDelta) {
map.setPitch(map.getPitch() + p.pitchDelta);
}
}
};
MouseRotateWrapper.prototype.off = function off() {
var element = this.element;
DOM.removeEventListener(element, 'mousedown', this.mousedown);
DOM.removeEventListener(element, 'touchstart', this.touchstart, { passive: false });
DOM.removeEventListener(element, 'touchmove', this.touchmove);
DOM.removeEventListener(element, 'touchend', this.touchend);
DOM.removeEventListener(element, 'touchcancel', this.reset);
this.offTemp();
};
MouseRotateWrapper.prototype.offTemp = function offTemp() {
DOM.enableDrag();
DOM.removeEventListener(performance.window, 'mousemove', this.mousemove);
DOM.removeEventListener(performance.window, 'mouseup', this.mouseup);
};
MouseRotateWrapper.prototype.mousedown = function mousedown(e) {
this.down(performance.extend({}, e, {
ctrlKey: true,
preventDefault: function () {
return e.preventDefault();
}
}), DOM.mousePos(this.element, e));
DOM.addEventListener(performance.window, 'mousemove', this.mousemove);
DOM.addEventListener(performance.window, 'mouseup', this.mouseup);
};
MouseRotateWrapper.prototype.mousemove = function mousemove(e) {
this.move(e, DOM.mousePos(this.element, e));
};
MouseRotateWrapper.prototype.mouseup = function mouseup(e) {
this.mouseRotate.mouseupWindow(e);
if (this.mousePitch) {
this.mousePitch.mouseupWindow(e);
}
this.offTemp();
};
MouseRotateWrapper.prototype.touchstart = function touchstart(e) {
if (e.targetTouches.length !== 1) {
this.reset();
} else {
this._startPos = this._lastPos = DOM.touchPos(this.element, e.targetTouches)[0];
this.down({
type: 'mousedown',
button: 0,
ctrlKey: true,
preventDefault: function () {
return e.preventDefault();
}
}, this._startPos);
}
};
MouseRotateWrapper.prototype.touchmove = function touchmove(e) {
if (e.targetTouches.length !== 1) {
this.reset();
} else {
this._lastPos = DOM.touchPos(this.element, e.targetTouches)[0];
this.move({
preventDefault: function () {
return e.preventDefault();
}
}, this._lastPos);
}
};
MouseRotateWrapper.prototype.touchend = function touchend(e) {
if (e.targetTouches.length === 0 && this._startPos && this._lastPos && this._startPos.dist(this._lastPos) < this._clickTolerance) {
this.element.click();
}
this.reset();
};
MouseRotateWrapper.prototype.reset = function reset() {
this.mouseRotate.reset();
if (this.mousePitch) {
this.mousePitch.reset();
}
delete this._startPos;
delete this._lastPos;
this.offTemp();
};
function smartWrap (lngLat, priorPos, transform) {
lngLat = new performance.LngLat(lngLat.lng, lngLat.lat);
if (priorPos) {
var left = new performance.LngLat(lngLat.lng - 360, lngLat.lat);
var right = new performance.LngLat(lngLat.lng + 360, lngLat.lat);
var delta = transform.locationPoint(lngLat).distSqr(priorPos);
if (transform.locationPoint(left).distSqr(priorPos) < delta) {
lngLat = left;
} else if (transform.locationPoint(right).distSqr(priorPos) < delta) {
lngLat = right;
}
}
while (Math.abs(lngLat.lng - transform.center.lng) > 180) {
var pos = transform.locationPoint(lngLat);
if (pos.x >= 0 && pos.y >= 0 && pos.x <= transform.width && pos.y <= transform.height) {
break;
}
if (lngLat.lng > transform.center.lng) {
lngLat.lng -= 360;
} else {
lngLat.lng += 360;
}
}
return lngLat;
}
var anchorTranslate = {
'center': 'translate(-50%,-50%)',
'top': 'translate(-50%,0)',
'top-left': 'translate(0,0)',
'top-right': 'translate(-100%,0)',
'bottom': 'translate(-50%,-100%)',
'bottom-left': 'translate(0,-100%)',
'bottom-right': 'translate(-100%,-100%)',
'left': 'translate(0,-50%)',
'right': 'translate(-100%,-50%)'
};
function applyAnchorClass(element, anchor, prefix) {
var classList = element.classList;
for (var key in anchorTranslate) {
classList.remove('mapboxgl-' + prefix + '-anchor-' + key);
}
classList.add('mapboxgl-' + prefix + '-anchor-' + anchor);
}
var Marker = function (Evented) {
function Marker(options, legacyOptions) {
Evented.call(this);
if (options instanceof performance.window.HTMLElement || legacyOptions) {
options = performance.extend({ element: options }, legacyOptions);
}
performance.bindAll([
'_update',
'_onMove',
'_onUp',
'_addDragHandler',
'_onMapClick',
'_onKeyPress'
], this);
this._anchor = options && options.anchor || 'center';
this._color = options && options.color || '#3FB1CE';
this._scale = options && options.scale || 1;
this._draggable = options && options.draggable || false;
this._clickTolerance = options && options.clickTolerance || 0;
this._isDragging = false;
this._state = 'inactive';
this._rotation = options && options.rotation || 0;
this._rotationAlignment = options && options.rotationAlignment || 'auto';
this._pitchAlignment = options && options.pitchAlignment && options.pitchAlignment !== 'auto' ? options.pitchAlignment : this._rotationAlignment;
if (!options || !options.element) {
this._defaultMarker = true;
this._element = DOM.create('div');
this._element.setAttribute('aria-label', 'Map marker');
var svg = DOM.createNS('http://www.w3.org/2000/svg', 'svg');
var defaultHeight = 41;
var defaultWidth = 27;
svg.setAttributeNS(null, 'display', 'block');
svg.setAttributeNS(null, 'height', defaultHeight + 'px');
svg.setAttributeNS(null, 'width', defaultWidth + 'px');
svg.setAttributeNS(null, 'viewBox', '0 0 ' + defaultWidth + ' ' + defaultHeight);
var markerLarge = DOM.createNS('http://www.w3.org/2000/svg', 'g');
markerLarge.setAttributeNS(null, 'stroke', 'none');
markerLarge.setAttributeNS(null, 'stroke-width', '1');
markerLarge.setAttributeNS(null, 'fill', 'none');
markerLarge.setAttributeNS(null, 'fill-rule', 'evenodd');
var page1 = DOM.createNS('http://www.w3.org/2000/svg', 'g');
page1.setAttributeNS(null, 'fill-rule', 'nonzero');
var shadow = DOM.createNS('http://www.w3.org/2000/svg', 'g');
shadow.setAttributeNS(null, 'transform', 'translate(3.0, 29.0)');
shadow.setAttributeNS(null, 'fill', '#000000');
var ellipses = [
{
'rx': '10.5',
'ry': '5.25002273'
},
{
'rx': '10.5',
'ry': '5.25002273'
},
{
'rx': '9.5',
'ry': '4.77275007'
},
{
'rx': '8.5',
'ry': '4.29549936'
},
{
'rx': '7.5',
'ry': '3.81822308'
},
{
'rx': '6.5',
'ry': '3.34094679'
},
{
'rx': '5.5',
'ry': '2.86367051'
},
{
'rx': '4.5',
'ry': '2.38636864'
}
];
for (var i = 0, list = ellipses; i < list.length; i += 1) {
var data = list[i];
var ellipse = DOM.createNS('http://www.w3.org/2000/svg', 'ellipse');
ellipse.setAttributeNS(null, 'opacity', '0.04');
ellipse.setAttributeNS(null, 'cx', '10.5');
ellipse.setAttributeNS(null, 'cy', '5.80029008');
ellipse.setAttributeNS(null, 'rx', data['rx']);
ellipse.setAttributeNS(null, 'ry', data['ry']);
shadow.appendChild(ellipse);
}
var background = DOM.createNS('http://www.w3.org/2000/svg', 'g');
background.setAttributeNS(null, 'fill', this._color);
var bgPath = DOM.createNS('http://www.w3.org/2000/svg', 'path');
bgPath.setAttributeNS(null, 'd', 'M27,13.5 C27,19.074644 20.250001,27.000002 14.75,34.500002 C14.016665,35.500004 12.983335,35.500004 12.25,34.500002 C6.7499993,27.000002 0,19.222562 0,13.5 C0,6.0441559 6.0441559,0 13.5,0 C20.955844,0 27,6.0441559 27,13.5 Z');
background.appendChild(bgPath);
var border = DOM.createNS('http://www.w3.org/2000/svg', 'g');
border.setAttributeNS(null, 'opacity', '0.25');
border.setAttributeNS(null, 'fill', '#000000');
var borderPath = DOM.createNS('http://www.w3.org/2000/svg', 'path');
borderPath.setAttributeNS(null, 'd', 'M13.5,0 C6.0441559,0 0,6.0441559 0,13.5 C0,19.222562 6.7499993,27 12.25,34.5 C13,35.522727 14.016664,35.500004 14.75,34.5 C20.250001,27 27,19.074644 27,13.5 C27,6.0441559 20.955844,0 13.5,0 Z M13.5,1 C20.415404,1 26,6.584596 26,13.5 C26,15.898657 24.495584,19.181431 22.220703,22.738281 C19.945823,26.295132 16.705119,30.142167 13.943359,33.908203 C13.743445,34.180814 13.612715,34.322738 13.5,34.441406 C13.387285,34.322738 13.256555,34.180814 13.056641,33.908203 C10.284481,30.127985 7.4148684,26.314159 5.015625,22.773438 C2.6163816,19.232715 1,15.953538 1,13.5 C1,6.584596 6.584596,1 13.5,1 Z');
border.appendChild(borderPath);
var maki = DOM.createNS('http://www.w3.org/2000/svg', 'g');
maki.setAttributeNS(null, 'transform', 'translate(6.0, 7.0)');
maki.setAttributeNS(null, 'fill', '#FFFFFF');
var circleContainer = DOM.createNS('http://www.w3.org/2000/svg', 'g');
circleContainer.setAttributeNS(null, 'transform', 'translate(8.0, 8.0)');
var circle1 = DOM.createNS('http://www.w3.org/2000/svg', 'circle');
circle1.setAttributeNS(null, 'fill', '#000000');
circle1.setAttributeNS(null, 'opacity', '0.25');
circle1.setAttributeNS(null, 'cx', '5.5');
circle1.setAttributeNS(null, 'cy', '5.5');
circle1.setAttributeNS(null, 'r', '5.4999962');
var circle2 = DOM.createNS('http://www.w3.org/2000/svg', 'circle');
circle2.setAttributeNS(null, 'fill', '#FFFFFF');
circle2.setAttributeNS(null, 'cx', '5.5');
circle2.setAttributeNS(null, 'cy', '5.5');
circle2.setAttributeNS(null, 'r', '5.4999962');
circleContainer.appendChild(circle1);
circleContainer.appendChild(circle2);
page1.appendChild(shadow);
page1.appendChild(background);
page1.appendChild(border);
page1.appendChild(maki);
page1.appendChild(circleContainer);
svg.appendChild(page1);
svg.setAttributeNS(null, 'height', defaultHeight * this._scale + 'px');
svg.setAttributeNS(null, 'width', defaultWidth * this._scale + 'px');
this._element.appendChild(svg);
this._offset = performance.Point.convert(options && options.offset || [
0,
-14
]);
} else {
this._element = options.element;
this._offset = performance.Point.convert(options && options.offset || [
0,
0
]);
}
this._element.classList.add('mapboxgl-marker');
this._element.addEventListener('dragstart', function (e) {
e.preventDefault();
});
this._element.addEventListener('mousedown', function (e) {
e.preventDefault();
});
applyAnchorClass(this._element, this._anchor, 'marker');
this._popup = null;
}
if (Evented)
Marker.__proto__ = Evented;
Marker.prototype = Object.create(Evented && Evented.prototype);
Marker.prototype.constructor = Marker;
Marker.prototype.addTo = function addTo(map) {
this.remove();
this._map = map;
map.getCanvasContainer().appendChild(this._element);
map.on('move', this._update);
map.on('moveend', this._update);
this.setDraggable(this._draggable);
this._update();
this._map.on('click', this._onMapClick);
return this;
};
Marker.prototype.remove = function remove() {
if (this._map) {
this._map.off('click', this._onMapClick);
this._map.off('move', this._update);
this._map.off('moveend', this._update);
this._map.off('mousedown', this._addDragHandler);
this._map.off('touchstart', this._addDragHandler);
this._map.off('mouseup', this._onUp);
this._map.off('touchend', this._onUp);
this._map.off('mousemove', this._onMove);
this._map.off('touchmove', this._onMove);
delete this._map;
}
DOM.remove(this._element);
if (this._popup) {
this._popup.remove();
}
return this;
};
Marker.prototype.getLngLat = function getLngLat() {
return this._lngLat;
};
Marker.prototype.setLngLat = function setLngLat(lnglat) {
this._lngLat = performance.LngLat.convert(lnglat);
this._pos = null;
if (this._popup) {
this._popup.setLngLat(this._lngLat);
}
this._update();
return this;
};
Marker.prototype.getElement = function getElement() {
return this._element;
};
Marker.prototype.setPopup = function setPopup(popup) {
if (this._popup) {
this._popup.remove();
this._popup = null;
this._element.removeEventListener('keypress', this._onKeyPress);
if (!this._originalTabIndex) {
this._element.removeAttribute('tabindex');
}
}
if (popup) {
if (!('offset' in popup.options)) {
var markerHeight = 41 - 5.8 / 2;
var markerRadius = 13.5;
var linearOffset = Math.sqrt(Math.pow(markerRadius, 2) / 2);
popup.options.offset = this._defaultMarker ? {
'top': [
0,
0
],
'top-left': [
0,
0
],
'top-right': [
0,
0
],
'bottom': [
0,
-markerHeight
],
'bottom-left': [
linearOffset,
(markerHeight - markerRadius + linearOffset) * -1
],
'bottom-right': [
-linearOffset,
(markerHeight - markerRadius + linearOffset) * -1
],
'left': [
markerRadius,
(markerHeight - markerRadius) * -1
],
'right': [
-markerRadius,
(markerHeight - markerRadius) * -1
]
} : this._offset;
}
this._popup = popup;
if (this._lngLat) {
this._popup.setLngLat(this._lngLat);
}
this._originalTabIndex = this._element.getAttribute('tabindex');
if (!this._originalTabIndex) {
this._element.setAttribute('tabindex', '0');
}
this._element.addEventListener('keypress', this._onKeyPress);
}
return this;
};
Marker.prototype._onKeyPress = function _onKeyPress(e) {
var code = e.code;
var legacyCode = e.charCode || e.keyCode;
if (code === 'Space' || code === 'Enter' || legacyCode === 32 || legacyCode === 13) {
this.togglePopup();
}
};
Marker.prototype._onMapClick = function _onMapClick(e) {
var targetElement = e.originalEvent.target;
var element = this._element;
if (this._popup && (targetElement === element || element.contains(targetElement))) {
this.togglePopup();
}
};
Marker.prototype.getPopup = function getPopup() {
return this._popup;
};
Marker.prototype.togglePopup = function togglePopup() {
var popup = this._popup;
if (!popup) {
return this;
} else if (popup.isOpen()) {
popup.remove();
} else {
popup.addTo(this._map);
}
return this;
};
Marker.prototype._update = function _update(e) {
if (!this._map) {
return;
}
if (this._map.transform.renderWorldCopies) {
this._lngLat = smartWrap(this._lngLat, this._pos, this._map.transform);
}
this._pos = this._map.project(this._lngLat)._add(this._offset);
var rotation = '';
if (this._rotationAlignment === 'viewport' || this._rotationAlignment === 'auto') {
rotation = 'rotateZ(' + this._rotation + 'deg)';
} else if (this._rotationAlignment === 'map') {
rotation = 'rotateZ(' + (this._rotation - this._map.getBearing()) + 'deg)';
}
var pitch = '';
if (this._pitchAlignment === 'viewport' || this._pitchAlignment === 'auto') {
pitch = 'rotateX(0deg)';
} else if (this._pitchAlignment === 'map') {
pitch = 'rotateX(' + this._map.getPitch() + 'deg)';
}
if (!e || e.type === 'moveend') {
this._pos = this._pos.round();
}
DOM.setTransform(this._element, anchorTranslate[this._anchor] + ' translate(' + this._pos.x + 'px, ' + this._pos.y + 'px) ' + pitch + ' ' + rotation);
};
Marker.prototype.getOffset = function getOffset() {
return this._offset;
};
Marker.prototype.setOffset = function setOffset(offset) {
this._offset = performance.Point.convert(offset);
this._update();
return this;
};
Marker.prototype._onMove = function _onMove(e) {
if (!this._isDragging) {
var clickTolerance = this._clickTolerance || this._map._clickTolerance;
this._isDragging = e.point.dist(this._pointerdownPos) >= clickTolerance;
}
if (!this._isDragging) {
return;
}
this._pos = e.point.sub(this._positionDelta);
this._lngLat = this._map.unproject(this._pos);
this.setLngLat(this._lngLat);
this._element.style.pointerEvents = 'none';
if (this._state === 'pending') {
this._state = 'active';
this.fire(new performance.Event('dragstart'));
}
this.fire(new performance.Event('drag'));
};
Marker.prototype._onUp = function _onUp() {
this._element.style.pointerEvents = 'auto';
this._positionDelta = null;
this._pointerdownPos = null;
this._isDragging = false;
this._map.off('mousemove', this._onMove);
this._map.off('touchmove', this._onMove);
if (this._state === 'active') {
this.fire(new performance.Event('dragend'));
}
this._state = 'inactive';
};
Marker.prototype._addDragHandler = function _addDragHandler(e) {
if (this._element.contains(e.originalEvent.target)) {
e.preventDefault();
this._positionDelta = e.point.sub(this._pos).add(this._offset);
this._pointerdownPos = e.point;
this._state = 'pending';
this._map.on('mousemove', this._onMove);
this._map.on('touchmove', this._onMove);
this._map.once('mouseup', this._onUp);
this._map.once('touchend', this._onUp);
}
};
Marker.prototype.setDraggable = function setDraggable(shouldBeDraggable) {
this._draggable = !!shouldBeDraggable;
if (this._map) {
if (shouldBeDraggable) {
this._map.on('mousedown', this._addDragHandler);
this._map.on('touchstart', this._addDragHandler);
} else {
this._map.off('mousedown', this._addDragHandler);
this._map.off('touchstart', this._addDragHandler);
}
}
return this;
};
Marker.prototype.isDraggable = function isDraggable() {
return this._draggable;
};
Marker.prototype.setRotation = function setRotation(rotation) {
this._rotation = rotation || 0;
this._update();
return this;
};
Marker.prototype.getRotation = function getRotation() {
return this._rotation;
};
Marker.prototype.setRotationAlignment = function setRotationAlignment(alignment) {
this._rotationAlignment = alignment || 'auto';
this._update();
return this;
};
Marker.prototype.getRotationAlignment = function getRotationAlignment() {
return this._rotationAlignment;
};
Marker.prototype.setPitchAlignment = function setPitchAlignment(alignment) {
this._pitchAlignment = alignment && alignment !== 'auto' ? alignment : this._rotationAlignment;
this._update();
return this;
};
Marker.prototype.getPitchAlignment = function getPitchAlignment() {
return this._pitchAlignment;
};
return Marker;
}(performance.Evented);
var defaultOptions$3 = {
positionOptions: {
enableHighAccuracy: false,
maximumAge: 0,
timeout: 6000
},
fitBoundsOptions: { maxZoom: 15 },
trackUserLocation: false,
showAccuracyCircle: true,
showUserLocation: true
};
var supportsGeolocation;
function checkGeolocationSupport(callback) {
if (supportsGeolocation !== undefined) {
callback(supportsGeolocation);
} else if (performance.window.navigator.permissions !== undefined) {
performance.window.navigator.permissions.query({ name: 'geolocation' }).then(function (p) {
supportsGeolocation = p.state !== 'denied';
callback(supportsGeolocation);
});
} else {
supportsGeolocation = !!performance.window.navigator.geolocation;
callback(supportsGeolocation);
}
}
var numberOfWatches = 0;
var noTimeout = false;
var GeolocateControl = function (Evented) {
function GeolocateControl(options) {
Evented.call(this);
this.options = performance.extend({}, defaultOptions$3, options);
performance.bindAll([
'_onSuccess',
'_onError',
'_onZoom',
'_finish',
'_setupUI',
'_updateCamera',
'_updateMarker'
], this);
}
if (Evented)
GeolocateControl.__proto__ = Evented;
GeolocateControl.prototype = Object.create(Evented && Evented.prototype);
GeolocateControl.prototype.constructor = GeolocateControl;
GeolocateControl.prototype.onAdd = function onAdd(map) {
this._map = map;
this._container = DOM.create('div', 'mapboxgl-ctrl mapboxgl-ctrl-group');
checkGeolocationSupport(this._setupUI);
return this._container;
};
GeolocateControl.prototype.onRemove = function onRemove() {
if (this._geolocationWatchID !== undefined) {
performance.window.navigator.geolocation.clearWatch(this._geolocationWatchID);
this._geolocationWatchID = undefined;
}
if (this.options.showUserLocation && this._userLocationDotMarker) {
this._userLocationDotMarker.remove();
}
if (this.options.showAccuracyCircle && this._accuracyCircleMarker) {
this._accuracyCircleMarker.remove();
}
DOM.remove(this._container);
this._map.off('zoom', this._onZoom);
this._map = undefined;
numberOfWatches = 0;
noTimeout = false;
};
GeolocateControl.prototype._isOutOfMapMaxBounds = function _isOutOfMapMaxBounds(position) {
var bounds = this._map.getMaxBounds();
var coordinates = position.coords;
return bounds && (coordinates.longitude < bounds.getWest() || coordinates.longitude > bounds.getEast() || coordinates.latitude < bounds.getSouth() || coordinates.latitude > bounds.getNorth());
};
GeolocateControl.prototype._setErrorState = function _setErrorState() {
switch (this._watchState) {
case 'WAITING_ACTIVE':
this._watchState = 'ACTIVE_ERROR';
this._geolocateButton.classList.remove('mapboxgl-ctrl-geolocate-active');
this._geolocateButton.classList.add('mapboxgl-ctrl-geolocate-active-error');
break;
case 'ACTIVE_LOCK':
this._watchState = 'ACTIVE_ERROR';
this._geolocateButton.classList.remove('mapboxgl-ctrl-geolocate-active');
this._geolocateButton.classList.add('mapboxgl-ctrl-geolocate-active-error');
this._geolocateButton.classList.add('mapboxgl-ctrl-geolocate-waiting');
break;
case 'BACKGROUND':
this._watchState = 'BACKGROUND_ERROR';
this._geolocateButton.classList.remove('mapboxgl-ctrl-geolocate-background');
this._geolocateButton.classList.add('mapboxgl-ctrl-geolocate-background-error');
this._geolocateButton.classList.add('mapboxgl-ctrl-geolocate-waiting');
break;
}
};
GeolocateControl.prototype._onSuccess = function _onSuccess(position) {
if (!this._map) {
return;
}
if (this._isOutOfMapMaxBounds(position)) {
this._setErrorState();
this.fire(new performance.Event('outofmaxbounds', position));
this._updateMarker();
this._finish();
return;
}
if (this.options.trackUserLocation) {
this._lastKnownPosition = position;
switch (this._watchState) {
case 'WAITING_ACTIVE':
case 'ACTIVE_LOCK':
case 'ACTIVE_ERROR':
this._watchState = 'ACTIVE_LOCK';
this._geolocateButton.classList.remove('mapboxgl-ctrl-geolocate-waiting');
this._geolocateButton.classList.remove('mapboxgl-ctrl-geolocate-active-error');
this._geolocateButton.classList.add('mapboxgl-ctrl-geolocate-active');
break;
case 'BACKGROUND':
case 'BACKGROUND_ERROR':
this._watchState = 'BACKGROUND';
this._geolocateButton.classList.remove('mapboxgl-ctrl-geolocate-waiting');
this._geolocateButton.classList.remove('mapboxgl-ctrl-geolocate-background-error');
this._geolocateButton.classList.add('mapboxgl-ctrl-geolocate-background');
break;
}
}
if (this.options.showUserLocation && this._watchState !== 'OFF') {
this._updateMarker(position);
}
if (!this.options.trackUserLocation || this._watchState === 'ACTIVE_LOCK') {
this._updateCamera(position);
}
if (this.options.showUserLocation) {
this._dotElement.classList.remove('mapboxgl-user-location-dot-stale');
}
this.fire(new performance.Event('geolocate', position));
this._finish();
};
GeolocateControl.prototype._updateCamera = function _updateCamera(position) {
var center = new performance.LngLat(position.coords.longitude, position.coords.latitude);
var radius = position.coords.accuracy;
var bearing = this._map.getBearing();
var options = performance.extend({ bearing: bearing }, this.options.fitBoundsOptions);
this._map.fitBounds(center.toBounds(radius), options, { geolocateSource: true });
};
GeolocateControl.prototype._updateMarker = function _updateMarker(position) {
if (position) {
var center = new performance.LngLat(position.coords.longitude, position.coords.latitude);
this._accuracyCircleMarker.setLngLat(center).addTo(this._map);
this._userLocationDotMarker.setLngLat(center).addTo(this._map);
this._accuracy = position.coords.accuracy;
if (this.options.showUserLocation && this.options.showAccuracyCircle) {
this._updateCircleRadius();
}
} else {
this._userLocationDotMarker.remove();
this._accuracyCircleMarker.remove();
}
};
GeolocateControl.prototype._updateCircleRadius = function _updateCircleRadius() {
var y = this._map._container.clientHeight / 2;
var a = this._map.unproject([
0,
y
]);
var b = this._map.unproject([
1,
y
]);
var metersPerPixel = a.distanceTo(b);
var circleDiameter = Math.ceil(2 * this._accuracy / metersPerPixel);
this._circleElement.style.width = circleDiameter + 'px';
this._circleElement.style.height = circleDiameter + 'px';
};
GeolocateControl.prototype._onZoom = function _onZoom() {
if (this.options.showUserLocation && this.options.showAccuracyCircle) {
this._updateCircleRadius();
}
};
GeolocateControl.prototype._onError = function _onError(error) {
if (!this._map) {
return;
}
if (this.options.trackUserLocation) {
if (error.code === 1) {
this._watchState = 'OFF';
this._geolocateButton.classList.remove('mapboxgl-ctrl-geolocate-waiting');
this._geolocateButton.classList.remove('mapboxgl-ctrl-geolocate-active');
this._geolocateButton.classList.remove('mapboxgl-ctrl-geolocate-active-error');
this._geolocateButton.classList.remove('mapboxgl-ctrl-geolocate-background');
this._geolocateButton.classList.remove('mapboxgl-ctrl-geolocate-background-error');
this._geolocateButton.disabled = true;
var title = this._map._getUIString('GeolocateControl.LocationNotAvailable');
this._geolocateButton.title = title;
this._geolocateButton.setAttribute('aria-label', title);
if (this._geolocationWatchID !== undefined) {
this._clearWatch();
}
} else if (error.code === 3 && noTimeout) {
return;
} else {
this._setErrorState();
}
}
if (this._watchState !== 'OFF' && this.options.showUserLocation) {
this._dotElement.classList.add('mapboxgl-user-location-dot-stale');
}
this.fire(new performance.Event('error', error));
this._finish();
};
GeolocateControl.prototype._finish = function _finish() {
if (this._timeoutId) {
clearTimeout(this._timeoutId);
}
this._timeoutId = undefined;
};
GeolocateControl.prototype._setupUI = function _setupUI(supported) {
var this$1 = this;
this._container.addEventListener('contextmenu', function (e) {
return e.preventDefault();
});
this._geolocateButton = DOM.create('button', 'mapboxgl-ctrl-geolocate', this._container);
DOM.create('span', 'mapboxgl-ctrl-icon', this._geolocateButton).setAttribute('aria-hidden', true);
this._geolocateButton.type = 'button';
if (supported === false) {
performance.warnOnce('Geolocation support is not available so the GeolocateControl will be disabled.');
var title = this._map._getUIString('GeolocateControl.LocationNotAvailable');
this._geolocateButton.disabled = true;
this._geolocateButton.title = title;
this._geolocateButton.setAttribute('aria-label', title);
} else {
var title$1 = this._map._getUIString('GeolocateControl.FindMyLocation');
this._geolocateButton.title = title$1;
this._geolocateButton.setAttribute('aria-label', title$1);
}
if (this.options.trackUserLocation) {
this._geolocateButton.setAttribute('aria-pressed', 'false');
this._watchState = 'OFF';
}
if (this.options.showUserLocation) {
this._dotElement = DOM.create('div', 'mapboxgl-user-location-dot');
this._userLocationDotMarker = new Marker(this._dotElement);
this._circleElement = DOM.create('div', 'mapboxgl-user-location-accuracy-circle');
this._accuracyCircleMarker = new Marker({
element: this._circleElement,
pitchAlignment: 'map'
});
if (this.options.trackUserLocation) {
this._watchState = 'OFF';
}
this._map.on('zoom', this._onZoom);
}
this._geolocateButton.addEventListener('click', this.trigger.bind(this));
this._setup = true;
if (this.options.trackUserLocation) {
this._map.on('movestart', function (event) {
var fromResize = event.originalEvent && event.originalEvent.type === 'resize';
if (!event.geolocateSource && this$1._watchState === 'ACTIVE_LOCK' && !fromResize) {
this$1._watchState = 'BACKGROUND';
this$1._geolocateButton.classList.add('mapboxgl-ctrl-geolocate-background');
this$1._geolocateButton.classList.remove('mapboxgl-ctrl-geolocate-active');
this$1.fire(new performance.Event('trackuserlocationend'));
}
});
}
};
GeolocateControl.prototype.trigger = function trigger() {
if (!this._setup) {
performance.warnOnce('Geolocate control triggered before added to a map');
return false;
}
if (this.options.trackUserLocation) {
switch (this._watchState) {
case 'OFF':
this._watchState = 'WAITING_ACTIVE';
this.fire(new performance.Event('trackuserlocationstart'));
break;
case 'WAITING_ACTIVE':
case 'ACTIVE_LOCK':
case 'ACTIVE_ERROR':
case 'BACKGROUND_ERROR':
numberOfWatches--;
noTimeout = false;
this._watchState = 'OFF';
this._geolocateButton.classList.remove('mapboxgl-ctrl-geolocate-waiting');
this._geolocateButton.classList.remove('mapboxgl-ctrl-geolocate-active');
this._geolocateButton.classList.remove('mapboxgl-ctrl-geolocate-active-error');
this._geolocateButton.classList.remove('mapboxgl-ctrl-geolocate-background');
this._geolocateButton.classList.remove('mapboxgl-ctrl-geolocate-background-error');
this.fire(new performance.Event('trackuserlocationend'));
break;
case 'BACKGROUND':
this._watchState = 'ACTIVE_LOCK';
this._geolocateButton.classList.remove('mapboxgl-ctrl-geolocate-background');
if (this._lastKnownPosition) {
this._updateCamera(this._lastKnownPosition);
}
this.fire(new performance.Event('trackuserlocationstart'));
break;
}
switch (this._watchState) {
case 'WAITING_ACTIVE':
this._geolocateButton.classList.add('mapboxgl-ctrl-geolocate-waiting');
this._geolocateButton.classList.add('mapboxgl-ctrl-geolocate-active');
break;
case 'ACTIVE_LOCK':
this._geolocateButton.classList.add('mapboxgl-ctrl-geolocate-active');
break;
case 'ACTIVE_ERROR':
this._geolocateButton.classList.add('mapboxgl-ctrl-geolocate-waiting');
this._geolocateButton.classList.add('mapboxgl-ctrl-geolocate-active-error');
break;
case 'BACKGROUND':
this._geolocateButton.classList.add('mapboxgl-ctrl-geolocate-background');
break;
case 'BACKGROUND_ERROR':
this._geolocateButton.classList.add('mapboxgl-ctrl-geolocate-waiting');
this._geolocateButton.classList.add('mapboxgl-ctrl-geolocate-background-error');
break;
}
if (this._watchState === 'OFF' && this._geolocationWatchID !== undefined) {
this._clearWatch();
} else if (this._geolocationWatchID === undefined) {
this._geolocateButton.classList.add('mapboxgl-ctrl-geolocate-waiting');
this._geolocateButton.setAttribute('aria-pressed', 'true');
numberOfWatches++;
var positionOptions;
if (numberOfWatches > 1) {
positionOptions = {
maximumAge: 600000,
timeout: 0
};
noTimeout = true;
} else {
positionOptions = this.options.positionOptions;
noTimeout = false;
}
this._geolocationWatchID = performance.window.navigator.geolocation.watchPosition(this._onSuccess, this._onError, positionOptions);
}
} else {
performance.window.navigator.geolocation.getCurrentPosition(this._onSuccess, this._onError, this.options.positionOptions);
this._timeoutId = setTimeout(this._finish, 10000);
}
return true;
};
GeolocateControl.prototype._clearWatch = function _clearWatch() {
performance.window.navigator.geolocation.clearWatch(this._geolocationWatchID);
this._geolocationWatchID = undefined;
this._geolocateButton.classList.remove('mapboxgl-ctrl-geolocate-waiting');
this._geolocateButton.setAttribute('aria-pressed', 'false');
if (this.options.showUserLocation) {
this._updateMarker(null);
}
};
return GeolocateControl;
}(performance.Evented);
var defaultOptions$4 = {
maxWidth: 100,
unit: 'metric'
};
var ScaleControl = function ScaleControl(options) {
this.options = performance.extend({}, defaultOptions$4, options);
performance.bindAll([
'_onMove',
'setUnit'
], this);
};
ScaleControl.prototype.getDefaultPosition = function getDefaultPosition() {
return 'bottom-left';
};
ScaleControl.prototype._onMove = function _onMove() {
updateScale(this._map, this._container, this.options);
};
ScaleControl.prototype.onAdd = function onAdd(map) {
this._map = map;
this._container = DOM.create('div', 'mapboxgl-ctrl mapboxgl-ctrl-scale', map.getContainer());
this._map.on('move', this._onMove);
this._onMove();
return this._container;
};
ScaleControl.prototype.onRemove = function onRemove() {
DOM.remove(this._container);
this._map.off('move', this._onMove);
this._map = undefined;
};
ScaleControl.prototype.setUnit = function setUnit(unit) {
this.options.unit = unit;
updateScale(this._map, this._container, this.options);
};
function updateScale(map, container, options) {
var maxWidth = options && options.maxWidth || 100;
var y = map._container.clientHeight / 2;
var left = map.unproject([
0,
y
]);
var right = map.unproject([
maxWidth,
y
]);
var maxMeters = left.distanceTo(right);
if (options && options.unit === 'imperial') {
var maxFeet = 3.2808 * maxMeters;
if (maxFeet > 5280) {
var maxMiles = maxFeet / 5280;
setScale(container, maxWidth, maxMiles, map._getUIString('ScaleControl.Miles'));
} else {
setScale(container, maxWidth, maxFeet, map._getUIString('ScaleControl.Feet'));
}
} else if (options && options.unit === 'nautical') {
var maxNauticals = maxMeters / 1852;
setScale(container, maxWidth, maxNauticals, map._getUIString('ScaleControl.NauticalMiles'));
} else if (maxMeters >= 1000) {
setScale(container, maxWidth, maxMeters / 1000, map._getUIString('ScaleControl.Kilometers'));
} else {
setScale(container, maxWidth, maxMeters, map._getUIString('ScaleControl.Meters'));
}
}
function setScale(container, maxWidth, maxDistance, unit) {
var distance = getRoundNum(maxDistance);
var ratio = distance / maxDistance;
container.style.width = maxWidth * ratio + 'px';
container.innerHTML = distance + ' ' + unit;
}
function getDecimalRoundNum(d) {
var multiplier = Math.pow(10, Math.ceil(-Math.log(d) / Math.LN10));
return Math.round(d * multiplier) / multiplier;
}
function getRoundNum(num) {
var pow10 = Math.pow(10, ('' + Math.floor(num)).length - 1);
var d = num / pow10;
d = d >= 10 ? 10 : d >= 5 ? 5 : d >= 3 ? 3 : d >= 2 ? 2 : d >= 1 ? 1 : getDecimalRoundNum(d);
return pow10 * d;
}
var FullscreenControl = function FullscreenControl(options) {
this._fullscreen = false;
if (options && options.container) {
if (options.container instanceof performance.window.HTMLElement) {
this._container = options.container;
} else {
performance.warnOnce('Full screen control \'container\' must be a DOM element.');
}
}
performance.bindAll([
'_onClickFullscreen',
'_changeIcon'
], this);
if ('onfullscreenchange' in performance.window.document) {
this._fullscreenchange = 'fullscreenchange';
} else if ('onmozfullscreenchange' in performance.window.document) {
this._fullscreenchange = 'mozfullscreenchange';
} else if ('onwebkitfullscreenchange' in performance.window.document) {
this._fullscreenchange = 'webkitfullscreenchange';
} else if ('onmsfullscreenchange' in performance.window.document) {
this._fullscreenchange = 'MSFullscreenChange';
}
};
FullscreenControl.prototype.onAdd = function onAdd(map) {
this._map = map;
if (!this._container) {
this._container = this._map.getContainer();
}
this._controlContainer = DOM.create('div', 'mapboxgl-ctrl mapboxgl-ctrl-group');
if (this._checkFullscreenSupport()) {
this._setupUI();
} else {
this._controlContainer.style.display = 'none';
performance.warnOnce('This device does not support fullscreen mode.');
}
return this._controlContainer;
};
FullscreenControl.prototype.onRemove = function onRemove() {
DOM.remove(this._controlContainer);
this._map = null;
performance.window.document.removeEventListener(this._fullscreenchange, this._changeIcon);
};
FullscreenControl.prototype._checkFullscreenSupport = function _checkFullscreenSupport() {
return !!(performance.window.document.fullscreenEnabled || performance.window.document.mozFullScreenEnabled || performance.window.document.msFullscreenEnabled || performance.window.document.webkitFullscreenEnabled);
};
FullscreenControl.prototype._setupUI = function _setupUI() {
var button = this._fullscreenButton = DOM.create('button', 'mapboxgl-ctrl-fullscreen', this._controlContainer);
DOM.create('span', 'mapboxgl-ctrl-icon', button).setAttribute('aria-hidden', true);
button.type = 'button';
this._updateTitle();
this._fullscreenButton.addEventListener('click', this._onClickFullscreen);
performance.window.document.addEventListener(this._fullscreenchange, this._changeIcon);
};
FullscreenControl.prototype._updateTitle = function _updateTitle() {
var title = this._getTitle();
this._fullscreenButton.setAttribute('aria-label', title);
this._fullscreenButton.title = title;
};
FullscreenControl.prototype._getTitle = function _getTitle() {
return this._map._getUIString(this._isFullscreen() ? 'FullscreenControl.Exit' : 'FullscreenControl.Enter');
};
FullscreenControl.prototype._isFullscreen = function _isFullscreen() {
return this._fullscreen;
};
FullscreenControl.prototype._changeIcon = function _changeIcon() {
var fullscreenElement = performance.window.document.fullscreenElement || performance.window.document.mozFullScreenElement || performance.window.document.webkitFullscreenElement || performance.window.document.msFullscreenElement;
if (fullscreenElement === this._container !== this._fullscreen) {
this._fullscreen = !this._fullscreen;
this._fullscreenButton.classList.toggle('mapboxgl-ctrl-shrink');
this._fullscreenButton.classList.toggle('mapboxgl-ctrl-fullscreen');
this._updateTitle();
}
};
FullscreenControl.prototype._onClickFullscreen = function _onClickFullscreen() {
if (this._isFullscreen()) {
if (performance.window.document.exitFullscreen) {
performance.window.document.exitFullscreen();
} else if (performance.window.document.mozCancelFullScreen) {
performance.window.document.mozCancelFullScreen();
} else if (performance.window.document.msExitFullscreen) {
performance.window.document.msExitFullscreen();
} else if (performance.window.document.webkitCancelFullScreen) {
performance.window.document.webkitCancelFullScreen();
}
} else if (this._container.requestFullscreen) {
this._container.requestFullscreen();
} else if (this._container.mozRequestFullScreen) {
this._container.mozRequestFullScreen();
} else if (this._container.msRequestFullscreen) {
this._container.msRequestFullscreen();
} else if (this._container.webkitRequestFullscreen) {
this._container.webkitRequestFullscreen();
}
};
var defaultOptions$5 = {
closeButton: true,
closeOnClick: true,
focusAfterOpen: true,
className: '',
maxWidth: '240px'
};
var focusQuerySelector = [
'a[href]',
'[tabindex]:not([tabindex=\'-1\'])',
'[contenteditable]:not([contenteditable=\'false\'])',
'button:not([disabled])',
'input:not([disabled])',
'select:not([disabled])',
'textarea:not([disabled])'
].join(', ');
var Popup = function (Evented) {
function Popup(options) {
Evented.call(this);
this.options = performance.extend(Object.create(defaultOptions$5), options);
performance.bindAll([
'_update',
'_onClose',
'remove',
'_onMouseMove',
'_onMouseUp',
'_onDrag'
], this);
}
if (Evented)
Popup.__proto__ = Evented;
Popup.prototype = Object.create(Evented && Evented.prototype);
Popup.prototype.constructor = Popup;
Popup.prototype.addTo = function addTo(map) {
if (this._map) {
this.remove();
}
this._map = map;
if (this.options.closeOnClick) {
this._map.on('click', this._onClose);
}
if (this.options.closeOnMove) {
this._map.on('move', this._onClose);
}
this._map.on('remove', this.remove);
this._update();
this._focusFirstElement();
if (this._trackPointer) {
this._map.on('mousemove', this._onMouseMove);
this._map.on('mouseup', this._onMouseUp);
if (this._container) {
this._container.classList.add('mapboxgl-popup-track-pointer');
}
this._map._canvasContainer.classList.add('mapboxgl-track-pointer');
} else {
this._map.on('move', this._update);
}
this.fire(new performance.Event('open'));
return this;
};
Popup.prototype.isOpen = function isOpen() {
return !!this._map;
};
Popup.prototype.remove = function remove() {
if (this._content) {
DOM.remove(this._content);
}
if (this._container) {
DOM.remove(this._container);
delete this._container;
}
if (this._map) {
this._map.off('move', this._update);
this._map.off('move', this._onClose);
this._map.off('click', this._onClose);
this._map.off('remove', this.remove);
this._map.off('mousemove', this._onMouseMove);
this._map.off('mouseup', this._onMouseUp);
this._map.off('drag', this._onDrag);
delete this._map;
}
this.fire(new performance.Event('close'));
return this;
};
Popup.prototype.getLngLat = function getLngLat() {
return this._lngLat;
};
Popup.prototype.setLngLat = function setLngLat(lnglat) {
this._lngLat = performance.LngLat.convert(lnglat);
this._pos = null;
this._trackPointer = false;
this._update();
if (this._map) {
this._map.on('move', this._update);
this._map.off('mousemove', this._onMouseMove);
if (this._container) {
this._container.classList.remove('mapboxgl-popup-track-pointer');
}
this._map._canvasContainer.classList.remove('mapboxgl-track-pointer');
}
return this;
};
Popup.prototype.trackPointer = function trackPointer() {
this._trackPointer = true;
this._pos = null;
this._update();
if (this._map) {
this._map.off('move', this._update);
this._map.on('mousemove', this._onMouseMove);
this._map.on('drag', this._onDrag);
if (this._container) {
this._container.classList.add('mapboxgl-popup-track-pointer');
}
this._map._canvasContainer.classList.add('mapboxgl-track-pointer');
}
return this;
};
Popup.prototype.getElement = function getElement() {
return this._container;
};
Popup.prototype.setText = function setText(text) {
return this.setDOMContent(performance.window.document.createTextNode(text));
};
Popup.prototype.setHTML = function setHTML(html) {
var frag = performance.window.document.createDocumentFragment();
var temp = performance.window.document.createElement('body');
var child;
temp.innerHTML = html;
while (true) {
child = temp.firstChild;
if (!child) {
break;
}
frag.appendChild(child);
}
return this.setDOMContent(frag);
};
Popup.prototype.getMaxWidth = function getMaxWidth() {
return this._container && this._container.style.maxWidth;
};
Popup.prototype.setMaxWidth = function setMaxWidth(maxWidth) {
this.options.maxWidth = maxWidth;
this._update();
return this;
};
Popup.prototype.setDOMContent = function setDOMContent(htmlNode) {
if (this._content) {
while (this._content.hasChildNodes()) {
if (this._content.firstChild) {
this._content.removeChild(this._content.firstChild);
}
}
} else {
this._content = DOM.create('div', 'mapboxgl-popup-content', this._container);
}
this._content.appendChild(htmlNode);
this._createCloseButton();
this._update();
this._focusFirstElement();
return this;
};
Popup.prototype.addClassName = function addClassName(className) {
if (this._container) {
this._container.classList.add(className);
}
};
Popup.prototype.removeClassName = function removeClassName(className) {
if (this._container) {
this._container.classList.remove(className);
}
};
Popup.prototype.setOffset = function setOffset(offset) {
this.options.offset = offset;
this._update();
return this;
};
Popup.prototype.toggleClassName = function toggleClassName(className) {
if (this._container) {
return this._container.classList.toggle(className);
}
};
Popup.prototype._createCloseButton = function _createCloseButton() {
if (this.options.closeButton) {
this._closeButton = DOM.create('button', 'mapboxgl-popup-close-button', this._content);
this._closeButton.type = 'button';
this._closeButton.setAttribute('aria-label', 'Close popup');
this._closeButton.innerHTML = '×';
this._closeButton.addEventListener('click', this._onClose);
}
};
Popup.prototype._onMouseUp = function _onMouseUp(event) {
this._update(event.point);
};
Popup.prototype._onMouseMove = function _onMouseMove(event) {
this._update(event.point);
};
Popup.prototype._onDrag = function _onDrag(event) {
this._update(event.point);
};
Popup.prototype._update = function _update(cursor) {
var this$1 = this;
var hasPosition = this._lngLat || this._trackPointer;
if (!this._map || !hasPosition || !this._content) {
return;
}
if (!this._container) {
this._container = DOM.create('div', 'mapboxgl-popup', this._map.getContainer());
this._tip = DOM.create('div', 'mapboxgl-popup-tip', this._container);
this._container.appendChild(this._content);
if (this.options.className) {
this.options.className.split(' ').forEach(function (name) {
return this$1._container.classList.add(name);
});
}
if (this._trackPointer) {
this._container.classList.add('mapboxgl-popup-track-pointer');
}
}
if (this.options.maxWidth && this._container.style.maxWidth !== this.options.maxWidth) {
this._container.style.maxWidth = this.options.maxWidth;
}
if (this._map.transform.renderWorldCopies && !this._trackPointer) {
this._lngLat = smartWrap(this._lngLat, this._pos, this._map.transform);
}
if (this._trackPointer && !cursor) {
return;
}
var pos = this._pos = this._trackPointer && cursor ? cursor : this._map.project(this._lngLat);
var anchor = this.options.anchor;
var offset = normalizeOffset(this.options.offset);
if (!anchor) {
var width = this._container.offsetWidth;
var height = this._container.offsetHeight;
var anchorComponents;
if (pos.y + offset.bottom.y < height) {
anchorComponents = ['top'];
} else if (pos.y > this._map.transform.height - height) {
anchorComponents = ['bottom'];
} else {
anchorComponents = [];
}
if (pos.x < width / 2) {
anchorComponents.push('left');
} else if (pos.x > this._map.transform.width - width / 2) {
anchorComponents.push('right');
}
if (anchorComponents.length === 0) {
anchor = 'bottom';
} else {
anchor = anchorComponents.join('-');
}
}
var offsetedPos = pos.add(offset[anchor]).round();
DOM.setTransform(this._container, anchorTranslate[anchor] + ' translate(' + offsetedPos.x + 'px,' + offsetedPos.y + 'px)');
applyAnchorClass(this._container, anchor, 'popup');
};
Popup.prototype._focusFirstElement = function _focusFirstElement() {
if (!this.options.focusAfterOpen || !this._container) {
return;
}
var firstFocusable = this._container.querySelector(focusQuerySelector);
if (firstFocusable) {
firstFocusable.focus();
}
};
Popup.prototype._onClose = function _onClose() {
this.remove();
};
return Popup;
}(performance.Evented);
function normalizeOffset(offset) {
if (!offset) {
return normalizeOffset(new performance.Point(0, 0));
} else if (typeof offset === 'number') {
var cornerOffset = Math.round(Math.sqrt(0.5 * Math.pow(offset, 2)));
return {
'center': new performance.Point(0, 0),
'top': new performance.Point(0, offset),
'top-left': new performance.Point(cornerOffset, cornerOffset),
'top-right': new performance.Point(-cornerOffset, cornerOffset),
'bottom': new performance.Point(0, -offset),
'bottom-left': new performance.Point(cornerOffset, -cornerOffset),
'bottom-right': new performance.Point(-cornerOffset, -cornerOffset),
'left': new performance.Point(offset, 0),
'right': new performance.Point(-offset, 0)
};
} else if (offset instanceof performance.Point || Array.isArray(offset)) {
var convertedOffset = performance.Point.convert(offset);
return {
'center': convertedOffset,
'top': convertedOffset,
'top-left': convertedOffset,
'top-right': convertedOffset,
'bottom': convertedOffset,
'bottom-left': convertedOffset,
'bottom-right': convertedOffset,
'left': convertedOffset,
'right': convertedOffset
};
} else {
return {
'center': performance.Point.convert(offset['center'] || [
0,
0
]),
'top': performance.Point.convert(offset['top'] || [
0,
0
]),
'top-left': performance.Point.convert(offset['top-left'] || [
0,
0
]),
'top-right': performance.Point.convert(offset['top-right'] || [
0,
0
]),
'bottom': performance.Point.convert(offset['bottom'] || [
0,
0
]),
'bottom-left': performance.Point.convert(offset['bottom-left'] || [
0,
0
]),
'bottom-right': performance.Point.convert(offset['bottom-right'] || [
0,
0
]),
'left': performance.Point.convert(offset['left'] || [
0,
0
]),
'right': performance.Point.convert(offset['right'] || [
0,
0
])
};
}
}
var exported = {
version: performance.version,
supported: mapboxGlSupported,
setRTLTextPlugin: performance.setRTLTextPlugin,
getRTLTextPluginStatus: performance.getRTLTextPluginStatus,
Map: Map,
NavigationControl: NavigationControl,
GeolocateControl: GeolocateControl,
AttributionControl: AttributionControl,
ScaleControl: ScaleControl,
FullscreenControl: FullscreenControl,
Popup: Popup,
Marker: Marker,
Style: Style,
LngLat: performance.LngLat,
LngLatBounds: performance.LngLatBounds,
Point: performance.Point,
MercatorCoordinate: performance.MercatorCoordinate,
Evented: performance.Evented,
config: performance.config,
prewarm: prewarm,
clearPrewarmedResources: clearPrewarmedResources,
get accessToken() {
return performance.config.ACCESS_TOKEN;
},
set accessToken(token) {
performance.config.ACCESS_TOKEN = token;
},
get baseApiUrl() {
return performance.config.API_URL;
},
set baseApiUrl(url) {
performance.config.API_URL = url;
},
get workerCount() {
return WorkerPool.workerCount;
},
set workerCount(count) {
WorkerPool.workerCount = count;
},
get maxParallelImageRequests() {
return performance.config.MAX_PARALLEL_IMAGE_REQUESTS;
},
set maxParallelImageRequests(numRequests) {
performance.config.MAX_PARALLEL_IMAGE_REQUESTS = numRequests;
},
clearStorage: function clearStorage(callback) {
performance.clearTileCache(callback);
},
workerUrl: ''
};
return exported;
});
//
return mapboxgl;
})));
//# sourceMappingURL=mapbox-gl-unminified.js.map
/***/ }),
/***/ 440:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
var meta_1 = __webpack_require__(3256);
// Note: change RADIUS => earthRadius
var RADIUS = 6378137;
/**
* Takes one or more features and returns their area in square meters.
*
* @name area
* @param {GeoJSON} geojson input GeoJSON feature(s)
* @returns {number} area in square meters
* @example
* var polygon = turf.polygon([[[125, -15], [113, -22], [154, -27], [144, -15], [125, -15]]]);
*
* var area = turf.area(polygon);
*
* //addToMap
* var addToMap = [polygon]
* polygon.properties.area = area
*/
function area(geojson) {
return meta_1.geomReduce(geojson, function (value, geom) {
return value + calculateArea(geom);
}, 0);
}
exports["default"] = area;
/**
* Calculate Area
*
* @private
* @param {Geometry} geom GeoJSON Geometries
* @returns {number} area
*/
function calculateArea(geom) {
var total = 0;
var i;
switch (geom.type) {
case "Polygon":
return polygonArea(geom.coordinates);
case "MultiPolygon":
for (i = 0; i < geom.coordinates.length; i++) {
total += polygonArea(geom.coordinates[i]);
}
return total;
case "Point":
case "MultiPoint":
case "LineString":
case "MultiLineString":
return 0;
}
return 0;
}
function polygonArea(coords) {
var total = 0;
if (coords && coords.length > 0) {
total += Math.abs(ringArea(coords[0]));
for (var i = 1; i < coords.length; i++) {
total -= Math.abs(ringArea(coords[i]));
}
}
return total;
}
/**
* @private
* Calculate the approximate area of the polygon were it projected onto the earth.
* Note that this area will be positive if ring is oriented clockwise, otherwise it will be negative.
*
* Reference:
* Robert. G. Chamberlain and William H. Duquette, "Some Algorithms for Polygons on a Sphere",
* JPL Publication 07-03, Jet Propulsion
* Laboratory, Pasadena, CA, June 2007 https://trs.jpl.nasa.gov/handle/2014/40409
*
* @param {Array>} coords Ring Coordinates
* @returns {number} The approximate signed geodesic area of the polygon in square meters.
*/
function ringArea(coords) {
var p1;
var p2;
var p3;
var lowerIndex;
var middleIndex;
var upperIndex;
var i;
var total = 0;
var coordsLength = coords.length;
if (coordsLength > 2) {
for (i = 0; i < coordsLength; i++) {
if (i === coordsLength - 2) {
// i = N-2
lowerIndex = coordsLength - 2;
middleIndex = coordsLength - 1;
upperIndex = 0;
}
else if (i === coordsLength - 1) {
// i = N-1
lowerIndex = coordsLength - 1;
middleIndex = 0;
upperIndex = 1;
}
else {
// i = 0 to N-3
lowerIndex = i;
middleIndex = i + 1;
upperIndex = i + 2;
}
p1 = coords[lowerIndex];
p2 = coords[middleIndex];
p3 = coords[upperIndex];
total += (rad(p3[0]) - rad(p1[0])) * Math.sin(rad(p2[1]));
}
total = (total * RADIUS * RADIUS) / 2;
}
return total;
}
function rad(num) {
return (num * Math.PI) / 180;
}
/***/ }),
/***/ 6284:
/***/ (function(__unused_webpack_module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
/**
* @module helpers
*/
/**
* Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.
*
* @memberof helpers
* @type {number}
*/
exports.earthRadius = 6371008.8;
/**
* Unit of measurement factors using a spherical (non-ellipsoid) earth radius.
*
* @memberof helpers
* @type {Object}
*/
exports.factors = {
centimeters: exports.earthRadius * 100,
centimetres: exports.earthRadius * 100,
degrees: exports.earthRadius / 111325,
feet: exports.earthRadius * 3.28084,
inches: exports.earthRadius * 39.37,
kilometers: exports.earthRadius / 1000,
kilometres: exports.earthRadius / 1000,
meters: exports.earthRadius,
metres: exports.earthRadius,
miles: exports.earthRadius / 1609.344,
millimeters: exports.earthRadius * 1000,
millimetres: exports.earthRadius * 1000,
nauticalmiles: exports.earthRadius / 1852,
radians: 1,
yards: exports.earthRadius * 1.0936,
};
/**
* Units of measurement factors based on 1 meter.
*
* @memberof helpers
* @type {Object}
*/
exports.unitsFactors = {
centimeters: 100,
centimetres: 100,
degrees: 1 / 111325,
feet: 3.28084,
inches: 39.37,
kilometers: 1 / 1000,
kilometres: 1 / 1000,
meters: 1,
metres: 1,
miles: 1 / 1609.344,
millimeters: 1000,
millimetres: 1000,
nauticalmiles: 1 / 1852,
radians: 1 / exports.earthRadius,
yards: 1.0936133,
};
/**
* Area of measurement factors based on 1 square meter.
*
* @memberof helpers
* @type {Object}
*/
exports.areaFactors = {
acres: 0.000247105,
centimeters: 10000,
centimetres: 10000,
feet: 10.763910417,
hectares: 0.0001,
inches: 1550.003100006,
kilometers: 0.000001,
kilometres: 0.000001,
meters: 1,
metres: 1,
miles: 3.86e-7,
millimeters: 1000000,
millimetres: 1000000,
yards: 1.195990046,
};
/**
* Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.
*
* @name feature
* @param {Geometry} geometry input geometry
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a GeoJSON Feature
* @example
* var geometry = {
* "type": "Point",
* "coordinates": [110, 50]
* };
*
* var feature = turf.feature(geometry);
*
* //=feature
*/
function feature(geom, properties, options) {
if (options === void 0) { options = {}; }
var feat = { type: "Feature" };
if (options.id === 0 || options.id) {
feat.id = options.id;
}
if (options.bbox) {
feat.bbox = options.bbox;
}
feat.properties = properties || {};
feat.geometry = geom;
return feat;
}
exports.feature = feature;
/**
* Creates a GeoJSON {@link Geometry} from a Geometry string type & coordinates.
* For GeometryCollection type use `helpers.geometryCollection`
*
* @name geometry
* @param {string} type Geometry Type
* @param {Array} coordinates Coordinates
* @param {Object} [options={}] Optional Parameters
* @returns {Geometry} a GeoJSON Geometry
* @example
* var type = "Point";
* var coordinates = [110, 50];
* var geometry = turf.geometry(type, coordinates);
* // => geometry
*/
function geometry(type, coordinates, _options) {
if (_options === void 0) { _options = {}; }
switch (type) {
case "Point":
return point(coordinates).geometry;
case "LineString":
return lineString(coordinates).geometry;
case "Polygon":
return polygon(coordinates).geometry;
case "MultiPoint":
return multiPoint(coordinates).geometry;
case "MultiLineString":
return multiLineString(coordinates).geometry;
case "MultiPolygon":
return multiPolygon(coordinates).geometry;
default:
throw new Error(type + " is invalid");
}
}
exports.geometry = geometry;
/**
* Creates a {@link Point} {@link Feature} from a Position.
*
* @name point
* @param {Array} coordinates longitude, latitude position (each in decimal degrees)
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a Point feature
* @example
* var point = turf.point([-75.343, 39.984]);
*
* //=point
*/
function point(coordinates, properties, options) {
if (options === void 0) { options = {}; }
if (!coordinates) {
throw new Error("coordinates is required");
}
if (!Array.isArray(coordinates)) {
throw new Error("coordinates must be an Array");
}
if (coordinates.length < 2) {
throw new Error("coordinates must be at least 2 numbers long");
}
if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) {
throw new Error("coordinates must contain numbers");
}
var geom = {
type: "Point",
coordinates: coordinates,
};
return feature(geom, properties, options);
}
exports.point = point;
/**
* Creates a {@link Point} {@link FeatureCollection} from an Array of Point coordinates.
*
* @name points
* @param {Array>} coordinates an array of Points
* @param {Object} [properties={}] Translate these properties to each Feature
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north]
* associated with the FeatureCollection
* @param {string|number} [options.id] Identifier associated with the FeatureCollection
* @returns {FeatureCollection} Point Feature
* @example
* var points = turf.points([
* [-75, 39],
* [-80, 45],
* [-78, 50]
* ]);
*
* //=points
*/
function points(coordinates, properties, options) {
if (options === void 0) { options = {}; }
return featureCollection(coordinates.map(function (coords) {
return point(coords, properties);
}), options);
}
exports.points = points;
/**
* Creates a {@link Polygon} {@link Feature} from an Array of LinearRings.
*
* @name polygon
* @param {Array>>} coordinates an array of LinearRings
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} Polygon Feature
* @example
* var polygon = turf.polygon([[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]], { name: 'poly1' });
*
* //=polygon
*/
function polygon(coordinates, properties, options) {
if (options === void 0) { options = {}; }
for (var _i = 0, coordinates_1 = coordinates; _i < coordinates_1.length; _i++) {
var ring = coordinates_1[_i];
if (ring.length < 4) {
throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");
}
for (var j = 0; j < ring[ring.length - 1].length; j++) {
// Check if first point of Polygon contains two numbers
if (ring[ring.length - 1][j] !== ring[0][j]) {
throw new Error("First and last Position are not equivalent.");
}
}
}
var geom = {
type: "Polygon",
coordinates: coordinates,
};
return feature(geom, properties, options);
}
exports.polygon = polygon;
/**
* Creates a {@link Polygon} {@link FeatureCollection} from an Array of Polygon coordinates.
*
* @name polygons
* @param {Array>>>} coordinates an array of Polygon coordinates
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the FeatureCollection
* @returns {FeatureCollection} Polygon FeatureCollection
* @example
* var polygons = turf.polygons([
* [[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]],
* [[[-15, 42], [-14, 46], [-12, 41], [-17, 44], [-15, 42]]],
* ]);
*
* //=polygons
*/
function polygons(coordinates, properties, options) {
if (options === void 0) { options = {}; }
return featureCollection(coordinates.map(function (coords) {
return polygon(coords, properties);
}), options);
}
exports.polygons = polygons;
/**
* Creates a {@link LineString} {@link Feature} from an Array of Positions.
*
* @name lineString
* @param {Array>} coordinates an array of Positions
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} LineString Feature
* @example
* var linestring1 = turf.lineString([[-24, 63], [-23, 60], [-25, 65], [-20, 69]], {name: 'line 1'});
* var linestring2 = turf.lineString([[-14, 43], [-13, 40], [-15, 45], [-10, 49]], {name: 'line 2'});
*
* //=linestring1
* //=linestring2
*/
function lineString(coordinates, properties, options) {
if (options === void 0) { options = {}; }
if (coordinates.length < 2) {
throw new Error("coordinates must be an array of two or more positions");
}
var geom = {
type: "LineString",
coordinates: coordinates,
};
return feature(geom, properties, options);
}
exports.lineString = lineString;
/**
* Creates a {@link LineString} {@link FeatureCollection} from an Array of LineString coordinates.
*
* @name lineStrings
* @param {Array>>} coordinates an array of LinearRings
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north]
* associated with the FeatureCollection
* @param {string|number} [options.id] Identifier associated with the FeatureCollection
* @returns {FeatureCollection} LineString FeatureCollection
* @example
* var linestrings = turf.lineStrings([
* [[-24, 63], [-23, 60], [-25, 65], [-20, 69]],
* [[-14, 43], [-13, 40], [-15, 45], [-10, 49]]
* ]);
*
* //=linestrings
*/
function lineStrings(coordinates, properties, options) {
if (options === void 0) { options = {}; }
return featureCollection(coordinates.map(function (coords) {
return lineString(coords, properties);
}), options);
}
exports.lineStrings = lineStrings;
/**
* Takes one or more {@link Feature|Features} and creates a {@link FeatureCollection}.
*
* @name featureCollection
* @param {Feature[]} features input features
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {FeatureCollection} FeatureCollection of Features
* @example
* var locationA = turf.point([-75.343, 39.984], {name: 'Location A'});
* var locationB = turf.point([-75.833, 39.284], {name: 'Location B'});
* var locationC = turf.point([-75.534, 39.123], {name: 'Location C'});
*
* var collection = turf.featureCollection([
* locationA,
* locationB,
* locationC
* ]);
*
* //=collection
*/
function featureCollection(features, options) {
if (options === void 0) { options = {}; }
var fc = { type: "FeatureCollection" };
if (options.id) {
fc.id = options.id;
}
if (options.bbox) {
fc.bbox = options.bbox;
}
fc.features = features;
return fc;
}
exports.featureCollection = featureCollection;
/**
* Creates a {@link Feature} based on a
* coordinate array. Properties can be added optionally.
*
* @name multiLineString
* @param {Array>>} coordinates an array of LineStrings
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a MultiLineString feature
* @throws {Error} if no coordinates are passed
* @example
* var multiLine = turf.multiLineString([[[0,0],[10,10]]]);
*
* //=multiLine
*/
function multiLineString(coordinates, properties, options) {
if (options === void 0) { options = {}; }
var geom = {
type: "MultiLineString",
coordinates: coordinates,
};
return feature(geom, properties, options);
}
exports.multiLineString = multiLineString;
/**
* Creates a {@link Feature} based on a
* coordinate array. Properties can be added optionally.
*
* @name multiPoint
* @param {Array>} coordinates an array of Positions
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a MultiPoint feature
* @throws {Error} if no coordinates are passed
* @example
* var multiPt = turf.multiPoint([[0,0],[10,10]]);
*
* //=multiPt
*/
function multiPoint(coordinates, properties, options) {
if (options === void 0) { options = {}; }
var geom = {
type: "MultiPoint",
coordinates: coordinates,
};
return feature(geom, properties, options);
}
exports.multiPoint = multiPoint;
/**
* Creates a {@link Feature} based on a
* coordinate array. Properties can be added optionally.
*
* @name multiPolygon
* @param {Array>>>} coordinates an array of Polygons
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a multipolygon feature
* @throws {Error} if no coordinates are passed
* @example
* var multiPoly = turf.multiPolygon([[[[0,0],[0,10],[10,10],[10,0],[0,0]]]]);
*
* //=multiPoly
*
*/
function multiPolygon(coordinates, properties, options) {
if (options === void 0) { options = {}; }
var geom = {
type: "MultiPolygon",
coordinates: coordinates,
};
return feature(geom, properties, options);
}
exports.multiPolygon = multiPolygon;
/**
* Creates a {@link Feature} based on a
* coordinate array. Properties can be added optionally.
*
* @name geometryCollection
* @param {Array} geometries an array of GeoJSON Geometries
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a GeoJSON GeometryCollection Feature
* @example
* var pt = turf.geometry("Point", [100, 0]);
* var line = turf.geometry("LineString", [[101, 0], [102, 1]]);
* var collection = turf.geometryCollection([pt, line]);
*
* // => collection
*/
function geometryCollection(geometries, properties, options) {
if (options === void 0) { options = {}; }
var geom = {
type: "GeometryCollection",
geometries: geometries,
};
return feature(geom, properties, options);
}
exports.geometryCollection = geometryCollection;
/**
* Round number to precision
*
* @param {number} num Number
* @param {number} [precision=0] Precision
* @returns {number} rounded number
* @example
* turf.round(120.4321)
* //=120
*
* turf.round(120.4321, 2)
* //=120.43
*/
function round(num, precision) {
if (precision === void 0) { precision = 0; }
if (precision && !(precision >= 0)) {
throw new Error("precision must be a positive number");
}
var multiplier = Math.pow(10, precision || 0);
return Math.round(num * multiplier) / multiplier;
}
exports.round = round;
/**
* Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
*
* @name radiansToLength
* @param {number} radians in radians across the sphere
* @param {string} [units="kilometers"] can be degrees, radians, miles, inches, yards, metres,
* meters, kilometres, kilometers.
* @returns {number} distance
*/
function radiansToLength(radians, units) {
if (units === void 0) { units = "kilometers"; }
var factor = exports.factors[units];
if (!factor) {
throw new Error(units + " units is invalid");
}
return radians * factor;
}
exports.radiansToLength = radiansToLength;
/**
* Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
*
* @name lengthToRadians
* @param {number} distance in real units
* @param {string} [units="kilometers"] can be degrees, radians, miles, inches, yards, metres,
* meters, kilometres, kilometers.
* @returns {number} radians
*/
function lengthToRadians(distance, units) {
if (units === void 0) { units = "kilometers"; }
var factor = exports.factors[units];
if (!factor) {
throw new Error(units + " units is invalid");
}
return distance / factor;
}
exports.lengthToRadians = lengthToRadians;
/**
* Convert a distance measurement (assuming a spherical Earth) from a real-world unit into degrees
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, centimeters, kilometres, feet
*
* @name lengthToDegrees
* @param {number} distance in real units
* @param {string} [units="kilometers"] can be degrees, radians, miles, inches, yards, metres,
* meters, kilometres, kilometers.
* @returns {number} degrees
*/
function lengthToDegrees(distance, units) {
return radiansToDegrees(lengthToRadians(distance, units));
}
exports.lengthToDegrees = lengthToDegrees;
/**
* Converts any bearing angle from the north line direction (positive clockwise)
* and returns an angle between 0-360 degrees (positive clockwise), 0 being the north line
*
* @name bearingToAzimuth
* @param {number} bearing angle, between -180 and +180 degrees
* @returns {number} angle between 0 and 360 degrees
*/
function bearingToAzimuth(bearing) {
var angle = bearing % 360;
if (angle < 0) {
angle += 360;
}
return angle;
}
exports.bearingToAzimuth = bearingToAzimuth;
/**
* Converts an angle in radians to degrees
*
* @name radiansToDegrees
* @param {number} radians angle in radians
* @returns {number} degrees between 0 and 360 degrees
*/
function radiansToDegrees(radians) {
var degrees = radians % (2 * Math.PI);
return (degrees * 180) / Math.PI;
}
exports.radiansToDegrees = radiansToDegrees;
/**
* Converts an angle in degrees to radians
*
* @name degreesToRadians
* @param {number} degrees angle between 0 and 360 degrees
* @returns {number} angle in radians
*/
function degreesToRadians(degrees) {
var radians = degrees % 360;
return (radians * Math.PI) / 180;
}
exports.degreesToRadians = degreesToRadians;
/**
* Converts a length to the requested unit.
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
*
* @param {number} length to be converted
* @param {Units} [originalUnit="kilometers"] of the length
* @param {Units} [finalUnit="kilometers"] returned unit
* @returns {number} the converted length
*/
function convertLength(length, originalUnit, finalUnit) {
if (originalUnit === void 0) { originalUnit = "kilometers"; }
if (finalUnit === void 0) { finalUnit = "kilometers"; }
if (!(length >= 0)) {
throw new Error("length must be a positive number");
}
return radiansToLength(lengthToRadians(length, originalUnit), finalUnit);
}
exports.convertLength = convertLength;
/**
* Converts a area to the requested unit.
* Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches, hectares
* @param {number} area to be converted
* @param {Units} [originalUnit="meters"] of the distance
* @param {Units} [finalUnit="kilometers"] returned unit
* @returns {number} the converted area
*/
function convertArea(area, originalUnit, finalUnit) {
if (originalUnit === void 0) { originalUnit = "meters"; }
if (finalUnit === void 0) { finalUnit = "kilometers"; }
if (!(area >= 0)) {
throw new Error("area must be a positive number");
}
var startFactor = exports.areaFactors[originalUnit];
if (!startFactor) {
throw new Error("invalid original units");
}
var finalFactor = exports.areaFactors[finalUnit];
if (!finalFactor) {
throw new Error("invalid final units");
}
return (area / startFactor) * finalFactor;
}
exports.convertArea = convertArea;
/**
* isNumber
*
* @param {*} num Number to validate
* @returns {boolean} true/false
* @example
* turf.isNumber(123)
* //=true
* turf.isNumber('foo')
* //=false
*/
function isNumber(num) {
return !isNaN(num) && num !== null && !Array.isArray(num);
}
exports.isNumber = isNumber;
/**
* isObject
*
* @param {*} input variable to validate
* @returns {boolean} true/false
* @example
* turf.isObject({elevation: 10})
* //=true
* turf.isObject('foo')
* //=false
*/
function isObject(input) {
return !!input && input.constructor === Object;
}
exports.isObject = isObject;
/**
* Validate BBox
*
* @private
* @param {Array} bbox BBox to validate
* @returns {void}
* @throws Error if BBox is not valid
* @example
* validateBBox([-180, -40, 110, 50])
* //=OK
* validateBBox([-180, -40])
* //=Error
* validateBBox('Foo')
* //=Error
* validateBBox(5)
* //=Error
* validateBBox(null)
* //=Error
* validateBBox(undefined)
* //=Error
*/
function validateBBox(bbox) {
if (!bbox) {
throw new Error("bbox is required");
}
if (!Array.isArray(bbox)) {
throw new Error("bbox must be an Array");
}
if (bbox.length !== 4 && bbox.length !== 6) {
throw new Error("bbox must be an Array of 4 or 6 numbers");
}
bbox.forEach(function (num) {
if (!isNumber(num)) {
throw new Error("bbox must only contain numbers");
}
});
}
exports.validateBBox = validateBBox;
/**
* Validate Id
*
* @private
* @param {string|number} id Id to validate
* @returns {void}
* @throws Error if Id is not valid
* @example
* validateId([-180, -40, 110, 50])
* //=Error
* validateId([-180, -40])
* //=Error
* validateId('Foo')
* //=OK
* validateId(5)
* //=OK
* validateId(null)
* //=Error
* validateId(undefined)
* //=Error
*/
function validateId(id) {
if (!id) {
throw new Error("id is required");
}
if (["string", "number"].indexOf(typeof id) === -1) {
throw new Error("id must be a number or a string");
}
}
exports.validateId = validateId;
/***/ }),
/***/ 3256:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
var helpers = __webpack_require__(6284);
/**
* Callback for coordEach
*
* @callback coordEachCallback
* @param {Array} currentCoord The current coordinate being processed.
* @param {number} coordIndex The current index of the coordinate being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @param {number} geometryIndex The current index of the Geometry being processed.
*/
/**
* Iterate over coordinates in any GeoJSON object, similar to Array.forEach()
*
* @name coordEach
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (currentCoord, coordIndex, featureIndex, multiFeatureIndex)
* @param {boolean} [excludeWrapCoord=false] whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {"foo": "bar"}),
* turf.point([36, 53], {"hello": "world"})
* ]);
*
* turf.coordEach(features, function (currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {
* //=currentCoord
* //=coordIndex
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* });
*/
function coordEach(geojson, callback, excludeWrapCoord) {
// Handles null Geometry -- Skips this GeoJSON
if (geojson === null) return;
var j,
k,
l,
geometry,
stopG,
coords,
geometryMaybeCollection,
wrapShrink = 0,
coordIndex = 0,
isGeometryCollection,
type = geojson.type,
isFeatureCollection = type === "FeatureCollection",
isFeature = type === "Feature",
stop = isFeatureCollection ? geojson.features.length : 1;
// This logic may look a little weird. The reason why it is that way
// is because it's trying to be fast. GeoJSON supports multiple kinds
// of objects at its root: FeatureCollection, Features, Geometries.
// This function has the responsibility of handling all of them, and that
// means that some of the `for` loops you see below actually just don't apply
// to certain inputs. For instance, if you give this just a
// Point geometry, then both loops are short-circuited and all we do
// is gradually rename the input until it's called 'geometry'.
//
// This also aims to allocate as few resources as possible: just a
// few numbers and booleans, rather than any temporary arrays as would
// be required with the normalization approach.
for (var featureIndex = 0; featureIndex < stop; featureIndex++) {
geometryMaybeCollection = isFeatureCollection
? geojson.features[featureIndex].geometry
: isFeature
? geojson.geometry
: geojson;
isGeometryCollection = geometryMaybeCollection
? geometryMaybeCollection.type === "GeometryCollection"
: false;
stopG = isGeometryCollection
? geometryMaybeCollection.geometries.length
: 1;
for (var geomIndex = 0; geomIndex < stopG; geomIndex++) {
var multiFeatureIndex = 0;
var geometryIndex = 0;
geometry = isGeometryCollection
? geometryMaybeCollection.geometries[geomIndex]
: geometryMaybeCollection;
// Handles null Geometry -- Skips this geometry
if (geometry === null) continue;
coords = geometry.coordinates;
var geomType = geometry.type;
wrapShrink =
excludeWrapCoord &&
(geomType === "Polygon" || geomType === "MultiPolygon")
? 1
: 0;
switch (geomType) {
case null:
break;
case "Point":
if (
callback(
coords,
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false
)
return false;
coordIndex++;
multiFeatureIndex++;
break;
case "LineString":
case "MultiPoint":
for (j = 0; j < coords.length; j++) {
if (
callback(
coords[j],
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false
)
return false;
coordIndex++;
if (geomType === "MultiPoint") multiFeatureIndex++;
}
if (geomType === "LineString") multiFeatureIndex++;
break;
case "Polygon":
case "MultiLineString":
for (j = 0; j < coords.length; j++) {
for (k = 0; k < coords[j].length - wrapShrink; k++) {
if (
callback(
coords[j][k],
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false
)
return false;
coordIndex++;
}
if (geomType === "MultiLineString") multiFeatureIndex++;
if (geomType === "Polygon") geometryIndex++;
}
if (geomType === "Polygon") multiFeatureIndex++;
break;
case "MultiPolygon":
for (j = 0; j < coords.length; j++) {
geometryIndex = 0;
for (k = 0; k < coords[j].length; k++) {
for (l = 0; l < coords[j][k].length - wrapShrink; l++) {
if (
callback(
coords[j][k][l],
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false
)
return false;
coordIndex++;
}
geometryIndex++;
}
multiFeatureIndex++;
}
break;
case "GeometryCollection":
for (j = 0; j < geometry.geometries.length; j++)
if (
coordEach(geometry.geometries[j], callback, excludeWrapCoord) ===
false
)
return false;
break;
default:
throw new Error("Unknown Geometry Type");
}
}
}
}
/**
* Callback for coordReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback coordReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Array} currentCoord The current coordinate being processed.
* @param {number} coordIndex The current index of the coordinate being processed.
* Starts at index 0, if an initialValue is provided, and at index 1 otherwise.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @param {number} geometryIndex The current index of the Geometry being processed.
*/
/**
* Reduce coordinates in any GeoJSON object, similar to Array.reduce()
*
* @name coordReduce
* @param {FeatureCollection|Geometry|Feature} geojson any GeoJSON object
* @param {Function} callback a method that takes (previousValue, currentCoord, coordIndex)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @param {boolean} [excludeWrapCoord=false] whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.
* @returns {*} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {"foo": "bar"}),
* turf.point([36, 53], {"hello": "world"})
* ]);
*
* turf.coordReduce(features, function (previousValue, currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {
* //=previousValue
* //=currentCoord
* //=coordIndex
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* return currentCoord;
* });
*/
function coordReduce(geojson, callback, initialValue, excludeWrapCoord) {
var previousValue = initialValue;
coordEach(
geojson,
function (
currentCoord,
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) {
if (coordIndex === 0 && initialValue === undefined)
previousValue = currentCoord;
else
previousValue = callback(
previousValue,
currentCoord,
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
);
},
excludeWrapCoord
);
return previousValue;
}
/**
* Callback for propEach
*
* @callback propEachCallback
* @param {Object} currentProperties The current Properties being processed.
* @param {number} featureIndex The current index of the Feature being processed.
*/
/**
* Iterate over properties in any GeoJSON object, similar to Array.forEach()
*
* @name propEach
* @param {FeatureCollection|Feature} geojson any GeoJSON object
* @param {Function} callback a method that takes (currentProperties, featureIndex)
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.propEach(features, function (currentProperties, featureIndex) {
* //=currentProperties
* //=featureIndex
* });
*/
function propEach(geojson, callback) {
var i;
switch (geojson.type) {
case "FeatureCollection":
for (i = 0; i < geojson.features.length; i++) {
if (callback(geojson.features[i].properties, i) === false) break;
}
break;
case "Feature":
callback(geojson.properties, 0);
break;
}
}
/**
* Callback for propReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback propReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {*} currentProperties The current Properties being processed.
* @param {number} featureIndex The current index of the Feature being processed.
*/
/**
* Reduce properties in any GeoJSON object into a single value,
* similar to how Array.reduce works. However, in this case we lazily run
* the reduction, so an array of all properties is unnecessary.
*
* @name propReduce
* @param {FeatureCollection|Feature} geojson any GeoJSON object
* @param {Function} callback a method that takes (previousValue, currentProperties, featureIndex)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {*} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.propReduce(features, function (previousValue, currentProperties, featureIndex) {
* //=previousValue
* //=currentProperties
* //=featureIndex
* return currentProperties
* });
*/
function propReduce(geojson, callback, initialValue) {
var previousValue = initialValue;
propEach(geojson, function (currentProperties, featureIndex) {
if (featureIndex === 0 && initialValue === undefined)
previousValue = currentProperties;
else
previousValue = callback(previousValue, currentProperties, featureIndex);
});
return previousValue;
}
/**
* Callback for featureEach
*
* @callback featureEachCallback
* @param {Feature} currentFeature The current Feature being processed.
* @param {number} featureIndex The current index of the Feature being processed.
*/
/**
* Iterate over features in any GeoJSON object, similar to
* Array.forEach.
*
* @name featureEach
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (currentFeature, featureIndex)
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.featureEach(features, function (currentFeature, featureIndex) {
* //=currentFeature
* //=featureIndex
* });
*/
function featureEach(geojson, callback) {
if (geojson.type === "Feature") {
callback(geojson, 0);
} else if (geojson.type === "FeatureCollection") {
for (var i = 0; i < geojson.features.length; i++) {
if (callback(geojson.features[i], i) === false) break;
}
}
}
/**
* Callback for featureReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback featureReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Feature} currentFeature The current Feature being processed.
* @param {number} featureIndex The current index of the Feature being processed.
*/
/**
* Reduce features in any GeoJSON object, similar to Array.reduce().
*
* @name featureReduce
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {*} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {"foo": "bar"}),
* turf.point([36, 53], {"hello": "world"})
* ]);
*
* turf.featureReduce(features, function (previousValue, currentFeature, featureIndex) {
* //=previousValue
* //=currentFeature
* //=featureIndex
* return currentFeature
* });
*/
function featureReduce(geojson, callback, initialValue) {
var previousValue = initialValue;
featureEach(geojson, function (currentFeature, featureIndex) {
if (featureIndex === 0 && initialValue === undefined)
previousValue = currentFeature;
else previousValue = callback(previousValue, currentFeature, featureIndex);
});
return previousValue;
}
/**
* Get all coordinates from any GeoJSON object.
*
* @name coordAll
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @returns {Array>} coordinate position array
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* var coords = turf.coordAll(features);
* //= [[26, 37], [36, 53]]
*/
function coordAll(geojson) {
var coords = [];
coordEach(geojson, function (coord) {
coords.push(coord);
});
return coords;
}
/**
* Callback for geomEach
*
* @callback geomEachCallback
* @param {Geometry} currentGeometry The current Geometry being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {Object} featureProperties The current Feature Properties being processed.
* @param {Array} featureBBox The current Feature BBox being processed.
* @param {number|string} featureId The current Feature Id being processed.
*/
/**
* Iterate over each geometry in any GeoJSON object, similar to Array.forEach()
*
* @name geomEach
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (currentGeometry, featureIndex, featureProperties, featureBBox, featureId)
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.geomEach(features, function (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {
* //=currentGeometry
* //=featureIndex
* //=featureProperties
* //=featureBBox
* //=featureId
* });
*/
function geomEach(geojson, callback) {
var i,
j,
g,
geometry,
stopG,
geometryMaybeCollection,
isGeometryCollection,
featureProperties,
featureBBox,
featureId,
featureIndex = 0,
isFeatureCollection = geojson.type === "FeatureCollection",
isFeature = geojson.type === "Feature",
stop = isFeatureCollection ? geojson.features.length : 1;
// This logic may look a little weird. The reason why it is that way
// is because it's trying to be fast. GeoJSON supports multiple kinds
// of objects at its root: FeatureCollection, Features, Geometries.
// This function has the responsibility of handling all of them, and that
// means that some of the `for` loops you see below actually just don't apply
// to certain inputs. For instance, if you give this just a
// Point geometry, then both loops are short-circuited and all we do
// is gradually rename the input until it's called 'geometry'.
//
// This also aims to allocate as few resources as possible: just a
// few numbers and booleans, rather than any temporary arrays as would
// be required with the normalization approach.
for (i = 0; i < stop; i++) {
geometryMaybeCollection = isFeatureCollection
? geojson.features[i].geometry
: isFeature
? geojson.geometry
: geojson;
featureProperties = isFeatureCollection
? geojson.features[i].properties
: isFeature
? geojson.properties
: {};
featureBBox = isFeatureCollection
? geojson.features[i].bbox
: isFeature
? geojson.bbox
: undefined;
featureId = isFeatureCollection
? geojson.features[i].id
: isFeature
? geojson.id
: undefined;
isGeometryCollection = geometryMaybeCollection
? geometryMaybeCollection.type === "GeometryCollection"
: false;
stopG = isGeometryCollection
? geometryMaybeCollection.geometries.length
: 1;
for (g = 0; g < stopG; g++) {
geometry = isGeometryCollection
? geometryMaybeCollection.geometries[g]
: geometryMaybeCollection;
// Handle null Geometry
if (geometry === null) {
if (
callback(
null,
featureIndex,
featureProperties,
featureBBox,
featureId
) === false
)
return false;
continue;
}
switch (geometry.type) {
case "Point":
case "LineString":
case "MultiPoint":
case "Polygon":
case "MultiLineString":
case "MultiPolygon": {
if (
callback(
geometry,
featureIndex,
featureProperties,
featureBBox,
featureId
) === false
)
return false;
break;
}
case "GeometryCollection": {
for (j = 0; j < geometry.geometries.length; j++) {
if (
callback(
geometry.geometries[j],
featureIndex,
featureProperties,
featureBBox,
featureId
) === false
)
return false;
}
break;
}
default:
throw new Error("Unknown Geometry Type");
}
}
// Only increase `featureIndex` per each feature
featureIndex++;
}
}
/**
* Callback for geomReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback geomReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Geometry} currentGeometry The current Geometry being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {Object} featureProperties The current Feature Properties being processed.
* @param {Array} featureBBox The current Feature BBox being processed.
* @param {number|string} featureId The current Feature Id being processed.
*/
/**
* Reduce geometry in any GeoJSON object, similar to Array.reduce().
*
* @name geomReduce
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {*} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.geomReduce(features, function (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {
* //=previousValue
* //=currentGeometry
* //=featureIndex
* //=featureProperties
* //=featureBBox
* //=featureId
* return currentGeometry
* });
*/
function geomReduce(geojson, callback, initialValue) {
var previousValue = initialValue;
geomEach(
geojson,
function (
currentGeometry,
featureIndex,
featureProperties,
featureBBox,
featureId
) {
if (featureIndex === 0 && initialValue === undefined)
previousValue = currentGeometry;
else
previousValue = callback(
previousValue,
currentGeometry,
featureIndex,
featureProperties,
featureBBox,
featureId
);
}
);
return previousValue;
}
/**
* Callback for flattenEach
*
* @callback flattenEachCallback
* @param {Feature} currentFeature The current flattened feature being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
*/
/**
* Iterate over flattened features in any GeoJSON object, similar to
* Array.forEach.
*
* @name flattenEach
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (currentFeature, featureIndex, multiFeatureIndex)
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.multiPoint([[40, 30], [36, 53]], {hello: 'world'})
* ]);
*
* turf.flattenEach(features, function (currentFeature, featureIndex, multiFeatureIndex) {
* //=currentFeature
* //=featureIndex
* //=multiFeatureIndex
* });
*/
function flattenEach(geojson, callback) {
geomEach(geojson, function (geometry, featureIndex, properties, bbox, id) {
// Callback for single geometry
var type = geometry === null ? null : geometry.type;
switch (type) {
case null:
case "Point":
case "LineString":
case "Polygon":
if (
callback(
helpers.feature(geometry, properties, { bbox: bbox, id: id }),
featureIndex,
0
) === false
)
return false;
return;
}
var geomType;
// Callback for multi-geometry
switch (type) {
case "MultiPoint":
geomType = "Point";
break;
case "MultiLineString":
geomType = "LineString";
break;
case "MultiPolygon":
geomType = "Polygon";
break;
}
for (
var multiFeatureIndex = 0;
multiFeatureIndex < geometry.coordinates.length;
multiFeatureIndex++
) {
var coordinate = geometry.coordinates[multiFeatureIndex];
var geom = {
type: geomType,
coordinates: coordinate,
};
if (
callback(helpers.feature(geom, properties), featureIndex, multiFeatureIndex) ===
false
)
return false;
}
});
}
/**
* Callback for flattenReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback flattenReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Feature} currentFeature The current Feature being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
*/
/**
* Reduce flattened features in any GeoJSON object, similar to Array.reduce().
*
* @name flattenReduce
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex, multiFeatureIndex)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {*} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.multiPoint([[40, 30], [36, 53]], {hello: 'world'})
* ]);
*
* turf.flattenReduce(features, function (previousValue, currentFeature, featureIndex, multiFeatureIndex) {
* //=previousValue
* //=currentFeature
* //=featureIndex
* //=multiFeatureIndex
* return currentFeature
* });
*/
function flattenReduce(geojson, callback, initialValue) {
var previousValue = initialValue;
flattenEach(
geojson,
function (currentFeature, featureIndex, multiFeatureIndex) {
if (
featureIndex === 0 &&
multiFeatureIndex === 0 &&
initialValue === undefined
)
previousValue = currentFeature;
else
previousValue = callback(
previousValue,
currentFeature,
featureIndex,
multiFeatureIndex
);
}
);
return previousValue;
}
/**
* Callback for segmentEach
*
* @callback segmentEachCallback
* @param {Feature} currentSegment The current Segment being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @param {number} geometryIndex The current index of the Geometry being processed.
* @param {number} segmentIndex The current index of the Segment being processed.
* @returns {void}
*/
/**
* Iterate over 2-vertex line segment in any GeoJSON object, similar to Array.forEach()
* (Multi)Point geometries do not contain segments therefore they are ignored during this operation.
*
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON
* @param {Function} callback a method that takes (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex)
* @returns {void}
* @example
* var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
*
* // Iterate over GeoJSON by 2-vertex segments
* turf.segmentEach(polygon, function (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {
* //=currentSegment
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* //=segmentIndex
* });
*
* // Calculate the total number of segments
* var total = 0;
* turf.segmentEach(polygon, function () {
* total++;
* });
*/
function segmentEach(geojson, callback) {
flattenEach(geojson, function (feature, featureIndex, multiFeatureIndex) {
var segmentIndex = 0;
// Exclude null Geometries
if (!feature.geometry) return;
// (Multi)Point geometries do not contain segments therefore they are ignored during this operation.
var type = feature.geometry.type;
if (type === "Point" || type === "MultiPoint") return;
// Generate 2-vertex line segments
var previousCoords;
var previousFeatureIndex = 0;
var previousMultiIndex = 0;
var prevGeomIndex = 0;
if (
coordEach(
feature,
function (
currentCoord,
coordIndex,
featureIndexCoord,
multiPartIndexCoord,
geometryIndex
) {
// Simulating a meta.coordReduce() since `reduce` operations cannot be stopped by returning `false`
if (
previousCoords === undefined ||
featureIndex > previousFeatureIndex ||
multiPartIndexCoord > previousMultiIndex ||
geometryIndex > prevGeomIndex
) {
previousCoords = currentCoord;
previousFeatureIndex = featureIndex;
previousMultiIndex = multiPartIndexCoord;
prevGeomIndex = geometryIndex;
segmentIndex = 0;
return;
}
var currentSegment = helpers.lineString(
[previousCoords, currentCoord],
feature.properties
);
if (
callback(
currentSegment,
featureIndex,
multiFeatureIndex,
geometryIndex,
segmentIndex
) === false
)
return false;
segmentIndex++;
previousCoords = currentCoord;
}
) === false
)
return false;
});
}
/**
* Callback for segmentReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback segmentReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Feature} currentSegment The current Segment being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @param {number} geometryIndex The current index of the Geometry being processed.
* @param {number} segmentIndex The current index of the Segment being processed.
*/
/**
* Reduce 2-vertex line segment in any GeoJSON object, similar to Array.reduce()
* (Multi)Point geometries do not contain segments therefore they are ignored during this operation.
*
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON
* @param {Function} callback a method that takes (previousValue, currentSegment, currentIndex)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {void}
* @example
* var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
*
* // Iterate over GeoJSON by 2-vertex segments
* turf.segmentReduce(polygon, function (previousSegment, currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {
* //= previousSegment
* //= currentSegment
* //= featureIndex
* //= multiFeatureIndex
* //= geometryIndex
* //= segmentIndex
* return currentSegment
* });
*
* // Calculate the total number of segments
* var initialValue = 0
* var total = turf.segmentReduce(polygon, function (previousValue) {
* previousValue++;
* return previousValue;
* }, initialValue);
*/
function segmentReduce(geojson, callback, initialValue) {
var previousValue = initialValue;
var started = false;
segmentEach(
geojson,
function (
currentSegment,
featureIndex,
multiFeatureIndex,
geometryIndex,
segmentIndex
) {
if (started === false && initialValue === undefined)
previousValue = currentSegment;
else
previousValue = callback(
previousValue,
currentSegment,
featureIndex,
multiFeatureIndex,
geometryIndex,
segmentIndex
);
started = true;
}
);
return previousValue;
}
/**
* Callback for lineEach
*
* @callback lineEachCallback
* @param {Feature} currentLine The current LineString|LinearRing being processed
* @param {number} featureIndex The current index of the Feature being processed
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed
* @param {number} geometryIndex The current index of the Geometry being processed
*/
/**
* Iterate over line or ring coordinates in LineString, Polygon, MultiLineString, MultiPolygon Features or Geometries,
* similar to Array.forEach.
*
* @name lineEach
* @param {Geometry|Feature} geojson object
* @param {Function} callback a method that takes (currentLine, featureIndex, multiFeatureIndex, geometryIndex)
* @example
* var multiLine = turf.multiLineString([
* [[26, 37], [35, 45]],
* [[36, 53], [38, 50], [41, 55]]
* ]);
*
* turf.lineEach(multiLine, function (currentLine, featureIndex, multiFeatureIndex, geometryIndex) {
* //=currentLine
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* });
*/
function lineEach(geojson, callback) {
// validation
if (!geojson) throw new Error("geojson is required");
flattenEach(geojson, function (feature, featureIndex, multiFeatureIndex) {
if (feature.geometry === null) return;
var type = feature.geometry.type;
var coords = feature.geometry.coordinates;
switch (type) {
case "LineString":
if (callback(feature, featureIndex, multiFeatureIndex, 0, 0) === false)
return false;
break;
case "Polygon":
for (
var geometryIndex = 0;
geometryIndex < coords.length;
geometryIndex++
) {
if (
callback(
helpers.lineString(coords[geometryIndex], feature.properties),
featureIndex,
multiFeatureIndex,
geometryIndex
) === false
)
return false;
}
break;
}
});
}
/**
* Callback for lineReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback lineReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Feature} currentLine The current LineString|LinearRing being processed.
* @param {number} featureIndex The current index of the Feature being processed
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed
* @param {number} geometryIndex The current index of the Geometry being processed
*/
/**
* Reduce features in any GeoJSON object, similar to Array.reduce().
*
* @name lineReduce
* @param {Geometry|Feature} geojson object
* @param {Function} callback a method that takes (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {*} The value that results from the reduction.
* @example
* var multiPoly = turf.multiPolygon([
* turf.polygon([[[12,48],[2,41],[24,38],[12,48]], [[9,44],[13,41],[13,45],[9,44]]]),
* turf.polygon([[[5, 5], [0, 0], [2, 2], [4, 4], [5, 5]]])
* ]);
*
* turf.lineReduce(multiPoly, function (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex) {
* //=previousValue
* //=currentLine
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* return currentLine
* });
*/
function lineReduce(geojson, callback, initialValue) {
var previousValue = initialValue;
lineEach(
geojson,
function (currentLine, featureIndex, multiFeatureIndex, geometryIndex) {
if (featureIndex === 0 && initialValue === undefined)
previousValue = currentLine;
else
previousValue = callback(
previousValue,
currentLine,
featureIndex,
multiFeatureIndex,
geometryIndex
);
}
);
return previousValue;
}
/**
* Finds a particular 2-vertex LineString Segment from a GeoJSON using `@turf/meta` indexes.
*
* Negative indexes are permitted.
* Point & MultiPoint will always return null.
*
* @param {FeatureCollection|Feature|Geometry} geojson Any GeoJSON Feature or Geometry
* @param {Object} [options={}] Optional parameters
* @param {number} [options.featureIndex=0] Feature Index
* @param {number} [options.multiFeatureIndex=0] Multi-Feature Index
* @param {number} [options.geometryIndex=0] Geometry Index
* @param {number} [options.segmentIndex=0] Segment Index
* @param {Object} [options.properties={}] Translate Properties to output LineString
* @param {BBox} [options.bbox={}] Translate BBox to output LineString
* @param {number|string} [options.id={}] Translate Id to output LineString
* @returns {Feature} 2-vertex GeoJSON Feature LineString
* @example
* var multiLine = turf.multiLineString([
* [[10, 10], [50, 30], [30, 40]],
* [[-10, -10], [-50, -30], [-30, -40]]
* ]);
*
* // First Segment (defaults are 0)
* turf.findSegment(multiLine);
* // => Feature>
*
* // First Segment of 2nd Multi Feature
* turf.findSegment(multiLine, {multiFeatureIndex: 1});
* // => Feature>
*
* // Last Segment of Last Multi Feature
* turf.findSegment(multiLine, {multiFeatureIndex: -1, segmentIndex: -1});
* // => Feature>
*/
function findSegment(geojson, options) {
// Optional Parameters
options = options || {};
if (!helpers.isObject(options)) throw new Error("options is invalid");
var featureIndex = options.featureIndex || 0;
var multiFeatureIndex = options.multiFeatureIndex || 0;
var geometryIndex = options.geometryIndex || 0;
var segmentIndex = options.segmentIndex || 0;
// Find FeatureIndex
var properties = options.properties;
var geometry;
switch (geojson.type) {
case "FeatureCollection":
if (featureIndex < 0)
featureIndex = geojson.features.length + featureIndex;
properties = properties || geojson.features[featureIndex].properties;
geometry = geojson.features[featureIndex].geometry;
break;
case "Feature":
properties = properties || geojson.properties;
geometry = geojson.geometry;
break;
case "Point":
case "MultiPoint":
return null;
case "LineString":
case "Polygon":
case "MultiLineString":
case "MultiPolygon":
geometry = geojson;
break;
default:
throw new Error("geojson is invalid");
}
// Find SegmentIndex
if (geometry === null) return null;
var coords = geometry.coordinates;
switch (geometry.type) {
case "Point":
case "MultiPoint":
return null;
case "LineString":
if (segmentIndex < 0) segmentIndex = coords.length + segmentIndex - 1;
return helpers.lineString(
[coords[segmentIndex], coords[segmentIndex + 1]],
properties,
options
);
case "Polygon":
if (geometryIndex < 0) geometryIndex = coords.length + geometryIndex;
if (segmentIndex < 0)
segmentIndex = coords[geometryIndex].length + segmentIndex - 1;
return helpers.lineString(
[
coords[geometryIndex][segmentIndex],
coords[geometryIndex][segmentIndex + 1],
],
properties,
options
);
case "MultiLineString":
if (multiFeatureIndex < 0)
multiFeatureIndex = coords.length + multiFeatureIndex;
if (segmentIndex < 0)
segmentIndex = coords[multiFeatureIndex].length + segmentIndex - 1;
return helpers.lineString(
[
coords[multiFeatureIndex][segmentIndex],
coords[multiFeatureIndex][segmentIndex + 1],
],
properties,
options
);
case "MultiPolygon":
if (multiFeatureIndex < 0)
multiFeatureIndex = coords.length + multiFeatureIndex;
if (geometryIndex < 0)
geometryIndex = coords[multiFeatureIndex].length + geometryIndex;
if (segmentIndex < 0)
segmentIndex =
coords[multiFeatureIndex][geometryIndex].length - segmentIndex - 1;
return helpers.lineString(
[
coords[multiFeatureIndex][geometryIndex][segmentIndex],
coords[multiFeatureIndex][geometryIndex][segmentIndex + 1],
],
properties,
options
);
}
throw new Error("geojson is invalid");
}
/**
* Finds a particular Point from a GeoJSON using `@turf/meta` indexes.
*
* Negative indexes are permitted.
*
* @param {FeatureCollection|Feature|Geometry} geojson Any GeoJSON Feature or Geometry
* @param {Object} [options={}] Optional parameters
* @param {number} [options.featureIndex=0] Feature Index
* @param {number} [options.multiFeatureIndex=0] Multi-Feature Index
* @param {number} [options.geometryIndex=0] Geometry Index
* @param {number} [options.coordIndex=0] Coord Index
* @param {Object} [options.properties={}] Translate Properties to output Point
* @param {BBox} [options.bbox={}] Translate BBox to output Point
* @param {number|string} [options.id={}] Translate Id to output Point
* @returns {Feature} 2-vertex GeoJSON Feature Point
* @example
* var multiLine = turf.multiLineString([
* [[10, 10], [50, 30], [30, 40]],
* [[-10, -10], [-50, -30], [-30, -40]]
* ]);
*
* // First Segment (defaults are 0)
* turf.findPoint(multiLine);
* // => Feature>
*
* // First Segment of the 2nd Multi-Feature
* turf.findPoint(multiLine, {multiFeatureIndex: 1});
* // => Feature>
*
* // Last Segment of last Multi-Feature
* turf.findPoint(multiLine, {multiFeatureIndex: -1, coordIndex: -1});
* // => Feature>
*/
function findPoint(geojson, options) {
// Optional Parameters
options = options || {};
if (!helpers.isObject(options)) throw new Error("options is invalid");
var featureIndex = options.featureIndex || 0;
var multiFeatureIndex = options.multiFeatureIndex || 0;
var geometryIndex = options.geometryIndex || 0;
var coordIndex = options.coordIndex || 0;
// Find FeatureIndex
var properties = options.properties;
var geometry;
switch (geojson.type) {
case "FeatureCollection":
if (featureIndex < 0)
featureIndex = geojson.features.length + featureIndex;
properties = properties || geojson.features[featureIndex].properties;
geometry = geojson.features[featureIndex].geometry;
break;
case "Feature":
properties = properties || geojson.properties;
geometry = geojson.geometry;
break;
case "Point":
case "MultiPoint":
return null;
case "LineString":
case "Polygon":
case "MultiLineString":
case "MultiPolygon":
geometry = geojson;
break;
default:
throw new Error("geojson is invalid");
}
// Find Coord Index
if (geometry === null) return null;
var coords = geometry.coordinates;
switch (geometry.type) {
case "Point":
return helpers.point(coords, properties, options);
case "MultiPoint":
if (multiFeatureIndex < 0)
multiFeatureIndex = coords.length + multiFeatureIndex;
return helpers.point(coords[multiFeatureIndex], properties, options);
case "LineString":
if (coordIndex < 0) coordIndex = coords.length + coordIndex;
return helpers.point(coords[coordIndex], properties, options);
case "Polygon":
if (geometryIndex < 0) geometryIndex = coords.length + geometryIndex;
if (coordIndex < 0)
coordIndex = coords[geometryIndex].length + coordIndex;
return helpers.point(coords[geometryIndex][coordIndex], properties, options);
case "MultiLineString":
if (multiFeatureIndex < 0)
multiFeatureIndex = coords.length + multiFeatureIndex;
if (coordIndex < 0)
coordIndex = coords[multiFeatureIndex].length + coordIndex;
return helpers.point(coords[multiFeatureIndex][coordIndex], properties, options);
case "MultiPolygon":
if (multiFeatureIndex < 0)
multiFeatureIndex = coords.length + multiFeatureIndex;
if (geometryIndex < 0)
geometryIndex = coords[multiFeatureIndex].length + geometryIndex;
if (coordIndex < 0)
coordIndex =
coords[multiFeatureIndex][geometryIndex].length - coordIndex;
return helpers.point(
coords[multiFeatureIndex][geometryIndex][coordIndex],
properties,
options
);
}
throw new Error("geojson is invalid");
}
exports.coordEach = coordEach;
exports.coordReduce = coordReduce;
exports.propEach = propEach;
exports.propReduce = propReduce;
exports.featureEach = featureEach;
exports.featureReduce = featureReduce;
exports.coordAll = coordAll;
exports.geomEach = geomEach;
exports.geomReduce = geomReduce;
exports.flattenEach = flattenEach;
exports.flattenReduce = flattenReduce;
exports.segmentEach = segmentEach;
exports.segmentReduce = segmentReduce;
exports.lineEach = lineEach;
exports.lineReduce = lineReduce;
exports.findSegment = findSegment;
exports.findPoint = findPoint;
/***/ }),
/***/ 2428:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
var meta_1 = __webpack_require__(2500);
/**
* Takes a set of features, calculates the bbox of all input features, and returns a bounding box.
*
* @name bbox
* @param {GeoJSON} geojson any GeoJSON object
* @returns {BBox} bbox extent in [minX, minY, maxX, maxY] order
* @example
* var line = turf.lineString([[-74, 40], [-78, 42], [-82, 35]]);
* var bbox = turf.bbox(line);
* var bboxPolygon = turf.bboxPolygon(bbox);
*
* //addToMap
* var addToMap = [line, bboxPolygon]
*/
function bbox(geojson) {
var result = [Infinity, Infinity, -Infinity, -Infinity];
meta_1.coordEach(geojson, function (coord) {
if (result[0] > coord[0]) {
result[0] = coord[0];
}
if (result[1] > coord[1]) {
result[1] = coord[1];
}
if (result[2] < coord[0]) {
result[2] = coord[0];
}
if (result[3] < coord[1]) {
result[3] = coord[1];
}
});
return result;
}
bbox["default"] = bbox;
exports["default"] = bbox;
/***/ }),
/***/ 6796:
/***/ (function(__unused_webpack_module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
/**
* @module helpers
*/
/**
* Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.
*
* @memberof helpers
* @type {number}
*/
exports.earthRadius = 6371008.8;
/**
* Unit of measurement factors using a spherical (non-ellipsoid) earth radius.
*
* @memberof helpers
* @type {Object}
*/
exports.factors = {
centimeters: exports.earthRadius * 100,
centimetres: exports.earthRadius * 100,
degrees: exports.earthRadius / 111325,
feet: exports.earthRadius * 3.28084,
inches: exports.earthRadius * 39.37,
kilometers: exports.earthRadius / 1000,
kilometres: exports.earthRadius / 1000,
meters: exports.earthRadius,
metres: exports.earthRadius,
miles: exports.earthRadius / 1609.344,
millimeters: exports.earthRadius * 1000,
millimetres: exports.earthRadius * 1000,
nauticalmiles: exports.earthRadius / 1852,
radians: 1,
yards: exports.earthRadius * 1.0936,
};
/**
* Units of measurement factors based on 1 meter.
*
* @memberof helpers
* @type {Object}
*/
exports.unitsFactors = {
centimeters: 100,
centimetres: 100,
degrees: 1 / 111325,
feet: 3.28084,
inches: 39.37,
kilometers: 1 / 1000,
kilometres: 1 / 1000,
meters: 1,
metres: 1,
miles: 1 / 1609.344,
millimeters: 1000,
millimetres: 1000,
nauticalmiles: 1 / 1852,
radians: 1 / exports.earthRadius,
yards: 1.0936133,
};
/**
* Area of measurement factors based on 1 square meter.
*
* @memberof helpers
* @type {Object}
*/
exports.areaFactors = {
acres: 0.000247105,
centimeters: 10000,
centimetres: 10000,
feet: 10.763910417,
hectares: 0.0001,
inches: 1550.003100006,
kilometers: 0.000001,
kilometres: 0.000001,
meters: 1,
metres: 1,
miles: 3.86e-7,
millimeters: 1000000,
millimetres: 1000000,
yards: 1.195990046,
};
/**
* Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.
*
* @name feature
* @param {Geometry} geometry input geometry
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a GeoJSON Feature
* @example
* var geometry = {
* "type": "Point",
* "coordinates": [110, 50]
* };
*
* var feature = turf.feature(geometry);
*
* //=feature
*/
function feature(geom, properties, options) {
if (options === void 0) { options = {}; }
var feat = { type: "Feature" };
if (options.id === 0 || options.id) {
feat.id = options.id;
}
if (options.bbox) {
feat.bbox = options.bbox;
}
feat.properties = properties || {};
feat.geometry = geom;
return feat;
}
exports.feature = feature;
/**
* Creates a GeoJSON {@link Geometry} from a Geometry string type & coordinates.
* For GeometryCollection type use `helpers.geometryCollection`
*
* @name geometry
* @param {string} type Geometry Type
* @param {Array} coordinates Coordinates
* @param {Object} [options={}] Optional Parameters
* @returns {Geometry} a GeoJSON Geometry
* @example
* var type = "Point";
* var coordinates = [110, 50];
* var geometry = turf.geometry(type, coordinates);
* // => geometry
*/
function geometry(type, coordinates, _options) {
if (_options === void 0) { _options = {}; }
switch (type) {
case "Point":
return point(coordinates).geometry;
case "LineString":
return lineString(coordinates).geometry;
case "Polygon":
return polygon(coordinates).geometry;
case "MultiPoint":
return multiPoint(coordinates).geometry;
case "MultiLineString":
return multiLineString(coordinates).geometry;
case "MultiPolygon":
return multiPolygon(coordinates).geometry;
default:
throw new Error(type + " is invalid");
}
}
exports.geometry = geometry;
/**
* Creates a {@link Point} {@link Feature} from a Position.
*
* @name point
* @param {Array} coordinates longitude, latitude position (each in decimal degrees)
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a Point feature
* @example
* var point = turf.point([-75.343, 39.984]);
*
* //=point
*/
function point(coordinates, properties, options) {
if (options === void 0) { options = {}; }
if (!coordinates) {
throw new Error("coordinates is required");
}
if (!Array.isArray(coordinates)) {
throw new Error("coordinates must be an Array");
}
if (coordinates.length < 2) {
throw new Error("coordinates must be at least 2 numbers long");
}
if (!isNumber(coordinates[0]) || !isNumber(coordinates[1])) {
throw new Error("coordinates must contain numbers");
}
var geom = {
type: "Point",
coordinates: coordinates,
};
return feature(geom, properties, options);
}
exports.point = point;
/**
* Creates a {@link Point} {@link FeatureCollection} from an Array of Point coordinates.
*
* @name points
* @param {Array>} coordinates an array of Points
* @param {Object} [properties={}] Translate these properties to each Feature
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north]
* associated with the FeatureCollection
* @param {string|number} [options.id] Identifier associated with the FeatureCollection
* @returns {FeatureCollection} Point Feature
* @example
* var points = turf.points([
* [-75, 39],
* [-80, 45],
* [-78, 50]
* ]);
*
* //=points
*/
function points(coordinates, properties, options) {
if (options === void 0) { options = {}; }
return featureCollection(coordinates.map(function (coords) {
return point(coords, properties);
}), options);
}
exports.points = points;
/**
* Creates a {@link Polygon} {@link Feature} from an Array of LinearRings.
*
* @name polygon
* @param {Array>>} coordinates an array of LinearRings
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} Polygon Feature
* @example
* var polygon = turf.polygon([[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]], { name: 'poly1' });
*
* //=polygon
*/
function polygon(coordinates, properties, options) {
if (options === void 0) { options = {}; }
for (var _i = 0, coordinates_1 = coordinates; _i < coordinates_1.length; _i++) {
var ring = coordinates_1[_i];
if (ring.length < 4) {
throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");
}
for (var j = 0; j < ring[ring.length - 1].length; j++) {
// Check if first point of Polygon contains two numbers
if (ring[ring.length - 1][j] !== ring[0][j]) {
throw new Error("First and last Position are not equivalent.");
}
}
}
var geom = {
type: "Polygon",
coordinates: coordinates,
};
return feature(geom, properties, options);
}
exports.polygon = polygon;
/**
* Creates a {@link Polygon} {@link FeatureCollection} from an Array of Polygon coordinates.
*
* @name polygons
* @param {Array>>>} coordinates an array of Polygon coordinates
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the FeatureCollection
* @returns {FeatureCollection} Polygon FeatureCollection
* @example
* var polygons = turf.polygons([
* [[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]],
* [[[-15, 42], [-14, 46], [-12, 41], [-17, 44], [-15, 42]]],
* ]);
*
* //=polygons
*/
function polygons(coordinates, properties, options) {
if (options === void 0) { options = {}; }
return featureCollection(coordinates.map(function (coords) {
return polygon(coords, properties);
}), options);
}
exports.polygons = polygons;
/**
* Creates a {@link LineString} {@link Feature} from an Array of Positions.
*
* @name lineString
* @param {Array>} coordinates an array of Positions
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} LineString Feature
* @example
* var linestring1 = turf.lineString([[-24, 63], [-23, 60], [-25, 65], [-20, 69]], {name: 'line 1'});
* var linestring2 = turf.lineString([[-14, 43], [-13, 40], [-15, 45], [-10, 49]], {name: 'line 2'});
*
* //=linestring1
* //=linestring2
*/
function lineString(coordinates, properties, options) {
if (options === void 0) { options = {}; }
if (coordinates.length < 2) {
throw new Error("coordinates must be an array of two or more positions");
}
var geom = {
type: "LineString",
coordinates: coordinates,
};
return feature(geom, properties, options);
}
exports.lineString = lineString;
/**
* Creates a {@link LineString} {@link FeatureCollection} from an Array of LineString coordinates.
*
* @name lineStrings
* @param {Array>>} coordinates an array of LinearRings
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north]
* associated with the FeatureCollection
* @param {string|number} [options.id] Identifier associated with the FeatureCollection
* @returns {FeatureCollection} LineString FeatureCollection
* @example
* var linestrings = turf.lineStrings([
* [[-24, 63], [-23, 60], [-25, 65], [-20, 69]],
* [[-14, 43], [-13, 40], [-15, 45], [-10, 49]]
* ]);
*
* //=linestrings
*/
function lineStrings(coordinates, properties, options) {
if (options === void 0) { options = {}; }
return featureCollection(coordinates.map(function (coords) {
return lineString(coords, properties);
}), options);
}
exports.lineStrings = lineStrings;
/**
* Takes one or more {@link Feature|Features} and creates a {@link FeatureCollection}.
*
* @name featureCollection
* @param {Feature[]} features input features
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {FeatureCollection} FeatureCollection of Features
* @example
* var locationA = turf.point([-75.343, 39.984], {name: 'Location A'});
* var locationB = turf.point([-75.833, 39.284], {name: 'Location B'});
* var locationC = turf.point([-75.534, 39.123], {name: 'Location C'});
*
* var collection = turf.featureCollection([
* locationA,
* locationB,
* locationC
* ]);
*
* //=collection
*/
function featureCollection(features, options) {
if (options === void 0) { options = {}; }
var fc = { type: "FeatureCollection" };
if (options.id) {
fc.id = options.id;
}
if (options.bbox) {
fc.bbox = options.bbox;
}
fc.features = features;
return fc;
}
exports.featureCollection = featureCollection;
/**
* Creates a {@link Feature} based on a
* coordinate array. Properties can be added optionally.
*
* @name multiLineString
* @param {Array>>} coordinates an array of LineStrings
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a MultiLineString feature
* @throws {Error} if no coordinates are passed
* @example
* var multiLine = turf.multiLineString([[[0,0],[10,10]]]);
*
* //=multiLine
*/
function multiLineString(coordinates, properties, options) {
if (options === void 0) { options = {}; }
var geom = {
type: "MultiLineString",
coordinates: coordinates,
};
return feature(geom, properties, options);
}
exports.multiLineString = multiLineString;
/**
* Creates a {@link Feature} based on a
* coordinate array. Properties can be added optionally.
*
* @name multiPoint
* @param {Array>} coordinates an array of Positions
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a MultiPoint feature
* @throws {Error} if no coordinates are passed
* @example
* var multiPt = turf.multiPoint([[0,0],[10,10]]);
*
* //=multiPt
*/
function multiPoint(coordinates, properties, options) {
if (options === void 0) { options = {}; }
var geom = {
type: "MultiPoint",
coordinates: coordinates,
};
return feature(geom, properties, options);
}
exports.multiPoint = multiPoint;
/**
* Creates a {@link Feature} based on a
* coordinate array. Properties can be added optionally.
*
* @name multiPolygon
* @param {Array>>>} coordinates an array of Polygons
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a multipolygon feature
* @throws {Error} if no coordinates are passed
* @example
* var multiPoly = turf.multiPolygon([[[[0,0],[0,10],[10,10],[10,0],[0,0]]]]);
*
* //=multiPoly
*
*/
function multiPolygon(coordinates, properties, options) {
if (options === void 0) { options = {}; }
var geom = {
type: "MultiPolygon",
coordinates: coordinates,
};
return feature(geom, properties, options);
}
exports.multiPolygon = multiPolygon;
/**
* Creates a {@link Feature} based on a
* coordinate array. Properties can be added optionally.
*
* @name geometryCollection
* @param {Array} geometries an array of GeoJSON Geometries
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a GeoJSON GeometryCollection Feature
* @example
* var pt = turf.geometry("Point", [100, 0]);
* var line = turf.geometry("LineString", [[101, 0], [102, 1]]);
* var collection = turf.geometryCollection([pt, line]);
*
* // => collection
*/
function geometryCollection(geometries, properties, options) {
if (options === void 0) { options = {}; }
var geom = {
type: "GeometryCollection",
geometries: geometries,
};
return feature(geom, properties, options);
}
exports.geometryCollection = geometryCollection;
/**
* Round number to precision
*
* @param {number} num Number
* @param {number} [precision=0] Precision
* @returns {number} rounded number
* @example
* turf.round(120.4321)
* //=120
*
* turf.round(120.4321, 2)
* //=120.43
*/
function round(num, precision) {
if (precision === void 0) { precision = 0; }
if (precision && !(precision >= 0)) {
throw new Error("precision must be a positive number");
}
var multiplier = Math.pow(10, precision || 0);
return Math.round(num * multiplier) / multiplier;
}
exports.round = round;
/**
* Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
*
* @name radiansToLength
* @param {number} radians in radians across the sphere
* @param {string} [units="kilometers"] can be degrees, radians, miles, inches, yards, metres,
* meters, kilometres, kilometers.
* @returns {number} distance
*/
function radiansToLength(radians, units) {
if (units === void 0) { units = "kilometers"; }
var factor = exports.factors[units];
if (!factor) {
throw new Error(units + " units is invalid");
}
return radians * factor;
}
exports.radiansToLength = radiansToLength;
/**
* Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
*
* @name lengthToRadians
* @param {number} distance in real units
* @param {string} [units="kilometers"] can be degrees, radians, miles, inches, yards, metres,
* meters, kilometres, kilometers.
* @returns {number} radians
*/
function lengthToRadians(distance, units) {
if (units === void 0) { units = "kilometers"; }
var factor = exports.factors[units];
if (!factor) {
throw new Error(units + " units is invalid");
}
return distance / factor;
}
exports.lengthToRadians = lengthToRadians;
/**
* Convert a distance measurement (assuming a spherical Earth) from a real-world unit into degrees
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, centimeters, kilometres, feet
*
* @name lengthToDegrees
* @param {number} distance in real units
* @param {string} [units="kilometers"] can be degrees, radians, miles, inches, yards, metres,
* meters, kilometres, kilometers.
* @returns {number} degrees
*/
function lengthToDegrees(distance, units) {
return radiansToDegrees(lengthToRadians(distance, units));
}
exports.lengthToDegrees = lengthToDegrees;
/**
* Converts any bearing angle from the north line direction (positive clockwise)
* and returns an angle between 0-360 degrees (positive clockwise), 0 being the north line
*
* @name bearingToAzimuth
* @param {number} bearing angle, between -180 and +180 degrees
* @returns {number} angle between 0 and 360 degrees
*/
function bearingToAzimuth(bearing) {
var angle = bearing % 360;
if (angle < 0) {
angle += 360;
}
return angle;
}
exports.bearingToAzimuth = bearingToAzimuth;
/**
* Converts an angle in radians to degrees
*
* @name radiansToDegrees
* @param {number} radians angle in radians
* @returns {number} degrees between 0 and 360 degrees
*/
function radiansToDegrees(radians) {
var degrees = radians % (2 * Math.PI);
return (degrees * 180) / Math.PI;
}
exports.radiansToDegrees = radiansToDegrees;
/**
* Converts an angle in degrees to radians
*
* @name degreesToRadians
* @param {number} degrees angle between 0 and 360 degrees
* @returns {number} angle in radians
*/
function degreesToRadians(degrees) {
var radians = degrees % 360;
return (radians * Math.PI) / 180;
}
exports.degreesToRadians = degreesToRadians;
/**
* Converts a length to the requested unit.
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
*
* @param {number} length to be converted
* @param {Units} [originalUnit="kilometers"] of the length
* @param {Units} [finalUnit="kilometers"] returned unit
* @returns {number} the converted length
*/
function convertLength(length, originalUnit, finalUnit) {
if (originalUnit === void 0) { originalUnit = "kilometers"; }
if (finalUnit === void 0) { finalUnit = "kilometers"; }
if (!(length >= 0)) {
throw new Error("length must be a positive number");
}
return radiansToLength(lengthToRadians(length, originalUnit), finalUnit);
}
exports.convertLength = convertLength;
/**
* Converts a area to the requested unit.
* Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches, hectares
* @param {number} area to be converted
* @param {Units} [originalUnit="meters"] of the distance
* @param {Units} [finalUnit="kilometers"] returned unit
* @returns {number} the converted area
*/
function convertArea(area, originalUnit, finalUnit) {
if (originalUnit === void 0) { originalUnit = "meters"; }
if (finalUnit === void 0) { finalUnit = "kilometers"; }
if (!(area >= 0)) {
throw new Error("area must be a positive number");
}
var startFactor = exports.areaFactors[originalUnit];
if (!startFactor) {
throw new Error("invalid original units");
}
var finalFactor = exports.areaFactors[finalUnit];
if (!finalFactor) {
throw new Error("invalid final units");
}
return (area / startFactor) * finalFactor;
}
exports.convertArea = convertArea;
/**
* isNumber
*
* @param {*} num Number to validate
* @returns {boolean} true/false
* @example
* turf.isNumber(123)
* //=true
* turf.isNumber('foo')
* //=false
*/
function isNumber(num) {
return !isNaN(num) && num !== null && !Array.isArray(num);
}
exports.isNumber = isNumber;
/**
* isObject
*
* @param {*} input variable to validate
* @returns {boolean} true/false
* @example
* turf.isObject({elevation: 10})
* //=true
* turf.isObject('foo')
* //=false
*/
function isObject(input) {
return !!input && input.constructor === Object;
}
exports.isObject = isObject;
/**
* Validate BBox
*
* @private
* @param {Array} bbox BBox to validate
* @returns {void}
* @throws Error if BBox is not valid
* @example
* validateBBox([-180, -40, 110, 50])
* //=OK
* validateBBox([-180, -40])
* //=Error
* validateBBox('Foo')
* //=Error
* validateBBox(5)
* //=Error
* validateBBox(null)
* //=Error
* validateBBox(undefined)
* //=Error
*/
function validateBBox(bbox) {
if (!bbox) {
throw new Error("bbox is required");
}
if (!Array.isArray(bbox)) {
throw new Error("bbox must be an Array");
}
if (bbox.length !== 4 && bbox.length !== 6) {
throw new Error("bbox must be an Array of 4 or 6 numbers");
}
bbox.forEach(function (num) {
if (!isNumber(num)) {
throw new Error("bbox must only contain numbers");
}
});
}
exports.validateBBox = validateBBox;
/**
* Validate Id
*
* @private
* @param {string|number} id Id to validate
* @returns {void}
* @throws Error if Id is not valid
* @example
* validateId([-180, -40, 110, 50])
* //=Error
* validateId([-180, -40])
* //=Error
* validateId('Foo')
* //=OK
* validateId(5)
* //=OK
* validateId(null)
* //=Error
* validateId(undefined)
* //=Error
*/
function validateId(id) {
if (!id) {
throw new Error("id is required");
}
if (["string", "number"].indexOf(typeof id) === -1) {
throw new Error("id must be a number or a string");
}
}
exports.validateId = validateId;
/***/ }),
/***/ 2500:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
var helpers = __webpack_require__(6796);
/**
* Callback for coordEach
*
* @callback coordEachCallback
* @param {Array} currentCoord The current coordinate being processed.
* @param {number} coordIndex The current index of the coordinate being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @param {number} geometryIndex The current index of the Geometry being processed.
*/
/**
* Iterate over coordinates in any GeoJSON object, similar to Array.forEach()
*
* @name coordEach
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (currentCoord, coordIndex, featureIndex, multiFeatureIndex)
* @param {boolean} [excludeWrapCoord=false] whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {"foo": "bar"}),
* turf.point([36, 53], {"hello": "world"})
* ]);
*
* turf.coordEach(features, function (currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {
* //=currentCoord
* //=coordIndex
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* });
*/
function coordEach(geojson, callback, excludeWrapCoord) {
// Handles null Geometry -- Skips this GeoJSON
if (geojson === null) return;
var j,
k,
l,
geometry,
stopG,
coords,
geometryMaybeCollection,
wrapShrink = 0,
coordIndex = 0,
isGeometryCollection,
type = geojson.type,
isFeatureCollection = type === "FeatureCollection",
isFeature = type === "Feature",
stop = isFeatureCollection ? geojson.features.length : 1;
// This logic may look a little weird. The reason why it is that way
// is because it's trying to be fast. GeoJSON supports multiple kinds
// of objects at its root: FeatureCollection, Features, Geometries.
// This function has the responsibility of handling all of them, and that
// means that some of the `for` loops you see below actually just don't apply
// to certain inputs. For instance, if you give this just a
// Point geometry, then both loops are short-circuited and all we do
// is gradually rename the input until it's called 'geometry'.
//
// This also aims to allocate as few resources as possible: just a
// few numbers and booleans, rather than any temporary arrays as would
// be required with the normalization approach.
for (var featureIndex = 0; featureIndex < stop; featureIndex++) {
geometryMaybeCollection = isFeatureCollection
? geojson.features[featureIndex].geometry
: isFeature
? geojson.geometry
: geojson;
isGeometryCollection = geometryMaybeCollection
? geometryMaybeCollection.type === "GeometryCollection"
: false;
stopG = isGeometryCollection
? geometryMaybeCollection.geometries.length
: 1;
for (var geomIndex = 0; geomIndex < stopG; geomIndex++) {
var multiFeatureIndex = 0;
var geometryIndex = 0;
geometry = isGeometryCollection
? geometryMaybeCollection.geometries[geomIndex]
: geometryMaybeCollection;
// Handles null Geometry -- Skips this geometry
if (geometry === null) continue;
coords = geometry.coordinates;
var geomType = geometry.type;
wrapShrink =
excludeWrapCoord &&
(geomType === "Polygon" || geomType === "MultiPolygon")
? 1
: 0;
switch (geomType) {
case null:
break;
case "Point":
if (
callback(
coords,
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false
)
return false;
coordIndex++;
multiFeatureIndex++;
break;
case "LineString":
case "MultiPoint":
for (j = 0; j < coords.length; j++) {
if (
callback(
coords[j],
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false
)
return false;
coordIndex++;
if (geomType === "MultiPoint") multiFeatureIndex++;
}
if (geomType === "LineString") multiFeatureIndex++;
break;
case "Polygon":
case "MultiLineString":
for (j = 0; j < coords.length; j++) {
for (k = 0; k < coords[j].length - wrapShrink; k++) {
if (
callback(
coords[j][k],
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false
)
return false;
coordIndex++;
}
if (geomType === "MultiLineString") multiFeatureIndex++;
if (geomType === "Polygon") geometryIndex++;
}
if (geomType === "Polygon") multiFeatureIndex++;
break;
case "MultiPolygon":
for (j = 0; j < coords.length; j++) {
geometryIndex = 0;
for (k = 0; k < coords[j].length; k++) {
for (l = 0; l < coords[j][k].length - wrapShrink; l++) {
if (
callback(
coords[j][k][l],
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) === false
)
return false;
coordIndex++;
}
geometryIndex++;
}
multiFeatureIndex++;
}
break;
case "GeometryCollection":
for (j = 0; j < geometry.geometries.length; j++)
if (
coordEach(geometry.geometries[j], callback, excludeWrapCoord) ===
false
)
return false;
break;
default:
throw new Error("Unknown Geometry Type");
}
}
}
}
/**
* Callback for coordReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback coordReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Array} currentCoord The current coordinate being processed.
* @param {number} coordIndex The current index of the coordinate being processed.
* Starts at index 0, if an initialValue is provided, and at index 1 otherwise.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @param {number} geometryIndex The current index of the Geometry being processed.
*/
/**
* Reduce coordinates in any GeoJSON object, similar to Array.reduce()
*
* @name coordReduce
* @param {FeatureCollection|Geometry|Feature} geojson any GeoJSON object
* @param {Function} callback a method that takes (previousValue, currentCoord, coordIndex)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @param {boolean} [excludeWrapCoord=false] whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.
* @returns {*} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {"foo": "bar"}),
* turf.point([36, 53], {"hello": "world"})
* ]);
*
* turf.coordReduce(features, function (previousValue, currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {
* //=previousValue
* //=currentCoord
* //=coordIndex
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* return currentCoord;
* });
*/
function coordReduce(geojson, callback, initialValue, excludeWrapCoord) {
var previousValue = initialValue;
coordEach(
geojson,
function (
currentCoord,
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
) {
if (coordIndex === 0 && initialValue === undefined)
previousValue = currentCoord;
else
previousValue = callback(
previousValue,
currentCoord,
coordIndex,
featureIndex,
multiFeatureIndex,
geometryIndex
);
},
excludeWrapCoord
);
return previousValue;
}
/**
* Callback for propEach
*
* @callback propEachCallback
* @param {Object} currentProperties The current Properties being processed.
* @param {number} featureIndex The current index of the Feature being processed.
*/
/**
* Iterate over properties in any GeoJSON object, similar to Array.forEach()
*
* @name propEach
* @param {FeatureCollection|Feature} geojson any GeoJSON object
* @param {Function} callback a method that takes (currentProperties, featureIndex)
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.propEach(features, function (currentProperties, featureIndex) {
* //=currentProperties
* //=featureIndex
* });
*/
function propEach(geojson, callback) {
var i;
switch (geojson.type) {
case "FeatureCollection":
for (i = 0; i < geojson.features.length; i++) {
if (callback(geojson.features[i].properties, i) === false) break;
}
break;
case "Feature":
callback(geojson.properties, 0);
break;
}
}
/**
* Callback for propReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback propReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {*} currentProperties The current Properties being processed.
* @param {number} featureIndex The current index of the Feature being processed.
*/
/**
* Reduce properties in any GeoJSON object into a single value,
* similar to how Array.reduce works. However, in this case we lazily run
* the reduction, so an array of all properties is unnecessary.
*
* @name propReduce
* @param {FeatureCollection|Feature} geojson any GeoJSON object
* @param {Function} callback a method that takes (previousValue, currentProperties, featureIndex)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {*} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.propReduce(features, function (previousValue, currentProperties, featureIndex) {
* //=previousValue
* //=currentProperties
* //=featureIndex
* return currentProperties
* });
*/
function propReduce(geojson, callback, initialValue) {
var previousValue = initialValue;
propEach(geojson, function (currentProperties, featureIndex) {
if (featureIndex === 0 && initialValue === undefined)
previousValue = currentProperties;
else
previousValue = callback(previousValue, currentProperties, featureIndex);
});
return previousValue;
}
/**
* Callback for featureEach
*
* @callback featureEachCallback
* @param {Feature} currentFeature The current Feature being processed.
* @param {number} featureIndex The current index of the Feature being processed.
*/
/**
* Iterate over features in any GeoJSON object, similar to
* Array.forEach.
*
* @name featureEach
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (currentFeature, featureIndex)
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.featureEach(features, function (currentFeature, featureIndex) {
* //=currentFeature
* //=featureIndex
* });
*/
function featureEach(geojson, callback) {
if (geojson.type === "Feature") {
callback(geojson, 0);
} else if (geojson.type === "FeatureCollection") {
for (var i = 0; i < geojson.features.length; i++) {
if (callback(geojson.features[i], i) === false) break;
}
}
}
/**
* Callback for featureReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback featureReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Feature} currentFeature The current Feature being processed.
* @param {number} featureIndex The current index of the Feature being processed.
*/
/**
* Reduce features in any GeoJSON object, similar to Array.reduce().
*
* @name featureReduce
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {*} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {"foo": "bar"}),
* turf.point([36, 53], {"hello": "world"})
* ]);
*
* turf.featureReduce(features, function (previousValue, currentFeature, featureIndex) {
* //=previousValue
* //=currentFeature
* //=featureIndex
* return currentFeature
* });
*/
function featureReduce(geojson, callback, initialValue) {
var previousValue = initialValue;
featureEach(geojson, function (currentFeature, featureIndex) {
if (featureIndex === 0 && initialValue === undefined)
previousValue = currentFeature;
else previousValue = callback(previousValue, currentFeature, featureIndex);
});
return previousValue;
}
/**
* Get all coordinates from any GeoJSON object.
*
* @name coordAll
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @returns {Array>} coordinate position array
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* var coords = turf.coordAll(features);
* //= [[26, 37], [36, 53]]
*/
function coordAll(geojson) {
var coords = [];
coordEach(geojson, function (coord) {
coords.push(coord);
});
return coords;
}
/**
* Callback for geomEach
*
* @callback geomEachCallback
* @param {Geometry} currentGeometry The current Geometry being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {Object} featureProperties The current Feature Properties being processed.
* @param {Array} featureBBox The current Feature BBox being processed.
* @param {number|string} featureId The current Feature Id being processed.
*/
/**
* Iterate over each geometry in any GeoJSON object, similar to Array.forEach()
*
* @name geomEach
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (currentGeometry, featureIndex, featureProperties, featureBBox, featureId)
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.geomEach(features, function (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {
* //=currentGeometry
* //=featureIndex
* //=featureProperties
* //=featureBBox
* //=featureId
* });
*/
function geomEach(geojson, callback) {
var i,
j,
g,
geometry,
stopG,
geometryMaybeCollection,
isGeometryCollection,
featureProperties,
featureBBox,
featureId,
featureIndex = 0,
isFeatureCollection = geojson.type === "FeatureCollection",
isFeature = geojson.type === "Feature",
stop = isFeatureCollection ? geojson.features.length : 1;
// This logic may look a little weird. The reason why it is that way
// is because it's trying to be fast. GeoJSON supports multiple kinds
// of objects at its root: FeatureCollection, Features, Geometries.
// This function has the responsibility of handling all of them, and that
// means that some of the `for` loops you see below actually just don't apply
// to certain inputs. For instance, if you give this just a
// Point geometry, then both loops are short-circuited and all we do
// is gradually rename the input until it's called 'geometry'.
//
// This also aims to allocate as few resources as possible: just a
// few numbers and booleans, rather than any temporary arrays as would
// be required with the normalization approach.
for (i = 0; i < stop; i++) {
geometryMaybeCollection = isFeatureCollection
? geojson.features[i].geometry
: isFeature
? geojson.geometry
: geojson;
featureProperties = isFeatureCollection
? geojson.features[i].properties
: isFeature
? geojson.properties
: {};
featureBBox = isFeatureCollection
? geojson.features[i].bbox
: isFeature
? geojson.bbox
: undefined;
featureId = isFeatureCollection
? geojson.features[i].id
: isFeature
? geojson.id
: undefined;
isGeometryCollection = geometryMaybeCollection
? geometryMaybeCollection.type === "GeometryCollection"
: false;
stopG = isGeometryCollection
? geometryMaybeCollection.geometries.length
: 1;
for (g = 0; g < stopG; g++) {
geometry = isGeometryCollection
? geometryMaybeCollection.geometries[g]
: geometryMaybeCollection;
// Handle null Geometry
if (geometry === null) {
if (
callback(
null,
featureIndex,
featureProperties,
featureBBox,
featureId
) === false
)
return false;
continue;
}
switch (geometry.type) {
case "Point":
case "LineString":
case "MultiPoint":
case "Polygon":
case "MultiLineString":
case "MultiPolygon": {
if (
callback(
geometry,
featureIndex,
featureProperties,
featureBBox,
featureId
) === false
)
return false;
break;
}
case "GeometryCollection": {
for (j = 0; j < geometry.geometries.length; j++) {
if (
callback(
geometry.geometries[j],
featureIndex,
featureProperties,
featureBBox,
featureId
) === false
)
return false;
}
break;
}
default:
throw new Error("Unknown Geometry Type");
}
}
// Only increase `featureIndex` per each feature
featureIndex++;
}
}
/**
* Callback for geomReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback geomReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Geometry} currentGeometry The current Geometry being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {Object} featureProperties The current Feature Properties being processed.
* @param {Array} featureBBox The current Feature BBox being processed.
* @param {number|string} featureId The current Feature Id being processed.
*/
/**
* Reduce geometry in any GeoJSON object, similar to Array.reduce().
*
* @name geomReduce
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {*} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.geomReduce(features, function (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {
* //=previousValue
* //=currentGeometry
* //=featureIndex
* //=featureProperties
* //=featureBBox
* //=featureId
* return currentGeometry
* });
*/
function geomReduce(geojson, callback, initialValue) {
var previousValue = initialValue;
geomEach(
geojson,
function (
currentGeometry,
featureIndex,
featureProperties,
featureBBox,
featureId
) {
if (featureIndex === 0 && initialValue === undefined)
previousValue = currentGeometry;
else
previousValue = callback(
previousValue,
currentGeometry,
featureIndex,
featureProperties,
featureBBox,
featureId
);
}
);
return previousValue;
}
/**
* Callback for flattenEach
*
* @callback flattenEachCallback
* @param {Feature} currentFeature The current flattened feature being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
*/
/**
* Iterate over flattened features in any GeoJSON object, similar to
* Array.forEach.
*
* @name flattenEach
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (currentFeature, featureIndex, multiFeatureIndex)
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.multiPoint([[40, 30], [36, 53]], {hello: 'world'})
* ]);
*
* turf.flattenEach(features, function (currentFeature, featureIndex, multiFeatureIndex) {
* //=currentFeature
* //=featureIndex
* //=multiFeatureIndex
* });
*/
function flattenEach(geojson, callback) {
geomEach(geojson, function (geometry, featureIndex, properties, bbox, id) {
// Callback for single geometry
var type = geometry === null ? null : geometry.type;
switch (type) {
case null:
case "Point":
case "LineString":
case "Polygon":
if (
callback(
helpers.feature(geometry, properties, { bbox: bbox, id: id }),
featureIndex,
0
) === false
)
return false;
return;
}
var geomType;
// Callback for multi-geometry
switch (type) {
case "MultiPoint":
geomType = "Point";
break;
case "MultiLineString":
geomType = "LineString";
break;
case "MultiPolygon":
geomType = "Polygon";
break;
}
for (
var multiFeatureIndex = 0;
multiFeatureIndex < geometry.coordinates.length;
multiFeatureIndex++
) {
var coordinate = geometry.coordinates[multiFeatureIndex];
var geom = {
type: geomType,
coordinates: coordinate,
};
if (
callback(helpers.feature(geom, properties), featureIndex, multiFeatureIndex) ===
false
)
return false;
}
});
}
/**
* Callback for flattenReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback flattenReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Feature} currentFeature The current Feature being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
*/
/**
* Reduce flattened features in any GeoJSON object, similar to Array.reduce().
*
* @name flattenReduce
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex, multiFeatureIndex)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {*} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.multiPoint([[40, 30], [36, 53]], {hello: 'world'})
* ]);
*
* turf.flattenReduce(features, function (previousValue, currentFeature, featureIndex, multiFeatureIndex) {
* //=previousValue
* //=currentFeature
* //=featureIndex
* //=multiFeatureIndex
* return currentFeature
* });
*/
function flattenReduce(geojson, callback, initialValue) {
var previousValue = initialValue;
flattenEach(
geojson,
function (currentFeature, featureIndex, multiFeatureIndex) {
if (
featureIndex === 0 &&
multiFeatureIndex === 0 &&
initialValue === undefined
)
previousValue = currentFeature;
else
previousValue = callback(
previousValue,
currentFeature,
featureIndex,
multiFeatureIndex
);
}
);
return previousValue;
}
/**
* Callback for segmentEach
*
* @callback segmentEachCallback
* @param {Feature} currentSegment The current Segment being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @param {number} geometryIndex The current index of the Geometry being processed.
* @param {number} segmentIndex The current index of the Segment being processed.
* @returns {void}
*/
/**
* Iterate over 2-vertex line segment in any GeoJSON object, similar to Array.forEach()
* (Multi)Point geometries do not contain segments therefore they are ignored during this operation.
*
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON
* @param {Function} callback a method that takes (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex)
* @returns {void}
* @example
* var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
*
* // Iterate over GeoJSON by 2-vertex segments
* turf.segmentEach(polygon, function (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {
* //=currentSegment
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* //=segmentIndex
* });
*
* // Calculate the total number of segments
* var total = 0;
* turf.segmentEach(polygon, function () {
* total++;
* });
*/
function segmentEach(geojson, callback) {
flattenEach(geojson, function (feature, featureIndex, multiFeatureIndex) {
var segmentIndex = 0;
// Exclude null Geometries
if (!feature.geometry) return;
// (Multi)Point geometries do not contain segments therefore they are ignored during this operation.
var type = feature.geometry.type;
if (type === "Point" || type === "MultiPoint") return;
// Generate 2-vertex line segments
var previousCoords;
var previousFeatureIndex = 0;
var previousMultiIndex = 0;
var prevGeomIndex = 0;
if (
coordEach(
feature,
function (
currentCoord,
coordIndex,
featureIndexCoord,
multiPartIndexCoord,
geometryIndex
) {
// Simulating a meta.coordReduce() since `reduce` operations cannot be stopped by returning `false`
if (
previousCoords === undefined ||
featureIndex > previousFeatureIndex ||
multiPartIndexCoord > previousMultiIndex ||
geometryIndex > prevGeomIndex
) {
previousCoords = currentCoord;
previousFeatureIndex = featureIndex;
previousMultiIndex = multiPartIndexCoord;
prevGeomIndex = geometryIndex;
segmentIndex = 0;
return;
}
var currentSegment = helpers.lineString(
[previousCoords, currentCoord],
feature.properties
);
if (
callback(
currentSegment,
featureIndex,
multiFeatureIndex,
geometryIndex,
segmentIndex
) === false
)
return false;
segmentIndex++;
previousCoords = currentCoord;
}
) === false
)
return false;
});
}
/**
* Callback for segmentReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback segmentReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Feature} currentSegment The current Segment being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @param {number} geometryIndex The current index of the Geometry being processed.
* @param {number} segmentIndex The current index of the Segment being processed.
*/
/**
* Reduce 2-vertex line segment in any GeoJSON object, similar to Array.reduce()
* (Multi)Point geometries do not contain segments therefore they are ignored during this operation.
*
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON
* @param {Function} callback a method that takes (previousValue, currentSegment, currentIndex)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {void}
* @example
* var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
*
* // Iterate over GeoJSON by 2-vertex segments
* turf.segmentReduce(polygon, function (previousSegment, currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {
* //= previousSegment
* //= currentSegment
* //= featureIndex
* //= multiFeatureIndex
* //= geometryIndex
* //= segmentIndex
* return currentSegment
* });
*
* // Calculate the total number of segments
* var initialValue = 0
* var total = turf.segmentReduce(polygon, function (previousValue) {
* previousValue++;
* return previousValue;
* }, initialValue);
*/
function segmentReduce(geojson, callback, initialValue) {
var previousValue = initialValue;
var started = false;
segmentEach(
geojson,
function (
currentSegment,
featureIndex,
multiFeatureIndex,
geometryIndex,
segmentIndex
) {
if (started === false && initialValue === undefined)
previousValue = currentSegment;
else
previousValue = callback(
previousValue,
currentSegment,
featureIndex,
multiFeatureIndex,
geometryIndex,
segmentIndex
);
started = true;
}
);
return previousValue;
}
/**
* Callback for lineEach
*
* @callback lineEachCallback
* @param {Feature} currentLine The current LineString|LinearRing being processed
* @param {number} featureIndex The current index of the Feature being processed
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed
* @param {number} geometryIndex The current index of the Geometry being processed
*/
/**
* Iterate over line or ring coordinates in LineString, Polygon, MultiLineString, MultiPolygon Features or Geometries,
* similar to Array.forEach.
*
* @name lineEach
* @param {Geometry|Feature} geojson object
* @param {Function} callback a method that takes (currentLine, featureIndex, multiFeatureIndex, geometryIndex)
* @example
* var multiLine = turf.multiLineString([
* [[26, 37], [35, 45]],
* [[36, 53], [38, 50], [41, 55]]
* ]);
*
* turf.lineEach(multiLine, function (currentLine, featureIndex, multiFeatureIndex, geometryIndex) {
* //=currentLine
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* });
*/
function lineEach(geojson, callback) {
// validation
if (!geojson) throw new Error("geojson is required");
flattenEach(geojson, function (feature, featureIndex, multiFeatureIndex) {
if (feature.geometry === null) return;
var type = feature.geometry.type;
var coords = feature.geometry.coordinates;
switch (type) {
case "LineString":
if (callback(feature, featureIndex, multiFeatureIndex, 0, 0) === false)
return false;
break;
case "Polygon":
for (
var geometryIndex = 0;
geometryIndex < coords.length;
geometryIndex++
) {
if (
callback(
helpers.lineString(coords[geometryIndex], feature.properties),
featureIndex,
multiFeatureIndex,
geometryIndex
) === false
)
return false;
}
break;
}
});
}
/**
* Callback for lineReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback lineReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Feature} currentLine The current LineString|LinearRing being processed.
* @param {number} featureIndex The current index of the Feature being processed
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed
* @param {number} geometryIndex The current index of the Geometry being processed
*/
/**
* Reduce features in any GeoJSON object, similar to Array.reduce().
*
* @name lineReduce
* @param {Geometry|Feature} geojson object
* @param {Function} callback a method that takes (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {*} The value that results from the reduction.
* @example
* var multiPoly = turf.multiPolygon([
* turf.polygon([[[12,48],[2,41],[24,38],[12,48]], [[9,44],[13,41],[13,45],[9,44]]]),
* turf.polygon([[[5, 5], [0, 0], [2, 2], [4, 4], [5, 5]]])
* ]);
*
* turf.lineReduce(multiPoly, function (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex) {
* //=previousValue
* //=currentLine
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* return currentLine
* });
*/
function lineReduce(geojson, callback, initialValue) {
var previousValue = initialValue;
lineEach(
geojson,
function (currentLine, featureIndex, multiFeatureIndex, geometryIndex) {
if (featureIndex === 0 && initialValue === undefined)
previousValue = currentLine;
else
previousValue = callback(
previousValue,
currentLine,
featureIndex,
multiFeatureIndex,
geometryIndex
);
}
);
return previousValue;
}
/**
* Finds a particular 2-vertex LineString Segment from a GeoJSON using `@turf/meta` indexes.
*
* Negative indexes are permitted.
* Point & MultiPoint will always return null.
*
* @param {FeatureCollection|Feature|Geometry} geojson Any GeoJSON Feature or Geometry
* @param {Object} [options={}] Optional parameters
* @param {number} [options.featureIndex=0] Feature Index
* @param {number} [options.multiFeatureIndex=0] Multi-Feature Index
* @param {number} [options.geometryIndex=0] Geometry Index
* @param {number} [options.segmentIndex=0] Segment Index
* @param {Object} [options.properties={}] Translate Properties to output LineString
* @param {BBox} [options.bbox={}] Translate BBox to output LineString
* @param {number|string} [options.id={}] Translate Id to output LineString
* @returns {Feature} 2-vertex GeoJSON Feature LineString
* @example
* var multiLine = turf.multiLineString([
* [[10, 10], [50, 30], [30, 40]],
* [[-10, -10], [-50, -30], [-30, -40]]
* ]);
*
* // First Segment (defaults are 0)
* turf.findSegment(multiLine);
* // => Feature>
*
* // First Segment of 2nd Multi Feature
* turf.findSegment(multiLine, {multiFeatureIndex: 1});
* // => Feature>
*
* // Last Segment of Last Multi Feature
* turf.findSegment(multiLine, {multiFeatureIndex: -1, segmentIndex: -1});
* // => Feature>
*/
function findSegment(geojson, options) {
// Optional Parameters
options = options || {};
if (!helpers.isObject(options)) throw new Error("options is invalid");
var featureIndex = options.featureIndex || 0;
var multiFeatureIndex = options.multiFeatureIndex || 0;
var geometryIndex = options.geometryIndex || 0;
var segmentIndex = options.segmentIndex || 0;
// Find FeatureIndex
var properties = options.properties;
var geometry;
switch (geojson.type) {
case "FeatureCollection":
if (featureIndex < 0)
featureIndex = geojson.features.length + featureIndex;
properties = properties || geojson.features[featureIndex].properties;
geometry = geojson.features[featureIndex].geometry;
break;
case "Feature":
properties = properties || geojson.properties;
geometry = geojson.geometry;
break;
case "Point":
case "MultiPoint":
return null;
case "LineString":
case "Polygon":
case "MultiLineString":
case "MultiPolygon":
geometry = geojson;
break;
default:
throw new Error("geojson is invalid");
}
// Find SegmentIndex
if (geometry === null) return null;
var coords = geometry.coordinates;
switch (geometry.type) {
case "Point":
case "MultiPoint":
return null;
case "LineString":
if (segmentIndex < 0) segmentIndex = coords.length + segmentIndex - 1;
return helpers.lineString(
[coords[segmentIndex], coords[segmentIndex + 1]],
properties,
options
);
case "Polygon":
if (geometryIndex < 0) geometryIndex = coords.length + geometryIndex;
if (segmentIndex < 0)
segmentIndex = coords[geometryIndex].length + segmentIndex - 1;
return helpers.lineString(
[
coords[geometryIndex][segmentIndex],
coords[geometryIndex][segmentIndex + 1],
],
properties,
options
);
case "MultiLineString":
if (multiFeatureIndex < 0)
multiFeatureIndex = coords.length + multiFeatureIndex;
if (segmentIndex < 0)
segmentIndex = coords[multiFeatureIndex].length + segmentIndex - 1;
return helpers.lineString(
[
coords[multiFeatureIndex][segmentIndex],
coords[multiFeatureIndex][segmentIndex + 1],
],
properties,
options
);
case "MultiPolygon":
if (multiFeatureIndex < 0)
multiFeatureIndex = coords.length + multiFeatureIndex;
if (geometryIndex < 0)
geometryIndex = coords[multiFeatureIndex].length + geometryIndex;
if (segmentIndex < 0)
segmentIndex =
coords[multiFeatureIndex][geometryIndex].length - segmentIndex - 1;
return helpers.lineString(
[
coords[multiFeatureIndex][geometryIndex][segmentIndex],
coords[multiFeatureIndex][geometryIndex][segmentIndex + 1],
],
properties,
options
);
}
throw new Error("geojson is invalid");
}
/**
* Finds a particular Point from a GeoJSON using `@turf/meta` indexes.
*
* Negative indexes are permitted.
*
* @param {FeatureCollection|Feature|Geometry} geojson Any GeoJSON Feature or Geometry
* @param {Object} [options={}] Optional parameters
* @param {number} [options.featureIndex=0] Feature Index
* @param {number} [options.multiFeatureIndex=0] Multi-Feature Index
* @param {number} [options.geometryIndex=0] Geometry Index
* @param {number} [options.coordIndex=0] Coord Index
* @param {Object} [options.properties={}] Translate Properties to output Point
* @param {BBox} [options.bbox={}] Translate BBox to output Point
* @param {number|string} [options.id={}] Translate Id to output Point
* @returns {Feature} 2-vertex GeoJSON Feature Point
* @example
* var multiLine = turf.multiLineString([
* [[10, 10], [50, 30], [30, 40]],
* [[-10, -10], [-50, -30], [-30, -40]]
* ]);
*
* // First Segment (defaults are 0)
* turf.findPoint(multiLine);
* // => Feature>
*
* // First Segment of the 2nd Multi-Feature
* turf.findPoint(multiLine, {multiFeatureIndex: 1});
* // => Feature>
*
* // Last Segment of last Multi-Feature
* turf.findPoint(multiLine, {multiFeatureIndex: -1, coordIndex: -1});
* // => Feature>
*/
function findPoint(geojson, options) {
// Optional Parameters
options = options || {};
if (!helpers.isObject(options)) throw new Error("options is invalid");
var featureIndex = options.featureIndex || 0;
var multiFeatureIndex = options.multiFeatureIndex || 0;
var geometryIndex = options.geometryIndex || 0;
var coordIndex = options.coordIndex || 0;
// Find FeatureIndex
var properties = options.properties;
var geometry;
switch (geojson.type) {
case "FeatureCollection":
if (featureIndex < 0)
featureIndex = geojson.features.length + featureIndex;
properties = properties || geojson.features[featureIndex].properties;
geometry = geojson.features[featureIndex].geometry;
break;
case "Feature":
properties = properties || geojson.properties;
geometry = geojson.geometry;
break;
case "Point":
case "MultiPoint":
return null;
case "LineString":
case "Polygon":
case "MultiLineString":
case "MultiPolygon":
geometry = geojson;
break;
default:
throw new Error("geojson is invalid");
}
// Find Coord Index
if (geometry === null) return null;
var coords = geometry.coordinates;
switch (geometry.type) {
case "Point":
return helpers.point(coords, properties, options);
case "MultiPoint":
if (multiFeatureIndex < 0)
multiFeatureIndex = coords.length + multiFeatureIndex;
return helpers.point(coords[multiFeatureIndex], properties, options);
case "LineString":
if (coordIndex < 0) coordIndex = coords.length + coordIndex;
return helpers.point(coords[coordIndex], properties, options);
case "Polygon":
if (geometryIndex < 0) geometryIndex = coords.length + geometryIndex;
if (coordIndex < 0)
coordIndex = coords[geometryIndex].length + coordIndex;
return helpers.point(coords[geometryIndex][coordIndex], properties, options);
case "MultiLineString":
if (multiFeatureIndex < 0)
multiFeatureIndex = coords.length + multiFeatureIndex;
if (coordIndex < 0)
coordIndex = coords[multiFeatureIndex].length + coordIndex;
return helpers.point(coords[multiFeatureIndex][coordIndex], properties, options);
case "MultiPolygon":
if (multiFeatureIndex < 0)
multiFeatureIndex = coords.length + multiFeatureIndex;
if (geometryIndex < 0)
geometryIndex = coords[multiFeatureIndex].length + geometryIndex;
if (coordIndex < 0)
coordIndex =
coords[multiFeatureIndex][geometryIndex].length - coordIndex;
return helpers.point(
coords[multiFeatureIndex][geometryIndex][coordIndex],
properties,
options
);
}
throw new Error("geojson is invalid");
}
exports.coordEach = coordEach;
exports.coordReduce = coordReduce;
exports.propEach = propEach;
exports.propReduce = propReduce;
exports.featureEach = featureEach;
exports.featureReduce = featureReduce;
exports.coordAll = coordAll;
exports.geomEach = geomEach;
exports.geomReduce = geomReduce;
exports.flattenEach = flattenEach;
exports.flattenReduce = flattenReduce;
exports.segmentEach = segmentEach;
exports.segmentReduce = segmentReduce;
exports.lineEach = lineEach;
exports.lineReduce = lineReduce;
exports.findSegment = findSegment;
exports.findPoint = findPoint;
/***/ }),
/***/ 7844:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
var meta_1 = __webpack_require__(3752);
var helpers_1 = __webpack_require__(9840);
/**
* Takes one or more features and calculates the centroid using the mean of all vertices.
* This lessens the effect of small islands and artifacts when calculating the centroid of a set of polygons.
*
* @name centroid
* @param {GeoJSON} geojson GeoJSON to be centered
* @param {Object} [options={}] Optional Parameters
* @param {Object} [options.properties={}] an Object that is used as the {@link Feature}'s properties
* @returns {Feature} the centroid of the input features
* @example
* var polygon = turf.polygon([[[-81, 41], [-88, 36], [-84, 31], [-80, 33], [-77, 39], [-81, 41]]]);
*
* var centroid = turf.centroid(polygon);
*
* //addToMap
* var addToMap = [polygon, centroid]
*/
function centroid(geojson, options) {
if (options === void 0) { options = {}; }
var xSum = 0;
var ySum = 0;
var len = 0;
meta_1.coordEach(geojson, function (coord) {
xSum += coord[0];
ySum += coord[1];
len++;
});
return helpers_1.point([xSum / len, ySum / len], options.properties);
}
exports["default"] = centroid;
/***/ }),
/***/ 9840:
/***/ (function(__unused_webpack_module, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
/**
* @module helpers
*/
/**
* Earth Radius used with the Harvesine formula and approximates using a spherical (non-ellipsoid) Earth.
*
* @memberof helpers
* @type {number}
*/
exports.earthRadius = 6371008.8;
/**
* Unit of measurement factors using a spherical (non-ellipsoid) earth radius.
*
* @memberof helpers
* @type {Object}
*/
exports.factors = {
centimeters: exports.earthRadius * 100,
centimetres: exports.earthRadius * 100,
degrees: exports.earthRadius / 111325,
feet: exports.earthRadius * 3.28084,
inches: exports.earthRadius * 39.370,
kilometers: exports.earthRadius / 1000,
kilometres: exports.earthRadius / 1000,
meters: exports.earthRadius,
metres: exports.earthRadius,
miles: exports.earthRadius / 1609.344,
millimeters: exports.earthRadius * 1000,
millimetres: exports.earthRadius * 1000,
nauticalmiles: exports.earthRadius / 1852,
radians: 1,
yards: exports.earthRadius / 1.0936,
};
/**
* Units of measurement factors based on 1 meter.
*
* @memberof helpers
* @type {Object}
*/
exports.unitsFactors = {
centimeters: 100,
centimetres: 100,
degrees: 1 / 111325,
feet: 3.28084,
inches: 39.370,
kilometers: 1 / 1000,
kilometres: 1 / 1000,
meters: 1,
metres: 1,
miles: 1 / 1609.344,
millimeters: 1000,
millimetres: 1000,
nauticalmiles: 1 / 1852,
radians: 1 / exports.earthRadius,
yards: 1 / 1.0936,
};
/**
* Area of measurement factors based on 1 square meter.
*
* @memberof helpers
* @type {Object}
*/
exports.areaFactors = {
acres: 0.000247105,
centimeters: 10000,
centimetres: 10000,
feet: 10.763910417,
inches: 1550.003100006,
kilometers: 0.000001,
kilometres: 0.000001,
meters: 1,
metres: 1,
miles: 3.86e-7,
millimeters: 1000000,
millimetres: 1000000,
yards: 1.195990046,
};
/**
* Wraps a GeoJSON {@link Geometry} in a GeoJSON {@link Feature}.
*
* @name feature
* @param {Geometry} geometry input geometry
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a GeoJSON Feature
* @example
* var geometry = {
* "type": "Point",
* "coordinates": [110, 50]
* };
*
* var feature = turf.feature(geometry);
*
* //=feature
*/
function feature(geom, properties, options) {
if (options === void 0) { options = {}; }
var feat = { type: "Feature" };
if (options.id === 0 || options.id) {
feat.id = options.id;
}
if (options.bbox) {
feat.bbox = options.bbox;
}
feat.properties = properties || {};
feat.geometry = geom;
return feat;
}
exports.feature = feature;
/**
* Creates a GeoJSON {@link Geometry} from a Geometry string type & coordinates.
* For GeometryCollection type use `helpers.geometryCollection`
*
* @name geometry
* @param {string} type Geometry Type
* @param {Array} coordinates Coordinates
* @param {Object} [options={}] Optional Parameters
* @returns {Geometry} a GeoJSON Geometry
* @example
* var type = "Point";
* var coordinates = [110, 50];
* var geometry = turf.geometry(type, coordinates);
* // => geometry
*/
function geometry(type, coordinates, options) {
if (options === void 0) { options = {}; }
switch (type) {
case "Point": return point(coordinates).geometry;
case "LineString": return lineString(coordinates).geometry;
case "Polygon": return polygon(coordinates).geometry;
case "MultiPoint": return multiPoint(coordinates).geometry;
case "MultiLineString": return multiLineString(coordinates).geometry;
case "MultiPolygon": return multiPolygon(coordinates).geometry;
default: throw new Error(type + " is invalid");
}
}
exports.geometry = geometry;
/**
* Creates a {@link Point} {@link Feature} from a Position.
*
* @name point
* @param {Array} coordinates longitude, latitude position (each in decimal degrees)
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a Point feature
* @example
* var point = turf.point([-75.343, 39.984]);
*
* //=point
*/
function point(coordinates, properties, options) {
if (options === void 0) { options = {}; }
var geom = {
type: "Point",
coordinates: coordinates,
};
return feature(geom, properties, options);
}
exports.point = point;
/**
* Creates a {@link Point} {@link FeatureCollection} from an Array of Point coordinates.
*
* @name points
* @param {Array>} coordinates an array of Points
* @param {Object} [properties={}] Translate these properties to each Feature
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north]
* associated with the FeatureCollection
* @param {string|number} [options.id] Identifier associated with the FeatureCollection
* @returns {FeatureCollection} Point Feature
* @example
* var points = turf.points([
* [-75, 39],
* [-80, 45],
* [-78, 50]
* ]);
*
* //=points
*/
function points(coordinates, properties, options) {
if (options === void 0) { options = {}; }
return featureCollection(coordinates.map(function (coords) {
return point(coords, properties);
}), options);
}
exports.points = points;
/**
* Creates a {@link Polygon} {@link Feature} from an Array of LinearRings.
*
* @name polygon
* @param {Array>>} coordinates an array of LinearRings
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} Polygon Feature
* @example
* var polygon = turf.polygon([[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]], { name: 'poly1' });
*
* //=polygon
*/
function polygon(coordinates, properties, options) {
if (options === void 0) { options = {}; }
for (var _i = 0, coordinates_1 = coordinates; _i < coordinates_1.length; _i++) {
var ring = coordinates_1[_i];
if (ring.length < 4) {
throw new Error("Each LinearRing of a Polygon must have 4 or more Positions.");
}
for (var j = 0; j < ring[ring.length - 1].length; j++) {
// Check if first point of Polygon contains two numbers
if (ring[ring.length - 1][j] !== ring[0][j]) {
throw new Error("First and last Position are not equivalent.");
}
}
}
var geom = {
type: "Polygon",
coordinates: coordinates,
};
return feature(geom, properties, options);
}
exports.polygon = polygon;
/**
* Creates a {@link Polygon} {@link FeatureCollection} from an Array of Polygon coordinates.
*
* @name polygons
* @param {Array>>>} coordinates an array of Polygon coordinates
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the FeatureCollection
* @returns {FeatureCollection} Polygon FeatureCollection
* @example
* var polygons = turf.polygons([
* [[[-5, 52], [-4, 56], [-2, 51], [-7, 54], [-5, 52]]],
* [[[-15, 42], [-14, 46], [-12, 41], [-17, 44], [-15, 42]]],
* ]);
*
* //=polygons
*/
function polygons(coordinates, properties, options) {
if (options === void 0) { options = {}; }
return featureCollection(coordinates.map(function (coords) {
return polygon(coords, properties);
}), options);
}
exports.polygons = polygons;
/**
* Creates a {@link LineString} {@link Feature} from an Array of Positions.
*
* @name lineString
* @param {Array>} coordinates an array of Positions
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} LineString Feature
* @example
* var linestring1 = turf.lineString([[-24, 63], [-23, 60], [-25, 65], [-20, 69]], {name: 'line 1'});
* var linestring2 = turf.lineString([[-14, 43], [-13, 40], [-15, 45], [-10, 49]], {name: 'line 2'});
*
* //=linestring1
* //=linestring2
*/
function lineString(coordinates, properties, options) {
if (options === void 0) { options = {}; }
if (coordinates.length < 2) {
throw new Error("coordinates must be an array of two or more positions");
}
var geom = {
type: "LineString",
coordinates: coordinates,
};
return feature(geom, properties, options);
}
exports.lineString = lineString;
/**
* Creates a {@link LineString} {@link FeatureCollection} from an Array of LineString coordinates.
*
* @name lineStrings
* @param {Array>>} coordinates an array of LinearRings
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north]
* associated with the FeatureCollection
* @param {string|number} [options.id] Identifier associated with the FeatureCollection
* @returns {FeatureCollection} LineString FeatureCollection
* @example
* var linestrings = turf.lineStrings([
* [[-24, 63], [-23, 60], [-25, 65], [-20, 69]],
* [[-14, 43], [-13, 40], [-15, 45], [-10, 49]]
* ]);
*
* //=linestrings
*/
function lineStrings(coordinates, properties, options) {
if (options === void 0) { options = {}; }
return featureCollection(coordinates.map(function (coords) {
return lineString(coords, properties);
}), options);
}
exports.lineStrings = lineStrings;
/**
* Takes one or more {@link Feature|Features} and creates a {@link FeatureCollection}.
*
* @name featureCollection
* @param {Feature[]} features input features
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {FeatureCollection} FeatureCollection of Features
* @example
* var locationA = turf.point([-75.343, 39.984], {name: 'Location A'});
* var locationB = turf.point([-75.833, 39.284], {name: 'Location B'});
* var locationC = turf.point([-75.534, 39.123], {name: 'Location C'});
*
* var collection = turf.featureCollection([
* locationA,
* locationB,
* locationC
* ]);
*
* //=collection
*/
function featureCollection(features, options) {
if (options === void 0) { options = {}; }
var fc = { type: "FeatureCollection" };
if (options.id) {
fc.id = options.id;
}
if (options.bbox) {
fc.bbox = options.bbox;
}
fc.features = features;
return fc;
}
exports.featureCollection = featureCollection;
/**
* Creates a {@link Feature} based on a
* coordinate array. Properties can be added optionally.
*
* @name multiLineString
* @param {Array>>} coordinates an array of LineStrings
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a MultiLineString feature
* @throws {Error} if no coordinates are passed
* @example
* var multiLine = turf.multiLineString([[[0,0],[10,10]]]);
*
* //=multiLine
*/
function multiLineString(coordinates, properties, options) {
if (options === void 0) { options = {}; }
var geom = {
type: "MultiLineString",
coordinates: coordinates,
};
return feature(geom, properties, options);
}
exports.multiLineString = multiLineString;
/**
* Creates a {@link Feature} based on a
* coordinate array. Properties can be added optionally.
*
* @name multiPoint
* @param {Array>} coordinates an array of Positions
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a MultiPoint feature
* @throws {Error} if no coordinates are passed
* @example
* var multiPt = turf.multiPoint([[0,0],[10,10]]);
*
* //=multiPt
*/
function multiPoint(coordinates, properties, options) {
if (options === void 0) { options = {}; }
var geom = {
type: "MultiPoint",
coordinates: coordinates,
};
return feature(geom, properties, options);
}
exports.multiPoint = multiPoint;
/**
* Creates a {@link Feature} based on a
* coordinate array. Properties can be added optionally.
*
* @name multiPolygon
* @param {Array>>>} coordinates an array of Polygons
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a multipolygon feature
* @throws {Error} if no coordinates are passed
* @example
* var multiPoly = turf.multiPolygon([[[[0,0],[0,10],[10,10],[10,0],[0,0]]]]);
*
* //=multiPoly
*
*/
function multiPolygon(coordinates, properties, options) {
if (options === void 0) { options = {}; }
var geom = {
type: "MultiPolygon",
coordinates: coordinates,
};
return feature(geom, properties, options);
}
exports.multiPolygon = multiPolygon;
/**
* Creates a {@link Feature} based on a
* coordinate array. Properties can be added optionally.
*
* @name geometryCollection
* @param {Array} geometries an array of GeoJSON Geometries
* @param {Object} [properties={}] an Object of key-value pairs to add as properties
* @param {Object} [options={}] Optional Parameters
* @param {Array} [options.bbox] Bounding Box Array [west, south, east, north] associated with the Feature
* @param {string|number} [options.id] Identifier associated with the Feature
* @returns {Feature} a GeoJSON GeometryCollection Feature
* @example
* var pt = turf.geometry("Point", [100, 0]);
* var line = turf.geometry("LineString", [[101, 0], [102, 1]]);
* var collection = turf.geometryCollection([pt, line]);
*
* // => collection
*/
function geometryCollection(geometries, properties, options) {
if (options === void 0) { options = {}; }
var geom = {
type: "GeometryCollection",
geometries: geometries,
};
return feature(geom, properties, options);
}
exports.geometryCollection = geometryCollection;
/**
* Round number to precision
*
* @param {number} num Number
* @param {number} [precision=0] Precision
* @returns {number} rounded number
* @example
* turf.round(120.4321)
* //=120
*
* turf.round(120.4321, 2)
* //=120.43
*/
function round(num, precision) {
if (precision === void 0) { precision = 0; }
if (precision && !(precision >= 0)) {
throw new Error("precision must be a positive number");
}
var multiplier = Math.pow(10, precision || 0);
return Math.round(num * multiplier) / multiplier;
}
exports.round = round;
/**
* Convert a distance measurement (assuming a spherical Earth) from radians to a more friendly unit.
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
*
* @name radiansToLength
* @param {number} radians in radians across the sphere
* @param {string} [units="kilometers"] can be degrees, radians, miles, or kilometers inches, yards, metres,
* meters, kilometres, kilometers.
* @returns {number} distance
*/
function radiansToLength(radians, units) {
if (units === void 0) { units = "kilometers"; }
var factor = exports.factors[units];
if (!factor) {
throw new Error(units + " units is invalid");
}
return radians * factor;
}
exports.radiansToLength = radiansToLength;
/**
* Convert a distance measurement (assuming a spherical Earth) from a real-world unit into radians
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
*
* @name lengthToRadians
* @param {number} distance in real units
* @param {string} [units="kilometers"] can be degrees, radians, miles, or kilometers inches, yards, metres,
* meters, kilometres, kilometers.
* @returns {number} radians
*/
function lengthToRadians(distance, units) {
if (units === void 0) { units = "kilometers"; }
var factor = exports.factors[units];
if (!factor) {
throw new Error(units + " units is invalid");
}
return distance / factor;
}
exports.lengthToRadians = lengthToRadians;
/**
* Convert a distance measurement (assuming a spherical Earth) from a real-world unit into degrees
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, centimeters, kilometres, feet
*
* @name lengthToDegrees
* @param {number} distance in real units
* @param {string} [units="kilometers"] can be degrees, radians, miles, or kilometers inches, yards, metres,
* meters, kilometres, kilometers.
* @returns {number} degrees
*/
function lengthToDegrees(distance, units) {
return radiansToDegrees(lengthToRadians(distance, units));
}
exports.lengthToDegrees = lengthToDegrees;
/**
* Converts any bearing angle from the north line direction (positive clockwise)
* and returns an angle between 0-360 degrees (positive clockwise), 0 being the north line
*
* @name bearingToAzimuth
* @param {number} bearing angle, between -180 and +180 degrees
* @returns {number} angle between 0 and 360 degrees
*/
function bearingToAzimuth(bearing) {
var angle = bearing % 360;
if (angle < 0) {
angle += 360;
}
return angle;
}
exports.bearingToAzimuth = bearingToAzimuth;
/**
* Converts an angle in radians to degrees
*
* @name radiansToDegrees
* @param {number} radians angle in radians
* @returns {number} degrees between 0 and 360 degrees
*/
function radiansToDegrees(radians) {
var degrees = radians % (2 * Math.PI);
return degrees * 180 / Math.PI;
}
exports.radiansToDegrees = radiansToDegrees;
/**
* Converts an angle in degrees to radians
*
* @name degreesToRadians
* @param {number} degrees angle between 0 and 360 degrees
* @returns {number} angle in radians
*/
function degreesToRadians(degrees) {
var radians = degrees % 360;
return radians * Math.PI / 180;
}
exports.degreesToRadians = degreesToRadians;
/**
* Converts a length to the requested unit.
* Valid units: miles, nauticalmiles, inches, yards, meters, metres, kilometers, centimeters, feet
*
* @param {number} length to be converted
* @param {Units} [originalUnit="kilometers"] of the length
* @param {Units} [finalUnit="kilometers"] returned unit
* @returns {number} the converted length
*/
function convertLength(length, originalUnit, finalUnit) {
if (originalUnit === void 0) { originalUnit = "kilometers"; }
if (finalUnit === void 0) { finalUnit = "kilometers"; }
if (!(length >= 0)) {
throw new Error("length must be a positive number");
}
return radiansToLength(lengthToRadians(length, originalUnit), finalUnit);
}
exports.convertLength = convertLength;
/**
* Converts a area to the requested unit.
* Valid units: kilometers, kilometres, meters, metres, centimetres, millimeters, acres, miles, yards, feet, inches
* @param {number} area to be converted
* @param {Units} [originalUnit="meters"] of the distance
* @param {Units} [finalUnit="kilometers"] returned unit
* @returns {number} the converted distance
*/
function convertArea(area, originalUnit, finalUnit) {
if (originalUnit === void 0) { originalUnit = "meters"; }
if (finalUnit === void 0) { finalUnit = "kilometers"; }
if (!(area >= 0)) {
throw new Error("area must be a positive number");
}
var startFactor = exports.areaFactors[originalUnit];
if (!startFactor) {
throw new Error("invalid original units");
}
var finalFactor = exports.areaFactors[finalUnit];
if (!finalFactor) {
throw new Error("invalid final units");
}
return (area / startFactor) * finalFactor;
}
exports.convertArea = convertArea;
/**
* isNumber
*
* @param {*} num Number to validate
* @returns {boolean} true/false
* @example
* turf.isNumber(123)
* //=true
* turf.isNumber('foo')
* //=false
*/
function isNumber(num) {
return !isNaN(num) && num !== null && !Array.isArray(num) && !/^\s*$/.test(num);
}
exports.isNumber = isNumber;
/**
* isObject
*
* @param {*} input variable to validate
* @returns {boolean} true/false
* @example
* turf.isObject({elevation: 10})
* //=true
* turf.isObject('foo')
* //=false
*/
function isObject(input) {
return (!!input) && (input.constructor === Object);
}
exports.isObject = isObject;
/**
* Validate BBox
*
* @private
* @param {Array} bbox BBox to validate
* @returns {void}
* @throws Error if BBox is not valid
* @example
* validateBBox([-180, -40, 110, 50])
* //=OK
* validateBBox([-180, -40])
* //=Error
* validateBBox('Foo')
* //=Error
* validateBBox(5)
* //=Error
* validateBBox(null)
* //=Error
* validateBBox(undefined)
* //=Error
*/
function validateBBox(bbox) {
if (!bbox) {
throw new Error("bbox is required");
}
if (!Array.isArray(bbox)) {
throw new Error("bbox must be an Array");
}
if (bbox.length !== 4 && bbox.length !== 6) {
throw new Error("bbox must be an Array of 4 or 6 numbers");
}
bbox.forEach(function (num) {
if (!isNumber(num)) {
throw new Error("bbox must only contain numbers");
}
});
}
exports.validateBBox = validateBBox;
/**
* Validate Id
*
* @private
* @param {string|number} id Id to validate
* @returns {void}
* @throws Error if Id is not valid
* @example
* validateId([-180, -40, 110, 50])
* //=Error
* validateId([-180, -40])
* //=Error
* validateId('Foo')
* //=OK
* validateId(5)
* //=OK
* validateId(null)
* //=Error
* validateId(undefined)
* //=Error
*/
function validateId(id) {
if (!id) {
throw new Error("id is required");
}
if (["string", "number"].indexOf(typeof id) === -1) {
throw new Error("id must be a number or a string");
}
}
exports.validateId = validateId;
// Deprecated methods
function radians2degrees() {
throw new Error("method has been renamed to `radiansToDegrees`");
}
exports.radians2degrees = radians2degrees;
function degrees2radians() {
throw new Error("method has been renamed to `degreesToRadians`");
}
exports.degrees2radians = degrees2radians;
function distanceToDegrees() {
throw new Error("method has been renamed to `lengthToDegrees`");
}
exports.distanceToDegrees = distanceToDegrees;
function distanceToRadians() {
throw new Error("method has been renamed to `lengthToRadians`");
}
exports.distanceToRadians = distanceToRadians;
function radiansToDistance() {
throw new Error("method has been renamed to `radiansToLength`");
}
exports.radiansToDistance = radiansToDistance;
function bearingToAngle() {
throw new Error("method has been renamed to `bearingToAzimuth`");
}
exports.bearingToAngle = bearingToAngle;
function convertDistance() {
throw new Error("method has been renamed to `convertLength`");
}
exports.convertDistance = convertDistance;
/***/ }),
/***/ 3752:
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
"use strict";
Object.defineProperty(exports, "__esModule", ({ value: true }));
var helpers = __webpack_require__(9840);
/**
* Callback for coordEach
*
* @callback coordEachCallback
* @param {Array} currentCoord The current coordinate being processed.
* @param {number} coordIndex The current index of the coordinate being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @param {number} geometryIndex The current index of the Geometry being processed.
*/
/**
* Iterate over coordinates in any GeoJSON object, similar to Array.forEach()
*
* @name coordEach
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (currentCoord, coordIndex, featureIndex, multiFeatureIndex)
* @param {boolean} [excludeWrapCoord=false] whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {"foo": "bar"}),
* turf.point([36, 53], {"hello": "world"})
* ]);
*
* turf.coordEach(features, function (currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {
* //=currentCoord
* //=coordIndex
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* });
*/
function coordEach(geojson, callback, excludeWrapCoord) {
// Handles null Geometry -- Skips this GeoJSON
if (geojson === null) return;
var j, k, l, geometry, stopG, coords,
geometryMaybeCollection,
wrapShrink = 0,
coordIndex = 0,
isGeometryCollection,
type = geojson.type,
isFeatureCollection = type === 'FeatureCollection',
isFeature = type === 'Feature',
stop = isFeatureCollection ? geojson.features.length : 1;
// This logic may look a little weird. The reason why it is that way
// is because it's trying to be fast. GeoJSON supports multiple kinds
// of objects at its root: FeatureCollection, Features, Geometries.
// This function has the responsibility of handling all of them, and that
// means that some of the `for` loops you see below actually just don't apply
// to certain inputs. For instance, if you give this just a
// Point geometry, then both loops are short-circuited and all we do
// is gradually rename the input until it's called 'geometry'.
//
// This also aims to allocate as few resources as possible: just a
// few numbers and booleans, rather than any temporary arrays as would
// be required with the normalization approach.
for (var featureIndex = 0; featureIndex < stop; featureIndex++) {
geometryMaybeCollection = (isFeatureCollection ? geojson.features[featureIndex].geometry :
(isFeature ? geojson.geometry : geojson));
isGeometryCollection = (geometryMaybeCollection) ? geometryMaybeCollection.type === 'GeometryCollection' : false;
stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;
for (var geomIndex = 0; geomIndex < stopG; geomIndex++) {
var multiFeatureIndex = 0;
var geometryIndex = 0;
geometry = isGeometryCollection ?
geometryMaybeCollection.geometries[geomIndex] : geometryMaybeCollection;
// Handles null Geometry -- Skips this geometry
if (geometry === null) continue;
coords = geometry.coordinates;
var geomType = geometry.type;
wrapShrink = (excludeWrapCoord && (geomType === 'Polygon' || geomType === 'MultiPolygon')) ? 1 : 0;
switch (geomType) {
case null:
break;
case 'Point':
if (callback(coords, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;
coordIndex++;
multiFeatureIndex++;
break;
case 'LineString':
case 'MultiPoint':
for (j = 0; j < coords.length; j++) {
if (callback(coords[j], coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;
coordIndex++;
if (geomType === 'MultiPoint') multiFeatureIndex++;
}
if (geomType === 'LineString') multiFeatureIndex++;
break;
case 'Polygon':
case 'MultiLineString':
for (j = 0; j < coords.length; j++) {
for (k = 0; k < coords[j].length - wrapShrink; k++) {
if (callback(coords[j][k], coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;
coordIndex++;
}
if (geomType === 'MultiLineString') multiFeatureIndex++;
if (geomType === 'Polygon') geometryIndex++;
}
if (geomType === 'Polygon') multiFeatureIndex++;
break;
case 'MultiPolygon':
for (j = 0; j < coords.length; j++) {
geometryIndex = 0;
for (k = 0; k < coords[j].length; k++) {
for (l = 0; l < coords[j][k].length - wrapShrink; l++) {
if (callback(coords[j][k][l], coordIndex, featureIndex, multiFeatureIndex, geometryIndex) === false) return false;
coordIndex++;
}
geometryIndex++;
}
multiFeatureIndex++;
}
break;
case 'GeometryCollection':
for (j = 0; j < geometry.geometries.length; j++)
if (coordEach(geometry.geometries[j], callback, excludeWrapCoord) === false) return false;
break;
default:
throw new Error('Unknown Geometry Type');
}
}
}
}
/**
* Callback for coordReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback coordReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Array} currentCoord The current coordinate being processed.
* @param {number} coordIndex The current index of the coordinate being processed.
* Starts at index 0, if an initialValue is provided, and at index 1 otherwise.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @param {number} geometryIndex The current index of the Geometry being processed.
*/
/**
* Reduce coordinates in any GeoJSON object, similar to Array.reduce()
*
* @name coordReduce
* @param {FeatureCollection|Geometry|Feature} geojson any GeoJSON object
* @param {Function} callback a method that takes (previousValue, currentCoord, coordIndex)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @param {boolean} [excludeWrapCoord=false] whether or not to include the final coordinate of LinearRings that wraps the ring in its iteration.
* @returns {*} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {"foo": "bar"}),
* turf.point([36, 53], {"hello": "world"})
* ]);
*
* turf.coordReduce(features, function (previousValue, currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {
* //=previousValue
* //=currentCoord
* //=coordIndex
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* return currentCoord;
* });
*/
function coordReduce(geojson, callback, initialValue, excludeWrapCoord) {
var previousValue = initialValue;
coordEach(geojson, function (currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex) {
if (coordIndex === 0 && initialValue === undefined) previousValue = currentCoord;
else previousValue = callback(previousValue, currentCoord, coordIndex, featureIndex, multiFeatureIndex, geometryIndex);
}, excludeWrapCoord);
return previousValue;
}
/**
* Callback for propEach
*
* @callback propEachCallback
* @param {Object} currentProperties The current Properties being processed.
* @param {number} featureIndex The current index of the Feature being processed.
*/
/**
* Iterate over properties in any GeoJSON object, similar to Array.forEach()
*
* @name propEach
* @param {FeatureCollection|Feature} geojson any GeoJSON object
* @param {Function} callback a method that takes (currentProperties, featureIndex)
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.propEach(features, function (currentProperties, featureIndex) {
* //=currentProperties
* //=featureIndex
* });
*/
function propEach(geojson, callback) {
var i;
switch (geojson.type) {
case 'FeatureCollection':
for (i = 0; i < geojson.features.length; i++) {
if (callback(geojson.features[i].properties, i) === false) break;
}
break;
case 'Feature':
callback(geojson.properties, 0);
break;
}
}
/**
* Callback for propReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback propReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {*} currentProperties The current Properties being processed.
* @param {number} featureIndex The current index of the Feature being processed.
*/
/**
* Reduce properties in any GeoJSON object into a single value,
* similar to how Array.reduce works. However, in this case we lazily run
* the reduction, so an array of all properties is unnecessary.
*
* @name propReduce
* @param {FeatureCollection|Feature} geojson any GeoJSON object
* @param {Function} callback a method that takes (previousValue, currentProperties, featureIndex)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {*} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.propReduce(features, function (previousValue, currentProperties, featureIndex) {
* //=previousValue
* //=currentProperties
* //=featureIndex
* return currentProperties
* });
*/
function propReduce(geojson, callback, initialValue) {
var previousValue = initialValue;
propEach(geojson, function (currentProperties, featureIndex) {
if (featureIndex === 0 && initialValue === undefined) previousValue = currentProperties;
else previousValue = callback(previousValue, currentProperties, featureIndex);
});
return previousValue;
}
/**
* Callback for featureEach
*
* @callback featureEachCallback
* @param {Feature} currentFeature The current Feature being processed.
* @param {number} featureIndex The current index of the Feature being processed.
*/
/**
* Iterate over features in any GeoJSON object, similar to
* Array.forEach.
*
* @name featureEach
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (currentFeature, featureIndex)
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.featureEach(features, function (currentFeature, featureIndex) {
* //=currentFeature
* //=featureIndex
* });
*/
function featureEach(geojson, callback) {
if (geojson.type === 'Feature') {
callback(geojson, 0);
} else if (geojson.type === 'FeatureCollection') {
for (var i = 0; i < geojson.features.length; i++) {
if (callback(geojson.features[i], i) === false) break;
}
}
}
/**
* Callback for featureReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback featureReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Feature} currentFeature The current Feature being processed.
* @param {number} featureIndex The current index of the Feature being processed.
*/
/**
* Reduce features in any GeoJSON object, similar to Array.reduce().
*
* @name featureReduce
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {*} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {"foo": "bar"}),
* turf.point([36, 53], {"hello": "world"})
* ]);
*
* turf.featureReduce(features, function (previousValue, currentFeature, featureIndex) {
* //=previousValue
* //=currentFeature
* //=featureIndex
* return currentFeature
* });
*/
function featureReduce(geojson, callback, initialValue) {
var previousValue = initialValue;
featureEach(geojson, function (currentFeature, featureIndex) {
if (featureIndex === 0 && initialValue === undefined) previousValue = currentFeature;
else previousValue = callback(previousValue, currentFeature, featureIndex);
});
return previousValue;
}
/**
* Get all coordinates from any GeoJSON object.
*
* @name coordAll
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @returns {Array>} coordinate position array
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* var coords = turf.coordAll(features);
* //= [[26, 37], [36, 53]]
*/
function coordAll(geojson) {
var coords = [];
coordEach(geojson, function (coord) {
coords.push(coord);
});
return coords;
}
/**
* Callback for geomEach
*
* @callback geomEachCallback
* @param {Geometry} currentGeometry The current Geometry being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {Object} featureProperties The current Feature Properties being processed.
* @param {Array} featureBBox The current Feature BBox being processed.
* @param {number|string} featureId The current Feature Id being processed.
*/
/**
* Iterate over each geometry in any GeoJSON object, similar to Array.forEach()
*
* @name geomEach
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (currentGeometry, featureIndex, featureProperties, featureBBox, featureId)
* @returns {void}
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.geomEach(features, function (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {
* //=currentGeometry
* //=featureIndex
* //=featureProperties
* //=featureBBox
* //=featureId
* });
*/
function geomEach(geojson, callback) {
var i, j, g, geometry, stopG,
geometryMaybeCollection,
isGeometryCollection,
featureProperties,
featureBBox,
featureId,
featureIndex = 0,
isFeatureCollection = geojson.type === 'FeatureCollection',
isFeature = geojson.type === 'Feature',
stop = isFeatureCollection ? geojson.features.length : 1;
// This logic may look a little weird. The reason why it is that way
// is because it's trying to be fast. GeoJSON supports multiple kinds
// of objects at its root: FeatureCollection, Features, Geometries.
// This function has the responsibility of handling all of them, and that
// means that some of the `for` loops you see below actually just don't apply
// to certain inputs. For instance, if you give this just a
// Point geometry, then both loops are short-circuited and all we do
// is gradually rename the input until it's called 'geometry'.
//
// This also aims to allocate as few resources as possible: just a
// few numbers and booleans, rather than any temporary arrays as would
// be required with the normalization approach.
for (i = 0; i < stop; i++) {
geometryMaybeCollection = (isFeatureCollection ? geojson.features[i].geometry :
(isFeature ? geojson.geometry : geojson));
featureProperties = (isFeatureCollection ? geojson.features[i].properties :
(isFeature ? geojson.properties : {}));
featureBBox = (isFeatureCollection ? geojson.features[i].bbox :
(isFeature ? geojson.bbox : undefined));
featureId = (isFeatureCollection ? geojson.features[i].id :
(isFeature ? geojson.id : undefined));
isGeometryCollection = (geometryMaybeCollection) ? geometryMaybeCollection.type === 'GeometryCollection' : false;
stopG = isGeometryCollection ? geometryMaybeCollection.geometries.length : 1;
for (g = 0; g < stopG; g++) {
geometry = isGeometryCollection ?
geometryMaybeCollection.geometries[g] : geometryMaybeCollection;
// Handle null Geometry
if (geometry === null) {
if (callback(null, featureIndex, featureProperties, featureBBox, featureId) === false) return false;
continue;
}
switch (geometry.type) {
case 'Point':
case 'LineString':
case 'MultiPoint':
case 'Polygon':
case 'MultiLineString':
case 'MultiPolygon': {
if (callback(geometry, featureIndex, featureProperties, featureBBox, featureId) === false) return false;
break;
}
case 'GeometryCollection': {
for (j = 0; j < geometry.geometries.length; j++) {
if (callback(geometry.geometries[j], featureIndex, featureProperties, featureBBox, featureId) === false) return false;
}
break;
}
default:
throw new Error('Unknown Geometry Type');
}
}
// Only increase `featureIndex` per each feature
featureIndex++;
}
}
/**
* Callback for geomReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback geomReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Geometry} currentGeometry The current Geometry being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {Object} featureProperties The current Feature Properties being processed.
* @param {Array} featureBBox The current Feature BBox being processed.
* @param {number|string} featureId The current Feature Id being processed.
*/
/**
* Reduce geometry in any GeoJSON object, similar to Array.reduce().
*
* @name geomReduce
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {*} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.point([36, 53], {hello: 'world'})
* ]);
*
* turf.geomReduce(features, function (previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {
* //=previousValue
* //=currentGeometry
* //=featureIndex
* //=featureProperties
* //=featureBBox
* //=featureId
* return currentGeometry
* });
*/
function geomReduce(geojson, callback, initialValue) {
var previousValue = initialValue;
geomEach(geojson, function (currentGeometry, featureIndex, featureProperties, featureBBox, featureId) {
if (featureIndex === 0 && initialValue === undefined) previousValue = currentGeometry;
else previousValue = callback(previousValue, currentGeometry, featureIndex, featureProperties, featureBBox, featureId);
});
return previousValue;
}
/**
* Callback for flattenEach
*
* @callback flattenEachCallback
* @param {Feature} currentFeature The current flattened feature being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
*/
/**
* Iterate over flattened features in any GeoJSON object, similar to
* Array.forEach.
*
* @name flattenEach
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (currentFeature, featureIndex, multiFeatureIndex)
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.multiPoint([[40, 30], [36, 53]], {hello: 'world'})
* ]);
*
* turf.flattenEach(features, function (currentFeature, featureIndex, multiFeatureIndex) {
* //=currentFeature
* //=featureIndex
* //=multiFeatureIndex
* });
*/
function flattenEach(geojson, callback) {
geomEach(geojson, function (geometry, featureIndex, properties, bbox, id) {
// Callback for single geometry
var type = (geometry === null) ? null : geometry.type;
switch (type) {
case null:
case 'Point':
case 'LineString':
case 'Polygon':
if (callback(helpers.feature(geometry, properties, {bbox: bbox, id: id}), featureIndex, 0) === false) return false;
return;
}
var geomType;
// Callback for multi-geometry
switch (type) {
case 'MultiPoint':
geomType = 'Point';
break;
case 'MultiLineString':
geomType = 'LineString';
break;
case 'MultiPolygon':
geomType = 'Polygon';
break;
}
for (var multiFeatureIndex = 0; multiFeatureIndex < geometry.coordinates.length; multiFeatureIndex++) {
var coordinate = geometry.coordinates[multiFeatureIndex];
var geom = {
type: geomType,
coordinates: coordinate
};
if (callback(helpers.feature(geom, properties), featureIndex, multiFeatureIndex) === false) return false;
}
});
}
/**
* Callback for flattenReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback flattenReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Feature} currentFeature The current Feature being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
*/
/**
* Reduce flattened features in any GeoJSON object, similar to Array.reduce().
*
* @name flattenReduce
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON object
* @param {Function} callback a method that takes (previousValue, currentFeature, featureIndex, multiFeatureIndex)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {*} The value that results from the reduction.
* @example
* var features = turf.featureCollection([
* turf.point([26, 37], {foo: 'bar'}),
* turf.multiPoint([[40, 30], [36, 53]], {hello: 'world'})
* ]);
*
* turf.flattenReduce(features, function (previousValue, currentFeature, featureIndex, multiFeatureIndex) {
* //=previousValue
* //=currentFeature
* //=featureIndex
* //=multiFeatureIndex
* return currentFeature
* });
*/
function flattenReduce(geojson, callback, initialValue) {
var previousValue = initialValue;
flattenEach(geojson, function (currentFeature, featureIndex, multiFeatureIndex) {
if (featureIndex === 0 && multiFeatureIndex === 0 && initialValue === undefined) previousValue = currentFeature;
else previousValue = callback(previousValue, currentFeature, featureIndex, multiFeatureIndex);
});
return previousValue;
}
/**
* Callback for segmentEach
*
* @callback segmentEachCallback
* @param {Feature} currentSegment The current Segment being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @param {number} geometryIndex The current index of the Geometry being processed.
* @param {number} segmentIndex The current index of the Segment being processed.
* @returns {void}
*/
/**
* Iterate over 2-vertex line segment in any GeoJSON object, similar to Array.forEach()
* (Multi)Point geometries do not contain segments therefore they are ignored during this operation.
*
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON
* @param {Function} callback a method that takes (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex)
* @returns {void}
* @example
* var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
*
* // Iterate over GeoJSON by 2-vertex segments
* turf.segmentEach(polygon, function (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {
* //=currentSegment
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* //=segmentIndex
* });
*
* // Calculate the total number of segments
* var total = 0;
* turf.segmentEach(polygon, function () {
* total++;
* });
*/
function segmentEach(geojson, callback) {
flattenEach(geojson, function (feature, featureIndex, multiFeatureIndex) {
var segmentIndex = 0;
// Exclude null Geometries
if (!feature.geometry) return;
// (Multi)Point geometries do not contain segments therefore they are ignored during this operation.
var type = feature.geometry.type;
if (type === 'Point' || type === 'MultiPoint') return;
// Generate 2-vertex line segments
var previousCoords;
var previousFeatureIndex = 0;
var previousMultiIndex = 0;
var prevGeomIndex = 0;
if (coordEach(feature, function (currentCoord, coordIndex, featureIndexCoord, multiPartIndexCoord, geometryIndex) {
// Simulating a meta.coordReduce() since `reduce` operations cannot be stopped by returning `false`
if (previousCoords === undefined || featureIndex > previousFeatureIndex || multiPartIndexCoord > previousMultiIndex || geometryIndex > prevGeomIndex) {
previousCoords = currentCoord;
previousFeatureIndex = featureIndex;
previousMultiIndex = multiPartIndexCoord;
prevGeomIndex = geometryIndex;
segmentIndex = 0;
return;
}
var currentSegment = helpers.lineString([previousCoords, currentCoord], feature.properties);
if (callback(currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) === false) return false;
segmentIndex++;
previousCoords = currentCoord;
}) === false) return false;
});
}
/**
* Callback for segmentReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback segmentReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Feature} currentSegment The current Segment being processed.
* @param {number} featureIndex The current index of the Feature being processed.
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed.
* @param {number} geometryIndex The current index of the Geometry being processed.
* @param {number} segmentIndex The current index of the Segment being processed.
*/
/**
* Reduce 2-vertex line segment in any GeoJSON object, similar to Array.reduce()
* (Multi)Point geometries do not contain segments therefore they are ignored during this operation.
*
* @param {FeatureCollection|Feature|Geometry} geojson any GeoJSON
* @param {Function} callback a method that takes (previousValue, currentSegment, currentIndex)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {void}
* @example
* var polygon = turf.polygon([[[-50, 5], [-40, -10], [-50, -10], [-40, 5], [-50, 5]]]);
*
* // Iterate over GeoJSON by 2-vertex segments
* turf.segmentReduce(polygon, function (previousSegment, currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {
* //= previousSegment
* //= currentSegment
* //= featureIndex
* //= multiFeatureIndex
* //= geometryIndex
* //= segmentInex
* return currentSegment
* });
*
* // Calculate the total number of segments
* var initialValue = 0
* var total = turf.segmentReduce(polygon, function (previousValue) {
* previousValue++;
* return previousValue;
* }, initialValue);
*/
function segmentReduce(geojson, callback, initialValue) {
var previousValue = initialValue;
var started = false;
segmentEach(geojson, function (currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex) {
if (started === false && initialValue === undefined) previousValue = currentSegment;
else previousValue = callback(previousValue, currentSegment, featureIndex, multiFeatureIndex, geometryIndex, segmentIndex);
started = true;
});
return previousValue;
}
/**
* Callback for lineEach
*
* @callback lineEachCallback
* @param {Feature} currentLine The current LineString|LinearRing being processed
* @param {number} featureIndex The current index of the Feature being processed
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed
* @param {number} geometryIndex The current index of the Geometry being processed
*/
/**
* Iterate over line or ring coordinates in LineString, Polygon, MultiLineString, MultiPolygon Features or Geometries,
* similar to Array.forEach.
*
* @name lineEach
* @param {Geometry|Feature} geojson object
* @param {Function} callback a method that takes (currentLine, featureIndex, multiFeatureIndex, geometryIndex)
* @example
* var multiLine = turf.multiLineString([
* [[26, 37], [35, 45]],
* [[36, 53], [38, 50], [41, 55]]
* ]);
*
* turf.lineEach(multiLine, function (currentLine, featureIndex, multiFeatureIndex, geometryIndex) {
* //=currentLine
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* });
*/
function lineEach(geojson, callback) {
// validation
if (!geojson) throw new Error('geojson is required');
flattenEach(geojson, function (feature, featureIndex, multiFeatureIndex) {
if (feature.geometry === null) return;
var type = feature.geometry.type;
var coords = feature.geometry.coordinates;
switch (type) {
case 'LineString':
if (callback(feature, featureIndex, multiFeatureIndex, 0, 0) === false) return false;
break;
case 'Polygon':
for (var geometryIndex = 0; geometryIndex < coords.length; geometryIndex++) {
if (callback(helpers.lineString(coords[geometryIndex], feature.properties), featureIndex, multiFeatureIndex, geometryIndex) === false) return false;
}
break;
}
});
}
/**
* Callback for lineReduce
*
* The first time the callback function is called, the values provided as arguments depend
* on whether the reduce method has an initialValue argument.
*
* If an initialValue is provided to the reduce method:
* - The previousValue argument is initialValue.
* - The currentValue argument is the value of the first element present in the array.
*
* If an initialValue is not provided:
* - The previousValue argument is the value of the first element present in the array.
* - The currentValue argument is the value of the second element present in the array.
*
* @callback lineReduceCallback
* @param {*} previousValue The accumulated value previously returned in the last invocation
* of the callback, or initialValue, if supplied.
* @param {Feature} currentLine The current LineString|LinearRing being processed.
* @param {number} featureIndex The current index of the Feature being processed
* @param {number} multiFeatureIndex The current index of the Multi-Feature being processed
* @param {number} geometryIndex The current index of the Geometry being processed
*/
/**
* Reduce features in any GeoJSON object, similar to Array.reduce().
*
* @name lineReduce
* @param {Geometry|Feature} geojson object
* @param {Function} callback a method that takes (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex)
* @param {*} [initialValue] Value to use as the first argument to the first call of the callback.
* @returns {*} The value that results from the reduction.
* @example
* var multiPoly = turf.multiPolygon([
* turf.polygon([[[12,48],[2,41],[24,38],[12,48]], [[9,44],[13,41],[13,45],[9,44]]]),
* turf.polygon([[[5, 5], [0, 0], [2, 2], [4, 4], [5, 5]]])
* ]);
*
* turf.lineReduce(multiPoly, function (previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex) {
* //=previousValue
* //=currentLine
* //=featureIndex
* //=multiFeatureIndex
* //=geometryIndex
* return currentLine
* });
*/
function lineReduce(geojson, callback, initialValue) {
var previousValue = initialValue;
lineEach(geojson, function (currentLine, featureIndex, multiFeatureIndex, geometryIndex) {
if (featureIndex === 0 && initialValue === undefined) previousValue = currentLine;
else previousValue = callback(previousValue, currentLine, featureIndex, multiFeatureIndex, geometryIndex);
});
return previousValue;
}
/**
* Finds a particular 2-vertex LineString Segment from a GeoJSON using `@turf/meta` indexes.
*
* Negative indexes are permitted.
* Point & MultiPoint will always return null.
*
* @param {FeatureCollection|Feature|Geometry} geojson Any GeoJSON Feature or Geometry
* @param {Object} [options={}] Optional parameters
* @param {number} [options.featureIndex=0] Feature Index
* @param {number} [options.multiFeatureIndex=0] Multi-Feature Index
* @param {number} [options.geometryIndex=0] Geometry Index
* @param {number} [options.segmentIndex=0] Segment Index
* @param {Object} [options.properties={}] Translate Properties to output LineString
* @param {BBox} [options.bbox={}] Translate BBox to output LineString
* @param {number|string} [options.id={}] Translate Id to output LineString
* @returns {Feature} 2-vertex GeoJSON Feature LineString
* @example
* var multiLine = turf.multiLineString([
* [[10, 10], [50, 30], [30, 40]],
* [[-10, -10], [-50, -30], [-30, -40]]
* ]);
*
* // First Segment (defaults are 0)
* turf.findSegment(multiLine);
* // => Feature>
*
* // First Segment of 2nd Multi Feature
* turf.findSegment(multiLine, {multiFeatureIndex: 1});
* // => Feature>
*
* // Last Segment of Last Multi Feature
* turf.findSegment(multiLine, {multiFeatureIndex: -1, segmentIndex: -1});
* // => Feature>
*/
function findSegment(geojson, options) {
// Optional Parameters
options = options || {};
if (!helpers.isObject(options)) throw new Error('options is invalid');
var featureIndex = options.featureIndex || 0;
var multiFeatureIndex = options.multiFeatureIndex || 0;
var geometryIndex = options.geometryIndex || 0;
var segmentIndex = options.segmentIndex || 0;
// Find FeatureIndex
var properties = options.properties;
var geometry;
switch (geojson.type) {
case 'FeatureCollection':
if (featureIndex < 0) featureIndex = geojson.features.length + featureIndex;
properties = properties || geojson.features[featureIndex].properties;
geometry = geojson.features[featureIndex].geometry;
break;
case 'Feature':
properties = properties || geojson.properties;
geometry = geojson.geometry;
break;
case 'Point':
case 'MultiPoint':
return null;
case 'LineString':
case 'Polygon':
case 'MultiLineString':
case 'MultiPolygon':
geometry = geojson;
break;
default:
throw new Error('geojson is invalid');
}
// Find SegmentIndex
if (geometry === null) return null;
var coords = geometry.coordinates;
switch (geometry.type) {
case 'Point':
case 'MultiPoint':
return null;
case 'LineString':
if (segmentIndex < 0) segmentIndex = coords.length + segmentIndex - 1;
return helpers.lineString([coords[segmentIndex], coords[segmentIndex + 1]], properties, options);
case 'Polygon':
if (geometryIndex < 0) geometryIndex = coords.length + geometryIndex;
if (segmentIndex < 0) segmentIndex = coords[geometryIndex].length + segmentIndex - 1;
return helpers.lineString([coords[geometryIndex][segmentIndex], coords[geometryIndex][segmentIndex + 1]], properties, options);
case 'MultiLineString':
if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;
if (segmentIndex < 0) segmentIndex = coords[multiFeatureIndex].length + segmentIndex - 1;
return helpers.lineString([coords[multiFeatureIndex][segmentIndex], coords[multiFeatureIndex][segmentIndex + 1]], properties, options);
case 'MultiPolygon':
if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;
if (geometryIndex < 0) geometryIndex = coords[multiFeatureIndex].length + geometryIndex;
if (segmentIndex < 0) segmentIndex = coords[multiFeatureIndex][geometryIndex].length - segmentIndex - 1;
return helpers.lineString([coords[multiFeatureIndex][geometryIndex][segmentIndex], coords[multiFeatureIndex][geometryIndex][segmentIndex + 1]], properties, options);
}
throw new Error('geojson is invalid');
}
/**
* Finds a particular Point from a GeoJSON using `@turf/meta` indexes.
*
* Negative indexes are permitted.
*
* @param {FeatureCollection|Feature|Geometry} geojson Any GeoJSON Feature or Geometry
* @param {Object} [options={}] Optional parameters
* @param {number} [options.featureIndex=0] Feature Index
* @param {number} [options.multiFeatureIndex=0] Multi-Feature Index
* @param {number} [options.geometryIndex=0] Geometry Index
* @param {number} [options.coordIndex=0] Coord Index
* @param {Object} [options.properties={}] Translate Properties to output Point
* @param {BBox} [options.bbox={}] Translate BBox to output Point
* @param {number|string} [options.id={}] Translate Id to output Point
* @returns {Feature} 2-vertex GeoJSON Feature Point
* @example
* var multiLine = turf.multiLineString([
* [[10, 10], [50, 30], [30, 40]],
* [[-10, -10], [-50, -30], [-30, -40]]
* ]);
*
* // First Segment (defaults are 0)
* turf.findPoint(multiLine);
* // => Feature>
*
* // First Segment of the 2nd Multi-Feature
* turf.findPoint(multiLine, {multiFeatureIndex: 1});
* // => Feature>
*
* // Last Segment of last Multi-Feature
* turf.findPoint(multiLine, {multiFeatureIndex: -1, coordIndex: -1});
* // => Feature>
*/
function findPoint(geojson, options) {
// Optional Parameters
options = options || {};
if (!helpers.isObject(options)) throw new Error('options is invalid');
var featureIndex = options.featureIndex || 0;
var multiFeatureIndex = options.multiFeatureIndex || 0;
var geometryIndex = options.geometryIndex || 0;
var coordIndex = options.coordIndex || 0;
// Find FeatureIndex
var properties = options.properties;
var geometry;
switch (geojson.type) {
case 'FeatureCollection':
if (featureIndex < 0) featureIndex = geojson.features.length + featureIndex;
properties = properties || geojson.features[featureIndex].properties;
geometry = geojson.features[featureIndex].geometry;
break;
case 'Feature':
properties = properties || geojson.properties;
geometry = geojson.geometry;
break;
case 'Point':
case 'MultiPoint':
return null;
case 'LineString':
case 'Polygon':
case 'MultiLineString':
case 'MultiPolygon':
geometry = geojson;
break;
default:
throw new Error('geojson is invalid');
}
// Find Coord Index
if (geometry === null) return null;
var coords = geometry.coordinates;
switch (geometry.type) {
case 'Point':
return helpers.point(coords, properties, options);
case 'MultiPoint':
if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;
return helpers.point(coords[multiFeatureIndex], properties, options);
case 'LineString':
if (coordIndex < 0) coordIndex = coords.length + coordIndex;
return helpers.point(coords[coordIndex], properties, options);
case 'Polygon':
if (geometryIndex < 0) geometryIndex = coords.length + geometryIndex;
if (coordIndex < 0) coordIndex = coords[geometryIndex].length + coordIndex;
return helpers.point(coords[geometryIndex][coordIndex], properties, options);
case 'MultiLineString':
if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;
if (coordIndex < 0) coordIndex = coords[multiFeatureIndex].length + coordIndex;
return helpers.point(coords[multiFeatureIndex][coordIndex], properties, options);
case 'MultiPolygon':
if (multiFeatureIndex < 0) multiFeatureIndex = coords.length + multiFeatureIndex;
if (geometryIndex < 0) geometryIndex = coords[multiFeatureIndex].length + geometryIndex;
if (coordIndex < 0) coordIndex = coords[multiFeatureIndex][geometryIndex].length - coordIndex;
return helpers.point(coords[multiFeatureIndex][geometryIndex][coordIndex], properties, options);
}
throw new Error('geojson is invalid');
}
exports.coordEach = coordEach;
exports.coordReduce = coordReduce;
exports.propEach = propEach;
exports.propReduce = propReduce;
exports.featureEach = featureEach;
exports.featureReduce = featureReduce;
exports.coordAll = coordAll;
exports.geomEach = geomEach;
exports.geomReduce = geomReduce;
exports.flattenEach = flattenEach;
exports.flattenReduce = flattenReduce;
exports.segmentEach = segmentEach;
exports.segmentReduce = segmentReduce;
exports.lineEach = lineEach;
exports.lineReduce = lineReduce;
exports.findSegment = findSegment;
exports.findPoint = findPoint;
/***/ }),
/***/ 3160:
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
__webpack_require__.r(__webpack_exports__);
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ decode: function() { return /* binding */ decode; },
/* harmony export */ encode: function() { return /* binding */ encode; }
/* harmony export */ });
/*
* base64-arraybuffer 1.0.2
* Copyright (c) 2022 Niklas von Hertzen
* Released under MIT License
*/
var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
// Use a lookup table to find the index.
var lookup = typeof Uint8Array === 'undefined' ? [] : new Uint8Array(256);
for (var i = 0; i < chars.length; i++) {
lookup[chars.charCodeAt(i)] = i;
}
var encode = function (arraybuffer) {
var bytes = new Uint8Array(arraybuffer), i, len = bytes.length, base64 = '';
for (i = 0; i < len; i += 3) {
base64 += chars[bytes[i] >> 2];
base64 += chars[((bytes[i] & 3) << 4) | (bytes[i + 1] >> 4)];
base64 += chars[((bytes[i + 1] & 15) << 2) | (bytes[i + 2] >> 6)];
base64 += chars[bytes[i + 2] & 63];
}
if (len % 3 === 2) {
base64 = base64.substring(0, base64.length - 1) + '=';
}
else if (len % 3 === 1) {
base64 = base64.substring(0, base64.length - 2) + '==';
}
return base64;
};
var decode = function (base64) {
var bufferLength = base64.length * 0.75, len = base64.length, i, p = 0, encoded1, encoded2, encoded3, encoded4;
if (base64[base64.length - 1] === '=') {
bufferLength--;
if (base64[base64.length - 2] === '=') {
bufferLength--;
}
}
var arraybuffer = new ArrayBuffer(bufferLength), bytes = new Uint8Array(arraybuffer);
for (i = 0; i < len; i += 4) {
encoded1 = lookup[base64.charCodeAt(i)];
encoded2 = lookup[base64.charCodeAt(i + 1)];
encoded3 = lookup[base64.charCodeAt(i + 2)];
encoded4 = lookup[base64.charCodeAt(i + 3)];
bytes[p++] = (encoded1 << 2) | (encoded2 >> 4);
bytes[p++] = ((encoded2 & 15) << 4) | (encoded3 >> 2);
bytes[p++] = ((encoded3 & 3) << 6) | (encoded4 & 63);
}
return arraybuffer;
};
//# sourceMappingURL=base64-arraybuffer.es5.js.map
/***/ }),
/***/ 6116:
/***/ (function(module) {
module.exports = {
AFG: 'afghan',
ALA: '\\b\\wland',
ALB: 'albania',
DZA: 'algeria',
ASM: '^(?=.*americ).*samoa',
AND: 'andorra',
AGO: 'angola',
AIA: 'anguill?a',
ATA: 'antarctica',
ATG: 'antigua',
ARG: 'argentin',
ARM: 'armenia',
ABW: '^(?!.*bonaire).*\\baruba',
AUS: 'australia',
AUT: '^(?!.*hungary).*austria|\\baustri.*\\bemp',
AZE: 'azerbaijan',
BHS: 'bahamas',
BHR: 'bahrain',
BGD: 'bangladesh|^(?=.*east).*paki?stan',
BRB: 'barbados',
BLR: 'belarus|byelo',
BEL: '^(?!.*luxem).*belgium',
BLZ: 'belize|^(?=.*british).*honduras',
BEN: 'benin|dahome',
BMU: 'bermuda',
BTN: 'bhutan',
BOL: 'bolivia',
BES: '^(?=.*bonaire).*eustatius|^(?=.*carib).*netherlands|\\bbes.?islands',
BIH: 'herzegovina|bosnia',
BWA: 'botswana|bechuana',
BVT: 'bouvet',
BRA: 'brazil',
IOT: 'british.?indian.?ocean',
BRN: 'brunei',
BGR: 'bulgaria',
BFA: 'burkina|\\bfaso|upper.?volta',
BDI: 'burundi',
CPV: 'verde',
KHM: 'cambodia|kampuchea|khmer',
CMR: 'cameroon',
CAN: 'canada',
CYM: 'cayman',
CAF: '\\bcentral.african.republic',
TCD: '\\bchad',
CHL: '\\bchile',
CHN: '^(?!.*\\bmac)(?!.*\\bhong)(?!.*\\btai)(?!.*\\brep).*china|^(?=.*peo)(?=.*rep).*china',
CXR: 'christmas',
CCK: '\\bcocos|keeling',
COL: 'colombia',
COM: 'comoro',
COG: '^(?!.*\\bdem)(?!.*\\bd[\\.]?r)(?!.*kinshasa)(?!.*zaire)(?!.*belg)(?!.*l.opoldville)(?!.*free).*\\bcongo',
COK: '\\bcook',
CRI: 'costa.?rica',
CIV: 'ivoire|ivory',
HRV: 'croatia',
CUB: '\\bcuba',
CUW: '^(?!.*bonaire).*\\bcura(c|ç)ao',
CYP: 'cyprus',
CSK: 'czechoslovakia',
CZE: '^(?=.*rep).*czech|czechia|bohemia',
COD: '\\bdem.*congo|congo.*\\bdem|congo.*\\bd[\\.]?r|\\bd[\\.]?r.*congo|belgian.?congo|congo.?free.?state|kinshasa|zaire|l.opoldville|drc|droc|rdc',
DNK: 'denmark',
DJI: 'djibouti',
DMA: 'dominica(?!n)',
DOM: 'dominican.rep',
ECU: 'ecuador',
EGY: 'egypt',
SLV: 'el.?salvador',
GNQ: 'guine.*eq|eq.*guine|^(?=.*span).*guinea',
ERI: 'eritrea',
EST: 'estonia',
ETH: 'ethiopia|abyssinia',
FLK: 'falkland|malvinas',
FRO: 'faroe|faeroe',
FJI: 'fiji',
FIN: 'finland',
FRA: '^(?!.*\\bdep)(?!.*martinique).*france|french.?republic|\\bgaul',
GUF: '^(?=.*french).*guiana',
PYF: 'french.?polynesia|tahiti',
ATF: 'french.?southern',
GAB: 'gabon',
GMB: 'gambia',
GEO: '^(?!.*south).*georgia',
DDR: 'german.?democratic.?republic|democratic.?republic.*germany|east.germany',
DEU: '^(?!.*east).*germany|^(?=.*\\bfed.*\\brep).*german',
GHA: 'ghana|gold.?coast',
GIB: 'gibraltar',
GRC: 'greece|hellenic|hellas',
GRL: 'greenland',
GRD: 'grenada',
GLP: 'guadeloupe',
GUM: '\\bguam',
GTM: 'guatemala',
GGY: 'guernsey',
GIN: '^(?!.*eq)(?!.*span)(?!.*bissau)(?!.*portu)(?!.*new).*guinea',
GNB: 'bissau|^(?=.*portu).*guinea',
GUY: 'guyana|british.?guiana',
HTI: 'haiti',
HMD: 'heard.*mcdonald',
VAT: 'holy.?see|vatican|papal.?st',
HND: '^(?!.*brit).*honduras',
HKG: 'hong.?kong',
HUN: '^(?!.*austr).*hungary',
ISL: 'iceland',
IND: 'india(?!.*ocea)',
IDN: 'indonesia',
IRN: '\\biran|persia',
IRQ: '\\biraq|mesopotamia',
IRL: '(^ireland)|(^republic.*ireland)',
IMN: '^(?=.*isle).*\\bman',
ISR: 'israel',
ITA: 'italy',
JAM: 'jamaica',
JPN: 'japan',
JEY: 'jersey',
JOR: 'jordan',
KAZ: 'kazak',
KEN: 'kenya|british.?east.?africa|east.?africa.?prot',
KIR: 'kiribati',
PRK: '^(?=.*democrat|people|north|d.*p.*.r).*\\bkorea|dprk|korea.*(d.*p.*r)',
KWT: 'kuwait',
KGZ: 'kyrgyz|kirghiz',
LAO: '\\blaos?\\b',
LVA: 'latvia',
LBN: 'lebanon',
LSO: 'lesotho|basuto',
LBR: 'liberia',
LBY: 'libya',
LIE: 'liechtenstein',
LTU: 'lithuania',
LUX: '^(?!.*belg).*luxem',
MAC: 'maca(o|u)',
MDG: 'madagascar|malagasy',
MWI: 'malawi|nyasa',
MYS: 'malaysia',
MDV: 'maldive',
MLI: '\\bmali\\b',
MLT: '\\bmalta',
MHL: 'marshall',
MTQ: 'martinique',
MRT: 'mauritania',
MUS: 'mauritius',
MYT: '\\bmayotte',
MEX: '\\bmexic',
FSM: 'fed.*micronesia|micronesia.*fed',
MCO: 'monaco',
MNG: 'mongolia',
MNE: '^(?!.*serbia).*montenegro',
MSR: 'montserrat',
MAR: 'morocco|\\bmaroc',
MOZ: 'mozambique',
MMR: 'myanmar|burma',
NAM: 'namibia',
NRU: 'nauru',
NPL: 'nepal',
NLD: '^(?!.*\\bant)(?!.*\\bcarib).*netherlands',
ANT: '^(?=.*\\bant).*(nether|dutch)',
NCL: 'new.?caledonia',
NZL: 'new.?zealand',
NIC: 'nicaragua',
NER: '\\bniger(?!ia)',
NGA: 'nigeria',
NIU: 'niue',
NFK: 'norfolk',
MNP: 'mariana',
NOR: 'norway',
OMN: '\\boman|trucial',
PAK: '^(?!.*east).*paki?stan',
PLW: 'palau',
PSE: 'palestin|\\bgaza|west.?bank',
PAN: 'panama',
PNG: 'papua|new.?guinea',
PRY: 'paraguay',
PER: 'peru',
PHL: 'philippines',
PCN: 'pitcairn',
POL: 'poland',
PRT: 'portugal',
PRI: 'puerto.?rico',
QAT: 'qatar',
KOR: '^(?!.*d.*p.*r)(?!.*democrat)(?!.*people)(?!.*north).*\\bkorea(?!.*d.*p.*r)',
MDA: 'moldov|b(a|e)ssarabia',
REU: 'r(e|é)union',
ROU: 'r(o|u|ou)mania',
RUS: '\\brussia|soviet.?union|u\\.?s\\.?s\\.?r|socialist.?republics',
RWA: 'rwanda',
BLM: 'barth(e|é)lemy',
SHN: 'helena',
KNA: 'kitts|\\bnevis',
LCA: '\\blucia',
MAF: '^(?=.*collectivity).*martin|^(?=.*france).*martin(?!ique)|^(?=.*french).*martin(?!ique)',
SPM: 'miquelon',
VCT: 'vincent',
WSM: '^(?!.*amer).*samoa',
SMR: 'san.?marino',
STP: '\\bs(a|ã)o.?tom(e|é)',
SAU: '\\bsa\\w*.?arabia',
SEN: 'senegal',
SRB: '^(?!.*monte).*serbia',
SYC: 'seychell',
SLE: 'sierra',
SGP: 'singapore',
SXM: '^(?!.*martin)(?!.*saba).*maarten',
SVK: '^(?!.*cze).*slovak',
SVN: 'slovenia',
SLB: 'solomon',
SOM: 'somali',
ZAF: 'south.africa|s\\\\..?africa',
SGS: 'south.?georgia|sandwich',
SSD: '\\bs\\w*.?sudan',
ESP: 'spain',
LKA: 'sri.?lanka|ceylon',
SDN: '^(?!.*\\bs(?!u)).*sudan',
SUR: 'surinam|dutch.?guiana',
SJM: 'svalbard',
SWZ: 'swaziland',
SWE: 'sweden',
CHE: 'switz|swiss',
SYR: 'syria',
TWN: 'taiwan|taipei|formosa|^(?!.*peo)(?=.*rep).*china',
TJK: 'tajik',
THA: 'thailand|\\bsiam',
MKD: 'macedonia|fyrom',
TLS: '^(?=.*leste).*timor|^(?=.*east).*timor',
TGO: 'togo',
TKL: 'tokelau',
TON: 'tonga',
TTO: 'trinidad|tobago',
TUN: 'tunisia',
TUR: 'turkey',
TKM: 'turkmen',
TCA: 'turks',
TUV: 'tuvalu',
UGA: 'uganda',
UKR: 'ukrain',
ARE: 'emirates|^u\\.?a\\.?e\\.?$|united.?arab.?em',
GBR: 'united.?kingdom|britain|^u\\.?k\\.?$',
TZA: 'tanzania',
USA: 'united.?states\\b(?!.*islands)|\\bu\\.?s\\.?a\\.?\\b|^\\s*u\\.?s\\.?\\b(?!.*islands)',
UMI: 'minor.?outlying.?is',
URY: 'uruguay',
UZB: 'uzbek',
VUT: 'vanuatu|new.?hebrides',
VEN: 'venezuela',
VNM: '^(?!.*republic).*viet.?nam|^(?=.*socialist).*viet.?nam',
VGB: '^(?=.*\\bu\\.?\\s?k).*virgin|^(?=.*brit).*virgin|^(?=.*kingdom).*virgin',
VIR: '^(?=.*\\bu\\.?\\s?s).*virgin|^(?=.*states).*virgin',
WLF: 'futuna|wallis',
ESH: 'western.sahara',
YEM: '^(?!.*arab)(?!.*north)(?!.*sana)(?!.*peo)(?!.*dem)(?!.*south)(?!.*aden)(?!.*\\bp\\.?d\\.?r).*yemen',
YMD: '^(?=.*peo).*yemen|^(?!.*rep)(?=.*dem).*yemen|^(?=.*south).*yemen|^(?=.*aden).*yemen|^(?=.*\\bp\\.?d\\.?r).*yemen',
YUG: 'yugoslavia',
ZMB: 'zambia|northern.?rhodesia',
EAZ: 'zanzibar',
ZWE: 'zimbabwe|^(?!.*northern).*rhodesia'
}
/***/ }),
/***/ 7624:
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
E9: function() { return /* reexport */ format; },
SO: function() { return /* reexport */ locale; }
});
// UNUSED EXPORTS: FormatSpecifier, formatDefaultLocale, formatPrefix, formatSpecifier, precisionFixed, precisionPrefix, precisionRound
;// CONCATENATED MODULE: ./node_modules/d3-format/src/formatDecimal.js
/* harmony default export */ function formatDecimal(x) {
return Math.abs(x = Math.round(x)) >= 1e21
? x.toLocaleString("en").replace(/,/g, "")
: x.toString(10);
}
// Computes the decimal coefficient and exponent of the specified number x with
// significant digits p, where x is positive and p is in [1, 21] or undefined.
// For example, formatDecimalParts(1.23) returns ["123", 0].
function formatDecimalParts(x, p) {
if ((i = (x = p ? x.toExponential(p - 1) : x.toExponential()).indexOf("e")) < 0) return null; // NaN, ±Infinity
var i, coefficient = x.slice(0, i);
// The string returned by toExponential either has the form \d\.\d+e[-+]\d+
// (e.g., 1.2e+3) or the form \de[-+]\d+ (e.g., 1e+3).
return [
coefficient.length > 1 ? coefficient[0] + coefficient.slice(2) : coefficient,
+x.slice(i + 1)
];
}
;// CONCATENATED MODULE: ./node_modules/d3-format/src/exponent.js
/* harmony default export */ function exponent(x) {
return x = formatDecimalParts(Math.abs(x)), x ? x[1] : NaN;
}
;// CONCATENATED MODULE: ./node_modules/d3-format/src/formatGroup.js
/* harmony default export */ function formatGroup(grouping, thousands) {
return function(value, width) {
var i = value.length,
t = [],
j = 0,
g = grouping[0],
length = 0;
while (i > 0 && g > 0) {
if (length + g + 1 > width) g = Math.max(1, width - length);
t.push(value.substring(i -= g, i + g));
if ((length += g + 1) > width) break;
g = grouping[j = (j + 1) % grouping.length];
}
return t.reverse().join(thousands);
};
}
;// CONCATENATED MODULE: ./node_modules/d3-format/src/formatNumerals.js
/* harmony default export */ function formatNumerals(numerals) {
return function(value) {
return value.replace(/[0-9]/g, function(i) {
return numerals[+i];
});
};
}
;// CONCATENATED MODULE: ./node_modules/d3-format/src/formatSpecifier.js
// [[fill]align][sign][symbol][0][width][,][.precision][~][type]
var re = /^(?:(.)?([<>=^]))?([+\-( ])?([$#])?(0)?(\d+)?(,)?(\.\d+)?(~)?([a-z%])?$/i;
function formatSpecifier(specifier) {
if (!(match = re.exec(specifier))) throw new Error("invalid format: " + specifier);
var match;
return new FormatSpecifier({
fill: match[1],
align: match[2],
sign: match[3],
symbol: match[4],
zero: match[5],
width: match[6],
comma: match[7],
precision: match[8] && match[8].slice(1),
trim: match[9],
type: match[10]
});
}
formatSpecifier.prototype = FormatSpecifier.prototype; // instanceof
function FormatSpecifier(specifier) {
this.fill = specifier.fill === undefined ? " " : specifier.fill + "";
this.align = specifier.align === undefined ? ">" : specifier.align + "";
this.sign = specifier.sign === undefined ? "-" : specifier.sign + "";
this.symbol = specifier.symbol === undefined ? "" : specifier.symbol + "";
this.zero = !!specifier.zero;
this.width = specifier.width === undefined ? undefined : +specifier.width;
this.comma = !!specifier.comma;
this.precision = specifier.precision === undefined ? undefined : +specifier.precision;
this.trim = !!specifier.trim;
this.type = specifier.type === undefined ? "" : specifier.type + "";
}
FormatSpecifier.prototype.toString = function() {
return this.fill
+ this.align
+ this.sign
+ this.symbol
+ (this.zero ? "0" : "")
+ (this.width === undefined ? "" : Math.max(1, this.width | 0))
+ (this.comma ? "," : "")
+ (this.precision === undefined ? "" : "." + Math.max(0, this.precision | 0))
+ (this.trim ? "~" : "")
+ this.type;
};
;// CONCATENATED MODULE: ./node_modules/d3-format/src/formatTrim.js
// Trims insignificant zeros, e.g., replaces 1.2000k with 1.2k.
/* harmony default export */ function formatTrim(s) {
out: for (var n = s.length, i = 1, i0 = -1, i1; i < n; ++i) {
switch (s[i]) {
case ".": i0 = i1 = i; break;
case "0": if (i0 === 0) i0 = i; i1 = i; break;
default: if (!+s[i]) break out; if (i0 > 0) i0 = 0; break;
}
}
return i0 > 0 ? s.slice(0, i0) + s.slice(i1 + 1) : s;
}
;// CONCATENATED MODULE: ./node_modules/d3-format/src/formatPrefixAuto.js
var prefixExponent;
/* harmony default export */ function formatPrefixAuto(x, p) {
var d = formatDecimalParts(x, p);
if (!d) return x + "";
var coefficient = d[0],
exponent = d[1],
i = exponent - (prefixExponent = Math.max(-8, Math.min(8, Math.floor(exponent / 3))) * 3) + 1,
n = coefficient.length;
return i === n ? coefficient
: i > n ? coefficient + new Array(i - n + 1).join("0")
: i > 0 ? coefficient.slice(0, i) + "." + coefficient.slice(i)
: "0." + new Array(1 - i).join("0") + formatDecimalParts(x, Math.max(0, p + i - 1))[0]; // less than 1y!
}
;// CONCATENATED MODULE: ./node_modules/d3-format/src/formatRounded.js
/* harmony default export */ function formatRounded(x, p) {
var d = formatDecimalParts(x, p);
if (!d) return x + "";
var coefficient = d[0],
exponent = d[1];
return exponent < 0 ? "0." + new Array(-exponent).join("0") + coefficient
: coefficient.length > exponent + 1 ? coefficient.slice(0, exponent + 1) + "." + coefficient.slice(exponent + 1)
: coefficient + new Array(exponent - coefficient.length + 2).join("0");
}
;// CONCATENATED MODULE: ./node_modules/d3-format/src/formatTypes.js
/* harmony default export */ var formatTypes = ({
"%": function(x, p) { return (x * 100).toFixed(p); },
"b": function(x) { return Math.round(x).toString(2); },
"c": function(x) { return x + ""; },
"d": formatDecimal,
"e": function(x, p) { return x.toExponential(p); },
"f": function(x, p) { return x.toFixed(p); },
"g": function(x, p) { return x.toPrecision(p); },
"o": function(x) { return Math.round(x).toString(8); },
"p": function(x, p) { return formatRounded(x * 100, p); },
"r": formatRounded,
"s": formatPrefixAuto,
"X": function(x) { return Math.round(x).toString(16).toUpperCase(); },
"x": function(x) { return Math.round(x).toString(16); }
});
;// CONCATENATED MODULE: ./node_modules/d3-format/src/identity.js
/* harmony default export */ function identity(x) {
return x;
}
;// CONCATENATED MODULE: ./node_modules/d3-format/src/locale.js
var map = Array.prototype.map,
prefixes = ["y","z","a","f","p","n","µ","m","","k","M","G","T","P","E","Z","Y"];
/* harmony default export */ function locale(locale) {
var group = locale.grouping === undefined || locale.thousands === undefined ? identity : formatGroup(map.call(locale.grouping, Number), locale.thousands + ""),
currencyPrefix = locale.currency === undefined ? "" : locale.currency[0] + "",
currencySuffix = locale.currency === undefined ? "" : locale.currency[1] + "",
decimal = locale.decimal === undefined ? "." : locale.decimal + "",
numerals = locale.numerals === undefined ? identity : formatNumerals(map.call(locale.numerals, String)),
percent = locale.percent === undefined ? "%" : locale.percent + "",
minus = locale.minus === undefined ? "-" : locale.minus + "",
nan = locale.nan === undefined ? "NaN" : locale.nan + "";
function newFormat(specifier) {
specifier = formatSpecifier(specifier);
var fill = specifier.fill,
align = specifier.align,
sign = specifier.sign,
symbol = specifier.symbol,
zero = specifier.zero,
width = specifier.width,
comma = specifier.comma,
precision = specifier.precision,
trim = specifier.trim,
type = specifier.type;
// The "n" type is an alias for ",g".
if (type === "n") comma = true, type = "g";
// The "" type, and any invalid type, is an alias for ".12~g".
else if (!formatTypes[type]) precision === undefined && (precision = 12), trim = true, type = "g";
// If zero fill is specified, padding goes after sign and before digits.
if (zero || (fill === "0" && align === "=")) zero = true, fill = "0", align = "=";
// Compute the prefix and suffix.
// For SI-prefix, the suffix is lazily computed.
var prefix = symbol === "$" ? currencyPrefix : symbol === "#" && /[boxX]/.test(type) ? "0" + type.toLowerCase() : "",
suffix = symbol === "$" ? currencySuffix : /[%p]/.test(type) ? percent : "";
// What format function should we use?
// Is this an integer type?
// Can this type generate exponential notation?
var formatType = formatTypes[type],
maybeSuffix = /[defgprs%]/.test(type);
// Set the default precision if not specified,
// or clamp the specified precision to the supported range.
// For significant precision, it must be in [1, 21].
// For fixed precision, it must be in [0, 20].
precision = precision === undefined ? 6
: /[gprs]/.test(type) ? Math.max(1, Math.min(21, precision))
: Math.max(0, Math.min(20, precision));
function format(value) {
var valuePrefix = prefix,
valueSuffix = suffix,
i, n, c;
if (type === "c") {
valueSuffix = formatType(value) + valueSuffix;
value = "";
} else {
value = +value;
// Determine the sign. -0 is not less than 0, but 1 / -0 is!
var valueNegative = value < 0 || 1 / value < 0;
// Perform the initial formatting.
value = isNaN(value) ? nan : formatType(Math.abs(value), precision);
// Trim insignificant zeros.
if (trim) value = formatTrim(value);
// If a negative value rounds to zero after formatting, and no explicit positive sign is requested, hide the sign.
if (valueNegative && +value === 0 && sign !== "+") valueNegative = false;
// Compute the prefix and suffix.
valuePrefix = (valueNegative ? (sign === "(" ? sign : minus) : sign === "-" || sign === "(" ? "" : sign) + valuePrefix;
valueSuffix = (type === "s" ? prefixes[8 + prefixExponent / 3] : "") + valueSuffix + (valueNegative && sign === "(" ? ")" : "");
// Break the formatted value into the integer “value” part that can be
// grouped, and fractional or exponential “suffix” part that is not.
if (maybeSuffix) {
i = -1, n = value.length;
while (++i < n) {
if (c = value.charCodeAt(i), 48 > c || c > 57) {
valueSuffix = (c === 46 ? decimal + value.slice(i + 1) : value.slice(i)) + valueSuffix;
value = value.slice(0, i);
break;
}
}
}
}
// If the fill character is not "0", grouping is applied before padding.
if (comma && !zero) value = group(value, Infinity);
// Compute the padding.
var length = valuePrefix.length + value.length + valueSuffix.length,
padding = length < width ? new Array(width - length + 1).join(fill) : "";
// If the fill character is "0", grouping is applied after padding.
if (comma && zero) value = group(padding + value, padding.length ? width - valueSuffix.length : Infinity), padding = "";
// Reconstruct the final output based on the desired alignment.
switch (align) {
case "<": value = valuePrefix + value + valueSuffix + padding; break;
case "=": value = valuePrefix + padding + value + valueSuffix; break;
case "^": value = padding.slice(0, length = padding.length >> 1) + valuePrefix + value + valueSuffix + padding.slice(length); break;
default: value = padding + valuePrefix + value + valueSuffix; break;
}
return numerals(value);
}
format.toString = function() {
return specifier + "";
};
return format;
}
function formatPrefix(specifier, value) {
var f = newFormat((specifier = formatSpecifier(specifier), specifier.type = "f", specifier)),
e = Math.max(-8, Math.min(8, Math.floor(exponent(value) / 3))) * 3,
k = Math.pow(10, -e),
prefix = prefixes[8 + e / 3];
return function(value) {
return f(k * value) + prefix;
};
}
return {
format: newFormat,
formatPrefix: formatPrefix
};
}
;// CONCATENATED MODULE: ./node_modules/d3-format/src/defaultLocale.js
var defaultLocale_locale;
var format;
var formatPrefix;
defaultLocale({
decimal: ".",
thousands: ",",
grouping: [3],
currency: ["$", ""],
minus: "-"
});
function defaultLocale(definition) {
defaultLocale_locale = locale(definition);
format = defaultLocale_locale.format;
formatPrefix = defaultLocale_locale.formatPrefix;
return defaultLocale_locale;
}
;// CONCATENATED MODULE: ./node_modules/d3-format/src/index.js
/***/ }),
/***/ 4336:
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
Yn: function() { return /* reexport */ timeFormat; },
m_: function() { return /* reexport */ formatLocale; },
E9: function() { return /* reexport */ utcFormat; }
});
// UNUSED EXPORTS: isoFormat, isoParse, timeFormatDefaultLocale, timeParse, utcParse
// EXTERNAL MODULE: ./node_modules/d3-time/src/utcWeek.js
var utcWeek = __webpack_require__(8208);
// EXTERNAL MODULE: ./node_modules/d3-time/src/utcDay.js
var utcDay = __webpack_require__(8931);
// EXTERNAL MODULE: ./node_modules/d3-time/src/week.js
var src_week = __webpack_require__(6192);
// EXTERNAL MODULE: ./node_modules/d3-time/src/day.js
var src_day = __webpack_require__(8936);
// EXTERNAL MODULE: ./node_modules/d3-time/src/year.js
var year = __webpack_require__(2171);
// EXTERNAL MODULE: ./node_modules/d3-time/src/utcYear.js
var utcYear = __webpack_require__(3528);
;// CONCATENATED MODULE: ./node_modules/d3-time-format/src/locale.js
function localDate(d) {
if (0 <= d.y && d.y < 100) {
var date = new Date(-1, d.m, d.d, d.H, d.M, d.S, d.L);
date.setFullYear(d.y);
return date;
}
return new Date(d.y, d.m, d.d, d.H, d.M, d.S, d.L);
}
function utcDate(d) {
if (0 <= d.y && d.y < 100) {
var date = new Date(Date.UTC(-1, d.m, d.d, d.H, d.M, d.S, d.L));
date.setUTCFullYear(d.y);
return date;
}
return new Date(Date.UTC(d.y, d.m, d.d, d.H, d.M, d.S, d.L));
}
function newDate(y, m, d) {
return {y: y, m: m, d: d, H: 0, M: 0, S: 0, L: 0};
}
function formatLocale(locale) {
var locale_dateTime = locale.dateTime,
locale_date = locale.date,
locale_time = locale.time,
locale_periods = locale.periods,
locale_weekdays = locale.days,
locale_shortWeekdays = locale.shortDays,
locale_months = locale.months,
locale_shortMonths = locale.shortMonths;
var periodRe = formatRe(locale_periods),
periodLookup = formatLookup(locale_periods),
weekdayRe = formatRe(locale_weekdays),
weekdayLookup = formatLookup(locale_weekdays),
shortWeekdayRe = formatRe(locale_shortWeekdays),
shortWeekdayLookup = formatLookup(locale_shortWeekdays),
monthRe = formatRe(locale_months),
monthLookup = formatLookup(locale_months),
shortMonthRe = formatRe(locale_shortMonths),
shortMonthLookup = formatLookup(locale_shortMonths);
var formats = {
"a": formatShortWeekday,
"A": formatWeekday,
"b": formatShortMonth,
"B": formatMonth,
"c": null,
"d": formatDayOfMonth,
"e": formatDayOfMonth,
"f": formatMicroseconds,
"H": formatHour24,
"I": formatHour12,
"j": formatDayOfYear,
"L": formatMilliseconds,
"m": formatMonthNumber,
"M": formatMinutes,
"p": formatPeriod,
"q": formatQuarter,
"Q": formatUnixTimestamp,
"s": formatUnixTimestampSeconds,
"S": formatSeconds,
"u": formatWeekdayNumberMonday,
"U": formatWeekNumberSunday,
"V": formatWeekNumberISO,
"w": formatWeekdayNumberSunday,
"W": formatWeekNumberMonday,
"x": null,
"X": null,
"y": formatYear,
"Y": formatFullYear,
"Z": formatZone,
"%": formatLiteralPercent
};
var utcFormats = {
"a": formatUTCShortWeekday,
"A": formatUTCWeekday,
"b": formatUTCShortMonth,
"B": formatUTCMonth,
"c": null,
"d": formatUTCDayOfMonth,
"e": formatUTCDayOfMonth,
"f": formatUTCMicroseconds,
"H": formatUTCHour24,
"I": formatUTCHour12,
"j": formatUTCDayOfYear,
"L": formatUTCMilliseconds,
"m": formatUTCMonthNumber,
"M": formatUTCMinutes,
"p": formatUTCPeriod,
"q": formatUTCQuarter,
"Q": formatUnixTimestamp,
"s": formatUnixTimestampSeconds,
"S": formatUTCSeconds,
"u": formatUTCWeekdayNumberMonday,
"U": formatUTCWeekNumberSunday,
"V": formatUTCWeekNumberISO,
"w": formatUTCWeekdayNumberSunday,
"W": formatUTCWeekNumberMonday,
"x": null,
"X": null,
"y": formatUTCYear,
"Y": formatUTCFullYear,
"Z": formatUTCZone,
"%": formatLiteralPercent
};
var parses = {
"a": parseShortWeekday,
"A": parseWeekday,
"b": parseShortMonth,
"B": parseMonth,
"c": parseLocaleDateTime,
"d": parseDayOfMonth,
"e": parseDayOfMonth,
"f": parseMicroseconds,
"H": parseHour24,
"I": parseHour24,
"j": parseDayOfYear,
"L": parseMilliseconds,
"m": parseMonthNumber,
"M": parseMinutes,
"p": parsePeriod,
"q": parseQuarter,
"Q": parseUnixTimestamp,
"s": parseUnixTimestampSeconds,
"S": parseSeconds,
"u": parseWeekdayNumberMonday,
"U": parseWeekNumberSunday,
"V": parseWeekNumberISO,
"w": parseWeekdayNumberSunday,
"W": parseWeekNumberMonday,
"x": parseLocaleDate,
"X": parseLocaleTime,
"y": parseYear,
"Y": parseFullYear,
"Z": parseZone,
"%": parseLiteralPercent
};
// These recursive directive definitions must be deferred.
formats.x = newFormat(locale_date, formats);
formats.X = newFormat(locale_time, formats);
formats.c = newFormat(locale_dateTime, formats);
utcFormats.x = newFormat(locale_date, utcFormats);
utcFormats.X = newFormat(locale_time, utcFormats);
utcFormats.c = newFormat(locale_dateTime, utcFormats);
function newFormat(specifier, formats) {
return function(date) {
var string = [],
i = -1,
j = 0,
n = specifier.length,
c,
pad,
format;
if (!(date instanceof Date)) date = new Date(+date);
while (++i < n) {
if (specifier.charCodeAt(i) === 37) {
string.push(specifier.slice(j, i));
if ((pad = pads[c = specifier.charAt(++i)]) != null) c = specifier.charAt(++i);
else pad = c === "e" ? " " : "0";
if (format = formats[c]) c = format(date, pad);
string.push(c);
j = i + 1;
}
}
string.push(specifier.slice(j, i));
return string.join("");
};
}
function newParse(specifier, Z) {
return function(string) {
var d = newDate(1900, undefined, 1),
i = parseSpecifier(d, specifier, string += "", 0),
week, day;
if (i != string.length) return null;
// If a UNIX timestamp is specified, return it.
if ("Q" in d) return new Date(d.Q);
if ("s" in d) return new Date(d.s * 1000 + ("L" in d ? d.L : 0));
// If this is utcParse, never use the local timezone.
if (Z && !("Z" in d)) d.Z = 0;
// The am-pm flag is 0 for AM, and 1 for PM.
if ("p" in d) d.H = d.H % 12 + d.p * 12;
// If the month was not specified, inherit from the quarter.
if (d.m === undefined) d.m = "q" in d ? d.q : 0;
// Convert day-of-week and week-of-year to day-of-year.
if ("V" in d) {
if (d.V < 1 || d.V > 53) return null;
if (!("w" in d)) d.w = 1;
if ("Z" in d) {
week = utcDate(newDate(d.y, 0, 1)), day = week.getUTCDay();
week = day > 4 || day === 0 ? utcWeek/* utcMonday */.ot.ceil(week) : (0,utcWeek/* utcMonday */.ot)(week);
week = utcDay/* default */.c.offset(week, (d.V - 1) * 7);
d.y = week.getUTCFullYear();
d.m = week.getUTCMonth();
d.d = week.getUTCDate() + (d.w + 6) % 7;
} else {
week = localDate(newDate(d.y, 0, 1)), day = week.getDay();
week = day > 4 || day === 0 ? src_week/* monday */.qT.ceil(week) : (0,src_week/* monday */.qT)(week);
week = src_day/* default */.c.offset(week, (d.V - 1) * 7);
d.y = week.getFullYear();
d.m = week.getMonth();
d.d = week.getDate() + (d.w + 6) % 7;
}
} else if ("W" in d || "U" in d) {
if (!("w" in d)) d.w = "u" in d ? d.u % 7 : "W" in d ? 1 : 0;
day = "Z" in d ? utcDate(newDate(d.y, 0, 1)).getUTCDay() : localDate(newDate(d.y, 0, 1)).getDay();
d.m = 0;
d.d = "W" in d ? (d.w + 6) % 7 + d.W * 7 - (day + 5) % 7 : d.w + d.U * 7 - (day + 6) % 7;
}
// If a time zone is specified, all fields are interpreted as UTC and then
// offset according to the specified time zone.
if ("Z" in d) {
d.H += d.Z / 100 | 0;
d.M += d.Z % 100;
return utcDate(d);
}
// Otherwise, all fields are in local time.
return localDate(d);
};
}
function parseSpecifier(d, specifier, string, j) {
var i = 0,
n = specifier.length,
m = string.length,
c,
parse;
while (i < n) {
if (j >= m) return -1;
c = specifier.charCodeAt(i++);
if (c === 37) {
c = specifier.charAt(i++);
parse = parses[c in pads ? specifier.charAt(i++) : c];
if (!parse || ((j = parse(d, string, j)) < 0)) return -1;
} else if (c != string.charCodeAt(j++)) {
return -1;
}
}
return j;
}
function parsePeriod(d, string, i) {
var n = periodRe.exec(string.slice(i));
return n ? (d.p = periodLookup[n[0].toLowerCase()], i + n[0].length) : -1;
}
function parseShortWeekday(d, string, i) {
var n = shortWeekdayRe.exec(string.slice(i));
return n ? (d.w = shortWeekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
}
function parseWeekday(d, string, i) {
var n = weekdayRe.exec(string.slice(i));
return n ? (d.w = weekdayLookup[n[0].toLowerCase()], i + n[0].length) : -1;
}
function parseShortMonth(d, string, i) {
var n = shortMonthRe.exec(string.slice(i));
return n ? (d.m = shortMonthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
}
function parseMonth(d, string, i) {
var n = monthRe.exec(string.slice(i));
return n ? (d.m = monthLookup[n[0].toLowerCase()], i + n[0].length) : -1;
}
function parseLocaleDateTime(d, string, i) {
return parseSpecifier(d, locale_dateTime, string, i);
}
function parseLocaleDate(d, string, i) {
return parseSpecifier(d, locale_date, string, i);
}
function parseLocaleTime(d, string, i) {
return parseSpecifier(d, locale_time, string, i);
}
function formatShortWeekday(d) {
return locale_shortWeekdays[d.getDay()];
}
function formatWeekday(d) {
return locale_weekdays[d.getDay()];
}
function formatShortMonth(d) {
return locale_shortMonths[d.getMonth()];
}
function formatMonth(d) {
return locale_months[d.getMonth()];
}
function formatPeriod(d) {
return locale_periods[+(d.getHours() >= 12)];
}
function formatQuarter(d) {
return 1 + ~~(d.getMonth() / 3);
}
function formatUTCShortWeekday(d) {
return locale_shortWeekdays[d.getUTCDay()];
}
function formatUTCWeekday(d) {
return locale_weekdays[d.getUTCDay()];
}
function formatUTCShortMonth(d) {
return locale_shortMonths[d.getUTCMonth()];
}
function formatUTCMonth(d) {
return locale_months[d.getUTCMonth()];
}
function formatUTCPeriod(d) {
return locale_periods[+(d.getUTCHours() >= 12)];
}
function formatUTCQuarter(d) {
return 1 + ~~(d.getUTCMonth() / 3);
}
return {
format: function(specifier) {
var f = newFormat(specifier += "", formats);
f.toString = function() { return specifier; };
return f;
},
parse: function(specifier) {
var p = newParse(specifier += "", false);
p.toString = function() { return specifier; };
return p;
},
utcFormat: function(specifier) {
var f = newFormat(specifier += "", utcFormats);
f.toString = function() { return specifier; };
return f;
},
utcParse: function(specifier) {
var p = newParse(specifier += "", true);
p.toString = function() { return specifier; };
return p;
}
};
}
var pads = {"-": "", "_": " ", "0": "0"},
numberRe = /^\s*\d+/, // note: ignores next directive
percentRe = /^%/,
requoteRe = /[\\^$*+?|[\]().{}]/g;
function pad(value, fill, width) {
var sign = value < 0 ? "-" : "",
string = (sign ? -value : value) + "",
length = string.length;
return sign + (length < width ? new Array(width - length + 1).join(fill) + string : string);
}
function requote(s) {
return s.replace(requoteRe, "\\$&");
}
function formatRe(names) {
return new RegExp("^(?:" + names.map(requote).join("|") + ")", "i");
}
function formatLookup(names) {
var map = {}, i = -1, n = names.length;
while (++i < n) map[names[i].toLowerCase()] = i;
return map;
}
function parseWeekdayNumberSunday(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 1));
return n ? (d.w = +n[0], i + n[0].length) : -1;
}
function parseWeekdayNumberMonday(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 1));
return n ? (d.u = +n[0], i + n[0].length) : -1;
}
function parseWeekNumberSunday(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 2));
return n ? (d.U = +n[0], i + n[0].length) : -1;
}
function parseWeekNumberISO(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 2));
return n ? (d.V = +n[0], i + n[0].length) : -1;
}
function parseWeekNumberMonday(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 2));
return n ? (d.W = +n[0], i + n[0].length) : -1;
}
function parseFullYear(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 4));
return n ? (d.y = +n[0], i + n[0].length) : -1;
}
function parseYear(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 2));
return n ? (d.y = +n[0] + (+n[0] > 68 ? 1900 : 2000), i + n[0].length) : -1;
}
function parseZone(d, string, i) {
var n = /^(Z)|([+-]\d\d)(?::?(\d\d))?/.exec(string.slice(i, i + 6));
return n ? (d.Z = n[1] ? 0 : -(n[2] + (n[3] || "00")), i + n[0].length) : -1;
}
function parseQuarter(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 1));
return n ? (d.q = n[0] * 3 - 3, i + n[0].length) : -1;
}
function parseMonthNumber(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 2));
return n ? (d.m = n[0] - 1, i + n[0].length) : -1;
}
function parseDayOfMonth(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 2));
return n ? (d.d = +n[0], i + n[0].length) : -1;
}
function parseDayOfYear(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 3));
return n ? (d.m = 0, d.d = +n[0], i + n[0].length) : -1;
}
function parseHour24(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 2));
return n ? (d.H = +n[0], i + n[0].length) : -1;
}
function parseMinutes(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 2));
return n ? (d.M = +n[0], i + n[0].length) : -1;
}
function parseSeconds(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 2));
return n ? (d.S = +n[0], i + n[0].length) : -1;
}
function parseMilliseconds(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 3));
return n ? (d.L = +n[0], i + n[0].length) : -1;
}
function parseMicroseconds(d, string, i) {
var n = numberRe.exec(string.slice(i, i + 6));
return n ? (d.L = Math.floor(n[0] / 1000), i + n[0].length) : -1;
}
function parseLiteralPercent(d, string, i) {
var n = percentRe.exec(string.slice(i, i + 1));
return n ? i + n[0].length : -1;
}
function parseUnixTimestamp(d, string, i) {
var n = numberRe.exec(string.slice(i));
return n ? (d.Q = +n[0], i + n[0].length) : -1;
}
function parseUnixTimestampSeconds(d, string, i) {
var n = numberRe.exec(string.slice(i));
return n ? (d.s = +n[0], i + n[0].length) : -1;
}
function formatDayOfMonth(d, p) {
return pad(d.getDate(), p, 2);
}
function formatHour24(d, p) {
return pad(d.getHours(), p, 2);
}
function formatHour12(d, p) {
return pad(d.getHours() % 12 || 12, p, 2);
}
function formatDayOfYear(d, p) {
return pad(1 + src_day/* default */.c.count((0,year/* default */.c)(d), d), p, 3);
}
function formatMilliseconds(d, p) {
return pad(d.getMilliseconds(), p, 3);
}
function formatMicroseconds(d, p) {
return formatMilliseconds(d, p) + "000";
}
function formatMonthNumber(d, p) {
return pad(d.getMonth() + 1, p, 2);
}
function formatMinutes(d, p) {
return pad(d.getMinutes(), p, 2);
}
function formatSeconds(d, p) {
return pad(d.getSeconds(), p, 2);
}
function formatWeekdayNumberMonday(d) {
var day = d.getDay();
return day === 0 ? 7 : day;
}
function formatWeekNumberSunday(d, p) {
return pad(src_week/* sunday */.uU.count((0,year/* default */.c)(d) - 1, d), p, 2);
}
function formatWeekNumberISO(d, p) {
var day = d.getDay();
d = (day >= 4 || day === 0) ? (0,src_week/* thursday */.kD)(d) : src_week/* thursday */.kD.ceil(d);
return pad(src_week/* thursday */.kD.count((0,year/* default */.c)(d), d) + ((0,year/* default */.c)(d).getDay() === 4), p, 2);
}
function formatWeekdayNumberSunday(d) {
return d.getDay();
}
function formatWeekNumberMonday(d, p) {
return pad(src_week/* monday */.qT.count((0,year/* default */.c)(d) - 1, d), p, 2);
}
function formatYear(d, p) {
return pad(d.getFullYear() % 100, p, 2);
}
function formatFullYear(d, p) {
return pad(d.getFullYear() % 10000, p, 4);
}
function formatZone(d) {
var z = d.getTimezoneOffset();
return (z > 0 ? "-" : (z *= -1, "+"))
+ pad(z / 60 | 0, "0", 2)
+ pad(z % 60, "0", 2);
}
function formatUTCDayOfMonth(d, p) {
return pad(d.getUTCDate(), p, 2);
}
function formatUTCHour24(d, p) {
return pad(d.getUTCHours(), p, 2);
}
function formatUTCHour12(d, p) {
return pad(d.getUTCHours() % 12 || 12, p, 2);
}
function formatUTCDayOfYear(d, p) {
return pad(1 + utcDay/* default */.c.count((0,utcYear/* default */.c)(d), d), p, 3);
}
function formatUTCMilliseconds(d, p) {
return pad(d.getUTCMilliseconds(), p, 3);
}
function formatUTCMicroseconds(d, p) {
return formatUTCMilliseconds(d, p) + "000";
}
function formatUTCMonthNumber(d, p) {
return pad(d.getUTCMonth() + 1, p, 2);
}
function formatUTCMinutes(d, p) {
return pad(d.getUTCMinutes(), p, 2);
}
function formatUTCSeconds(d, p) {
return pad(d.getUTCSeconds(), p, 2);
}
function formatUTCWeekdayNumberMonday(d) {
var dow = d.getUTCDay();
return dow === 0 ? 7 : dow;
}
function formatUTCWeekNumberSunday(d, p) {
return pad(utcWeek/* utcSunday */.EV.count((0,utcYear/* default */.c)(d) - 1, d), p, 2);
}
function formatUTCWeekNumberISO(d, p) {
var day = d.getUTCDay();
d = (day >= 4 || day === 0) ? (0,utcWeek/* utcThursday */.yA)(d) : utcWeek/* utcThursday */.yA.ceil(d);
return pad(utcWeek/* utcThursday */.yA.count((0,utcYear/* default */.c)(d), d) + ((0,utcYear/* default */.c)(d).getUTCDay() === 4), p, 2);
}
function formatUTCWeekdayNumberSunday(d) {
return d.getUTCDay();
}
function formatUTCWeekNumberMonday(d, p) {
return pad(utcWeek/* utcMonday */.ot.count((0,utcYear/* default */.c)(d) - 1, d), p, 2);
}
function formatUTCYear(d, p) {
return pad(d.getUTCFullYear() % 100, p, 2);
}
function formatUTCFullYear(d, p) {
return pad(d.getUTCFullYear() % 10000, p, 4);
}
function formatUTCZone() {
return "+0000";
}
function formatLiteralPercent() {
return "%";
}
function formatUnixTimestamp(d) {
return +d;
}
function formatUnixTimestampSeconds(d) {
return Math.floor(+d / 1000);
}
;// CONCATENATED MODULE: ./node_modules/d3-time-format/src/defaultLocale.js
var locale;
var timeFormat;
var timeParse;
var utcFormat;
var utcParse;
defaultLocale({
dateTime: "%x, %X",
date: "%-m/%-d/%Y",
time: "%-I:%M:%S %p",
periods: ["AM", "PM"],
days: ["Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"],
shortDays: ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"],
months: ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
shortMonths: ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"]
});
function defaultLocale(definition) {
locale = formatLocale(definition);
timeFormat = locale.format;
timeParse = locale.parse;
utcFormat = locale.utcFormat;
utcParse = locale.utcParse;
return locale;
}
;// CONCATENATED MODULE: ./node_modules/d3-time-format/src/index.js
/***/ }),
/***/ 8936:
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ m: function() { return /* binding */ days; }
/* harmony export */ });
/* harmony import */ var _interval_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1628);
/* harmony import */ var _duration_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9792);
var day = (0,_interval_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .c)(function(date) {
date.setHours(0, 0, 0, 0);
}, function(date, step) {
date.setDate(date.getDate() + step);
}, function(start, end) {
return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * _duration_js__WEBPACK_IMPORTED_MODULE_1__/* .durationMinute */ .iy) / _duration_js__WEBPACK_IMPORTED_MODULE_1__/* .durationDay */ .SK;
}, function(date) {
return date.getDate() - 1;
});
/* harmony default export */ __webpack_exports__.c = (day);
var days = day.range;
/***/ }),
/***/ 9792:
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ KK: function() { return /* binding */ durationWeek; },
/* harmony export */ SK: function() { return /* binding */ durationDay; },
/* harmony export */ cg: function() { return /* binding */ durationHour; },
/* harmony export */ iy: function() { return /* binding */ durationMinute; },
/* harmony export */ yc: function() { return /* binding */ durationSecond; }
/* harmony export */ });
var durationSecond = 1e3;
var durationMinute = 6e4;
var durationHour = 36e5;
var durationDay = 864e5;
var durationWeek = 6048e5;
/***/ }),
/***/ 3220:
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
// ESM COMPAT FLAG
__webpack_require__.r(__webpack_exports__);
// EXPORTS
__webpack_require__.d(__webpack_exports__, {
timeDay: function() { return /* reexport */ day/* default */.c; },
timeDays: function() { return /* reexport */ day/* days */.m; },
timeFriday: function() { return /* reexport */ week/* friday */.iB; },
timeFridays: function() { return /* reexport */ week/* fridays */.sJ; },
timeHour: function() { return /* reexport */ src_hour; },
timeHours: function() { return /* reexport */ hours; },
timeInterval: function() { return /* reexport */ interval/* default */.c; },
timeMillisecond: function() { return /* reexport */ src_millisecond; },
timeMilliseconds: function() { return /* reexport */ milliseconds; },
timeMinute: function() { return /* reexport */ src_minute; },
timeMinutes: function() { return /* reexport */ minutes; },
timeMonday: function() { return /* reexport */ week/* monday */.qT; },
timeMondays: function() { return /* reexport */ week/* mondays */.QP; },
timeMonth: function() { return /* reexport */ src_month; },
timeMonths: function() { return /* reexport */ months; },
timeSaturday: function() { return /* reexport */ week/* saturday */.Wc; },
timeSaturdays: function() { return /* reexport */ week/* saturdays */.aI; },
timeSecond: function() { return /* reexport */ src_second; },
timeSeconds: function() { return /* reexport */ seconds; },
timeSunday: function() { return /* reexport */ week/* sunday */.uU; },
timeSundays: function() { return /* reexport */ week/* sundays */.Ab; },
timeThursday: function() { return /* reexport */ week/* thursday */.kD; },
timeThursdays: function() { return /* reexport */ week/* thursdays */.eC; },
timeTuesday: function() { return /* reexport */ week/* tuesday */.Mf; },
timeTuesdays: function() { return /* reexport */ week/* tuesdays */.Oc; },
timeWednesday: function() { return /* reexport */ week/* wednesday */.eg; },
timeWednesdays: function() { return /* reexport */ week/* wednesdays */.sn; },
timeWeek: function() { return /* reexport */ week/* sunday */.uU; },
timeWeeks: function() { return /* reexport */ week/* sundays */.Ab; },
timeYear: function() { return /* reexport */ year/* default */.c; },
timeYears: function() { return /* reexport */ year/* years */.Q; },
utcDay: function() { return /* reexport */ utcDay/* default */.c; },
utcDays: function() { return /* reexport */ utcDay/* utcDays */.o; },
utcFriday: function() { return /* reexport */ utcWeek/* utcFriday */.od; },
utcFridays: function() { return /* reexport */ utcWeek/* utcFridays */.iG; },
utcHour: function() { return /* reexport */ src_utcHour; },
utcHours: function() { return /* reexport */ utcHours; },
utcMillisecond: function() { return /* reexport */ src_millisecond; },
utcMilliseconds: function() { return /* reexport */ milliseconds; },
utcMinute: function() { return /* reexport */ src_utcMinute; },
utcMinutes: function() { return /* reexport */ utcMinutes; },
utcMonday: function() { return /* reexport */ utcWeek/* utcMonday */.ot; },
utcMondays: function() { return /* reexport */ utcWeek/* utcMondays */.iO; },
utcMonth: function() { return /* reexport */ src_utcMonth; },
utcMonths: function() { return /* reexport */ utcMonths; },
utcSaturday: function() { return /* reexport */ utcWeek/* utcSaturday */.Ad; },
utcSaturdays: function() { return /* reexport */ utcWeek/* utcSaturdays */.K8; },
utcSecond: function() { return /* reexport */ src_second; },
utcSeconds: function() { return /* reexport */ seconds; },
utcSunday: function() { return /* reexport */ utcWeek/* utcSunday */.EV; },
utcSundays: function() { return /* reexport */ utcWeek/* utcSundays */.Wq; },
utcThursday: function() { return /* reexport */ utcWeek/* utcThursday */.yA; },
utcThursdays: function() { return /* reexport */ utcWeek/* utcThursdays */.ob; },
utcTuesday: function() { return /* reexport */ utcWeek/* utcTuesday */.sG; },
utcTuesdays: function() { return /* reexport */ utcWeek/* utcTuesdays */.kl; },
utcWednesday: function() { return /* reexport */ utcWeek/* utcWednesday */._6; },
utcWednesdays: function() { return /* reexport */ utcWeek/* utcWednesdays */.W_; },
utcWeek: function() { return /* reexport */ utcWeek/* utcSunday */.EV; },
utcWeeks: function() { return /* reexport */ utcWeek/* utcSundays */.Wq; },
utcYear: function() { return /* reexport */ utcYear/* default */.c; },
utcYears: function() { return /* reexport */ utcYear/* utcYears */.i; }
});
// EXTERNAL MODULE: ./node_modules/d3-time/src/interval.js
var interval = __webpack_require__(1628);
;// CONCATENATED MODULE: ./node_modules/d3-time/src/millisecond.js
var millisecond = (0,interval/* default */.c)(function() {
// noop
}, function(date, step) {
date.setTime(+date + step);
}, function(start, end) {
return end - start;
});
// An optimized implementation for this simple case.
millisecond.every = function(k) {
k = Math.floor(k);
if (!isFinite(k) || !(k > 0)) return null;
if (!(k > 1)) return millisecond;
return (0,interval/* default */.c)(function(date) {
date.setTime(Math.floor(date / k) * k);
}, function(date, step) {
date.setTime(+date + step * k);
}, function(start, end) {
return (end - start) / k;
});
};
/* harmony default export */ var src_millisecond = (millisecond);
var milliseconds = millisecond.range;
// EXTERNAL MODULE: ./node_modules/d3-time/src/duration.js
var duration = __webpack_require__(9792);
;// CONCATENATED MODULE: ./node_modules/d3-time/src/second.js
var second = (0,interval/* default */.c)(function(date) {
date.setTime(date - date.getMilliseconds());
}, function(date, step) {
date.setTime(+date + step * duration/* durationSecond */.yc);
}, function(start, end) {
return (end - start) / duration/* durationSecond */.yc;
}, function(date) {
return date.getUTCSeconds();
});
/* harmony default export */ var src_second = (second);
var seconds = second.range;
;// CONCATENATED MODULE: ./node_modules/d3-time/src/minute.js
var minute = (0,interval/* default */.c)(function(date) {
date.setTime(date - date.getMilliseconds() - date.getSeconds() * duration/* durationSecond */.yc);
}, function(date, step) {
date.setTime(+date + step * duration/* durationMinute */.iy);
}, function(start, end) {
return (end - start) / duration/* durationMinute */.iy;
}, function(date) {
return date.getMinutes();
});
/* harmony default export */ var src_minute = (minute);
var minutes = minute.range;
;// CONCATENATED MODULE: ./node_modules/d3-time/src/hour.js
var hour = (0,interval/* default */.c)(function(date) {
date.setTime(date - date.getMilliseconds() - date.getSeconds() * duration/* durationSecond */.yc - date.getMinutes() * duration/* durationMinute */.iy);
}, function(date, step) {
date.setTime(+date + step * duration/* durationHour */.cg);
}, function(start, end) {
return (end - start) / duration/* durationHour */.cg;
}, function(date) {
return date.getHours();
});
/* harmony default export */ var src_hour = (hour);
var hours = hour.range;
// EXTERNAL MODULE: ./node_modules/d3-time/src/day.js
var day = __webpack_require__(8936);
// EXTERNAL MODULE: ./node_modules/d3-time/src/week.js
var week = __webpack_require__(6192);
;// CONCATENATED MODULE: ./node_modules/d3-time/src/month.js
var month = (0,interval/* default */.c)(function(date) {
date.setDate(1);
date.setHours(0, 0, 0, 0);
}, function(date, step) {
date.setMonth(date.getMonth() + step);
}, function(start, end) {
return end.getMonth() - start.getMonth() + (end.getFullYear() - start.getFullYear()) * 12;
}, function(date) {
return date.getMonth();
});
/* harmony default export */ var src_month = (month);
var months = month.range;
// EXTERNAL MODULE: ./node_modules/d3-time/src/year.js
var year = __webpack_require__(2171);
;// CONCATENATED MODULE: ./node_modules/d3-time/src/utcMinute.js
var utcMinute = (0,interval/* default */.c)(function(date) {
date.setUTCSeconds(0, 0);
}, function(date, step) {
date.setTime(+date + step * duration/* durationMinute */.iy);
}, function(start, end) {
return (end - start) / duration/* durationMinute */.iy;
}, function(date) {
return date.getUTCMinutes();
});
/* harmony default export */ var src_utcMinute = (utcMinute);
var utcMinutes = utcMinute.range;
;// CONCATENATED MODULE: ./node_modules/d3-time/src/utcHour.js
var utcHour = (0,interval/* default */.c)(function(date) {
date.setUTCMinutes(0, 0, 0);
}, function(date, step) {
date.setTime(+date + step * duration/* durationHour */.cg);
}, function(start, end) {
return (end - start) / duration/* durationHour */.cg;
}, function(date) {
return date.getUTCHours();
});
/* harmony default export */ var src_utcHour = (utcHour);
var utcHours = utcHour.range;
// EXTERNAL MODULE: ./node_modules/d3-time/src/utcDay.js
var utcDay = __webpack_require__(8931);
// EXTERNAL MODULE: ./node_modules/d3-time/src/utcWeek.js
var utcWeek = __webpack_require__(8208);
;// CONCATENATED MODULE: ./node_modules/d3-time/src/utcMonth.js
var utcMonth = (0,interval/* default */.c)(function(date) {
date.setUTCDate(1);
date.setUTCHours(0, 0, 0, 0);
}, function(date, step) {
date.setUTCMonth(date.getUTCMonth() + step);
}, function(start, end) {
return end.getUTCMonth() - start.getUTCMonth() + (end.getUTCFullYear() - start.getUTCFullYear()) * 12;
}, function(date) {
return date.getUTCMonth();
});
/* harmony default export */ var src_utcMonth = (utcMonth);
var utcMonths = utcMonth.range;
// EXTERNAL MODULE: ./node_modules/d3-time/src/utcYear.js
var utcYear = __webpack_require__(3528);
;// CONCATENATED MODULE: ./node_modules/d3-time/src/index.js
/***/ }),
/***/ 1628:
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ c: function() { return /* binding */ newInterval; }
/* harmony export */ });
var t0 = new Date,
t1 = new Date;
function newInterval(floori, offseti, count, field) {
function interval(date) {
return floori(date = arguments.length === 0 ? new Date : new Date(+date)), date;
}
interval.floor = function(date) {
return floori(date = new Date(+date)), date;
};
interval.ceil = function(date) {
return floori(date = new Date(date - 1)), offseti(date, 1), floori(date), date;
};
interval.round = function(date) {
var d0 = interval(date),
d1 = interval.ceil(date);
return date - d0 < d1 - date ? d0 : d1;
};
interval.offset = function(date, step) {
return offseti(date = new Date(+date), step == null ? 1 : Math.floor(step)), date;
};
interval.range = function(start, stop, step) {
var range = [], previous;
start = interval.ceil(start);
step = step == null ? 1 : Math.floor(step);
if (!(start < stop) || !(step > 0)) return range; // also handles Invalid Date
do range.push(previous = new Date(+start)), offseti(start, step), floori(start);
while (previous < start && start < stop);
return range;
};
interval.filter = function(test) {
return newInterval(function(date) {
if (date >= date) while (floori(date), !test(date)) date.setTime(date - 1);
}, function(date, step) {
if (date >= date) {
if (step < 0) while (++step <= 0) {
while (offseti(date, -1), !test(date)) {} // eslint-disable-line no-empty
} else while (--step >= 0) {
while (offseti(date, +1), !test(date)) {} // eslint-disable-line no-empty
}
}
});
};
if (count) {
interval.count = function(start, end) {
t0.setTime(+start), t1.setTime(+end);
floori(t0), floori(t1);
return Math.floor(count(t0, t1));
};
interval.every = function(step) {
step = Math.floor(step);
return !isFinite(step) || !(step > 0) ? null
: !(step > 1) ? interval
: interval.filter(field
? function(d) { return field(d) % step === 0; }
: function(d) { return interval.count(0, d) % step === 0; });
};
}
return interval;
}
/***/ }),
/***/ 8931:
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ o: function() { return /* binding */ utcDays; }
/* harmony export */ });
/* harmony import */ var _interval_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1628);
/* harmony import */ var _duration_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9792);
var utcDay = (0,_interval_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .c)(function(date) {
date.setUTCHours(0, 0, 0, 0);
}, function(date, step) {
date.setUTCDate(date.getUTCDate() + step);
}, function(start, end) {
return (end - start) / _duration_js__WEBPACK_IMPORTED_MODULE_1__/* .durationDay */ .SK;
}, function(date) {
return date.getUTCDate() - 1;
});
/* harmony default export */ __webpack_exports__.c = (utcDay);
var utcDays = utcDay.range;
/***/ }),
/***/ 8208:
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ Ad: function() { return /* binding */ utcSaturday; },
/* harmony export */ EV: function() { return /* binding */ utcSunday; },
/* harmony export */ K8: function() { return /* binding */ utcSaturdays; },
/* harmony export */ W_: function() { return /* binding */ utcWednesdays; },
/* harmony export */ Wq: function() { return /* binding */ utcSundays; },
/* harmony export */ _6: function() { return /* binding */ utcWednesday; },
/* harmony export */ iG: function() { return /* binding */ utcFridays; },
/* harmony export */ iO: function() { return /* binding */ utcMondays; },
/* harmony export */ kl: function() { return /* binding */ utcTuesdays; },
/* harmony export */ ob: function() { return /* binding */ utcThursdays; },
/* harmony export */ od: function() { return /* binding */ utcFriday; },
/* harmony export */ ot: function() { return /* binding */ utcMonday; },
/* harmony export */ sG: function() { return /* binding */ utcTuesday; },
/* harmony export */ yA: function() { return /* binding */ utcThursday; }
/* harmony export */ });
/* harmony import */ var _interval_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1628);
/* harmony import */ var _duration_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9792);
function utcWeekday(i) {
return (0,_interval_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .c)(function(date) {
date.setUTCDate(date.getUTCDate() - (date.getUTCDay() + 7 - i) % 7);
date.setUTCHours(0, 0, 0, 0);
}, function(date, step) {
date.setUTCDate(date.getUTCDate() + step * 7);
}, function(start, end) {
return (end - start) / _duration_js__WEBPACK_IMPORTED_MODULE_1__/* .durationWeek */ .KK;
});
}
var utcSunday = utcWeekday(0);
var utcMonday = utcWeekday(1);
var utcTuesday = utcWeekday(2);
var utcWednesday = utcWeekday(3);
var utcThursday = utcWeekday(4);
var utcFriday = utcWeekday(5);
var utcSaturday = utcWeekday(6);
var utcSundays = utcSunday.range;
var utcMondays = utcMonday.range;
var utcTuesdays = utcTuesday.range;
var utcWednesdays = utcWednesday.range;
var utcThursdays = utcThursday.range;
var utcFridays = utcFriday.range;
var utcSaturdays = utcSaturday.range;
/***/ }),
/***/ 3528:
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ i: function() { return /* binding */ utcYears; }
/* harmony export */ });
/* harmony import */ var _interval_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1628);
var utcYear = (0,_interval_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .c)(function(date) {
date.setUTCMonth(0, 1);
date.setUTCHours(0, 0, 0, 0);
}, function(date, step) {
date.setUTCFullYear(date.getUTCFullYear() + step);
}, function(start, end) {
return end.getUTCFullYear() - start.getUTCFullYear();
}, function(date) {
return date.getUTCFullYear();
});
// An optimized implementation for this simple case.
utcYear.every = function(k) {
return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : (0,_interval_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .c)(function(date) {
date.setUTCFullYear(Math.floor(date.getUTCFullYear() / k) * k);
date.setUTCMonth(0, 1);
date.setUTCHours(0, 0, 0, 0);
}, function(date, step) {
date.setUTCFullYear(date.getUTCFullYear() + step * k);
});
};
/* harmony default export */ __webpack_exports__.c = (utcYear);
var utcYears = utcYear.range;
/***/ }),
/***/ 6192:
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ Ab: function() { return /* binding */ sundays; },
/* harmony export */ Mf: function() { return /* binding */ tuesday; },
/* harmony export */ Oc: function() { return /* binding */ tuesdays; },
/* harmony export */ QP: function() { return /* binding */ mondays; },
/* harmony export */ Wc: function() { return /* binding */ saturday; },
/* harmony export */ aI: function() { return /* binding */ saturdays; },
/* harmony export */ eC: function() { return /* binding */ thursdays; },
/* harmony export */ eg: function() { return /* binding */ wednesday; },
/* harmony export */ iB: function() { return /* binding */ friday; },
/* harmony export */ kD: function() { return /* binding */ thursday; },
/* harmony export */ qT: function() { return /* binding */ monday; },
/* harmony export */ sJ: function() { return /* binding */ fridays; },
/* harmony export */ sn: function() { return /* binding */ wednesdays; },
/* harmony export */ uU: function() { return /* binding */ sunday; }
/* harmony export */ });
/* harmony import */ var _interval_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1628);
/* harmony import */ var _duration_js__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(9792);
function weekday(i) {
return (0,_interval_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .c)(function(date) {
date.setDate(date.getDate() - (date.getDay() + 7 - i) % 7);
date.setHours(0, 0, 0, 0);
}, function(date, step) {
date.setDate(date.getDate() + step * 7);
}, function(start, end) {
return (end - start - (end.getTimezoneOffset() - start.getTimezoneOffset()) * _duration_js__WEBPACK_IMPORTED_MODULE_1__/* .durationMinute */ .iy) / _duration_js__WEBPACK_IMPORTED_MODULE_1__/* .durationWeek */ .KK;
});
}
var sunday = weekday(0);
var monday = weekday(1);
var tuesday = weekday(2);
var wednesday = weekday(3);
var thursday = weekday(4);
var friday = weekday(5);
var saturday = weekday(6);
var sundays = sunday.range;
var mondays = monday.range;
var tuesdays = tuesday.range;
var wednesdays = wednesday.range;
var thursdays = thursday.range;
var fridays = friday.range;
var saturdays = saturday.range;
/***/ }),
/***/ 2171:
/***/ (function(__unused_webpack_module, __webpack_exports__, __webpack_require__) {
"use strict";
/* harmony export */ __webpack_require__.d(__webpack_exports__, {
/* harmony export */ Q: function() { return /* binding */ years; }
/* harmony export */ });
/* harmony import */ var _interval_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(1628);
var year = (0,_interval_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .c)(function(date) {
date.setMonth(0, 1);
date.setHours(0, 0, 0, 0);
}, function(date, step) {
date.setFullYear(date.getFullYear() + step);
}, function(start, end) {
return end.getFullYear() - start.getFullYear();
}, function(date) {
return date.getFullYear();
});
// An optimized implementation for this simple case.
year.every = function(k) {
return !isFinite(k = Math.floor(k)) || !(k > 0) ? null : (0,_interval_js__WEBPACK_IMPORTED_MODULE_0__/* ["default"] */ .c)(function(date) {
date.setFullYear(Math.floor(date.getFullYear() / k) * k);
date.setMonth(0, 1);
date.setHours(0, 0, 0, 0);
}, function(date, step) {
date.setFullYear(date.getFullYear() + step * k);
});
};
/* harmony default export */ __webpack_exports__.c = (year);
var years = year.range;
/***/ }),
/***/ 1252:
/***/ (function(module) {
"use strict";
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
var R = typeof Reflect === 'object' ? Reflect : null
var ReflectApply = R && typeof R.apply === 'function'
? R.apply
: function ReflectApply(target, receiver, args) {
return Function.prototype.apply.call(target, receiver, args);
}
var ReflectOwnKeys
if (R && typeof R.ownKeys === 'function') {
ReflectOwnKeys = R.ownKeys
} else if (Object.getOwnPropertySymbols) {
ReflectOwnKeys = function ReflectOwnKeys(target) {
return Object.getOwnPropertyNames(target)
.concat(Object.getOwnPropertySymbols(target));
};
} else {
ReflectOwnKeys = function ReflectOwnKeys(target) {
return Object.getOwnPropertyNames(target);
};
}
function ProcessEmitWarning(warning) {
if (console && console.warn) console.warn(warning);
}
var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) {
return value !== value;
}
function EventEmitter() {
EventEmitter.init.call(this);
}
module.exports = EventEmitter;
module.exports.once = once;
// Backwards-compat with node 0.10.x
EventEmitter.EventEmitter = EventEmitter;
EventEmitter.prototype._events = undefined;
EventEmitter.prototype._eventsCount = 0;
EventEmitter.prototype._maxListeners = undefined;
// By default EventEmitters will print a warning if more than 10 listeners are
// added to it. This is a useful default which helps finding memory leaks.
var defaultMaxListeners = 10;
function checkListener(listener) {
if (typeof listener !== 'function') {
throw new TypeError('The "listener" argument must be of type Function. Received type ' + typeof listener);
}
}
Object.defineProperty(EventEmitter, 'defaultMaxListeners', {
enumerable: true,
get: function() {
return defaultMaxListeners;
},
set: function(arg) {
if (typeof arg !== 'number' || arg < 0 || NumberIsNaN(arg)) {
throw new RangeError('The value of "defaultMaxListeners" is out of range. It must be a non-negative number. Received ' + arg + '.');
}
defaultMaxListeners = arg;
}
});
EventEmitter.init = function() {
if (this._events === undefined ||
this._events === Object.getPrototypeOf(this)._events) {
this._events = Object.create(null);
this._eventsCount = 0;
}
this._maxListeners = this._maxListeners || undefined;
};
// Obviously not all Emitters should be limited to 10. This function allows
// that to be increased. Set to zero for unlimited.
EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) {
if (typeof n !== 'number' || n < 0 || NumberIsNaN(n)) {
throw new RangeError('The value of "n" is out of range. It must be a non-negative number. Received ' + n + '.');
}
this._maxListeners = n;
return this;
};
function _getMaxListeners(that) {
if (that._maxListeners === undefined)
return EventEmitter.defaultMaxListeners;
return that._maxListeners;
}
EventEmitter.prototype.getMaxListeners = function getMaxListeners() {
return _getMaxListeners(this);
};
EventEmitter.prototype.emit = function emit(type) {
var args = [];
for (var i = 1; i < arguments.length; i++) args.push(arguments[i]);
var doError = (type === 'error');
var events = this._events;
if (events !== undefined)
doError = (doError && events.error === undefined);
else if (!doError)
return false;
// If there is no 'error' event listener then throw.
if (doError) {
var er;
if (args.length > 0)
er = args[0];
if (er instanceof Error) {
// Note: The comments on the `throw` lines are intentional, they show
// up in Node's output if this results in an unhandled exception.
throw er; // Unhandled 'error' event
}
// At least give some kind of context to the user
var err = new Error('Unhandled error.' + (er ? ' (' + er.message + ')' : ''));
err.context = er;
throw err; // Unhandled 'error' event
}
var handler = events[type];
if (handler === undefined)
return false;
if (typeof handler === 'function') {
ReflectApply(handler, this, args);
} else {
var len = handler.length;
var listeners = arrayClone(handler, len);
for (var i = 0; i < len; ++i)
ReflectApply(listeners[i], this, args);
}
return true;
};
function _addListener(target, type, listener, prepend) {
var m;
var events;
var existing;
checkListener(listener);
events = target._events;
if (events === undefined) {
events = target._events = Object.create(null);
target._eventsCount = 0;
} else {
// To avoid recursion in the case that type === "newListener"! Before
// adding it to the listeners, first emit "newListener".
if (events.newListener !== undefined) {
target.emit('newListener', type,
listener.listener ? listener.listener : listener);
// Re-assign `events` because a newListener handler could have caused the
// this._events to be assigned to a new object
events = target._events;
}
existing = events[type];
}
if (existing === undefined) {
// Optimize the case of one listener. Don't need the extra array object.
existing = events[type] = listener;
++target._eventsCount;
} else {
if (typeof existing === 'function') {
// Adding the second element, need to change to array.
existing = events[type] =
prepend ? [listener, existing] : [existing, listener];
// If we've already got an array, just append.
} else if (prepend) {
existing.unshift(listener);
} else {
existing.push(listener);
}
// Check for listener leak
m = _getMaxListeners(target);
if (m > 0 && existing.length > m && !existing.warned) {
existing.warned = true;
// No error code for this since it is a Warning
// eslint-disable-next-line no-restricted-syntax
var w = new Error('Possible EventEmitter memory leak detected. ' +
existing.length + ' ' + String(type) + ' listeners ' +
'added. Use emitter.setMaxListeners() to ' +
'increase limit');
w.name = 'MaxListenersExceededWarning';
w.emitter = target;
w.type = type;
w.count = existing.length;
ProcessEmitWarning(w);
}
}
return target;
}
EventEmitter.prototype.addListener = function addListener(type, listener) {
return _addListener(this, type, listener, false);
};
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.prependListener =
function prependListener(type, listener) {
return _addListener(this, type, listener, true);
};
function onceWrapper() {
if (!this.fired) {
this.target.removeListener(this.type, this.wrapFn);
this.fired = true;
if (arguments.length === 0)
return this.listener.call(this.target);
return this.listener.apply(this.target, arguments);
}
}
function _onceWrap(target, type, listener) {
var state = { fired: false, wrapFn: undefined, target: target, type: type, listener: listener };
var wrapped = onceWrapper.bind(state);
wrapped.listener = listener;
state.wrapFn = wrapped;
return wrapped;
}
EventEmitter.prototype.once = function once(type, listener) {
checkListener(listener);
this.on(type, _onceWrap(this, type, listener));
return this;
};
EventEmitter.prototype.prependOnceListener =
function prependOnceListener(type, listener) {
checkListener(listener);
this.prependListener(type, _onceWrap(this, type, listener));
return this;
};
// Emits a 'removeListener' event if and only if the listener was removed.
EventEmitter.prototype.removeListener =
function removeListener(type, listener) {
var list, events, position, i, originalListener;
checkListener(listener);
events = this._events;
if (events === undefined)
return this;
list = events[type];
if (list === undefined)
return this;
if (list === listener || list.listener === listener) {
if (--this._eventsCount === 0)
this._events = Object.create(null);
else {
delete events[type];
if (events.removeListener)
this.emit('removeListener', type, list.listener || listener);
}
} else if (typeof list !== 'function') {
position = -1;
for (i = list.length - 1; i >= 0; i--) {
if (list[i] === listener || list[i].listener === listener) {
originalListener = list[i].listener;
position = i;
break;
}
}
if (position < 0)
return this;
if (position === 0)
list.shift();
else {
spliceOne(list, position);
}
if (list.length === 1)
events[type] = list[0];
if (events.removeListener !== undefined)
this.emit('removeListener', type, originalListener || listener);
}
return this;
};
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
EventEmitter.prototype.removeAllListeners =
function removeAllListeners(type) {
var listeners, events, i;
events = this._events;
if (events === undefined)
return this;
// not listening for removeListener, no need to emit
if (events.removeListener === undefined) {
if (arguments.length === 0) {
this._events = Object.create(null);
this._eventsCount = 0;
} else if (events[type] !== undefined) {
if (--this._eventsCount === 0)
this._events = Object.create(null);
else
delete events[type];
}
return this;
}
// emit removeListener for all listeners on all events
if (arguments.length === 0) {
var keys = Object.keys(events);
var key;
for (i = 0; i < keys.length; ++i) {
key = keys[i];
if (key === 'removeListener') continue;
this.removeAllListeners(key);
}
this.removeAllListeners('removeListener');
this._events = Object.create(null);
this._eventsCount = 0;
return this;
}
listeners = events[type];
if (typeof listeners === 'function') {
this.removeListener(type, listeners);
} else if (listeners !== undefined) {
// LIFO order
for (i = listeners.length - 1; i >= 0; i--) {
this.removeListener(type, listeners[i]);
}
}
return this;
};
function _listeners(target, type, unwrap) {
var events = target._events;
if (events === undefined)
return [];
var evlistener = events[type];
if (evlistener === undefined)
return [];
if (typeof evlistener === 'function')
return unwrap ? [evlistener.listener || evlistener] : [evlistener];
return unwrap ?
unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length);
}
EventEmitter.prototype.listeners = function listeners(type) {
return _listeners(this, type, true);
};
EventEmitter.prototype.rawListeners = function rawListeners(type) {
return _listeners(this, type, false);
};
EventEmitter.listenerCount = function(emitter, type) {
if (typeof emitter.listenerCount === 'function') {
return emitter.listenerCount(type);
} else {
return listenerCount.call(emitter, type);
}
};
EventEmitter.prototype.listenerCount = listenerCount;
function listenerCount(type) {
var events = this._events;
if (events !== undefined) {
var evlistener = events[type];
if (typeof evlistener === 'function') {
return 1;
} else if (evlistener !== undefined) {
return evlistener.length;
}
}
return 0;
}
EventEmitter.prototype.eventNames = function eventNames() {
return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : [];
};
function arrayClone(arr, n) {
var copy = new Array(n);
for (var i = 0; i < n; ++i)
copy[i] = arr[i];
return copy;
}
function spliceOne(list, index) {
for (; index + 1 < list.length; index++)
list[index] = list[index + 1];
list.pop();
}
function unwrapListeners(arr) {
var ret = new Array(arr.length);
for (var i = 0; i < ret.length; ++i) {
ret[i] = arr[i].listener || arr[i];
}
return ret;
}
function once(emitter, name) {
return new Promise(function (resolve, reject) {
function errorListener(err) {
emitter.removeListener(name, resolver);
reject(err);
}
function resolver() {
if (typeof emitter.removeListener === 'function') {
emitter.removeListener('error', errorListener);
}
resolve([].slice.call(arguments));
};
eventTargetAgnosticAddListener(emitter, name, resolver, { once: true });
if (name !== 'error') {
addErrorHandlerIfEventEmitter(emitter, errorListener, { once: true });
}
});
}
function addErrorHandlerIfEventEmitter(emitter, handler, flags) {
if (typeof emitter.on === 'function') {
eventTargetAgnosticAddListener(emitter, 'error', handler, flags);
}
}
function eventTargetAgnosticAddListener(emitter, name, listener, flags) {
if (typeof emitter.on === 'function') {
if (flags.once) {
emitter.once(name, listener);
} else {
emitter.on(name, listener);
}
} else if (typeof emitter.addEventListener === 'function') {
// EventTarget does not have `error` event semantics like Node
// EventEmitters, we do not listen for `error` events here.
emitter.addEventListener(name, function wrapListener(arg) {
// IE does not have builtin `{ once: true }` support so we
// have to do it manually.
if (flags.once) {
emitter.removeEventListener(name, wrapListener);
}
listener(arg);
});
} else {
throw new TypeError('The "emitter" argument must be of type EventEmitter. Received type ' + typeof emitter);
}
}
/***/ }),
/***/ 8248:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
/**
* inspired by is-number
* but significantly simplified and sped up by ignoring number and string constructors
* ie these return false:
* new Number(1)
* new String('1')
*/
var allBlankCharCodes = __webpack_require__(4576);
module.exports = function(n) {
var type = typeof n;
if(type === 'string') {
var original = n;
n = +n;
// whitespace strings cast to zero - filter them out
if(n===0 && allBlankCharCodes(original)) return false;
}
else if(type !== 'number') return false;
return n - n < 1;
};
/***/ }),
/***/ 2408:
/***/ (function(module) {
module.exports = adjoint;
/**
* Calculates the adjugate of a mat4
*
* @param {mat4} out the receiving matrix
* @param {mat4} a the source matrix
* @returns {mat4} out
*/
function adjoint(out, a) {
var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
out[0] = (a11 * (a22 * a33 - a23 * a32) - a21 * (a12 * a33 - a13 * a32) + a31 * (a12 * a23 - a13 * a22));
out[1] = -(a01 * (a22 * a33 - a23 * a32) - a21 * (a02 * a33 - a03 * a32) + a31 * (a02 * a23 - a03 * a22));
out[2] = (a01 * (a12 * a33 - a13 * a32) - a11 * (a02 * a33 - a03 * a32) + a31 * (a02 * a13 - a03 * a12));
out[3] = -(a01 * (a12 * a23 - a13 * a22) - a11 * (a02 * a23 - a03 * a22) + a21 * (a02 * a13 - a03 * a12));
out[4] = -(a10 * (a22 * a33 - a23 * a32) - a20 * (a12 * a33 - a13 * a32) + a30 * (a12 * a23 - a13 * a22));
out[5] = (a00 * (a22 * a33 - a23 * a32) - a20 * (a02 * a33 - a03 * a32) + a30 * (a02 * a23 - a03 * a22));
out[6] = -(a00 * (a12 * a33 - a13 * a32) - a10 * (a02 * a33 - a03 * a32) + a30 * (a02 * a13 - a03 * a12));
out[7] = (a00 * (a12 * a23 - a13 * a22) - a10 * (a02 * a23 - a03 * a22) + a20 * (a02 * a13 - a03 * a12));
out[8] = (a10 * (a21 * a33 - a23 * a31) - a20 * (a11 * a33 - a13 * a31) + a30 * (a11 * a23 - a13 * a21));
out[9] = -(a00 * (a21 * a33 - a23 * a31) - a20 * (a01 * a33 - a03 * a31) + a30 * (a01 * a23 - a03 * a21));
out[10] = (a00 * (a11 * a33 - a13 * a31) - a10 * (a01 * a33 - a03 * a31) + a30 * (a01 * a13 - a03 * a11));
out[11] = -(a00 * (a11 * a23 - a13 * a21) - a10 * (a01 * a23 - a03 * a21) + a20 * (a01 * a13 - a03 * a11));
out[12] = -(a10 * (a21 * a32 - a22 * a31) - a20 * (a11 * a32 - a12 * a31) + a30 * (a11 * a22 - a12 * a21));
out[13] = (a00 * (a21 * a32 - a22 * a31) - a20 * (a01 * a32 - a02 * a31) + a30 * (a01 * a22 - a02 * a21));
out[14] = -(a00 * (a11 * a32 - a12 * a31) - a10 * (a01 * a32 - a02 * a31) + a30 * (a01 * a12 - a02 * a11));
out[15] = (a00 * (a11 * a22 - a12 * a21) - a10 * (a01 * a22 - a02 * a21) + a20 * (a01 * a12 - a02 * a11));
return out;
};
/***/ }),
/***/ 6860:
/***/ (function(module) {
module.exports = clone;
/**
* Creates a new mat4 initialized with values from an existing matrix
*
* @param {mat4} a matrix to clone
* @returns {mat4} a new 4x4 matrix
*/
function clone(a) {
var out = new Float32Array(16);
out[0] = a[0];
out[1] = a[1];
out[2] = a[2];
out[3] = a[3];
out[4] = a[4];
out[5] = a[5];
out[6] = a[6];
out[7] = a[7];
out[8] = a[8];
out[9] = a[9];
out[10] = a[10];
out[11] = a[11];
out[12] = a[12];
out[13] = a[13];
out[14] = a[14];
out[15] = a[15];
return out;
};
/***/ }),
/***/ 4492:
/***/ (function(module) {
module.exports = copy;
/**
* Copy the values from one mat4 to another
*
* @param {mat4} out the receiving matrix
* @param {mat4} a the source matrix
* @returns {mat4} out
*/
function copy(out, a) {
out[0] = a[0];
out[1] = a[1];
out[2] = a[2];
out[3] = a[3];
out[4] = a[4];
out[5] = a[5];
out[6] = a[6];
out[7] = a[7];
out[8] = a[8];
out[9] = a[9];
out[10] = a[10];
out[11] = a[11];
out[12] = a[12];
out[13] = a[13];
out[14] = a[14];
out[15] = a[15];
return out;
};
/***/ }),
/***/ 4212:
/***/ (function(module) {
module.exports = create;
/**
* Creates a new identity mat4
*
* @returns {mat4} a new 4x4 matrix
*/
function create() {
var out = new Float32Array(16);
out[0] = 1;
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 0;
out[5] = 1;
out[6] = 0;
out[7] = 0;
out[8] = 0;
out[9] = 0;
out[10] = 1;
out[11] = 0;
out[12] = 0;
out[13] = 0;
out[14] = 0;
out[15] = 1;
return out;
};
/***/ }),
/***/ 800:
/***/ (function(module) {
module.exports = determinant;
/**
* Calculates the determinant of a mat4
*
* @param {mat4} a the source matrix
* @returns {Number} determinant of a
*/
function determinant(a) {
var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],
b00 = a00 * a11 - a01 * a10,
b01 = a00 * a12 - a02 * a10,
b02 = a00 * a13 - a03 * a10,
b03 = a01 * a12 - a02 * a11,
b04 = a01 * a13 - a03 * a11,
b05 = a02 * a13 - a03 * a12,
b06 = a20 * a31 - a21 * a30,
b07 = a20 * a32 - a22 * a30,
b08 = a20 * a33 - a23 * a30,
b09 = a21 * a32 - a22 * a31,
b10 = a21 * a33 - a23 * a31,
b11 = a22 * a33 - a23 * a32;
// Calculate the determinant
return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
};
/***/ }),
/***/ 1784:
/***/ (function(module) {
module.exports = fromQuat;
/**
* Creates a matrix from a quaternion rotation.
*
* @param {mat4} out mat4 receiving operation result
* @param {quat4} q Rotation quaternion
* @returns {mat4} out
*/
function fromQuat(out, q) {
var x = q[0], y = q[1], z = q[2], w = q[3],
x2 = x + x,
y2 = y + y,
z2 = z + z,
xx = x * x2,
yx = y * x2,
yy = y * y2,
zx = z * x2,
zy = z * y2,
zz = z * z2,
wx = w * x2,
wy = w * y2,
wz = w * z2;
out[0] = 1 - yy - zz;
out[1] = yx + wz;
out[2] = zx - wy;
out[3] = 0;
out[4] = yx - wz;
out[5] = 1 - xx - zz;
out[6] = zy + wx;
out[7] = 0;
out[8] = zx + wy;
out[9] = zy - wx;
out[10] = 1 - xx - yy;
out[11] = 0;
out[12] = 0;
out[13] = 0;
out[14] = 0;
out[15] = 1;
return out;
};
/***/ }),
/***/ 1616:
/***/ (function(module) {
module.exports = fromRotation
/**
* Creates a matrix from a given angle around a given axis
* This is equivalent to (but much faster than):
*
* mat4.identity(dest)
* mat4.rotate(dest, dest, rad, axis)
*
* @param {mat4} out mat4 receiving operation result
* @param {Number} rad the angle to rotate the matrix by
* @param {vec3} axis the axis to rotate around
* @returns {mat4} out
*/
function fromRotation(out, rad, axis) {
var s, c, t
var x = axis[0]
var y = axis[1]
var z = axis[2]
var len = Math.sqrt(x * x + y * y + z * z)
if (Math.abs(len) < 0.000001) {
return null
}
len = 1 / len
x *= len
y *= len
z *= len
s = Math.sin(rad)
c = Math.cos(rad)
t = 1 - c
// Perform rotation-specific matrix multiplication
out[0] = x * x * t + c
out[1] = y * x * t + z * s
out[2] = z * x * t - y * s
out[3] = 0
out[4] = x * y * t - z * s
out[5] = y * y * t + c
out[6] = z * y * t + x * s
out[7] = 0
out[8] = x * z * t + y * s
out[9] = y * z * t - x * s
out[10] = z * z * t + c
out[11] = 0
out[12] = 0
out[13] = 0
out[14] = 0
out[15] = 1
return out
}
/***/ }),
/***/ 1944:
/***/ (function(module) {
module.exports = fromRotationTranslation;
/**
* Creates a matrix from a quaternion rotation and vector translation
* This is equivalent to (but much faster than):
*
* mat4.identity(dest);
* mat4.translate(dest, vec);
* var quatMat = mat4.create();
* quat4.toMat4(quat, quatMat);
* mat4.multiply(dest, quatMat);
*
* @param {mat4} out mat4 receiving operation result
* @param {quat4} q Rotation quaternion
* @param {vec3} v Translation vector
* @returns {mat4} out
*/
function fromRotationTranslation(out, q, v) {
// Quaternion math
var x = q[0], y = q[1], z = q[2], w = q[3],
x2 = x + x,
y2 = y + y,
z2 = z + z,
xx = x * x2,
xy = x * y2,
xz = x * z2,
yy = y * y2,
yz = y * z2,
zz = z * z2,
wx = w * x2,
wy = w * y2,
wz = w * z2;
out[0] = 1 - (yy + zz);
out[1] = xy + wz;
out[2] = xz - wy;
out[3] = 0;
out[4] = xy - wz;
out[5] = 1 - (xx + zz);
out[6] = yz + wx;
out[7] = 0;
out[8] = xz + wy;
out[9] = yz - wx;
out[10] = 1 - (xx + yy);
out[11] = 0;
out[12] = v[0];
out[13] = v[1];
out[14] = v[2];
out[15] = 1;
return out;
};
/***/ }),
/***/ 9444:
/***/ (function(module) {
module.exports = fromScaling
/**
* Creates a matrix from a vector scaling
* This is equivalent to (but much faster than):
*
* mat4.identity(dest)
* mat4.scale(dest, dest, vec)
*
* @param {mat4} out mat4 receiving operation result
* @param {vec3} v Scaling vector
* @returns {mat4} out
*/
function fromScaling(out, v) {
out[0] = v[0]
out[1] = 0
out[2] = 0
out[3] = 0
out[4] = 0
out[5] = v[1]
out[6] = 0
out[7] = 0
out[8] = 0
out[9] = 0
out[10] = v[2]
out[11] = 0
out[12] = 0
out[13] = 0
out[14] = 0
out[15] = 1
return out
}
/***/ }),
/***/ 8268:
/***/ (function(module) {
module.exports = fromTranslation
/**
* Creates a matrix from a vector translation
* This is equivalent to (but much faster than):
*
* mat4.identity(dest)
* mat4.translate(dest, dest, vec)
*
* @param {mat4} out mat4 receiving operation result
* @param {vec3} v Translation vector
* @returns {mat4} out
*/
function fromTranslation(out, v) {
out[0] = 1
out[1] = 0
out[2] = 0
out[3] = 0
out[4] = 0
out[5] = 1
out[6] = 0
out[7] = 0
out[8] = 0
out[9] = 0
out[10] = 1
out[11] = 0
out[12] = v[0]
out[13] = v[1]
out[14] = v[2]
out[15] = 1
return out
}
/***/ }),
/***/ 1856:
/***/ (function(module) {
module.exports = fromXRotation
/**
* Creates a matrix from the given angle around the X axis
* This is equivalent to (but much faster than):
*
* mat4.identity(dest)
* mat4.rotateX(dest, dest, rad)
*
* @param {mat4} out mat4 receiving operation result
* @param {Number} rad the angle to rotate the matrix by
* @returns {mat4} out
*/
function fromXRotation(out, rad) {
var s = Math.sin(rad),
c = Math.cos(rad)
// Perform axis-specific matrix multiplication
out[0] = 1
out[1] = 0
out[2] = 0
out[3] = 0
out[4] = 0
out[5] = c
out[6] = s
out[7] = 0
out[8] = 0
out[9] = -s
out[10] = c
out[11] = 0
out[12] = 0
out[13] = 0
out[14] = 0
out[15] = 1
return out
}
/***/ }),
/***/ 9216:
/***/ (function(module) {
module.exports = fromYRotation
/**
* Creates a matrix from the given angle around the Y axis
* This is equivalent to (but much faster than):
*
* mat4.identity(dest)
* mat4.rotateY(dest, dest, rad)
*
* @param {mat4} out mat4 receiving operation result
* @param {Number} rad the angle to rotate the matrix by
* @returns {mat4} out
*/
function fromYRotation(out, rad) {
var s = Math.sin(rad),
c = Math.cos(rad)
// Perform axis-specific matrix multiplication
out[0] = c
out[1] = 0
out[2] = -s
out[3] = 0
out[4] = 0
out[5] = 1
out[6] = 0
out[7] = 0
out[8] = s
out[9] = 0
out[10] = c
out[11] = 0
out[12] = 0
out[13] = 0
out[14] = 0
out[15] = 1
return out
}
/***/ }),
/***/ 7736:
/***/ (function(module) {
module.exports = fromZRotation
/**
* Creates a matrix from the given angle around the Z axis
* This is equivalent to (but much faster than):
*
* mat4.identity(dest)
* mat4.rotateZ(dest, dest, rad)
*
* @param {mat4} out mat4 receiving operation result
* @param {Number} rad the angle to rotate the matrix by
* @returns {mat4} out
*/
function fromZRotation(out, rad) {
var s = Math.sin(rad),
c = Math.cos(rad)
// Perform axis-specific matrix multiplication
out[0] = c
out[1] = s
out[2] = 0
out[3] = 0
out[4] = -s
out[5] = c
out[6] = 0
out[7] = 0
out[8] = 0
out[9] = 0
out[10] = 1
out[11] = 0
out[12] = 0
out[13] = 0
out[14] = 0
out[15] = 1
return out
}
/***/ }),
/***/ 8848:
/***/ (function(module) {
module.exports = frustum;
/**
* Generates a frustum matrix with the given bounds
*
* @param {mat4} out mat4 frustum matrix will be written into
* @param {Number} left Left bound of the frustum
* @param {Number} right Right bound of the frustum
* @param {Number} bottom Bottom bound of the frustum
* @param {Number} top Top bound of the frustum
* @param {Number} near Near bound of the frustum
* @param {Number} far Far bound of the frustum
* @returns {mat4} out
*/
function frustum(out, left, right, bottom, top, near, far) {
var rl = 1 / (right - left),
tb = 1 / (top - bottom),
nf = 1 / (near - far);
out[0] = (near * 2) * rl;
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 0;
out[5] = (near * 2) * tb;
out[6] = 0;
out[7] = 0;
out[8] = (right + left) * rl;
out[9] = (top + bottom) * tb;
out[10] = (far + near) * nf;
out[11] = -1;
out[12] = 0;
out[13] = 0;
out[14] = (far * near * 2) * nf;
out[15] = 0;
return out;
};
/***/ }),
/***/ 6635:
/***/ (function(module) {
module.exports = identity;
/**
* Set a mat4 to the identity matrix
*
* @param {mat4} out the receiving matrix
* @returns {mat4} out
*/
function identity(out) {
out[0] = 1;
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 0;
out[5] = 1;
out[6] = 0;
out[7] = 0;
out[8] = 0;
out[9] = 0;
out[10] = 1;
out[11] = 0;
out[12] = 0;
out[13] = 0;
out[14] = 0;
out[15] = 1;
return out;
};
/***/ }),
/***/ 6524:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
module.exports = {
create: __webpack_require__(4212)
, clone: __webpack_require__(6860)
, copy: __webpack_require__(4492)
, identity: __webpack_require__(6635)
, transpose: __webpack_require__(6520)
, invert: __webpack_require__(4308)
, adjoint: __webpack_require__(2408)
, determinant: __webpack_require__(800)
, multiply: __webpack_require__(944)
, translate: __webpack_require__(5176)
, scale: __webpack_require__(8152)
, rotate: __webpack_require__(16)
, rotateX: __webpack_require__(5456)
, rotateY: __webpack_require__(4840)
, rotateZ: __webpack_require__(4192)
, fromRotation: __webpack_require__(1616)
, fromRotationTranslation: __webpack_require__(1944)
, fromScaling: __webpack_require__(9444)
, fromTranslation: __webpack_require__(8268)
, fromXRotation: __webpack_require__(1856)
, fromYRotation: __webpack_require__(9216)
, fromZRotation: __webpack_require__(7736)
, fromQuat: __webpack_require__(1784)
, frustum: __webpack_require__(8848)
, perspective: __webpack_require__(1296)
, perspectiveFromFieldOfView: __webpack_require__(3688)
, ortho: __webpack_require__(7688)
, lookAt: __webpack_require__(6508)
, str: __webpack_require__(9412)
}
/***/ }),
/***/ 4308:
/***/ (function(module) {
module.exports = invert;
/**
* Inverts a mat4
*
* @param {mat4} out the receiving matrix
* @param {mat4} a the source matrix
* @returns {mat4} out
*/
function invert(out, a) {
var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15],
b00 = a00 * a11 - a01 * a10,
b01 = a00 * a12 - a02 * a10,
b02 = a00 * a13 - a03 * a10,
b03 = a01 * a12 - a02 * a11,
b04 = a01 * a13 - a03 * a11,
b05 = a02 * a13 - a03 * a12,
b06 = a20 * a31 - a21 * a30,
b07 = a20 * a32 - a22 * a30,
b08 = a20 * a33 - a23 * a30,
b09 = a21 * a32 - a22 * a31,
b10 = a21 * a33 - a23 * a31,
b11 = a22 * a33 - a23 * a32,
// Calculate the determinant
det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;
if (!det) {
return null;
}
det = 1.0 / det;
out[0] = (a11 * b11 - a12 * b10 + a13 * b09) * det;
out[1] = (a02 * b10 - a01 * b11 - a03 * b09) * det;
out[2] = (a31 * b05 - a32 * b04 + a33 * b03) * det;
out[3] = (a22 * b04 - a21 * b05 - a23 * b03) * det;
out[4] = (a12 * b08 - a10 * b11 - a13 * b07) * det;
out[5] = (a00 * b11 - a02 * b08 + a03 * b07) * det;
out[6] = (a32 * b02 - a30 * b05 - a33 * b01) * det;
out[7] = (a20 * b05 - a22 * b02 + a23 * b01) * det;
out[8] = (a10 * b10 - a11 * b08 + a13 * b06) * det;
out[9] = (a01 * b08 - a00 * b10 - a03 * b06) * det;
out[10] = (a30 * b04 - a31 * b02 + a33 * b00) * det;
out[11] = (a21 * b02 - a20 * b04 - a23 * b00) * det;
out[12] = (a11 * b07 - a10 * b09 - a12 * b06) * det;
out[13] = (a00 * b09 - a01 * b07 + a02 * b06) * det;
out[14] = (a31 * b01 - a30 * b03 - a32 * b00) * det;
out[15] = (a20 * b03 - a21 * b01 + a22 * b00) * det;
return out;
};
/***/ }),
/***/ 6508:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
var identity = __webpack_require__(6635);
module.exports = lookAt;
/**
* Generates a look-at matrix with the given eye position, focal point, and up axis
*
* @param {mat4} out mat4 frustum matrix will be written into
* @param {vec3} eye Position of the viewer
* @param {vec3} center Point the viewer is looking at
* @param {vec3} up vec3 pointing up
* @returns {mat4} out
*/
function lookAt(out, eye, center, up) {
var x0, x1, x2, y0, y1, y2, z0, z1, z2, len,
eyex = eye[0],
eyey = eye[1],
eyez = eye[2],
upx = up[0],
upy = up[1],
upz = up[2],
centerx = center[0],
centery = center[1],
centerz = center[2];
if (Math.abs(eyex - centerx) < 0.000001 &&
Math.abs(eyey - centery) < 0.000001 &&
Math.abs(eyez - centerz) < 0.000001) {
return identity(out);
}
z0 = eyex - centerx;
z1 = eyey - centery;
z2 = eyez - centerz;
len = 1 / Math.sqrt(z0 * z0 + z1 * z1 + z2 * z2);
z0 *= len;
z1 *= len;
z2 *= len;
x0 = upy * z2 - upz * z1;
x1 = upz * z0 - upx * z2;
x2 = upx * z1 - upy * z0;
len = Math.sqrt(x0 * x0 + x1 * x1 + x2 * x2);
if (!len) {
x0 = 0;
x1 = 0;
x2 = 0;
} else {
len = 1 / len;
x0 *= len;
x1 *= len;
x2 *= len;
}
y0 = z1 * x2 - z2 * x1;
y1 = z2 * x0 - z0 * x2;
y2 = z0 * x1 - z1 * x0;
len = Math.sqrt(y0 * y0 + y1 * y1 + y2 * y2);
if (!len) {
y0 = 0;
y1 = 0;
y2 = 0;
} else {
len = 1 / len;
y0 *= len;
y1 *= len;
y2 *= len;
}
out[0] = x0;
out[1] = y0;
out[2] = z0;
out[3] = 0;
out[4] = x1;
out[5] = y1;
out[6] = z1;
out[7] = 0;
out[8] = x2;
out[9] = y2;
out[10] = z2;
out[11] = 0;
out[12] = -(x0 * eyex + x1 * eyey + x2 * eyez);
out[13] = -(y0 * eyex + y1 * eyey + y2 * eyez);
out[14] = -(z0 * eyex + z1 * eyey + z2 * eyez);
out[15] = 1;
return out;
};
/***/ }),
/***/ 944:
/***/ (function(module) {
module.exports = multiply;
/**
* Multiplies two mat4's
*
* @param {mat4} out the receiving matrix
* @param {mat4} a the first operand
* @param {mat4} b the second operand
* @returns {mat4} out
*/
function multiply(out, a, b) {
var a00 = a[0], a01 = a[1], a02 = a[2], a03 = a[3],
a10 = a[4], a11 = a[5], a12 = a[6], a13 = a[7],
a20 = a[8], a21 = a[9], a22 = a[10], a23 = a[11],
a30 = a[12], a31 = a[13], a32 = a[14], a33 = a[15];
// Cache only the current line of the second matrix
var b0 = b[0], b1 = b[1], b2 = b[2], b3 = b[3];
out[0] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
out[1] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
out[2] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
out[3] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
b0 = b[4]; b1 = b[5]; b2 = b[6]; b3 = b[7];
out[4] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
out[5] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
out[6] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
out[7] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
b0 = b[8]; b1 = b[9]; b2 = b[10]; b3 = b[11];
out[8] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
out[9] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
out[10] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
out[11] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
b0 = b[12]; b1 = b[13]; b2 = b[14]; b3 = b[15];
out[12] = b0*a00 + b1*a10 + b2*a20 + b3*a30;
out[13] = b0*a01 + b1*a11 + b2*a21 + b3*a31;
out[14] = b0*a02 + b1*a12 + b2*a22 + b3*a32;
out[15] = b0*a03 + b1*a13 + b2*a23 + b3*a33;
return out;
};
/***/ }),
/***/ 7688:
/***/ (function(module) {
module.exports = ortho;
/**
* Generates a orthogonal projection matrix with the given bounds
*
* @param {mat4} out mat4 frustum matrix will be written into
* @param {number} left Left bound of the frustum
* @param {number} right Right bound of the frustum
* @param {number} bottom Bottom bound of the frustum
* @param {number} top Top bound of the frustum
* @param {number} near Near bound of the frustum
* @param {number} far Far bound of the frustum
* @returns {mat4} out
*/
function ortho(out, left, right, bottom, top, near, far) {
var lr = 1 / (left - right),
bt = 1 / (bottom - top),
nf = 1 / (near - far);
out[0] = -2 * lr;
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 0;
out[5] = -2 * bt;
out[6] = 0;
out[7] = 0;
out[8] = 0;
out[9] = 0;
out[10] = 2 * nf;
out[11] = 0;
out[12] = (left + right) * lr;
out[13] = (top + bottom) * bt;
out[14] = (far + near) * nf;
out[15] = 1;
return out;
};
/***/ }),
/***/ 1296:
/***/ (function(module) {
module.exports = perspective;
/**
* Generates a perspective projection matrix with the given bounds
*
* @param {mat4} out mat4 frustum matrix will be written into
* @param {number} fovy Vertical field of view in radians
* @param {number} aspect Aspect ratio. typically viewport width/height
* @param {number} near Near bound of the frustum
* @param {number} far Far bound of the frustum
* @returns {mat4} out
*/
function perspective(out, fovy, aspect, near, far) {
var f = 1.0 / Math.tan(fovy / 2),
nf = 1 / (near - far);
out[0] = f / aspect;
out[1] = 0;
out[2] = 0;
out[3] = 0;
out[4] = 0;
out[5] = f;
out[6] = 0;
out[7] = 0;
out[8] = 0;
out[9] = 0;
out[10] = (far + near) * nf;
out[11] = -1;
out[12] = 0;
out[13] = 0;
out[14] = (2 * far * near) * nf;
out[15] = 0;
return out;
};
/***/ }),
/***/ 3688:
/***/ (function(module) {
module.exports = perspectiveFromFieldOfView;
/**
* Generates a perspective projection matrix with the given field of view.
* This is primarily useful for generating projection matrices to be used
* with the still experiemental WebVR API.
*
* @param {mat4} out mat4 frustum matrix will be written into
* @param {number} fov Object containing the following values: upDegrees, downDegrees, leftDegrees, rightDegrees
* @param {number} near Near bound of the frustum
* @param {number} far Far bound of the frustum
* @returns {mat4} out
*/
function perspectiveFromFieldOfView(out, fov, near, far) {
var upTan = Math.tan(fov.upDegrees * Math.PI/180.0),
downTan = Math.tan(fov.downDegrees * Math.PI/180.0),
leftTan = Math.tan(fov.leftDegrees * Math.PI/180.0),
rightTan = Math.tan(fov.rightDegrees * Math.PI/180.0),
xScale = 2.0 / (leftTan + rightTan),
yScale = 2.0 / (upTan + downTan);
out[0] = xScale;
out[1] = 0.0;
out[2] = 0.0;
out[3] = 0.0;
out[4] = 0.0;
out[5] = yScale;
out[6] = 0.0;
out[7] = 0.0;
out[8] = -((leftTan - rightTan) * xScale * 0.5);
out[9] = ((upTan - downTan) * yScale * 0.5);
out[10] = far / (near - far);
out[11] = -1.0;
out[12] = 0.0;
out[13] = 0.0;
out[14] = (far * near) / (near - far);
out[15] = 0.0;
return out;
}
/***/ }),
/***/ 16:
/***/ (function(module) {
module.exports = rotate;
/**
* Rotates a mat4 by the given angle
*
* @param {mat4} out the receiving matrix
* @param {mat4} a the matrix to rotate
* @param {Number} rad the angle to rotate the matrix by
* @param {vec3} axis the axis to rotate around
* @returns {mat4} out
*/
function rotate(out, a, rad, axis) {
var x = axis[0], y = axis[1], z = axis[2],
len = Math.sqrt(x * x + y * y + z * z),
s, c, t,
a00, a01, a02, a03,
a10, a11, a12, a13,
a20, a21, a22, a23,
b00, b01, b02,
b10, b11, b12,
b20, b21, b22;
if (Math.abs(len) < 0.000001) { return null; }
len = 1 / len;
x *= len;
y *= len;
z *= len;
s = Math.sin(rad);
c = Math.cos(rad);
t = 1 - c;
a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3];
a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7];
a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11];
// Construct the elements of the rotation matrix
b00 = x * x * t + c; b01 = y * x * t + z * s; b02 = z * x * t - y * s;
b10 = x * y * t - z * s; b11 = y * y * t + c; b12 = z * y * t + x * s;
b20 = x * z * t + y * s; b21 = y * z * t - x * s; b22 = z * z * t + c;
// Perform rotation-specific matrix multiplication
out[0] = a00 * b00 + a10 * b01 + a20 * b02;
out[1] = a01 * b00 + a11 * b01 + a21 * b02;
out[2] = a02 * b00 + a12 * b01 + a22 * b02;
out[3] = a03 * b00 + a13 * b01 + a23 * b02;
out[4] = a00 * b10 + a10 * b11 + a20 * b12;
out[5] = a01 * b10 + a11 * b11 + a21 * b12;
out[6] = a02 * b10 + a12 * b11 + a22 * b12;
out[7] = a03 * b10 + a13 * b11 + a23 * b12;
out[8] = a00 * b20 + a10 * b21 + a20 * b22;
out[9] = a01 * b20 + a11 * b21 + a21 * b22;
out[10] = a02 * b20 + a12 * b21 + a22 * b22;
out[11] = a03 * b20 + a13 * b21 + a23 * b22;
if (a !== out) { // If the source and destination differ, copy the unchanged last row
out[12] = a[12];
out[13] = a[13];
out[14] = a[14];
out[15] = a[15];
}
return out;
};
/***/ }),
/***/ 5456:
/***/ (function(module) {
module.exports = rotateX;
/**
* Rotates a matrix by the given angle around the X axis
*
* @param {mat4} out the receiving matrix
* @param {mat4} a the matrix to rotate
* @param {Number} rad the angle to rotate the matrix by
* @returns {mat4} out
*/
function rotateX(out, a, rad) {
var s = Math.sin(rad),
c = Math.cos(rad),
a10 = a[4],
a11 = a[5],
a12 = a[6],
a13 = a[7],
a20 = a[8],
a21 = a[9],
a22 = a[10],
a23 = a[11];
if (a !== out) { // If the source and destination differ, copy the unchanged rows
out[0] = a[0];
out[1] = a[1];
out[2] = a[2];
out[3] = a[3];
out[12] = a[12];
out[13] = a[13];
out[14] = a[14];
out[15] = a[15];
}
// Perform axis-specific matrix multiplication
out[4] = a10 * c + a20 * s;
out[5] = a11 * c + a21 * s;
out[6] = a12 * c + a22 * s;
out[7] = a13 * c + a23 * s;
out[8] = a20 * c - a10 * s;
out[9] = a21 * c - a11 * s;
out[10] = a22 * c - a12 * s;
out[11] = a23 * c - a13 * s;
return out;
};
/***/ }),
/***/ 4840:
/***/ (function(module) {
module.exports = rotateY;
/**
* Rotates a matrix by the given angle around the Y axis
*
* @param {mat4} out the receiving matrix
* @param {mat4} a the matrix to rotate
* @param {Number} rad the angle to rotate the matrix by
* @returns {mat4} out
*/
function rotateY(out, a, rad) {
var s = Math.sin(rad),
c = Math.cos(rad),
a00 = a[0],
a01 = a[1],
a02 = a[2],
a03 = a[3],
a20 = a[8],
a21 = a[9],
a22 = a[10],
a23 = a[11];
if (a !== out) { // If the source and destination differ, copy the unchanged rows
out[4] = a[4];
out[5] = a[5];
out[6] = a[6];
out[7] = a[7];
out[12] = a[12];
out[13] = a[13];
out[14] = a[14];
out[15] = a[15];
}
// Perform axis-specific matrix multiplication
out[0] = a00 * c - a20 * s;
out[1] = a01 * c - a21 * s;
out[2] = a02 * c - a22 * s;
out[3] = a03 * c - a23 * s;
out[8] = a00 * s + a20 * c;
out[9] = a01 * s + a21 * c;
out[10] = a02 * s + a22 * c;
out[11] = a03 * s + a23 * c;
return out;
};
/***/ }),
/***/ 4192:
/***/ (function(module) {
module.exports = rotateZ;
/**
* Rotates a matrix by the given angle around the Z axis
*
* @param {mat4} out the receiving matrix
* @param {mat4} a the matrix to rotate
* @param {Number} rad the angle to rotate the matrix by
* @returns {mat4} out
*/
function rotateZ(out, a, rad) {
var s = Math.sin(rad),
c = Math.cos(rad),
a00 = a[0],
a01 = a[1],
a02 = a[2],
a03 = a[3],
a10 = a[4],
a11 = a[5],
a12 = a[6],
a13 = a[7];
if (a !== out) { // If the source and destination differ, copy the unchanged last row
out[8] = a[8];
out[9] = a[9];
out[10] = a[10];
out[11] = a[11];
out[12] = a[12];
out[13] = a[13];
out[14] = a[14];
out[15] = a[15];
}
// Perform axis-specific matrix multiplication
out[0] = a00 * c + a10 * s;
out[1] = a01 * c + a11 * s;
out[2] = a02 * c + a12 * s;
out[3] = a03 * c + a13 * s;
out[4] = a10 * c - a00 * s;
out[5] = a11 * c - a01 * s;
out[6] = a12 * c - a02 * s;
out[7] = a13 * c - a03 * s;
return out;
};
/***/ }),
/***/ 8152:
/***/ (function(module) {
module.exports = scale;
/**
* Scales the mat4 by the dimensions in the given vec3
*
* @param {mat4} out the receiving matrix
* @param {mat4} a the matrix to scale
* @param {vec3} v the vec3 to scale the matrix by
* @returns {mat4} out
**/
function scale(out, a, v) {
var x = v[0], y = v[1], z = v[2];
out[0] = a[0] * x;
out[1] = a[1] * x;
out[2] = a[2] * x;
out[3] = a[3] * x;
out[4] = a[4] * y;
out[5] = a[5] * y;
out[6] = a[6] * y;
out[7] = a[7] * y;
out[8] = a[8] * z;
out[9] = a[9] * z;
out[10] = a[10] * z;
out[11] = a[11] * z;
out[12] = a[12];
out[13] = a[13];
out[14] = a[14];
out[15] = a[15];
return out;
};
/***/ }),
/***/ 9412:
/***/ (function(module) {
module.exports = str;
/**
* Returns a string representation of a mat4
*
* @param {mat4} mat matrix to represent as a string
* @returns {String} string representation of the matrix
*/
function str(a) {
return 'mat4(' + a[0] + ', ' + a[1] + ', ' + a[2] + ', ' + a[3] + ', ' +
a[4] + ', ' + a[5] + ', ' + a[6] + ', ' + a[7] + ', ' +
a[8] + ', ' + a[9] + ', ' + a[10] + ', ' + a[11] + ', ' +
a[12] + ', ' + a[13] + ', ' + a[14] + ', ' + a[15] + ')';
};
/***/ }),
/***/ 5176:
/***/ (function(module) {
module.exports = translate;
/**
* Translate a mat4 by the given vector
*
* @param {mat4} out the receiving matrix
* @param {mat4} a the matrix to translate
* @param {vec3} v vector to translate by
* @returns {mat4} out
*/
function translate(out, a, v) {
var x = v[0], y = v[1], z = v[2],
a00, a01, a02, a03,
a10, a11, a12, a13,
a20, a21, a22, a23;
if (a === out) {
out[12] = a[0] * x + a[4] * y + a[8] * z + a[12];
out[13] = a[1] * x + a[5] * y + a[9] * z + a[13];
out[14] = a[2] * x + a[6] * y + a[10] * z + a[14];
out[15] = a[3] * x + a[7] * y + a[11] * z + a[15];
} else {
a00 = a[0]; a01 = a[1]; a02 = a[2]; a03 = a[3];
a10 = a[4]; a11 = a[5]; a12 = a[6]; a13 = a[7];
a20 = a[8]; a21 = a[9]; a22 = a[10]; a23 = a[11];
out[0] = a00; out[1] = a01; out[2] = a02; out[3] = a03;
out[4] = a10; out[5] = a11; out[6] = a12; out[7] = a13;
out[8] = a20; out[9] = a21; out[10] = a22; out[11] = a23;
out[12] = a00 * x + a10 * y + a20 * z + a[12];
out[13] = a01 * x + a11 * y + a21 * z + a[13];
out[14] = a02 * x + a12 * y + a22 * z + a[14];
out[15] = a03 * x + a13 * y + a23 * z + a[15];
}
return out;
};
/***/ }),
/***/ 6520:
/***/ (function(module) {
module.exports = transpose;
/**
* Transpose the values of a mat4
*
* @param {mat4} out the receiving matrix
* @param {mat4} a the source matrix
* @returns {mat4} out
*/
function transpose(out, a) {
// If we are transposing ourselves we can skip a few steps but have to cache some values
if (out === a) {
var a01 = a[1], a02 = a[2], a03 = a[3],
a12 = a[6], a13 = a[7],
a23 = a[11];
out[1] = a[4];
out[2] = a[8];
out[3] = a[12];
out[4] = a01;
out[6] = a[9];
out[7] = a[13];
out[8] = a02;
out[9] = a12;
out[11] = a[14];
out[12] = a03;
out[13] = a13;
out[14] = a23;
} else {
out[0] = a[0];
out[1] = a[4];
out[2] = a[8];
out[3] = a[12];
out[4] = a[1];
out[5] = a[5];
out[6] = a[9];
out[7] = a[13];
out[8] = a[2];
out[9] = a[6];
out[10] = a[10];
out[11] = a[14];
out[12] = a[3];
out[13] = a[7];
out[14] = a[11];
out[15] = a[15];
}
return out;
};
/***/ }),
/***/ 2264:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var isBrowser = __webpack_require__(1820)
var hasHover
if (typeof __webpack_require__.g.matchMedia === 'function') {
hasHover = !__webpack_require__.g.matchMedia('(hover: none)').matches
}
else {
hasHover = isBrowser
}
module.exports = hasHover
/***/ }),
/***/ 9184:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
"use strict";
var isBrowser = __webpack_require__(1820)
function detect() {
var supported = false
try {
var opts = Object.defineProperty({}, 'passive', {
get: function() {
supported = true
}
})
window.addEventListener('test', null, opts)
window.removeEventListener('test', null, opts)
} catch(e) {
supported = false
}
return supported
}
module.exports = isBrowser && detect()
/***/ }),
/***/ 1820:
/***/ (function(module) {
module.exports = true;
/***/ }),
/***/ 4576:
/***/ (function(module) {
"use strict";
/**
* Is this string all whitespace?
* This solution kind of makes my brain hurt, but it's significantly faster
* than !str.trim() or any other solution I could find.
*
* whitespace codes from: http://en.wikipedia.org/wiki/Whitespace_character
* and verified with:
*
* for(var i = 0; i < 65536; i++) {
* var s = String.fromCharCode(i);
* if(+s===0 && !s.trim()) console.log(i, s);
* }
*
* which counts a couple of these as *not* whitespace, but finds nothing else
* that *is* whitespace. Note that charCodeAt stops at 16 bits, but it appears
* that there are no whitespace characters above this, and code points above
* this do not map onto white space characters.
*/
module.exports = function(str){
var l = str.length,
a;
for(var i = 0; i < l; i++) {
a = str.charCodeAt(i);
if((a < 9 || a > 13) && (a !== 32) && (a !== 133) && (a !== 160) &&
(a !== 5760) && (a !== 6158) && (a < 8192 || a > 8205) &&
(a !== 8232) && (a !== 8233) && (a !== 8239) && (a !== 8287) &&
(a !== 8288) && (a !== 12288) && (a !== 65279)) {
return false;
}
}
return true;
}
/***/ }),
/***/ 9128:
/***/ (function(module) {
var rootPosition = { left: 0, top: 0 }
module.exports = mouseEventOffset
function mouseEventOffset (ev, target, out) {
target = target || ev.currentTarget || ev.srcElement
if (!Array.isArray(out)) {
out = [ 0, 0 ]
}
var cx = ev.clientX || 0
var cy = ev.clientY || 0
var rect = getBoundingClientOffset(target)
out[0] = cx - rect.left
out[1] = cy - rect.top
return out
}
function getBoundingClientOffset (element) {
if (element === window ||
element === document ||
element === document.body) {
return rootPosition
} else {
return element.getBoundingClientRect()
}
}
/***/ }),
/***/ 8324:
/***/ (function(module, exports, __webpack_require__) {
var __WEBPACK_AMD_DEFINE_RESULT__;/*! Native Promise Only
v0.8.1 (c) Kyle Simpson
MIT License: http://getify.mit-license.org
*/
(function UMD(name,context,definition){
// special form of UMD for polyfilling across evironments
context[name] = context[name] || definition();
if ( true && module.exports) { module.exports = context[name]; }
else if (true) { !(__WEBPACK_AMD_DEFINE_RESULT__ = (function $AMD$(){ return context[name]; }).call(exports, __webpack_require__, exports, module),
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__)); }
})("Promise",typeof __webpack_require__.g != "undefined" ? __webpack_require__.g : this,function DEF(){
/*jshint validthis:true */
"use strict";
var builtInProp, cycle, scheduling_queue,
ToString = Object.prototype.toString,
timer = (typeof setImmediate != "undefined") ?
function timer(fn) { return setImmediate(fn); } :
setTimeout
;
// dammit, IE8.
try {
Object.defineProperty({},"x",{});
builtInProp = function builtInProp(obj,name,val,config) {
return Object.defineProperty(obj,name,{
value: val,
writable: true,
configurable: config !== false
});
};
}
catch (err) {
builtInProp = function builtInProp(obj,name,val) {
obj[name] = val;
return obj;
};
}
// Note: using a queue instead of array for efficiency
scheduling_queue = (function Queue() {
var first, last, item;
function Item(fn,self) {
this.fn = fn;
this.self = self;
this.next = void 0;
}
return {
add: function add(fn,self) {
item = new Item(fn,self);
if (last) {
last.next = item;
}
else {
first = item;
}
last = item;
item = void 0;
},
drain: function drain() {
var f = first;
first = last = cycle = void 0;
while (f) {
f.fn.call(f.self);
f = f.next;
}
}
};
})();
function schedule(fn,self) {
scheduling_queue.add(fn,self);
if (!cycle) {
cycle = timer(scheduling_queue.drain);
}
}
// promise duck typing
function isThenable(o) {
var _then, o_type = typeof o;
if (o != null &&
(
o_type == "object" || o_type == "function"
)
) {
_then = o.then;
}
return typeof _then == "function" ? _then : false;
}
function notify() {
for (var i=0; i 0) {
schedule(notify,self);
}
}
}
catch (err) {
reject.call(new MakeDefWrapper(self),err);
}
}
function reject(msg) {
var self = this;
// already triggered?
if (self.triggered) { return; }
self.triggered = true;
// unwrap
if (self.def) {
self = self.def;
}
self.msg = msg;
self.state = 2;
if (self.chain.length > 0) {
schedule(notify,self);
}
}
function iteratePromises(Constructor,arr,resolver,rejecter) {
for (var idx=0; idx 2) {
data.push([command].concat(args.splice(0, 2)))
type = 'l'
command = command == 'm' ? 'l' : 'L'
}
while (true) {
if (args.length == length[type]) {
args.unshift(command)
return data.push(args)
}
if (args.length < length[type]) throw new Error('malformed path data')
data.push([command].concat(args.splice(0, length[type])))
}
})
return data
}
var number = /-?[0-9]*\.?[0-9]+(?:e[-+]?\d+)?/ig
function parseValues(args) {
var numbers = args.match(number)
return numbers ? numbers.map(Number) : []
}
/***/ }),
/***/ 1456:
/***/ (function(module) {
// ray-casting algorithm based on
// https://wrf.ecse.rpi.edu/Research/Short_Notes/pnpoly.html
module.exports = function pointInPolygonNested (point, vs, start, end) {
var x = point[0], y = point[1];
var inside = false;
if (start === undefined) start = 0;
if (end === undefined) end = vs.length;
var len = end - start;
for (var i = 0, j = len - 1; i < len; j = i++) {
var xi = vs[i+start][0], yi = vs[i+start][1];
var xj = vs[j+start][0], yj = vs[j+start][1];
var intersect = ((yi > y) !== (yj > y))
&& (x < (xj - xi) * (y - yi) / (yj - yi) + xi);
if (intersect) inside = !inside;
}
return inside;
};
/***/ }),
/***/ 4756:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
/*
* @copyright 2016 Sean Connelly (@voidqk), http://syntheti.cc
* @license MIT
* @preserve Project Home: https://github.com/voidqk/polybooljs
*/
var BuildLog = __webpack_require__(2928);
var Epsilon = __webpack_require__(8648);
var Intersecter = __webpack_require__(9819);
var SegmentChainer = __webpack_require__(1403);
var SegmentSelector = __webpack_require__(2368);
var GeoJSON = __webpack_require__(7792);
var buildLog = false;
var epsilon = Epsilon();
var PolyBool;
PolyBool = {
// getter/setter for buildLog
buildLog: function(bl){
if (bl === true)
buildLog = BuildLog();
else if (bl === false)
buildLog = false;
return buildLog === false ? false : buildLog.list;
},
// getter/setter for epsilon
epsilon: function(v){
return epsilon.epsilon(v);
},
// core API
segments: function(poly){
var i = Intersecter(true, epsilon, buildLog);
poly.regions.forEach(i.addRegion);
return {
segments: i.calculate(poly.inverted),
inverted: poly.inverted
};
},
combine: function(segments1, segments2){
var i3 = Intersecter(false, epsilon, buildLog);
return {
combined: i3.calculate(
segments1.segments, segments1.inverted,
segments2.segments, segments2.inverted
),
inverted1: segments1.inverted,
inverted2: segments2.inverted
};
},
selectUnion: function(combined){
return {
segments: SegmentSelector.union(combined.combined, buildLog),
inverted: combined.inverted1 || combined.inverted2
}
},
selectIntersect: function(combined){
return {
segments: SegmentSelector.intersect(combined.combined, buildLog),
inverted: combined.inverted1 && combined.inverted2
}
},
selectDifference: function(combined){
return {
segments: SegmentSelector.difference(combined.combined, buildLog),
inverted: combined.inverted1 && !combined.inverted2
}
},
selectDifferenceRev: function(combined){
return {
segments: SegmentSelector.differenceRev(combined.combined, buildLog),
inverted: !combined.inverted1 && combined.inverted2
}
},
selectXor: function(combined){
return {
segments: SegmentSelector.xor(combined.combined, buildLog),
inverted: combined.inverted1 !== combined.inverted2
}
},
polygon: function(segments){
return {
regions: SegmentChainer(segments.segments, epsilon, buildLog),
inverted: segments.inverted
};
},
// GeoJSON converters
polygonFromGeoJSON: function(geojson){
return GeoJSON.toPolygon(PolyBool, geojson);
},
polygonToGeoJSON: function(poly){
return GeoJSON.fromPolygon(PolyBool, epsilon, poly);
},
// helper functions for common operations
union: function(poly1, poly2){
return operate(poly1, poly2, PolyBool.selectUnion);
},
intersect: function(poly1, poly2){
return operate(poly1, poly2, PolyBool.selectIntersect);
},
difference: function(poly1, poly2){
return operate(poly1, poly2, PolyBool.selectDifference);
},
differenceRev: function(poly1, poly2){
return operate(poly1, poly2, PolyBool.selectDifferenceRev);
},
xor: function(poly1, poly2){
return operate(poly1, poly2, PolyBool.selectXor);
}
};
function operate(poly1, poly2, selector){
var seg1 = PolyBool.segments(poly1);
var seg2 = PolyBool.segments(poly2);
var comb = PolyBool.combine(seg1, seg2);
var seg3 = selector(comb);
return PolyBool.polygon(seg3);
}
if (typeof window === 'object')
window.PolyBool = PolyBool;
module.exports = PolyBool;
/***/ }),
/***/ 2928:
/***/ (function(module) {
// (c) Copyright 2016, Sean Connelly (@voidqk), http://syntheti.cc
// MIT License
// Project Home: https://github.com/voidqk/polybooljs
//
// used strictly for logging the processing of the algorithm... only useful if you intend on
// looking under the covers (for pretty UI's or debugging)
//
function BuildLog(){
var my;
var nextSegmentId = 0;
var curVert = false;
function push(type, data){
my.list.push({
type: type,
data: data ? JSON.parse(JSON.stringify(data)) : void 0
});
return my;
}
my = {
list: [],
segmentId: function(){
return nextSegmentId++;
},
checkIntersection: function(seg1, seg2){
return push('check', { seg1: seg1, seg2: seg2 });
},
segmentChop: function(seg, end){
push('div_seg', { seg: seg, pt: end });
return push('chop', { seg: seg, pt: end });
},
statusRemove: function(seg){
return push('pop_seg', { seg: seg });
},
segmentUpdate: function(seg){
return push('seg_update', { seg: seg });
},
segmentNew: function(seg, primary){
return push('new_seg', { seg: seg, primary: primary });
},
segmentRemove: function(seg){
return push('rem_seg', { seg: seg });
},
tempStatus: function(seg, above, below){
return push('temp_status', { seg: seg, above: above, below: below });
},
rewind: function(seg){
return push('rewind', { seg: seg });
},
status: function(seg, above, below){
return push('status', { seg: seg, above: above, below: below });
},
vert: function(x){
if (x === curVert)
return my;
curVert = x;
return push('vert', { x: x });
},
log: function(data){
if (typeof data !== 'string')
data = JSON.stringify(data, false, ' ');
return push('log', { txt: data });
},
reset: function(){
return push('reset');
},
selected: function(segs){
return push('selected', { segs: segs });
},
chainStart: function(seg){
return push('chain_start', { seg: seg });
},
chainRemoveHead: function(index, pt){
return push('chain_rem_head', { index: index, pt: pt });
},
chainRemoveTail: function(index, pt){
return push('chain_rem_tail', { index: index, pt: pt });
},
chainNew: function(pt1, pt2){
return push('chain_new', { pt1: pt1, pt2: pt2 });
},
chainMatch: function(index){
return push('chain_match', { index: index });
},
chainClose: function(index){
return push('chain_close', { index: index });
},
chainAddHead: function(index, pt){
return push('chain_add_head', { index: index, pt: pt });
},
chainAddTail: function(index, pt){
return push('chain_add_tail', { index: index, pt: pt, });
},
chainConnect: function(index1, index2){
return push('chain_con', { index1: index1, index2: index2 });
},
chainReverse: function(index){
return push('chain_rev', { index: index });
},
chainJoin: function(index1, index2){
return push('chain_join', { index1: index1, index2: index2 });
},
done: function(){
return push('done');
}
};
return my;
}
module.exports = BuildLog;
/***/ }),
/***/ 8648:
/***/ (function(module) {
// (c) Copyright 2016, Sean Connelly (@voidqk), http://syntheti.cc
// MIT License
// Project Home: https://github.com/voidqk/polybooljs
//
// provides the raw computation functions that takes epsilon into account
//
// zero is defined to be between (-epsilon, epsilon) exclusive
//
function Epsilon(eps){
if (typeof eps !== 'number')
eps = 0.0000000001; // sane default? sure why not
var my = {
epsilon: function(v){
if (typeof v === 'number')
eps = v;
return eps;
},
pointAboveOrOnLine: function(pt, left, right){
var Ax = left[0];
var Ay = left[1];
var Bx = right[0];
var By = right[1];
var Cx = pt[0];
var Cy = pt[1];
return (Bx - Ax) * (Cy - Ay) - (By - Ay) * (Cx - Ax) >= -eps;
},
pointBetween: function(p, left, right){
// p must be collinear with left->right
// returns false if p == left, p == right, or left == right
var d_py_ly = p[1] - left[1];
var d_rx_lx = right[0] - left[0];
var d_px_lx = p[0] - left[0];
var d_ry_ly = right[1] - left[1];
var dot = d_px_lx * d_rx_lx + d_py_ly * d_ry_ly;
// if `dot` is 0, then `p` == `left` or `left` == `right` (reject)
// if `dot` is less than 0, then `p` is to the left of `left` (reject)
if (dot < eps)
return false;
var sqlen = d_rx_lx * d_rx_lx + d_ry_ly * d_ry_ly;
// if `dot` > `sqlen`, then `p` is to the right of `right` (reject)
// therefore, if `dot - sqlen` is greater than 0, then `p` is to the right of `right` (reject)
if (dot - sqlen > -eps)
return false;
return true;
},
pointsSameX: function(p1, p2){
return Math.abs(p1[0] - p2[0]) < eps;
},
pointsSameY: function(p1, p2){
return Math.abs(p1[1] - p2[1]) < eps;
},
pointsSame: function(p1, p2){
return my.pointsSameX(p1, p2) && my.pointsSameY(p1, p2);
},
pointsCompare: function(p1, p2){
// returns -1 if p1 is smaller, 1 if p2 is smaller, 0 if equal
if (my.pointsSameX(p1, p2))
return my.pointsSameY(p1, p2) ? 0 : (p1[1] < p2[1] ? -1 : 1);
return p1[0] < p2[0] ? -1 : 1;
},
pointsCollinear: function(pt1, pt2, pt3){
// does pt1->pt2->pt3 make a straight line?
// essentially this is just checking to see if the slope(pt1->pt2) === slope(pt2->pt3)
// if slopes are equal, then they must be collinear, because they share pt2
var dx1 = pt1[0] - pt2[0];
var dy1 = pt1[1] - pt2[1];
var dx2 = pt2[0] - pt3[0];
var dy2 = pt2[1] - pt3[1];
return Math.abs(dx1 * dy2 - dx2 * dy1) < eps;
},
linesIntersect: function(a0, a1, b0, b1){
// returns false if the lines are coincident (e.g., parallel or on top of each other)
//
// returns an object if the lines intersect:
// {
// pt: [x, y], where the intersection point is at
// alongA: where intersection point is along A,
// alongB: where intersection point is along B
// }
//
// alongA and alongB will each be one of: -2, -1, 0, 1, 2
//
// with the following meaning:
//
// -2 intersection point is before segment's first point
// -1 intersection point is directly on segment's first point
// 0 intersection point is between segment's first and second points (exclusive)
// 1 intersection point is directly on segment's second point
// 2 intersection point is after segment's second point
var adx = a1[0] - a0[0];
var ady = a1[1] - a0[1];
var bdx = b1[0] - b0[0];
var bdy = b1[1] - b0[1];
var axb = adx * bdy - ady * bdx;
if (Math.abs(axb) < eps)
return false; // lines are coincident
var dx = a0[0] - b0[0];
var dy = a0[1] - b0[1];
var A = (bdx * dy - bdy * dx) / axb;
var B = (adx * dy - ady * dx) / axb;
var ret = {
alongA: 0,
alongB: 0,
pt: [
a0[0] + A * adx,
a0[1] + A * ady
]
};
// categorize where intersection point is along A and B
if (A <= -eps)
ret.alongA = -2;
else if (A < eps)
ret.alongA = -1;
else if (A - 1 <= -eps)
ret.alongA = 0;
else if (A - 1 < eps)
ret.alongA = 1;
else
ret.alongA = 2;
if (B <= -eps)
ret.alongB = -2;
else if (B < eps)
ret.alongB = -1;
else if (B - 1 <= -eps)
ret.alongB = 0;
else if (B - 1 < eps)
ret.alongB = 1;
else
ret.alongB = 2;
return ret;
},
pointInsideRegion: function(pt, region){
var x = pt[0];
var y = pt[1];
var last_x = region[region.length - 1][0];
var last_y = region[region.length - 1][1];
var inside = false;
for (var i = 0; i < region.length; i++){
var curr_x = region[i][0];
var curr_y = region[i][1];
// if y is between curr_y and last_y, and
// x is to the right of the boundary created by the line
if ((curr_y - y > eps) != (last_y - y > eps) &&
(last_x - curr_x) * (y - curr_y) / (last_y - curr_y) + curr_x - x > eps)
inside = !inside
last_x = curr_x;
last_y = curr_y;
}
return inside;
}
};
return my;
}
module.exports = Epsilon;
/***/ }),
/***/ 7792:
/***/ (function(module) {
// (c) Copyright 2017, Sean Connelly (@voidqk), http://syntheti.cc
// MIT License
// Project Home: https://github.com/voidqk/polybooljs
//
// convert between PolyBool polygon format and GeoJSON formats (Polygon and MultiPolygon)
//
var GeoJSON = {
// convert a GeoJSON object to a PolyBool polygon
toPolygon: function(PolyBool, geojson){
// converts list of LineString's to segments
function GeoPoly(coords){
// check for empty coords
if (coords.length <= 0)
return PolyBool.segments({ inverted: false, regions: [] });
// convert LineString to segments
function LineString(ls){
// remove tail which should be the same as head
var reg = ls.slice(0, ls.length - 1);
return PolyBool.segments({ inverted: false, regions: [reg] });
}
// the first LineString is considered the outside
var out = LineString(coords[0]);
// the rest of the LineStrings are considered interior holes, so subtract them from the
// current result
for (var i = 1; i < coords.length; i++)
out = PolyBool.selectDifference(PolyBool.combine(out, LineString(coords[i])));
return out;
}
if (geojson.type === 'Polygon'){
// single polygon, so just convert it and we're done
return PolyBool.polygon(GeoPoly(geojson.coordinates));
}
else if (geojson.type === 'MultiPolygon'){
// multiple polygons, so union all the polygons together
var out = PolyBool.segments({ inverted: false, regions: [] });
for (var i = 0; i < geojson.coordinates.length; i++)
out = PolyBool.selectUnion(PolyBool.combine(out, GeoPoly(geojson.coordinates[i])));
return PolyBool.polygon(out);
}
throw new Error('PolyBool: Cannot convert GeoJSON object to PolyBool polygon');
},
// convert a PolyBool polygon to a GeoJSON object
fromPolygon: function(PolyBool, eps, poly){
// make sure out polygon is clean
poly = PolyBool.polygon(PolyBool.segments(poly));
// test if r1 is inside r2
function regionInsideRegion(r1, r2){
// we're guaranteed no lines intersect (because the polygon is clean), but a vertex
// could be on the edge -- so we just average pt[0] and pt[1] to produce a point on the
// edge of the first line, which cannot be on an edge
return eps.pointInsideRegion([
(r1[0][0] + r1[1][0]) * 0.5,
(r1[0][1] + r1[1][1]) * 0.5
], r2);
}
// calculate inside heirarchy
//
// _____________________ _______ roots -> A -> F
// | A | | F | | |
// | _______ _______ | | ___ | +-- B +-- G
// | | B | | C | | | | | | | |
// | | ___ | | ___ | | | | | | | +-- D
// | | | D | | | | E | | | | | G | | |
// | | |___| | | |___| | | | | | | +-- C
// | |_______| |_______| | | |___| | |
// |_____________________| |_______| +-- E
function newNode(region){
return {
region: region,
children: []
};
}
var roots = newNode(null);
function addChild(root, region){
// first check if we're inside any children
for (var i = 0; i < root.children.length; i++){
var child = root.children[i];
if (regionInsideRegion(region, child.region)){
// we are, so insert inside them instead
addChild(child, region);
return;
}
}
// not inside any children, so check to see if any children are inside us
var node = newNode(region);
for (var i = 0; i < root.children.length; i++){
var child = root.children[i];
if (regionInsideRegion(child.region, region)){
// oops... move the child beneath us, and remove them from root
node.children.push(child);
root.children.splice(i, 1);
i--;
}
}
// now we can add ourselves
root.children.push(node);
}
// add all regions to the root
for (var i = 0; i < poly.regions.length; i++){
var region = poly.regions[i];
if (region.length < 3) // regions must have at least 3 points (sanity check)
continue;
addChild(roots, region);
}
// with our heirarchy, we can distinguish between exterior borders, and interior holes
// the root nodes are exterior, children are interior, children's children are exterior,
// children's children's children are interior, etc
// while we're at it, exteriors are counter-clockwise, and interiors are clockwise
function forceWinding(region, clockwise){
// first, see if we're clockwise or counter-clockwise
// https://en.wikipedia.org/wiki/Shoelace_formula
var winding = 0;
var last_x = region[region.length - 1][0];
var last_y = region[region.length - 1][1];
var copy = [];
for (var i = 0; i < region.length; i++){
var curr_x = region[i][0];
var curr_y = region[i][1];
copy.push([curr_x, curr_y]); // create a copy while we're at it
winding += curr_y * last_x - curr_x * last_y;
last_x = curr_x;
last_y = curr_y;
}
// this assumes Cartesian coordinates (Y is positive going up)
var isclockwise = winding < 0;
if (isclockwise !== clockwise)
copy.reverse();
// while we're here, the last point must be the first point...
copy.push([copy[0][0], copy[0][1]]);
return copy;
}
var geopolys = [];
function addExterior(node){
var poly = [forceWinding(node.region, false)];
geopolys.push(poly);
// children of exteriors are interior
for (var i = 0; i < node.children.length; i++)
poly.push(getInterior(node.children[i]));
}
function getInterior(node){
// children of interiors are exterior
for (var i = 0; i < node.children.length; i++)
addExterior(node.children[i]);
// return the clockwise interior
return forceWinding(node.region, true);
}
// root nodes are exterior
for (var i = 0; i < roots.children.length; i++)
addExterior(roots.children[i]);
// lastly, construct the approrpriate GeoJSON object
if (geopolys.length <= 0) // empty GeoJSON Polygon
return { type: 'Polygon', coordinates: [] };
if (geopolys.length == 1) // use a GeoJSON Polygon
return { type: 'Polygon', coordinates: geopolys[0] };
return { // otherwise, use a GeoJSON MultiPolygon
type: 'MultiPolygon',
coordinates: geopolys
};
}
};
module.exports = GeoJSON;
/***/ }),
/***/ 9819:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
// (c) Copyright 2016, Sean Connelly (@voidqk), http://syntheti.cc
// MIT License
// Project Home: https://github.com/voidqk/polybooljs
//
// this is the core work-horse
//
var LinkedList = __webpack_require__(8088);
function Intersecter(selfIntersection, eps, buildLog){
// selfIntersection is true/false depending on the phase of the overall algorithm
//
// segment creation
//
function segmentNew(start, end){
return {
id: buildLog ? buildLog.segmentId() : -1,
start: start,
end: end,
myFill: {
above: null, // is there fill above us?
below: null // is there fill below us?
},
otherFill: null
};
}
function segmentCopy(start, end, seg){
return {
id: buildLog ? buildLog.segmentId() : -1,
start: start,
end: end,
myFill: {
above: seg.myFill.above,
below: seg.myFill.below
},
otherFill: null
};
}
//
// event logic
//
var event_root = LinkedList.create();
function eventCompare(p1_isStart, p1_1, p1_2, p2_isStart, p2_1, p2_2){
// compare the selected points first
var comp = eps.pointsCompare(p1_1, p2_1);
if (comp !== 0)
return comp;
// the selected points are the same
if (eps.pointsSame(p1_2, p2_2)) // if the non-selected points are the same too...
return 0; // then the segments are equal
if (p1_isStart !== p2_isStart) // if one is a start and the other isn't...
return p1_isStart ? 1 : -1; // favor the one that isn't the start
// otherwise, we'll have to calculate which one is below the other manually
return eps.pointAboveOrOnLine(p1_2,
p2_isStart ? p2_1 : p2_2, // order matters
p2_isStart ? p2_2 : p2_1
) ? 1 : -1;
}
function eventAdd(ev, other_pt){
event_root.insertBefore(ev, function(here){
// should ev be inserted before here?
var comp = eventCompare(
ev .isStart, ev .pt, other_pt,
here.isStart, here.pt, here.other.pt
);
return comp < 0;
});
}
function eventAddSegmentStart(seg, primary){
var ev_start = LinkedList.node({
isStart: true,
pt: seg.start,
seg: seg,
primary: primary,
other: null,
status: null
});
eventAdd(ev_start, seg.end);
return ev_start;
}
function eventAddSegmentEnd(ev_start, seg, primary){
var ev_end = LinkedList.node({
isStart: false,
pt: seg.end,
seg: seg,
primary: primary,
other: ev_start,
status: null
});
ev_start.other = ev_end;
eventAdd(ev_end, ev_start.pt);
}
function eventAddSegment(seg, primary){
var ev_start = eventAddSegmentStart(seg, primary);
eventAddSegmentEnd(ev_start, seg, primary);
return ev_start;
}
function eventUpdateEnd(ev, end){
// slides an end backwards
// (start)------------(end) to:
// (start)---(end)
if (buildLog)
buildLog.segmentChop(ev.seg, end);
ev.other.remove();
ev.seg.end = end;
ev.other.pt = end;
eventAdd(ev.other, ev.pt);
}
function eventDivide(ev, pt){
var ns = segmentCopy(pt, ev.seg.end, ev.seg);
eventUpdateEnd(ev, pt);
return eventAddSegment(ns, ev.primary);
}
function calculate(primaryPolyInverted, secondaryPolyInverted){
// if selfIntersection is true then there is no secondary polygon, so that isn't used
//
// status logic
//
var status_root = LinkedList.create();
function statusCompare(ev1, ev2){
var a1 = ev1.seg.start;
var a2 = ev1.seg.end;
var b1 = ev2.seg.start;
var b2 = ev2.seg.end;
if (eps.pointsCollinear(a1, b1, b2)){
if (eps.pointsCollinear(a2, b1, b2))
return 1;//eventCompare(true, a1, a2, true, b1, b2);
return eps.pointAboveOrOnLine(a2, b1, b2) ? 1 : -1;
}
return eps.pointAboveOrOnLine(a1, b1, b2) ? 1 : -1;
}
function statusFindSurrounding(ev){
return status_root.findTransition(function(here){
var comp = statusCompare(ev, here.ev);
return comp > 0;
});
}
function checkIntersection(ev1, ev2){
// returns the segment equal to ev1, or false if nothing equal
var seg1 = ev1.seg;
var seg2 = ev2.seg;
var a1 = seg1.start;
var a2 = seg1.end;
var b1 = seg2.start;
var b2 = seg2.end;
if (buildLog)
buildLog.checkIntersection(seg1, seg2);
var i = eps.linesIntersect(a1, a2, b1, b2);
if (i === false){
// segments are parallel or coincident
// if points aren't collinear, then the segments are parallel, so no intersections
if (!eps.pointsCollinear(a1, a2, b1))
return false;
// otherwise, segments are on top of each other somehow (aka coincident)
if (eps.pointsSame(a1, b2) || eps.pointsSame(a2, b1))
return false; // segments touch at endpoints... no intersection
var a1_equ_b1 = eps.pointsSame(a1, b1);
var a2_equ_b2 = eps.pointsSame(a2, b2);
if (a1_equ_b1 && a2_equ_b2)
return ev2; // segments are exactly equal
var a1_between = !a1_equ_b1 && eps.pointBetween(a1, b1, b2);
var a2_between = !a2_equ_b2 && eps.pointBetween(a2, b1, b2);
// handy for debugging:
// buildLog.log({
// a1_equ_b1: a1_equ_b1,
// a2_equ_b2: a2_equ_b2,
// a1_between: a1_between,
// a2_between: a2_between
// });
if (a1_equ_b1){
if (a2_between){
// (a1)---(a2)
// (b1)----------(b2)
eventDivide(ev2, a2);
}
else{
// (a1)----------(a2)
// (b1)---(b2)
eventDivide(ev1, b2);
}
return ev2;
}
else if (a1_between){
if (!a2_equ_b2){
// make a2 equal to b2
if (a2_between){
// (a1)---(a2)
// (b1)-----------------(b2)
eventDivide(ev2, a2);
}
else{
// (a1)----------(a2)
// (b1)----------(b2)
eventDivide(ev1, b2);
}
}
// (a1)---(a2)
// (b1)----------(b2)
eventDivide(ev2, a1);
}
}
else{
// otherwise, lines intersect at i.pt, which may or may not be between the endpoints
// is A divided between its endpoints? (exclusive)
if (i.alongA === 0){
if (i.alongB === -1) // yes, at exactly b1
eventDivide(ev1, b1);
else if (i.alongB === 0) // yes, somewhere between B's endpoints
eventDivide(ev1, i.pt);
else if (i.alongB === 1) // yes, at exactly b2
eventDivide(ev1, b2);
}
// is B divided between its endpoints? (exclusive)
if (i.alongB === 0){
if (i.alongA === -1) // yes, at exactly a1
eventDivide(ev2, a1);
else if (i.alongA === 0) // yes, somewhere between A's endpoints (exclusive)
eventDivide(ev2, i.pt);
else if (i.alongA === 1) // yes, at exactly a2
eventDivide(ev2, a2);
}
}
return false;
}
//
// main event loop
//
var segments = [];
while (!event_root.isEmpty()){
var ev = event_root.getHead();
if (buildLog)
buildLog.vert(ev.pt[0]);
if (ev.isStart){
if (buildLog)
buildLog.segmentNew(ev.seg, ev.primary);
var surrounding = statusFindSurrounding(ev);
var above = surrounding.before ? surrounding.before.ev : null;
var below = surrounding.after ? surrounding.after.ev : null;
if (buildLog){
buildLog.tempStatus(
ev.seg,
above ? above.seg : false,
below ? below.seg : false
);
}
function checkBothIntersections(){
if (above){
var eve = checkIntersection(ev, above);
if (eve)
return eve;
}
if (below)
return checkIntersection(ev, below);
return false;
}
var eve = checkBothIntersections();
if (eve){
// ev and eve are equal
// we'll keep eve and throw away ev
// merge ev.seg's fill information into eve.seg
if (selfIntersection){
var toggle; // are we a toggling edge?
if (ev.seg.myFill.below === null)
toggle = true;
else
toggle = ev.seg.myFill.above !== ev.seg.myFill.below;
// merge two segments that belong to the same polygon
// think of this as sandwiching two segments together, where `eve.seg` is
// the bottom -- this will cause the above fill flag to toggle
if (toggle)
eve.seg.myFill.above = !eve.seg.myFill.above;
}
else{
// merge two segments that belong to different polygons
// each segment has distinct knowledge, so no special logic is needed
// note that this can only happen once per segment in this phase, because we
// are guaranteed that all self-intersections are gone
eve.seg.otherFill = ev.seg.myFill;
}
if (buildLog)
buildLog.segmentUpdate(eve.seg);
ev.other.remove();
ev.remove();
}
if (event_root.getHead() !== ev){
// something was inserted before us in the event queue, so loop back around and
// process it before continuing
if (buildLog)
buildLog.rewind(ev.seg);
continue;
}
//
// calculate fill flags
//
if (selfIntersection){
var toggle; // are we a toggling edge?
if (ev.seg.myFill.below === null) // if we are a new segment...
toggle = true; // then we toggle
else // we are a segment that has previous knowledge from a division
toggle = ev.seg.myFill.above !== ev.seg.myFill.below; // calculate toggle
// next, calculate whether we are filled below us
if (!below){ // if nothing is below us...
// we are filled below us if the polygon is inverted
ev.seg.myFill.below = primaryPolyInverted;
}
else{
// otherwise, we know the answer -- it's the same if whatever is below
// us is filled above it
ev.seg.myFill.below = below.seg.myFill.above;
}
// since now we know if we're filled below us, we can calculate whether
// we're filled above us by applying toggle to whatever is below us
if (toggle)
ev.seg.myFill.above = !ev.seg.myFill.below;
else
ev.seg.myFill.above = ev.seg.myFill.below;
}
else{
// now we fill in any missing transition information, since we are all-knowing
// at this point
if (ev.seg.otherFill === null){
// if we don't have other information, then we need to figure out if we're
// inside the other polygon
var inside;
if (!below){
// if nothing is below us, then we're inside if the other polygon is
// inverted
inside =
ev.primary ? secondaryPolyInverted : primaryPolyInverted;
}
else{ // otherwise, something is below us
// so copy the below segment's other polygon's above
if (ev.primary === below.primary)
inside = below.seg.otherFill.above;
else
inside = below.seg.myFill.above;
}
ev.seg.otherFill = {
above: inside,
below: inside
};
}
}
if (buildLog){
buildLog.status(
ev.seg,
above ? above.seg : false,
below ? below.seg : false
);
}
// insert the status and remember it for later removal
ev.other.status = surrounding.insert(LinkedList.node({ ev: ev }));
}
else{
var st = ev.status;
if (st === null){
throw new Error('PolyBool: Zero-length segment detected; your epsilon is ' +
'probably too small or too large');
}
// removing the status will create two new adjacent edges, so we'll need to check
// for those
if (status_root.exists(st.prev) && status_root.exists(st.next))
checkIntersection(st.prev.ev, st.next.ev);
if (buildLog)
buildLog.statusRemove(st.ev.seg);
// remove the status
st.remove();
// if we've reached this point, we've calculated everything there is to know, so
// save the segment for reporting
if (!ev.primary){
// make sure `seg.myFill` actually points to the primary polygon though
var s = ev.seg.myFill;
ev.seg.myFill = ev.seg.otherFill;
ev.seg.otherFill = s;
}
segments.push(ev.seg);
}
// remove the event and continue
event_root.getHead().remove();
}
if (buildLog)
buildLog.done();
return segments;
}
// return the appropriate API depending on what we're doing
if (!selfIntersection){
// performing combination of polygons, so only deal with already-processed segments
return {
calculate: function(segments1, inverted1, segments2, inverted2){
// segmentsX come from the self-intersection API, or this API
// invertedX is whether we treat that list of segments as an inverted polygon or not
// returns segments that can be used for further operations
segments1.forEach(function(seg){
eventAddSegment(segmentCopy(seg.start, seg.end, seg), true);
});
segments2.forEach(function(seg){
eventAddSegment(segmentCopy(seg.start, seg.end, seg), false);
});
return calculate(inverted1, inverted2);
}
};
}
// otherwise, performing self-intersection, so deal with regions
return {
addRegion: function(region){
// regions are a list of points:
// [ [0, 0], [100, 0], [50, 100] ]
// you can add multiple regions before running calculate
var pt1;
var pt2 = region[region.length - 1];
for (var i = 0; i < region.length; i++){
pt1 = pt2;
pt2 = region[i];
var forward = eps.pointsCompare(pt1, pt2);
if (forward === 0) // points are equal, so we have a zero-length segment
continue; // just skip it
eventAddSegment(
segmentNew(
forward < 0 ? pt1 : pt2,
forward < 0 ? pt2 : pt1
),
true
);
}
},
calculate: function(inverted){
// is the polygon inverted?
// returns segments
return calculate(inverted, false);
}
};
}
module.exports = Intersecter;
/***/ }),
/***/ 8088:
/***/ (function(module) {
// (c) Copyright 2016, Sean Connelly (@voidqk), http://syntheti.cc
// MIT License
// Project Home: https://github.com/voidqk/polybooljs
//
// simple linked list implementation that allows you to traverse down nodes and save positions
//
var LinkedList = {
create: function(){
var my = {
root: { root: true, next: null },
exists: function(node){
if (node === null || node === my.root)
return false;
return true;
},
isEmpty: function(){
return my.root.next === null;
},
getHead: function(){
return my.root.next;
},
insertBefore: function(node, check){
var last = my.root;
var here = my.root.next;
while (here !== null){
if (check(here)){
node.prev = here.prev;
node.next = here;
here.prev.next = node;
here.prev = node;
return;
}
last = here;
here = here.next;
}
last.next = node;
node.prev = last;
node.next = null;
},
findTransition: function(check){
var prev = my.root;
var here = my.root.next;
while (here !== null){
if (check(here))
break;
prev = here;
here = here.next;
}
return {
before: prev === my.root ? null : prev,
after: here,
insert: function(node){
node.prev = prev;
node.next = here;
prev.next = node;
if (here !== null)
here.prev = node;
return node;
}
};
}
};
return my;
},
node: function(data){
data.prev = null;
data.next = null;
data.remove = function(){
data.prev.next = data.next;
if (data.next)
data.next.prev = data.prev;
data.prev = null;
data.next = null;
};
return data;
}
};
module.exports = LinkedList;
/***/ }),
/***/ 1403:
/***/ (function(module) {
// (c) Copyright 2016, Sean Connelly (@voidqk), http://syntheti.cc
// MIT License
// Project Home: https://github.com/voidqk/polybooljs
//
// converts a list of segments into a list of regions, while also removing unnecessary verticies
//
function SegmentChainer(segments, eps, buildLog){
var chains = [];
var regions = [];
segments.forEach(function(seg){
var pt1 = seg.start;
var pt2 = seg.end;
if (eps.pointsSame(pt1, pt2)){
console.warn('PolyBool: Warning: Zero-length segment detected; your epsilon is ' +
'probably too small or too large');
return;
}
if (buildLog)
buildLog.chainStart(seg);
// search for two chains that this segment matches
var first_match = {
index: 0,
matches_head: false,
matches_pt1: false
};
var second_match = {
index: 0,
matches_head: false,
matches_pt1: false
};
var next_match = first_match;
function setMatch(index, matches_head, matches_pt1){
// return true if we've matched twice
next_match.index = index;
next_match.matches_head = matches_head;
next_match.matches_pt1 = matches_pt1;
if (next_match === first_match){
next_match = second_match;
return false;
}
next_match = null;
return true; // we've matched twice, we're done here
}
for (var i = 0; i < chains.length; i++){
var chain = chains[i];
var head = chain[0];
var head2 = chain[1];
var tail = chain[chain.length - 1];
var tail2 = chain[chain.length - 2];
if (eps.pointsSame(head, pt1)){
if (setMatch(i, true, true))
break;
}
else if (eps.pointsSame(head, pt2)){
if (setMatch(i, true, false))
break;
}
else if (eps.pointsSame(tail, pt1)){
if (setMatch(i, false, true))
break;
}
else if (eps.pointsSame(tail, pt2)){
if (setMatch(i, false, false))
break;
}
}
if (next_match === first_match){
// we didn't match anything, so create a new chain
chains.push([ pt1, pt2 ]);
if (buildLog)
buildLog.chainNew(pt1, pt2);
return;
}
if (next_match === second_match){
// we matched a single chain
if (buildLog)
buildLog.chainMatch(first_match.index);
// add the other point to the apporpriate end, and check to see if we've closed the
// chain into a loop
var index = first_match.index;
var pt = first_match.matches_pt1 ? pt2 : pt1; // if we matched pt1, then we add pt2, etc
var addToHead = first_match.matches_head; // if we matched at head, then add to the head
var chain = chains[index];
var grow = addToHead ? chain[0] : chain[chain.length - 1];
var grow2 = addToHead ? chain[1] : chain[chain.length - 2];
var oppo = addToHead ? chain[chain.length - 1] : chain[0];
var oppo2 = addToHead ? chain[chain.length - 2] : chain[1];
if (eps.pointsCollinear(grow2, grow, pt)){
// grow isn't needed because it's directly between grow2 and pt:
// grow2 ---grow---> pt
if (addToHead){
if (buildLog)
buildLog.chainRemoveHead(first_match.index, pt);
chain.shift();
}
else{
if (buildLog)
buildLog.chainRemoveTail(first_match.index, pt);
chain.pop();
}
grow = grow2; // old grow is gone... new grow is what grow2 was
}
if (eps.pointsSame(oppo, pt)){
// we're closing the loop, so remove chain from chains
chains.splice(index, 1);
if (eps.pointsCollinear(oppo2, oppo, grow)){
// oppo isn't needed because it's directly between oppo2 and grow:
// oppo2 ---oppo--->grow
if (addToHead){
if (buildLog)
buildLog.chainRemoveTail(first_match.index, grow);
chain.pop();
}
else{
if (buildLog)
buildLog.chainRemoveHead(first_match.index, grow);
chain.shift();
}
}
if (buildLog)
buildLog.chainClose(first_match.index);
// we have a closed chain!
regions.push(chain);
return;
}
// not closing a loop, so just add it to the apporpriate side
if (addToHead){
if (buildLog)
buildLog.chainAddHead(first_match.index, pt);
chain.unshift(pt);
}
else{
if (buildLog)
buildLog.chainAddTail(first_match.index, pt);
chain.push(pt);
}
return;
}
// otherwise, we matched two chains, so we need to combine those chains together
function reverseChain(index){
if (buildLog)
buildLog.chainReverse(index);
chains[index].reverse(); // gee, that's easy
}
function appendChain(index1, index2){
// index1 gets index2 appended to it, and index2 is removed
var chain1 = chains[index1];
var chain2 = chains[index2];
var tail = chain1[chain1.length - 1];
var tail2 = chain1[chain1.length - 2];
var head = chain2[0];
var head2 = chain2[1];
if (eps.pointsCollinear(tail2, tail, head)){
// tail isn't needed because it's directly between tail2 and head
// tail2 ---tail---> head
if (buildLog)
buildLog.chainRemoveTail(index1, tail);
chain1.pop();
tail = tail2; // old tail is gone... new tail is what tail2 was
}
if (eps.pointsCollinear(tail, head, head2)){
// head isn't needed because it's directly between tail and head2
// tail ---head---> head2
if (buildLog)
buildLog.chainRemoveHead(index2, head);
chain2.shift();
}
if (buildLog)
buildLog.chainJoin(index1, index2);
chains[index1] = chain1.concat(chain2);
chains.splice(index2, 1);
}
var F = first_match.index;
var S = second_match.index;
if (buildLog)
buildLog.chainConnect(F, S);
var reverseF = chains[F].length < chains[S].length; // reverse the shorter chain, if needed
if (first_match.matches_head){
if (second_match.matches_head){
if (reverseF){
// <<<< F <<<< --- >>>> S >>>>
reverseChain(F);
// >>>> F >>>> --- >>>> S >>>>
appendChain(F, S);
}
else{
// <<<< F <<<< --- >>>> S >>>>
reverseChain(S);
// <<<< F <<<< --- <<<< S <<<< logically same as:
// >>>> S >>>> --- >>>> F >>>>
appendChain(S, F);
}
}
else{
// <<<< F <<<< --- <<<< S <<<< logically same as:
// >>>> S >>>> --- >>>> F >>>>
appendChain(S, F);
}
}
else{
if (second_match.matches_head){
// >>>> F >>>> --- >>>> S >>>>
appendChain(F, S);
}
else{
if (reverseF){
// >>>> F >>>> --- <<<< S <<<<
reverseChain(F);
// <<<< F <<<< --- <<<< S <<<< logically same as:
// >>>> S >>>> --- >>>> F >>>>
appendChain(S, F);
}
else{
// >>>> F >>>> --- <<<< S <<<<
reverseChain(S);
// >>>> F >>>> --- >>>> S >>>>
appendChain(F, S);
}
}
}
});
return regions;
}
module.exports = SegmentChainer;
/***/ }),
/***/ 2368:
/***/ (function(module) {
// (c) Copyright 2016, Sean Connelly (@voidqk), http://syntheti.cc
// MIT License
// Project Home: https://github.com/voidqk/polybooljs
//
// filter a list of segments based on boolean operations
//
function select(segments, selection, buildLog){
var result = [];
segments.forEach(function(seg){
var index =
(seg.myFill.above ? 8 : 0) +
(seg.myFill.below ? 4 : 0) +
((seg.otherFill && seg.otherFill.above) ? 2 : 0) +
((seg.otherFill && seg.otherFill.below) ? 1 : 0);
if (selection[index] !== 0){
// copy the segment to the results, while also calculating the fill status
result.push({
id: buildLog ? buildLog.segmentId() : -1,
start: seg.start,
end: seg.end,
myFill: {
above: selection[index] === 1, // 1 if filled above
below: selection[index] === 2 // 2 if filled below
},
otherFill: null
});
}
});
if (buildLog)
buildLog.selected(result);
return result;
}
var SegmentSelector = {
union: function(segments, buildLog){ // primary | secondary
// above1 below1 above2 below2 Keep? Value
// 0 0 0 0 => no 0
// 0 0 0 1 => yes filled below 2
// 0 0 1 0 => yes filled above 1
// 0 0 1 1 => no 0
// 0 1 0 0 => yes filled below 2
// 0 1 0 1 => yes filled below 2
// 0 1 1 0 => no 0
// 0 1 1 1 => no 0
// 1 0 0 0 => yes filled above 1
// 1 0 0 1 => no 0
// 1 0 1 0 => yes filled above 1
// 1 0 1 1 => no 0
// 1 1 0 0 => no 0
// 1 1 0 1 => no 0
// 1 1 1 0 => no 0
// 1 1 1 1 => no 0
return select(segments, [
0, 2, 1, 0,
2, 2, 0, 0,
1, 0, 1, 0,
0, 0, 0, 0
], buildLog);
},
intersect: function(segments, buildLog){ // primary & secondary
// above1 below1 above2 below2 Keep? Value
// 0 0 0 0 => no 0
// 0 0 0 1 => no 0
// 0 0 1 0 => no 0
// 0 0 1 1 => no 0
// 0 1 0 0 => no 0
// 0 1 0 1 => yes filled below 2
// 0 1 1 0 => no 0
// 0 1 1 1 => yes filled below 2
// 1 0 0 0 => no 0
// 1 0 0 1 => no 0
// 1 0 1 0 => yes filled above 1
// 1 0 1 1 => yes filled above 1
// 1 1 0 0 => no 0
// 1 1 0 1 => yes filled below 2
// 1 1 1 0 => yes filled above 1
// 1 1 1 1 => no 0
return select(segments, [
0, 0, 0, 0,
0, 2, 0, 2,
0, 0, 1, 1,
0, 2, 1, 0
], buildLog);
},
difference: function(segments, buildLog){ // primary - secondary
// above1 below1 above2 below2 Keep? Value
// 0 0 0 0 => no 0
// 0 0 0 1 => no 0
// 0 0 1 0 => no 0
// 0 0 1 1 => no 0
// 0 1 0 0 => yes filled below 2
// 0 1 0 1 => no 0
// 0 1 1 0 => yes filled below 2
// 0 1 1 1 => no 0
// 1 0 0 0 => yes filled above 1
// 1 0 0 1 => yes filled above 1
// 1 0 1 0 => no 0
// 1 0 1 1 => no 0
// 1 1 0 0 => no 0
// 1 1 0 1 => yes filled above 1
// 1 1 1 0 => yes filled below 2
// 1 1 1 1 => no 0
return select(segments, [
0, 0, 0, 0,
2, 0, 2, 0,
1, 1, 0, 0,
0, 1, 2, 0
], buildLog);
},
differenceRev: function(segments, buildLog){ // secondary - primary
// above1 below1 above2 below2 Keep? Value
// 0 0 0 0 => no 0
// 0 0 0 1 => yes filled below 2
// 0 0 1 0 => yes filled above 1
// 0 0 1 1 => no 0
// 0 1 0 0 => no 0
// 0 1 0 1 => no 0
// 0 1 1 0 => yes filled above 1
// 0 1 1 1 => yes filled above 1
// 1 0 0 0 => no 0
// 1 0 0 1 => yes filled below 2
// 1 0 1 0 => no 0
// 1 0 1 1 => yes filled below 2
// 1 1 0 0 => no 0
// 1 1 0 1 => no 0
// 1 1 1 0 => no 0
// 1 1 1 1 => no 0
return select(segments, [
0, 2, 1, 0,
0, 0, 1, 1,
0, 2, 0, 2,
0, 0, 0, 0
], buildLog);
},
xor: function(segments, buildLog){ // primary ^ secondary
// above1 below1 above2 below2 Keep? Value
// 0 0 0 0 => no 0
// 0 0 0 1 => yes filled below 2
// 0 0 1 0 => yes filled above 1
// 0 0 1 1 => no 0
// 0 1 0 0 => yes filled below 2
// 0 1 0 1 => no 0
// 0 1 1 0 => no 0
// 0 1 1 1 => yes filled above 1
// 1 0 0 0 => yes filled above 1
// 1 0 0 1 => no 0
// 1 0 1 0 => no 0
// 1 0 1 1 => yes filled below 2
// 1 1 0 0 => no 0
// 1 1 0 1 => yes filled above 1
// 1 1 1 0 => yes filled below 2
// 1 1 1 1 => no 0
return select(segments, [
0, 2, 1, 0,
2, 0, 0, 1,
1, 0, 0, 2,
0, 1, 2, 0
], buildLog);
}
};
module.exports = SegmentSelector;
/***/ }),
/***/ 9760:
/***/ (function(module, exports, __webpack_require__) {
var __WEBPACK_AMD_DEFINE_RESULT__;// TinyColor v1.4.2
// https://github.com/bgrins/TinyColor
// Brian Grinstead, MIT License
(function(Math) {
var trimLeft = /^\s+/,
trimRight = /\s+$/,
tinyCounter = 0,
mathRound = Math.round,
mathMin = Math.min,
mathMax = Math.max,
mathRandom = Math.random;
function tinycolor (color, opts) {
color = (color) ? color : '';
opts = opts || { };
// If input is already a tinycolor, return itself
if (color instanceof tinycolor) {
return color;
}
// If we are called as a function, call using new instead
if (!(this instanceof tinycolor)) {
return new tinycolor(color, opts);
}
var rgb = inputToRGB(color);
this._originalInput = color,
this._r = rgb.r,
this._g = rgb.g,
this._b = rgb.b,
this._a = rgb.a,
this._roundA = mathRound(100*this._a) / 100,
this._format = opts.format || rgb.format;
this._gradientType = opts.gradientType;
// Don't let the range of [0,255] come back in [0,1].
// Potentially lose a little bit of precision here, but will fix issues where
// .5 gets interpreted as half of the total, instead of half of 1
// If it was supposed to be 128, this was already taken care of by `inputToRgb`
if (this._r < 1) { this._r = mathRound(this._r); }
if (this._g < 1) { this._g = mathRound(this._g); }
if (this._b < 1) { this._b = mathRound(this._b); }
this._ok = rgb.ok;
this._tc_id = tinyCounter++;
}
tinycolor.prototype = {
isDark: function() {
return this.getBrightness() < 128;
},
isLight: function() {
return !this.isDark();
},
isValid: function() {
return this._ok;
},
getOriginalInput: function() {
return this._originalInput;
},
getFormat: function() {
return this._format;
},
getAlpha: function() {
return this._a;
},
getBrightness: function() {
//http://www.w3.org/TR/AERT#color-contrast
var rgb = this.toRgb();
return (rgb.r * 299 + rgb.g * 587 + rgb.b * 114) / 1000;
},
getLuminance: function() {
//http://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
var rgb = this.toRgb();
var RsRGB, GsRGB, BsRGB, R, G, B;
RsRGB = rgb.r/255;
GsRGB = rgb.g/255;
BsRGB = rgb.b/255;
if (RsRGB <= 0.03928) {R = RsRGB / 12.92;} else {R = Math.pow(((RsRGB + 0.055) / 1.055), 2.4);}
if (GsRGB <= 0.03928) {G = GsRGB / 12.92;} else {G = Math.pow(((GsRGB + 0.055) / 1.055), 2.4);}
if (BsRGB <= 0.03928) {B = BsRGB / 12.92;} else {B = Math.pow(((BsRGB + 0.055) / 1.055), 2.4);}
return (0.2126 * R) + (0.7152 * G) + (0.0722 * B);
},
setAlpha: function(value) {
this._a = boundAlpha(value);
this._roundA = mathRound(100*this._a) / 100;
return this;
},
toHsv: function() {
var hsv = rgbToHsv(this._r, this._g, this._b);
return { h: hsv.h * 360, s: hsv.s, v: hsv.v, a: this._a };
},
toHsvString: function() {
var hsv = rgbToHsv(this._r, this._g, this._b);
var h = mathRound(hsv.h * 360), s = mathRound(hsv.s * 100), v = mathRound(hsv.v * 100);
return (this._a == 1) ?
"hsv(" + h + ", " + s + "%, " + v + "%)" :
"hsva(" + h + ", " + s + "%, " + v + "%, "+ this._roundA + ")";
},
toHsl: function() {
var hsl = rgbToHsl(this._r, this._g, this._b);
return { h: hsl.h * 360, s: hsl.s, l: hsl.l, a: this._a };
},
toHslString: function() {
var hsl = rgbToHsl(this._r, this._g, this._b);
var h = mathRound(hsl.h * 360), s = mathRound(hsl.s * 100), l = mathRound(hsl.l * 100);
return (this._a == 1) ?
"hsl(" + h + ", " + s + "%, " + l + "%)" :
"hsla(" + h + ", " + s + "%, " + l + "%, "+ this._roundA + ")";
},
toHex: function(allow3Char) {
return rgbToHex(this._r, this._g, this._b, allow3Char);
},
toHexString: function(allow3Char) {
return '#' + this.toHex(allow3Char);
},
toHex8: function(allow4Char) {
return rgbaToHex(this._r, this._g, this._b, this._a, allow4Char);
},
toHex8String: function(allow4Char) {
return '#' + this.toHex8(allow4Char);
},
toRgb: function() {
return { r: mathRound(this._r), g: mathRound(this._g), b: mathRound(this._b), a: this._a };
},
toRgbString: function() {
return (this._a == 1) ?
"rgb(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ")" :
"rgba(" + mathRound(this._r) + ", " + mathRound(this._g) + ", " + mathRound(this._b) + ", " + this._roundA + ")";
},
toPercentageRgb: function() {
return { r: mathRound(bound01(this._r, 255) * 100) + "%", g: mathRound(bound01(this._g, 255) * 100) + "%", b: mathRound(bound01(this._b, 255) * 100) + "%", a: this._a };
},
toPercentageRgbString: function() {
return (this._a == 1) ?
"rgb(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%)" :
"rgba(" + mathRound(bound01(this._r, 255) * 100) + "%, " + mathRound(bound01(this._g, 255) * 100) + "%, " + mathRound(bound01(this._b, 255) * 100) + "%, " + this._roundA + ")";
},
toName: function() {
if (this._a === 0) {
return "transparent";
}
if (this._a < 1) {
return false;
}
return hexNames[rgbToHex(this._r, this._g, this._b, true)] || false;
},
toFilter: function(secondColor) {
var hex8String = '#' + rgbaToArgbHex(this._r, this._g, this._b, this._a);
var secondHex8String = hex8String;
var gradientType = this._gradientType ? "GradientType = 1, " : "";
if (secondColor) {
var s = tinycolor(secondColor);
secondHex8String = '#' + rgbaToArgbHex(s._r, s._g, s._b, s._a);
}
return "progid:DXImageTransform.Microsoft.gradient("+gradientType+"startColorstr="+hex8String+",endColorstr="+secondHex8String+")";
},
toString: function(format) {
var formatSet = !!format;
format = format || this._format;
var formattedString = false;
var hasAlpha = this._a < 1 && this._a >= 0;
var needsAlphaFormat = !formatSet && hasAlpha && (format === "hex" || format === "hex6" || format === "hex3" || format === "hex4" || format === "hex8" || format === "name");
if (needsAlphaFormat) {
// Special case for "transparent", all other non-alpha formats
// will return rgba when there is transparency.
if (format === "name" && this._a === 0) {
return this.toName();
}
return this.toRgbString();
}
if (format === "rgb") {
formattedString = this.toRgbString();
}
if (format === "prgb") {
formattedString = this.toPercentageRgbString();
}
if (format === "hex" || format === "hex6") {
formattedString = this.toHexString();
}
if (format === "hex3") {
formattedString = this.toHexString(true);
}
if (format === "hex4") {
formattedString = this.toHex8String(true);
}
if (format === "hex8") {
formattedString = this.toHex8String();
}
if (format === "name") {
formattedString = this.toName();
}
if (format === "hsl") {
formattedString = this.toHslString();
}
if (format === "hsv") {
formattedString = this.toHsvString();
}
return formattedString || this.toHexString();
},
clone: function() {
return tinycolor(this.toString());
},
_applyModification: function(fn, args) {
var color = fn.apply(null, [this].concat([].slice.call(args)));
this._r = color._r;
this._g = color._g;
this._b = color._b;
this.setAlpha(color._a);
return this;
},
lighten: function() {
return this._applyModification(lighten, arguments);
},
brighten: function() {
return this._applyModification(brighten, arguments);
},
darken: function() {
return this._applyModification(darken, arguments);
},
desaturate: function() {
return this._applyModification(desaturate, arguments);
},
saturate: function() {
return this._applyModification(saturate, arguments);
},
greyscale: function() {
return this._applyModification(greyscale, arguments);
},
spin: function() {
return this._applyModification(spin, arguments);
},
_applyCombination: function(fn, args) {
return fn.apply(null, [this].concat([].slice.call(args)));
},
analogous: function() {
return this._applyCombination(analogous, arguments);
},
complement: function() {
return this._applyCombination(complement, arguments);
},
monochromatic: function() {
return this._applyCombination(monochromatic, arguments);
},
splitcomplement: function() {
return this._applyCombination(splitcomplement, arguments);
},
triad: function() {
return this._applyCombination(triad, arguments);
},
tetrad: function() {
return this._applyCombination(tetrad, arguments);
}
};
// If input is an object, force 1 into "1.0" to handle ratios properly
// String input requires "1.0" as input, so 1 will be treated as 1
tinycolor.fromRatio = function(color, opts) {
if (typeof color == "object") {
var newColor = {};
for (var i in color) {
if (color.hasOwnProperty(i)) {
if (i === "a") {
newColor[i] = color[i];
}
else {
newColor[i] = convertToPercentage(color[i]);
}
}
}
color = newColor;
}
return tinycolor(color, opts);
};
// Given a string or object, convert that input to RGB
// Possible string inputs:
//
// "red"
// "#f00" or "f00"
// "#ff0000" or "ff0000"
// "#ff000000" or "ff000000"
// "rgb 255 0 0" or "rgb (255, 0, 0)"
// "rgb 1.0 0 0" or "rgb (1, 0, 0)"
// "rgba (255, 0, 0, 1)" or "rgba 255, 0, 0, 1"
// "rgba (1.0, 0, 0, 1)" or "rgba 1.0, 0, 0, 1"
// "hsl(0, 100%, 50%)" or "hsl 0 100% 50%"
// "hsla(0, 100%, 50%, 1)" or "hsla 0 100% 50%, 1"
// "hsv(0, 100%, 100%)" or "hsv 0 100% 100%"
//
function inputToRGB(color) {
var rgb = { r: 0, g: 0, b: 0 };
var a = 1;
var s = null;
var v = null;
var l = null;
var ok = false;
var format = false;
if (typeof color == "string") {
color = stringInputToObject(color);
}
if (typeof color == "object") {
if (isValidCSSUnit(color.r) && isValidCSSUnit(color.g) && isValidCSSUnit(color.b)) {
rgb = rgbToRgb(color.r, color.g, color.b);
ok = true;
format = String(color.r).substr(-1) === "%" ? "prgb" : "rgb";
}
else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.v)) {
s = convertToPercentage(color.s);
v = convertToPercentage(color.v);
rgb = hsvToRgb(color.h, s, v);
ok = true;
format = "hsv";
}
else if (isValidCSSUnit(color.h) && isValidCSSUnit(color.s) && isValidCSSUnit(color.l)) {
s = convertToPercentage(color.s);
l = convertToPercentage(color.l);
rgb = hslToRgb(color.h, s, l);
ok = true;
format = "hsl";
}
if (color.hasOwnProperty("a")) {
a = color.a;
}
}
a = boundAlpha(a);
return {
ok: ok,
format: color.format || format,
r: mathMin(255, mathMax(rgb.r, 0)),
g: mathMin(255, mathMax(rgb.g, 0)),
b: mathMin(255, mathMax(rgb.b, 0)),
a: a
};
}
// Conversion Functions
// --------------------
// `rgbToHsl`, `rgbToHsv`, `hslToRgb`, `hsvToRgb` modified from:
//
// `rgbToRgb`
// Handle bounds / percentage checking to conform to CSS color spec
//
// *Assumes:* r, g, b in [0, 255] or [0, 1]
// *Returns:* { r, g, b } in [0, 255]
function rgbToRgb(r, g, b){
return {
r: bound01(r, 255) * 255,
g: bound01(g, 255) * 255,
b: bound01(b, 255) * 255
};
}
// `rgbToHsl`
// Converts an RGB color value to HSL.
// *Assumes:* r, g, and b are contained in [0, 255] or [0, 1]
// *Returns:* { h, s, l } in [0,1]
function rgbToHsl(r, g, b) {
r = bound01(r, 255);
g = bound01(g, 255);
b = bound01(b, 255);
var max = mathMax(r, g, b), min = mathMin(r, g, b);
var h, s, l = (max + min) / 2;
if(max == min) {
h = s = 0; // achromatic
}
else {
var d = max - min;
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
switch(max) {
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
case g: h = (b - r) / d + 2; break;
case b: h = (r - g) / d + 4; break;
}
h /= 6;
}
return { h: h, s: s, l: l };
}
// `hslToRgb`
// Converts an HSL color value to RGB.
// *Assumes:* h is contained in [0, 1] or [0, 360] and s and l are contained [0, 1] or [0, 100]
// *Returns:* { r, g, b } in the set [0, 255]
function hslToRgb(h, s, l) {
var r, g, b;
h = bound01(h, 360);
s = bound01(s, 100);
l = bound01(l, 100);
function hue2rgb(p, q, t) {
if(t < 0) t += 1;
if(t > 1) t -= 1;
if(t < 1/6) return p + (q - p) * 6 * t;
if(t < 1/2) return q;
if(t < 2/3) return p + (q - p) * (2/3 - t) * 6;
return p;
}
if(s === 0) {
r = g = b = l; // achromatic
}
else {
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
var p = 2 * l - q;
r = hue2rgb(p, q, h + 1/3);
g = hue2rgb(p, q, h);
b = hue2rgb(p, q, h - 1/3);
}
return { r: r * 255, g: g * 255, b: b * 255 };
}
// `rgbToHsv`
// Converts an RGB color value to HSV
// *Assumes:* r, g, and b are contained in the set [0, 255] or [0, 1]
// *Returns:* { h, s, v } in [0,1]
function rgbToHsv(r, g, b) {
r = bound01(r, 255);
g = bound01(g, 255);
b = bound01(b, 255);
var max = mathMax(r, g, b), min = mathMin(r, g, b);
var h, s, v = max;
var d = max - min;
s = max === 0 ? 0 : d / max;
if(max == min) {
h = 0; // achromatic
}
else {
switch(max) {
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
case g: h = (b - r) / d + 2; break;
case b: h = (r - g) / d + 4; break;
}
h /= 6;
}
return { h: h, s: s, v: v };
}
// `hsvToRgb`
// Converts an HSV color value to RGB.
// *Assumes:* h is contained in [0, 1] or [0, 360] and s and v are contained in [0, 1] or [0, 100]
// *Returns:* { r, g, b } in the set [0, 255]
function hsvToRgb(h, s, v) {
h = bound01(h, 360) * 6;
s = bound01(s, 100);
v = bound01(v, 100);
var i = Math.floor(h),
f = h - i,
p = v * (1 - s),
q = v * (1 - f * s),
t = v * (1 - (1 - f) * s),
mod = i % 6,
r = [v, q, p, p, t, v][mod],
g = [t, v, v, q, p, p][mod],
b = [p, p, t, v, v, q][mod];
return { r: r * 255, g: g * 255, b: b * 255 };
}
// `rgbToHex`
// Converts an RGB color to hex
// Assumes r, g, and b are contained in the set [0, 255]
// Returns a 3 or 6 character hex
function rgbToHex(r, g, b, allow3Char) {
var hex = [
pad2(mathRound(r).toString(16)),
pad2(mathRound(g).toString(16)),
pad2(mathRound(b).toString(16))
];
// Return a 3 character hex if possible
if (allow3Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1)) {
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0);
}
return hex.join("");
}
// `rgbaToHex`
// Converts an RGBA color plus alpha transparency to hex
// Assumes r, g, b are contained in the set [0, 255] and
// a in [0, 1]. Returns a 4 or 8 character rgba hex
function rgbaToHex(r, g, b, a, allow4Char) {
var hex = [
pad2(mathRound(r).toString(16)),
pad2(mathRound(g).toString(16)),
pad2(mathRound(b).toString(16)),
pad2(convertDecimalToHex(a))
];
// Return a 4 character hex if possible
if (allow4Char && hex[0].charAt(0) == hex[0].charAt(1) && hex[1].charAt(0) == hex[1].charAt(1) && hex[2].charAt(0) == hex[2].charAt(1) && hex[3].charAt(0) == hex[3].charAt(1)) {
return hex[0].charAt(0) + hex[1].charAt(0) + hex[2].charAt(0) + hex[3].charAt(0);
}
return hex.join("");
}
// `rgbaToArgbHex`
// Converts an RGBA color to an ARGB Hex8 string
// Rarely used, but required for "toFilter()"
function rgbaToArgbHex(r, g, b, a) {
var hex = [
pad2(convertDecimalToHex(a)),
pad2(mathRound(r).toString(16)),
pad2(mathRound(g).toString(16)),
pad2(mathRound(b).toString(16))
];
return hex.join("");
}
// `equals`
// Can be called with any tinycolor input
tinycolor.equals = function (color1, color2) {
if (!color1 || !color2) { return false; }
return tinycolor(color1).toRgbString() == tinycolor(color2).toRgbString();
};
tinycolor.random = function() {
return tinycolor.fromRatio({
r: mathRandom(),
g: mathRandom(),
b: mathRandom()
});
};
// Modification Functions
// ----------------------
// Thanks to less.js for some of the basics here
//
function desaturate(color, amount) {
amount = (amount === 0) ? 0 : (amount || 10);
var hsl = tinycolor(color).toHsl();
hsl.s -= amount / 100;
hsl.s = clamp01(hsl.s);
return tinycolor(hsl);
}
function saturate(color, amount) {
amount = (amount === 0) ? 0 : (amount || 10);
var hsl = tinycolor(color).toHsl();
hsl.s += amount / 100;
hsl.s = clamp01(hsl.s);
return tinycolor(hsl);
}
function greyscale(color) {
return tinycolor(color).desaturate(100);
}
function lighten (color, amount) {
amount = (amount === 0) ? 0 : (amount || 10);
var hsl = tinycolor(color).toHsl();
hsl.l += amount / 100;
hsl.l = clamp01(hsl.l);
return tinycolor(hsl);
}
function brighten(color, amount) {
amount = (amount === 0) ? 0 : (amount || 10);
var rgb = tinycolor(color).toRgb();
rgb.r = mathMax(0, mathMin(255, rgb.r - mathRound(255 * - (amount / 100))));
rgb.g = mathMax(0, mathMin(255, rgb.g - mathRound(255 * - (amount / 100))));
rgb.b = mathMax(0, mathMin(255, rgb.b - mathRound(255 * - (amount / 100))));
return tinycolor(rgb);
}
function darken (color, amount) {
amount = (amount === 0) ? 0 : (amount || 10);
var hsl = tinycolor(color).toHsl();
hsl.l -= amount / 100;
hsl.l = clamp01(hsl.l);
return tinycolor(hsl);
}
// Spin takes a positive or negative amount within [-360, 360] indicating the change of hue.
// Values outside of this range will be wrapped into this range.
function spin(color, amount) {
var hsl = tinycolor(color).toHsl();
var hue = (hsl.h + amount) % 360;
hsl.h = hue < 0 ? 360 + hue : hue;
return tinycolor(hsl);
}
// Combination Functions
// ---------------------
// Thanks to jQuery xColor for some of the ideas behind these
//
function complement(color) {
var hsl = tinycolor(color).toHsl();
hsl.h = (hsl.h + 180) % 360;
return tinycolor(hsl);
}
function triad(color) {
var hsl = tinycolor(color).toHsl();
var h = hsl.h;
return [
tinycolor(color),
tinycolor({ h: (h + 120) % 360, s: hsl.s, l: hsl.l }),
tinycolor({ h: (h + 240) % 360, s: hsl.s, l: hsl.l })
];
}
function tetrad(color) {
var hsl = tinycolor(color).toHsl();
var h = hsl.h;
return [
tinycolor(color),
tinycolor({ h: (h + 90) % 360, s: hsl.s, l: hsl.l }),
tinycolor({ h: (h + 180) % 360, s: hsl.s, l: hsl.l }),
tinycolor({ h: (h + 270) % 360, s: hsl.s, l: hsl.l })
];
}
function splitcomplement(color) {
var hsl = tinycolor(color).toHsl();
var h = hsl.h;
return [
tinycolor(color),
tinycolor({ h: (h + 72) % 360, s: hsl.s, l: hsl.l}),
tinycolor({ h: (h + 216) % 360, s: hsl.s, l: hsl.l})
];
}
function analogous(color, results, slices) {
results = results || 6;
slices = slices || 30;
var hsl = tinycolor(color).toHsl();
var part = 360 / slices;
var ret = [tinycolor(color)];
for (hsl.h = ((hsl.h - (part * results >> 1)) + 720) % 360; --results; ) {
hsl.h = (hsl.h + part) % 360;
ret.push(tinycolor(hsl));
}
return ret;
}
function monochromatic(color, results) {
results = results || 6;
var hsv = tinycolor(color).toHsv();
var h = hsv.h, s = hsv.s, v = hsv.v;
var ret = [];
var modification = 1 / results;
while (results--) {
ret.push(tinycolor({ h: h, s: s, v: v}));
v = (v + modification) % 1;
}
return ret;
}
// Utility Functions
// ---------------------
tinycolor.mix = function(color1, color2, amount) {
amount = (amount === 0) ? 0 : (amount || 50);
var rgb1 = tinycolor(color1).toRgb();
var rgb2 = tinycolor(color2).toRgb();
var p = amount / 100;
var rgba = {
r: ((rgb2.r - rgb1.r) * p) + rgb1.r,
g: ((rgb2.g - rgb1.g) * p) + rgb1.g,
b: ((rgb2.b - rgb1.b) * p) + rgb1.b,
a: ((rgb2.a - rgb1.a) * p) + rgb1.a
};
return tinycolor(rgba);
};
// Readability Functions
// ---------------------
// false
// tinycolor.isReadable("#000", "#111",{level:"AA",size:"large"}) => false
tinycolor.isReadable = function(color1, color2, wcag2) {
var readability = tinycolor.readability(color1, color2);
var wcag2Parms, out;
out = false;
wcag2Parms = validateWCAG2Parms(wcag2);
switch (wcag2Parms.level + wcag2Parms.size) {
case "AAsmall":
case "AAAlarge":
out = readability >= 4.5;
break;
case "AAlarge":
out = readability >= 3;
break;
case "AAAsmall":
out = readability >= 7;
break;
}
return out;
};
// `mostReadable`
// Given a base color and a list of possible foreground or background
// colors for that base, returns the most readable color.
// Optionally returns Black or White if the most readable color is unreadable.
// *Example*
// tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:false}).toHexString(); // "#112255"
// tinycolor.mostReadable(tinycolor.mostReadable("#123", ["#124", "#125"],{includeFallbackColors:true}).toHexString(); // "#ffffff"
// tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"large"}).toHexString(); // "#faf3f3"
// tinycolor.mostReadable("#a8015a", ["#faf3f3"],{includeFallbackColors:true,level:"AAA",size:"small"}).toHexString(); // "#ffffff"
tinycolor.mostReadable = function(baseColor, colorList, args) {
var bestColor = null;
var bestScore = 0;
var readability;
var includeFallbackColors, level, size ;
args = args || {};
includeFallbackColors = args.includeFallbackColors ;
level = args.level;
size = args.size;
for (var i= 0; i < colorList.length ; i++) {
readability = tinycolor.readability(baseColor, colorList[i]);
if (readability > bestScore) {
bestScore = readability;
bestColor = tinycolor(colorList[i]);
}
}
if (tinycolor.isReadable(baseColor, bestColor, {"level":level,"size":size}) || !includeFallbackColors) {
return bestColor;
}
else {
args.includeFallbackColors=false;
return tinycolor.mostReadable(baseColor,["#fff", "#000"],args);
}
};
// Big List of Colors
// ------------------
//
var names = tinycolor.names = {
aliceblue: "f0f8ff",
antiquewhite: "faebd7",
aqua: "0ff",
aquamarine: "7fffd4",
azure: "f0ffff",
beige: "f5f5dc",
bisque: "ffe4c4",
black: "000",
blanchedalmond: "ffebcd",
blue: "00f",
blueviolet: "8a2be2",
brown: "a52a2a",
burlywood: "deb887",
burntsienna: "ea7e5d",
cadetblue: "5f9ea0",
chartreuse: "7fff00",
chocolate: "d2691e",
coral: "ff7f50",
cornflowerblue: "6495ed",
cornsilk: "fff8dc",
crimson: "dc143c",
cyan: "0ff",
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: "f0f",
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: "789",
lightslategrey: "789",
lightsteelblue: "b0c4de",
lightyellow: "ffffe0",
lime: "0f0",
limegreen: "32cd32",
linen: "faf0e6",
magenta: "f0f",
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: "f00",
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: "fff",
whitesmoke: "f5f5f5",
yellow: "ff0",
yellowgreen: "9acd32"
};
// Make it easy to access colors via `hexNames[hex]`
var hexNames = tinycolor.hexNames = flip(names);
// Utilities
// ---------
// `{ 'name1': 'val1' }` becomes `{ 'val1': 'name1' }`
function flip(o) {
var flipped = { };
for (var i in o) {
if (o.hasOwnProperty(i)) {
flipped[o[i]] = i;
}
}
return flipped;
}
// Return a valid alpha value [0,1] with all invalid values being set to 1
function boundAlpha(a) {
a = parseFloat(a);
if (isNaN(a) || a < 0 || a > 1) {
a = 1;
}
return a;
}
// Take input from [0, n] and return it as [0, 1]
function bound01(n, max) {
if (isOnePointZero(n)) { n = "100%"; }
var processPercent = isPercentage(n);
n = mathMin(max, mathMax(0, parseFloat(n)));
// Automatically convert percentage into number
if (processPercent) {
n = parseInt(n * max, 10) / 100;
}
// Handle floating point rounding errors
if ((Math.abs(n - max) < 0.000001)) {
return 1;
}
// Convert into [0, 1] range if it isn't already
return (n % max) / parseFloat(max);
}
// Force a number between 0 and 1
function clamp01(val) {
return mathMin(1, mathMax(0, val));
}
// Parse a base-16 hex value into a base-10 integer
function parseIntFromHex(val) {
return parseInt(val, 16);
}
// Need to handle 1.0 as 100%, since once it is a number, there is no difference between it and 1
//
function isOnePointZero(n) {
return typeof n == "string" && n.indexOf('.') != -1 && parseFloat(n) === 1;
}
// Check to see if string passed in is a percentage
function isPercentage(n) {
return typeof n === "string" && n.indexOf('%') != -1;
}
// Force a hex value to have 2 characters
function pad2(c) {
return c.length == 1 ? '0' + c : '' + c;
}
// Replace a decimal with it's percentage value
function convertToPercentage(n) {
if (n <= 1) {
n = (n * 100) + "%";
}
return n;
}
// Converts a decimal to a hex value
function convertDecimalToHex(d) {
return Math.round(parseFloat(d) * 255).toString(16);
}
// Converts a hex value to a decimal
function convertHexToDecimal(h) {
return (parseIntFromHex(h) / 255);
}
var matchers = (function() {
//
var CSS_INTEGER = "[-\\+]?\\d+%?";
//
var CSS_NUMBER = "[-\\+]?\\d*\\.\\d+%?";
// Allow positive/negative integer/number. Don't capture the either/or, just the entire outcome.
var CSS_UNIT = "(?:" + CSS_NUMBER + ")|(?:" + CSS_INTEGER + ")";
// Actual matching.
// Parentheses and commas are optional, but not required.
// Whitespace can take the place of commas or opening paren
var PERMISSIVE_MATCH3 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
var PERMISSIVE_MATCH4 = "[\\s|\\(]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")[,|\\s]+(" + CSS_UNIT + ")\\s*\\)?";
return {
CSS_UNIT: new RegExp(CSS_UNIT),
rgb: new RegExp("rgb" + PERMISSIVE_MATCH3),
rgba: new RegExp("rgba" + PERMISSIVE_MATCH4),
hsl: new RegExp("hsl" + PERMISSIVE_MATCH3),
hsla: new RegExp("hsla" + PERMISSIVE_MATCH4),
hsv: new RegExp("hsv" + PERMISSIVE_MATCH3),
hsva: new RegExp("hsva" + PERMISSIVE_MATCH4),
hex3: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
hex6: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/,
hex4: /^#?([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})([0-9a-fA-F]{1})$/,
hex8: /^#?([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})([0-9a-fA-F]{2})$/
};
})();
// `isValidCSSUnit`
// Take in a single string / number and check to see if it looks like a CSS unit
// (see `matchers` above for definition).
function isValidCSSUnit(color) {
return !!matchers.CSS_UNIT.exec(color);
}
// `stringInputToObject`
// Permissive string parsing. Take in a number of formats, and output an object
// based on detected format. Returns `{ r, g, b }` or `{ h, s, l }` or `{ h, s, v}`
function stringInputToObject(color) {
color = color.replace(trimLeft,'').replace(trimRight, '').toLowerCase();
var named = false;
if (names[color]) {
color = names[color];
named = true;
}
else if (color == 'transparent') {
return { r: 0, g: 0, b: 0, a: 0, format: "name" };
}
// Try to match string input using regular expressions.
// Keep most of the number bounding out of this function - don't worry about [0,1] or [0,100] or [0,360]
// Just return an object and let the conversion functions handle that.
// This way the result will be the same whether the tinycolor is initialized with string or object.
var match;
if ((match = matchers.rgb.exec(color))) {
return { r: match[1], g: match[2], b: match[3] };
}
if ((match = matchers.rgba.exec(color))) {
return { r: match[1], g: match[2], b: match[3], a: match[4] };
}
if ((match = matchers.hsl.exec(color))) {
return { h: match[1], s: match[2], l: match[3] };
}
if ((match = matchers.hsla.exec(color))) {
return { h: match[1], s: match[2], l: match[3], a: match[4] };
}
if ((match = matchers.hsv.exec(color))) {
return { h: match[1], s: match[2], v: match[3] };
}
if ((match = matchers.hsva.exec(color))) {
return { h: match[1], s: match[2], v: match[3], a: match[4] };
}
if ((match = matchers.hex8.exec(color))) {
return {
r: parseIntFromHex(match[1]),
g: parseIntFromHex(match[2]),
b: parseIntFromHex(match[3]),
a: convertHexToDecimal(match[4]),
format: named ? "name" : "hex8"
};
}
if ((match = matchers.hex6.exec(color))) {
return {
r: parseIntFromHex(match[1]),
g: parseIntFromHex(match[2]),
b: parseIntFromHex(match[3]),
format: named ? "name" : "hex"
};
}
if ((match = matchers.hex4.exec(color))) {
return {
r: parseIntFromHex(match[1] + '' + match[1]),
g: parseIntFromHex(match[2] + '' + match[2]),
b: parseIntFromHex(match[3] + '' + match[3]),
a: convertHexToDecimal(match[4] + '' + match[4]),
format: named ? "name" : "hex8"
};
}
if ((match = matchers.hex3.exec(color))) {
return {
r: parseIntFromHex(match[1] + '' + match[1]),
g: parseIntFromHex(match[2] + '' + match[2]),
b: parseIntFromHex(match[3] + '' + match[3]),
format: named ? "name" : "hex"
};
}
return false;
}
function validateWCAG2Parms(parms) {
// return valid WCAG2 parms for isReadable.
// If input parms are invalid, return {"level":"AA", "size":"small"}
var level, size;
parms = parms || {"level":"AA", "size":"small"};
level = (parms.level || "AA").toUpperCase();
size = (parms.size || "small").toLowerCase();
if (level !== "AA" && level !== "AAA") {
level = "AA";
}
if (size !== "small" && size !== "large") {
size = "small";
}
return {"level":level, "size":size};
}
// Node: Export function
if ( true && module.exports) {
module.exports = tinycolor;
}
// AMD/requirejs: Define the module
else if (true) {
!(__WEBPACK_AMD_DEFINE_RESULT__ = (function () {return tinycolor;}).call(exports, __webpack_require__, exports, module),
__WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
}
// Browser: Expose to window
else {}
})(Math);
/***/ }),
/***/ 7020:
/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
/*
* World Calendars
* https://github.com/alexcjohnson/world-calendars
*
* Batch-converted from kbwood/calendars
* Many thanks to Keith Wood and all of the contributors to the original project!
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* http://keith-wood.name/calendars.html
Traditional Chinese calendar for jQuery v2.0.2.
Written by Nicolas Riesco (enquiries@nicolasriesco.net) December 2016.
Available under the MIT (http://keith-wood.name/licence.html) license.
Please attribute the author if you use it. */
var main = __webpack_require__(8700);
var assign = __webpack_require__(896);
var gregorianCalendar = main.instance();
/** Implementation of the traditional Chinese calendar.
Source of calendar tables https://github.com/isee15/Lunar-Solar-Calendar-Converter .
@class ChineseCalendar
@param [language=''] {string} The language code (default English) for localisation. */
function ChineseCalendar(language) {
this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];
}
ChineseCalendar.prototype = new main.baseCalendar;
assign(ChineseCalendar.prototype, {
/** The calendar name.
@memberof ChineseCalendar */
name: 'Chinese',
/** Julian date of start of Gregorian epoch: 1 January 0001 CE.
@memberof GregorianCalendar */
jdEpoch: 1721425.5,
/** true
if has a year zero, false
if not.
@memberof ChineseCalendar */
hasYearZero: false,
/** The minimum month number.
This calendar uses month indices to account for intercalary months.
@memberof ChineseCalendar */
minMonth: 0,
/** The first month in the year.
This calendar uses month indices to account for intercalary months.
@memberof ChineseCalendar */
firstMonth: 0,
/** The minimum day number.
@memberof ChineseCalendar */
minDay: 1,
/** Localisations for the plugin.
Entries are objects indexed by the language code ('' being the default US/English).
Each object has the following attributes.
@memberof ChineseCalendar
@property name {string} The calendar name.
@property epochs {string[]} The epoch names.
@property monthNames {string[]} The long names of the months of the year.
@property monthNamesShort {string[]} The short names of the months of the year.
@property dayNames {string[]} The long names of the days of the week.
@property dayNamesShort {string[]} The short names of the days of the week.
@property dayNamesMin {string[]} The minimal names of the days of the week.
@property dateFormat {string} The date format for this calendar.
See the options on formatDate
for details.
@property firstDay {number} The number of the first day of the week, starting at 0.
@property isRTL {number} true
if this localisation reads right-to-left. */
regionalOptions: { // Localisations
'': {
name: 'Chinese',
epochs: ['BEC', 'EC'],
monthNumbers: function(date, padded) {
if (typeof date === 'string') {
var match = date.match(MONTH_NUMBER_REGEXP);
return (match) ? match[0] : '';
}
var year = this._validateYear(date);
var monthIndex = date.month();
var month = '' + this.toChineseMonth(year, monthIndex);
if (padded && month.length < 2) {
month = "0" + month;
}
if (this.isIntercalaryMonth(year, monthIndex)) {
month += 'i';
}
return month;
},
monthNames: function(date) {
if (typeof date === 'string') {
var match = date.match(MONTH_NAME_REGEXP);
return (match) ? match[0] : '';
}
var year = this._validateYear(date);
var monthIndex = date.month();
var month = this.toChineseMonth(year, monthIndex);
var monthName = ['一月','二月','三月','四月','五月','六月',
'七月','八月','九月','十月','十一月','十二月'][month - 1];
if (this.isIntercalaryMonth(year, monthIndex)) {
monthName = '闰' + monthName;
}
return monthName;
},
monthNamesShort: function(date) {
if (typeof date === 'string') {
var match = date.match(MONTH_SHORT_NAME_REGEXP);
return (match) ? match[0] : '';
}
var year = this._validateYear(date);
var monthIndex = date.month();
var month = this.toChineseMonth(year, monthIndex);
var monthName = ['一','二','三','四','五','六',
'七','八','九','十','十一','十二'][month - 1];
if (this.isIntercalaryMonth(year, monthIndex)) {
monthName = '闰' + monthName;
}
return monthName;
},
parseMonth: function(year, monthString) {
year = this._validateYear(year);
var month = parseInt(monthString);
var isIntercalary;
if (!isNaN(month)) {
var i = monthString[monthString.length - 1];
isIntercalary = (i === 'i' || i === 'I');
} else {
if (monthString[0] === '闰') {
isIntercalary = true;
monthString = monthString.substring(1);
}
if (monthString[monthString.length - 1] === '月') {
monthString = monthString.substring(0, monthString.length - 1);
}
month = 1 +
['一','二','三','四','五','六',
'七','八','九','十','十一','十二'].indexOf(monthString);
}
var monthIndex = this.toMonthIndex(year, month, isIntercalary);
return monthIndex;
},
dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
dayNamesMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
digits: null,
dateFormat: 'yyyy/mm/dd',
firstDay: 1,
isRTL: false
}
},
/** Check that a candidate date is from the same calendar and is valid.
@memberof BaseCalendar
@private
@param year {CDate|number} The date or the year to validate.
@param error {string} Error message if invalid.
@return {number} The year.
@throws Error if year out of range. */
_validateYear: function(year, error) {
if (year.year) {
year = year.year();
}
if (typeof year !== 'number' || year < 1888 || year > 2111) {
throw error.replace(/\{0\}/, this.local.name);
}
return year;
},
/** Retrieve the month index (i.e. accounting for intercalary months).
@memberof ChineseCalendar
@param year {number} The year.
@param month {number} The month (1 for first month).
@param [isIntercalary=false] {boolean} If month is intercalary.
@return {number} The month index (0 for first month).
@throws Error if an invalid month/year or a different calendar used. */
toMonthIndex: function(year, month, isIntercalary) {
// compute intercalary month in the year (0 if none)
var intercalaryMonth = this.intercalaryMonth(year);
// validate month
var invalidIntercalaryMonth =
(isIntercalary && month !== intercalaryMonth);
if (invalidIntercalaryMonth || month < 1 || month > 12) {
throw main.local.invalidMonth
.replace(/\{0\}/, this.local.name);
}
// compute month index
var monthIndex;
if (!intercalaryMonth) {
monthIndex = month - 1;
} else if(!isIntercalary && month <= intercalaryMonth) {
monthIndex = month - 1;
} else {
monthIndex = month;
}
return monthIndex;
},
/** Retrieve the month (i.e. accounting for intercalary months).
@memberof ChineseCalendar
@param year {CDate|number} The date or the year to examine.
@param monthIndex {number} The month index (0 for first month).
@return {number} The month (1 for first month).
@throws Error if an invalid month/year or a different calendar used. */
toChineseMonth: function(year, monthIndex) {
if (year.year) {
year = year.year();
monthIndex = year.month();
}
// compute intercalary month in the year (0 if none)
var intercalaryMonth = this.intercalaryMonth(year);
// validate month
var maxMonthIndex = (intercalaryMonth) ? 12 : 11;
if (monthIndex < 0 || monthIndex > maxMonthIndex) {
throw main.local.invalidMonth
.replace(/\{0\}/, this.local.name);
}
// compute Chinese month
var month;
if (!intercalaryMonth) {
month = monthIndex + 1;
} else if(monthIndex < intercalaryMonth) {
month = monthIndex + 1;
} else {
month = monthIndex;
}
return month;
},
/** Determine the intercalary month of a year (if any).
@memberof ChineseCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {number} The intercalary month number, or 0 if none.
@throws Error if an invalid year or a different calendar used. */
intercalaryMonth: function(year) {
year = this._validateYear(year);
var monthDaysTable = LUNAR_MONTH_DAYS[year - LUNAR_MONTH_DAYS[0]];
var intercalaryMonth = monthDaysTable >> 13;
return intercalaryMonth;
},
/** Determine whether this date is an intercalary month.
@memberof ChineseCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [monthIndex] {number} The month index to examine.
@return {boolean} true
if this is an intercalary month, false
if not.
@throws Error if an invalid year or a different calendar used. */
isIntercalaryMonth: function(year, monthIndex) {
if (year.year) {
year = year.year();
monthIndex = year.month();
}
var intercalaryMonth = this.intercalaryMonth(year);
return !!intercalaryMonth && intercalaryMonth === monthIndex;
},
/** Determine whether this date is in a leap year.
@memberof ChineseCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {boolean} true
if this is a leap year, false
if not.
@throws Error if an invalid year or a different calendar used. */
leapYear: function(year) {
return (this.intercalaryMonth(year) !== 0);
},
/** Determine the week of the year for a date - ISO 8601.
@memberof ChineseCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [monthIndex] {number} The month index to examine.
@param [day] {number} The day to examine.
@return {number} The week of the year.
@throws Error if an invalid date or a different calendar used. */
weekOfYear: function(year, monthIndex, day) {
// compute Chinese new year
var validatedYear =
this._validateYear(year, main.local.invalidyear);
var packedDate =
CHINESE_NEW_YEAR[validatedYear - CHINESE_NEW_YEAR[0]];
var y = (packedDate >> 9) & 0xFFF;
var m = (packedDate >> 5) & 0x0F;
var d = packedDate & 0x1F;
// find first Thrusday of the year
var firstThursday;
firstThursday = gregorianCalendar.newDate(y, m, d);
firstThursday.add(4 - (firstThursday.dayOfWeek() || 7), 'd');
// compute days from first Thursday
var offset =
this.toJD(year, monthIndex, day) - firstThursday.toJD();
return 1 + Math.floor(offset / 7);
},
/** Retrieve the number of months in a year.
@memberof ChineseCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {number} The number of months.
@throws Error if an invalid year or a different calendar used. */
monthsInYear: function(year) {
return (this.leapYear(year)) ? 13 : 12;
},
/** Retrieve the number of days in a month.
@memberof ChineseCalendar
@param year {CDate|number} The date to examine or the year of the month.
@param [monthIndex] {number} The month index.
@return {number} The number of days in this month.
@throws Error if an invalid month/year or a different calendar used. */
daysInMonth: function(year, monthIndex) {
if (year.year) {
monthIndex = year.month();
year = year.year();
}
year = this._validateYear(year);
var monthDaysTable = LUNAR_MONTH_DAYS[year - LUNAR_MONTH_DAYS[0]];
var intercalaryMonth = monthDaysTable >> 13;
var maxMonthIndex = (intercalaryMonth) ? 12 : 11;
if (monthIndex > maxMonthIndex) {
throw main.local.invalidMonth
.replace(/\{0\}/, this.local.name);
}
var daysInMonth = (monthDaysTable & (1 << (12 - monthIndex))) ?
30 : 29;
return daysInMonth;
},
/** Determine whether this date is a week day.
@memberof ChineseCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [monthIndex] {number} The month index to examine.
@param [day] {number} The day to examine.
@return {boolean} true
if a week day, false
if not.
@throws Error if an invalid date or a different calendar used. */
weekDay: function(year, monthIndex, day) {
return (this.dayOfWeek(year, monthIndex, day) || 7) < 6;
},
/** Retrieve the Julian date equivalent for this date,
i.e. days since January 1, 4713 BCE Greenwich noon.
@memberof ChineseCalendar
@param year {CDate|number} The date to convert or the year to convert.
@param [monthIndex] {number} The month index to convert.
@param [day] {number} The day to convert.
@return {number} The equivalent Julian date.
@throws Error if an invalid date or a different calendar used. */
toJD: function(year, monthIndex, day) {
var date = this._validate(year, month, day, main.local.invalidDate);
year = this._validateYear(date.year());
monthIndex = date.month();
day = date.day();
var isIntercalary = this.isIntercalaryMonth(year, monthIndex);
var month = this.toChineseMonth(year, monthIndex);
var solar = toSolar(year, month, day, isIntercalary);
return gregorianCalendar.toJD(solar.year, solar.month, solar.day);
},
/** Create a new date from a Julian date.
@memberof ChineseCalendar
@param jd {number} The Julian date to convert.
@return {CDate} The equivalent date. */
fromJD: function(jd) {
var date = gregorianCalendar.fromJD(jd);
var lunar = toLunar(date.year(), date.month(), date.day());
var monthIndex = this.toMonthIndex(
lunar.year, lunar.month, lunar.isIntercalary);
return this.newDate(lunar.year, monthIndex, lunar.day);
},
/** Create a new date from a string.
@memberof ChineseCalendar
@param dateString {string} String representing a Chinese date
@return {CDate} The new date.
@throws Error if an invalid date. */
fromString: function(dateString) {
var match = dateString.match(DATE_REGEXP);
var year = this._validateYear(+match[1]);
var month = +match[2];
var isIntercalary = !!match[3];
var monthIndex = this.toMonthIndex(year, month, isIntercalary);
var day = +match[4];
return this.newDate(year, monthIndex, day);
},
/** Add period(s) to a date.
Cater for no year zero.
@memberof ChineseCalendar
@param date {CDate} The starting date.
@param offset {number} The number of periods to adjust by.
@param period {string} One of 'y' for year, 'm' for month, 'w' for week, 'd' for day.
@return {CDate} The updated date.
@throws Error if a different calendar used. */
add: function(date, offset, period) {
var year = date.year();
var monthIndex = date.month();
var isIntercalary = this.isIntercalaryMonth(year, monthIndex);
var month = this.toChineseMonth(year, monthIndex);
var cdate = Object.getPrototypeOf(ChineseCalendar.prototype)
.add.call(this, date, offset, period);
if (period === 'y') {
// Resync month
var resultYear = cdate.year();
var resultMonthIndex = cdate.month();
// Using the fact the month index of an intercalary month
// equals its month number:
var resultCanBeIntercalaryMonth =
this.isIntercalaryMonth(resultYear, month);
var correctedMonthIndex =
(isIntercalary && resultCanBeIntercalaryMonth) ?
this.toMonthIndex(resultYear, month, true) :
this.toMonthIndex(resultYear, month, false);
if (correctedMonthIndex !== resultMonthIndex) {
cdate.month(correctedMonthIndex);
}
}
return cdate;
},
});
// Used by ChineseCalendar.prototype.fromString
var DATE_REGEXP = /^\s*(-?\d\d\d\d|\d\d)[-/](\d?\d)([iI]?)[-/](\d?\d)/m;
var MONTH_NUMBER_REGEXP = /^\d?\d[iI]?/m;
var MONTH_NAME_REGEXP = /^闰?十?[一二三四五六七八九]?月/m;
var MONTH_SHORT_NAME_REGEXP = /^闰?十?[一二三四五六七八九]?/m;
// Chinese calendar implementation
main.calendars.chinese = ChineseCalendar;
// Chinese calendar tables from year 1888 to 2111
//
// Source:
// https://github.com/isee15/Lunar-Solar-Calendar-Converter.git
// Table of intercalary months and days per month from year 1888 to 2111
//
// bit (12 - i): days in the i^th month
// (= 0 if i^th lunar month has 29 days)
// (= 1 if i^th lunar month has 30 days)
// (first month in lunar year is i = 0)
// bits (13,14,15,16): intercalary month
// (= 0 if lunar year has no intercalary month)
var LUNAR_MONTH_DAYS = [1887, 0x1694, 0x16aa, 0x4ad5,
0xab6, 0xc4b7, 0x4ae, 0xa56, 0xb52a, 0x1d2a, 0xd54, 0x75aa, 0x156a,
0x1096d, 0x95c, 0x14ae, 0xaa4d, 0x1a4c, 0x1b2a, 0x8d55, 0xad4,
0x135a, 0x495d, 0x95c, 0xd49b, 0x149a, 0x1a4a, 0xbaa5, 0x16a8,
0x1ad4, 0x52da, 0x12b6, 0xe937, 0x92e, 0x1496, 0xb64b, 0xd4a,
0xda8, 0x95b5, 0x56c, 0x12ae, 0x492f, 0x92e, 0xcc96, 0x1a94,
0x1d4a, 0xada9, 0xb5a, 0x56c, 0x726e, 0x125c, 0xf92d, 0x192a,
0x1a94, 0xdb4a, 0x16aa, 0xad4, 0x955b, 0x4ba, 0x125a, 0x592b,
0x152a, 0xf695, 0xd94, 0x16aa, 0xaab5, 0x9b4, 0x14b6, 0x6a57,
0xa56, 0x1152a, 0x1d2a, 0xd54, 0xd5aa, 0x156a, 0x96c, 0x94ae,
0x14ae, 0xa4c, 0x7d26, 0x1b2a, 0xeb55, 0xad4, 0x12da, 0xa95d,
0x95a, 0x149a, 0x9a4d, 0x1a4a, 0x11aa5, 0x16a8, 0x16d4, 0xd2da,
0x12b6, 0x936, 0x9497, 0x1496, 0x1564b, 0xd4a, 0xda8, 0xd5b4,
0x156c, 0x12ae, 0xa92f, 0x92e, 0xc96, 0x6d4a, 0x1d4a, 0x10d65,
0xb58, 0x156c, 0xb26d, 0x125c, 0x192c, 0x9a95, 0x1a94, 0x1b4a,
0x4b55, 0xad4, 0xf55b, 0x4ba, 0x125a, 0xb92b, 0x152a, 0x1694,
0x96aa, 0x15aa, 0x12ab5, 0x974, 0x14b6, 0xca57, 0xa56, 0x1526,
0x8e95, 0xd54, 0x15aa, 0x49b5, 0x96c, 0xd4ae, 0x149c, 0x1a4c,
0xbd26, 0x1aa6, 0xb54, 0x6d6a, 0x12da, 0x1695d, 0x95a, 0x149a,
0xda4b, 0x1a4a, 0x1aa4, 0xbb54, 0x16b4, 0xada, 0x495b, 0x936,
0xf497, 0x1496, 0x154a, 0xb6a5, 0xda4, 0x15b4, 0x6ab6, 0x126e,
0x1092f, 0x92e, 0xc96, 0xcd4a, 0x1d4a, 0xd64, 0x956c, 0x155c,
0x125c, 0x792e, 0x192c, 0xfa95, 0x1a94, 0x1b4a, 0xab55, 0xad4,
0x14da, 0x8a5d, 0xa5a, 0x1152b, 0x152a, 0x1694, 0xd6aa, 0x15aa,
0xab4, 0x94ba, 0x14b6, 0xa56, 0x7527, 0xd26, 0xee53, 0xd54, 0x15aa,
0xa9b5, 0x96c, 0x14ae, 0x8a4e, 0x1a4c, 0x11d26, 0x1aa4, 0x1b54,
0xcd6a, 0xada, 0x95c, 0x949d, 0x149a, 0x1a2a, 0x5b25, 0x1aa4,
0xfb52, 0x16b4, 0xaba, 0xa95b, 0x936, 0x1496, 0x9a4b, 0x154a,
0x136a5, 0xda4, 0x15ac];
// Table of Chinese New Years from year 1888 to 2111
//
// bits (0 to 4): solar day
// bits (5 to 8): solar month
// bits (9 to 20): solar year
var CHINESE_NEW_YEAR = [1887, 0xec04c, 0xec23f, 0xec435, 0xec649,
0xec83e, 0xeca51, 0xecc46, 0xece3a, 0xed04d, 0xed242, 0xed436,
0xed64a, 0xed83f, 0xeda53, 0xedc48, 0xede3d, 0xee050, 0xee244,
0xee439, 0xee64d, 0xee842, 0xeea36, 0xeec4a, 0xeee3e, 0xef052,
0xef246, 0xef43a, 0xef64e, 0xef843, 0xefa37, 0xefc4b, 0xefe41,
0xf0054, 0xf0248, 0xf043c, 0xf0650, 0xf0845, 0xf0a38, 0xf0c4d,
0xf0e42, 0xf1037, 0xf124a, 0xf143e, 0xf1651, 0xf1846, 0xf1a3a,
0xf1c4e, 0xf1e44, 0xf2038, 0xf224b, 0xf243f, 0xf2653, 0xf2848,
0xf2a3b, 0xf2c4f, 0xf2e45, 0xf3039, 0xf324d, 0xf3442, 0xf3636,
0xf384a, 0xf3a3d, 0xf3c51, 0xf3e46, 0xf403b, 0xf424e, 0xf4443,
0xf4638, 0xf484c, 0xf4a3f, 0xf4c52, 0xf4e48, 0xf503c, 0xf524f,
0xf5445, 0xf5639, 0xf584d, 0xf5a42, 0xf5c35, 0xf5e49, 0xf603e,
0xf6251, 0xf6446, 0xf663b, 0xf684f, 0xf6a43, 0xf6c37, 0xf6e4b,
0xf703f, 0xf7252, 0xf7447, 0xf763c, 0xf7850, 0xf7a45, 0xf7c39,
0xf7e4d, 0xf8042, 0xf8254, 0xf8449, 0xf863d, 0xf8851, 0xf8a46,
0xf8c3b, 0xf8e4f, 0xf9044, 0xf9237, 0xf944a, 0xf963f, 0xf9853,
0xf9a47, 0xf9c3c, 0xf9e50, 0xfa045, 0xfa238, 0xfa44c, 0xfa641,
0xfa836, 0xfaa49, 0xfac3d, 0xfae52, 0xfb047, 0xfb23a, 0xfb44e,
0xfb643, 0xfb837, 0xfba4a, 0xfbc3f, 0xfbe53, 0xfc048, 0xfc23c,
0xfc450, 0xfc645, 0xfc839, 0xfca4c, 0xfcc41, 0xfce36, 0xfd04a,
0xfd23d, 0xfd451, 0xfd646, 0xfd83a, 0xfda4d, 0xfdc43, 0xfde37,
0xfe04b, 0xfe23f, 0xfe453, 0xfe648, 0xfe83c, 0xfea4f, 0xfec44,
0xfee38, 0xff04c, 0xff241, 0xff436, 0xff64a, 0xff83e, 0xffa51,
0xffc46, 0xffe3a, 0x10004e, 0x100242, 0x100437, 0x10064b, 0x100841,
0x100a53, 0x100c48, 0x100e3c, 0x10104f, 0x101244, 0x101438,
0x10164c, 0x101842, 0x101a35, 0x101c49, 0x101e3d, 0x102051,
0x102245, 0x10243a, 0x10264e, 0x102843, 0x102a37, 0x102c4b,
0x102e3f, 0x103053, 0x103247, 0x10343b, 0x10364f, 0x103845,
0x103a38, 0x103c4c, 0x103e42, 0x104036, 0x104249, 0x10443d,
0x104651, 0x104846, 0x104a3a, 0x104c4e, 0x104e43, 0x105038,
0x10524a, 0x10543e, 0x105652, 0x105847, 0x105a3b, 0x105c4f,
0x105e45, 0x106039, 0x10624c, 0x106441, 0x106635, 0x106849,
0x106a3d, 0x106c51, 0x106e47, 0x10703c, 0x10724f, 0x107444,
0x107638, 0x10784c, 0x107a3f, 0x107c53, 0x107e48];
function toLunar(yearOrDate, monthOrResult, day, result) {
var solarDate;
var lunarDate;
if(typeof yearOrDate === 'object') {
solarDate = yearOrDate;
lunarDate = monthOrResult || {};
} else {
var isValidYear = (typeof yearOrDate === 'number') &&
(yearOrDate >= 1888) && (yearOrDate <= 2111);
if(!isValidYear)
throw new Error("Solar year outside range 1888-2111");
var isValidMonth = (typeof monthOrResult === 'number') &&
(monthOrResult >= 1) && (monthOrResult <= 12);
if(!isValidMonth)
throw new Error("Solar month outside range 1 - 12");
var isValidDay = (typeof day === 'number') && (day >= 1) && (day <= 31);
if(!isValidDay)
throw new Error("Solar day outside range 1 - 31");
solarDate = {
year: yearOrDate,
month: monthOrResult,
day: day,
};
lunarDate = result || {};
}
// Compute Chinese new year and lunar year
var chineseNewYearPackedDate =
CHINESE_NEW_YEAR[solarDate.year - CHINESE_NEW_YEAR[0]];
var packedDate = (solarDate.year << 9) | (solarDate.month << 5)
| solarDate.day;
lunarDate.year = (packedDate >= chineseNewYearPackedDate) ?
solarDate.year :
solarDate.year - 1;
chineseNewYearPackedDate =
CHINESE_NEW_YEAR[lunarDate.year - CHINESE_NEW_YEAR[0]];
var y = (chineseNewYearPackedDate >> 9) & 0xFFF;
var m = (chineseNewYearPackedDate >> 5) & 0x0F;
var d = chineseNewYearPackedDate & 0x1F;
// Compute days from new year
var daysFromNewYear;
var chineseNewYearJSDate = new Date(y, m -1, d);
var jsDate = new Date(solarDate.year, solarDate.month - 1, solarDate.day);
daysFromNewYear = Math.round(
(jsDate - chineseNewYearJSDate) / (24 * 3600 * 1000));
// Compute lunar month and day
var monthDaysTable = LUNAR_MONTH_DAYS[lunarDate.year - LUNAR_MONTH_DAYS[0]];
var i;
for(i = 0; i < 13; i++) {
var daysInMonth = (monthDaysTable & (1 << (12 - i))) ? 30 : 29;
if (daysFromNewYear < daysInMonth) {
break;
}
daysFromNewYear -= daysInMonth;
}
var intercalaryMonth = monthDaysTable >> 13;
if (!intercalaryMonth || i < intercalaryMonth) {
lunarDate.isIntercalary = false;
lunarDate.month = 1 + i;
} else if (i === intercalaryMonth) {
lunarDate.isIntercalary = true;
lunarDate.month = i;
} else {
lunarDate.isIntercalary = false;
lunarDate.month = i;
}
lunarDate.day = 1 + daysFromNewYear;
return lunarDate;
}
function toSolar(yearOrDate, monthOrResult, day, isIntercalaryOrResult, result) {
var solarDate;
var lunarDate;
if(typeof yearOrDate === 'object') {
lunarDate = yearOrDate;
solarDate = monthOrResult || {};
} else {
var isValidYear = (typeof yearOrDate === 'number') &&
(yearOrDate >= 1888) && (yearOrDate <= 2111);
if(!isValidYear)
throw new Error("Lunar year outside range 1888-2111");
var isValidMonth = (typeof monthOrResult === 'number') &&
(monthOrResult >= 1) && (monthOrResult <= 12);
if(!isValidMonth)
throw new Error("Lunar month outside range 1 - 12");
var isValidDay = (typeof day === 'number') && (day >= 1) && (day <= 30);
if(!isValidDay)
throw new Error("Lunar day outside range 1 - 30");
var isIntercalary;
if(typeof isIntercalaryOrResult === 'object') {
isIntercalary = false;
solarDate = isIntercalaryOrResult;
} else {
isIntercalary = !!isIntercalaryOrResult;
solarDate = result || {};
}
lunarDate = {
year: yearOrDate,
month: monthOrResult,
day: day,
isIntercalary: isIntercalary,
};
}
// Compute days from new year
var daysFromNewYear;
daysFromNewYear = lunarDate.day - 1;
var monthDaysTable = LUNAR_MONTH_DAYS[lunarDate.year - LUNAR_MONTH_DAYS[0]];
var intercalaryMonth = monthDaysTable >> 13;
var monthsFromNewYear;
if (!intercalaryMonth) {
monthsFromNewYear = lunarDate.month - 1;
} else if (lunarDate.month > intercalaryMonth) {
monthsFromNewYear = lunarDate.month;
} else if (lunarDate.isIntercalary) {
monthsFromNewYear = lunarDate.month;
} else {
monthsFromNewYear = lunarDate.month - 1;
}
for(var i = 0; i < monthsFromNewYear; i++) {
var daysInMonth = (monthDaysTable & (1 << (12 - i))) ? 30 : 29;
daysFromNewYear += daysInMonth;
}
// Compute Chinese new year
var packedDate = CHINESE_NEW_YEAR[lunarDate.year - CHINESE_NEW_YEAR[0]];
var y = (packedDate >> 9) & 0xFFF;
var m = (packedDate >> 5) & 0x0F;
var d = packedDate & 0x1F;
// Compute solar date
var jsDate = new Date(y, m - 1, d + daysFromNewYear);
solarDate.year = jsDate.getFullYear();
solarDate.month = 1 + jsDate.getMonth();
solarDate.day = jsDate.getDate();
return solarDate;
}
/***/ }),
/***/ 7411:
/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
/*
* World Calendars
* https://github.com/alexcjohnson/world-calendars
*
* Batch-converted from kbwood/calendars
* Many thanks to Keith Wood and all of the contributors to the original project!
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* http://keith-wood.name/calendars.html
Coptic calendar for jQuery v2.0.2.
Written by Keith Wood (wood.keith{at}optusnet.com.au) February 2010.
Available under the MIT (http://keith-wood.name/licence.html) license.
Please attribute the author if you use it. */
var main = __webpack_require__(8700);
var assign = __webpack_require__(896);
/** Implementation of the Coptic calendar.
See http://en.wikipedia.org/wiki/Coptic_calendar.
See also Calendrical Calculations: The Millennium Edition
(http://emr.cs.iit.edu/home/reingold/calendar-book/index.shtml).
@class CopticCalendar
@param [language=''] {string} The language code (default English) for localisation. */
function CopticCalendar(language) {
this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];
}
CopticCalendar.prototype = new main.baseCalendar;
assign(CopticCalendar.prototype, {
/** The calendar name.
@memberof CopticCalendar */
name: 'Coptic',
/** Julian date of start of Coptic epoch: 29 August 284 CE (Gregorian).
@memberof CopticCalendar */
jdEpoch: 1825029.5,
/** Days per month in a common year.
@memberof CopticCalendar */
daysPerMonth: [30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 5],
/** true
if has a year zero, false
if not.
@memberof CopticCalendar */
hasYearZero: false,
/** The minimum month number.
@memberof CopticCalendar */
minMonth: 1,
/** The first month in the year.
@memberof CopticCalendar */
firstMonth: 1,
/** The minimum day number.
@memberof CopticCalendar */
minDay: 1,
/** Localisations for the plugin.
Entries are objects indexed by the language code ('' being the default US/English).
Each object has the following attributes.
@memberof CopticCalendar
@property name {string} The calendar name.
@property epochs {string[]} The epoch names.
@property monthNames {string[]} The long names of the months of the year.
@property monthNamesShort {string[]} The short names of the months of the year.
@property dayNames {string[]} The long names of the days of the week.
@property dayNamesShort {string[]} The short names of the days of the week.
@property dayNamesMin {string[]} The minimal names of the days of the week.
@property dateFormat {string} The date format for this calendar.
See the options on formatDate
for details.
@property firstDay {number} The number of the first day of the week, starting at 0.
@property isRTL {number} true
if this localisation reads right-to-left. */
regionalOptions: { // Localisations
'': {
name: 'Coptic',
epochs: ['BAM', 'AM'],
monthNames: ['Thout', 'Paopi', 'Hathor', 'Koiak', 'Tobi', 'Meshir',
'Paremhat', 'Paremoude', 'Pashons', 'Paoni', 'Epip', 'Mesori', 'Pi Kogi Enavot'],
monthNamesShort: ['Tho', 'Pao', 'Hath', 'Koi', 'Tob', 'Mesh',
'Pat', 'Pad', 'Pash', 'Pao', 'Epi', 'Meso', 'PiK'],
dayNames: ['Tkyriaka', 'Pesnau', 'Pshoment', 'Peftoou', 'Ptiou', 'Psoou', 'Psabbaton'],
dayNamesShort: ['Tky', 'Pes', 'Psh', 'Pef', 'Pti', 'Pso', 'Psa'],
dayNamesMin: ['Tk', 'Pes', 'Psh', 'Pef', 'Pt', 'Pso', 'Psa'],
digits: null,
dateFormat: 'dd/mm/yyyy',
firstDay: 0,
isRTL: false
}
},
/** Determine whether this date is in a leap year.
@memberof CopticCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {boolean} true
if this is a leap year, false
if not.
@throws Error if an invalid year or a different calendar used. */
leapYear: function(year) {
var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
var year = date.year() + (date.year() < 0 ? 1 : 0); // No year zero
return year % 4 === 3 || year % 4 === -1;
},
/** Retrieve the number of months in a year.
@memberof CopticCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {number} The number of months.
@throws Error if an invalid year or a different calendar used. */
monthsInYear: function(year) {
this._validate(year, this.minMonth, this.minDay,
main.local.invalidYear || main.regionalOptions[''].invalidYear);
return 13;
},
/** Determine the week of the year for a date.
@memberof CopticCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number) the month to examine.
@param [day] {number} The day to examine.
@return {number} The week of the year.
@throws Error if an invalid date or a different calendar used. */
weekOfYear: function(year, month, day) {
// Find Sunday of this week starting on Sunday
var checkDate = this.newDate(year, month, day);
checkDate.add(-checkDate.dayOfWeek(), 'd');
return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;
},
/** Retrieve the number of days in a month.
@memberof CopticCalendar
@param year {CDate|number} The date to examine or the year of the month.
@param [month] {number} The month.
@return {number} The number of days in this month.
@throws Error if an invalid month/year or a different calendar used. */
daysInMonth: function(year, month) {
var date = this._validate(year, month, this.minDay, main.local.invalidMonth);
return this.daysPerMonth[date.month() - 1] +
(date.month() === 13 && this.leapYear(date.year()) ? 1 : 0);
},
/** Determine whether this date is a week day.
@memberof CopticCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param month {number} The month to examine.
@param day {number} The day to examine.
@return {boolean} true
if a week day, false
if not.
@throws Error if an invalid date or a different calendar used. */
weekDay: function(year, month, day) {
return (this.dayOfWeek(year, month, day) || 7) < 6;
},
/** Retrieve the Julian date equivalent for this date,
i.e. days since January 1, 4713 BCE Greenwich noon.
@memberof CopticCalendar
@param year {CDate|number} The date to convert or the year to convert.
@param [month] {number) the month to convert.
@param [day] {number} The day to convert.
@return {number} The equivalent Julian date.
@throws Error if an invalid date or a different calendar used. */
toJD: function(year, month, day) {
var date = this._validate(year, month, day, main.local.invalidDate);
year = date.year();
if (year < 0) { year++; } // No year zero
return date.day() + (date.month() - 1) * 30 +
(year - 1) * 365 + Math.floor(year / 4) + this.jdEpoch - 1;
},
/** Create a new date from a Julian date.
@memberof CopticCalendar
@param jd {number} The Julian date to convert.
@return {CDate} The equivalent date. */
fromJD: function(jd) {
var c = Math.floor(jd) + 0.5 - this.jdEpoch;
var year = Math.floor((c - Math.floor((c + 366) / 1461)) / 365) + 1;
if (year <= 0) { year--; } // No year zero
c = Math.floor(jd) + 0.5 - this.newDate(year, 1, 1).toJD();
var month = Math.floor(c / 30) + 1;
var day = c - (month - 1) * 30 + 1;
return this.newDate(year, month, day);
}
});
// Coptic calendar implementation
main.calendars.coptic = CopticCalendar;
/***/ }),
/***/ 5668:
/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
/*
* World Calendars
* https://github.com/alexcjohnson/world-calendars
*
* Batch-converted from kbwood/calendars
* Many thanks to Keith Wood and all of the contributors to the original project!
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* http://keith-wood.name/calendars.html
Discworld calendar for jQuery v2.0.2.
Written by Keith Wood (wood.keith{at}optusnet.com.au) January 2016.
Available under the MIT (http://keith-wood.name/licence.html) license.
Please attribute the author if you use it. */
var main = __webpack_require__(8700);
var assign = __webpack_require__(896);
/** Implementation of the Discworld calendar - Unseen University version.
See also http://wiki.lspace.org/mediawiki/Discworld_calendar
and http://discworld.wikia.com/wiki/Discworld_calendar.
@class DiscworldCalendar
@param [language=''] {string} The language code (default English) for localisation. */
function DiscworldCalendar(language) {
this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];
}
DiscworldCalendar.prototype = new main.baseCalendar;
assign(DiscworldCalendar.prototype, {
/** The calendar name.
@memberof DiscworldCalendar */
name: 'Discworld',
/** Julian date of start of Discworld epoch: 1 January 0001 CE.
@memberof DiscworldCalendar */
jdEpoch: 1721425.5,
/** Days per month in a common year.
@memberof DiscworldCalendar */
daysPerMonth: [16, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32],
/** true
if has a year zero, false
if not.
@memberof DiscworldCalendar */
hasYearZero: false,
/** The minimum month number.
@memberof DiscworldCalendar */
minMonth: 1,
/** The first month in the year.
@memberof DiscworldCalendar */
firstMonth: 1,
/** The minimum day number.
@memberof DiscworldCalendar */
minDay: 1,
/** Localisations for the plugin.
Entries are objects indexed by the language code ('' being the default US/English).
Each object has the following attributes.
@memberof DiscworldCalendar
@property name {string} The calendar name.
@property epochs {string[]} The epoch names.
@property monthNames {string[]} The long names of the months of the year.
@property monthNamesShort {string[]} The short names of the months of the year.
@property dayNames {string[]} The long names of the days of the week.
@property dayNamesShort {string[]} The short names of the days of the week.
@property dayNamesMin {string[]} The minimal names of the days of the week.
@property dateFormat {string} The date format for this calendar.
See the options on formatDate
for details.
@property firstDay {number} The number of the first day of the week, starting at 0.
@property isRTL {number} true
if this localisation reads right-to-left. */
regionalOptions: { // Localisations
'': {
name: 'Discworld',
epochs: ['BUC', 'UC'],
monthNames: ['Ick', 'Offle', 'February', 'March', 'April', 'May', 'June',
'Grune', 'August', 'Spune', 'Sektober', 'Ember', 'December'],
monthNamesShort: ['Ick', 'Off', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Gru', 'Aug', 'Spu', 'Sek', 'Emb', 'Dec'],
dayNames: ['Sunday', 'Octeday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
dayNamesShort: ['Sun', 'Oct', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
dayNamesMin: ['Su', 'Oc', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
digits: null,
dateFormat: 'yyyy/mm/dd',
firstDay: 2,
isRTL: false
}
},
/** Determine whether this date is in a leap year.
@memberof DiscworldCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {boolean} true
if this is a leap year, false
if not.
@throws Error if an invalid year or a different calendar used. */
leapYear: function(year) {
this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
return false;
},
/** Retrieve the number of months in a year.
@memberof DiscworldCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {number} The number of months.
@throws Error if an invalid year or a different calendar used. */
monthsInYear: function(year) {
this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
return 13;
},
/** Retrieve the number of days in a year.
@memberof DiscworldCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {number} The number of days.
@throws Error if an invalid year or a different calendar used. */
daysInYear: function(year) {
this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
return 400;
},
/** Determine the week of the year for a date.
@memberof DiscworldCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {number} The week of the year.
@throws Error if an invalid date or a different calendar used. */
weekOfYear: function(year, month, day) {
// Find Sunday of this week starting on Sunday
var checkDate = this.newDate(year, month, day);
checkDate.add(-checkDate.dayOfWeek(), 'd');
return Math.floor((checkDate.dayOfYear() - 1) / 8) + 1;
},
/** Retrieve the number of days in a month.
@memberof DiscworldCalendar
@param year {CDate|number} The date to examine or the year of the month.
@param [month] {number} The month.
@return {number} The number of days in this month.
@throws Error if an invalid month/year or a different calendar used. */
daysInMonth: function(year, month) {
var date = this._validate(year, month, this.minDay, main.local.invalidMonth);
return this.daysPerMonth[date.month() - 1];
},
/** Retrieve the number of days in a week.
@memberof DiscworldCalendar
@return {number} The number of days. */
daysInWeek: function() {
return 8;
},
/** Retrieve the day of the week for a date.
@memberof DiscworldCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {number} The day of the week: 0 to number of days - 1.
@throws Error if an invalid date or a different calendar used. */
dayOfWeek: function(year, month, day) {
var date = this._validate(year, month, day, main.local.invalidDate);
return (date.day() + 1) % 8;
},
/** Determine whether this date is a week day.
@memberof DiscworldCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {boolean} true
if a week day, false
if not.
@throws Error if an invalid date or a different calendar used. */
weekDay: function(year, month, day) {
var dow = this.dayOfWeek(year, month, day);
return (dow >= 2 && dow <= 6);
},
/** Retrieve additional information about a date.
@memberof DiscworldCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {object} Additional information - contents depends on calendar.
@throws Error if an invalid date or a different calendar used. */
extraInfo: function(year, month, day) {
var date = this._validate(year, month, day, main.local.invalidDate);
return {century: centuries[Math.floor((date.year() - 1) / 100) + 1] || ''};
},
/** Retrieve the Julian date equivalent for this date,
i.e. days since January 1, 4713 BCE Greenwich noon.
@memberof DiscworldCalendar
@param year {CDate|number} The date to convert or the year to convert.
@param [month] {number} The month to convert.
@param [day] {number} The day to convert.
@return {number} The equivalent Julian date.
@throws Error if an invalid date or a different calendar used. */
toJD: function(year, month, day) {
var date = this._validate(year, month, day, main.local.invalidDate);
year = date.year() + (date.year() < 0 ? 1 : 0);
month = date.month();
day = date.day();
return day + (month > 1 ? 16 : 0) + (month > 2 ? (month - 2) * 32 : 0) +
(year - 1) * 400 + this.jdEpoch - 1;
},
/** Create a new date from a Julian date.
@memberof DiscworldCalendar
@param jd {number} The Julian date to convert.
@return {CDate} The equivalent date. */
fromJD: function(jd) {
jd = Math.floor(jd + 0.5) - Math.floor(this.jdEpoch) - 1;
var year = Math.floor(jd / 400) + 1;
jd -= (year - 1) * 400;
jd += (jd > 15 ? 16 : 0);
var month = Math.floor(jd / 32) + 1;
var day = jd - (month - 1) * 32 + 1;
return this.newDate(year <= 0 ? year - 1 : year, month, day);
}
});
// Names of the centuries
var centuries = {
20: 'Fruitbat',
21: 'Anchovy'
};
// Discworld calendar implementation
main.calendars.discworld = DiscworldCalendar;
/***/ }),
/***/ 2787:
/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
/*
* World Calendars
* https://github.com/alexcjohnson/world-calendars
*
* Batch-converted from kbwood/calendars
* Many thanks to Keith Wood and all of the contributors to the original project!
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* http://keith-wood.name/calendars.html
Ethiopian calendar for jQuery v2.0.2.
Written by Keith Wood (wood.keith{at}optusnet.com.au) February 2010.
Available under the MIT (http://keith-wood.name/licence.html) license.
Please attribute the author if you use it. */
var main = __webpack_require__(8700);
var assign = __webpack_require__(896);
/** Implementation of the Ethiopian calendar.
See http://en.wikipedia.org/wiki/Ethiopian_calendar.
See also Calendrical Calculations: The Millennium Edition
(http://emr.cs.iit.edu/home/reingold/calendar-book/index.shtml).
@class EthiopianCalendar
@param [language=''] {string} The language code (default English) for localisation. */
function EthiopianCalendar(language) {
this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];
}
EthiopianCalendar.prototype = new main.baseCalendar;
assign(EthiopianCalendar.prototype, {
/** The calendar name.
@memberof EthiopianCalendar */
name: 'Ethiopian',
/** Julian date of start of Ethiopian epoch: 27 August 8 CE (Gregorian).
@memberof EthiopianCalendar */
jdEpoch: 1724220.5,
/** Days per month in a common year.
@memberof EthiopianCalendar */
daysPerMonth: [30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 5],
/** true
if has a year zero, false
if not.
@memberof EthiopianCalendar */
hasYearZero: false,
/** The minimum month number.
@memberof EthiopianCalendar */
minMonth: 1,
/** The first month in the year.
@memberof EthiopianCalendar */
firstMonth: 1,
/** The minimum day number.
@memberof EthiopianCalendar */
minDay: 1,
/** Localisations for the plugin.
Entries are objects indexed by the language code ('' being the default US/English).
Each object has the following attributes.
@memberof EthiopianCalendar
@property name {string} The calendar name.
@property epochs {string[]} The epoch names.
@property monthNames {string[]} The long names of the months of the year.
@property monthNamesShort {string[]} The short names of the months of the year.
@property dayNames {string[]} The long names of the days of the week.
@property dayNamesShort {string[]} The short names of the days of the week.
@property dayNamesMin {string[]} The minimal names of the days of the week.
@property dateFormat {string} The date format for this calendar.
See the options on formatDate
for details.
@property firstDay {number} The number of the first day of the week, starting at 0.
@property isRTL {number} true
if this localisation reads right-to-left. */
regionalOptions: { // Localisations
'': {
name: 'Ethiopian',
epochs: ['BEE', 'EE'],
monthNames: ['Meskerem', 'Tikemet', 'Hidar', 'Tahesas', 'Tir', 'Yekatit',
'Megabit', 'Miazia', 'Genbot', 'Sene', 'Hamle', 'Nehase', 'Pagume'],
monthNamesShort: ['Mes', 'Tik', 'Hid', 'Tah', 'Tir', 'Yek',
'Meg', 'Mia', 'Gen', 'Sen', 'Ham', 'Neh', 'Pag'],
dayNames: ['Ehud', 'Segno', 'Maksegno', 'Irob', 'Hamus', 'Arb', 'Kidame'],
dayNamesShort: ['Ehu', 'Seg', 'Mak', 'Iro', 'Ham', 'Arb', 'Kid'],
dayNamesMin: ['Eh', 'Se', 'Ma', 'Ir', 'Ha', 'Ar', 'Ki'],
digits: null,
dateFormat: 'dd/mm/yyyy',
firstDay: 0,
isRTL: false
}
},
/** Determine whether this date is in a leap year.
@memberof EthiopianCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {boolean} true
if this is a leap year, false
if not.
@throws Error if an invalid year or a different calendar used. */
leapYear: function(year) {
var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
var year = date.year() + (date.year() < 0 ? 1 : 0); // No year zero
return year % 4 === 3 || year % 4 === -1;
},
/** Retrieve the number of months in a year.
@memberof EthiopianCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {number} The number of months.
@throws Error if an invalid year or a different calendar used. */
monthsInYear: function(year) {
this._validate(year, this.minMonth, this.minDay,
main.local.invalidYear || main.regionalOptions[''].invalidYear);
return 13;
},
/** Determine the week of the year for a date.
@memberof EthiopianCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {number} The week of the year.
@throws Error if an invalid date or a different calendar used. */
weekOfYear: function(year, month, day) {
// Find Sunday of this week starting on Sunday
var checkDate = this.newDate(year, month, day);
checkDate.add(-checkDate.dayOfWeek(), 'd');
return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;
},
/** Retrieve the number of days in a month.
@memberof EthiopianCalendar
@param year {CDate|number} The date to examine or the year of the month.
@param [month] {number} The month.
@return {number} The number of days in this month.
@throws Error if an invalid month/year or a different calendar used. */
daysInMonth: function(year, month) {
var date = this._validate(year, month, this.minDay, main.local.invalidMonth);
return this.daysPerMonth[date.month() - 1] +
(date.month() === 13 && this.leapYear(date.year()) ? 1 : 0);
},
/** Determine whether this date is a week day.
@memberof EthiopianCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {boolean} true
if a week day, false
if not.
@throws Error if an invalid date or a different calendar used. */
weekDay: function(year, month, day) {
return (this.dayOfWeek(year, month, day) || 7) < 6;
},
/** Retrieve the Julian date equivalent for this date,
i.e. days since January 1, 4713 BCE Greenwich noon.
@memberof EthiopianCalendar
@param year {CDate|number} The date to convert or the year to convert.
@param [month] {number} The month to convert.
@param [day] {number} The day to convert.
@return {number} The equivalent Julian date.
@throws Error if an invalid date or a different calendar used. */
toJD: function(year, month, day) {
var date = this._validate(year, month, day, main.local.invalidDate);
year = date.year();
if (year < 0) { year++; } // No year zero
return date.day() + (date.month() - 1) * 30 +
(year - 1) * 365 + Math.floor(year / 4) + this.jdEpoch - 1;
},
/** Create a new date from a Julian date.
@memberof EthiopianCalendar
@param jd {number} the Julian date to convert.
@return {CDate} the equivalent date. */
fromJD: function(jd) {
var c = Math.floor(jd) + 0.5 - this.jdEpoch;
var year = Math.floor((c - Math.floor((c + 366) / 1461)) / 365) + 1;
if (year <= 0) { year--; } // No year zero
c = Math.floor(jd) + 0.5 - this.newDate(year, 1, 1).toJD();
var month = Math.floor(c / 30) + 1;
var day = c - (month - 1) * 30 + 1;
return this.newDate(year, month, day);
}
});
// Ethiopian calendar implementation
main.calendars.ethiopian = EthiopianCalendar;
/***/ }),
/***/ 2084:
/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
/*
* World Calendars
* https://github.com/alexcjohnson/world-calendars
*
* Batch-converted from kbwood/calendars
* Many thanks to Keith Wood and all of the contributors to the original project!
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* http://keith-wood.name/calendars.html
Hebrew calendar for jQuery v2.0.2.
Written by Keith Wood (wood.keith{at}optusnet.com.au) August 2009.
Available under the MIT (http://keith-wood.name/licence.html) license.
Please attribute the author if you use it. */
var main = __webpack_require__(8700);
var assign = __webpack_require__(896);
/** Implementation of the Hebrew civil calendar.
Based on code from http://www.fourmilab.ch/documents/calendar/.
See also http://en.wikipedia.org/wiki/Hebrew_calendar.
@class HebrewCalendar
@param [language=''] {string} The language code (default English) for localisation. */
function HebrewCalendar(language) {
this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];
}
HebrewCalendar.prototype = new main.baseCalendar;
assign(HebrewCalendar.prototype, {
/** The calendar name.
@memberof HebrewCalendar */
name: 'Hebrew',
/** Julian date of start of Hebrew epoch: 7 October 3761 BCE.
@memberof HebrewCalendar */
jdEpoch: 347995.5,
/** Days per month in a common year.
@memberof HebrewCalendar */
daysPerMonth: [30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 29],
/** true
if has a year zero, false
if not.
@memberof HebrewCalendar */
hasYearZero: false,
/** The minimum month number.
@memberof HebrewCalendar */
minMonth: 1,
/** The first month in the year.
@memberof HebrewCalendar */
firstMonth: 7,
/** The minimum day number.
@memberof HebrewCalendar */
minDay: 1,
/** Localisations for the plugin.
Entries are objects indexed by the language code ('' being the default US/English).
Each object has the following attributes.
@memberof HebrewCalendar
@property name {string} The calendar name.
@property epochs {string[]} The epoch names.
@property monthNames {string[]} The long names of the months of the year.
@property monthNamesShort {string[]} The short names of the months of the year.
@property dayNames {string[]} The long names of the days of the week.
@property dayNamesShort {string[]} The short names of the days of the week.
@property dayNamesMin {string[]} The minimal names of the days of the week.
@property dateFormat {string} The date format for this calendar.
See the options on formatDate
for details.
@property firstDay {number} The number of the first day of the week, starting at 0.
@property isRTL {number} true
if this localisation reads right-to-left. */
regionalOptions: { // Localisations
'': {
name: 'Hebrew',
epochs: ['BAM', 'AM'],
monthNames: ['Nisan', 'Iyar', 'Sivan', 'Tammuz', 'Av', 'Elul',
'Tishrei', 'Cheshvan', 'Kislev', 'Tevet', 'Shevat', 'Adar', 'Adar II'],
monthNamesShort: ['Nis', 'Iya', 'Siv', 'Tam', 'Av', 'Elu', 'Tis', 'Che', 'Kis', 'Tev', 'She', 'Ada', 'Ad2'],
dayNames: ['Yom Rishon', 'Yom Sheni', 'Yom Shlishi', 'Yom Revi\'i', 'Yom Chamishi', 'Yom Shishi', 'Yom Shabbat'],
dayNamesShort: ['Ris', 'She', 'Shl', 'Rev', 'Cha', 'Shi', 'Sha'],
dayNamesMin: ['Ri','She','Shl','Re','Ch','Shi','Sha'],
digits: null,
dateFormat: 'dd/mm/yyyy',
firstDay: 0,
isRTL: false
}
},
/** Determine whether this date is in a leap year.
@memberof HebrewCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {boolean} true
if this is a leap year, false
if not.
@throws Error if an invalid year or a different calendar used. */
leapYear: function(year) {
var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
return this._leapYear(date.year());
},
/** Determine whether this date is in a leap year.
@memberof HebrewCalendar
@private
@param year {number} The year to examine.
@return {boolean} true
if this is a leap year, false
if not.
@throws Error if an invalid year or a different calendar used. */
_leapYear: function(year) {
year = (year < 0 ? year + 1 : year);
return mod(year * 7 + 1, 19) < 7;
},
/** Retrieve the number of months in a year.
@memberof HebrewCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {number} The number of months.
@throws Error if an invalid year or a different calendar used. */
monthsInYear: function(year) {
this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
return this._leapYear(year.year ? year.year() : year) ? 13 : 12;
},
/** Determine the week of the year for a date.
@memberof HebrewCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {number} The week of the year.
@throws Error if an invalid date or a different calendar used. */
weekOfYear: function(year, month, day) {
// Find Sunday of this week starting on Sunday
var checkDate = this.newDate(year, month, day);
checkDate.add(-checkDate.dayOfWeek(), 'd');
return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;
},
/** Retrieve the number of days in a year.
@memberof HebrewCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {number} The number of days.
@throws Error if an invalid year or a different calendar used. */
daysInYear: function(year) {
var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
year = date.year();
return this.toJD((year === -1 ? +1 : year + 1), 7, 1) - this.toJD(year, 7, 1);
},
/** Retrieve the number of days in a month.
@memberof HebrewCalendar
@param year {CDate|number} The date to examine or the year of the month.
@param [month] {number} The month.
@return {number} The number of days in this month.
@throws Error if an invalid month/year or a different calendar used. */
daysInMonth: function(year, month) {
if (year.year) {
month = year.month();
year = year.year();
}
this._validate(year, month, this.minDay, main.local.invalidMonth);
return (month === 12 && this.leapYear(year) ? 30 : // Adar I
(month === 8 && mod(this.daysInYear(year), 10) === 5 ? 30 : // Cheshvan in shlemah year
(month === 9 && mod(this.daysInYear(year), 10) === 3 ? 29 : // Kislev in chaserah year
this.daysPerMonth[month - 1])));
},
/** Determine whether this date is a week day.
@memberof HebrewCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {boolean} true
if a week day, false
if not.
@throws Error if an invalid date or a different calendar used. */
weekDay: function(year, month, day) {
return this.dayOfWeek(year, month, day) !== 6;
},
/** Retrieve additional information about a date - year type.
@memberof HebrewCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {object} Additional information - contents depends on calendar.
@throws Error if an invalid date or a different calendar used. */
extraInfo: function(year, month, day) {
var date = this._validate(year, month, day, main.local.invalidDate);
return {yearType: (this.leapYear(date) ? 'embolismic' : 'common') + ' ' +
['deficient', 'regular', 'complete'][this.daysInYear(date) % 10 - 3]};
},
/** Retrieve the Julian date equivalent for this date,
i.e. days since January 1, 4713 BCE Greenwich noon.
@memberof HebrewCalendar
@param year {CDate)|number} The date to convert or the year to convert.
@param [month] {number} The month to convert.
@param [day] {number} The day to convert.
@return {number} The equivalent Julian date.
@throws Error if an invalid date or a different calendar used. */
toJD: function(year, month, day) {
var date = this._validate(year, month, day, main.local.invalidDate);
year = date.year();
month = date.month();
day = date.day();
var adjYear = (year <= 0 ? year + 1 : year);
var jd = this.jdEpoch + this._delay1(adjYear) +
this._delay2(adjYear) + day + 1;
if (month < 7) {
for (var m = 7; m <= this.monthsInYear(year); m++) {
jd += this.daysInMonth(year, m);
}
for (var m = 1; m < month; m++) {
jd += this.daysInMonth(year, m);
}
}
else {
for (var m = 7; m < month; m++) {
jd += this.daysInMonth(year, m);
}
}
return jd;
},
/** Test for delay of start of new year and to avoid
Sunday, Wednesday, or Friday as start of the new year.
@memberof HebrewCalendar
@private
@param year {number} The year to examine.
@return {number} The days to offset by. */
_delay1: function(year) {
var months = Math.floor((235 * year - 234) / 19);
var parts = 12084 + 13753 * months;
var day = months * 29 + Math.floor(parts / 25920);
if (mod(3 * (day + 1), 7) < 3) {
day++;
}
return day;
},
/** Check for delay in start of new year due to length of adjacent years.
@memberof HebrewCalendar
@private
@param year {number} The year to examine.
@return {number} The days to offset by. */
_delay2: function(year) {
var last = this._delay1(year - 1);
var present = this._delay1(year);
var next = this._delay1(year + 1);
return ((next - present) === 356 ? 2 : ((present - last) === 382 ? 1 : 0));
},
/** Create a new date from a Julian date.
@memberof HebrewCalendar
@param jd {number} The Julian date to convert.
@return {CDate} The equivalent date. */
fromJD: function(jd) {
jd = Math.floor(jd) + 0.5;
var year = Math.floor(((jd - this.jdEpoch) * 98496.0) / 35975351.0) - 1;
while (jd >= this.toJD((year === -1 ? +1 : year + 1), 7, 1)) {
year++;
}
var month = (jd < this.toJD(year, 1, 1)) ? 7 : 1;
while (jd > this.toJD(year, month, this.daysInMonth(year, month))) {
month++;
}
var day = jd - this.toJD(year, month, 1) + 1;
return this.newDate(year, month, day);
}
});
// Modulus function which works for non-integers.
function mod(a, b) {
return a - (b * Math.floor(a / b));
}
// Hebrew calendar implementation
main.calendars.hebrew = HebrewCalendar;
/***/ }),
/***/ 6368:
/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
/*
* World Calendars
* https://github.com/alexcjohnson/world-calendars
*
* Batch-converted from kbwood/calendars
* Many thanks to Keith Wood and all of the contributors to the original project!
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* http://keith-wood.name/calendars.html
Islamic calendar for jQuery v2.0.2.
Written by Keith Wood (wood.keith{at}optusnet.com.au) August 2009.
Available under the MIT (http://keith-wood.name/licence.html) license.
Please attribute the author if you use it. */
var main = __webpack_require__(8700);
var assign = __webpack_require__(896);
/** Implementation of the Islamic or '16 civil' calendar.
Based on code from http://www.iranchamber.com/calendar/converter/iranian_calendar_converter.php.
See also http://en.wikipedia.org/wiki/Islamic_calendar.
@class IslamicCalendar
@param [language=''] {string} The language code (default English) for localisation. */
function IslamicCalendar(language) {
this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];
}
IslamicCalendar.prototype = new main.baseCalendar;
assign(IslamicCalendar.prototype, {
/** The calendar name.
@memberof IslamicCalendar */
name: 'Islamic',
/** Julian date of start of Islamic epoch: 16 July 622 CE.
@memberof IslamicCalendar */
jdEpoch: 1948439.5,
/** Days per month in a common year.
@memberof IslamicCalendar */
daysPerMonth: [30, 29, 30, 29, 30, 29, 30, 29, 30, 29, 30, 29],
/** true
if has a year zero, false
if not.
@memberof IslamicCalendar */
hasYearZero: false,
/** The minimum month number.
@memberof IslamicCalendar */
minMonth: 1,
/** The first month in the year.
@memberof IslamicCalendar */
firstMonth: 1,
/** The minimum day number.
@memberof IslamicCalendar */
minDay: 1,
/** Localisations for the plugin.
Entries are objects indexed by the language code ('' being the default US/English).
Each object has the following attributes.
@memberof IslamicCalendar
@property name {string} The calendar name.
@property epochs {string[]} The epoch names.
@property monthNames {string[]} The long names of the months of the year.
@property monthNamesShort {string[]} The short names of the months of the year.
@property dayNames {string[]} The long names of the days of the week.
@property dayNamesShort {string[]} The short names of the days of the week.
@property dayNamesMin {string[]} The minimal names of the days of the week.
@property dateFormat {string} The date format for this calendar.
See the options on formatDate
for details.
@property firstDay {number} The number of the first day of the week, starting at 0.
@property isRTL {number} true
if this localisation reads right-to-left. */
regionalOptions: { // Localisations
'': {
name: 'Islamic',
epochs: ['BH', 'AH'],
monthNames: ['Muharram', 'Safar', 'Rabi\' al-awwal', 'Rabi\' al-thani', 'Jumada al-awwal', 'Jumada al-thani',
'Rajab', 'Sha\'aban', 'Ramadan', 'Shawwal', 'Dhu al-Qi\'dah', 'Dhu al-Hijjah'],
monthNamesShort: ['Muh', 'Saf', 'Rab1', 'Rab2', 'Jum1', 'Jum2', 'Raj', 'Sha\'', 'Ram', 'Shaw', 'DhuQ', 'DhuH'],
dayNames: ['Yawm al-ahad', 'Yawm al-ithnayn', 'Yawm ath-thulaathaa\'',
'Yawm al-arbi\'aa\'', 'Yawm al-khamīs', 'Yawm al-jum\'a', 'Yawm as-sabt'],
dayNamesShort: ['Aha', 'Ith', 'Thu', 'Arb', 'Kha', 'Jum', 'Sab'],
dayNamesMin: ['Ah','It','Th','Ar','Kh','Ju','Sa'],
digits: null,
dateFormat: 'yyyy/mm/dd',
firstDay: 6,
isRTL: false
}
},
/** Determine whether this date is in a leap year.
@memberof IslamicCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {boolean} true
if this is a leap year, false
if not.
@throws Error if an invalid year or a different calendar used. */
leapYear: function(year) {
var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
return (date.year() * 11 + 14) % 30 < 11;
},
/** Determine the week of the year for a date.
@memberof IslamicCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {number} The week of the year.
@throws Error if an invalid date or a different calendar used. */
weekOfYear: function(year, month, day) {
// Find Sunday of this week starting on Sunday
var checkDate = this.newDate(year, month, day);
checkDate.add(-checkDate.dayOfWeek(), 'd');
return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;
},
/** Retrieve the number of days in a year.
@memberof IslamicCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {number} The number of days.
@throws Error if an invalid year or a different calendar used. */
daysInYear: function(year) {
return (this.leapYear(year) ? 355 : 354);
},
/** Retrieve the number of days in a month.
@memberof IslamicCalendar
@param year {CDate|number} The date to examine or the year of the month.
@param [month] {number} The month.
@return {number} The number of days in this month.
@throws Error if an invalid month/year or a different calendar used. */
daysInMonth: function(year, month) {
var date = this._validate(year, month, this.minDay, main.local.invalidMonth);
return this.daysPerMonth[date.month() - 1] +
(date.month() === 12 && this.leapYear(date.year()) ? 1 : 0);
},
/** Determine whether this date is a week day.
@memberof IslamicCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {boolean} true
if a week day, false
if not.
@throws Error if an invalid date or a different calendar used. */
weekDay: function(year, month, day) {
return this.dayOfWeek(year, month, day) !== 5;
},
/** Retrieve the Julian date equivalent for this date,
i.e. days since January 1, 4713 BCE Greenwich noon.
@memberof IslamicCalendar
@param year {CDate|number} The date to convert or the year to convert.
@param [month] {number} The month to convert.
@param [day] {number} The day to convert.
@return {number} The equivalent Julian date.
@throws Error if an invalid date or a different calendar used. */
toJD: function(year, month, day) {
var date = this._validate(year, month, day, main.local.invalidDate);
year = date.year();
month = date.month();
day = date.day();
year = (year <= 0 ? year + 1 : year);
return day + Math.ceil(29.5 * (month - 1)) + (year - 1) * 354 +
Math.floor((3 + (11 * year)) / 30) + this.jdEpoch - 1;
},
/** Create a new date from a Julian date.
@memberof IslamicCalendar
@param jd {number} The Julian date to convert.
@return {CDate} The equivalent date. */
fromJD: function(jd) {
jd = Math.floor(jd) + 0.5;
var year = Math.floor((30 * (jd - this.jdEpoch) + 10646) / 10631);
year = (year <= 0 ? year - 1 : year);
var month = Math.min(12, Math.ceil((jd - 29 - this.toJD(year, 1, 1)) / 29.5) + 1);
var day = jd - this.toJD(year, month, 1) + 1;
return this.newDate(year, month, day);
}
});
// Islamic (16 civil) calendar implementation
main.calendars.islamic = IslamicCalendar;
/***/ }),
/***/ 4747:
/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
/*
* World Calendars
* https://github.com/alexcjohnson/world-calendars
*
* Batch-converted from kbwood/calendars
* Many thanks to Keith Wood and all of the contributors to the original project!
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* http://keith-wood.name/calendars.html
Julian calendar for jQuery v2.0.2.
Written by Keith Wood (wood.keith{at}optusnet.com.au) August 2009.
Available under the MIT (http://keith-wood.name/licence.html) license.
Please attribute the author if you use it. */
var main = __webpack_require__(8700);
var assign = __webpack_require__(896);
/** Implementation of the Julian calendar.
Based on code from http://www.fourmilab.ch/documents/calendar/.
See also http://en.wikipedia.org/wiki/Julian_calendar.
@class JulianCalendar
@augments BaseCalendar
@param [language=''] {string} The language code (default English) for localisation. */
function JulianCalendar(language) {
this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];
}
JulianCalendar.prototype = new main.baseCalendar;
assign(JulianCalendar.prototype, {
/** The calendar name.
@memberof JulianCalendar */
name: 'Julian',
/** Julian date of start of Julian epoch: 1 January 0001 AD = 30 December 0001 BCE.
@memberof JulianCalendar */
jdEpoch: 1721423.5,
/** Days per month in a common year.
@memberof JulianCalendar */
daysPerMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
/** true
if has a year zero, false
if not.
@memberof JulianCalendar */
hasYearZero: false,
/** The minimum month number.
@memberof JulianCalendar */
minMonth: 1,
/** The first month in the year.
@memberof JulianCalendar */
firstMonth: 1,
/** The minimum day number.
@memberof JulianCalendar */
minDay: 1,
/** Localisations for the plugin.
Entries are objects indexed by the language code ('' being the default US/English).
Each object has the following attributes.
@memberof JulianCalendar
@property name {string} The calendar name.
@property epochs {string[]} The epoch names.
@property monthNames {string[]} The long names of the months of the year.
@property monthNamesShort {string[]} The short names of the months of the year.
@property dayNames {string[]} The long names of the days of the week.
@property dayNamesShort {string[]} The short names of the days of the week.
@property dayNamesMin {string[]} The minimal names of the days of the week.
@property dateFormat {string} The date format for this calendar.
See the options on formatDate
for details.
@property firstDay {number} The number of the first day of the week, starting at 0.
@property isRTL {number} true
if this localisation reads right-to-left. */
regionalOptions: { // Localisations
'': {
name: 'Julian',
epochs: ['BC', 'AD'],
monthNames: ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'],
monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
dayNamesMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
digits: null,
dateFormat: 'mm/dd/yyyy',
firstDay: 0,
isRTL: false
}
},
/** Determine whether this date is in a leap year.
@memberof JulianCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {boolean} true
if this is a leap year, false
if not.
@throws Error if an invalid year or a different calendar used. */
leapYear: function(year) {
var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
var year = (date.year() < 0 ? date.year() + 1 : date.year()); // No year zero
return (year % 4) === 0;
},
/** Determine the week of the year for a date - ISO 8601.
@memberof JulianCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {number} The week of the year.
@throws Error if an invalid date or a different calendar used. */
weekOfYear: function(year, month, day) {
// Find Thursday of this week starting on Monday
var checkDate = this.newDate(year, month, day);
checkDate.add(4 - (checkDate.dayOfWeek() || 7), 'd');
return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;
},
/** Retrieve the number of days in a month.
@memberof JulianCalendar
@param year {CDate|number} The date to examine or the year of the month.
@param [month] {number} The month.
@return {number} The number of days in this month.
@throws Error if an invalid month/year or a different calendar used. */
daysInMonth: function(year, month) {
var date = this._validate(year, month, this.minDay, main.local.invalidMonth);
return this.daysPerMonth[date.month() - 1] +
(date.month() === 2 && this.leapYear(date.year()) ? 1 : 0);
},
/** Determine whether this date is a week day.
@memberof JulianCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {boolean} True if a week day, false if not.
@throws Error if an invalid date or a different calendar used. */
weekDay: function(year, month, day) {
return (this.dayOfWeek(year, month, day) || 7) < 6;
},
/** Retrieve the Julian date equivalent for this date,
i.e. days since January 1, 4713 BCE Greenwich noon.
@memberof JulianCalendar
@param year {CDate|number} The date to convert or the year to convert.
@param [month] {number} The month to convert.
@param [day] {number} The day to convert.
@return {number} The equivalent Julian date.
@throws Error if an invalid date or a different calendar used. */
toJD: function(year, month, day) {
var date = this._validate(year, month, day, main.local.invalidDate);
year = date.year();
month = date.month();
day = date.day();
if (year < 0) { year++; } // No year zero
// Jean Meeus algorithm, "Astronomical Algorithms", 1991
if (month <= 2) {
year--;
month += 12;
}
return Math.floor(365.25 * (year + 4716)) +
Math.floor(30.6001 * (month + 1)) + day - 1524.5;
},
/** Create a new date from a Julian date.
@memberof JulianCalendar
@param jd {number} The Julian date to convert.
@return {CDate} The equivalent date. */
fromJD: function(jd) {
// Jean Meeus algorithm, "Astronomical Algorithms", 1991
var a = Math.floor(jd + 0.5);
var b = a + 1524;
var c = Math.floor((b - 122.1) / 365.25);
var d = Math.floor(365.25 * c);
var e = Math.floor((b - d) / 30.6001);
var month = e - Math.floor(e < 14 ? 1 : 13);
var year = c - Math.floor(month > 2 ? 4716 : 4715);
var day = b - d - Math.floor(30.6001 * e);
if (year <= 0) { year--; } // No year zero
return this.newDate(year, month, day);
}
});
// Julian calendar implementation
main.calendars.julian = JulianCalendar;
/***/ }),
/***/ 5616:
/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
/*
* World Calendars
* https://github.com/alexcjohnson/world-calendars
*
* Batch-converted from kbwood/calendars
* Many thanks to Keith Wood and all of the contributors to the original project!
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* http://keith-wood.name/calendars.html
Mayan calendar for jQuery v2.0.2.
Written by Keith Wood (wood.keith{at}optusnet.com.au) August 2009.
Available under the MIT (http://keith-wood.name/licence.html) license.
Please attribute the author if you use it. */
var main = __webpack_require__(8700);
var assign = __webpack_require__(896);
/** Implementation of the Mayan Long Count calendar.
See also http://en.wikipedia.org/wiki/Mayan_calendar.
@class MayanCalendar
@param [language=''] {string} The language code (default English) for localisation. */
function MayanCalendar(language) {
this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];
}
MayanCalendar.prototype = new main.baseCalendar;
assign(MayanCalendar.prototype, {
/** The calendar name.
@memberof MayanCalendar */
name: 'Mayan',
/** Julian date of start of Mayan epoch: 11 August 3114 BCE.
@memberof MayanCalendar */
jdEpoch: 584282.5,
/** true
if has a year zero, false
if not.
@memberof MayanCalendar */
hasYearZero: true,
/** The minimum month number.
@memberof MayanCalendar */
minMonth: 0,
/** The first month in the year.
@memberof MayanCalendar */
firstMonth: 0,
/** The minimum day number.
@memberof MayanCalendar */
minDay: 0,
/** Localisations for the plugin.
Entries are objects indexed by the language code ('' being the default US/English).
Each object has the following attributes.
@memberof MayanCalendar
@property name {string} The calendar name.
@property epochs {string[]} The epoch names.
@property monthNames {string[]} The long names of the months of the year.
@property monthNamesShort {string[]} The short names of the months of the year.
@property dayNames {string[]} The long names of the days of the week.
@property dayNamesShort {string[]} The short names of the days of the week.
@property dayNamesMin {string[]} The minimal names of the days of the week.
@property dateFormat {string} The date format for this calendar.
See the options on formatDate
for details.
@property firstDay {number} The number of the first day of the week, starting at 0.
@property isRTL {number} true
if this localisation reads right-to-left.
@property haabMonths {string[]} The names of the Haab months.
@property tzolkinMonths {string[]} The names of the Tzolkin months. */
regionalOptions: { // Localisations
'': {
name: 'Mayan',
epochs: ['', ''],
monthNames: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'10', '11', '12', '13', '14', '15', '16', '17'],
monthNamesShort: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'10', '11', '12', '13', '14', '15', '16', '17'],
dayNames: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'10', '11', '12', '13', '14', '15', '16', '17', '18', '19'],
dayNamesShort: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'10', '11', '12', '13', '14', '15', '16', '17', '18', '19'],
dayNamesMin: ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
'10', '11', '12', '13', '14', '15', '16', '17', '18', '19'],
digits: null,
dateFormat: 'YYYY.m.d',
firstDay: 0,
isRTL: false,
haabMonths: ['Pop', 'Uo', 'Zip', 'Zotz', 'Tzec', 'Xul', 'Yaxkin', 'Mol', 'Chen', 'Yax',
'Zac', 'Ceh', 'Mac', 'Kankin', 'Muan', 'Pax', 'Kayab', 'Cumku', 'Uayeb'],
tzolkinMonths: ['Imix', 'Ik', 'Akbal', 'Kan', 'Chicchan', 'Cimi', 'Manik', 'Lamat', 'Muluc', 'Oc',
'Chuen', 'Eb', 'Ben', 'Ix', 'Men', 'Cib', 'Caban', 'Etznab', 'Cauac', 'Ahau']
}
},
/** Determine whether this date is in a leap year.
@memberof MayanCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {boolean} true
if this is a leap year, false
if not.
@throws Error if an invalid year or a different calendar used. */
leapYear: function(year) {
this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
return false;
},
/** Format the year, if not a simple sequential number.
@memberof MayanCalendar
@param year {CDate|number} The date to format or the year to format.
@return {string} The formatted year.
@throws Error if an invalid year or a different calendar used. */
formatYear: function(year) {
var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
year = date.year();
var baktun = Math.floor(year / 400);
year = year % 400;
year += (year < 0 ? 400 : 0);
var katun = Math.floor(year / 20);
return baktun + '.' + katun + '.' + (year % 20);
},
/** Convert from the formatted year back to a single number.
@memberof MayanCalendar
@param years {string} The year as n.n.n.
@return {number} The sequential year.
@throws Error if an invalid value is supplied. */
forYear: function(years) {
years = years.split('.');
if (years.length < 3) {
throw 'Invalid Mayan year';
}
var year = 0;
for (var i = 0; i < years.length; i++) {
var y = parseInt(years[i], 10);
if (Math.abs(y) > 19 || (i > 0 && y < 0)) {
throw 'Invalid Mayan year';
}
year = year * 20 + y;
}
return year;
},
/** Retrieve the number of months in a year.
@memberof MayanCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {number} The number of months.
@throws Error if an invalid year or a different calendar used. */
monthsInYear: function(year) {
this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
return 18;
},
/** Determine the week of the year for a date.
@memberof MayanCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {number} The week of the year.
@throws Error if an invalid date or a different calendar used. */
weekOfYear: function(year, month, day) {
this._validate(year, month, day, main.local.invalidDate);
return 0;
},
/** Retrieve the number of days in a year.
@memberof MayanCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {number} The number of days.
@throws Error if an invalid year or a different calendar used. */
daysInYear: function(year) {
this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
return 360;
},
/** Retrieve the number of days in a month.
@memberof MayanCalendar
@param year {CDate|number} The date to examine or the year of the month.
@param [month] {number} The month.
@return {number} The number of days in this month.
@throws Error if an invalid month/year or a different calendar used. */
daysInMonth: function(year, month) {
this._validate(year, month, this.minDay, main.local.invalidMonth);
return 20;
},
/** Retrieve the number of days in a week.
@memberof MayanCalendar
@return {number} The number of days. */
daysInWeek: function() {
return 5; // Just for formatting
},
/** Retrieve the day of the week for a date.
@memberof MayanCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {number} The day of the week: 0 to number of days - 1.
@throws Error if an invalid date or a different calendar used. */
dayOfWeek: function(year, month, day) {
var date = this._validate(year, month, day, main.local.invalidDate);
return date.day();
},
/** Determine whether this date is a week day.
@memberof MayanCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {boolean} true
if a week day, false
if not.
@throws Error if an invalid date or a different calendar used. */
weekDay: function(year, month, day) {
this._validate(year, month, day, main.local.invalidDate);
return true;
},
/** Retrieve additional information about a date - Haab and Tzolkin equivalents.
@memberof MayanCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {object} Additional information - contents depends on calendar.
@throws Error if an invalid date or a different calendar used. */
extraInfo: function(year, month, day) {
var date = this._validate(year, month, day, main.local.invalidDate);
var jd = date.toJD();
var haab = this._toHaab(jd);
var tzolkin = this._toTzolkin(jd);
return {haabMonthName: this.local.haabMonths[haab[0] - 1],
haabMonth: haab[0], haabDay: haab[1],
tzolkinDayName: this.local.tzolkinMonths[tzolkin[0] - 1],
tzolkinDay: tzolkin[0], tzolkinTrecena: tzolkin[1]};
},
/** Retrieve Haab date from a Julian date.
@memberof MayanCalendar
@private
@param jd {number} The Julian date.
@return {number[]} Corresponding Haab month and day. */
_toHaab: function(jd) {
jd -= this.jdEpoch;
var day = mod(jd + 8 + ((18 - 1) * 20), 365);
return [Math.floor(day / 20) + 1, mod(day, 20)];
},
/** Retrieve Tzolkin date from a Julian date.
@memberof MayanCalendar
@private
@param jd {number} The Julian date.
@return {number[]} Corresponding Tzolkin day and trecena. */
_toTzolkin: function(jd) {
jd -= this.jdEpoch;
return [amod(jd + 20, 20), amod(jd + 4, 13)];
},
/** Retrieve the Julian date equivalent for this date,
i.e. days since January 1, 4713 BCE Greenwich noon.
@memberof MayanCalendar
@param year {CDate|number} The date to convert or the year to convert.
@param [month] {number} The month to convert.
@param [day] {number} The day to convert.
@return {number} The equivalent Julian date.
@throws Error if an invalid date or a different calendar used. */
toJD: function(year, month, day) {
var date = this._validate(year, month, day, main.local.invalidDate);
return date.day() + (date.month() * 20) + (date.year() * 360) + this.jdEpoch;
},
/** Create a new date from a Julian date.
@memberof MayanCalendar
@param jd {number} The Julian date to convert.
@return {CDate} The equivalent date. */
fromJD: function(jd) {
jd = Math.floor(jd) + 0.5 - this.jdEpoch;
var year = Math.floor(jd / 360);
jd = jd % 360;
jd += (jd < 0 ? 360 : 0);
var month = Math.floor(jd / 20);
var day = jd % 20;
return this.newDate(year, month, day);
}
});
// Modulus function which works for non-integers.
function mod(a, b) {
return a - (b * Math.floor(a / b));
}
// Modulus function which returns numerator if modulus is zero.
function amod(a, b) {
return mod(a - 1, b) + 1;
}
// Mayan calendar implementation
main.calendars.mayan = MayanCalendar;
/***/ }),
/***/ 632:
/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
/*
* World Calendars
* https://github.com/alexcjohnson/world-calendars
*
* Batch-converted from kbwood/calendars
* Many thanks to Keith Wood and all of the contributors to the original project!
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* http://keith-wood.name/calendars.html
Nanakshahi calendar for jQuery v2.0.2.
Written by Keith Wood (wood.keith{at}optusnet.com.au) January 2016.
Available under the MIT (http://keith-wood.name/licence.html) license.
Please attribute the author if you use it. */
var main = __webpack_require__(8700);
var assign = __webpack_require__(896);
/** Implementation of the Nanakshahi calendar.
See also https://en.wikipedia.org/wiki/Nanakshahi_calendar.
@class NanakshahiCalendar
@param [language=''] {string} The language code (default English) for localisation. */
function NanakshahiCalendar(language) {
this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];
}
NanakshahiCalendar.prototype = new main.baseCalendar;
var gregorian = main.instance('gregorian');
assign(NanakshahiCalendar.prototype, {
/** The calendar name.
@memberof NanakshahiCalendar */
name: 'Nanakshahi',
/** Julian date of start of Nanakshahi epoch: 14 March 1469 CE.
@memberof NanakshahiCalendar */
jdEpoch: 2257673.5,
/** Days per month in a common year.
@memberof NanakshahiCalendar */
daysPerMonth: [31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 30, 30],
/** true
if has a year zero, false
if not.
@memberof NanakshahiCalendar */
hasYearZero: false,
/** The minimum month number.
@memberof NanakshahiCalendar */
minMonth: 1,
/** The first month in the year.
@memberof NanakshahiCalendar */
firstMonth: 1,
/** The minimum day number.
@memberof NanakshahiCalendar */
minDay: 1,
/** Localisations for the plugin.
Entries are objects indexed by the language code ('' being the default US/English).
Each object has the following attributes.
@memberof NanakshahiCalendar
@property name {string} The calendar name.
@property epochs {string[]} The epoch names.
@property monthNames {string[]} The long names of the months of the year.
@property monthNamesShort {string[]} The short names of the months of the year.
@property dayNames {string[]} The long names of the days of the week.
@property dayNamesShort {string[]} The short names of the days of the week.
@property dayNamesMin {string[]} The minimal names of the days of the week.
@property dateFormat {string} The date format for this calendar.
See the options on formatDate
for details.
@property firstDay {number} The number of the first day of the week, starting at 0.
@property isRTL {number} true
if this localisation reads right-to-left. */
regionalOptions: { // Localisations
'': {
name: 'Nanakshahi',
epochs: ['BN', 'AN'],
monthNames: ['Chet', 'Vaisakh', 'Jeth', 'Harh', 'Sawan', 'Bhadon',
'Assu', 'Katak', 'Maghar', 'Poh', 'Magh', 'Phagun'],
monthNamesShort: ['Che', 'Vai', 'Jet', 'Har', 'Saw', 'Bha', 'Ass', 'Kat', 'Mgr', 'Poh', 'Mgh', 'Pha'],
dayNames: ['Somvaar', 'Mangalvar', 'Budhvaar', 'Veervaar', 'Shukarvaar', 'Sanicharvaar', 'Etvaar'],
dayNamesShort: ['Som', 'Mangal', 'Budh', 'Veer', 'Shukar', 'Sanichar', 'Et'],
dayNamesMin: ['So', 'Ma', 'Bu', 'Ve', 'Sh', 'Sa', 'Et'],
digits: null,
dateFormat: 'dd-mm-yyyy',
firstDay: 0,
isRTL: false
}
},
/** Determine whether this date is in a leap year.
@memberof NanakshahiCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {boolean} true
if this is a leap year, false
if not.
@throws Error if an invalid year or a different calendar used. */
leapYear: function(year) {
var date = this._validate(year, this.minMonth, this.minDay,
main.local.invalidYear || main.regionalOptions[''].invalidYear);
return gregorian.leapYear(date.year() + (date.year() < 1 ? 1 : 0) + 1469);
},
/** Determine the week of the year for a date.
@memberof NanakshahiCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {number} The week of the year.
@throws Error if an invalid date or a different calendar used. */
weekOfYear: function(year, month, day) {
// Find Monday of this week starting on Monday
var checkDate = this.newDate(year, month, day);
checkDate.add(1 - (checkDate.dayOfWeek() || 7), 'd');
return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;
},
/** Retrieve the number of days in a month.
@memberof NanakshahiCalendar
@param year {CDate|number} The date to examine or the year of the month.
@param [month] {number} The month.
@return {number} The number of days in this month.
@throws Error if an invalid month/year or a different calendar used. */
daysInMonth: function(year, month) {
var date = this._validate(year, month, this.minDay, main.local.invalidMonth);
return this.daysPerMonth[date.month() - 1] +
(date.month() === 12 && this.leapYear(date.year()) ? 1 : 0);
},
/** Determine whether this date is a week day.
@memberof NanakshahiCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {boolean} true
if a week day, false
if not.
@throws Error if an invalid date or a different calendar used. */
weekDay: function(year, month, day) {
return (this.dayOfWeek(year, month, day) || 7) < 6;
},
/** Retrieve the Julian date equivalent for this date,
i.e. days since January 1, 4713 BCE Greenwich noon.
@memberof NanakshahiCalendar
@param year {CDate|number} The date to convert or the year to convert.
@param [month] {number} The month to convert.
@param [day] {number} The day to convert.
@return {number} The equivalent Julian date.
@throws Error if an invalid date or a different calendar used. */
toJD: function(year, month, day) {
var date = this._validate(year, month, day, main.local.invalidMonth);
var year = date.year();
if (year < 0) { year++; } // No year zero
var doy = date.day();
for (var m = 1; m < date.month(); m++) {
doy += this.daysPerMonth[m - 1];
}
return doy + gregorian.toJD(year + 1468, 3, 13);
},
/** Create a new date from a Julian date.
@memberof NanakshahiCalendar
@param jd {number} The Julian date to convert.
@return {CDate} The equivalent date. */
fromJD: function(jd) {
jd = Math.floor(jd + 0.5);
var year = Math.floor((jd - (this.jdEpoch - 1)) / 366);
while (jd >= this.toJD(year + 1, 1, 1)) {
year++;
}
var day = jd - Math.floor(this.toJD(year, 1, 1) + 0.5) + 1;
var month = 1;
while (day > this.daysInMonth(year, month)) {
day -= this.daysInMonth(year, month);
month++;
}
return this.newDate(year, month, day);
}
});
// Nanakshahi calendar implementation
main.calendars.nanakshahi = NanakshahiCalendar;
/***/ }),
/***/ 3040:
/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
/*
* World Calendars
* https://github.com/alexcjohnson/world-calendars
*
* Batch-converted from kbwood/calendars
* Many thanks to Keith Wood and all of the contributors to the original project!
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* http://keith-wood.name/calendars.html
Nepali calendar for jQuery v2.0.2.
Written by Artur Neumann (ict.projects{at}nepal.inf.org) April 2013.
Available under the MIT (http://keith-wood.name/licence.html) license.
Please attribute the author if you use it. */
var main = __webpack_require__(8700);
var assign = __webpack_require__(896);
/** Implementation of the Nepali civil calendar.
Based on the ideas from
http://codeissue.com/articles/a04e050dea7468f/algorithm-to-convert-english-date-to-nepali-date-using-c-net
and http://birenj2ee.blogspot.com/2011/04/nepali-calendar-in-java.html
See also http://en.wikipedia.org/wiki/Nepali_calendar
and https://en.wikipedia.org/wiki/Bikram_Samwat.
@class NepaliCalendar
@param [language=''] {string} The language code (default English) for localisation. */
function NepaliCalendar(language) {
this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];
}
NepaliCalendar.prototype = new main.baseCalendar;
assign(NepaliCalendar.prototype, {
/** The calendar name.
@memberof NepaliCalendar */
name: 'Nepali',
/** Julian date of start of Nepali epoch: 14 April 57 BCE.
@memberof NepaliCalendar */
jdEpoch: 1700709.5,
/** Days per month in a common year.
@memberof NepaliCalendar */
daysPerMonth: [31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
/** true
if has a year zero, false
if not.
@memberof NepaliCalendar */
hasYearZero: false,
/** The minimum month number.
@memberof NepaliCalendar */
minMonth: 1,
/** The first month in the year.
@memberof NepaliCalendar */
firstMonth: 1,
/** The minimum day number.
@memberof NepaliCalendar */
minDay: 1,
/** The number of days in the year.
@memberof NepaliCalendar */
daysPerYear: 365,
/** Localisations for the plugin.
Entries are objects indexed by the language code ('' being the default US/English).
Each object has the following attributes.
@memberof NepaliCalendar
@property name {string} The calendar name.
@property epochs {string[]} The epoch names.
@property monthNames {string[]} The long names of the months of the year.
@property monthNamesShort {string[]} The short names of the months of the year.
@property dayNames {string[]} The long names of the days of the week.
@property dayNamesShort {string[]} The short names of the days of the week.
@property dayNamesMin {string[]} The minimal names of the days of the week.
@property dateFormat {string} The date format for this calendar.
See the options on formatDate
for details.
@property firstDay {number} The number of the first day of the week, starting at 0.
@property isRTL {number} true
if this localisation reads right-to-left. */
regionalOptions: { // Localisations
'': {
name: 'Nepali',
epochs: ['BBS', 'ABS'],
monthNames: ['Baisakh', 'Jestha', 'Ashadh', 'Shrawan', 'Bhadra', 'Ashwin',
'Kartik', 'Mangsir', 'Paush', 'Mangh', 'Falgun', 'Chaitra'],
monthNamesShort: ['Bai', 'Je', 'As', 'Shra', 'Bha', 'Ash', 'Kar', 'Mang', 'Pau', 'Ma', 'Fal', 'Chai'],
dayNames: ['Aaitabaar', 'Sombaar', 'Manglbaar', 'Budhabaar', 'Bihibaar', 'Shukrabaar', 'Shanibaar'],
dayNamesShort: ['Aaita', 'Som', 'Mangl', 'Budha', 'Bihi', 'Shukra', 'Shani'],
dayNamesMin: ['Aai', 'So', 'Man', 'Bu', 'Bi', 'Shu', 'Sha'],
digits: null,
dateFormat: 'dd/mm/yyyy',
firstDay: 1,
isRTL: false
}
},
/** Determine whether this date is in a leap year.
@memberof NepaliCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {boolean} true
if this is a leap year, false
if not.
@throws Error if an invalid year or a different calendar used. */
leapYear: function(year) {
return this.daysInYear(year) !== this.daysPerYear;
},
/** Determine the week of the year for a date.
@memberof NepaliCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {number} The week of the year.
@throws Error if an invalid date or a different calendar used. */
weekOfYear: function(year, month, day) {
// Find Sunday of this week starting on Sunday
var checkDate = this.newDate(year, month, day);
checkDate.add(-checkDate.dayOfWeek(), 'd');
return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;
},
/** Retrieve the number of days in a year.
@memberof NepaliCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {number} The number of days.
@throws Error if an invalid year or a different calendar used. */
daysInYear: function(year) {
var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
year = date.year();
if (typeof this.NEPALI_CALENDAR_DATA[year] === 'undefined') {
return this.daysPerYear;
}
var daysPerYear = 0;
for (var month_number = this.minMonth; month_number <= 12; month_number++) {
daysPerYear += this.NEPALI_CALENDAR_DATA[year][month_number];
}
return daysPerYear;
},
/** Retrieve the number of days in a month.
@memberof NepaliCalendar
@param year {CDate|number| The date to examine or the year of the month.
@param [month] {number} The month.
@return {number} The number of days in this month.
@throws Error if an invalid month/year or a different calendar used. */
daysInMonth: function(year, month) {
if (year.year) {
month = year.month();
year = year.year();
}
this._validate(year, month, this.minDay, main.local.invalidMonth);
return (typeof this.NEPALI_CALENDAR_DATA[year] === 'undefined' ?
this.daysPerMonth[month - 1] : this.NEPALI_CALENDAR_DATA[year][month]);
},
/** Determine whether this date is a week day.
@memberof NepaliCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {boolean} true
if a week day, false
if not.
@throws Error if an invalid date or a different calendar used. */
weekDay: function(year, month, day) {
return this.dayOfWeek(year, month, day) !== 6;
},
/** Retrieve the Julian date equivalent for this date,
i.e. days since January 1, 4713 BCE Greenwich noon.
@memberof NepaliCalendar
@param year {CDate|number} The date to convert or the year to convert.
@param [month] {number} The month to convert.
@param [day] {number} The day to convert.
@return {number} The equivalent Julian date.
@throws Error if an invalid date or a different calendar used. */
toJD: function(nepaliYear, nepaliMonth, nepaliDay) {
var date = this._validate(nepaliYear, nepaliMonth, nepaliDay, main.local.invalidDate);
nepaliYear = date.year();
nepaliMonth = date.month();
nepaliDay = date.day();
var gregorianCalendar = main.instance();
var gregorianDayOfYear = 0; // We will add all the days that went by since
// the 1st. January and then we can get the Gregorian Date
var nepaliMonthToCheck = nepaliMonth;
var nepaliYearToCheck = nepaliYear;
this._createMissingCalendarData(nepaliYear);
// Get the correct year
var gregorianYear = nepaliYear - (nepaliMonthToCheck > 9 || (nepaliMonthToCheck === 9 &&
nepaliDay >= this.NEPALI_CALENDAR_DATA[nepaliYearToCheck][0]) ? 56 : 57);
// First we add the amount of days in the actual Nepali month as the day of year in the
// Gregorian one because at least this days are gone since the 1st. Jan.
if (nepaliMonth !== 9) {
gregorianDayOfYear = nepaliDay;
nepaliMonthToCheck--;
}
// Now we loop throw all Nepali month and add the amount of days to gregorianDayOfYear
// we do this till we reach Paush (9th month). 1st. January always falls in this month
while (nepaliMonthToCheck !== 9) {
if (nepaliMonthToCheck <= 0) {
nepaliMonthToCheck = 12;
nepaliYearToCheck--;
}
gregorianDayOfYear += this.NEPALI_CALENDAR_DATA[nepaliYearToCheck][nepaliMonthToCheck];
nepaliMonthToCheck--;
}
// If the date that has to be converted is in Paush (month no. 9) we have to do some other calculation
if (nepaliMonth === 9) {
// Add the days that are passed since the first day of Paush and substract the
// amount of days that lie between 1st. Jan and 1st Paush
gregorianDayOfYear += nepaliDay - this.NEPALI_CALENDAR_DATA[nepaliYearToCheck][0];
// For the first days of Paush we are now in negative values,
// because in the end of the gregorian year we substract
// 365 / 366 days (P.S. remember math in school + - gives -)
if (gregorianDayOfYear < 0) {
gregorianDayOfYear += gregorianCalendar.daysInYear(gregorianYear);
}
}
else {
gregorianDayOfYear += this.NEPALI_CALENDAR_DATA[nepaliYearToCheck][9] -
this.NEPALI_CALENDAR_DATA[nepaliYearToCheck][0];
}
return gregorianCalendar.newDate(gregorianYear, 1 ,1).add(gregorianDayOfYear, 'd').toJD();
},
/** Create a new date from a Julian date.
@memberof NepaliCalendar
@param jd {number} The Julian date to convert.
@return {CDate} The equivalent date. */
fromJD: function(jd) {
var gregorianCalendar = main.instance();
var gregorianDate = gregorianCalendar.fromJD(jd);
var gregorianYear = gregorianDate.year();
var gregorianDayOfYear = gregorianDate.dayOfYear();
var nepaliYear = gregorianYear + 56; //this is not final, it could be also +57 but +56 is always true for 1st Jan.
this._createMissingCalendarData(nepaliYear);
var nepaliMonth = 9; // Jan 1 always fall in Nepali month Paush which is the 9th month of Nepali calendar.
// Get the Nepali day in Paush (month 9) of 1st January
var dayOfFirstJanInPaush = this.NEPALI_CALENDAR_DATA[nepaliYear][0];
// Check how many days are left of Paush .
// Days calculated from 1st Jan till the end of the actual Nepali month,
// we use this value to check if the gregorian Date is in the actual Nepali month.
var daysSinceJanFirstToEndOfNepaliMonth =
this.NEPALI_CALENDAR_DATA[nepaliYear][nepaliMonth] - dayOfFirstJanInPaush + 1;
// If the gregorian day-of-year is smaller o equal than the sum of days between the 1st January and
// the end of the actual nepali month we found the correct nepali month.
// Example:
// The 4th February 2011 is the gregorianDayOfYear 35 (31 days of January + 4)
// 1st January 2011 is in the nepali year 2067, where 1st. January is in the 17th day of Paush (9th month)
// In 2067 Paush has 30days, This means (30-17+1=14) there are 14days between 1st January and end of Paush
// (including 17th January)
// The gregorianDayOfYear (35) is bigger than 14, so we check the next month
// The next nepali month (Mangh) has 29 days
// 29+14=43, this is bigger than gregorianDayOfYear(35) so, we found the correct nepali month
while (gregorianDayOfYear > daysSinceJanFirstToEndOfNepaliMonth) {
nepaliMonth++;
if (nepaliMonth > 12) {
nepaliMonth = 1;
nepaliYear++;
}
daysSinceJanFirstToEndOfNepaliMonth += this.NEPALI_CALENDAR_DATA[nepaliYear][nepaliMonth];
}
// The last step is to calculate the nepali day-of-month
// to continue our example from before:
// we calculated there are 43 days from 1st. January (17 Paush) till end of Mangh (29 days)
// when we subtract from this 43 days the day-of-year of the the Gregorian date (35),
// we know how far the searched day is away from the end of the Nepali month.
// So we simply subtract this number from the amount of days in this month (30)
var nepaliDayOfMonth = this.NEPALI_CALENDAR_DATA[nepaliYear][nepaliMonth] -
(daysSinceJanFirstToEndOfNepaliMonth - gregorianDayOfYear);
return this.newDate(nepaliYear, nepaliMonth, nepaliDayOfMonth);
},
/** Creates missing data in the NEPALI_CALENDAR_DATA table.
This data will not be correct but just give an estimated result. Mostly -/+ 1 day
@private
@param nepaliYear {number} The missing year number. */
_createMissingCalendarData: function(nepaliYear) {
var tmp_calendar_data = this.daysPerMonth.slice(0);
tmp_calendar_data.unshift(17);
for (var nepaliYearToCreate = (nepaliYear - 1); nepaliYearToCreate < (nepaliYear + 2); nepaliYearToCreate++) {
if (typeof this.NEPALI_CALENDAR_DATA[nepaliYearToCreate] === 'undefined') {
this.NEPALI_CALENDAR_DATA[nepaliYearToCreate] = tmp_calendar_data;
}
}
},
NEPALI_CALENDAR_DATA: {
// These data are from http://www.ashesh.com.np
1970: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
1971: [18, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30],
1972: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
1973: [19, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
1974: [19, 31, 31, 32, 30, 31, 31, 30, 29, 30, 29, 30, 30],
1975: [18, 31, 31, 32, 32, 30, 31, 30, 29, 30, 29, 30, 30],
1976: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
1977: [18, 31, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31],
1978: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
1979: [18, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
1980: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
1981: [18, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
1982: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
1983: [18, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
1984: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
1985: [18, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
1986: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
1987: [18, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
1988: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
1989: [18, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
1990: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
1991: [18, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
// These data are from http://nepalicalendar.rat32.com/index.php
1992: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
1993: [18, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
1994: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
1995: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
1996: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
1997: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
1998: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
1999: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
2000: [17, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
2001: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
2002: [18, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
2003: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
2004: [17, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
2005: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
2006: [18, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
2007: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
2008: [17, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
2009: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
2010: [18, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
2011: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
2012: [17, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
2013: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
2014: [18, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
2015: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
2016: [17, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
2017: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
2018: [18, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
2019: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
2020: [17, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
2021: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
2022: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
2023: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
2024: [17, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
2025: [18, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
2026: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
2027: [17, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
2028: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
2029: [18, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30],
2030: [17, 31, 32, 31, 32, 31, 30, 30, 30, 30, 30, 30, 31],
2031: [17, 31, 32, 31, 32, 31, 31, 31, 31, 31, 31, 31, 31],
2032: [17, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32],
2033: [18, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
2034: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
2035: [17, 30, 32, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
2036: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
2037: [18, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
2038: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
2039: [17, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
2040: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
2041: [18, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
2042: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
2043: [17, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
2044: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
2045: [18, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
2046: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
2047: [17, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
2048: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
2049: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
2050: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
2051: [17, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
2052: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
2053: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
2054: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
2055: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 30, 29, 30],
2056: [17, 31, 31, 32, 31, 32, 30, 30, 29, 30, 29, 30, 30],
2057: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
2058: [17, 30, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
2059: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
2060: [17, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
2061: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
2062: [17, 30, 32, 31, 32, 31, 31, 29, 30, 29, 30, 29, 31],
2063: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
2064: [17, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
2065: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
2066: [17, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 29, 31],
2067: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
2068: [17, 31, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
2069: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
2070: [17, 31, 31, 31, 32, 31, 31, 29, 30, 30, 29, 30, 30],
2071: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
2072: [17, 31, 32, 31, 32, 31, 30, 30, 29, 30, 29, 30, 30],
2073: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 31],
2074: [17, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
2075: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
2076: [16, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
2077: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 29, 31],
2078: [17, 31, 31, 31, 32, 31, 31, 30, 29, 30, 29, 30, 30],
2079: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 29, 30, 30],
2080: [16, 31, 32, 31, 32, 31, 30, 30, 30, 29, 29, 30, 30],
// These data are from http://www.ashesh.com.np/nepali-calendar/
2081: [17, 31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30],
2082: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
2083: [17, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
2084: [17, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
2085: [17, 31, 32, 31, 32, 31, 31, 30, 30, 29, 30, 30, 30],
2086: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
2087: [16, 31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30],
2088: [16, 30, 31, 32, 32, 30, 31, 30, 30, 29, 30, 30, 30],
2089: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
2090: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
2091: [16, 31, 31, 32, 31, 31, 31, 30, 30, 29, 30, 30, 30],
2092: [16, 31, 31, 32, 32, 31, 30, 30, 30, 29, 30, 30, 30],
2093: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
2094: [17, 31, 31, 32, 31, 31, 30, 30, 30, 29, 30, 30, 30],
2095: [17, 31, 31, 32, 31, 31, 31, 30, 29, 30, 30, 30, 30],
2096: [17, 30, 31, 32, 32, 31, 30, 30, 29, 30, 29, 30, 30],
2097: [17, 31, 32, 31, 32, 31, 30, 30, 30, 29, 30, 30, 30],
2098: [17, 31, 31, 32, 31, 31, 31, 29, 30, 29, 30, 30, 31],
2099: [17, 31, 31, 32, 31, 31, 31, 30, 29, 29, 30, 30, 30],
2100: [17, 31, 32, 31, 32, 30, 31, 30, 29, 30, 29, 30, 30]
}
});
// Nepali calendar implementation
main.calendars.nepali = NepaliCalendar;
/***/ }),
/***/ 1104:
/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
/*
* World Calendars
* https://github.com/alexcjohnson/world-calendars
*
* Batch-converted from kbwood/calendars
* Many thanks to Keith Wood and all of the contributors to the original project!
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* http://keith-wood.name/calendars.html
Persian calendar for jQuery v2.0.2.
Written by Keith Wood (wood.keith{at}optusnet.com.au) August 2009.
Available under the MIT (http://keith-wood.name/licence.html) license.
Please attribute the author if you use it. */
var main = __webpack_require__(8700);
var assign = __webpack_require__(896);
/** Implementation of the Persian or Jalali calendar.
Based on code from http://www.iranchamber.com/calendar/converter/iranian_calendar_converter.php.
See also http://en.wikipedia.org/wiki/Iranian_calendar.
@class PersianCalendar
@param [language=''] {string} The language code (default English) for localisation. */
function PersianCalendar(language) {
this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];
}
PersianCalendar.prototype = new main.baseCalendar;
assign(PersianCalendar.prototype, {
/** The calendar name.
@memberof PersianCalendar */
name: 'Persian',
/** Julian date of start of Persian epoch: 19 March 622 CE.
@memberof PersianCalendar */
jdEpoch: 1948320.5,
/** Days per month in a common year.
@memberof PersianCalendar */
daysPerMonth: [31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 29],
/** true
if has a year zero, false
if not.
@memberof PersianCalendar */
hasYearZero: false,
/** The minimum month number.
@memberof PersianCalendar */
minMonth: 1,
/** The first month in the year.
@memberof PersianCalendar */
firstMonth: 1,
/** The minimum day number.
@memberof PersianCalendar */
minDay: 1,
/** Localisations for the plugin.
Entries are objects indexed by the language code ('' being the default US/English).
Each object has the following attributes.
@memberof PersianCalendar
@property name {string} The calendar name.
@property epochs {string[]} The epoch names.
@property monthNames {string[]} The long names of the months of the year.
@property monthNamesShort {string[]} The short names of the months of the year.
@property dayNames {string[]} The long names of the days of the week.
@property dayNamesShort {string[]} The short names of the days of the week.
@property dayNamesMin {string[]} The minimal names of the days of the week.
@property dateFormat {string} The date format for this calendar.
See the options on formatDate
for details.
@property firstDay {number} The number of the first day of the week, starting at 0.
@property isRTL {number} true
if this localisation reads right-to-left. */
regionalOptions: { // Localisations
'': {
name: 'Persian',
epochs: ['BP', 'AP'],
monthNames: ['Farvardin', 'Ordibehesht', 'Khordad', 'Tir', 'Mordad', 'Shahrivar',
'Mehr', 'Aban', 'Azar', 'Day', 'Bahman', 'Esfand'],
monthNamesShort: ['Far', 'Ord', 'Kho', 'Tir', 'Mor', 'Sha', 'Meh', 'Aba', 'Aza', 'Day', 'Bah', 'Esf'],
dayNames: ['Yekshambe', 'Doshambe', 'Seshambe', 'Chæharshambe', 'Panjshambe', 'Jom\'e', 'Shambe'],
dayNamesShort: ['Yek', 'Do', 'Se', 'Chæ', 'Panj', 'Jom', 'Sha'],
dayNamesMin: ['Ye','Do','Se','Ch','Pa','Jo','Sh'],
digits: null,
dateFormat: 'yyyy/mm/dd',
firstDay: 6,
isRTL: false
}
},
/** Determine whether this date is in a leap year.
@memberof PersianCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {boolean} true
if this is a leap year, false
if not.
@throws Error if an invalid year or a different calendar used. */
leapYear: function(year) {
var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
return (((((date.year() - (date.year() > 0 ? 474 : 473)) % 2820) +
474 + 38) * 682) % 2816) < 682;
},
/** Determine the week of the year for a date.
@memberof PersianCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {number} The week of the year.
@throws Error if an invalid date or a different calendar used. */
weekOfYear: function(year, month, day) {
// Find Saturday of this week starting on Saturday
var checkDate = this.newDate(year, month, day);
checkDate.add(-((checkDate.dayOfWeek() + 1) % 7), 'd');
return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;
},
/** Retrieve the number of days in a month.
@memberof PersianCalendar
@param year {CDate|number} The date to examine or the year of the month.
@param [month] {number} The month.
@return {number} The number of days in this month.
@throws Error if an invalid month/year or a different calendar used. */
daysInMonth: function(year, month) {
var date = this._validate(year, month, this.minDay, main.local.invalidMonth);
return this.daysPerMonth[date.month() - 1] +
(date.month() === 12 && this.leapYear(date.year()) ? 1 : 0);
},
/** Determine whether this date is a week day.
@memberof PersianCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {boolean} true
if a week day, false
if not.
@throws Error if an invalid date or a different calendar used. */
weekDay: function(year, month, day) {
return this.dayOfWeek(year, month, day) !== 5;
},
/** Retrieve the Julian date equivalent for this date,
i.e. days since January 1, 4713 BCE Greenwich noon.
@memberof PersianCalendar
@param year {CDate|number} The date to convert or the year to convert.
@param [month] {number} The month to convert.
@param [day] {number} The day to convert.
@return {number} The equivalent Julian date.
@throws Error if an invalid date or a different calendar used. */
toJD: function(year, month, day) {
var date = this._validate(year, month, day, main.local.invalidDate);
year = date.year();
month = date.month();
day = date.day();
var epBase = year - (year >= 0 ? 474 : 473);
var epYear = 474 + mod(epBase, 2820);
return day + (month <= 7 ? (month - 1) * 31 : (month - 1) * 30 + 6) +
Math.floor((epYear * 682 - 110) / 2816) + (epYear - 1) * 365 +
Math.floor(epBase / 2820) * 1029983 + this.jdEpoch - 1;
},
/** Create a new date from a Julian date.
@memberof PersianCalendar
@param jd {number} The Julian date to convert.
@return {CDate} The equivalent date. */
fromJD: function(jd) {
jd = Math.floor(jd) + 0.5;
var depoch = jd - this.toJD(475, 1, 1);
var cycle = Math.floor(depoch / 1029983);
var cyear = mod(depoch, 1029983);
var ycycle = 2820;
if (cyear !== 1029982) {
var aux1 = Math.floor(cyear / 366);
var aux2 = mod(cyear, 366);
ycycle = Math.floor(((2134 * aux1) + (2816 * aux2) + 2815) / 1028522) + aux1 + 1;
}
var year = ycycle + (2820 * cycle) + 474;
year = (year <= 0 ? year - 1 : year);
var yday = jd - this.toJD(year, 1, 1) + 1;
var month = (yday <= 186 ? Math.ceil(yday / 31) : Math.ceil((yday - 6) / 30));
var day = jd - this.toJD(year, month, 1) + 1;
return this.newDate(year, month, day);
}
});
// Modulus function which works for non-integers.
function mod(a, b) {
return a - (b * Math.floor(a / b));
}
// Persian (Jalali) calendar implementation
main.calendars.persian = PersianCalendar;
main.calendars.jalali = PersianCalendar;
/***/ }),
/***/ 9075:
/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
/*
* World Calendars
* https://github.com/alexcjohnson/world-calendars
*
* Batch-converted from kbwood/calendars
* Many thanks to Keith Wood and all of the contributors to the original project!
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* http://keith-wood.name/calendars.html
Taiwanese (Minguo) calendar for jQuery v2.0.2.
Written by Keith Wood (wood.keith{at}optusnet.com.au) February 2010.
Available under the MIT (http://keith-wood.name/licence.html) license.
Please attribute the author if you use it. */
var main = __webpack_require__(8700);
var assign = __webpack_require__(896);
var gregorianCalendar = main.instance();
/** Implementation of the Taiwanese calendar.
See http://en.wikipedia.org/wiki/Minguo_calendar.
@class TaiwanCalendar
@param [language=''] {string} The language code (default English) for localisation. */
function TaiwanCalendar(language) {
this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];
}
TaiwanCalendar.prototype = new main.baseCalendar;
assign(TaiwanCalendar.prototype, {
/** The calendar name.
@memberof TaiwanCalendar */
name: 'Taiwan',
/** Julian date of start of Taiwan epoch: 1 January 1912 CE (Gregorian).
@memberof TaiwanCalendar */
jdEpoch: 2419402.5,
/** Difference in years between Taiwan and Gregorian calendars.
@memberof TaiwanCalendar */
yearsOffset: 1911,
/** Days per month in a common year.
@memberof TaiwanCalendar */
daysPerMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
/** true
if has a year zero, false
if not.
@memberof TaiwanCalendar */
hasYearZero: false,
/** The minimum month number.
@memberof TaiwanCalendar */
minMonth: 1,
/** The first month in the year.
@memberof TaiwanCalendar */
firstMonth: 1,
/** The minimum day number.
@memberof TaiwanCalendar */
minDay: 1,
/** Localisations for the plugin.
Entries are objects indexed by the language code ('' being the default US/English).
Each object has the following attributes.
@memberof TaiwanCalendar
@property name {string} The calendar name.
@property epochs {string[]} The epoch names.
@property monthNames {string[]} The long names of the months of the year.
@property monthNamesShort {string[]} The short names of the months of the year.
@property dayNames {string[]} The long names of the days of the week.
@property dayNamesShort {string[]} The short names of the days of the week.
@property dayNamesMin {string[]} The minimal names of the days of the week.
@property dateFormat {string} The date format for this calendar.
See the options on formatDate
for details.
@property firstDay {number} The number of the first day of the week, starting at 0.
@property isRTL {number} true
if this localisation reads right-to-left. */
regionalOptions: { // Localisations
'': {
name: 'Taiwan',
epochs: ['BROC', 'ROC'],
monthNames: ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'],
monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
dayNamesMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
digits: null,
dateFormat: 'yyyy/mm/dd',
firstDay: 1,
isRTL: false
}
},
/** Determine whether this date is in a leap year.
@memberof TaiwanCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {boolean} true
if this is a leap year, false
if not.
@throws Error if an invalid year or a different calendar used. */
leapYear: function(year) {
var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
var year = this._t2gYear(date.year());
return gregorianCalendar.leapYear(year);
},
/** Determine the week of the year for a date - ISO 8601.
@memberof TaiwanCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {number} The week of the year.
@throws Error if an invalid date or a different calendar used. */
weekOfYear: function(year, month, day) {
var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
var year = this._t2gYear(date.year());
return gregorianCalendar.weekOfYear(year, date.month(), date.day());
},
/** Retrieve the number of days in a month.
@memberof TaiwanCalendar
@param year {CDate|number} The date to examine or the year of the month.
@param [month] {number} The month.
@return {number} The number of days in this month.
@throws Error if an invalid month/year or a different calendar used. */
daysInMonth: function(year, month) {
var date = this._validate(year, month, this.minDay, main.local.invalidMonth);
return this.daysPerMonth[date.month() - 1] +
(date.month() === 2 && this.leapYear(date.year()) ? 1 : 0);
},
/** Determine whether this date is a week day.
@memberof TaiwanCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {boolean} true
if a week day, false
if not.
@throws Error if an invalid date or a different calendar used. */
weekDay: function(year, month, day) {
return (this.dayOfWeek(year, month, day) || 7) < 6;
},
/** Retrieve the Julian date equivalent for this date,
i.e. days since January 1, 4713 BCE Greenwich noon.
@memberof TaiwanCalendar
@param year {CDate|number} The date to convert or the year to convert.
@param [month] {number} The month to convert.
@param [day] {number} The day to convert.
@return {number} The equivalent Julian date.
@throws Error if an invalid date or a different calendar used. */
toJD: function(year, month, day) {
var date = this._validate(year, month, day, main.local.invalidDate);
var year = this._t2gYear(date.year());
return gregorianCalendar.toJD(year, date.month(), date.day());
},
/** Create a new date from a Julian date.
@memberof TaiwanCalendar
@param jd {number} The Julian date to convert.
@return {CDate} The equivalent date. */
fromJD: function(jd) {
var date = gregorianCalendar.fromJD(jd);
var year = this._g2tYear(date.year());
return this.newDate(year, date.month(), date.day());
},
/** Convert Taiwanese to Gregorian year.
@memberof TaiwanCalendar
@private
@param year {number} The Taiwanese year.
@return {number} The corresponding Gregorian year. */
_t2gYear: function(year) {
return year + this.yearsOffset + (year >= -this.yearsOffset && year <= -1 ? 1 : 0);
},
/** Convert Gregorian to Taiwanese year.
@memberof TaiwanCalendar
@private
@param year {number} The Gregorian year.
@return {number} The corresponding Taiwanese year. */
_g2tYear: function(year) {
return year - this.yearsOffset - (year >= 1 && year <= this.yearsOffset ? 1 : 0);
}
});
// Taiwan calendar implementation
main.calendars.taiwan = TaiwanCalendar;
/***/ }),
/***/ 4592:
/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
/*
* World Calendars
* https://github.com/alexcjohnson/world-calendars
*
* Batch-converted from kbwood/calendars
* Many thanks to Keith Wood and all of the contributors to the original project!
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* http://keith-wood.name/calendars.html
Thai calendar for jQuery v2.0.2.
Written by Keith Wood (wood.keith{at}optusnet.com.au) February 2010.
Available under the MIT (http://keith-wood.name/licence.html) license.
Please attribute the author if you use it. */
var main = __webpack_require__(8700);
var assign = __webpack_require__(896);
var gregorianCalendar = main.instance();
/** Implementation of the Thai calendar.
See http://en.wikipedia.org/wiki/Thai_calendar.
@class ThaiCalendar
@param [language=''] {string} The language code (default English) for localisation. */
function ThaiCalendar(language) {
this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];
}
ThaiCalendar.prototype = new main.baseCalendar;
assign(ThaiCalendar.prototype, {
/** The calendar name.
@memberof ThaiCalendar */
name: 'Thai',
/** Julian date of start of Thai epoch: 1 January 543 BCE (Gregorian).
@memberof ThaiCalendar */
jdEpoch: 1523098.5,
/** Difference in years between Thai and Gregorian calendars.
@memberof ThaiCalendar */
yearsOffset: 543,
/** Days per month in a common year.
@memberof ThaiCalendar */
daysPerMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
/** true
if has a year zero, false
if not.
@memberof ThaiCalendar */
hasYearZero: false,
/** The minimum month number.
@memberof ThaiCalendar */
minMonth: 1,
/** The first month in the year.
@memberof ThaiCalendar */
firstMonth: 1,
/** The minimum day number.
@memberof ThaiCalendar */
minDay: 1,
/** Localisations for the plugin.
Entries are objects indexed by the language code ('' being the default US/English).
Each object has the following attributes.
@memberof ThaiCalendar
@property name {string} The calendar name.
@property epochs {string[]} The epoch names.
@property monthNames {string[]} The long names of the months of the year.
@property monthNamesShort {string[]} The short names of the months of the year.
@property dayNames {string[]} The long names of the days of the week.
@property dayNamesShort {string[]} The short names of the days of the week.
@property dayNamesMin {string[]} The minimal names of the days of the week.
@property dateFormat {string} The date format for this calendar.
See the options on formatDate
for details.
@property firstDay {number} The number of the first day of the week, starting at 0.
@property isRTL {number} true
if this localisation reads right-to-left. */
regionalOptions: { // Localisations
'': {
name: 'Thai',
epochs: ['BBE', 'BE'],
monthNames: ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'],
monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
dayNamesMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
digits: null,
dateFormat: 'dd/mm/yyyy',
firstDay: 0,
isRTL: false
}
},
/** Determine whether this date is in a leap year.
@memberof ThaiCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {boolean} true
if this is a leap year, false
if not.
@throws Error if an invalid year or a different calendar used. */
leapYear: function(year) {
var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
var year = this._t2gYear(date.year());
return gregorianCalendar.leapYear(year);
},
/** Determine the week of the year for a date - ISO 8601.
@memberof ThaiCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {number} The week of the year.
@throws Error if an invalid date or a different calendar used. */
weekOfYear: function(year, month, day) {
var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
var year = this._t2gYear(date.year());
return gregorianCalendar.weekOfYear(year, date.month(), date.day());
},
/** Retrieve the number of days in a month.
@memberof ThaiCalendar
@param year {CDate|number} The date to examine or the year of the month.
@param [month] {number} The month.
@return {number} The number of days in this month.
@throws Error if an invalid month/year or a different calendar used. */
daysInMonth: function(year, month) {
var date = this._validate(year, month, this.minDay, main.local.invalidMonth);
return this.daysPerMonth[date.month() - 1] +
(date.month() === 2 && this.leapYear(date.year()) ? 1 : 0);
},
/** Determine whether this date is a week day.
@memberof ThaiCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {boolean} true
if a week day, false
if not.
@throws Error if an invalid date or a different calendar used. */
weekDay: function(year, month, day) {
return (this.dayOfWeek(year, month, day) || 7) < 6;
},
/** Retrieve the Julian date equivalent for this date,
i.e. days since January 1, 4713 BCE Greenwich noon.
@memberof ThaiCalendar
@param year {CDate|number} The date to convert or the year to convert.
@param [month] {number} The month to convert.
@param [day] {number} The day to convert.
@return {number} The equivalent Julian date.
@throws Error if an invalid date or a different calendar used. */
toJD: function(year, month, day) {
var date = this._validate(year, month, day, main.local.invalidDate);
var year = this._t2gYear(date.year());
return gregorianCalendar.toJD(year, date.month(), date.day());
},
/** Create a new date from a Julian date.
@memberof ThaiCalendar
@param jd {number} The Julian date to convert.
@return {CDate} The equivalent date. */
fromJD: function(jd) {
var date = gregorianCalendar.fromJD(jd);
var year = this._g2tYear(date.year());
return this.newDate(year, date.month(), date.day());
},
/** Convert Thai to Gregorian year.
@memberof ThaiCalendar
@private
@param year {number} The Thai year.
@return {number} The corresponding Gregorian year. */
_t2gYear: function(year) {
return year - this.yearsOffset - (year >= 1 && year <= this.yearsOffset ? 1 : 0);
},
/** Convert Gregorian to Thai year.
@memberof ThaiCalendar
@private
@param year {number} The Gregorian year.
@return {number} The corresponding Thai year. */
_g2tYear: function(year) {
return year + this.yearsOffset + (year >= -this.yearsOffset && year <= -1 ? 1 : 0);
}
});
// Thai calendar implementation
main.calendars.thai = ThaiCalendar;
/***/ }),
/***/ 5348:
/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
/*
* World Calendars
* https://github.com/alexcjohnson/world-calendars
*
* Batch-converted from kbwood/calendars
* Many thanks to Keith Wood and all of the contributors to the original project!
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* http://keith-wood.name/calendars.html
UmmAlQura calendar for jQuery v2.0.2.
Written by Amro Osama March 2013.
Modified by Binnooh.com & www.elm.sa - 2014 - Added dates back to 1276 Hijri year.
Available under the MIT (http://keith-wood.name/licence.html) license.
Please attribute the author if you use it. */
var main = __webpack_require__(8700);
var assign = __webpack_require__(896);
/** Implementation of the UmmAlQura or 'saudi' calendar.
See also http://en.wikipedia.org/wiki/Islamic_calendar#Saudi_Arabia.27s_Umm_al-Qura_calendar.
http://www.ummulqura.org.sa/About.aspx
http://www.staff.science.uu.nl/~gent0113/islam/ummalqura.htm
@class UmmAlQuraCalendar
@param [language=''] {string} The language code (default English) for localisation. */
function UmmAlQuraCalendar(language) {
this.local = this.regionalOptions[language || ''] || this.regionalOptions[''];
}
UmmAlQuraCalendar.prototype = new main.baseCalendar;
assign(UmmAlQuraCalendar.prototype, {
/** The calendar name.
@memberof UmmAlQuraCalendar */
name: 'UmmAlQura',
//jdEpoch: 1948440, // Julian date of start of UmmAlQura epoch: 14 March 1937 CE
//daysPerMonth: // Days per month in a common year, replaced by a method.
/** true
if has a year zero, false
if not.
@memberof UmmAlQuraCalendar */
hasYearZero: false,
/** The minimum month number.
@memberof UmmAlQuraCalendar */
minMonth: 1,
/** The first month in the year.
@memberof UmmAlQuraCalendar */
firstMonth: 1,
/** The minimum day number.
@memberof UmmAlQuraCalendar */
minDay: 1,
/** Localisations for the plugin.
Entries are objects indexed by the language code ('' being the default US/English).
Each object has the following attributes.
@memberof UmmAlQuraCalendar
@property name {string} The calendar name.
@property epochs {string[]} The epoch names.
@property monthNames {string[]} The long names of the months of the year.
@property monthNamesShort {string[]} The short names of the months of the year.
@property dayNames {string[]} The long names of the days of the week.
@property dayNamesShort {string[]} The short names of the days of the week.
@property dayNamesMin {string[]} The minimal names of the days of the week.
@property dateFormat {string} The date format for this calendar.
See the options on formatDate
for details.
@property firstDay {number} The number of the first day of the week, starting at 0.
@property isRTL {number} true
if this localisation reads right-to-left. */
regionalOptions: { // Localisations
'': {
name: 'Umm al-Qura',
epochs: ['BH', 'AH'],
monthNames: ['Al-Muharram', 'Safar', 'Rabi\' al-awwal', 'Rabi\' Al-Thani', 'Jumada Al-Awwal', 'Jumada Al-Thani',
'Rajab', 'Sha\'aban', 'Ramadan', 'Shawwal', 'Dhu al-Qi\'dah', 'Dhu al-Hijjah'],
monthNamesShort: ['Muh', 'Saf', 'Rab1', 'Rab2', 'Jum1', 'Jum2', 'Raj', 'Sha\'', 'Ram', 'Shaw', 'DhuQ', 'DhuH'],
dayNames: ['Yawm al-Ahad', 'Yawm al-Ithnain', 'Yawm al-Thalāthā’', 'Yawm al-Arba‘ā’', 'Yawm al-Khamīs', 'Yawm al-Jum‘a', 'Yawm al-Sabt'],
dayNamesMin: ['Ah', 'Ith', 'Th', 'Ar', 'Kh', 'Ju', 'Sa'],
digits: null,
dateFormat: 'yyyy/mm/dd',
firstDay: 6,
isRTL: true
}
},
/** Determine whether this date is in a leap year.
@memberof UmmAlQuraCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {boolean} true
if this is a leap year, false
if not.
@throws Error if an invalid year or a different calendar used. */
leapYear: function (year) {
var date = this._validate(year, this.minMonth, this.minDay, main.local.invalidYear);
return (this.daysInYear(date.year()) === 355);
},
/** Determine the week of the year for a date.
@memberof UmmAlQuraCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {number} The week of the year.
@throws Error if an invalid date or a different calendar used. */
weekOfYear: function (year, month, day) {
// Find Sunday of this week starting on Sunday
var checkDate = this.newDate(year, month, day);
checkDate.add(-checkDate.dayOfWeek(), 'd');
return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;
},
/** Retrieve the number of days in a year.
@memberof UmmAlQuraCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {number} The number of days.
@throws Error if an invalid year or a different calendar used. */
daysInYear: function (year) {
var daysCount = 0;
for (var i = 1; i <= 12; i++) {
daysCount += this.daysInMonth(year, i);
}
return daysCount;
},
/** Retrieve the number of days in a month.
@memberof UmmAlQuraCalendar
@param year {CDate|number} The date to examine or the year of the month.
@param [month] {number} The month.
@return {number} The number of days in this month.
@throws Error if an invalid month/year or a different calendar used. */
daysInMonth: function (year, month) {
var date = this._validate(year, month, this.minDay, main.local.invalidMonth);
var mcjdn = date.toJD() - 2400000 + 0.5; // Modified Chronological Julian Day Number (MCJDN)
// the MCJDN's of the start of the lunations in the Umm al-Qura calendar are stored in the 'ummalqura_dat' array
var index = 0;
for (var i = 0; i < ummalqura_dat.length; i++) {
if (ummalqura_dat[i] > mcjdn) {
return (ummalqura_dat[index] - ummalqura_dat[index - 1]);
}
index++;
}
return 30; // Unknown outside
},
/** Determine whether this date is a week day.
@memberof UmmAlQuraCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {boolean} true
if a week day, false
if not.
@throws Error if an invalid date or a different calendar used. */
weekDay: function (year, month, day) {
return this.dayOfWeek(year, month, day) !== 5;
},
/** Retrieve the Julian date equivalent for this date,
i.e. days since January 1, 4713 BCE Greenwich noon.
@memberof UmmAlQuraCalendar
@param year {CDate|number} The date to convert or the year to convert.
@param [month] {number} The month to convert.
@param [day] {number} The day to convert.
@return {number} The equivalent Julian date.
@throws Error if an invalid date or a different calendar used. */
toJD: function (year, month, day) {
var date = this._validate(year, month, day, main.local.invalidDate);
var index = (12 * (date.year() - 1)) + date.month() - 15292;
var mcjdn = date.day() + ummalqura_dat[index - 1] - 1;
return mcjdn + 2400000 - 0.5; // Modified Chronological Julian Day Number (MCJDN)
},
/** Create a new date from a Julian date.
@memberof UmmAlQuraCalendar
@param jd {number} The Julian date to convert.
@return {CDate} The equivalent date. */
fromJD: function (jd) {
var mcjdn = jd - 2400000 + 0.5; // Modified Chronological Julian Day Number (MCJDN)
// the MCJDN's of the start of the lunations in the Umm al-Qura calendar
// are stored in the 'ummalqura_dat' array
var index = 0;
for (var i = 0; i < ummalqura_dat.length; i++) {
if (ummalqura_dat[i] > mcjdn) break;
index++;
}
var lunation = index + 15292; //UmmAlQura Lunation Number
var ii = Math.floor((lunation - 1) / 12);
var year = ii + 1;
var month = lunation - 12 * ii;
var day = mcjdn - ummalqura_dat[index - 1] + 1;
return this.newDate(year, month, day);
},
/** Determine whether a date is valid for this calendar.
@memberof UmmAlQuraCalendar
@param year {number} The year to examine.
@param month {number} The month to examine.
@param day {number} The day to examine.
@return {boolean} true
if a valid date, false
if not. */
isValid: function(year, month, day) {
var valid = main.baseCalendar.prototype.isValid.apply(this, arguments);
if (valid) {
year = (year.year != null ? year.year : year);
valid = (year >= 1276 && year <= 1500);
}
return valid;
},
/** Check that a candidate date is from the same calendar and is valid.
@memberof UmmAlQuraCalendar
@private
@param year {CDate|number} The date to validate or the year to validate.
@param month {number} The month to validate.
@param day {number} The day to validate.
@param error {string} Error message if invalid.
@throws Error if different calendars used or invalid date. */
_validate: function(year, month, day, error) {
var date = main.baseCalendar.prototype._validate.apply(this, arguments);
if (date.year < 1276 || date.year > 1500) {
throw error.replace(/\{0\}/, this.local.name);
}
return date;
}
});
// UmmAlQura calendar implementation
main.calendars.ummalqura = UmmAlQuraCalendar;
var ummalqura_dat = [
20, 50, 79, 109, 138, 168, 197, 227, 256, 286, 315, 345, 374, 404, 433, 463, 492, 522, 551, 581,
611, 641, 670, 700, 729, 759, 788, 818, 847, 877, 906, 936, 965, 995, 1024, 1054, 1083, 1113, 1142, 1172,
1201, 1231, 1260, 1290, 1320, 1350, 1379, 1409, 1438, 1468, 1497, 1527, 1556, 1586, 1615, 1645, 1674, 1704, 1733, 1763,
1792, 1822, 1851, 1881, 1910, 1940, 1969, 1999, 2028, 2058, 2087, 2117, 2146, 2176, 2205, 2235, 2264, 2294, 2323, 2353,
2383, 2413, 2442, 2472, 2501, 2531, 2560, 2590, 2619, 2649, 2678, 2708, 2737, 2767, 2796, 2826, 2855, 2885, 2914, 2944,
2973, 3003, 3032, 3062, 3091, 3121, 3150, 3180, 3209, 3239, 3268, 3298, 3327, 3357, 3386, 3416, 3446, 3476, 3505, 3535,
3564, 3594, 3623, 3653, 3682, 3712, 3741, 3771, 3800, 3830, 3859, 3889, 3918, 3948, 3977, 4007, 4036, 4066, 4095, 4125,
4155, 4185, 4214, 4244, 4273, 4303, 4332, 4362, 4391, 4421, 4450, 4480, 4509, 4539, 4568, 4598, 4627, 4657, 4686, 4716,
4745, 4775, 4804, 4834, 4863, 4893, 4922, 4952, 4981, 5011, 5040, 5070, 5099, 5129, 5158, 5188, 5218, 5248, 5277, 5307,
5336, 5366, 5395, 5425, 5454, 5484, 5513, 5543, 5572, 5602, 5631, 5661, 5690, 5720, 5749, 5779, 5808, 5838, 5867, 5897,
5926, 5956, 5985, 6015, 6044, 6074, 6103, 6133, 6162, 6192, 6221, 6251, 6281, 6311, 6340, 6370, 6399, 6429, 6458, 6488,
6517, 6547, 6576, 6606, 6635, 6665, 6694, 6724, 6753, 6783, 6812, 6842, 6871, 6901, 6930, 6960, 6989, 7019, 7048, 7078,
7107, 7137, 7166, 7196, 7225, 7255, 7284, 7314, 7344, 7374, 7403, 7433, 7462, 7492, 7521, 7551, 7580, 7610, 7639, 7669,
7698, 7728, 7757, 7787, 7816, 7846, 7875, 7905, 7934, 7964, 7993, 8023, 8053, 8083, 8112, 8142, 8171, 8201, 8230, 8260,
8289, 8319, 8348, 8378, 8407, 8437, 8466, 8496, 8525, 8555, 8584, 8614, 8643, 8673, 8702, 8732, 8761, 8791, 8821, 8850,
8880, 8909, 8938, 8968, 8997, 9027, 9056, 9086, 9115, 9145, 9175, 9205, 9234, 9264, 9293, 9322, 9352, 9381, 9410, 9440,
9470, 9499, 9529, 9559, 9589, 9618, 9648, 9677, 9706, 9736, 9765, 9794, 9824, 9853, 9883, 9913, 9943, 9972, 10002, 10032,
10061, 10090, 10120, 10149, 10178, 10208, 10237, 10267, 10297, 10326, 10356, 10386, 10415, 10445, 10474, 10504, 10533, 10562, 10592, 10621,
10651, 10680, 10710, 10740, 10770, 10799, 10829, 10858, 10888, 10917, 10947, 10976, 11005, 11035, 11064, 11094, 11124, 11153, 11183, 11213,
11242, 11272, 11301, 11331, 11360, 11389, 11419, 11448, 11478, 11507, 11537, 11567, 11596, 11626, 11655, 11685, 11715, 11744, 11774, 11803,
11832, 11862, 11891, 11921, 11950, 11980, 12010, 12039, 12069, 12099, 12128, 12158, 12187, 12216, 12246, 12275, 12304, 12334, 12364, 12393,
12423, 12453, 12483, 12512, 12542, 12571, 12600, 12630, 12659, 12688, 12718, 12747, 12777, 12807, 12837, 12866, 12896, 12926, 12955, 12984,
13014, 13043, 13072, 13102, 13131, 13161, 13191, 13220, 13250, 13280, 13310, 13339, 13368, 13398, 13427, 13456, 13486, 13515, 13545, 13574,
13604, 13634, 13664, 13693, 13723, 13752, 13782, 13811, 13840, 13870, 13899, 13929, 13958, 13988, 14018, 14047, 14077, 14107, 14136, 14166,
14195, 14224, 14254, 14283, 14313, 14342, 14372, 14401, 14431, 14461, 14490, 14520, 14550, 14579, 14609, 14638, 14667, 14697, 14726, 14756,
14785, 14815, 14844, 14874, 14904, 14933, 14963, 14993, 15021, 15051, 15081, 15110, 15140, 15169, 15199, 15228, 15258, 15287, 15317, 15347,
15377, 15406, 15436, 15465, 15494, 15524, 15553, 15582, 15612, 15641, 15671, 15701, 15731, 15760, 15790, 15820, 15849, 15878, 15908, 15937,
15966, 15996, 16025, 16055, 16085, 16114, 16144, 16174, 16204, 16233, 16262, 16292, 16321, 16350, 16380, 16409, 16439, 16468, 16498, 16528,
16558, 16587, 16617, 16646, 16676, 16705, 16734, 16764, 16793, 16823, 16852, 16882, 16912, 16941, 16971, 17001, 17030, 17060, 17089, 17118,
17148, 17177, 17207, 17236, 17266, 17295, 17325, 17355, 17384, 17414, 17444, 17473, 17502, 17532, 17561, 17591, 17620, 17650, 17679, 17709,
17738, 17768, 17798, 17827, 17857, 17886, 17916, 17945, 17975, 18004, 18034, 18063, 18093, 18122, 18152, 18181, 18211, 18241, 18270, 18300,
18330, 18359, 18388, 18418, 18447, 18476, 18506, 18535, 18565, 18595, 18625, 18654, 18684, 18714, 18743, 18772, 18802, 18831, 18860, 18890,
18919, 18949, 18979, 19008, 19038, 19068, 19098, 19127, 19156, 19186, 19215, 19244, 19274, 19303, 19333, 19362, 19392, 19422, 19452, 19481,
19511, 19540, 19570, 19599, 19628, 19658, 19687, 19717, 19746, 19776, 19806, 19836, 19865, 19895, 19924, 19954, 19983, 20012, 20042, 20071,
20101, 20130, 20160, 20190, 20219, 20249, 20279, 20308, 20338, 20367, 20396, 20426, 20455, 20485, 20514, 20544, 20573, 20603, 20633, 20662,
20692, 20721, 20751, 20780, 20810, 20839, 20869, 20898, 20928, 20957, 20987, 21016, 21046, 21076, 21105, 21135, 21164, 21194, 21223, 21253,
21282, 21312, 21341, 21371, 21400, 21430, 21459, 21489, 21519, 21548, 21578, 21607, 21637, 21666, 21696, 21725, 21754, 21784, 21813, 21843,
21873, 21902, 21932, 21962, 21991, 22021, 22050, 22080, 22109, 22138, 22168, 22197, 22227, 22256, 22286, 22316, 22346, 22375, 22405, 22434,
22464, 22493, 22522, 22552, 22581, 22611, 22640, 22670, 22700, 22730, 22759, 22789, 22818, 22848, 22877, 22906, 22936, 22965, 22994, 23024,
23054, 23083, 23113, 23143, 23173, 23202, 23232, 23261, 23290, 23320, 23349, 23379, 23408, 23438, 23467, 23497, 23527, 23556, 23586, 23616,
23645, 23674, 23704, 23733, 23763, 23792, 23822, 23851, 23881, 23910, 23940, 23970, 23999, 24029, 24058, 24088, 24117, 24147, 24176, 24206,
24235, 24265, 24294, 24324, 24353, 24383, 24413, 24442, 24472, 24501, 24531, 24560, 24590, 24619, 24648, 24678, 24707, 24737, 24767, 24796,
24826, 24856, 24885, 24915, 24944, 24974, 25003, 25032, 25062, 25091, 25121, 25150, 25180, 25210, 25240, 25269, 25299, 25328, 25358, 25387,
25416, 25446, 25475, 25505, 25534, 25564, 25594, 25624, 25653, 25683, 25712, 25742, 25771, 25800, 25830, 25859, 25888, 25918, 25948, 25977,
26007, 26037, 26067, 26096, 26126, 26155, 26184, 26214, 26243, 26272, 26302, 26332, 26361, 26391, 26421, 26451, 26480, 26510, 26539, 26568,
26598, 26627, 26656, 26686, 26715, 26745, 26775, 26805, 26834, 26864, 26893, 26923, 26952, 26982, 27011, 27041, 27070, 27099, 27129, 27159,
27188, 27218, 27248, 27277, 27307, 27336, 27366, 27395, 27425, 27454, 27484, 27513, 27542, 27572, 27602, 27631, 27661, 27691, 27720, 27750,
27779, 27809, 27838, 27868, 27897, 27926, 27956, 27985, 28015, 28045, 28074, 28104, 28134, 28163, 28193, 28222, 28252, 28281, 28310, 28340,
28369, 28399, 28428, 28458, 28488, 28517, 28547, 28577,
// From 1356
28607, 28636, 28665, 28695, 28724, 28754, 28783, 28813, 28843, 28872, 28901, 28931, 28960, 28990, 29019, 29049, 29078, 29108, 29137, 29167,
29196, 29226, 29255, 29285, 29315, 29345, 29375, 29404, 29434, 29463, 29492, 29522, 29551, 29580, 29610, 29640, 29669, 29699, 29729, 29759,
29788, 29818, 29847, 29876, 29906, 29935, 29964, 29994, 30023, 30053, 30082, 30112, 30141, 30171, 30200, 30230, 30259, 30289, 30318, 30348,
30378, 30408, 30437, 30467, 30496, 30526, 30555, 30585, 30614, 30644, 30673, 30703, 30732, 30762, 30791, 30821, 30850, 30880, 30909, 30939,
30968, 30998, 31027, 31057, 31086, 31116, 31145, 31175, 31204, 31234, 31263, 31293, 31322, 31352, 31381, 31411, 31441, 31471, 31500, 31530,
31559, 31589, 31618, 31648, 31676, 31706, 31736, 31766, 31795, 31825, 31854, 31884, 31913, 31943, 31972, 32002, 32031, 32061, 32090, 32120,
32150, 32180, 32209, 32239, 32268, 32298, 32327, 32357, 32386, 32416, 32445, 32475, 32504, 32534, 32563, 32593, 32622, 32652, 32681, 32711,
32740, 32770, 32799, 32829, 32858, 32888, 32917, 32947, 32976, 33006, 33035, 33065, 33094, 33124, 33153, 33183, 33213, 33243, 33272, 33302,
33331, 33361, 33390, 33420, 33450, 33479, 33509, 33539, 33568, 33598, 33627, 33657, 33686, 33716, 33745, 33775, 33804, 33834, 33863, 33893,
33922, 33952, 33981, 34011, 34040, 34069, 34099, 34128, 34158, 34187, 34217, 34247, 34277, 34306, 34336, 34365, 34395, 34424, 34454, 34483,
34512, 34542, 34571, 34601, 34631, 34660, 34690, 34719, 34749, 34778, 34808, 34837, 34867, 34896, 34926, 34955, 34985, 35015, 35044, 35074,
35103, 35133, 35162, 35192, 35222, 35251, 35280, 35310, 35340, 35370, 35399, 35429, 35458, 35488, 35517, 35547, 35576, 35605, 35635, 35665,
35694, 35723, 35753, 35782, 35811, 35841, 35871, 35901, 35930, 35960, 35989, 36019, 36048, 36078, 36107, 36136, 36166, 36195, 36225, 36254,
36284, 36314, 36343, 36373, 36403, 36433, 36462, 36492, 36521, 36551, 36580, 36610, 36639, 36669, 36698, 36728, 36757, 36786, 36816, 36845,
36875, 36904, 36934, 36963, 36993, 37022, 37052, 37081, 37111, 37141, 37170, 37200, 37229, 37259, 37288, 37318, 37347, 37377, 37406, 37436,
37465, 37495, 37524, 37554, 37584, 37613, 37643, 37672, 37701, 37731, 37760, 37790, 37819, 37849, 37878, 37908, 37938, 37967, 37997, 38027,
38056, 38085, 38115, 38144, 38174, 38203, 38233, 38262, 38292, 38322, 38351, 38381, 38410, 38440, 38469, 38499, 38528, 38558, 38587, 38617,
38646, 38676, 38705, 38735, 38764, 38794, 38823, 38853, 38882, 38912, 38941, 38971, 39001, 39030, 39059, 39089, 39118, 39148, 39178, 39208,
39237, 39267, 39297, 39326, 39355, 39385, 39414, 39444, 39473, 39503, 39532, 39562, 39592, 39621, 39650, 39680, 39709, 39739, 39768, 39798,
39827, 39857, 39886, 39916, 39946, 39975, 40005, 40035, 40064, 40094, 40123, 40153, 40182, 40212, 40241, 40271, 40300, 40330, 40359, 40389,
40418, 40448, 40477, 40507, 40536, 40566, 40595, 40625, 40655, 40685, 40714, 40744, 40773, 40803, 40832, 40862, 40892, 40921, 40951, 40980,
41009, 41039, 41068, 41098, 41127, 41157, 41186, 41216, 41245, 41275, 41304, 41334, 41364, 41393, 41422, 41452, 41481, 41511, 41540, 41570,
41599, 41629, 41658, 41688, 41718, 41748, 41777, 41807, 41836, 41865, 41894, 41924, 41953, 41983, 42012, 42042, 42072, 42102, 42131, 42161,
42190, 42220, 42249, 42279, 42308, 42337, 42367, 42397, 42426, 42456, 42485, 42515, 42545, 42574, 42604, 42633, 42662, 42692, 42721, 42751,
42780, 42810, 42839, 42869, 42899, 42929, 42958, 42988, 43017, 43046, 43076, 43105, 43135, 43164, 43194, 43223, 43253, 43283, 43312, 43342,
43371, 43401, 43430, 43460, 43489, 43519, 43548, 43578, 43607, 43637, 43666, 43696, 43726, 43755, 43785, 43814, 43844, 43873, 43903, 43932,
43962, 43991, 44021, 44050, 44080, 44109, 44139, 44169, 44198, 44228, 44258, 44287, 44317, 44346, 44375, 44405, 44434, 44464, 44493, 44523,
44553, 44582, 44612, 44641, 44671, 44700, 44730, 44759, 44788, 44818, 44847, 44877, 44906, 44936, 44966, 44996, 45025, 45055, 45084, 45114,
45143, 45172, 45202, 45231, 45261, 45290, 45320, 45350, 45380, 45409, 45439, 45468, 45498, 45527, 45556, 45586, 45615, 45644, 45674, 45704,
45733, 45763, 45793, 45823, 45852, 45882, 45911, 45940, 45970, 45999, 46028, 46058, 46088, 46117, 46147, 46177, 46206, 46236, 46265, 46295,
46324, 46354, 46383, 46413, 46442, 46472, 46501, 46531, 46560, 46590, 46620, 46649, 46679, 46708, 46738, 46767, 46797, 46826, 46856, 46885,
46915, 46944, 46974, 47003, 47033, 47063, 47092, 47122, 47151, 47181, 47210, 47240, 47269, 47298, 47328, 47357, 47387, 47417, 47446, 47476,
47506, 47535, 47565, 47594, 47624, 47653, 47682, 47712, 47741, 47771, 47800, 47830, 47860, 47890, 47919, 47949, 47978, 48008, 48037, 48066,
48096, 48125, 48155, 48184, 48214, 48244, 48273, 48303, 48333, 48362, 48392, 48421, 48450, 48480, 48509, 48538, 48568, 48598, 48627, 48657,
48687, 48717, 48746, 48776, 48805, 48834, 48864, 48893, 48922, 48952, 48982, 49011, 49041, 49071, 49100, 49130, 49160, 49189, 49218, 49248,
49277, 49306, 49336, 49365, 49395, 49425, 49455, 49484, 49514, 49543, 49573, 49602, 49632, 49661, 49690, 49720, 49749, 49779, 49809, 49838,
49868, 49898, 49927, 49957, 49986, 50016, 50045, 50075, 50104, 50133, 50163, 50192, 50222, 50252, 50281, 50311, 50340, 50370, 50400, 50429,
50459, 50488, 50518, 50547, 50576, 50606, 50635, 50665, 50694, 50724, 50754, 50784, 50813, 50843, 50872, 50902, 50931, 50960, 50990, 51019,
51049, 51078, 51108, 51138, 51167, 51197, 51227, 51256, 51286, 51315, 51345, 51374, 51403, 51433, 51462, 51492, 51522, 51552, 51582, 51611,
51641, 51670, 51699, 51729, 51758, 51787, 51816, 51846, 51876, 51906, 51936, 51965, 51995, 52025, 52054, 52083, 52113, 52142, 52171, 52200,
52230, 52260, 52290, 52319, 52349, 52379, 52408, 52438, 52467, 52497, 52526, 52555, 52585, 52614, 52644, 52673, 52703, 52733, 52762, 52792,
52822, 52851, 52881, 52910, 52939, 52969, 52998, 53028, 53057, 53087, 53116, 53146, 53176, 53205, 53235, 53264, 53294, 53324, 53353, 53383,
53412, 53441, 53471, 53500, 53530, 53559, 53589, 53619, 53648, 53678, 53708, 53737, 53767, 53796, 53825, 53855, 53884, 53913, 53943, 53973,
54003, 54032, 54062, 54092, 54121, 54151, 54180, 54209, 54239, 54268, 54297, 54327, 54357, 54387, 54416, 54446, 54476, 54505, 54535, 54564,
54593, 54623, 54652, 54681, 54711, 54741, 54770, 54800, 54830, 54859, 54889, 54919, 54948, 54977, 55007, 55036, 55066, 55095, 55125, 55154,
55184, 55213, 55243, 55273, 55302, 55332, 55361, 55391, 55420, 55450, 55479, 55508, 55538, 55567, 55597, 55627, 55657, 55686, 55716, 55745,
55775, 55804, 55834, 55863, 55892, 55922, 55951, 55981, 56011, 56040, 56070, 56100, 56129, 56159, 56188, 56218, 56247, 56276, 56306, 56335,
56365, 56394, 56424, 56454, 56483, 56513, 56543, 56572, 56601, 56631, 56660, 56690, 56719, 56749, 56778, 56808, 56837, 56867, 56897, 56926,
56956, 56985, 57015, 57044, 57074, 57103, 57133, 57162, 57192, 57221, 57251, 57280, 57310, 57340, 57369, 57399, 57429, 57458, 57487, 57517,
57546, 57576, 57605, 57634, 57664, 57694, 57723, 57753, 57783, 57813, 57842, 57871, 57901, 57930, 57959, 57989, 58018, 58048, 58077, 58107,
58137, 58167, 58196, 58226, 58255, 58285, 58314, 58343, 58373, 58402, 58432, 58461, 58491, 58521, 58551, 58580, 58610, 58639, 58669, 58698,
58727, 58757, 58786, 58816, 58845, 58875, 58905, 58934, 58964, 58994, 59023, 59053, 59082, 59111, 59141, 59170, 59200, 59229, 59259, 59288,
59318, 59348, 59377, 59407, 59436, 59466, 59495, 59525, 59554, 59584, 59613, 59643, 59672, 59702, 59731, 59761, 59791, 59820, 59850, 59879,
59909, 59939, 59968, 59997, 60027, 60056, 60086, 60115, 60145, 60174, 60204, 60234, 60264, 60293, 60323, 60352, 60381, 60411, 60440, 60469,
60499, 60528, 60558, 60588, 60618, 60648, 60677, 60707, 60736, 60765, 60795, 60824, 60853, 60883, 60912, 60942, 60972, 61002, 61031, 61061,
61090, 61120, 61149, 61179, 61208, 61237, 61267, 61296, 61326, 61356, 61385, 61415, 61445, 61474, 61504, 61533, 61563, 61592, 61621, 61651,
61680, 61710, 61739, 61769, 61799, 61828, 61858, 61888, 61917, 61947, 61976, 62006, 62035, 62064, 62094, 62123, 62153, 62182, 62212, 62242,
62271, 62301, 62331, 62360, 62390, 62419, 62448, 62478, 62507, 62537, 62566, 62596, 62625, 62655, 62685, 62715, 62744, 62774, 62803, 62832,
62862, 62891, 62921, 62950, 62980, 63009, 63039, 63069, 63099, 63128, 63157, 63187, 63216, 63246, 63275, 63305, 63334, 63363, 63393, 63423,
63453, 63482, 63512, 63541, 63571, 63600, 63630, 63659, 63689, 63718, 63747, 63777, 63807, 63836, 63866, 63895, 63925, 63955, 63984, 64014,
64043, 64073, 64102, 64131, 64161, 64190, 64220, 64249, 64279, 64309, 64339, 64368, 64398, 64427, 64457, 64486, 64515, 64545, 64574, 64603,
64633, 64663, 64692, 64722, 64752, 64782, 64811, 64841, 64870, 64899, 64929, 64958, 64987, 65017, 65047, 65076, 65106, 65136, 65166, 65195,
65225, 65254, 65283, 65313, 65342, 65371, 65401, 65431, 65460, 65490, 65520, 65549, 65579, 65608, 65638, 65667, 65697, 65726, 65755, 65785,
65815, 65844, 65874, 65903, 65933, 65963, 65992, 66022, 66051, 66081, 66110, 66140, 66169, 66199, 66228, 66258, 66287, 66317, 66346, 66376,
66405, 66435, 66465, 66494, 66524, 66553, 66583, 66612, 66641, 66671, 66700, 66730, 66760, 66789, 66819, 66849, 66878, 66908, 66937, 66967,
66996, 67025, 67055, 67084, 67114, 67143, 67173, 67203, 67233, 67262, 67292, 67321, 67351, 67380, 67409, 67439, 67468, 67497, 67527, 67557,
67587, 67617, 67646, 67676, 67705, 67735, 67764, 67793, 67823, 67852, 67882, 67911, 67941, 67971, 68000, 68030, 68060, 68089, 68119, 68148,
68177, 68207, 68236, 68266, 68295, 68325, 68354, 68384, 68414, 68443, 68473, 68502, 68532, 68561, 68591, 68620, 68650, 68679, 68708, 68738,
68768, 68797, 68827, 68857, 68886, 68916, 68946, 68975, 69004, 69034, 69063, 69092, 69122, 69152, 69181, 69211, 69240, 69270, 69300, 69330,
69359, 69388, 69418, 69447, 69476, 69506, 69535, 69565, 69595, 69624, 69654, 69684, 69713, 69743, 69772, 69802, 69831, 69861, 69890, 69919,
69949, 69978, 70008, 70038, 70067, 70097, 70126, 70156, 70186, 70215, 70245, 70274, 70303, 70333, 70362, 70392, 70421, 70451, 70481, 70510,
70540, 70570, 70599, 70629, 70658, 70687, 70717, 70746, 70776, 70805, 70835, 70864, 70894, 70924, 70954, 70983, 71013, 71042, 71071, 71101,
71130, 71159, 71189, 71218, 71248, 71278, 71308, 71337, 71367, 71397, 71426, 71455, 71485, 71514, 71543, 71573, 71602, 71632, 71662, 71691,
71721, 71751, 71781, 71810, 71839, 71869, 71898, 71927, 71957, 71986, 72016, 72046, 72075, 72105, 72135, 72164, 72194, 72223, 72253, 72282,
72311, 72341, 72370, 72400, 72429, 72459, 72489, 72518, 72548, 72577, 72607, 72637, 72666, 72695, 72725, 72754, 72784, 72813, 72843, 72872,
72902, 72931, 72961, 72991, 73020, 73050, 73080, 73109, 73139, 73168, 73197, 73227, 73256, 73286, 73315, 73345, 73375, 73404, 73434, 73464,
73493, 73523, 73552, 73581, 73611, 73640, 73669, 73699, 73729, 73758, 73788, 73818, 73848, 73877, 73907, 73936, 73965, 73995, 74024, 74053,
74083, 74113, 74142, 74172, 74202, 74231, 74261, 74291, 74320, 74349, 74379, 74408, 74437, 74467, 74497, 74526, 74556, 74586, 74615, 74645,
74675, 74704, 74733, 74763, 74792, 74822, 74851, 74881, 74910, 74940, 74969, 74999, 75029, 75058, 75088, 75117, 75147, 75176, 75206, 75235,
75264, 75294, 75323, 75353, 75383, 75412, 75442, 75472, 75501, 75531, 75560, 75590, 75619, 75648, 75678, 75707, 75737, 75766, 75796, 75826,
75856, 75885, 75915, 75944, 75974, 76003, 76032, 76062, 76091, 76121, 76150, 76180, 76210, 76239, 76269, 76299, 76328, 76358, 76387, 76416,
76446, 76475, 76505, 76534, 76564, 76593, 76623, 76653, 76682, 76712, 76741, 76771, 76801, 76830, 76859, 76889, 76918, 76948, 76977, 77007,
77036, 77066, 77096, 77125, 77155, 77185, 77214, 77243, 77273, 77302, 77332, 77361, 77390, 77420, 77450, 77479, 77509, 77539, 77569, 77598,
77627, 77657, 77686, 77715, 77745, 77774, 77804, 77833, 77863, 77893, 77923, 77952, 77982, 78011, 78041, 78070, 78099, 78129, 78158, 78188,
78217, 78247, 78277, 78307, 78336, 78366, 78395, 78425, 78454, 78483, 78513, 78542, 78572, 78601, 78631, 78661, 78690, 78720, 78750, 78779,
78808, 78838, 78867, 78897, 78926, 78956, 78985, 79015, 79044, 79074, 79104, 79133, 79163, 79192, 79222, 79251, 79281, 79310, 79340, 79369,
79399, 79428, 79458, 79487, 79517, 79546, 79576, 79606, 79635, 79665, 79695, 79724, 79753, 79783, 79812, 79841, 79871, 79900, 79930, 79960,
79990];
/***/ }),
/***/ 8700:
/***/ (function(module, __unused_webpack_exports, __webpack_require__) {
/*
* World Calendars
* https://github.com/alexcjohnson/world-calendars
*
* Batch-converted from kbwood/calendars
* Many thanks to Keith Wood and all of the contributors to the original project!
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* http://keith-wood.name/calendars.html
Calendars for jQuery v2.0.2.
Written by Keith Wood (wood.keith{at}optusnet.com.au) August 2009.
Available under the MIT (http://keith-wood.name/licence.html) license.
Please attribute the author if you use it. */
var assign = __webpack_require__(896);
function Calendars() {
this.regionalOptions = [];
this.regionalOptions[''] = {
invalidCalendar: 'Calendar {0} not found',
invalidDate: 'Invalid {0} date',
invalidMonth: 'Invalid {0} month',
invalidYear: 'Invalid {0} year',
differentCalendars: 'Cannot mix {0} and {1} dates'
};
this.local = this.regionalOptions[''];
this.calendars = {};
this._localCals = {};
}
/** Create the calendars plugin.
Provides support for various world calendars in a consistent manner.
@class Calendars
@example _exports.instance('julian').newDate(2014, 12, 25) */
assign(Calendars.prototype, {
/** Obtain a calendar implementation and localisation.
@memberof Calendars
@param [name='gregorian'] {string} The name of the calendar, e.g. 'gregorian', 'persian', 'islamic'.
@param [language=''] {string} The language code to use for localisation (default is English).
@return {Calendar} The calendar and localisation.
@throws Error if calendar not found. */
instance: function(name, language) {
name = (name || 'gregorian').toLowerCase();
language = language || '';
var cal = this._localCals[name + '-' + language];
if (!cal && this.calendars[name]) {
cal = new this.calendars[name](language);
this._localCals[name + '-' + language] = cal;
}
if (!cal) {
throw (this.local.invalidCalendar || this.regionalOptions[''].invalidCalendar).
replace(/\{0\}/, name);
}
return cal;
},
/** Create a new date - for today if no other parameters given.
@memberof Calendars
@param year {CDate|number} The date to copy or the year for the date.
@param [month] {number} The month for the date.
@param [day] {number} The day for the date.
@param [calendar='gregorian'] {BaseCalendar|string} The underlying calendar or the name of the calendar.
@param [language=''] {string} The language to use for localisation (default English).
@return {CDate} The new date.
@throws Error if an invalid date. */
newDate: function(year, month, day, calendar, language) {
calendar = (year != null && year.year ? year.calendar() : (typeof calendar === 'string' ?
this.instance(calendar, language) : calendar)) || this.instance();
return calendar.newDate(year, month, day);
},
/** A simple digit substitution function for localising numbers via the Calendar digits option.
@member Calendars
@param digits {string[]} The substitute digits, for 0 through 9.
@return {function} The substitution function. */
substituteDigits: function(digits) {
return function(value) {
return (value + '').replace(/[0-9]/g, function(digit) {
return digits[digit];
});
}
},
/** Digit substitution function for localising Chinese style numbers via the Calendar digits option.
@member Calendars
@param digits {string[]} The substitute digits, for 0 through 9.
@param powers {string[]} The characters denoting powers of 10, i.e. 1, 10, 100, 1000.
@return {function} The substitution function. */
substituteChineseDigits: function(digits, powers) {
return function(value) {
var localNumber = '';
var power = 0;
while (value > 0) {
var units = value % 10;
localNumber = (units === 0 ? '' : digits[units] + powers[power]) + localNumber;
power++;
value = Math.floor(value / 10);
}
if (localNumber.indexOf(digits[1] + powers[1]) === 0) {
localNumber = localNumber.substr(1);
}
return localNumber || digits[0];
}
}
});
/** Generic date, based on a particular calendar.
@class CDate
@param calendar {BaseCalendar} The underlying calendar implementation.
@param year {number} The year for this date.
@param month {number} The month for this date.
@param day {number} The day for this date.
@return {CDate} The date object.
@throws Error if an invalid date. */
function CDate(calendar, year, month, day) {
this._calendar = calendar;
this._year = year;
this._month = month;
this._day = day;
if (this._calendar._validateLevel === 0 &&
!this._calendar.isValid(this._year, this._month, this._day)) {
throw (_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate).
replace(/\{0\}/, this._calendar.local.name);
}
}
/** Pad a numeric value with leading zeroes.
@private
@param value {number} The number to format.
@param length {number} The minimum length.
@return {string} The formatted number. */
function pad(value, length) {
value = '' + value;
return '000000'.substring(0, length - value.length) + value;
}
assign(CDate.prototype, {
/** Create a new date.
@memberof CDate
@param [year] {CDate|number} The date to copy or the year for the date (default this date).
@param [month] {number} The month for the date.
@param [day] {number} The day for the date.
@return {CDate} The new date.
@throws Error if an invalid date. */
newDate: function(year, month, day) {
return this._calendar.newDate((year == null ? this : year), month, day);
},
/** Set or retrieve the year for this date.
@memberof CDate
@param [year] {number} The year for the date.
@return {number|CDate} The date's year (if no parameter) or the updated date.
@throws Error if an invalid date. */
year: function(year) {
return (arguments.length === 0 ? this._year : this.set(year, 'y'));
},
/** Set or retrieve the month for this date.
@memberof CDate
@param [month] {number} The month for the date.
@return {number|CDate} The date's month (if no parameter) or the updated date.
@throws Error if an invalid date. */
month: function(month) {
return (arguments.length === 0 ? this._month : this.set(month, 'm'));
},
/** Set or retrieve the day for this date.
@memberof CDate
@param [day] {number} The day for the date.
@return {number|CData} The date's day (if no parameter) or the updated date.
@throws Error if an invalid date. */
day: function(day) {
return (arguments.length === 0 ? this._day : this.set(day, 'd'));
},
/** Set new values for this date.
@memberof CDate
@param year {number} The year for the date.
@param month {number} The month for the date.
@param day {number} The day for the date.
@return {CDate} The updated date.
@throws Error if an invalid date. */
date: function(year, month, day) {
if (!this._calendar.isValid(year, month, day)) {
throw (_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate).
replace(/\{0\}/, this._calendar.local.name);
}
this._year = year;
this._month = month;
this._day = day;
return this;
},
/** Determine whether this date is in a leap year.
@memberof CDate
@return {boolean} true
if this is a leap year, false
if not. */
leapYear: function() {
return this._calendar.leapYear(this);
},
/** Retrieve the epoch designator for this date, e.g. BCE or CE.
@memberof CDate
@return {string} The current epoch. */
epoch: function() {
return this._calendar.epoch(this);
},
/** Format the year, if not a simple sequential number.
@memberof CDate
@return {string} The formatted year. */
formatYear: function() {
return this._calendar.formatYear(this);
},
/** Retrieve the month of the year for this date,
i.e. the month's position within a numbered year.
@memberof CDate
@return {number} The month of the year: minMonth
to months per year. */
monthOfYear: function() {
return this._calendar.monthOfYear(this);
},
/** Retrieve the week of the year for this date.
@memberof CDate
@return {number} The week of the year: 1 to weeks per year. */
weekOfYear: function() {
return this._calendar.weekOfYear(this);
},
/** Retrieve the number of days in the year for this date.
@memberof CDate
@return {number} The number of days in this year. */
daysInYear: function() {
return this._calendar.daysInYear(this);
},
/** Retrieve the day of the year for this date.
@memberof CDate
@return {number} The day of the year: 1 to days per year. */
dayOfYear: function() {
return this._calendar.dayOfYear(this);
},
/** Retrieve the number of days in the month for this date.
@memberof CDate
@return {number} The number of days. */
daysInMonth: function() {
return this._calendar.daysInMonth(this);
},
/** Retrieve the day of the week for this date.
@memberof CDate
@return {number} The day of the week: 0 to number of days - 1. */
dayOfWeek: function() {
return this._calendar.dayOfWeek(this);
},
/** Determine whether this date is a week day.
@memberof CDate
@return {boolean} true
if a week day, false
if not. */
weekDay: function() {
return this._calendar.weekDay(this);
},
/** Retrieve additional information about this date.
@memberof CDate
@return {object} Additional information - contents depends on calendar. */
extraInfo: function() {
return this._calendar.extraInfo(this);
},
/** Add period(s) to a date.
@memberof CDate
@param offset {number} The number of periods to adjust by.
@param period {string} One of 'y' for year, 'm' for month, 'w' for week, 'd' for day.
@return {CDate} The updated date. */
add: function(offset, period) {
return this._calendar.add(this, offset, period);
},
/** Set a portion of the date.
@memberof CDate
@param value {number} The new value for the period.
@param period {string} One of 'y' for year, 'm' for month, 'd' for day.
@return {CDate} The updated date.
@throws Error if not a valid date. */
set: function(value, period) {
return this._calendar.set(this, value, period);
},
/** Compare this date to another date.
@memberof CDate
@param date {CDate} The other date.
@return {number} -1 if this date is before the other date,
0 if they are equal, or +1 if this date is after the other date. */
compareTo: function(date) {
if (this._calendar.name !== date._calendar.name) {
throw (_exports.local.differentCalendars || _exports.regionalOptions[''].differentCalendars).
replace(/\{0\}/, this._calendar.local.name).replace(/\{1\}/, date._calendar.local.name);
}
var c = (this._year !== date._year ? this._year - date._year :
this._month !== date._month ? this.monthOfYear() - date.monthOfYear() :
this._day - date._day);
return (c === 0 ? 0 : (c < 0 ? -1 : +1));
},
/** Retrieve the calendar backing this date.
@memberof CDate
@return {BaseCalendar} The calendar implementation. */
calendar: function() {
return this._calendar;
},
/** Retrieve the Julian date equivalent for this date,
i.e. days since January 1, 4713 BCE Greenwich noon.
@memberof CDate
@return {number} The equivalent Julian date. */
toJD: function() {
return this._calendar.toJD(this);
},
/** Create a new date from a Julian date.
@memberof CDate
@param jd {number} The Julian date to convert.
@return {CDate} The equivalent date. */
fromJD: function(jd) {
return this._calendar.fromJD(jd);
},
/** Convert this date to a standard (Gregorian) JavaScript Date.
@memberof CDate
@return {Date} The equivalent JavaScript date. */
toJSDate: function() {
return this._calendar.toJSDate(this);
},
/** Create a new date from a standard (Gregorian) JavaScript Date.
@memberof CDate
@param jsd {Date} The JavaScript date to convert.
@return {CDate} The equivalent date. */
fromJSDate: function(jsd) {
return this._calendar.fromJSDate(jsd);
},
/** Convert to a string for display.
@memberof CDate
@return {string} This date as a string. */
toString: function() {
return (this.year() < 0 ? '-' : '') + pad(Math.abs(this.year()), 4) +
'-' + pad(this.month(), 2) + '-' + pad(this.day(), 2);
}
});
/** Basic functionality for all calendars.
Other calendars should extend this:
OtherCalendar.prototype = new BaseCalendar;
@class BaseCalendar */
function BaseCalendar() {
this.shortYearCutoff = '+10';
}
assign(BaseCalendar.prototype, {
_validateLevel: 0, // "Stack" to turn validation on/off
/** Create a new date within this calendar - today if no parameters given.
@memberof BaseCalendar
@param year {CDate|number} The date to duplicate or the year for the date.
@param [month] {number} The month for the date.
@param [day] {number} The day for the date.
@return {CDate} The new date.
@throws Error if not a valid date or a different calendar used. */
newDate: function(year, month, day) {
if (year == null) {
return this.today();
}
if (year.year) {
this._validate(year, month, day,
_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);
day = year.day();
month = year.month();
year = year.year();
}
return new CDate(this, year, month, day);
},
/** Create a new date for today.
@memberof BaseCalendar
@return {CDate} Today's date. */
today: function() {
return this.fromJSDate(new Date());
},
/** Retrieve the epoch designator for this date.
@memberof BaseCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {string} The current epoch.
@throws Error if an invalid year or a different calendar used. */
epoch: function(year) {
var date = this._validate(year, this.minMonth, this.minDay,
_exports.local.invalidYear || _exports.regionalOptions[''].invalidYear);
return (date.year() < 0 ? this.local.epochs[0] : this.local.epochs[1]);
},
/** Format the year, if not a simple sequential number
@memberof BaseCalendar
@param year {CDate|number} The date to format or the year to format.
@return {string} The formatted year.
@throws Error if an invalid year or a different calendar used. */
formatYear: function(year) {
var date = this._validate(year, this.minMonth, this.minDay,
_exports.local.invalidYear || _exports.regionalOptions[''].invalidYear);
return (date.year() < 0 ? '-' : '') + pad(Math.abs(date.year()), 4)
},
/** Retrieve the number of months in a year.
@memberof BaseCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {number} The number of months.
@throws Error if an invalid year or a different calendar used. */
monthsInYear: function(year) {
this._validate(year, this.minMonth, this.minDay,
_exports.local.invalidYear || _exports.regionalOptions[''].invalidYear);
return 12;
},
/** Calculate the month's ordinal position within the year -
for those calendars that don't start at month 1!
@memberof BaseCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param month {number} The month to examine.
@return {number} The ordinal position, starting from minMonth
.
@throws Error if an invalid year/month or a different calendar used. */
monthOfYear: function(year, month) {
var date = this._validate(year, month, this.minDay,
_exports.local.invalidMonth || _exports.regionalOptions[''].invalidMonth);
return (date.month() + this.monthsInYear(date) - this.firstMonth) %
this.monthsInYear(date) + this.minMonth;
},
/** Calculate actual month from ordinal position, starting from minMonth.
@memberof BaseCalendar
@param year {number} The year to examine.
@param ord {number} The month's ordinal position.
@return {number} The month's number.
@throws Error if an invalid year/month. */
fromMonthOfYear: function(year, ord) {
var m = (ord + this.firstMonth - 2 * this.minMonth) %
this.monthsInYear(year) + this.minMonth;
this._validate(year, m, this.minDay,
_exports.local.invalidMonth || _exports.regionalOptions[''].invalidMonth);
return m;
},
/** Retrieve the number of days in a year.
@memberof BaseCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {number} The number of days.
@throws Error if an invalid year or a different calendar used. */
daysInYear: function(year) {
var date = this._validate(year, this.minMonth, this.minDay,
_exports.local.invalidYear || _exports.regionalOptions[''].invalidYear);
return (this.leapYear(date) ? 366 : 365);
},
/** Retrieve the day of the year for a date.
@memberof BaseCalendar
@param year {CDate|number} The date to convert or the year to convert.
@param [month] {number} The month to convert.
@param [day] {number} The day to convert.
@return {number} The day of the year.
@throws Error if an invalid date or a different calendar used. */
dayOfYear: function(year, month, day) {
var date = this._validate(year, month, day,
_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);
return date.toJD() - this.newDate(date.year(),
this.fromMonthOfYear(date.year(), this.minMonth), this.minDay).toJD() + 1;
},
/** Retrieve the number of days in a week.
@memberof BaseCalendar
@return {number} The number of days. */
daysInWeek: function() {
return 7;
},
/** Retrieve the day of the week for a date.
@memberof BaseCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {number} The day of the week: 0 to number of days - 1.
@throws Error if an invalid date or a different calendar used. */
dayOfWeek: function(year, month, day) {
var date = this._validate(year, month, day,
_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);
return (Math.floor(this.toJD(date)) + 2) % this.daysInWeek();
},
/** Retrieve additional information about a date.
@memberof BaseCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {object} Additional information - contents depends on calendar.
@throws Error if an invalid date or a different calendar used. */
extraInfo: function(year, month, day) {
this._validate(year, month, day,
_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);
return {};
},
/** Add period(s) to a date.
Cater for no year zero.
@memberof BaseCalendar
@param date {CDate} The starting date.
@param offset {number} The number of periods to adjust by.
@param period {string} One of 'y' for year, 'm' for month, 'w' for week, 'd' for day.
@return {CDate} The updated date.
@throws Error if a different calendar used. */
add: function(date, offset, period) {
this._validate(date, this.minMonth, this.minDay,
_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);
return this._correctAdd(date, this._add(date, offset, period), offset, period);
},
/** Add period(s) to a date.
@memberof BaseCalendar
@private
@param date {CDate} The starting date.
@param offset {number} The number of periods to adjust by.
@param period {string} One of 'y' for year, 'm' for month, 'w' for week, 'd' for day.
@return {CDate} The updated date. */
_add: function(date, offset, period) {
this._validateLevel++;
if (period === 'd' || period === 'w') {
var jd = date.toJD() + offset * (period === 'w' ? this.daysInWeek() : 1);
var d = date.calendar().fromJD(jd);
this._validateLevel--;
return [d.year(), d.month(), d.day()];
}
try {
var y = date.year() + (period === 'y' ? offset : 0);
var m = date.monthOfYear() + (period === 'm' ? offset : 0);
var d = date.day();// + (period === 'd' ? offset : 0) +
//(period === 'w' ? offset * this.daysInWeek() : 0);
var resyncYearMonth = function(calendar) {
while (m < calendar.minMonth) {
y--;
m += calendar.monthsInYear(y);
}
var yearMonths = calendar.monthsInYear(y);
while (m > yearMonths - 1 + calendar.minMonth) {
y++;
m -= yearMonths;
yearMonths = calendar.monthsInYear(y);
}
};
if (period === 'y') {
if (date.month() !== this.fromMonthOfYear(y, m)) { // Hebrew
m = this.newDate(y, date.month(), this.minDay).monthOfYear();
}
m = Math.min(m, this.monthsInYear(y));
d = Math.min(d, this.daysInMonth(y, this.fromMonthOfYear(y, m)));
}
else if (period === 'm') {
resyncYearMonth(this);
d = Math.min(d, this.daysInMonth(y, this.fromMonthOfYear(y, m)));
}
var ymd = [y, this.fromMonthOfYear(y, m), d];
this._validateLevel--;
return ymd;
}
catch (e) {
this._validateLevel--;
throw e;
}
},
/** Correct a candidate date after adding period(s) to a date.
Handle no year zero if necessary.
@memberof BaseCalendar
@private
@param date {CDate} The starting date.
@param ymd {number[]} The added date.
@param offset {number} The number of periods to adjust by.
@param period {string} One of 'y' for year, 'm' for month, 'w' for week, 'd' for day.
@return {CDate} The updated date. */
_correctAdd: function(date, ymd, offset, period) {
if (!this.hasYearZero && (period === 'y' || period === 'm')) {
if (ymd[0] === 0 || // In year zero
(date.year() > 0) !== (ymd[0] > 0)) { // Crossed year zero
var adj = {y: [1, 1, 'y'], m: [1, this.monthsInYear(-1), 'm'],
w: [this.daysInWeek(), this.daysInYear(-1), 'd'],
d: [1, this.daysInYear(-1), 'd']}[period];
var dir = (offset < 0 ? -1 : +1);
ymd = this._add(date, offset * adj[0] + dir * adj[1], adj[2]);
}
}
return date.date(ymd[0], ymd[1], ymd[2]);
},
/** Set a portion of the date.
@memberof BaseCalendar
@param date {CDate} The starting date.
@param value {number} The new value for the period.
@param period {string} One of 'y' for year, 'm' for month, 'd' for day.
@return {CDate} The updated date.
@throws Error if an invalid date or a different calendar used. */
set: function(date, value, period) {
this._validate(date, this.minMonth, this.minDay,
_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);
var y = (period === 'y' ? value : date.year());
var m = (period === 'm' ? value : date.month());
var d = (period === 'd' ? value : date.day());
if (period === 'y' || period === 'm') {
d = Math.min(d, this.daysInMonth(y, m));
}
return date.date(y, m, d);
},
/** Determine whether a date is valid for this calendar.
@memberof BaseCalendar
@param year {number} The year to examine.
@param month {number} The month to examine.
@param day {number} The day to examine.
@return {boolean} true
if a valid date, false
if not. */
isValid: function(year, month, day) {
this._validateLevel++;
var valid = (this.hasYearZero || year !== 0);
if (valid) {
var date = this.newDate(year, month, this.minDay);
valid = (month >= this.minMonth && month - this.minMonth < this.monthsInYear(date)) &&
(day >= this.minDay && day - this.minDay < this.daysInMonth(date));
}
this._validateLevel--;
return valid;
},
/** Convert the date to a standard (Gregorian) JavaScript Date.
@memberof BaseCalendar
@param year {CDate|number} The date to convert or the year to convert.
@param [month] {number} The month to convert.
@param [day] {number} The day to convert.
@return {Date} The equivalent JavaScript date.
@throws Error if an invalid date or a different calendar used. */
toJSDate: function(year, month, day) {
var date = this._validate(year, month, day,
_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);
return _exports.instance().fromJD(this.toJD(date)).toJSDate();
},
/** Convert the date from a standard (Gregorian) JavaScript Date.
@memberof BaseCalendar
@param jsd {Date} The JavaScript date.
@return {CDate} The equivalent calendar date. */
fromJSDate: function(jsd) {
return this.fromJD(_exports.instance().fromJSDate(jsd).toJD());
},
/** Check that a candidate date is from the same calendar and is valid.
@memberof BaseCalendar
@private
@param year {CDate|number} The date to validate or the year to validate.
@param [month] {number} The month to validate.
@param [day] {number} The day to validate.
@param error {string} Rrror message if invalid.
@throws Error if different calendars used or invalid date. */
_validate: function(year, month, day, error) {
if (year.year) {
if (this._validateLevel === 0 && this.name !== year.calendar().name) {
throw (_exports.local.differentCalendars || _exports.regionalOptions[''].differentCalendars).
replace(/\{0\}/, this.local.name).replace(/\{1\}/, year.calendar().local.name);
}
return year;
}
try {
this._validateLevel++;
if (this._validateLevel === 1 && !this.isValid(year, month, day)) {
throw error.replace(/\{0\}/, this.local.name);
}
var date = this.newDate(year, month, day);
this._validateLevel--;
return date;
}
catch (e) {
this._validateLevel--;
throw e;
}
}
});
/** Implementation of the Proleptic Gregorian Calendar.
See http://en.wikipedia.org/wiki/Gregorian_calendar
and http://en.wikipedia.org/wiki/Proleptic_Gregorian_calendar.
@class GregorianCalendar
@augments BaseCalendar
@param [language=''] {string} The language code (default English) for localisation. */
function GregorianCalendar(language) {
this.local = this.regionalOptions[language] || this.regionalOptions[''];
}
GregorianCalendar.prototype = new BaseCalendar;
assign(GregorianCalendar.prototype, {
/** The calendar name.
@memberof GregorianCalendar */
name: 'Gregorian',
/** Julian date of start of Gregorian epoch: 1 January 0001 CE.
@memberof GregorianCalendar */
jdEpoch: 1721425.5,
/** Days per month in a common year.
@memberof GregorianCalendar */
daysPerMonth: [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31],
/** true
if has a year zero, false
if not.
@memberof GregorianCalendar */
hasYearZero: false,
/** The minimum month number.
@memberof GregorianCalendar */
minMonth: 1,
/** The first month in the year.
@memberof GregorianCalendar */
firstMonth: 1,
/** The minimum day number.
@memberof GregorianCalendar */
minDay: 1,
/** Localisations for the plugin.
Entries are objects indexed by the language code ('' being the default US/English).
Each object has the following attributes.
@memberof GregorianCalendar
@property name {string} The calendar name.
@property epochs {string[]} The epoch names.
@property monthNames {string[]} The long names of the months of the year.
@property monthNamesShort {string[]} The short names of the months of the year.
@property dayNames {string[]} The long names of the days of the week.
@property dayNamesShort {string[]} The short names of the days of the week.
@property dayNamesMin {string[]} The minimal names of the days of the week.
@property dateFormat {string} The date format for this calendar.
See the options on formatDate
for details.
@property firstDay {number} The number of the first day of the week, starting at 0.
@property isRTL {number} true
if this localisation reads right-to-left. */
regionalOptions: { // Localisations
'': {
name: 'Gregorian',
epochs: ['BCE', 'CE'],
monthNames: ['January', 'February', 'March', 'April', 'May', 'June',
'July', 'August', 'September', 'October', 'November', 'December'],
monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'],
dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'],
dayNamesMin: ['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa'],
digits: null,
dateFormat: 'mm/dd/yyyy',
firstDay: 0,
isRTL: false
}
},
/** Determine whether this date is in a leap year.
@memberof GregorianCalendar
@param year {CDate|number} The date to examine or the year to examine.
@return {boolean} true
if this is a leap year, false
if not.
@throws Error if an invalid year or a different calendar used. */
leapYear: function(year) {
var date = this._validate(year, this.minMonth, this.minDay,
_exports.local.invalidYear || _exports.regionalOptions[''].invalidYear);
var year = date.year() + (date.year() < 0 ? 1 : 0); // No year zero
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
},
/** Determine the week of the year for a date - ISO 8601.
@memberof GregorianCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {number} The week of the year, starting from 1.
@throws Error if an invalid date or a different calendar used. */
weekOfYear: function(year, month, day) {
// Find Thursday of this week starting on Monday
var checkDate = this.newDate(year, month, day);
checkDate.add(4 - (checkDate.dayOfWeek() || 7), 'd');
return Math.floor((checkDate.dayOfYear() - 1) / 7) + 1;
},
/** Retrieve the number of days in a month.
@memberof GregorianCalendar
@param year {CDate|number} The date to examine or the year of the month.
@param [month] {number} The month.
@return {number} The number of days in this month.
@throws Error if an invalid month/year or a different calendar used. */
daysInMonth: function(year, month) {
var date = this._validate(year, month, this.minDay,
_exports.local.invalidMonth || _exports.regionalOptions[''].invalidMonth);
return this.daysPerMonth[date.month() - 1] +
(date.month() === 2 && this.leapYear(date.year()) ? 1 : 0);
},
/** Determine whether this date is a week day.
@memberof GregorianCalendar
@param year {CDate|number} The date to examine or the year to examine.
@param [month] {number} The month to examine.
@param [day] {number} The day to examine.
@return {boolean} true
if a week day, false
if not.
@throws Error if an invalid date or a different calendar used. */
weekDay: function(year, month, day) {
return (this.dayOfWeek(year, month, day) || 7) < 6;
},
/** Retrieve the Julian date equivalent for this date,
i.e. days since January 1, 4713 BCE Greenwich noon.
@memberof GregorianCalendar
@param year {CDate|number} The date to convert or the year to convert.
@param [month] {number} The month to convert.
@param [day] {number} The day to convert.
@return {number} The equivalent Julian date.
@throws Error if an invalid date or a different calendar used. */
toJD: function(year, month, day) {
var date = this._validate(year, month, day,
_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);
year = date.year();
month = date.month();
day = date.day();
if (year < 0) { year++; } // No year zero
// Jean Meeus algorithm, "Astronomical Algorithms", 1991
if (month < 3) {
month += 12;
year--;
}
var a = Math.floor(year / 100);
var b = 2 - a + Math.floor(a / 4);
return Math.floor(365.25 * (year + 4716)) +
Math.floor(30.6001 * (month + 1)) + day + b - 1524.5;
},
/** Create a new date from a Julian date.
@memberof GregorianCalendar
@param jd {number} The Julian date to convert.
@return {CDate} The equivalent date. */
fromJD: function(jd) {
// Jean Meeus algorithm, "Astronomical Algorithms", 1991
var z = Math.floor(jd + 0.5);
var a = Math.floor((z - 1867216.25) / 36524.25);
a = z + 1 + a - Math.floor(a / 4);
var b = a + 1524;
var c = Math.floor((b - 122.1) / 365.25);
var d = Math.floor(365.25 * c);
var e = Math.floor((b - d) / 30.6001);
var day = b - d - Math.floor(e * 30.6001);
var month = e - (e > 13.5 ? 13 : 1);
var year = c - (month > 2.5 ? 4716 : 4715);
if (year <= 0) { year--; } // No year zero
return this.newDate(year, month, day);
},
/** Convert this date to a standard (Gregorian) JavaScript Date.
@memberof GregorianCalendar
@param year {CDate|number} The date to convert or the year to convert.
@param [month] {number} The month to convert.
@param [day] {number} The day to convert.
@return {Date} The equivalent JavaScript date.
@throws Error if an invalid date or a different calendar used. */
toJSDate: function(year, month, day) {
var date = this._validate(year, month, day,
_exports.local.invalidDate || _exports.regionalOptions[''].invalidDate);
var jsd = new Date(date.year(), date.month() - 1, date.day());
jsd.setHours(0);
jsd.setMinutes(0);
jsd.setSeconds(0);
jsd.setMilliseconds(0);
// Hours may be non-zero on daylight saving cut-over:
// > 12 when midnight changeover, but then cannot generate
// midnight datetime, so jump to 1AM, otherwise reset.
jsd.setHours(jsd.getHours() > 12 ? jsd.getHours() + 2 : 0);
return jsd;
},
/** Create a new date from a standard (Gregorian) JavaScript Date.
@memberof GregorianCalendar
@param jsd {Date} The JavaScript date to convert.
@return {CDate} The equivalent date. */
fromJSDate: function(jsd) {
return this.newDate(jsd.getFullYear(), jsd.getMonth() + 1, jsd.getDate());
}
});
// Singleton manager
var _exports = module.exports = new Calendars();
// Date template
_exports.cdate = CDate;
// Base calendar template
_exports.baseCalendar = BaseCalendar;
// Gregorian calendar implementation
_exports.calendars.gregorian = GregorianCalendar;
/***/ }),
/***/ 5168:
/***/ (function(__unused_webpack_module, __unused_webpack_exports, __webpack_require__) {
/*
* World Calendars
* https://github.com/alexcjohnson/world-calendars
*
* Batch-converted from kbwood/calendars
* Many thanks to Keith Wood and all of the contributors to the original project!
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
/* http://keith-wood.name/calendars.html
Calendars extras for jQuery v2.0.2.
Written by Keith Wood (wood.keith{at}optusnet.com.au) August 2009.
Available under the MIT (http://keith-wood.name/licence.html) license.
Please attribute the author if you use it. */
var assign = __webpack_require__(896);
var main = __webpack_require__(8700);
assign(main.regionalOptions[''], {
invalidArguments: 'Invalid arguments',
invalidFormat: 'Cannot format a date from another calendar',
missingNumberAt: 'Missing number at position {0}',
unknownNameAt: 'Unknown name at position {0}',
unexpectedLiteralAt: 'Unexpected literal at position {0}',
unexpectedText: 'Additional text found at end'
});
main.local = main.regionalOptions[''];
assign(main.cdate.prototype, {
/** Format this date.
Found in the jquery.calendars.plus.js
module.
@memberof CDate
@param [format] {string} The date format to use (see formatDate
).
@param [settings] {object} Options for the formatDate
function.
@return {string} The formatted date. */
formatDate: function(format, settings) {
if (typeof format !== 'string') {
settings = format;
format = '';
}
return this._calendar.formatDate(format || '', this, settings);
}
});
assign(main.baseCalendar.prototype, {
UNIX_EPOCH: main.instance().newDate(1970, 1, 1).toJD(),
SECS_PER_DAY: 24 * 60 * 60,
TICKS_EPOCH: main.instance().jdEpoch, // 1 January 0001 CE
TICKS_PER_DAY: 24 * 60 * 60 * 10000000,
/** Date form for ATOM (RFC 3339/ISO 8601).
Found in the jquery.calendars.plus.js
module.
@memberof BaseCalendar */
ATOM: 'yyyy-mm-dd',
/** Date form for cookies.
Found in the jquery.calendars.plus.js
module.
@memberof BaseCalendar */
COOKIE: 'D, dd M yyyy',
/** Date form for full date.
Found in the jquery.calendars.plus.js
module.
@memberof BaseCalendar */
FULL: 'DD, MM d, yyyy',
/** Date form for ISO 8601.
Found in the jquery.calendars.plus.js
module.
@memberof BaseCalendar */
ISO_8601: 'yyyy-mm-dd',
/** Date form for Julian date.
Found in the jquery.calendars.plus.js
module.
@memberof BaseCalendar */
JULIAN: 'J',
/** Date form for RFC 822.
Found in the jquery.calendars.plus.js
module.
@memberof BaseCalendar */
RFC_822: 'D, d M yy',
/** Date form for RFC 850.
Found in the jquery.calendars.plus.js
module.
@memberof BaseCalendar */
RFC_850: 'DD, dd-M-yy',
/** Date form for RFC 1036.
Found in the jquery.calendars.plus.js
module.
@memberof BaseCalendar */
RFC_1036: 'D, d M yy',
/** Date form for RFC 1123.
Found in the jquery.calendars.plus.js
module.
@memberof BaseCalendar */
RFC_1123: 'D, d M yyyy',
/** Date form for RFC 2822.
Found in the jquery.calendars.plus.js
module.
@memberof BaseCalendar */
RFC_2822: 'D, d M yyyy',
/** Date form for RSS (RFC 822).
Found in the jquery.calendars.plus.js
module.
@memberof BaseCalendar */
RSS: 'D, d M yy',
/** Date form for Windows ticks.
Found in the jquery.calendars.plus.js
module.
@memberof BaseCalendar */
TICKS: '!',
/** Date form for Unix timestamp.
Found in the jquery.calendars.plus.js
module.
@memberof BaseCalendar */
TIMESTAMP: '@',
/** Date form for W3c (ISO 8601).
Found in the jquery.calendars.plus.js
module.
@memberof BaseCalendar */
W3C: 'yyyy-mm-dd',
/** Format a date object into a string value.
The format can be combinations of the following:
- d - day of month (no leading zero)
- dd - day of month (two digit)
- o - day of year (no leading zeros)
- oo - day of year (three digit)
- D - day name short
- DD - day name long
- w - week of year (no leading zero)
- ww - week of year (two digit)
- m - month of year (no leading zero)
- mm - month of year (two digit)
- M - month name short
- MM - month name long
- yy - year (two digit)
- yyyy - year (four digit)
- YYYY - formatted year
- J - Julian date (days since January 1, 4713 BCE Greenwich noon)
- @ - Unix timestamp (s since 01/01/1970)
- ! - Windows ticks (100ns since 01/01/0001)
- '...' - literal text
- '' - single quote
Found in the jquery.calendars.plus.js
module.
@memberof BaseCalendar
@param [format] {string} The desired format of the date (defaults to calendar format).
@param date {CDate} The date value to format.
@param [settings] {object} Addition options, whose attributes include:
@property [dayNamesShort] {string[]} Abbreviated names of the days from Sunday.
@property [dayNames] {string[]} Names of the days from Sunday.
@property [monthNamesShort] {string[]} Abbreviated names of the months.
@property [monthNames] {string[]} Names of the months.
@property [calculateWeek] {CalendarsPickerCalculateWeek} Function that determines week of the year.
@property [localNumbers=false] {boolean} true
to localise numbers (if available),
false
to use normal Arabic numerals.
@return {string} The date in the above format.
@throws Errors if the date is from a different calendar. */
formatDate: function(format, date, settings) {
if (typeof format !== 'string') {
settings = date;
date = format;
format = '';
}
if (!date) {
return '';
}
if (date.calendar() !== this) {
throw main.local.invalidFormat || main.regionalOptions[''].invalidFormat;
}
format = format || this.local.dateFormat;
settings = settings || {};
var dayNamesShort = settings.dayNamesShort || this.local.dayNamesShort;
var dayNames = settings.dayNames || this.local.dayNames;
var monthNumbers = settings.monthNumbers || this.local.monthNumbers;
var monthNamesShort = settings.monthNamesShort || this.local.monthNamesShort;
var monthNames = settings.monthNames || this.local.monthNames;
var calculateWeek = settings.calculateWeek || this.local.calculateWeek;
// Check whether a format character is doubled
var doubled = function(match, step) {
var matches = 1;
while (iFormat + matches < format.length && format.charAt(iFormat + matches) === match) {
matches++;
}
iFormat += matches - 1;
return Math.floor(matches / (step || 1)) > 1;
};
// Format a number, with leading zeroes if necessary
var formatNumber = function(match, value, len, step) {
var num = '' + value;
if (doubled(match, step)) {
while (num.length < len) {
num = '0' + num;
}
}
return num;
};
// Format a name, short or long as requested
var formatName = function(match, value, shortNames, longNames) {
return (doubled(match) ? longNames[value] : shortNames[value]);
};
// Format month number
// (e.g. Chinese calendar needs to account for intercalary months)
var calendar = this;
var formatMonth = function(date) {
return (typeof monthNumbers === 'function') ?
monthNumbers.call(calendar, date, doubled('m')) :
localiseNumbers(formatNumber('m', date.month(), 2));
};
// Format a month name, short or long as requested
var formatMonthName = function(date, useLongName) {
if (useLongName) {
return (typeof monthNames === 'function') ?
monthNames.call(calendar, date) :
monthNames[date.month() - calendar.minMonth];
} else {
return (typeof monthNamesShort === 'function') ?
monthNamesShort.call(calendar, date) :
monthNamesShort[date.month() - calendar.minMonth];
}
};
// Localise numbers if requested and available
var digits = this.local.digits;
var localiseNumbers = function(value) {
return (settings.localNumbers && digits ? digits(value) : value);
};
var output = '';
var literal = false;
for (var iFormat = 0; iFormat < format.length; iFormat++) {
if (literal) {
if (format.charAt(iFormat) === "'" && !doubled("'")) {
literal = false;
}
else {
output += format.charAt(iFormat);
}
}
else {
switch (format.charAt(iFormat)) {
case 'd': output += localiseNumbers(formatNumber('d', date.day(), 2)); break;
case 'D': output += formatName('D', date.dayOfWeek(),
dayNamesShort, dayNames); break;
case 'o': output += formatNumber('o', date.dayOfYear(), 3); break;
case 'w': output += formatNumber('w', date.weekOfYear(), 2); break;
case 'm': output += formatMonth(date); break;
case 'M': output += formatMonthName(date, doubled('M')); break;
case 'y':
output += (doubled('y', 2) ? date.year() :
(date.year() % 100 < 10 ? '0' : '') + date.year() % 100);
break;
case 'Y':
doubled('Y', 2);
output += date.formatYear();
break;
case 'J': output += date.toJD(); break;
case '@': output += (date.toJD() - this.UNIX_EPOCH) * this.SECS_PER_DAY; break;
case '!': output += (date.toJD() - this.TICKS_EPOCH) * this.TICKS_PER_DAY; break;
case "'":
if (doubled("'")) {
output += "'";
}
else {
literal = true;
}
break;
default:
output += format.charAt(iFormat);
}
}
}
return output;
},
/** Parse a string value into a date object.
See formatDate
for the possible formats, plus:
- * - ignore rest of string
Found in the jquery.calendars.plus.js
module.
@memberof BaseCalendar
@param format {string} The expected format of the date ('' for default calendar format).
@param value {string} The date in the above format.
@param [settings] {object} Additional options whose attributes include:
@property [shortYearCutoff] {number} The cutoff year for determining the century.
@property [dayNamesShort] {string[]} Abbreviated names of the days from Sunday.
@property [dayNames] {string[]} Names of the days from Sunday.
@property [monthNamesShort] {string[]} Abbreviated names of the months.
@property [monthNames] {string[]} Names of the months.
@return {CDate} The extracted date value or null
if value is blank.
@throws Errors if the format and/or value are missing,
if the value doesn't match the format, or if the date is invalid. */
parseDate: function(format, value, settings) {
if (value == null) {
throw main.local.invalidArguments || main.regionalOptions[''].invalidArguments;
}
value = (typeof value === 'object' ? value.toString() : value + '');
if (value === '') {
return null;
}
format = format || this.local.dateFormat;
settings = settings || {};
var shortYearCutoff = settings.shortYearCutoff || this.shortYearCutoff;
shortYearCutoff = (typeof shortYearCutoff !== 'string' ? shortYearCutoff :
this.today().year() % 100 + parseInt(shortYearCutoff, 10));
var dayNamesShort = settings.dayNamesShort || this.local.dayNamesShort;
var dayNames = settings.dayNames || this.local.dayNames;
var parseMonth = settings.parseMonth || this.local.parseMonth;
var monthNumbers = settings.monthNumbers || this.local.monthNumbers;
var monthNamesShort = settings.monthNamesShort || this.local.monthNamesShort;
var monthNames = settings.monthNames || this.local.monthNames;
var jd = -1;
var year = -1;
var month = -1;
var day = -1;
var doy = -1;
var shortYear = false;
var literal = false;
// Check whether a format character is doubled
var doubled = function(match, step) {
var matches = 1;
while (iFormat + matches < format.length && format.charAt(iFormat + matches) === match) {
matches++;
}
iFormat += matches - 1;
return Math.floor(matches / (step || 1)) > 1;
};
// Extract a number from the string value
var getNumber = function(match, step) {
var isDoubled = doubled(match, step);
var size = [2, 3, isDoubled ? 4 : 2, isDoubled ? 4 : 2, 10, 11, 20]['oyYJ@!'.indexOf(match) + 1];
var digits = new RegExp('^-?\\d{1,' + size + '}');
var num = value.substring(iValue).match(digits);
if (!num) {
throw (main.local.missingNumberAt || main.regionalOptions[''].missingNumberAt).
replace(/\{0\}/, iValue);
}
iValue += num[0].length;
return parseInt(num[0], 10);
};
// Extract a month number from the string value
var calendar = this;
var getMonthNumber = function() {
if (typeof monthNumbers === 'function') {
doubled('m'); // update iFormat
var month = monthNumbers.call(calendar, value.substring(iValue));
iValue += month.length;
return month;
}
return getNumber('m');
};
// Extract a name from the string value and convert to an index
var getName = function(match, shortNames, longNames, step) {
var names = (doubled(match, step) ? longNames : shortNames);
for (var i = 0; i < names.length; i++) {
if (value.substr(iValue, names[i].length).toLowerCase() === names[i].toLowerCase()) {
iValue += names[i].length;
return i + calendar.minMonth;
}
}
throw (main.local.unknownNameAt || main.regionalOptions[''].unknownNameAt).
replace(/\{0\}/, iValue);
};
// Extract a month number from the string value
var getMonthName = function() {
if (typeof monthNames === 'function') {
var month = doubled('M') ?
monthNames.call(calendar, value.substring(iValue)) :
monthNamesShort.call(calendar, value.substring(iValue));
iValue += month.length;
return month;
}
return getName('M', monthNamesShort, monthNames);
};
// Confirm that a literal character matches the string value
var checkLiteral = function() {
if (value.charAt(iValue) !== format.charAt(iFormat)) {
throw (main.local.unexpectedLiteralAt ||
main.regionalOptions[''].unexpectedLiteralAt).replace(/\{0\}/, iValue);
}
iValue++;
};
var iValue = 0;
for (var iFormat = 0; iFormat < format.length; iFormat++) {
if (literal) {
if (format.charAt(iFormat) === "'" && !doubled("'")) {
literal = false;
}
else {
checkLiteral();
}
}
else {
switch (format.charAt(iFormat)) {
case 'd': day = getNumber('d'); break;
case 'D': getName('D', dayNamesShort, dayNames); break;
case 'o': doy = getNumber('o'); break;
case 'w': getNumber('w'); break;
case 'm': month = getMonthNumber(); break;
case 'M': month = getMonthName(); break;
case 'y':
var iSave = iFormat;
shortYear = !doubled('y', 2);
iFormat = iSave;
year = getNumber('y', 2);
break;
case 'Y': year = getNumber('Y', 2); break;
case 'J':
jd = getNumber('J') + 0.5;
if (value.charAt(iValue) === '.') {
iValue++;
getNumber('J');
}
break;
case '@': jd = getNumber('@') / this.SECS_PER_DAY + this.UNIX_EPOCH; break;
case '!': jd = getNumber('!') / this.TICKS_PER_DAY + this.TICKS_EPOCH; break;
case '*': iValue = value.length; break;
case "'":
if (doubled("'")) {
checkLiteral();
}
else {
literal = true;
}
break;
default: checkLiteral();
}
}
}
if (iValue < value.length) {
throw main.local.unexpectedText || main.regionalOptions[''].unexpectedText;
}
if (year === -1) {
year = this.today().year();
}
else if (year < 100 && shortYear) {
year += (shortYearCutoff === -1 ? 1900 : this.today().year() -
this.today().year() % 100 - (year <= shortYearCutoff ? 0 : 100));
}
if (typeof month === 'string') {
month = parseMonth.call(this, year, month);
}
if (doy > -1) {
month = 1;
day = doy;
for (var dim = this.daysInMonth(year, month); day > dim; dim = this.daysInMonth(year, month)) {
month++;
day -= dim;
}
}
return (jd > -1 ? this.fromJD(jd) : this.newDate(year, month, day));
},
/** A date may be specified as an exact value or a relative one.
Found in the jquery.calendars.plus.js
module.
@memberof BaseCalendar
@param dateSpec {CDate|number|string} The date as an object or string in the given format or
an offset - numeric days from today, or string amounts and periods, e.g. '+1m +2w'.
@param defaultDate {CDate} The date to use if no other supplied, may be null
.
@param currentDate {CDate} The current date as a possible basis for relative dates,
if null
today is used (optional)
@param [dateFormat] {string} The expected date format - see formatDate
.
@param [settings] {object} Additional options whose attributes include:
@property [shortYearCutoff] {number} The cutoff year for determining the century.
@property [dayNamesShort] {string[]} Abbreviated names of the days from Sunday.
@property [dayNames] {string[]} Names of the days from Sunday.
@property [monthNamesShort] {string[]} Abbreviated names of the months.
@property [monthNames] {string[]} Names of the months.
@return {CDate} The decoded date. */
determineDate: function(dateSpec, defaultDate, currentDate, dateFormat, settings) {
if (currentDate && typeof currentDate !== 'object') {
settings = dateFormat;
dateFormat = currentDate;
currentDate = null;
}
if (typeof dateFormat !== 'string') {
settings = dateFormat;
dateFormat = '';
}
var calendar = this;
var offsetString = function(offset) {
try {
return calendar.parseDate(dateFormat, offset, settings);
}
catch (e) {
// Ignore
}
offset = offset.toLowerCase();
var date = (offset.match(/^c/) && currentDate ?
currentDate.newDate() : null) || calendar.today();
var pattern = /([+-]?[0-9]+)\s*(d|w|m|y)?/g;
var matches = pattern.exec(offset);
while (matches) {
date.add(parseInt(matches[1], 10), matches[2] || 'd');
matches = pattern.exec(offset);
}
return date;
};
defaultDate = (defaultDate ? defaultDate.newDate() : null);
dateSpec = (dateSpec == null ? defaultDate :
(typeof dateSpec === 'string' ? offsetString(dateSpec) : (typeof dateSpec === 'number' ?
(isNaN(dateSpec) || dateSpec === Infinity || dateSpec === -Infinity ? defaultDate :
calendar.today().add(dateSpec, 'd')) : calendar.newDate(dateSpec))));
return dateSpec;
}
});
/***/ })
/******/ });
/************************************************************************/
/******/ // The module cache
/******/ var __webpack_module_cache__ = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ var cachedModule = __webpack_module_cache__[moduleId];
/******/ if (cachedModule !== undefined) {
/******/ return cachedModule.exports;
/******/ }
/******/ // Create a new module (and put it into the cache)
/******/ var module = __webpack_module_cache__[moduleId] = {
/******/ // no module.id needed
/******/ // no module.loaded needed
/******/ exports: {}
/******/ };
/******/
/******/ // Execute the module function
/******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ !function() {
/******/ // define getter functions for harmony exports
/******/ __webpack_require__.d = function(exports, definition) {
/******/ for(var key in definition) {
/******/ if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/ }
/******/ }
/******/ };
/******/ }();
/******/
/******/ /* webpack/runtime/global */
/******/ !function() {
/******/ __webpack_require__.g = (function() {
/******/ if (typeof globalThis === 'object') return globalThis;
/******/ try {
/******/ return this || new Function('return this')();
/******/ } catch (e) {
/******/ if (typeof window === 'object') return window;
/******/ }
/******/ })();
/******/ }();
/******/
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ !function() {
/******/ __webpack_require__.o = function(obj, prop) { return Object.prototype.hasOwnProperty.call(obj, prop); }
/******/ }();
/******/
/******/ /* webpack/runtime/make namespace object */
/******/ !function() {
/******/ // define __esModule on exports
/******/ __webpack_require__.r = function(exports) {
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ }
/******/ Object.defineProperty(exports, '__esModule', { value: true });
/******/ };
/******/ }();
/******/
/************************************************************************/
/******/
/******/ // startup
/******/ // Load entry module and return exports
/******/ // This entry module is referenced by other modules so it can't be inlined
/******/ var __webpack_exports__ = __webpack_require__(488);
/******/
/******/ return __webpack_exports__;
/******/ })()
;
});